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