Skip to content

Commit cfb5ddd

Browse files
committed
Pretty print quotes
1 parent b6dbe42 commit cfb5ddd

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.dotc.printing
22

3-
import dotty.tools.dotc.ast.Trees.{Closure, DefDef, Untyped, ValDef}
3+
import dotty.tools.dotc.ast.Trees._
44
import dotty.tools.dotc.ast.untpd.{PackageDef, Template, TypeDef}
55
import dotty.tools.dotc.ast.{Trees, untpd}
66
import dotty.tools.dotc.printing.Texts._
@@ -51,4 +51,16 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
5151
}
5252
}
5353
}
54+
55+
override protected def toTextCore[T >: Untyped](tree: Tree[T]): Text = {
56+
import untpd.{modsDeco => _, _}
57+
tree match {
58+
case TypeApply(fun, args) =>
59+
if (tree.symbol eq defn.quoteMethod) "'"
60+
else if (tree.symbol eq defn.typeQuoteMethod) "'[" ~ toTextGlobal(args, ", ") ~ "]"
61+
else super.toTextCore(tree)
62+
case _ =>
63+
super.toTextCore(tree)
64+
}
65+
}
5466
}

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
229229
protected def blockText[T >: Untyped](trees: List[Tree[T]]): Text =
230230
("{" ~ toText(trees, "\n") ~ "}").close
231231

232-
override def toText[T >: Untyped](tree: Tree[T]): Text = controlled {
232+
protected def toTextCore[T >: Untyped](tree: Tree[T]): Text = {
233233
import untpd.{modsDeco => _, _}
234234

235235
def isLocalThis(tree: Tree) = tree.typeOpt match {
@@ -274,7 +274,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
274274
case _ => toTextGlobal(arg)
275275
}
276276

277-
def toTextCore(tree: Tree): Text = tree match {
277+
tree match {
278278
case id: Trees.BackquotedIdent[_] if !homogenizedView =>
279279
"`" ~ toText(id.name) ~ "`"
280280
case id: Trees.SearchFailureIdent[_] =>
@@ -511,6 +511,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
511511
case _ =>
512512
tree.fallbackToText(this)
513513
}
514+
}
515+
516+
override def toText[T >: Untyped](tree: Tree[T]): Text = controlled {
517+
import untpd.{modsDeco => _, _}
514518

515519
var txt = toTextCore(tree)
516520

@@ -550,7 +554,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
550554
if (ctx.settings.YprintPosSyms.value && tree.isDef)
551555
txt = (txt ~
552556
s"@@(${tree.symbol.name}=" ~ tree.symbol.pos.toString ~ ")").close
553-
}
557+
}
554558
if (ctx.settings.YshowTreeIds.value)
555559
txt = (txt ~ "#" ~ tree.uniqueId.toString).close
556560
tree match {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<special-ops>.'[Int](3)
1+
'(3)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val a: quoted.Expr[Int] = <special-ops>.'[Int](4)
3-
<special-ops>.'[Int](a.unary_~)
2+
val a: quoted.Expr[Int] = '(4)
3+
'(a.unary_~)
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val t: quoted.Type[String] = <special-ops>.type_'[String]
2+
val t: quoted.Type[String] = '[String]
33
t: quoted.Type[String]
44
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val a: quoted.Expr[Int] = <special-ops>.'[Int](4)
3-
<special-ops>.'[Int](a.unary_~)
2+
val a: quoted.Expr[Int] = '(4)
3+
'(a.unary_~)
44
}

0 commit comments

Comments
 (0)