23 if (
auto *
attr = D->
getAttr<ExternalSourceSymbolAttr>()) {
24 return attr->getGeneratedDeclaration();
31 : IndexOpts(IndexOpts), DataConsumer(DataConsumer) {}
37 Resolver = Ctx ? std::make_unique<HeuristicResolver>(*Ctx) :
nullptr;
45 return Ctx->getLangOpts();
49 return IndexOpts.IndexFunctionLocals;
53 return IndexOpts.IndexImplicitInstantiation;
57 return IndexOpts.IndexParametersInDeclarations;
61 return IndexOpts.IndexTemplateParameters;
77 const Decl *OrigD = D;
81 return handleDeclOccurrence(D, Loc,
false,
cast<Decl>(DC),
100 return handleDeclOccurrence(D, Loc,
true, Parent, Roles, Relations,
128 FileID FID =
SM.getFileID(
SM.getFileLoc(Loc));
138 switch (IndexOpts.SystemSymbolFilter) {
157 return DataConsumer.handleModuleOccurrence(ImportD, Mod, Roles, Loc);
163 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
164 TKind = SD->getSpecializationKind();
165 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
166 TKind = FD->getTemplateSpecializationKind();
167 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
168 TKind = VD->getTemplateSpecializationKind();
169 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
170 if (RD->getInstantiatedFromMemberClass())
171 TKind = RD->getTemplateSpecializationKind();
172 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
173 if (ED->getInstantiatedFromMemberEnum())
174 TKind = ED->getTemplateSpecializationKind();
193 llvm_unreachable(
"invalid TemplateSpecializationKind");
196bool IndexingContext::shouldIgnoreIfImplicit(
const Decl *D) {
212 if (
const auto *CTSD =
215 else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
222 SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
223 const auto *
Template = SD->getTemplateInstantiationPattern();
228 return SD->getSpecializedTemplate()->getTemplatedDecl();
229 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
230 return FD->getTemplateInstantiationPattern();
231 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
232 return VD->getTemplateInstantiationPattern();
233 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
234 return RD->getInstantiatedFromMemberClass();
235 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
236 return ED->getInstantiatedFromMemberEnum();
241 for (
const NamedDecl *BaseND : Pattern->lookup(ND->getDeclName())) {
242 if (BaseND->isImplicit())
244 if (BaseND->getKind() == ND->getKind())
248 }
else if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
249 if (
const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext())) {
251 for (
const NamedDecl *BaseECD : Pattern->lookup(ECD->getDeclName()))
260 if (
auto VD = dyn_cast<VarDecl>(D))
261 return VD->isThisDeclarationADefinition(Ctx);
263 if (
auto FD = dyn_cast<FunctionDecl>(D))
264 return FD->isThisDeclarationADefinition();
266 if (
auto TD = dyn_cast<TagDecl>(D))
267 return TD->isThisDeclarationADefinition();
269 if (
auto MD = dyn_cast<ObjCMethodDecl>(D))
294 if (
auto NS = dyn_cast<NamespaceDecl>(Parent)) {
295 if (NS->isAnonymousNamespace())
297 }
else if (
auto RD = dyn_cast<RecordDecl>(Parent)) {
298 if (RD->isAnonymousStructOrUnion())
300 }
else if (
auto ND = dyn_cast<NamedDecl>(Parent)) {
310 if (
auto TD = dyn_cast<TemplateDecl>(D)) {
311 if (
auto TTD = TD->getTemplatedDecl()) {
354 llvm_unreachable(
"Unsupported SymbolRole value!");
359 for (
auto &Rel : Relations) {
360 if (acceptForRelation(Rel.Roles))
367bool IndexingContext::handleDeclOccurrence(
const Decl *D, SourceLocation Loc,
368 bool IsRef,
const Decl *Parent,
370 ArrayRef<SymbolRelation> Relations,
373 const DeclContext *ContainerDC) {
379 SourceManager &
SM = Ctx->getSourceManager();
380 FileID FID =
SM.getFileID(
SM.getFileLoc(Loc));
385 const SrcMgr::SLocEntry &SEntry =
SM.getSLocEntry(FID, &
Invalid);
390 switch (IndexOpts.SystemSymbolFilter) {
426 SmallVector<SymbolRelation, 6> FinalRelations;
427 FinalRelations.reserve(Relations.size()+1);
429 auto addRelation = [&](SymbolRelation Rel) {
430 auto It = llvm::find_if(FinalRelations, [&](SymbolRelation Elem) ->
bool {
433 if (It != FinalRelations.end()) {
434 It->Roles |= Rel.Roles;
436 FinalRelations.push_back(Rel);
443 addRelation(SymbolRelation{
448 addRelation(SymbolRelation{
455 for (
auto &Rel : Relations) {
456 addRelation(SymbolRelation(Rel.Roles,
457 Rel.RelatedSymbol->getCanonicalDecl()));
460 IndexDataConsumer::ASTNodeInfo Node{OrigE, OrigD, Parent, ContainerDC};
461 return DataConsumer.handleDeclOccurrence(D, Roles, FinalRelations, Loc, Node);
467 if (!shouldIndexMacroOccurrence(
false, Loc))
470 DataConsumer.handleMacroOccurrence(&Name, &MI, Roles, Loc);
476 if (!shouldIndexMacroOccurrence(
false, Loc))
479 DataConsumer.handleMacroOccurrence(&Name, &MI, Roles, Loc);
485 if (!shouldIndexMacroOccurrence(
true, Loc))
488 DataConsumer.handleMacroOccurrence(&Name, &MI, Roles, Loc);
491bool IndexingContext::shouldIndexMacroOccurrence(
bool IsRef,
508 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()
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 handleModuleOccurrence(const ImportDecl *ImportD, const Module *Mod, SymbolRoleSet Roles, SourceLocation Loc)
void setASTContext(ASTContext &ctx)
bool shouldIndexImplicitInstantiation() const
bool importedModule(const ImportDecl *ImportD)
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations={})
bool shouldIndex(const Decl *D)
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations={}, const Expr *RefE=nullptr)
bool shouldIndexFunctionLocalSymbols() const
void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MD)
bool shouldIndexTemplateParameters() const
IndexingContext(IndexingOptions IndexOpts, IndexDataConsumer &DataConsumer)
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)
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.
bool isa(CodeGen::Address addr)
@ Template
We are parsing a template declaration.
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,...
U cast(CodeGen::Address addr)
SystemSymbolFilterKind SystemSymbolFilter
const Decl * RelatedSymbol