diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-08-29 17:35:28 +0200 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-09-05 14:35:07 +0200 |
commit | 1ac6bb934f274f4c4f5d982a6c076e4e535ba90b (patch) | |
tree | 6f4d28c8f632231491164cfa3e6192ef74e48dc8 /src | |
parent | eabe3b408d29a026881ac90f920a4face1be86fd (diff) | |
download | scala-1ac6bb934f274f4c4f5d982a6c076e4e535ba90b.tar.gz scala-1ac6bb934f274f4c4f5d982a6c076e4e535ba90b.tar.bz2 scala-1ac6bb934f274f4c4f5d982a6c076e4e535ba90b.zip |
minor changes to TreeGen.mkTemplate
1. Make superPos parameter optional with default value NoPosition
2. use Option instead of List for local optional constructor variable
Diffstat (limited to 'src')
-rw-r--r-- | src/reflect/scala/reflect/internal/TreeGen.scala | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala index 29c57fc9c0..a7ea8c816f 100644 --- a/src/reflect/scala/reflect/internal/TreeGen.scala +++ b/src/reflect/scala/reflect/internal/TreeGen.scala @@ -324,7 +324,8 @@ abstract class TreeGen extends macros.TreeBuilder { * body * } */ - def mkTemplate(parents: List[Tree], self: ValDef, constrMods: Modifiers, vparamss: List[List[ValDef]], body: List[Tree], superPos: Position): Template = { + def mkTemplate(parents: List[Tree], self: ValDef, constrMods: Modifiers, + vparamss: List[List[ValDef]], body: List[Tree], superPos: Position = NoPosition): Template = { /* Add constructor to template */ // create parameters for <init> as synthetic trees. @@ -348,10 +349,10 @@ abstract class TreeGen extends macros.TreeBuilder { } val lvdefs = evdefs collect { case vdef: ValDef => copyValDef(vdef)(mods = vdef.mods | PRESUPER) } - val constrs = { - if (constrMods hasFlag TRAIT) { - if (body forall treeInfo.isInterfaceMember) List() - else List( + val constr = { + if (constrMods.isTrait) { + if (body forall treeInfo.isInterfaceMember) None + else Some( atPos(wrappingPos(superPos, lvdefs)) ( DefDef(NoMods, nme.MIXIN_CONSTRUCTOR, List(), List(Nil), TypeTree(), Block(lvdefs, Literal(Constant()))))) } else { @@ -365,18 +366,18 @@ abstract class TreeGen extends macros.TreeBuilder { // (the type macros aren't in the trunk yet, but there is a plan for them to land there soon) // this means that we don't know what will be the arguments of the super call // therefore here we emit a dummy which gets populated when the template is named and typechecked - List( + Some( // TODO: previously this was `wrappingPos(superPos, lvdefs ::: argss.flatten)` // is it going to be a problem that we can no longer include the `argss`? atPos(wrappingPos(superPos, lvdefs)) ( DefDef(constrMods, nme.CONSTRUCTOR, List(), vparamss1, TypeTree(), Block(lvdefs ::: List(superCall), Literal(Constant()))))) } } - constrs foreach (ensureNonOverlapping(_, parents ::: gvdefs, focus=false)) + constr foreach (ensureNonOverlapping(_, parents ::: gvdefs, focus=false)) // Field definitions for the class - remove defaults. val fieldDefs = vparamss.flatten map (vd => copyValDef(vd)(mods = vd.mods &~ DEFAULTPARAM, rhs = EmptyTree)) - global.Template(parents, self, gvdefs ::: fieldDefs ::: constrs ::: etdefs ::: rest) + global.Template(parents, self, gvdefs ::: fieldDefs ::: constr ++: etdefs ::: rest) } /** Create positioned tree representing an object creation <new parents { stats } |