aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scala/async/TransformUtils.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-11-27 17:42:40 +0100
committerJason Zaugg <jzaugg@gmail.com>2012-11-27 17:44:38 +0100
commitc79d8c07d194aeaa0565f2c136b8308519d59015 (patch)
tree01cdb87f6ae7d67921994e0540035462122c1aa3 /src/main/scala/scala/async/TransformUtils.scala
parent5ee41166ea1684672ddb9a0d605a664661ba5f47 (diff)
downloadscala-async-c79d8c07d194aeaa0565f2c136b8308519d59015.tar.gz
scala-async-c79d8c07d194aeaa0565f2c136b8308519d59015.tar.bz2
scala-async-c79d8c07d194aeaa0565f2c136b8308519d59015.zip
Fix ANF transform involving `xs: _*` trees.
We need to unwrap and inline `xs`, then rewrap the result expression with the wildcard star. Addresses the first half of #46.
Diffstat (limited to 'src/main/scala/scala/async/TransformUtils.scala')
-rw-r--r--src/main/scala/scala/async/TransformUtils.scala21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main/scala/scala/async/TransformUtils.scala b/src/main/scala/scala/async/TransformUtils.scala
index 23f39d2..f780799 100644
--- a/src/main/scala/scala/async/TransformUtils.scala
+++ b/src/main/scala/scala/async/TransformUtils.scala
@@ -253,4 +253,25 @@ private[async] final case class TransformUtils[C <: Context](c: C) {
val castTree = tree.asInstanceOf[symtab.Tree]
treeInfo.isExprSafeToInline(castTree)
}
+
+ /** Map a list of arguments to:
+ * - A list of argument Trees
+ * - A list of auxillary results.
+ *
+ * The function unwraps and rewraps the `arg :_*` construct.
+ *
+ * @param args The original argument trees
+ * @param f A function from argument (with '_*' unwrapped) and argument index to argument.
+ * @tparam A The type of the auxillary result
+ */
+ def mapArguments[A](args: List[Tree])(f: (Tree, Int) => (A, Tree)): (List[A], List[Tree]) = {
+ args match {
+ case args :+ Typed(tree, Ident(tpnme.WILDCARD_STAR)) =>
+ val (a, argExprs :+ lastArgExpr) = (args :+ tree).zipWithIndex.map(f.tupled).unzip
+ val exprs = argExprs :+ Typed(lastArgExpr, Ident(tpnme.WILDCARD_STAR)).setPos(lastArgExpr.pos)
+ (a, exprs)
+ case args =>
+ args.zipWithIndex.map(f.tupled).unzip
+ }
+ }
}