diff options
author | Martin Odersky <odersky@gmail.com> | 2011-08-24 17:02:31 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2011-08-24 17:02:31 +0000 |
commit | 77175ede13ac1b0b37e82aabdfe091e0ec592b25 (patch) | |
tree | dd8551c9ca54d6532ca7e44abe675560d34f2fc4 /src/compiler/scala/tools/nsc/Driver.scala | |
parent | 48e8133cb08a252ea0ec325d4c6537bccb2e0465 (diff) | |
download | scala-77175ede13ac1b0b37e82aabdfe091e0ec592b25.tar.gz scala-77175ede13ac1b0b37e82aabdfe091e0ec592b25.tar.bz2 scala-77175ede13ac1b0b37e82aabdfe091e0ec592b25.zip |
Refactored everything that's clean in nsc.Main ...
Refactored everything that's clean in nsc.Main to nsc.Driver. Left the
cruft in Main which now inherits Driver. Makes it simpler to create new
compiler variants by subclassing Driver instead of adding yet one more
case to the convoluted logic in Main.
Diffstat (limited to 'src/compiler/scala/tools/nsc/Driver.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/Driver.scala | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/Driver.scala b/src/compiler/scala/tools/nsc/Driver.scala new file mode 100644 index 0000000000..db95c1442b --- /dev/null +++ b/src/compiler/scala/tools/nsc/Driver.scala @@ -0,0 +1,69 @@ +package scala.tools.nsc + +import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} +import Properties.{ versionString, copyrightString } +import scala.tools.nsc.util.{ BatchSourceFile, FakePos } + +abstract class Driver { + + val versionMsg = "Scala compiler " + + versionString + " -- " + + copyrightString + + var reporter: ConsoleReporter = _ + protected var command: CompilerCommand = _ + protected var settings: Settings = _ + + protected def scalacError(msg: String) { + reporter.error(FakePos("scalac"), msg + "\n scalac -help gives more information") + } + + protected def processSettingsHook(): Boolean = true + + protected def newCompiler(): Global + + protected def doCompile(compiler: Global) { + if (command.files.isEmpty) { + reporter.info(null, command.usageMsg, true) + reporter.info(null, compiler.pluginOptionsHelp, true) + } else { + val run = new compiler.Run() + run compile command.files + reporter.printSummary() + } + } + + def process(args: Array[String]) { + val ss = new Settings(scalacError) + reporter = new ConsoleReporter(ss) + command = new CompilerCommand(args.toList, ss) + settings = command.settings + + if (settings.version.value) { + reporter.info(null, versionMsg, true) + } else if (processSettingsHook()) { + val compiler = newCompiler() + try { + if (reporter.hasErrors) + reporter.flush() + else if (command.shouldStopWithInfo) + reporter.info(null, command.getInfoMessage(compiler), true) + else + doCompile(compiler) + } catch { + case ex => + compiler.logThrowable(ex) + ex match { + case FatalError(msg) => reporter.error(null, "fatal error: " + msg) + case _ => throw ex + } + } + } + } + + def main(args: Array[String]) { + process(args) + sys.exit(if (reporter.hasErrors) 1 else 0) + } + +}
\ No newline at end of file |