summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-03-08 06:06:36 +0000
committerPaul Phillips <paulp@improving.org>2010-03-08 06:06:36 +0000
commit217415af22e2909a44405cf75ab34933023d1612 (patch)
treeb8f7454a19695cd9651a5409ab138946649a2803
parentfee21b7e701bbb4a3f311cf06ecd668cb5d0bc94 (diff)
downloadscala-217415af22e2909a44405cf75ab34933023d1612.tar.gz
scala-217415af22e2909a44405cf75ab34933023d1612.tar.bz2
scala-217415af22e2909a44405cf75ab34933023d1612.zip
More progress toward immutable Settings, and va...
More progress toward immutable Settings, and various cleanups encountered along the way. No review.
-rw-r--r--src/compiler/scala/tools/nsc/doc/Settings.scala1
-rw-r--r--src/compiler/scala/tools/nsc/settings/AbsScalaSettings.scala (renamed from src/compiler/scala/tools/nsc/settings/AbsScalacSettings.scala)25
-rw-r--r--src/compiler/scala/tools/nsc/settings/AbsSettings.scala10
-rw-r--r--src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala76
-rw-r--r--src/compiler/scala/tools/nsc/settings/MutableSettings.scala12
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala (renamed from src/compiler/scala/tools/nsc/settings/ScalacSettings.scala)63
-rw-r--r--src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala71
-rw-r--r--src/intellij/scala-lang.ipr2
-rw-r--r--src/partest/scala/tools/partest/nest/TestFile.scala4
9 files changed, 159 insertions, 105 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/Settings.scala b/src/compiler/scala/tools/nsc/doc/Settings.scala
index 0ea17970f6..3d02689605 100644
--- a/src/compiler/scala/tools/nsc/doc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/doc/Settings.scala
@@ -32,5 +32,4 @@ class Settings(error: String => Unit) extends scala.tools.nsc.Settings(error) {
// working around issue described in r18708.
suppressVTWarn.value = true
-
}
diff --git a/src/compiler/scala/tools/nsc/settings/AbsScalacSettings.scala b/src/compiler/scala/tools/nsc/settings/AbsScalaSettings.scala
index bb0c6f8ee7..790f4cce00 100644
--- a/src/compiler/scala/tools/nsc/settings/AbsScalacSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/AbsScalaSettings.scala
@@ -6,17 +6,17 @@
package scala.tools.nsc
package settings
-trait AbsScalacSettings {
+trait AbsScalaSettings {
self: AbsSettings =>
- type BooleanSetting <: AbsSetting
- type ChoiceSetting <: AbsSetting
- type DefinesSetting <: AbsSetting
- type IntSetting <: AbsSetting
- type MultiStringSetting <: AbsSetting
- type PathSetting <: AbsSetting
- type PhasesSetting <: AbsSetting
- type StringSetting <: AbsSetting
+ type BooleanSetting <: AbsSetting { type T = Boolean }
+ type ChoiceSetting <: AbsSetting { type T = String }
+ type DefinesSetting <: AbsSetting { type T = List[(String, String)] }
+ type IntSetting <: AbsSetting { type T = Int }
+ type MultiStringSetting <: AbsSetting { type T = List[String] }
+ type PathSetting <: AbsSetting { type T = String }
+ type PhasesSetting <: AbsSetting { type T = List[String] }
+ type StringSetting <: AbsSetting { type T = String }
type OutputDirs
type OutputSetting <: AbsSetting
@@ -30,4 +30,11 @@ trait AbsScalacSettings {
def PathSetting(name: String, arg: String, descr: String, default: String): PathSetting
def PhasesSetting(name: String, descr: String): PhasesSetting
def StringSetting(name: String, arg: String, descr: String, default: String): StringSetting
+
+ /** **/
+ abstract class SettingGroup(val prefix: String) extends AbsSetting {
+ def name = prefix
+ def helpDescription: String = error("todo")
+ def unparse: List[String] = List(name)
+ }
}
diff --git a/src/compiler/scala/tools/nsc/settings/AbsSettings.scala b/src/compiler/scala/tools/nsc/settings/AbsSettings.scala
index 8b51c00a48..91b26d083a 100644
--- a/src/compiler/scala/tools/nsc/settings/AbsSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/AbsSettings.scala
@@ -17,7 +17,7 @@ trait AbsSettings {
type Setting <: AbsSetting // Fix to the concrete Setting type
type ResultOfTryToSet // List[String] in mutable, (Settings, List[String]) in immutable
def errorFn: String => Unit
- protected def allSettings: Set[Setting]
+ protected def allSettings: collection.Set[Setting]
// settings minus internal usage settings
def visibleSettings = allSettings filterNot (_.isInternalOnly)
@@ -59,6 +59,14 @@ trait AbsSettings {
def helpDescription: String
def unparse: List[String] // A list of Strings which can recreate this setting.
+ /** In mutable Settings, these return the same object with a var set.
+ * In immutable, of course they will return a new object, which means
+ * we can't use "this.type", at least not in a non-casty manner, which
+ * is unfortunate because we lose type information without it.
+ */
+ def withAbbreviation(name: String): Setting
+ def withHelpSyntax(help: String): Setting
+
def helpSyntax: String = name
def abbreviations: List[String] = Nil
def dependencies: List[(Setting, String)] = Nil
diff --git a/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala
new file mode 100644
index 0000000000..a68963f6d8
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala
@@ -0,0 +1,76 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2010 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+package scala.tools.nsc
+package settings
+
+trait AdvancedScalaSettings {
+ self: AbsScalaSettings =>
+
+ abstract class X extends SettingGroup("-X") {
+ val assemextdirs: StringSetting
+ val assemname: StringSetting
+ val assempath: StringSetting
+ val checkinit: BooleanSetting
+ val disableassertions: BooleanSetting
+ val elidelevel: IntSetting
+ val experimental: BooleanSetting
+ val future: BooleanSetting
+ val generatephasegraph: StringSetting
+ val logimplicits: BooleanSetting
+ val migration: BooleanSetting
+ val noforwarders: BooleanSetting
+ val nojline: BooleanSetting
+ val nouescape: BooleanSetting
+ val plugin: MultiStringSetting
+ val plugindisable: MultiStringSetting
+ val pluginlist: BooleanSetting
+ val pluginrequire: MultiStringSetting
+ val pluginsdir: StringSetting
+ val print: PhasesSetting
+ val printicode: BooleanSetting
+ val printpos: BooleanSetting
+ val printtypes: BooleanSetting
+ val prompt: BooleanSetting
+ val resident: BooleanSetting
+ val script: StringSetting
+ val showclass: StringSetting
+ val showobject: StringSetting
+ val showphases: BooleanSetting
+ val sourcedir: StringSetting
+ val sourcereader: StringSetting
+ }
+ // def Xexperimental = X.experimental
+ // def Xmigration28 = X.migration
+ // def Xnojline = X.nojline
+ // def Xprint = X.print
+ // def Xprintpos = X.printpos
+ // def Xshowcls = X.showclass
+ // def Xshowobj = X.showobject
+ // def assemextdirs = X.assemextdirs
+ // def assemname = X.assemname
+ // def assemrefs = X.assempath
+ // def checkInit = X.checkinit
+ // def disable = X.plugindisable
+ // def elideLevel = X.elidelevel
+ // def future = X.future
+ // def genPhaseGraph = X.generatephasegraph
+ // def logimplicits = X.logimplicits
+ // def noForwarders = X.noforwarders
+ // def noassertions = X.disableassertions
+ // def nouescape = X.nouescape
+ // def plugin = X.plugin
+ // def pluginsDir = X.pluginsdir
+ // def printtypes = X.printtypes
+ // def prompt = X.prompt
+ // def require = X.require
+ // def resident = X.resident
+ // def script = X.script
+ // def showPhases = X.showphases
+ // def showPlugins = X.pluginlist
+ // def sourceReader = X.sourcereader
+ // def sourcedir = X.sourcedir
+ // def writeICode = X.printicode
+} \ No newline at end of file
diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
index 8e11b4f506..9bcf48e1b7 100644
--- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
@@ -16,7 +16,7 @@ import interpreter.{ returning }
/** A mutable Settings object.
*/
-class MutableSettings(val errorFn: String => Unit) extends AbsSettings with ScalacSettings with Mutable {
+class MutableSettings(val errorFn: String => Unit) extends AbsSettings with ScalaSettings with Mutable {
type ResultOfTryToSet = List[String]
/** Iterates over the arguments applying them to settings where applicable.
@@ -166,9 +166,7 @@ class MutableSettings(val errorFn: String => Unit) extends AbsSettings with Scal
}
// a wrapper for all Setting creators to keep our list up to date
- // and tell them how to announce errors
private def add[T <: Setting](s: T): T = {
- s setErrorHandler errorFn
allSettings += s
s
}
@@ -309,11 +307,6 @@ class MutableSettings(val errorFn: String => Unit) extends AbsSettings with Scal
* Subclasses each define a `value' field of the appropriate type.
*/
abstract class Setting(val name: String, val helpDescription: String) extends AbsSetting with SettingValue with Mutable {
- /** Error handling function, set after creation by enclosing Settings instance */
- private var _errorFn: String => Unit = _
- private[nsc] def setErrorHandler(e: String => Unit) = _errorFn = e
- def errorFn(msg: String) = _errorFn(msg)
-
/** Will be called after this Setting is set for any extra work. */
private var _postSetHook: this.type => Unit = (x: this.type) => ()
def postSetHook() = { _postSetHook(this) ; this }
@@ -467,8 +460,7 @@ class MutableSettings(val errorFn: String => Unit) extends AbsSettings with Scal
extends Setting(name, descr) {
type T = List[String]
protected var v: List[String] = Nil
- // def appendToValue(str: String) { value ++= List(str) }
- def appendToValue(str: String) { value = value ++ List(str) } // ++= List(str) }
+ def appendToValue(str: String) { value ++= List(str) }
def tryToSet(args: List[String]) = {
val (strings, rest) = args span (x => !x.startsWith("-"))
diff --git a/src/compiler/scala/tools/nsc/settings/ScalacSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index 60c996f02d..0de60672ac 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalacSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -11,17 +11,17 @@ import io.AbstractFile
import util.{ ClassPath, SourceFile, CommandLineParser }
import annotation.elidable
import scala.tools.util.{ PathResolver, StringOps }
-import scala.collection.mutable.ListBuffer
+import scala.collection.mutable.{ HashSet, ListBuffer }
import scala.collection.immutable.TreeSet
import interpreter.{ returning }
-trait ScalacSettings extends AbsScalacSettings with StandardScalaSettings {
+trait ScalaSettings extends AbsScalaSettings with StandardScalaSettings {
self: MutableSettings =>
import PathResolver.{ Defaults, Environment }
/** Set of settings */
- protected var allSettings = Set[Setting]()
+ protected lazy val allSettings = HashSet[Setting]()
/** Disable a setting */
def disable(s: Setting) = allSettings -= s
@@ -30,53 +30,19 @@ trait ScalacSettings extends AbsScalacSettings with StandardScalaSettings {
* Temporary Settings
*/
val suppressVTWarn = BooleanSetting ("-Ysuppress-vt-typer-warnings", "Suppress warnings from the typer when testing the virtual class encoding, NOT FOR FINAL!")
- def appendToClasspath(entry: String) = {
- val oldClasspath = classpath.value
- classpath.value = ClassPath.join(classpath.value, entry)
-
- if (Ylogcp.value)
- Console.println("Updated classpath from '%s' to '%s'".format(oldClasspath, classpath.value))
- }
-
- /**
- * Classpath related settings
- */
-
- val classpath = PathSetting ("-classpath", "path", "Specify where to find user class files", ".") withAbbreviation ("-cp")
- val bootclasspath = PathSetting ("-bootclasspath", "path", "Override location of bootstrap class files", Defaults.scalaBootClassPath)
- val extdirs = PathSetting ("-extdirs", "dirs", "Override location of installed extensions", Defaults.scalaExtDirs)
- val javabootclasspath = PathSetting ("-javabootclasspath", "path", "Override java boot classpath.", Defaults.javaBootClassPath)
- val javaextdirs = PathSetting ("-javaextdirs", "path", "Override java extdirs classpath.", Defaults.javaExtDirs)
- /** This one is most likely temporary, but so helpful while I try to get an iron grip on the classpath. */
- val javaignorecp = BooleanSetting ("-javaignorecp", "scala will not use java's -classpath no matter what.")
-
- val d = OutputSetting (outputDirs, ".")
- val sourcepath = StringSetting ("-sourcepath", "path", "Specify where to find input source files", "")
- val Ylogcp = BooleanSetting ("-Ylog-classpath", "Output information about what classpath is being applied.")
/**
* Standard settings
*/
// argfiles is only for the help message
val argfiles = BooleanSetting ("@<file>", "A text file containing compiler arguments (options and source files)")
+ val classpath = PathSetting ("-classpath", "path", "Specify where to find user class files", ".") .
+ withAbbreviation ("-cp")
+ val d = OutputSetting (outputDirs, ".")
val defines = DefinesSetting()
- val dependencyfile = StringSetting ("-dependencyfile", "file", "Specify the file in which dependencies are tracked", ".scala_dependencies")
- val deprecation = BooleanSetting ("-deprecation", "Output source locations where deprecated APIs are used")
- val encoding = StringSetting ("-encoding", "encoding", "Specify character encoding used by source files", Properties.sourceEncoding)
- val explaintypes = BooleanSetting ("-explaintypes", "Explain type errors in more detail")
- val g = ChoiceSetting ("-g", "Specify level of generated debugging info", List("none", "source", "line", "vars", "notailcalls"), "vars")
- val help = BooleanSetting ("-help", "Print a synopsis of standard options")
- val make = ChoiceSetting ("-make", "Specify recompilation detection strategy", List("all", "changed", "immediate", "transitive", "transitivenocp"), "all") .
- withHelpSyntax("-make:<strategy>")
- val nowarn = BooleanSetting ("-nowarn", "Generate no warnings")
- val optimise = BooleanSetting ("-optimise", "Generates faster bytecode by applying optimisations to the program").withAbbreviation("-optimize") .
- withPostSetHook(_ => List(inline, Xcloselim, Xdce) foreach (_.value = true))
- val print = BooleanSetting ("-print", "Print program with all Scala-specific features removed")
- 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")
- val version = BooleanSetting ("-version", "Print product version and exit")
+ val optimise = BooleanSetting ("-optimise", "Generates faster bytecode by applying optimisations to the program") .
+ withAbbreviation("-optimize") .
+ withPostSetHook(_ => List(inline, Xcloselim, Xdce) foreach (_.value = true))
/**
* -X "Advanced" settings
@@ -115,6 +81,16 @@ trait ScalacSettings extends AbsScalacSettings with StandardScalaSettings {
val showPhases = BooleanSetting ("-Xshow-phases", "Print a synopsis of compiler phases")
val sourceReader = StringSetting ("-Xsource-reader", "classname", "Specify a custom method for reading source files", "scala.tools.nsc.io.SourceReader")
+ /** Compatibility stubs for options whose value name did
+ * not previously match the option name.
+ */
+ def XO = optimise
+ def debuginfo = g
+ def dependenciesFile = dependencyfile
+ def nowarnings = nowarn
+ def outdir = d
+ def printLate = print
+
/**
* -Y "Private" settings
*/
@@ -132,6 +108,7 @@ trait ScalacSettings extends AbsScalacSettings with StandardScalaSettings {
val Xlinearizer = ChoiceSetting ("-Ylinearizer", "Linearizer to use", List("normal", "dfs", "rpo", "dump"), "rpo") .
withHelpSyntax("-Ylinearizer:<which>")
val log = PhasesSetting ("-Ylog", "Log operations in")
+ val Ylogcp = BooleanSetting ("-Ylog-classpath", "Output information about what classpath is being applied.")
val Ynogenericsig = BooleanSetting ("-Yno-generic-signatures", "Suppress generation of generic signatures for Java")
val noimports = BooleanSetting ("-Yno-imports", "Compile without any implicit imports")
val nopredefs = BooleanSetting ("-Yno-predefs", "Compile without any implicit predefined values")
diff --git a/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala
index 6ad82454e5..74e69b82e6 100644
--- a/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala
@@ -6,55 +6,50 @@
package scala.tools.nsc
package settings
+import scala.tools.util.PathResolver.Defaults
+
/** Settings which aren't behind a -X, -Y, or -P option.
- * Wherever possible, the val and the option have identical.
- * names.
+ * When possible, the val and the option have identical names.
+ * The abstract settings are commented as to why they are as yet
+ * implemented in MutableSettings rather than mutation-generically.
*/
trait StandardScalaSettings {
- self: AbsScalacSettings =>
+ self: AbsScalaSettings =>
/** Path related settings.
+ * !!! javaignorecp is temporary while I try to get an iron grip on the classpath.
*/
- val bootclasspath: PathSetting
- val classpath: PathSetting
- val d: OutputSetting
- val extdirs: PathSetting
- val g: ChoiceSetting
- val javabootclasspath: PathSetting
- val javaextdirs: PathSetting
- val javaignorecp: BooleanSetting
- val sourcepath: StringSetting
+ val bootclasspath = PathSetting ("-bootclasspath", "path", "Override location of bootstrap class files", Defaults.scalaBootClassPath)
+ val classpath: PathSetting // is mutated directly in various places (thus inspiring this very effort)
+ val d: OutputSetting // depends on mutable OutputDirs class
+ val extdirs = PathSetting ("-extdirs", "dirs", "Override location of installed extensions", Defaults.scalaExtDirs)
+ val javabootclasspath = PathSetting ("-javabootclasspath", "path", "Override java boot classpath.", Defaults.javaBootClassPath)
+ val javaextdirs = PathSetting ("-javaextdirs", "path", "Override java extdirs classpath.", Defaults.javaExtDirs)
+ val javaignorecp = BooleanSetting ("-javaignorecp", "scala will not use java's -classpath no matter what.")
+ val sourcepath = StringSetting ("-sourcepath", "path", "Specify where to find input source files", "")
/** Other settings.
*/
- val dependencyfile: StringSetting
- val deprecation: BooleanSetting
- val encoding: StringSetting
- val explaintypes: BooleanSetting
- val help: BooleanSetting
- val make: ChoiceSetting
- val nowarn: BooleanSetting
- val optimise: BooleanSetting
- val print: BooleanSetting
- val target: ChoiceSetting
- val unchecked: BooleanSetting
- val uniqid: BooleanSetting
- val verbose: BooleanSetting
- val version: BooleanSetting
+ val dependencyfile = StringSetting ("-dependencyfile", "file", "Specify the file in which dependencies are tracked", ".scala_dependencies")
+ val deprecation = BooleanSetting ("-deprecation", "Output source locations where deprecated APIs are used")
+ val encoding = StringSetting ("-encoding", "encoding", "Specify character encoding used by source files", Properties.sourceEncoding)
+ val explaintypes = BooleanSetting ("-explaintypes", "Explain type errors in more detail")
+ val g = ChoiceSetting ("-g", "Specify level of generated debugging info", List("none", "source", "line", "vars", "notailcalls"), "vars")
+ val help = BooleanSetting ("-help", "Print a synopsis of standard options")
+ val make = ChoiceSetting ("-make", "Specify recompilation detection strategy", List("all", "changed", "immediate", "transitive", "transitivenocp"), "all") .
+ withHelpSyntax("-make:<strategy>")
+ val nowarn = BooleanSetting ("-nowarn", "Generate no warnings")
+ val optimise: BooleanSetting // depends on post hook which mutates other settings
+ val print = BooleanSetting ("-print", "Print program with all Scala-specific features removed")
+ 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")
+ val version = BooleanSetting ("-version", "Print product version and exit")
/** These are @<file> and -Dkey=val style settings, which don't
* nicely map to identifiers.
*/
- val argfiles: BooleanSetting
- val defines: DefinesSetting
-
- /** Compatibility stubs for options whose value name did
- * not previously match the option name.
- */
- def XO = optimise
- def debuginfo = g
- def dependenciesFile = dependencyfile
- def nowarnings = nowarn
- def outdir = d
- def printLate = print
+ val argfiles: BooleanSetting // exists only to echo help message, should be done differently
+ val defines: DefinesSetting // not entirely clear that DefinesSetting makes sense as a Setting
}
diff --git a/src/intellij/scala-lang.ipr b/src/intellij/scala-lang.ipr
index 45af31680c..2506c74f6a 100644
--- a/src/intellij/scala-lang.ipr
+++ b/src/intellij/scala-lang.ipr
@@ -1361,7 +1361,7 @@
<option name="GENERATE_IIOP_STUBS" value="false" />
<option name="ADDITIONAL_OPTIONS_STRING" value="" />
</component>
- <component name="ScalacSettings">
+ <component name="ScalaSettings">
<option name="MAXIMUM_HEAP_SIZE" value="1024" />
<option name="DEPRECATION" value="false" />
<option name="UNCHECKED" value="false" />
diff --git a/src/partest/scala/tools/partest/nest/TestFile.scala b/src/partest/scala/tools/partest/nest/TestFile.scala
index 397ae4ba04..741556fdd5 100644
--- a/src/partest/scala/tools/partest/nest/TestFile.scala
+++ b/src/partest/scala/tools/partest/nest/TestFile.scala
@@ -24,12 +24,12 @@ abstract class TestFile(kind: String) {
def setOutDirTo = objectDir
def defineSettings(settings: Settings, setOutDir: Boolean) = {
- settings appendToClasspath dir.path
+ settings.classpath append dir.path
if (setOutDir)
settings.outdir.value = setOutDirTo.path
flags foreach (settings processArgumentString _)
- settings appendToClasspath fileManager.CLASSPATH
+ settings.classpath append fileManager.CLASSPATH
}
override def toString(): String = "%s %s".format(kind, file)