From b34c9f524f5d6170b0004dd20d2b08ba823e2f18 Mon Sep 17 00:00:00 2001 From: michelou Date: Tue, 4 Jul 2006 14:40:14 +0000 Subject: removed leading/trailing tabs/blanks in ast/Tre... removed leading/trailing tabs/blanks in ast/TreePrinters.scala --- .../scala/tools/nsc/ast/TreePrinters.scala | 183 +++++++++++---------- 1 file changed, 93 insertions(+), 90 deletions(-) diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala index 69cbd69129..828d886efc 100644 --- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala @@ -1,34 +1,35 @@ -/* NSC -- new scala compiler - * Copyright 2005 LAMP/EPFL +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL * @author Martin Odersky */ // $Id$ -package scala.tools.nsc.ast; -import java.io._; -import symtab.Flags._; +package scala.tools.nsc.ast + +import java.io.{OutputStream,PrintWriter} +import symtab.Flags._ abstract class TreePrinters { - val global: Global; - import global._; + val global: Global + import global._ class TreePrinter(out: PrintWriter) { - protected var indentMargin = 0; - protected val indentStep = 2; - protected var indentString = " "; + protected var indentMargin = 0 + protected val indentStep = 2 + protected var indentString = " " // 40 - def flush = out.flush(); + def flush = out.flush() - def indent = indentMargin = indentMargin + indentStep; - def undent = indentMargin = indentMargin - indentStep; + def indent = indentMargin = indentMargin + indentStep + def undent = indentMargin = indentMargin - indentStep def println = { - out.println(); + out.println() while (indentMargin > indentString.length()) - indentString = indentString + indentString; + indentString = indentString + indentString if (indentMargin > 0) - out.write(indentString, 0, indentMargin); + out.write(indentString, 0, indentMargin) } def printSeq[a](ls: List[a])(printelem: a => unit)(printsep: => unit): unit = ls match { @@ -38,7 +39,7 @@ abstract class TreePrinters { } def printColumn(ts: List[Tree], start: String, sep: String, end: String): unit = { - print(start); indent; println; + print(start); indent; println printSeq(ts){print}{print(sep); println}; undent; println; print(end) } @@ -46,7 +47,7 @@ abstract class TreePrinters { print(start); printSeq(ts){print}{print(sep)}; print(end) } - def printRow(ts: List[Tree], sep: String): unit = printRow(ts, "", sep, ""); + def printRow(ts: List[Tree], sep: String): unit = printRow(ts, "", sep, "") def printTypeParams(ts: List[AbsTypeDef]): unit = if (!ts.isEmpty) { @@ -54,23 +55,25 @@ abstract class TreePrinters { } def printValueParams(ts: List[ValDef]): unit = { - print("("); - if (!ts.isEmpty) printFlags(ts.head.mods.flags & IMPLICIT, nme.EMPTY.toTypeName); - printSeq(ts){printParam}{print(", ")}; + print("(") + if (!ts.isEmpty) printFlags(ts.head.mods.flags & IMPLICIT, nme.EMPTY.toTypeName) + printSeq(ts){printParam}{print(", ")} print(")") } def printParam(tree: Tree): unit = tree match { case ValDef(mods, name, tp, rhs) => - print(symName(tree, name)); printOpt(": ", tp); + print(symName(tree, name)); printOpt(": ", tp) case AbsTypeDef(mods, name, lo, hi) => - print(symName(tree, name)); - printOpt(" >: ", lo); printOpt(" <: ", hi); + print(symName(tree, name)) + printOpt(" >: ", lo); printOpt(" <: ", hi) } def printBlock(tree: Tree): unit = tree match { - case Block(_, _) => print(tree) - case _ => printColumn(List(tree), "{", ";", "}") + case Block(_, _) => + print(tree) + case _ => + printColumn(List(tree), "{", ";", "}") } def symName(tree: Tree, name: Name): String = @@ -93,9 +96,9 @@ abstract class TreePrinters { } def printFlags(flags: long, privateWithin: Name): unit = { - var mask = if (settings.debug.value) -1 else PrintableFlags; - val s = flagsToString(flags & mask); - if (!privateWithin.isEmpty) print("private["+privateWithin+"] "); + var mask = if (settings.debug.value) -1 else PrintableFlags + val s = flagsToString(flags & mask) + if (!privateWithin.isEmpty) print("private[" + privateWithin + "] ") if (s.length() != 0) print(s + " ") } @@ -104,7 +107,7 @@ abstract class TreePrinters { val str = new StringBuffer() attr match { case Triple(tp, args, nvPairs) => - str.append(tp.toString()); + str.append(tp.toString()) if (!args.isEmpty) str.append(args.mkString("(", ",", ")")) if (!nvPairs.isEmpty) @@ -119,76 +122,76 @@ abstract class TreePrinters { if (!attrs.isEmpty) print(attrs.map(attrToString).mkString("[", ",", "]")) } - def print(str: String): unit = out.print(str); - def print(name: Name): unit = print(name.toString()); + def print(str: String): unit = out.print(str) + def print(name: Name): unit = print(name.toString()) def printRaw(tree: Tree): unit = { tree match { case EmptyTree => - print(""); + print("") case ClassDef(mods, name, tparams, tp, impl) => - printAttributes(tree.symbol.attributes); - printModifiers(tree, mods); - print((if (mods hasFlag TRAIT) "trait " else "class ") + symName(tree, name)); - printTypeParams(tparams); - printOpt("requires ", tp); print(" extends "); print(impl); + printAttributes(tree.symbol.attributes) + printModifiers(tree, mods) + print((if (mods hasFlag TRAIT) "trait " else "class ") + symName(tree, name)) + printTypeParams(tparams) + printOpt("requires ", tp); print(" extends "); print(impl) case PackageDef(packaged, stats) => print("package "); print(packaged); printColumn(stats, " {", ";", "}") case ModuleDef(mods, name, impl) => - printAttributes(tree.symbol.attributes); - printModifiers(tree, mods); print("object " + symName(tree, name)); - print(" extends "); print(impl); + printAttributes(tree.symbol.attributes) + printModifiers(tree, mods); print("object " + symName(tree, name)) + print(" extends "); print(impl) case ValDef(mods, name, tp, rhs) => - printAttributes(tree.symbol.attributes); - printModifiers(tree, mods); - print(if (mods.hasFlag(MUTABLE)) "var " else "val "); - print(symName(tree, name)); - printOpt(": ", tp); + printAttributes(tree.symbol.attributes) + printModifiers(tree, mods) + print(if (mods.hasFlag(MUTABLE)) "var " else "val ") + print(symName(tree, name)) + printOpt(": ", tp) if (!mods.hasFlag(DEFERRED)) { - print(" = "); + print(" = ") if (rhs.isEmpty) print("_") else print(rhs) } case DefDef(mods, name, tparams, vparamss, tp, rhs) => - printAttributes(tree.symbol.attributes); - printModifiers(tree, mods); - print("def " + symName(tree, name)); - printTypeParams(tparams); vparamss foreach printValueParams; - printOpt(": ", tp); printOpt(" = ", rhs); + printAttributes(tree.symbol.attributes) + printModifiers(tree, mods) + print("def " + symName(tree, name)) + printTypeParams(tparams); vparamss foreach printValueParams + printOpt(": ", tp); printOpt(" = ", rhs) case AbsTypeDef(mods, name, lo, hi) => - printAttributes(tree.symbol.attributes); - printModifiers(tree, mods); print("type "); printParam(tree); + printAttributes(tree.symbol.attributes) + printModifiers(tree, mods); print("type "); printParam(tree) case AliasTypeDef(mods, name, tparams, rhs) => - printAttributes(tree.symbol.attributes); - printModifiers(tree, mods); print("type " + symName(tree, name)); - printTypeParams(tparams); printOpt(" = ", rhs); + printAttributes(tree.symbol.attributes) + printModifiers(tree, mods); print("type " + symName(tree, name)) + printTypeParams(tparams); printOpt(" = ", rhs) case LabelDef(name, params, rhs) => - print(symName(tree, name)); printRow(params, "(", ",", ")"); printBlock(rhs); + print(symName(tree, name)); printRow(params, "(", ",", ")"); printBlock(rhs) case Import(expr, selectors) => def selectorToString(s: Pair[Name, Name]): String = if (s._1 == nme.WILDCARD || s._1 == s._2) s._1.toString() - else s._1.toString() + "=>" + s._2.toString(); - print("import "); print(expr); + else s._1.toString() + "=>" + s._2.toString() + print("import "); print(expr) print(selectors.map(selectorToString).mkString(".{", ", ", "}")) case Attributed(attr, definition) => if (tree.symbol == NoSymbol) { - print("["); print(attr); print("]"); println; print(definition); + print("["); print(attr); print("]"); println; print(definition) } case DocDef(comment, definition) => - print(comment); println; print(definition); + print(comment); println; print(definition) case Template(parents, body) => - printRow(parents, " with "); + printRow(parents, " with ") if (!body.isEmpty) printColumn(body, " {", ";", "}") case Block(stats, expr) => @@ -198,7 +201,7 @@ abstract class TreePrinters { print(selector); printColumn(cases, " match {", "", "}") case CaseDef(pat, guard, body) => - print("case "); print(pat); printOpt(" if ", guard); + print("case "); print(pat); printOpt(" if ", guard) print(" => "); print(body) case Sequence(trees) => @@ -208,13 +211,13 @@ abstract class TreePrinters { printRow(trees, "(", "| ", ")") case Star(elem) => - print("("); print(elem); print(")*"); + print("("); print(elem); print(")*") case Bind(name, t) => - print("("); print(symName(tree, name)); print(" @ "); print(t); print(")"); + print("("); print(symName(tree, name)); print(" @ "); print(t); print(")") case ArrayValue(elemtpt, trees) => - print("Array["); print(elemtpt); printRow(trees, "]{", ", ", "}") + print("Array["); print(elemtpt); printRow(trees, "]{", ", ", "}") case Function(vparams, body) => print("("); printValueParams(vparams); print(" => "); print(body); print(")") @@ -223,8 +226,8 @@ abstract class TreePrinters { print(lhs); print(" = "); print(rhs) case If(cond, thenp, elsep) => - print("if ("); print(cond); print(")"); indent; println; - print(thenp); undent; + print("if ("); print(cond); print(")"); indent; println + print(thenp); undent if (!elsep.isEmpty) { println; print("else"); indent; println; print(elsep); undent } @@ -233,8 +236,8 @@ abstract class TreePrinters { print("return "); print(expr) case Try(block, catches, finalizer) => - print("try "); printBlock(block); - if (!catches.isEmpty) printColumn(catches, " catch {", "", "}"); + print("try "); printBlock(block) + if (!catches.isEmpty) printColumn(catches, " catch {", "", "}") printOpt(" finally ", finalizer) case Throw(expr) => @@ -244,23 +247,23 @@ abstract class TreePrinters { print("new "); print(tpe) case Typed(expr, tp) => - print("("); print(expr); print(") : "); print(tp); + print("("); print(expr); print(") : "); print(tp) case TypeApply(fun, targs) => - print(fun); printRow(targs, "[", ", ", "]"); + print(fun); printRow(targs, "[", ", ", "]") case Apply(fun, vargs) => - print(fun); printRow(vargs, "(", ", ", ")"); + print(fun); printRow(vargs, "(", ", ", ")") case Super(qual, mix) => - if (!qual.isEmpty || tree.symbol != NoSymbol) print(symName(tree, qual) + "."); - print("super"); + if (!qual.isEmpty || tree.symbol != NoSymbol) print(symName(tree, qual) + ".") + print("super") if (!mix.isEmpty) - print("[" + mix + "]") + print("[" + mix + "]") case This(qual) => - if (!qual.isEmpty) print(symName(tree, qual) + "."); - print("this"); + if (!qual.isEmpty) print(symName(tree, qual) + ".") + print("this") case Select(qualifier, name) => print(qualifier); print("."); print(symName(tree, name)) @@ -270,17 +273,17 @@ abstract class TreePrinters { case Literal(x) => print(x.tag match { - case NullTag => "null" + case NullTag => "null" case StringTag => "\"" + x.stringValue + "\"" - case ClassTag => x.stringValue + ".class" - case CharTag => "\'" + x.charValue + "\'" - case LongTag => x.longValue.toString() + "L"; - case _ => x.value.toString() + case ClassTag => x.stringValue + ".class" + case CharTag => "\'" + x.charValue + "\'" + case LongTag => x.longValue.toString() + "L" + case _ => x.value.toString() }) case TypeTree() => print( - if (tree.tpe == null) + if (tree.tpe == null) "" else if (tree.tpe.symbol != null && tree.tpe.symbol.isAnonymousClass) tree.tpe.symbol.toString() @@ -320,7 +323,7 @@ abstract class TreePrinters { } else tree); def print(unit: CompilationUnit): unit = { - print("// Scala source: " + unit.source + "\n"); + print("// Scala source: " + unit.source + "\n") if (unit.body != null) { print(unit.body); println } else { @@ -330,12 +333,12 @@ abstract class TreePrinters { } def printAll(): unit = { - print("[[syntax trees at end of " + phase + "]]"); + print("[[syntax trees at end of " + phase + "]]") for (val unit <- global.currentRun.units) print(unit) } } - def create(writer: PrintWriter): TreePrinter = new TreePrinter(writer); - def create(stream: OutputStream): TreePrinter = create(new PrintWriter(stream)); - def create(): TreePrinter = create(System.out); + def create(writer: PrintWriter): TreePrinter = new TreePrinter(writer) + def create(stream: OutputStream): TreePrinter = create(new PrintWriter(stream)) + def create(): TreePrinter = create(System.out) } -- cgit v1.2.3