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 VisitTypedefTypeLoc(TypedefTypeLoc TL) {
62 TypedefNameDecl *ND = TL.
getDecl();
65 return IndexCtx.handleReference(Underlying, Loc, Parent,
69 TRY_TO(IndexCtx.handleReference(ND, Loc,
72 TRY_TO(IndexCtx.handleReference(CD, Loc, Parent, ParentDC,
73 (
unsigned)SymbolRole::Implicit,
77 TRY_TO(IndexCtx.handleReference(ND, Loc,
84 bool VisitAutoTypeLoc(AutoTypeLoc TL) {
91 bool traverseParamVarHelper(ParmVarDecl *D) {
98 bool TraverseParmVarDecl(ParmVarDecl *D) {
106 if (FD->isThisDeclarationADefinition()) {
107 return traverseParamVarHelper(D);
111 return base::TraverseParmVarDecl(D);
115 IndexCtx.indexNestedNameSpecifierLoc(NNS, Parent, ParentDC);
119 bool VisitTagTypeLoc(TagTypeLoc TL) {
121 if (!IndexCtx.shouldIndexFunctionLocalSymbols() &&
126 IndexCtx.indexTagDecl(D);
130 return IndexCtx.handleReference(D, TL.
getNameLoc(),
135 bool VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
140 bool VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
148 void HandleTemplateSpecializationTypeLoc(
TemplateName TemplName,
149 SourceLocation TemplNameLoc,
150 CXXRecordDecl *ResolvedClass,
154 if (!IsTypeAlias && ResolvedClass &&
156 IndexCtx.shouldIndexImplicitInstantiation())) {
157 IndexCtx.handleReference(ResolvedClass, TemplNameLoc, Parent, ParentDC,
160 IndexCtx.handleReference(D, TemplNameLoc, Parent, ParentDC,
165 bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
169 HandleTemplateSpecializationTypeLoc(
175 bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL,
176 bool TraverseQualifier) {
177 if (!WalkUpFromTemplateSpecializationTypeLoc(TL))
179 if (!TraverseTemplateName(TL.
getTypePtr()->getTemplateName()))
184 SmallVector<SymbolRelation, 3> SavedRelations = Relations;
186 auto ResetSavedRelations =
187 llvm::make_scope_exit([&] { this->Relations = SavedRelations; });
188 for (
unsigned I = 0, E = TL.
getNumArgs(); I != E; ++I) {
189 if (!TraverseTemplateArgumentLoc(TL.
getArgLoc(I)))
196 bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) {
200 HandleTemplateSpecializationTypeLoc(
206 bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
207 std::vector<const NamedDecl *> Symbols =
208 IndexCtx.getResolver()->resolveDependentNameType(TL.
getTypePtr());
209 if (Symbols.size() != 1)
211 return IndexCtx.handleReference(Symbols[0], TL.
getNameLoc(), Parent,
215 bool TraverseStmt(Stmt *S) {
216 IndexCtx.indexBody(S, Parent, ParentDC);
244 TypeIndexer(*
this, Parent, DC, isBase, isIBType).TraverseTypeLoc(TL);
253 Qualifier.getKind()) {
283 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(D)) {
284 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.
SourceLocation getConceptNameLoc() const
TemplateDecl * getNamedConcept() 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...
SourceLocation getNameLoc() const
TagDecl * getOriginalDecl() 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...
TagDecl * castAsTagDecl() const
QualType getUnderlyingType() const
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type,...
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)
The JSON file list parser is used to communicate input to InstallAPI.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
const FunctionProtoType * T