diff options
-rw-r--r-- | src/compiler/scala/reflect/runtime/ToolBoxes.scala | 24 | ||||
-rw-r--r-- | src/partest/scala/tools/partest/utils/CodeTest.scala | 5 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/compiler/scala/reflect/runtime/ToolBoxes.scala b/src/compiler/scala/reflect/runtime/ToolBoxes.scala index 9b0f8a33b4..8713ef01b7 100644 --- a/src/compiler/scala/reflect/runtime/ToolBoxes.scala +++ b/src/compiler/scala/reflect/runtime/ToolBoxes.scala @@ -14,6 +14,7 @@ import scala.tools.nsc.util.FreshNameCreator import scala.reflect.internal.Flags import scala.tools.nsc.util.NoSourceFile import java.lang.{Class => jClass} +import scala.tools.nsc.util.trace trait ToolBoxes extends { self: Universe => @@ -46,7 +47,7 @@ trait ToolBoxes extends { self: Universe => } def compileExpr(expr: Tree, fvs: List[Symbol]): String = { - val cdef = wrapInClass(expr, fvs) + val cdef = trace("wrapped: ")(wrapInClass(expr, fvs)) val unit = wrapInCompilationUnit(cdef) val run = new Run run.compileUnits(List(unit), run.namerPhase) @@ -78,14 +79,18 @@ trait ToolBoxes extends { self: Universe => lazy val classLoader = new AbstractFileClassLoader(virtualDirectory, getClass.getClassLoader) - - def typeCheck(tree: rm.Tree, expectedType: rm.Type): rm.Tree = { - if (compiler.settings.verbose.value) println("typing "+tree+", pt = "+expectedType) - val run = new compiler.Run - compiler.phase = run.refchecksPhase + private def importAndTypeCheck(tree: rm.Tree, expectedType: rm.Type): compiler.Tree = { val ctree: compiler.Tree = importer.importTree(tree.asInstanceOf[Tree]) val pt: compiler.Type = importer.importType(expectedType.asInstanceOf[Type]) + val run = new compiler.Run + compiler.phase = run.refchecksPhase val ttree: compiler.Tree = compiler.typer.typed(ctree, compiler.analyzer.EXPRmode, pt) + ttree + } + + def typeCheck(tree: rm.Tree, expectedType: rm.Type): rm.Tree = { + if (compiler.settings.verbose.value) println("typing "+tree+", pt = "+expectedType) + val ttree = importAndTypeCheck(tree, expectedType) exporter.importTree(ttree).asInstanceOf[rm.Tree] } @@ -100,5 +105,12 @@ trait ToolBoxes extends { self: Universe => } finally compiler.settings.printtypes.value = saved } + + def runExpr(tree: rm.Tree, expectedType: rm.Type): Any = { + val ttree = importAndTypeCheck(tree, expectedType) + compiler.runExpr(ttree) + } + + def runExpr(tree: rm.Tree): Any = runExpr(tree, WildcardType.asInstanceOf[rm.Type]) } }
\ No newline at end of file diff --git a/src/partest/scala/tools/partest/utils/CodeTest.scala b/src/partest/scala/tools/partest/utils/CodeTest.scala index 96a20b7fd5..544b95a00d 100644 --- a/src/partest/scala/tools/partest/utils/CodeTest.scala +++ b/src/partest/scala/tools/partest/utils/CodeTest.scala @@ -18,11 +18,14 @@ import scala.tools.nsc.Settings /** Runner for testing code tree liftingg */ object CodeTest { - def apply[T](code: Code[T], args: Array[String]) = { + def apply[T](code: Code[T], args: Array[String] = Array()) = { println("testing: "+code.tree) val reporter = new ConsoleReporter(new Settings) val toolbox = new ToolBox(reporter, args mkString " ") val ttree = toolbox.typeCheck(code.tree, code.manifest.tpe) println("result = " + toolbox.showAttributed(ttree)) + //val evaluated = toolbox.runExpr(ttree) + //println("evaluated = "+evaluated) + //evaluated } } |