diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala | 51 |
1 files changed, 18 insertions, 33 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 91ff530e05..fba74330a6 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -191,14 +191,6 @@ abstract class TreeBuilder { } } - /** Create a tree representing an assignment <lhs = rhs> */ - def makeAssign(lhs: Tree, rhs: Tree): Tree = lhs match { - case Apply(fn, args) => - Apply(atPos(fn.pos) { Select(fn, nme.update) }, args ::: List(rhs)) - case _ => - Assign(lhs, rhs) - } - /** Tree for `od op`, start is start0 if od.pos is borked. */ def makePostfixSelect(start0: Int, end: Int, od: Tree, op: Name): Tree = { val start = if (od.pos.isDefined) od.pos.startOrPoint else start0 @@ -206,22 +198,21 @@ abstract class TreeBuilder { } /** Create tree representing a while loop */ - def makeWhile(startPos: Int, cond: Tree, body: Tree): Tree = { - val lname = freshTermName(nme.WHILE_PREFIX) - def default = wrappingPos(List(cond, body)) match { - case p if p.isDefined => p.endOrPoint - case _ => startPos - } - val continu = atPos(o2p(body.pos pointOrElse default)) { Apply(Ident(lname), Nil) } - val rhs = If(cond, Block(List(body), continu), Literal(Constant(()))) - LabelDef(lname, Nil, rhs) + def makeWhile(cond: Tree, body: Tree): Tree = { + val lname = freshTermName(nme.WHILE_PREFIX) + val continu = atPos(cond.pos.focus)(Apply(Ident(lname), Nil)) + val rhs = atPos(cond.pos union body.pos)(If(cond, atPos(body.pos)(Block(body :: Nil, continu)), Literal(Constant(())))) + + atPos(rhs.pos)(LabelDef(lname, Nil, rhs)) } /** Create tree representing a do-while loop */ def makeDoWhile(lname: TermName, body: Tree, cond: Tree): Tree = { - val continu = Apply(Ident(lname), Nil) - val rhs = Block(List(body), If(cond, continu, Literal(Constant(())))) - LabelDef(lname, Nil, rhs) + val continu = atPos(cond.pos.focus)(Apply(Ident(lname), Nil)) + val condition = atPos(cond.pos)(If(cond, continu, Literal(Constant(())))) + val rhs = atPos(cond.pos union body.pos)(Block(body :: Nil, condition)) + + atPos(rhs.pos)(LabelDef(lname, Nil, rhs)) } /** Create block of statements `stats` */ @@ -313,19 +304,13 @@ abstract class TreeBuilder { * The closure is assigned a transparent position with the point at pos.point and * the limits given by pat and body. */ - def makeClosure(pos: Position, pat: Tree, body: Tree): Tree = { - def splitpos = wrappingPos(List(pat, body)).withPoint(pos.point).makeTransparent - matchVarPattern(pat) match { - case Some((name, tpt)) => - Function( - List(atPos(pat.pos) { ValDef(Modifiers(PARAM), name.toTermName, tpt, EmptyTree) }), - body) setPos splitpos - case None => - atPos(splitpos) { - makeVisitor(List(CaseDef(pat, EmptyTree, body)), checkExhaustive = false) - } + def makeClosure(pos: Position, pat: Tree, body: Tree): Tree = + atPos((pos union pat.pos union body.pos).makeTransparent) { + matchVarPattern(pat) match { + case Some((name, tpt)) => Function(atPos(pat.pos)(ValDef(Modifiers(PARAM), name.toTermName, tpt, EmptyTree)) :: Nil, body) + case None => makeVisitor(CaseDef(pat, body) :: Nil, checkExhaustive = false) + } } - } /* Make an application qual.meth(pat => body) positioned at `pos`. */ @@ -503,7 +488,7 @@ abstract class TreeBuilder { tmp, TypeTree(), matchExpr) } var cnt = 0 - val restDefs = for ((vname, tpt, pos) <- vars) yield atPos(pos) { + val restDefs = for ((vname, tpt, pos) <- vars) yield atPos(pos.focus) { cnt += 1 ValDef(mods, vname.toTermName, tpt, Select(Ident(tmp), newTermName("_" + cnt))) } |