diff options
author | Martin Odersky <odersky@gmail.com> | 2013-01-29 09:44:37 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-01-29 09:44:37 +0100 |
commit | bbc4f7a3234937e5f79e8310e6fff2f9b4af0f98 (patch) | |
tree | 36537cd033d5e37a489839f2970245df9db5e544 /src/dotty/tools/dotc/core/Printers.scala | |
parent | 9770566c50baff03a7e61344c203b29db8750e8f (diff) | |
download | dotty-bbc4f7a3234937e5f79e8310e6fff2f9b4af0f98.tar.gz dotty-bbc4f7a3234937e5f79e8310e6fff2f9b4af0f98.tar.bz2 dotty-bbc4f7a3234937e5f79e8310e6fff2f9b4af0f98.zip |
New Context architecture based on cloning
Diffstat (limited to 'src/dotty/tools/dotc/core/Printers.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Printers.scala | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Printers.scala b/src/dotty/tools/dotc/core/Printers.scala index 67d4d3422..d7476c433 100644 --- a/src/dotty/tools/dotc/core/Printers.scala +++ b/src/dotty/tools/dotc/core/Printers.scala @@ -3,8 +3,28 @@ package core import Types._, Symbols._, Contexts._, Scopes._ +trait Printers { + + private[this] var _diagnostics: Option[StringBuilder] = _ + protected def diagnostics_=(diagnostics: Option[StringBuilder]) = _diagnostics = diagnostics + def diagnostics: Option[StringBuilder] = _diagnostics + + def diagnose(str: => String) = + for (sb <- diagnostics) { + sb.setLength(0) + sb.append(str) + } +} + + object Printers { + trait PrinterBase { self: ContextBase => + + private[core] var showRecursions = 0 + + } + abstract class Printer { def show(tp: Type)(implicit ctx: Context): String def show(sym: Symbol)(implicit ctx: Context): String @@ -13,9 +33,41 @@ object Printers { def show(sc: Scope)(implicit ctx: Context): String } + object StdPrinter { + final val maxShowRecursions = 50 + } + class StdPrinter extends Printer { - def show(tp: Type)(implicit ctx: Context): String = ??? - def show(sym: Symbol)(implicit ctx: Context): String = ??? + import StdPrinter._ + + def controlled(op: => String)(implicit ctx: Context): String = + if (ctx.showRecursions < maxShowRecursions) + try { + ctx.showRecursions += 1 + op + } finally { + ctx.showRecursions -= 1 + } + else { + if (???/*ctx.settings.debug.value*/) { + ctx.warning("Exceeded recursion depth attempting to print type.") + (new Throwable).printStackTrace + } + "..." + } + + def show(tp: Type)(implicit ctx: Context): String = controlled { + tp match { + case TermRef(pre, name) => + ??? // showPrefix(pre) + show(name) + + + + } + } + def show(sym: Symbol)(implicit ctx: Context): String = controlled { + ??? + } def showLocated(sym: Symbol)(implicit ctx: Context): String = ??? def showDef(sym: Symbol)(implicit ctx: Context): String = ??? def show(sc: Scope)(implicit ctx: Context): String = @@ -23,4 +75,5 @@ object Printers { } + }
\ No newline at end of file |