@@ -471,28 +471,17 @@ abstract class BTypes {
471
471
* - for an OBJECT type, the 'L' and ';' are not part of the range of the created Type
472
472
* - for an ARRAY type, the full descriptor is part of the range
473
473
*/
474
- def toASMType : asm.Type = this match {
475
- case UNIT => asm.Type .VOID_TYPE
476
- case BOOL => asm.Type .BOOLEAN_TYPE
477
- case CHAR => asm.Type .CHAR_TYPE
478
- case BYTE => asm.Type .BYTE_TYPE
479
- case SHORT => asm.Type .SHORT_TYPE
480
- case INT => asm.Type .INT_TYPE
481
- case FLOAT => asm.Type .FLOAT_TYPE
482
- case LONG => asm.Type .LONG_TYPE
483
- case DOUBLE => asm.Type .DOUBLE_TYPE
484
- case ClassBType (internalName) => asm.Type .getObjectType(internalName) // see (*) above
485
- case a : ArrayBType => asm.Type .getObjectType(a.descriptor)
486
- case m : MethodBType => asm.Type .getMethodType(m.descriptor)
487
- }
474
+ def toASMType : asm.Type
488
475
489
476
def asRefBType : RefBType = this .asInstanceOf [RefBType ]
490
477
def asArrayBType : ArrayBType = this .asInstanceOf [ArrayBType ]
491
478
def asClassBType : ClassBType = this .asInstanceOf [ClassBType ]
492
479
def asPrimitiveBType : PrimitiveBType = this .asInstanceOf [PrimitiveBType ]
493
480
}
494
481
495
- sealed abstract class PrimitiveBType (override val descriptor : String ) extends BType {
482
+ sealed abstract class PrimitiveBType (
483
+ override val descriptor : String ,
484
+ override val toASMType : asm.Type ) extends BType {
496
485
private [BTypes ] override def buildDescriptor (sb : java.lang.StringBuilder ): Unit = {
497
486
sb.append(descriptor)
498
487
}
@@ -560,15 +549,15 @@ abstract class BTypes {
560
549
}
561
550
}
562
551
563
- case object UNIT extends PrimitiveBType (" V" )
564
- case object BOOL extends PrimitiveBType (" Z" )
565
- case object CHAR extends PrimitiveBType (" C" )
566
- case object BYTE extends PrimitiveBType (" B" )
567
- case object SHORT extends PrimitiveBType (" S" )
568
- case object INT extends PrimitiveBType (" I" )
569
- case object FLOAT extends PrimitiveBType (" F" )
570
- case object LONG extends PrimitiveBType (" J" )
571
- case object DOUBLE extends PrimitiveBType (" D" )
552
+ case object UNIT extends PrimitiveBType (" V" ,asm. Type . VOID_TYPE )
553
+ case object BOOL extends PrimitiveBType (" Z" ,asm. Type . BOOLEAN_TYPE )
554
+ case object CHAR extends PrimitiveBType (" C" ,asm. Type . CHAR_TYPE )
555
+ case object BYTE extends PrimitiveBType (" B" ,asm. Type . BYTE_TYPE )
556
+ case object SHORT extends PrimitiveBType (" S" ,asm. Type . SHORT_TYPE )
557
+ case object INT extends PrimitiveBType (" I" ,asm. Type . INT_TYPE )
558
+ case object FLOAT extends PrimitiveBType (" F" ,asm. Type . FLOAT_TYPE )
559
+ case object LONG extends PrimitiveBType (" J" ,asm. Type . LONG_TYPE )
560
+ case object DOUBLE extends PrimitiveBType (" D" ,asm. Type . DOUBLE_TYPE )
572
561
573
562
sealed trait RefBType extends BType {
574
563
/**
@@ -863,6 +852,16 @@ abstract class BTypes {
863
852
descriptorCache = sb.substring(start)
864
853
} else sb.append(descriptorCache)
865
854
855
+
856
+ /**
857
+ * The asm.Type corresponding to this BType.
858
+ *
859
+ * Note about asm.Type.getObjectType (*): For class types, the method expects the internal
860
+ * name, i.e. without the surrounding 'L' and ';'.
861
+ */
862
+ override lazy val toASMType = asm.Type .getObjectType(internalName)
863
+
864
+
866
865
/**
867
866
* Write-once variable allows initializing a cyclic graph of infos. This is required for
868
867
* nested classes. Example: for the definition `class A { class B }` we have
@@ -1132,6 +1131,15 @@ abstract class BTypes {
1132
1131
descriptorCache = sb.substring(start)
1133
1132
} else sb.append(descriptorCache)
1134
1133
1134
+
1135
+ /**
1136
+ * For array types on the other hand, the method expects a full descriptor,
1137
+ * for example "[Ljava/lang/String;".
1138
+ *
1139
+ */
1140
+ override lazy val toASMType = asm.Type .getObjectType(descriptor)
1141
+
1142
+
1135
1143
def dimension : Int = componentType match {
1136
1144
case a : ArrayBType => 1 + a.dimension
1137
1145
case _ => 1
@@ -1163,6 +1171,8 @@ abstract class BTypes {
1163
1171
descriptorCache = sb.substring(start)
1164
1172
1165
1173
} else sb.append(descriptorCache)
1174
+
1175
+ override lazy val toASMType = asm.Type .getMethodType(descriptor)
1166
1176
}
1167
1177
1168
1178
/* Some definitions that are required for the implementation of BTypes. They are abstract because
0 commit comments