Go to the documentation of this file.
18 using namespace clang;
19 using namespace index;
22 if (
auto *
attr = D->
getAttr<ExternalSourceSymbolAttr>()) {
23 return attr->getGeneratedDeclaration();
65 const Decl *OrigD = D;
66 if (isa<ObjCPropertyImplDecl>(D)) {
67 D = cast<ObjCPropertyImplDecl>(D)->getPropertyDecl();
69 return handleDeclOccurrence(D, Loc,
false, cast<Decl>(DC),
85 (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
86 isa<TemplateTemplateParmDecl>(D))) {
89 return handleDeclOccurrence(D, Loc,
true,
Parent, Roles, Relations,
117 FileID FID =
SM.getFileID(
SM.getFileLoc(Loc));
121 bool Invalid =
false;
123 if (Invalid || !SEntry.
isFile())
152 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
153 TKind = SD->getSpecializationKind();
154 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
155 TKind = FD->getTemplateSpecializationKind();
156 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
157 TKind = VD->getTemplateSpecializationKind();
158 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
159 if (RD->getInstantiatedFromMemberClass())
160 TKind = RD->getTemplateSpecializationKind();
161 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
162 if (ED->getInstantiatedFromMemberEnum())
163 TKind = ED->getTemplateSpecializationKind();
164 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D) ||
165 isa<EnumConstantDecl>(D)) {
174 return isa<ClassTemplateSpecializationDecl>(D);
182 llvm_unreachable(
"invalid TemplateSpecializationKind");
185 bool IndexingContext::shouldIgnoreIfImplicit(
const Decl *D) {
186 if (isa<ObjCInterfaceDecl>(D))
188 if (isa<ObjCCategoryDecl>(D))
190 if (isa<ObjCIvarDecl>(D))
192 if (isa<ObjCMethodDecl>(D))
194 if (isa<ImportDecl>(D))
201 if (
const auto *CTSD =
204 else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
211 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
212 const auto *Template = SD->getTemplateInstantiationPattern();
217 return SD->getSpecializedTemplate()->getTemplatedDecl();
218 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
219 return FD->getTemplateInstantiationPattern();
220 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
221 return VD->getTemplateInstantiationPattern();
222 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
223 return RD->getInstantiatedFromMemberClass();
224 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
225 return ED->getInstantiatedFromMemberEnum();
226 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D)) {
227 const auto *ND = cast<NamedDecl>(D);
230 for (
const NamedDecl *BaseND : Pattern->lookup(ND->getDeclName())) {
231 if (BaseND->isImplicit())
233 if (BaseND->getKind() == ND->getKind())
237 }
else if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
238 if (
const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext())) {
240 for (
const NamedDecl *BaseECD : Pattern->lookup(ECD->getDeclName()))
249 if (
auto VD = dyn_cast<VarDecl>(D))
250 return VD->isThisDeclarationADefinition(Ctx);
252 if (
auto FD = dyn_cast<FunctionDecl>(D))
253 return FD->isThisDeclarationADefinition();
255 if (
auto TD = dyn_cast<TagDecl>(D))
256 return TD->isThisDeclarationADefinition();
258 if (
auto MD = dyn_cast<ObjCMethodDecl>(D))
259 return MD->isThisDeclarationADefinition() || isa<ObjCImplDecl>(ContainerDC);
261 if (isa<TypedefNameDecl>(D) || isa<EnumConstantDecl>(D) ||
262 isa<FieldDecl>(D) || isa<MSPropertyDecl>(D) || isa<ObjCImplDecl>(D) ||
263 isa<ObjCPropertyImplDecl>(D) || isa<ConceptDecl>(D))
272 !isa<ObjCCategoryDecl>(ND)) || isa<CXXDeductionGuideDecl>(ND);
278 for (;;
Parent = cast<Decl>(
Parent->getDeclContext())) {
279 if (isa<TranslationUnitDecl>(
Parent))
281 if (isa<LinkageSpecDecl>(
Parent) || isa<BlockDecl>(
Parent))
283 if (
auto NS = dyn_cast<NamespaceDecl>(
Parent)) {
284 if (NS->isAnonymousNamespace())
286 }
else if (
auto RD = dyn_cast<RecordDecl>(
Parent)) {
287 if (RD->isAnonymousStructOrUnion())
289 }
else if (
auto ND = dyn_cast<NamedDecl>(
Parent)) {
299 if (
auto TD = dyn_cast<TemplateDecl>(D)) {
300 if (
auto TTD = TD->getTemplatedDecl()) {
343 llvm_unreachable(
"Unsupported SymbolRole value!");
348 for (
auto &Rel : Relations) {
349 if (acceptForRelation(Rel.Roles))
363 if (D->
isImplicit() && !isa<ObjCMethodDecl>(D))
369 FileID FID =
SM.getFileID(
SM.getFileLoc(Loc));
375 if (Invalid || !SEntry.
isFile())
416 FinalRelations.reserve(Relations.size()+1);
419 auto It = llvm::find_if(FinalRelations, [&](
SymbolRelation Elem) ->
bool {
422 if (It != FinalRelations.end()) {
423 It->Roles |= Rel.Roles;
425 FinalRelations.push_back(Rel);
444 for (
auto &Rel : Relations) {
446 Rel.RelatedSymbol->getCanonicalDecl()));
456 if (!shouldIndexMacroOccurrence(
false, Loc))
465 if (!shouldIndexMacroOccurrence(
false, Loc))
474 if (!shouldIndexMacroOccurrence(
true, Loc))
480 bool IndexingContext::shouldIndexMacroOccurrence(
bool IsRef,
497 FileID FID =
SM.getFileID(
SM.getFileLoc(Loc));
501 bool Invalid =
false;
503 if (Invalid || !SEntry.
isFile())
bool shouldIndex(const Decl *D)
static bool shouldSkipNamelessDecl(const NamedDecl *ND)
Whether the given NamedDecl should be skipped because it has no name.
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, llvm::function_ref< bool(SymbolRole)> Fn)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Encodes a location in the source.
This represents a decl that may have a name.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None, const Expr *RefE=nullptr, const Decl *RefD=nullptr)
const LangOptions & getLangOpts() const
Encapsulates the data about a macro definition (e.g.
bool IndexParametersInDeclarations
static const CXXRecordDecl * getDeclContextForTemplateInstationPattern(const Decl *D)
SourceManager & getSourceManager()
bool shouldIndexParametersInDeclarations() const
This class handles loading and caching of source files into memory.
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
Describes a module or submodule.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
virtual bool handleModuleOccurrence(const ImportDecl *ImportD, const Module *Mod, SymbolRoleSet Roles, SourceLocation Loc)
void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
bool IndexTemplateParameters
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const FileInfo & getFile() const
void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
bool isInvalidDecl() const
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MD)
static void reportModuleReferences(const Module *Mod, ArrayRef< SourceLocation > IdLocs, const ImportDecl *ImportD, IndexDataConsumer &DataConsumer)
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
ArrayRef< SourceLocation > getIdentifierLocs() const
Retrieves the locations of each of the identifiers that make up the complete module name in the impor...
virtual bool handleMacroOccurrence(const IdentifierInfo *Name, const MacroInfo *MI, SymbolRoleSet Roles, SourceLocation Loc)
bool isFunctionLocalSymbol(const Decl *D)
const Decl * RelatedSymbol
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Module * Parent
The parent of this module.
static const Decl * adjustTemplateImplicitInstantiation(const Decl *D)
Represents a C++ struct/union/class.
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
bool shouldIndexImplicitInstantiation() const
bool shouldIndexFunctionLocalSymbols() const
static const Decl * getCanonicalDecl(const Decl *D)
bool importedModule(const ImportDecl *ImportD)
SymbolRole
Set of roles that are attributed to symbol occurrences.
Decl - This represents one declaration (or definition), e.g.
static bool isGeneratedDecl(const Decl *D)
@ RelationSpecializationOf
SystemSymbolFilterKind SystemSymbolFilter
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
bool IndexImplicitInstantiation
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static bool shouldReportOccurrenceForSystemDeclOnlyMode(bool IsRef, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations)
virtual bool handleDeclOccurrence(const Decl *D, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations, SourceLocation Loc, ASTNodeInfo ASTNode)
static bool isDeclADefinition(const Decl *D, const DeclContext *ContainerDC, ASTContext &Ctx)
static bool isTemplateImplicitInstantiation(const Decl *D)
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
bool shouldIndexTemplateParameters() const
static const Decl * adjustParent(const Decl *Parent)
bool isEmpty() const
Evaluates true when this declaration name is empty.
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
This represents one expression.
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None)
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Represents a class template specialization, which refers to a class template with a given set of temp...
SourceLocation getLocation() const
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Represents a function declaration or definition.
Represents a relation to another symbol for a symbol occurrence.
const LangOptions & getLangOpts() const
This is a discriminated union of FileInfo and ExpansionInfo.
DeclContext * getDeclContext()