diff options
author | Som Snytt <som.snytt@gmail.com> | 2012-04-26 15:35:57 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2012-04-26 15:35:57 -0700 |
commit | 2a9cce8a6859a34c259d0b399687df3a242de16b (patch) | |
tree | ca15e0b069265ff7ec43d147e613bb044f38c91a /test/files/run/macro-range/Common_1.scala | |
parent | 47bfd744177121de08fed489a5b0b1b59a1ae06a (diff) | |
parent | f7e1a4940386491b0691147b12b1b321c4cce2c5 (diff) | |
download | scala-2a9cce8a6859a34c259d0b399687df3a242de16b.tar.gz scala-2a9cce8a6859a34c259d0b399687df3a242de16b.tar.bz2 scala-2a9cce8a6859a34c259d0b399687df3a242de16b.zip |
SI-5543: Merge with trunk
Reverts name unenmanglement that was objectionable in the previous patch
commit 47bfd744177121de08fed489a5b0b1b59a1ae06a.
Diffstat (limited to 'test/files/run/macro-range/Common_1.scala')
-rw-r--r-- | test/files/run/macro-range/Common_1.scala | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/files/run/macro-range/Common_1.scala b/test/files/run/macro-range/Common_1.scala new file mode 100644 index 0000000000..bd46e1f529 --- /dev/null +++ b/test/files/run/macro-range/Common_1.scala @@ -0,0 +1,48 @@ +import reflect.api.Modifier +import reflect.makro.Context + +abstract class RangeDefault { + val from, to: Int + def foreach(f: Int => Unit) = { + var i = from + while (i < to) { f(i); i += 1 } + } +} + +/** This class should go into reflect.macro once it is a bit more stable. */ +abstract class Utils { + val context: Context + import context.mirror._ + + class TreeSubstituter(from: List[Symbol], to: List[Tree]) extends Transformer { + override def transform(tree: Tree): Tree = tree match { + case Ident(_) => + def subst(from: List[Symbol], to: List[Tree]): Tree = + if (from.isEmpty) tree + else if (tree.symbol == from.head) to.head.duplicate // TODO: does it ever make sense *not* to perform a shallowDuplicate on `to.head`? + else subst(from.tail, to.tail); + subst(from, to) + case _ => + val tree1 = super.transform(tree) + if (tree1 ne tree) tree1.tpe = null + tree1 + } + } + def makeApply(fn: Tree, args: List[Tree]): Tree = fn match { + case Function(vparams, body) => + new TreeSubstituter(vparams map (_.symbol), args) transform body + case Block(stats, expr) => + Block(stats, makeApply(expr, args)) + case _ => + // todo. read the compiler config and print if -Ydebug is set + //println("no beta on "+fn+" "+fn.getClass) + Apply(fn, args) + } + def makeWhile(lname: TermName, cond: Tree, body: Tree): Tree = { + val continu = Apply(Ident(lname), Nil) + val rhs = If(cond, Block(List(body), continu), Literal(Constant())) + LabelDef(lname, Nil, rhs) + } + def makeBinop(left: Tree, op: String, right: Tree): Tree = + Apply(Select(left, newTermName(op)), List(right)) +} |