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),
84 (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
85 isa<TemplateTemplateParmDecl>(D))) {
88 return handleDeclOccurrence(D,
Loc,
true,
Parent, Roles, Relations,
120 bool Invalid =
false;
122 if (Invalid || !SEntry.
isFile())
151 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
152 TKind = SD->getSpecializationKind();
153 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
154 TKind = FD->getTemplateSpecializationKind();
155 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
156 TKind = VD->getTemplateSpecializationKind();
157 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
158 if (RD->getInstantiatedFromMemberClass())
159 TKind = RD->getTemplateSpecializationKind();
160 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
161 if (ED->getInstantiatedFromMemberEnum())
162 TKind = ED->getTemplateSpecializationKind();
163 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D) ||
164 isa<EnumConstantDecl>(D)) {
173 return isa<ClassTemplateSpecializationDecl>(D);
181 llvm_unreachable(
"invalid TemplateSpecializationKind");
184 bool IndexingContext::shouldIgnoreIfImplicit(
const Decl *D) {
185 if (isa<ObjCInterfaceDecl>(D))
187 if (isa<ObjCCategoryDecl>(D))
189 if (isa<ObjCIvarDecl>(D))
191 if (isa<ObjCMethodDecl>(D))
193 if (isa<ImportDecl>(D))
200 if (
const auto *CTSD =
203 else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
210 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
211 const auto *Template = SD->getTemplateInstantiationPattern();
216 return SD->getSpecializedTemplate()->getTemplatedDecl();
217 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
218 return FD->getTemplateInstantiationPattern();
219 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
220 return VD->getTemplateInstantiationPattern();
221 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
222 return RD->getInstantiatedFromMemberClass();
223 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
224 return ED->getInstantiatedFromMemberEnum();
225 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D)) {
226 const auto *ND = cast<NamedDecl>(D);
229 for (
const NamedDecl *BaseND : Pattern->lookup(ND->getDeclName())) {
230 if (BaseND->isImplicit())
232 if (BaseND->getKind() == ND->getKind())
236 }
else if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
237 if (
const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext())) {
239 for (
const NamedDecl *BaseECD : Pattern->lookup(ECD->getDeclName()))
248 if (
auto VD = dyn_cast<VarDecl>(D))
249 return VD->isThisDeclarationADefinition(Ctx);
251 if (
auto FD = dyn_cast<FunctionDecl>(D))
252 return FD->isThisDeclarationADefinition();
254 if (
auto TD = dyn_cast<TagDecl>(D))
255 return TD->isThisDeclarationADefinition();
257 if (
auto MD = dyn_cast<ObjCMethodDecl>(D))
258 return MD->isThisDeclarationADefinition() || isa<ObjCImplDecl>(ContainerDC);
260 if (isa<TypedefNameDecl>(D) || isa<EnumConstantDecl>(D) ||
261 isa<FieldDecl>(D) || isa<MSPropertyDecl>(D) || isa<ObjCImplDecl>(D) ||
262 isa<ObjCPropertyImplDecl>(D) || isa<ConceptDecl>(D))
271 !isa<ObjCCategoryDecl>(ND)) || isa<CXXDeductionGuideDecl>(ND);
277 for (;;
Parent = cast<Decl>(
Parent->getDeclContext())) {
278 if (isa<TranslationUnitDecl>(
Parent))
280 if (isa<LinkageSpecDecl>(
Parent) || isa<BlockDecl>(
Parent))
282 if (
auto NS = dyn_cast<NamespaceDecl>(
Parent)) {
283 if (NS->isAnonymousNamespace())
285 }
else if (
auto RD = dyn_cast<RecordDecl>(
Parent)) {
286 if (RD->isAnonymousStructOrUnion())
288 }
else if (
auto ND = dyn_cast<NamedDecl>(
Parent)) {
298 if (
auto TD = dyn_cast<TemplateDecl>(D)) {
299 if (
auto TTD = TD->getTemplatedDecl()) {
342 llvm_unreachable(
"Unsupported SymbolRole value!");
347 for (
auto &Rel : Relations) {
348 if (acceptForRelation(Rel.Roles))
362 if (D->
isImplicit() && !isa<ObjCMethodDecl>(D))
374 if (Invalid || !SEntry.
isFile())
415 FinalRelations.reserve(Relations.size()+1);
418 auto It = llvm::find_if(FinalRelations, [&](
SymbolRelation Elem) ->
bool {
421 if (It != FinalRelations.end()) {
422 It->Roles |= Rel.Roles;
424 FinalRelations.push_back(Rel);
443 for (
auto &Rel : Relations) {
445 Rel.RelatedSymbol->getCanonicalDecl()));
455 if (!shouldIndexMacroOccurrence(
false,
Loc))
464 if (!shouldIndexMacroOccurrence(
false,
Loc))
473 if (!shouldIndexMacroOccurrence(
true,
Loc))
479 bool IndexingContext::shouldIndexMacroOccurrence(
bool IsRef,
500 bool Invalid =
false;
502 if (Invalid || !SEntry.
isFile())
Defines the clang::ASTContext interface.
Defines the C++ template declaration subclasses.
static const Decl * getCanonicalDecl(const Decl *D)
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 const CXXRecordDecl * getDeclContextForTemplateInstationPattern(const Decl *D)
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)
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
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
SourceLocation getLocation() const
DeclContext * getDeclContext()
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...
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
ArrayRef< SourceLocation > getIdentifierLocs() const
Retrieves the locations of each of the identifiers that make up the complete module name in the impor...
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 handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=std::nullopt, const Expr *RefE=nullptr)
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 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)
The JSON file list parser is used to communicate input to InstallAPI.
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