summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-01-30 06:30:57 +0000
committerPaul Phillips <paulp@improving.org>2010-01-30 06:30:57 +0000
commitc73ab4525e402cbbc0fd745a34c453520c87564c (patch)
tree9283e20e3edc5b0eb68853ba52a5101474dd2037 /src/compiler/scala/tools/nsc/ast/TreeInfo.scala
parentbb149d1b96015d83e58de5ea9b380550267c4f06 (diff)
downloadscala-c73ab4525e402cbbc0fd745a34c453520c87564c.tar.gz
scala-c73ab4525e402cbbc0fd745a34c453520c87564c.tar.bz2
scala-c73ab4525e402cbbc0fd745a34c453520c87564c.zip
A compact tree printer, for primitives like mys...
A compact tree printer, for primitives like myself who do all their debugging in the console and need extraneous information filtered out. New option: -Ycompact-trees. Supply that in conjunction with -Xprint:all and suddenly the output is a (relative) masterpiece of concision. Review by anyone who is game to review such a thing. Community?
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/TreeInfo.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeInfo.scala17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
index fd7227c371..aa0e484578 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
@@ -350,4 +350,21 @@ abstract class TreeInfo {
case TypeDef(_, _, _, _) => !isAbsTypeDef(tree)
case _ => false
}
+
+ /** Some handy extractors for spotting true and false expressions
+ * through the haze of braces.
+ */
+ abstract class SeeThroughBlocks[T] {
+ protected def unapplyImpl(x: Tree): T
+ def unapply(x: Tree): T = x match {
+ case Block(Nil, expr) => unapply(expr)
+ case _ => unapplyImpl(x)
+ }
+ }
+ object IsTrue extends SeeThroughBlocks[Boolean] {
+ protected def unapplyImpl(x: Tree): Boolean = x equalsStructure Literal(Constant(true))
+ }
+ object IsFalse extends SeeThroughBlocks[Boolean] {
+ protected def unapplyImpl(x: Tree): Boolean = x equalsStructure Literal(Constant(false))
+ }
}