diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-09 10:03:23 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-09 10:03:23 +0100 |
commit | 3debc923154bb5beec8d08b88e8f96ae18ee3734 (patch) | |
tree | 8d87997ddfc293ba24f1bba3057c9b7b58d93b7f /src/dotty/tools/dotc/core/Printers.scala | |
parent | 25e09861e097b8db659ba1fc2d103e540db86a22 (diff) | |
download | dotty-3debc923154bb5beec8d08b88e8f96ae18ee3734.tar.gz dotty-3debc923154bb5beec8d08b88e8f96ae18ee3734.tar.bz2 dotty-3debc923154bb5beec8d08b88e8f96ae18ee3734.zip |
Integration of Constants
Diffstat (limited to 'src/dotty/tools/dotc/core/Printers.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Printers.scala | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/src/dotty/tools/dotc/core/Printers.scala b/src/dotty/tools/dotc/core/Printers.scala index 44a647f50..1796be217 100644 --- a/src/dotty/tools/dotc/core/Printers.scala +++ b/src/dotty/tools/dotc/core/Printers.scala @@ -10,8 +10,6 @@ trait Printers { this: Context => import Printers._ - def show(tp: Type): String = printer(this).show(tp, GlobalPrec) - private var _diagnostics: Option[StringBuilder] = _ protected def diagnostics_=(diagnostics: Option[StringBuilder]) = _diagnostics = diagnostics @@ -242,18 +240,6 @@ object Printers { protected def isEmptyPrefix(sym: Symbol) = sym.isEffectiveRoot || sym.isAnonymousClass || sym.name.isReplWrapperName - @switch private def escapedChar(ch: Char): String = ch match { - case '\b' => "\\b" - case '\t' => "\\t" - case '\n' => "\\n" - case '\f' => "\\f" - case '\r' => "\\r" - case '"' => "\\\"" - case '\'' => "\\\'" - case '\\' => "\\\\" - case _ => if (ch.isControl) "\\0" + toOctalString(ch) else String.valueOf(ch) - } - /** The string representation of this type used as a prefix */ protected def showPrefix(tp: Type): String = controlled { tp match { @@ -365,23 +351,25 @@ object Printers { def showLocated(sym: Symbol): String = show(sym) + showLocation(sym) - def show(const: Constant) = { - ??? /* - def escape(text: String): String = text flatMap escapedChar - tag match { - case NullTag => "null" - case StringTag => "\"" + escape(stringValue) + "\"" - case ClazzTag => - def show(tpe: Type) = "classOf[" + signature(tpe) + "]" - typeValue match { - case ErasedValueType(orig) => show(orig) - case _ => show(typeValue) - } - case CharTag => "'" + escapedChar(charValue) + "'" - case LongTag => longValue.toString() + "L" - case EnumTag => symbolValue.name.toString() - case _ => String.valueOf(value) - }*/ + @switch private def escapedChar(ch: Char): String = ch match { + case '\b' => "\\b" + case '\t' => "\\t" + case '\n' => "\\n" + case '\f' => "\\f" + case '\r' => "\\r" + case '"' => "\\\"" + case '\'' => "\\\'" + case '\\' => "\\\\" + case _ => if (ch.isControl) "\\0" + toOctalString(ch) else String.valueOf(ch) + } + + def show(const: Constant) = const.tag match { + case StringTag => "\"" + (const.value.toString flatMap escapedChar) + "\"" + case ClazzTag => s"classOf[${const.tpe.show}]" + case CharTag => s"'${escapedChar(const.charValue)}'" + case LongTag => const.longValue.toString + "L" + case EnumTag => const.symbolValue.name.toString + case _ => String.valueOf(const.value) } def show(annot: Annotation): String = ??? @@ -391,7 +379,6 @@ object Printers { def show(sc: Scope): String = "Scope{\n" + show(sc.toList, ";\n ") + "\n}" - } class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { |