aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/Trees.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-02-22 10:58:18 +0100
committerMartin Odersky <odersky@gmail.com>2014-02-24 18:56:48 +0100
commitafb74449e0443d321da4b79e776eab376fdc51b1 (patch)
treea8f9101da583018b398f18c8b95c9e5fd18e5110 /src/dotty/tools/dotc/ast/Trees.scala
parenta4e2a6ed89c33f8c79c7129cc493bff0f84e044c (diff)
downloaddotty-afb74449e0443d321da4b79e776eab376fdc51b1.tar.gz
dotty-afb74449e0443d321da4b79e776eab376fdc51b1.tar.bz2
dotty-afb74449e0443d321da4b79e776eab376fdc51b1.zip
More statistics for created and retained trees
Diffstat (limited to 'src/dotty/tools/dotc/ast/Trees.scala')
-rw-r--r--src/dotty/tools/dotc/ast/Trees.scala12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala
index f4f1260f4..12a635ce6 100644
--- a/src/dotty/tools/dotc/ast/Trees.scala
+++ b/src/dotty/tools/dotc/ast/Trees.scala
@@ -297,6 +297,18 @@ object Trees {
def orElse[U >: Untyped <: T](that: => Tree[U]): Tree[U] =
if (this eq genericEmptyTree) that else this
+ /** The number of nodes in this tree */
+ def treeSize: Int = {
+ var s = 1
+ def addSize(elem: Any): Unit = elem match {
+ case t: Tree[_] => s += t.treeSize
+ case ts: List[_] => ts foreach addSize
+ case _ =>
+ }
+ productIterator foreach addSize
+ s
+ }
+
override def toText(printer: Printer) = printer.toText(this)
override def hashCode(): Int = System.identityHashCode(this)