@@ -250,7 +250,7 @@ private module Gvn {
250250
251251 private class LeafType extends Type {
252252 LeafType ( ) {
253- not exists ( this . getAChild ( ) ) and
253+ not this instanceof Unification :: GenericType and
254254 not this instanceof MethodTypeParameter and
255255 not this instanceof DynamicType
256256 }
@@ -267,7 +267,9 @@ private module Gvn {
267267 gvnConstructedCons ( _, _, _, head , tail )
268268 }
269269
270- private ConstructedGvnTypeList gvnConstructed ( Type t , Unification:: CompoundTypeKind k , int i ) {
270+ private ConstructedGvnTypeList gvnConstructed (
271+ Unification:: GenericType t , Unification:: CompoundTypeKind k , int i
272+ ) {
271273 result = TConstructedGvnTypeNil ( k ) and
272274 i = - 1 and
273275 k = Unification:: getTypeKind ( t )
@@ -278,14 +280,17 @@ private module Gvn {
278280 }
279281
280282 pragma [ noinline]
281- private GvnType gvnTypeChild ( Type t , int i ) { result = getGlobalValueNumber ( t .getChild ( i ) ) }
283+ private GvnType gvnTypeChildExt ( Unification:: GenericType t , int i ) {
284+ result = getGlobalValueNumber ( t .getChildExt ( i ) )
285+ }
282286
283287 pragma [ noinline]
284288 private predicate gvnConstructedCons (
285- Type t , Unification:: CompoundTypeKind k , int i , GvnType head , ConstructedGvnTypeList tail
289+ Unification:: GenericType t , Unification:: CompoundTypeKind k , int i , GvnType head ,
290+ ConstructedGvnTypeList tail
286291 ) {
287292 tail = gvnConstructed ( t , k , i - 1 ) and
288- head = gvnTypeChild ( t , i )
293+ head = gvnTypeChildExt ( t , i )
289294 }
290295
291296 /** Gets the global value number for a given type. */
@@ -319,6 +324,8 @@ private module Gvn {
319324 }
320325
321326 private class ConstructedGvnTypeList extends TConstructedGvnTypeList {
327+ Unification:: CompoundTypeKind getKind ( ) { this = gvnConstructed ( _, result , _) }
328+
322329 private int length ( ) {
323330 this = TConstructedGvnTypeNil ( _) and result = - 1
324331 or
@@ -338,17 +345,38 @@ private module Gvn {
338345 )
339346 }
340347
348+ language [ monotonicAggregates]
349+ private string toString ( Unification:: GenericType t ) {
350+ t = this .getKind ( ) .getConstructedSourceDeclaration ( ) .getQualifier * ( ) and
351+ exists ( int offset , int children , string name , string nameArgs |
352+ offset = t .getNumberOfQualifierChildrenExt ( ) and
353+ children = t .getNumberOfChildrenSelf ( ) and
354+ name = Unification:: getQualifiedName ( t ) and
355+ if children = 0
356+ then nameArgs = name
357+ else
358+ exists ( string offsetArgs |
359+ offsetArgs =
360+ concat ( int i |
361+ i in [ offset .. offset + children - 1 ]
362+ |
363+ this .getArg ( i ) .toString ( ) , "," order by i
364+ ) and
365+ nameArgs = name .prefix ( name .length ( ) - children - 1 ) + "<" + offsetArgs + ">"
366+ )
367+ |
368+ offset = 0 and result = nameArgs
369+ or
370+ result = this .toString ( t .getQualifier ( ) ) + "." + nameArgs
371+ )
372+ }
373+
341374 language [ monotonicAggregates]
342375 string toString ( ) {
343- exists ( Unification:: CompoundTypeKind k , string args |
344- this = gvnConstructed ( _, k , _) and
345- args =
346- concat ( int i |
347- i in [ 0 .. k .getNumberOfTypeParameters ( ) - 1 ]
348- |
349- this .getArg ( i ) .toString ( ) , "," order by i
350- ) and
351- result = k .toString ( args )
376+ exists ( Unification:: CompoundTypeKind k | k = this .getKind ( ) |
377+ result = k .toString ( this .getArg ( 0 ) .toString ( ) )
378+ or
379+ result = this .toString ( k .getConstructedSourceDeclaration ( ) )
352380 )
353381 }
354382
0 commit comments