aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/Trees.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-05-30 10:09:48 +0200
committerMartin Odersky <odersky@gmail.com>2013-05-30 10:09:48 +0200
commit17d0e7008f62882c10193ea0db09c9b90736c320 (patch)
tree44cf4d4f2675effabb2ba651f9399d7d6fce21a1 /src/dotty/tools/dotc/ast/Trees.scala
parentc53ac49cbe7c98c05a99fea3c8e1dcad75275a82 (diff)
downloaddotty-17d0e7008f62882c10193ea0db09c9b90736c320.tar.gz
dotty-17d0e7008f62882c10193ea0db09c9b90736c320.tar.bz2
dotty-17d0e7008f62882c10193ea0db09c9b90736c320.zip
wip, because I have to get off this machine.
Diffstat (limited to 'src/dotty/tools/dotc/ast/Trees.scala')
-rw-r--r--src/dotty/tools/dotc/ast/Trees.scala19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala
index 3b38fed7d..6dfaa9c7b 100644
--- a/src/dotty/tools/dotc/ast/Trees.scala
+++ b/src/dotty/tools/dotc/ast/Trees.scala
@@ -216,6 +216,11 @@ object Trees {
/** Is this tree either the empty tree or the empty ValDef? */
def isEmpty: Boolean = false
+ /** Convert tree to a list. Gives a singleton list, except
+ * for thickets which return their element trees.
+ */
+ def toList: List[Tree[T]] = this :: Nil
+
/** if this tree is the empty tree, the alternative, else this tree */
def orElse(that: => Tree[T]): Tree[T] =
if (this eq EmptyTree) that else this
@@ -465,7 +470,7 @@ object Trees {
/** A type tree that represents an existing or inferred type */
case class TypeTree[T >: Untyped](original: Tree[T] = emptyTree[T])
- extends DenotingTree[T] with TypTree[T]
+ extends DenotingTree[T] with TypTree[T] {
type ThisTree[T >: Untyped] = TypeTree[T]
override def initialPos = NoPosition
override def isEmpty = !hasType && original.isEmpty
@@ -607,7 +612,7 @@ object Trees {
override def withType(tpe: Type) = this.asInstanceOf[ThisTree[Type]]
}
- val EmptyTree: Thicket[_] = Thicket(Array[Tree[Untyped]]())
+ val EmptyTree: Thicket[_] = Thicket(Nil)
def emptyTree[T >: Untyped](): Thicket[T] = EmptyTree.asInstanceOf[Thicket[T]]
@@ -636,18 +641,18 @@ object Trees {
* The contained trees will be integrated when transformed with
* a `transform(List[Tree])` call.
*/
- case class Thicket[T >: Untyped](trees: Array[Tree[T]])
+ case class Thicket[T >: Untyped](trees: List[Tree[T]])
extends Tree[T] with WithoutType[T] {
type ThisTree[T >: Untyped] = Thicket[T]
override def isEmpty: Boolean = trees.isEmpty
+ override def toList: List[Tree[T]] = trees
override def toString = if (isEmpty) "EmptyTree" else "Thicket(" + trees.mkString(", ") + ")"
}
object Thicket {
def apply[T >: Untyped](): Tree[T] = emptyTree()
- def apply[T >: Untyped](x1: Tree[T], x2: Tree[T]): Thicket[T] = Thicket(Array[Tree[T]](x1, x2))
- def apply[T >: Untyped](x1: Tree[T], x2: Tree[T], x3: Tree[T]): Thicket[T] = Thicket(Array[Tree[T]](x1, x2, x3))
- def apply[T >: Untyped](elems: List[Tree[T]]): Thicket[T] = apply(elems.toArray)
+ def apply[T >: Untyped](x1: Tree[T], x2: Tree[T]): Thicket[T] = Thicket(List(x1, x2))
+ def apply[T >: Untyped](x1: Tree[T], x2: Tree[T], x3: Tree[T]): Thicket[T] = Thicket(List(x1, x2, x3))
}
// ----- Auxiliary creation methods ------------------
@@ -888,7 +893,7 @@ object Trees {
case tree: SharedTree[_] if (shared eq tree.shared) => tree
case _ => SharedTree(shared).copyAttr(tree)
}
- def derivedThicket(trees: Array[Tree[T]]): Thicket[T] = tree match {
+ def derivedThicket(trees: List[Tree[T]]): Thicket[T] = tree match {
case tree: Thicket[_] if (trees eq tree.trees) => tree
case _ => Thicket(trees).copyAttr(tree)
}