@@ -10,6 +10,7 @@ import TastyUnpickler._
10
10
import TastyBuffer .{Addr , NameRef }
11
11
import util .Positions .{Position , offsetToInt }
12
12
import collection .mutable
13
+ import printing .Highlighting ._
13
14
14
15
class TastyPrinter (bytes : Array [Byte ])(implicit ctx : Context ) {
15
16
@@ -22,8 +23,8 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
22
23
23
24
def printNames () =
24
25
for ((name, idx) <- nameAtRef.contents.zipWithIndex) {
25
- val index = " %4d: " .format(idx)
26
- println(index + nameToString(name))
26
+ val index = nameColor( " %4d" .format(idx) )
27
+ println(index + " : " + nameToString(name))
27
28
}
28
29
29
30
def printContents (): Unit = {
@@ -41,13 +42,13 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
41
42
import reader ._
42
43
var indent = 0
43
44
def newLine () = {
44
- val length = " %5d: " .format(index(currentAddr) - index(startAddr))
45
- print(s " \n $length" + " " * indent)
45
+ val length = treeColor( " %5d" .format(index(currentAddr) - index(startAddr) ))
46
+ print(s " \n $length: " + " " * indent)
46
47
}
47
- def printNat () = print(" " + readNat())
48
+ def printNat () = print(Yellow ( " " + readNat()).show )
48
49
def printName () = {
49
50
val idx = readNat()
50
- print(" " ) ;print( idx); print( " [ " ); print( nameRefToString(NameRef (idx))); print( " ]" )
51
+ print(nameColor( " " + idx + " [ " + nameRefToString(NameRef (idx)) + " ]" ).show )
51
52
}
52
53
def printTree (): Unit = {
53
54
newLine()
@@ -56,7 +57,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
56
57
indent += 2
57
58
if (tag >= firstLengthTreeTag) {
58
59
val len = readNat()
59
- print(s " ( $len) " )
60
+ print(s " ( ${lengthColor( len.toString)} ) " )
60
61
val end = currentAddr + len
61
62
def printTrees () = until(end)(printTree())
62
63
tag match {
@@ -83,7 +84,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
83
84
}
84
85
else if (tag >= firstNatASTTreeTag) {
85
86
tag match {
86
- case IDENT | SELECT | TERMREF | TYPEREF | SELFDEF => printName()
87
+ case IDENT | IDENTtpt | SELECT | TERMREF | TYPEREF | SELFDEF => printName()
87
88
case _ => printNat()
88
89
}
89
90
printTree()
@@ -108,11 +109,18 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
108
109
109
110
class PositionSectionUnpickler extends SectionUnpickler [Unit ](" Positions" ) {
110
111
def unpickle (reader : TastyReader , tastyName : NameTable ): Unit = {
111
- print(s " ${reader.endAddr.index - reader.currentAddr.index}" )
112
+ print(s " ${reader.endAddr.index - reader.currentAddr.index}" )
112
113
val positions = new PositionUnpickler (reader).positions
113
114
println(s " position bytes: " )
114
115
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) {
117
+ print(treeColor(" %10d" .format(addr.index)))
118
+ println(s " : ${offsetToInt(pos.start)} .. ${pos.end}" )
119
+ }
116
120
}
117
121
}
122
+
123
+ private def nameColor (str : String ): String = Magenta (str).show
124
+ private def treeColor (str : String ): String = Yellow (str).show
125
+ private def lengthColor (str : String ): String = Cyan (str).show
118
126
}
0 commit comments