aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/printing/Printer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-05-17 13:28:02 +0200
committerMartin Odersky <odersky@gmail.com>2013-05-17 13:28:02 +0200
commit94b9a2a0d083cca2ba1358582d8d6fd8143b0b31 (patch)
treee84279f763b7a241bf18c27c7227d66618936719 /src/dotty/tools/dotc/printing/Printer.scala
parentd2261b37cf23ccd04e9029f3556c2dc9e2bdf077 (diff)
downloaddotty-94b9a2a0d083cca2ba1358582d8d6fd8143b0b31.tar.gz
dotty-94b9a2a0d083cca2ba1358582d8d6fd8143b0b31.tar.bz2
dotty-94b9a2a0d083cca2ba1358582d8d6fd8143b0b31.zip
Refactored Printing architecture.
Split printers into several files. Added refined printing of trees. Changed Showable and generalized printing under a precedence.
Diffstat (limited to 'src/dotty/tools/dotc/printing/Printer.scala')
-rw-r--r--src/dotty/tools/dotc/printing/Printer.scala91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/printing/Printer.scala b/src/dotty/tools/dotc/printing/Printer.scala
new file mode 100644
index 000000000..9ba3141f8
--- /dev/null
+++ b/src/dotty/tools/dotc/printing/Printer.scala
@@ -0,0 +1,91 @@
+package dotty.tools.dotc
+package printing
+
+import core._
+import Texts._, Trees._
+import Types.Type, Symbols.Symbol, Contexts.Context, Scopes.Scope, Constants.Constant,
+ Names.Name, Denotations.Denotation, Annotations.Annotation
+
+/** The base class of all printers
+ */
+abstract class Printer {
+
+ private[this] var prec: Precedence = GlobalPrec
+
+ /** The current precedence level */
+ def currentPrecedence = prec
+
+ /** Generate text using `op`, assuming a given precedence level `prec`. */
+ def atPrec(prec: Precedence)(op: => Text): Text = {
+ val outerPrec = this.prec
+ this.prec = prec
+ try op
+ finally this.prec = outerPrec
+ }
+
+ /** Generate text using `op`, assuming a given precedence level `prec`.
+ * If new level `prec` is lower than previous level, put text in parentheses.
+ */
+ def changePrec(prec: Precedence)(op: => Text): Text =
+ if (prec < this.prec) atPrec(prec) ("(" ~ op ~ ")") else atPrec(prec)(op)
+
+ /** The name, possibley with with namespace suffix if debugNames is set:
+ * /L for local names, /V for other term names, /T for type names
+ */
+ def nameString(name: Name): String
+
+ /** The name of the given symbol.
+ * If !settings.debug, the original name where
+ * expansions of operators are translated back to operator symbol.
+ * E.g. $eq => =.
+ * If settings.uniqid, adds id.
+ */
+ def nameString(sym: Symbol): String
+
+ /** The fully qualified name of the symbol */
+ def fullNameString(sym: Symbol): String
+
+ /** The kind of the symbol */
+ def kindString(sym: Symbol): String
+
+ /** The name as a text */
+ def toText(name: Name): Text
+
+ /** Textual representation, including symbol's kind e.g., "class Foo", "method Bar".
+ * If hasMeaninglessName is true, uses the owner's name to disambiguate identity.
+ */
+ def toText(sym: Symbol): Text
+
+ /** Textual representation of symbol's declaration */
+ def dclText(sym: Symbol): Text
+
+ /** If symbol's owner is a printable class C, the text "in C", otherwise "" */
+ def locationText(sym: Symbol): Text
+
+ /** Textual representation of symbol and its location */
+ def locatedText(sym: Symbol): Text
+
+ /** Textual representation of denotation */
+ def toText(denot: Denotation): Text
+
+ /** Textual representation of constant */
+ def toText(const: Constant): Text
+
+ /** Textual representation of annotation */
+ def toText(annot: Annotation): Text
+
+ /** Textual representation of type */
+ def toText(tp: Type): Text
+
+ /** Textual representation of all symbols in given list,
+ * using `dclText` for displaying each.
+ */
+ def dclsText(syms: List[Symbol], sep: String = "\n"): Text
+
+ /** Textual representation of all definitions in a scope using `dclText` for each */
+ def toText(sc: Scope): Text
+
+ /** Textual representation of tree */
+ def toText[T >: Untyped](tree: Tree[T]): Text
+}
+