14 using namespace clang;
15 using namespace index;
17 #define TRY_DECL(D,CALL_EXPR) \ 19 if (!IndexCtx.shouldIndex(D)) return true; \ 24 #define TRY_TO(CALL_EXPR) \ 32 class IndexingDeclVisitor :
public ConstDeclVisitor<IndexingDeclVisitor, bool> {
37 : IndexCtx(indexCtx) { }
41 bool VisitDecl(
const Decl *D) {
73 if (
const NamedDecl *TTD = TD->getTemplatedDecl())
84 bool isIBType =
false) {
85 if (!Parent) Parent = D;
94 if (
const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
95 auto *DC = Parm->getDeclContext();
96 if (
auto *FD = dyn_cast<FunctionDecl>(DC)) {
97 if (FD->isThisDeclarationADefinition())
99 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(DC)) {
100 if (MD->isThisDeclarationADefinition())
105 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
106 if (FD->isThisDeclarationADefinition()) {
107 for (
auto PI : FD->parameters()) {
114 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
115 if (FD->isThisDeclarationADefinition()) {
116 for (
const auto *PV : FD->parameters()) {
117 if (PV->hasDefaultArg() && !PV->hasUninstantiatedDefaultArg() &&
118 !PV->hasUnparsedDefaultArg())
119 IndexCtx.
indexBody(PV->getDefaultArg(), D);
132 for(
auto overridden: Overriden) {
149 if (AssociatedProp) {
152 AssociatedProp->getGetterNameLoc():
153 AssociatedProp->getSetterNameLoc();
163 }
else if (AttrLoc.
isValid()) {
170 bool hasIBActionAndFirst = D->
hasAttr<IBActionAttr>();
172 handleDeclarator(I, D, hasIBActionAndFirst);
173 hasIBActionAndFirst =
false;
192 gatherTemplatePseudoOverrides(
const NamedDecl *D,
203 if (
const auto *CTD = Template.dyn_cast<ClassTemplateDecl *>()) {
205 bool TypeOverride = isa<TypeDecl>(D);
207 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(ND))
208 ND = CTD->getTemplatedDecl();
209 if (ND->isImplicit())
213 if (ND->getKind() != D->
getKind())
215 }
else if (!isa<TypeDecl>(ND))
217 if (
const auto *FD = dyn_cast<FunctionDecl>(ND)) {
218 const auto *DFD = cast<FunctionDecl>(D);
220 if (FD->getStorageClass() != DFD->getStorageClass() ||
221 FD->getNumParams() != DFD->getNumParams())
224 Relations.emplace_back(
233 if (
auto *CXXMD = dyn_cast<CXXMethodDecl>(D)) {
234 if (CXXMD->isVirtual())
240 gatherTemplatePseudoOverrides(D, Relations);
244 Base->getTemplatedDecl()));
251 Ctor->getParent(), Ctor->getDeclContext());
254 for (
const auto *Init : Ctor->inits()) {
255 if (Init->isWritten()) {
257 if (
const FieldDecl *Member = Init->getAnyMember())
260 IndexCtx.
indexBody(Init->getInit(), D, D);
264 if (
auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) {
266 TypeNameInfo->getTypeLoc().getLocStart(),
267 Dtor->getParent(), Dtor->getDeclContext());
269 }
else if (
const auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
270 IndexCtx.
handleReference(Guide->getDeducedTemplate()->getTemplatedDecl(),
271 Guide->getLocation(), Guide,
272 Guide->getDeclContext());
277 for (
const auto &Arg : TemplateArgInfo->arguments())
290 bool VisitVarDecl(
const VarDecl *D) {
292 gatherTemplatePseudoOverrides(D, Relations);
300 for (
const auto *Binding : D->
bindings())
302 return Base::VisitDecompositionDecl(D);
305 bool VisitFieldDecl(
const FieldDecl *D) {
307 gatherTemplatePseudoOverrides(D, Relations);
341 gatherTemplatePseudoOverrides(D, Relations);
348 bool VisitTagDecl(
const TagDecl *D) {
353 gatherTemplatePseudoOverrides(D, Relations);
357 gatherTemplatePseudoOverrides(D, Relations);
370 I = ProtList.
begin(), E = ProtList.
end(); I != E; ++I, ++LI) {
387 bool hasSuperTypedef =
false;
389 if (
auto *TT = TInfo->getType()->getAs<
TypedefType>()) {
390 if (
auto *TD = TT->getDecl()) {
391 hasSuperTypedef =
true;
440 if (I->getLocation().isInvalid())
443 for (
const auto *I : D->
decls()) {
444 if (!isa<ObjCPropertyImplDecl>(I) ||
445 cast<ObjCPropertyImplDecl>(I)->getLocation().isValid())
463 if (!CategoryLoc.isValid())
464 CategoryLoc = D->getLocation();
466 TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D,
482 CategoryLoc = D->getLocation();
501 handleObjCMethod(MD, D);
504 handleObjCMethod(MD, D);
506 if (IBOutletCollectionAttr *attr = D->
getAttr<IBOutletCollectionAttr>())
521 Relations.push_back({(SymbolRoleSet)SymbolRole::RelationAccessorOf, ID});
522 if (Loc.isInvalid()) {
535 if (MD->isPropertyAccessor() &&
536 !hasUserDefined(MD, Container))
537 IndexCtx.
handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
540 if (MD->isPropertyAccessor() &&
541 !hasUserDefined(MD, Container))
542 IndexCtx.
handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
545 if (IvarD->getSynthesize()) {
583 bool VisitUsingDecl(
const UsingDecl *D) {
589 for (
const auto *I : D->
shadows())
629 bool VisitClassTemplateSpecializationDecl(
const 636 const Decl *SpecializationOf =
637 Template.is<ClassTemplateDecl *>()
638 ? (
Decl *)Template.get<ClassTemplateDecl *>()
651 static bool shouldIndexTemplateParameterDefaultValue(
const NamedDecl *D) {
656 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
657 return FD->getCanonicalDecl() == FD;
658 else if (
const auto *TD = dyn_cast<TagDecl>(D))
659 return TD->getCanonicalDecl() == TD;
660 else if (
const auto *VD = dyn_cast<VarDecl>(D))
661 return VD->getCanonicalDecl() == VD;
670 shouldIndexTemplateParameterDefaultValue(Parent)) {
673 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(TP)) {
674 if (TTP->hasDefaultArgument())
676 }
else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(TP)) {
677 if (NTTP->hasDefaultArgument())
679 }
else if (
const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(TP)) {
680 if (TTPD->hasDefaultArgument())
681 handleTemplateArgumentLoc(TTPD->getDefaultArgument(),
Parent,
682 TP->getLexicalDeclContext());
723 if (D->
isImplicit() && shouldIgnoreIfImplicit(D))
726 if (isTemplateImplicitInstantiation(D))
729 IndexingDeclVisitor Visitor(*
this);
730 bool ShouldContinue = Visitor.Visit(D);
734 if (!Visitor.Handled && isa<DeclContext>(D))
735 return indexDeclContext(cast<DeclContext>(D));
741 for (
const auto *I : DC->
decls())
751 if (isa<ObjCMethodDecl>(D))
759 if (!indexTopLevelDecl(*I))
An instance of this class is created to represent a function declaration or definition.
bool isThisDeclarationADefinition() const
Returns whether this specific method is a definition.
Represents a relation to another symbol for a symbol occurrence.
unsigned param_size() const
ObjCInterfaceDecl * getClassInterface()
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
ObjCIvarDecl * getPropertyIvarDecl() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Stmt - This represents one statement.
Expr * getBitWidth() const
#define TRY_DECL(D, CALL_EXPR)
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
EnumConstantDecl - An instance of this object exists for each enum constant that is defined...
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Decl - This represents one declaration (or definition), e.g.
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
bool indexTopLevelDecl(const Decl *D)
NamespaceDecl - Represent a C++ namespace.
A container of type source information.
Represents a C++ constructor within a class.
const DeclContext * getParentFunctionOrMethod() const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext...
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
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...
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
ObjCMethodDecl - Represents an instance or class method declaration.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Stores a list of template parameters for a TemplateDecl and its derived classes.
ParmVarDecl - Represents a parameter to a function.
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Represents a class template specialization, which refers to a class template with a given set of temp...
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
const LangOptions & getLangOpts() const
const ObjCProtocolList & getReferencedProtocols() const
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
ObjCMethodDecl * getSetterMethodDecl() const
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
loc_iterator loc_begin() const
Represents a C++ using-declaration.
ArrayRef< BindingDecl * > bindings() const
bool isBitField() const
Determines whether this field is a bitfield.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
ObjCContainerDecl - Represents a container for method declarations.
NamedDecl * getNominatedNamespaceAsWritten()
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
bool shouldIndexFunctionLocalSymbols() const
void getOverriddenMethods(SmallVectorImpl< const ObjCMethodDecl *> &Overridden) const
Return overridden methods for the given Method.
bool indexDecl(const Decl *D)
const Expr * getInitExpr() const
SourceLocation getPropertyIvarDeclLoc() const
Represents an Objective-C protocol declaration.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Represents an ObjC class declaration.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Represents a ValueDecl that came out of a declarator.
TypeSourceInfo * getTypeSourceInfo() const
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
TypeSourceInfo * getSuperClassTInfo() const
TypeSourceInfo * getTypeSourceInfo() const
bool indexDeclContext(const DeclContext *DC)
Represents a C++ destructor within a class.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
SourceLocation getSelectorStartLoc() const
overridden_method_range overridden_methods() const
DeclContext * getDeclContext()
ObjCInterfaceDecl * getSuperClass() const
bool indexDeclGroupRef(DeclGroupRef DG)
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this...
propimpl_range property_impls() const
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None, const Expr *RefE=nullptr, const Decl *RefD=nullptr)
bool isInstanceMethod() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Selector getSelector() const
ObjCProtocolList::iterator protocol_iterator
TypeSourceInfo * getAsTypeSourceInfo() const
TypeSourceInfo * getReturnTypeSourceInfo() const
Encodes a location in the source.
bool getSynthesize() const
TagDecl - Represents the declaration of a struct/union/class/enum.
ObjCCategoryDecl * getCategoryDecl() const
Represents a dependent using declaration which was not marked with typename.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Represents a static or instance method of a struct/union/class.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
ObjCCategoryDecl - Represents a category declaration.
Represents one property declaration in an Objective-C interface.
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node...
Represents a C++11 static_assert declaration.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Base class for declarations which introduce a typedef-name.
const ObjCInterfaceDecl * getClassInterface() const
bool shouldIndex(const Decl *D)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
const TemplateArgument & getArgument() const
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None)
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.).
Kind getPropertyImplementation() const
The template argument is a pack expansion of a template name that was provided for a template templat...
const ObjCProtocolList & getReferencedProtocols() const
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
const Expr * getInit() const
A decomposition declaration.
Represents a dependent using declaration which was marked with typename.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
Location wrapper for a TemplateArgument.
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, const DeclContext *DC=nullptr)
void indexTagDecl(const TagDecl *D, ArrayRef< SymbolRelation > Relations=None)
TypeSourceInfo * getTypeSourceInfo() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool importedModule(const ImportDecl *ImportD)
A list of Objective-C protocols, along with the source locations at which they were referenced...
The template argument is a type.
ArgKind getKind() const
Return the kind of stored template argument.
shadow_range shadows() const
bool isThisDeclarationADefinition() const
isThisDeclarationADefinition() - Return true if this declaration is a completion definition of the ty...
Represents a C++ struct/union/class.
The template argument is a template name that was provided for a template template parameter...
TemplateArgumentLocInfo getLocInfo() const
ObjCIvarDecl - Represents an ObjC instance variable.
Location information for a TemplateArgument.
Declaration of a class template.
ObjCPropertyDecl * getPropertyDecl() const
SourceLocation getTemplateNameLoc() const
void indexBody(const Stmt *S, const NamedDecl *Parent, const DeclContext *DC=nullptr)
An instance of this class represents the declaration of a property member.
ObjCMethodDecl * getMethod(Selector Sel, bool isInstance, bool AllowHidden=false) const
ObjCMethodDecl * getGetterMethodDecl() const
NamedDecl - This represents a decl with a name.
Represents a C++ namespace alias.
bool isPropertyAccessor() const
Represents C++ using-directive.
A simple visitor class that helps create declaration visitors.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
bool isFreeStanding() const
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
SourceLocation getLocation() const
ArrayRef< ParmVarDecl * > parameters() const
NamedDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...