summaryrefslogtreecommitdiff
path: root/sources
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
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')
-rw-r--r--sources/meta/scalac/checkers/MetaCheckTreeNodes.java4
-rw-r--r--sources/scala/tools/scalai/InterpreterCommand.java6
-rw-r--r--sources/scala/tools/scalai/Main.java4
-rw-r--r--sources/scalac/CompilerCommand.java25
-rw-r--r--sources/scalac/CompilerPhases.java164
-rw-r--r--sources/scalac/Global.java114
-rw-r--r--sources/scalac/Main.java2
-rw-r--r--sources/scalac/Phase.java112
-rw-r--r--sources/scalac/PhaseDescriptor.java247
-rw-r--r--sources/scalac/PhaseRepository.java90
-rw-r--r--sources/scalac/ast/Transformer.java.tmpl4
-rw-r--r--sources/scalac/ast/parser/ParserPhase.java36
-rw-r--r--sources/scalac/backend/jvm/GenJVMBCELPhase.java45
-rw-r--r--sources/scalac/backend/jvm/GenJVMPhase.java38
-rw-r--r--sources/scalac/backend/msil/GenMSILPhase.java36
-rw-r--r--sources/scalac/checkers/CheckTreeNodes.java.tmpl3
-rw-r--r--sources/scalac/symtab/SourceCompleter.java6
-rw-r--r--sources/scalac/symtab/Symbol.java6
-rw-r--r--sources/scalac/transformer/AddAccessorsPhase.java35
-rw-r--r--sources/scalac/transformer/AddConstructorsPhase.java42
-rw-r--r--sources/scalac/transformer/AddInterfacesPhase.java24
-rw-r--r--sources/scalac/transformer/ErasurePhase.java68
-rw-r--r--sources/scalac/transformer/ExpandMixinsPhase.java77
-rw-r--r--sources/scalac/transformer/ExplicitOuterClasses.java4
-rw-r--r--sources/scalac/transformer/ExplicitOuterClassesPhase.java27
-rw-r--r--sources/scalac/transformer/LambdaLiftPhase.java33
-rw-r--r--sources/scalac/transformer/TransMatchPhase.java34
-rw-r--r--sources/scalac/transformer/UnCurryPhase.java32
-rw-r--r--sources/scalac/transformer/matching/AlgebraicMatcher.java2
-rw-r--r--sources/scalac/transformer/matching/CodeFactory.java2
-rw-r--r--sources/scalac/transformer/matching/PatternMatcher.java2
-rw-r--r--sources/scalac/typechecker/Analyzer.java12
-rw-r--r--sources/scalac/typechecker/AnalyzerPhase.java35
-rw-r--r--sources/scalac/typechecker/RefCheckPhase.java25
-rw-r--r--sources/scalac/util/EmptyPhase.java36
-rw-r--r--sources/scalac/util/OptionParser.java7
36 files changed, 799 insertions, 640 deletions
diff --git a/sources/meta/scalac/checkers/MetaCheckTreeNodes.java b/sources/meta/scalac/checkers/MetaCheckTreeNodes.java
index 9fb2f2018d..d18d012d20 100644
--- a/sources/meta/scalac/checkers/MetaCheckTreeNodes.java
+++ b/sources/meta/scalac/checkers/MetaCheckTreeNodes.java
@@ -43,7 +43,7 @@ public class MetaCheckTreeNodes extends AbstractTreeCaseExpander {
private void printCheckNode(TreeNode node) {
if (node.start.constant != null) {
writer.println("assert global.currentPhase.id >= " +
- "global.PHASE."+node.start.constant + ".id :").indent();
+ "phases."+node.start.constant + ".id() :").indent();
writer.println("\"cannot create instance of " + node.name +
" before phase " + node.start.name + ", \" +");
writer.println(
@@ -51,7 +51,7 @@ public class MetaCheckTreeNodes extends AbstractTreeCaseExpander {
}
if (node.stop.constant != null) {
writer.println("assert global.currentPhase.id <= " +
- "global.PHASE."+node.stop.constant + ".id :").indent();
+ "phases."+node.stop.constant + ".id() :").indent();
writer.println("\"cannot create instance of " + node.name +
" after phase " + node.stop.name + ", \" +");
writer.println(
diff --git a/sources/scala/tools/scalai/InterpreterCommand.java b/sources/scala/tools/scalai/InterpreterCommand.java
index 9b538d5b49..5369009179 100644
--- a/sources/scala/tools/scalai/InterpreterCommand.java
+++ b/sources/scala/tools/scalai/InterpreterCommand.java
@@ -9,7 +9,7 @@
package scalai;
-import scalac.PhaseRepository;
+import scalac.CompilerPhases;
import scalac.CompilerCommand;
import scalac.util.Reporter;
import scalac.util.StringOptionParser;
@@ -30,14 +30,14 @@ public class InterpreterCommand extends CompilerCommand {
// Public Constructors
public InterpreterCommand(String product, String version,
- Reporter reporter, PhaseRepository phases)
+ Reporter reporter, CompilerPhases phases)
{
this(product, version, "<source files> [-- <module> <args>]",
reporter, phases);
}
public InterpreterCommand(String product, String version, String syntax,
- Reporter reporter, PhaseRepository phases)
+ Reporter reporter, CompilerPhases phases)
{
super(product, version, syntax, reporter, phases);
diff --git a/sources/scala/tools/scalai/Main.java b/sources/scala/tools/scalai/Main.java
index a5c3dfda77..5c7952e1b0 100644
--- a/sources/scala/tools/scalai/Main.java
+++ b/sources/scala/tools/scalai/Main.java
@@ -9,7 +9,7 @@
package scalai;
-import scalac.PhaseRepository;
+import scalac.CompilerPhases;
import scalac.util.Reporter;
public class Main {
@@ -28,7 +28,7 @@ public class Main {
public static void main(String[] args) {
Reporter reporter = new Reporter();
InterpreterCommand command = new InterpreterCommand(
- PRODUCT, VERSION, reporter, new PhaseRepository());
+ PRODUCT, VERSION, reporter, new CompilerPhases());
if (command.parse(args)) {
InterpreterShell shell = new InterpreterShell(command);
shell.main(command.files.toArray(), command.script.value,
diff --git a/sources/scalac/CompilerCommand.java b/sources/scalac/CompilerCommand.java
index 3eb8a1d117..615a22400c 100644
--- a/sources/scalac/CompilerCommand.java
+++ b/sources/scalac/CompilerCommand.java
@@ -31,7 +31,7 @@ import scalac.util.Strings;
public class CompilerCommand extends CommandParser {
- public final PhaseRepository phases;
+ public final CompilerPhases phases;
public final BooleanOptionParser nowarn;
public final BooleanOptionParser verbose;
@@ -68,13 +68,13 @@ public class CompilerCommand extends CommandParser {
public final UnknownArgumentParser unknown_arguments;
public CompilerCommand(String product, String version,
- Reporter reporter, PhaseRepository phases)
+ Reporter reporter, CompilerPhases phases)
{
this(product, version, "<source files>", reporter, phases);
}
protected CompilerCommand(String product, String version, String syntax,
- Reporter reporter, PhaseRepository phases)
+ Reporter reporter, CompilerPhases phases)
{
super(product, version, syntax, reporter);
this.phases = phases;
@@ -151,15 +151,15 @@ public class CompilerCommand extends CommandParser {
this.skip = new PhaseSetOptionParser(this,
"skip", "Skip <phases> (see below)",
- phases.phases, PhaseDescriptor.SKIP),
+ phases.phases(), PhaseDescriptor.SKIP),
this.check = new PhaseSetOptionParser(this,
"check", "Check the tree after <phases> (see below)",
- phases.phases, PhaseDescriptor.CHECK),
+ phases.phases(), PhaseDescriptor.CHECK),
this.print = new PrintOptionParser(this,
"print", "Print out program after <phases> (see below)",
- phases.phases, PhaseDescriptor.PRINT),
+ phases.phases(), PhaseDescriptor.PRINT),
this.printer = new ChoiceOptionParser(this,
"printer", "Printer to use",
@@ -171,7 +171,7 @@ public class CompilerCommand extends CommandParser {
this.graph = new PhaseSetOptionParser(this,
"graph", "Graph the program after <phases> (see below)",
- phases.phases, PhaseDescriptor.GRAPH),
+ phases.phases(), PhaseDescriptor.GRAPH),
this.doc = new BooleanOptionParser(this,
"doc", "Generate documentation",
@@ -187,11 +187,11 @@ public class CompilerCommand extends CommandParser {
this.stop = new PhaseSetOptionParser(this,
"stop", "Stop after first phase in <phases> (see below)",
- phases.phases, PhaseDescriptor.STOP),
+ phases.phases(), PhaseDescriptor.STOP),
this.log = new PhaseSetOptionParser(this,
"log", "Log operations in <phases> (see below)",
- phases.phases, PhaseDescriptor.LOG),
+ phases.phases(), PhaseDescriptor.LOG),
this.version = new VersionOptionParser(this,
"version", "Print product version and exit",
@@ -224,9 +224,10 @@ public class CompilerCommand extends CommandParser {
buffer.append(Strings.EOL);
buffer.append("and possible compilation phases include:");
buffer.append(Strings.EOL);
- List lines = new ArrayList(phases.phases.length);
- for (int i = 0; i < phases.phases.length; i++) {
- PhaseDescriptor phase = phases.phases[i];
+ PhaseDescriptor[] array = phases.phases();
+ List lines = new ArrayList(array.length);
+ for (int i = 0; i < array.length; i++) {
+ PhaseDescriptor phase = array[i];
lines.add(" " + phase.name() + "\t " + phase.description());
}
lines.add(" " + "all" + "\t " + "matches all phases");
diff --git a/sources/scalac/CompilerPhases.java b/sources/scalac/CompilerPhases.java
new file mode 100644
index 0000000000..165b1b975a
--- /dev/null
+++ b/sources/scalac/CompilerPhases.java
@@ -0,0 +1,164 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scalac;
+
+import java.util.List;
+import java.util.ArrayList;
+
+public class CompilerPhases {
+
+ //########################################################################
+ // Public Fields
+
+ public final PhaseDescriptor INITIAL;
+ public final PhaseDescriptor PARSER;
+ public final PhaseDescriptor ANALYZER;
+ public final PhaseDescriptor REFCHECK;
+ public final PhaseDescriptor UNCURRY;
+ // public final PhaseDescriptor OPTIMIZE;
+ public final PhaseDescriptor TRANSMATCH;
+ public final PhaseDescriptor LAMBDALIFT;
+ public final PhaseDescriptor EXPLICITOUTER;
+ public final PhaseDescriptor ADDACCESSORS;
+ public final PhaseDescriptor ADDINTERFACES;
+ public final PhaseDescriptor EXPANDMIXIN;
+ public final PhaseDescriptor ERASURE;
+ public final PhaseDescriptor ADDCONSTRUCTORS;
+ public final PhaseDescriptor GENMSIL;
+ public final PhaseDescriptor GENJVM;
+ public final PhaseDescriptor GENJVM_BCEL;
+ public final PhaseDescriptor TERMINAL;
+
+ //########################################################################
+ // Private Fields
+
+ private final List phases;
+
+ //########################################################################
+ // Public Constructors
+
+ public CompilerPhases() {
+ this.phases = new ArrayList();
+ PhaseDescriptor[] array = {
+ this.INITIAL = new PhaseDescriptor(
+ "initial",
+ "initializing compiler",
+ "initializing compiler",
+ scalac.util.EmptyPhase.class),
+ this.PARSER = new PhaseDescriptor(
+ "parse",
+ "parse source files",
+ "parsed",
+ scalac.ast.parser.ParserPhase.class),
+ this.ANALYZER = new PhaseDescriptor(
+ "analyze",
+ "name and type analysis",
+ "type checking",
+ scalac.typechecker.AnalyzerPhase.class),
+ this.REFCHECK = new PhaseDescriptor(
+ "refcheck",
+ "reference checking",
+ "reference checking",
+ scalac.typechecker.RefCheckPhase.class),
+ this.UNCURRY = new PhaseDescriptor(
+ "uncurry",
+ "uncurry function types and applications",
+ "uncurried",
+ scalac.transformer.UnCurryPhase.class),
+// this.OPTIMIZE = new PhaseDescriptor(
+// "optimize",
+// "tree-optimizer",
+// "tree optimization",
+// scalac.optimizer.OptimizePhase.class),
+ this.TRANSMATCH = new PhaseDescriptor(
+ "transmatch",
+ "translate match expressions",
+ "translated pattern matching",
+ scalac.transformer.TransMatchPhase.class),
+ this.LAMBDALIFT = new PhaseDescriptor(
+ "lambdalift",
+ "lambda lifter",
+ "lambda lifting",
+ scalac.transformer.LambdaLiftPhase.class),
+ this.EXPLICITOUTER = new PhaseDescriptor(
+ "explicitouterclasses",
+ "make links from inner classes to enclosing one explicit",
+ "made outer links explicit",
+ scalac.transformer.ExplicitOuterClassesPhase.class),
+ this.ADDACCESSORS = new PhaseDescriptor(
+ "addaccessors",
+ "add accessors for constructor arguments",
+ "added accessors",
+ scalac.transformer.AddAccessorsPhase.class),
+ this.ADDINTERFACES = new PhaseDescriptor(
+ "addinterfaces",
+ "add one interface per class",
+ "added interfaces",
+ scalac.transformer.AddInterfacesPhase.class),
+ this.EXPANDMIXIN = new PhaseDescriptor(
+ "expandmixins",
+ "expand mixins by code copying",
+ "expanded mixins",
+ scalac.transformer.ExpandMixinsPhase.class),
+ this.ERASURE = new PhaseDescriptor(
+ "erasure",
+ "type eraser",
+ "erased types",
+ scalac.transformer.ErasurePhase.class),
+ this.ADDCONSTRUCTORS = new PhaseDescriptor(
+ "addconstructors",
+ "add explicit constructor for each class",
+ "added constructors",
+ scalac.transformer.AddConstructorsPhase.class),
+ this.GENMSIL = new PhaseDescriptor(
+ "genmsil",
+ "generate MSIL code",
+ "generated MSIL code",
+ scalac.backend.msil.GenMSILPhase.class),
+ this.GENJVM = new PhaseDescriptor(
+ "genjvm",
+ "generate JVM bytecodes",
+ "generated JVM code",
+ scalac.backend.jvm.GenJVMPhase.class),
+ this.GENJVM_BCEL = new PhaseDescriptor(
+ "genjvm-bcel",
+ "generate JVM bytecodes",
+ "generated JVM code",
+ scalac.backend.jvm.GenJVMBCELPhase.class),
+ this.TERMINAL = new PhaseDescriptor(
+ "terminal",
+ "compilation terminated",
+ "compilation terminated",
+ scalac.util.EmptyPhase.class),
+ };
+ for (int i = 0; i < array.length; i++) phases.add(array[i]);
+ }
+
+ //########################################################################
+ // Public Methods
+
+ public PhaseDescriptor[] phases() {
+ PhaseDescriptor[] array = new PhaseDescriptor[phases.size()];
+ phases.toArray(array);
+ return array;
+ }
+
+ public void freeze() {
+ PhaseDescriptor[] phases = phases();
+ PhaseDescriptor.freeze(phases);
+ for (int i = 0; i < phases.length; i++)
+ if (phases[i].hasSkipFlag()) remove(phases[i]);
+ }
+
+ public void remove(PhaseDescriptor phase) {
+ phases.remove(phase);
+ }
+
+ //########################################################################
+}
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java
index 0ae1923b0d..4b118fef7b 100644
--- a/sources/scalac/Global.java
+++ b/sources/scalac/Global.java
@@ -109,7 +109,7 @@ public class Global {
/** the current phase
*/
- public PhaseDescriptor currentPhase;
+ public Phase currentPhase;
/** the global definitions
*/
@@ -121,8 +121,8 @@ public class Global {
/** compilation phases.
*/
- public final PhaseRepository PHASE;
- public final PhaseDescriptor[] phases;
+ public final CompilerPhases PHASE;
+ public final Phase[] phases;
public static final int START_PHASE_ID = 1;
public static final int POST_ANALYZER_PHASE_ID = 3;
@@ -197,48 +197,24 @@ public class Global {
this.docmodulePath = args.docmodulePath.value;
this.freshNameCreator = new FreshNameCreator();
this.make = new DefaultTreeFactory();
- this.currentPhase = PhaseDescriptor.INITIAL;
+ this.PHASE = args.phases;
+ // if (!optimize) PHASE.remove(args.phases.OPTIMIZE);
+ if (target != TARGET_MSIL) PHASE.remove(args.phases.GENMSIL);
+ if (target != TARGET_JVM) PHASE.remove(args.phases.GENJVM);
+ if (target != TARGET_JVM_BCEL) PHASE.remove(args.phases.GENJVM_BCEL);
+ PHASE.freeze();
+ PhaseDescriptor[] descriptors = PHASE.phases();
+ this.phases = new Phase[descriptors.length];
+ this.currentPhase = phases[0] = descriptors[0].create(this);
this.definitions = new Definitions(this);
this.primitives = new Primitives(this);
this.treeGen = new TreeGen(this, make);
- this.PHASE = args.phases;
- List phases = new ArrayList();
- phases.add(PHASE.INITIAL);
- phases.add(PHASE.PARSER);
- phases.add(PHASE.ANALYZER);
- phases.add(PHASE.REFCHECK);
- phases.add(PHASE.UNCURRY);
- /*
- if (optimize) {
- phases.add(PHASE.OPTIMIZE);
- } */
- phases.add(PHASE.TRANSMATCH);
- phases.add(PHASE.LAMBDALIFT);
- phases.add(PHASE.EXPLICITOUTER);
- phases.add(PHASE.ADDACCESSORS);
- phases.add(PHASE.ADDINTERFACES);
- phases.add(PHASE.EXPANDMIXIN);
- phases.add(PHASE.ERASURE);
- if (target == TARGET_INT
- || target == TARGET_MSIL
- || target == TARGET_JVM
- || target == TARGET_JVM_BCEL) {
- phases.add(PHASE.ADDCONSTRUCTORS);
- }
- if (target == TARGET_MSIL) phases.add(PHASE.GENMSIL);
- if (target == TARGET_JVM) phases.add(PHASE.GENJVM);
- if (target == TARGET_JVM_BCEL) phases.add(PHASE.GENJVM_BCEL);
- phases.add(PHASE.TERMINAL);
- this.phases = new PhaseDescriptor[phases.size()];
- for (int i = 0; i < phases.size(); i++) {
- PhaseDescriptor phase = (PhaseDescriptor)phases.get(i);
- this.phases[i] = phase;
- if (i > 0) this.phases[i - 1].flags |= phase.flags >>> 16;
- phase.initialize(this, i);
- assert phase.id == i;
- }
- assert PHASE.PARSER.id == START_PHASE_ID;
- assert PHASE.ANALYZER.id + 1 == POST_ANALYZER_PHASE_ID;
+ for (int i = 1; i < descriptors.length; i++)
+ this.currentPhase = phases[i] = descriptors[i].create(this);
+ this.currentPhase = phases[0];
+
+ assert PHASE.PARSER.id() == START_PHASE_ID;
+ assert PHASE.ANALYZER.id() + 1 == POST_ANALYZER_PHASE_ID;
}
/** Move to next phase
@@ -290,28 +266,20 @@ public class Global {
// apply successive phases and pray that it works
for (int i = 0; i < phases.length && reporter.errors() == 0; ++i) {
currentPhase = phases[i];
- if ((currentPhase.flags & PhaseDescriptor.SKIP) != 0) {
- operation("skipping phase " + currentPhase.name());
- } else {
- start();
- currentPhase.apply(this);
- stop(currentPhase.taskDescription());
- }
- if ((currentPhase.flags & PhaseDescriptor.PRINT) != 0)
+ start();
+ currentPhase.apply(units);
+ stop(currentPhase.descriptor.taskDescription());
+ if (currentPhase.descriptor.hasPrintFlag())
currentPhase.print(this);
- if ((currentPhase.flags & PhaseDescriptor.GRAPH) != 0)
+ if (currentPhase.descriptor.hasGraphFlag())
currentPhase.graph(this);
- if ((currentPhase.flags & PhaseDescriptor.CHECK) != 0)
+ if (currentPhase.descriptor.hasCheckFlag())
currentPhase.check(this);
- if ((currentPhase.flags & PhaseDescriptor.STOP) != 0) {
- operation("stopped after phase " + currentPhase.name());
- break;
- }
- if (currentPhase == PHASE.PARSER) fix1();
- if (currentPhase == PHASE.ANALYZER) fix2();
- if (currentPhase == PHASE.ANALYZER && doc) {
+ if (currentPhase == PHASE.PARSER.phase()) fix1();
+ if (currentPhase == PHASE.ANALYZER.phase()) fix2();
+ if (currentPhase == PHASE.ANALYZER.phase() && doc) {
DocModule.apply(this);
- operation("stopped after phase " + currentPhase.name());
+ operation("stopped after phase " + currentPhase);
break;
}
}
@@ -330,22 +298,18 @@ public class Global {
/** transform a unit and stop at the current compilation phase
*/
public void transformUnit(Unit unit) {
- PhaseDescriptor oldCurrentPhase = currentPhase;
- int i = PHASE.REFCHECK.id; // or PHASE.UNCURRY.id?
+ Phase oldCurrentPhase = currentPhase;
+ int i = PHASE.REFCHECK.id(); // or PHASE.UNCURRY.id?
while ((i < oldCurrentPhase.id) && (reporter.errors() == 0)) {
currentPhase = phases[i];
- if ((currentPhase.flags & PhaseDescriptor.SKIP) != 0) {
- operation("skipping phase " + currentPhase.name());
- } else {
- start();
- currentPhase.apply(unit);
- stop(currentPhase.taskDescription());
- }
- if ((currentPhase.flags & PhaseDescriptor.PRINT) != 0)
+ start();
+ currentPhase.apply(new Unit[] {unit}); // !!! pb with Analyzer
+ stop(currentPhase.descriptor.taskDescription());
+ if (currentPhase.descriptor.hasPrintFlag())
currentPhase.print(this);
- if ((currentPhase.flags & PhaseDescriptor.GRAPH) != 0)
+ if (currentPhase.descriptor.hasGraphFlag())
currentPhase.graph(this);
- if ((currentPhase.flags & PhaseDescriptor.CHECK) != 0)
+ if (currentPhase.descriptor.hasCheckFlag())
currentPhase.check(this);
}
currentPhase = oldCurrentPhase;
@@ -400,7 +364,7 @@ public class Global {
}
for (int i = 0; i < imports.size(); i++) {
Symbol module = (Symbol)imports.get(i);
- PHASE.ANALYZER.addConsoleImport(this, module);
+ ((scalac.typechecker.AnalyzerPhase)PHASE.ANALYZER.phase()).addConsoleImport(this, module);
}
}
@@ -578,7 +542,7 @@ public class Global {
// the boolean return value is here to let one write "assert log( ... )"
public boolean log(String message) {
if (log()) {
- reporter.report("[log " + currentPhase.name() + "] " + message);
+ reporter.report("[log " + currentPhase + "] " + message);
}
return true;
}
@@ -586,7 +550,7 @@ public class Global {
/** return true if logging is switched on for the current phase
*/
public boolean log() {
- return (currentPhase.flags & PhaseDescriptor.LOG) != 0;
+ return currentPhase.descriptor.hasLogFlag();
}
/** start a new timer
diff --git a/sources/scalac/Main.java b/sources/scalac/Main.java
index 5816156ae6..7583f316d3 100644
--- a/sources/scalac/Main.java
+++ b/sources/scalac/Main.java
@@ -26,7 +26,7 @@ public class Main {
public static void main(String[] args) {
Reporter reporter = new Reporter();
CompilerCommand command = new CompilerCommand(
- PRODUCT, VERSION, reporter, new PhaseRepository());
+ PRODUCT, VERSION, reporter, new CompilerPhases());
if (command.parse(args) && command.files.list.size() > 0) {
Global global = new Global(command);
global.compile(command.files.toArray(), false);
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();
+ }
+
+ //########################################################################
+}
diff --git a/sources/scalac/PhaseDescriptor.java b/sources/scalac/PhaseDescriptor.java
index e555383fac..17c296f3d6 100644
--- a/sources/scalac/PhaseDescriptor.java
+++ b/sources/scalac/PhaseDescriptor.java
@@ -8,153 +8,180 @@
package scalac;
-import java.util.*;
-import scalac.ast.printer.*;
-import scalac.ast.*;
-import scalac.symtab.*;
-import scalac.checkers.*;
-import java.io.PrintWriter;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
-/**
- * Information about a compiler phase.
- *
- * @author Michel Schinz
- */
+import scalac.util.Debug;
-public abstract class PhaseDescriptor {
+/** Information about a compiler phase. */
+public final class PhaseDescriptor {
- private static class InitialPhaseDescriptor extends PhaseDescriptor {
+ //########################################################################
+ // Public Constants
- public String name() {
- return "initial";
- }
-
- public String description() {
- return "initializing compiler";
- }
-
- /** apply phase to all compilation units
- */
- public void apply(Global global) {}
-
- public void apply(Unit unit) {}
- }
+ public static final int STOP = 0x0001;
+ public static final int SKIP = 0x0002;
+ public static final int PRINT = 0x0004;
+ public static final int GRAPH = 0x0008;
+ public static final int CHECK = 0x0010;
+ public static final int LOG = 0x0020;
- private static class TerminalPhaseDescriptor extends PhaseDescriptor {
+ //########################################################################
+ // Public Functions
- public String name() {
- return "terminal";
+ /** Freezes the given phases (patches flags and assigns ids). */
+ public static void freeze(PhaseDescriptor[] phases) {
+ if (phases.length == 0) return;
+ // propagate STOP and SKIP
+ for (int i = 0; i < phases.length - 1; i++) {
+ phases[i].flags |= (phases[i + 1].flags >>> 16) & (STOP | SKIP);
+ phases[i+1].flags &= ~((STOP | SKIP) << 16);
}
-
- public String description() {
- return "compilation terminated ";
+ // add SKIP flags implied by STOP flag
+ boolean stop = false;
+ for (int i = 0; i < phases.length; i++) {
+ stop |= phases[i].hasStopFlag();
+ if (stop) phases[i].flags |= SKIP;
+ }
+ // propagate other flags and freeze remaing phases
+ PhaseDescriptor last = null;
+ for (int i = 0; i < phases.length; i++) {
+ if (phases[i].hasSkipFlag()) continue;
+ if (last != null) last.flags |= phases[i].flags >>> 16;
+ phases[i].flags &= 0x0000FFFF;
+ phases[i].freeze(last);
+ last = phases[i];
}
-
- /** apply phase to all compilation units
- */
- public void apply(Global global) {}
-
- public void apply(Unit unit) {}
}
- 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;
+ //########################################################################
+ // Private Fields
+
+ /** The phase name */
+ private final String name;
+ /** The phase description */
+ private final String description;
+ /** The phase task description */
+ private final String task;
+ /** The phase implementation class */
+ private final Class clasz;
+
+ /** The flags of this phase */
+ private int flags;
+ /** The phase instance */
+ private Phase phase;
+ /** The phase identifier */
+ private int id = -1;
+
+ //########################################################################
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public PhaseDescriptor(String name, String description, String task,
+ Class clasz)
+ {
+ this.name = name;
+ this.description = description;
+ this.task = task;
+ this.clasz = clasz;
+ }
- public int flags;
- public int id;
+ //########################################################################
+ // Public Methods
- /** return a short, one-word name for the phase.
- */
- public abstract String name();
+ /** Returns the one-word name of this phase. */
+ public String name() {
+ return name;
+ }
- /** return a one-line description for the phase.
- */
- public abstract String description();
+ /** Returns a one-line description of this phase. */
+ public String description() {
+ return description;
+ }
- /** a one-line task description of this phase
- */
+ /** Returns a one-line task description of this phase. */
public String taskDescription() {
- return description();
+ return task;
}
- /** initialize the phase
- */
- public final void initialize(Global global) {
- throw new Error();
+ /** Freezes this phase by assigning it an identifier. */
+ public void freeze(PhaseDescriptor prev) {
+ assert id < 0 : "phase " + name + " already frozen";
+ id = prev != null ? prev.id + 1 : 0;
}
- public void initialize(Global global, int id) {
- this.id = id;
+
+ /** Creates the object implementing this phase. */
+ public Phase create(Global global) {
+ assert id >= 0 : "phase " + name + " not yet frozen";
+ assert phase == null : "phase " + name + " already created";
+ try {
+ Class[] params = { Global.class, PhaseDescriptor.class };
+ Object[] args = { global, this };
+ Constructor constructor = clasz.getConstructor(params);
+ return phase = (Phase)constructor.newInstance(args);
+ } catch (NoSuchMethodException exception) {
+ throw Debug.abort(exception);
+ } catch (IllegalAccessException exception) {
+ throw Debug.abort(exception);
+ } catch (InstantiationException exception) {
+ throw Debug.abort(exception);
+ } catch (InvocationTargetException exception) {
+ throw Debug.abort(exception);
+ }
}
- /** 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;
+ /** Returns the object implementing this phase. */
+ public Phase phase() {
+ assert phase != null : "phase " + name + " not yet created";
+ return phase;
}
- /** apply phase to all compilation units
- */
- public abstract void apply(Global global);
+ /** Returns the identifier of this phase. */
+ public int id() {
+ assert id >= 0 : "phase " + name + " not yet frozen";
+ return id;
+ }
- /** apply this phase to a compilation unit
- */
- public abstract void apply(Unit unit);
+ /** Adds the given flag (to previous phase if prev is true). */
+ public void addFlag(int flag, boolean prev) {
+ assert id < 0 : "phase " + name + " already frozen";
+ flags |= flag << (prev ? 16 : 0);
+ }
- /** check all compilation units
- */
- public void check(Global global) {
- for (int i = 0; i < global.units.length; i++)
- check(global.units[i]);
+ /** Has this phase the SKIP flag? */
+ public boolean hasSkipFlag() {
+ return (flags & SKIP) != 0;
}
- /** 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]);
+ /** Has this phase the CHECK flag? */
+ public boolean hasCheckFlag() {
+ return (flags & CHECK) != 0;
}
- /** graph all compilation units
- */
- public void graph(Global global) {
- for (int i = 0; i < global.units.length; i++)
- graph(global.units[i]);
+ /** Has this phase the PRINT flag? */
+ public boolean hasPrintFlag() {
+ return (flags & PRINT) != 0;
}
- /** return an array of checkers which can be applied after the phase
- */
- public Checker[] postCheckers(Global global) {
- return new Checker[0];
+ /** Has this phase the GRAPH flag? */
+ public boolean hasGraphFlag() {
+ return (flags & GRAPH) != 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);
+ /** Has this phase the STOP flag? */
+ public boolean hasStopFlag() {
+ return (flags & STOP) != 0;
}
- /** 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");
- */
+ /** Has this phase the LOG flag? */
+ public boolean hasLogFlag() {
+ return (flags & LOG) != 0;
}
+ /** Returns the name of this phase. */
public String toString() {
return name();
}
+
+ //########################################################################
}
diff --git a/sources/scalac/PhaseRepository.java b/sources/scalac/PhaseRepository.java
deleted file mode 100644
index c730479d87..0000000000
--- a/sources/scalac/PhaseRepository.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac;
-
-import scalac.ast.parser.ParserPhase;
-import scalac.typechecker.AnalyzerPhase;
-import scalac.typechecker.RefCheckPhase;
-import scalac.transformer.UnCurryPhase;
-import scalac.transformer.TransMatchPhase;
-import scalac.transformer.LambdaLiftPhase;
-import scalac.transformer.ExplicitOuterClassesPhase;
-import scalac.transformer.AddAccessorsPhase;
-import scalac.transformer.AddInterfacesPhase;
-import scalac.transformer.ExpandMixinsPhase;
-import scalac.transformer.ErasurePhase;
-import scalac.transformer.AddConstructorsPhase;
-/*
-import scalac.optimizer.OptimizePhase;
-*/
-import scalac.backend.jvm.GenJVMPhase;
-import scalac.backend.jvm.GenJVMBCELPhase;
-import scalac.backend.msil.GenMSILPhase;
-
-public class PhaseRepository {
-
- //########################################################################
- // Private state
-
- public final PhaseDescriptor[] phases;
-
- //########################################################################
- // Reporter constructors
-
- public PhaseRepository() {
- this.phases = new PhaseDescriptor[] {
- INITIAL = PhaseDescriptor.INITIAL,
- PARSER = new ParserPhase(),
- ANALYZER = new AnalyzerPhase(),
- REFCHECK = new RefCheckPhase(),
- UNCURRY = new UnCurryPhase(),
- /*
- OPTIMIZE = new OptimizePhase(),
- */
- TRANSMATCH = new TransMatchPhase(),
- LAMBDALIFT = new LambdaLiftPhase(),
- EXPLICITOUTER = new ExplicitOuterClassesPhase(),
- ADDACCESSORS = new AddAccessorsPhase(),
- ADDINTERFACES = new AddInterfacesPhase(),
- EXPANDMIXIN = new ExpandMixinsPhase(),
- ERASURE = new ErasurePhase(),
- ADDCONSTRUCTORS = new AddConstructorsPhase(),
- GENJVM = new GenJVMPhase(),
- GENJVM_BCEL = new GenJVMBCELPhase(),
- GENMSIL = new GenMSILPhase(),
- TERMINAL = PhaseDescriptor.TERMINAL,
- };
- }
-
- //########################################################################
- // Reporter interface
-
- public final PhaseDescriptor INITIAL;
- public final ParserPhase PARSER;
- public final AnalyzerPhase ANALYZER;
- public final RefCheckPhase REFCHECK;
- public final UnCurryPhase UNCURRY;
- /*
- public final OptimizePhase OPTIMIZE;
- */
- public final TransMatchPhase TRANSMATCH;
- public final LambdaLiftPhase LAMBDALIFT;
- public final ExplicitOuterClassesPhase EXPLICITOUTER;
- public final AddAccessorsPhase ADDACCESSORS;
- public final AddInterfacesPhase ADDINTERFACES;
- public final ExpandMixinsPhase EXPANDMIXIN;
- public final ErasurePhase ERASURE;
- public final AddConstructorsPhase ADDCONSTRUCTORS;
- public final GenJVMPhase GENJVM;
- public final GenJVMBCELPhase GENJVM_BCEL;
- public final GenMSILPhase GENMSIL;
- public final PhaseDescriptor TERMINAL;
-
- //########################################################################
-}
diff --git a/sources/scalac/ast/Transformer.java.tmpl b/sources/scalac/ast/Transformer.java.tmpl
index 9e83e34b18..970ecfa00d 100644
--- a/sources/scalac/ast/Transformer.java.tmpl
+++ b/sources/scalac/ast/Transformer.java.tmpl
@@ -54,10 +54,6 @@ public class Transformer {
//########################################################################
// Public Methods
- public void apply() {
- apply(global.units);
- }
-
public void apply(Unit[] units) {
for (int i = 0; i < units.length; i++) apply(units[i]);
}
diff --git a/sources/scalac/ast/parser/ParserPhase.java b/sources/scalac/ast/parser/ParserPhase.java
index 1a1dde1ffe..1355b3926d 100644
--- a/sources/scalac/ast/parser/ParserPhase.java
+++ b/sources/scalac/ast/parser/ParserPhase.java
@@ -9,31 +9,31 @@
package scalac.ast.parser;
import scalac.Global;
-import scalac.Unit;
+import scalac.Phase;
import scalac.PhaseDescriptor;
+import scalac.Unit;
-public class ParserPhase extends PhaseDescriptor {
-
- public String name() {
- return "parse";
- }
+public class ParserPhase extends Phase {
- public String description () {
- return "parse source files";
- }
+ //########################################################################
+ // Public Constructors
- public String taskDescription() {
- return "parsed";
+ /** Initializes this instance. */
+ public ParserPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
}
- public void apply(Global global) {
- for (int i = 0; i < global.units.length; i++) apply(global.units[i]);
- }
+ //########################################################################
+ // Public Methods
- public void apply(Unit unit) {
- unit.global.start();
- unit.body = new Parser(unit).parse();
- unit.global.stop("parsed " + unit.source);
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++) {
+ global.start();
+ units[i].body = new Parser(units[i]).parse();
+ global.stop("parsed " + units[i].source);
+ }
}
+ //########################################################################
}
diff --git a/sources/scalac/backend/jvm/GenJVMBCELPhase.java b/sources/scalac/backend/jvm/GenJVMBCELPhase.java
index 4ef402fd86..3d1b50a77e 100644
--- a/sources/scalac/backend/jvm/GenJVMBCELPhase.java
+++ b/sources/scalac/backend/jvm/GenJVMBCELPhase.java
@@ -9,31 +9,42 @@
package scalac.backend.jvm;
import scalac.Global;
-import scalac.Unit;
+import scalac.Phase;
import scalac.PhaseDescriptor;
-import scalac.ApplicationError;
+import scalac.Unit;
-public class GenJVMBCELPhase extends PhaseDescriptor {
+/**
+ * Phase to generate Java bytecodes using the BCEL library.
+ *
+ * @author Michel Schinz
+ * @version 1.0
+ */
- public String name () {
- return "genjvm-bcel";
- }
+public class GenJVMBCELPhase extends Phase {
- public String description () {
- return "generate JVM bytecodes";
- }
+ //########################################################################
+ // Private Fields
- public String taskDescription() {
- return "generated JVM code";
- }
+ /** The tree to code translator */
+ private final GenJVMBCEL translator;
+
+ //########################################################################
+ // Public Constructors
- public void apply(Global global) {
- for (int i = 0; i < global.units.length; i++)
- apply(global.units[i]);
+ /** Initializes this instance. */
+ public GenJVMBCELPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
+ this.translator = new GenJVMBCEL(global);
}
- public void apply(Unit unit) {
- new GenJVMBCEL(unit.global).translate(unit);
+ //########################################################################
+ // Public Methods
+
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++) translator.translate(units[i]);
}
+
+ //########################################################################
}
diff --git a/sources/scalac/backend/jvm/GenJVMPhase.java b/sources/scalac/backend/jvm/GenJVMPhase.java
index 6087cfb2e1..9fb1c72e89 100644
--- a/sources/scalac/backend/jvm/GenJVMPhase.java
+++ b/sources/scalac/backend/jvm/GenJVMPhase.java
@@ -9,9 +9,9 @@
package scalac.backend.jvm;
import scalac.Global;
-import scalac.Unit;
+import scalac.Phase;
import scalac.PhaseDescriptor;
-import scalac.ApplicationError;
+import scalac.Unit;
/**
* Phase to generate Java bytecodes using the FJBG library.
@@ -20,26 +20,30 @@ import scalac.ApplicationError;
* @version 1.0
*/
-public class GenJVMPhase extends PhaseDescriptor {
+public class GenJVMPhase extends Phase {
- public String name () {
- return "genjvm";
- }
+ //########################################################################
+ // Private Fields
- public String description () {
- return "generate JVM bytecodes";
- }
+ /** The tree to code translator */
+ private final GenJVM translator;
- public String taskDescription() {
- return "generated JVM code";
- }
+ //########################################################################
+ // Public Constructors
- public void apply(Global global) {
- for (int i = 0; i < global.units.length; i++)
- apply(global.units[i]);
+ /** Initializes this instance. */
+ public GenJVMPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
+ this.translator = new GenJVM(global);
}
- public void apply(Unit unit) {
- new GenJVM(unit.global).translate(unit);
+ //########################################################################
+ // Public Methods
+
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++) translator.translate(units[i]);
}
+
+ //########################################################################
}
diff --git a/sources/scalac/backend/msil/GenMSILPhase.java b/sources/scalac/backend/msil/GenMSILPhase.java
index 0e814e2346..6ba91bf7eb 100644
--- a/sources/scalac/backend/msil/GenMSILPhase.java
+++ b/sources/scalac/backend/msil/GenMSILPhase.java
@@ -9,12 +9,19 @@
package scalac.backend.msil;
import scalac.Global;
-import scalac.Unit;
+import scalac.Phase;
import scalac.PhaseDescriptor;
+import scalac.Unit;
import java.util.HashMap;
-public class GenMSILPhase extends PhaseDescriptor {
+public class GenMSILPhase extends Phase {
+
+ //########################################################################
+ // Private Fields
+
+ /** The tree to code translator */
+ private final GenMSIL translator;
final HashMap assemblies = new HashMap();
@@ -24,23 +31,22 @@ public class GenMSILPhase extends PhaseDescriptor {
final HashMap symbols2methods = new HashMap();
final HashMap symbols2moduleFields = new HashMap();
- public String name () {
- return "genmsil";
- }
+ //########################################################################
+ // Public Constructors
- public String description () {
- return "generate MSIL code";
+ /** Initializes this instance. */
+ public GenMSILPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
+ this.translator = new GenMSIL(global, this);
}
- public String taskDescription() {
- return "generated MSIL code";
- }
+ //########################################################################
+ // Public Methods
- public void apply(Global global) {
- new GenMSIL(global, this).apply();
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++) translator.apply(units[i]);
}
- public void apply(Unit unit) {
- new GenMSIL(unit.global, this).apply(unit);
- }
+ //########################################################################
}
diff --git a/sources/scalac/checkers/CheckTreeNodes.java.tmpl b/sources/scalac/checkers/CheckTreeNodes.java.tmpl
index e0b66a0eb4..ca07b23cbd 100644
--- a/sources/scalac/checkers/CheckTreeNodes.java.tmpl
+++ b/sources/scalac/checkers/CheckTreeNodes.java.tmpl
@@ -9,7 +9,7 @@
package scalac.checkers;
import scalac.Global;
-import scalac.symtab.Symbol;
+import scalac.CompilerPhases;
{#Imports#}
/** Class to check tree nodes. */
@@ -24,6 +24,7 @@ public class CheckTreeNodes {
// Private Fields
private final Global global = Global.instance;
+ private final CompilerPhases phases = global.PHASE;
//########################################################################
// Public Methods
diff --git a/sources/scalac/symtab/SourceCompleter.java b/sources/scalac/symtab/SourceCompleter.java
index 43a8ec8a10..51e5d7437f 100644
--- a/sources/scalac/symtab/SourceCompleter.java
+++ b/sources/scalac/symtab/SourceCompleter.java
@@ -12,7 +12,7 @@ import ch.epfl.lamp.util.SourceFile;
import scalac.*;
import scalac.ast.parser.*;
-import scalac.typechecker.Analyzer;
+import scalac.typechecker.AnalyzerPhase;
import java.io.*;
@@ -39,8 +39,8 @@ public class SourceCompleter extends Type.LazyType {
c.fullName()) + ".scala";
java.io.File f = global.classPath.openJavaFile(filename);
Unit unit = new Unit(global, new SourceFile(f), false);
- global.PHASE.PARSER.apply(unit);
- global.PHASE.ANALYZER.lateEnter(global, unit, c);
+ global.PHASE.PARSER.phase().apply(new Unit[] {unit});
+ ((AnalyzerPhase)global.PHASE.ANALYZER.phase()).lateEnter(global, unit, c);
global.operation("added " + filename + " in " +
(System.currentTimeMillis() - msec) + "ms");
} catch (IOException e) {
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index 2e3ebbbf90..5abc022439 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -13,7 +13,7 @@ package scalac.symtab;
import ch.epfl.lamp.util.Position;
import scalac.ApplicationError;
import scalac.Global;
-import scalac.PhaseDescriptor;
+import scalac.Phase;
import scalac.util.ArrayApply;
import scalac.util.Name;
import scalac.util.Names;
@@ -676,7 +676,7 @@ public abstract class Symbol implements Modifiers, Kinds {
assert infos != TypeIntervalList.EMPTY : this;
int nextid = infos.limit;
if (nextid < id) {
- PhaseDescriptor curphase = Global.instance.currentPhase;
+ Phase curphase = Global.instance.currentPhase;
do {
Global.instance.currentPhase = Global.instance.phases[nextid];
Type newInfo =
@@ -1290,7 +1290,7 @@ public abstract class TypeSymbol extends Symbol {
//todo: needed?
private Type[] closureAt(int id) {
- PhaseDescriptor savedPhase = Global.instance.currentPhase;
+ Phase savedPhase = Global.instance.currentPhase;
Global.instance.currentPhase = Global.instance.phases[id];
Type[] c = closure();
Global.instance.currentPhase = savedPhase;
diff --git a/sources/scalac/transformer/AddAccessorsPhase.java b/sources/scalac/transformer/AddAccessorsPhase.java
index 61bb92c912..59497a0972 100644
--- a/sources/scalac/transformer/AddAccessorsPhase.java
+++ b/sources/scalac/transformer/AddAccessorsPhase.java
@@ -9,30 +9,29 @@
package scalac.transformer;
-import scalac.*;
+import scalac.Global;
+import scalac.Phase;
+import scalac.PhaseDescriptor;
+import scalac.Unit;
import scalac.checkers.*;
-import java.util.*;
+public class AddAccessorsPhase extends Phase {
-public class AddAccessorsPhase extends PhaseDescriptor {
- public String name () {
- return "addaccessors";
- }
+ //########################################################################
+ // Public Constructors
- public String description () {
- return "add accessors for constructor arguments";
+ /** Initializes this instance. */
+ public AddAccessorsPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
}
- public String taskDescription() {
- return "added accessors";
- }
+ //########################################################################
+ // Public Methods
- public void apply(Global global) {
- new AddAccessors(global).apply();
- }
-
- public void apply(Unit unit) {
- new AddAccessors(unit.global).apply(unit);
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++)
+ new AddAccessors(global).apply(units[i]);
}
public Checker[] postCheckers(Global global) {
@@ -43,4 +42,6 @@ public class AddAccessorsPhase extends PhaseDescriptor {
new CheckNames(global)
};
}
+
+ //########################################################################
}
diff --git a/sources/scalac/transformer/AddConstructorsPhase.java b/sources/scalac/transformer/AddConstructorsPhase.java
index 81a74b9d58..3bc86ffba5 100644
--- a/sources/scalac/transformer/AddConstructorsPhase.java
+++ b/sources/scalac/transformer/AddConstructorsPhase.java
@@ -10,34 +10,36 @@
package scalac.transformer;
import java.util.HashMap;
-import scalac.*;
-import scalac.checkers.*;
+import scalac.Global;
+import scalac.Phase;
+import scalac.PhaseDescriptor;
+import scalac.Unit;
+import scalac.checkers.*;
-public class AddConstructorsPhase extends PhaseDescriptor {
+public class AddConstructorsPhase extends Phase {
- /** Maps the old constructor symbols to the new ones
- */
- HashMap constructors = new HashMap();
+ //########################################################################
+ // Private Fields
- public String name() {
- return "addconstructors";
- }
+ /** A maps from old constructor symbols to new ones */
+ private final HashMap/*<Symbol,Symbol>*/ constructors = new HashMap();
- public String description() {
- return "add explicit constructor for each class";
- }
+ //########################################################################
+ // Public Constructors
- public String taskDescription() {
- return "added constructors";
+ /** Initializes this instance. */
+ public AddConstructorsPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
}
- public void apply(Global global) {
- new AddConstructors(global, constructors).apply();
- }
+ //########################################################################
+ // Public Methods
- public void apply(Unit unit) {
- new AddConstructors(unit.global, constructors).apply(unit);
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++)
+ new AddConstructors(global, constructors).apply(units[i]);
}
public Checker[] postCheckers(Global global) {
@@ -48,4 +50,6 @@ public class AddConstructorsPhase extends PhaseDescriptor {
new CheckNames(global)
};
}
+
+ //########################################################################
}
diff --git a/sources/scalac/transformer/AddInterfacesPhase.java b/sources/scalac/transformer/AddInterfacesPhase.java
index fbbed6a98d..4df6c4bac7 100644
--- a/sources/scalac/transformer/AddInterfacesPhase.java
+++ b/sources/scalac/transformer/AddInterfacesPhase.java
@@ -18,25 +18,17 @@ import scalac.util.Name;
import java.util.*;
import scalac.util.Debug;
-public class AddInterfacesPhase extends PhaseDescriptor {
- public String name () {
- return "addinterfaces";
- }
-
- public String description () {
- return "add one interface per class";
- }
-
- public String taskDescription() {
- return "added interfaces";
- }
+public class AddInterfacesPhase extends Phase {
- public void apply(Global global) {
- new AddInterfaces(global, this).apply();
+ /** Initializes this instance. */
+ public AddInterfacesPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
}
- public void apply(Unit unit) {
- new AddInterfaces(unit.global, this).apply(unit);
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++)
+ new AddInterfaces(global, this).apply(units[i]);
}
public Type transformInfo(Symbol sym, Type tp) {
diff --git a/sources/scalac/transformer/ErasurePhase.java b/sources/scalac/transformer/ErasurePhase.java
index 8accd1ed9a..bd90b57eb8 100644
--- a/sources/scalac/transformer/ErasurePhase.java
+++ b/sources/scalac/transformer/ErasurePhase.java
@@ -10,7 +10,9 @@
package scalac.transformer;
import scalac.Global;
-import scalac.*;
+import scalac.Phase;
+import scalac.PhaseDescriptor;
+import scalac.Unit;
import scalac.backend.Primitive;
import scalac.backend.Primitives;
import scalac.checkers.Checker;
@@ -23,46 +25,30 @@ import scalac.symtab.Symbol;
import scalac.symtab.Type;
import scalac.util.Debug;
-public class ErasurePhase extends PhaseDescriptor {
+public class ErasurePhase extends Phase {
- public Definitions definitions;
- public Primitives primitives;
+ //########################################################################
+ // Private Fields
- public String name () {
- return "erasure";
- }
-
- public String description () {
- return "type eraser";
- }
+ private final Definitions definitions;
+ private final Primitives primitives;
+ private final Erasure erasure;
- public String taskDescription() {
- return "erased types";
- }
+ //########################################################################
+ // Public Constructors
- public void apply(Global global) {
+ public ErasurePhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
this.definitions = global.definitions;
this.primitives = global.primitives;
- new Erasure(global).apply();
+ this.erasure = new Erasure(global);
}
- public void apply(Unit unit) {
- this.definitions = unit.global.definitions;
- this.primitives = unit.global.primitives;
- new Erasure(unit.global).apply(unit);
- }
+ //########################################################################
+ // Public Methods
- private Type eraseParams(Type tp) {
- switch (tp) {
- case PolyType(_, Type result):
- return eraseParams(result);
- case MethodType(Symbol[] params, Type result):
- Symbol[] params1 = Type.erasureMap.map(params);
- if (params1 == params) return tp;
- else return Type.MethodType(params1, result);
- default:
- return tp;
- }
+ public void apply(Unit[] units) {
+ erasure.apply(units);
}
public Type transformInfo(Symbol sym, Type tp) {
@@ -85,4 +71,22 @@ public class ErasurePhase extends PhaseDescriptor {
new CheckNames(global)
};
}
+
+ //########################################################################
+ // Private Methods
+
+ private Type eraseParams(Type tp) {
+ switch (tp) {
+ case PolyType(_, Type result):
+ return eraseParams(result);
+ case MethodType(Symbol[] params, Type result):
+ Symbol[] params1 = Type.erasureMap.map(params);
+ if (params1 == params) return tp;
+ else return Type.MethodType(params1, result);
+ default:
+ return tp;
+ }
+ }
+
+ //########################################################################
}
diff --git a/sources/scalac/transformer/ExpandMixinsPhase.java b/sources/scalac/transformer/ExpandMixinsPhase.java
index 8824559336..ba0f43bd25 100644
--- a/sources/scalac/transformer/ExpandMixinsPhase.java
+++ b/sources/scalac/transformer/ExpandMixinsPhase.java
@@ -12,8 +12,9 @@ package scalac.transformer;
import java.util.Map;
import java.util.HashMap;
-import scalac.PhaseDescriptor;
import scalac.Global;
+import scalac.Phase;
+import scalac.PhaseDescriptor;
import scalac.Unit;
import scalac.ast.Tree;
import scalac.ast.Tree.Template;
@@ -21,6 +22,7 @@ import scalac.ast.Traverser;
import scalac.ast.Transformer;
import scalac.symtab.Symbol;
import scalac.symtab.Type;
+import scalac.checkers.*;
import scalac.util.Debug;
// TODO do not copy hidden members which are not accessible via
@@ -30,59 +32,43 @@ import scalac.util.Debug;
* A phase to expand mixins using code copying. We assume that links
* to outer classes have been made explicit by a previous phase.
*/
-public class ExpandMixinsPhase extends PhaseDescriptor {
+public class ExpandMixinsPhase extends Phase {
//########################################################################
// Private Fields
- /** The global environment */
- private Global global;
-
/** A map from classes to their interface */
- private Map interfaces;
+ private final Map/*<Symbol,Symbol>*/ interfaces;
/** A map from classes to their expanded template */
- private final Map/*<Symbol,Template>*/ expansions = new HashMap();
+ private final Map/*<Symbol,Template>*/ expansions;
/** A map from classes to their original (unexpanded) template */
- private final Map/*<Symbol,Template>*/ templates = new HashMap();
-
+ private final Map/*<Symbol,Template>*/ templates;
/** A traverser that collects class definitions */
- private Traverser collector;
+ private final Traverser collector;
/** A transformer that expands classes that have mixins */
- private Transformer expander;
+ private final Transformer expander;
//########################################################################
- // Public Methods
-
- public String name () {
- return "expandmixins";
- }
-
- public String description () {
- return "expand mixins by code copying";
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public ExpandMixinsPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
+ Phase addinterfaces = global.PHASE.ADDINTERFACES.phase();
+ this.interfaces = ((AddInterfacesPhase)addinterfaces).classToIFace;
+ this.expansions = new HashMap();
+ this.templates = new HashMap();
+ this.collector = new Collector();
+ this.expander = new Expander(global);
}
- public String taskDescription() {
- return "expanded mixins";
- }
-
- public void apply(Global global) {
- apply(global, global.units);
- }
-
- public void apply(Unit unit) {
- apply(unit.global, new Unit[] { unit });
- }
+ //########################################################################
+ // Public Methods
- public void apply(Global global, Unit[] units) {
- if (this.global == null) {
- this.global = global;
- this.interfaces = global.PHASE.ADDINTERFACES.classToIFace;
- this.collector = new Collector();
- this.expander = new Expander(global);
- }
+ public void apply(Unit[] units) {
collector.traverse(units);
expander.apply(units);
assert templates.isEmpty() : templates.keySet();
@@ -95,15 +81,14 @@ public class ExpandMixinsPhase extends PhaseDescriptor {
return type;
}
- // !!!
- // public Checker[] postCheckers(Global global) {
- // return new Checker[] {
- // new CheckSymbols(global),
- // new CheckTypes(global),
- // new CheckOwners(global),
- // new CheckNames(global)
- // };
- // }
+ public Checker[] postCheckers(Global global) {
+ return new Checker[] {
+ new CheckSymbols(global),
+ new CheckTypes(global),
+ new CheckOwners(global),
+ new CheckNames(global)
+ };
+ }
//########################################################################
// Private Methods
diff --git a/sources/scalac/transformer/ExplicitOuterClasses.java b/sources/scalac/transformer/ExplicitOuterClasses.java
index a9977a11ef..47937f515a 100644
--- a/sources/scalac/transformer/ExplicitOuterClasses.java
+++ b/sources/scalac/transformer/ExplicitOuterClasses.java
@@ -32,9 +32,9 @@ public class ExplicitOuterClasses extends Transformer {
// Mapping from class constructor symbols to owner field symbols.
protected final HashMap/*<Symbol,Symbol>*/ outerMap;
- public ExplicitOuterClasses(Global global) {
+ public ExplicitOuterClasses(Global global, ExplicitOuterClassesPhase phase) {
super(global);
- this.phase = global.PHASE.EXPLICITOUTER;
+ this.phase = phase;
this.outerMap = phase.outerMap;
}
diff --git a/sources/scalac/transformer/ExplicitOuterClassesPhase.java b/sources/scalac/transformer/ExplicitOuterClassesPhase.java
index 805530bcd3..ace14302f6 100644
--- a/sources/scalac/transformer/ExplicitOuterClassesPhase.java
+++ b/sources/scalac/transformer/ExplicitOuterClassesPhase.java
@@ -15,28 +15,19 @@ import scalac.symtab.*;
import scalac.util.*;
import java.util.HashMap;
-public class ExplicitOuterClassesPhase extends PhaseDescriptor {
+public class ExplicitOuterClassesPhase extends Phase {
// Mapping from class constructor symbols to owner field symbols.
- protected HashMap/*<Symbol,Symbol>*/ outerMap = new HashMap();
+ protected final HashMap/*<Symbol,Symbol>*/ outerMap = new HashMap();
- public String name () {
- return "explicitouterclasses";
+ /** Initializes this instance. */
+ public ExplicitOuterClassesPhase(Global global,PhaseDescriptor descriptor){
+ super(global, descriptor);
}
- public String description () {
- return "make links from inner classes to enclosing one explicit";
- }
-
- public String taskDescription() {
- return "made outer links explicit";
- }
-
- public void apply(Global global) {
- new ExplicitOuterClasses(global).apply();
- }
-
- public void apply(Unit unit) {
- new ExplicitOuterClasses(unit.global).apply(unit);
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++)
+ new ExplicitOuterClasses(global, this).apply(units[i]);
}
public Checker[] postCheckers(Global global) {
diff --git a/sources/scalac/transformer/LambdaLiftPhase.java b/sources/scalac/transformer/LambdaLiftPhase.java
index a891aa0dc7..e2181c5ccf 100644
--- a/sources/scalac/transformer/LambdaLiftPhase.java
+++ b/sources/scalac/transformer/LambdaLiftPhase.java
@@ -15,37 +15,22 @@ import scalac.symtab.*;
import scalac.checkers.*;
import java.util.ArrayList;
-public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers {
+public class LambdaLiftPhase extends Phase implements Kinds, Modifiers {
- private Global global;
- int nextPhase;
+ final int nextPhase;
- public void initialize(Global global, int id) {
- super.initialize(global, id);
- this.global = global;
+ /** Initializes this instance. */
+ public LambdaLiftPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
this.nextPhase = id + 1;
}
- public String name () {
- return "lambdalift";
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++)
+ new LambdaLift(global, this).apply(units[i]);
}
- public String description () {
- return "lambda lifter";
- }
-
- public String taskDescription() {
- return "lambda lifting";
- }
-
- public void apply(Global global) {
- new LambdaLift(global, this).apply();
- }
-
- public void apply(Unit unit) {
- new LambdaLift(unit.global, this).apply(unit);
- }
-
public Type transformInfo(Symbol sym, Type tp) {
/*
if (global.debug)
diff --git a/sources/scalac/transformer/TransMatchPhase.java b/sources/scalac/transformer/TransMatchPhase.java
index 4781ad0cf9..313474e897 100644
--- a/sources/scalac/transformer/TransMatchPhase.java
+++ b/sources/scalac/transformer/TransMatchPhase.java
@@ -8,29 +8,29 @@
package scalac.transformer;
-import scalac.*;
+import scalac.Global;
+import scalac.Phase;
+import scalac.PhaseDescriptor;
+import scalac.Unit;
import scalac.checkers.*;
-public class TransMatchPhase extends PhaseDescriptor {
+public class TransMatchPhase extends Phase {
- public String name () {
- return "transmatch";
- }
+ //########################################################################
+ // Public Constructors
- public String description () {
- return "translate match expressions";
+ /** Initializes this instance. */
+ public TransMatchPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
}
- public String taskDescription() {
- return "translated pattern matching";
- }
+ //########################################################################
+ // Public Methods
- public void apply(Global global) {
- new TransMatch(global).apply();
- }
-
- public void apply(Unit unit) {
- new TransMatch(unit.global).apply(unit);
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++)
+ new TransMatch(global).apply(units[i]);
}
public Checker[] postCheckers(Global global) {
@@ -41,4 +41,6 @@ public class TransMatchPhase extends PhaseDescriptor {
new CheckNames(global)
};
}
+
+ //########################################################################
}
diff --git a/sources/scalac/transformer/UnCurryPhase.java b/sources/scalac/transformer/UnCurryPhase.java
index d9ae38ba4e..ce5bf61287 100644
--- a/sources/scalac/transformer/UnCurryPhase.java
+++ b/sources/scalac/transformer/UnCurryPhase.java
@@ -14,33 +14,17 @@ import scalac.symtab.*;
import scalac.typechecker.Infer;
import scalac.checkers.*;
-public class UnCurryPhase extends PhaseDescriptor implements Modifiers {
+public class UnCurryPhase extends Phase implements Modifiers {
- private Global global;
-
- public void initialize(Global global, int id) {
- super.initialize(global, id);
- this.global = global;
- }
-
- public String name () {
- return "uncurry";
- }
-
- public String description () {
- return "uncurry function types and applications";
- }
-
- public String taskDescription() {
- return "uncurried";
- }
-
- public void apply(Global global) {
- new UnCurry(global, this).apply();
+ /** Initializes this instance. */
+ public UnCurryPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
}
- public void apply(Unit unit) {
- new UnCurry(unit.global, this).apply(unit);
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++)
+ new UnCurry(global, this).apply(units[i]);
}
/** - return symbol's transformed type,
diff --git a/sources/scalac/transformer/matching/AlgebraicMatcher.java b/sources/scalac/transformer/matching/AlgebraicMatcher.java
index aba3f9d90b..b94521bb43 100644
--- a/sources/scalac/transformer/matching/AlgebraicMatcher.java
+++ b/sources/scalac/transformer/matching/AlgebraicMatcher.java
@@ -109,7 +109,7 @@ public class AlgebraicMatcher extends PatternTool {
/** return the analyzed type
*/
public Type typeOf0(Symbol sym) {
- return sym.typeAt(unit.global.PHASE.ANALYZER.id);
+ return sym.typeAt(unit.global.PHASE.ANALYZER.id());
}
/** factories
diff --git a/sources/scalac/transformer/matching/CodeFactory.java b/sources/scalac/transformer/matching/CodeFactory.java
index 425fd4c9ac..b8d5b08ca4 100644
--- a/sources/scalac/transformer/matching/CodeFactory.java
+++ b/sources/scalac/transformer/matching/CodeFactory.java
@@ -414,7 +414,7 @@ class CodeFactory extends PatternTool {
/** return the analyzed type
*/
public Type typeOf0(Symbol sym) {
- return sym.typeAt(unit.global.PHASE.ANALYZER.id);
+ return sym.typeAt(unit.global.PHASE.ANALYZER.id());
}
diff --git a/sources/scalac/transformer/matching/PatternMatcher.java b/sources/scalac/transformer/matching/PatternMatcher.java
index 6e0cc8f069..7960bdabcd 100644
--- a/sources/scalac/transformer/matching/PatternMatcher.java
+++ b/sources/scalac/transformer/matching/PatternMatcher.java
@@ -114,7 +114,7 @@ public class PatternMatcher extends PatternTool {
/** return the analyzed type
*/
public Type typeOf0(Symbol sym) {
- return sym.typeAt(unit.global.PHASE.ANALYZER.id);
+ return sym.typeAt(unit.global.PHASE.ANALYZER.id());
}
//
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index 1398d150c4..296f20dc76 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -54,11 +54,13 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
private boolean inAlternative; // for pattern matching;
private HashMap patternVars; // for pattern matching; maps x to {true,false}
- public void apply() {
- for (int i = 0; i < global.units.length; i++) {
- enterUnit(global.units[i]);
- }
- super.apply(); // this calls apply(u) for every unit `u'.
+ public void apply(Unit[] units) {
+// for (int i = 0; i < units.length; i++) {
+// enterUnit(global.units[i]);
+// }
+// super.apply(units); // this calls apply(u) for every unit `u'.
+ for (int i = 0; i < units.length; i++) enterUnit(units[i]);
+ super.apply(units); // this calls apply(u) for every unit `u'.
int n = descr.newSources.size();
while (n > 0) {
int l = global.units.length;
diff --git a/sources/scalac/typechecker/AnalyzerPhase.java b/sources/scalac/typechecker/AnalyzerPhase.java
index 158b7dd530..2b7d0fa886 100644
--- a/sources/scalac/typechecker/AnalyzerPhase.java
+++ b/sources/scalac/typechecker/AnalyzerPhase.java
@@ -17,15 +17,16 @@ import scalac.checkers.*;
import java.util.HashMap;
import java.util.ArrayList;
-public class AnalyzerPhase extends PhaseDescriptor {
+public class AnalyzerPhase extends Phase {
- /* final */ Context startContext;
- /* final */ Context consoleContext;
- HashMap/*<Unit,Context>*/ contexts = new HashMap();
- ArrayList/*<Unit>*/ newSources = new ArrayList();
+ final Context startContext;
+ final Context consoleContext;
+ final HashMap/*<Unit,Context>*/ contexts = new HashMap();
+ final ArrayList/*<Unit>*/ newSources = new ArrayList();
- public void initialize(Global global, int id) {
- super.initialize(global, id);
+ /** Initializes this instance. */
+ public AnalyzerPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
Definitions definitions = global.definitions;
this.startContext = new Context(
Tree.Empty,
@@ -102,24 +103,8 @@ public class AnalyzerPhase extends PhaseDescriptor {
importConsole, new Scope(), consoleContext.imports);
}
- public String name() {
- return "analyze";
- }
-
- public String description () {
- return "name and type analysis";
- }
-
- public String taskDescription() {
- return "type checking";
- }
-
- public void apply(Global global) {
- new Analyzer(global, this).apply();
- }
-
- public void apply(Unit unit) {
- new Analyzer(unit.global, this).apply(unit);
+ public void apply(Unit[] units) {
+ new Analyzer(global, this).apply(units);
}
public void lateEnter(Global global, Unit unit, Symbol symbol) {
diff --git a/sources/scalac/typechecker/RefCheckPhase.java b/sources/scalac/typechecker/RefCheckPhase.java
index bfaa1e4fc4..7749e4b357 100644
--- a/sources/scalac/typechecker/RefCheckPhase.java
+++ b/sources/scalac/typechecker/RefCheckPhase.java
@@ -12,26 +12,17 @@ import scalac.*;
import scalac.ast.*;
import scalac.checkers.*;
-public class RefCheckPhase extends PhaseDescriptor {
+public class RefCheckPhase extends Phase {
- public String name() {
- return "refcheck";
+ /** Initializes this instance. */
+ public RefCheckPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
}
- public String description () {
- return "reference checking";
- }
-
- public String taskDescription () {
- return "reference checking";
- }
-
- public void apply(Global global) {
- new RefCheck(global).apply();
- }
-
- public void apply(Unit unit) {
- new RefCheck(unit.global).apply(unit);
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ for (int i = 0; i < units.length; i++)
+ new RefCheck(global).apply(units[i]);
}
public Checker[] postCheckers(Global global) {
diff --git a/sources/scalac/util/EmptyPhase.java b/sources/scalac/util/EmptyPhase.java
new file mode 100644
index 0000000000..84ffe81adf
--- /dev/null
+++ b/sources/scalac/util/EmptyPhase.java
@@ -0,0 +1,36 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scalac.util;
+
+import scalac.Global;
+import scalac.Phase;
+import scalac.PhaseDescriptor;
+import scalac.Unit;
+
+/** This class implements a phase that does nothing. */
+public class EmptyPhase extends Phase {
+
+ //########################################################################
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public EmptyPhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
+ }
+
+ //########################################################################
+ // Public Methods
+
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ // do nothing
+ }
+
+ //########################################################################
+}
diff --git a/sources/scalac/util/OptionParser.java b/sources/scalac/util/OptionParser.java
index c2c3af6e6f..b82c147f9c 100644
--- a/sources/scalac/util/OptionParser.java
+++ b/sources/scalac/util/OptionParser.java
@@ -414,15 +414,16 @@ public class PhaseSetOptionParser extends OptionParser {
public void consumePhase(String token) {
if (token.equals("all")) {
- for (int i = 0; i < phases.length; i++) phases[i].flags |= flag;
+ for (int i = 0; i < phases.length; i++)
+ phases[i].addFlag(flag, false);
return;
}
PhaseDescriptor phase = lookup(getPhaseName(token));
if (phase != null) {
boolean before = getBeforeFlag(token);
boolean after = getAfterFlag(token) || !before;
- if (before) phase.flags |= flag << 16;
- if (after) phase.flags |= flag;
+ if (before) phase.addFlag(flag, true);
+ if (after) phase.addFlag(flag, false);
}
}