@@ -65,7 +65,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
65
65
if (ctx.compilationUnit.containsQuotesOrSplices) super .run
66
66
67
67
protected def newTransformer (implicit ctx : Context ): Transformer =
68
- new Reifier (inQuote = false , null , 0 , new LevelInfo )
68
+ new Reifier (inQuote = false , null , 0 , new LevelInfo , new mutable. ListBuffer [ Tree ] )
69
69
70
70
private class LevelInfo {
71
71
/** A map from locally defined symbols to the staging levels of their definitions */
@@ -92,21 +92,22 @@ class ReifyQuotes extends MacroTransformWithImplicits {
92
92
* @param outer the next outer reifier, null is this is the topmost transformer
93
93
* @param level the current level, where quotes add one and splices subtract one level
94
94
* @param levels a stacked map from symbols to the levels in which they were defined
95
+ * @param embedded a list of embedded quotes (if `inSplice = true`) or splices (if `inQuote = true`
95
96
*/
96
- private class Reifier (inQuote : Boolean , val outer : Reifier , val level : Int , levels : LevelInfo ) extends ImplicitsTransformer {
97
+ private class Reifier (inQuote : Boolean , val outer : Reifier , val level : Int , levels : LevelInfo ,
98
+ val embedded : mutable.ListBuffer [Tree ]) extends ImplicitsTransformer {
97
99
import levels ._
98
100
assert(level >= 0 )
99
101
100
102
/** A nested reifier for a quote (if `isQuote = true`) or a splice (if not) */
101
- def nested (isQuote : Boolean ): Reifier =
102
- new Reifier (isQuote, this , if (isQuote) level + 1 else level - 1 , levels)
103
+ def nested (isQuote : Boolean ): Reifier = {
104
+ val nestedEmbedded = if (level > 1 || (level == 1 && isQuote)) embedded else new mutable.ListBuffer [Tree ]
105
+ new Reifier (isQuote, this , if (isQuote) level + 1 else level - 1 , levels, nestedEmbedded)
106
+ }
103
107
104
108
/** We are in a `~(...)` context that is not shadowed by a nested `'(...)` */
105
109
def inSplice = outer != null && ! inQuote
106
110
107
- /** A list of embedded quotes (if `inSplice = true`) or splices (if `inQuote = true`) */
108
- val embedded = new mutable.ListBuffer [Tree ]
109
-
110
111
/** A map from type ref T to expressions of type `quoted.Type[T]`".
111
112
* These will be turned into splices using `addTags`
112
113
*/
@@ -281,9 +282,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
281
282
private def quotation (body : Tree , quote : Tree )(implicit ctx : Context ): Tree = {
282
283
val isType = quote.symbol eq defn.typeQuoteMethod
283
284
if (level > 0 ) {
284
- val reifier = nested(isQuote = true )
285
- val body1 = reifier.transform(body)
286
- embedded ++= reifier.embedded
285
+ val body1 = nested(isQuote = true ).transform(body)
287
286
// Keep quotes in quotes as trees to reduce pickled size and have a Expr.show without pickled quotes embedded
288
287
if (isType) ref(defn.typeQuoteMethod).appliedToType(body1.tpe.widen)
289
288
else ref(defn.quoteMethod).appliedToType(body1.tpe.widen).appliedTo(body1)
@@ -305,9 +304,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
305
304
*/
306
305
private def splice (splice : Select )(implicit ctx : Context ): Tree = {
307
306
if (level > 1 ) {
308
- val reifier = nested(isQuote = false )
309
- val body1 = reifier.transform(splice.qualifier)
310
- embedded ++= reifier.embedded
307
+ val body1 = nested(isQuote = false ).transform(splice.qualifier)
311
308
body1.select(splice.name)
312
309
}
313
310
else if (! inQuote && level == 0 ) {
0 commit comments