diff options
author | Martin Odersky <odersky@gmail.com> | 2014-10-13 12:05:41 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-10-13 12:05:41 +0200 |
commit | a8124506dc4aee451cadde7f07d1e0a1ebdab108 (patch) | |
tree | 10f96ae41940d64f77d7bb0f33b9bec70f432c43 | |
parent | 0876deed1d725b0350b558365179252b024c2d44 (diff) | |
download | dotty-a8124506dc4aee451cadde7f07d1e0a1ebdab108.tar.gz dotty-a8124506dc4aee451cadde7f07d1e0a1ebdab108.tar.bz2 dotty-a8124506dc4aee451cadde7f07d1e0a1ebdab108.zip |
More refined printing options
When using RefinedPrinter we now have a choice whether when
printing a definition tree such as
def foo(x: T): U
we print the parameter and result type info found in the tree or in the symbol.
Previously, we printed the sym info when after typer and the tree info before.
This turns out to be too inflexble. With the patch, we print the sym info if
option -Yprint-syms is set, and the tree info otherwise.
Also, align -Yno-deep-subtypes from camelCase to standard hyphenated option notation.
Tweak where unique ids are printed.
-rw-r--r-- | src/dotty/tools/dotc/config/ScalaSettings.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/RefinedPrinter.scala | 26 | ||||
-rw-r--r-- | test/dotc/tests.scala | 4 |
3 files changed, 20 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala index f23fb6201..743925e40 100644 --- a/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -145,8 +145,9 @@ class ScalaSettings extends Settings.SettingGroup { val noSelfCheck = BooleanSetting("-Yno-self-type-checks", "Suppress check for self-type conformance among inherited members.") val YshowSuppressedErrors = BooleanSetting("-Yshow-suppressed-errors", "Also show follow-on errors and warnings that are normally supressed.") val Yheartbeat = BooleanSetting("-Yheartbeat", "show heartbeat stack trace of compiler operations.") - val Yprintpos = BooleanSetting("-Yprintpos", "show tree positions") - val YnoDeepSubtypes = BooleanSetting("-YnoDeepSubtypes", "throw an exception on deep subtyping call stacks") + val Yprintpos = BooleanSetting("-Yprintpos", "show tree positions.") + val YnoDeepSubtypes = BooleanSetting("-Yno-deep-subtypes", "throw an exception on deep subtyping call stacks.") + val YprintSyms = BooleanSetting("-Yprint-syms", "when printing trees print info in symbols instead of corresponding info in trees.") def stop = YstopAfter /** Area-specific debug output. diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 6076ca787..d9e248e40 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -180,7 +180,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { def annotText(tree: untpd.Tree): Text = "@" ~ constrText(tree) // DD - def useSymbol = ctx.isAfterTyper(ctx.phase) && tree.hasType && tree.symbol.exists + def useSymbol = + tree.hasType && tree.symbol.exists && ctx.settings.YprintSyms.value def modText(mods: untpd.Modifiers, kw: String): Text = { // DD val suppressKw = if (ownerIsClass) mods is ParamAndLocal else mods is Param @@ -209,6 +210,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { if (ctx.settings.uniqid.value && tree.hasType && tree.symbol.exists) s"#${tree.symbol.id}" else "" } + def nameIdText(tree: untpd.NameTree): Text = + toText(tree.name) ~ idText(tree) + import untpd._ var txt: Text = tree match { @@ -219,8 +223,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case tp: NamedType if name != nme.WILDCARD => toTextPrefix(tp.prefix) ~ selectionString(tp) case _ => toText(name) } - case Select(qual, name) => - toTextLocal(qual) ~ ("." ~ toText(name) provided name != nme.CONSTRUCTOR) + case tree @ Select(qual, name) => + toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided name != nme.CONSTRUCTOR) case This(name) => optDotPrefix(name) ~ "this" ~ idText(tree) case Super(This(name), mix) => @@ -297,15 +301,15 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { toTextLocal(extractor) ~ "(" ~ toTextGlobal(patterns, ", ") ~ ")" ~ ("(" ~ toTextGlobal(implicits, ", ") ~ ")" provided implicits.nonEmpty) - case ValDef(mods, name, tpt, rhs) => + case tree @ ValDef(mods, name, tpt, rhs) => dclTextOr { - modText(mods, if (mods is Mutable) "var" else "val") ~~ toText(name) ~ + modText(mods, if (mods is Mutable) "var" else "val") ~~ nameIdText(tree) ~ optAscription(tpt) } ~ optText(rhs)(" = " ~ _) - case DefDef(mods, name, tparams, vparamss, tpt, rhs) => + case tree @ DefDef(mods, name, tparams, vparamss, tpt, rhs) => atOwner(tree) { dclTextOr { - val first = modText(mods, "def") ~~ toText(name) ~ tparamsText(tparams) + val first = modText(mods, "def") ~~ nameIdText(tree) ~ tparamsText(tparams) addVparamssText(first, vparamss) ~ optAscription(tpt) } ~ optText(rhs)(" = " ~ _) } @@ -314,11 +318,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { 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 + modText(mods, "type") ~~ nameIdText(tree) ~ tparamsText(tree.tparams) ~ rhsText1 } rhs match { case impl: Template => - modText(mods, if (mods is Trait) "trait" else "class") ~~ toText(name) ~~ idText(tree) ~ toText(impl) ~ + modText(mods, if (mods is Trait) "trait" else "class") ~~ nameIdText(tree) ~ toText(impl) ~ (if (tree.hasType && ctx.settings.verbose.value) s"[decls = ${tree.symbol.info.decls}]" else "") case rhs: TypeBoundsTree => typeDefText(toText(rhs)) @@ -367,9 +371,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { "<empty>" case TypedSplice(t) => toText(t) - case ModuleDef(mods, name, impl) => + case tree @ ModuleDef(mods, name, impl) => atOwner(tree) { - modText(mods, "object") ~~ toText(name) ~ toText(impl) + modText(mods, "object") ~~ nameIdText(tree) ~ toText(impl) } case SymbolLit(str) => "'" + str diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index dccd96eed..614dc9527 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -14,13 +14,13 @@ class tests extends CompilerTest { "-pagewidth", "160") implicit val defaultOptions = noCheckOptions ++ List( - "-YnoDeepSubtypes", + "-Yno-deep-subtypes", "-Ycheck:patternMatcher,gettersSetters,constructors" ) val twice = List("#runs", "2", "-YnoDoubleBindings") val doErase = List("-Ystop-before:terminal") - val allowDeepSubtypes = defaultOptions diff List("-YnoDeepSubtypes") + val allowDeepSubtypes = defaultOptions diff List("-Yno-deep-subtypes") val posDir = "./tests/pos/" val negDir = "./tests/neg/" |