@@ -95,7 +95,7 @@ abstract class ClassfileParser {
95
95
private def readMethodFlags () = JavaAccFlags methodFlags u2
96
96
private def readFieldFlags () = JavaAccFlags fieldFlags u2
97
97
private def readTypeName () = readName().toTypeName
98
- private def readName () = pool getName u2
98
+ private def readName () = pool. getName(u2).name
99
99
private def readType () = pool getType u2
100
100
101
101
private object unpickler extends scala.reflect.internal.pickling.UnPickler {
@@ -175,7 +175,7 @@ abstract class ClassfileParser {
175
175
protected val len = u2
176
176
protected val starts = new Array [Int ](len)
177
177
protected val values = new Array [AnyRef ](len)
178
- protected val internalized = new Array [Name ](len)
178
+ protected val internalized = new Array [NameOrString ](len)
179
179
180
180
{ var i = 1
181
181
while (i < starts.length) {
@@ -206,28 +206,35 @@ abstract class ClassfileParser {
206
206
else this errorBadTag start
207
207
}
208
208
209
+ class NameOrString (val value : String ) {
210
+ private var _name : Name = null
211
+ def name : Name = {
212
+ if (_name eq null ) _name = TermName (value)
213
+ _name
214
+ }
215
+ }
209
216
/** Return the name found at given index. */
210
- def getName (index : Int ): Name = (
217
+ def getName (index : Int ): NameOrString = (
211
218
if (index <= 0 || len <= index) errorBadIndex(index)
212
219
else values(index) match {
213
- case name : Name => name
220
+ case name : NameOrString => name
214
221
case _ =>
215
222
val start = firstExpecting(index, CONSTANT_UTF8 )
216
223
val len = in.getChar(start).toInt
217
- recordAtIndex(TermName (fromMUTF8(in.buf, start, len + 2 )), index)
224
+ recordAtIndex(new NameOrString (fromMUTF8(in.buf, start, len + 2 )), index)
218
225
}
219
226
)
220
227
221
228
private def fromMUTF8 (bytes : Array [Byte ], offset : Int , len : Int ): String =
222
229
new DataInputStream (new ByteArrayInputStream (bytes, offset, len)).readUTF
223
230
224
231
/** Return the name found at given index in the constant pool, with '/' replaced by '.'. */
225
- def getExternalName (index : Int ): Name = {
232
+ def getExternalName (index : Int ): NameOrString = {
226
233
if (index <= 0 || len <= index)
227
234
errorBadIndex(index)
228
235
229
236
if (internalized(index) == null )
230
- internalized(index) = getName(index).replace('/' , '.' )
237
+ internalized(index) = new NameOrString ( getName(index).value. replace('/' , '.' ) )
231
238
232
239
internalized(index)
233
240
}
@@ -237,7 +244,7 @@ abstract class ClassfileParser {
237
244
values(index) match {
238
245
case sym : Symbol => sym
239
246
case _ =>
240
- val result = getClassName(index) match {
247
+ val result = getClassName(index).name match {
241
248
case name if nme.isModuleName(name) => rootMirror getModuleByName name.dropModule
242
249
case name => classNameToSymbol(name)
243
250
}
@@ -248,7 +255,7 @@ abstract class ClassfileParser {
248
255
/** Return the external name of the class info structure found at 'index'.
249
256
* Use 'getClassSymbol' if the class is sure to be a top-level class.
250
257
*/
251
- def getClassName (index : Int ): Name = {
258
+ def getClassName (index : Int ): NameOrString = {
252
259
val start = firstExpecting(index, CONSTANT_CLASS )
253
260
getExternalName((in getChar start).toInt)
254
261
}
@@ -267,14 +274,14 @@ abstract class ClassfileParser {
267
274
val start = firstExpecting(index, CONSTANT_NAMEANDTYPE )
268
275
val name = getName(in.getChar(start).toInt)
269
276
// create a dummy symbol for method types
270
- val dummy = ownerTpe.typeSymbol.newMethod(name.toTermName, ownerTpe.typeSymbol.pos)
277
+ val dummy = ownerTpe.typeSymbol.newMethod(name.name. toTermName, ownerTpe.typeSymbol.pos)
271
278
val tpe = getType(dummy, in.getChar(start + 2 ).toInt)
272
279
// fix the return type, which is blindly set to the class currently parsed
273
280
val restpe = tpe match {
274
- case MethodType (formals, _) if name == nme.CONSTRUCTOR => MethodType (formals, ownerTpe)
275
- case _ => tpe
281
+ case MethodType (formals, _) if name.name == nme.CONSTRUCTOR => MethodType (formals, ownerTpe)
282
+ case _ => tpe
276
283
}
277
- ((name, restpe))
284
+ ((name.name , restpe))
278
285
}
279
286
}
280
287
@@ -289,21 +296,21 @@ abstract class ClassfileParser {
289
296
case cls : Symbol => cls.tpe_*
290
297
case _ =>
291
298
val name = getClassName(index)
292
- name charAt 0 match {
293
- case ARRAY_TAG => recordAtIndex(sigToType(null , name), index)
294
- case _ => recordAtIndex(classNameToSymbol(name), index).tpe_*
299
+ name.value. charAt( 0 ) match {
300
+ case ARRAY_TAG => recordAtIndex(sigToType(null , name.value ), index)
301
+ case _ => recordAtIndex(classNameToSymbol(name.name ), index).tpe_*
295
302
}
296
303
}
297
304
}
298
305
299
306
def getType (index : Int ): Type = getType(null , index)
300
- def getType (sym : Symbol , index : Int ): Type = sigToType(sym, getExternalName(index))
307
+ def getType (sym : Symbol , index : Int ): Type = sigToType(sym, getExternalName(index).value )
301
308
def getSuperClass (index : Int ): Symbol = if (index == 0 ) AnyClass else getClassSymbol(index) // the only classfile that is allowed to have `0` in the super_class is java/lang/Object (see jvm spec)
302
309
303
310
private def createConstant (index : Int ): Constant = {
304
311
val start = starts(index)
305
312
Constant ((in.buf(start).toInt: @ switch) match {
306
- case CONSTANT_STRING => getName(in.getChar(start + 1 ).toInt).toString
313
+ case CONSTANT_STRING => getName(in.getChar(start + 1 ).toInt).value
307
314
case CONSTANT_INTEGER => in.getInt(start + 1 )
308
315
case CONSTANT_FLOAT => in.getFloat(start + 1 )
309
316
case CONSTANT_LONG => in.getLong(start + 1 )
@@ -451,7 +458,7 @@ abstract class ClassfileParser {
451
458
452
459
val jflags = readClassFlags()
453
460
val classNameIndex = u2
454
- currentClass = pool.getClassName(classNameIndex)
461
+ currentClass = pool.getClassName(classNameIndex).name
455
462
456
463
// Ensure that (top-level) classfiles are in the correct directory
457
464
val isTopLevel = ! (currentClass containsChar '$' ) // Java class name; *don't* try to to use Scala name decoding (scala/bug#7532)
@@ -650,7 +657,8 @@ abstract class ClassfileParser {
650
657
}
651
658
}
652
659
653
- private def sigToType (sym : Symbol , sig : Name ): Type = {
660
+ private def sigToType (sym : Symbol , sig : String ): Type = {
661
+ val sigChars = sig.toCharArray
654
662
var index = 0
655
663
val end = sig.length
656
664
def accept (ch : Char ): Unit = {
@@ -660,7 +668,7 @@ abstract class ClassfileParser {
660
668
def subName (isDelimiter : Char => Boolean ): Name = {
661
669
val start = index
662
670
while (! isDelimiter(sig.charAt(index))) { index += 1 }
663
- sig.subName( start, index)
671
+ newTermName(sigChars, start, index - start )
664
672
}
665
673
def sig2type (tparams : immutable.Map [Name ,Symbol ], skiptvs : Boolean ): Type = {
666
674
val tag = sig.charAt(index); index += 1
@@ -842,7 +850,7 @@ abstract class ClassfileParser {
842
850
attrName match {
843
851
case tpnme.SignatureATTR =>
844
852
val sig = pool.getExternalName(u2)
845
- val newType = sigToType(sym, sig)
853
+ val newType = sigToType(sym, sig.value )
846
854
sym.setInfo(newType)
847
855
848
856
case tpnme.SyntheticATTR =>
@@ -879,7 +887,7 @@ abstract class ClassfileParser {
879
887
val access = u2
880
888
881
889
val name =
882
- if ((access & ACC_SYNTHETIC ) == 0 ) rawname.encode
890
+ if ((access & ACC_SYNTHETIC ) == 0 ) rawname.name. encode
883
891
else nme.NO_NAME
884
892
885
893
paramNames += name
@@ -985,7 +993,7 @@ abstract class ClassfileParser {
985
993
val index = u2
986
994
tag match {
987
995
case STRING_TAG =>
988
- Some (LiteralAnnotArg (Constant (pool.getName(index).toString )))
996
+ Some (LiteralAnnotArg (Constant (pool.getName(index).value )))
989
997
case BOOL_TAG | BYTE_TAG | CHAR_TAG | SHORT_TAG | INT_TAG |
990
998
LONG_TAG | FLOAT_TAG | DOUBLE_TAG =>
991
999
Some (LiteralAnnotArg (pool.getConstant(index)))
@@ -1259,9 +1267,9 @@ abstract class ClassfileParser {
1259
1267
1260
1268
/** An entry in the InnerClasses attribute of this class file. */
1261
1269
case class InnerClassEntry (external : Int , outer : Int , name : Int , jflags : JavaAccFlags ) {
1262
- def externalName = pool getClassName external
1263
- def outerName = pool getClassName outer
1264
- def originalName = pool getName name
1270
+ def externalName = pool. getClassName( external).name
1271
+ def outerName = pool. getClassName( outer).name
1272
+ def originalName = pool. getName(name). name
1265
1273
def isModule = originalName.isTermName
1266
1274
def scope = if (jflags.isStatic) staticScope else instanceScope
1267
1275
def enclosing = if (jflags.isStatic) enclModule else enclClass
0 commit comments