summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
diff options
context:
space:
mode:
authorDen Shabalin <den.shabalin@gmail.com>2013-07-08 20:24:45 +0200
committerEugene Burmako <xeno.by@gmail.com>2013-07-08 21:02:30 +0200
commit310df92551c33ed0242e9a50606732a9b02bfee8 (patch)
treed605db96d7ce1fa8b590d48617853f46513e0c2c /src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
parent9e064f783e7ee42b9d27655e2b15d830f8bae5f0 (diff)
downloadscala-310df92551c33ed0242e9a50606732a9b02bfee8.tar.gz
scala-310df92551c33ed0242e9a50606732a9b02bfee8.tar.bz2
scala-310df92551c33ed0242e9a50606732a9b02bfee8.zip
moves TreeBuilder into the parser
This is the first of the two patches to the parser necessary for quasiquotes to function. This one moves TreeBuilder from Global to the internals of the Parsers, so that quasiquotes will be able to override it later to support some corner cases arising from splicing (see the subsequent quasiquote commit for more details). Surprisingly enough, almost noone used TreeBuilder outside the parser, and it was necessary to move just a couple of methods to TreeGen to satisfy broken dependencies.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index ef5872986c..8778a655c1 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -26,13 +26,22 @@ import util.FreshNameCreator
* the beginnings of a campaign against this latest incursion by Cutty
* McPastington and his army of very similar soldiers.
*/
-trait ParsersCommon extends ScannersCommon {
+trait ParsersCommon extends ScannersCommon { self =>
val global : Global
import global._
def newLiteral(const: Any) = Literal(Constant(const))
def literalUnit = newLiteral(())
+ class ParserTreeBuilder extends TreeBuilder {
+ val global: self.global.type = self.global
+ 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)
+ }
+
/** This is now an abstract class, only to work around the optimizer:
* methods in traits are never inlined.
*/
@@ -290,6 +299,7 @@ self =>
/** whether a non-continuable syntax error has been seen */
private var lastErrorOffset : Int = -1
+ val treeBuilder = new ParserTreeBuilder
import treeBuilder.{global => _, _}
/** The types of the context bounds of type parameters of the surrounding class
@@ -399,7 +409,7 @@ self =>
def mainParamType = AppliedTypeTree(Ident(tpnme.Array), List(Ident(tpnme.String)))
def mainParameter = List(ValDef(Modifiers(Flags.PARAM), nme.argv, mainParamType, EmptyTree))
def mainSetArgv = List(ValDef(NoMods, nme.args, TypeTree(), Ident(nme.argv)))
- def mainDef = DefDef(NoMods, nme.main, Nil, List(mainParameter), scalaDot(tpnme.Unit), Block(mainSetArgv, makeAnonymousNew(stmts)))
+ def mainDef = DefDef(NoMods, nme.main, Nil, List(mainParameter), scalaDot(tpnme.Unit), Block(mainSetArgv, gen.mkAnonymousNew(stmts)))
// object Main
def moduleName = newTermName(ScriptRunner scriptMain settings)
@@ -1501,7 +1511,7 @@ self =>
val pname = freshName("x$")
in.nextToken()
val id = atPos(start) (Ident(pname))
- val param = atPos(id.pos.focus){ makeSyntheticParam(pname.toTermName) }
+ val param = atPos(id.pos.focus){ gen.mkSyntheticParam(pname.toTermName) }
placeholderParams = param :: placeholderParams
id
case LPAREN =>
@@ -1516,7 +1526,7 @@ self =>
val tstart = in.offset
val (parents, self, stats) = template()
val cpos = r2p(tstart, tstart, in.lastOffset max tstart)
- makeNew(parents, self, stats, npos, cpos)
+ gen.mkNew(parents, self, stats, npos, cpos)
case _ =>
syntaxErrorOrIncompleteAnd("illegal start of simple expression", skipIt = true)(errorTermTree)
}