@@ -108,8 +108,8 @@ private module Internal {
108108 */
109109 cached
110110 newtype TSsaDefinition =
111- TExplicitDef ( ReachableBasicBlock bb , int i , VarDef d , SsaSourceVariable v ) {
112- bb .defAt ( i , v , d ) and
111+ TExplicitDef ( ReachableBasicBlock bb , int i , VarDef d , SsaSourceVariable v , VarRef lhs ) {
112+ bb .defAt ( i , v , d , lhs ) and
113113 (
114114 liveAfterDef ( bb , i , v ) or
115115 v .isCaptured ( )
@@ -412,17 +412,22 @@ class SsaVariable extends TSsaDefinition {
412412 /** Gets a textual representation of this element. */
413413 string toString ( ) { result = this .getDefinition ( ) .prettyPrintRef ( ) }
414414
415+ /** Gets the location of this SSA variable. */
416+ Location getLocation ( ) { result = this .getDefinition ( ) .getLocation ( ) }
417+
415418 /**
419+ * DEPRECATED. Use `getLocation().hasLocationInfo()` instead.
420+ *
416421 * Holds if this element is at the specified location.
417422 * The location spans column `startcolumn` of line `startline` to
418423 * column `endcolumn` of line `endline` in file `filepath`.
419424 * For more information, see
420425 * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
421426 */
422- predicate hasLocationInfo (
427+ deprecated predicate hasLocationInfo (
423428 string filepath , int startline , int startcolumn , int endline , int endcolumn
424429 ) {
425- this .getDefinition ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
430+ this .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
426431 }
427432}
428433
@@ -478,23 +483,22 @@ class SsaDefinition extends TSsaDefinition {
478483 string toString ( ) { result = this .prettyPrintDef ( ) }
479484
480485 /**
486+ * DEPRECATED. Use `getLocation().hasLocationInfo()` instead.
487+ *
481488 * Holds if this element is at the specified location.
482489 * The location spans column `startcolumn` of line `startline` to
483490 * column `endcolumn` of line `endline` in file `filepath`.
484491 * For more information, see
485492 * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
486493 */
487- abstract predicate hasLocationInfo (
494+ deprecated predicate hasLocationInfo (
488495 string filepath , int startline , int startcolumn , int endline , int endcolumn
489- ) ;
496+ ) {
497+ this .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
498+ }
490499
491500 /** Gets the location of this element. */
492- final Location getLocation ( ) {
493- exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
494- this .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
495- result .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
496- )
497- }
501+ Location getLocation ( ) { result = this .getBasicBlock ( ) .getLocation ( ) }
498502
499503 /** Gets the function or toplevel to which this definition belongs. */
500504 StmtContainer getContainer ( ) { result = this .getBasicBlock ( ) .getContainer ( ) }
@@ -505,36 +509,34 @@ class SsaDefinition extends TSsaDefinition {
505509 */
506510class SsaExplicitDefinition extends SsaDefinition , TExplicitDef {
507511 override predicate definesAt ( ReachableBasicBlock bb , int i , SsaSourceVariable v ) {
508- this = TExplicitDef ( bb , i , _, v )
512+ this = TExplicitDef ( bb , i , _, v , _ )
509513 }
510514
511515 /** This SSA definition corresponds to the definition of `v` at `def`. */
512- predicate defines ( VarDef def , SsaSourceVariable v ) { this = TExplicitDef ( _, _, def , v ) }
516+ predicate defines ( VarDef def , SsaSourceVariable v ) { this = TExplicitDef ( _, _, def , v , _ ) }
513517
514518 /** Gets the variable definition wrapped by this SSA definition. */
515- VarDef getDef ( ) { this = TExplicitDef ( _, _, result , _) }
519+ VarDef getDef ( ) { this = TExplicitDef ( _, _, result , _, _) }
520+
521+ /** Gets the variable reference appearing on the left-hand side of this assignment. */
522+ VarRef getLhs ( ) { this = TExplicitDef ( _, _, _, _, result ) }
516523
517524 /** Gets the basic block to which this definition belongs. */
518525 override ReachableBasicBlock getBasicBlock ( ) { this .definesAt ( result , _, _) }
519526
520- override SsaSourceVariable getSourceVariable ( ) { this = TExplicitDef ( _, _, _, result ) }
527+ override SsaSourceVariable getSourceVariable ( ) { this = TExplicitDef ( _, _, _, result , _ ) }
521528
522529 override VarDef getAContributingVarDef ( ) { result = this .getDef ( ) }
523530
524531 override string prettyPrintRef ( ) {
525- exists ( int l , int c | this .hasLocationInfo ( _, l , c , _, _) | result = "def@" + l + ":" + c )
532+ exists ( int l , int c | this .getLocation ( ) .hasLocationInfo ( _, l , c , _, _) |
533+ result = "def@" + l + ":" + c
534+ )
526535 }
527536
528537 override string prettyPrintDef ( ) { result = this .getDef ( ) .toString ( ) }
529538
530- override predicate hasLocationInfo (
531- string filepath , int startline , int startcolumn , int endline , int endcolumn
532- ) {
533- exists ( Location loc |
534- pragma [ only_bind_into ] ( loc ) = pragma [ only_bind_into ] ( this .getDef ( ) ) .getLocation ( ) and
535- loc .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
536- )
537- }
539+ override Location getLocation ( ) { result = this .getLhs ( ) .getLocation ( ) }
538540
539541 /**
540542 * Gets the data flow node representing the incoming value assigned at this definition,
@@ -557,21 +559,10 @@ abstract class SsaImplicitDefinition extends SsaDefinition {
557559 abstract string getKind ( ) ;
558560
559561 override string prettyPrintRef ( ) {
560- exists ( int l , int c | this .hasLocationInfo ( _, l , c , _, _) |
562+ exists ( int l , int c | this .getLocation ( ) . hasLocationInfo ( _, l , c , _, _) |
561563 result = this .getKind ( ) + "@" + l + ":" + c
562564 )
563565 }
564-
565- override predicate hasLocationInfo (
566- string filepath , int startline , int startcolumn , int endline , int endcolumn
567- ) {
568- endline = startline and
569- endcolumn = startcolumn and
570- exists ( Location loc |
571- pragma [ only_bind_into ] ( loc ) = pragma [ only_bind_into ] ( this .getBasicBlock ( ) ) .getLocation ( ) and
572- loc .hasLocationInfo ( filepath , startline , startcolumn , _, _)
573- )
574- }
575566}
576567
577568/**
@@ -617,16 +608,6 @@ class SsaVariableCapture extends SsaImplicitDefinition, TCapture {
617608 override string getKind ( ) { result = "capture" }
618609
619610 override string prettyPrintDef ( ) { result = "capture variable " + this .getSourceVariable ( ) }
620-
621- override predicate hasLocationInfo (
622- string filepath , int startline , int startcolumn , int endline , int endcolumn
623- ) {
624- exists ( ReachableBasicBlock bb , int i | this .definesAt ( bb , i , _) |
625- bb .getNode ( i )
626- .getLocation ( )
627- .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
628- )
629- }
630611}
631612
632613/**
@@ -747,13 +728,7 @@ class SsaRefinementNode extends SsaPseudoDefinition, TRefinement {
747728 this .getSourceVariable ( ) + " = refine[" + this .getGuard ( ) + "](" + this .ppInputs ( ) + ")"
748729 }
749730
750- override predicate hasLocationInfo (
751- string filepath , int startline , int startcolumn , int endline , int endcolumn
752- ) {
753- this .getGuard ( )
754- .getLocation ( )
755- .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
756- }
731+ override Location getLocation ( ) { result = this .getGuard ( ) .getLocation ( ) }
757732}
758733
759734module Ssa {
0 commit comments