@@ -10,6 +10,7 @@ import TastyUnpickler._
1010import TastyBuffer .{Addr , NameRef }
1111import util .Positions .{Position , offsetToInt }
1212import collection .mutable
13+ import printing .Highlighting ._
1314
1415class 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 = nameColor( " %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 = treeColor( " %5d" .format(index(currentAddr) - index(startAddr) ))
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(nameColor( " " + 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 " ( ${lengthColor( len.toString)} ) " )
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()
@@ -108,11 +109,18 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
108109
109110 class PositionSectionUnpickler extends SectionUnpickler [Unit ](" Positions" ) {
110111 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}" )
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) {
117+ print(treeColor(" %10d" .format(addr.index)))
118+ println(s " : ${offsetToInt(pos.start)} .. ${pos.end}" )
119+ }
116120 }
117121 }
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
118126}
0 commit comments