@@ -446,16 +446,25 @@ class AssignableDefinition extends TAssignableDefinition {
446446 * the definitions of `x` and `y` in `M(out x, out y)` and `(x, y) = (0, 1)`
447447 * relate to the same call to `M` and assignment node, respectively.
448448 */
449- ControlFlow:: Node getAControlFlowNode ( ) { none ( ) }
449+ ControlFlow:: Node getAControlFlowNode ( ) {
450+ result = this .getExpr ( ) .getAControlFlowNode ( )
451+ }
452+
453+ /**
454+ * Gets the underlying expression that updates the targeted assignable when
455+ * reached, if any.
456+ *
457+ * Not all definitions have an associated expression, for example implicit
458+ * parameter definitions.
459+ */
460+ Expr getExpr ( ) { none ( ) }
450461
451462 /** DEPRECATED: Use `getAControlFlowNode()` instead. */
452463 deprecated
453464 ControlFlow:: Node getControlFlowNode ( ) { result = this .getAControlFlowNode ( ) }
454465
455466 /** Gets the enclosing callable of this definition. */
456- Callable getEnclosingCallable ( ) {
457- result = this .getAControlFlowNode ( ) .getBasicBlock ( ) .getCallable ( )
458- }
467+ Callable getEnclosingCallable ( ) { result = this .getExpr ( ) .getEnclosingCallable ( ) }
459468
460469 /**
461470 * Gets the assigned expression, if any. For example, the expression assigned
@@ -581,7 +590,7 @@ class AssignableDefinition extends TAssignableDefinition {
581590
582591 /** Gets the location of this assignable definition. */
583592 Location getLocation ( ) {
584- result = this .getAControlFlowNode ( ) .getLocation ( )
593+ result = this .getExpr ( ) .getLocation ( )
585594 }
586595}
587596
@@ -602,9 +611,7 @@ module AssignableDefinitions {
602611 result = a
603612 }
604613
605- override ControlFlow:: Node getAControlFlowNode ( ) {
606- result = a .getAControlFlowNode ( )
607- }
614+ override Expr getExpr ( ) { result = a }
608615
609616 override Expr getSource ( ) {
610617 result = a .getRValue ( ) and
@@ -633,30 +640,19 @@ module AssignableDefinitions {
633640 result = ae
634641 }
635642
636- private Expr getLeaf ( ) {
637- result = leaf
638- }
639-
640643 /**
641644 * Gets the evaluation order of this definition among the other definitions
642645 * in the compound tuple assignment. For example, in `(x, (y, z)) = ...` the
643646 * orders of the definitions of `x`, `y`, and `z` are 0, 1, and 2, respectively.
644647 */
645648 int getEvaluationOrder ( ) {
646- exists ( ControlFlow:: BasicBlock bb , int i |
647- bb .getNode ( i ) .getElement ( ) = leaf |
648- i = rank [ result + 1 ] ( int j , TupleAssignmentDefinition def |
649- bb .getNode ( j ) .getElement ( ) = def .getLeaf ( ) and
650- ae = def .getAssignment ( )
651- |
652- j
653- )
649+ leaf = rank [ result + 1 ] ( Expr leaf0 |
650+ exists ( TTupleAssignmentDefinition ( ae , leaf0 ) ) |
651+ leaf0 order by leaf0 .getLocation ( ) .getStartLine ( ) , leaf0 .getLocation ( ) .getStartColumn ( )
654652 )
655653 }
656654
657- override ControlFlow:: Node getAControlFlowNode ( ) {
658- result = ae .getAControlFlowNode ( )
659- }
655+ override Expr getExpr ( ) { result = ae }
660656
661657 override Expr getSource ( ) {
662658 result = getTupleSource ( this ) // need not exist
@@ -700,9 +696,7 @@ module AssignableDefinitions {
700696 )
701697 }
702698
703- override ControlFlow:: Node getAControlFlowNode ( ) {
704- result = this .getCall ( ) .getAControlFlowNode ( )
705- }
699+ override Expr getExpr ( ) { result = this .getCall ( ) }
706700
707701 override predicate isCertain ( ) {
708702 not isUncertainRefCall ( this .getCall ( ) , this .getTargetAccess ( ) )
@@ -732,9 +726,7 @@ module AssignableDefinitions {
732726 result = mo
733727 }
734728
735- override ControlFlow:: Node getAControlFlowNode ( ) {
736- result = mo .getAControlFlowNode ( )
737- }
729+ override Expr getExpr ( ) { result = mo }
738730
739731 override string toString ( ) {
740732 result = mo .toString ( )
@@ -756,9 +748,7 @@ module AssignableDefinitions {
756748 result = lvde
757749 }
758750
759- override ControlFlow:: Node getAControlFlowNode ( ) {
760- result = lvde .getAControlFlowNode ( )
761- }
751+ override Expr getExpr ( ) { result = lvde }
762752
763753 override string toString ( ) {
764754 result = lvde .toString ( )
@@ -785,6 +775,10 @@ module AssignableDefinitions {
785775 result = p .getCallable ( ) .getEntryPoint ( )
786776 }
787777
778+ override Callable getEnclosingCallable ( ) {
779+ result = p .getCallable ( )
780+ }
781+
788782 override string toString ( ) {
789783 result = p .toString ( )
790784 }
@@ -809,9 +803,7 @@ module AssignableDefinitions {
809803 result = aoe
810804 }
811805
812- override ControlFlow:: Node getAControlFlowNode ( ) {
813- result = aoe .getAControlFlowNode ( )
814- }
806+ override Expr getExpr ( ) { result = aoe }
815807
816808 override string toString ( ) {
817809 result = aoe .toString ( )
@@ -833,9 +825,7 @@ module AssignableDefinitions {
833825 result = ipe .getVariableDeclExpr ( )
834826 }
835827
836- override ControlFlow:: Node getAControlFlowNode ( ) {
837- result = this .getDeclaration ( ) .getAControlFlowNode ( )
838- }
828+ override Expr getExpr ( ) { result = this .getDeclaration ( ) }
839829
840830 override Expr getSource ( ) {
841831 result = ipe .getExpr ( )
@@ -870,9 +860,7 @@ module AssignableDefinitions {
870860 result = tc .getVariableDeclExpr ( )
871861 }
872862
873- override ControlFlow:: Node getAControlFlowNode ( ) {
874- result = this .getDeclaration ( ) .getAControlFlowNode ( )
875- }
863+ override Expr getExpr ( ) { result = this .getDeclaration ( ) }
876864
877865 override Expr getSource ( ) {
878866 result = any ( SwitchStmt ss | ss .getATypeCase ( ) = tc ) .getCondition ( )
@@ -906,10 +894,6 @@ module AssignableDefinitions {
906894 result = a
907895 }
908896
909- override ControlFlow:: Node getAControlFlowNode ( ) {
910- none ( ) // initializers are currently not part of the CFG
911- }
912-
913897 override Expr getSource ( ) {
914898 result = e
915899 }
0 commit comments