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) {
64 if (
const NamedDecl *TTD = TD->getTemplatedDecl())
86 bool isIBType =
false) {
87 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)) {
98 FD->isThisDeclarationADefinition())
100 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(DC)) {
101 if (MD->isThisDeclarationADefinition())
106 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
108 FD->isThisDeclarationADefinition()) {
109 for (
auto PI : FD->parameters()) {
116 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
117 if (FD->isThisDeclarationADefinition()) {
118 for (
const auto *PV : FD->parameters()) {
119 if (PV->hasDefaultArg() && !PV->hasUninstantiatedDefaultArg() &&
120 !PV->hasUnparsedDefaultArg())
121 IndexCtx.
indexBody(PV->getDefaultArg(), D);
134 for(
auto overridden: Overriden) {
151 if (AssociatedProp) {
154 AssociatedProp->getGetterNameLoc():
155 AssociatedProp->getSetterNameLoc();
165 }
else if (AttrLoc.
isValid()) {
172 bool hasIBActionAndFirst = D->
hasAttr<IBActionAttr>();
174 handleDeclarator(I, D, hasIBActionAndFirst);
175 hasIBActionAndFirst =
false;
194 gatherTemplatePseudoOverrides(
const NamedDecl *D,
205 if (
const auto *CTD = Template.dyn_cast<ClassTemplateDecl *>()) {
207 bool TypeOverride = isa<TypeDecl>(D);
209 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(ND))
210 ND = CTD->getTemplatedDecl();
211 if (ND->isImplicit())
215 if (ND->getKind() != D->
getKind())
217 }
else if (!isa<TypeDecl>(ND))
219 if (
const auto *FD = dyn_cast<FunctionDecl>(ND)) {
220 const auto *DFD = cast<FunctionDecl>(D);
222 if (FD->getStorageClass() != DFD->getStorageClass() ||
223 FD->getNumParams() != DFD->getNumParams())
226 Relations.emplace_back(
235 if (
auto *CXXMD = dyn_cast<CXXMethodDecl>(D)) {
236 if (CXXMD->isVirtual())
242 gatherTemplatePseudoOverrides(D, Relations);
246 Base->getTemplatedDecl()));
253 Ctor->getParent(), Ctor->getDeclContext(),
257 for (
const auto *Init : Ctor->inits()) {
258 if (Init->isWritten()) {
260 if (
const FieldDecl *Member = Init->getAnyMember())
263 IndexCtx.
indexBody(Init->getInit(), D, D);
267 if (
auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) {
269 TypeNameInfo->getTypeLoc().getBeginLoc(),
270 Dtor->getParent(), Dtor->getDeclContext(),
273 }
else if (
const auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
274 IndexCtx.
handleReference(Guide->getDeducedTemplate()->getTemplatedDecl(),
275 Guide->getLocation(), Guide,
276 Guide->getDeclContext());
281 for (
const auto &Arg : TemplateArgInfo->arguments())
294 bool VisitVarDecl(
const VarDecl *D) {
296 gatherTemplatePseudoOverrides(D, Relations);
304 for (
const auto *Binding : D->
bindings())
306 return Base::VisitDecompositionDecl(D);
309 bool VisitFieldDecl(
const FieldDecl *D) {
311 gatherTemplatePseudoOverrides(D, Relations);
346 gatherTemplatePseudoOverrides(D, Relations);
353 bool VisitTagDecl(
const TagDecl *D) {
358 gatherTemplatePseudoOverrides(D, Relations);
362 gatherTemplatePseudoOverrides(D, Relations);
375 I = ProtList.
begin(), E = ProtList.
end(); I != E; ++I, ++LI) {
392 bool hasSuperTypedef =
false;
394 if (
auto *TT = TInfo->getType()->getAs<
TypedefType>()) {
395 if (
auto *TD = TT->getDecl()) {
396 hasSuperTypedef =
true;
445 if (I->getLocation().isInvalid())
448 for (
const auto *I : D->
decls()) {
449 if (!isa<ObjCPropertyImplDecl>(I) ||
450 cast<ObjCPropertyImplDecl>(I)->getLocation().isValid())
468 if (!CategoryLoc.isValid())
469 CategoryLoc = D->getLocation();
471 TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D,
487 CategoryLoc = D->getLocation();
506 handleObjCMethod(MD, D);
509 handleObjCMethod(MD, D);
511 if (IBOutletCollectionAttr *attr = D->
getAttr<IBOutletCollectionAttr>())
526 Relations.push_back({(SymbolRoleSet)SymbolRole::RelationAccessorOf, ID});
527 if (Loc.isInvalid()) {
540 if (MD->isPropertyAccessor() && !hasUserDefined(MD, Container))
541 IndexCtx.
handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
544 if (MD->isPropertyAccessor() && !hasUserDefined(MD, Container))
545 IndexCtx.
handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
548 if (IvarD->getSynthesize()) {
586 bool VisitUsingDecl(
const UsingDecl *D) {
593 for (
const auto *I : D->
shadows())
633 bool VisitClassTemplateSpecializationDecl(
const 640 const Decl *SpecializationOf =
641 Template.is<ClassTemplateDecl *>()
642 ? (
Decl *)Template.get<ClassTemplateDecl *>()
655 static bool shouldIndexTemplateParameterDefaultValue(
const NamedDecl *D) {
660 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
661 return FD->getCanonicalDecl() == FD;
662 else if (
const auto *TD = dyn_cast<TagDecl>(D))
663 return TD->getCanonicalDecl() == TD;
664 else if (
const auto *VD = dyn_cast<VarDecl>(D))
665 return VD->getCanonicalDecl() == VD;
677 shouldIndexTemplateParameterDefaultValue(Parent)) {
682 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(TP)) {
683 if (TTP->hasDefaultArgument())
685 }
else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(TP)) {
686 if (NTTP->hasDefaultArgument())
688 }
else if (
const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(TP)) {
689 if (TTPD->hasDefaultArgument())
690 handleTemplateArgumentLoc(TTPD->getDefaultArgument(),
Parent,
691 TP->getLexicalDeclContext());
696 return Visit(Parent);
732 if (D->
isImplicit() && shouldIgnoreIfImplicit(D))
735 if (isTemplateImplicitInstantiation(D) && !shouldIndexImplicitInstantiation())
738 IndexingDeclVisitor Visitor(*
this);
739 bool ShouldContinue = Visitor.Visit(D);
743 if (!Visitor.Handled && isa<DeclContext>(D))
744 return indexDeclContext(cast<DeclContext>(D));
750 for (
const auto *I : DC->
decls())
760 if (isa<ObjCMethodDecl>(D))
768 if (!indexTopLevelDecl(*I))
Represents 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.
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)
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()))
Represents 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.
Represents a parameter to a function.
DeclarationName getDeclName() const
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...
Represents a member of a struct/union/class.
ObjCMethodDecl * getSetterMethodDecl() const
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
loc_iterator loc_begin() const
bool shouldIndexParametersInDeclarations() const
Represents a C++ using-declaration.
ArrayRef< BindingDecl * > bindings() const
bool isBitField() const
Determines whether this field is a bitfield.
bool shouldIndexTemplateParameters() const
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
bool isSynthesizedAccessorStub() const
Encodes a location in the source.
bool getSynthesize() const
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
Return true if this declaration is a completion definition of the type.
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
This represents a decl that may have 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
True if this tag is free standing, e.g. "struct foo;".
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...