14 using namespace clang;
27 Stmt *getParentStmt()
const {
28 return StmtStack.size() < 2 ? nullptr : StmtStack.end()[-2];
33 : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { }
35 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
37 bool dataTraverseStmtPre(
Stmt *S) {
38 StmtStack.push_back(S);
42 bool dataTraverseStmtPost(
Stmt *S) {
43 assert(StmtStack.back() == S);
48 bool TraverseTypeLoc(
TypeLoc TL) {
61 assert(!StmtStack.empty() && E == StmtStack.back());
62 if (StmtStack.size() == 1)
64 auto It = StmtStack.end()-2;
65 while (isa<CastExpr>(*It) || isa<ParenExpr>(*It)) {
66 if (
auto ICE = dyn_cast<ImplicitCastExpr>(*It)) {
67 if (ICE->getCastKind() == CK_LValueToRValue)
70 if (It == StmtStack.begin())
74 const Stmt *Parent = *It;
76 if (
auto BO = dyn_cast<BinaryOperator>(Parent)) {
77 if (BO->getOpcode() == BO_Assign && BO->getLHS()->IgnoreParenCasts() == E)
80 }
else if (
auto UO = dyn_cast<UnaryOperator>(Parent)) {
81 if (UO->isIncrementDecrementOp()) {
84 }
else if (UO->getOpcode() == UO_AddrOf) {
88 }
else if (
auto CA = dyn_cast<CompoundAssignOperator>(Parent)) {
89 if (CA->getLHS()->IgnoreParenCasts() == E) {
94 }
else if (
auto CE = dyn_cast<CallExpr>(Parent)) {
95 if (CE->getCallee()->IgnoreParenCasts() == E) {
96 addCallRole(Roles, Relations);
97 if (
auto *ME = dyn_cast<MemberExpr>(E)) {
98 if (
auto *CXXMD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl()))
99 if (CXXMD->isVirtual() && !ME->hasQualifier()) {
101 auto BaseTy = ME->getBase()->IgnoreImpCasts()->getType();
102 if (!BaseTy.isNull())
103 if (
auto *CXXRD = BaseTy->getPointeeCXXRecordDecl())
108 }
else if (
auto CXXOp = dyn_cast<CXXOperatorCallExpr>(CE)) {
109 if (CXXOp->getNumArgs() > 0 && CXXOp->getArg(0)->IgnoreParenCasts() == E) {
111 if (Op == OO_Equal) {
113 }
else if ((Op >= OO_PlusEqual && Op <= OO_PipeEqual) ||
114 Op == OO_LessLessEqual || Op == OO_GreaterGreaterEqual ||
115 Op == OO_PlusPlus || Op == OO_MinusMinus) {
118 }
else if (Op == OO_Amp) {
131 if (
auto *FD = dyn_cast<FunctionDecl>(ParentDC))
133 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(ParentDC))
134 Relations.emplace_back((
unsigned)SymbolRole::RelationCalledBy, MD);
141 Parent, ParentDC, Roles, Relations, E);
151 Parent, ParentDC, Roles, Relations, E);
154 bool indexDependentReference(
172 std::vector<const NamedDecl *> Symbols =
175 if (Symbols.size() != 1)
182 return IndexCtx.
handleReference(Symbols[0], Loc, Parent, ParentDC, Roles,
188 return indexDependentReference(
190 [](
const NamedDecl *D) {
return D->isCXXInstanceMember(); });
196 return indexDependentReference(
198 [](
const NamedDecl *D) {
return !D->isCXXInstanceMember(); });
203 if (D.isFieldDesignator() && D.getField())
214 Parent, ParentDC, Roles, Relations, E);
221 if (
auto *RecE = dyn_cast<ObjCMessageExpr>(
222 MsgE->getInstanceReceiver()->IgnoreParenCasts())) {
223 if (RecE->getMethodFamily() ==
OMF_alloc)
232 addCallRole(Roles, Relations);
233 Stmt *Containing = getParentStmt();
236 const auto *E = POE->getSyntacticForm();
237 if (
const auto *BinOp = dyn_cast<BinaryOperator>(E))
242 if (PRE->isExplicitProperty())
244 if (
const ObjCMethodDecl *Getter = PRE->getImplicitPropertyGetter()) {
248 if (Getter->isClassMethod() &&
249 Getter->getCanonicalDecl()->findPropertyDecl())
254 bool IsPropCall = Containing && isa<PseudoObjectExpr>(Containing);
258 IsImplicitProperty(cast<PseudoObjectExpr>(Containing))))
267 if (
const auto *clsD = Ty->getInterface()) {
271 for (
const auto *protD : Ty->quals()) {
278 addReceivers(Ptr->getObjectType());
284 Parent, ParentDC, Roles, Relations, E);
297 Parent, ParentDC, Roles, Relations, E);
302 if (Getter->isClassMethod()) {
303 if (
const auto *PD = Getter->getCanonicalDecl()->findPropertyDecl()) {
307 ParentDC, Roles, Relations, E);
330 addCallRole(Roles, Relations);
333 Roles, Relations, E);
338 return passObjCLiteralMethodCall(MD, E);
345 return passObjCLiteralMethodCall(MD, E);
352 return passObjCLiteralMethodCall(MD, E);
360 addCallRole(Roles, Relations);
362 Parent, ParentDC, Roles, Relations, E);
366 DataRecursionQueue *Q =
nullptr) {
369 return base::TraverseCXXOperatorCallExpr(E, Q);
407 bool TraverseInitListExpr(
InitListExpr *S, DataRecursionQueue *Q =
nullptr) {
410 if (!TraverseStmt(SubStmt, Q))
418 if (D.isFieldDesignator())
433 if (
auto *DIE = dyn_cast<DesignatedInitExpr>(init))
434 visitSyntacticDesignatedInitExpr(DIE);
437 return visitForm(SemaForm);
442 return visitForm(SyntaxForm);
479 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.
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
The receiver is an object instance.
A (possibly-)qualified type.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
ObjCProtocolDecl * getProtocol() const
Stmt - This represents one statement.
void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
Decl - This represents one declaration (or definition), e.g.
The base class of the type hierarchy.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies this declaration.
bool indexTopLevelDecl(const Decl *D)
bool isSemanticForm() const
Represents a call to a C++ constructor.
Describes the capture of a variable or of this, or of a C++1y init-capture.
This file provides some common utility functions for processing Lambda related AST Constructs...
QualType getBaseType() const
const T * getAs() const
Member-template getAs<specific type>'.
ObjCInterfaceDecl * getClassReceiver() const
ObjCMethodDecl - Represents an instance or class method declaration.
bool hasDefinition() const
Represents a parameter to a function.
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.
ObjCPropertyDecl * getExplicitProperty() const
Base wrapper for a particular "section" of type source info.
Represents a C99 designated initializer expression.
FieldDecl * getField() const
For a field offsetof node, returns the field.
Represents a class type in Objective C.
A C++ nested-name-specifier augmented with source location information.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
bool isExplicitProperty() const
SourceLocation getBeginLoc() const LLVM_READONLY
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
bool isFunctionLocalSymbol(const Decl *D)
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const
Check if the specified ScheduleKind is dynamic.
const DeclGroupRef getDeclGroup() const
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp, [NSNumber numberWithInt:42]];.
Describes an C or C++ initializer list.
bool capturesThis() const
Determine whether this capture handles the C++ this pointer.
bool isClassReceiver() const
bool shouldIndexFunctionLocalSymbols() const
Helper class for OffsetOfExpr.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
ObjCMethodDecl * getArrayWithObjectsMethod() const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Represents a C++ member access expression where the actual member referenced could not be resolved be...
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ObjCMethodDecl * getDictWithObjectsMethod() const
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
SourceLocation getLocation() const
SourceLocation getLocation() const
ObjCMethodDecl * getBoxingMethod() const
llvm::MutableArrayRef< Designator > designators()
This represents one expression.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
DeclContext * getDeclContext()
CXXRecordDecl * getDefinition() const
bool indexDeclGroupRef(DeclGroupRef DG)
Represents a C++ template name within the type system.
ArrayRef< Expr * > inits()
Kind getKind() const
Determine what kind of offsetof node this is.
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)
An expression that sends a message to the given Objective-C object or class.
ObjCMethodDecl * getImplicitPropertyGetter() const
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'...
A member reference to an MSPropertyDecl.
const OffsetOfNode & getComponent(unsigned Idx) const
SourceLocation getOperatorLoc() const
Returns the location of the operator symbol in the expression.
bool capturesVariable() const
Determine whether this capture handles a variable.
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
SourceLocation getProtocolIdLoc() const
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
SourceLocation getEndLoc() const LLVM_READONLY
Encodes a location in the source.
DeclarationName getName() const
getName - Returns the embedded declaration name.
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
ObjCProtocolExpr used for protocol expression in Objective-C.
QualType getReceiverType() const
Retrieve the receiver type to which this message is being directed.
bool isImplicit() const
Indicates whether the message send was implicitly generated by the implementation.
const ObjCMethodDecl * getMethodDecl() const
ObjCBoxedExpr - used for generalized expression boxing.
A qualified reference to a name whose declaration cannot yet be resolved.
SourceLocation getMemberLoc() const
Dataflow Directional Tag Classes.
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...
SourceLocation getLocation() const
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
MSPropertyDecl * getPropertyDecl() const
bool capturesVLAType() const
Determine whether this captures a variable length array bound expression.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Represents a pointer to an Objective C object.
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, const DeclContext *DC=nullptr)
SourceLocation getLocation() const
const Type * getTypePtrOrNull() 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.
SourceLocation getSelectorStartLoc() const
Declaration of a class template.
SourceLocation getLocation() const
Retrieve the source location of the capture.
unsigned getNumComponents() const
SourceLocation getBeginLoc() const LLVM_READONLY
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...
SourceLocation getReceiverLocation() const
void indexBody(const Stmt *S, const NamedDecl *Parent, const DeclContext *DC=nullptr)
This represents a decl that may have a name.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type, member-designator).
InitListExpr * getSyntacticForm() const
InitListExpr * getSemanticForm() const
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.