Skip to content

Commit 6ce73bd

Browse files
committed
Safely reuse pool
1 parent 90d4876 commit 6ce73bd

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class ClassfileParser(
111111
}
112112

113113
/** Return the class symbol of the given name. */
114-
def classNameToSymbol(name: Name)(using Context): Symbol = innerClasses.get(name) match {
114+
def classNameToSymbol(name: Name)(using Context, DataReader): Symbol = innerClasses.get(name) match {
115115
case Some(entry) => innerClasses.classSymbol(entry)
116116
case None => requiredClass(name)
117117
}
@@ -316,7 +316,7 @@ class ClassfileParser(
316316
case BOOL_TAG => defn.BooleanType
317317
}
318318

319-
private def sigToType(sig: String, owner: Symbol = null, isVarargs: Boolean = false)(using Context): Type = {
319+
private def sigToType(sig: String, owner: Symbol = null, isVarargs: Boolean = false)(using Context, DataReader): Type = {
320320
var index = 0
321321
val end = sig.length
322322
def accept(ch: Char): Unit = {
@@ -718,7 +718,7 @@ class ClassfileParser(
718718
/** Enter own inner classes in the right scope. It needs the scopes to be set up,
719719
* and implicitly current class' superclasses.
720720
*/
721-
private def enterOwnInnerClasses()(using Context): Unit = {
721+
private def enterOwnInnerClasses()(using Context, DataReader): Unit = {
722722
def enterClassAndModule(entry: InnerClassEntry, file: AbstractFile, jflags: Int) =
723723
SymbolLoaders.enterClassAndModule(
724724
getOwner(jflags),
@@ -921,20 +921,20 @@ class ClassfileParser(
921921
}
922922

923923
/** An entry in the InnerClasses attribute of this class file. */
924-
case class InnerClassEntry(external: Int, outer: Int, name: Int, jflags: Int) {
925-
def externalName: SimpleName = pool.getClassName(external).name
926-
def outerName: SimpleName = pool.getClassName(outer).name
927-
def originalName: SimpleName = pool.getName(name).name
924+
private case class InnerClassEntry(external: Int, outer: Int, name: Int, jflags: Int) {
925+
def externalName(using DataReader): SimpleName = pool.getClassName(external).name
926+
def outerName(using DataReader): SimpleName = pool.getClassName(outer).name
927+
def originalName(using DataReader): SimpleName = pool.getName(name).name
928928

929-
override def toString: String =
929+
def show(using DataReader): String =
930930
s"$originalName in $outerName($externalName)"
931931
}
932932

933-
object innerClasses extends util.HashMap[Name, InnerClassEntry] {
933+
private object innerClasses extends util.HashMap[Name, InnerClassEntry] {
934934
/** Return the Symbol of the top level class enclosing `name`,
935935
* or 'name's symbol if no entry found for `name`.
936936
*/
937-
def topLevelClass(name: Name)(using Context): Symbol = {
937+
def topLevelClass(name: Name)(using Context, DataReader): Symbol = {
938938
val tlName = if (contains(name)) {
939939
var entry = this(name)
940940
while (contains(entry.outerName))
@@ -949,7 +949,7 @@ class ClassfileParser(
949949
/** Return the class symbol for `entry`. It looks it up in its outer class.
950950
* This might force outer class symbols.
951951
*/
952-
def classSymbol(entry: InnerClassEntry)(using Context): Symbol = {
952+
def classSymbol(entry: InnerClassEntry)(using Context, DataReader): Symbol = {
953953
def getMember(sym: Symbol, name: Name)(using Context): Symbol =
954954
if (isStatic(entry.jflags))
955955
if (sym == classRoot.symbol)
@@ -1024,7 +1024,7 @@ class ClassfileParser(
10241024
}
10251025
}
10261026

1027-
def getClassSymbol(name: SimpleName)(using Context): Symbol =
1027+
def getClassSymbol(name: SimpleName)(using Context, DataReader): Symbol =
10281028
if (name.endsWith("$") && (name ne nme.nothingRuntimeClass) && (name ne nme.nullRuntimeClass))
10291029
// Null$ and Nothing$ ARE classes
10301030
requiredModule(name.dropRight(1))
@@ -1061,7 +1061,7 @@ class ClassfileParser(
10611061
}
10621062

10631063
/** Return the name found at given index. */
1064-
def getName(index: Int): NameOrString = {
1064+
def getName(index: Int)(using in: DataReader): NameOrString = {
10651065
if (index <= 0 || len <= index)
10661066
errorBadIndex(index)
10671067

@@ -1078,7 +1078,7 @@ class ClassfileParser(
10781078
}
10791079

10801080
/** Return the name found at given index in the constant pool, with '/' replaced by '.'. */
1081-
def getExternalName(index: Int): NameOrString = {
1081+
def getExternalName(index: Int)(using in: DataReader): NameOrString = {
10821082
if (index <= 0 || len <= index)
10831083
errorBadIndex(index)
10841084

@@ -1088,7 +1088,7 @@ class ClassfileParser(
10881088
internalized(index)
10891089
}
10901090

1091-
def getClassSymbol(index: Int)(using Context): Symbol = {
1091+
def getClassSymbol(index: Int)(using ctx: Context, in: DataReader): Symbol = {
10921092
if (index <= 0 || len <= index) errorBadIndex(index)
10931093
var c = values(index).asInstanceOf[Symbol]
10941094
if (c eq null) {
@@ -1104,7 +1104,7 @@ class ClassfileParser(
11041104
/** Return the external name of the class info structure found at 'index'.
11051105
* Use 'getClassSymbol' if the class is sure to be a top-level class.
11061106
*/
1107-
def getClassName(index: Int): NameOrString = {
1107+
def getClassName(index: Int)(using in: DataReader): NameOrString = {
11081108
val start = starts(index)
11091109
if (in.getByte(start).toInt != CONSTANT_CLASS) errorBadTag(start)
11101110
getExternalName(in.getChar(start + 1))
@@ -1114,7 +1114,7 @@ class ClassfileParser(
11141114
* arrays are considered to be class types, they might
11151115
* appear as entries in 'newarray' or 'cast' opcodes.
11161116
*/
1117-
def getClassOrArrayType(index: Int)(using Context): Type = {
1117+
def getClassOrArrayType(index: Int)(using ctx: Context, in: DataReader): Type = {
11181118
if (index <= 0 || len <= index) errorBadIndex(index)
11191119
val value = values(index)
11201120
var c: Type = null
@@ -1139,15 +1139,15 @@ class ClassfileParser(
11391139
c
11401140
}
11411141

1142-
def getType(index: Int, isVarargs: Boolean = false)(using Context): Type =
1142+
def getType(index: Int, isVarargs: Boolean = false)(using Context, DataReader): Type =
11431143
sigToType(getExternalName(index).value, isVarargs = isVarargs)
11441144

1145-
def getSuperClass(index: Int)(using Context): Symbol = {
1145+
def getSuperClass(index: Int)(using Context, DataReader): Symbol = {
11461146
assert(index != 0, "attempt to parse java.lang.Object from classfile")
11471147
getClassSymbol(index)
11481148
}
11491149

1150-
def getConstant(index: Int, pt: Type = WildcardType)(using Context): Constant = {
1150+
def getConstant(index: Int, pt: Type = WildcardType)(using ctx: Context, in: DataReader): Constant = {
11511151
if (index <= 0 || len <= index) errorBadIndex(index)
11521152
var value = values(index)
11531153
if (value eq null) {
@@ -1198,7 +1198,7 @@ class ClassfileParser(
11981198
arr
11991199
}
12001200

1201-
def getBytes(index: Int): Array[Byte] = {
1201+
def getBytes(index: Int)(using in: DataReader): Array[Byte] = {
12021202
if (index <= 0 || len <= index) errorBadIndex(index)
12031203
var value = values(index).asInstanceOf[Array[Byte]]
12041204
if (value eq null) {
@@ -1213,7 +1213,7 @@ class ClassfileParser(
12131213
value
12141214
}
12151215

1216-
def getBytes(indices: List[Int]): Array[Byte] = {
1216+
def getBytes(indices: List[Int])(using in: DataReader): Array[Byte] = {
12171217
assert(!indices.isEmpty, indices)
12181218
var value = values(indices.head).asInstanceOf[Array[Byte]]
12191219
if (value eq null) {
@@ -1234,11 +1234,11 @@ class ClassfileParser(
12341234
}
12351235

12361236
/** Throws an exception signaling a bad constant index. */
1237-
private def errorBadIndex(index: Int) =
1237+
private def errorBadIndex(index: Int)(using in: DataReader) =
12381238
throw new RuntimeException("bad constant pool index: " + index + " at pos: " + in.bp)
12391239

12401240
/** Throws an exception signaling a bad tag at given address. */
1241-
private def errorBadTag(start: Int) =
1241+
private def errorBadTag(start: Int)(using in: DataReader) =
12421242
throw new RuntimeException("bad constant pool tag " + in.getByte(start) + " at byte " + start)
12431243
}
12441244
}

0 commit comments

Comments
 (0)