@@ -97,10 +97,14 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
97
97
sb.append(" tooling: " ).append(header.toolingVersion).append(" \n " )
98
98
sb.append(" UUID: " ).append(header.uuid).append(" \n " )
99
99
end if
100
- sb.append(" \n " )
101
100
102
101
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
+ ))
104
108
for ((name, idx) <- nameAtRef.contents.zipWithIndex) {
105
109
val index = nameStr(" %6d" .format(idx))
106
110
sb.append(index).append(" : " ).append(refs.nameRefToString(NameRef (idx))).append(" \n " )
@@ -187,19 +191,20 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
187
191
}
188
192
indent -= 2
189
193
}
190
- sb.append(s " \n\n Trees ( ${endAddr.index - startAddr.index} bytes, starting from $base ): " )
194
+ sb.append(sectionHeader( " Trees " , reader, lineEnd = false ) )
191
195
while (! isAtEnd) {
192
196
printTree()
193
197
newLine()
194
198
}
199
+ sb.append(" \n " )
195
200
}
196
201
}
197
202
198
203
class PositionSectionUnpickler (sb : StringBuilder ) extends PrinterSectionUnpickler [Unit ](PositionsSection ) {
199
204
def unpickle0 (reader : TastyReader )(using tastyName : NameRefs ): Unit = {
200
205
import reader .*
201
206
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) )
203
208
val lineSizes = posUnpickler.lineSizes
204
209
sb.append(s " lines: ${lineSizes.length}\n " )
205
210
sb.append(s " line sizes: \n " )
@@ -232,7 +237,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
232
237
import reader .*
233
238
val comments = new CommentUnpickler (reader).comments
234
239
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) )
236
241
val sorted = comments.toSeq.sortBy(_._1.index)
237
242
for ((addr, cmt) <- sorted) {
238
243
sb.append(treeStr(" %6d" .format(addr.index)))
@@ -245,7 +250,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
245
250
import dotty .tools .tasty .TastyFormat .*
246
251
def unpickle0 (reader : TastyReader )(using nameAtRef : NameRefs ): Unit = {
247
252
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) )
249
254
while ! isAtEnd do
250
255
// TODO: Should we elide attributes under testPickler? (i.e.
251
256
// 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) {
290
295
}
291
296
}
292
297
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
+
293
309
abstract class PrinterSectionUnpickler [T ](val name : String ) {
294
310
def unpickle0 (reader : TastyReader )(using refs : NameRefs ): T
295
311
}
0 commit comments