summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-06-30 21:39:16 +0000
committerPaul Phillips <paulp@improving.org>2009-06-30 21:39:16 +0000
commitab099645c9dfc907b800c42dc36033e9ae1a1e05 (patch)
treea56a5fdedf6043b1fe84aa37d937bd0beda5d82f /src/compiler/scala/tools/nsc/ast/TreeDSL.scala
parentd6519af64cab257fd45d12b818b2117e9c0f5440 (diff)
downloadscala-ab099645c9dfc907b800c42dc36033e9ae1a1e05.tar.gz
scala-ab099645c9dfc907b800c42dc36033e9ae1a1e05.tar.bz2
scala-ab099645c9dfc907b800c42dc36033e9ae1a1e05.zip
Mostly rewriting Unapplies as I work my way thr...
Mostly rewriting Unapplies as I work my way through all the pattern matcher related code.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/TreeDSL.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeDSL.scala26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
index 3dce8148db..96da61a7fd 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
@@ -16,6 +16,7 @@ trait TreeDSL {
import global._
import definitions._
+ import gen.{ scalaDot }
object CODE {
object LIT extends (Any => Literal) {
@@ -182,12 +183,25 @@ trait TreeDSL {
def BLOCK(xs: Tree*) = Block(xs.init.toList, xs.last)
def NOT(tree: Tree) = Select(tree, getMember(BooleanClass, nme.UNARY_!))
- //
- // Unused, from the pattern matcher:
- // def SEQELEM(tpe: Type): Type = (tpe.widen baseType SeqClass) match {
- // case NoType => Predef.error("arg " + tpe + " not subtype of Seq[A]")
- // case t => t typeArgs 0
- // }
+ private val _SOME = scalaDot(nme.Some)
+ def SOME(xs: Tree*) = Apply(_SOME, List(makeTupleTerm(xs.toList, true)))
+
+ /** Some of this is basically verbatim from TreeBuilder, but we do not want
+ * to get involved with him because he's an untyped only sort.
+ */
+ private def tupleName(count: Int, f: (String) => Name = newTermName(_: String)) =
+ scalaDot(f("Tuple" + count))
+
+ def makeTupleTerm(trees: List[Tree], flattenUnary: Boolean): Tree = trees match {
+ case Nil => UNIT
+ case List(tree) if flattenUnary => tree
+ case _ => Apply(tupleName(trees.length), trees)
+ }
+ def makeTupleType(trees: List[Tree], flattenUnary: Boolean): Tree = trees match {
+ case Nil => gen.scalaUnitConstr
+ case List(tree) if flattenUnary => tree
+ case _ => AppliedTypeTree(tupleName(trees.length, newTypeName), trees)
+ }
/** Implicits - some of these should probably disappear **/
implicit def mkTreeMethods(target: Tree): TreeMethods = new TreeMethods(target)