diff options
author | Antonio Cunei <antonio.cunei@epfl.ch> | 2008-10-15 13:58:23 +0000 |
---|---|---|
committer | Antonio Cunei <antonio.cunei@epfl.ch> | 2008-10-15 13:58:23 +0000 |
commit | 86b39a89cda0680d487b3591b492e4dc2ed5263f (patch) | |
tree | ee6490ac748ce7c2247f870251db5adb8f9c2d50 | |
parent | 1615902e57a0d61cebb62409bdc8da0cf1d8bf18 (diff) | |
download | scala-86b39a89cda0680d487b3591b492e4dc2ed5263f.tar.gz scala-86b39a89cda0680d487b3591b492e4dc2ed5263f.tar.bz2 scala-86b39a89cda0680d487b3591b492e4dc2ed5263f.zip |
Fix for #296
The handling of informative messages in CompileServer and in Main was
duplicated, and the two copies slowly diverged over time. The code has
now been refactored, cleaned up, and made more general.
The FakePos(fsc) message was due to a missing override def toString.
Both problems are fixed.
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileServer.scala | 11 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompilerCommand.scala | 30 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Main.scala | 19 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/Position.scala | 4 |
4 files changed, 41 insertions, 23 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index 9c3845798e..541aadaffa 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -114,13 +114,10 @@ class StandardCompileServer extends SocketServer { override def displayPrompt = () } - if (command.settings.version.value) - reporter.info(null, versionMsg, true) - else if (command.settings.help.value || command.settings.Xhelp.value) { - if (command.settings.help.value) reporter.info(null, command.usageMsg, true) - if (command.settings.Xhelp.value) reporter.info(null, command.xusageMsg, true) - } - else if (command.files.isEmpty) + if (command.shouldStopWithInfo) { + reporter.info(null, + command.getInfoMessage(newGlobal(command.settings, reporter)), true) + } else if (command.files.isEmpty) reporter.info(null, command.usageMsg, true) else { try { diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index 9ad0bb2539..6f22fb8612 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -66,6 +66,36 @@ class CompilerCommand(arguments: List[String], val settings: Settings, "\n") } + // If any of these settings is set, the compiler shouldn't + // start; an informative message of some sort + // should be printed instead. + // (note: do not add "files.isEmpty" do this list) + val stopSettings=List[(()=>Boolean, + (Global)=>String)]( + (()=> settings.help.value, compiler => + usageMsg + compiler.pluginOptionsHelp + ), + (()=> settings.Xhelp.value, compiler => + xusageMsg + ), + (()=> settings.Yhelp.value, compiler => + yusageMsg + ), + (()=> settings.showPlugins.value, compiler => + compiler.pluginDescriptions + ), + (()=> settings.showPhases.value, compiler => + compiler.phaseDescriptions + ) + ) + + def shouldStopWithInfo = stopSettings.exists({pair => (pair._1)()}) + def getInfoMessage(compiler:Global) = + stopSettings.find({pair => (pair._1)()}) match { + case Some((test,getMessage)) => getMessage(compiler) + case None => "" + } + /** Whether the command was processed okay */ var ok = true diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala index a3ff3b7fa3..74e74ae5f8 100644 --- a/src/compiler/scala/tools/nsc/Main.scala +++ b/src/compiler/scala/tools/nsc/Main.scala @@ -60,24 +60,13 @@ object Main extends AnyRef with EvalLoop { return } - if (command.settings.help.value || command.settings.Xhelp.value || command.settings.Yhelp.value) { - if (command.settings.help.value) { - reporter.info(null, command.usageMsg, true) - reporter.info(null, compiler.pluginOptionsHelp, true) - } - if (command.settings.Xhelp.value) - reporter.info(null, command.xusageMsg, true) - if (command.settings.Yhelp.value) - reporter.info(null, command.yusageMsg, true) - } else if (command.settings.showPlugins.value) - reporter.info(null, compiler.pluginDescriptions, true) - else if (command.settings.showPhases.value) - reporter.info(null, compiler.phaseDescriptions, true) - else { + if (command.shouldStopWithInfo) { + reporter.info(null, command.getInfoMessage(compiler), true) + } else { if (command.settings.resident.value) resident(compiler) else if (command.files.isEmpty) { - reporter.info(null, command.usageMsg, true) + reporter.info(null, command.usageMsg, true) reporter.info(null, compiler.pluginOptionsHelp, true) } else { val run = new compiler.Run diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala index 320ee48e77..142c92e0b2 100644 --- a/src/compiler/scala/tools/nsc/util/Position.scala +++ b/src/compiler/scala/tools/nsc/util/Position.scala @@ -71,7 +71,9 @@ trait Position { } case object NoPosition extends Position -case class FakePos(msg: String) extends Position +case class FakePos(msg: String) extends Position { + override def toString=msg +} case class LinePosition(source0: SourceFile, line0: Int) extends Position { assert(line0 >= 1) |