diff options
author | Martin Odersky <odersky@gmail.com> | 2013-08-17 10:19:43 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-08-17 10:19:43 +0200 |
commit | fd6a6774be4be37f707f509aef997e456a6b64ac (patch) | |
tree | 50eea18194ce6a7b588b200a34150b8d75e64f0f /src/dotty/tools/dotc | |
parent | 0575d51b898d14f818e35a19a5f9f67f280a0b04 (diff) | |
download | dotty-fd6a6774be4be37f707f509aef997e456a6b64ac.tar.gz dotty-fd6a6774be4be37f707f509aef997e456a6b64ac.tar.bz2 dotty-fd6a6774be4be37f707f509aef997e456a6b64ac.zip |
Defined root context with imports
… and cleaned up and simplified other context-reated features.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r-- | src/dotty/tools/dotc/CompilationUnit.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/Compiler.scala | 12 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/Trees.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Contexts.scala | 29 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/PlainPrinter.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/Printer.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/Printers.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/RefinedPrinter.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/ImportInfo.scala | 12 |
9 files changed, 42 insertions, 37 deletions
diff --git a/src/dotty/tools/dotc/CompilationUnit.scala b/src/dotty/tools/dotc/CompilationUnit.scala index 0c662116e..791e8899d 100644 --- a/src/dotty/tools/dotc/CompilationUnit.scala +++ b/src/dotty/tools/dotc/CompilationUnit.scala @@ -12,4 +12,6 @@ class CompilationUnit(val source: SourceFile) { var tpdTree: tpd.Tree = tpd.EmptyTree + def isJava = source.file.name.endsWith(".java") + }
\ No newline at end of file diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index 6f5e162ee..d285fef5a 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -5,20 +5,28 @@ import core._ import Contexts._ import Periods._ import Symbols._ -import typer.{FrontEnd, Typer} +import typer.{FrontEnd, Typer, Mode, ImportInfo} import reporting.ConsoleReporter class Compiler { def phases = List(new FrontEnd) + def rootImports(implicit ctx: Context) = + defn.JavaLangPackageVal :: defn.ScalaPackageVal :: defn.PredefModule :: Nil + def rootContext(implicit ctx: Context): Context = { ctx.usePhases(phases) - ctx.fresh + val start = ctx.fresh .withPeriod(Period(ctx.runId + 1, FirstPhaseId)) + .withRunInfo(new RunInfo) .withOwner(defn.RootClass) .withTyper(new Typer) + .withMode(Mode.None) .withTyperState(new MutableTyperState(ctx.typerState, new ConsoleReporter()(ctx))) + def addImport(ctx: Context, sym: Symbol) = + ctx.fresh.withImportInfo(ImportInfo.rootImport(sym)(ctx)) + (start /: rootImports)(addImport) } def newRun(implicit ctx: Context): Run = diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala index 9eeb28da4..8157c287d 100644 --- a/src/dotty/tools/dotc/ast/Trees.scala +++ b/src/dotty/tools/dotc/ast/Trees.scala @@ -805,12 +805,6 @@ object Trees { traverser.traverse(tree) } - // ----- Position handling ----------------------------------------- - - protected implicit def pos(implicit ctx: Context): Position = ctx.position - - def defPos(sym: Symbol)(implicit ctx: Context) = ctx.position union sym.coord.toPosition - // ----- Helper classes for copying, transforming, accumulating ----------------- val cpy: TreeCopier diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 6c2670d5d..ed86849b9 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -88,20 +88,10 @@ object Contexts { protected def typerState_=(typerState: TyperState) = _typerState = typerState def typerState: TyperState = _typerState - /** The current position */ - private[this] var _position: Position = _ - protected def position_=(position: Position) = _position = position - def position: Position = _position - /** The current plain printer */ - private[this] var _plainPrinter: Context => Printer = _ - protected def plainPrinter_=(plainPrinter: Context => Printer) = _plainPrinter = plainPrinter - def plainPrinter: Context => Printer = _plainPrinter - - /** The current refined printer */ - private[this] var _refinedPrinter: Context => Printer = _ - protected def refinedPrinter_=(refinedPrinter: Context => Printer) = _refinedPrinter = refinedPrinter - def refinedPrinter: Context => Printer = _refinedPrinter + private[this] var _printerFn: Context => Printer = _ + protected def printerFn_=(printerFn: Context => Printer) = _printerFn = printerFn + def printerFn: Context => Printer = _printerFn /** The current owner symbol */ private[this] var _owner: Symbol = _ @@ -162,7 +152,7 @@ object Contexts { _typeComparer } - /** The new implicit references that are introduces by this scope */ + /** The new implicit references that are introduced by this scope */ private var implicitsCache: ContextualImplicits = null def implicits: ContextualImplicits = { if (implicitsCache == null ) @@ -255,8 +245,7 @@ object Contexts { .withMode(mode) // typerState and its constraint is not preserved in condensed // reporter is always ThrowingReporter - .withPlainPrinter(plainPrinter) - .withRefinedPrinter(refinedPrinter) + .withPrinterFn(printerFn) .withOwner(owner) .withSettings(sstate) // tree is not preserved in condensed @@ -301,9 +290,7 @@ object Contexts { override def withMode(mode: Mode): this.type = { this.mode = mode; this } def withTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this } def withNewTyperState: this.type = withTyperState(typerState.fresh) - def withPosition(position: Position): this.type = { this.position = position; this } - def withPlainPrinter(printer: Context => Printer): this.type = { this.plainPrinter = printer; this } - def withRefinedPrinter(printer: Context => Printer): this.type = { this.refinedPrinter = printer; this } + def withPrinterFn(printer: Context => Printer): this.type = { this.printerFn = printer; this } def withOwner(owner: Symbol): this.type = { this.owner = owner; this } def withSettings(sstate: SettingsState): this.type = { this.sstate = sstate; this } def withCompilationUnit(compilationUnit: CompilationUnit): this.type = { this.compilationUnit = compilationUnit; this } @@ -334,9 +321,7 @@ object Contexts { period = InitialPeriod mode = Mode.None typerState = new TyperState(new ConsoleReporter()(this)) - position = NoPosition - plainPrinter = new PlainPrinter(_) - refinedPrinter = new RefinedPrinter(_) + printerFn = new RefinedPrinter(_) owner = NoSymbol sstate = settings.defaultState tree = untpd.EmptyTree diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index ee3526d1b..fe67f5b89 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -354,5 +354,7 @@ class PlainPrinter(_ctx: Context) extends Printer { tree.fallbackToText(this) } }.close // todo: override in refined printer + + def plain = this } diff --git a/src/dotty/tools/dotc/printing/Printer.scala b/src/dotty/tools/dotc/printing/Printer.scala index 6944c4ae2..af87302e4 100644 --- a/src/dotty/tools/dotc/printing/Printer.scala +++ b/src/dotty/tools/dotc/printing/Printer.scala @@ -87,5 +87,8 @@ abstract class Printer { /** Textual representation of tree */ def toText[T >: Untyped](tree: Tree[T]): Text + + /** A plain printer without any embellishments */ + def plain: Printer } diff --git a/src/dotty/tools/dotc/printing/Printers.scala b/src/dotty/tools/dotc/printing/Printers.scala index ba1cf83bb..7107ccb78 100644 --- a/src/dotty/tools/dotc/printing/Printers.scala +++ b/src/dotty/tools/dotc/printing/Printers.scala @@ -5,11 +5,10 @@ import core.Contexts.Context trait Printers { this: Context => - /** A creation method for printers, depending on debug option */ - def printerFn = if (this.debug) plainPrinter else refinedPrinter - - /** A function creatung a printer */ - def printer = printerFn(this) - + /** A function creating a printer */ + def printer = { + val pr = printerFn(this) + if (this.debug) pr.plain else pr + } } diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 87441f7b7..fe6711e7f 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -394,4 +394,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } override def toText(denot: Denotation): Text = toText(denot.symbol) + + override def plain = new PlainPrinter(_ctx) } diff --git a/src/dotty/tools/dotc/typer/ImportInfo.scala b/src/dotty/tools/dotc/typer/ImportInfo.scala index 50455e97f..1b8cd115d 100644 --- a/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -2,12 +2,22 @@ package dotty.tools package dotc package typer -import ast.untpd +import ast.{tpd, untpd} import ast.Trees._ import core._ import util.SimpleMap import Symbols._, Names._, Denotations._, Types._, Contexts._, StdNames._, Flags._ +object ImportInfo { + /** The import info for a root import from given symbol `sym` */ + def rootImport(sym: Symbol)(implicit ctx: Context) = { + val expr = tpd.Ident(sym.symTermRef) + val selectors = untpd.Ident(nme.WILDCARD) :: Nil + val imp = tpd.Import(expr, selectors) + new ImportInfo(imp.symbol, selectors, rootImport = true) + } +} + /** Info relating to an import clause * @param sym The import symbol defined by the clause * @param selectors The selector clauses |