summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-08-22 12:27:22 +0000
committerMartin Odersky <odersky@gmail.com>2007-08-22 12:27:22 +0000
commitd0310bece6ca4047221698c08de1d85b703bd07d (patch)
treeba02cb90d292086fea2a545ffed30be06cb72fba
parent83767dc5e2181f7953afc2a91a5253f652f8fc11 (diff)
downloadscala-d0310bece6ca4047221698c08de1d85b703bd07d.tar.gz
scala-d0310bece6ca4047221698c08de1d85b703bd07d.tar.bz2
scala-d0310bece6ca4047221698c08de1d85b703bd07d.zip
cleaned up Trees
-rw-r--r--src/compiler/scala/tools/nsc/CompilationUnits.scala2
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala34
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala9
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeInfo.scala4
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreePrinters.scala15
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala66
6 files changed, 44 insertions, 86 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala
index cecac2107f..8822f52642 100644
--- a/src/compiler/scala/tools/nsc/CompilationUnits.scala
+++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala
@@ -15,7 +15,7 @@ trait CompilationUnits { self: Global =>
/** One unit of compilation that has been submitted to the compiler.
* It typically corresponds to a single file of source code. It includes
* error-reporting hooks. */
- class CompilationUnit(val source: SourceFile) extends TreeBody {
+ class CompilationUnit(val source: SourceFile) extends CompilationUnitTrait {
/** the fresh name creator */
var fresh = new FreshNameCreator
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index fd5e1dcd2e..b550dce067 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -32,8 +32,7 @@ import backend.msil.GenMSIL
import backend.opt.{Inliners, ClosureElimination, DeadCodeElimination}
import backend.icode.analysis._
-class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
- with Trees
+class Global(var settings: Settings, var reporter: Reporter) extends Trees
with CompilationUnits
with Plugins
{
@@ -57,25 +56,6 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
}
val nodeToString = nodePrinters.nodeToString
- object treePrinters extends TreePrinters {
- val global: Global.this.type = Global.this
- }
- val treePrinter = treePrinters.create()
- def printTree(tree: Tree, writer: PrintWriter) {
- val printer = treePrinters.create(writer)
- printer.print(tree)
- printer.flush
- }
-
- object treeBrowsers extends TreeBrowsers {
- val global: Global.this.type = Global.this
- }
- val treeBrowser = treeBrowsers.create()
-
- object treeInfo extends TreeInfo {
- val global: Global.this.type = Global.this
- }
-
object gen extends TreeGen {
val global: Global.this.type = Global.this
}
@@ -549,9 +529,9 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
if (settings.print contains globalPhase.name)
if (globalPhase.id >= icodePhase.id) writeICode()
else if (settings.Xshowtrees.value) nodePrinters.printAll()
- else treePrinter.printAll()
+ else printAllUnits()
if (settings.printLate.value && globalPhase.name == "cleanup")
- treePrinter.printAll()
+ printAllUnits()
if (settings.browse contains globalPhase.name) treeBrowser.browse(units)
informTime(globalPhase.description, startTime)
@@ -640,6 +620,14 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
}
} // class Run
+
+ def printAllUnits() {
+ print("[[syntax trees at end of " + phase + "]]")
+ atPhase(phase.next) {
+ for (unit <- currentRun.units) treePrinter.print(unit)
+ }
+ }
+
def showDef(name: Name, module: Boolean) {
def getSym(name: Name, module: Boolean): Symbol = {
var i = name.length - 1
diff --git a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
index d5ee4018cc..2247876a22 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
@@ -27,8 +27,8 @@ import symtab.Flags._
*/
abstract class TreeBrowsers {
- val global: Global
- import global._
+ val trees: Trees
+ import trees._
import nme.EMPTY
def create(): SwingBrowser = new SwingBrowser();
@@ -49,8 +49,6 @@ abstract class TreeBrowsers {
class SwingBrowser {
def browse(t: Tree): Unit = {
- val phase: Phase = globalPhase
-
val tm = new ASTTreeModel(t)
val frame = new BrowserFrame()
@@ -68,7 +66,6 @@ abstract class TreeBrowsers {
/** print the whole program */
def browse(units: List[CompilationUnit]): Unit = {
- val phase: Phase = globalPhase
var unitList: List[UnitTree] = Nil
for (i <- units)
@@ -663,7 +660,7 @@ abstract class TreeBrowsers {
)
case _ =>
- abort("Unknown case: " + t.toString())
+ throw new Error("Unknown case: " + t.toString())
}
}
diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
index 77247576ad..b1347d6be7 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
@@ -16,8 +16,8 @@ import util.HashSet
*/
abstract class TreeInfo {
- val global: Global
- import global._
+ val trees: Trees
+ import trees._
def isTerm(tree: Tree): Boolean = tree.isTerm
def isType(tree: Tree): Boolean = tree.isType
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
index 2a17e9f7ed..f9ee9755d0 100644
--- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
@@ -12,15 +12,15 @@ import symtab.Flags._
abstract class TreePrinters {
- val global: Global
- import global._
+ val trees: Trees
+ import trees._
class TreePrinter(out: PrintWriter) {
protected var indentMargin = 0
protected val indentStep = 2
protected var indentString = " " // 40
- def flush = out.flush()
+ def flush() = out.flush()
def indent = indentMargin += indentStep
def undent = indentMargin -= indentStep
@@ -345,7 +345,7 @@ abstract class TreePrinters {
case tree =>
print("<unknown tree of class "+tree.getClass+">")
}
- if (global.settings.printtypes.value && tree.isTerm && !tree.isEmpty) {
+ if (settings.printtypes.value && tree.isTerm && !tree.isEmpty) {
print("{"); print(if (tree.tpe eq null) "<null>" else tree.tpe.toString()); print("}")
}
}
@@ -374,13 +374,6 @@ abstract class TreePrinters {
}
println; flush
}
-
- def printAll() {
- print("[[syntax trees at end of " + phase + "]]")
- atPhase(phase.next) {
- for (unit <- global.currentRun.units) print(unit)
- }
- }
}
def create(writer: PrintWriter): TreePrinter = new TreePrinter(writer)
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 4c9ab110c7..5d08d4fa8a 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -14,36 +14,37 @@ import scala.tools.nsc.util.{HashSet, Position, NoPosition, SourceFile}
import scala.collection.mutable.ListBuffer
-trait Trees {
- self: SymbolTable =>
+abstract class Trees extends SymbolTable {
//statistics
var nodeCount = 0
- /** print tree into buffer */
- def printTree(tree: Tree, writer: PrintWriter)
-
- trait TreeBody {
+ trait CompilationUnitTrait {
var body: Tree
+ val source: SourceFile
}
- type CompilationUnit <: TreeBody
-
- val copy = new LazyTreeCopier()
+ type CompilationUnit <: CompilationUnitTrait
// sub-components --------------------------------------------------
-/*
- object treeBrowsers extends TreeBrowsers {
- val global: Global.this.type = Global.this
+ object treePrinters extends TreePrinters {
+ val trees: Trees.this.type = Trees.this
}
- val treeBrowser = treeBrowsers.create()
+ val treePrinter = treePrinters.create()
object treeInfo extends TreeInfo {
- val global: Global.this.type = Global.this
+ val trees: Trees.this.type = Trees.this
}
-*/
- // -------------------------------------------------------------------
+
+ val copy = new LazyTreeCopier()
+
+ object treeBrowsers extends TreeBrowsers {
+ val trees: Trees.this.type = Trees.this
+ }
+ val treeBrowser = treeBrowsers.create()
+
+ // modifiers --------------------------------------------------------
case class Modifiers(flags: Long, privateWithin: Name, annotations: List[Annotation]) {
def isCovariant = hasFlag(COVARIANT )
@@ -88,29 +89,6 @@ trait Trees {
val NoMods = Modifiers(0)
- //todo: cleanup
- def isPreSuper(tree: Tree) = tree match {
- case ValDef(mods, _, _, _) => mods hasFlag PRESUPER
- case _ => false
- }
-
- /** Is tree legal as a member definition of an interface?
- //todo: cleanup
- */
- def isInterfaceMember(tree: Tree): Boolean = tree match {
- case EmptyTree => true
- case Import(_, _) => true
- case TypeDef(_, _, _, _) => true
- case DefDef(mods, _, _, _, _, __) => mods.hasFlag(DEFERRED)
- case ValDef(mods, _, _, _) => mods.hasFlag(DEFERRED)
- case DocDef(_, definition) => isInterfaceMember(definition)
- case _ => false
- }
-
-
-
-
-
// @M helper method for asserts that check consistency in kinding
//def kindingIrrelevant(tp: Type) = (tp eq null) || phase.name == "erasure" || phase.erasedTypes
@@ -172,8 +150,10 @@ trait Trees {
override def toString(): String = {
val buffer = new StringWriter()
- printTree(this, new PrintWriter(buffer))
- buffer.toString()
+ val printer = treePrinters.create(new PrintWriter(buffer))
+ printer.print(this)
+ printer.flush()
+ buffer.toString
}
override def hashCode(): Int = super.hashCode()
@@ -519,7 +499,7 @@ trait Trees {
ret.symbol = vd.symbol
ret
})
- val (vdefs, rest) = body span /*treeInfo.*/isPreSuper
+ val (vdefs, rest) = body span treeInfo.isPreSuper
val (lvdefs, gvdefs) = List.unzip {
vdefs map {
case vdef @ ValDef(mods, name, tpt, rhs) =>
@@ -529,7 +509,7 @@ trait Trees {
}
val constrs =
if (constrMods hasFlag TRAIT) {
- if (body forall /*treeInfo.*/isInterfaceMember) List()
+ if (body forall treeInfo.isInterfaceMember) List()
else List(
DefDef(NoMods, nme.MIXIN_CONSTRUCTOR, List(), List(List()), TypeTree(), Block(lvdefs, Literal(()))))
} else {