diff options
author | Martin Odersky <odersky@gmail.com> | 2006-01-03 13:34:58 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2006-01-03 13:34:58 +0000 |
commit | ec25a32375121896a054a3428c3a7f5b1c867cee (patch) | |
tree | 729afdb00deee056567b5512233c3e3ac5b0e31f /src/compiler | |
parent | 4f8cb21ef3123f74b9344f4dde07ed9abe800a42 (diff) | |
download | scala-ec25a32375121896a054a3428c3a7f5b1c867cee.tar.gz scala-ec25a32375121896a054a3428c3a7f5b1c867cee.tar.bz2 scala-ec25a32375121896a054a3428c3a7f5b1c867cee.zip |
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Settings.scala | 213 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/StdNames.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 13 |
4 files changed, 124 insertions, 107 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 8c2429985b..66b264a4ce 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -421,7 +421,8 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable val unit = new CompilationUnit(getSourceFile(file)); addUnit(unit); var localPhase = firstPhase.asInstanceOf[GlobalPhase]; - while (localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id) { + while ((localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id) && + reporter.errors == 0) { atPhase(localPhase)(localPhase.applyPhase(unit)); localPhase = localPhase.next.asInstanceOf[GlobalPhase]; } diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index 9b76db2b9b..9cb74fd726 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -2,94 +2,95 @@ * Copyright 2005 LAMP/EPFL * @author Martin Odersky */ -// $Id$ -package scala.tools.nsc; +// $Id: Settings.scala +package scala.tools.nsc -import java.io.File; +import java.io.File +import System.getProperty class Settings(error: String => unit) { - private var allsettings: List[Setting] = List(); - - private val classpathDefault = { - val scalaCp = System.getProperty("scala.class.path"); - if (scalaCp != null) scalaCp + File.pathSeparator + "." - else "." - } - private val bootclasspathDefault = { - val javaBcp = System.getProperty("sun.boot.class.path"); - val scalaBcp = { - val explicit = System.getProperty("scala.boot.class.path"); - if(explicit != null) - explicit - else { - val scalaHome = System.getProperty("scala.home"); - if(scalaHome != null) { - val guess = new File(new File(new File(scalaHome), "lib"), "scala-library.jar"); - if(guess.exists()) - guess.getPath() - else - null - } - else - null - } - } - - if (javaBcp != null && scalaBcp != null) javaBcp + File.pathSeparator + scalaBcp - else if (javaBcp != null) javaBcp - else if (scalaBcp != null) scalaBcp - else "" - } - private val extdirsDefault = { - val javaExt = System.getProperty("java.ext.dirs"); - val scalaExt = System.getProperty("scala.ext.dirs"); - if (javaExt != null && scalaExt != null) javaExt + File.pathSeparator + scalaExt - else if (javaExt != null) javaExt - else if (scalaExt != null) scalaExt - else "" + private var allsettings: List[Setting] = List() + + private val classpathDefault = + alternatePath( + concatPath( + getProperty("java.class.path"), + getProperty("scala.class.path")), + ".") + + private val bootclasspathDefault = + alternatePath( + concatPath( + getProperty("sun.boot.class.path"), + alternatePath( + getProperty("scala.boot.class.path"), + guessedScalaBootClassPath)), + "") + + private val extdirsDefault = + alternatePath( + concatPath( + getProperty("java.ext.dirs"), + getProperty("scala.ext.dirs")), + "") + + private def alternatePath(p1: String, p2: => String) = + if (p1 != null) p1 else p2 + + private def concatPath(p1: String, p2: String) = + if (p1 != null && p2 != null) p1 + File.pathSeparator + p2 + else if (p1 != null) p1 + else p2 + + private def guessedScalaBootClassPath = { + val scalaHome = System.getProperty("scala.home") + if (scalaHome != null) { + val guess = new File(new File(new File(scalaHome), "lib"), "scala-library.jar") + if (guess.exists()) guess.getPath() else null + } else null } - val debuginfo = BooleanSetting("-g", "Generate debugging info"); - val nowarnings = BooleanSetting("-nowarn", "Generate no warnings"); - val noassertions = BooleanSetting("-noassert", "Generate no assertions and assumptions"); - val verbose = BooleanSetting("-verbose", "Output messages about what the compiler is doing"); - val classpath = StringSetting ("-classpath", "path", "Specify where to find user class files", classpathDefault); - val sourcepath = StringSetting ("-sourcepath", "path", "Specify where to find input source files", ""); - val bootclasspath = StringSetting ("-bootclasspath", "path", "Override location of bootstrap class files", bootclasspathDefault); - val extdirs = StringSetting ("-extdirs", "dirs", "Override location of installed extensions", extdirsDefault); - val outdir = StringSetting ("-d", "directory", "Specify where to place generated class files", ""); - val encoding = StringSetting ("-encoding", "encoding", "Specify character encoding used by source files", "ISO-8859-1"); - val separate = ChoiceSetting ("-separate", "Read symbol files for separate compilation", List("yes","no"), "default"); - val target = ChoiceSetting ("-target", "Specify which backend to use", List("jvm", "msil"), "jvm"); - val debug = BooleanSetting("-debug", "Output debugging messages"); - val statistics = BooleanSetting("-statistics", "Print compiler statistics"); - val explaintypes = BooleanSetting("-explaintypes", "Explain type errors in more detail"); - val resident = BooleanSetting("-resident", "Compiler stays resident, files to compile are read from standard input"); - val uniqid = BooleanSetting("-uniqid", "Print identifiers with unique names (debugging option)"); - val printtypes = BooleanSetting("-printtypes", "Print tree types (debugging option)"); - val prompt = BooleanSetting("-prompt", "Display a prompt after each error (debugging option)"); - val noimports = BooleanSetting("-noimports", "Compile without any implicit imports"); - val nopredefs = BooleanSetting("-nopredefs", "Compile without any implicit predefined values"); - val skip = PhasesSetting ("-skip", "Skip"); - val check = PhasesSetting ("-check", "Check the tree at start of"); - val print = PhasesSetting ("-print", "Print out program after"); - val printer = ChoiceSetting ("-printer", "Printer to use", List("text", "html"), "text"); - val printfile = StringSetting ("-printfile", "file", "Specify file in which to print trees", "-"); - val graph = PhasesSetting ("-graph", "Graph the program after"); - val browse = PhasesSetting ("-browse", "Browse the abstract syntax tree after"); - val stop = PhasesSetting ("-stop", "Stop after phase"); - val log = PhasesSetting ("-log", "Log operations in"); - val version = BooleanSetting("-version", "Print product version and exit"); - val help = BooleanSetting("-help", "Print a synopsis of standard options"); - - val Xshowcls = StringSetting ("-Xshowcls", "class", "Show class info", ""); - val Xshowobj = StringSetting ("-Xshowobj", "object", "Show object info", ""); - val Xshowicode = BooleanSetting("-Xshowicode", "Print the generated ICode"); - val Xgadt = BooleanSetting("-Xgadt", "enable gadt for classes"); + val debuginfo = BooleanSetting("-g", "Generate debugging info") + val nowarnings = BooleanSetting("-nowarn", "Generate no warnings") + val noassertions = BooleanSetting("-noassert", "Generate no assertions and assumptions") + val verbose = BooleanSetting("-verbose", "Output messages about what the compiler is doing") + val classpath = StringSetting ("-classpath", "path", "Specify where to find user class files", classpathDefault) + val sourcepath = StringSetting ("-sourcepath", "path", "Specify where to find input source files", "") + val bootclasspath = StringSetting ("-bootclasspath", "path", "Override location of bootstrap class files", bootclasspathDefault) + val extdirs = StringSetting ("-extdirs", "dirs", "Override location of installed extensions", extdirsDefault) + val outdir = StringSetting ("-d", "directory", "Specify where to place generated class files", "") + val encoding = StringSetting ("-encoding", "encoding", "Specify character encoding used by source files", "ISO-8859-1") + val separate = ChoiceSetting ("-separate", "Read symbol files for separate compilation", List("yes","no"), "default") + val target = ChoiceSetting ("-target", "Specify which backend to use", List("jvm", "msil"), "jvm") + val debug = BooleanSetting("-debug", "Output debugging messages") + val statistics = BooleanSetting("-statistics", "Print compiler statistics") + val explaintypes = BooleanSetting("-explaintypes", "Explain type errors in more detail") + val resident = BooleanSetting("-resident", "Compiler stays resident, files to compile are read from standard input") + val uniqid = BooleanSetting("-uniqid", "Print identifiers with unique names (debugging option)") + val printtypes = BooleanSetting("-printtypes", "Print tree types (debugging option)") + val prompt = BooleanSetting("-prompt", "Display a prompt after each error (debugging option)") + val noimports = BooleanSetting("-noimports", "Compile without any implicit imports") + val nopredefs = BooleanSetting("-nopredefs", "Compile without any implicit predefined values") + val skip = PhasesSetting ("-skip", "Skip") + val check = PhasesSetting ("-check", "Check the tree at start of") + val print = PhasesSetting ("-print", "Print out program after") + val printer = ChoiceSetting ("-printer", "Printer to use", List("text", "html"), "text") + val printfile = StringSetting ("-printfile", "file", "Specify file in which to print trees", "-") + val graph = PhasesSetting ("-graph", "Graph the program after") + val browse = PhasesSetting ("-browse", "Browse the abstract syntax tree after") + val stop = PhasesSetting ("-stop", "Stop after phase") + val log = PhasesSetting ("-log", "Log operations in") + val version = BooleanSetting("-version", "Print product version and exit") + val help = BooleanSetting("-help", "Print a synopsis of standard options") + + val Xshowcls = StringSetting ("-Xshowcls", "class", "Show class info", "") + val Xshowobj = StringSetting ("-Xshowobj", "object", "Show object info", "") + val Xshowicode = BooleanSetting("-Xshowicode", "Print the generated ICode") + val Xgadt = BooleanSetting("-Xgadt", "enable gadt for classes") /** A list of all settings */ - def allSettings: List[Setting] = allsettings.reverse; + def allSettings: List[Setting] = allsettings.reverse /** A base class for settings of all types. * Subclasses each define a `value' field of the appropriate type. @@ -102,22 +103,22 @@ class Settings(error: String => unit) { * issue error message and return empty. * If first arg does not define this setting return args unchanged. */ - def tryToSet(args: List[String]): List[String]; + def tryToSet(args: List[String]): List[String] /** The syntax defining this setting in a help string */ - def helpSyntax: String = name; + def helpSyntax: String = name /** A description of the purpose of this setting in a help string */ - def helpDescription = descr; + def helpDescription = descr // initialization - allsettings = this :: allsettings; + allsettings = this :: allsettings } /** A setting represented by a boolean flag (false, unless set) */ case class BooleanSetting(name: String, descr: String) extends Setting(name, descr) { - var value: boolean = false; + var value: boolean = false def tryToSet(args: List[String]): List[String] = args match { case n :: rest if (n == name) => value = true; rest @@ -128,21 +129,21 @@ class Settings(error: String => unit) { /** A setting represented by a string, (`default' unless set) */ case class StringSetting(name: String, arg: String, descr: String, default: String) extends Setting(name, descr) { - var value: String = default; + var value: String = default def tryToSet(args: List[String]): List[String] = args match { case n :: rest if (n == name) => if (rest.isEmpty) { - error("missing argument"); + error("missing argument") List() } else { - value = rest.head; + value = rest.head rest.tail } case _ => args } - override def helpSyntax = name + " <" + arg + ">"; + override def helpSyntax = name + " <" + arg + ">" } /** A setting represented by a string in a given set of `choices', @@ -150,26 +151,26 @@ class Settings(error: String => unit) { */ case class ChoiceSetting(name: String, descr: String, choices: List[String], default: String) extends Setting(name, descr + choices.mkString(" (", ",", ")")) { - var value: String = default; + var value: String = default - private def argument: String = name.substring(1); + private def argument: String = name.substring(1) def tryToSet(args: List[String]): List[String] = args match { case n :: rest if (n startsWith (name + ":")) => - val choice = n.substring(name.length() + 1); + val choice = n.substring(name.length() + 1) if (!(choices contains choice)) { error( if (choice == "") "missing " + argument - else "unknown " + argument + " '" + choice + "'"); - List() - } else { - value = choice; + else "unknown " + argument + " '" + choice + "'") + List() + } else { + value = choice rest - } + } case _ => args } - override def helpSyntax = name + ":<" + argument + ">"; + override def helpSyntax = name + ":<" + argument + ">" } /** A setting represented by a list of strings which should be prefixes of @@ -178,22 +179,22 @@ class Settings(error: String => unit) { */ case class PhasesSetting(name: String, descr: String) extends Setting(name, descr + " <phases> (see below)") { - var value: List[String] = List(); + var value: List[String] = List() def tryToSet(args: List[String]): List[String] = args match { case n :: rest if (n startsWith (name + ":")) => - val phase = n.substring(name.length() + 1); + val phase = n.substring(name.length() + 1) if (phase == "") { - error("missing phase"); - List() - } else { - value = value ::: List(phase); + error("missing phase") + List() + } else { + value = value ::: List(phase) rest - } + } case _ => args } - override def helpSyntax = name + ":<phase>"; + override def helpSyntax = name + ":<phase>" def contains(phasename: String): boolean = value exists (str => phasename startsWith str) diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala index 2b8b8692f5..d0bf3da3ac 100644 --- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala +++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala @@ -202,6 +202,7 @@ import scala.tools.nsc.util.NameTransformer; val String = newTermName("String"); val Symbol = newTermName("Symbol"); val Synthetic = newTermName("Synthetic"); + val System = newTermName("System"); val Text = newTermName("Text"); val Throwable = newTermName("Throwable"); @@ -213,6 +214,7 @@ import scala.tools.nsc.util.NameTransformer; val While = newTermName("While"); val apply = newTermName("apply"); val array = newTermName("array"); + val arraycopy = newTermName("arraycopy"); val assert_ = newTermName("assert"); val assume_ = newTermName("assume"); val asInstanceOf = newTermName("asInstanceOf"); diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index ce2e17e149..8971d5787b 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -531,6 +531,19 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { case TypeApply(fun, args) if (fun.symbol.owner != AnyClass) => // leave all other type tests/type casts, remove all other type applications fun + case Apply(fn, args) => + def isGenericArray(tpe: Type): boolean = erasure(tpe).symbol == BoxedArrayClass + if (fn.hasSymbol && + fn.symbol.name == nme.arraycopy && + fn.symbol.owner.name == nme.System.toTypeName && + fn.symbol.owner.owner == JavaLangPackage.tpe.symbol && + args.length == 5 && + (isGenericArray(args(0).tpe) || isGenericArray(args(2).tpe))) + unit.warning(tree.pos, + "System.arraycopy should be applied only to arrays with fixed element types;\n" + + "use Array.copy instead") + tree + case Template(parents, body) => assert(!currentOwner.isImplClass); //System.out.println("checking no dble defs " + tree);//DEBUG |