Skip to content

Commit b3b3b2e

Browse files
committed
Remove Context from TastyPrinter
1 parent 0bd50d3 commit b3b3b2e

File tree

6 files changed

+31
-30
lines changed

6 files changed

+31
-30
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dotty.tools.dotc
2+
package core
3+
package tasty
4+
5+
class TastyAnsiiPrinter(bytes: Array[Byte]) extends TastyPrinter(bytes) {
6+
override protected def nameStr(str: String): String = Console.MAGENTA + str + Console.RESET
7+
override protected def treeStr(str: String): String = Console.YELLOW + str + Console.RESET
8+
override protected def lengthStr(str: String): String = Console.CYAN + str + Console.RESET
9+
}

compiler/src/dotty/tools/dotc/core/tasty/TastyHTMLPrinter.scala

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@ package dotty.tools.dotc
22
package core
33
package tasty
44

5-
import dotty.tools.tasty.TastyBuffer.NameRef
6-
7-
import Contexts._, Decorators._
8-
import Names.Name
9-
import TastyUnpickler._
10-
import util.Spans.offsetToInt
11-
import printing.Highlighting._
12-
13-
class TastyHTMLPrinter(bytes: Array[Byte])(using Context) extends TastyPrinter(bytes) {
14-
override protected def nameColor(str: String): String = s"<span class='name'>$str</span>"
15-
override protected def treeColor(str: String): String = s"<span class='tree'>$str</span>"
16-
override protected def lengthColor(str: String): String = s"<span class='length'>$str</span>"
5+
class TastyHTMLPrinter(bytes: Array[Byte]) extends TastyPrinter(bytes) {
6+
override protected def nameStr(str: String): String = s"<span class='name'>$str</span>"
7+
override protected def treeStr(str: String): String = s"<span class='tree'>$str</span>"
8+
override protected def lengthStr(str: String): String = s"<span class='length'>$str</span>"
179
}

compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import TastyUnpickler._
1111
import util.Spans.offsetToInt
1212
import printing.Highlighting._
1313

14-
class TastyPrinter(bytes: Array[Byte])(using Context) {
14+
class TastyPrinter(bytes: Array[Byte]) {
1515

1616
private val sb: StringBuilder = new StringBuilder
1717

@@ -24,7 +24,7 @@ class TastyPrinter(bytes: Array[Byte])(using Context) {
2424

2525
def printNames(): Unit =
2626
for ((name, idx) <- nameAtRef.contents.zipWithIndex) {
27-
val index = nameColor("%4d".format(idx))
27+
val index = nameStr("%4d".format(idx))
2828
sb.append(index).append(": ").append(nameToString(name)).append("\n")
2929
}
3030

@@ -59,13 +59,13 @@ class TastyPrinter(bytes: Array[Byte])(using Context) {
5959
import reader._
6060
var indent = 0
6161
def newLine() = {
62-
val length = treeColor("%5d".format(index(currentAddr) - index(startAddr)))
62+
val length = treeStr("%5d".format(index(currentAddr) - index(startAddr)))
6363
sb.append(s"\n $length:" + " " * indent)
6464
}
65-
def printNat() = sb.append(treeColor(" " + readNat()))
65+
def printNat() = sb.append(treeStr(" " + readNat()))
6666
def printName() = {
6767
val idx = readNat()
68-
sb.append(nameColor(" " + idx + " [" + nameRefToString(NameRef(idx)) + "]"))
68+
sb.append(nameStr(" " + idx + " [" + nameRefToString(NameRef(idx)) + "]"))
6969
}
7070
def printTree(): Unit = {
7171
newLine()
@@ -74,7 +74,7 @@ class TastyPrinter(bytes: Array[Byte])(using Context) {
7474
indent += 2
7575
if (tag >= firstLengthTreeTag) {
7676
val len = readNat()
77-
sb.append(s"(${lengthColor(len.toString)})")
77+
sb.append(s"(${lengthStr(len.toString)})")
7878
val end = currentAddr + len
7979
def printTrees() = until(end)(printTree())
8080
tag match {
@@ -116,7 +116,7 @@ class TastyPrinter(bytes: Array[Byte])(using Context) {
116116
}
117117
indent -= 2
118118
}
119-
sb.append(i"start = ${reader.startAddr}, base = $base, current = $currentAddr, end = $endAddr\n")
119+
sb.append(s"start = ${reader.startAddr}, base = $base, current = $currentAddr, end = $endAddr\n")
120120
sb.append(s"${endAddr.index - startAddr.index} bytes of AST, base = $currentAddr\n")
121121
while (!isAtEnd) {
122122
printTree()
@@ -136,7 +136,7 @@ class TastyPrinter(bytes: Array[Byte])(using Context) {
136136
sb.append(s" position bytes:\n")
137137
val sorted = spans.toSeq.sortBy(_._1.index)
138138
for ((addr, pos) <- sorted) {
139-
sb.append(treeColor("%10d".format(addr.index)))
139+
sb.append(treeStr("%10d".format(addr.index)))
140140
sb.append(s": ${offsetToInt(pos.start)} .. ${pos.end}\n")
141141
}
142142
sb.result
@@ -153,14 +153,14 @@ class TastyPrinter(bytes: Array[Byte])(using Context) {
153153
sb.append(s" comment bytes:\n")
154154
val sorted = comments.toSeq.sortBy(_._1.index)
155155
for ((addr, cmt) <- sorted) {
156-
sb.append(treeColor("%10d".format(addr.index)))
156+
sb.append(treeStr("%10d".format(addr.index)))
157157
sb.append(s": ${cmt.raw} (expanded = ${cmt.isExpanded})\n")
158158
}
159159
sb.result
160160
}
161161
}
162162

163-
protected def nameColor(str: String): String = Magenta(str).show
164-
protected def treeColor(str: String): String = Yellow(str).show
165-
protected def lengthColor(str: String): String = Cyan(str).show
163+
protected def nameStr(str: String): String = str
164+
protected def treeStr(str: String): String = str
165+
protected def lengthStr(str: String): String = str
166166
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scala.io.Codec
88

99
import dotty.tools.dotc.core.Contexts._
1010
import dotty.tools.dotc.core.Phases.Phase
11-
import dotty.tools.dotc.core.tasty.TastyPrinter
11+
import dotty.tools.dotc.core.tasty.TastyAnsiiPrinter
1212
import dotty.tools.dotc.quoted.QuoteContextImpl
1313
import dotty.tools.io.File
1414

@@ -40,7 +40,7 @@ class DecompilationPrinter extends Phase {
4040
private def printToOutput(out: PrintStream)(using Context): Unit = {
4141
val unit = ctx.compilationUnit
4242
if (ctx.settings.printTasty.value)
43-
println(new TastyPrinter(unit.pickled.head._2()).printContents())
43+
println(new TastyAnsiiPrinter(unit.pickled.head._2()).printContents())
4444
else {
4545
val unitFile = unit.source.toString.replace("\\", "/").replace(".class", ".tasty")
4646
out.println(s"/** Decompiled from $unitFile */")

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import dotty.tools.dotc.core.Mode
1212
import dotty.tools.dotc.core.Symbols._
1313
import dotty.tools.dotc.core.Types._
1414
import dotty.tools.dotc.core.tasty.TreePickler.Hole
15-
import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyPrinter }
15+
import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyAnsiiPrinter }
1616
import dotty.tools.dotc.core.tasty.DottyUnpickler
1717
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
1818
import dotty.tools.dotc.report
@@ -173,14 +173,14 @@ object PickledQuotes {
173173
positionWarnings.foreach(report.warning(_))
174174

175175
val pickled = pickler.assembleParts()
176-
quotePickling.println(s"**** pickled quote\n${new TastyPrinter(pickled).printContents()}")
176+
quotePickling.println(s"**** pickled quote\n${new TastyAnsiiPrinter(pickled).printContents()}")
177177
pickled
178178
}
179179

180180
/** Unpickle TASTY bytes into it's tree */
181181
private def unpickle(pickledQuote: PickledQuote, isType: Boolean)(using Context): Tree = {
182182
val bytes = pickledQuote.bytes()
183-
quotePickling.println(s"**** unpickling quote from TASTY\n${new TastyPrinter(bytes).printContents()}")
183+
quotePickling.println(s"**** unpickling quote from TASTY\n${new TastyAnsiiPrinter(bytes).printContents()}")
184184

185185
val mode = if (isType) UnpickleMode.TypeTree else UnpickleMode.Term
186186
val unpickler = new DottyUnpickler(bytes, mode)

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Pickler extends Phase {
9090
if pickling ne noPrinter then
9191
pickling.synchronized {
9292
println(i"**** pickled info of $cls")
93-
println(new TastyPrinter(pickled).printContents())
93+
println(new TastyAnsiiPrinter(pickled).printContents())
9494
}
9595
pickled
9696
}(using ExecutionContext.global)

0 commit comments

Comments
 (0)