diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/Driver.scala | 69 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Main.scala | 72 |
2 files changed, 83 insertions, 58 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 diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala index de1d148a36..38da47aacc 100644 --- a/src/compiler/scala/tools/nsc/Main.scala +++ b/src/compiler/scala/tools/nsc/Main.scala @@ -17,19 +17,10 @@ import Properties.{ versionString, copyrightString, residentPromptString, msilLi /** The main class for NSC, a compiler for the programming * language Scala. */ -object Main extends AnyRef with EvalLoop { - val versionMsg = "Scala compiler " + - versionString + " -- " + - copyrightString +object Main extends Driver with EvalLoop { val prompt = residentPromptString - var reporter: ConsoleReporter = _ - - private def scalacError(msg: String) { - reporter.error(FakePos("scalac"), msg + "\n scalac -help gives more information") - } - def resident(compiler: Global) { loop { line => val args = line.split(' ').toList @@ -39,15 +30,8 @@ object Main extends AnyRef with EvalLoop { } } - def process(args: Array[String]) { - val ss = new Settings(scalacError) - reporter = new ConsoleReporter(ss) - val command = new CompilerCommand(args.toList, ss) - val settings = command.settings - - if (settings.version.value) - reporter.info(null, versionMsg, true) - else if (settings.Yidedebug.value) { + override def processSettingsHook(): Boolean = + if (settings.Yidedebug.value) { settings.Xprintpos.value = true settings.Yrangepos.value = true val compiler = new interactive.Global(settings, reporter) @@ -62,6 +46,7 @@ object Main extends AnyRef with EvalLoop { case None => reporter.reset() // Causes other compiler errors to be ignored } askShutdown + false } else if (settings.Ybuilderdebug.value != "none") { def fileSet(files : List[String]) = Set.empty ++ (files map AbstractFile.getFile) @@ -78,50 +63,21 @@ object Main extends AnyRef with EvalLoop { val command = new CompilerCommand(args.toList, settings) buildManager.update(fileSet(command.files), Set.empty) } + false } else { if (settings.target.value == "msil") msilLibPath foreach (x => settings.assemrefs.value += (pathSeparator + x)) - - val compiler = - if (settings.Yrangepos.value) new interactive.Global(settings, reporter) - else new Global(settings, reporter) - - try { - if (reporter.hasErrors) - return reporter.flush() - - if (command.shouldStopWithInfo) { - reporter.info(null, command.getInfoMessage(compiler), true) - } - else { - if (settings.resident.value) - resident(compiler) - else 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() - } - } - } - catch { - case ex => - compiler.logThrowable(ex) - ex match { - case FatalError(msg) => reporter.error(null, "fatal error: " + msg) - case _ => throw ex - } - } + true } - } - def main(args: Array[String]) { - process(args) - sys.exit(if (reporter.hasErrors) 1 else 0) - } + override def newCompiler(): Global = + if (settings.Yrangepos.value) new interactive.Global(settings, reporter) + else new Global(settings, reporter) + override def doCompile(compiler: Global) { + if (settings.resident.value) + resident(compiler) + else super.doCompile(compiler) + } } |