@@ -130,51 +130,41 @@ class ReifyQuotes extends MacroTransformWithImplicits {
130
130
* defined versions. As a side effect, prepend the expressions `tag1, ..., `tagN`
131
131
* as splices to `embedded`.
132
132
*/
133
- private def addTags (expr : Tree )(implicit ctx : Context ): Tree =
133
+ private def addTags (expr : Tree )(implicit ctx : Context ): Tree = {
134
+
135
+ def mkTagSymbolAndAssign (typeRef : TypeRef , tag : Tree ): Tree = {
136
+ val rhs = transform(tag.select(tpnme.UNARY_~ ))
137
+ val alias = ctx.typeAssigner.assignType(untpd.TypeBoundsTree (rhs, rhs), rhs, rhs)
138
+
139
+ val original = typeRef.symbol.asType
140
+
141
+ val local = ctx.newSymbol(
142
+ owner = ctx.owner,
143
+ name = UniqueName .fresh(" T" .toTermName).toTypeName,
144
+ flags = Synthetic ,
145
+ info = TypeAlias (tag.tpe.select(tpnme.UNARY_~ )),
146
+ coord = typeRef.prefix.termSymbol.coord).asType
147
+
148
+ ctx.typeAssigner.assignType(untpd.TypeDef (local.name, alias), local)
149
+ }
150
+
134
151
if (importedTags.isEmpty && explicitTags.isEmpty) expr
135
152
else {
136
153
val itags = importedTags.toList
137
154
138
- println(" addTags: expr: " + expr)
139
- println(" addTags: tags: " )
140
- itags.foreach(println)
141
-
142
155
val typeDefs = for ((tref, tag) <- itags) yield {
143
- val rhs = transform(tag.select(tpnme.UNARY_~ ))
144
- val alias = ctx.typeAssigner.assignType(untpd.TypeBoundsTree (rhs, rhs), rhs, rhs)
145
- val original = tref.symbol.asType
146
- val local = original.copy(
147
- owner = ctx.owner,
148
- name = (original.name + " $$" ).toTypeName,
149
- flags = Synthetic ,
150
- info = TypeAlias (tag.tpe.select(tpnme.UNARY_~ ))).asType
151
-
152
- ctx.typeAssigner.assignType(untpd.TypeDef (local.name, alias), local)
156
+ mkTagSymbolAndAssign(tref, tag)
153
157
}
154
158
importedTags.clear()
155
159
156
-
157
160
val explicitTypeDefs = for (tref <- explicitTags) yield {
158
161
val tag = ref(tref.prefix.termSymbol)
159
- val rhs = transform(tag.select(tpnme.UNARY_~ ))
160
-
161
- val alias = ctx.typeAssigner.assignType(untpd.TypeBoundsTree (rhs, rhs), rhs, rhs)
162
-
163
- val local = ctx.newSymbol(
164
- owner = ctx.owner,
165
- name = UniqueName .fresh(" ttt" .toTermName).toTypeName,
166
- flags = Synthetic ,
167
- info = TypeAlias (tag.tpe.select(tpnme.UNARY_~ )),
168
- coord = tref.prefix.termSymbol.coord).asType
169
-
170
- (tref, ctx.typeAssigner.assignType(untpd.TypeDef (local.name, alias), local))
162
+ mkTagSymbolAndAssign(tref, tag)
171
163
}
172
- val map : Map [Type , Type ] = explicitTypeDefs.map(x => (x._1, x._2.symbol.typeRef)).toMap
173
164
174
- println()
175
- println(map)
176
- println()
177
- println()
165
+ val tagsExplicitTypeDefsPairs = explicitTags.zip(explicitTypeDefs)
166
+
167
+ val map : Map [Type , Type ] = tagsExplicitTypeDefsPairs.map(x => (x._1, x._2.symbol.typeRef)).toMap
178
168
179
169
val tMap = new TypeMap () {
180
170
override def apply (tp : Type ): Type = {
@@ -185,16 +175,14 @@ class ReifyQuotes extends MacroTransformWithImplicits {
185
175
}
186
176
}
187
177
188
- val ret = Block (typeDefs ++ explicitTypeDefs.map(_._2),
189
- new TreeTypeMap (typeMap = tMap,
190
- substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol))
191
- .apply(expr))
192
-
193
- println(" addTags: ret: " + ret)
194
- println(ret.show)
195
- println()
196
- ret
178
+ Block (typeDefs ++ tagsExplicitTypeDefsPairs.map(_._2),
179
+ new TreeTypeMap (
180
+ typeMap = tMap,
181
+ substFrom = itags.map(_._1.symbol),
182
+ substTo = typeDefs.map(_.symbol)
183
+ ).apply(expr))
197
184
}
185
+ }
198
186
199
187
/** Enter staging level of symbol defined by `tree`, if applicable. */
200
188
def markDef (tree : Tree )(implicit ctx : Context ) = tree match {
@@ -501,18 +489,11 @@ class ReifyQuotes extends MacroTransformWithImplicits {
501
489
case Quoted (quotedTree) =>
502
490
quotation(quotedTree, tree)
503
491
case tree : TypeTree if tree.tpe.typeSymbol.isSplice =>
504
- val splicedType = tree.tpe.asInstanceOf [TypeRef ].prefix.termSymbol
505
- val ret = splice(ref(splicedType).select(tpnme.UNARY_~ ))
506
- // println()
507
- // println("TypeTree: " + tree)
508
- // println("TypeTrees: " + tree.show)
509
- // println("TypeTree ret: " + ret)
510
- // println("TypeTree rets: " + ret.show)
511
- ret
492
+ val splicedType = tree.tpe.asInstanceOf [TypeRef ].prefix.termSymbol
493
+ splice(ref(splicedType).select(tpnme.UNARY_~ ))
512
494
case tree : TypeApply =>
513
495
super .transform(tree)
514
496
case tree : Select if tree.symbol.isSplice =>
515
- // println("Select: " + tree)
516
497
splice(tree)
517
498
case tree : RefTree if needsLifting(tree) =>
518
499
val lift = lifters(tree.symbol)
0 commit comments