@@ -105,29 +105,19 @@ module ControlFlow {
105
105
/** A node in the expression-level control-flow graph. */
106
106
class Node extends TNode {
107
107
/** Gets the statement containing this node, if any. */
108
- Stmt getEnclosingStmt ( ) {
109
- result = this .asStmt ( ) or
110
- result = this .asExpr ( ) .getEnclosingStmt ( )
111
- }
108
+ Stmt getEnclosingStmt ( ) { none ( ) }
112
109
113
110
/** Gets the immediately enclosing callable whose body contains this node. */
114
- Callable getEnclosingCallable ( ) {
115
- this = TExitNode ( result ) or
116
- result = this .asStmt ( ) .getEnclosingCallable ( ) or
117
- result = this .asExpr ( ) .getEnclosingCallable ( )
118
- }
111
+ Callable getEnclosingCallable ( ) { none ( ) }
119
112
120
113
/** Gets the statement this `Node` corresponds to, if any. */
121
- Stmt asStmt ( ) { this = TStmtNode ( result ) }
114
+ Stmt asStmt ( ) { none ( ) }
122
115
123
116
/** Gets the expression this `Node` corresponds to, if any. */
124
- Expr asExpr ( ) { this = TExprNode ( result ) }
117
+ Expr asExpr ( ) { none ( ) }
125
118
126
119
/** Gets the call this `Node` corresponds to, if any. */
127
- Call asCall ( ) {
128
- result = this .asExpr ( ) or
129
- result = this .asStmt ( )
130
- }
120
+ Call asCall ( ) { none ( ) }
131
121
132
122
/** Gets an immediate successor of this node. */
133
123
Node getASuccessor ( ) { result = succ ( this ) }
@@ -148,33 +138,77 @@ module ControlFlow {
148
138
BasicBlock getBasicBlock ( ) { result .getANode ( ) = this }
149
139
150
140
/** Gets a textual representation of this element. */
151
- string toString ( ) {
152
- result = this .asExpr ( ) .toString ( )
153
- or
154
- result = this .asStmt ( ) .toString ( )
155
- or
156
- result = "Exit" and this instanceof ExitNode
157
- }
141
+ string toString ( ) { none ( ) }
158
142
159
143
/** Gets the source location for this element. */
160
- Location getLocation ( ) {
161
- result = this .asExpr ( ) .getLocation ( ) or
162
- result = this .asStmt ( ) .getLocation ( ) or
163
- result = this .( ExitNode ) .getEnclosingCallable ( ) .getLocation ( )
164
- }
144
+ Location getLocation ( ) { none ( ) }
165
145
166
146
/**
167
147
* Gets the most appropriate AST node for this control flow node, if any.
168
148
*/
169
- ExprParent getAstNode ( ) {
170
- result = this .asExpr ( ) or
171
- result = this .asStmt ( ) or
172
- this = TExitNode ( result )
173
- }
149
+ ExprParent getAstNode ( ) { none ( ) }
150
+ }
151
+
152
+ /** A control-flow node that represents the evaluation of an expression. */
153
+ class ExprNode extends Node , TExprNode {
154
+ Expr e ;
155
+
156
+ ExprNode ( ) { this = TExprNode ( e ) }
157
+
158
+ override Stmt getEnclosingStmt ( ) { result = e .getEnclosingStmt ( ) }
159
+
160
+ override Callable getEnclosingCallable ( ) { result = e .getEnclosingCallable ( ) }
161
+
162
+ override Expr asExpr ( ) { result = e }
163
+
164
+ override Call asCall ( ) { result = e }
165
+
166
+ override ExprParent getAstNode ( ) { result = e }
167
+
168
+ /** Gets a textual representation of this element. */
169
+ override string toString ( ) { result = e .toString ( ) }
170
+
171
+ /** Gets the source location for this element. */
172
+ override Location getLocation ( ) { result = e .getLocation ( ) }
173
+ }
174
+
175
+ /** A control-flow node that represents a statement. */
176
+ class StmtNode extends Node , TStmtNode {
177
+ Stmt s ;
178
+
179
+ StmtNode ( ) { this = TStmtNode ( s ) }
180
+
181
+ override Stmt getEnclosingStmt ( ) { result = s }
182
+
183
+ override Callable getEnclosingCallable ( ) { result = s .getEnclosingCallable ( ) }
184
+
185
+ override Stmt asStmt ( ) { result = s }
186
+
187
+ override Call asCall ( ) { result = s }
188
+
189
+ override ExprParent getAstNode ( ) { result = s }
190
+
191
+ override string toString ( ) { result = s .toString ( ) }
192
+
193
+ override Location getLocation ( ) { result = s .getLocation ( ) }
174
194
}
175
195
176
196
/** A control flow node indicating the termination of a callable. */
177
- class ExitNode extends Node , TExitNode { }
197
+ class ExitNode extends Node , TExitNode {
198
+ Callable c ;
199
+
200
+ ExitNode ( ) { this = TExitNode ( c ) }
201
+
202
+ override Callable getEnclosingCallable ( ) { result = c }
203
+
204
+ override ExprParent getAstNode ( ) { result = c }
205
+
206
+ /** Gets a textual representation of this element. */
207
+ override string toString ( ) { result = "Exit" }
208
+
209
+ /** Gets the source location for this element. */
210
+ override Location getLocation ( ) { result = c .getLocation ( ) }
211
+ }
178
212
}
179
213
180
214
class ControlFlowNode = ControlFlow:: Node ;
0 commit comments