13 using namespace clang;
14 using namespace clang::index;
28 : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { }
30 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
32 bool dataTraverseStmtPre(
Stmt *
S) {
33 StmtStack.push_back(S);
37 bool dataTraverseStmtPost(
Stmt *S) {
38 assert(StmtStack.back() ==
S);
43 bool TraverseTypeLoc(
TypeLoc TL) {
44 IndexCtx.indexTypeLoc(TL, Parent, ParentDC);
49 IndexCtx.indexNestedNameSpecifierLoc(NNS, Parent, ParentDC);
56 assert(!StmtStack.empty() && E == StmtStack.back());
57 if (StmtStack.size() == 1)
59 auto It = StmtStack.end()-2;
60 while (isa<CastExpr>(*It) || isa<ParenExpr>(*It)) {
61 if (
auto ICE = dyn_cast<ImplicitCastExpr>(*It)) {
62 if (ICE->getCastKind() == CK_LValueToRValue)
65 if (It == StmtStack.begin())
69 const Stmt *Parent = *It;
71 if (
auto BO = dyn_cast<BinaryOperator>(Parent)) {
72 if (BO->getOpcode() == BO_Assign && BO->getLHS()->IgnoreParenCasts() ==
E)
75 }
else if (
auto UO = dyn_cast<UnaryOperator>(Parent)) {
76 if (UO->isIncrementDecrementOp()) {
79 }
else if (UO->getOpcode() == UO_AddrOf) {
83 }
else if (
auto CA = dyn_cast<CompoundAssignOperator>(Parent)) {
84 if (CA->getLHS()->IgnoreParenCasts() ==
E) {
89 }
else if (
auto CE = dyn_cast<CallExpr>(Parent)) {
90 if (CE->getCallee()->IgnoreParenCasts() ==
E) {
91 addCallRole(Roles, Relations);
92 if (
auto *ME = dyn_cast<MemberExpr>(E)) {
93 if (
auto *CXXMD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl()))
94 if (CXXMD->isVirtual() && !ME->hasQualifier()) {
96 auto BaseTy = ME->getBase()->IgnoreImpCasts()->getType();
98 if (
auto *CXXRD = BaseTy->getPointeeCXXRecordDecl())
103 }
else if (
auto CXXOp = dyn_cast<CXXOperatorCallExpr>(CE)) {
104 if (CXXOp->getNumArgs() > 0 && CXXOp->getArg(0)->IgnoreParenCasts() ==
E) {
106 if (Op == OO_Equal) {
108 }
else if ((Op >= OO_PlusEqual && Op <= OO_PipeEqual) ||
109 Op == OO_LessLessEqual || Op == OO_GreaterGreaterEqual ||
110 Op == OO_PlusPlus || Op == OO_MinusMinus) {
113 }
else if (Op == OO_Amp) {
126 if (
auto *FD = dyn_cast<FunctionDecl>(ParentDC))
128 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(ParentDC))
129 Relations.emplace_back((
unsigned)SymbolRole::RelationCalledBy, MD);
136 Parent, ParentDC, Roles, Relations,
E);
146 Parent, ParentDC, Roles, Relations,
E);
151 if (D.isFieldDesignator())
152 return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), Parent,
162 Parent, ParentDC, Roles, Relations,
E);
169 if (
auto *RecE = dyn_cast<ObjCMessageExpr>(
170 MsgE->getInstanceReceiver()->IgnoreParenCasts())) {
171 if (RecE->getMethodFamily() ==
OMF_alloc)
180 addCallRole(Roles, Relations);
191 Parent, ParentDC, Roles, Relations,
E);
219 addCallRole(Roles, Relations);
221 return IndexCtx.handleReference(MD, E->getLocStart(),
222 Parent, ParentDC, Roles, Relations,
E);
227 return passObjCLiteralMethodCall(MD, E);
234 return passObjCLiteralMethodCall(MD, E);
241 return passObjCLiteralMethodCall(MD, E);
249 addCallRole(Roles, Relations);
251 Parent, ParentDC, Roles, Relations,
E);
255 DataRecursionQueue *Q =
nullptr) {
258 return base::TraverseCXXOperatorCallExpr(E, Q);
262 if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
272 if (!IndexCtx.isFunctionLocalDecl(D))
273 IndexCtx.indexTopLevelDecl(D);
295 bool TraverseInitListExpr(
InitListExpr *S, DataRecursionQueue *Q =
nullptr) {
297 class SyntacticFormIndexer :
306 : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { }
308 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
312 if (D.isFieldDesignator())
313 return IndexCtx.handleReference(D.getField(), D.getFieldLoc(),
322 for (
Stmt *SubStmt : Form->children()) {
323 if (!TraverseStmt(SubStmt, Q))
335 SyntacticFormIndexer(IndexCtx, Parent, ParentDC).TraverseStmt(SyntaxForm);
337 return visitForm(SemaForm);
342 return visitForm(SyntaxForm);
357 DC = Parent->getLexicalDeclContext();
358 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
SourceLocation getProtocolIdLoc() const
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
Base wrapper for a particular "section" of type source info.
Represents a C99 designated initializer expression.
ObjCProtocolDecl * getProtocol() const
A C++ nested-name-specifier augmented with source location information.
bool isSemanticForm() 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
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
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...
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
InitListExpr * getSemanticForm() const
SourceLocation getMemberLoc() const
const ObjCMethodDecl * getMethodDecl() const
llvm::MutableArrayRef< Designator > designators()
Expr - This represents one expression.
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.
SourceLocation getLocation() const
An expression that sends a message to the given Objective-C object or class.
A member reference to an MSPropertyDecl.
Encodes a location in the source.
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
ObjCProtocolExpr used for protocol expression in Objective-C.
SourceLocation getSelectorStartLoc() const
ObjCBoxedExpr - used for generalized expression boxing.
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.
ObjCMethodDecl * getArrayWithObjectsMethod() const
detail::InMemoryDirectory::const_iterator E
ObjCMethodDecl * getDictWithObjectsMethod() const
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'...
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.
bool isImplicit() const
Indicates whether the message send was implicitly generated by the implementation.
A reference to a declared variable, function, enum, etc.
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.
bool capturesVariable() const
Determine whether this capture handles a variable.
SourceLocation getLocStart() const LLVM_READONLY