aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/Driver.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-06-15 17:11:19 +0200
committerMartin Odersky <odersky@gmail.com>2015-06-29 08:59:39 +0200
commit6beb1b402f84d4a3f3096a1fca2f71b69fb03c1a (patch)
treea6225111499a16a1c5981f049a14138eba18dcc9 /src/dotty/tools/dotc/Driver.scala
parentde8368d5db436bb126e2f327d58fa1882e427e51 (diff)
downloaddotty-6beb1b402f84d4a3f3096a1fca2f71b69fb03c1a.tar.gz
dotty-6beb1b402f84d4a3f3096a1fca2f71b69fb03c1a.tar.bz2
dotty-6beb1b402f84d4a3f3096a1fca2f71b69fb03c1a.zip
Refactor Driver
- Make parts more reusable - Introduce hook "sourcesRequired" that controls whether no sources on the command line give a help message.
Diffstat (limited to 'src/dotty/tools/dotc/Driver.scala')
-rw-r--r--src/dotty/tools/dotc/Driver.scala41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala
index f5e41cbef..7e9d4a5e4 100644
--- a/src/dotty/tools/dotc/Driver.scala
+++ b/src/dotty/tools/dotc/Driver.scala
@@ -8,33 +8,40 @@ import scala.util.control.NonFatal
abstract class Driver extends DotClass {
- val prompt = "\ndotc>"
+ val prompt = "\ndotc> "
protected def newCompiler(): Compiler
protected def emptyReporter: Reporter = new StoreReporter
- protected def doCompile(compiler: Compiler, fileNames: List[String], reporter: Option[Reporter] = None)
- (implicit ctx: Context): Reporter =
- if (fileNames.nonEmpty) {
- val run = compiler.newRun(ctx, reporter)
- run.compile(fileNames)
- run.printSummary()
- } else emptyReporter
+ protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
+ if (fileNames.nonEmpty)
+ try {
+ val run = compiler.newRun
+ run.compile(fileNames)
+ run.printSummary()
+ }
+ catch {
+ case ex: FatalError =>
+ ctx.error(ex.getMessage) // signals that we should fail compilation.
+ ctx.typerState.reporter
+ }
+ else emptyReporter
protected def initCtx = (new ContextBase).initialCtx
- def process(args: Array[String], rootCtx: Context, reporter: Option[Reporter] = None): Reporter = {
+ protected def sourcesRequired = true
+
+ def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
val summary = CompilerCommand.distill(args)(rootCtx)
implicit val ctx: Context = initCtx.fresh.setSettings(summary.sstate)
- val fileNames = CompilerCommand.checkUsage(summary)
- try {
- doCompile(newCompiler(), fileNames, reporter)
- } catch {
- case ex: FatalError =>
- ctx.error(ex.getMessage) // signals that we should fail compilation.
- ctx.typerState.reporter
- }
+ val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)
+ (fileNames, ctx)
+ }
+
+ def process(args: Array[String], rootCtx: Context): Reporter = {
+ val (fileNames, ctx) = setup(args, rootCtx)
+ doCompile(newCompiler(), fileNames)(ctx)
}
def main(args: Array[String]): Unit =