diff options
author | Paul Phillips <paulp@improving.org> | 2009-07-01 21:43:53 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-07-01 21:43:53 +0000 |
commit | def1f684c0f25f7f7e8186ea13a59be2a6cd7ad9 (patch) | |
tree | 236b22cbe98e2c2c1a4e33afc52ac5fa58eb1400 /src/compiler | |
parent | e308e10616f47eea2115eec32a31c3aad47904c7 (diff) | |
download | scala-def1f684c0f25f7f7e8186ea13a59be2a6cd7ad9.tar.gz scala-def1f684c0f25f7f7e8186ea13a59be2a6cd7ad9.tar.bz2 scala-def1f684c0f25f7f7e8186ea13a59be2a6cd7ad9.zip |
Reverted treebuilder all the way to r18056.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 165ae7936b..96b052013a 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -10,9 +10,6 @@ import symtab.Flags._ import scala.collection.mutable.ListBuffer import scala.tools.nsc.util.Position -/** Methods for building trees, used in the parser. All the trees - * returned by this class must be untyped. - */ abstract class TreeBuilder { val global: Global @@ -21,13 +18,19 @@ abstract class TreeBuilder { def freshName(prefix: String): Name def freshName(): Name = freshName("x$") - lazy val rootId = gen.rootId _ - lazy val rootScalaDot = gen.rootScalaDot _ - lazy val scalaDot = gen.scalaDot _ - lazy val scalaAnyRefConstr = gen.scalaAnyRefConstr - lazy val scalaUnitConstr = gen.scalaUnitConstr - lazy val scalaScalaObjectConstr = gen.scalaScalaObjectConstr - lazy val productConstr = gen.productConstr + def rootId(name: Name) = Select(Ident(nme.ROOTPKG), name) + def rootScalaDot(name: Name): Tree = Select(rootId(nme.scala_) setSymbol definitions.ScalaPackage, name) + + def scalaDot(name: Name): Tree = + Select(Ident(nme.scala_) setSymbol definitions.ScalaPackage, name) + def scalaAnyRefConstr: Tree = + scalaDot(nme.AnyRef.toTypeName) + def scalaUnitConstr: Tree = + scalaDot(nme.Unit.toTypeName) + def scalaScalaObjectConstr: Tree = + scalaDot(nme.ScalaObject.toTypeName) + def productConstr: Tree = + scalaDot(nme.Product.toTypeName) /** Convert all occurrences of (lower-case) variables in a pattern as follows: * x becomes x @ _ @@ -90,13 +93,13 @@ abstract class TreeBuilder { } def makeTupleTerm(trees: List[Tree], flattenUnary: Boolean): Tree = trees match { - case Nil => Literal(()) + case List() => Literal(()) case List(tree) if flattenUnary => tree case _ => makeTuple(trees, false) } def makeTupleType(trees: List[Tree], flattenUnary: Boolean): Tree = trees match { - case Nil => scalaUnitConstr + case List() => scalaUnitConstr case List(tree) if flattenUnary => tree case _ => AppliedTypeTree(scalaDot(newTypeName("Tuple" + trees.length)), trees) } @@ -151,9 +154,9 @@ abstract class TreeBuilder { val x = nme.ANON_CLASS_NAME.toTypeName Block( List(ClassDef( - Modifiers(FINAL), x, Nil, - Template(parents, self, NoMods, List(Nil), argss, stats))), - New(Ident(x), List(Nil))) + Modifiers(FINAL), x, List(), + Template(parents, self, NoMods, List(List()), argss, stats))), + New(Ident(x), List(List()))) } /** Create a tree represeting an assignment <lhs = rhs> */ @@ -167,18 +170,18 @@ abstract class TreeBuilder { /** A type tree corresponding to (possibly unary) intersection type */ def makeIntersectionTypeTree(tps: List[Tree]): Tree = if (tps.tail.isEmpty) tps.head - else CompoundTypeTree(Template(tps, emptyValDef, Nil)) + else CompoundTypeTree(Template(tps, emptyValDef, List())) /** Create tree representing a while loop */ def makeWhile(lname: Name, cond: Tree, body: Tree): Tree = { - val continu = Apply(Ident(lname), Nil) + val continu = Apply(Ident(lname), List()) val rhs = If(cond, Block(List(body), continu), Literal(())) LabelDef(lname, Nil, rhs) } /** Create tree representing a do-while loop */ def makeDoWhile(lname: Name, body: Tree, cond: Tree): Tree = { - val continu = Apply(Ident(lname), Nil) + val continu = Apply(Ident(lname), List()) val rhs = Block(List(body), If(cond, continu, Literal(()))) LabelDef(lname, Nil, rhs) } @@ -219,7 +222,7 @@ abstract class TreeBuilder { ValDef(Modifiers(PARAM | SYNTHETIC), pname, TypeTree(), EmptyTree) def makeSyntheticTypeParam(pname: Name, bounds: Tree) = - TypeDef(Modifiers(DEFERRED | SYNTHETIC), pname, Nil, bounds) + TypeDef(Modifiers(DEFERRED | SYNTHETIC), pname, List(), bounds) abstract class Enumerator { def pos: Position } case class ValFrom(pos: Position, pat: Tree, rhs: Tree) extends Enumerator @@ -351,19 +354,19 @@ abstract class TreeBuilder { /** Create tree for a pattern alternative */ def makeAlternative(ts: List[Tree]): Tree = { def alternatives(t: Tree): List[Tree] = t match { - case Alternative(ts) => ts - case _ => List(t) + case Alternative(ts) => ts + case _ => List(t) } - Alternative(ts flatMap alternatives) + Alternative(for (t <- ts; a <- alternatives(t)) yield a) } /** Create tree for a pattern sequence */ def makeSequence(ts: List[Tree]): Tree = { def elements(t: Tree): List[Tree] = t match { case Sequence(ts) => ts - case _ => List(t) + case _ => List(t) } - Sequence(ts flatMap elements) + Sequence(for (t <- ts; e <- elements(t)) yield e) } /** Create visitor <x => x match cases> */ @@ -371,7 +374,7 @@ abstract class TreeBuilder { makeVisitor(cases, checkExhaustive, "x$") private def makeUnchecked(expr: Tree): Tree = atPos(expr.pos) { - Annotated(New(scalaDot(definitions.UncheckedClass.name), List(Nil)), expr) + Annotated(New(scalaDot(definitions.UncheckedClass.name), List(List())), expr) } /** Create visitor <x => x match cases> */ @@ -432,7 +435,8 @@ abstract class TreeBuilder { } /** Create a tree representing the function type (argtpes) => restpe */ - val makeFunctionTypeTree = gen.scalaFunctionConstr _ + def makeFunctionTypeTree(argtpes: List[Tree], restpe: Tree): Tree = + AppliedTypeTree(rootScalaDot(newTypeName("Function" + argtpes.length)), argtpes ::: List(restpe)) /** Append implicit view section if for `implicitViews' if nonempty */ def addImplicitViews(owner: Name, vparamss: List[List[ValDef]], implicitViews: List[Tree]): List[List[ValDef]] = { |