diff options
author | Martin Odersky <odersky@gmail.com> | 2007-08-21 17:56:34 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2007-08-21 17:56:34 +0000 |
commit | 1e350595d8ad8a30234750da25a1718235547202 (patch) | |
tree | 0ee472217479faeb6f5d84b8527c4e973805ad85 | |
parent | 649289cb6882a3534ef7ac2f4a50e096af84c45f (diff) | |
download | scala-1e350595d8ad8a30234750da25a1718235547202.tar.gz scala-1e350595d8ad8a30234750da25a1718235547202.tar.bz2 scala-1e350595d8ad8a30234750da25a1718235547202.zip |
disentangled Trees from Global.
-rw-r--r-- | src/compiler/scala/tools/nsc/CompilationUnits.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Trees.scala | 59 |
3 files changed, 60 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala index 0d3dff42a8..cecac2107f 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) { + class CompilationUnit(val source: SourceFile) extends TreeBody { /** 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 b0f6c17585..fd5e1dcd2e 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -61,6 +61,11 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable 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 @@ -111,7 +116,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable val global: Global.this.type = Global.this } - val copy = new LazyTreeCopier() +// val copy = new LazyTreeCopier() val comments = if (onlyPresentation) new HashMap[Symbol,String] diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index d5e103fcd7..4c9ab110c7 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -8,18 +8,43 @@ package scala.tools.nsc.ast import java.io.{PrintWriter, StringWriter} -import scala.tools.nsc.symtab.Flags +import scala.tools.nsc.symtab.{Flags, SymbolTable} import scala.tools.nsc.symtab.Flags._ import scala.tools.nsc.util.{HashSet, Position, NoPosition, SourceFile} import scala.collection.mutable.ListBuffer trait Trees { - self: Global => + self: SymbolTable => //statistics var nodeCount = 0 + /** print tree into buffer */ + def printTree(tree: Tree, writer: PrintWriter) + + trait TreeBody { + var body: Tree + } + + type CompilationUnit <: TreeBody + + val copy = new LazyTreeCopier() + + // sub-components -------------------------------------------------- + +/* + 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 + } +*/ + // ------------------------------------------------------------------- + case class Modifiers(flags: Long, privateWithin: Name, annotations: List[Annotation]) { def isCovariant = hasFlag(COVARIANT ) def isContravariant = hasFlag(CONTRAVARIANT) @@ -63,6 +88,29 @@ 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 @@ -124,8 +172,7 @@ trait Trees { override def toString(): String = { val buffer = new StringWriter() - val printer = treePrinters.create(new PrintWriter(buffer)) - printer.print(this); printer.flush + printTree(this, new PrintWriter(buffer)) buffer.toString() } @@ -472,7 +519,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) => @@ -482,7 +529,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 { |