@@ -40,7 +40,10 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
40
40
41
41
private lazy val mirrorCodeGen = Impl .JMirrorBuilder ()
42
42
43
- def gen (unit : CompilationUnit ): Unit = {
43
+ def genUnit (unit : CompilationUnit ): GeneratedDefs = {
44
+ val generatedClasses = mutable.ListBuffer .empty[GeneratedClass ]
45
+ val generatedTasty = mutable.ListBuffer .empty[GeneratedTasty ]
46
+
44
47
val postProcessor = Phases .genBCodePhase match {
45
48
case genBCode : GenBCode => genBCode.postProcessor
46
49
case _ => null
@@ -52,7 +55,7 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
52
55
val sourceFile = unit.source.file
53
56
54
57
def registerGeneratedClass (classNode : ClassNode , isArtifact : Boolean ) = if (classNode != null ){
55
- postProcessor. generatedClasses += GeneratedClass (classNode, sourceFile, isArtifact, onFileCreated(classNode, sym, unit.source))
58
+ generatedClasses += GeneratedClass (classNode, sourceFile, isArtifact, onFileCreated(classNode, sym, unit.source))
56
59
}
57
60
58
61
val plainC = genClass(cd, unit)
@@ -68,12 +71,33 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
68
71
69
72
if sym.isClass then
70
73
val attrNode = if (mirrorC ne null ) mirrorC else plainC
71
- setTastyAttributes (sym, attrNode, postProcessor, unit )
74
+ genTastyAndSetAttributes (sym, attrNode)
72
75
catch
73
76
case ex : Throwable =>
74
77
ex.printStackTrace()
75
78
report.error(s " Error while emitting ${unit.source}\n ${ex.getMessage}" , NoSourcePosition )
76
79
80
+
81
+ def genTastyAndSetAttributes (claszSymbol : Symbol , store : ClassNode ): Unit =
82
+ import Impl .createJAttribute
83
+ for (binary <- unit.pickled.get(claszSymbol.asClass)) {
84
+ generatedTasty += GeneratedTasty (store, binary)
85
+ val tasty =
86
+ val uuid = new TastyHeaderUnpickler (binary()).readHeader()
87
+ val lo = uuid.getMostSignificantBits
88
+ val hi = uuid.getLeastSignificantBits
89
+
90
+ // TASTY attribute is created but only the UUID bytes are stored in it.
91
+ // A TASTY attribute has length 16 if and only if the .tasty file exists.
92
+ val buffer = new TastyBuffer (16 )
93
+ buffer.writeUncompressedLong(lo)
94
+ buffer.writeUncompressedLong(hi)
95
+ buffer.bytes
96
+
97
+ val dataAttr = createJAttribute(nme.TASTYATTR .mangledString, tasty, 0 , tasty.length)
98
+ store.visitAttribute(dataAttr)
99
+ }
100
+
77
101
def genClassDefs (tree : Tree ): Unit =
78
102
tree match {
79
103
case EmptyTree => ()
@@ -83,8 +107,10 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
83
107
}
84
108
85
109
genClassDefs(unit.tpdTree)
110
+ GeneratedDefs (generatedClasses.toList, generatedTasty.toList)
86
111
}
87
112
113
+ // Creates a callback that would be evaluated in PostProcessor after creating a file
88
114
private def onFileCreated (cls : ClassNode , claszSymbol : Symbol , sourceFile : interfaces.SourceFile ): AbstractFile => Unit = clsFile => {
89
115
val (fullClassName, isLocal) = atPhase(sbtExtractDependenciesPhase) {
90
116
(ExtractDependencies .classNameAsString(claszSymbol), claszSymbol.isLocal)
@@ -112,25 +138,6 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
112
138
override def jfile = Optional .ofNullable(absfile.file)
113
139
}
114
140
115
- private def setTastyAttributes (claszSymbol : Symbol , store : ClassNode , postProcessor : PostProcessor , unit : CompilationUnit ): Unit =
116
- import Impl .createJAttribute
117
- for (binary <- unit.pickled.get(claszSymbol.asClass)) {
118
- postProcessor.generatedTasty += GeneratedTasty (store, binary)
119
- val tasty =
120
- val uuid = new TastyHeaderUnpickler (binary()).readHeader()
121
- val lo = uuid.getMostSignificantBits
122
- val hi = uuid.getLeastSignificantBits
123
-
124
- // TASTY attribute is created but only the UUID bytes are stored in it.
125
- // A TASTY attribute has length 16 if and only if the .tasty file exists.
126
- val buffer = new TastyBuffer (16 )
127
- buffer.writeUncompressedLong(lo)
128
- buffer.writeUncompressedLong(hi)
129
- buffer.bytes
130
-
131
- val dataAttr = createJAttribute(nme.TASTYATTR .mangledString, tasty, 0 , tasty.length)
132
- store.visitAttribute(dataAttr)
133
- }
134
141
135
142
private def genClass (cd : TypeDef , unit : CompilationUnit ): ClassNode = {
136
143
val b = new Impl .SyncAndTryBuilder (unit) {}
@@ -175,4 +182,4 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
175
182
protected val primitives : DottyPrimitives = self.primitives
176
183
}
177
184
object Impl extends ImplEarlyInit with BCodeSyncAndTry
178
- }
185
+ }
0 commit comments