summaryrefslogtreecommitdiff
path: root/sources/scalac/transformer
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/transformer
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/transformer')
-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
13 files changed, 165 insertions, 217 deletions
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());
}
//