Skip to content

Commit 4c010ea

Browse files
committed
Remove SyntaxHighlighting fro Expr, Type and Reflection
1 parent ff7c398 commit 4c010ea

File tree

7 files changed

+40
-51
lines changed

7 files changed

+40
-51
lines changed

compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DecompilationPrinter extends Phase {
4444
else {
4545
val unitFile = unit.source.toString.replace("\\", "/").replace(".class", ".tasty")
4646
out.println(s"/** Decompiled from $unitFile */")
47-
out.println(QuoteContextImpl.showTree(unit.tpdTree))
47+
out.println(QuoteContextImpl.showDecompiledTree(unit.tpdTree))
4848
}
4949
}
5050
}

compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver {
3434
run.printSummary()
3535
val unit = ctx.run.units.head
3636

37-
val decompiled = QuoteContextImpl.showTree(unit.tpdTree)
37+
val decompiled = QuoteContextImpl.showDecompiledTree(unit.tpdTree)
3838
val tree = new TastyHTMLPrinter(unit.pickled.head._2()).showContents()
3939

4040
reporter.removeBufferedMessages.foreach(message => System.err.println(message))

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@ object QuoteContextImpl {
2626
def apply()(using Context): QuoteContext =
2727
new QuoteContextImpl(ctx)
2828

29-
def showTree(tree: tpd.Tree)(using Context): String = {
30-
val qctx = QuoteContextImpl()(using MacroExpansion.context(tree))
31-
val syntaxHighlight =
32-
if (ctx.settings.color.value == "always") SyntaxHighlight.ANSI
33-
else SyntaxHighlight.plain
34-
show(using qctx)(tree.asInstanceOf[qctx.reflect.Tree], syntaxHighlight)(using ctx.asInstanceOf[qctx.reflect.Context])
29+
def showDecompiledTree(tree: tpd.Tree)(using Context): String = {
30+
val qctx: QuoteContextImpl = new QuoteContextImpl(MacroExpansion.context(tree))
31+
if ctx.settings.color.value == "always" then
32+
qctx.reflect.TreeMethodsImpl.extension_showAnsiColored(tree)
33+
else
34+
qctx.reflect.TreeMethodsImpl.extension_show(tree)
3535
}
3636

37-
private def show(using qctx: QuoteContext)(tree: qctx.reflect.Tree, syntaxHighlight: SyntaxHighlight)(using qctx.reflect.Context) =
38-
tree.showWith(syntaxHighlight)
39-
4037
private[dotty] def checkScopeId(id: ScopeId)(using Context): Unit =
4138
if (id != scopeId)
4239
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
@@ -67,9 +64,9 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
6764
def showExtractors: String =
6865
Extractors.showTree(using QuoteContextImpl.this)(self)
6966
def show: String =
70-
self.showWith(SyntaxHighlight.plain)
71-
def showWith(syntaxHighlight: SyntaxHighlight): String =
72-
SourceCode.showTree(using QuoteContextImpl.this)(self)(syntaxHighlight)
67+
SourceCode.showTree(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
68+
def showAnsiColored: String =
69+
SourceCode.showTree(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
7370
def isExpr: Boolean =
7471
self match
7572
case TermTypeTest(self) =>
@@ -1592,10 +1589,10 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
15921589
Extractors.showType(using QuoteContextImpl.this)(self)
15931590

15941591
def show: String =
1595-
self.showWith(SyntaxHighlight.plain)
1592+
SourceCode.showType(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
15961593

1597-
def showWith(syntaxHighlight: SyntaxHighlight): String =
1598-
SourceCode.showType(using QuoteContextImpl.this)(self)(syntaxHighlight)
1594+
def showAnsiColored: String =
1595+
SourceCode.showType(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
15991596

16001597
def seal: scala.quoted.Type[_] =
16011598
new scala.internal.quoted.Type(Inferred(self), QuoteContextImpl.this.hashCode)
@@ -2174,9 +2171,9 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
21742171
def showExtractors: String =
21752172
Extractors.showConstant(using QuoteContextImpl.this)(self)
21762173
def show: String =
2177-
self.showWith(SyntaxHighlight.plain)
2178-
def showWith(syntaxHighlight: SyntaxHighlight): String =
2179-
SourceCode.showConstant(using QuoteContextImpl.this)(self)(syntaxHighlight)
2174+
SourceCode.showConstant(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
2175+
def showAnsiColored: String =
2176+
SourceCode.showConstant(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
21802177
end extension
21812178
end ConstantMethodsImpl
21822179

@@ -2397,9 +2394,9 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
23972394
def showExtractors: String =
23982395
Extractors.showSymbol(using QuoteContextImpl.this)(self)
23992396
def show: String =
2400-
self.showWith(SyntaxHighlight.plain)
2401-
def showWith(syntaxHighlight: SyntaxHighlight): String =
2402-
SourceCode.showSymbol(using QuoteContextImpl.this)(self)(syntaxHighlight)
2397+
SourceCode.showSymbol(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
2398+
def showAnsiColored: String =
2399+
SourceCode.showSymbol(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
24032400

24042401
end extension
24052402

@@ -2533,9 +2530,9 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
25332530
def showExtractors: String =
25342531
Extractors.showFlags(using QuoteContextImpl.this)(self)
25352532
def show: String =
2536-
self.showWith(SyntaxHighlight.plain)
2537-
def showWith(syntaxHighlight: SyntaxHighlight): String =
2538-
SourceCode.showFlags(using QuoteContextImpl.this)(self)(syntaxHighlight)
2533+
SourceCode.showFlags(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
2534+
def showAnsiColored: String =
2535+
SourceCode.showFlags(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
25392536
end extension
25402537
end FlagsMethodsImpl
25412538

library/src-bootstrapped/scala/quoted/Expr.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package scala.quoted
22

3-
import scala.quoted.reflection.printers.SyntaxHighlight
43
import scala.internal.tasty.CompilerInterface.quoteContextWithCompilerInterface
54

65
/** Quoted expression of type `T` */
76
abstract class Expr[+T] private[scala] {
87

98
/** Show a source code like representation of this expression without syntax highlight */
10-
def show(using qctx: QuoteContext): String =
11-
this.unseal.showWith(SyntaxHighlight.plain)
9+
def show(using qctx: QuoteContext): String = this.unseal.show
1210

13-
/** Show a source code like representation of this expression */
14-
def showWith(syntaxHighlight: SyntaxHighlight)(using qctx: QuoteContext): String =
15-
this.unseal.showWith(syntaxHighlight)
11+
/** Shows the tree as fully typed source code colored with ANSI */
12+
def showAnsiColored(using qctx: QuoteContext): String = this.unseal.showAnsiColored
1613

1714
/** Pattern matches `this` against `that`. Effectively performing a deep equality check.
1815
* It does the equivalent of

library/src-bootstrapped/scala/quoted/Type.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package scala.quoted
22

33
import scala.annotation.compileTimeOnly
4-
import scala.quoted.reflection.printers.SyntaxHighlight
54

65
/** Quoted type (or kind) `T` */
76
abstract class Type[T <: AnyKind] private[scala] {
@@ -10,12 +9,10 @@ abstract class Type[T <: AnyKind] private[scala] {
109
type Underlying = T
1110

1211
/** Show a source code like representation of this type without syntax highlight */
13-
def show(using qctx: QuoteContext): String =
14-
this.unseal.showWith(SyntaxHighlight.plain)
12+
def show(using qctx: QuoteContext): String = this.unseal.show
1513

16-
/** Show a source code like representation of this type */
17-
def showWith(syntaxHighlight: SyntaxHighlight)(using qctx: QuoteContext): String =
18-
this.unseal.showWith(syntaxHighlight)
14+
/** Shows the tree as fully typed source code colored with ANSI */
15+
def showAnsiColored(using qctx: QuoteContext): String = this.unseal.showAnsiColored
1916

2017
/** View this expression `quoted.Type[T]` as a `TypeTree` */
2118
def unseal(using qctx: QuoteContext): qctx.reflect.TypeTree

library/src/scala/tasty/Reflection.scala

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package scala.tasty
33
import scala.internal.tasty.CompilerInterface
44

55
import scala.quoted.QuoteContext
6-
import scala.quoted.reflection.printers.SyntaxHighlight
76
import scala.tasty.reflect._
87

98
/** TASTy Reflect Interface.
@@ -156,8 +155,8 @@ trait Reflection { reflection =>
156155
/** Shows the tree as fully typed source code */
157156
def show: String
158157

159-
/** Shows the tree as fully typed source code */
160-
def showWith(syntaxHighlight: SyntaxHighlight): String
158+
/** Shows the tree as fully typed source code colored with ANSI */
159+
def showAnsiColored: String
161160

162161
/** Does this tree represent a valid expression? */
163162
def isExpr: Boolean
@@ -1753,8 +1752,8 @@ trait Reflection { reflection =>
17531752
/** Shows the tree as fully typed source code */
17541753
def show: String
17551754

1756-
/** Shows the tree as fully typed source code */
1757-
def showWith(syntaxHighlight: SyntaxHighlight): String
1755+
/** Shows the tree as fully typed source code colored with ANSI */
1756+
def showAnsiColored: String
17581757

17591758
/** Convert `TypeRepr` to an `quoted.Type[_]` */
17601759
def seal: scala.quoted.Type[_]
@@ -2491,8 +2490,8 @@ trait Reflection { reflection =>
24912490
/** Shows the tree as fully typed source code */
24922491
def show: String
24932492

2494-
/** Shows the tree as fully typed source code */
2495-
def showWith(syntaxHighlight: SyntaxHighlight): String
2493+
/** Shows the tree as fully typed source code colored with ANSI */
2494+
def showAnsiColored: String
24962495
end extension
24972496
}
24982497

@@ -2800,8 +2799,8 @@ trait Reflection { reflection =>
28002799
/** Shows the tree as fully typed source code */
28012800
def show: String
28022801

2803-
/** Shows the tree as fully typed source code */
2804-
def showWith(syntaxHighlight: SyntaxHighlight): String
2802+
/** Shows the tree as fully typed source code colored with ANSI */
2803+
def showAnsiColored: String
28052804

28062805
/** Case class or case object children of a sealed trait */
28072806
def children: List[Symbol]
@@ -3155,8 +3154,8 @@ trait Reflection { reflection =>
31553154
/** Shows the tree as fully typed source code */
31563155
def show: String
31573156

3158-
/** Shows the tree as fully typed source code */
3159-
def showWith(syntaxHighlight: SyntaxHighlight): String
3157+
/** Shows the tree as fully typed source code colored with ANSI */
3158+
def showAnsiColored: String
31603159

31613160
end extension
31623161
}

tests/run-macros/i6270/Macro_1.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.reflection.printers.SyntaxHighlight.ANSI
32

43
object api {
54
extension (inline x: String) inline def reflect : String =
@@ -15,6 +14,6 @@ object api {
1514

1615
private def reflImplColor(x: Expr[String])(using qctx: QuoteContext) : Expr[String] = {
1716
import qctx.reflect._
18-
Expr(x.showWith(ANSI))
17+
Expr(x.showAnsiColored)
1918
}
2019
}

0 commit comments

Comments
 (0)