@@ -18,6 +18,7 @@ class DataFlowCfgNode extends ControlFlowNode {
1818
1919/** A data flow node for which we should synthesise an associated pre-update node. */
2020abstract class NeedsSyntheticPreUpdateNode extends Node {
21+ /** This will figure in the texttual representation of the synthesised pre-update node. */
2122 abstract string label ( ) ;
2223}
2324
@@ -38,14 +39,22 @@ class SyntheticPreUpdateNode extends Node, TSyntheticPreUpdateNode {
3839
3940/** A data flow node for which we should synthesise an associated post-update node. */
4041abstract class NeedsSyntheticPostUpdateNode extends Node {
42+ /** This will figure in the texttual representation of the synthesised post-update node. */
4143 abstract string label ( ) ;
4244}
4345
4446/** An argument might have its value changed as a result of a call. */
4547class ArgumentPreUpdateNode extends NeedsSyntheticPostUpdateNode , ArgumentNode {
4648 // Certain arguments, such as implicit self arguments are already post-update nodes
4749 // and should not have an extra node synthesised.
48- ArgumentPreUpdateNode ( ) { this .isNotPostUpdate ( ) }
50+ ArgumentPreUpdateNode ( ) {
51+ this = any ( CallNodeCall c ) .getArg ( _)
52+ or
53+ this = any ( SpecialCall c ) .getArg ( _)
54+ or
55+ // Avoid argument 0 of class calls as those have non-synthetic post-update nodes.
56+ exists ( ClassCall c , int n | n > 0 | this = c .getArg ( n ) )
57+ }
4958
5059 override string label ( ) { result = "arg" }
5160}
@@ -95,7 +104,7 @@ class SyntheticPostUpdateNode extends PostUpdateNode, TSyntheticPostUpdateNode {
95104 * object after the constructor (currently only `__init__`) has run.
96105 */
97106class ObjectCreationNode extends PostUpdateNode , NeedsSyntheticPreUpdateNode , CfgNode {
98- ObjectCreationNode ( ) { node .( CallNode ) = any ( ClassValue c ) .getACall ( ) }
107+ ObjectCreationNode ( ) { node .( CallNode ) = any ( ClassCall c ) .getNode ( ) }
99108
100109 override Node getPreUpdateNode ( ) { result .( SyntheticPreUpdateNode ) .getPostUpdateNode ( ) = this }
101110
@@ -371,7 +380,7 @@ class ClassCall extends DataFlowCall, TClassCall {
371380 )
372381 }
373382
374- override DataFlowCallable getEnclosingCallable ( ) { result .getScope ( ) = call .getNode ( ) . getScope ( ) }
383+ override DataFlowCallable getEnclosingCallable ( ) { result .getScope ( ) = call .getScope ( ) }
375384}
376385
377386/** Represents a call to a special method. */
@@ -404,15 +413,6 @@ class ArgumentNode extends Node {
404413
405414 /** Gets the call in which this node is an argument. */
406415 final DataFlowCall getCall ( ) { this .argumentOf ( result , _) }
407-
408- predicate isNotPostUpdate ( ) {
409- this = any ( CallNodeCall c ) .getArg ( _)
410- or
411- this = any ( SpecialCall c ) .getArg ( _)
412- or
413- // Avoid argument 0 of class calls as those have non-synthetic post-update nodes.
414- exists ( ClassCall c , int n | n > 0 | this = c .getArg ( n ) )
415- }
416416}
417417
418418/** Gets a viable run-time target for the call `call`. */
@@ -469,7 +469,7 @@ class DataFlowType extends TDataFlowType {
469469}
470470
471471/** A node that performs a type cast. */
472- class CastNode extends CfgNode {
472+ class CastNode extends Node {
473473 CastNode ( ) { none ( ) }
474474}
475475
@@ -605,19 +605,10 @@ predicate comprehensionStoreStep(CfgNode nodeFrom, Content c, CfgNode nodeTo) {
605605 * data flows from `x` to (the post-update node for) `obj` via assignment to `foo`.
606606 */
607607predicate attributeStoreStep ( CfgNode nodeFrom , Content c , PostUpdateNode nodeTo ) {
608- exists ( AssignStmt a , Attribute attr |
609- a .getValue ( ) .getAFlowNode ( ) = nodeFrom .getNode ( ) and
610- a .getATarget ( ) .( Attribute ) = attr and
608+ exists ( AttrNode attr |
609+ nodeFrom .asCfgNode ( ) = attr .( DefinitionNode ) .getValue ( ) and
611610 attr .getName ( ) = c .( AttributeContent ) .getAttribute ( ) and
612- attr .getObject ( ) .getAFlowNode ( ) = nodeTo .getPreUpdateNode ( ) .( CfgNode ) .getNode ( ) and
613- attr .getCtx ( ) instanceof Store
614- )
615- or
616- exists ( AssignExpr ae |
617- ae .getValue ( ) .getAFlowNode ( ) = nodeFrom .getNode ( ) and
618- ae .getTarget ( ) .( Attribute ) .getName ( ) = c .( AttributeContent ) .getAttribute ( ) and
619- ae .getTarget ( ) .( Attribute ) .getObject ( ) .getAFlowNode ( ) =
620- nodeTo .getPreUpdateNode ( ) .( CfgNode ) .getNode ( )
611+ attr .getObject ( ) = nodeTo .getPreUpdateNode ( ) .( CfgNode ) .getNode ( )
621612 )
622613}
623614
@@ -726,11 +717,11 @@ predicate comprehensionReadStep(CfgNode nodeFrom, Content c, EssaNode nodeTo) {
726717 * data flows from `obj` to `obj.foo` via a read from `foo`.
727718 */
728719predicate attributeReadStep ( CfgNode nodeFrom , Content c , CfgNode nodeTo ) {
729- exists ( Attribute attr |
730- nodeTo .asCfgNode ( ) . ( AttrNode ) . getNode ( ) = attr and
731- nodeFrom .asCfgNode ( ) = attr .getObject ( ) . getAFlowNode ( ) and
720+ exists ( AttrNode attr |
721+ nodeTo .asCfgNode ( ) = attr and
722+ nodeFrom .asCfgNode ( ) = attr .getObject ( ) and
732723 attr .getName ( ) = c .( AttributeContent ) .getAttribute ( ) and
733- attr .getCtx ( ) instanceof Load
724+ attr .isLoad ( )
734725 )
735726}
736727
0 commit comments