File tree 4 files changed +28
-13
lines changed
compiler/src/dotty/tools/dotc 4 files changed +28
-13
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import dotty.tools.dotc.core.Contexts._
8
8
import dotty .tools .dotc .core .Flags ._
9
9
import dotty .tools .dotc .core .Decorators ._
10
10
import dotty .tools .dotc .core .Symbols ._
11
-
11
+ import dotty . tools . dotc . quoted . Quoted
12
12
import scala .reflect .ClassTag
13
13
import java .net .URLClassLoader
14
14
@@ -53,13 +53,9 @@ class Interpreter(implicit ctx: Context) {
53
53
private def interpretTreeImpl (tree : Tree ): Object = {
54
54
try {
55
55
tree match {
56
- case Apply (_, quote :: Nil ) if tree.symbol eq defn.quoteMethod =>
57
- RawQuoted (quote)
58
- case TypeApply (_, quote :: Nil ) if tree.symbol eq defn.typeQuoteMethod =>
59
- RawQuoted (quote)
56
+ case Quoted (quotedTree) => RawQuoted (quotedTree)
60
57
61
- case Literal (Constant (c)) =>
62
- c.asInstanceOf [AnyRef ]
58
+ case Literal (Constant (c)) => c.asInstanceOf [AnyRef ]
63
59
64
60
case Apply (fn, args) if fn.symbol.isConstructor =>
65
61
val cls = fn.symbol.owner
Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc .quoted
2
+
3
+ import dotty .tools .dotc .ast .Trees .GenericApply
4
+ import dotty .tools .dotc .ast .tpd
5
+ import dotty .tools .dotc .core .Contexts .Context
6
+ import dotty .tools .dotc .core .Types .Type
7
+ import dotty .tools .dotc .transform .SymUtils ._
8
+
9
+ /** Extractors for quotes */
10
+ object Quoted {
11
+
12
+ /** Extracts the content of a quoted tree.
13
+ * The result can be the contents of a term ot type quote, which
14
+ * will return a term or type tree respectively.
15
+ */
16
+ def unapply (tree : tpd.Tree )(implicit ctx : Context ): Option [tpd.Tree ] = tree match {
17
+ case tree : GenericApply [Type ] if tree.symbol.isQuote => Some (tree.args.head)
18
+ case _ => None
19
+ }
20
+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import NameKinds.OuterSelectName
17
17
import scala .collection .mutable
18
18
import dotty .tools .dotc .core .StdNames ._
19
19
import dotty .tools .dotc .quoted .PickledQuotes
20
+ import dotty .tools .dotc .quoted .Quoted
20
21
21
22
22
23
/** Translates quoted terms and types to `unpickle` method calls.
@@ -316,10 +317,8 @@ class ReifyQuotes extends MacroTransform {
316
317
enteredSyms = enteredSyms.tail
317
318
}
318
319
tree match {
319
- case Apply (fn, arg :: Nil ) if fn.symbol == defn.quoteMethod =>
320
- quotation(arg, tree)
321
- case TypeApply (fn, arg :: Nil ) if fn.symbol == defn.typeQuoteMethod =>
322
- quotation(arg, tree)
320
+ case Quoted (quotedTree) =>
321
+ quotation(quotedTree, tree)
323
322
case Select (body, _) if tree.symbol.isSplice =>
324
323
splice(body, tree)
325
324
case Block (stats, _) =>
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import dotty.tools.dotc.ast.Trees._
7
7
import dotty .tools .dotc .ast .tpd
8
8
import dotty .tools .dotc .interpreter ._
9
9
import dotty .tools .dotc .quoted .PickledQuotes
10
+ import dotty .tools .dotc .quoted .Quoted
10
11
11
12
import scala .quoted
12
13
@@ -19,8 +20,7 @@ object Splicer {
19
20
* resulting expression is return as a `Tree`
20
21
*/
21
22
def splice (tree : Tree )(implicit ctx : Context ): Tree = tree match {
22
- case Apply (quote, quoted :: Nil ) if quote.symbol == defn.quoteMethod => quoted
23
- case TypeApply (quote, quoted :: Nil ) if quote.symbol == defn.typeQuoteMethod => quoted
23
+ case Quoted (quotedTree) => quotedTree
24
24
case tree : RefTree => reflectiveSplice(tree)
25
25
case tree : Apply => reflectiveSplice(tree)
26
26
case tree : Inlined => reflectiveSplice(tree)
You can’t perform that action at this time.
0 commit comments