@@ -77,78 +77,6 @@ trait Trees extends scala.reflect.internal.Trees { self: Global =>
7777 case xs :: rest => rest.foldLeft(Apply (gen.mkSuperInitCall, xs): Tree )(Apply .apply)
7878 }
7979
80- /** Generates a template with constructor corresponding to
81- *
82- * constrmods (vparams1_) ... (vparams_n) preSuper { presupers }
83- * extends superclass(args_1) ... (args_n) with mixins { self => body }
84- *
85- * This gets translated to
86- *
87- * extends superclass with mixins { self =>
88- * presupers' // presupers without rhs
89- * vparamss // abstract fields corresponding to value parameters
90- * def <init>(vparamss) {
91- * presupers
92- * super.<init>(args)
93- * }
94- * body
95- * }
96- */
97- def Template (parents : List [Tree ], self : ValDef , constrMods : Modifiers , vparamss : List [List [ValDef ]], body : List [Tree ], superPos : Position ): Template = {
98- /* Add constructor to template */
99-
100- // create parameters for <init> as synthetic trees.
101- var vparamss1 = mmap(vparamss) { vd =>
102- atPos(vd.pos.focus) {
103- val mods = Modifiers (vd.mods.flags & (IMPLICIT | DEFAULTPARAM | BYNAMEPARAM ) | PARAM | PARAMACCESSOR )
104- ValDef (mods withAnnotations vd.mods.annotations, vd.name, vd.tpt.duplicate, vd.rhs.duplicate)
105- }
106- }
107- val (edefs, rest) = body span treeInfo.isEarlyDef
108- val (evdefs, etdefs) = edefs partition treeInfo.isEarlyValDef
109- val gvdefs = evdefs map {
110- case vdef @ ValDef (_, _, tpt, _) =>
111- copyValDef(vdef)(
112- // atPos for the new tpt is necessary, since the original tpt might have no position
113- // (when missing type annotation for ValDef for example), so even though setOriginal modifies the
114- // position of TypeTree, it would still be NoPosition. That's what the author meant.
115- tpt = atPos(vdef.pos.focus)(TypeTree () setOriginal tpt setPos tpt.pos.focus),
116- rhs = EmptyTree
117- )
118- }
119- val lvdefs = evdefs collect { case vdef : ValDef => copyValDef(vdef)(mods = vdef.mods | PRESUPER ) }
120-
121- val constrs = {
122- if (constrMods hasFlag TRAIT ) {
123- if (body forall treeInfo.isInterfaceMember) List ()
124- else List (
125- atPos(wrappingPos(superPos, lvdefs)) (
126- DefDef (NoMods , nme.MIXIN_CONSTRUCTOR , List (), ListOfNil , TypeTree (), Block (lvdefs, Literal (Constant ())))))
127- } else {
128- // convert (implicit ... ) to ()(implicit ... ) if its the only parameter section
129- if (vparamss1.isEmpty || ! vparamss1.head.isEmpty && vparamss1.head.head.mods.isImplicit)
130- vparamss1 = List () :: vparamss1
131- val superRef : Tree = atPos(superPos)(gen.mkSuperInitCall)
132- val superCall = pendingSuperCall // we can't know in advance which of the parents will end up as a superclass
133- // this requires knowing which of the parents is a type macro and which is not
134- // and that's something that cannot be found out before typer
135- // (the type macros aren't in the trunk yet, but there is a plan for them to land there soon)
136- // this means that we don't know what will be the arguments of the super call
137- // therefore here we emit a dummy which gets populated when the template is named and typechecked
138- List (
139- // TODO: previously this was `wrappingPos(superPos, lvdefs ::: argss.flatten)`
140- // is it going to be a problem that we can no longer include the `argss`?
141- atPos(wrappingPos(superPos, lvdefs)) (
142- DefDef (constrMods, nme.CONSTRUCTOR , List (), vparamss1, TypeTree (), Block (lvdefs ::: List (superCall), Literal (Constant ())))))
143- }
144- }
145- constrs foreach (ensureNonOverlapping(_, parents ::: gvdefs, focus= false ))
146- // Field definitions for the class - remove defaults.
147- val fieldDefs = vparamss.flatten map (vd => copyValDef(vd)(mods = vd.mods &~ DEFAULTPARAM , rhs = EmptyTree ))
148-
149- Template (parents, self, gvdefs ::: fieldDefs ::: constrs ::: etdefs ::: rest)
150- }
151-
15280 /** Construct class definition with given class symbol, value parameters,
15381 * supercall arguments and template body.
15482 *
@@ -167,9 +95,9 @@ trait Trees extends scala.reflect.internal.Trees { self: Global =>
16795 )
16896
16997 ClassDef (sym,
170- Template (sym.info.parents map TypeTree ,
171- if (sym.thisSym == sym || phase.erasedTypes) emptyValDef else ValDef (sym.thisSym),
172- constrMods, vparamss, body, superPos))
98+ gen.mkTemplate (sym.info.parents map TypeTree ,
99+ if (sym.thisSym == sym || phase.erasedTypes) emptyValDef else ValDef (sym.thisSym),
100+ constrMods, vparamss, body, superPos))
173101 }
174102
175103 // --- subcomponents --------------------------------------------------
0 commit comments