13 using namespace clang;
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) {
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())
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()) {
290 ParentDC, Roles, Relations, E);
313 addCallRole(Roles, Relations);
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);
390 bool TraverseInitListExpr(
InitListExpr *S, DataRecursionQueue *Q =
nullptr) {
393 if (!TraverseStmt(SubStmt, Q))
401 if (D.isFieldDesignator())
416 if (
auto *DIE = dyn_cast<DesignatedInitExpr>(init))
417 visitSyntacticDesignatedInitExpr(DIE);
420 return visitForm(SemaForm);
425 return visitForm(SyntaxForm);
452 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.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
ObjCProtocolDecl * getProtocol() const
Stmt - This represents one statement.
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
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.
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
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.
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
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...
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()
Expr - This represents one expression.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
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.
Encodes a location in the source.
DeclarationName getName() const
getName - Returns the embedded declaration name.
SourceLocation getLocStart() const LLVM_READONLY
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.
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.
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...
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, const DeclContext *DC=nullptr)
SourceLocation getLocation() const
SourceLocation getLocStart() const LLVM_READONLY
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
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).
SourceLocation getLocEnd() const LLVM_READONLY
InitListExpr * getSyntacticForm() const
InitListExpr * getSemanticForm() const
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.