Skip to content

Commit 5a2c54a

Browse files
committed
Minor changes in InsertExpression
1 parent 6791207 commit 5a2c54a

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

compiler/src/dotty/tools/debug/InsertExpression.scala

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private class InsertExpression(config: ExpressionCompilerConfig) extends Phase:
2929

3030
// TODO move reflection methods (callMethod, getField, etc) to scala3-library
3131
// under scala.runtime (or scala.debug?) to avoid recompiling them again and again
32-
private val evaluationClassSource =
32+
private val expressionClassSource =
3333
s"""|class ${config.expressionClassName}(thisObject: Any, names: Array[String], values: Array[Any]) {
3434
| import java.lang.reflect.InvocationTargetException
3535
| val classLoader = getClass.getClassLoader
@@ -122,10 +122,10 @@ private class InsertExpression(config: ExpressionCompilerConfig) extends Phase:
122122
|""".stripMargin
123123

124124
override def run(using Context): Unit =
125-
val inserter = Inserter(parseExpression, parseEvaluationClass)
125+
val inserter = Inserter(parseExpression, parseExpressionClass)
126126
ctx.compilationUnit.untpdTree = inserter.transform(ctx.compilationUnit.untpdTree)
127127

128-
class Inserter(expression: Tree, expressionClass: Seq[Tree]) extends UntypedTreeMap:
128+
private class Inserter(expression: Tree, expressionClass: Seq[Tree]) extends UntypedTreeMap:
129129
override def transform(tree: Tree)(using Context): Tree =
130130
tree match
131131
case tree: PackageDef =>
@@ -181,9 +181,7 @@ private class InsertExpression(config: ExpressionCompilerConfig) extends Phase:
181181
new VirtualFile("<wrapped-expression>", contentBytes)
182182
val sourceFile =
183183
new SourceFile(wrappedExpressionFile, wrappedExpression.toArray):
184-
override def start: Int =
185-
// prefix.size depends on the OS
186-
-prefix.size
184+
override def start: Int = -prefix.size
187185
override def underlying: SourceFile = expressionFile
188186
override def atSpan(span: Span): SourcePosition =
189187
if (span.exists) SourcePosition(this, span)
@@ -198,9 +196,8 @@ private class InsertExpression(config: ExpressionCompilerConfig) extends Phase:
198196
.body
199197
.head
200198

201-
private def parseEvaluationClass(using Context): Seq[Tree] =
202-
val sourceFile =
203-
SourceFile.virtual("<evaluation class>", evaluationClassSource)
199+
private def parseExpressionClass(using Context): Seq[Tree] =
200+
val sourceFile = SourceFile.virtual("<expression class>", expressionClassSource)
204201
parse(sourceFile).asInstanceOf[PackageDef].stats
205202

206203
private def parse(sourceFile: SourceFile)(using Context): Tree =
@@ -233,4 +230,4 @@ private class InsertExpression(config: ExpressionCompilerConfig) extends Phase:
233230
else report.warning(msg, srcPos)
234231

235232
private object InsertExpression:
236-
val name: String = "insert-expression"
233+
val name: String = "insertExpression"

0 commit comments

Comments
 (0)