@@ -16,15 +16,17 @@ import dotty.tools.tasty.TastyReader
1616import dotty .tools .tasty .TastyFormat .{ASTsSection , PositionsSection , CommentsSection , AttributesSection }
1717import dotty .tools .tasty .TastyVersion
1818
19+ import dotty .tools .io .AbstractFile
20+
1921object DottyUnpickler {
2022
2123 /** Exception thrown if classfile is corrupted */
2224 class BadSignature (msg : String ) extends RuntimeException (msg)
2325
24- class TreeSectionUnpickler (posUnpickler : Option [ PositionUnpickler ], commentUnpickler : Option [CommentUnpickler ], attributeUnpickler : Option [AttributeUnpickler ])
26+ class TreeSectionUnpickler (compilationUnitInfo : CompilationUnitInfo , posUnpickler : Option [PositionUnpickler ], commentUnpickler : Option [CommentUnpickler ])
2527 extends SectionUnpickler [TreeUnpickler ](ASTsSection ) {
2628 def unpickle (reader : TastyReader , nameAtRef : NameTable ): TreeUnpickler =
27- new TreeUnpickler (reader, nameAtRef, posUnpickler, commentUnpickler, attributeUnpickler )
29+ new TreeUnpickler (reader, nameAtRef, compilationUnitInfo, posUnpickler, commentUnpickler )
2830 }
2931
3032 class PositionsSectionUnpickler extends SectionUnpickler [PositionUnpickler ](PositionsSection ) {
@@ -44,21 +46,28 @@ object DottyUnpickler {
4446}
4547
4648/** A class for unpickling Tasty trees and symbols.
49+ * @param tastyFile tasty file from which we unpickle (used for CompilationUnitInfo)
4750 * @param bytes the bytearray containing the Tasty file from which we unpickle
4851 * @param mode the tasty file contains package (TopLevel), an expression (Term) or a type (TypeTree)
4952 */
50- class DottyUnpickler (bytes : Array [Byte ], mode : UnpickleMode = UnpickleMode .TopLevel ) extends ClassfileParser .Embedded with tpd.TreeProvider {
53+ class DottyUnpickler (tastyFile : AbstractFile , bytes : Array [Byte ], mode : UnpickleMode = UnpickleMode .TopLevel ) extends ClassfileParser .Embedded with tpd.TreeProvider {
5154 import tpd .*
5255 import DottyUnpickler .*
5356
5457 val unpickler : TastyUnpickler = new TastyUnpickler (bytes)
58+
59+ val tastyAttributes : Attributes =
60+ unpickler.unpickle(new AttributesSectionUnpickler )
61+ .map(_.attributes).getOrElse(Attributes .empty)
62+ val compilationUnitInfo : CompilationUnitInfo =
63+ import unpickler .header .{majorVersion , minorVersion , experimentalVersion }
64+ val tastyVersion = TastyVersion (majorVersion, minorVersion, experimentalVersion)
65+ val tastyInfo = TastyInfo (tastyVersion, tastyAttributes)
66+ new CompilationUnitInfo (tastyFile, Some (tastyInfo))
67+
5568 private val posUnpicklerOpt = unpickler.unpickle(new PositionsSectionUnpickler )
5669 private val commentUnpicklerOpt = unpickler.unpickle(new CommentsSectionUnpickler )
57- private val attributeUnpicklerOpt = unpickler.unpickle(new AttributesSectionUnpickler )
58- private val treeUnpickler = unpickler.unpickle(treeSectionUnpickler(posUnpicklerOpt, commentUnpicklerOpt, attributeUnpicklerOpt)).get
59-
60- def tastyAttributes : Attributes =
61- attributeUnpicklerOpt.map(_.attributes).getOrElse(Attributes .empty)
70+ private val treeUnpickler = unpickler.unpickle(treeSectionUnpickler(posUnpicklerOpt, commentUnpicklerOpt)).get
6271
6372 /** Enter all toplevel classes and objects into their scopes
6473 * @param roots a set of SymDenotations that should be overwritten by unpickling
@@ -69,9 +78,8 @@ class DottyUnpickler(bytes: Array[Byte], mode: UnpickleMode = UnpickleMode.TopLe
6978 protected def treeSectionUnpickler (
7079 posUnpicklerOpt : Option [PositionUnpickler ],
7180 commentUnpicklerOpt : Option [CommentUnpickler ],
72- attributeUnpicklerOpt : Option [AttributeUnpickler ]
7381 ): TreeSectionUnpickler =
74- new TreeSectionUnpickler (posUnpicklerOpt, commentUnpicklerOpt, attributeUnpicklerOpt )
82+ new TreeSectionUnpickler (compilationUnitInfo, posUnpicklerOpt, commentUnpicklerOpt )
7583
7684 protected def computeRootTrees (using Context ): List [Tree ] = treeUnpickler.unpickle(mode)
7785
0 commit comments