File tree Expand file tree Collapse file tree 4 files changed +28
-13
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 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._
88import dotty .tools .dotc .core .Flags ._
99import dotty .tools .dotc .core .Decorators ._
1010import dotty .tools .dotc .core .Symbols ._
11-
11+ import dotty . tools . dotc . quoted . Quoted
1212import scala .reflect .ClassTag
1313import java .net .URLClassLoader
1414
@@ -53,13 +53,9 @@ class Interpreter(implicit ctx: Context) {
5353 private def interpretTreeImpl (tree : Tree ): Object = {
5454 try {
5555 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)
6057
61- case Literal (Constant (c)) =>
62- c.asInstanceOf [AnyRef ]
58+ case Literal (Constant (c)) => c.asInstanceOf [AnyRef ]
6359
6460 case Apply (fn, args) if fn.symbol.isConstructor =>
6561 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
1717import scala .collection .mutable
1818import dotty .tools .dotc .core .StdNames ._
1919import dotty .tools .dotc .quoted .PickledQuotes
20+ import dotty .tools .dotc .quoted .Quoted
2021
2122
2223/** Translates quoted terms and types to `unpickle` method calls.
@@ -316,10 +317,8 @@ class ReifyQuotes extends MacroTransform {
316317 enteredSyms = enteredSyms.tail
317318 }
318319 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)
323322 case Select (body, _) if tree.symbol.isSplice =>
324323 splice(body, tree)
325324 case Block (stats, _) =>
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import dotty.tools.dotc.ast.Trees._
77import dotty .tools .dotc .ast .tpd
88import dotty .tools .dotc .interpreter ._
99import dotty .tools .dotc .quoted .PickledQuotes
10+ import dotty .tools .dotc .quoted .Quoted
1011
1112import scala .quoted
1213
@@ -19,8 +20,7 @@ object Splicer {
1920 * resulting expression is return as a `Tree`
2021 */
2122 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
2424 case tree : RefTree => reflectiveSplice(tree)
2525 case tree : Apply => reflectiveSplice(tree)
2626 case tree : Inlined => reflectiveSplice(tree)
You can’t perform that action at this time.
0 commit comments