summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2006-11-30 14:20:55 +0000
committerMartin Odersky <odersky@gmail.com>2006-11-30 14:20:55 +0000
commita42ba536683c1714fb14faa82fa942d80a43580c (patch)
treee7d85bc0ff477f4b29a45dcbce100954857dc586 /src/compiler/scala/tools
parent959f3bc8f8013351823bc3e6061c1b134a30b73e (diff)
downloadscala-a42ba536683c1714fb14faa82fa942d80a43580c.tar.gz
scala-a42ba536683c1714fb14faa82fa942d80a43580c.tar.bz2
scala-a42ba536683c1714fb14faa82fa942d80a43580c.zip
added cancel capability to nsc
Diffstat (limited to 'src/compiler/scala/tools')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala36
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala8
-rw-r--r--src/compiler/scala/tools/nsc/Main.scala20
-rw-r--r--src/compiler/scala/tools/nsc/MainTokenMetric.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ScriptRunner.scala2
-rw-r--r--src/compiler/scala/tools/nsc/reporters/Reporter.scala10
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala4
7 files changed, 34 insertions, 48 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index eebbf739ed..6466a02d8d 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -206,7 +206,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
abstract class GlobalPhase(prev: Phase) extends Phase(prev) {
phaseWithId(id) = this
- def run: unit = currentRun.units foreach applyPhase
+ def run { currentRun.units foreach applyPhase }
def apply(unit: CompilationUnit): unit
private val isErased = prev.name == "erasure" || prev.erasedTypes
@@ -217,7 +217,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
if (settings.debug.value) inform("[running phase " + name + " on " + unit + "]")
val unit0 = currentRun.currentUnit
currentRun.currentUnit = unit
- apply(unit)
+ if (!reporter.cancelled) apply(unit)
currentRun.advanceUnit
assert(currentRun.currentUnit == unit)
currentRun.currentUnit = unit0
@@ -393,13 +393,12 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
var uncheckedWarnings: boolean = false
private var p: Phase = firstPhase
- private var stopped = false
- for (val pd <- phaseDescriptors) {
- if (!stopped) {
- if (!(settings.skip contains pd.phaseName)) p = pd.newPhase(p)
- stopped = settings.stop contains pd.phaseName
- }
- }
+
+ for (val pd <- phaseDescriptors.takeWhile(pd => !(settings.stop contains pd.phaseName)))
+ if (!(settings.skip contains pd.phaseName)) p = pd.newPhase(p)
+
+ def cancel { reporter.cancelled = true }
+
// progress tracking
def progress(current: Int, total: Int): Unit = {}
@@ -469,7 +468,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
addUnit(new CompilationUnit(source))
globalPhase = firstPhase
- while (globalPhase != terminalPhase && reporter.errors == 0) {
+ while (globalPhase != terminalPhase && !reporter.hasErrors) {
val startTime = currentTime
phase = globalPhase
globalPhase.run
@@ -493,19 +492,19 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
if (settings.Xshowobj.value != "")
showDef(newTermName(settings.Xshowobj.value), true)
- if (reporter.errors == 0) {
- assert(stopped || symData.isEmpty, symData.elements.toList)
+ if (reporter.hasErrors) {
+ for (val Pair(sym, file) <- symSource.elements) {
+ sym.reset(new loaders.SourcefileLoader(file))
+ if (sym.isTerm) sym.moduleClass.reset(loaders.moduleClassLoader)
+ }
+ } else {
+ assert(symData.isEmpty || !settings.stop.value.isEmpty || !settings.skip.value.isEmpty)
if (deprecationWarnings) {
warning("there were deprecation warnings; re-run with -deprecation for details")
}
if (uncheckedWarnings) {
warning("there were unchecked warnings; re-run with -unchecked for details")
}
- } else {
- for (val Pair(sym, file) <- symSource.elements) {
- sym.reset(new loaders.SourcefileLoader(file))
- if (sym.isTerm) sym.moduleClass.reset(loaders.moduleClassLoader)
- }
}
for (val Pair(sym, file) <- symSource.elements) resetPackageClass(sym.owner)
//units foreach (.clear())
@@ -523,8 +522,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
val unit = new CompilationUnit(getSourceFile(file))
addUnit(unit)
var localPhase = firstPhase.asInstanceOf[GlobalPhase]
- while ((localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id) &&
- reporter.errors == 0) {
+ while ((localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id) && !reporter.hasErrors) {
atPhase(localPhase)(localPhase.applyPhase(unit))
localPhase = localPhase.next.asInstanceOf[GlobalPhase]
}
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 624a9cc986..aeb23ef8a5 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -179,7 +179,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
// parse the main code along with the imports
reporter.reset
val trees = simpleParse(codeForImports + line)
- if (reporter.errors > 0)
+ if (reporter.hasErrors)
Nil // the result did not parse, so stop
else {
// parse the imports alone
@@ -215,7 +215,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
val cr = new compiler.Run
reporter.reset
cr.compileSources(sources)
- reporter.errors == 0
+ !reporter.hasErrors
}
/** Compile a string. Returns true if there are no
@@ -503,7 +503,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
objRun.compileSources(
List(new SourceFile("<console>", objectSourceCode.toCharArray))
)
- if (reporter.errors > 0) return false
+ if (reporter.hasErrors) return false
// extract and remember types
typeOf = findTypes(objRun)
@@ -514,7 +514,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
)
// success
- reporter.errors == 0
+ !reporter.hasErrors
}
/** Dig the types of all bound variables out of the compiler run.
diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala
index 712fb38704..eb0f61def0 100644
--- a/src/compiler/scala/tools/nsc/Main.scala
+++ b/src/compiler/scala/tools/nsc/Main.scala
@@ -28,6 +28,7 @@ object Main extends AnyRef with EvalLoop {
reporter.error(/*new Position */FakePos(PRODUCT),
msg + "\n " + PRODUCT + " -help gives more information")
+ /* needed ?? */
def errors() = reporter.errors
def resident(compiler: Global): unit =
@@ -37,19 +38,6 @@ object Main extends AnyRef with EvalLoop {
(new compiler.Run) compile command.files
}
-/*
- def forever(compiler: Global): unit = {
- var cnt = 0
- while (true) {
- Console.println("Iteration: "+cnt)
- cnt = cnt + 1
- val args = List("Global.scala")
- val command = new CompilerCommand(args, error, true)
- (new compiler.Run) compile command.files
- }
- }
-*/
-
def process(args: Array[String]): unit = {
reporter = new ConsoleReporter();
val command = new CompilerCommand(List.fromArray(args), error, false);
@@ -61,10 +49,6 @@ object Main extends AnyRef with EvalLoop {
else {
try {
object compiler extends Global(command.settings, reporter);
-/*
- if (command.settings.Xgenerics.value)
- forever(compiler)
-*/
if (command.settings.resident.value)
resident(compiler)
else if (command.files.isEmpty)
@@ -94,7 +78,7 @@ object Main extends AnyRef with EvalLoop {
def main(args: Array[String]): unit = {
process(args)
- exit(if (reporter.errors > 0) 1 else 0)
+ exit(if (reporter.hasErrors) 1 else 0)
}
}
diff --git a/src/compiler/scala/tools/nsc/MainTokenMetric.scala b/src/compiler/scala/tools/nsc/MainTokenMetric.scala
index 8eaf3243f6..f0eb7ad71b 100644
--- a/src/compiler/scala/tools/nsc/MainTokenMetric.scala
+++ b/src/compiler/scala/tools/nsc/MainTokenMetric.scala
@@ -56,7 +56,7 @@ object MainTokenMetric {
def main(args: Array[String]): unit = {
process(args)
- exit(if (reporter.errors > 0) 1 else 0)
+ exit(if (reporter.hasErrors) 1 else 0)
}
}
diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala
index 5e509959c2..50203f4491 100644
--- a/src/compiler/scala/tools/nsc/ScriptRunner.scala
+++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala
@@ -239,7 +239,7 @@ object ScriptRunner {
val compiler = new Global(settings, reporter)
val cr = new compiler.Run
cr.compileSources(List(wrappedScript(scriptFile, &compiler.getSourceFile)))
- Pair(compiledPath, reporter.errors == 0)
+ Pair(compiledPath, !reporter.hasErrors)
} else {
val compok = compileWithDaemon(settings, scriptFile)
Pair(compiledPath, compok)
diff --git a/src/compiler/scala/tools/nsc/reporters/Reporter.scala b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
index 950e1a2c6f..b75a75f565 100644
--- a/src/compiler/scala/tools/nsc/reporters/Reporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
@@ -23,20 +23,24 @@ abstract class Reporter {
def reset : Unit = {
errors = 0;
warnings = 0;
-
+ cancelled = false
}
def count(severity : Severity): Int = severity match {
case ERROR => errors;
case WARNING => warnings;
case INFO => 0;
- };
+ }
def incr(severity : Severity): Unit = severity match {
case ERROR => errors = errors + 1;
case WARNING => warnings = warnings + 1;;
case INFO => {}
- };
+ }
+
var errors : Int = 0;
var warnings : Int = 0;
+ var cancelled: boolean = false
+
+ def hasErrors: boolean = errors != 0 || cancelled
protected def info0(pos : Position, msg : String, severity : Severity, force : Boolean) : Unit;
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 6b126feb10..1ad34fce8b 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -905,7 +905,7 @@ trait Typers requires Analyzer {
enterSyms(context.outer.make(templ, clazz, clazz.info.decls), templ.body)
validateParentClasses(parents1, selfType)
val body =
- if (phase.id <= currentRun.typerPhase.id && reporter.errors == 0)
+ if (phase.id <= currentRun.typerPhase.id && !reporter.hasErrors)
templ.body flatMap addGetterSetter
else templ.body
val body1 = typedStats(body, templ.symbol)
@@ -1053,7 +1053,7 @@ trait Typers requires Analyzer {
case _ =>
typedSuperCall(ddef.rhs, UnitClass.tpe)
}
- if (meth.isPrimaryConstructor && phase.id <= currentRun.typerPhase.id && reporter.errors == 0)
+ if (meth.isPrimaryConstructor && phase.id <= currentRun.typerPhase.id && !reporter.hasErrors)
computeParamAliases(meth.owner, vparamss1, result)
result
} else transformedOrTyped(ddef.rhs, tpt1.tpe)