From 644350e3ca3e3298de932d08affbe4b8ed69cc3e Mon Sep 17 00:00:00 2001 From: Gilles Dubochet Date: Mon, 4 Feb 2008 18:05:29 +0000 Subject: Defined a more precise notion of equality on co... Defined a more precise notion of equality on compiler settings. --- src/compiler/scala/tools/nsc/CompileServer.scala | 8 +--- src/compiler/scala/tools/nsc/Settings.scala | 52 ++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index 4ad9f247aa..9c3845798e 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -38,13 +38,7 @@ class StandardCompileServer extends SocketServer { private var inSession: Boolean = false private var progress: Boolean = false - private def settingsAreCompatible(s1: Settings, s2: Settings) = - s1.encoding.value == s2.encoding.value && - s1.classpath.value == s2.classpath.value && - s1.sourcepath.value == s2.sourcepath.value && - s1.outdir.value == s2.outdir.value && - s1.bootclasspath.value == s2.bootclasspath.value && - s1.extdirs.value == s2.extdirs.value + private def settingsAreCompatible(s1: Settings, s2: Settings) = s1 == s2 private def exit(code: Int): Nothing = { System.err.close() diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index 90246cead5..4692eabca6 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -10,6 +10,7 @@ import java.io.File import java.lang.System class Settings(error: String => Unit) { + def this() = this(Console.println) private var allsettings: List[Setting] = List() @@ -176,6 +177,16 @@ class Settings(error: String => Unit) { allsettings = allsettings filter (s !=) } + override def equals(that: Any) = that match { + case s:Settings => + assert(this.allSettings.length == s.allSettings.length) + List.forall2 ( + this.allSettings, + s.allSettings + )(_==_) + case _ => false + } + def checkDependencies: Boolean = { def hasValue(s: Setting, value: String): Boolean = s match { case bs: BooleanSetting => bs.value @@ -240,7 +251,7 @@ class Settings(error: String => Unit) { def dependsOn(s: Setting, value: String): this.type = { dependency = Some((s, value)); this } def dependsOn(s: Setting): this.type = dependsOn(s, "") - def isStandard: Boolean = !isAdvanced && !isPrivate + def isStandard: Boolean = !isAdvanced && !isPrivate && !(name eq "-Y") def isAdvanced: Boolean = (name startsWith "-X") && !(name eq "-X") def isPrivate: Boolean = @@ -265,6 +276,12 @@ class Settings(error: String => Unit) { } def unparse: List[String] = if (value) List(name) else Nil + + override def equals(that: Any) = that match { + case bs:BooleanSetting => this.name == bs.name && this.value == bs.value + case _ => false + } + } /** A setting represented by a string, (`default' unless set) */ @@ -294,6 +311,12 @@ class Settings(error: String => Unit) { def unparse: List[String] = if (value == default) Nil else List(name, value) + + override def equals(that: Any) = that match { + case ss:StringSetting => this.name == ss.name && this.value == ss.value + case _ => false + } + } /** A setting that accumulates all strings supplied to it */ @@ -326,8 +349,16 @@ class Settings(error: String => Unit) { override def helpSyntax = name + ":<" + arg + ">" def unparse: List[String] = - for (opt <- value) - yield nameColon+opt + for (opt <- value) yield nameColon+opt + + override def equals(that: Any) = that match { + case mss:MultiStringSetting => + this.name == mss.name && + this.value.length == mss.value.length && + List.forall2(this.value.sort(_<_), mss.value.sort(_<_))(_==_) + case _ => false + } + } /** A setting represented by a string in a given set of choices, @@ -371,6 +402,12 @@ class Settings(error: String => Unit) { def unparse: List[String] = if (value == default) Nil else List(name + ":" + value) + + override def equals(that: Any) = that match { + case cs:ChoiceSetting => this.name == cs.name && this.value == cs.value + case _ => false + } + } /** Same as ChoiceSetting but have a level int which tells the @@ -451,5 +488,14 @@ class Settings(error: String => Unit) { (Nil) ((args, phase) => List(name + ":" + phase) ::: args)) + + override def equals(that: Any) = that match { + case ps:PhasesSetting => + this.name == ps.name && + this.value.length == ps.value.length && + List.forall2(this.value.sort(_<_), ps.value.sort(_<_))(_==_) + case _ => false + } + } } -- cgit v1.2.3