diff options
author | Paul Phillips <paulp@improving.org> | 2011-09-28 20:49:29 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-09-28 20:49:29 +0000 |
commit | 82eb1aa430195648b6fe80f67c45c741884dc2d7 (patch) | |
tree | 1a6b52bdd181d571e5f773942b3c1aa04a04d99a | |
parent | 26ddf17b21f289bba1ac76db7d5df54af306e75b (diff) | |
download | scala-82eb1aa430195648b6fe80f67c45c741884dc2d7.tar.gz scala-82eb1aa430195648b6fe80f67c45c741884dc2d7.tar.bz2 scala-82eb1aa430195648b6fe80f67c45c741884dc2d7.zip |
Hand specialized SettingValue.
Discovered every time we do something like
if (settings.debug.value)
the boolean is coming out of a box. How uncouth. To fix this, I had to
make the storage abstract, so concrete setting types have to declare
the storage personally. This seems a small price to pay. I tried to use
specialization but I think it's impossible to get the type parameter and
the abstract type to agree with one another when mr. invariant var is
the object of your affection, without scalac putting the kibosh on the
whole adventure. No review.
3 files changed, 28 insertions, 22 deletions
diff --git a/src/compiler/scala/reflect/internal/settings/MutableSettings.scala b/src/compiler/scala/reflect/internal/settings/MutableSettings.scala index 3bf296760f..b756408541 100644 --- a/src/compiler/scala/reflect/internal/settings/MutableSettings.scala +++ b/src/compiler/scala/reflect/internal/settings/MutableSettings.scala @@ -12,10 +12,12 @@ package settings abstract class MutableSettings extends AbsSettings { type Setting <: SettingValue + type BooleanSetting <: Setting { type T = Boolean } + type IntSetting <: Setting { type T = Int } // basically this is a value which remembers if it's been modified trait SettingValue extends AbsSettingValue { - protected var v: T = _ + protected var v: T protected var setByUser: Boolean = false def postSetHook(): Unit = () @@ -29,15 +31,15 @@ abstract class MutableSettings extends AbsSettings { } } - def overrideObjects: SettingValue { type T = Boolean } - def printtypes: SettingValue { type T = Boolean } - def debug: SettingValue { type T = Boolean } - def YdepMethTpes: SettingValue { type T = Boolean } - def Ynotnull: SettingValue { type T = Boolean } - def explaintypes: SettingValue { type T = Boolean } - def verbose: SettingValue { type T = Boolean } - def uniqid: SettingValue { type T = Boolean } - def Xprintpos: SettingValue { type T = Boolean } - def Yrecursion: SettingValue { type T = Int } - def maxClassfileName: SettingValue { type T = Int } + def overrideObjects: BooleanSetting + def printtypes: BooleanSetting + def debug: BooleanSetting + def YdepMethTpes: BooleanSetting + def Ynotnull: BooleanSetting + def explaintypes: BooleanSetting + def verbose: BooleanSetting + def uniqid: BooleanSetting + def Xprintpos: BooleanSetting + def Yrecursion: IntSetting + def maxClassfileName: IntSetting }
\ No newline at end of file diff --git a/src/compiler/scala/reflect/runtime/Settings.scala b/src/compiler/scala/reflect/runtime/Settings.scala index 4bd72ce47b..86e8457850 100644 --- a/src/compiler/scala/reflect/runtime/Settings.scala +++ b/src/compiler/scala/reflect/runtime/Settings.scala @@ -7,16 +7,18 @@ package runtime */ class Settings extends internal.settings.MutableSettings { - class Setting extends SettingValue + trait Setting extends SettingValue { } class BooleanSetting(x: Boolean) extends Setting { type T = Boolean - v = x + protected var v: Boolean = x + override def value: Boolean = v } class IntSetting(x: Int) extends Setting { type T = Int - v = x + protected var v: Int = x + override def value: Int = v } val overrideObjects = new BooleanSetting(false) diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala index 0ccb8df4bb..67a556f6f0 100644 --- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala @@ -361,7 +361,8 @@ class MutableSettings(val errorFn: String => Unit) parser: String => Option[Int]) extends Setting(name, descr) { type T = Int - v = default + protected var v: Int = default + override def value: Int = v // not stable values! val IntMin = Int.MinValue @@ -418,7 +419,8 @@ class MutableSettings(val errorFn: String => Unit) descr: String) extends Setting(name, descr) { type T = Boolean - v = false + protected var v: Boolean = false + override def value: Boolean = v def tryToSet(args: List[String]) = { value = true ; Some(args) } def unparse: List[String] = if (value) List(name) else Nil @@ -434,7 +436,7 @@ class MutableSettings(val errorFn: String => Unit) descr: String) extends Setting(name, descr) { type T = List[String] - v = Nil + protected var v: T = Nil def tryToSet(args: List[String]) = args match { case x :: xs if x startsWith prefix => @@ -455,7 +457,7 @@ class MutableSettings(val errorFn: String => Unit) val default: String) extends Setting(name, descr) { type T = String - v = default + protected var v: T = default def tryToSet(args: List[String]) = args match { case Nil => errorAndValue("missing argument", None) @@ -505,7 +507,7 @@ class MutableSettings(val errorFn: String => Unit) descr: String) extends Setting(name, descr) { type T = List[String] - v = Nil + protected var v: T = Nil def appendToValue(str: String) { value ++= List(str) } def tryToSet(args: List[String]) = { @@ -532,7 +534,7 @@ class MutableSettings(val errorFn: String => Unit) val default: String) extends Setting(name, descr + choices.mkString(" (", ",", ") default:" + default)) { type T = String - v = default + protected var v: T = default def indexOfChoice: Int = choices indexOf value private def usageErrorMessage = { @@ -573,7 +575,7 @@ class MutableSettings(val errorFn: String => Unit) private[nsc] def this(name: String, descr: String) = this(name, descr, "") type T = List[String] - v = Nil + protected var v: T = Nil override def value = if (v contains "all") List("all") else super.value private lazy val (numericValues, stringValues) = value filterNot (_ == "" ) partition (_ forall (ch => ch.isDigit || ch == '-')) |