aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/Driver.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-08-12 16:24:43 +0200
committerMartin Odersky <odersky@gmail.com>2013-08-12 16:24:43 +0200
commit34317c162e9d79729e57d22bb167f420e948da8f (patch)
tree6a3ff884020f14e7507f45de9d88240cf687ea2d /src/dotty/tools/dotc/Driver.scala
parent775b2a1857290f5e83036148dbbfcdc3a29a12d2 (diff)
downloaddotty-34317c162e9d79729e57d22bb167f420e948da8f.tar.gz
dotty-34317c162e9d79729e57d22bb167f420e948da8f.tar.bz2
dotty-34317c162e9d79729e57d22bb167f420e948da8f.zip
Added main runner and driver.
Left dummies for Compiler and Run.
Diffstat (limited to 'src/dotty/tools/dotc/Driver.scala')
-rw-r--r--src/dotty/tools/dotc/Driver.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala
new file mode 100644
index 000000000..a175b8bc4
--- /dev/null
+++ b/src/dotty/tools/dotc/Driver.scala
@@ -0,0 +1,44 @@
+package dotty.tools.dotc
+
+import config.CompilerCommand
+import core.Contexts.{Context, ContextBase}
+import core.DotClass
+
+abstract class Driver extends DotClass {
+
+ val prompt = "\ndotc>"
+
+ protected def newCompiler(): Compiler
+
+ protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context) =
+ if (fileNames.nonEmpty) {
+ val run = compiler.newRun
+ run.compile(fileNames)
+ ctx.reporter.printSummary
+ }
+
+ protected def initCtx = (new ContextBase).initialCtx
+
+ def process(args: Array[String]): Boolean = {
+ val summary = CompilerCommand.distill(args)(initCtx)
+ implicit val ctx = initCtx.fresh.withSettings(summary.sstate)
+ val fileNames = CompilerCommand.checkUsage(summary)
+ try {
+ doCompile(newCompiler(), fileNames)
+ !ctx.reporter.hasErrors
+ } catch {
+ case ex: Throwable =>
+ ctx.error(ex.getMessage)
+ ex match {
+ case ex: FatalError => false // signals that we should fail compilation.
+ case _ => throw ex // unexpected error, tell the outside world.
+ }
+ }
+ }
+
+ def main(args: Array[String]): Unit =
+ sys.exit(if (process(args)) 1 else 0)
+}
+
+class FatalError(msg: String) extends Exception
+