blob: dc1431acada35015ff08302eb0e969e52c4b3a77 (
plain) (
tree)
|
|
package dotty.tools.dotc
import config.CompilerCommand
import core.Contexts.{Context, ContextBase}
import util.DotClass
import reporting._
import scala.util.control.NonFatal
abstract class Driver extends DotClass {
val prompt = "\ndotc>"
protected def newCompiler(): Compiler
protected def emptyReporter: Reporter = new StoreReporter
protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
if (fileNames.nonEmpty) {
val run = compiler.newRun
run.compile(fileNames)
run.printSummary()
} else emptyReporter
protected def initCtx = (new ContextBase).initialCtx
def process(args: Array[String], rootCtx: Context): Reporter = {
val summary = CompilerCommand.distill(args)(rootCtx)
implicit val ctx: Context = initCtx.fresh.setSettings(summary.sstate)
val fileNames = CompilerCommand.checkUsage(summary)
try {
doCompile(newCompiler(), fileNames)
} catch {
case ex: FatalError =>
ctx.error(ex.getMessage) // signals that we should fail compilation.
ctx.typerState.reporter
}
}
def main(args: Array[String]): Unit =
sys.exit(if (process(args, initCtx).hasErrors) 1 else 0)
}
class FatalError(msg: String) extends Exception
|