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));
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");
185bool 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));
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))
480bool IndexingContext::shouldIndexMacroOccurrence(
bool IsRef,
497 FileID FID =
SM.getFileID(
SM.getFileLoc(Loc));
Defines the clang::ASTContext interface.
Defines the C++ template declaration subclasses.
static bool shouldSkipNamelessDecl(const NamedDecl *ND)
Whether the given NamedDecl should be skipped because it has no name.
static const Decl * adjustParent(const Decl *Parent)
static void reportModuleReferences(const Module *Mod, ArrayRef< SourceLocation > IdLocs, const ImportDecl *ImportD, IndexDataConsumer &DataConsumer)
static bool isGeneratedDecl(const Decl *D)
static bool isDeclADefinition(const Decl *D, const DeclContext *ContainerDC, ASTContext &Ctx)
static bool shouldReportOccurrenceForSystemDeclOnlyMode(bool IsRef, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations)
static const Decl * adjustTemplateImplicitInstantiation(const Decl *D)
static const CXXRecordDecl * getDeclContextForTemplateInstationPattern(const Decl *D)
static const Decl * getCanonicalDecl(const Decl *D)
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
const LangOptions & getLangOpts() const
Represents a C++ struct/union/class.
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
Represents a class template specialization, which refers to a class template with a given set of temp...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
bool isInvalidDecl() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
bool isEmpty() const
Evaluates true when this declaration name is empty.
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
This represents one expression.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a function declaration or definition.
One of these records is kept for each identifier that is lexed.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
ArrayRef< SourceLocation > getIdentifierLocs() const
Retrieves the locations of each of the identifiers that make up the complete module name in the impor...
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Encapsulates the data about a macro definition (e.g.
Describes a module or submodule.
Module * Parent
The parent of this module.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
virtual bool handleDeclOccurrence(const Decl *D, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations, SourceLocation Loc, ASTNodeInfo ASTNode)
virtual bool handleMacroOccurrence(const IdentifierInfo *Name, const MacroInfo *MI, SymbolRoleSet Roles, SourceLocation Loc)
virtual bool handleModuleOccurrence(const ImportDecl *ImportD, const Module *Mod, SymbolRoleSet Roles, SourceLocation Loc)
bool shouldIndexImplicitInstantiation() const
bool importedModule(const ImportDecl *ImportD)
bool shouldIndex(const Decl *D)
bool shouldIndexFunctionLocalSymbols() const
void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MD)
bool shouldIndexTemplateParameters() const
bool shouldIndexParametersInDeclarations() const
void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
static bool isTemplateImplicitInstantiation(const Decl *D)
const LangOptions & getLangOpts() const
void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=std::nullopt, const Expr *RefE=nullptr, const Decl *RefD=nullptr)
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=std::nullopt)
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
SymbolRole
Set of roles that are attributed to symbol occurrences.
@ RelationSpecializationOf
bool isFunctionLocalSymbol(const Decl *D)
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, llvm::function_ref< bool(SymbolRole)> Fn)
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
SystemSymbolFilterKind SystemSymbolFilter
bool IndexParametersInDeclarations
bool IndexImplicitInstantiation
bool IndexTemplateParameters
Represents a relation to another symbol for a symbol occurrence.
const Decl * RelatedSymbol