30 Stmt *getParentStmt()
const {
31 return StmtStack.size() < 2 ? nullptr : StmtStack.end()[-2];
41 StmtStack.push_back(S);
46 assert(StmtStack.back() == S);
64 assert(!StmtStack.empty() &&
E == StmtStack.back());
65 if (StmtStack.size() == 1)
67 auto It = StmtStack.end()-2;
68 while (isa<CastExpr>(*It) || isa<ParenExpr>(*It)) {
69 if (
auto ICE = dyn_cast<ImplicitCastExpr>(*It)) {
70 if (ICE->getCastKind() == CK_LValueToRValue)
71 Roles |= (
unsigned)(
unsigned)SymbolRole::Read;
73 if (It == StmtStack.begin())
79 if (
auto BO = dyn_cast<BinaryOperator>(Parent)) {
80 if (BO->getOpcode() == BO_Assign) {
81 if (BO->getLHS()->IgnoreParenCasts() ==
E)
82 Roles |= (
unsigned)SymbolRole::Write;
83 }
else if (
auto CA = dyn_cast<CompoundAssignOperator>(Parent)) {
84 if (CA->getLHS()->IgnoreParenCasts() ==
E) {
86 Roles |= (
unsigned)SymbolRole::Write;
89 }
else if (
auto UO = dyn_cast<UnaryOperator>(Parent)) {
90 if (UO->isIncrementDecrementOp()) {
92 Roles |= (
unsigned)SymbolRole::Write;
93 }
else if (UO->getOpcode() == UO_AddrOf) {
94 Roles |= (
unsigned)SymbolRole::AddressOf;
97 }
else if (
auto CE = dyn_cast<CallExpr>(Parent)) {
98 if (CE->getCallee()->IgnoreParenCasts() ==
E) {
99 addCallRole(Roles, Relations);
100 if (
auto *ME = dyn_cast<MemberExpr>(
E)) {
101 if (
auto *CXXMD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl()))
102 if (CXXMD->isVirtual() && !ME->hasQualifier()) {
103 Roles |= (
unsigned)SymbolRole::Dynamic;
104 auto BaseTy = ME->getBase()->IgnoreImpCasts()->getType();
105 if (!BaseTy.isNull())
106 if (
auto *CXXRD = BaseTy->getPointeeCXXRecordDecl())
107 Relations.emplace_back((
unsigned)SymbolRole::RelationReceivedBy,
111 }
else if (
auto CXXOp = dyn_cast<CXXOperatorCallExpr>(CE)) {
112 if (CXXOp->getNumArgs() > 0 && CXXOp->getArg(0)->IgnoreParenCasts() ==
E) {
114 if (Op == OO_Equal) {
115 Roles |= (
unsigned)SymbolRole::Write;
116 }
else if ((Op >= OO_PlusEqual && Op <= OO_PipeEqual) ||
117 Op == OO_LessLessEqual || Op == OO_GreaterGreaterEqual ||
118 Op == OO_PlusPlus || Op == OO_MinusMinus) {
119 Roles |= (
unsigned)SymbolRole::Read;
120 Roles |= (
unsigned)SymbolRole::Write;
121 }
else if (Op == OO_Amp) {
122 Roles |= (
unsigned)SymbolRole::AddressOf;
133 Roles |= (
unsigned)SymbolRole::Call;
134 if (
auto *FD = dyn_cast<FunctionDecl>(ParentDC))
135 Relations.emplace_back((
unsigned)SymbolRole::RelationCalledBy, FD);
136 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(ParentDC))
137 Relations.emplace_back((
unsigned)SymbolRole::RelationCalledBy, MD);
144 Parent, ParentDC, Roles, Relations,
E);
148 return IndexCtx.
handleReference(S->getLabel(), S->getLabelLoc(), Parent,
165 Parent, ParentDC, Roles, Relations,
E);
168 bool indexDependentReference(
170 llvm::function_ref<
bool(
const NamedDecl *ND)> Filter) {