aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scala/async/TransformUtils.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/scala/async/TransformUtils.scala')
-rw-r--r--src/main/scala/scala/async/TransformUtils.scala40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/scala/scala/async/TransformUtils.scala b/src/main/scala/scala/async/TransformUtils.scala
index 103c8d2..b79be87 100644
--- a/src/main/scala/scala/async/TransformUtils.scala
+++ b/src/main/scala/scala/async/TransformUtils.scala
@@ -4,6 +4,7 @@
package scala.async
import scala.reflect.macros.Context
+import reflect.ClassTag
/**
* Utilities used in both `ExprBuilder` and `AnfTransform`.
@@ -117,4 +118,43 @@ class TransformUtils[C <: Context](val c: C) {
case s: SymTree if s.symbol.isMethod => s.symbol
}.headOption.getOrElse(sys.error(s"Unable to find a method symbol in ${apply.tree}"))
}
+
+ /** Using [[scala.reflect.api.Trees.TreeCopier]] copies more than we would like:
+ * we don't want to copy types and symbols to the new trees in some cases.
+ *
+ * Instead, we just copy positions and attachments.
+ */
+ object attachCopy {
+ def copyAttach[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))
+ }
}