diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/reflect/internal/FrontEnds.scala | 75 | ||||
-rw-r--r-- | src/compiler/scala/reflect/internal/Reporters.scala | 74 | ||||
-rw-r--r-- | src/compiler/scala/reflect/internal/SymbolTable.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/reflect/makro/runtime/Context.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/reflect/makro/runtime/FrontEnds.scala (renamed from src/compiler/scala/reflect/makro/runtime/Reporters.scala) | 12 | ||||
-rw-r--r-- | src/compiler/scala/reflect/runtime/ToolBoxes.scala | 38 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 32 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ToolBoxes.scala | 8 | ||||
-rwxr-xr-x | src/compiler/scala/tools/nsc/ast/DocComments.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/IMain.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/SymbolTable.scala | 3 |
11 files changed, 122 insertions, 133 deletions
diff --git a/src/compiler/scala/reflect/internal/FrontEnds.scala b/src/compiler/scala/reflect/internal/FrontEnds.scala new file mode 100644 index 0000000000..74501c7686 --- /dev/null +++ b/src/compiler/scala/reflect/internal/FrontEnds.scala @@ -0,0 +1,75 @@ +package scala.reflect +package internal + +trait FrontEnds { self: SymbolTable => + + import scala.tools.nsc.reporters._ + import scala.tools.nsc.Settings + + def mkConsoleFrontEnd(minSeverity: Int = 1): FrontEnd = { + val settings = new Settings() + if (minSeverity <= 0) settings.verbose.value = true + if (minSeverity > 1) settings.nowarn.value = true + wrapReporter(new ConsoleReporter(settings)) + } + + abstract class FrontEndToReporterProxy(val frontEnd: FrontEnd) extends AbstractReporter { + import frontEnd.{Severity => ApiSeverity} + val API_INFO = frontEnd.INFO + val API_WARNING = frontEnd.WARNING + val API_ERROR = frontEnd.ERROR + + type NscSeverity = Severity + val NSC_INFO = INFO + val NSC_WARNING = WARNING + val NSC_ERROR = ERROR + + def display(pos: Position, msg: String, nscSeverity: NscSeverity): Unit = + frontEnd.log(pos, msg, nscSeverity match { + case NSC_INFO => API_INFO + case NSC_WARNING => API_WARNING + case NSC_ERROR => API_ERROR + }) + + def displayPrompt(): Unit = + frontEnd.interactive() + } + + def wrapFrontEnd(frontEnd: FrontEnd): Reporter = new FrontEndToReporterProxy(frontEnd) { + val settings = new Settings() + settings.verbose.value = true + settings.nowarn.value = false + } + + class ReporterToFrontEndProxy(val reporter: Reporter) extends FrontEnd { + val API_INFO = INFO + val API_WARNING = WARNING + val API_ERROR = ERROR + + override def hasErrors = reporter.hasErrors + override def hasWarnings = reporter.hasWarnings + + def display(info: Info): Unit = info.severity match { + case API_INFO => reporter.info(info.pos, info.msg, false) + case API_WARNING => reporter.warning(info.pos, info.msg) + case API_ERROR => reporter.error(info.pos, info.msg) + } + + def interactive(): Unit = reporter match { + case reporter: AbstractReporter => reporter.displayPrompt() + case _ => // do nothing + } + + override def flush(): Unit = { + super.flush() + reporter.flush() + } + + override def reset(): Unit = { + super.reset() + reporter.reset() + } + } + + def wrapReporter(reporter: Reporter): FrontEnd = new ReporterToFrontEndProxy(reporter) +} diff --git a/src/compiler/scala/reflect/internal/Reporters.scala b/src/compiler/scala/reflect/internal/Reporters.scala deleted file mode 100644 index 20d4a1d026..0000000000 --- a/src/compiler/scala/reflect/internal/Reporters.scala +++ /dev/null @@ -1,74 +0,0 @@ -package scala.reflect -package internal - -trait Reporters { self: SymbolTable => - - import self.{Reporter => ApiReporter} - import scala.tools.nsc.reporters._ - import scala.tools.nsc.reporters.{Reporter => NscReporter} - import scala.tools.nsc.Settings - - def mkConsoleReporter(minSeverity: Int = 1): ApiReporter = { - val settings = new Settings() - if (minSeverity <= 0) settings.verbose.value = true - if (minSeverity > 1) settings.nowarn.value = true - wrapNscReporter(new ConsoleReporter(settings)) - } - - abstract class ApiToNscReporterProxy(val apiReporter: ApiReporter) extends AbstractReporter { - import apiReporter.{Severity => ApiSeverity} - val API_INFO = apiReporter.INFO - val API_WARNING = apiReporter.WARNING - val API_ERROR = apiReporter.ERROR - - type NscSeverity = Severity - val NSC_INFO = INFO - val NSC_WARNING = WARNING - val NSC_ERROR = ERROR - - def display(pos: Position, msg: String, nscSeverity: NscSeverity): Unit = - apiReporter.log(pos, msg, nscSeverity match { - case NSC_INFO => API_INFO - case NSC_WARNING => API_WARNING - case NSC_ERROR => API_ERROR - }) - - def displayPrompt(): Unit = - apiReporter.interactive() - } - - def wrapApiReporter(apiReporter: ApiReporter): NscReporter = new ApiToNscReporterProxy(apiReporter) { - val settings = new Settings() - settings.verbose.value = true - settings.nowarn.value = false - } - - class NscToApiReporterProxy(val nscReporter: NscReporter) extends ApiReporter { - val API_INFO = INFO - val API_WARNING = WARNING - val API_ERROR = ERROR - - def display(info: Info): Unit = info.severity match { - case API_INFO => nscReporter.info(info.pos, info.msg, false) - case API_WARNING => nscReporter.warning(info.pos, info.msg) - case API_ERROR => nscReporter.error(info.pos, info.msg) - } - - def interactive(): Unit = nscReporter match { - case nscReporter: AbstractReporter => nscReporter.displayPrompt() - case _ => // do nothing - } - - override def flush(): Unit = { - super.flush() - nscReporter.flush() - } - - override def reset(): Unit = { - super.reset() - nscReporter.reset() - } - } - - def wrapNscReporter(nscReporter: NscReporter): ApiReporter = new NscToApiReporterProxy(nscReporter) -} diff --git a/src/compiler/scala/reflect/internal/SymbolTable.scala b/src/compiler/scala/reflect/internal/SymbolTable.scala index 0688d13ae5..7d9dd282cf 100644 --- a/src/compiler/scala/reflect/internal/SymbolTable.scala +++ b/src/compiler/scala/reflect/internal/SymbolTable.scala @@ -36,7 +36,7 @@ abstract class SymbolTable extends api.Universe with Importers with Required with TreeBuildUtil - with Reporters + with FrontEnds with CapturedVariables with StdAttachments { @@ -53,7 +53,7 @@ abstract class SymbolTable extends api.Universe /** Overridden when we know more about what was happening during a failure. */ def supplementErrorMessage(msg: String): String = msg - + private[scala] def printCaller[T](msg: String)(result: T) = { Console.err.println(msg + ": " + result) Console.err.println("Called from:") diff --git a/src/compiler/scala/reflect/makro/runtime/Context.scala b/src/compiler/scala/reflect/makro/runtime/Context.scala index 184008658e..15a4118b85 100644 --- a/src/compiler/scala/reflect/makro/runtime/Context.scala +++ b/src/compiler/scala/reflect/makro/runtime/Context.scala @@ -10,7 +10,7 @@ abstract class Context extends scala.reflect.makro.Context with Enclosures with Names with Reifiers - with Reporters + with FrontEnds with Settings with Symbols with Typers diff --git a/src/compiler/scala/reflect/makro/runtime/Reporters.scala b/src/compiler/scala/reflect/makro/runtime/FrontEnds.scala index 0fd037bdd2..7cfa8e80f3 100644 --- a/src/compiler/scala/reflect/makro/runtime/Reporters.scala +++ b/src/compiler/scala/reflect/makro/runtime/FrontEnds.scala @@ -1,21 +1,21 @@ package scala.reflect.makro package runtime -trait Reporters { +trait FrontEnds { self: Context => import mirror._ - def reporter: mirror.Reporter = wrapNscReporter(mirror.reporter) + def frontEnd: FrontEnd = wrapReporter(mirror.reporter) - def setReporter(reporter: mirror.Reporter): this.type = { - mirror.reporter = wrapApiReporter(reporter) + def setFrontEnd(frontEnd: FrontEnd): this.type = { + mirror.reporter = wrapFrontEnd(frontEnd) this } - def withReporter[T](reporter: Reporter)(op: => T): T = { + def withFrontEnd[T](frontEnd: FrontEnd)(op: => T): T = { val old = mirror.reporter - setReporter(reporter) + setFrontEnd(frontEnd) try op finally mirror.reporter = old } diff --git a/src/compiler/scala/reflect/runtime/ToolBoxes.scala b/src/compiler/scala/reflect/runtime/ToolBoxes.scala index 6d832a590f..21a90326cf 100644 --- a/src/compiler/scala/reflect/runtime/ToolBoxes.scala +++ b/src/compiler/scala/reflect/runtime/ToolBoxes.scala @@ -16,14 +16,11 @@ import scala.compat.Platform.EOL trait ToolBoxes extends { self: Universe => - import self.{Reporter => ApiReporter} - import scala.tools.nsc.reporters.{Reporter => NscReporter} + def mkToolBox(frontEnd: FrontEnd = mkSilentFrontEnd(), options: String = "") = new ToolBox(frontEnd, options) - def mkToolBox(reporter: ApiReporter = mkSilentReporter(), options: String = "") = new ToolBox(reporter, options) + class ToolBox(val frontEnd: FrontEnd, val options: String) extends AbsToolBox { - class ToolBox(val reporter: ApiReporter, val options: String) extends AbsToolBox { - - class ToolBoxGlobal(settings: scala.tools.nsc.Settings, reporter: NscReporter) + class ToolBoxGlobal(settings: scala.tools.nsc.Settings, reporter: Reporter) extends ReflectGlobal(settings, reporter, ToolBox.this.classLoader) { import definitions._ @@ -200,11 +197,7 @@ trait ToolBoxes extends { self: Universe => val run = new Run reporter.reset() run.compileUnits(List(unit), run.namerPhase) - if (reporter.hasErrors) { - var msg = "reflective compilation has failed: " + EOL + EOL - msg += ToolBox.this.reporter.infos map (_.msg) mkString EOL - throw new ToolBoxError(ToolBox.this, msg) - } + throwIfErrors() val className = mdef.symbol.fullName if (settings.debug.value) println("generated: "+className) @@ -250,6 +243,15 @@ trait ToolBoxes extends { self: Universe => settings.Yshowsymkinds.value = saved3 } } + + // reporter doesn't accumulate errors, but the front-end does + def throwIfErrors() = { + if (frontEnd.hasErrors) { + var msg = "reflective compilation has failed: " + EOL + EOL + msg += frontEnd.infos map (_.msg) mkString EOL + throw new ToolBoxError(ToolBox.this, msg) + } + } } // todo. is not going to work with quoted arguments with embedded whitespaces @@ -263,19 +265,13 @@ trait ToolBoxes extends { self: Universe => lazy val compiler: ToolBoxGlobal = { try { - val errorFn: String => Unit = msg => reporter.log(NoPosition, msg, reporter.ERROR) - // [Eugene] settings shouldn't be passed via reporters, this is crazy -// val command = reporter match { -// case reporter: AbstractReporter => new CompilerCommand(arguments.toList, reporter.settings, errorFn) -// case _ => new CompilerCommand(arguments.toList, errorFn) -// } + val errorFn: String => Unit = msg => frontEnd.log(NoPosition, msg, frontEnd.ERROR) val command = new CompilerCommand(arguments.toList, errorFn) command.settings.outputDirs setSingleOutput virtualDirectory - val nscReporter = new ApiToNscReporterProxy(reporter) { val settings = command.settings } - val instance = new ToolBoxGlobal(command.settings, nscReporter) - if (nscReporter.hasErrors) { + val instance = new ToolBoxGlobal(command.settings, new FrontEndToReporterProxy(frontEnd) { val settings = command.settings }) + if (frontEnd.hasErrors) { var msg = "reflective compilation has failed: cannot initialize the compiler: " + EOL + EOL - msg += reporter.infos map (_.msg) mkString EOL + msg += frontEnd.infos map (_.msg) mkString EOL throw new ToolBoxError(this, msg) } instance.phase = (new instance.Run).typerPhase // need to manually set a phase, because otherwise TypeHistory will crash diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 6c038162b3..f9cef385dc 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -11,7 +11,7 @@ import compat.Platform.currentTime import scala.tools.util.{ Profiling, PathResolver } import scala.collection.{ mutable, immutable } import io.{ SourceReader, AbstractFile, Path } -import reporters.{ Reporter => NscReporter, ConsoleReporter } +import reporters.{ Reporter, ConsoleReporter } import util.{ NoPosition, Exceptional, ClassPath, SourceFile, NoSourceFile, Statistics, StatisticsInfo, BatchSourceFile, ScriptSourceFile, ShowPickled, ScalaClassLoader, returning } import scala.reflect.internal.pickling.{ PickleBuffer, PickleFormat } import settings.{ AestheticSettings } @@ -31,17 +31,17 @@ import backend.icode.analysis._ import language.postfixOps import reflect.internal.StdAttachments -class Global(var currentSettings: Settings, var reporter: NscReporter) extends SymbolTable - with ClassLoaders - with ToolBoxes - with CompilationUnits - with Plugins - with PhaseAssembly - with Trees - with FreeVars - with TreePrinters - with DocComments - with Positions { +class Global(var currentSettings: Settings, var reporter: Reporter) extends SymbolTable + with ClassLoaders + with ToolBoxes + with CompilationUnits + with Plugins + with PhaseAssembly + with Trees + with FreeVars + with TreePrinters + with DocComments + with Positions { override def settings = currentSettings @@ -49,7 +49,7 @@ class Global(var currentSettings: Settings, var reporter: NscReporter) extends S // alternate constructors ------------------------------------------ - def this(reporter: NscReporter) = + def this(reporter: Reporter) = this(new Settings(err => reporter.error(null, err)), reporter) def this(settings: Settings) = @@ -1614,7 +1614,7 @@ object Global { * This allows the use of a custom Global subclass with the software which * wraps Globals, such as scalac, fsc, and the repl. */ - def fromSettings(settings: Settings, reporter: NscReporter): Global = { + def fromSettings(settings: Settings, reporter: Reporter): Global = { // !!! The classpath isn't known until the Global is created, which is too // late, so we have to duplicate it here. Classpath is too tightly coupled, // it is a construct external to the compiler and should be treated as such. @@ -1622,7 +1622,7 @@ object Global { val loader = ScalaClassLoader.fromURLs(new PathResolver(settings).result.asURLs, parentLoader) val name = settings.globalClass.value val clazz = Class.forName(name, true, loader) - val cons = clazz.getConstructor(classOf[Settings], classOf[NscReporter]) + val cons = clazz.getConstructor(classOf[Settings], classOf[Reporter]) cons.newInstance(settings, reporter).asInstanceOf[Global] } @@ -1630,7 +1630,7 @@ object Global { /** A global instantiated this way honors -Yglobal-class setting, and * falls back on calling the Global constructor directly. */ - def apply(settings: Settings, reporter: NscReporter): Global = { + def apply(settings: Settings, reporter: Reporter): Global = { val g = ( if (settings.globalClass.isDefault) null else try fromSettings(settings, reporter) catch { case x => diff --git a/src/compiler/scala/tools/nsc/ToolBoxes.scala b/src/compiler/scala/tools/nsc/ToolBoxes.scala index eb298833b8..5b2b5ff5e9 100644 --- a/src/compiler/scala/tools/nsc/ToolBoxes.scala +++ b/src/compiler/scala/tools/nsc/ToolBoxes.scala @@ -4,11 +4,9 @@ import util.ScalaClassLoader trait ToolBoxes { self: Global => - import self.{Reporter => ApiReporter} + def mkToolBox(frontEnd: FrontEnd = mkSilentFrontEnd(), options: String = "") = new ToolBox(frontEnd, options) - def mkToolBox(reporter: ApiReporter = mkSilentReporter(), options: String = "") = new ToolBox(reporter, options) - - class ToolBox(val reporter: ApiReporter, val options: String) extends AbsToolBox { + class ToolBox(val frontEnd: FrontEnd, val options: String) extends AbsToolBox { def typeCheck(tree0: Tree, pt: Type = WildcardType, freeTypes: Map[FreeType, Type] = Map[FreeType, Type](), silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree = { val tree = substituteFreeTypes(tree0, freeTypes) val currentTyper = typer @@ -43,7 +41,7 @@ trait ToolBoxes { self: Global => // need to reset the tree, otherwise toolbox will refuse to work with it tree = resetAllAttrs(tree0.duplicate) val imported = importer.importTree(tree) - val toolBox = libraryClasspathMirror.mkToolBox(reporter.asInstanceOf[libraryClasspathMirror.Reporter], options) + val toolBox = libraryClasspathMirror.mkToolBox(frontEnd.asInstanceOf[libraryClasspathMirror.FrontEnd], options) try toolBox.runExpr(imported) catch { case ex: toolBox.ToolBoxError => diff --git a/src/compiler/scala/tools/nsc/ast/DocComments.scala b/src/compiler/scala/tools/nsc/ast/DocComments.scala index 8e7eeed3cc..b3ed446563 100755 --- a/src/compiler/scala/tools/nsc/ast/DocComments.scala +++ b/src/compiler/scala/tools/nsc/ast/DocComments.scala @@ -7,7 +7,7 @@ package scala.tools.nsc package ast import symtab._ -import reporters.{Reporter => NscReporter} +import reporters._ import util.{Position, NoPosition} import util.DocStrings._ import scala.reflect.internal.Chars._ @@ -21,8 +21,6 @@ trait DocComments { self: Global => var cookedDocComments = Map[Symbol, String]() - def reporter: NscReporter - /** The raw doc comment map */ val docComments = mutable.HashMap[Symbol, DocComment]() diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala index 13124e6afc..bfcfa5f2b9 100644 --- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala +++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala @@ -13,7 +13,6 @@ import scala.sys.BooleanProp import io.VirtualDirectory import scala.tools.nsc.io.AbstractFile import reporters._ -import reporters.{Reporter => NscReporter} import symtab.Flags import scala.reflect.internal.Names import scala.tools.util.PathResolver @@ -282,7 +281,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends protected def createLineManager(classLoader: ClassLoader): Line.Manager = new Line.Manager(classLoader) /** Instantiate a compiler. Overridable. */ - protected def newCompiler(settings: Settings, reporter: NscReporter): ReplGlobal = { + protected def newCompiler(settings: Settings, reporter: Reporter): ReplGlobal = { settings.outputDirs setSingleOutput virtualDirectory settings.exposeEmptyPackage.value = true new Global(settings, reporter) with ReplGlobal diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala index fb85ebeeb0..75b486ca7d 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala @@ -6,7 +6,4 @@ package scala.tools.nsc package symtab -import ast.{Trees, TreePrinters, DocComments} -import util._ - abstract class SymbolTable extends reflect.internal.SymbolTable
\ No newline at end of file |