@@ -51,7 +51,7 @@ private boolean isTargetThis(Expr e) {
51
51
result = false and not e .( MemberAccess ) .targetIsThisInstance ( )
52
52
}
53
53
54
- /** Gets the AST node kind of element `cfe` wrapped in the GvnKind type. */
54
+ /** Gets the AST node kind of element `cfe` wrapped in the ` GvnKind` type. */
55
55
private GvnKind getKind ( ControlFlowElement cfe ) {
56
56
exists ( int kind |
57
57
expressions ( cfe , kind , _) and
@@ -72,33 +72,21 @@ private class ConstantGvn extends Gvn, TConstantGvn {
72
72
override string toString ( ) { this = TConstantGvn ( result ) }
73
73
}
74
74
75
- private class ListGvn extends Gvn , TListGvn {
76
- private GvnList l ;
77
-
78
- ListGvn ( ) { this = TListGvn ( l ) }
79
-
80
- override string toString ( ) { result = "[" + l .toString ( ) + "]" }
81
- }
82
-
83
- abstract private class GvnList extends TGvnList {
84
- abstract string toString ( ) ;
85
- }
86
-
87
- private class GvnNil extends GvnList , TGvnNil {
75
+ private class GvnBase extends Gvn , TGvnBase {
88
76
private GvnKind kind ;
89
77
90
- GvnNil ( ) { this = TGvnNil ( kind ) }
78
+ GvnBase ( ) { this = TGvnBase ( kind ) }
91
79
92
80
override string toString ( ) { result = "(kind:" + kind + ")" }
93
81
}
94
82
95
- private class GvnCons extends GvnList , TGvnCons {
83
+ private class GvnStruct extends Gvn , TGvnStruct {
96
84
private Gvn head ;
97
- private GvnList tail ;
85
+ private Gvn tail ;
98
86
99
- GvnCons ( ) { this = TGvnCons ( head , tail ) }
87
+ GvnStruct ( ) { this = TGvnStruct ( head , tail ) }
100
88
101
- override string toString ( ) { result = head .toString ( ) + " :: " + tail .toString ( ) }
89
+ override string toString ( ) { result = "(" + head .toString ( ) + " :: " + tail .toString ( ) + ")" }
102
90
}
103
91
104
92
/**
@@ -118,14 +106,14 @@ private GvnKind getGvnKind(ControlFlowElement cfe) {
118
106
)
119
107
}
120
108
121
- private GvnList gvnConstructed ( ControlFlowElement cfe , GvnKind kind , int index ) {
109
+ private Gvn gvnConstructed ( ControlFlowElement cfe , GvnKind kind , int index ) {
122
110
kind = getGvnKind ( cfe ) and
123
- result = TGvnNil ( kind ) and
111
+ result = TGvnBase ( kind ) and
124
112
index = - 1
125
113
or
126
- exists ( Gvn head , GvnList tail |
127
- gvnConstructedCons ( cfe , kind , index , head , tail ) and
128
- result = TGvnCons ( head , tail )
114
+ exists ( Gvn head , Gvn tail |
115
+ gvnConstructedStruct ( cfe , kind , index , head , tail ) and
116
+ result = TGvnStruct ( head , tail )
129
117
)
130
118
}
131
119
@@ -155,8 +143,8 @@ private Gvn gvnChild(ControlFlowElement cfe, int index) {
155
143
}
156
144
157
145
pragma [ noinline]
158
- private predicate gvnConstructedCons (
159
- ControlFlowElement cfe , GvnKind kind , int index , Gvn head , GvnList tail
146
+ private predicate gvnConstructedStruct (
147
+ ControlFlowElement cfe , GvnKind kind , int index , Gvn head , Gvn tail
160
148
) {
161
149
tail = gvnConstructed ( cfe , kind , index - 1 ) and
162
150
head = gvnChild ( cfe , index )
@@ -176,23 +164,14 @@ private module Cached {
176
164
177
165
/**
178
166
* Type for containing the global value number of a control flow element.
179
- * A global value number, can either be a constant or a list of global value numbers,
180
- * where the list also carries a `kind`, which is used to distinguish between general expressions,
181
- * declarations and statements.
167
+ * A global value number, can either be a constant, a kind or a structure containing multiple global value numbers.
168
+ * The construction of the type produces a list like structure.
182
169
*/
183
170
cached
184
171
newtype TGvn =
185
172
TConstantGvn ( string s ) { s = any ( Expr e ) .getValue ( ) } or
186
- TListGvn ( GvnList l )
187
-
188
- /**
189
- * Type for containing a list of global value numbers with a kind.
190
- * The empty list carries the kind of the controlflowelement.
191
- */
192
- cached
193
- newtype TGvnList =
194
- TGvnNil ( GvnKind gkind ) or
195
- TGvnCons ( Gvn head , GvnList tail ) { gvnConstructedCons ( _, _, _, head , tail ) }
173
+ TGvnBase ( GvnKind gkind ) or
174
+ TGvnStruct ( Gvn head , Gvn tail ) { gvnConstructedStruct ( _, _, _, head , tail ) }
196
175
}
197
176
198
177
private import Cached
@@ -203,10 +182,9 @@ Gvn toGvn(ControlFlowElement cfe) {
203
182
result = TConstantGvn ( cfe .( Expr ) .getValue ( ) )
204
183
or
205
184
not exists ( cfe .( Expr ) .getValue ( ) ) and
206
- exists ( GvnList l , GvnKind kind , int index |
207
- l = gvnConstructed ( cfe , kind , index - 1 ) and
208
- index = getNumberOfActualChildren ( cfe ) and
209
- result = TListGvn ( l )
185
+ exists ( GvnKind kind , int index |
186
+ result = gvnConstructed ( cfe , kind , index - 1 ) and
187
+ index = getNumberOfActualChildren ( cfe )
210
188
)
211
189
}
212
190
0 commit comments