summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/UnCurry.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-02-22 22:46:32 -0800
committerPaul Phillips <paulp@improving.org>2012-02-23 00:35:22 -0800
commit4a984f82d5bfca05123c53bd385d0299818f8a75 (patch)
treed9f5cc270fee70649ee22cd715c0899ae204ef26 /src/compiler/scala/tools/nsc/transform/UnCurry.scala
parent98cf4014a3a14dbc348a464584133d90719bdbb8 (diff)
downloadscala-4a984f82d5bfca05123c53bd385d0299818f8a75.tar.gz
scala-4a984f82d5bfca05123c53bd385d0299818f8a75.tar.bz2
scala-4a984f82d5bfca05123c53bd385d0299818f8a75.zip
Methods to derive new DefDefs.
I guess I'd seen DefDef(mods, name, tparams, vparamss, tpt, rhs) one too many times and went a little crazy. What do you prefer: - val DefDef(mods, name, tparams, vparamss, tpt, rhs) = tree1 - treeCopy.DefDef(tree1, mods, name, tparams, vparamss, tpt, transform(rhs)) + deriveDefDef(tree1)(transform) Me too.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/UnCurry.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index 6a7fcc98c3..4b587a3f41 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -458,9 +458,8 @@ abstract class UnCurry extends InfoTransform
*/
private def replaceElidableTree(tree: Tree): Tree = {
tree match {
- case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
- val newRhs = Block(Nil, gen.mkZero(rhs.tpe)) setType rhs.tpe
- treeCopy.DefDef(tree, mods, name, tparams, vparamss, tpt, newRhs) setSymbol tree.symbol setType tree.tpe
+ case DefDef(_,_,_,_,_,_) =>
+ deriveDefDef(tree)(rhs => Block(Nil, gen.mkZero(rhs.tpe)) setType rhs.tpe) setSymbol tree.symbol setType tree.tpe
case _ =>
gen.mkZero(tree.tpe) setType tree.tpe
}
@@ -628,14 +627,16 @@ abstract class UnCurry extends InfoTransform
} else super.transform(tree).asInstanceOf[Template]
newMembers.clear
tmpl
- case dd @ DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
- val rhs1 = nonLocalReturnKeys.get(tree.symbol) match {
- case None => rhs
- case Some(k) => atPos(rhs.pos)(nonLocalReturnTry(rhs, k, tree.symbol))
- }
- val flatdd = treeCopy.DefDef(tree, mods, name, tparams, List(vparamss.flatten), tpt, rhs1)
- if (dd.symbol hasAnnotation VarargsClass) addJavaVarargsForwarders(dd, flatdd, tree)
- flatdd
+ case dd @ DefDef(_, _, _, vparamss0, _, rhs0) =>
+ val flatdd = copyDefDef(dd)(
+ vparamss = List(vparamss0.flatten),
+ rhs = nonLocalReturnKeys get dd.symbol match {
+ case Some(k) => atPos(rhs0.pos)(nonLocalReturnTry(rhs0, k, dd.symbol))
+ case None => rhs0
+ }
+ )
+ addJavaVarargsForwarders(dd, flatdd)
+
case Try(body, catches, finalizer) =>
if (opt.virtPatmat) { if(catches exists (cd => !treeInfo.isCatchCase(cd))) debugwarn("VPM BUG! illegal try/catch "+ catches); tree }
else if (catches forall treeInfo.isCatchCase) tree
@@ -698,9 +699,9 @@ abstract class UnCurry extends InfoTransform
* It looks for the method in the `repeatedParams` map, and generates a Java-style
* varargs forwarder. It then adds the forwarder to the `newMembers` sequence.
*/
- private def addJavaVarargsForwarders(dd: DefDef, flatdd: DefDef, tree: Tree): Unit = {
- if (!repeatedParams.contains(dd.symbol))
- return
+ private def addJavaVarargsForwarders(dd: DefDef, flatdd: DefDef): DefDef = {
+ if (!dd.symbol.hasAnnotation(VarargsClass) || !repeatedParams.contains(dd.symbol))
+ return flatdd
def toSeqType(tp: Type): Type = {
val arg = elementType(ArrayClass, tp)
@@ -721,7 +722,7 @@ abstract class UnCurry extends InfoTransform
val reps = repeatedParams(dd.symbol)
val rpsymbols = reps.map(_.symbol).toSet
- val theTyper = typer.atOwner(tree, currentClass)
+ val theTyper = typer.atOwner(dd, currentClass)
val flatparams = flatdd.vparamss.head
// create the type
@@ -773,10 +774,11 @@ abstract class UnCurry extends InfoTransform
case None =>
// enter symbol into scope
currentClass.info.decls enter forwsym
-
// add the method to `newMembers`
newMembers += forwtree
}
+
+ flatdd
}
}
}