diff options
-rwxr-xr-x | sources/scala/tools/nsc/Global.scala | 13 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/Main.scala | 6 | ||||
-rw-r--r-- | sources/scala/tools/nsc/MainInterpreter.scala | 6 | ||||
-rw-r--r-- | sources/scala/tools/nsc/MainTokenMetric.scala | 2 | ||||
-rw-r--r-- | sources/scala/tools/nsc/ant/NSC.scala | 12 | ||||
-rw-r--r-- | sources/scala/tools/nsc/reporters/AbstractReporter.scala | 45 | ||||
-rw-r--r-- | sources/scala/tools/nsc/reporters/ConsoleReporter.scala | 48 | ||||
-rw-r--r-- | sources/scala/tools/nsc/reporters/Reporter.scala | 42 | ||||
-rw-r--r-- | sources/scala/tools/nsc/reporters/StoreReporter.scala | 35 | ||||
-rw-r--r-- | sources/scala/tools/nsc/typechecker/TreeCheckers.scala | 14 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/typechecker/Typers.scala | 2 |
11 files changed, 139 insertions, 86 deletions
diff --git a/sources/scala/tools/nsc/Global.scala b/sources/scala/tools/nsc/Global.scala index e6d2747d4b..8be805b45b 100755 --- a/sources/scala/tools/nsc/Global.scala +++ b/sources/scala/tools/nsc/Global.scala @@ -274,6 +274,9 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable private var curRun: Run = NoRun; override def currentRun: Run = curRun; + class TyperRun extends Run { + override val terminalPhase : Phase = typerPhase.next; + } class Run extends CompilerRun { curRun = this; override val firstPhase = syntaxAnalyzer.newPhase(NoPhase); @@ -290,7 +293,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable } } - override val terminalPhase = new GlobalPhase(p) { + override val terminalPhase : Phase = new GlobalPhase(p) { def name = "terminal"; def apply(unit: CompilationUnit): unit = {} } @@ -325,15 +328,17 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable /** A map from compiled top-level symbols to their picklers */ val symData = new HashMap[Symbol, PickleBuffer]; + + def compileSources(sources: List[SourceFile]): unit = { val startTime = System.currentTimeMillis(); - reporter.resetCounters(); + reporter.reset; for (val source <- sources) addUnit(new CompilationUnit(source)); globalPhase = firstPhase; - while (globalPhase != terminalPhase && reporter.errors() == 0) { + while (globalPhase != terminalPhase && reporter.errors == 0) { val startTime = System.currentTimeMillis(); phase = globalPhase; globalPhase.run; @@ -353,7 +358,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable if (settings.Xshowobj.value != "") showDef(newTermName(settings.Xshowobj.value), true); if (settings.Xshowicode.value) writeICode(); - if (reporter.errors() == 0) { + if (reporter.errors == 0) { for (val Pair(sym, pickled) <- symData.elements.toList) { sym setPos Position.NOPOS; if (symData contains sym) { diff --git a/sources/scala/tools/nsc/Main.scala b/sources/scala/tools/nsc/Main.scala index 016590fd36..58b352db61 100755 --- a/sources/scala/tools/nsc/Main.scala +++ b/sources/scala/tools/nsc/Main.scala @@ -26,7 +26,7 @@ object Main extends Object with EvalLoop { reporter.error(new Position(PRODUCT), msg + "\n " + PRODUCT + " -help gives more information"); - def errors() = reporter.errors(); + def errors() = reporter.errors; def resident(compiler: Global): unit = { loop(line => { @@ -39,7 +39,7 @@ object Main extends Object with EvalLoop { def process(args: Array[String]): unit = { reporter = new ConsoleReporter(); val command = new CompilerCommand(List.fromArray(args), error, false); - reporter.prompt(command.settings.prompt.value); + reporter.prompt = command.settings.prompt.value; if (command.settings.version.value) reporter.info(null, versionMsg, true) else if (command.settings.help.value) @@ -65,7 +65,7 @@ object Main extends Object with EvalLoop { def main(args: Array[String]): unit = { process(args); - System.exit(if (reporter.errors() > 0) 1 else 0); + System.exit(if (reporter.errors > 0) 1 else 0); } } diff --git a/sources/scala/tools/nsc/MainInterpreter.scala b/sources/scala/tools/nsc/MainInterpreter.scala index af6e487f26..b1ea38e065 100644 --- a/sources/scala/tools/nsc/MainInterpreter.scala +++ b/sources/scala/tools/nsc/MainInterpreter.scala @@ -26,7 +26,7 @@ object MainInterpreter extends Object with EvalLoop { reporter.error(new Position(PRODUCT), msg + "\n " + PRODUCT + " -help gives more information"); - def errors() = reporter.errors(); + def errors() = reporter.errors; def interpret(gCompiler: Global): unit = { val interpreter = new Interpreter { @@ -46,7 +46,7 @@ object MainInterpreter extends Object with EvalLoop { def process(args: Array[String]): unit = { reporter = new ConsoleReporter(); val command = new CompilerCommand(List.fromArray(args), error, false); - reporter.prompt(command.settings.prompt.value); + reporter.prompt = (command.settings.prompt.value); if (command.settings.version.value) reporter.info(null, versionMsg, true) else if (command.settings.help.value) // 2do replace with InterpCommand @@ -68,7 +68,7 @@ object MainInterpreter extends Object with EvalLoop { def main(args: Array[String]): unit = { process(args); - System.exit(if (reporter.errors() > 0) 1 else 0); + System.exit(if (reporter.errors > 0) 1 else 0); } } diff --git a/sources/scala/tools/nsc/MainTokenMetric.scala b/sources/scala/tools/nsc/MainTokenMetric.scala index e4fe60b1ad..55a7759494 100644 --- a/sources/scala/tools/nsc/MainTokenMetric.scala +++ b/sources/scala/tools/nsc/MainTokenMetric.scala @@ -56,7 +56,7 @@ object MainTokenMetric { def main(args: Array[String]): unit = { process(args); - System.exit(if (reporter.errors() > 0) 1 else 0); + System.exit(if (reporter.errors > 0) 1 else 0); } } diff --git a/sources/scala/tools/nsc/ant/NSC.scala b/sources/scala/tools/nsc/ant/NSC.scala index 3502a01e37..f4e59a30f4 100644 --- a/sources/scala/tools/nsc/ant/NSC.scala +++ b/sources/scala/tools/nsc/ant/NSC.scala @@ -627,10 +627,10 @@ package scala.tools.nsc.ant { val compiler = new Global(settings, reporter); try { (new compiler.Run).compile(sourceFiles.map(f:File=>f.toString())); - if (reporter.errors() > 0) + if (reporter.errors > 0) error("Compile failed with " - + reporter.errors() + " error" - + (if (reporter.errors() > 1) "s" else "") + + reporter.errors + " error" + + (if (reporter.errors > 1) "s" else "") + "; see the compiler error output for details."); } catch { @@ -641,10 +641,10 @@ package scala.tools.nsc.ant { + msg + "); see the error output for details."); } } - if (reporter.warnings() > 0) + if (reporter.warnings > 0) log("Compile suceeded with " - + reporter.errors() + " warning" - + (if (reporter.warnings() > 1) "s" else "") + + reporter.errors + " warning" + + (if (reporter.warnings > 1) "s" else "") + "; see the compiler output for details."); reporter.printSummary() } diff --git a/sources/scala/tools/nsc/reporters/AbstractReporter.scala b/sources/scala/tools/nsc/reporters/AbstractReporter.scala index b85fde78ca..c2953e0a5c 100644 --- a/sources/scala/tools/nsc/reporters/AbstractReporter.scala +++ b/sources/scala/tools/nsc/reporters/AbstractReporter.scala @@ -7,37 +7,36 @@ // $Id$ package scala.tools.nsc.reporters; -import java.util.HashSet; +import scala.collection.mutable.HashSet; import scala.tools.nsc.util.Position; /** - * This abstract class implements most aspects of a Reporter, only how - * things are displayed has to be implemented in subclasses. + * This reporter implements filtering. */ abstract class AbstractReporter extends Reporter { - private val positions = new HashSet(); + private val positions = new HashSet[Position](); - def displayInfo (pos : Position, msg : String) : Unit; - def displayWarning(pos : Position, msg : String) : Unit; - def displayError (pos : Position, msg : String) : Unit; + def display(pos : Position, msg : String, severity : Severity) : Unit; + var prompt : Boolean = false; + var verbose : Boolean = false; + var nowarn : Boolean = false; def displayPrompt : Unit; // XXX: while is pos ignored? - def info(pos : Position, msg : String, force : Boolean) : Unit = - if (force || verbose) displayInfo(pos, msg); - - def warning(pos : Position, msg : String) : Unit = { - val hidden = testAndLog(pos); - if (nowarn) return; - if (!hidden || prompt) displayWarning(pos, msg); - if (!hidden) warningsx = warningsx + 1; - if (prompt) displayPrompt; - } - def error(pos : Position, msg : String) : Unit = { - val hidden = testAndLog(pos); - if (!hidden || prompt) displayError(pos, msg); - if (!hidden) errorsx = errorsx + 1; - if (prompt) displayPrompt; + protected def info0(pos : Position, msg : String, severity : Severity, force : Boolean) : Unit = severity match { + case INFO => if (force || verbose) display(pos, msg, severity); + case WARNING => { + val hidden = testAndLog(pos); + if (!nowarn) { + if (!hidden || prompt) display(pos, msg, severity); + if (prompt) displayPrompt; + } + } + case ERROR => { + val hidden = testAndLog(pos); + if (!hidden || prompt) display(pos, msg, severity); + if (prompt) displayPrompt; + } } //######################################################################## @@ -48,7 +47,7 @@ abstract class AbstractReporter extends Reporter { if (pos == null) return false; if (pos.column == 0) return false; if (positions.contains(pos)) return true; - positions.add(pos); + positions += (pos); return false; } diff --git a/sources/scala/tools/nsc/reporters/ConsoleReporter.scala b/sources/scala/tools/nsc/reporters/ConsoleReporter.scala index 181fde5b6e..e90af0f1e1 100644 --- a/sources/scala/tools/nsc/reporters/ConsoleReporter.scala +++ b/sources/scala/tools/nsc/reporters/ConsoleReporter.scala @@ -18,23 +18,25 @@ import java.io.PrintWriter; * This class implements a Reporter that displays messages on a text * console. */ -class ConsoleReporter(_reader : BufferedReader, _writer : PrintWriter) extends AbstractReporter { - - //######################################################################## - // Private Fields - - /** The reader to ask for failures on demand */ - private val reader = _reader; - /** The writer to print messages */ - private val writer = _writer; - - +class ConsoleReporter(reader : BufferedReader, writer : PrintWriter) extends AbstractReporter { //######################################################################## // Public Fields /** Whether a short file name should be displayed before errors */ var shortname : Boolean = false; + def label(severity : Severity): String = severity match { + case ERROR => "error"; + case WARNING => "warning"; + case INFO => null; + }; + def clabel(severity : Severity) = { + val label0 = label(severity); + if (label0 == null) ""; else label0 + ": "; + } + + + //######################################################################## // Public Constructors def this() = this( @@ -44,14 +46,11 @@ class ConsoleReporter(_reader : BufferedReader, _writer : PrintWriter) extends A //######################################################################## // Public Methods - Count - /** Returns the number of errors issued totally as a string */ - def getErrorCountString = getCountString(errorsx, "error"); - - /** Returns the number of warnings issued totally as a string */ - def getWarningCountString = getCountString(warningsx, "warning"); + /** Returns the number of errors issued totally as a string */ + def getCountString(severity : Severity) : Unit = getCountString0(count(severity), label(severity));; /** Returns a string meaning "n elements". */ - def getCountString(n : Int, elements : String) : String = + def getCountString0(n : Int, elements : String) : String = n match { case 0 => "no " + elements + "s"; case 1 => "one " + elements; @@ -82,8 +81,7 @@ class ConsoleReporter(_reader : BufferedReader, _writer : PrintWriter) extends A } else printMessage(msg); } - def printWarning(pos : Position, msg : String) = printMessage(pos, "warning: " + msg); - def printError (pos : Position, msg : String) = printMessage(pos, "error: " + msg); + def print(pos : Position, msg : String, severity : Severity) = printMessage(pos, clabel(severity) + msg); def printSourceLine(pos : Position) = if (pos != null && pos.offset != Position.NOPOS) { printMessage(pos.lineContent); @@ -103,16 +101,16 @@ class ConsoleReporter(_reader : BufferedReader, _writer : PrintWriter) extends A /** Prints the number of errors and warnings if their are non-zero. */ def printSummary() = { - if (warningsx > 0) printMessage(getWarningCountString + " found"); - if ( errorsx > 0) printMessage(getErrorCountString + " found"); + if (warnings > 0) printMessage(getCountString(WARNING) + " found"); + if ( errors > 0) printMessage(getCountString(ERROR ) + " found"); } //######################################################################## // Public Methods - Display - def displayInfo (pos : Position, msg : String) : Unit = printMessage(pos, msg); - def displayWarning(pos : Position, msg : String) : Unit = printWarning(pos, msg); - def displayError (pos : Position, msg : String) : Unit = printError (pos, msg); - + def display(pos : Position, msg : String, severity : Severity) : Unit = { + incr(severity); + print(pos, msg, severity); + }; def displayPrompt : Unit = try { var continue = true; while (continue) { diff --git a/sources/scala/tools/nsc/reporters/Reporter.scala b/sources/scala/tools/nsc/reporters/Reporter.scala index 3687ea3b66..950e1a2c6f 100644 --- a/sources/scala/tools/nsc/reporters/Reporter.scala +++ b/sources/scala/tools/nsc/reporters/Reporter.scala @@ -15,24 +15,32 @@ import scala.tools.nsc.util.Position; * error messages. */ abstract class Reporter { - var verbose : Boolean = false; - var nowarn : Boolean = false; - var prompt : Boolean = false; + abstract class Severity(val code : Int); + object INFO extends Severity(0); + object WARNING extends Severity(1); + object ERROR extends Severity(2); - def prompt(v : Boolean) : Unit = this.prompt = v; + def reset : Unit = { + errors = 0; + warnings = 0; - def warnings() = warningsx; - def errors() = errorsx; - - protected var warningsx : Int = 0; - protected var errorsx : Int = 0; - def resetCounters() : Unit = { - warningsx = 0; - errorsx = 0; } - - def info(pos : Position, msg : String, force : Boolean) : Unit; - def warning(pos : Position, msg : String ) : Unit; - def error(pos : Position, msg : String ) : Unit; - + 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; + + protected def info0(pos : Position, msg : String, severity : Severity, force : Boolean) : Unit; + + def info(pos : Position, msg : String, force : Boolean) : Unit = info0(pos, msg, INFO , force); + def warning(pos : Position, msg : String ) : Unit = info0(pos, msg, WARNING, false); + def error(pos : Position, msg : String ) : Unit = info0(pos, msg, ERROR, false); } diff --git a/sources/scala/tools/nsc/reporters/StoreReporter.scala b/sources/scala/tools/nsc/reporters/StoreReporter.scala new file mode 100644 index 0000000000..3011487e39 --- /dev/null +++ b/sources/scala/tools/nsc/reporters/StoreReporter.scala @@ -0,0 +1,35 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package scala.tools.nsc.reporters; +import scala.tools.nsc.util.Position; +import scala.collection.mutable.HashSet; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * This class implements a Reporter that displays messages on a text + * console. + */ +class StoreReporter extends Reporter { + + class Info(val pos: Position, val msg: String, val severity: Severity); + + val infos = new HashSet[Info]; + + protected def info0(pos : Position, msg : String, severity : Severity, force : Boolean) : Unit = if (!force) { + infos += new Info(pos, msg, severity); + incr(severity); + } + override def reset = { + infos.clear; + } +} diff --git a/sources/scala/tools/nsc/typechecker/TreeCheckers.scala b/sources/scala/tools/nsc/typechecker/TreeCheckers.scala index cc5d7aa62e..b494e1c33f 100644 --- a/sources/scala/tools/nsc/typechecker/TreeCheckers.scala +++ b/sources/scala/tools/nsc/typechecker/TreeCheckers.scala @@ -6,6 +6,7 @@ package scala.tools.nsc.typechecker; import scala.tools.nsc.util.Position; +import scala.tools.nsc.reporters.AbstractReporter; import symtab.Flags._; abstract class TreeCheckers extends Analyzer { @@ -20,8 +21,14 @@ abstract class TreeCheckers extends Analyzer { } def check(unit: CompilationUnit): unit = { - val curPrompt = reporter.prompt; - reporter.prompt(true); + val areporter = if (reporter.isInstanceOf[AbstractReporter]) reporter.asInstanceOf[AbstractReporter] else null; + + val curPrompt = if (areporter != null) { + val ret = areporter.prompt; + areporter.prompt = true; + ret; + } else false; + val context = startContext.make(unit); context.checking = true; tpeOfTree.clear; @@ -29,7 +36,8 @@ abstract class TreeCheckers extends Analyzer { checker.precheck.traverse(unit.body); checker.typed(unit.body); checker.postcheck.traverse(unit.body); - reporter.prompt(curPrompt); + if (areporter != null) + areporter.prompt = curPrompt; } override def newTyper(context: Context): Typer = new TreeChecker(context); diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala index ae3947299e..9f4532a762 100755 --- a/sources/scala/tools/nsc/typechecker/Typers.scala +++ b/sources/scala/tools/nsc/typechecker/Typers.scala @@ -686,7 +686,7 @@ import collection.mutable.HashMap; case _ => typedSuperCall(ddef.rhs) } - if (meth.isPrimaryConstructor && !phase.erasedTypes && reporter.errors() == 0) + if (meth.isPrimaryConstructor && !phase.erasedTypes && reporter.errors == 0) computeParamAliases(meth.owner, vparamss1, result); result } else transformedOrTyped(ddef.rhs, tpt1.tpe); |