14 using namespace clang;
15 using namespace index;
17 #define TRY_TO(CALL_EXPR) \
25 class IndexingDeclVisitor :
public ConstDeclVisitor<IndexingDeclVisitor, bool> {
30 : IndexCtx(indexCtx) { }
34 bool VisitDecl(
const Decl *D) {
50 if (!Parent) Parent = D;
54 if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
57 if (
const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
58 auto *DC = Parm->getDeclContext();
59 if (
auto *FD = dyn_cast<FunctionDecl>(DC)) {
60 if (FD->isThisDeclarationADefinition())
61 IndexCtx.handleDecl(Parm);
62 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(DC)) {
63 if (MD->isThisDeclarationADefinition())
64 IndexCtx.handleDecl(Parm);
66 IndexCtx.handleDecl(Parm);
68 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
69 if (FD->isThisDeclarationADefinition()) {
70 for (
auto PI : FD->parameters()) {
71 IndexCtx.handleDecl(PI);
83 handleDeclarator(
I, D);
88 IndexCtx.indexBody(Body, D, D);
100 if (
auto *CXXMD = dyn_cast<CXXMethodDecl>(D)) {
101 if (CXXMD->isVirtual())
103 for (
auto I = CXXMD->begin_overridden_methods(),
104 E = CXXMD->end_overridden_methods();
I !=
E; ++
I) {
109 if (!IndexCtx.handleDecl(D, Roles, Relations))
115 for (
const auto *Init : Ctor->inits()) {
116 if (Init->isWritten()) {
117 IndexCtx.indexTypeSourceInfo(Init->getTypeSourceInfo(), D);
118 if (
const FieldDecl *Member = Init->getAnyMember())
119 IndexCtx.handleReference(Member, Init->getMemberLocation(), D, D,
121 IndexCtx.indexBody(Init->getInit(), D, D);
129 IndexCtx.indexBody(Body, D, D);
135 bool VisitVarDecl(
const VarDecl *D) {
136 if (!IndexCtx.handleDecl(D))
139 IndexCtx.indexBody(D->
getInit(), D);
143 bool VisitFieldDecl(
const FieldDecl *D) {
144 if (!IndexCtx.handleDecl(D))
161 return IndexCtx.handleDecl(D,
162 cast<Decl>(D->getDeclContext())->getLocation(),
165 if (!IndexCtx.handleDecl(D))
177 if (!IndexCtx.handleDecl(D))
184 if (!IndexCtx.handleDecl(D))
190 bool VisitTagDecl(
const TagDecl *D) {
194 IndexCtx.indexTagDecl(D);
196 auto *Parent = dyn_cast<
NamedDecl>(D->getDeclContext());
197 return IndexCtx.handleReference(D, D->getLocation(), Parent,
198 D->getLexicalDeclContext(),
209 I = ProtList.
begin(),
E = ProtList.
end();
I !=
E; ++
I, ++LI) {
212 TRY_TO(IndexCtx.handleReference(PD, Loc, ContD, ContD,
221 TRY_TO(IndexCtx.handleDecl(D));
227 TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D));
228 TRY_TO(IndexCtx.indexDeclContext(D));
230 return IndexCtx.handleReference(D, D->getLocation(),
nullptr,
238 TRY_TO(IndexCtx.handleDecl(D));
240 TRY_TO(IndexCtx.indexDeclContext(D));
242 return IndexCtx.handleReference(D, D->getLocation(),
nullptr,
254 IndexCtx.handleDecl(Class);
256 if (!IndexCtx.handleDecl(D))
261 for (
const auto *IvarI : D->
ivars())
262 IndexCtx.indexDecl(IvarI);
263 for (
const auto *
I : D->
decls()) {
264 if (!isa<ObjCIvarDecl>(
I))
265 IndexCtx.indexDecl(
I);
272 if (!IndexCtx.handleDecl(D))
274 IndexCtx.indexDeclContext(D);
283 if (!IndexCtx.handleDecl(D))
285 IndexCtx.indexDeclContext(D);
301 if (MD->getLexicalDeclContext() == D->getLexicalDeclContext())
302 handleObjCMethod(MD);
304 if (MD->getLexicalDeclContext() == D->getLexicalDeclContext())
305 handleObjCMethod(MD);
306 if (!IndexCtx.handleDecl(D))
314 if (!IndexCtx.handleReference(PD, D->getLocation(),
315 cast<NamedDecl>(D->getDeclContext()),
325 if (!IvarD->getSynthesize())
330 auto *ImplD = cast<ObjCImplDecl>(D->getDeclContext());
332 if (MD->isPropertyAccessor() &&
333 !hasUserDefined(MD, ImplD))
334 IndexCtx.handleDecl(MD, D->getLocation(),
SymbolRoleSet(), {}, ImplD);
337 if (MD->isPropertyAccessor() &&
338 !hasUserDefined(MD, ImplD))
339 IndexCtx.handleDecl(MD, D->getLocation(),
SymbolRoleSet(), {}, ImplD);
345 if (!IndexCtx.handleDecl(D))
347 IndexCtx.indexDeclContext(D);
351 bool VisitUsingDecl(
const UsingDecl *D) {
352 const DeclContext *DC = D->getDeclContext()->getRedeclContext();
356 D->getLexicalDeclContext());
358 IndexCtx.handleReference(
I->getUnderlyingDecl(), D->getLocation(), Parent,
364 const DeclContext *DC = D->getDeclContext()->getRedeclContext();
368 D->getLexicalDeclContext());
370 D->getLocation(), Parent,
371 D->getLexicalDeclContext(),
375 bool VisitClassTemplateSpecializationDecl(
const
380 IndexCtx.indexTagDecl(D);
397 if (isa<ClassTemplateDecl>(ND) && D->getDeclContext()->isDependentContext())
402 IndexCtx.indexTypeSourceInfo(Ty, cast<NamedDecl>(D->getDeclContext()));
408 return IndexCtx.importedModule(D);
415 if (D->isImplicit() && shouldIgnoreIfImplicit(D))
418 if (isTemplateImplicitInstantiation(D))
421 IndexingDeclVisitor Visitor(*
this);
422 bool ShouldContinue = Visitor.Visit(D);
426 if (!Visitor.Handled && isa<DeclContext>(D))
427 return indexDeclContext(cast<DeclContext>(D));
433 for (
const auto *
I : DC->
decls())
440 if (D->getLocation().isInvalid())
443 if (isa<ObjCMethodDecl>(D))
451 if (!indexTopLevelDecl(*
I))
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Represents a relation to another symbol for a symbol occurrence.
bool isBitField() const
Determines whether this field is a bitfield.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
const Expr * getInitExpr() const
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
EnumConstantDecl - An instance of this object exists for each enum constant that is defined...
bool indexTopLevelDecl(const Decl *D)
const Expr * getInit() const
NamespaceDecl - Represent a C++ namespace.
Represents a C++ constructor within a class.
Expr * getInClassInitializer() const
getInClassInitializer - Get the C++11 in-class initializer for this member, or null if one has not be...
ObjCMethodDecl * getMethod(Selector Sel, bool isInstance, bool AllowHidden=false) const
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
TRY_TO(TraverseType(T->getPointeeType()))
VarDecl - An instance of this class is created to represent a variable declaration or definition...
ObjCMethodDecl - Represents an instance or class method declaration.
ParmVarDecl - Represents a parameter to a function.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
TypeSourceInfo * getTypeSourceInfo() const
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Kind getPropertyImplementation() const
ObjCProtocolList::iterator protocol_iterator
Represents a class template specialization, which refers to a class template with a given set of temp...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
bool isThisDeclarationADefinition() const
isThisDeclarationADefinition() - Return true if this declaration is a completion definition of the ty...
Represents a C++ using-declaration.
bool isThisDeclarationADefinition() const
Returns whether this specific method is a definition.
ObjCContainerDecl - Represents a container for method declarations.
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
NamedDecl * getNominatedNamespaceAsWritten()
bool indexDecl(const Decl *D)
Represents an Objective-C protocol declaration.
Represents an ObjC class declaration.
detail::InMemoryDirectory::const_iterator I
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Represents a ValueDecl that came out of a declarator.
bool isDeleted() const
Whether this function has been deleted.
ObjCIvarDecl * getPropertyIvarDecl() const
Expr * getBitWidth() const
bool indexDeclContext(const DeclContext *DC)
bool indexDeclGroupRef(DeclGroupRef DG)
bool isInstanceMethod() const
shadow_range shadows() const
TypeSourceInfo * getTypeSourceInfo() const
TypeSourceInfo * getReturnTypeSourceInfo() const
ObjCCategoryDecl * getCategoryDecl() const
ArrayRef< ParmVarDecl * > parameters() const
Stmt * getBody(const FunctionDecl *&Definition) const
getBody - Retrieve the body (definition) of the function.
Encodes a location in the source.
TagDecl - Represents the declaration of a struct/union/class/enum.
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
bool getSynthesize() const
ObjCCategoryDecl - Represents a category declaration.
const ObjCInterfaceDecl * getClassInterface() const
bool isPropertyAccessor() const
Represents one property declaration in an Objective-C interface.
loc_iterator loc_begin() const
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Base class for declarations which introduce a typedef-name.
const ObjCProtocolList & getReferencedProtocols() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
The base class of all kinds of template declarations (e.g., class, function, etc.).
bool isFreeStanding() const
SourceLocation getPropertyIvarDeclLoc() const
bool isThisDeclarationADefinition() const
isThisDeclarationADefinition - Returns whether this specific declaration of the function is also a de...
Selector getSelector() const
detail::InMemoryDirectory::const_iterator E
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
ObjCMethodDecl * getGetterMethodDecl() const
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
ObjCMethodDecl * getSetterMethodDecl() const
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
A list of Objective-C protocols, along with the source locations at which they were referenced...
ObjCPropertyDecl * getPropertyDecl() const
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node...
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCInterfaceDecl * getSuperClass() const
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
An instance of this class represents the declaration of a property member.
NamedDecl - This represents a decl with a name.
Represents C++ using-directive.
TypeSourceInfo * getTypeSourceInfo() const
A simple visitor class that helps create declaration visitors.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
bool hasInClassInitializer() const
hasInClassInitializer - Determine whether this member has a C++11 in-class initializer.