@@ -270,6 +270,16 @@ module AccessPath {
270
270
271
271
/** A module for computing an access to a variable that happens after a property has been written onto it */
272
272
private module GetLaterAccess {
273
+ /**
274
+ * Gets an reference to the SSA variable `variable`.
275
+ * Either the definition or a use of the SSA variable
276
+ */
277
+ private VarRef getAVariableRef ( SsaVariable variable ) {
278
+ result = variable .getAUse ( )
279
+ or
280
+ result = variable .getDefinition ( ) .( SsaExplicitDefinition ) .getDef ( ) .getTarget ( )
281
+ }
282
+
273
283
/**
274
284
* Gets an access to a variable that is written to in `write`, where the access is after the write.
275
285
*
@@ -286,7 +296,7 @@ module AccessPath {
286
296
pragma [ noopt]
287
297
DataFlow:: Node getLaterBaseAccess ( DataFlow:: PropWrite write ) {
288
298
exists (
289
- ControlFlowNode writeNode , BindingPattern access , VarRef otherAccess , Variable variable ,
299
+ ControlFlowNode writeNode , BindingPattern access , VarRef otherAccess , SsaVariable variable ,
290
300
StmtContainer container
291
301
|
292
302
access = getBaseVar ( write ) and
@@ -323,24 +333,23 @@ module AccessPath {
323
333
}
324
334
325
335
/** Gets an access to `var` inside `container` where `usedInWrite` indicates whether the access is the base of a property write. */
326
- private VarRef getAnAccessInContainer ( Variable var , StmtContainer container , boolean usedInWrite ) {
327
- result .getVariable ( ) = var and
336
+ private VarRef getAnAccessInContainer (
337
+ SsaVariable var , StmtContainer container , boolean usedInWrite
338
+ ) {
339
+ result = getAVariableRef ( var ) and
328
340
result .getContainer ( ) = container and
329
- var .isLocal ( ) and
330
341
if result = getBaseVar ( _) then usedInWrite = true else usedInWrite = false
331
342
}
332
343
333
344
/** Gets a variable that is relevant for the computations in the `GetLaterAccess` module. */
334
- private Variable getARelevantVariable ( ) {
345
+ private SsaVariable getARelevantVariable ( ) {
335
346
// The variable might be used where `getLaterBaseAccess()` is called.
336
347
exists ( DataFlow:: Node node |
337
348
exists ( fromRhs ( node , _) ) and
338
- node .asExpr ( ) . ( VarAccess ) . getVariable ( ) = result
349
+ node .asExpr ( ) = getAVariableRef ( result )
339
350
) and
340
351
// There is a write that writes to the variable.
341
- getBaseVar ( _) .getVariable ( ) = result and
342
- // It's local.
343
- result .isLocal ( ) and // we skip global variables, because that turns messy quick.
352
+ getBaseVar ( _) = getAVariableRef ( result ) and
344
353
// There is both a "write" and "read" in the same container of the variable.
345
354
exists ( StmtContainer container |
346
355
exists ( getAnAccessInContainer ( result , container , true ) ) and // a "write", an access to the variable that is the base of a property reference.
@@ -350,9 +359,9 @@ module AccessPath {
350
359
351
360
/** Gets a basic-block that has a read of the variable that is written to by `write`, where the basicblock occurs after `start`. */
352
361
private ReachableBasicBlock getASuccessorBBThatReadsVar ( DataFlow:: PropWrite write ) {
353
- exists ( VarAccess baseExpr , Variable var , ControlFlowNode writeNode |
362
+ exists ( VarRef baseExpr , SsaVariable var , ControlFlowNode writeNode |
354
363
baseExpr = getBaseVar ( write ) and
355
- var = baseExpr . getVariable ( ) and
364
+ getAVariableRef ( var ) = baseExpr and
356
365
var = getARelevantVariable ( ) and
357
366
writeNode = write .getWriteNode ( ) and
358
367
writeNode .getBasicBlock ( ) .( ReachableBasicBlock ) .strictlyDominates ( result ) and
0 commit comments