diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/scala/async/AnfTransform.scala | 22 | ||||
-rw-r--r-- | src/main/scala/scala/async/AsyncAnalysis.scala | 4 | ||||
-rw-r--r-- | src/main/scala/scala/async/TransformUtils.scala | 27 |
3 files changed, 14 insertions, 39 deletions
diff --git a/src/main/scala/scala/async/AnfTransform.scala b/src/main/scala/scala/async/AnfTransform.scala index 5effa8f..f52bdad 100644 --- a/src/main/scala/scala/async/AnfTransform.scala +++ b/src/main/scala/scala/async/AnfTransform.scala @@ -127,11 +127,11 @@ private[async] final case class AnfTransform[C <: Context](c: C) { val varDef = defineVar(name.matchRes, expr.tpe, tree.pos) val casesWithAssign = cases map { case cd@CaseDef(pat, guard, Block(caseStats, caseExpr)) => - attachCopy.CaseDef(cd)(pat, guard, Block(caseStats, Assign(Ident(varDef.name), caseExpr))) + attachCopy(cd)(CaseDef(pat, guard, Block(caseStats, Assign(Ident(varDef.name), caseExpr)))) case cd@CaseDef(pat, guard, body) => - attachCopy.CaseDef(cd)(pat, guard, Assign(Ident(varDef.name), body)) + attachCopy(cd)(CaseDef(pat, guard, Assign(Ident(varDef.name), body))) } - val matchWithAssign = attachCopy.Match(tree)(scrut, casesWithAssign) + val matchWithAssign = attachCopy(tree)(Match(scrut, casesWithAssign)) stats :+ varDef :+ matchWithAssign :+ Ident(varDef.name) } case _ => @@ -168,7 +168,7 @@ private[async] final case class AnfTransform[C <: Context](c: C) { tree match { case Select(qual, sel) if containsAwait => val stats :+ expr = inline.transformToList(qual) - stats :+ attachCopy.Select(tree)(expr, sel).setSymbol(tree.symbol) + stats :+ attachCopy(tree)(Select(expr, sel).setSymbol(tree.symbol)) case Apply(fun, args) if containsAwait => // we an assume that no await call appears in a by-name argument position, @@ -178,7 +178,7 @@ private[async] final case class AnfTransform[C <: Context](c: C) { val argLists = args map inline.transformToList val allArgStats = argLists flatMap (_.init) val simpleArgs = argLists map (_.last) - funStats ++ allArgStats :+ attachCopy.Apply(tree)(simpleFun, simpleArgs).setSymbol(tree.symbol) + funStats ++ allArgStats :+ attachCopy(tree)(Apply(simpleFun, simpleArgs).setSymbol(tree.symbol)) case Block(stats, expr) if containsAwait => inline.transformToList(stats :+ expr) @@ -186,35 +186,35 @@ private[async] final case class AnfTransform[C <: Context](c: C) { case ValDef(mods, name, tpt, rhs) if containsAwait => if (rhs exists isAwait) { val stats :+ expr = inline.transformToList(rhs) - stats :+ attachCopy.ValDef(tree)(mods, name, tpt, expr).setSymbol(tree.symbol) + stats :+ attachCopy(tree)(ValDef(mods, name, tpt, expr).setSymbol(tree.symbol)) } else List(tree) case Assign(lhs, rhs) if containsAwait => val stats :+ expr = inline.transformToList(rhs) - stats :+ attachCopy.Assign(tree)(lhs, expr) + stats :+ attachCopy(tree)(Assign(lhs, expr)) case If(cond, thenp, elsep) if containsAwait => val stats :+ expr = inline.transformToList(cond) val thenBlock = inline.transformToBlock(thenp) val elseBlock = inline.transformToBlock(elsep) stats :+ - c.typeCheck(attachCopy.If(tree)(expr, thenBlock, elseBlock)) + c.typeCheck(attachCopy(tree)(If(expr, thenBlock, elseBlock))) case Match(scrut, cases) if containsAwait => val scrutStats :+ scrutExpr = inline.transformToList(scrut) val caseDefs = cases map { case CaseDef(pat, guard, body) => val block = inline.transformToBlock(body) - attachCopy.CaseDef(tree)(pat, guard, block) + attachCopy(tree)(CaseDef(pat, guard, block)) } - scrutStats :+ c.typeCheck(attachCopy.Match(tree)(scrutExpr, caseDefs)) + scrutStats :+ c.typeCheck(attachCopy(tree)(Match(scrutExpr, caseDefs))) case LabelDef(name, params, rhs) if containsAwait => List(LabelDef(name, params, Block(inline.transformToList(rhs), Literal(Constant(())))).setSymbol(tree.symbol)) case TypeApply(fun, targs) if containsAwait => val funStats :+ simpleFun = inline.transformToList(fun) - funStats :+ attachCopy.TypeApply(tree)(simpleFun, targs).setSymbol(tree.symbol) + funStats :+ attachCopy(tree)(TypeApply(simpleFun, targs).setSymbol(tree.symbol)) case _ => List(tree) diff --git a/src/main/scala/scala/async/AsyncAnalysis.scala b/src/main/scala/scala/async/AsyncAnalysis.scala index 0394e4a..645d9f5 100644 --- a/src/main/scala/scala/async/AsyncAnalysis.scala +++ b/src/main/scala/scala/async/AsyncAnalysis.scala @@ -5,7 +5,7 @@ package scala.async import scala.reflect.macros.Context -import collection.mutable +import scala.collection.mutable private[async] final case class AsyncAnalysis[C <: Context](c: C) { import c.universe._ @@ -102,7 +102,7 @@ private[async] final case class AsyncAnalysis[C <: Context](c: C) { private var valDefChunkId = Map[Symbol, (ValDef, Int)]() - val valDefsToLift: mutable.Set[ValDef] = collection.mutable.Set[ValDef]() + val valDefsToLift = mutable.Set[ValDef]() override def traverse(tree: Tree) = { tree match { diff --git a/src/main/scala/scala/async/TransformUtils.scala b/src/main/scala/scala/async/TransformUtils.scala index 7b2f135..afa52b8 100644 --- a/src/main/scala/scala/async/TransformUtils.scala +++ b/src/main/scala/scala/async/TransformUtils.scala @@ -174,37 +174,12 @@ private[async] final case class TransformUtils[C <: Context](c: C) { * Instead, we just copy positions and attachments. */ object attachCopy { - def copyAttach[T <: Tree](orig: Tree, tree: T): tree.type = { + def apply[T <: Tree](orig: Tree)(tree: T): tree.type = { tree.setPos(orig.pos) for (att <- orig.attachments.all) tree.updateAttachment[Any](att)(ClassTag.apply[Any](att.getClass)) tree } - - def Apply(tree: Tree)(fun: Tree, args: List[Tree]): Apply = - copyAttach(tree, c.universe.Apply(fun, args)) - - def Assign(tree: Tree)(lhs: Tree, rhs: Tree): Assign = - copyAttach(tree, c.universe.Assign(lhs, rhs)) - - def CaseDef(tree: Tree)(pat: Tree, guard: Tree, block: Tree): CaseDef = - copyAttach(tree, c.universe.CaseDef(pat, guard, block)) - - def If(tree: Tree)(cond: Tree, thenp: Tree, elsep: Tree): If = - copyAttach(tree, c.universe.If(cond, thenp, elsep)) - - def Match(tree: Tree)(selector: Tree, cases: List[CaseDef]): Match = - copyAttach(tree, c.universe.Match(selector, cases)) - - def Select(tree: Tree)(qual: Tree, name: Name): Select = - copyAttach(tree, c.universe.Select(qual, name)) - - def TypeApply(tree: Tree)(fun: Tree, args: List[Tree]): TypeApply = { - copyAttach(tree, c.universe.TypeApply(fun, args)) - } - - def ValDef(tree: Tree)(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree): ValDef = - copyAttach(tree, c.universe.ValDef(mods, name, tpt, rhs)) } } |