@@ -97,10 +97,14 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
9797 sb.append(" tooling: " ).append(header.toolingVersion).append(" \n " )
9898 sb.append(" UUID: " ).append(header.uuid).append(" \n " )
9999 end if
100- sb.append(" \n " )
101100
102101 private def printNames (sb : StringBuilder )(using refs : NameRefs ): Unit =
103- sb.append(s " Names ( ${unpickler.namesEnd.index - unpickler.namesStart.index} bytes, starting from ${unpickler.namesStart.index}): \n " )
102+ sb.append(sectionHeader(
103+ name = " Names" ,
104+ count = (unpickler.namesEnd.index - unpickler.namesStart.index).toString,
105+ base = showBase(unpickler.namesStart.index),
106+ lineEnd = true
107+ ))
104108 for ((name, idx) <- nameAtRef.contents.zipWithIndex) {
105109 val index = nameStr(" %6d" .format(idx))
106110 sb.append(index).append(" : " ).append(refs.nameRefToString(NameRef (idx))).append(" \n " )
@@ -187,19 +191,20 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
187191 }
188192 indent -= 2
189193 }
190- sb.append(s " \n\n Trees ( ${endAddr.index - startAddr.index} bytes, starting from $base ): " )
194+ sb.append(sectionHeader( " Trees " , reader, lineEnd = false ) )
191195 while (! isAtEnd) {
192196 printTree()
193197 newLine()
194198 }
199+ sb.append(" \n " )
195200 }
196201 }
197202
198203 class PositionSectionUnpickler (sb : StringBuilder ) extends PrinterSectionUnpickler [Unit ](PositionsSection ) {
199204 def unpickle0 (reader : TastyReader )(using tastyName : NameRefs ): Unit = {
200205 import reader .*
201206 val posUnpickler = new PositionUnpickler (reader, tastyName)
202- sb.append(s " \n\n Positions ( ${reader.endAddr.index - reader.startAddr.index} bytes, starting from $base ): \n " )
207+ sb.append(sectionHeader( " Positions " , reader) )
203208 val lineSizes = posUnpickler.lineSizes
204209 sb.append(s " lines: ${lineSizes.length}\n " )
205210 sb.append(s " line sizes: \n " )
@@ -232,7 +237,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
232237 import reader .*
233238 val comments = new CommentUnpickler (reader).comments
234239 if ! comments.isEmpty then
235- sb.append(s " \n\n Comments ( ${reader.endAddr.index - reader.startAddr.index} bytes, starting from $base ): \n " )
240+ sb.append(sectionHeader( " Comments " , reader) )
236241 val sorted = comments.toSeq.sortBy(_._1.index)
237242 for ((addr, cmt) <- sorted) {
238243 sb.append(treeStr(" %6d" .format(addr.index)))
@@ -245,7 +250,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
245250 import dotty .tools .tasty .TastyFormat .*
246251 def unpickle0 (reader : TastyReader )(using nameAtRef : NameRefs ): Unit = {
247252 import reader .*
248- sb.append(s " \n\n Attributes ( ${reader.endAddr.index - reader.startAddr.index} bytes, starting from $base ): \n " )
253+ sb.append(sectionHeader( " Attributes " , reader) )
249254 while ! isAtEnd do
250255 // TODO: Should we elide attributes under testPickler? (i.e.
251256 // if we add new attributes many check files will need to be updated)
@@ -290,6 +295,17 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
290295 }
291296 }
292297
298+ private final def showBase (index : Int ): String =
299+ if testPickler then " <elided base index>" else index.toString()
300+
301+ private final def sectionHeader (name : String , reader : TastyReader , lineEnd : Boolean = true ): String =
302+ val count = reader.endAddr.index - reader.startAddr.index
303+ sectionHeader(name, count.toString, {showBase(reader.base)}, lineEnd)
304+
305+ private final def sectionHeader (name : String , count : String , base : String , lineEnd : Boolean ): String =
306+ val suffix = if lineEnd then " \n " else " "
307+ s " \n $name ( $count bytes, starting from $base): $suffix"
308+
293309 abstract class PrinterSectionUnpickler [T ](val name : String ) {
294310 def unpickle0 (reader : TastyReader )(using refs : NameRefs ): T
295311 }
0 commit comments