13 using namespace clang;
14 using namespace clang::index;
26 Stmt *getParentStmt()
const {
27 return StmtStack.size() < 2 ?
nullptr : StmtStack.end()[-2];
32 : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { }
34 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
36 bool dataTraverseStmtPre(
Stmt *
S) {
37 StmtStack.push_back(S);
41 bool dataTraverseStmtPost(
Stmt *S) {
42 assert(StmtStack.back() ==
S);
47 bool TraverseTypeLoc(
TypeLoc TL) {
48 IndexCtx.indexTypeLoc(TL, Parent, ParentDC);
53 IndexCtx.indexNestedNameSpecifierLoc(NNS, Parent, ParentDC);
60 assert(!StmtStack.empty() && E == StmtStack.back());
61 if (StmtStack.size() == 1)
63 auto It = StmtStack.end()-2;
64 while (isa<CastExpr>(*It) || isa<ParenExpr>(*It)) {
65 if (
auto ICE = dyn_cast<ImplicitCastExpr>(*It)) {
66 if (ICE->getCastKind() == CK_LValueToRValue)
69 if (It == StmtStack.begin())
73 const Stmt *Parent = *It;
75 if (
auto BO = dyn_cast<BinaryOperator>(Parent)) {
76 if (BO->getOpcode() == BO_Assign && BO->getLHS()->IgnoreParenCasts() ==
E)
79 }
else if (
auto UO = dyn_cast<UnaryOperator>(Parent)) {
80 if (UO->isIncrementDecrementOp()) {
83 }
else if (UO->getOpcode() == UO_AddrOf) {
87 }
else if (
auto CA = dyn_cast<CompoundAssignOperator>(Parent)) {
88 if (CA->getLHS()->IgnoreParenCasts() ==
E) {
93 }
else if (
auto CE = dyn_cast<CallExpr>(Parent)) {
94 if (CE->getCallee()->IgnoreParenCasts() ==
E) {
95 addCallRole(Roles, Relations);
96 if (
auto *ME = dyn_cast<MemberExpr>(E)) {
97 if (
auto *CXXMD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl()))
98 if (CXXMD->isVirtual() && !ME->hasQualifier()) {
100 auto BaseTy = ME->getBase()->IgnoreImpCasts()->getType();
101 if (!BaseTy.isNull())
102 if (
auto *CXXRD = BaseTy->getPointeeCXXRecordDecl())
107 }
else if (
auto CXXOp = dyn_cast<CXXOperatorCallExpr>(CE)) {
108 if (CXXOp->getNumArgs() > 0 && CXXOp->getArg(0)->IgnoreParenCasts() ==
E) {
110 if (Op == OO_Equal) {
112 }
else if ((Op >= OO_PlusEqual && Op <= OO_PipeEqual) ||
113 Op == OO_LessLessEqual || Op == OO_GreaterGreaterEqual ||
114 Op == OO_PlusPlus || Op == OO_MinusMinus) {
117 }
else if (Op == OO_Amp) {
130 if (
auto *FD = dyn_cast<FunctionDecl>(ParentDC))
132 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(ParentDC))
133 Relations.emplace_back((
unsigned)SymbolRole::RelationCalledBy, MD);
140 Parent, ParentDC, Roles, Relations,
E);
150 Parent, ParentDC, Roles, Relations,
E);
153 bool indexDependentReference(
155 llvm::function_ref<
bool(
const NamedDecl *ND)> Filter) {
171 std::vector<const NamedDecl *> Symbols =
174 if (Symbols.size() != 1)
181 return IndexCtx.handleReference(Symbols[0], Loc, Parent, ParentDC, Roles,
187 return indexDependentReference(
189 [](
const NamedDecl *D) {
return D->isCXXInstanceMember(); });
195 return indexDependentReference(
197 [](
const NamedDecl *D) {
return !D->isCXXInstanceMember(); });
202 if (D.isFieldDesignator() && D.getField())
203 return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), Parent,
213 Parent, ParentDC, Roles, Relations,
E);
220 if (
auto *RecE = dyn_cast<ObjCMessageExpr>(
221 MsgE->getInstanceReceiver()->IgnoreParenCasts())) {
222 if (RecE->getMethodFamily() ==
OMF_alloc)
231 addCallRole(Roles, Relations);
232 Stmt *Containing = getParentStmt();
235 const auto *E = POE->getSyntacticForm();
236 if (
const auto *BinOp = dyn_cast<BinaryOperator>(E))
241 if (PRE->isExplicitProperty())
243 if (
const ObjCMethodDecl *Getter = PRE->getImplicitPropertyGetter()) {
247 if (Getter->isClassMethod() &&
248 Getter->getCanonicalDecl()->findPropertyDecl())
253 bool IsPropCall = Containing && isa<PseudoObjectExpr>(Containing);
257 IsImplicitProperty(cast<PseudoObjectExpr>(Containing))))
267 Parent, ParentDC, Roles, Relations,
E);
280 Parent, ParentDC, Roles, Relations,
E);
285 if (Getter->isClassMethod()) {
286 if (
const auto *PD = Getter->getCanonicalDecl()->findPropertyDecl()) {
289 return IndexCtx.handleReference(PD, E->
getLocation(), Parent,
290 ParentDC, Roles, Relations,
E);
313 addCallRole(Roles, Relations);
315 return IndexCtx.handleReference(MD, E->
getLocStart(),
316 Parent, ParentDC, Roles, Relations,
E);
321 return passObjCLiteralMethodCall(MD, E);
328 return passObjCLiteralMethodCall(MD, E);
335 return passObjCLiteralMethodCall(MD, E);
343 addCallRole(Roles, Relations);
345 Parent, ParentDC, Roles, Relations,
E);
349 DataRecursionQueue *Q =
nullptr) {
352 return base::TraverseCXXOperatorCallExpr(E, Q);
356 if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
367 IndexCtx.indexTopLevelDecl(D);
390 bool TraverseInitListExpr(
InitListExpr *S, DataRecursionQueue *Q =
nullptr) {
393 if (!TraverseStmt(SubStmt, Q))
401 if (D.isFieldDesignator())
402 return IndexCtx.handleReference(D.getField(), D.getFieldLoc(),
416 if (
auto *DIE = dyn_cast<DesignatedInitExpr>(init))
417 visitSyntacticDesignatedInitExpr(DIE);
420 return visitForm(SemaForm);
425 return visitForm(SyntaxForm);
441 BodyIndexer(*
this, Parent, DC).TraverseStmt(const_cast<Stmt*>(S));
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
A call to an overloaded operator written using operator syntax.
Represents a single C99 designator.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
The receiver is an object instance.
const DeclGroupRef getDeclGroup() const
SourceLocation getLocation() const
Stmt - This represents one statement.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getProtocolIdLoc() const
bool hasDefinition() const
The base class of the type hierarchy.
InitListExpr * getSyntacticForm() const
Represents a call to a C++ constructor.
Describes the capture of a variable or of this, or of a C++1y init-capture.
bool isExplicitProperty() const
ObjCMethodDecl - Represents an instance or class method declaration.
virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const
Check if the specified ScheduleKind is dynamic.
SourceLocation getOperatorLoc() const
Returns the location of the operator symbol in the expression.
SourceLocation getLocation() const
std::vector< const NamedDecl * > lookupDependentName(const DeclarationName &Name, llvm::function_ref< bool(const NamedDecl *ND)> Filter)
Performs an imprecise lookup of a dependent name in this class.
Base wrapper for a particular "section" of type source info.
Represents a C99 designated initializer expression.
DeclarationName getName() const
getName - Returns the embedded declaration name.
ObjCProtocolDecl * getProtocol() const
A C++ nested-name-specifier augmented with source location information.
ObjCInterfaceDecl * getClassReceiver() const
bool isSemanticForm() const
bool isFunctionLocalSymbol(const Decl *D)
CXXRecordDecl * getDefinition() const
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp, [NSNumber numberWithInt:42]];.
Describes an C or C++ initializer list.
ObjCMethodDecl * getBoxingMethod() const
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies this declaration.
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
bool capturesVLAType() const
Determine whether this captures a variable length array bound expression.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Represents a C++ member access expression where the actual member referenced could not be resolved be...
A class that does preordor or postorder depth-first traversal on the entire Clang AST and visits each...
detail::InMemoryDirectory::const_iterator I
MSPropertyDecl * getPropertyDecl() const
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
SourceLocation getReceiverLocation() const
InitListExpr * getSemanticForm() const
SourceLocation getMemberLoc() const
const ObjCMethodDecl * getMethodDecl() const
const Type * getTypePtrOrNull() const
llvm::MutableArrayRef< Designator > designators()
Expr - This represents one expression.
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
ObjCMethodDecl * getImplicitPropertyGetter() const
SourceLocation getLocation() const
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
SourceLocation getLocation() const
Retrieve the source location of the capture.
Represents a C++ template name within the type system.
ArrayRef< Expr * > inits()
SourceLocation getLocation() const
An expression that sends a message to the given Objective-C object or class.
A member reference to an MSPropertyDecl.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Encodes a location in the source.
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
ObjCProtocolExpr used for protocol expression in Objective-C.
QualType getBaseType() const
SourceLocation getSelectorStartLoc() const
ObjCBoxedExpr - used for generalized expression boxing.
A qualified reference to a name whose declaration cannot yet be resolved.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
bool isClassReceiver() const
ObjCMethodDecl * getArrayWithObjectsMethod() const
detail::InMemoryDirectory::const_iterator E
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
ObjCMethodDecl * getDictWithObjectsMethod() const
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'...
const T * getAs() const
Member-template getAs<specific type>'.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
ObjCPropertyDecl * getExplicitProperty() const
ObjCIvarRefExpr - A reference to an ObjC instance variable.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Represents a C++ struct/union/class.
bool isImplicit() const
Indicates whether the message send was implicitly generated by the implementation.
Declaration of a class template.
A reference to a declared variable, function, enum, etc.
Represents a type template specialization; the template must be a class template, a type alias templa...
bool capturesThis() const
Determine whether this capture handles the C++ this pointer.
void indexBody(const Stmt *S, const NamedDecl *Parent, const DeclContext *DC=nullptr)
NamedDecl - This represents a decl with a name.
SourceLocation getLocStart() const LLVM_READONLY
bool capturesVariable() const
Determine whether this capture handles a variable.
SourceLocation getLocStart() const LLVM_READONLY