diff options
Diffstat (limited to 'sources/scalac')
20 files changed, 69 insertions, 109 deletions
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java index bfba148993..ec8f20ab81 100644 --- a/sources/scalac/Global.java +++ b/sources/scalac/Global.java @@ -389,9 +389,9 @@ public abstract class Global { start(); // System.out.println("*** " + currentPhase.descriptor.description() + " ***"); currentPhase.apply(units); - stop(currentPhase.descriptor.taskDescription()); if (currentPhase == PHASE.ANALYZER.phase()) units = ((AnalyzerPhase)currentPhase).getUnits(); + stop(currentPhase.descriptor.taskDescription()); if (currentPhase.descriptor.hasPrintFlag()) print(units); // if (currentPhase.descriptor.hasGraphFlag()) // !!! // if (currentPhase.descriptor.hasCheckFlag()) // !!! @@ -423,7 +423,7 @@ public abstract class Global { currentPhase = PHASE.PARSER.phase(); PHASE.PARSER.phase().apply(new CompilationUnit[] {unit}); currentPhase = PHASE.ANALYZER.phase(); - ((AnalyzerPhase)PHASE.ANALYZER.phase()).lateEnter(unit); + ((AnalyzerPhase)PHASE.ANALYZER.phase()).apply(unit); // !!! add code for later phases? currentPhase = backup; } diff --git a/sources/scalac/Phase.java b/sources/scalac/Phase.java index cd3c1a1d5d..88420302e9 100644 --- a/sources/scalac/Phase.java +++ b/sources/scalac/Phase.java @@ -62,7 +62,12 @@ public abstract class Phase { } /** Applies this phase to the given compilation units. */ - public abstract void apply(CompilationUnit[] units); + public void apply(CompilationUnit[] units) { + for (int i = 0; i < units.length; i++) apply(units[i]); + } + + /** Applies this phase to the given compilation unit. */ + public abstract void apply(CompilationUnit unit); /** Returns the name of this phase. */ public final String toString() { diff --git a/sources/scalac/ast/Transformer.java.tmpl b/sources/scalac/ast/Transformer.java.tmpl index 189a8a8d6d..bf5fa09f4f 100644 --- a/sources/scalac/ast/Transformer.java.tmpl +++ b/sources/scalac/ast/Transformer.java.tmpl @@ -55,10 +55,6 @@ public class Transformer { //######################################################################## // Public Methods - public void apply(CompilationUnit[] units) { - for (int i = 0; i < units.length; i++) apply(units[i]); - } - public void apply(CompilationUnit unit) { unit.global.log("transforming " + unit); unit.body = transform(unit.body); diff --git a/sources/scalac/backend/jvm/GenJVMPhase.java b/sources/scalac/backend/jvm/GenJVMPhase.java index eb02e0645c..06d39839c8 100644 --- a/sources/scalac/backend/jvm/GenJVMPhase.java +++ b/sources/scalac/backend/jvm/GenJVMPhase.java @@ -40,9 +40,9 @@ public class GenJVMPhase extends Phase { //######################################################################## // Public Methods - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - for (int i = 0; i < units.length; i++) translator.translate(units[i]); + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + translator.translate(unit); } //######################################################################## diff --git a/sources/scalac/backend/msil/GenMSILPhase.java b/sources/scalac/backend/msil/GenMSILPhase.java index a12a0c2d52..0df65a1eb8 100644 --- a/sources/scalac/backend/msil/GenMSILPhase.java +++ b/sources/scalac/backend/msil/GenMSILPhase.java @@ -49,9 +49,14 @@ public class GenMSILPhase extends Phase { tc.init(); tc.collectSymbols(units); tc.initAssembly(); - for (int i = 0; i < units.length; i++) translator.apply(units[i]); + super.apply(units); tc.saveAssembly(); } + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + translator.apply(unit); + } + //######################################################################## } diff --git a/sources/scalac/transformer/AddAccessorsPhase.java b/sources/scalac/transformer/AddAccessorsPhase.java index f9a459722b..2f684e1acb 100644 --- a/sources/scalac/transformer/AddAccessorsPhase.java +++ b/sources/scalac/transformer/AddAccessorsPhase.java @@ -45,9 +45,9 @@ public class AddAccessorsPhase extends Phase { //######################################################################## // Public Methods - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - treeTransformer.apply(units); + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + treeTransformer.apply(unit); } //######################################################################## diff --git a/sources/scalac/transformer/AddConstructorsPhase.java b/sources/scalac/transformer/AddConstructorsPhase.java index a60842da9f..1dfb10e344 100644 --- a/sources/scalac/transformer/AddConstructorsPhase.java +++ b/sources/scalac/transformer/AddConstructorsPhase.java @@ -24,7 +24,7 @@ public class AddConstructorsPhase extends Phase { //######################################################################## // Private Fields - /** A maps from old constructor symbols to new ones */ + /** A map from old constructor symbols to new ones */ private final HashMap/*<Symbol,Symbol>*/ constructors = new HashMap(); //######################################################################## @@ -54,10 +54,9 @@ public class AddConstructorsPhase extends Phase { return type; } - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - for (int i = 0; i < units.length; i++) - new AddConstructors(global, constructors).apply(units[i]); + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + new AddConstructors(global, constructors).apply(unit); } //######################################################################## diff --git a/sources/scalac/transformer/AddInterfaces.java b/sources/scalac/transformer/AddInterfaces.java index c5b6b94fab..5722cf4396 100644 --- a/sources/scalac/transformer/AddInterfaces.java +++ b/sources/scalac/transformer/AddInterfaces.java @@ -221,20 +221,21 @@ public class AddInterfaces extends GenTransformer { } /** - * Returns the tree of the given class whose body is built by - * adding to the given body the class members. Non-abstract - * methods are removed from the ngiven method map. All other - * members are generated from their symbol. + * Returns the tree of the given class. Its body is built by + * adding its members to the provided body. Non-abstract methods + * are removed from the provided method map. All other members are + * generated from their symbol. */ private Tree getClassTree(Symbol clasz, TreeList body, Map methods) { Scope members = clasz.nextInfo().members(); - for (Scope.SymbolIterator i = members.iterator(); - i.hasNext(); ) { + for (Scope.SymbolIterator i = members.iterator(); i.hasNext(); ) { Symbol member = i.next(); if (!member.isTerm()) continue; body.append(getMemberTree(clasz, member, methods)); } - return gen.ClassDef(clasz, body.toArray()); + Tree[] array = body.toArray(); + if (!clasz.isInterface()) phase.classToBody.put(clasz, array); + return gen.ClassDef(clasz, array); } /** diff --git a/sources/scalac/transformer/AddInterfacesPhase.java b/sources/scalac/transformer/AddInterfacesPhase.java index e018abb00e..9b2447b119 100644 --- a/sources/scalac/transformer/AddInterfacesPhase.java +++ b/sources/scalac/transformer/AddInterfacesPhase.java @@ -24,10 +24,9 @@ public class AddInterfacesPhase extends Phase { super(global, descriptor); } - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - for (int i = 0; i < units.length; i++) - new AddInterfaces(global, this).apply(units[i]); + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + new AddInterfaces(global, this).apply(unit); } public Type transformInfo(Symbol sym, Type tp) { @@ -139,8 +138,9 @@ public class AddInterfacesPhase extends Phase { else return className; } - protected HashMap ifaceToClass = new HashMap(); - protected HashMap classToIFace = new HashMap(); + protected final HashMap/*<Symbol,Symbol>*/ ifaceToClass = new HashMap(); + protected final HashMap/*<Symbol,Symbol>*/ classToIFace = new HashMap(); + protected final HashMap/*<Symbol,Tree[]>*/ classToBody = new HashMap(); /** Return the class symbol corresponding to the given interface * symbol. If the class does not need an interface, return the diff --git a/sources/scalac/transformer/ErasurePhase.java b/sources/scalac/transformer/ErasurePhase.java index cfe2e20da6..c0669e22f2 100644 --- a/sources/scalac/transformer/ErasurePhase.java +++ b/sources/scalac/transformer/ErasurePhase.java @@ -45,8 +45,8 @@ public class ErasurePhase extends Phase { //######################################################################## // Public Methods - public void apply(CompilationUnit[] units) { - erasure.apply(units); + public void apply(CompilationUnit unit) { + erasure.apply(unit); } public Type transformInfo(Symbol sym, Type tp) { diff --git a/sources/scalac/transformer/ExpandMixinsPhase.java b/sources/scalac/transformer/ExpandMixinsPhase.java index f2851ea156..9f00dd9c41 100644 --- a/sources/scalac/transformer/ExpandMixinsPhase.java +++ b/sources/scalac/transformer/ExpandMixinsPhase.java @@ -68,9 +68,6 @@ public class ExpandMixinsPhase extends Phase { private final Map/*<Symbol,Tree[]>*/ bodies; - /** A traverser that collects class definitions */ - private final Traverser collector; - /** A transformer that expands classes that have mixins */ private final GenTransformer expander; @@ -84,18 +81,16 @@ public class ExpandMixinsPhase extends Phase { this.interfaces = ((AddInterfacesPhase)addinterfaces).classToIFace; this.transformers = new HashMap(); this.expansions = new HashMap(); - this.bodies = new HashMap(); - this.collector = new TreeCollector(); + this.bodies = ((AddInterfacesPhase)addinterfaces).classToBody; this.expander = new TreeExpander(global); } //######################################################################## // Public Methods - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - collector.traverse(units); - expander.apply(units); + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + expander.apply(unit); } /** Applies this phase to the given type for the given symbol. */ @@ -117,25 +112,6 @@ public class ExpandMixinsPhase extends Phase { // Private Methods //######################################################################## - // Private Class - Tree collector - - /** A tree traverser that collects class definitions. */ - private class TreeCollector extends Traverser { - public void traverse(Tree tree) { - switch(tree) { - case ClassDef(_, _, _, _, _, Template(_, Tree[] body)): - Symbol clasz = tree.symbol(); - if (!clasz.isInterface()) bodies.put(clasz, body); - traverse(body); - return; - case PackageDef(_, Template(_, Tree[] body)): - traverse(body); - return; - } - } - } - - //######################################################################## // Private Class - Tree expander /** diff --git a/sources/scalac/transformer/ExplicitOuterClassesPhase.java b/sources/scalac/transformer/ExplicitOuterClassesPhase.java index e8cd8fe9a9..b1b05832a1 100644 --- a/sources/scalac/transformer/ExplicitOuterClassesPhase.java +++ b/sources/scalac/transformer/ExplicitOuterClassesPhase.java @@ -64,9 +64,9 @@ public class ExplicitOuterClassesPhase extends Phase { //######################################################################## // Public Methods - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - treeTransformer.apply(units); + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + treeTransformer.apply(unit); } /** Applies this phase to the given type for the given symbol. */ diff --git a/sources/scalac/transformer/ICodePhase.java b/sources/scalac/transformer/ICodePhase.java index 7ac77cb11f..3274897641 100644 --- a/sources/scalac/transformer/ICodePhase.java +++ b/sources/scalac/transformer/ICodePhase.java @@ -35,9 +35,6 @@ public abstract class ICodePhase extends Phase { //######################################################################## // Public Methods - /** Applies this phase to the given compilation units. */ - public abstract void apply(CompilationUnit[] units); - /** Prints the given compilation units. */ public abstract void print(CompilationUnit[] units, CodePrinter printer); diff --git a/sources/scalac/transformer/LambdaLiftPhase.java b/sources/scalac/transformer/LambdaLiftPhase.java index e72575a707..42bf473112 100644 --- a/sources/scalac/transformer/LambdaLiftPhase.java +++ b/sources/scalac/transformer/LambdaLiftPhase.java @@ -21,10 +21,9 @@ public class LambdaLiftPhase extends Phase implements Kinds, Modifiers { super(global, descriptor); } - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - for (int i = 0; i < units.length; i++) - new LambdaLift(global, this).apply(units[i]); + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + new LambdaLift(global, this).apply(unit); } public Type transformInfo(Symbol sym, Type tp) { diff --git a/sources/scalac/transformer/MakeBoxingExplicitPhase.java b/sources/scalac/transformer/MakeBoxingExplicitPhase.java index e4d6f956b1..435886b1dc 100644 --- a/sources/scalac/transformer/MakeBoxingExplicitPhase.java +++ b/sources/scalac/transformer/MakeBoxingExplicitPhase.java @@ -40,13 +40,10 @@ public class MakeBoxingExplicitPhase extends Phase { //######################################################################## // Public Methods - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - for (int i = 0; i < units.length; i++) { - assert checker.check(units[i]); - new scalac.atree.ATreeFromSTree(global.definitions) - .translate(units[i]); // !!! - } + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + assert checker.check(unit); + new scalac.atree.ATreeFromSTree(definitions).translate(unit); // !!! } //######################################################################## diff --git a/sources/scalac/transformer/TailCallPhase.java b/sources/scalac/transformer/TailCallPhase.java index 667e906112..2487a7d436 100644 --- a/sources/scalac/transformer/TailCallPhase.java +++ b/sources/scalac/transformer/TailCallPhase.java @@ -60,9 +60,9 @@ public class TailCallPhase extends Phase { //######################################################################## // Public Methods - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - treeTransformer.apply(units); + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { + treeTransformer.apply(unit); } //######################################################################## diff --git a/sources/scalac/transformer/TypesAsValuesPhase.java b/sources/scalac/transformer/TypesAsValuesPhase.java index f8b90aee8a..217ed6553e 100644 --- a/sources/scalac/transformer/TypesAsValuesPhase.java +++ b/sources/scalac/transformer/TypesAsValuesPhase.java @@ -300,8 +300,8 @@ public class TypesAsValuesPhase extends Phase { return !classSym.owner().isPackageClass(); } - public void apply(CompilationUnit[] units) { - transformer.apply(units); + public void apply(CompilationUnit unit) { + transformer.apply(unit); } private class TV_Transformer extends GenTransformer { diff --git a/sources/scalac/transformer/WholeProgPhase.java b/sources/scalac/transformer/WholeProgPhase.java index 5ad7d271e7..7591352c21 100644 --- a/sources/scalac/transformer/WholeProgPhase.java +++ b/sources/scalac/transformer/WholeProgPhase.java @@ -11,35 +11,22 @@ package scalac.transformer; import scalac.Global; import scalac.Phase; import scalac.PhaseDescriptor; -import scalac.CompilationUnit; -import scalac.symtab.Definitions; - -import ch.epfl.lamp.util.CodePrinter; -import scalac.atree.ATreePrinter; - /** - * This class represents the wholeprog phase for the java version - * of the compiler. It doesn't do anything but permit to make - * a bridge between the java implementation of Socos et the - * scala one. See scala.tools.scalac.wholeprog.WholeProgPhase for - * implementation + * This class represents the wholeprog phase for the java version of + * the compiler. It doesn't do anything but permit to make a bridge + * between the java implementation of Socos and the scala one. See + * scala.tools.scalac.wholeprog.WholeProgPhase for implementation. */ -public class WholeProgPhase extends Phase { +public abstract class WholeProgPhase extends Phase { + + //######################################################################## + // Public Constructors /** Initializes this instance. */ public WholeProgPhase(Global global, PhaseDescriptor descriptor) { super(global, descriptor); - } //######################################################################## - // Public Methods - - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - // This java version doesn't make anything - } - } - diff --git a/sources/scalac/typechecker/AnalyzerPhase.java b/sources/scalac/typechecker/AnalyzerPhase.java index c4f56d22e8..0939806844 100644 --- a/sources/scalac/typechecker/AnalyzerPhase.java +++ b/sources/scalac/typechecker/AnalyzerPhase.java @@ -29,8 +29,6 @@ public abstract class AnalyzerPhase extends Phase { public abstract void addConsoleImport(Symbol module); - public abstract void lateEnter(CompilationUnit unit); - public abstract CompilationUnit[] getUnits(); } diff --git a/sources/scalac/util/EmptyPhase.java b/sources/scalac/util/EmptyPhase.java index 003983f4e0..5600fc85b9 100644 --- a/sources/scalac/util/EmptyPhase.java +++ b/sources/scalac/util/EmptyPhase.java @@ -27,8 +27,8 @@ public class EmptyPhase extends Phase { //######################################################################## // Public Methods - /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { + /** Applies this phase to the given compilation unit. */ + public void apply(CompilationUnit unit) { // do nothing } |