diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-11-24 12:46:26 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-11-24 12:46:26 +0100 |
commit | 32c5e0d67abf333daa91b0e95b7b38393f2bd37c (patch) | |
tree | 47163e9db0a5aa97979921776161242c79d137f3 /src/main/scala | |
parent | dac1d9497a1521be937afa8f09dbdee2f2280f8b (diff) | |
download | scala-async-32c5e0d67abf333daa91b0e95b7b38393f2bd37c.tar.gz scala-async-32c5e0d67abf333daa91b0e95b7b38393f2bd37c.tar.bz2 scala-async-32c5e0d67abf333daa91b0e95b7b38393f2bd37c.zip |
More small refactorings.
Goal is to make ExprBuilder less cluttered.
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/scala/async/Async.scala | 2 | ||||
-rw-r--r-- | src/main/scala/scala/async/ExprBuilder.scala | 35 | ||||
-rw-r--r-- | src/main/scala/scala/async/TransformUtils.scala | 4 |
3 files changed, 14 insertions, 27 deletions
diff --git a/src/main/scala/scala/async/Async.scala b/src/main/scala/scala/async/Async.scala index 8c956f1..473b948 100644 --- a/src/main/scala/scala/async/Async.scala +++ b/src/main/scala/scala/async/Async.scala @@ -105,7 +105,7 @@ abstract class AsyncBase { val initStates = asyncStates.init val localVarTrees = anfTree.collect { case vd@ValDef(_, _, tpt, _) if renameMap contains vd.symbol => - builder.mkVarDefTree(tpt.tpe, renameMap(vd.symbol)) + utils.mkVarDefTree(tpt.tpe, renameMap(vd.symbol)) } /* diff --git a/src/main/scala/scala/async/ExprBuilder.scala b/src/main/scala/scala/async/ExprBuilder.scala index 415c47d..298d5e7 100644 --- a/src/main/scala/scala/async/ExprBuilder.scala +++ b/src/main/scala/scala/async/ExprBuilder.scala @@ -26,21 +26,16 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](va private def mkResumeApply = Apply(Ident(name.resume), Nil) private def mkStateTree(nextState: Int): c.Tree = - mkStateTree(c.literal(nextState).tree) - - private def mkStateTree(nextState: Tree): c.Tree = - Assign(Ident(name.state), nextState) - - def mkVarDefTree(resultType: Type, resultName: TermName): c.Tree = { - ValDef(Modifiers(Flag.MUTABLE), resultName, TypeTree(resultType), defaultValue(resultType)) - } + Assign(Ident(name.state), c.literal(nextState).tree) private def mkHandlerCase(num: Int, rhs: List[c.Tree]): CaseDef = mkHandlerCase(num, Block(rhs: _*)) - private def mkHandlerCase(num: Int, rhs: c.Tree): CaseDef = { + private def mkHandlerCase(num: Int, rhs: c.Tree): CaseDef = CaseDef(c.literal(num).tree, EmptyTree, rhs) - } + + val stateAssigner = new StateAssigner + val labelDefStates = collection.mutable.Map[Symbol, Int]() class AsyncState(stats: List[c.Tree], val state: Int, val nextState: Int) { val body: c.Tree = stats match { @@ -48,8 +43,6 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](va case _ => Block(stats: _*) } - val varDefs: List[(TermName, Type)] = Nil - def mkHandlerCaseForState(): CaseDef = mkHandlerCase(state, stats :+ mkStateTree(nextState) :+ mkResumeApply) @@ -139,18 +132,12 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](va this } - //TODO do not ignore `mods` - def addVarDef(mods: Any, name: TermName, tpt: c.Tree, rhs: c.Tree): this.type = { - this += Assign(Ident(name), rhs) - this - } - def result(): AsyncState = { - val effectiveNestState = nextJumpState.getOrElse(nextState) + val effectiveNextState = nextJumpState.getOrElse(nextState) if (awaitable == null) - new AsyncState(stats.toList, state, effectiveNestState) + new AsyncState(stats.toList, state, effectiveNextState) else - new AsyncStateWithAwait(stats.toList, state, effectiveNestState, awaitable, resultName, resultType) + new AsyncStateWithAwait(stats.toList, state, effectiveNextState, awaitable, resultName, resultType) } /* Result needs to be created as a var at the beginning of the transformed method body, so that @@ -214,10 +201,6 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](va } } - val stateAssigner = new StateAssigner - - val labelDefStates = collection.mutable.Map[Symbol, Int]() - /** * An `AsyncBlockBuilder` builds a `ListBuffer[AsyncState]` based on the expressions of a `Block(stats, expr)` (see `Async.asyncImpl`). * @@ -227,7 +210,7 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](va * @param endState the state to continue with * @param toRename a `Map` for renaming the given key symbols to the mangled value names */ - class AsyncBlockBuilder(stats: List[c.Tree], expr: c.Tree, startState: Int, endState: Int, + final class AsyncBlockBuilder(stats: List[c.Tree], expr: c.Tree, startState: Int, endState: Int, private val toRename: Map[Symbol, c.Name]) { val asyncStates = ListBuffer[builder.AsyncState]() diff --git a/src/main/scala/scala/async/TransformUtils.scala b/src/main/scala/scala/async/TransformUtils.scala index 03709ab..22099b5 100644 --- a/src/main/scala/scala/async/TransformUtils.scala +++ b/src/main/scala/scala/async/TransformUtils.scala @@ -124,6 +124,10 @@ private[async] final case class TransformUtils[C <: Context](val c: C) { case _ => (List(tree), Literal(Constant(()))) } + def mkVarDefTree(resultType: Type, resultName: TermName): c.Tree = { + ValDef(Modifiers(Flag.MUTABLE), resultName, TypeTree(resultType), defaultValue(resultType)) + } + object defn { def mkList_apply[A](args: List[Expr[A]]): Expr[List[A]] = { c.Expr(Apply(Ident(definitions.List_apply), args.map(_.tree))) |