@@ -7,11 +7,13 @@ import dotty.tools.dotc.core.Constants.Constant
7
7
import dotty .tools .dotc .core .Contexts ._
8
8
import dotty .tools .dotc .core .Decorators ._
9
9
import dotty .tools .dotc .core .Flags ._
10
- import dotty .tools .dotc .core .NameKinds
11
10
import dotty .tools .dotc .core .StdNames ._
11
+ import dotty .tools .dotc .core .NameKinds
12
12
import dotty .tools .dotc .core .Symbols ._
13
13
import dotty .tools .dotc .core .tasty .{TastyPickler , TastyPrinter , TastyString }
14
- import dotty .tools .dotc .interpreter .RawQuoted
14
+
15
+ import scala .quoted .Types ._
16
+ import scala .quoted .Exprs ._
15
17
16
18
import scala .reflect .ClassTag
17
19
@@ -29,27 +31,37 @@ object PickledQuotes {
29
31
}
30
32
31
33
/** Transform the expression into its fully spliced Tree */
32
- def quotedToTree (expr : quoted.Quoted )(implicit ctx : Context ): Tree = expr match {
33
- case expr : quoted.TastyQuoted =>
34
- unpickleQuote(expr)
35
- case expr : quoted.Liftable .ConstantExpr [_] =>
36
- Literal (Constant (expr.value))
37
- case expr : quoted.Expr .FunctionAppliedTo [_, _] =>
38
- functionAppliedTo(quotedToTree(expr.f), quotedToTree(expr.x))
39
- case expr : quoted.Type .TaggedPrimitive [_] =>
40
- classTagToTypeTree(expr.ct)
41
- case expr : RawQuoted =>
42
- expr.tree
34
+ def quotedExprToTree (expr : quoted.Expr [_])(implicit ctx : Context ): Tree = expr match {
35
+ case expr : TastyExpr [_] => unpickleExpr(expr)
36
+ case expr : ValueExpr [_] => Literal (Constant (expr.value))
37
+ case expr : TreeExpr [Tree ] @ unchecked => expr.tree
38
+ case expr : FunctionAppliedTo [_, _] =>
39
+ functionAppliedTo(quotedExprToTree(expr.f), quotedExprToTree(expr.x))
40
+ }
41
+
42
+ /** Transform the expression into its fully spliced TypeTree */
43
+ def quotedTypeToTree (expr : quoted.Type [_])(implicit ctx : Context ): Tree = expr match {
44
+ case expr : TastyType [_] => unpickleType(expr)
45
+ case expr : TaggedType [_] => classTagToTypeTree(expr.ct)
46
+ case expr : TreeType [Tree ] @ unchecked => expr.tree
43
47
}
44
48
45
- /** Unpickle the tree contained in the TastyQuoted */
46
- private def unpickleQuote (expr : quoted. TastyQuoted )(implicit ctx : Context ): Tree = {
49
+ /** Unpickle the tree contained in the TastyExpr */
50
+ private def unpickleExpr (expr : TastyExpr [_] )(implicit ctx : Context ): Tree = {
47
51
val tastyBytes = TastyString .unpickle(expr.tasty)
48
52
val unpickled = unpickle(tastyBytes, expr.args)
53
+ unpickled match {
54
+ case PackageDef (_, (vdef : ValDef ) :: Nil ) => vdef.rhs
55
+ }
56
+ }
57
+
58
+ /** Unpickle the tree contained in the TastyType */
59
+ private def unpickleType (ttpe : TastyType [_])(implicit ctx : Context ): Tree = {
60
+ val tastyBytes = TastyString .unpickle(ttpe.tasty)
61
+ val unpickled = unpickle(tastyBytes, ttpe.args)
49
62
unpickled match {
50
63
case PackageDef (_, (vdef : ValDef ) :: Nil ) =>
51
- if (vdef.name == " $quote" .toTermName) vdef.rhs
52
- else vdef.rhs.asInstanceOf [TypeApply ].args.head
64
+ vdef.rhs.asInstanceOf [TypeApply ].args.head
53
65
}
54
66
}
55
67
0 commit comments