From ebe2c4bf3c1662b3667ce61fed54bde84afda615 Mon Sep 17 00:00:00 2001 From: paltherr Date: Fri, 3 Dec 2004 18:41:08 +0000 Subject: - Removed field units in class Global --- sources/scala/tools/scalac/Global.scala | 2 +- .../tools/scalac/ast/printer/SwingPrinter.scala | 20 ++++------ .../tools/scalac/ast/printer/TextTreePrinter.scala | 28 ++++++++------ sources/scala/tools/scalac/icode/ICodePhase.scala | 18 ++++----- .../scala/tools/scalac/icode/ICodePrinter.scala | 40 +++++++++---------- .../scala/tools/scalac/typechecker/Analyzer.scala | 28 ++++---------- .../tools/scalac/typechecker/AnalyzerPhase.scala | 7 ++++ .../tools/scalac/typechecker/DeSugarize.scala | 7 ++-- .../scalac/wholeprog/ApplicationBuilder.scala | 12 +++--- .../tools/scalac/wholeprog/MonomorphicCS.scala | 26 ++++++------- .../tools/scalac/wholeprog/WholeProgPhase.scala | 4 +- sources/scala/tools/scalai/Interpreter.java | 15 +++++--- sources/scalac/Global.java | 45 +++++++++++----------- sources/scalac/ast/Tree.java.tmpl | 7 +++- sources/scalac/ast/printer/TreePrinter.java | 8 +--- sources/scalac/atree/ATreePrinter.java | 9 +---- sources/scalac/transformer/ICodePhase.java | 27 ++++--------- sources/scalac/typechecker/AnalyzerPhase.java | 2 + 18 files changed, 139 insertions(+), 166 deletions(-) diff --git a/sources/scala/tools/scalac/Global.scala b/sources/scala/tools/scalac/Global.scala index 388663810d..81ce563e70 100644 --- a/sources/scala/tools/scalac/Global.scala +++ b/sources/scala/tools/scalac/Global.scala @@ -29,7 +29,7 @@ class Global(args: CompilerCommand, interpret: boolean) extends scalac_Global(ar override def newHTMLTreePrinter(writer: PrintWriter): TreePrinter = new HTMLTreePrinter(this, writer); override def newSwingTreePrinter(writer: PrintWriter): TreePrinter = - new SwingTreePrinter; + new SwingTreePrinter(this); } } diff --git a/sources/scala/tools/scalac/ast/printer/SwingPrinter.scala b/sources/scala/tools/scalac/ast/printer/SwingPrinter.scala index 2b34b9e487..436253213d 100644 --- a/sources/scala/tools/scalac/ast/printer/SwingPrinter.scala +++ b/sources/scala/tools/scalac/ast/printer/SwingPrinter.scala @@ -39,20 +39,22 @@ package scala.tools.scalac.ast.printer { * @author Iulian Dragos * @version 0.2 */ -class SwingTreePrinter extends TreePrinter { +class SwingTreePrinter(global0: scalac_Global) extends TreePrinter { + val global = global0; + def begin() = (); def end() = (); def flush() = (); /** print the whole program */ - def print(global: scalac_Global): Unit = { + def print(units: Array[CompilationUnit]): Unit = { val phase: Phase = global.currentPhase; val tm = new ASTTreeModel(); - for (val i <- Iterator.range(0, global.units.length)) - tm.addUnit(global.units(i)); + for (val i <- Iterator.range(0, units.length)) + tm.addUnit(units(i)); val frame = new WindowFrame(); frame.setTreeModel(tm); @@ -64,15 +66,7 @@ class SwingTreePrinter extends TreePrinter { lock.acquire; } - /** print one compilation unit*/ - def print(unit: CompilationUnit): Unit = { - } - - def print(tree: Tree) = this; - - def print(str: String) = this; - def println() = this; - + def print(tree: Tree): Unit = (); } diff --git a/sources/scala/tools/scalac/ast/printer/TextTreePrinter.scala b/sources/scala/tools/scalac/ast/printer/TextTreePrinter.scala index 1f33c381b3..6dd0bd1ac4 100644 --- a/sources/scala/tools/scalac/ast/printer/TextTreePrinter.scala +++ b/sources/scala/tools/scalac/ast/printer/TextTreePrinter.scala @@ -31,8 +31,14 @@ import java.util.ArrayList; class TextTreePrinter(global0: scalac_Global, out0: PrintWriter) with TreePrinter { - val global = global0; - val out = out0; + //########################################################################## + // Public Fields + + val global: scalac_Global = global0; + val out: PrintWriter = out0; + + //########################################################################## + // Public Constructors def this(global0: scalac_Global, out0: Writer) = this(global0, new PrintWriter(out0)); @@ -53,12 +59,8 @@ class TextTreePrinter(global0: scalac_Global, out0: PrintWriter) def end(): Unit = flush(); def flush(): Unit = out.flush(); - def print(global: scalac_Global): Unit = printUnitsOf(global); - def print(unit: CompilationUnit): Unit = printUnit(unit); - - def print(tree: Tree): TreePrinter = { printTree(tree); this } - def print(str: String) = { out.print(str); this } - def println() = { out.println(); this } + def print(units: Array[CompilationUnit]): Unit = printUnits(units); + def print(tree: Tree): Unit = printTree(tree); //########################################################################## @@ -75,6 +77,10 @@ class TextTreePrinter(global0: scalac_Global, out0: PrintWriter) indentMargin = indentMargin - Math.max(0, INDENT_STEP); } + protected def print(str: String): Unit = { + out.print(str); + } + protected def printString(str: String) = { out.print(str); } @@ -205,11 +211,11 @@ class TextTreePrinter(global0: scalac_Global, out0: PrintWriter) //########################################################################## // Public Methods - Printing Units - def printUnitsOf(global: scalac_Global): Unit = { + def printUnits(units: Array[CompilationUnit]): Unit = { val phase: Phase = global.currentPhase; beginSection(1, "syntax trees at "+phase+" (after "+phase.prev+")"); - for (val i <- Iterator.range(0, global.units.length)) - print(global.units(i)); + for (val i <- Iterator.range(0, units.length)) + printUnit(units(i)); } def printUnit(unit: CompilationUnit): Unit = { diff --git a/sources/scala/tools/scalac/icode/ICodePhase.scala b/sources/scala/tools/scalac/icode/ICodePhase.scala index 6b3f29cdf4..881e35a889 100644 --- a/sources/scala/tools/scalac/icode/ICodePhase.scala +++ b/sources/scala/tools/scalac/icode/ICodePhase.scala @@ -9,7 +9,7 @@ import scalac.symtab._; import scalac.transformer.{ICodePhase => scalac_ICodePhase} import scalac.{Global => scalac_Global} -import scalac.{CompilationUnit => scalac_CompilationUnit} +import scalac.CompilationUnit; import scalac.PhaseDescriptor; import scalac.Phase; import scalac.atree._; @@ -31,22 +31,20 @@ class ICodePhase(global: scalac_Global, descriptor: PhaseDescriptor) extends sca // ################################################## // Public methods - /* Apply the icode phase to the given units */ - override def apply(units: Array[scalac_CompilationUnit]) = { - val units_it = Iterator.fromArray(units); + /** Applies this phase to the given compilation units. */ + override def apply(units: Array[CompilationUnit]): Unit = + Iterator.fromArray(units).foreach(translate); - units_it.foreach(translate); - } - - /* Return a CodePrinter for the ICode */ - override def getPrinter(cp: CodePrinter) = new ICodePrinter(cp); + /** Prints the given compilation units. */ + override def print(units: Array[CompilationUnit], printer: CodePrinter):Unit= + new ICodePrinter(global, printer).printUnits(units); // ################################################## // Private methods /** This method translates a single unit, it traverses all methods and * generates ICode for each of them */ - private def translate(u: scalac_CompilationUnit) : unit = { + private def translate(u: CompilationUnit) : unit = { def genClass(c: AClass) : unit = { val nestedClasses_it = Iterator.fromArray(c.classes()); nestedClasses_it.foreach(genClass); diff --git a/sources/scala/tools/scalac/icode/ICodePrinter.scala b/sources/scala/tools/scalac/icode/ICodePrinter.scala index 2934f59033..81bac0a996 100644 --- a/sources/scala/tools/scalac/icode/ICodePrinter.scala +++ b/sources/scala/tools/scalac/icode/ICodePrinter.scala @@ -4,47 +4,43 @@ ** /_____/\____/\___/\____/____/ ** \* */ - // $Id$ import ch.epfl.lamp.util.CodePrinter; import scalac.CompilationUnit; import scalac.{Global => scalac_Global} -import scalac.atree._; - -import scalac.symtab._; package scala.tools.scalac.icode { +/** This class implements a Printer for the ICode. */ +class ICodePrinter(global0: scalac_Global, printer0: CodePrinter) { + //########################################################################## + // Public Fields -/* This class implements a Printer for the ICode */ -class ICodePrinter (printer: CodePrinter) extends ATreePrinter (printer: CodePrinter) { + val global: scalac_Global = global0; + val printer: CodePrinter = printer0; - // ################################################## - // Public methods + //########################################################################## + // Public Methods - /* This method print all ICode produced after the ICode phase */ - override def printGlobal(global: scalac_Global) : ATreePrinter = { // !!! Extends ATree !!! + /** Prints the ICode of the given units. */ + def printUnits(units: Array[CompilationUnit]): Unit = { val phase = global.currentPhase; - printer.println("[[ICode at "+phase+" (after "+phase.prev+")]]"); - val units_it = Iterator.fromArray(global.units); - units_it.foreach(printAnUnit); - - this; + Iterator.fromArray(units).foreach(printUnit); } - /* This method print a single unit. */ - def printAnUnit(unit: CompilationUnit) = { // ??? Private + /** Prints the ICode of the given unit. */ + def printUnit(unit: CompilationUnit): Unit = { printer.println ("// Scala source: "+unit.source); val classes_it = Iterator.fromArray(unit.repository.classes()); - classes_it.foreach((c: AClass) => { + classes_it.foreach(c => { printer.println (""); printer.println ("// ICode for class <"+c.symbol().name+">"); val methods_it = Iterator.fromArray(c.methods()); - methods_it.foreach((m: AMethod) => { + methods_it.foreach(m => { val icode : ICode = m.icode.asInstanceOf[ICode]; printer.println ("// ::"+m.symbol().name); icode.icTraverse((bb: IBasicBlock) => { @@ -52,7 +48,7 @@ class ICodePrinter (printer: CodePrinter) extends ATreePrinter (printer: CodePri printer.println("Initial stack -> "+bb.initialStack); printer.println("Substituable variables : "); if (bb.substituteVars != null) - bb.substituteVars.foreach((s: Symbol) => printer.print(s.name.toString())); + bb.substituteVars.foreach(s => printer.print(s.name.toString())); else printer.println(" {Empty} "); printer.println("Instructions:"); @@ -68,8 +64,8 @@ class ICodePrinter (printer: CodePrinter) extends ATreePrinter (printer: CodePri }); }); }); - - } + + //########################################################################## } } diff --git a/sources/scala/tools/scalac/typechecker/Analyzer.scala b/sources/scala/tools/scalac/typechecker/Analyzer.scala index 60e5470375..9cabf61193 100644 --- a/sources/scala/tools/scalac/typechecker/Analyzer.scala +++ b/sources/scala/tools/scalac/typechecker/Analyzer.scala @@ -60,30 +60,16 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer( type AttrInfo = Pair/**/ ; override def apply(units: Array[CompilationUnit]): unit = { - var i = 0; while (i < units.length) { - enterUnit(units(i)); - i = i + 1 - } - super.apply(units); + {var i = 0; while (i < units.length) { lateEnter(units(i)); i = i + 1; }} + val mixinOnly = global.target != Global.TARGET_INT; List.range(0, definitions.FUNCTION_COUNT).foreach( i => loadCode(definitions.FUNCTION_CLASS(i), mixinOnly)); - var n = descr.newSources.size(); - while (n > 0) { // this calls apply(u) for every unit `u'. - val l = global.units.length; - val newUnits = new Array[CompilationUnit](l + n); - System.arraycopy(global.units, 0, newUnits, 0, l); - var i = 0; while (i < n) { - newUnits(i + l) = descr.newSources.get(i).asInstanceOf[CompilationUnit]; - i = i + 1 - } - global.units = newUnits; - descr.newSources.clear(); - var j = l; while (j < newUnits.length) { - apply(newUnits(j)); - j = j + 1 - } - n = descr.newSources.size(); + + var n = 0; + while (n < descr.newSources.size()) { + apply(descr.newSources.get(n).asInstanceOf[CompilationUnit]); + n = n + 1; } } diff --git a/sources/scala/tools/scalac/typechecker/AnalyzerPhase.scala b/sources/scala/tools/scalac/typechecker/AnalyzerPhase.scala index 275bba16d4..a894e7cc8b 100644 --- a/sources/scala/tools/scalac/typechecker/AnalyzerPhase.scala +++ b/sources/scala/tools/scalac/typechecker/AnalyzerPhase.scala @@ -52,6 +52,13 @@ class AnalyzerPhase(global: scalac_Global, descriptor: PhaseDescriptor) extends val contexts = new HashMap/**/(); val newSources = new ArrayList/**/(); + override def getUnits(): Array[CompilationUnit] = { + val array = new Array[CompilationUnit](newSources.size()); + newSources.toArray(array.asInstanceOf[Array[Object]]); + newSources.clear(); + array + } + override def addConsoleImport(module: Symbol): unit = consoleContext = addImport(consoleContext, module); diff --git a/sources/scala/tools/scalac/typechecker/DeSugarize.scala b/sources/scala/tools/scalac/typechecker/DeSugarize.scala index 3b983a6f1e..7d8b9d8bde 100644 --- a/sources/scala/tools/scalac/typechecker/DeSugarize.scala +++ b/sources/scala/tools/scalac/typechecker/DeSugarize.scala @@ -630,10 +630,9 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala //debug def print(tree: Tree, conv: String, result: Tree): unit = { if (global.log()) { - new TextTreePrinter(global) - .print(tree).println() - .print(" --" + conv + "--> ").println() - .print(result).println().end(); + System.out.println(tree); + System.out.println(" --" + conv + "--> "); + System.out.println(tree); } } } diff --git a/sources/scala/tools/scalac/wholeprog/ApplicationBuilder.scala b/sources/scala/tools/scalac/wholeprog/ApplicationBuilder.scala index 244c6ae1e4..77f22e356c 100644 --- a/sources/scala/tools/scalac/wholeprog/ApplicationBuilder.scala +++ b/sources/scala/tools/scalac/wholeprog/ApplicationBuilder.scala @@ -1,7 +1,7 @@ // $Id$ import scalac.{Global => scalac_Global} -import scalac.{CompilationUnit => scalac_CompilationUnit} +import scalac.CompilationUnit; import scalac.atree._; import scalac.symtab._; import scalac.util.Name; @@ -29,7 +29,7 @@ class ApplicationBuilder(globall: scalac_Global) { var worklist: Set[Symbol] = new HashSet[Symbol]; var app: Set[Symbol] = new HashSet[Symbol]; - def finalClasses(app: Set[Symbol], units: Array[scalac_CompilationUnit]): Unit = { + def finalClasses(app: Set[Symbol], units: Array[CompilationUnit]): Unit = { val m = new MonomorphicCallSites(global, app); m.buildClassHierarchy; @@ -46,12 +46,12 @@ class ApplicationBuilder(globall: scalac_Global) { // u.body.foreach( (b) => transf.transform(b) ); // }); - m.monomorphicCallsites; + m.monomorphicCallsites(units); } /** find the whole application that is referenced by the root class */ - def buildApplication(root: String, units: Array[scalac_CompilationUnit]): unit = { + def buildApplication(root: String, units: Array[CompilationUnit]): unit = { rootClassName = Name.fromString(root); var rootClass: Symbol = null; @@ -82,7 +82,7 @@ class ApplicationBuilder(globall: scalac_Global) { finalClasses(app, units); } // where - def buildCodeMap(units: Array[scalac_CompilationUnit]): Unit = { + def buildCodeMap(units: Array[CompilationUnit]): Unit = { //val map = new SymbolMap(); def mapTree(t: Tree): unit = { @@ -105,7 +105,7 @@ class ApplicationBuilder(globall: scalac_Global) { }; } - units.foreach( (u: scalac_CompilationUnit) => + units.foreach( (u: CompilationUnit) => u.body.foreach( (b) => mapTree(b) )); } diff --git a/sources/scala/tools/scalac/wholeprog/MonomorphicCS.scala b/sources/scala/tools/scalac/wholeprog/MonomorphicCS.scala index eb04b72f27..e71fdd2004 100644 --- a/sources/scala/tools/scalac/wholeprog/MonomorphicCS.scala +++ b/sources/scala/tools/scalac/wholeprog/MonomorphicCS.scala @@ -15,7 +15,7 @@ ** [iuli] 2.05.2004 */ import scalac.{Global => scalac_Global} -import scalac.{CompilationUnit => scalac_CompilationUnit} +import scalac.CompilationUnit; import scalac.symtab._; import scalac.util._; import scala.collection.mutable._; @@ -85,7 +85,7 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) { } /** Identify and print monomoprhic callsites */ - def monomorphicCallsites: Unit = { + def monomorphicCallsites(units: Array[CompilationUnit]): Unit = { val cg = callGraph; var nr: int = 0; var views: Int = 0; @@ -122,7 +122,7 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) { Logger.setFile("inlining.log"); Console.println("[start build callgraph]"); StopWatch.start; - buildCallGraph; + buildCallGraph(units); Console.println("[end build callgraph] " + StopWatch.stop + " ms"); if (global.args.Xrta.value) { @@ -158,7 +158,7 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) { if (global.args.Xinline.value) { Console.println("[start inlining]"); StopWatch.start; - doInline(inlinable); + doInline(units, inlinable); Console.println("[end inlining] " + StopWatch.stop + " ms"); } } @@ -207,10 +207,10 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) { } /** perform inlines */ - def doInline(sites: InlinableCollection): Unit = { + def doInline(units: Array[CompilationUnit], sites: InlinableCollection): Unit = { val transformer: Transformer = new InlineMethods(sites, global); - global.units.foreach( (u) => { + units.foreach( (u) => { u.body = transformer.transform(u.body); }); @@ -223,9 +223,9 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) { var viewsTotal = 0; // calls to "view" methods - def buildCallGraph: Unit = { - createNodes(callGraph); - createEdges(callGraph); + def buildCallGraph(units: Array[CompilationUnit]): Unit = { + createNodes(units, callGraph); + createEdges(units, callGraph); // print call graph size var nodes = 0; @@ -249,16 +249,16 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) { file.flush(); } - def createNodes(cg: CallGraph): Unit = { + def createNodes(units: Array[CompilationUnit], cg: CallGraph): Unit = { val trav: Traverser = new MethodNodeCreator(cg); - global.units.foreach( (u) => trav.traverse(u.body) ); + units.foreach( (u) => trav.traverse(u.body) ); } - def createEdges(cg: CallGraph): Unit = { + def createEdges(units: Array[CompilationUnit], cg: CallGraph): Unit = { val trav: Traverser = new CallGraphEdgeTraverser(cg); - global.units.foreach( (u) => trav.traverse(u.body) ); + units.foreach( (u) => trav.traverse(u.body) ); } /** Walk the nodes in the AST tree and creates nodes in the callgraph diff --git a/sources/scala/tools/scalac/wholeprog/WholeProgPhase.scala b/sources/scala/tools/scalac/wholeprog/WholeProgPhase.scala index 58683d030b..5a6f8a8295 100644 --- a/sources/scala/tools/scalac/wholeprog/WholeProgPhase.scala +++ b/sources/scala/tools/scalac/wholeprog/WholeProgPhase.scala @@ -17,7 +17,7 @@ import scala.tools.scalac.{CompilerPhases => old_CompilerPhases} import scalac.{Global => scalac_Global} import scalac.transformer.{WholeProgPhase => scalac_WholeProgPhase} import scalac.PhaseDescriptor; -import scalac.{CompilationUnit => scalac_Unit} +import scalac.CompilationUnit; import scalac.util.Name; package scala.tools.scalac.wholeprog { @@ -32,7 +32,7 @@ class WholeProgPhase(global: scalac_Global, descriptor: PhaseDescriptor) /* Apply the global analysis phase to the given units */ - override def apply(units: Array[scalac_Unit]): unit = { + override def apply(units: Array[CompilationUnit]): unit = { if (!global.args.XdotFile.value.equals("$")) { val dotFilePrinter = new PrintDotFile(units); diff --git a/sources/scala/tools/scalai/Interpreter.java b/sources/scala/tools/scalai/Interpreter.java index a322826ba2..22187887e9 100644 --- a/sources/scala/tools/scalai/Interpreter.java +++ b/sources/scala/tools/scalai/Interpreter.java @@ -14,6 +14,7 @@ import java.util.HashMap; import scala.tools.util.Position; +import scalac.CompilationUnit; import scalac.Global; import scalac.Phase; import scalac.symtab.Definitions; @@ -70,14 +71,14 @@ public class Interpreter { public EvaluatorResult interpret(String input, boolean interactive) { if (input.trim().length() == 0) return EvaluatorResult.Void; - global.compile("", input + ";", interactive); - return interpret(interactive); + return interpret( + global.compile("", input + ";", interactive), + interactive); } public EvaluatorResult interpret(String[] files, boolean interactive) { if (files.length == 0) return EvaluatorResult.Void; - global.compile(files, interactive); - return interpret(interactive); + return interpret(global.compile(files, interactive), interactive); } public EvaluatorResult toString(Object object, String type) { @@ -91,10 +92,12 @@ public class Interpreter { //######################################################################## // Private Methods - private EvaluatorResult interpret(boolean interactive) { + private EvaluatorResult interpret(CompilationUnit[] units, + boolean interactive) + { try { if (global.reporter.errors() != 0) return EvaluatorResult.Void; - compiler.compile(global.units); + compiler.compile(units); if (interactive) { Variable console = compiler.getModule(global.console); evaluator.evaluate(console); diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java index eb41e5f3e5..dd0de1b26b 100644 --- a/sources/scalac/Global.java +++ b/sources/scalac/Global.java @@ -42,6 +42,7 @@ import scalac.symtab.classfile.PackageParser; import scalac.symtab.classfile.CLRPackageParser; import scalac.typechecker.AnalyzerPhase; import scalac.typechecker.Infer; +import scalac.transformer.ICodePhase; import scalac.util.*; /** The global environment of a compiler run @@ -94,10 +95,6 @@ public abstract class Global { */ private final SourceReader reader; - /** all compilation units - */ - public CompilationUnit[] units; - /** the class path */ public final ClassPath classPath; @@ -142,7 +139,7 @@ public abstract class Global { /** The set of already compiled sourcefiles */ - public HashSet/**/ compiledUnits = new HashSet(); + private HashSet/**/ compiledUnits = new HashSet(); /** the current phase */ @@ -348,7 +345,7 @@ public abstract class Global { /** the top-level compilation process */ - public void compile(String[] files, boolean console) { + public CompilationUnit[] compile(String[] files, boolean console) { reporter.resetCounters(); // parse files List units = new ArrayList(files.length); @@ -361,8 +358,8 @@ public abstract class Global { error(exception.getMessage()); } } - this.units = (CompilationUnit[])units.toArray(new CompilationUnit[units.size()]); - compile(); + CompilationUnit[] array = new CompilationUnit[units.size()]; + return compile((CompilationUnit[])units.toArray(array)); } /** @@ -372,17 +369,17 @@ public abstract class Global { * @param input * @param console */ - public void compile(String filename, String input, boolean console) { + public CompilationUnit[] compile(String filename, String input, boolean console) { reporter.resetCounters(); SourceFile source = getSourceFile(filename, input); compiledUnits.add(source); - units = new CompilationUnit[]{new CompilationUnit(this, source, console)}; - compile(); + CompilationUnit[] units = {new CompilationUnit(this, source, console)}; + return compile(units); } /** compile all compilation units */ - private void compile() { + private CompilationUnit[] compile(CompilationUnit[] units) { treePrinter.begin(); currentPhase = PHASE.INITIAL.phase(); @@ -393,11 +390,13 @@ public abstract class Global { // System.out.println("*** " + currentPhase.descriptor.description() + " ***"); currentPhase.apply(units); stop(currentPhase.descriptor.taskDescription()); - if (currentPhase.descriptor.hasPrintFlag()) print(); + if (currentPhase == PHASE.ANALYZER.phase()) + units = ((AnalyzerPhase)currentPhase).getUnits(); + if (currentPhase.descriptor.hasPrintFlag()) print(units); // if (currentPhase.descriptor.hasGraphFlag()) // !!! // if (currentPhase.descriptor.hasCheckFlag()) // !!! - if (currentPhase == PHASE.PARSER.phase()) fix1(); - if (currentPhase == PHASE.ANALYZER.phase()) fix2(); + if (currentPhase == PHASE.PARSER.phase()) fix1(units); + if (currentPhase == PHASE.ANALYZER.phase()) fix2(units); } if (reporter.errors() != 0) { imports.clear(); @@ -411,6 +410,7 @@ public abstract class Global { symdata.clear(); compiledNow.clear(); treePrinter.end(); + return units; } /** Compiles an additional source file. */ @@ -429,30 +429,31 @@ public abstract class Global { } } - private void print() { + private void print(CompilationUnit[] units) { if (currentPhase.id == PHASE.MAKEBOXINGEXPLICIT.id()) { boolean html = args.printer.value.equals(PRINTER_HTML); if (html) writer.println("
");
             ATreePrinter printer = new ATreePrinter(new CodePrinter(writer));
             boolean next = currentPhase.next != null;
             if (next) currentPhase = currentPhase.next;
-            printer.printGlobal(this);
+            printer.printUnits(units);
             if (next) currentPhase = currentPhase.prev;
             if (html) writer.println("
"); } else if (currentPhase.id == PHASE.ICODE.id()) { + Phase phase = currentPhase; boolean html = args.printer.value.equals(PRINTER_HTML); if (html) writer.println("
");
-	    ATreePrinter printer = ((scalac.transformer.ICodePhase)currentPhase).getPrinter(new CodePrinter(writer)); // Oh !!
+
             boolean next = currentPhase.next != null;
             if (next) currentPhase = currentPhase.next;
-            printer.printGlobal(this);
+            ((ICodePhase)phase).print(units, new CodePrinter(writer));
             if (next) currentPhase = currentPhase.prev;
             if (html) writer.println("
"); } else { // go to next phase to print symbols with their new type boolean next = currentPhase.next != null; if (next) currentPhase = currentPhase.next; - treePrinter.print(this); + treePrinter.print(units); if (next) currentPhase = currentPhase.prev; } } @@ -498,7 +499,7 @@ public abstract class Global { private List imports = new ArrayList(); public Symbol console; - private void fix1() { + private void fix1(CompilationUnit[] units) { for (int i = 0; i < units.length; i++) { if (units[i].console) fix1(units[i]); } @@ -524,7 +525,7 @@ public abstract class Global { module++; } - private void fix2() { + private void fix2(CompilationUnit[] units) { for (int i = 0; i < units.length; i++) { if (units[i].console) fix2(units[i]); } diff --git a/sources/scalac/ast/Tree.java.tmpl b/sources/scalac/ast/Tree.java.tmpl index 0b130451fe..8a12c16577 100644 --- a/sources/scalac/ast/Tree.java.tmpl +++ b/sources/scalac/ast/Tree.java.tmpl @@ -14,6 +14,7 @@ import java.io.PrintWriter; import scala.tools.util.Position; import scalac.Global; +import scalac.ast.printer.TreePrinter; import scalac.checkers.CheckTreeNodes; import scalac.symtab.Symbol; import scalac.symtab.Type; @@ -111,8 +112,10 @@ public class Tree { /** Returns the string representation of this tree. */ public String toString() { StringWriter buffer = new StringWriter(); - Global global = Global.instance; - global.newTextTreePrinter(new PrintWriter(buffer)).print(this).flush(); + TreePrinter printer = + Global.instance.newTextTreePrinter(new PrintWriter(buffer)); + printer.print(this); + printer.flush(); return buffer.toString(); } diff --git a/sources/scalac/ast/printer/TreePrinter.java b/sources/scalac/ast/printer/TreePrinter.java index ce6ae2bd18..a0884b0b2a 100644 --- a/sources/scalac/ast/printer/TreePrinter.java +++ b/sources/scalac/ast/printer/TreePrinter.java @@ -23,10 +23,6 @@ public interface TreePrinter { public void end(); public void flush(); - public void print(Global global); - public void print(CompilationUnit unit); - - public TreePrinter print(Tree tree); - public TreePrinter print(String str); - public TreePrinter println(); + public void print(CompilationUnit[] units); + public void print(Tree tree); } diff --git a/sources/scalac/atree/ATreePrinter.java b/sources/scalac/atree/ATreePrinter.java index 44098d3332..022f78aed5 100644 --- a/sources/scalac/atree/ATreePrinter.java +++ b/sources/scalac/atree/ATreePrinter.java @@ -239,15 +239,10 @@ public class ATreePrinter { //######################################################################## // Public Methods - Printing trees - /** Prints all global units. */ - public ATreePrinter printGlobal(Global global) { - Phase phase = global.currentPhase; - println("[[attributed trees at "+phase+" (after "+phase.prev+")]]"); - return printUnits(global.units); - } - /** Prints the units. */ public ATreePrinter printUnits(CompilationUnit[] units) { + Phase phase = global.currentPhase; + println("[[attributed trees at "+phase+" (after "+phase.prev+")]]"); for (int i = 0; i < units.length; i++) printUnit(units[i]); return this; } diff --git a/sources/scalac/transformer/ICodePhase.java b/sources/scalac/transformer/ICodePhase.java index beaa7f6aab..7ac77cb11f 100644 --- a/sources/scalac/transformer/ICodePhase.java +++ b/sources/scalac/transformer/ICodePhase.java @@ -8,15 +8,12 @@ package scalac.transformer; +import ch.epfl.lamp.util.CodePrinter; + 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 ICode phase for the java version @@ -25,12 +22,7 @@ import scalac.atree.ATreePrinter; * scala one. See scala.tools.scalac.icode.ICodePhase for * implementation */ -public class ICodePhase extends Phase { - - //######################################################################## - // Private Fields - - private final Definitions definitions; +public abstract class ICodePhase extends Phase { //######################################################################## // Public Constructors @@ -38,21 +30,16 @@ public class ICodePhase extends Phase { /** Initializes this instance. */ public ICodePhase(Global global, PhaseDescriptor descriptor) { super(global, descriptor); - this.definitions = global.definitions; } //######################################################################## // Public Methods /** Applies this phase to the given compilation units. */ - public void apply(CompilationUnit[] units) { - // This java version doesn't make anything - } + public abstract void apply(CompilationUnit[] units); - public ATreePrinter getPrinter(CodePrinter cp) { - return new ATreePrinter(cp); - // !! Useless - } + /** Prints the given compilation units. */ + public abstract void print(CompilationUnit[] units, CodePrinter printer); + //######################################################################## } - diff --git a/sources/scalac/typechecker/AnalyzerPhase.java b/sources/scalac/typechecker/AnalyzerPhase.java index 7104adfd03..c4f56d22e8 100644 --- a/sources/scalac/typechecker/AnalyzerPhase.java +++ b/sources/scalac/typechecker/AnalyzerPhase.java @@ -31,4 +31,6 @@ public abstract class AnalyzerPhase extends Phase { public abstract void lateEnter(CompilationUnit unit); + public abstract CompilationUnit[] getUnits(); + } -- cgit v1.2.3