@@ -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,24 @@ 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 {
181
+ SsaExplicitDefinition ( ) { not this instanceof SsaImplicitDefinition }
182
+
182
183
/** Gets the instruction where the definition happens. */
183
184
IR:: Instruction getInstruction ( ) {
184
- exists ( BasicBlock bb , int i | this = TExplicitDef ( bb , i , _ ) | result = bb .getNode ( i ) )
185
+ exists ( BasicBlock bb , int i | this . definesAt ( _ , bb , i ) | result = bb .getNode ( i ) )
185
186
}
186
187
187
188
/** Gets the right-hand side of the definition. */
188
189
IR:: Instruction getRhs ( ) { this .getInstruction ( ) .writes ( _, result ) }
189
190
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
191
override string prettyPrintRef ( ) {
199
192
exists ( Location loc | loc = this .getLocation ( ) |
200
193
result = "def@" + loc .getStartLine ( ) + ":" + loc .getStartColumn ( )
201
194
)
202
195
}
203
196
204
197
override string prettyPrintDef ( ) { result = "definition of " + this .getSourceVariable ( ) }
205
-
206
- override Location getLocation ( ) { result = this .getInstruction ( ) .getLocation ( ) }
207
198
}
208
199
209
200
/** Provides a helper predicate for working with explicit SSA definitions. */
@@ -230,8 +221,6 @@ abstract class SsaImplicitDefinition extends SsaDefinition {
230
221
result = this .getKind ( ) + "@" + loc .getStartLine ( ) + ":" + loc .getStartColumn ( )
231
222
)
232
223
}
233
-
234
- override Location getLocation ( ) { result = this .getBasicBlock ( ) .getLocation ( ) }
235
224
}
236
225
237
226
/**
@@ -241,24 +230,16 @@ abstract class SsaImplicitDefinition extends SsaDefinition {
241
230
* Capturing definitions appear at the beginning of such functions, as well as
242
231
* at any function call that may affect the value of the variable.
243
232
*/
244
- class SsaVariableCapture extends SsaImplicitDefinition , TCapture {
245
- override predicate definesAt ( SsaSourceVariable v , ReachableBasicBlock bb , int i ) {
246
- this = TCapture ( bb , i , v )
233
+ class SsaVariableCapture extends SsaImplicitDefinition {
234
+ SsaVariableCapture ( ) {
235
+ exists ( BasicBlock bb , int i , SsaSourceVariable v | this .definesAt ( v , bb , i ) |
236
+ mayCapture ( bb , i , v )
237
+ )
247
238
}
248
239
249
- override ReachableBasicBlock getBasicBlock ( ) { this .definesAt ( _, result , _) }
250
-
251
- override SsaSourceVariable getSourceVariable ( ) { this .definesAt ( result , _, _) }
252
-
253
240
override string getKind ( ) { result = "capture" }
254
241
255
242
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
243
}
263
244
264
245
/**
@@ -283,26 +264,16 @@ abstract class SsaPseudoDefinition extends SsaImplicitDefinition {
283
264
* in the flow graph where otherwise two or more definitions for the variable
284
265
* would be visible.
285
266
*/
286
- class SsaPhiNode extends SsaPseudoDefinition , TPhi {
267
+ class SsaPhiNode extends SsaPseudoDefinition instanceof ZZZPhiNode {
287
268
override SsaVariable getAnInput ( ) {
288
269
result = getDefReachingEndOf ( this .getBasicBlock ( ) .getAPredecessor ( ) , this .getSourceVariable ( ) )
289
270
}
290
271
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
272
override string getKind ( ) { result = "phi" }
300
273
301
274
override string prettyPrintDef ( ) {
302
275
result = this .getSourceVariable ( ) + " = phi(" + this .ppInputs ( ) + ")"
303
276
}
304
-
305
- override Location getLocation ( ) { result = this .getBasicBlock ( ) .getLocation ( ) }
306
277
}
307
278
308
279
/**
0 commit comments