@@ -11,7 +11,10 @@ object StagingContext {
11
11
/** A key to be used in a context property that tracks the quoteation level */
12
12
private val QuotationLevel = new Property .Key [Int ]
13
13
14
- private val QuotationContexts = new Property .Key [List [tpd.Tree ]]
14
+ /** A key to be used in a context property that tracks the quoteation stack.
15
+ * Stack containing the QuoteContext references recieved by the surrounding quotes.
16
+ */
17
+ private val QuoteQontextStack = new Property .Key [List [tpd.Tree ]]
15
18
16
19
/** All enclosing calls that are currently inlined, from innermost to outermost. */
17
20
def level (implicit ctx : Context ): Int =
@@ -21,25 +24,27 @@ object StagingContext {
21
24
def quoteContext (implicit ctx : Context ): Context =
22
25
ctx.fresh.setProperty(QuotationLevel , level + 1 )
23
26
24
- /** Context with an incremented quotation level. */
27
+ /** Context with an incremented quotation level and pushes a refecence to a QuoteContext on the quote context stack */
25
28
def pushQuoteContext (qctxRef : tpd.Tree )(implicit ctx : Context ): Context =
26
- val old = ctx.property(QuotationContexts ).getOrElse(List .empty)
29
+ val old = ctx.property(QuoteQontextStack ).getOrElse(List .empty)
27
30
ctx.fresh.setProperty(QuotationLevel , level + 1 )
28
- .setProperty(QuotationContexts , qctxRef :: old)
31
+ .setProperty(QuoteQontextStack , qctxRef :: old)
29
32
30
33
/** Context with a decremented quotation level. */
31
34
def spliceContext (implicit ctx : Context ): Context =
32
35
ctx.fresh.setProperty(QuotationLevel , level - 1 )
33
36
37
+ /** Context with a decremented quotation level and pops the Some of top of the quote context stack or None if the stack is empty.
38
+ * The quotation stack could be empty if we are in a top level splice or an eroneous splice directly witin a top level splice.
39
+ */
34
40
def popQuoteContext ()(implicit ctx : Context ): (Option [tpd.Tree ], Context ) =
35
41
val ctx1 = ctx.fresh.setProperty(QuotationLevel , level - 1 )
36
42
val head =
37
- ctx.property(QuotationContexts ) match
43
+ ctx.property(QuoteQontextStack ) match
38
44
case Some (x :: xs) =>
39
- ctx1.setProperty(QuotationContexts , xs)
45
+ ctx1.setProperty(QuoteQontextStack , xs)
40
46
Some (x)
41
47
case _ =>
42
48
None // Splice at level 0 or lower
43
49
(head, ctx1)
44
50
}
45
-
0 commit comments