summaryrefslogtreecommitdiff
path: root/sources/scalac/Phase.java
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-08-18 15:58:45 +0000
committerpaltherr <paltherr@epfl.ch>2003-08-18 15:58:45 +0000
commit87210b8f1092065be1b7cfaf13a3852fe861abe4 (patch)
tree0e2ee43a75d151a74cec60e0025876082f2d7bc5 /sources/scalac/Phase.java
parentc4e1967d6c99021400b8fa906f51f0bcba984fd4 (diff)
downloadscala-87210b8f1092065be1b7cfaf13a3852fe861abe4.tar.gz
scala-87210b8f1092065be1b7cfaf13a3852fe861abe4.tar.bz2
scala-87210b8f1092065be1b7cfaf13a3852fe861abe4.zip
- rewrote the phase creation process
- replace PhaseRepository by CompilerPhases
Diffstat (limited to 'sources/scalac/Phase.java')
-rw-r--r--sources/scalac/Phase.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/sources/scalac/Phase.java b/sources/scalac/Phase.java
index b0a4efe13f..eb0e87f274 100644
--- a/sources/scalac/Phase.java
+++ b/sources/scalac/Phase.java
@@ -5,3 +5,115 @@
\* */
// $Id$
+
+package scalac;
+
+import scalac.ast.printer.TreePrinter;
+import scalac.symtab.Symbol;
+import scalac.symtab.Type;
+import scalac.checkers.Checker;
+
+public abstract class Phase {
+
+ // !!! remove these obsolete methods !
+ public final String name() {
+ throw new Error("!!! obsolete");
+ }
+ public final String taskDescription() {
+ throw new Error("!!! obsolete");
+ }
+ public final String description() {
+ throw new Error("!!! obsolete");
+ }
+ public final void initialize(Global global) {
+ throw new Error("!!! obsolete");
+ }
+ public final void initialize(Global global, int id) {
+ throw new Error("!!! obsolete");
+ }
+ public final void apply(Global global) {
+ throw new Error("!!! obsolete");
+ }
+ public final void apply(Unit unit) {
+ throw new Error("!!! obsolete");
+ }
+
+ //########################################################################
+ // Public Fields
+
+ /** The global environment */
+ public final Global global;
+
+ /** The phase descriptor */
+ public final PhaseDescriptor descriptor;
+
+ /** The phase identifier */
+ public final int id;
+
+ //########################################################################
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public Phase(Global global, PhaseDescriptor descriptor) {
+ this.global = global;
+ this.descriptor = descriptor;
+ this.id = descriptor.id();
+ global.currentPhase = global.phases[id] = this;
+ }
+
+ //########################################################################
+ // Public Methods
+
+ /**
+ * Returns the info of `sym' after the phase. Assumes that `tp' is
+ * the info of symbol `sym' before this phase.
+ */
+ public Type transformInfo(Symbol sym, Type tp) {
+ return tp;
+ }
+
+ /** Applies this phase to the given compilation units. */
+ public abstract void apply(Unit[] units);
+
+ /** Prints all compilation units. */
+ public void print(Global global) {
+ TreePrinter printer = global.printer;
+ printer.beginSection(1, "Trees after phase " + this);
+ for (int i = 0; i < global.units.length; i++)
+ printer.print(global.units[i]);
+ }
+
+ /** Graphs all compilation units. */
+ public void graph(Global global) {
+ for (int i = 0; i < global.units.length; i++) graph(global.units[i]);
+ }
+
+ /** Graphs the result of this phase for the given compilation unit. */
+ public void graph(Unit unit) {
+ // !!! new scala.compiler.gdl.TreePrinter().printInFile(
+ // !!! unit, unit.source + "-" + name() + ".gdl");
+ }
+
+ /** Checks all compilation units. */
+ public void check(Global global) {
+ for (int i = 0; i < global.units.length; i++) check(global.units[i]);
+ }
+
+ /** Check the result of this phase for the given compilation unit. */
+ public void check(Unit unit) {
+ Checker[] checkers = postCheckers(unit.global);
+ for (int i = 0; i < checkers.length; i++) checkers[i].traverse(unit);
+ }
+
+ /** Returns an array of checkers which can be applied after the phase. */
+ public Checker[] postCheckers(Global global) {
+ return new Checker[0];
+ }
+
+ /** Returns the name of this phase. */
+ public final String toString() {
+ return descriptor.name();
+ }
+
+ //########################################################################
+}