15#include "llvm/ADT/ScopeExit.h"
23 IndexingContext &IndexCtx;
24 const NamedDecl *Parent;
25 const DeclContext *ParentDC;
27 SmallVector<SymbolRelation, 3> Relations;
29 typedef RecursiveASTVisitor<TypeIndexer> base;
32 TypeIndexer(IndexingContext &indexCtx,
const NamedDecl *parent,
33 const DeclContext *DC,
bool isBase,
bool isIBType)
34 : IndexCtx(indexCtx), Parent(parent), ParentDC(DC), IsBase(isBase) {
37 Relations.emplace_back((
unsigned)SymbolRole::RelationBaseOf, Parent);
41 Relations.emplace_back((
unsigned)SymbolRole::RelationIBTypeOf, Parent);
45 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
47#define TRY_TO(CALL_EXPR) \
60 bool handleTypeNameReference(NamedDecl *ND, SourceLocation Loc, QualType T) {
61 if (
auto *TND = dyn_cast<TypedefNameDecl>(ND))
62 if (TND->isTransparentTag())
63 ND = TND->getUnderlyingType()->castAsTagDecl();
66 IndexCtx.handleReference(ND, Loc, Parent, ParentDC,
SymbolRoleSet()));
68 TRY_TO(IndexCtx.handleReference(CD, Loc, Parent, ParentDC,
69 (
unsigned)SymbolRole::Implicit,
74 return IndexCtx.handleReference(ND, Loc, Parent, ParentDC,
SymbolRoleSet(),
78 bool VisitTypedefTypeLoc(TypedefTypeLoc TL) {
85 bool VisitUsingTypeLoc(UsingTypeLoc TL) {
86 return handleTypeNameReference(TL.
getDecl()->getTargetDecl(),
90 bool VisitAutoTypeLoc(AutoTypeLoc TL) {
97 bool traverseParamVarHelper(ParmVarDecl *D) {
104 bool TraverseParmVarDecl(ParmVarDecl *D) {
112 if (FD->isThisDeclarationADefinition()) {
113 return traverseParamVarHelper(D);
117 return base::TraverseParmVarDecl(D);
121 IndexCtx.indexNestedNameSpecifierLoc(NNS, Parent, ParentDC);
125 bool VisitTagTypeLoc(TagTypeLoc TL) {
127 if (!IndexCtx.shouldIndexFunctionLocalSymbols() &&
132 IndexCtx.indexTagDecl(D);
136 return IndexCtx.handleReference(D, TL.
getNameLoc(),
141 bool VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
146 bool VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
154 void HandleTemplateSpecializationTypeLoc(
TemplateName TemplName,
155 SourceLocation TemplNameLoc,
156 CXXRecordDecl *ResolvedClass,
160 if (!IsTypeAlias && ResolvedClass &&
162 IndexCtx.shouldIndexImplicitInstantiation())) {
163 IndexCtx.handleReference(ResolvedClass, TemplNameLoc, Parent, ParentDC,
166 IndexCtx.handleReference(D, TemplNameLoc, Parent, ParentDC,
171 bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
175 HandleTemplateSpecializationTypeLoc(
181 bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL,
182 bool TraverseQualifier) {
183 if (!WalkUpFromTemplateSpecializationTypeLoc(TL))
185 if (!TraverseTemplateName(TL.
getTypePtr()->getTemplateName()))
190 SmallVector<SymbolRelation, 3> SavedRelations = Relations;
192 llvm::scope_exit ResetSavedRelations(
193 [&] { this->Relations = SavedRelations; });
194 for (
unsigned I = 0, E = TL.
getNumArgs(); I != E; ++I) {
195 if (!TraverseTemplateArgumentLoc(TL.
getArgLoc(I)))
202 bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) {
206 HandleTemplateSpecializationTypeLoc(
212 bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
213 std::vector<const NamedDecl *> Symbols =
214 IndexCtx.getResolver()->resolveDependentNameType(TL.
getTypePtr());
215 if (Symbols.size() != 1)
217 return IndexCtx.handleReference(Symbols[0], TL.
getNameLoc(), Parent,
221 bool TraverseStmt(Stmt *S) {
222 IndexCtx.indexBody(S, Parent, ParentDC);
250 TypeIndexer(*
this, Parent, DC, isBase, isIBType).TraverseTypeLoc(TL);
259 Qualifier.getKind()) {
289 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(D)) {
290 for (
const auto &I : CXXRD->bases()) {
This file provides AST data structures related to concepts.
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc QualifierLoc)
#define TRY_TO(CALL_EXPR)
Defines the clang::TypeLoc interface and its subclasses.
TemplateName getNamedConcept() const
SourceLocation getConceptNameLoc() const
const TypeClass * getTypePtr() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
DeclContext * getDeclContext()
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
TypeSourceInfo * getTypeSourceInfo() const
SourceLocation getTemplateNameLoc() const
SourceLocation getNameLoc() const
SourceLocation getNameLoc() const
This represents a decl that may have a name.
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
NamespaceAndPrefixLoc castAsNamespaceAndPrefix() const
For a nested-name-specifier that refers to a namespace, retrieve the namespace and its prefix.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Type
A type, stored as a Type*.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
ObjCInterfaceDecl * getIFaceDecl() const
SourceLocation getNameLoc() const
ObjCProtocolDecl * getProtocol(unsigned i) const
unsigned getNumProtocols() const
SourceLocation getProtocolLoc(unsigned i) const
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Encodes a location in the source.
Represents the declaration of a struct/union/class/enum.
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
TagDecl * getDecl() const
SourceLocation getNameLoc() const
bool isDefinition() const
True if the tag was defined in this type specifier.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
unsigned getNumArgs() const
TemplateArgumentLoc getArgLoc(unsigned i) const
SourceLocation getTemplateNameLoc() const
Declaration of a template type parameter.
Wrapper for template type parameters.
TemplateTypeParmDecl * getDecl() const
Base wrapper for a particular "section" of type source info.
QualType getType() const
Get the type for which this source info wrapper provides information.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
SourceLocation getNameLoc() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations={})
bool shouldIndex(const Decl *D)
bool indexDeclContext(const DeclContext *DC)
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations={}, const Expr *RefE=nullptr)
void indexTagDecl(const TagDecl *D, ArrayRef< SymbolRelation > Relations={})
bool shouldIndexFunctionLocalSymbols() const
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, const DeclContext *DC=nullptr)
void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
bool isFunctionLocalSymbol(const Decl *D)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.