From 7acc55b2dc16a8981ac6572eb65b689e1d2622a1 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 29 Apr 2009 16:15:10 +0000 Subject: Removed various now-unnecessary java 1.4 workar... Removed various now-unnecessary java 1.4 workarounds and conditional behavior. --- src/compiler/scala/tools/ant/Scalac.scala | 2 +- src/compiler/scala/tools/nsc/Interpreter.scala | 7 ++---- src/compiler/scala/tools/nsc/ScriptRunner.scala | 7 ------ src/compiler/scala/tools/nsc/Settings.scala | 2 +- .../scala/tools/nsc/backend/jvm/GenJVM.scala | 18 ++++---------- .../scala/tools/nsc/javac/JavaParsers.scala | 2 +- .../nsc/symtab/classfile/ClassfileParser.scala | 28 ++++++++++------------ .../tools/nsc/symtab/classfile/UnPickler.scala | 4 ---- .../scala/tools/nsc/transform/CleanUp.scala | 6 +---- .../scala/tools/nsc/typechecker/Typers.scala | 11 +-------- .../scala/tools/nsc/util/NameTransformer.scala | 27 ++++++++++----------- 11 files changed, 36 insertions(+), 78 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala index 60360e222d..ecbe9aefb7 100644 --- a/src/compiler/scala/tools/ant/Scalac.scala +++ b/src/compiler/scala/tools/ant/Scalac.scala @@ -99,7 +99,7 @@ class Scalac extends MatchingTask { /** Defines valid values for the target property. */ object Target extends PermissibleValue { - val values = List("jvm-1.5", "jvm-1.4", "msil", "cldc") + val values = List("jvm-1.5", "msil", "cldc") } /** Defines valid values for the deprecation and diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 03c4920d4a..eefcc05b35 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -64,11 +64,8 @@ import Interpreter._ * @author Moez A. Abdel-Gawad * @author Lex Spoon */ -class Interpreter(val settings: Settings, out: PrintWriter) { - /* If running on pre-1.5 JVM, force target setting to 1.4 */ - private val major = System.getProperty("java.class.version").split("\\.")(0) - if (major.toInt < 49) this.settings.target.value = "jvm-1.4" - +class Interpreter(val settings: Settings, out: PrintWriter) +{ /** directory to save .class files to */ val virtualDirectory = new VirtualDirectory("(memory)", None) diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala index aa440adbf3..e31dcd38f9 100644 --- a/src/compiler/scala/tools/nsc/ScriptRunner.scala +++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala @@ -275,13 +275,6 @@ object ScriptRunner { : Boolean = { import Interpreter.deleteRecursively - /* If the script is running on pre-jvm-1.5 JVM, - it is necessary to force the target setting to jvm-1.4 */ - val major = System.getProperty("java.class.version").split("\\.")(0) - if (major.toInt < 49) { - settings.target.value = "jvm-1.4" - } - /** Compiles the script file, and returns * the directory with the compiled class files, * if the compilation succeeded. diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index a05a6dd157..31261b87e6 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -602,7 +602,7 @@ trait ScalacSettings val XO = BooleanSetting ("-optimise", "Generates faster bytecode by applying optimisations to the program") val printLate = BooleanSetting ("-print", "Print program with all Scala-specific features removed") val sourcepath = StringSetting ("-sourcepath", "path", "Specify where to find input source files", "") - val target = ChoiceSetting ("-target", "Specify for which target object files should be built", List("jvm-1.5", "jvm-1.4", "msil"), "jvm-1.5") + val target = ChoiceSetting ("-target", "Specify for which target object files should be built", List("jvm-1.5", "msil"), "jvm-1.5") val unchecked = BooleanSetting ("-unchecked", "Enable detailed unchecked warnings") val uniqid = BooleanSetting ("-uniqid", "Print identifiers with unique names for debugging") val verbose = BooleanSetting ("-verbose", "Output messages about what the compiler is doing") diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index b412340372..283b381d5f 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -103,9 +103,7 @@ abstract class GenJVM extends SubComponent { var innerClasses: Set[Symbol] = ListSet.empty // referenced inner classes - val fjbgContext = - if (settings.target.value == "jvm-1.5") new FJBGContext(49, 0) - else new FJBGContext() + val fjbgContext = new FJBGContext(49, 0) val emitSource = settings.debuginfo.level >= 1 val emitLines = settings.debuginfo.level >= 2 @@ -419,9 +417,8 @@ abstract class GenJVM extends SubComponent { } def addGenericSignature(jmember: JMember, sym: Symbol, owner: Symbol) { - if (settings.target.value == "jvm-1.5" - && !sym.hasFlag(Flags.EXPANDEDNAME | Flags.SYNTHETIC) - && !(sym.isMethod && sym.hasFlag(Flags.LIFTED))) { + if (!sym.hasFlag(Flags.EXPANDEDNAME | Flags.SYNTHETIC) + && !(sym.isMethod && sym.hasFlag(Flags.LIFTED))) { val memberTpe = atPhase(currentRun.erasurePhase)(owner.thisType.memberInfo(sym)) // println("sym: " + sym.fullNameString + " : " + memberTpe + " sym.info: " + sym.info) erasure.javaSig(sym, memberTpe) match { @@ -572,11 +569,6 @@ abstract class GenJVM extends SubComponent { javaTypes(m.params map (_.kind)), javaNames(m.params map (_.sym))); - if (m.symbol.hasFlag(Flags.BRIDGE) && settings.target.value == "jvm-1.4") { - jmethod.addAttribute(fjbgContext.JOtherAttribute(jclass, jmethod, "Bridge", - new Array[Byte](0))) - } - addRemoteException(jmethod, m.symbol) if (!jmethod.isAbstract() && !method.native) { @@ -1697,9 +1689,7 @@ abstract class GenJVM extends SubComponent { && !sym.enclClass.hasFlag(Flags.INTERFACE) && !sym.isClassConstructor) ACC_FINAL else 0) jf = jf | (if (sym.isStaticMember) ACC_STATIC else 0) - - if (settings.target.value == "jvm-1.5") - jf = jf | (if (sym hasFlag Flags.BRIDGE) ACC_BRIDGE | ACC_SYNTHETIC else 0) + jf = jf | (if (sym hasFlag Flags.BRIDGE) ACC_BRIDGE | ACC_SYNTHETIC else 0) if (sym.isClass && !sym.hasFlag(Flags.INTERFACE)) jf = jf | ACC_SUPER diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 688aff8fd9..f337dac0ac 100755 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -424,7 +424,7 @@ trait JavaParsers extends JavaScanners { // privateWithin == nme.EMPTY.toTypeName || // privateWithin == nme.EMPTY_PACKAGE_NAME_tn // XXX I think this test should just be "if (defaultAccess)" - // but then many cases like pos5/t1176 fail because scala code + // but then many cases like pos/t1176 fail because scala code // with no package cannot access java code with no package. // if (defaultAccess && !isEmptyPkg) // flags |= Flags.PROTECTED // package private diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index a4dcdc8fee..033d3ba89d 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -696,7 +696,7 @@ abstract class ClassfileParser { val attrLen = in.nextInt attrName match { case nme.SignatureATTR => - if (!isScala && !isScalaRaw && global.settings.target.value == "jvm-1.5") { + if (!isScala && !isScalaRaw) { val sig = pool.getExternalName(in.nextChar) val newType = sigToType(sym, sig) sym.setInfo(newType) @@ -855,20 +855,16 @@ abstract class ClassfileParser { getScope(jflags).enter(innerClass) getScope(jflags).enter(innerModule) - // the 1.4 library misses entries in the InnerClasses attributes (see HashMap$Entry in LinkedHashMap) - // TODO: remove this test when we drop support for 1.4 - if (settings.target.value != "jvm-1.4") { - val decls = innerClass.enclosingPackage.info.decls - val e = decls.lookupEntry(className(entry.externalName)) - if (e ne null) { - //println("removing " + e) - decls.unlink(e) - } - val e1 = decls.lookupEntry(className(entry.externalName).toTypeName) - if (e1 ne null) { - //println("removing " + e1) - decls.unlink(e1) - } + val decls = innerClass.enclosingPackage.info.decls + val e = decls.lookupEntry(className(entry.externalName)) + if (e ne null) { + //println("removing " + e) + decls.unlink(e) + } + val e1 = decls.lookupEntry(className(entry.externalName).toTypeName) + if (e1 ne null) { + //println("removing " + e1) + decls.unlink(e1) } } @@ -897,7 +893,7 @@ abstract class ClassfileParser { val attrLen = in.nextInt attrName match { case nme.SignatureATTR => - if (!isScala && global.settings.target.value == "jvm-1.5") + if (!isScala) hasMeta = true in.skip(attrLen) case nme.JacoMetaATTR => diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala index a3e2a2061d..2c0a10ecc8 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala @@ -253,10 +253,6 @@ abstract class UnPickler { val pre = readTypeRef() val sym = readSymbolRef() var args = until(end, readTypeRef) - if ((sym hasFlag JAVA) && sym.typeParams.isEmpty && global.settings.target.value != "jvm-1.5") { - // forget arguments, we are compiling for 1.4; see #1144 - args = List() - } rawTypeRef(pre, sym, args) case TYPEBOUNDStpe => mkTypeBounds(readTypeRef(), readTypeRef()) diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index bdf5bede41..f0eea1742b 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -723,10 +723,6 @@ abstract class CleanUp extends Transform { if ((isValueClass(tpe.typeSymbol) || tpe.typeSymbol == definitions.UnitClass) && !forCLDC) Select(gen.mkAttributedRef(javaBoxClassModule(tpe.typeSymbol)), "TYPE") - else if (settings.target.value != "jvm-1.5" && !forMSIL) - Apply( - gen.mkAttributedRef(classConstantMethod(tree.pos, signature(tpe))), - List()) else tree } } @@ -755,7 +751,7 @@ abstract class CleanUp extends Transform { /* Adds @serializable annotation to anonymous function classes */ case cdef @ ClassDef(mods, name, tparams, impl) => - if (settings.target.value == "jvm-1.4" || settings.target.value == "jvm-1.5") { + if (settings.target.value == "jvm-1.5") { val sym = cdef.symbol // is this an anonymous function class? if (sym.isAnonymousFunction && !sym.hasAttribute(SerializableAttr)) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 35442e10e7..41b6c61d74 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -69,11 +69,6 @@ trait Typers { self: Analyzer => private class NormalTyper(context : Context) extends Typer(context) // hooks for auto completion - /** when in 1.4 mode the compiler accepts and ignores useless - * type parameters of Java generics - */ - def onePointFourMode = true // todo changeto: settings.target.value == "jvm-1.4" - // Mode constants /** The three mode NOmode, EXPRmode @@ -2154,9 +2149,6 @@ trait Typers { self: Analyzer => error(annot.constr.pos, "attribute " + annType.typeSymbol.fullNameString + " is missing element " + name.name) } } - if (annType.typeSymbol.hasFlag(JAVA) && settings.target.value == "jvm-1.4") { - context.warning (annot.constr.pos, "Java annotation will not be emitted in classfile unless you use the '-target:jvm-1.5' option") - } if (attrError) annotationError else AnnotationInfo(annType, constrArgs, nvPairs) } @@ -3181,8 +3173,7 @@ trait Typers { self: Analyzer => }} TypeTree(owntype) setOriginal(tree) // setPos tree.pos } else if (tparams.length == 0) { - if (onePointFourMode && (tpt1.symbol hasFlag JAVA)) tpt1 - else errorTree(tree, tpt1.tpe+" does not take type parameters") + errorTree(tree, tpt1.tpe+" does not take type parameters") } else { //Console.println("\{tpt1}:\{tpt1.symbol}:\{tpt1.symbol.info}") if (settings.debug.value) Console.println(tpt1+":"+tpt1.symbol+":"+tpt1.symbol.info);//debug diff --git a/src/compiler/scala/tools/nsc/util/NameTransformer.scala b/src/compiler/scala/tools/nsc/util/NameTransformer.scala index 8a97afdbe2..0292e1c68a 100644 --- a/src/compiler/scala/tools/nsc/util/NameTransformer.scala +++ b/src/compiler/scala/tools/nsc/util/NameTransformer.scala @@ -59,16 +59,15 @@ object NameTransformer { } buf.append(op2code(c)) /* Handle glyphs that are not valid Java/JVM identifiers */ - } else if (!Character.isJavaIdentifierPart(c)) { - if (buf eq null) { - buf = new StringBuilder() - buf.append(name.substring(0, i)) - } - /* Annoying hack to format a hexadeciaml number with leading - zeros -- there does not appear to be any function pre-Java - 1.5 to do this. */ - buf.append("$u" + Integer.toHexString(c + 0x10000).substring(1).toUpperCase) - } else if (buf ne null) { + } + else if (!Character.isJavaIdentifierPart(c)) { + if (buf eq null) { + buf = new StringBuilder() + buf.append(name.substring(0, i)) + } + buf.append("$u%04X".format(c.toInt)) + } + else if (buf ne null) { buf.append(c) } i += 1 @@ -110,9 +109,9 @@ object NameTransformer { /* Handle the decoding of Unicode glyphs that are * not valid Java/JVM identifiers */ } else if ((len - i) >= 6 && // Check that there are enough characters left - ch1 == 'u' && + ch1 == 'u' && ((Character.isDigit(ch2)) || - ('A' <= ch2 && ch2 <= 'F'))) { + ('A' <= ch2 && ch2 <= 'F'))) { /* Skip past "$u", next four should be hexadecimal */ val hex = name.substring(i+2, i+6) try { @@ -137,9 +136,9 @@ object NameTransformer { buffer is non-empty, write the current character and advance one */ if ((ops eq null) && !unicode) { - if (buf ne null) + if (buf ne null) buf.append(c) - i += 1 + i += 1 } } //System.out.println("= " + (if (buf == null) name else buf.toString()));//DEBUG -- cgit v1.2.3