summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/Global.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-09-12 19:32:28 -0700
committerPaul Phillips <paulp@improving.org>2012-09-12 20:47:39 -0700
commit5f674e44c5d3dccb55ce080c60d92b8e412d03ac (patch)
tree64362883bda37fa6beb7687364515363f31721a0 /src/compiler/scala/tools/nsc/Global.scala
parent1806830ec802feea0b89f1a71e0dc15c1507b965 (diff)
downloadscala-5f674e44c5d3dccb55ce080c60d92b8e412d03ac.tar.gz
scala-5f674e44c5d3dccb55ce080c60d92b8e412d03ac.tar.bz2
scala-5f674e44c5d3dccb55ce080c60d92b8e412d03ac.zip
Rescued TreeBuilder from the parser.
For too long, Tree Builder has ruled over those who would like to build their own trees. Today marks the start of a new era. Trees are for building, not for parsers to hoard. It's in Global now. The particular motivation is exposing makeNew, and I also added makeAnonymousNew, so rather than this... Apply(Select( Block(List(ClassDef( Modifiers(scala.tools.nsc.symtab.Flags.FINAL), tpnme.ANON_CLASS_NAME, Nil, Template(List(Ident(definitions.AnyRefClass)), emptyValDef, List( DefDef(NoMods, nme.CONSTRUCTOR, Nil, List(Nil), TypeTree(), Block( List(Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), Nil)), Literal(Constant(())) )))))), Apply(Select(New(Ident(tpnme.ANON_CLASS_NAME)), nme.CONSTRUCTOR), Nil)) , sn.GetClass), Nil) We can write this. Apply(Select(makeAnonymousNew(Nil), nme.getClass_), Nil)
Diffstat (limited to 'src/compiler/scala/tools/nsc/Global.scala')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index d101337087..9e3f47e8fb 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -13,7 +13,7 @@ import scala.collection.{ mutable, immutable }
import io.{ SourceReader, AbstractFile, Path }
import reporters.{ Reporter, ConsoleReporter }
import util.{ Exceptional, ClassPath, MergedClassPath, StatisticsInfo, ScalaClassLoader, returning }
-import scala.reflect.internal.util.{ NoPosition, SourceFile, NoSourceFile, BatchSourceFile, ScriptSourceFile }
+import scala.reflect.internal.util.{ NoPosition, OffsetPosition, SourceFile, NoSourceFile, BatchSourceFile, ScriptSourceFile }
import scala.reflect.internal.pickling.{ PickleBuffer, PickleFormat }
import settings.{ AestheticSettings }
import symtab.{ Flags, SymbolTable, SymbolLoaders, SymbolTrackers }
@@ -96,6 +96,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
/** Generate ASTs */
type TreeGen = scala.tools.nsc.ast.TreeGen
+ /** Tree generation, usually based on existing symbols. */
override object gen extends {
val global: Global.this.type = Global.this
} with TreeGen {
@@ -103,6 +104,17 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
typer.typed(mkCast(tree, pt))
}
+ /** Trees fresh from the oven, mostly for use by the parser. */
+ object treeBuilder extends {
+ val global: Global.this.type = Global.this
+ } with TreeBuilder {
+ def freshName(prefix: String): Name = freshTermName(prefix)
+ def freshTermName(prefix: String): TermName = currentUnit.freshTermName(prefix)
+ def freshTypeName(prefix: String): TypeName = currentUnit.freshTypeName(prefix)
+ def o2p(offset: Int): Position = new OffsetPosition(currentUnit.source, offset)
+ def r2p(start: Int, mid: Int, end: Int): Position = rangePos(currentUnit.source, start, mid, end)
+ }
+
/** Fold constants */
object constfold extends {
val global: Global.this.type = Global.this