aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scala/async/TransformUtils.scala
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2012-12-03 04:56:10 -0800
committerPhilipp Haller <hallerp@gmail.com>2012-12-03 04:56:10 -0800
commit3859c11bca3ce9d9d2b18ec629dcc4b6218cf2e0 (patch)
treecf44ad32de20097b6c1795d01c988fe505c1e7b9 /src/main/scala/scala/async/TransformUtils.scala
parentcfe0649e16e60a704fee47c4111ebd1a1c24473e (diff)
parentc79d8c07d194aeaa0565f2c136b8308519d59015 (diff)
downloadscala-async-3859c11bca3ce9d9d2b18ec629dcc4b6218cf2e0.tar.gz
scala-async-3859c11bca3ce9d9d2b18ec629dcc4b6218cf2e0.tar.bz2
scala-async-3859c11bca3ce9d9d2b18ec629dcc4b6218cf2e0.zip
Merge pull request #47 from phaller/ticket/46-varargs-holistic-apply
Fix ANF transform involving `xs: _*` trees.
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
+ }
+ }
}