Skip to content

Commit 5973bf9

Browse files
committed
Merge pull request #15 from magarciaEPFL/b3
Flags.ModuleVal, Flags.PackageClass
2 parents 7d08ef7 + f5d03f2 commit 5973bf9

10 files changed

+185
-178
lines changed

src/dotty/tools/dotc/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import scala.annotation.switch
1515
import dotty.tools.asm
1616

1717
import dotc.ast.Trees._
18+
import core.Flags
1819
import core.Types.Type
1920
import core.StdNames
2021
import core.Symbols.{Symbol, NoSymbol}
@@ -52,9 +53,9 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
5253

5354
/* ---------------- helper utils for generating methods and code ---------------- */
5455

55-
def emit(opc: Int) { mnode.visitInsn(opc) }
56+
def emit(opc: Int): Unit = { mnode.visitInsn(opc) }
5657

57-
def emitZeroOf(tk: BType) {
58+
def emitZeroOf(tk: BType): Unit = {
5859
(tk.sort: @switch) match {
5960
case asm.Type.BOOLEAN => bc.boolconst(false)
6061
case asm.Type.BYTE |
@@ -74,7 +75,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
7475
* Two main cases: `tree` is an assignment,
7576
* otherwise an `adapt()` to UNIT is performed if needed.
7677
*/
77-
def genStat(tree: Tree) {
78+
def genStat(tree: Tree): Unit = {
7879
lineNumber(tree)
7980
tree match {
8081
case Assign(lhs @ Select(_, _), rhs) =>
@@ -340,12 +341,12 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
340341
)
341342
}
342343

343-
def genLoad(tree: Tree) {
344+
def genLoad(tree: Tree): Unit = {
344345
genLoad(tree, tpeTK(tree))
345346
}
346347

347348
/* Generate code for trees that produce values on the stack */
348-
def genLoad(tree: Tree, expectedType: BType) {
349+
def genLoad(tree: Tree, expectedType: BType): Unit = {
349350
var generatedType = expectedType
350351

351352
lineNumber(tree)
@@ -392,7 +393,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
392393
// case ApplyDynamic(qual, args) => sys.error("No invokedynamic support yet.")
393394

394395
case This(qual) =>
395-
val symIsModuleClass = tree.symbol.isModuleClass
396+
val symIsModuleClass = tree.symbol is Flags.ModuleVal
396397
assert(tree.symbol == claszSymbol || symIsModuleClass,
397398
s"Trying to access the this of another class: tree.symbol = ${tree.symbol}, class symbol = $claszSymbol compilation unit: $cunit")
398399
if (symIsModuleClass && tree.symbol != claszSymbol) {
@@ -406,7 +407,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
406407
}
407408

408409
case Select(Ident(nme.EMPTY_PACKAGE_NAME), module) =>
409-
assert(tree.symbol.isModule, s"Selection of non-module from empty package: $tree sym: ${tree.symbol} at: ${tree.pos}")
410+
assert(tree.symbol is Flags.ModuleVal, s"Selection of non-module from empty package: $tree sym: ${tree.symbol} at: ${tree.pos}")
410411
genLoadModule(tree)
411412

412413
case Select(qualifier, selector) =>
@@ -416,9 +417,9 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
416417
debuglog(s"Host class of $sym with qual $qualifier (${qualifier.tpe}) is $hostClass")
417418
val qualSafeToElide = treeInfo isQualifierSafeToElide qualifier
418419

419-
def genLoadQualUnlessElidable() { if (!qualSafeToElide) { genLoadQualifier(tree) } }
420+
def genLoadQualUnlessElidable(): Unit = { if (!qualSafeToElide) { genLoadQualifier(tree) } }
420421

421-
if (sym.isModule) {
422+
if (sym is Flags.ModuleVal) {
422423
genLoadQualUnlessElidable()
423424
genLoadModule(tree)
424425
}
@@ -435,7 +436,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
435436
val sym = tree.symbol
436437
if (!sym.isPackage) {
437438
val tk = symInfoTK(sym)
438-
if (sym.isModule) { genLoadModule(tree) }
439+
if (sym is Flags.ModuleVal) { genLoadModule(tree) }
439440
else { locals.load(sym) }
440441
generatedType = tk
441442
}
@@ -481,20 +482,20 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
481482
/*
482483
* must-single-thread
483484
*/
484-
def fieldLoad( field: Symbol, hostClass: Symbol = null) {
485+
def fieldLoad( field: Symbol, hostClass: Symbol = null): Unit = {
485486
fieldOp(field, isLoad = true, hostClass)
486487
}
487488
/*
488489
* must-single-thread
489490
*/
490-
def fieldStore(field: Symbol, hostClass: Symbol = null) {
491+
def fieldStore(field: Symbol, hostClass: Symbol = null): Unit = {
491492
fieldOp(field, isLoad = false, hostClass)
492493
}
493494

494495
/*
495496
* must-single-thread
496497
*/
497-
private def fieldOp(field: Symbol, isLoad: Boolean, hostClass: Symbol) {
498+
private def fieldOp(field: Symbol, isLoad: Boolean, hostClass: Symbol): Unit = {
498499
// LOAD_FIELD.hostClass , CALL_METHOD.hostClass , and #4283
499500
val owner =
500501
if (hostClass == null) internalName(field.owner)
@@ -516,7 +517,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
516517
* must-single-thread
517518
* Otherwise it's safe to call from multiple threads.
518519
*/
519-
def genConstant(const: Constant) {
520+
def genConstant(const: Constant): Unit = {
520521

521522
import dotc.core.Constants._
522523

@@ -565,15 +566,15 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
565566
}
566567
}
567568

568-
private def genLabelDef(lblDf: LabelDef, expectedType: BType) {
569+
private def genLabelDef(lblDf: LabelDef, expectedType: BType): Unit = {
569570
// duplication of LabelDefs contained in `finally`-clauses is handled when emitting RETURN. No bookkeeping for that required here.
570571
// no need to call index() over lblDf.params, on first access that magic happens (moreover, no LocalVariableTable entries needed for them).
571572
markProgramPoint(programPoint(lblDf.symbol))
572573
lineNumber(lblDf)
573574
genLoad(lblDf.rhs, expectedType)
574575
}
575576

576-
private def genReturn(r: Return) {
577+
private def genReturn(r: Return): Unit = {
577578
val Return(expr) = r
578579
val returnedKind = tpeTK(expr)
579580
genLoad(expr, returnedKind)
@@ -735,11 +736,11 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
735736
generatedType = genPrimitiveOp(app, expectedType)
736737
} else { // normal method call
737738

738-
def genNormalMethodCall() {
739+
def genNormalMethodCall(): Unit = {
739740

740741
val invokeStyle =
741742
if (sym.isStaticMember) icodes.opcodes.Static(onInstance = false)
742-
else if (sym.isPrivate || sym.isClassConstructor) icodes.opcodes.Static(onInstance = true)
743+
else if ((sym is Flags.Private) || sym.isClassConstructor) icodes.opcodes.Static(onInstance = true)
743744
else icodes.opcodes.Dynamic;
744745

745746
if (invokeStyle.hasInstance) {
@@ -756,12 +757,12 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
756757
val qualSym = findHostClass(qual.tpe, sym)
757758
if (qualSym == ArrayClass) {
758759
targetTypeKind = tpeTK(qual)
759-
log(s"Stored target type kind for ${sym.fullName} as $targetTypeKind")
760+
ctx.log(s"Stored target type kind for ${sym.fullName} as $targetTypeKind")
760761
}
761762
else {
762763
hostClass = qualSym
763764
if (qual.tpe.typeSymbol != qualSym) {
764-
log(s"Precisified host class for $sym from ${qual.tpe.typeSymbol.fullName} to ${qualSym.fullName}")
765+
ctx.log(s"Precisified host class for $sym from ${qual.tpe.typeSymbol.fullName} to ${qualSym.fullName}")
765766
}
766767
}
767768

@@ -870,7 +871,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
870871
generatedType
871872
}
872873

873-
def genBlock(tree: Block, expectedType: BType) {
874+
def genBlock(tree: Block, expectedType: BType): Unit = {
874875
val Block(stats, expr) = tree
875876
val savedScope = varsInScope
876877
varsInScope = Nil
@@ -902,7 +903,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
902903
}
903904

904905
/* Emit code to Load the qualifier of `tree` on top of the stack. */
905-
def genLoadQualifier(tree: Tree) {
906+
def genLoadQualifier(tree: Tree): Unit = {
906907
lineNumber(tree)
907908
tree match {
908909
case Select(qualifier, _) => genLoad(qualifier)
@@ -911,7 +912,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
911912
}
912913

913914
/* Generate code that loads args into label parameters. */
914-
def genLoadLabelArguments(args: List[Tree], lblDef: LabelDef, gotoPos: dotc.util.Positions.Position) {
915+
def genLoadLabelArguments(args: List[Tree], lblDef: LabelDef, gotoPos: dotc.util.Positions.Position): Unit = {
915916

916917
val aps = {
917918
val params: List[Symbol] = lblDef.params.map(_.symbol)
@@ -939,24 +940,24 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
939940

940941
}
941942

942-
def genLoadArguments(args: List[Tree], btpes: List[BType]) {
943+
def genLoadArguments(args: List[Tree], btpes: List[BType]): Unit = {
943944
(args zip btpes) foreach { case (arg, btpe) => genLoad(arg, btpe) }
944945
}
945946

946947
def genLoadModule(tree: Tree): BType = {
947948
val module = (
948-
if (!tree.symbol.isPackageClass) tree.symbol
949+
if (!tree.symbol is Flags.PackageClass) tree.symbol
949950
else tree.symbol.info.member(nme.PACKAGE) match {
950-
case NoSymbol => abort(s"SI-5604: Cannot use package as value: $tree")
951-
case s => abort(s"SI-5604: found package class where package object expected: $tree")
951+
case NoDenotation => abort(s"SI-5604: Cannot use package as value: $tree")
952+
case s => abort(s"SI-5604: found package class where package object expected: $tree")
952953
}
953954
)
954955
lineNumber(tree)
955956
genLoadModule(module)
956957
symInfoTK(module)
957958
}
958959

959-
def genLoadModule(module: Symbol) {
960+
def genLoadModule(module: Symbol): Unit = {
960961
def inStaticMethod = methSymbol != null && methSymbol.isStaticMember
961962
if (claszSymbol == module.moduleClass && jMethodName != "readResolve" && !inStaticMethod) {
962963
mnode.visitVarInsn(asm.Opcodes.ALOAD, 0)
@@ -971,15 +972,15 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
971972
}
972973
}
973974

974-
def genConversion(from: BType, to: BType, cast: Boolean) {
975+
def genConversion(from: BType, to: BType, cast: Boolean): Unit = {
975976
if (cast) { bc.emitT2T(from, to) }
976977
else {
977978
bc drop from
978979
bc boolconst (from == to)
979980
}
980981
}
981982

982-
def genCast(to: BType, cast: Boolean) {
983+
def genCast(to: BType, cast: Boolean): Unit = {
983984
if (cast) { bc checkCast to }
984985
else { bc isInstance to }
985986
}
@@ -988,7 +989,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
988989
def isPrimitive(fun: Symbol): Boolean = scalaPrimitives.isPrimitive(fun)
989990

990991
/* Generate coercion denoted by "code" */
991-
def genCoercion(code: Int) {
992+
def genCoercion(code: Int): Unit = {
992993
import scalaPrimitives._
993994
(code: @switch) match {
994995
case B2B | S2S | C2C | I2I | L2L | F2F | D2D => ()
@@ -1034,8 +1035,8 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
10341035
hostSymbol.info ; methodOwner.info
10351036

10361037
def needsInterfaceCall(sym: Symbol) = (
1037-
sym.isInterface
1038-
|| sym.isJavaDefined && sym.isNonBottomSubClass(definitions.ClassfileAnnotationClass)
1038+
(sym is Flags.Interface)
1039+
|| (sym is Flags.JavaDefined) && sym.isNonBottomSubClass(definitions.ClassfileAnnotationClass)
10391040
)
10401041

10411042
// whether to reference the type of the receiver or
@@ -1052,7 +1053,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
10521053
val bmType = asmMethodType(method)
10531054
val mdescr = bmType.getDescriptor
10541055

1055-
def initModule() {
1056+
def initModule(): Unit = {
10561057
// we initialize the MODULE$ field immediately after the super ctor
10571058
if (!isModuleInitialized &&
10581059
jMethodName == INSTANCE_CONSTRUCTOR_NAME &&
@@ -1121,7 +1122,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
11211122
def ifOneIsNull(l: Tree, r: Tree) = if (isNull(l)) r else if (isNull(r)) l else null
11221123

11231124
/* Emit code to compare the two top-most stack values using the 'op' operator. */
1124-
private def genCJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType) {
1125+
private def genCJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType): Unit = {
11251126
if (tk.isIntSizedType) { // BOOL, BYTE, CHAR, SHORT, or INT
11261127
bc.emitIF_ICMP(op, success)
11271128
} else if (tk.isRefOrArrayType) { // REFERENCE(_) | ARRAY(_)
@@ -1142,7 +1143,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
11421143
}
11431144

11441145
/* Emits code to compare (and consume) stack-top and zero using the 'op' operator */
1145-
private def genCZJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType) {
1146+
private def genCZJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType): Unit = {
11461147
if (tk.isIntSizedType) { // BOOL, BYTE, CHAR, SHORT, or INT
11471148
bc.emitIF(op, success)
11481149
} else if (tk.isRefOrArrayType) { // REFERENCE(_) | ARRAY(_)
@@ -1178,9 +1179,9 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
11781179
* Generate code for conditional expressions.
11791180
* The jump targets success/failure of the test are `then-target` and `else-target` resp.
11801181
*/
1181-
private def genCond(tree: Tree, success: asm.Label, failure: asm.Label) {
1182+
private def genCond(tree: Tree, success: asm.Label, failure: asm.Label): Unit = {
11821183

1183-
def genComparisonOp(l: Tree, r: Tree, code: Int) {
1184+
def genComparisonOp(l: Tree, r: Tree, code: Int): Unit = {
11841185
val op: TestOp = testOpForPrimitive(code - scalaPrimitives.ID)
11851186
// special-case reference (in)equality test for null (null eq x, x eq null)
11861187
var nonNullSide: Tree = null
@@ -1213,7 +1214,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
12131214
lazy val Select(lhs, _) = fun
12141215
val rhs = if (args.isEmpty) EmptyTree else args.head; // args.isEmpty only for ZNOT
12151216

1216-
def genZandOrZor(and: Boolean) { // TODO WRONG
1217+
def genZandOrZor(and: Boolean): Unit = { // TODO WRONG
12171218
// reaching "keepGoing" indicates the rhs should be evaluated too (ie not short-circuited).
12181219
val keepGoing = new asm.Label
12191220

@@ -1253,7 +1254,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
12531254
* @param l left-hand-side of the '=='
12541255
* @param r right-hand-side of the '=='
12551256
*/
1256-
def genEqEqPrimitive(l: Tree, r: Tree, success: asm.Label, failure: asm.Label) {
1257+
def genEqEqPrimitive(l: Tree, r: Tree, success: asm.Label, failure: asm.Label): Unit = {
12571258

12581259
/* True if the equality comparison is between values that require the use of the rich equality
12591260
* comparator (scala.runtime.Comparator.equals). This is the case when either side of the

src/dotty/tools/dotc/backend/jvm/BCodeGlue.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ abstract class BCodeGlue {
488488
*
489489
* can-multi-thread
490490
*/
491-
private def getDescriptor(buf: StringBuffer) {
491+
private def getDescriptor(buf: StringBuffer): Unit = {
492492
if (isPrimitiveOrVoid) {
493493
// descriptor is in byte 3 of 'off' for primitive types (buf == null)
494494
buf.append(((off & 0xFF000000) >>> 24).asInstanceOf[Char])

0 commit comments

Comments
 (0)