Skip to content

Commit 236b931

Browse files
committed
Unpickle comments in TastyPrinter
1 parent f29e03b commit 236b931

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
3434
println("Trees:")
3535
unpickle(new TreeSectionUnpickler)
3636
unpickle(new PositionSectionUnpickler)
37+
unpickle(new CommentSectionUnpickler)
3738
}
3839

3940
class TreeSectionUnpickler extends SectionUnpickler[Unit]("ASTs") {
@@ -120,6 +121,19 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
120121
}
121122
}
122123

124+
class CommentSectionUnpickler extends SectionUnpickler[Unit]("Comments") {
125+
def unpickle(reader: TastyReader, tastyName: NameTable): Unit = {
126+
print(s" ${reader.endAddr.index - reader.currentAddr.index}")
127+
val comments = new CommentUnpickler(reader).comments
128+
println(s" comment bytes:")
129+
val sorted = comments.toSeq.sortBy(_._1.index)
130+
for ((addr, cmt) <- sorted) {
131+
print(treeColor("%10d".format(addr.index)))
132+
println(s": ${cmt.raw} (expanded = ${cmt.isExpanded})")
133+
}
134+
}
135+
}
136+
123137
private def nameColor(str: String): String = Magenta(str).show
124138
private def treeColor(str: String): String = Yellow(str).show
125139
private def lengthColor(str: String): String = Cyan(str).show

0 commit comments

Comments
 (0)