summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2014-09-08 19:25:47 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2014-09-08 21:38:15 +0200
commit1ea684341ba9eeff7c6bc6f943fb2d048a9ff5a3 (patch)
treeb4ad06f7bc657a591a31669804cae2bf9e0dd569 /src/compiler/scala/tools/nsc/settings/MutableSettings.scala
parent861ad72b59c5ea7856b2853c092aaeb15453caea (diff)
downloadscala-1ea684341ba9eeff7c6bc6f943fb2d048a9ff5a3.tar.gz
scala-1ea684341ba9eeff7c6bc6f943fb2d048a9ff5a3.tar.bz2
scala-1ea684341ba9eeff7c6bc6f943fb2d048a9ff5a3.zip
Make MultiChoiceSetting.compute easier to understand
Diffstat (limited to 'src/compiler/scala/tools/nsc/settings/MutableSettings.scala')
-rw-r--r--src/compiler/scala/tools/nsc/settings/MutableSettings.scala29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
index 1f75afd49a..bbe21477cb 100644
--- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
@@ -604,10 +604,9 @@ class MutableSettings(val errorFn: String => Unit)
withHelpSyntax(s"$name:<_,$helpArg,-$helpArg>")
object ChoiceOrVal {
- def unapply(a: Any): Option[(String, String, List[domain.Choice])] = a match {
+ def unapply(a: domain.Value): Option[(String, String, List[domain.Choice])] = a match {
case c: domain.Choice => Some((c.name, c.help, c.expandsTo))
case v: domain.Value => Some((v.toString, "", Nil))
- case _ => None
}
}
@@ -641,31 +640,25 @@ class MutableSettings(val errorFn: String => Unit)
/** (Re)compute from current yeas, nays, wildcard status. */
def compute() = {
- def nonExpanding(vs: domain.ValueSet) = vs filter {
- case ChoiceOrVal(_, _, others) => others.isEmpty
+ def simple(v: domain.Value) = v match {
+ case ChoiceOrVal(_, _, Nil) => true
+ case _ => false
}
/**
- * Expand an option, if necessary recursively. Expanding options are not included in the
- * result (consistent with "_", which is not in the values either). Explicitly excluded
- * options (in nays) are not added.
+ * Expand an expanding option, if necessary recursively. Expanding options are not included in
+ * the result (consistent with "_", which is not in `value` either).
*
* Note: by precondition, options in nays are not expanding, they can only be leaves.
*/
def expand(vs: domain.ValueSet): domain.ValueSet = vs flatMap {
- // expand
- case c @ ChoiceOrVal(_, _, others) if others.nonEmpty => expand(domain.ValueSet(others: _*))
- case c @ ChoiceOrVal(_, _, _) if !nays(c) => domain.ValueSet(c)
- case _ => domain.ValueSet.empty
+ case c @ ChoiceOrVal(_, _, Nil) => domain.ValueSet(c)
+ case ChoiceOrVal(_, _, others) => expand(domain.ValueSet(others: _*))
}
- val expandedYeas = expand(yeas)
-
- // we include everything, except those explicitly disabled.
- val expandedAll = if (sawAll) nonExpanding(domain.values) &~ nays
- else domain.ValueSet.empty
-
- value = nonExpanding(yeas) | expandedYeas | expandedAll
+ // yeas from _ or expansions are weak: an explicit nay will disable them
+ val weakYeas = if (sawAll) domain.values filter simple else expand(yeas filterNot simple)
+ value = (yeas filter simple) | (weakYeas &~ nays)
}
/** Add a named choice to the multichoice value. */