clang: lib/Index/IndexTypeSourceInfo.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
14#include "llvm/ADT/ScopeExit.h"
15
16using namespace clang;
17using namespace index;
18
19namespace {
20
25 bool IsBase;
27
29
30public:
32 const DeclContext *DC, bool isBase, bool isIBType)
33 : IndexCtx(indexCtx), Parent(parent), ParentDC(DC), IsBase(isBase) {
34 if (IsBase) {
35 assert(Parent);
36 Relations.emplace_back((unsigned)SymbolRole::RelationBaseOf, Parent);
37 }
38 if (isIBType) {
39 assert(Parent);
40 Relations.emplace_back((unsigned)SymbolRole::RelationIBTypeOf, Parent);
41 }
42 }
43
45
46#define TRY_TO(CALL_EXPR) \
47 do { \
48 if (!CALL_EXPR) \
49 return false; \
50 } while (0)
51
57 }
58
66 }
67 if (IsBase) {
72 (unsigned)SymbolRole::Implicit,
73 Relations));
74 }
75 } else {
78 Relations));
79 }
80 return true;
81 }
82
86 ParentDC);
87 return true;
88 }
89
92 if (D->getTypeSourceInfo())
94 return true;
95 }
96
98
99
100
101
102
103
104 if (auto FD = dyn_cast(D->getDeclContext())) {
105 if (FD->isThisDeclarationADefinition()) {
106 return traverseParamVarHelper(D);
107 }
108 }
109
110 return base::TraverseParmVarDecl(D);
111 }
112
115 return true;
116 }
117
118 bool VisitTagTypeLoc(TagTypeLoc TL) {
122 return true;
123
126 return true;
127 }
128
131 Relations);
132 }
133
137 }
138
140 for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) {
143 }
144 return true;
145 }
146
147 void HandleTemplateSpecializationTypeLoc(TemplateName TemplName,
150 bool IsTypeAlias) {
151
152
153 if (!IsTypeAlias && ResolvedClass &&
156 IndexCtx.handleReference(ResolvedClass, TemplNameLoc, Parent, ParentDC,
161 }
162 }
163
166 if ()
167 return true;
168 HandleTemplateSpecializationTypeLoc(
170 T->isTypeAlias());
171 return true;
172 }
173
175 if (!WalkUpFromTemplateSpecializationTypeLoc(TL))
176 return false;
178 return false;
179
180
181
183 Relations.clear();
184 auto ResetSavedRelations =
185 llvm::make_scope_exit([&] { this->Relations = SavedRelations; });
186 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
188 return false;
189 }
190
191 return true;
192 }
193
196 if ()
197 return true;
198 HandleTemplateSpecializationTypeLoc(
200 false);
201 return true;
202 }
203
207 }
208
213 if ()
214 return true;
217 if (!TST)
218 return true;
222 if (!TD)
223 return true;
226 return true;
230 Name, [](const NamedDecl *ND) { return isa(ND); });
231 if (Symbols.size() != 1)
232 return true;
235 }
236
238 IndexCtx.indexBody(S, Parent, ParentDC);
239 return true;
240 }
241};
242
243}
244
248 bool isBase,
249 bool isIBType) {
251 return;
252
254}
255
259 bool isBase,
260 bool isIBType) {
262 return;
263
264 if (!DC)
265 DC = Parent->getLexicalDeclContext();
266 TypeIndexer(*this, Parent, DC, isBase, isIBType).TraverseTypeLoc(TL);
267}
268
272 if (!NNS)
273 return;
274
277
278 if (!DC)
279 DC = Parent->getLexicalDeclContext();
281
286 break;
287
291 break;
295 break;
296
300 break;
301 }
302}
303
307 return;
309 return;
310
312 if (D->isThisDeclarationADefinition()) {
314 if (auto CXXRD = dyn_cast(D)) {
315 for (const auto &I : CXXRD->bases()) {
316 indexTypeSourceInfo(I.getTypeSourceInfo(), CXXRD, CXXRD, true);
317 }
318 }
320 }
321 }
322}
This file provides AST data structures related to concepts.
#define TRY_TO(CALL_EXPR)
Defines the clang::TypeLoc interface and its subclasses.
ConceptDecl * getNamedConcept() const
SourceLocation getConceptNameLoc() const
Represents a C++ struct/union/class.
CXXRecordDecl * getDefinition() const
bool hasDefinition() const
std::vector< const NamedDecl * > lookupDependentName(DeclarationName Name, llvm::function_ref< bool(const NamedDecl *ND)> Filter)
Performs an imprecise lookup of a dependent name in this class.
Declaration of a class template.
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
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()
The name of a declaration.
SourceLocation getTemplateNameLoc() const
SourceLocation getNameLoc() const
Represents a qualified type name for which the type name is dependent.
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
const IdentifierInfo * getIdentifier() const
Retrieve the identifier that terminates this type name.
const TypeClass * getTypePtr() const
Wrapper for source info for injected class names of class templates.
CXXRecordDecl * getDecl() const
This represents a decl that may have a name.
A C++ nested-name-specifier augmented with source location information.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
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::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
Wrapper for source info for ObjC interfaces.
ObjCInterfaceDecl * getIFaceDecl() const
SourceLocation getNameLoc() const
ObjCProtocolDecl * getProtocol(unsigned i) const
unsigned getNumProtocols() const
SourceLocation getProtocolLoc(unsigned i) const
Represents a parameter to a function.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue=nullptr)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc)
Recursively visit a template argument location and dispatch to the appropriate method for the argumen...
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Recursively visit a C++ nested-name-specifier with location information.
bool TraverseTemplateName(TemplateName Template)
Recursively visit a template name and dispatch to the appropriate method.
bool TraverseTypeLoc(TypeLoc TL)
Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument ty...
bool shouldWalkTypesOfTypeLocs() const
Return whether this visitor should recurse into the types of TypeLocs.
Encodes a location in the source.
Stmt - This represents one statement.
Represents the declaration of a struct/union/class/enum.
Wrapper for source info for tag types.
TagDecl * getDecl() const
bool isDefinition() const
True if the tag was defined in this type specifier.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
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
Represents a type template specialization; the template must be a class template, a type alias templa...
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
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
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
const T * getAs() const
Member-template getAs'.
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Base class for declarations which introduce a typedef-name.
QualType getUnderlyingType() const
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type,...
Wrapper for source info for typedefs.
TypedefNameDecl * getTypedefNameDecl() const
bool shouldIndexImplicitInstantiation() const
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 indexBody(const Stmt *S, const NamedDecl *Parent, const DeclContext *DC=nullptr)
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.
const FunctionProtoType * T