@@ -16,15 +16,17 @@ import dotty.tools.tasty.TastyReader
16
16
import dotty .tools .tasty .TastyFormat .{ASTsSection , PositionsSection , CommentsSection , AttributesSection }
17
17
import dotty .tools .tasty .TastyVersion
18
18
19
+ import dotty .tools .io .AbstractFile
20
+
19
21
object DottyUnpickler {
20
22
21
23
/** Exception thrown if classfile is corrupted */
22
24
class BadSignature (msg : String ) extends RuntimeException (msg)
23
25
24
- class TreeSectionUnpickler (posUnpickler : Option [ PositionUnpickler ], commentUnpickler : Option [CommentUnpickler ], attributeUnpickler : Option [AttributeUnpickler ])
26
+ class TreeSectionUnpickler (compilationUnitInfo : CompilationUnitInfo , posUnpickler : Option [PositionUnpickler ], commentUnpickler : Option [CommentUnpickler ])
25
27
extends SectionUnpickler [TreeUnpickler ](ASTsSection ) {
26
28
def unpickle (reader : TastyReader , nameAtRef : NameTable ): TreeUnpickler =
27
- new TreeUnpickler (reader, nameAtRef, posUnpickler, commentUnpickler, attributeUnpickler )
29
+ new TreeUnpickler (reader, nameAtRef, compilationUnitInfo, posUnpickler, commentUnpickler )
28
30
}
29
31
30
32
class PositionsSectionUnpickler extends SectionUnpickler [PositionUnpickler ](PositionsSection ) {
@@ -44,21 +46,28 @@ object DottyUnpickler {
44
46
}
45
47
46
48
/** A class for unpickling Tasty trees and symbols.
49
+ * @param tastyFile tasty file from which we unpickle (used for CompilationUnitInfo)
47
50
* @param bytes the bytearray containing the Tasty file from which we unpickle
48
51
* @param mode the tasty file contains package (TopLevel), an expression (Term) or a type (TypeTree)
49
52
*/
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 {
51
54
import tpd .*
52
55
import DottyUnpickler .*
53
56
54
57
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
+
55
68
private val posUnpicklerOpt = unpickler.unpickle(new PositionsSectionUnpickler )
56
69
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
62
71
63
72
/** Enter all toplevel classes and objects into their scopes
64
73
* @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
69
78
protected def treeSectionUnpickler (
70
79
posUnpicklerOpt : Option [PositionUnpickler ],
71
80
commentUnpicklerOpt : Option [CommentUnpickler ],
72
- attributeUnpicklerOpt : Option [AttributeUnpickler ]
73
81
): TreeSectionUnpickler =
74
- new TreeSectionUnpickler (posUnpicklerOpt, commentUnpicklerOpt, attributeUnpicklerOpt )
82
+ new TreeSectionUnpickler (compilationUnitInfo, posUnpicklerOpt, commentUnpicklerOpt )
75
83
76
84
protected def computeRootTrees (using Context ): List [Tree ] = treeUnpickler.unpickle(mode)
77
85
0 commit comments