@@ -16,7 +16,7 @@ import scala.collection.mutable.{ArrayBuffer, ListBuffer}
16
16
import scala .annotation .switch
17
17
import scala .reflect .internal .JavaAccFlags
18
18
import scala .reflect .internal .pickling .{ByteCodecs , PickleBuffer }
19
- import scala .reflect .io .NoAbstractFile
19
+ import scala .reflect .io .{ NoAbstractFile , VirtualFile }
20
20
import scala .reflect .internal .util .Collections ._
21
21
import scala .tools .nsc .util .ClassPath
22
22
import scala .tools .nsc .io .AbstractFile
@@ -171,6 +171,8 @@ abstract class ClassfileParser {
171
171
protected val values = new Array [AnyRef ](len)
172
172
protected val internalized = new Array [NameOrString ](len)
173
173
174
+ private val initBp = in.bp
175
+
174
176
{ var i = 1
175
177
while (i < starts.length) {
176
178
starts(i) = in.bp
@@ -187,6 +189,7 @@ abstract class ClassfileParser {
187
189
}
188
190
}
189
191
}
192
+ private val in1 : AbstractFileReader = new AbstractFileReader (java.util.Arrays .copyOfRange(in.buf, initBp, in.bp))
190
193
191
194
def recordAtIndex [T <: AnyRef ](value : T , idx : Int ): T = {
192
195
values(idx) = value
@@ -195,12 +198,12 @@ abstract class ClassfileParser {
195
198
196
199
def firstExpecting (index : Int , expected : Int ): Int = {
197
200
val start = starts(index)
198
- val first = in .buf(start).toInt
201
+ val first = in1 .buf(start - initBp ).toInt
199
202
if (first == expected) start + 1
200
203
else this errorBadTag start
201
204
}
202
205
203
- class NameOrString (val value : String ) {
206
+ class NameOrString (val value : String ) { // TODO encode this as Name | String
204
207
private var _name : Name = null
205
208
def name : Name = {
206
209
if (_name eq null ) _name = TermName (value)
@@ -214,8 +217,8 @@ abstract class ClassfileParser {
214
217
case name : NameOrString => name
215
218
case _ =>
216
219
val start = firstExpecting(index, CONSTANT_UTF8 )
217
- val len = in .getChar(start).toInt
218
- recordAtIndex(new NameOrString (fromMUTF8(in .buf, start, len + 2 )), index)
220
+ val len = in1 .getChar(start - initBp ).toInt
221
+ recordAtIndex(new NameOrString (fromMUTF8(in1 .buf, start - initBp , len + 2 )), index)
219
222
}
220
223
)
221
224
@@ -251,7 +254,7 @@ abstract class ClassfileParser {
251
254
*/
252
255
def getClassName (index : Int ): NameOrString = {
253
256
val start = firstExpecting(index, CONSTANT_CLASS )
254
- getExternalName((in getChar start).toInt)
257
+ getExternalName((in1. getChar( start - initBp) ).toInt)
255
258
}
256
259
257
260
/** Return a name and a type at the given index. If the type is a method
@@ -266,10 +269,10 @@ abstract class ClassfileParser {
266
269
case p : ((Name @ unchecked, Type @ unchecked)) => p
267
270
case _ =>
268
271
val start = firstExpecting(index, CONSTANT_NAMEANDTYPE )
269
- val name = getName(in .getChar(start).toInt)
272
+ val name = getName(in1 .getChar(start - initBp ).toInt)
270
273
// create a dummy symbol for method types
271
274
val dummy = ownerTpe.typeSymbol.newMethod(name.name.toTermName, ownerTpe.typeSymbol.pos)
272
- val tpe = getType(dummy, in .getChar(start + 2 ).toInt)
275
+ val tpe = getType(dummy, in1 .getChar(start + 2 - initBp ).toInt)
273
276
// fix the return type, which is blindly set to the class currently parsed
274
277
val restpe = tpe match {
275
278
case MethodType (formals, _) if name == nme.CONSTRUCTOR => MethodType (formals, ownerTpe)
@@ -303,12 +306,12 @@ abstract class ClassfileParser {
303
306
304
307
private def createConstant (index : Int ): Constant = {
305
308
val start = starts(index)
306
- Constant ((in .buf(start).toInt: @ switch) match {
307
- case CONSTANT_STRING => getName(in .getChar(start + 1 ).toInt).value
308
- case CONSTANT_INTEGER => in .getInt(start + 1 )
309
- case CONSTANT_FLOAT => in .getFloat(start + 1 )
310
- case CONSTANT_LONG => in .getLong(start + 1 )
311
- case CONSTANT_DOUBLE => in .getDouble(start + 1 )
309
+ Constant ((in1 .buf(start - initBp ).toInt: @ switch) match {
310
+ case CONSTANT_STRING => getName(in1 .getChar(start + 1 - initBp ).toInt).value
311
+ case CONSTANT_INTEGER => in1 .getInt(start + 1 - initBp )
312
+ case CONSTANT_FLOAT => in1 .getFloat(start + 1 - initBp )
313
+ case CONSTANT_LONG => in1 .getLong(start + 1 - initBp )
314
+ case CONSTANT_DOUBLE => in1 .getDouble(start + 1 - initBp )
312
315
case CONSTANT_CLASS => getClassOrArrayType(index).typeSymbol.tpe_* // !!! Is this necessary or desirable?
313
316
case _ => errorBadTag(start)
314
317
})
0 commit comments