@@ -61,7 +61,7 @@ private predicate unresolvedIdentifier(Ident id, string name) {
61
61
/**
62
62
* An SSA variable.
63
63
*/
64
- class SsaVariable extends TSsaDefinition {
64
+ class SsaVariable instanceof SsaDefinition {
65
65
/** Gets the source variable corresponding to this SSA variable. */
66
66
SsaSourceVariable getSourceVariable ( ) { result = this .( SsaDefinition ) .getSourceVariable ( ) }
67
67
@@ -107,27 +107,26 @@ class SsaVariable extends TSsaDefinition {
107
107
/**
108
108
* An SSA definition.
109
109
*/
110
- class SsaDefinition extends TSsaDefinition {
110
+ class SsaDefinition instanceof ZZZDefinition {
111
+ /**
112
+ * Holds if this SSA definition defines `v` at index `i` in basic block `bb`.
113
+ * Phi nodes are considered to be at index `-1`, while normal variable writes
114
+ * are at the index of the control flow node they wrap.
115
+ */
116
+ predicate definesAt ( SsaSourceVariable v , BasicBlock bb , int i ) {
117
+ this .( ZZZDefinition ) .definesAt ( v , bb , i )
118
+ }
119
+
111
120
/** Gets the SSA variable defined by this definition. */
112
121
SsaVariable getVariable ( ) { result = this }
113
122
114
123
/** Gets the source variable defined by this definition. */
115
- abstract SsaSourceVariable getSourceVariable ( ) ;
124
+ SsaSourceVariable getSourceVariable ( ) { this . definesAt ( result , _ , _ ) }
116
125
117
126
/**
118
127
* Gets the basic block to which this definition belongs.
119
128
*/
120
- abstract ReachableBasicBlock getBasicBlock ( ) ;
121
-
122
- /**
123
- * INTERNAL: Use `getBasicBlock()` and `getSourceVariable()` instead.
124
- *
125
- * Holds if this is a definition of source variable `v` at index `idx` in basic block `bb`.
126
- *
127
- * Phi nodes are considered to be at index `-1`, all other definitions at the index of
128
- * the control flow node they correspond to.
129
- */
130
- abstract predicate definesAt ( SsaSourceVariable v , ReachableBasicBlock bb , int idx ) ;
129
+ ReachableBasicBlock getBasicBlock ( ) { this .definesAt ( _, result , _) }
131
130
132
131
/**
133
132
* INTERNAL: Use `toString()` instead.
@@ -146,12 +145,12 @@ class SsaDefinition extends TSsaDefinition {
146
145
/** Gets the innermost function or file to which this SSA definition belongs. */
147
146
ControlFlow:: Root getRoot ( ) { result = this .getBasicBlock ( ) .getRoot ( ) }
148
147
148
+ /** Gets the location of this SSA definition. */
149
+ Location getLocation ( ) { result = this .( ZZZDefinition ) .getLocation ( ) }
150
+
149
151
/** Gets a textual representation of this element. */
150
152
string toString ( ) { result = this .prettyPrintDef ( ) }
151
153
152
- /** Gets the source location for this element. */
153
- abstract Location getLocation ( ) ;
154
-
155
154
/**
156
155
* DEPRECATED: Use `getLocation()` instead.
157
156
*
@@ -178,32 +177,22 @@ class SsaDefinition extends TSsaDefinition {
178
177
/**
179
178
* An SSA definition that corresponds to an explicit assignment or other variable definition.
180
179
*/
181
- class SsaExplicitDefinition extends SsaDefinition , TExplicitDef {
180
+ class SsaExplicitDefinition extends SsaDefinition {
182
181
/** Gets the instruction where the definition happens. */
183
182
IR:: Instruction getInstruction ( ) {
184
- exists ( BasicBlock bb , int i | this = TExplicitDef ( bb , i , _ ) | result = bb .getNode ( i ) )
183
+ exists ( BasicBlock bb , int i | this . definesAt ( _ , bb , i ) | result = bb .getNode ( i ) )
185
184
}
186
185
187
186
/** Gets the right-hand side of the definition. */
188
187
IR:: Instruction getRhs ( ) { this .getInstruction ( ) .writes ( _, result ) }
189
188
190
- override predicate definesAt ( SsaSourceVariable v , ReachableBasicBlock bb , int i ) {
191
- this = TExplicitDef ( bb , i , v )
192
- }
193
-
194
- override ReachableBasicBlock getBasicBlock ( ) { this .definesAt ( _, result , _) }
195
-
196
- override SsaSourceVariable getSourceVariable ( ) { this .definesAt ( result , _, _) }
197
-
198
189
override string prettyPrintRef ( ) {
199
190
exists ( Location loc | loc = this .getLocation ( ) |
200
191
result = "def@" + loc .getStartLine ( ) + ":" + loc .getStartColumn ( )
201
192
)
202
193
}
203
194
204
195
override string prettyPrintDef ( ) { result = "definition of " + this .getSourceVariable ( ) }
205
-
206
- override Location getLocation ( ) { result = this .getInstruction ( ) .getLocation ( ) }
207
196
}
208
197
209
198
/** Provides a helper predicate for working with explicit SSA definitions. */
@@ -230,8 +219,6 @@ abstract class SsaImplicitDefinition extends SsaDefinition {
230
219
result = this .getKind ( ) + "@" + loc .getStartLine ( ) + ":" + loc .getStartColumn ( )
231
220
)
232
221
}
233
-
234
- override Location getLocation ( ) { result = this .getBasicBlock ( ) .getLocation ( ) }
235
222
}
236
223
237
224
/**
@@ -241,24 +228,16 @@ abstract class SsaImplicitDefinition extends SsaDefinition {
241
228
* Capturing definitions appear at the beginning of such functions, as well as
242
229
* at any function call that may affect the value of the variable.
243
230
*/
244
- class SsaVariableCapture extends SsaImplicitDefinition , TCapture {
245
- override predicate definesAt ( SsaSourceVariable v , ReachableBasicBlock bb , int i ) {
246
- this = TCapture ( bb , i , v )
231
+ class SsaVariableCapture extends SsaImplicitDefinition {
232
+ SsaVariableCapture ( ) {
233
+ exists ( BasicBlock bb , int i , SsaSourceVariable v | this .definesAt ( v , bb , i ) |
234
+ mayCapture ( bb , i , v )
235
+ )
247
236
}
248
237
249
- override ReachableBasicBlock getBasicBlock ( ) { this .definesAt ( _, result , _) }
250
-
251
- override SsaSourceVariable getSourceVariable ( ) { this .definesAt ( result , _, _) }
252
-
253
238
override string getKind ( ) { result = "capture" }
254
239
255
240
override string prettyPrintDef ( ) { result = "capture variable " + this .getSourceVariable ( ) }
256
-
257
- override Location getLocation ( ) {
258
- exists ( ReachableBasicBlock bb , int i | this .definesAt ( _, bb , i ) |
259
- result = bb .getNode ( i ) .getLocation ( )
260
- )
261
- }
262
241
}
263
242
264
243
/**
@@ -283,26 +262,16 @@ abstract class SsaPseudoDefinition extends SsaImplicitDefinition {
283
262
* in the flow graph where otherwise two or more definitions for the variable
284
263
* would be visible.
285
264
*/
286
- class SsaPhiNode extends SsaPseudoDefinition , TPhi {
265
+ class SsaPhiNode extends SsaPseudoDefinition instanceof ZZZPhiNode {
287
266
override SsaVariable getAnInput ( ) {
288
267
result = getDefReachingEndOf ( this .getBasicBlock ( ) .getAPredecessor ( ) , this .getSourceVariable ( ) )
289
268
}
290
269
291
- override predicate definesAt ( SsaSourceVariable v , ReachableBasicBlock bb , int i ) {
292
- bb = this .getBasicBlock ( ) and v = this .getSourceVariable ( ) and i = - 1
293
- }
294
-
295
- override ReachableBasicBlock getBasicBlock ( ) { this = TPhi ( result , _) }
296
-
297
- override SsaSourceVariable getSourceVariable ( ) { this = TPhi ( _, result ) }
298
-
299
270
override string getKind ( ) { result = "phi" }
300
271
301
272
override string prettyPrintDef ( ) {
302
273
result = this .getSourceVariable ( ) + " = phi(" + this .ppInputs ( ) + ")"
303
274
}
304
-
305
- override Location getLocation ( ) { result = this .getBasicBlock ( ) .getLocation ( ) }
306
275
}
307
276
308
277
/**
0 commit comments