aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Phases.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-02-27 09:12:27 +0100
committerMartin Odersky <odersky@gmail.com>2013-02-27 09:14:33 +0100
commit856f084c474125117ed2166720ba4192d358fbef (patch)
treebfbcc9c242dae55863ce4cd84a894fb12e34ab9f /src/dotty/tools/dotc/core/Phases.scala
parentd29cc7978daa49f68d14eba35af20fbb8dd423c1 (diff)
downloaddotty-856f084c474125117ed2166720ba4192d358fbef.tar.gz
dotty-856f084c474125117ed2166720ba4192d358fbef.tar.bz2
dotty-856f084c474125117ed2166720ba4192d358fbef.zip
Filling in all ???s
Added reporters. Added context for signatures. Implemented method signatures via erasure. Refined derivedNameType handling.
Diffstat (limited to 'src/dotty/tools/dotc/core/Phases.scala')
-rw-r--r--src/dotty/tools/dotc/core/Phases.scala84
1 files changed, 82 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala
index f9b8eaa9f..02d9c9749 100644
--- a/src/dotty/tools/dotc/core/Phases.scala
+++ b/src/dotty/tools/dotc/core/Phases.scala
@@ -1,11 +1,91 @@
package dotty.tools.dotc
package core
+import Periods._, Contexts._
+
+trait Phases { self: Context =>
+ import Phases._
+
+ def phase: Phase = base.phases(period.phaseId)
+
+ def phasesStack: List[Phase] =
+ if (phase == this.NoPhase) Nil
+ else phase :: outersIterator.dropWhile(_.phase == phase).next.phasesStack
+
+ /** Execute `op` at given phase id */
+ def atPhase[T](phase: Phase)(op: Context => T): T =
+ atPhase(phase.id)(op)
+
+ def atPhaseNotLaterThan[T](limit: Phase)(op: Context => T): T =
+ if (!limit.exists || phase <= limit) op(this) else atPhase(limit)(op)
+
+ def atPhaseNotLaterThanTyper[T](op: Context => T): T =
+ atPhaseNotLaterThan(base.typerPhase)(op)
+}
+
object Phases {
- abstract class Phase {
- def erasedTypes: Boolean
+ trait PhasesBase { this: ContextBase =>
+
+ lazy val allPhases = phases.slice(FirstPhaseId, nphases)
+
+ val NoPhase = new Phase(initialCtx) {
+ def name = "<no phase>"
+ def run() { throw new Error("NoPhase.run") }
+ }
+/*
+ object SomePhase extends Phase {
+ def name = "<some phase>"
+ def run() { throw new Error("SomePhase.run") }
+ }
+*/
+ def phaseNamed(name: String) =
+ allPhases.find(_.name == name).getOrElse(NoPhase)
+
+ final val typerName = "typer"
+ final val refchecksName = "refchecks"
+ final val erasureName = "erasure"
+ final val flattenName = "flatten"
+
+ lazy val typerPhase = phaseNamed(typerName)
+ lazy val refchecksPhase = phaseNamed(refchecksName)
+ lazy val erasurePhase = phaseNamed(erasureName)
+ lazy val flattenPhase = phaseNamed(flattenName)
}
+ abstract class Phase(initctx: Context) {
+
+ val id: Int = initctx.nphases
+ initctx.nphases += 1
+ def name: String
+
+ def run(): Unit
+
+ def description: String = name
+
+ def checkable: Boolean = true
+
+ final def exists: Boolean = id != NoPhaseId
+
+ final def <= (that: Phase) =
+ exists && id <= that.id
+
+ final def prev(implicit ctx: Context): Phase =
+ if (id > FirstPhaseId) ctx.phases(id - 1) else initctx.NoPhase
+
+ final def next(implicit ctx: Context): Phase =
+ if (hasNext) ctx.phases(id + 1) else initctx.NoPhase
+
+ final def hasNext(implicit ctx: Context) = id + 1 < ctx.nphases
+
+ final def iterator(implicit ctx: Context) =
+ Iterator.iterate(this)(_.next) takeWhile (_.hasNext)
+
+ final def erasedTypes(implicit ctx: Context): Boolean = ctx.erasurePhase <= this
+ final def flatClasses(implicit ctx: Context): Boolean = ctx.flattenPhase <= this
+ final def refChecked (implicit ctx: Context): Boolean = ctx.refchecksPhase <= this
+
+ override def toString = name
+ }
} \ No newline at end of file