From 2d28f7fcc3e2cfcce127b8e0e5851df7bca66df0 Mon Sep 17 00:00:00 2001 From: mihaylov Date: Wed, 13 Jun 2007 12:13:01 +0000 Subject: Fixed J2ME support in the compiler --- .../scala/tools/nsc/backend/icode/GenICode.scala | 18 ++++++---- src/compiler/scala/tools/nsc/doc/ModelFrames.scala | 14 +++++++- .../scala/tools/nsc/symtab/Definitions.scala | 40 +++++++++------------- .../scala/tools/nsc/transform/CleanUp.scala | 12 ++++--- .../scala/tools/nsc/typechecker/RefChecks.scala | 2 +- 5 files changed, 50 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 1b92462834..2696465725 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -1390,16 +1390,22 @@ abstract class GenICode extends SubComponent { * When it is statically known that both sides are equal and subtypes of Number of Character, * not using the rich equality is possible (their own equals method will do ok.)*/ def mustUseAnyComparator: Boolean = { + def isBoxed(sym: Symbol): Boolean = + if (forCLDC) { + (sym isNonBottomSubClass definitions.ByteClass) || + (sym isNonBottomSubClass definitions.ShortClass) || + (sym isNonBottomSubClass definitions.CharClass) || + (sym isNonBottomSubClass definitions.IntClass) || + (sym isNonBottomSubClass definitions.LongClass) + } + else ((sym isNonBottomSubClass definitions.BoxedNumberClass) || + (!forMSIL && (sym isNonBottomSubClass BoxedCharacterClass))) + val lsym = l.tpe.symbol val rsym = r.tpe.symbol (lsym == definitions.ObjectClass) || (rsym == definitions.ObjectClass) || - (lsym != rsym) && ( - (lsym isNonBottomSubClass definitions.BoxedNumberClass) || - (!forMSIL && (lsym isNonBottomSubClass BoxedCharacterClass)) || - (rsym isNonBottomSubClass definitions.BoxedNumberClass) || - (!forMSIL && (rsym isNonBottomSubClass BoxedCharacterClass)) - ) + (lsym != rsym) && (isBoxed(lsym) || isBoxed(rsym)) } if (mustUseAnyComparator) { diff --git a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala index 370a877f66..c3f6f8b3a3 100644 --- a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala +++ b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala @@ -20,6 +20,18 @@ trait ModelFrames extends ModelExtractor { import DocUtil._ def settings: Settings + val SyntheticClasses = new scala.collection.mutable.HashSet[global.Symbol]; + { + import global.definitions._ + SyntheticClasses ++= List( + AllClass, AllRefClass, AnyClass, AnyRefClass, AnyValClass, + //value classes + BooleanClass, ByteClass, CharClass, IntClass, LongClass, ShortClass, UnitClass) + + if (!global.forCLDC) + SyntheticClasses ++= List(FloatClass, DoubleClass) + } + val outdir = settings.outdir.value val windowTitle = settings.windowtitle.value val docTitle = load(settings.doctitle.value) @@ -287,7 +299,7 @@ trait ModelFrames extends ModelExtractor {
{ - if (global.definitions.SyntheticClasses contains clazz.sym) + if (SyntheticClasses contains clazz.sym) Text("[Source: none]") else { val name = owner.fullNameString('/') + (if (owner.isPackage) "/" + clazz.name else "") diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 1aca0eb6a2..2c6d153b9f 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -38,7 +38,6 @@ trait Definitions { var SingletonClass: Symbol = _ var ClassClass: Symbol = _ - var MethodClass: Symbol = _ var StringClass: Symbol = _ var ThrowableClass: Symbol = _ var NullPointerExceptionClass: Symbol = _ @@ -50,7 +49,6 @@ trait Definitions { // Symbol -> (Symbol, Type): scalaCaller -> (scalaMethodSym, DelegateType) // var Delegate_scalaCallerInfos: HashMap[Symbol, (Symbol, Type)] = _ var Delegate_scalaCallerTargets: HashMap[Symbol, Symbol] = _ - var SyntheticClasses: HashSet[Symbol] = _ // the scala value classes var UnitClass: Symbol = _ @@ -660,19 +658,21 @@ trait Definitions { addModuleMethod(LongClass, "MinValue", java.lang.Long.MIN_VALUE) addModuleMethod(LongClass, "MaxValue", java.lang.Long.MAX_VALUE) - addModuleMethod(FloatClass, "MinValue", -java.lang.Float.MAX_VALUE) - addModuleMethod(FloatClass, "MaxValue", java.lang.Float.MAX_VALUE) - addModuleMethod(FloatClass, "Epsilon", java.lang.Float.MIN_VALUE) - addModuleMethod(FloatClass, "NaN", java.lang.Float.NaN) - addModuleMethod(FloatClass, "PositiveInfinity", java.lang.Float.POSITIVE_INFINITY) - addModuleMethod(FloatClass, "NegativeInfinity", java.lang.Float.NEGATIVE_INFINITY) - - addModuleMethod(DoubleClass, "MinValue", -java.lang.Double.MAX_VALUE) - addModuleMethod(DoubleClass, "MaxValue", java.lang.Double.MAX_VALUE) - addModuleMethod(DoubleClass, "Epsilon", java.lang.Double.MIN_VALUE) - addModuleMethod(DoubleClass, "NaN", java.lang.Double.NaN) - addModuleMethod(DoubleClass, "PositiveInfinity", java.lang.Double.POSITIVE_INFINITY) - addModuleMethod(DoubleClass, "NegativeInfinity", java.lang.Double.NEGATIVE_INFINITY) + if (!forCLDC) { + addModuleMethod(FloatClass, "MinValue", -java.lang.Float.MAX_VALUE) + addModuleMethod(FloatClass, "MaxValue", java.lang.Float.MAX_VALUE) + addModuleMethod(FloatClass, "Epsilon", java.lang.Float.MIN_VALUE) + addModuleMethod(FloatClass, "NaN", java.lang.Float.NaN) + addModuleMethod(FloatClass, "PositiveInfinity", java.lang.Float.POSITIVE_INFINITY) + addModuleMethod(FloatClass, "NegativeInfinity", java.lang.Float.NEGATIVE_INFINITY) + + addModuleMethod(DoubleClass, "MinValue", -java.lang.Double.MAX_VALUE) + addModuleMethod(DoubleClass, "MaxValue", java.lang.Double.MAX_VALUE) + addModuleMethod(DoubleClass, "Epsilon", java.lang.Double.MIN_VALUE) + addModuleMethod(DoubleClass, "NaN", java.lang.Double.NaN) + addModuleMethod(DoubleClass, "PositiveInfinity", java.lang.Double.POSITIVE_INFINITY) + addModuleMethod(DoubleClass, "NegativeInfinity", java.lang.Double.NEGATIVE_INFINITY) + } } /** Is symbol a value class? */ @@ -761,7 +761,6 @@ trait Definitions { StringClass = getClass(if (forMSIL) "System.String" else "java.lang.String") ClassClass = getClass(if (forMSIL) "System.Type" else "java.lang.Class") - MethodClass = if (forMSIL) null else getClass("java.lang.reflect.Method") ThrowableClass = getClass(if (forMSIL) "System.Exception" else "java.lang.Throwable") NullPointerExceptionClass = getClass(if (forMSIL) "System.NullReferenceException" else "java.lang.NullPointerException") @@ -878,7 +877,7 @@ trait Definitions { PatternWildcard = NoSymbol.newValue(NoPosition, "_").setInfo(AllClass.typeConstructor) - BoxedNumberClass = if (forMSIL) getClass("System.IConvertible") + BoxedNumberClass = if (forCLDC) null else if (forMSIL) getClass("System.IConvertible") else getClass("java.lang.Number") BoxedArrayClass = getClass("scala.runtime.BoxedArray") BoxedAnyArrayClass = getClass("scala.runtime.BoxedAnyArray") @@ -940,13 +939,6 @@ trait Definitions { BeanPropertyAttr = if (forCLDC || forMSIL) null else getClass("scala.reflect.BeanProperty") DeprecatedAttr = getClass("scala.deprecated") NativeAttr = getClass("scala.native") - - SyntheticClasses = new HashSet[Symbol] - SyntheticClasses ++= List( - AllClass, AllRefClass, AnyClass, AnyRefClass, AnyValClass, - //value classes - BooleanClass, ByteClass, CharClass, DoubleClass, FloatClass, - IntClass, LongClass, ShortClass, UnitClass) } var nbScalaCallers: Int = 0 diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index 844856355b..a2439c7525 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -24,6 +24,8 @@ abstract class CleanUp extends Transform { class CleanUpTransformer(unit: CompilationUnit) extends Transformer { + private val MethodClass = if (forCLDC || forMSIL) null + else definitions.getClass("java.lang.reflect.Method") private val newDefs = new ListBuffer[Tree] private val classConstantMeth = new HashMap[String, Symbol] @@ -32,15 +34,17 @@ abstract class CleanUp extends Transform { private val javaBoxClassModule = new HashMap[Symbol, Symbol] if (!forMSIL) { - javaBoxClassModule(UnitClass) = getModule("java.lang.Void") javaBoxClassModule(BooleanClass) = getModule("java.lang.Boolean") javaBoxClassModule(ByteClass) = getModule("java.lang.Byte") javaBoxClassModule(ShortClass) = getModule("java.lang.Short") javaBoxClassModule(IntClass) = getModule("java.lang.Integer") javaBoxClassModule(CharClass) = getModule("java.lang.Character") javaBoxClassModule(LongClass) = getModule("java.lang.Long") - javaBoxClassModule(FloatClass) = getModule("java.lang.Float") - javaBoxClassModule(DoubleClass) = getModule("java.lang.Double") + if (!forCLDC) { + javaBoxClassModule(FloatClass) = getModule("java.lang.Float") + javaBoxClassModule(DoubleClass) = getModule("java.lang.Double") + javaBoxClassModule(UnitClass) = getModule("java.lang.Void") + } } private var localTyper: analyzer.Typer = null; @@ -305,7 +309,7 @@ abstract class CleanUp extends Transform { val tpe = c.typeValue atPos(tree.pos) { localTyper.typed { - if (isValueClass(tpe.symbol)) + if (isValueClass(tpe.symbol) && !forCLDC) Select(gen.mkAttributedRef(javaBoxClassModule(tpe.symbol)), "TYPE") else if (settings.target.value != "jvm-1.5") Apply( diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index f178590a42..d12992ad3d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -528,7 +528,7 @@ abstract class RefChecks extends InfoTransform { nonSensible("", false) else if (isNumericValueClass(receiver) && !isNumericValueClass(actual) && - !(forMSIL || (actual isSubClass BoxedNumberClass)) && + !(forMSIL || forCLDC|| (actual isSubClass BoxedNumberClass)) && !(receiver isSubClass actual)) nonSensible("", false) else if ((receiver hasFlag FINAL) && hasObjectEquals && !isValueClass(receiver) && -- cgit v1.2.3