diff options
-rw-r--r-- | build.xml | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ScalaDoc.scala | 111 |
2 files changed, 115 insertions, 4 deletions
@@ -499,7 +499,7 @@ BUILD LOCAL REFERENCE (LOCKER) LAYER <lockertool file="${locker.dir}/bin/${scaladoc.exec.name}" name="Scala doc generator" - class="scala.tools.nsc.Main" + class="scala.tools.nsc.ScalaDoc" toolflags="-Ydoc" version="${version.number}" copyright="${copyright.string}" @@ -696,7 +696,7 @@ BUILD QUICK-TEST LAYER <quicktool file="${quick.dir}/bin/${scaladoc.exec.name}" name="Scala doc generator" - class="scala.tools.nsc.Main" + class="scala.tools.nsc.ScalaDoc" toolflags="-Ydoc" version="${version.number}" copyright="${copyright.string}" @@ -1270,7 +1270,7 @@ OPTIMIZE <straptool file="${optimised.dir}/bin/${scaladoc.exec.name}" name="Scala doc generator" - class="scala.tools.nsc.Main" + class="scala.tools.nsc.ScalaDoc" toolflags="-Ydoc" version="${version.number}" copyright="${copyright.string}" @@ -1461,7 +1461,7 @@ TEST <straptool file="${strap.dir}/bin/${scaladoc.exec.name}" name="Scala doc generator" - class="scala.tools.nsc.Main" + class="scala.tools.nsc.ScalaDoc" toolflags="-Ydoc" version="${version.number}" copyright="${copyright.string}" diff --git a/src/compiler/scala/tools/nsc/ScalaDoc.scala b/src/compiler/scala/tools/nsc/ScalaDoc.scala new file mode 100644 index 0000000000..c58fb440a7 --- /dev/null +++ b/src/compiler/scala/tools/nsc/ScalaDoc.scala @@ -0,0 +1,111 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2007 LAMP/EPFL + * @author Martin Odersky + */ +// $Id$ + +package scala.tools.nsc + +import java.io.File + +import scala.tools.nsc.doc.DefaultDocDriver +import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} +import scala.tools.nsc.util.FakePos //{Position} + + +/** The main class for NSC, a compiler for the programming + * language Scala. + */ +object ScalaDoc extends AnyRef with EvalLoop { + + val versionMsg = "Scala compiler " + + Properties.versionString + " -- " + + Properties.copyrightString + + val prompt = Properties.residentPromptString + + var reporter: ConsoleReporter = _ + + def error(msg: String) { + reporter.error(/*new Position */FakePos("scalac"), + msg + "\n scalac -help gives more information") + } + + /* needed ?? */ + //def errors() = reporter.errors + + def resident(compiler: Global) { + loop { line => + val args = List.fromString(line, ' ') + val command = new CompilerCommand(args, new Settings(error), error, true) + (new compiler.Run) compile command.files + } + } + + def process(args: Array[String]) { + val settings = new Settings(error) + reporter = new ConsoleReporter(settings) + val command = new CompilerCommand(List.fromArray(args), settings, error, false) + if (command.settings.version.value) + reporter.info(null, versionMsg, true) + else { + if (command.settings.target.value == "msil") { + val libpath = System.getProperty("msil.libpath") + if (libpath != null) + command.settings.assemrefs.value = + command.settings.assemrefs.value + File.pathSeparator + libpath + } + try { + object compiler extends Global(command.settings, reporter) + if (reporter.hasErrors) { + reporter.flush() + 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.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 + if (command.settings.doc.value) { + val generator = new DefaultDocDriver { + lazy val global: compiler.type = compiler + def settings = command.settings + } + generator.process(command.settings, run.units) + } + reporter.printSummary() + } + } + } catch { + case ex @ FatalError(msg) => + if (command.settings.debug.value) + ex.printStackTrace(); + reporter.error(null, "fatal error: " + msg) + } + } + } + + def main(args: Array[String]) { + process(args) + exit(if (reporter.hasErrors) 1 else 0) + } + +} |