3
3
* @author Martin Odersky
4
4
*/
5
5
6
- package dotty .tools
7
- package dotc
6
+ package dotty .tools .dotc
8
7
package backend .jvm
9
8
10
9
import dotty .tools .asm
11
10
import scala .annotation .switch
12
11
import scala .collection .{ immutable , mutable }
13
12
import dotty .tools .io .AbstractFile
14
13
15
- import dotc . ast .Trees ._
16
-
17
- import dotc . core .StdNames
18
- import dotc . core .Types .Type
19
- import dotc . core .Symbols .{Symbol , NoSymbol }
20
- import dotc . core .SymDenotations ._
21
- import dotc . core .Flags
22
- import dotc . core .StdNames .{nme , tpnme }
14
+ import ast .Trees ._
15
+ import core . Contexts . Context
16
+ import core .StdNames
17
+ import core .Types .Type
18
+ import core .Symbols .{Symbol , NoSymbol }
19
+ import core .SymDenotations ._
20
+ import core .Flags
21
+ import core .StdNames .{nme , tpnme }
23
22
24
23
/*
25
24
* Traits encapsulating functionality to convert Scala AST Trees into ASM ClassNodes.
@@ -209,7 +208,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
209
208
/*
210
209
* must-single-thread
211
210
*/
212
- def initBytecodeWriter (entryPoints : List [Symbol ])(implicit ctx : core. Contexts . Context ): BytecodeWriter = {
211
+ def initBytecodeWriter (entryPoints : List [Symbol ])(implicit ctx : Context ): BytecodeWriter = {
213
212
settings.outputDirs.getSingleOutput match {
214
213
case Some (f) if f hasExtension " jar" =>
215
214
// If no main class was specified, see if there's only one
@@ -236,7 +235,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
236
235
/*
237
236
* must-single-thread
238
237
*/
239
- def fieldSymbols (cls : Symbol )(implicit ctx : core. Contexts . Context ): List [Symbol ] = {
238
+ def fieldSymbols (cls : Symbol )(implicit ctx : Context ): List [Symbol ] = {
240
239
for (f <- cls.info.decls.toList ;
241
240
if ! (f is Flags .Method ) && f.isTerm && ! (f is Flags .ModuleVal )
242
241
) yield f;
@@ -296,6 +295,17 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
296
295
297
296
} // end of method addInnerClassesASM()
298
297
298
+ /**
299
+ * All components (e.g. BCPickles, BCInnerClassGen) of the builder classes
300
+ * extend this trait to have access to the context.
301
+ *
302
+ * The context is provided by the three leaf classes (PlainClassBuilder,
303
+ * JMirrorBuilder and JBeanInfoBuilder) as class parameter.
304
+ */
305
+ trait HasContext {
306
+ implicit protected val ctx : Context
307
+ }
308
+
299
309
/*
300
310
* Custom attribute (JVMS 4.7.1) "ScalaSig" used as marker only
301
311
* i.e., the pickle is contained in a custom annotation, see:
@@ -308,7 +318,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
308
318
* while the "Signature" attribute can be associated to classes, methods, and fields.)
309
319
*
310
320
*/
311
- trait BCPickles {
321
+ trait BCPickles extends HasContext {
312
322
313
323
import scala .reflect .internal .pickling .{ PickleFormat , PickleBuffer }
314
324
@@ -383,7 +393,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
383
393
384
394
} // end of trait BCPickles
385
395
386
- trait BCInnerClassGen {
396
+ trait BCInnerClassGen extends HasContext {
387
397
388
398
def debugLevel = settings.debuginfo.indexOfChoice
389
399
@@ -405,14 +415,14 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
405
415
*
406
416
* must-single-thread
407
417
*/
408
- final def internalName (sym : Symbol )( implicit ctx : core. Contexts . Context ) : String = asmClassType(sym).getInternalName
418
+ final def internalName (sym : Symbol ): String = asmClassType(sym).getInternalName
409
419
410
420
/*
411
421
* Tracks (if needed) the inner class given by `sym`.
412
422
*
413
423
* must-single-thread
414
424
*/
415
- final def asmClassType (sym : Symbol )( implicit ctx : core. Contexts . Context ) : BType = {
425
+ final def asmClassType (sym : Symbol ): BType = {
416
426
assert(
417
427
hasInternalName(sym),
418
428
{
@@ -438,10 +448,8 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
438
448
* Tracks (if needed) the inner class given by `t`.
439
449
*
440
450
* must-single-thread
441
- *
442
- * TODO(lry): check if `ctx` should be a paramter of the class instead.
443
451
*/
444
- final def toTypeKind (t : Type )( implicit ctx : dotc.core. Contexts . Context ) : BType = {
452
+ final def toTypeKind (t : Type ): BType = {
445
453
446
454
/* Interfaces have to be handled delicately to avoid introducing spurious errors,
447
455
* but if we treat them all as AnyRef we lose too much information.
@@ -535,7 +543,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
535
543
/*
536
544
* must-single-thread
537
545
*/
538
- def asmMethodType (msym : Symbol )( implicit ctx : core. Contexts . Context ) : BType = {
546
+ def asmMethodType (msym : Symbol ): BType = {
539
547
assert(msym is Flags .Method , s " not a method-symbol: $msym" )
540
548
val resT : BType =
541
549
if (msym.isClassConstructor || msym.isConstructor) BType .VOID_TYPE
@@ -550,7 +558,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
550
558
*
551
559
* must-single-thread
552
560
*/
553
- final def trackMemberClasses (csym : Symbol , lateClosuresBTs : List [BType ])( implicit ctx : core. Contexts . Context ) : List [BType ] = {
561
+ final def trackMemberClasses (csym : Symbol , lateClosuresBTs : List [BType ]): List [BType ] = {
554
562
val lateInnerClasses = exitingErasure {
555
563
for (sym <- List (csym, csym.linkedClassOfClass); memberc <- sym.info.decls.map(innerClassSymbolFor) if memberc.isClass)
556
564
yield memberc
@@ -574,14 +582,14 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
574
582
*
575
583
* must-single-thread
576
584
*/
577
- final def descriptor (t : Type )( implicit ctx : core. Contexts . Context ) : String = (toTypeKind(t).getDescriptor)
585
+ final def descriptor (t : Type ): String = (toTypeKind(t).getDescriptor)
578
586
579
587
/*
580
588
* Tracks (if needed) the inner class given by `sym`.
581
589
*
582
590
* must-single-thread
583
591
*/
584
- final def descriptor (sym : Symbol )( implicit ctx : core. Contexts . Context ) : String = (asmClassType(sym).getDescriptor)
592
+ final def descriptor (sym : Symbol ): String = (asmClassType(sym).getDescriptor)
585
593
586
594
} // end of trait BCInnerClassGen
587
595
@@ -774,7 +782,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
774
782
775
783
} // end of trait BCAnnotGen
776
784
777
- trait BCJGenSigGen {
785
+ trait BCJGenSigGen extends HasContext {
778
786
779
787
// @M don't generate java generics sigs for (members of) implementation
780
788
// classes, as they are monomorphic (TODO: ok?)
@@ -996,7 +1004,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
996
1004
997
1005
} // end of trait BCForwardersGen
998
1006
999
- trait BCClassGen extends BCInnerClassGen {
1007
+ trait BCClassGen extends BCInnerClassGen with HasContext {
1000
1008
1001
1009
// Used as threshold above which a tableswitch bytecode instruction is preferred over a lookupswitch.
1002
1010
// There's a space tradeoff between these multi-branch instructions (details in the JVM spec).
@@ -1081,15 +1089,18 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
1081
1089
1082
1090
} // end of class JBuilder
1083
1091
1084
- /* functionality for building plain and mirror classes */
1092
+ /* functionality for building plain and mirror classes
1093
+ * TODO(lrytz): it seems only `JMirrorBuilder` extends `JCommonBuilder`.
1094
+ * So this class could be removed.
1095
+ */
1085
1096
abstract class JCommonBuilder
1086
1097
extends JBuilder
1087
1098
with BCAnnotGen
1088
1099
with BCForwardersGen
1089
1100
with BCPickles { }
1090
1101
1091
1102
/* builder of mirror classes */
1092
- class JMirrorBuilder extends JCommonBuilder {
1103
+ class JMirrorBuilder ( implicit protected val ctx : Context ) extends JCommonBuilder {
1093
1104
1094
1105
private var cunit : CompilationUnit = _
1095
1106
def getCurrentCUnit (): CompilationUnit = cunit;
@@ -1144,7 +1155,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
1144
1155
} // end of class JMirrorBuilder
1145
1156
1146
1157
/* builder of bean info classes */
1147
- class JBeanInfoBuilder extends JBuilder {
1158
+ class JBeanInfoBuilder ( implicit protected val ctx : Context ) extends JBuilder {
1148
1159
1149
1160
/*
1150
1161
* Generate a bean info class that describes the given class.
0 commit comments