18 using namespace clang;
19 using namespace index;
22 if (
auto *attr = D->
getAttr<ExternalSourceSymbolAttr>()) {
23 return attr->getGeneratedDeclaration();
57 const Decl *OrigD = D;
58 if (isa<ObjCPropertyImplDecl>(D)) {
59 D = cast<ObjCPropertyImplDecl>(D)->getPropertyDecl();
61 return handleDeclOccurrence(D, Loc,
false, cast<Decl>(DC),
76 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D))
79 return handleDeclOccurrence(D, Loc,
true, Parent, Roles, Relations,
98 if (Invalid || !SEntry.
isFile())
121 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
122 TKind = SD->getSpecializationKind();
123 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
124 TKind = FD->getTemplateSpecializationKind();
125 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
126 TKind = VD->getTemplateSpecializationKind();
127 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
128 if (RD->getInstantiatedFromMemberClass())
129 TKind = RD->getTemplateSpecializationKind();
130 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
131 if (ED->getInstantiatedFromMemberEnum())
132 TKind = ED->getTemplateSpecializationKind();
133 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D) ||
134 isa<EnumConstantDecl>(D)) {
147 llvm_unreachable(
"invalid TemplateSpecializationKind");
150 bool IndexingContext::shouldIgnoreIfImplicit(
const Decl *D) {
151 if (isa<ObjCInterfaceDecl>(D))
153 if (isa<ObjCCategoryDecl>(D))
155 if (isa<ObjCIvarDecl>(D))
157 if (isa<ObjCMethodDecl>(D))
159 if (isa<ImportDecl>(D))
166 if (
const auto *CTSD =
169 else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
176 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
177 return SD->getTemplateInstantiationPattern();
178 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
179 return FD->getTemplateInstantiationPattern();
180 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
181 return VD->getTemplateInstantiationPattern();
182 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
183 return RD->getInstantiatedFromMemberClass();
184 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
185 return ED->getInstantiatedFromMemberEnum();
186 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D)) {
187 const auto *ND = cast<NamedDecl>(D);
190 for (
const NamedDecl *BaseND : Pattern->lookup(ND->getDeclName())) {
191 if (BaseND->isImplicit())
193 if (BaseND->getKind() == ND->getKind())
197 }
else if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
198 if (
const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext())) {
200 for (
const NamedDecl *BaseECD : Pattern->lookup(ECD->getDeclName()))
209 if (
auto VD = dyn_cast<VarDecl>(D))
210 return VD->isThisDeclarationADefinition(Ctx);
212 if (
auto FD = dyn_cast<FunctionDecl>(D))
213 return FD->isThisDeclarationADefinition();
215 if (
auto TD = dyn_cast<TagDecl>(D))
216 return TD->isThisDeclarationADefinition();
218 if (
auto MD = dyn_cast<ObjCMethodDecl>(D))
219 return MD->isThisDeclarationADefinition() || isa<ObjCImplDecl>(ContainerDC);
221 if (isa<TypedefNameDecl>(D) ||
222 isa<EnumConstantDecl>(D) ||
224 isa<MSPropertyDecl>(D) ||
225 isa<ObjCImplDecl>(D) ||
226 isa<ObjCPropertyImplDecl>(D))
235 !isa<ObjCCategoryDecl>(ND)) || isa<CXXDeductionGuideDecl>(ND);
242 if (isa<TranslationUnitDecl>(Parent))
244 if (isa<LinkageSpecDecl>(Parent) || isa<BlockDecl>(
Parent))
246 if (
auto NS = dyn_cast<NamespaceDecl>(Parent)) {
247 if (NS->isAnonymousNamespace())
249 }
else if (
auto RD = dyn_cast<RecordDecl>(Parent)) {
250 if (RD->isAnonymousStructOrUnion())
252 }
else if (
auto ND = dyn_cast<NamedDecl>(Parent)) {
262 if (
auto TD = dyn_cast<TemplateDecl>(D)) {
263 if (
auto TTD = TD->getTemplatedDecl()) {
305 llvm_unreachable(
"Unsupported SymbolRole value!");
310 for (
auto &Rel : Relations) {
311 if (acceptForRelation(Rel.Roles))
325 if (D->
isImplicit() && !isa<ObjCMethodDecl>(D))
335 bool Invalid =
false;
337 if (Invalid || !SEntry.
isFile())
378 FinalRelations.reserve(Relations.size()+1);
381 auto It = std::find_if(FinalRelations.begin(), FinalRelations.end(),
383 return Elem.RelatedSymbol == Rel.RelatedSymbol;
385 if (It != FinalRelations.end()) {
386 It->Roles |= Rel.Roles;
388 FinalRelations.push_back(Rel);
407 for (
auto &Rel : Relations) {
409 Rel.RelatedSymbol->getCanonicalDecl()));
Defines the clang::ASTContext interface.
static const Decl * getCanonicalDecl(const Decl *D)
Represents a function declaration or definition.
This is a discriminated union of FileInfo and ExpansionInfo.
Represents a relation to another symbol for a symbol occurrence.
static bool shouldReportOccurrenceForSystemDeclOnlyMode(bool IsRef, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations)
Defines the SourceManager interface.
Decl - This represents one declaration (or definition), e.g.
Defines the C++ template declaration subclasses.
virtual bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations, SourceLocation Loc, ASTNodeInfo ASTNode)
virtual bool handleModuleOccurence(const ImportDecl *ImportD, SymbolRoleSet Roles, SourceLocation Loc)
bool isEmpty() const
Evaluates true when this declaration name is empty.
void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
static const CXXRecordDecl * getDeclContextForTemplateInstationPattern(const Decl *D)
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, llvm::function_ref< bool(SymbolRole)> Fn)
static const Decl * adjustTemplateImplicitInstantiation(const Decl *D)
const LangOptions & getLangOpts() const
SymbolRole
Set of roles that are attributed to symbol occurrences.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isFunctionLocalSymbol(const Decl *D)
void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MD)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const FileInfo & getFile() const
static bool shouldSkipNamelessDecl(const NamedDecl *ND)
Whether the given NamedDecl should be skipped because it has no name.
bool shouldIndexFunctionLocalSymbols() const
ArrayRef< SourceLocation > getIdentifierLocs() const
Retrieves the locations of each of the identifiers that make up the complete module name in the impor...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Expr - This represents one expression.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
DeclContext * getDeclContext()
static bool isTemplateImplicitInstantiation(const Decl *D)
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)
This template specialization was implicitly instantiated from a template.
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
SystemSymbolFilterKind SystemSymbolFilter
Encodes a location in the source.
static const Decl * adjustParent(const Decl *Parent)
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
bool shouldIndexImplicitInstantiation() 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...
bool IndexImplicitInstantiation
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...
bool shouldIndex(const Decl *D)
Dataflow Directional Tag Classes.
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...
static bool isGeneratedDecl(const Decl *D)
virtual bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *MI, SymbolRoleSet Roles, SourceLocation Loc)
This template specialization was instantiated from a template due to an explicit instantiation declar...
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Encapsulates the data about a macro definition (e.g.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
This template specialization was declared or defined by an explicit specialization (C++ [temp...
bool importedModule(const ImportDecl *ImportD)
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceManager & getSourceManager()
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ struct/union/class.
This represents a decl that may have a name.
const LangOptions & getLangOpts() const
This class handles loading and caching of source files into memory.
SourceLocation getLocation() const