diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-09-19 21:37:55 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-09-19 21:37:55 +0200 |
commit | b8362d6aa42433ea4d423f7498d5fae155dc68b0 (patch) | |
tree | 5750590e62c1b55a90833bdc3e4cb80c1953330e /src | |
parent | 2f9f8d5d67441f6f1999d68b2b2e57f5451f8da7 (diff) | |
download | scala-b8362d6aa42433ea4d423f7498d5fae155dc68b0.tar.gz scala-b8362d6aa42433ea4d423f7498d5fae155dc68b0.tar.bz2 scala-b8362d6aa42433ea4d423f7498d5fae155dc68b0.zip |
SI-6392 wraps non-terms before typecheck/eval
Wrap non-term arguments of typecheck and eval, so that toolboxes
can work with full-fledged files (except for package declarations).
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/reflect/ToolBoxFactory.scala | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala index 091224c88a..3d4b1e9a6f 100644 --- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala +++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala @@ -70,6 +70,14 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => } } + def wrapIntoTerm(tree: Tree): Tree = + if (!tree.isTerm) Block(List(tree), Literal(Constant(()))) else tree + + def unwrapFromTerm(tree: Tree): Tree = tree match { + case Block(List(tree), Literal(Constant(()))) => tree + case tree => tree + } + def extractFreeTerms(expr0: Tree, wrapFreeTermRefs: Boolean): (Tree, scala.collection.mutable.LinkedHashMap[FreeTermSymbol, TermName]) = { val freeTerms = expr0.freeTerms val freeTermNames = scala.collection.mutable.LinkedHashMap[FreeTermSymbol, TermName]() @@ -102,7 +110,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => // need to wrap the expr, because otherwise you won't be able to typecheck macros against something that contains free vars var (expr, freeTerms) = extractFreeTerms(expr0, wrapFreeTermRefs = false) val dummies = freeTerms.map{ case (freeTerm, name) => ValDef(NoMods, name, TypeTree(freeTerm.info), Select(Ident(PredefModule), newTermName("$qmark$qmark$qmark"))) }.toList - expr = Block(dummies, expr) + expr = Block(dummies, wrapIntoTerm(expr)) // [Eugene] how can we implement that? // !!! Why is this is in the empty package? If it's only to make @@ -137,6 +145,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => } }.transform(unwrapped) new TreeTypeSubstituter(dummies1 map (_.symbol), dummies1 map (dummy => SingleType(NoPrefix, invertedIndex(dummy.symbol.name)))).traverse(unwrapped) + unwrapped = if (expr0.isTerm) unwrapped else unwrapFromTerm(unwrapped) unwrapped } @@ -170,7 +179,9 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => } }) - def compile(expr: Tree): () => Any = { + def compile(expr0: Tree): () => Any = { + val expr = wrapIntoTerm(expr0) + val freeTerms = expr.freeTerms // need to calculate them here, because later on they will be erased val thunks = freeTerms map (fte => () => fte.value) // need to be lazy in order not to distort evaluation order verify(expr) |