@@ -108,8 +108,8 @@ private module Internal {
108
108
*/
109
109
cached
110
110
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
113
113
(
114
114
liveAfterDef ( bb , i , v ) or
115
115
v .isCaptured ( )
@@ -412,17 +412,22 @@ class SsaVariable extends TSsaDefinition {
412
412
/** Gets a textual representation of this element. */
413
413
string toString ( ) { result = this .getDefinition ( ) .prettyPrintRef ( ) }
414
414
415
+ /** Gets the location of this SSA variable. */
416
+ Location getLocation ( ) { result = this .getDefinition ( ) .getLocation ( ) }
417
+
415
418
/**
419
+ * DEPRECATED. Use `getLocation().hasLocationInfo()` instead.
420
+ *
416
421
* Holds if this element is at the specified location.
417
422
* The location spans column `startcolumn` of line `startline` to
418
423
* column `endcolumn` of line `endline` in file `filepath`.
419
424
* For more information, see
420
425
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
421
426
*/
422
- predicate hasLocationInfo (
427
+ deprecated predicate hasLocationInfo (
423
428
string filepath , int startline , int startcolumn , int endline , int endcolumn
424
429
) {
425
- this .getDefinition ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
430
+ this .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
426
431
}
427
432
}
428
433
@@ -478,23 +483,22 @@ class SsaDefinition extends TSsaDefinition {
478
483
string toString ( ) { result = this .prettyPrintDef ( ) }
479
484
480
485
/**
486
+ * DEPRECATED. Use `getLocation().hasLocationInfo()` instead.
487
+ *
481
488
* Holds if this element is at the specified location.
482
489
* The location spans column `startcolumn` of line `startline` to
483
490
* column `endcolumn` of line `endline` in file `filepath`.
484
491
* For more information, see
485
492
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
486
493
*/
487
- abstract predicate hasLocationInfo (
494
+ deprecated predicate hasLocationInfo (
488
495
string filepath , int startline , int startcolumn , int endline , int endcolumn
489
- ) ;
496
+ ) {
497
+ this .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
498
+ }
490
499
491
500
/** 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 ( ) }
498
502
499
503
/** Gets the function or toplevel to which this definition belongs. */
500
504
StmtContainer getContainer ( ) { result = this .getBasicBlock ( ) .getContainer ( ) }
@@ -505,36 +509,34 @@ class SsaDefinition extends TSsaDefinition {
505
509
*/
506
510
class SsaExplicitDefinition extends SsaDefinition , TExplicitDef {
507
511
override predicate definesAt ( ReachableBasicBlock bb , int i , SsaSourceVariable v ) {
508
- this = TExplicitDef ( bb , i , _, v )
512
+ this = TExplicitDef ( bb , i , _, v , _ )
509
513
}
510
514
511
515
/** 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 , _ ) }
513
517
514
518
/** 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 ) }
516
523
517
524
/** Gets the basic block to which this definition belongs. */
518
525
override ReachableBasicBlock getBasicBlock ( ) { this .definesAt ( result , _, _) }
519
526
520
- override SsaSourceVariable getSourceVariable ( ) { this = TExplicitDef ( _, _, _, result ) }
527
+ override SsaSourceVariable getSourceVariable ( ) { this = TExplicitDef ( _, _, _, result , _ ) }
521
528
522
529
override VarDef getAContributingVarDef ( ) { result = this .getDef ( ) }
523
530
524
531
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
+ )
526
535
}
527
536
528
537
override string prettyPrintDef ( ) { result = this .getDef ( ) .toString ( ) }
529
538
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 ( ) }
538
540
539
541
/**
540
542
* Gets the data flow node representing the incoming value assigned at this definition,
@@ -557,21 +559,10 @@ abstract class SsaImplicitDefinition extends SsaDefinition {
557
559
abstract string getKind ( ) ;
558
560
559
561
override string prettyPrintRef ( ) {
560
- exists ( int l , int c | this .hasLocationInfo ( _, l , c , _, _) |
562
+ exists ( int l , int c | this .getLocation ( ) . hasLocationInfo ( _, l , c , _, _) |
561
563
result = this .getKind ( ) + "@" + l + ":" + c
562
564
)
563
565
}
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
- }
575
566
}
576
567
577
568
/**
@@ -617,16 +608,6 @@ class SsaVariableCapture extends SsaImplicitDefinition, TCapture {
617
608
override string getKind ( ) { result = "capture" }
618
609
619
610
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
- }
630
611
}
631
612
632
613
/**
@@ -747,13 +728,7 @@ class SsaRefinementNode extends SsaPseudoDefinition, TRefinement {
747
728
this .getSourceVariable ( ) + " = refine[" + this .getGuard ( ) + "](" + this .ppInputs ( ) + ")"
748
729
}
749
730
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 ( ) }
757
732
}
758
733
759
734
module Ssa {
0 commit comments