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,
112 bool Invalid =
false;
114 if (Invalid || !SEntry.
isFile())
143 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
144 TKind = SD->getSpecializationKind();
145 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
146 TKind = FD->getTemplateSpecializationKind();
147 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
148 TKind = VD->getTemplateSpecializationKind();
149 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
150 if (RD->getInstantiatedFromMemberClass())
151 TKind = RD->getTemplateSpecializationKind();
152 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
153 if (ED->getInstantiatedFromMemberEnum())
154 TKind = ED->getTemplateSpecializationKind();
155 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D) ||
156 isa<EnumConstantDecl>(D)) {
169 llvm_unreachable(
"invalid TemplateSpecializationKind");
172 bool IndexingContext::shouldIgnoreIfImplicit(
const Decl *D) {
173 if (isa<ObjCInterfaceDecl>(D))
175 if (isa<ObjCCategoryDecl>(D))
177 if (isa<ObjCIvarDecl>(D))
179 if (isa<ObjCMethodDecl>(D))
181 if (isa<ImportDecl>(D))
188 if (
const auto *CTSD =
191 else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
198 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
199 return SD->getTemplateInstantiationPattern();
200 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
201 return FD->getTemplateInstantiationPattern();
202 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
203 return VD->getTemplateInstantiationPattern();
204 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
205 return RD->getInstantiatedFromMemberClass();
206 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
207 return ED->getInstantiatedFromMemberEnum();
208 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D)) {
209 const auto *ND = cast<NamedDecl>(D);
212 for (
const NamedDecl *BaseND : Pattern->lookup(ND->getDeclName())) {
213 if (BaseND->isImplicit())
215 if (BaseND->getKind() == ND->getKind())
219 }
else if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
220 if (
const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext())) {
222 for (
const NamedDecl *BaseECD : Pattern->lookup(ECD->getDeclName()))
231 if (
auto VD = dyn_cast<VarDecl>(D))
232 return VD->isThisDeclarationADefinition(Ctx);
234 if (
auto FD = dyn_cast<FunctionDecl>(D))
235 return FD->isThisDeclarationADefinition();
237 if (
auto TD = dyn_cast<TagDecl>(D))
238 return TD->isThisDeclarationADefinition();
240 if (
auto MD = dyn_cast<ObjCMethodDecl>(D))
241 return MD->isThisDeclarationADefinition() || isa<ObjCImplDecl>(ContainerDC);
243 if (isa<TypedefNameDecl>(D) ||
244 isa<EnumConstantDecl>(D) ||
246 isa<MSPropertyDecl>(D) ||
247 isa<ObjCImplDecl>(D) ||
248 isa<ObjCPropertyImplDecl>(D))
257 !isa<ObjCCategoryDecl>(ND)) || isa<CXXDeductionGuideDecl>(ND);
264 if (isa<TranslationUnitDecl>(Parent))
266 if (isa<LinkageSpecDecl>(Parent) || isa<BlockDecl>(
Parent))
268 if (
auto NS = dyn_cast<NamespaceDecl>(Parent)) {
269 if (NS->isAnonymousNamespace())
271 }
else if (
auto RD = dyn_cast<RecordDecl>(Parent)) {
272 if (RD->isAnonymousStructOrUnion())
274 }
else if (
auto ND = dyn_cast<NamedDecl>(Parent)) {
284 if (
auto TD = dyn_cast<TemplateDecl>(D)) {
285 if (
auto TTD = TD->getTemplatedDecl()) {
327 llvm_unreachable(
"Unsupported SymbolRole value!");
332 for (
auto &Rel : Relations) {
333 if (acceptForRelation(Rel.Roles))
347 if (D->
isImplicit() && !isa<ObjCMethodDecl>(D))
357 bool Invalid =
false;
359 if (Invalid || !SEntry.
isFile())
400 FinalRelations.reserve(Relations.size()+1);
403 auto It = std::find_if(FinalRelations.begin(), FinalRelations.end(),
405 return Elem.RelatedSymbol == Rel.RelatedSymbol;
407 if (It != FinalRelations.end()) {
408 It->Roles |= Rel.Roles;
410 FinalRelations.push_back(Rel);
429 for (
auto &Rel : Relations) {
431 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)
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)
bool isInvalidDecl() const
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...
Describes a module or submodule.
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
Module * Parent
The parent of this module.
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.
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
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)
static void reportModuleReferences(const Module *Mod, ArrayRef< SourceLocation > IdLocs, const ImportDecl *ImportD, IndexDataConsumer &DataConsumer)
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...
virtual bool handleModuleOccurence(const ImportDecl *ImportD, const Module *Mod, SymbolRoleSet Roles, SourceLocation Loc)
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