diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/NodePrinters.scala | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/NodePrinters.scala b/src/compiler/scala/tools/nsc/ast/NodePrinters.scala index 108c8fcbfa..5d849b9622 100644 --- a/src/compiler/scala/tools/nsc/ast/NodePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/NodePrinters.scala @@ -63,10 +63,14 @@ abstract class NodePrinters { } trait DefaultPrintAST extends PrintAST { + val printPos = settings.Xprintpos.value || settings.Yposdebug.value + + def showNameAndPos(tree: NameTree) = showPosition(tree) + showName(tree.name) def showDefTreeName(tree: DefTree) = showName(tree.name) + def showPosition(tree: Tree) = if (printPos) tree.pos.show else "" def showFlags(tree: MemberDef) = flagsToString(tree.symbol.flags | tree.mods.flags) - def showLiteral(lit: Literal) = lit.value.escapedStringValue - def showTypeTree(tt: TypeTree) = "<tpt>" + emptyOrComment(showType(tt)) + def showLiteral(lit: Literal) = showPosition(lit) + lit.value.escapedStringValue + def showTypeTree(tt: TypeTree) = showPosition(tt) + "<tpt>" + emptyOrComment(showType(tt)) def showName(name: Name) = name match { case nme.EMPTY | tpnme.EMPTY => "<empty>" case name => "\"" + name + "\"" @@ -97,17 +101,21 @@ abstract class NodePrinters { private var level = 0 def showName(name: Name): String + def showPosition(tree: Tree): String + def showNameAndPos(tree: NameTree): String def showDefTreeName(defTree: DefTree): String def showFlags(tree: MemberDef): String def showLiteral(lit: Literal): String def showTypeTree(tt: TypeTree): String def showAttributes(tree: Tree): String // symbol and type - def showRefTreeName(tree: Tree): String = tree match { - case SelectFromTypeTree(qual, name) => showRefTreeName(qual) + "#" + showName(name) - case Select(qual, name) => showRefTreeName(qual) + "." + showName(name) - case Ident(name) => showName(name) - case _ => "" + tree + def showRefTreeName(tree: Tree): String = { + tree match { + case SelectFromTypeTree(qual, name) => showRefTreeName(qual) + "#" + showName(name) + case Select(qual, name) => showRefTreeName(qual) + "." + showName(name) + case id @ Ident(name) => showNameAndPos(id) + case _ => "" + tree + } } def showRefTree(tree: RefTree): String = { def prefix0 = showRefTreeName(tree.qualifier) @@ -116,7 +124,7 @@ abstract class NodePrinters { case Select(_, _) => prefix0 + "." case _ => "" }) - prefix + showName(tree.name) + emptyOrComment(showAttributes(tree)) + prefix + showNameAndPos(tree) + emptyOrComment(showAttributes(tree)) } def emptyOrComment(s: String) = if (s == "") "" else " // " + s @@ -191,8 +199,9 @@ abstract class NodePrinters { } } + def treePrefix(tree: Tree) = showPosition(tree) + tree.printingPrefix def printMultiline(tree: Tree)(body: => Unit) { - printMultiline(tree.printingPrefix, showAttributes(tree))(body) + printMultiline(treePrefix(tree), showAttributes(tree))(body) } def printMultiline(prefix: String, comment: String)(body: => Unit) { printLine(prefix + "(", comment) @@ -218,10 +227,12 @@ abstract class NodePrinters { } def printSingle(tree: Tree, name: Name) { - println(tree.printingPrefix + "(" + showName(name) + ")" + showAttributes(tree)) + println(treePrefix(tree) + "(" + showName(name) + ")" + showAttributes(tree)) } def traverse(tree: Tree) { + showPosition(tree) + tree match { case AppliedTypeTree(tpt, args) => applyCommon(tree, tpt, args) case ApplyDynamic(fun, args) => applyCommon(tree, fun, args) @@ -230,6 +241,19 @@ abstract class NodePrinters { case Throw(Ident(name)) => printSingle(tree, name) + case b @ Bind(name, body) => + printMultiline(tree) { + println(showDefTreeName(b)) + traverse(body) + } + + case ld @ LabelDef(name, params, rhs) => + printMultiline(tree) { + showNameAndPos(ld) + traverseList("()", "params")(params) + traverse(rhs) + } + case Function(vparams, body) => printMultiline(tree) { traverseList("()", "parameter")(vparams) @@ -309,7 +333,7 @@ abstract class NodePrinters { val ps0 = parents map { p => if (p.tpe eq null) p match { case x: RefTree => showRefTree(x) - case x => "" + x + case x => showPosition(x) + x } else showName(newTypeName(p.tpe.typeSymbol.fullName)) } @@ -353,7 +377,7 @@ abstract class NodePrinters { case _ => tree match { case t: RefTree => println(showRefTree(t)) - case t if t.productArity == 0 => println(tree.printingPrefix) + case t if t.productArity == 0 => println(treePrefix(t)) case t => printMultiline(tree)(tree.productIterator foreach traverseAny) } } |