summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala6
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala11
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Global.scala5
-rw-r--r--src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala8
-rw-r--r--src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala9
-rw-r--r--src/compiler/scala/tools/nsc/reporters/Reporter.scala115
-rw-r--r--src/compiler/scala/tools/nsc/reporters/StoreReporter.scala12
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala5
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala6
-rw-r--r--src/compiler/scala/tools/util/StringOps.scala35
10 files changed, 92 insertions, 120 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index c98562f1f0..0f5be1791b 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -338,7 +338,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
currentRun.currentUnit = unit
if (!cancelled(unit)) {
currentRun.informUnitStarting(this, unit)
- reporter.withSource(unit.source) { apply(unit) }
+ apply(unit)
}
currentRun.advanceUnit
} finally {
@@ -1066,9 +1066,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
def loop(ph: Phase) {
if (stop(ph)) refreshProgress
else {
- reporter.withSource(unit.source) {
- atPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit)
- }
+ atPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit)
loop(ph.next match {
case `ph` => null // ph == ph.next implies terminal, and null ends processing
case x => x
diff --git a/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala b/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
index 88b998f1ac..b5ec0ceffb 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
@@ -21,12 +21,15 @@ abstract class SyntaxAnalyzer extends SubComponent with Parsers with MarkupParse
override val keepsTypeParams = false
def apply(unit: global.CompilationUnit) {
- global.informProgress("parsing " + unit)
+ import global._
+ informProgress("parsing " + unit)
unit.body =
if (unit.source.file.name.endsWith(".java")) new JavaUnitParser(unit).parse()
- else if (!global.reporter.incompleteHandled) new UnitParser(unit).smartParse()
- else new UnitParser(unit).parse()
- if (global.settings.Yrangepos.value && !global.reporter.hasErrors) global.validatePositions(unit.body)
+ else if (reporter.incompleteHandled) new UnitParser(unit).parse()
+ else new UnitParser(unit).smartParse()
+
+ if (settings.Yrangepos.value && !reporter.hasErrors)
+ validatePositions(unit.body)
}
}
}
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index 694df32e32..af5b9a9882 100644
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -942,10 +942,7 @@ class Global(settings: Settings, reporter: Reporter, projectName: String = "")
* @return true iff typechecked correctly
*/
private def applyPhase(phase: Phase, unit: CompilationUnit) {
- val oldSource = reporter.getSource
- reporter.withSource(unit.source) {
- atPhase(phase) { phase.asInstanceOf[GlobalPhase] applyPhase unit }
- }
+ atPhase(phase) { phase.asInstanceOf[GlobalPhase] applyPhase unit }
}
}
diff --git a/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala b/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
index 7d2c0fe424..49d23b1ab3 100644
--- a/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
@@ -14,6 +14,10 @@ import scala.tools.nsc.util.Position
* This reporter implements filtering.
*/
abstract class AbstractReporter extends Reporter {
+ val settings: Settings
+ def display(pos: Position, msg: String, severity: Severity): Unit
+ def displayPrompt(): Unit
+
private val positions = new HashMap[Position, Severity]
override def reset() {
@@ -21,14 +25,10 @@ abstract class AbstractReporter extends Reporter {
positions.clear
}
- val settings: Settings
private def isVerbose = settings.verbose.value
private def noWarnings = settings.nowarnings.value
private def isPromptSet = settings.prompt.value
- def display(pos: Position, msg: String, severity: Severity): Unit
- def displayPrompt(): Unit
-
protected def info0(pos: Position, msg: String, _severity: Severity, force: Boolean) {
val severity =
if (settings.Xwarnfatal.value && _severity == WARNING) ERROR
diff --git a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
index 75c25afa5b..a6e661c4b4 100644
--- a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
@@ -6,14 +6,17 @@
package scala.tools.nsc
package reporters
-import java.io.{BufferedReader, InputStreamReader, IOException, PrintWriter}
+import java.io.{ BufferedReader, IOException, PrintWriter }
import util._
+import scala.tools.util.StringOps.countElementsAsString
/**
* This class implements a Reporter that displays messages on a text
* console.
*/
class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: PrintWriter) extends AbstractReporter {
+ def this(settings: Settings) = this(settings, Console.in, new PrintWriter(Console.err, true))
+
/** Whether a short file name should be displayed before errors */
var shortname: Boolean = false
@@ -31,9 +34,6 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr
if (label0 eq null) "" else label0 + ": "
}
- def this(settings: Settings) =
- this(settings, Console.in, new PrintWriter(Console.err, true))
-
/** Returns the number of errors issued totally as a string.
*
* @param severity ...
@@ -43,7 +43,6 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr
countElementsAsString((severity).count, label(severity))
/** Prints the message. */
- //def printMessage(msg: String) { writer.println(msg) } // platform-dependent!
def printMessage(msg: String) { writer.print(msg + "\n"); writer.flush() }
/** Prints the message with the given position indication. */
diff --git a/src/compiler/scala/tools/nsc/reporters/Reporter.scala b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
index e253a8f5f0..063181b061 100644
--- a/src/compiler/scala/tools/nsc/reporters/Reporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
@@ -7,48 +7,22 @@ package scala.tools.nsc
package reporters
import scala.tools.nsc.util._
+import scala.tools.util.StringOps._
/**
* This interface provides methods to issue information, warning and
* error messages.
*/
abstract class Reporter {
+ protected def info0(pos: Position, msg: String, severity: Severity, force: Boolean): Unit
+
object severity extends Enumeration
class Severity(val id: Int) extends severity.Value {
var count: Int = 0
}
- val INFO = new Severity(0)
+ val INFO = new Severity(0)
val WARNING = new Severity(1)
- val ERROR = new Severity(2)
-
- def reset() {
- INFO.count = 0
- ERROR.count = 0
- WARNING.count = 0
- cancelled = false
- }
-
- var cancelled: Boolean = false
- def hasErrors: Boolean = ERROR.count > 0 || cancelled
- def hasWarnings: Boolean = WARNING.count > 0
-
- /** Flush all output */
- def flush() { }
-
- protected def info0(pos: Position, msg: String, severity: Severity, force: Boolean): Unit
-
- private var source: SourceFile = _
- def setSource(source: SourceFile) { this.source = source }
- def getSource: SourceFile = source
- def withSource[A](src: SourceFile)(op: => A) = {
- val oldSource = source
- try {
- source = src
- op
- } finally {
- source = oldSource
- }
- }
+ val ERROR = new Severity(2)
/** Whether very long lines can be truncated. This exists so important
* debugging information (like printing the classpath) is not rendered
@@ -63,64 +37,33 @@ abstract class Reporter {
finally _truncationOK = saved
}
+ private var incompleteHandler: (Position, String) => Unit = null
+ def incompleteHandled = incompleteHandler != null
+ def withIncompleteHandler[T](handler: (Position, String) => Unit)(thunk: => T) = {
+ val saved = incompleteHandler
+ incompleteHandler = handler
+ try thunk
+ finally incompleteHandler = saved
+ }
+
+ var cancelled = false
+ def hasErrors = ERROR.count > 0 || cancelled
+ def hasWarnings = WARNING.count > 0
+
def info(pos: Position, msg: String, force: Boolean) { info0(pos, msg, INFO, force) }
def warning(pos: Position, msg: String ) { info0(pos, msg, WARNING, false) }
def error(pos: Position, msg: String ) { info0(pos, msg, ERROR, false) }
-
- def comment(pos: Position, msg: String) {}
-
- /** An error that could possibly be fixed if the unit were longer.
- * This is used only when the interpreter tries
- * to distinguish fatal errors from those that are due to
- * needing more lines of input from the user.
- *
- * Should be re-factored into a subclass.
- */
- var incompleteInputError: (Position, String) => Unit = error
- var incompleteHandled: Boolean = false
-
- def withIncompleteHandler[T](handler: (Position, String) => Unit)(thunk: => T) = {
- val savedHandler = incompleteInputError
- val savedHandled = incompleteHandled
- try {
- incompleteInputError = handler
- incompleteHandled = true
- thunk
- } finally {
- incompleteInputError = savedHandler
- incompleteHandled = savedHandled
- }
+ def incompleteInputError(pos: Position, msg: String ) {
+ if (incompleteHandled) incompleteHandler(pos, msg)
+ else error(pos, msg)
}
- // @M: moved here from ConsoleReporter and made public -- also useful in e.g. Typers
- /** Returns a string meaning "n elements".
- *
- * @param n ...
- * @param elements ...
- * @return ...
- */
- def countElementsAsString(n: Int, elements: String): String =
- n match {
- case 0 => "no " + elements + "s"
- case 1 => "one " + elements
- case 2 => "two " + elements + "s"
- case 3 => "three " + elements + "s"
- case 4 => "four " + elements + "s"
- case _ => "" + n + " " + elements + "s"
- }
-
- /** Turns a count into a friendly English description if n<=4.
- *
- * @param n ...
- * @return ...
- */
- def countAsString(n: Int): String =
- n match {
- case 0 => "none"
- case 1 => "one"
- case 2 => "two"
- case 3 => "three"
- case 4 => "four"
- case _ => "" + n
- }
+ def comment(pos: Position, msg: String) { }
+ def flush() { }
+ def reset() {
+ INFO.count = 0
+ ERROR.count = 0
+ WARNING.count = 0
+ cancelled = false
+ }
}
diff --git a/src/compiler/scala/tools/nsc/reporters/StoreReporter.scala b/src/compiler/scala/tools/nsc/reporters/StoreReporter.scala
index 9f0e55c422..48601c325a 100644
--- a/src/compiler/scala/tools/nsc/reporters/StoreReporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/StoreReporter.scala
@@ -6,10 +6,8 @@
package scala.tools.nsc
package reporters
-import java.io.{BufferedReader, InputStreamReader, IOException, PrintWriter}
-
-import scala.collection.mutable.HashSet
-import scala.tools.nsc.util.{Position, SourceFile}
+import scala.collection.mutable
+import scala.tools.nsc.util.Position
/**
* This class implements a Reporter that displays messages on a text
@@ -19,7 +17,7 @@ class StoreReporter extends Reporter {
class Info(val pos: Position, val msg: String, val severity: Severity) {
override def toString() = "pos: " + pos + " " + msg + " " + severity
}
- val infos = new HashSet[Info]
+ val infos = new mutable.HashSet[Info]
protected def info0(pos: Position, msg: String, severity: Severity, force: Boolean) {
if (!force) {
infos += new Info(pos, msg, severity)
@@ -28,7 +26,7 @@ class StoreReporter extends Reporter {
}
override def reset() {
- super.reset
- infos.clear
+ super.reset()
+ infos.clear()
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 6c27bcace6..88cecbd402 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -9,6 +9,7 @@ package typechecker
import scala.collection.{ mutable, immutable }
import scala.collection.mutable.ListBuffer
import scala.util.control.ControlThrowable
+import scala.tools.util.StringOps.{ countAsString, countElementsAsString }
import symtab.Flags._
/** This trait ...
@@ -1055,8 +1056,8 @@ trait Infer {
errors foreach {case (targ, tparam, arityMismatches, varianceMismatches, stricterBounds) => errorMessages +=
(targ+"'s type parameters do not match "+tparam+"'s expected parameters: "+
(for ((a, p) <- arityMismatches)
- yield a+qualify(a,p)+ " has "+reporter.countElementsAsString(a.typeParams.length, "type parameter")+", but "+
- p+qualify(p,a)+" has "+reporter.countAsString(p.typeParams.length)).toList.mkString(", ") +
+ yield a+qualify(a,p)+ " has "+countElementsAsString(a.typeParams.length, "type parameter")+", but "+
+ p+qualify(p,a)+" has "+countAsString(p.typeParams.length)).toList.mkString(", ") +
(for ((a, p) <- varianceMismatches)
yield a+qualify(a,p)+ " is "+varStr(a)+", but "+
p+qualify(p,a)+" is declared "+varStr(p)).toList.mkString(", ") +
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 59cb6c4081..c43fa377a4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -16,9 +16,9 @@ import scala.collection.{ mutable, immutable }
import scala.tools.nsc.util.BatchSourceFile
import mutable.ListBuffer
import symtab.Flags._
-
import util.Statistics
import util.Statistics._
+import scala.tools.util.StringOps.{ countAsString, countElementsAsString }
// Suggestion check whether we can do without priming scopes with symbols of outer scopes,
// like the IDE does.
@@ -825,8 +825,8 @@ trait Typers extends Modes {
// Note that we treat Any and Nothing as kind-polymorphic.
// We can't perform this check when typing type arguments to an overloaded method before the overload is resolved
// (or in the case of an error type) -- this is indicated by pt == WildcardType (see case TypeApply in typed1).
- errorTree(tree, tree.tpe+" takes "+reporter.countElementsAsString(tree.tpe.typeParams.length, "type parameter")+
- ", expected: "+reporter.countAsString(pt.typeParams.length))
+ errorTree(tree, tree.tpe+" takes "+countElementsAsString(tree.tpe.typeParams.length, "type parameter")+
+ ", expected: "+countAsString(pt.typeParams.length))
tree setType tree.tpe
} else tree match { // (6)
case TypeTree() => tree
diff --git a/src/compiler/scala/tools/util/StringOps.scala b/src/compiler/scala/tools/util/StringOps.scala
index 63cfc06702..65ff582011 100644
--- a/src/compiler/scala/tools/util/StringOps.scala
+++ b/src/compiler/scala/tools/util/StringOps.scala
@@ -16,7 +16,7 @@ package util
* @author Martin Odersky
* @version 1.0
*/
-object StringOps {
+trait StringOps {
def onull(s: String) = if (s == null) "" else s
def oempty(xs: String*) = xs filterNot (x => x == null || x == "")
def ojoin(xs: Seq[String], sep: String) = oempty(xs: _*) mkString sep
@@ -53,4 +53,37 @@ object StringOps {
def splitAt(str: String, idx: Int, doDropIndex: Boolean = false): Option[(String, String)] =
if (idx == -1) None
else Some(str take idx, str drop (if (doDropIndex) idx + 1 else idx))
+
+ /** Returns a string meaning "n elements".
+ *
+ * @param n ...
+ * @param elements ...
+ * @return ...
+ */
+ def countElementsAsString(n: Int, elements: String): String =
+ n match {
+ case 0 => "no " + elements + "s"
+ case 1 => "one " + elements
+ case 2 => "two " + elements + "s"
+ case 3 => "three " + elements + "s"
+ case 4 => "four " + elements + "s"
+ case _ => "" + n + " " + elements + "s"
+ }
+
+ /** Turns a count into a friendly English description if n<=4.
+ *
+ * @param n ...
+ * @return ...
+ */
+ def countAsString(n: Int): String =
+ n match {
+ case 0 => "none"
+ case 1 => "one"
+ case 2 => "two"
+ case 3 => "three"
+ case 4 => "four"
+ case _ => "" + n
+ }
}
+
+object StringOps extends StringOps { }