17 using namespace clang;
18 using namespace index;
27 return handleDeclOccurrence(D, D->getLocation(),
false,
28 cast<Decl>(D->getDeclContext()), Roles, Relations,
29 nullptr,
nullptr, D->getDeclContext());
37 DC = D->getDeclContext();
38 return handleDeclOccurrence(D, Loc,
false, cast<Decl>(DC),
40 nullptr,
nullptr, DC);
53 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D))
56 return handleDeclOccurrence(D, Loc,
true, Parent, Roles, Relations,
66 Loc = ImportD->getLocation();
80 if (Invalid || !SEntry.
isFile())
94 if (ImportD->isImplicit())
103 if (isa<TemplateTemplateParmDecl>(D))
106 if (isa<ObjCTypeParamDecl>(D))
109 if (!D->getParentFunctionOrMethod())
112 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
113 switch (ND->getFormalLinkage()) {
119 llvm_unreachable(
"Not a sema linkage");
131 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
132 TKind = SD->getSpecializationKind();
134 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
135 TKind = FD->getTemplateSpecializationKind();
146 llvm_unreachable(
"invalid TemplateSpecializationKind");
149 bool IndexingContext::shouldIgnoreIfImplicit(
const Decl *D) {
150 if (isa<ObjCInterfaceDecl>(D))
152 if (isa<ObjCCategoryDecl>(D))
154 if (isa<ObjCIvarDecl>(D))
156 if (isa<ObjCMethodDecl>(D))
158 if (isa<ImportDecl>(D))
165 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
166 return SD->getTemplateInstantiationPattern();
168 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
169 return FD->getTemplateInstantiationPattern();
175 if (
auto VD = dyn_cast<VarDecl>(D))
176 return VD->isThisDeclarationADefinition(Ctx);
178 if (
auto FD = dyn_cast<FunctionDecl>(D))
179 return FD->isThisDeclarationADefinition();
181 if (
auto TD = dyn_cast<TagDecl>(D))
182 return TD->isThisDeclarationADefinition();
184 if (
auto MD = dyn_cast<ObjCMethodDecl>(D))
185 return MD->isThisDeclarationADefinition() || isa<ObjCImplDecl>(ContainerDC);
187 if (isa<TypedefNameDecl>(D) ||
188 isa<EnumConstantDecl>(D) ||
190 isa<MSPropertyDecl>(D) ||
191 isa<ObjCImplDecl>(D) ||
192 isa<ObjCPropertyImplDecl>(D))
201 for (;; Parent = cast<Decl>(Parent->getDeclContext())) {
202 if (isa<TranslationUnitDecl>(Parent))
204 if (isa<LinkageSpecDecl>(Parent) || isa<BlockDecl>(Parent))
206 if (
auto NS = dyn_cast<NamespaceDecl>(Parent)) {
207 if (NS->isAnonymousNamespace())
209 }
else if (
auto RD = dyn_cast<RecordDecl>(Parent)) {
210 if (RD->isAnonymousStructOrUnion())
212 }
else if (
auto FD = dyn_cast<FieldDecl>(Parent)) {
213 if (FD->getDeclName().isEmpty())
221 D = D->getCanonicalDecl();
222 if (
auto TD = dyn_cast<TemplateDecl>(D)) {
223 D = TD->getTemplatedDecl();
224 assert(D->isCanonicalDecl());
231 bool IsRef,
const Decl *Parent,
237 if (D->isImplicit() && !isa<ObjCMethodDecl>(D))
239 if (!isa<NamedDecl>(D) ||
240 (cast<NamedDecl>(D)->getDeclName().isEmpty() &&
241 !isa<TagDecl>(D) && !isa<ObjCCategoryDecl>(D)))
257 if (Invalid || !SEntry.
isFile())
293 if (D->isImplicit() && !isa<ObjCMethodDecl>(D) &&
294 !(isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->getBuiltinID())) {
301 assert((!Parent || !Parent->isImplicit() ||
302 (isa<FunctionDecl>(Parent) &&
303 cast<FunctionDecl>(Parent)->getBuiltinID()) ||
304 isa<ObjCInterfaceDecl>(Parent) || isa<ObjCMethodDecl>(Parent)) &&
305 "unexpected implicit parent!");
308 FinalRelations.reserve(Relations.size()+1);
311 auto It = std::find_if(FinalRelations.begin(), FinalRelations.end(),
313 return Elem.RelatedSymbol == Rel.RelatedSymbol;
315 if (It != FinalRelations.end()) {
316 It->Roles |= Rel.Roles;
318 FinalRelations.push_back(Rel);
326 for (
auto &Rel : Relations) {
328 Rel.RelatedSymbol->getCanonicalDecl()));
Defines the clang::ASTContext interface.
static const Decl * getCanonicalDecl(const Decl *D)
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
External linkage, which indicates that the entity can be referred to from other translation units...
This is a discriminated union of FileInfo and ExpansionInfo.
Represents a relation to another symbol for a symbol occurrence.
No linkage, which means that the entity is unique and can only be referred to from within its scope...
Defines the SourceManager interface.
virtual bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations, FileID FID, unsigned Offset, ASTNodeInfo ASTNode)
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
Defines the C++ template declaration subclasses.
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations=None, const Expr *RefE=nullptr, const Decl *RefD=nullptr)
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
Represents a class template specialization, which refers to a class template with a given set of temp...
static const Decl * adjustTemplateImplicitInstantiation(const Decl *D)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
ArrayRef< SourceLocation > getIdentifierLocs() const
Retrieves the locations of each of the identifiers that make up the complete module name in the impor...
Expr - This represents one expression.
virtual bool handleModuleOccurence(const ImportDecl *ImportD, SymbolRoleSet Roles, FileID FID, unsigned Offset)
static bool isTemplateImplicitInstantiation(const Decl *D)
This template specialization was implicitly instantiated from a template.
SystemSymbolFilterKind SystemSymbolFilter
static bool isFunctionLocalDecl(const Decl *D)
Encodes a location in the source.
static const Decl * adjustParent(const Decl *Parent)
const FileInfo & getFile() const
This template specialization was instantiated from a template due to an explicit instantiation defini...
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
static bool isDeclADefinition(const Decl *D, const DeclContext *ContainerDC, ASTContext &Ctx)
ast_type_traits::DynTypedNode Node
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
External linkage within a unique namespace.
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
This template specialization was instantiated from a template due to an explicit instantiation declar...
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
This template specialization was declared or defined by an explicit specialization (C++ [temp...
static bool isFunctionOrMethod(const Decl *D)
isFunctionOrMethod - Return true if the given decl has function type (function or function-typed vari...
bool importedModule(const ImportDecl *ImportD)
bool shouldIndexFunctionLocalSymbols() const
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
SourceManager & getSourceManager()
No linkage according to the standard, but is visible from other translation units because of types de...
NamedDecl - This represents a decl with a name.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
This class handles loading and caching of source files into memory.