1. Phase LiftCode triggers on any apply of Code.lift to a tree, not

just those that are precisely of the form "Code.lift(exp)".

2. The printout of a This(_) tree adds ".this" to the end.

3. This() is now only used for classes.  For modules, the code is
   rewritten as a Select() of the module.



git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@12330 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
spoon 2007-07-17 09:25:17 +00:00
parent 2c151a93e0
commit 6ab2efa74b
3 changed files with 11 additions and 4 deletions

View File

@ -93,6 +93,7 @@ trait Definitions {
//var RemoteRefClass: Symbol = _
var CodeClass: Symbol = _
var CodeModule: Symbol = _
def Code_lift = getMember(CodeModule, nme.lift_)
lazy val PartialFunctionClass: Symbol = getClass("scala.PartialFunction")
lazy val ByNameFunctionClass: Symbol = getClass("scala.ByNameFunction")
lazy val IterableClass: Symbol = getClass("scala.Iterable")

View File

@ -13,7 +13,8 @@ import scala.collection.immutable.ListMap
import scala.collection.mutable.{HashMap, ListBuffer}
import scala.tools.nsc.util.{FreshNameCreator, TreeSet}
/** This abstract class ...
/** Translate expressions of the form reflect.Code.lift(exp)
* to the lifted "reflect trees" representation of exp.
*
* @author Gilles Dubochet
* @version 1.0
@ -33,8 +34,8 @@ abstract class LiftCode extends Transform {
class AddRefFields(unit: CompilationUnit) extends Transformer {
override def transform(tree: Tree): Tree = tree match {
case Apply(TypeApply(Select(x@Ident(_), nme.lift_), _), List(tree))
if x.symbol == CodeModule =>
case Apply(lift, List(tree))
if lift.symbol == Code_lift =>
typed(atPos(tree.pos)(codify(tree)))
case _ =>
super.transform(tree)
@ -111,6 +112,11 @@ abstract class LiftCode extends Transform {
}
reflect.Function(vparams map (_.symbol) map env1,
new Reifier(env1, currentOwner).reify(body))
case tree@This(_) if tree.symbol.isModule =>
// there is no reflect node for a module's this, so
// represent it as a selection of the module
reify(typed(
Select(This(tree.symbol.owner), tree.symbol.name)))
case This(_) =>
reflect.This(reify(tree.symbol))
case Block(stats, expr) =>

View File

@ -43,7 +43,7 @@ object Print extends Function1[Any, String] {
case reflect.Function(params, body) =>
params.map(Print).mkString("(", ", ", ")") + " => " + Print(body)
case reflect.This(sym) =>
Print(sym)
Print(sym)+".this"
case reflect.Block(stats, expr) =>
(stats ::: List(expr)).map(Print).mkString("{\n", ";\n", "\n}")
case reflect.New(tpt) =>