@@ -10,16 +10,22 @@ private import Caching
10
10
* equal modulo identity conversions and type parameters.
11
11
*/
12
12
module Gvn {
13
- /** Gets the qualified name of type `t`. */
14
- string getQualifiedName ( Type t ) {
13
+ /**
14
+ * Gets the name of type `t`, including the enclosing type of `t` as a qualifier,
15
+ * but only if the enclosing type is not a `GenericType`.
16
+ */
17
+ string getNameNested ( Type t ) {
15
18
if not t instanceof NestedType or t .( NestedType ) .getDeclaringType ( ) instanceof GenericType
16
19
then result = t .getName ( )
17
- else result = getQualifiedName ( t .( NestedType ) .getDeclaringType ( ) ) + "." + t .getName ( )
20
+ else result = getNameNested ( t .( NestedType ) .getDeclaringType ( ) ) + "." + t .getName ( )
18
21
}
19
22
20
23
/**
21
24
* A generic type. This is either a type with a type parameter, a type with
22
25
* a type argument, or a nested type with a generic enclosing type.
26
+ *
27
+ * In this class, type parameters and type arguments are collectively referred
28
+ * to as "arguments".
23
29
*/
24
30
class GenericType extends Type {
25
31
GenericType ( ) {
@@ -29,43 +35,43 @@ module Gvn {
29
35
}
30
36
31
37
/** Gets the generic containing type, if any. */
32
- GenericType getQualifier ( ) { result = this .( NestedType ) .getDeclaringType ( ) }
38
+ GenericType getGenericDeclaringType ( ) { result = this .( NestedType ) .getDeclaringType ( ) }
33
39
34
40
/**
35
- * Gets the number of children of the generic containing type, or 0 if there
41
+ * Gets the number of arguments of the generic containing type, or 0 if there
36
42
* is no generic containing type.
37
43
*/
38
- int getNumberOfQualifierChildrenExt ( ) {
39
- result = this .getQualifier ( ) .getNumberOfChildrenExt ( )
44
+ int getNumberOfDeclaringArguments ( ) {
45
+ result = this .getGenericDeclaringType ( ) .getNumberOfArguments ( )
40
46
or
41
- not exists ( this .getQualifier ( ) ) and result = 0
47
+ not exists ( this .getGenericDeclaringType ( ) ) and result = 0
42
48
}
43
49
44
- /** Gets the number of children of this type, not taking nested types into account. */
45
- int getNumberOfChildrenSelf ( ) { result = count ( int i | exists ( this .getChild ( i ) ) and i >= 0 ) }
50
+ /** Gets the number of arguments of this type, not taking nested types into account. */
51
+ int getNumberOfArgumentsSelf ( ) { result = count ( int i | exists ( this .getChild ( i ) ) and i >= 0 ) }
46
52
47
- /** Gets the number of children of this type, taking nested types into account. */
48
- int getNumberOfChildrenExt ( ) {
49
- result = this .getNumberOfQualifierChildrenExt ( ) + this .getNumberOfChildrenSelf ( )
53
+ /** Gets the number of arguments of this type, taking nested types into account. */
54
+ int getNumberOfArguments ( ) {
55
+ result = this .getNumberOfDeclaringArguments ( ) + this .getNumberOfArgumentsSelf ( )
50
56
}
51
57
52
- /** Gets the `i`th child of this type, taking nested types into account. */
53
- Type getChildExt ( int i ) {
54
- result = this .getQualifier ( ) .getChildExt ( i )
58
+ /** Gets the `i`th argument of this type, taking nested types into account. */
59
+ Type getArgument ( int i ) {
60
+ result = this .getGenericDeclaringType ( ) .getArgument ( i )
55
61
or
56
62
exists ( int offset |
57
- offset = this .getNumberOfQualifierChildrenExt ( ) and
63
+ offset = this .getNumberOfDeclaringArguments ( ) and
58
64
result = this .getChild ( i - offset ) and
59
65
i >= offset
60
66
)
61
67
}
62
68
63
69
/** Gets a textual representation of this type, taking nested types into account. */
64
- string toStringExt ( ) {
65
- exists ( string name | name = getQualifiedName ( this ) |
66
- result = this .getQualifier ( ) .toStringExt ( ) + "." + name
70
+ string toStringNested ( ) {
71
+ exists ( string name | name = getNameNested ( this ) |
72
+ result = this .getGenericDeclaringType ( ) .toStringNested ( ) + "." + name
67
73
or
68
- not exists ( this .getQualifier ( ) ) and result = name
74
+ not exists ( this .getGenericDeclaringType ( ) ) and result = name
69
75
)
70
76
}
71
77
}
@@ -89,7 +95,7 @@ module Gvn {
89
95
this = TArrayTypeKind ( _, _) and result = 1
90
96
or
91
97
exists ( GenericType t | this = TConstructedType ( t .getSourceDeclaration ( ) ) |
92
- result = t .getNumberOfChildrenExt ( )
98
+ result = t .getNumberOfArguments ( )
93
99
)
94
100
}
95
101
@@ -117,7 +123,7 @@ module Gvn {
117
123
string toString ( ) {
118
124
result = this .toStringBuiltin ( "" )
119
125
or
120
- result = this .getConstructedSourceDeclaration ( ) .toStringExt ( )
126
+ result = this .getConstructedSourceDeclaration ( ) .toStringNested ( )
121
127
}
122
128
123
129
/** Gets the location of this kind. */
@@ -184,16 +190,16 @@ module Gvn {
184
190
}
185
191
186
192
pragma [ noinline]
187
- private GvnType gvnTypeChildExt ( GenericType t , int i ) {
188
- result = getGlobalValueNumber ( t .getChildExt ( i ) )
193
+ private GvnType gvnTypeArgument ( GenericType t , int i ) {
194
+ result = getGlobalValueNumber ( t .getArgument ( i ) )
189
195
}
190
196
191
197
pragma [ noinline]
192
198
private predicate gvnConstructedCons (
193
199
GenericType t , CompoundTypeKind k , int i , GvnType head , ConstructedGvnTypeList tail
194
200
) {
195
201
tail = gvnConstructed ( t , k , i - 1 ) and
196
- head = gvnTypeChildExt ( t , i )
202
+ head = gvnTypeArgument ( t , i )
197
203
}
198
204
199
205
private class ConstructedGvnTypeList extends TConstructedGvnTypeList {
@@ -229,11 +235,11 @@ module Gvn {
229
235
*/
230
236
language [ monotonicAggregates]
231
237
private string toStringConstructed ( GenericType t ) {
232
- t = this .getKind ( ) .getConstructedSourceDeclaration ( ) .getQualifier * ( ) and
238
+ t = this .getKind ( ) .getConstructedSourceDeclaration ( ) .getGenericDeclaringType * ( ) and
233
239
exists ( int offset , int children , string name , string nameArgs |
234
- offset = t .getNumberOfQualifierChildrenExt ( ) and
235
- children = t .getNumberOfChildrenSelf ( ) and
236
- name = getQualifiedName ( t ) and
240
+ offset = t .getNumberOfDeclaringArguments ( ) and
241
+ children = t .getNumberOfArgumentsSelf ( ) and
242
+ name = getNameNested ( t ) and
237
243
if children = 0
238
244
then nameArgs = name
239
245
else
@@ -249,7 +255,7 @@ module Gvn {
249
255
|
250
256
offset = 0 and result = nameArgs
251
257
or
252
- result = this .toStringConstructed ( t .getQualifier ( ) ) + "." + nameArgs
258
+ result = this .toStringConstructed ( t .getGenericDeclaringType ( ) ) + "." + nameArgs
253
259
)
254
260
}
255
261
0 commit comments