@@ -61,7 +61,7 @@ private predicate unresolvedIdentifier(Ident id, string name) {
6161/**
6262 * An SSA variable.
6363 */
64- class SsaVariable extends TSsaDefinition {
64+ class SsaVariable instanceof SsaDefinition {
6565 /** Gets the source variable corresponding to this SSA variable. */
6666 SsaSourceVariable getSourceVariable ( ) { result = this .( SsaDefinition ) .getSourceVariable ( ) }
6767
@@ -107,27 +107,26 @@ class SsaVariable extends TSsaDefinition {
107107/**
108108 * An SSA definition.
109109 */
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+
111120 /** Gets the SSA variable defined by this definition. */
112121 SsaVariable getVariable ( ) { result = this }
113122
114123 /** Gets the source variable defined by this definition. */
115- abstract SsaSourceVariable getSourceVariable ( ) ;
124+ SsaSourceVariable getSourceVariable ( ) { this . definesAt ( result , _ , _ ) }
116125
117126 /**
118127 * Gets the basic block to which this definition belongs.
119128 */
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 , _) }
131130
132131 /**
133132 * INTERNAL: Use `toString()` instead.
@@ -146,12 +145,12 @@ class SsaDefinition extends TSsaDefinition {
146145 /** Gets the innermost function or file to which this SSA definition belongs. */
147146 ControlFlow:: Root getRoot ( ) { result = this .getBasicBlock ( ) .getRoot ( ) }
148147
148+ /** Gets the location of this SSA definition. */
149+ Location getLocation ( ) { result = this .( ZZZDefinition ) .getLocation ( ) }
150+
149151 /** Gets a textual representation of this element. */
150152 string toString ( ) { result = this .prettyPrintDef ( ) }
151153
152- /** Gets the source location for this element. */
153- abstract Location getLocation ( ) ;
154-
155154 /**
156155 * DEPRECATED: Use `getLocation()` instead.
157156 *
@@ -178,32 +177,24 @@ class SsaDefinition extends TSsaDefinition {
178177/**
179178 * An SSA definition that corresponds to an explicit assignment or other variable definition.
180179 */
181- class SsaExplicitDefinition extends SsaDefinition , TExplicitDef {
180+ class SsaExplicitDefinition extends SsaDefinition {
181+ SsaExplicitDefinition ( ) { not this instanceof SsaImplicitDefinition }
182+
182183 /** Gets the instruction where the definition happens. */
183184 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 ) )
185186 }
186187
187188 /** Gets the right-hand side of the definition. */
188189 IR:: Instruction getRhs ( ) { this .getInstruction ( ) .writes ( _, result ) }
189190
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-
198191 override string prettyPrintRef ( ) {
199192 exists ( Location loc | loc = this .getLocation ( ) |
200193 result = "def@" + loc .getStartLine ( ) + ":" + loc .getStartColumn ( )
201194 )
202195 }
203196
204197 override string prettyPrintDef ( ) { result = "definition of " + this .getSourceVariable ( ) }
205-
206- override Location getLocation ( ) { result = this .getInstruction ( ) .getLocation ( ) }
207198}
208199
209200/** Provides a helper predicate for working with explicit SSA definitions. */
@@ -230,8 +221,6 @@ abstract class SsaImplicitDefinition extends SsaDefinition {
230221 result = this .getKind ( ) + "@" + loc .getStartLine ( ) + ":" + loc .getStartColumn ( )
231222 )
232223 }
233-
234- override Location getLocation ( ) { result = this .getBasicBlock ( ) .getLocation ( ) }
235224}
236225
237226/**
@@ -241,24 +230,16 @@ abstract class SsaImplicitDefinition extends SsaDefinition {
241230 * Capturing definitions appear at the beginning of such functions, as well as
242231 * at any function call that may affect the value of the variable.
243232 */
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+ )
247238 }
248239
249- override ReachableBasicBlock getBasicBlock ( ) { this .definesAt ( _, result , _) }
250-
251- override SsaSourceVariable getSourceVariable ( ) { this .definesAt ( result , _, _) }
252-
253240 override string getKind ( ) { result = "capture" }
254241
255242 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- }
262243}
263244
264245/**
@@ -283,26 +264,16 @@ abstract class SsaPseudoDefinition extends SsaImplicitDefinition {
283264 * in the flow graph where otherwise two or more definitions for the variable
284265 * would be visible.
285266 */
286- class SsaPhiNode extends SsaPseudoDefinition , TPhi {
267+ class SsaPhiNode extends SsaPseudoDefinition instanceof ZZZPhiNode {
287268 override SsaVariable getAnInput ( ) {
288269 result = getDefReachingEndOf ( this .getBasicBlock ( ) .getAPredecessor ( ) , this .getSourceVariable ( ) )
289270 }
290271
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-
299272 override string getKind ( ) { result = "phi" }
300273
301274 override string prettyPrintDef ( ) {
302275 result = this .getSourceVariable ( ) + " = phi(" + this .ppInputs ( ) + ")"
303276 }
304-
305- override Location getLocation ( ) { result = this .getBasicBlock ( ) .getLocation ( ) }
306277}
307278
308279/**
0 commit comments