@@ -547,6 +547,31 @@ class IfExprNode extends ControlFlowNode {
547547 override IfExp getNode ( ) { result = super .getNode ( ) }
548548}
549549
550+ /** A control flow node corresponding to an assignment expression such as `lhs := rhs`. */
551+ class AssignmentExprNode extends ControlFlowNode {
552+ AssignmentExprNode ( ) { toAst ( this ) instanceof AssignExpr }
553+
554+ /** Gets the flow node corresponding to the left-hand side of the assignment expression */
555+ ControlFlowNode getTarget ( ) {
556+ exists ( AssignExpr a |
557+ this .getNode ( ) = a and
558+ a .getTarget ( ) = result .getNode ( ) and
559+ result .getBasicBlock ( ) .dominates ( this .getBasicBlock ( ) )
560+ )
561+ }
562+
563+ /** Gets the flow node corresponding to the right-hand side of the assignment expression */
564+ ControlFlowNode getValue ( ) {
565+ exists ( AssignExpr a |
566+ this .getNode ( ) = a and
567+ a .getValue ( ) = result .getNode ( ) and
568+ result .getBasicBlock ( ) .dominates ( this .getBasicBlock ( ) )
569+ )
570+ }
571+
572+ override AssignExpr getNode ( ) { result = super .getNode ( ) }
573+ }
574+
550575/** A control flow node corresponding to a binary expression, such as `x + y` */
551576class BinaryExprNode extends ControlFlowNode {
552577 BinaryExprNode ( ) { toAst ( this ) instanceof BinaryExpr }
@@ -630,6 +655,8 @@ class DefinitionNode extends ControlFlowNode {
630655 Stages:: AST:: ref ( ) and
631656 exists ( Assign a | a .getATarget ( ) .getAFlowNode ( ) = this )
632657 or
658+ exists ( AssignExpr a | a .getTarget ( ) .getAFlowNode ( ) = this )
659+ or
633660 exists ( AnnAssign a | a .getTarget ( ) .getAFlowNode ( ) = this and exists ( a .getValue ( ) ) )
634661 or
635662 exists ( Alias a | a .getAsname ( ) .getAFlowNode ( ) = this )
@@ -787,6 +814,9 @@ private AstNode assigned_value(Expr lhs) {
787814 /* lhs = result */
788815 exists ( Assign a | a .getATarget ( ) = lhs and result = a .getValue ( ) )
789816 or
817+ /* lhs := result */
818+ exists ( AssignExpr a | a .getTarget ( ) = lhs and result = a .getValue ( ) )
819+ or
790820 /* lhs : annotation = result */
791821 exists ( AnnAssign a | a .getTarget ( ) = lhs and result = a .getValue ( ) )
792822 or
0 commit comments