17 using namespace clang;
18 using namespace index;
21 if (
auto *attr = D->
getAttr<ExternalSourceSymbolAttr>()) {
22 return attr->getGeneratedDeclaration();
60 const Decl *OrigD = D;
61 if (isa<ObjCPropertyImplDecl>(D)) {
62 D = cast<ObjCPropertyImplDecl>(D)->getPropertyDecl();
64 return handleDeclOccurrence(D, Loc,
false, cast<Decl>(DC),
79 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D))
82 return handleDeclOccurrence(D, Loc,
true, Parent, Roles, Relations,
115 bool Invalid =
false;
117 if (Invalid || !SEntry.
isFile())
146 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
147 TKind = SD->getSpecializationKind();
148 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
149 TKind = FD->getTemplateSpecializationKind();
150 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
151 TKind = VD->getTemplateSpecializationKind();
152 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
153 if (RD->getInstantiatedFromMemberClass())
154 TKind = RD->getTemplateSpecializationKind();
155 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
156 if (ED->getInstantiatedFromMemberEnum())
157 TKind = ED->getTemplateSpecializationKind();
158 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D) ||
159 isa<EnumConstantDecl>(D)) {
172 llvm_unreachable(
"invalid TemplateSpecializationKind");
175 bool IndexingContext::shouldIgnoreIfImplicit(
const Decl *D) {
176 if (isa<ObjCInterfaceDecl>(D))
178 if (isa<ObjCCategoryDecl>(D))
180 if (isa<ObjCIvarDecl>(D))
182 if (isa<ObjCMethodDecl>(D))
184 if (isa<ImportDecl>(D))
191 if (
const auto *CTSD =
194 else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
201 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
202 return SD->getTemplateInstantiationPattern();
203 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
204 return FD->getTemplateInstantiationPattern();
205 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
206 return VD->getTemplateInstantiationPattern();
207 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
208 return RD->getInstantiatedFromMemberClass();
209 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
210 return ED->getInstantiatedFromMemberEnum();
211 }
else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D)) {
212 const auto *ND = cast<NamedDecl>(D);
215 for (
const NamedDecl *BaseND : Pattern->lookup(ND->getDeclName())) {
216 if (BaseND->isImplicit())
218 if (BaseND->getKind() == ND->getKind())
222 }
else if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
223 if (
const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext())) {
225 for (
const NamedDecl *BaseECD : Pattern->lookup(ECD->getDeclName()))
234 if (
auto VD = dyn_cast<VarDecl>(D))
235 return VD->isThisDeclarationADefinition(Ctx);
237 if (
auto FD = dyn_cast<FunctionDecl>(D))
238 return FD->isThisDeclarationADefinition();
240 if (
auto TD = dyn_cast<TagDecl>(D))
241 return TD->isThisDeclarationADefinition();
243 if (
auto MD = dyn_cast<ObjCMethodDecl>(D))
244 return MD->isThisDeclarationADefinition() || isa<ObjCImplDecl>(ContainerDC);
246 if (isa<TypedefNameDecl>(D) ||
247 isa<EnumConstantDecl>(D) ||
249 isa<MSPropertyDecl>(D) ||
250 isa<ObjCImplDecl>(D) ||
251 isa<ObjCPropertyImplDecl>(D))
260 !isa<ObjCCategoryDecl>(ND)) || isa<CXXDeductionGuideDecl>(ND);
267 if (isa<TranslationUnitDecl>(Parent))
269 if (isa<LinkageSpecDecl>(Parent) || isa<BlockDecl>(
Parent))
271 if (
auto NS = dyn_cast<NamespaceDecl>(Parent)) {
272 if (NS->isAnonymousNamespace())
274 }
else if (
auto RD = dyn_cast<RecordDecl>(Parent)) {
275 if (RD->isAnonymousStructOrUnion())
277 }
else if (
auto ND = dyn_cast<NamedDecl>(Parent)) {
287 if (
auto TD = dyn_cast<TemplateDecl>(D)) {
288 if (
auto TTD = TD->getTemplatedDecl()) {
330 llvm_unreachable(
"Unsupported SymbolRole value!");
335 for (
auto &Rel : Relations) {
336 if (acceptForRelation(Rel.Roles))
350 if (D->
isImplicit() && !isa<ObjCMethodDecl>(D))
360 bool Invalid =
false;
362 if (Invalid || !SEntry.
isFile())
403 FinalRelations.reserve(Relations.size()+1);
406 auto It = std::find_if(FinalRelations.begin(), FinalRelations.end(),
408 return Elem.RelatedSymbol == Rel.RelatedSymbol;
410 if (It != FinalRelations.end()) {
411 It->Roles |= Rel.Roles;
413 FinalRelations.push_back(Rel);
432 for (
auto &Rel : Relations) {
434 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)
bool shouldIndexParametersInDeclarations() const
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.
bool IndexParametersInDeclarations
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