File tree Expand file tree Collapse file tree 4 files changed +21
-24
lines changed
compiler/src/dotty/tools/dotc
library/src/scala/tasty/util Expand file tree Collapse file tree 4 files changed +21
-24
lines changed Original file line number Diff line number Diff line change @@ -688,7 +688,7 @@ object StdNames {
688
688
class ScalaTermNames extends ScalaNames [TermName ] {
689
689
protected implicit def fromString (s : String ): TermName = termName(s)
690
690
691
- @ switch def syntheticParamName (i : Int ): TermName = i match {
691
+ def syntheticParamName (i : Int ): TermName = ( i : @ switch) match {
692
692
case 0 => x_0
693
693
case 1 => x_1
694
694
case 2 => x_2
@@ -702,7 +702,7 @@ object StdNames {
702
702
case _ => termName(" x$" + i)
703
703
}
704
704
705
- @ switch def productAccessorName (j : Int ): TermName = j match {
705
+ def productAccessorName (j : Int ): TermName = ( j : @ switch) match {
706
706
case 1 => nme._1
707
707
case 2 => nme._2
708
708
case 3 => nme._3
Original file line number Diff line number Diff line change @@ -443,7 +443,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
443
443
444
444
def toText (denot : Denotation ): Text = toText(denot.symbol) ~ " /D"
445
445
446
- @ switch private def escapedChar (ch : Char ): String = ch match {
446
+ private def escapedChar (ch : Char ): String = ( ch : @ switch) match {
447
447
case '\b ' => " \\ b"
448
448
case '\t ' => " \\ t"
449
449
case '\n ' => " \\ n"
Original file line number Diff line number Diff line change 1
1
package dotty .tools .dotc .quoted
2
2
3
3
import dotty .tools .dotc .ast .tpd
4
- import dotty .tools .dotc .core .Contexts .Context
5
- import dotty .tools .dotc .core .Constants ._
6
- import dotty .tools .dotc .core .quoted .PickledQuotes
7
- import dotty .tools .dotc .printing .RefinedPrinter
8
4
9
5
import scala .quoted .Expr
10
- import scala .runtime .BoxedUnit
11
6
import scala .quoted .Exprs .{LiftedExpr , TastyTreeExpr }
12
7
import scala .runtime .quoted ._
13
8
@@ -32,20 +27,7 @@ object Toolbox {
32
27
new QuoteDriver ().run(expr, runSettings)
33
28
}
34
29
35
- def show (expr : Expr [T ]): String = expr match {
36
- case expr : LiftedExpr [T ] =>
37
- expr.value match {
38
- case value : Class [_] => s " classOf[ ${value.getCanonicalName}] "
39
- case value if value == BoxedUnit .UNIT => " ()"
40
- case value =>
41
- implicit val ctx = new QuoteDriver ().initCtx
42
- if (showSettings.compilerArgs.contains(" -color:never" ))
43
- ctx.settings.color.update(" never" )
44
- val printer = new RefinedPrinter (ctx)
45
- printer.toText(Literal (Constant (value))).mkString(Int .MaxValue , false )
46
- }
47
- case _ => new QuoteDriver ().show(expr, showSettings)
48
- }
30
+ def show (expr : Expr [T ]): String = new QuoteDriver ().show(expr, showSettings)
49
31
50
32
}
51
33
Original file line number Diff line number Diff line change 1
1
package scala .tasty
2
2
package util
3
3
4
+ import scala .annotation .switch
5
+
4
6
class ShowSourceCode [T <: Tasty with Singleton ](tasty0 : T ) extends Show [T ](tasty0) {
5
7
import tasty ._
6
8
@@ -591,8 +593,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
591
593
case Constant .Long (v) => this += v += " L"
592
594
case Constant .Float (v) => this += v
593
595
case Constant .Double (v) => this += v
594
- case Constant .Char (v) => this += '\' ' += v.toString += '\' ' // TODO escape char
595
- case Constant .String (v) => this += '"' += v.toString += '"' // TODO escape string
596
+ case Constant .Char (v) => this += '\' ' += escapedChar(v) += '\' '
597
+ case Constant .String (v) => this += '"' += escapedString(v) += '"'
596
598
}
597
599
598
600
def printTypeOrBoundsTree (tpt : TypeOrBoundsTree ): Buffer = tpt match {
@@ -770,6 +772,19 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
770
772
def += (x : Char ): this .type = { sb.append(x); this }
771
773
def += (x : String ): this .type = { sb.append(x); this }
772
774
775
+ private def escapedChar (ch : Char ): String = (ch : @ switch) match {
776
+ case '\b ' => " \\ b"
777
+ case '\t ' => " \\ t"
778
+ case '\n ' => " \\ n"
779
+ case '\f ' => " \\ f"
780
+ case '\r ' => " \\ r"
781
+ case '"' => " \\\" "
782
+ case '\' ' => " \\\' "
783
+ case '\\ ' => " \\\\ "
784
+ case _ => if (ch.isControl) " \\ 0" + Integer .toOctalString(ch) else String .valueOf(ch)
785
+ }
786
+
787
+ private def escapedString (str : String ): String = str flatMap escapedChar
773
788
}
774
789
775
790
You can’t perform that action at this time.
0 commit comments