diff options
author | Martin Odersky <odersky@gmail.com> | 2003-02-13 14:41:36 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-02-13 14:41:36 +0000 |
commit | 4177daab2f54bdb20c71f623296a8bb32616fd12 (patch) | |
tree | 23f08b43f3758e825d5965b336030603a65bbcf7 /sources/scalac/PhaseDescriptor.java | |
parent | 33d6e170c97ca7b2f991896a0729941a7240b6d6 (diff) | |
download | scala-4177daab2f54bdb20c71f623296a8bb32616fd12.tar.gz scala-4177daab2f54bdb20c71f623296a8bb32616fd12.tar.bz2 scala-4177daab2f54bdb20c71f623296a8bb32616fd12.zip |
Initial version.
Diffstat (limited to 'sources/scalac/PhaseDescriptor.java')
-rw-r--r-- | sources/scalac/PhaseDescriptor.java | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/sources/scalac/PhaseDescriptor.java b/sources/scalac/PhaseDescriptor.java new file mode 100644 index 0000000000..0316a80215 --- /dev/null +++ b/sources/scalac/PhaseDescriptor.java @@ -0,0 +1,169 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +** ** +** $Id$ +\* */ + +package scalac; + +import java.util.*; +import scalac.ast.printer.*; +import scalac.ast.*; +import scalac.symtab.*; +import scalac.checkers.*; +import java.io.PrintWriter; + +/** + * Information about a compiler phase. + * + * @author Michel Schinz + */ + +public abstract class PhaseDescriptor { + + private static class InitialPhaseDescriptor extends PhaseDescriptor { + + public String name() { + return "initial"; + } + + public String description() { + return "initializing compiler"; + } + + public Phase createPhase(Global global) { + return null; + } + + /** apply phase to all compilation units + */ + public void apply(Global global) {} + } + + private static class TerminalPhaseDescriptor extends PhaseDescriptor { + + public String name() { + return "terminal"; + } + + public String description() { + return "compilation terminated "; + } + + public Phase createPhase(Global global) { + return null; + } + + /** apply phase to all compilation units + */ + public void apply(Global global) {} + } + + public static PhaseDescriptor INITIAL = new InitialPhaseDescriptor(); + public static PhaseDescriptor TERMINAL = new TerminalPhaseDescriptor(); + + public static final int SKIP = 0x0001; + public static final int CHECK = 0x0002; + public static final int PRINT = 0x0004; + public static final int GRAPH = 0x0008; + public static final int STOP = 0x0010; + public static final int LOG = 0x0020; + + public int flags; + public int id; + + /** return a short, one-word name for the phase. + */ + public abstract String name(); + + /** return a one-line description for the phase. + */ + public abstract String description(); + + /** a one-line task description of this phase + */ + public String taskDescription() { + return description(); + } + + /** initialize the phase + */ + public final void initialize(Global global) { + throw new Error(); + } + public void initialize(Global global, int id) { + this.id = id; + } + + /** create a phase + */ + public abstract Phase createPhase(Global global); + + /** Assume that `tp' is the info of symbol `sym' before this phase. + * Return the info of `sym' after the phase. + */ + public Type transformInfo(Symbol sym, Type tp) { + return tp; + } + + /** apply phase to all compilation units + */ + public void apply(Global global) { + global.start(); + createPhase(global).apply(); + global.stop(taskDescription()); + } + + /** check all compilation units + */ + public void check(Global global) { + for (int i = 0; i < global.units.length; i++) + check(global.units[i]); + } + + /** print all compilation units + */ + public void print(Global global) { + TreePrinter printer = global.printer; + + printer.beginSection(1, "Trees after phase " + name()); + for (int i = 0; i < global.units.length; i++) + printer.print(global.units[i]); + } + + /** graph all compilation units + */ + public void graph(Global global) { + for (int i = 0; i < global.units.length; i++) + graph(global.units[i]); + } + + /** return an array of checkers which can be applied after the phase + */ + public Checker[] postCheckers(Global global) { + return new Checker[0]; + } + + /** 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); + } + + /** graph the result of this phase for the given compilation unit + */ + public void graph(Unit unit) { + /* todo: uncomment + new scala.compiler.gdl.TreePrinter().printInFile( + unit, unit.source + "-" + name() + ".gdl"); + */ + } + + public String toString() { + return name(); + } +} |