aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/printing/RefinedPrinter.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-07-13 14:00:14 +0200
committerMartin Odersky <odersky@gmail.com>2014-07-17 11:02:02 +0200
commit90965aba05dbd1595e010e53e4958e807b6fccea (patch)
tree75eb0b206d5c284fe2b2da2ea066ad2672f71c40 /src/dotty/tools/dotc/printing/RefinedPrinter.scala
parent47bf26634000950a3ca0185d8b260595c41487e9 (diff)
downloaddotty-90965aba05dbd1595e010e53e4958e807b6fccea.tar.gz
dotty-90965aba05dbd1595e010e53e4958e807b6fccea.tar.bz2
dotty-90965aba05dbd1595e010e53e4958e807b6fccea.zip
Semantic printing
When refined printing a DefTree, if one is after typer, print the symbol's definition plus the rhs of the tree rather than the contents of the tree. Why: After typer, it's always the symbol's contents that should matter. Question: Can we enforce through the types that parts of DefTree reflected by the symbol disappear/are ignored?
Diffstat (limited to 'src/dotty/tools/dotc/printing/RefinedPrinter.scala')
-rw-r--r--src/dotty/tools/dotc/printing/RefinedPrinter.scala26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
index 017434aa4..acba22afe 100644
--- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala
+++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
@@ -194,7 +194,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case _ => toTextGlobal(arg)
}
- def idText = if (ctx.settings.uniqid.value) "#" + tree.symbol.id else ""
+ def dclTextOr(treeText: => Text) =
+ if (ctx.isAfterTyper(ctx.phase) && tree.symbol != null && tree.symbol.exists)
+ annotsText(tree.symbol) ~~ dclText(tree.symbol)
+ else treeText
import untpd._
@@ -285,19 +288,24 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
"(" ~ toTextGlobal(patterns, ", ") ~ ")" ~
("(" ~ toTextGlobal(implicits, ", ") ~ ")" provided implicits.nonEmpty)
case ValDef(mods, name, tpt, rhs) =>
- modText(mods, if (mods is Mutable) "var" else "val") ~~ toText(name) ~ idText ~
- optAscription(tpt) ~ optText(rhs)(" = " ~ _)
+ dclTextOr {
+ modText(mods, if (mods is Mutable) "var" else "val") ~~ toText(name) ~
+ optAscription(tpt)
+ } ~ optText(rhs)(" = " ~ _)
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
atOwner(tree) {
- val first = modText(mods, "def") ~~ toText(name) ~ idText ~ tparamsText(tparams)
- addVparamssText(first, vparamss) ~ optAscription(tpt) ~ optText(rhs)(" = " ~ _)
+ dclTextOr {
+ val first = modText(mods, "def") ~~ toText(name) ~ tparamsText(tparams)
+ addVparamssText(first, vparamss) ~ optAscription(tpt)
+ } ~ optText(rhs)(" = " ~ _)
}
case tree @ TypeDef(mods, name, rhs) =>
atOwner(tree) {
- def typeDefText(rhsText: Text) = {
- val rhsText1 = if (tree.hasType) toText(tree.symbol.info) else rhsText
- modText(mods, "type") ~~ toText(name) ~ idText ~ tparamsText(tree.tparams) ~ rhsText1
- }
+ def typeDefText(rhsText: Text) =
+ dclTextOr {
+ val rhsText1 = if (tree.hasType) toText(tree.symbol.info) else rhsText
+ modText(mods, "type") ~~ toText(name) ~ tparamsText(tree.tparams) ~ rhsText1
+ }
rhs match {
case impl: Template =>
modText(mods, if (mods is Trait) "trait" else "class") ~~ toText(name) ~ toText(impl) ~