Skip to content

Commit fbee942

Browse files
committed
Add color to tasty printer
Makes clear the distinction between name indices, tree indices and tree lengths.
1 parent 1d24b19 commit fbee942

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import TastyUnpickler._
1010
import TastyBuffer.{Addr, NameRef}
1111
import util.Positions.{Position, offsetToInt}
1212
import collection.mutable
13+
import printing.Highlighting._
1314

1415
class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
1516

@@ -22,8 +23,8 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
2223

2324
def printNames() =
2425
for ((name, idx) <- nameAtRef.contents.zipWithIndex) {
25-
val index = "%4d: ".format(idx)
26-
println(index + nameToString(name))
26+
val index = Magenta("%4d".format(idx))
27+
println(index + ": " + nameToString(name))
2728
}
2829

2930
def printContents(): Unit = {
@@ -41,13 +42,13 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
4142
import reader._
4243
var indent = 0
4344
def newLine() = {
44-
val length = "%5d:".format(index(currentAddr) - index(startAddr))
45-
print(s"\n $length" + " " * indent)
45+
val length = Yellow("%5d".format(index(currentAddr) - index(startAddr))).show
46+
print(s"\n $length:" + " " * indent)
4647
}
47-
def printNat() = print(" " + readNat())
48+
def printNat() = print(Yellow(" " + readNat()).show)
4849
def printName() = {
4950
val idx = readNat()
50-
print(" ") ;print(idx); print("["); print(nameRefToString(NameRef(idx))); print("]")
51+
print(Magenta(" " + idx + " [" + nameRefToString(NameRef(idx)) + "]").show)
5152
}
5253
def printTree(): Unit = {
5354
newLine()
@@ -56,7 +57,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
5657
indent += 2
5758
if (tag >= firstLengthTreeTag) {
5859
val len = readNat()
59-
print(s"($len)")
60+
print(s"(${Cyan(len.toString).show})")
6061
val end = currentAddr + len
6162
def printTrees() = until(end)(printTree())
6263
tag match {
@@ -83,7 +84,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
8384
}
8485
else if (tag >= firstNatASTTreeTag) {
8586
tag match {
86-
case IDENT | SELECT | TERMREF | TYPEREF | SELFDEF => printName()
87+
case IDENT | IDENTtpt | SELECT | TERMREF | TYPEREF | SELFDEF => printName()
8788
case _ => printNat()
8889
}
8990
printTree()
@@ -112,7 +113,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
112113
val positions = new PositionUnpickler(reader).positions
113114
println(s" position bytes:")
114115
val sorted = positions.toSeq.sortBy(_._1.index)
115-
for ((addr, pos) <- sorted) println(s" ${addr.index}: ${offsetToInt(pos.start)} .. ${pos.end}")
116+
for ((addr, pos) <- sorted) println(s" ${Yellow(addr.index.toString).show}: ${offsetToInt(pos.start)} .. ${pos.end}")
116117
}
117118
}
118119
}

0 commit comments

Comments
 (0)