@@ -10,16 +10,22 @@ private import Caching
1010 * equal modulo identity conversions and type parameters.
1111 */
1212module 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 ) {
1518 if not t instanceof NestedType or t .( NestedType ) .getDeclaringType ( ) instanceof GenericType
1619 then result = t .getName ( )
17- else result = getQualifiedName ( t .( NestedType ) .getDeclaringType ( ) ) + "." + t .getName ( )
20+ else result = getNameNested ( t .( NestedType ) .getDeclaringType ( ) ) + "." + t .getName ( )
1821 }
1922
2023 /**
2124 * A generic type. This is either a type with a type parameter, a type with
2225 * 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".
2329 */
2430 class GenericType extends Type {
2531 GenericType ( ) {
@@ -29,43 +35,43 @@ module Gvn {
2935 }
3036
3137 /** Gets the generic containing type, if any. */
32- GenericType getQualifier ( ) { result = this .( NestedType ) .getDeclaringType ( ) }
38+ GenericType getGenericDeclaringType ( ) { result = this .( NestedType ) .getDeclaringType ( ) }
3339
3440 /**
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
3642 * is no generic containing type.
3743 */
38- int getNumberOfQualifierChildrenExt ( ) {
39- result = this .getQualifier ( ) .getNumberOfChildrenExt ( )
44+ int getNumberOfDeclaringArguments ( ) {
45+ result = this .getGenericDeclaringType ( ) .getNumberOfArguments ( )
4046 or
41- not exists ( this .getQualifier ( ) ) and result = 0
47+ not exists ( this .getGenericDeclaringType ( ) ) and result = 0
4248 }
4349
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 ) }
4652
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 ( )
5056 }
5157
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 )
5561 or
5662 exists ( int offset |
57- offset = this .getNumberOfQualifierChildrenExt ( ) and
63+ offset = this .getNumberOfDeclaringArguments ( ) and
5864 result = this .getChild ( i - offset ) and
5965 i >= offset
6066 )
6167 }
6268
6369 /** 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
6773 or
68- not exists ( this .getQualifier ( ) ) and result = name
74+ not exists ( this .getGenericDeclaringType ( ) ) and result = name
6975 )
7076 }
7177 }
@@ -89,7 +95,7 @@ module Gvn {
8995 this = TArrayTypeKind ( _, _) and result = 1
9096 or
9197 exists ( GenericType t | this = TConstructedType ( t .getSourceDeclaration ( ) ) |
92- result = t .getNumberOfChildrenExt ( )
98+ result = t .getNumberOfArguments ( )
9399 )
94100 }
95101
@@ -117,7 +123,7 @@ module Gvn {
117123 string toString ( ) {
118124 result = this .toStringBuiltin ( "" )
119125 or
120- result = this .getConstructedSourceDeclaration ( ) .toStringExt ( )
126+ result = this .getConstructedSourceDeclaration ( ) .toStringNested ( )
121127 }
122128
123129 /** Gets the location of this kind. */
@@ -184,16 +190,16 @@ module Gvn {
184190 }
185191
186192 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 ) )
189195 }
190196
191197 pragma [ noinline]
192198 private predicate gvnConstructedCons (
193199 GenericType t , CompoundTypeKind k , int i , GvnType head , ConstructedGvnTypeList tail
194200 ) {
195201 tail = gvnConstructed ( t , k , i - 1 ) and
196- head = gvnTypeChildExt ( t , i )
202+ head = gvnTypeArgument ( t , i )
197203 }
198204
199205 private class ConstructedGvnTypeList extends TConstructedGvnTypeList {
@@ -229,11 +235,11 @@ module Gvn {
229235 */
230236 language [ monotonicAggregates]
231237 private string toStringConstructed ( GenericType t ) {
232- t = this .getKind ( ) .getConstructedSourceDeclaration ( ) .getQualifier * ( ) and
238+ t = this .getKind ( ) .getConstructedSourceDeclaration ( ) .getGenericDeclaringType * ( ) and
233239 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
237243 if children = 0
238244 then nameArgs = name
239245 else
@@ -249,7 +255,7 @@ module Gvn {
249255 |
250256 offset = 0 and result = nameArgs
251257 or
252- result = this .toStringConstructed ( t .getQualifier ( ) ) + "." + nameArgs
258+ result = this .toStringConstructed ( t .getGenericDeclaringType ( ) ) + "." + nameArgs
253259 )
254260 }
255261
0 commit comments