@@ -173,49 +173,36 @@ predicate excludeNode(Node n) {
173
173
excludeNode ( n .getParentNode ( ) )
174
174
}
175
175
176
- private newtype TPos =
177
- PosBefore ( ) or
178
- PosAt ( ) or
179
- PosAfter ( ) or
180
- PosBeforeDestructors ( ) or
181
- PosAfterDestructors ( )
182
-
183
- /** A `Pos` without a `bindingset` requirement on the constructor. */
184
- private class AnyPos extends TPos {
185
- string toString ( ) { result = "Pos" }
186
- }
187
-
188
176
/**
189
177
* A constant that indicates the type of sub-node in a pair of `(Node, Pos)`.
190
178
* See the comment block at the top of this file.
191
179
*/
192
- private class Pos extends AnyPos {
193
- // This is to make sure we get compile errors in code that forgets to restrict a `Pos`.
180
+ private class Pos extends int {
194
181
bindingset [ this ]
195
182
Pos ( ) { any ( ) }
196
183
197
184
/** Holds if this is the position just _before_ the associated `Node`. */
198
- predicate isBefore ( ) { this = PosBefore ( ) }
185
+ predicate isBefore ( ) { this = 0 }
199
186
200
187
/** Holds if `(n, this)` is the sub-node that represents `n` itself. */
201
- predicate isAt ( ) { this = PosAt ( ) }
188
+ predicate isAt ( ) { this = 1 }
202
189
203
190
/** Holds if this is the position just _after_ the associated `Node`. */
204
- predicate isAfter ( ) { this = PosAfter ( ) }
191
+ predicate isAfter ( ) { this = 2 }
205
192
206
193
/**
207
194
* Holds if `(n, this)` is the virtual sub-node that comes just _before_ any
208
195
* implicit destructor calls following `n`. The node `n` will be some node
209
196
* that may be followed by local variables going out of scope.
210
197
*/
211
- predicate isBeforeDestructors ( ) { this = PosBeforeDestructors ( ) }
198
+ predicate isBeforeDestructors ( ) { this = 3 }
212
199
213
200
/**
214
201
* Holds if `(n, this)` is the virtual sub-node that comes just _after_ any
215
202
* implicit destructor calls following `n`. The node `n` will be some node
216
203
* that may be followed by local variables going out of scope.
217
204
*/
218
- predicate isAfterDestructors ( ) { this = PosAfterDestructors ( ) }
205
+ predicate isAfterDestructors ( ) { this = 4 }
219
206
220
207
pragma [ inline]
221
208
predicate nodeBefore ( Node n , Node nEq ) { this .isBefore ( ) and n = nEq }
@@ -489,51 +476,25 @@ private Node getLastControlOrderChild(Node n) {
489
476
result = getControlOrderChildDense ( n , max ( int i | exists ( getControlOrderChildDense ( n , i ) ) ) )
490
477
}
491
478
492
- private newtype TSpec =
493
- SpecPos ( AnyPos p ) or
494
- SpecAround ( ) or
495
- SpecAroundDestructors ( ) or
496
- SpecBarrier ( )
497
-
498
- /** A `Spec` without a `bindingset` requirement on the constructor. */
499
- private class AnySpec extends TSpec {
500
- string toString ( ) { result = "Spec" }
501
- }
502
-
503
479
/**
504
480
* A constant that represents two positions: one position for when it's used as
505
481
* the _source_ of a sub-edge, and another position for when it's used as the
506
482
* _target_. Values include all the values of `Pos`, which resolve to
507
483
* themselves as both source and target, as well as two _around_ values and a
508
484
* _barrier_ value.
509
485
*/
510
- private class Spec extends AnySpec {
486
+ private class Spec extends Pos {
511
487
bindingset [ this ]
512
488
Spec ( ) { any ( ) }
513
489
514
- /** See Pos.isBefore. */
515
- predicate isBefore ( ) { this = SpecPos ( PosBefore ( ) ) }
516
-
517
- /** See Pos.isAt. */
518
- predicate isAt ( ) { this = SpecPos ( PosAt ( ) ) }
519
-
520
- /** See Pos.isAfter. */
521
- predicate isAfter ( ) { this = SpecPos ( PosAfter ( ) ) }
522
-
523
- /** See Pos.isBeforeDestructors. */
524
- predicate isBeforeDestructors ( ) { this = SpecPos ( PosBeforeDestructors ( ) ) }
525
-
526
- /** See Pos.isAfterDestructors. */
527
- predicate isAfterDestructors ( ) { this = SpecPos ( PosAfterDestructors ( ) ) }
528
-
529
490
/**
530
491
* Holds if this spec, when used on a node `n` between `(n1, p1)` and
531
492
* `(n2, p2)`, should add the following sub-edges.
532
493
*
533
494
* (n1, p1) ----> before(n)
534
495
* after(n) ----> (n2, p2)
535
496
*/
536
- predicate isAround ( ) { this = SpecAround ( ) }
497
+ predicate isAround ( ) { this = 5 }
537
498
538
499
/**
539
500
* Holds if this spec, when used on a node `n` between `(n1, p1)` and
@@ -542,16 +503,17 @@ private class Spec extends AnySpec {
542
503
* (n1, p1) ----> beforeDestructors(n)
543
504
* afterDestructors(n) ----> (n2, p2)
544
505
*/
545
- predicate isAroundDestructors ( ) { this = SpecAroundDestructors ( ) }
506
+ predicate isAroundDestructors ( ) { this = 6 }
546
507
547
508
/**
548
509
* Holds if this node is a _barrier_. A barrier resolves to no positions and
549
510
* can be inserted between nodes that should have no sub-edges between them.
550
511
*/
551
- predicate isBarrier ( ) { this = SpecBarrier ( ) }
512
+ predicate isBarrier ( ) { this = 7 }
552
513
553
514
Pos getSourcePos ( ) {
554
- this = SpecPos ( result )
515
+ this = [ 0 ..4 ] and
516
+ result = this
555
517
or
556
518
this .isAround ( ) and
557
519
result .isAfter ( )
@@ -561,7 +523,8 @@ private class Spec extends AnySpec {
561
523
}
562
524
563
525
Pos getTargetPos ( ) {
564
- this = SpecPos ( result )
526
+ this = [ 0 ..4 ] and
527
+ result = this
565
528
or
566
529
this .isAround ( ) and
567
530
result .isBefore ( )
0 commit comments