clang: lib/AST/ParentMap.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
17#include "llvm/ADT/DenseMap.h"
18
19using namespace clang;
20
21typedef llvm::DenseMap<Stmt*, Stmt*> MapTy;
22
27
30 if (!S)
31 return;
32
33 switch (S->getStmtClass()) {
34 case Stmt::PseudoObjectExprClass: {
37
38 auto [Iter, Inserted] = M.try_emplace(SF, S);
39 if (!Inserted) {
40
42 break;
43
44 Iter->second = S;
45 for (Stmt *SubStmt : S->children())
46 M.erase(SubStmt);
47 }
49
52 I != E; ++I) {
53 M[*I] = S;
55 }
56 break;
57 }
58 case Stmt::BinaryConditionalOperatorClass: {
59 assert(OVMode == OV_Transparent && "Should not appear alongside OVEs");
61
64
67
70
73
74 break;
75 }
76 case Stmt::OpaqueValueExprClass: {
77
78
79
80
81
84 auto [Iter, Inserted] = M.try_emplace(SrcExpr, S);
85
87 Iter->second = S;
88 Inserted = true;
89 }
90 if (Inserted)
92 break;
93 }
94 case Stmt::CapturedStmtClass:
95 for (Stmt *SubStmt : S->children()) {
96 if (SubStmt) {
97 M[SubStmt] = S;
99 }
100 }
101 if (Stmt *SubStmt = cast(S)->getCapturedStmt()) {
102 M[SubStmt] = S;
104 }
105 break;
106 default:
107 for (Stmt *SubStmt : S->children()) {
108 if (SubStmt) {
109 M[SubStmt] = S;
111 }
112 }
113 break;
114 }
115}
116
118 if (S) {
121 Impl = M;
122 }
123}
124
126 delete (MapTy*) Impl;
127}
128
130 if (S) {
132 }
133}
134
136 assert(S);
138 MapTy *M = reinterpret_cast<MapTy *>(Impl);
139 M->insert(std::make_pair(const_cast<Stmt *>(S), const_cast<Stmt *>(Parent)));
140}
141
144 return M->lookup(S);
145}
146
148 do {
150 } while (isa_and_nonnull(S));
151 return S;
152}
153
155 do {
157 }
158 while (S && (isa(S) || isa(S)));
159
160 return S;
161}
162
164 do {
166 } while (isa_and_nonnull(S) &&
167 cast(S)->IgnoreParenImpCasts() != S);
168
169 return S;
170}
171
174 while (isa(S)) {
177 };
179}
180
184
185
186 while (P && (isa(P) || isa(P) ||
187 isa(P))) {
188 DirectChild = P;
190 }
191
192 if ()
193 return false;
194
195 switch (P->getStmtClass()) {
196 default:
197 return isa(P);
198 case Stmt::DeclStmtClass:
199 return true;
200 case Stmt::BinaryOperatorClass: {
202
203
204 return BE->getOpcode()!=BO_Comma ||DirectChild==BE->getRHS();
205 }
206 case Stmt::ForStmtClass:
207 return DirectChild == cast(P)->getCond();
208 case Stmt::WhileStmtClass:
209 return DirectChild == cast(P)->getCond();
210 case Stmt::DoStmtClass:
211 return DirectChild == cast(P)->getCond();
212 case Stmt::IfStmtClass:
213 return DirectChild == cast(P)->getCond();
214 case Stmt::IndirectGotoStmtClass:
215 return DirectChild == cast(P)->getTarget();
216 case Stmt::SwitchStmtClass:
217 return DirectChild == cast(P)->getCond();
218 case Stmt::ObjCForCollectionStmtClass:
219 return DirectChild == cast(P)->getCollection();
220 case Stmt::ReturnStmtClass:
221 return true;
222 }
223}
224
static void BuildParentMap(MapTy &M, Stmt *S, OpaqueValueMode OVMode=OV_Transparent)
llvm::DenseMap< Stmt *, Stmt * > MapTy
Defines the Objective-C statement AST node classes.
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
A builtin binary operation expression such as "x + y" or "x <= y".
This represents one expression.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
bool isConsumedExpr(Expr *E) const
void addStmt(Stmt *S)
Adds and/or updates the parent/child-relations of the complete stmt tree of S.
void setParent(const Stmt *S, const Stmt *Parent)
Manually sets the parent of S to Parent.
Stmt * getOuterParenParent(Stmt *) const
Stmt * getParentIgnoreParenImpCasts(Stmt *) const
Stmt * getParentIgnoreParenCasts(Stmt *) const
Stmt * getParent(Stmt *) const
Stmt * getParentIgnoreParens(Stmt *) const
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
semantics_iterator semantics_end()
semantics_iterator semantics_begin()
Expr *const * semantics_iterator
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Stmt - This represents one statement.
The JSON file list parser is used to communicate input to InstallAPI.