summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-08-31 11:28:06 +0000
committerGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-08-31 11:28:06 +0000
commitb3ba623412b9a15ddd22396fd1323c8c698ca421 (patch)
treeb8711ae5fb8f97e3e6900574f72692b66a89899a /src/compiler
parentea2fa34a568aa7fbcec7e17703d736bc2028d573 (diff)
downloadscala-b3ba623412b9a15ddd22396fd1323c8c698ca421.tar.gz
scala-b3ba623412b9a15ddd22396fd1323c8c698ca421.tar.bz2
scala-b3ba623412b9a15ddd22396fd1323c8c698ca421.zip
Added support for Integer Settings.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index 712b2ed33c..7cbc77a7c9 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -269,6 +269,60 @@ class Settings(error: String => Unit) {
allsettings = this :: allsettings
}
+ /** A setting represented by a positive integer */
+ case class IntSetting(name: String, descr: String, default: Int, min: Option[Int], max: Option[Int]) extends Setting(descr) {
+ // Validate that min and max are consistent
+ (min, max) match { case (Some(i), Some(j)) => assert (i <= j)
+ case _ => () }
+
+ // Helper to validate an input
+ def valid(k: Int): Boolean =
+ (min, max) match { case (Some(i), Some(j)) => (i <= k) && (k <= j)
+ case (Some(i), None) => (i <= k)
+ case (None, Some(j)) => (k <= j)
+ case _ => true }
+
+ // Helper to generate a textual explaination of valid inputs
+ def validText: String =
+ (min, max) match { case (Some(i), Some(j)) => "must be between "+i+" and "+j
+ case (Some(i), None) => "must be greater than or equal to "+i
+ case (None, Some(j)) => "must be less than or equal to "+j
+ case _ => throw new Error("this should never be used") }
+
+ // Ensure that the default value is actually valid
+ assert(valid(default))
+
+ protected var v: Int = default
+
+ def value: Int = this.v
+ def value_=(s: Int) {
+ if(!valid(s)) error("invalid setting for -"+name+" "+validText)
+ setByUser = true;
+ this.v = s
+ }
+
+ def tryToSet(args: List[String]): List[String] = args match {
+ case n :: rest if (name == n) =>
+ if (rest.isEmpty) {
+ error("missing argument")
+ args
+ } else {
+ value = rest.head.toInt
+ rest.tail
+ }
+ case _ => args
+ }
+
+ def unparse: List[String] =
+ if (value == default) Nil else List(name, value.toString)
+
+ override def equals(that: Any) = that match {
+ case is:IntSetting => this.name == is.name && this.value == is.value
+ case _ => false
+ }
+ }
+
+
/** A setting represented by a boolean flag (false, unless set) */
case class BooleanSetting(name: String, descr: String) extends Setting(descr) {
protected var v: Boolean = false