diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/icode/Printers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/Printers.scala | 120 |
1 files changed, 59 insertions, 61 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Printers.scala b/src/compiler/scala/tools/nsc/backend/icode/Printers.scala index 4a5826e550..709d876cd0 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/Printers.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/Printers.scala @@ -1,66 +1,64 @@ /* NSC -- new scala compiler - * Copyright 2005 LAMP/EPFL + * Copyright 2005-2008 LAMP/EPFL * @author Martin Odersky */ // $Id$ -package scala.tools.nsc.backend.icode; +package scala.tools.nsc.backend.icode -import java.io.PrintWriter; +import java.io.PrintWriter -import scala.tools.nsc.util.Position; -import scala.tools.nsc.symtab.Flags; +import scala.tools.nsc.symtab.Flags +import scala.tools.nsc.util.Position trait Printers { self: ICodes => - // val global: Global; - import global._; - import global.icodes.opcodes._; - import global.icodes._; + import global._ + import global.icodes.opcodes._ + import global.icodes._ class TextPrinter(writer: PrintWriter, lin: Linearizer) { - var margin = 0; - var out = writer; + private var margin = 0 + private var out = writer - final val TAB = 2; + final val TAB = 2 - def setWriter(w: PrintWriter) = (out = w); + def setWriter(w: PrintWriter) { out = w } - def indent = margin = margin + TAB; - def undent = margin = margin - TAB; + def indent { margin += TAB } + def undent { margin -= TAB } - def print(s: String) = out.print(s); - def print(o: Any): Unit = print(o.toString()); + def print(s: String) { out.print(s) } + def print(o: Any) { print(o.toString()) } - def println(s: String): Unit = { + def println(s: String) { print(s); println } - def println = { - out.println(); - var i = 0; + def println { + out.println() + var i = 0 while (i < margin) { print(" "); - i = i + 1; + i += 1 } } - def printList[a](l: List[a], sep: String): Unit = l match { - case Nil => (); - case x :: Nil => print(x); - case x :: xs => print(x); print(sep); printList(xs, sep); + def printList[A](l: List[A], sep: String): Unit = l match { + case Nil => + case x :: Nil => print(x) + case x :: xs => print(x); print(sep); printList(xs, sep) } - def printList[a](pr: a => Unit)(l: List[a], sep: String): Unit = l match { - case Nil => (); - case x :: Nil => pr(x); - case x :: xs => pr(x); print(sep); printList(pr)(xs, sep); + def printList[A](pr: A => Unit)(l: List[A], sep: String): Unit = l match { + case Nil => + case x :: Nil => pr(x) + case x :: xs => pr(x); print(sep); printList(pr)(xs, sep) } - - private var clazz : IClass = _; - def printClass(cls: IClass): Unit = { + private var clazz: IClass = _ + def printClass(cls: IClass) { this.clazz = cls; print(cls.symbol.toString()); print(" extends "); printList(cls.symbol.info.parents, ", "); @@ -70,43 +68,43 @@ trait Printers { self: ICodes => println("// methods"); cls.methods.foreach(printMethod); undent; println; - println("}"); + println("}") } - def printField(f: IField): Unit = { + def printField(f: IField) { print(f.symbol.keyString); print(" "); print(f.symbol.nameString); print(": "); println(f.symbol.info.toString()); } - def printMethod(m: IMethod): Unit = { + def printMethod(m: IMethod) { print("def "); print(m.symbol.name); print("("); printList(printParam)(m.params, ", "); print(")"); - print(": "); print(m.symbol.info.resultType); + print(": "); print(m.symbol.info.resultType) if (!m.isDeferred) { - println(" {"); - println("locals: " + m.locals.mkString("", ", ", "")); - println("startBlock: " + m.code.startBlock); - println("blocks: " + m.code.blocks.mkString("[", ",", "]")); - println; - lin.linearize(m) foreach printBlock; - println("}"); - - indent;println("Exception handlers: "); - m.exh foreach printExceptionHandler; - - undent;println; + println(" {") + println("locals: " + m.locals.mkString("", ", ", "")) + println("startBlock: " + m.code.startBlock) + println("blocks: " + m.code.blocks.mkString("[", ",", "]")) + println + lin.linearize(m) foreach printBlock + println("}") + + indent; println("Exception handlers: ") + m.exh foreach printExceptionHandler + + undent; println } else - println; + println } - def printParam(p: Local): Unit = { + def printParam(p: Local) { print(p.sym.name); print(": "); print(p.sym.info); - print(" ("); print(p.kind); print(")"); + print(" ("); print(p.kind); print(")") } - def printExceptionHandler(e: ExceptionHandler) = { + def printExceptionHandler(e: ExceptionHandler) { indent; println("catch (" + e.cls.simpleName + ") in " + e.covered + " starting at: " + e.startBlock); println("consisting of blocks: " + e.blocks); @@ -115,20 +113,20 @@ trait Printers { self: ICodes => // linearizer.linearize(e.startBlock) foreach printBlock; } - def printBlock(bb: BasicBlock): Unit = { - print(bb.label); - if (bb.loopHeader) print("[loop header]"); - print(": "); indent; println; - bb.toList foreach printInstruction; - undent; println; + def printBlock(bb: BasicBlock) { + print(bb.label) + if (bb.loopHeader) print("[loop header]") + print(": "); indent; println + bb.toList foreach printInstruction + undent; println } - def printInstruction(i: Instruction): Unit = { + def printInstruction(i: Instruction) { // if (settings.Xdce.value) // print(if (i.useful) " " else " * "); if (settings.debug.value) print(i.pos.line.map(_.toString).getOrElse("No line")) - println(i.toString()); + println(i.toString()) } } } |