diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-16 03:06:34 -0700 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-16 03:06:34 -0700 |
commit | 9dbc321504ad5550638d6d7c2b3cd2f98273cf74 (patch) | |
tree | 7459704f5c9f0d471e63ec56b4f15c2803f10a59 /src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | |
parent | 8c68723acd738d94d049ac996d5e0ea22659c4ba (diff) | |
parent | 8a7b5666b6f10728f7c3ae9ca1bc2a8b82f6b965 (diff) | |
download | scala-9dbc321504ad5550638d6d7c2b3cd2f98273cf74.tar.gz scala-9dbc321504ad5550638d6d7c2b3cd2f98273cf74.tar.bz2 scala-9dbc321504ad5550638d6d7c2b3cd2f98273cf74.zip |
Merge pull request #2935 from densh/topic/si-7304-6489-6701
SI-6701, SI-7304, SI-6489, variable arity definitions refactoring
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index a974352169..07e24900e9 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -28,20 +28,14 @@ import util.FreshNameCreator */ trait ParsersCommon extends ScannersCommon { self => val global : Global - import global._ + // the use of currentUnit in the parser should be avoided as it might + // cause unexpected behaviour when you work with two units at the + // same time; use Parser.unit instead + import global.{currentUnit => _, _} 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. */ @@ -172,6 +166,7 @@ self => private val globalFresh = new FreshNameCreator.Default + def unit = global.currentUnit def freshName(prefix: String): Name = freshTermName(prefix) def freshTermName(prefix: String): TermName = newTermName(globalFresh.newName(prefix)) def freshTypeName(prefix: String): TypeName = newTypeName(globalFresh.newName(prefix)) @@ -196,7 +191,7 @@ self => * that we don't have the xml library on the compilation classpath. */ private[this] lazy val xmlp = { - currentUnit.encounteredXml(o2p(in.offset)) + unit.encounteredXml(o2p(in.offset)) new MarkupParser(this, preserveWS = true) } @@ -225,7 +220,7 @@ self => override def templateBody(isPre: Boolean) = skipBraces((emptyValDef, EmptyTree.asList)) } - class UnitParser(val unit: global.CompilationUnit, patches: List[BracePatch]) extends SourceFileParser(unit.source) { + class UnitParser(override val unit: global.CompilationUnit, patches: List[BracePatch]) extends SourceFileParser(unit.source) { uself => def this(unit: global.CompilationUnit) = this(unit, Nil) override def newScanner() = new UnitScanner(unit, patches) @@ -298,9 +293,10 @@ self => import nme.raw - abstract class Parser extends ParserCommon { + abstract class Parser extends ParserCommon { parser => val in: Scanner + def unit: CompilationUnit def freshName(prefix: String): Name def freshTermName(prefix: String): TermName def freshTypeName(prefix: String): TypeName @@ -310,8 +306,12 @@ self => /** whether a non-continuable syntax error has been seen */ private var lastErrorOffset : Int = -1 + class ParserTreeBuilder extends UnitTreeBuilder { + val global: self.global.type = self.global + def unit = parser.unit + } val treeBuilder = new ParserTreeBuilder - import treeBuilder.{global => _, _} + import treeBuilder.{global => _, unit => _, _} /** The types of the context bounds of type parameters of the surrounding class */ |