@@ -42,18 +42,19 @@ import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions
42
42
* @version 1.0
43
43
*
44
44
*/
45
- trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
45
+ trait BCodeHelpers extends BCodeIdiomatic {
46
46
// for some reason singleton types aren't allowed in constructor calls. will need several casts in code to enforce
47
-
48
47
// import global._
49
- // import bTypes._
50
- // import coreBTypes._
51
48
import bTypes ._
52
49
import tpd ._
53
50
import coreBTypes ._
54
51
import int .{_ , given }
55
52
import DottyBackendInterface ._
56
53
54
+ // We need to access GenBCode phase to get access to post-processor components.
55
+ // At this point it should always be initialized already.
56
+ protected lazy val backendUtils = genBCodePhase.asInstanceOf [GenBCode ].postProcessor.backendUtils
57
+
57
58
def ScalaATTRName : String = " Scala"
58
59
def ScalaSignatureATTRName : String = " ScalaSig"
59
60
@@ -64,96 +65,12 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
64
65
65
66
val bCodeAsmCommon : BCodeAsmCommon [int.type ] = new BCodeAsmCommon (int)
66
67
67
- /*
68
- * must-single-thread
69
- */
70
- def getFileForClassfile (base : AbstractFile , clsName : String , suffix : String ): AbstractFile = {
71
- getFile(base, clsName, suffix)
72
- }
73
-
74
- /*
75
- * must-single-thread
76
- */
77
- def getOutFolder (csym : Symbol , cName : String ): AbstractFile = {
78
- try {
79
- outputDirectory
80
- } catch {
81
- case ex : Throwable =>
82
- report.error(em " Couldn't create file for class $cName\n ${ex.getMessage}" , ctx.source.atSpan(csym.span))
83
- null
84
- }
85
- }
86
-
87
68
final def traitSuperAccessorName (sym : Symbol ): String = {
88
69
val nameString = sym.javaSimpleName.toString
89
70
if (sym.name == nme.TRAIT_CONSTRUCTOR ) nameString
90
71
else nameString + " $"
91
72
}
92
73
93
- // -----------------------------------------------------------------------------------------
94
- // finding the least upper bound in agreement with the bytecode verifier (given two internal names handed by ASM)
95
- // Background:
96
- // http://gallium.inria.fr/~xleroy/publi/bytecode-verification-JAR.pdf
97
- // http://comments.gmane.org/gmane.comp.java.vm.languages/2293
98
- // https://issues.scala-lang.org/browse/SI-3872
99
- // -----------------------------------------------------------------------------------------
100
-
101
- /* An `asm.ClassWriter` that uses `jvmWiseLUB()`
102
- * The internal name of the least common ancestor of the types given by inameA and inameB.
103
- * It's what ASM needs to know in order to compute stack map frames, http://asm.ow2.org/doc/developer-guide.html#controlflow
104
- */
105
- final class CClassWriter (flags : Int ) extends asm.ClassWriter (flags) {
106
-
107
- /**
108
- * This method is thread-safe: it depends only on the BTypes component, which does not depend
109
- * on global. TODO @lry move to a different place where no global is in scope, on bTypes.
110
- */
111
- override def getCommonSuperClass (inameA : String , inameB : String ): String = {
112
- val a = classBTypeFromInternalName(inameA)
113
- val b = classBTypeFromInternalName(inameB)
114
- val lub = a.jvmWiseLUB(b)
115
- val lubName = lub.internalName
116
- assert(lubName != " scala/Any" )
117
- lubName // ASM caches the answer during the lifetime of a ClassWriter. We outlive that. Not sure whether caching on our side would improve things.
118
- }
119
- }
120
-
121
- /*
122
- * must-single-thread
123
- */
124
- def initBytecodeWriter (): BytecodeWriter = {
125
- (None : Option [AbstractFile ] /* getSingleOutput*/ ) match { // todo: implement
126
- case Some (f) if f.hasExtension(" jar" ) =>
127
- new DirectToJarfileWriter (f.file)
128
- case _ =>
129
- factoryNonJarBytecodeWriter()
130
- }
131
- }
132
-
133
- /*
134
- * Populates the InnerClasses JVM attribute with `refedInnerClasses`. See also the doc on inner
135
- * classes in BTypes.scala.
136
- *
137
- * `refedInnerClasses` may contain duplicates, need not contain the enclosing inner classes of
138
- * each inner class it lists (those are looked up and included).
139
- *
140
- * This method serializes in the InnerClasses JVM attribute in an appropriate order,
141
- * not necessarily that given by `refedInnerClasses`.
142
- *
143
- * can-multi-thread
144
- */
145
- final def addInnerClasses (jclass : asm.ClassVisitor , declaredInnerClasses : List [ClassBType ], refedInnerClasses : List [ClassBType ]): Unit = {
146
- // sorting ensures nested classes are listed after their enclosing class thus satisfying the Eclipse Java compiler
147
- val allNestedClasses = new mutable.TreeSet [ClassBType ]()(Ordering .by(_.internalName))
148
- allNestedClasses ++= declaredInnerClasses
149
- refedInnerClasses.foreach(allNestedClasses ++= _.enclosingNestedClassesChain)
150
- for nestedClass <- allNestedClasses
151
- do {
152
- // Extract the innerClassEntry - we know it exists, enclosingNestedClassesChain only returns nested classes.
153
- val Some (e) = nestedClass.innerClassAttributeEntry: @ unchecked
154
- jclass.visitInnerClass(e.name, e.outerName, e.innerName, e.flags)
155
- }
156
- }
157
74
158
75
/*
159
76
* can-multi-thread
@@ -680,7 +597,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
680
597
681
598
val mirrorClass = new asm.tree.ClassNode
682
599
mirrorClass.visit(
683
- classfileVersion,
600
+ backendUtils. classfileVersion,
684
601
bType.info.flags,
685
602
mirrorName,
686
603
null /* no java-generic-signature */ ,
0 commit comments