11package dotty .tools .dotc .core .quoted
22
33import dotty .tools .dotc .ast .Trees ._
4- import dotty .tools .dotc .ast .{ tpd , untpd }
4+ import dotty .tools .dotc .ast .tpd
55import dotty .tools .dotc .config .Printers ._
66import dotty .tools .dotc .core .Constants .Constant
77import dotty .tools .dotc .core .Contexts ._
88import dotty .tools .dotc .core .Decorators ._
99import dotty .tools .dotc .core .Flags ._
10+ import dotty .tools .dotc .core .NameKinds
1011import dotty .tools .dotc .core .StdNames ._
1112import dotty .tools .dotc .core .Symbols ._
1213import dotty .tools .dotc .core .tasty .{TastyPickler , TastyPrinter , TastyString }
@@ -33,21 +34,16 @@ object PickledQuotes {
3334
3435 /** Transform the expression into its fully spliced Tree */
3536 def quotedToTree (expr : quoted.Quoted )(implicit ctx : Context ): Tree = expr match {
36- case expr : quoted.TastyQuoted => unpickleQuote(expr)
37- case expr : quoted.Liftable .ConstantExpr [_] => Literal (Constant (expr.value))
37+ case expr : quoted.TastyQuoted =>
38+ unpickleQuote(expr)
39+ case expr : quoted.Liftable .ConstantExpr [_] =>
40+ Literal (Constant (expr.value))
41+ case expr : quoted.Expr .FunctionAppliedTo [_, _] =>
42+ functionAppliedTo(quotedToTree(expr.f), quotedToTree(expr.x))
3843 case expr : quoted.Type .TaggedPrimitive [_] =>
39- val tpe = expr.ct match {
40- case ClassTag .Unit => defn.UnitType
41- case ClassTag .Byte => defn.ByteType
42- case ClassTag .Char => defn.CharType
43- case ClassTag .Short => defn.ShortType
44- case ClassTag .Int => defn.IntType
45- case ClassTag .Long => defn.LongType
46- case ClassTag .Float => defn.FloatType
47- case ClassTag .Double => defn.FloatType
48- }
49- TypeTree (tpe)
50- case expr : RawQuoted => expr.tree
44+ classTagToTypeTree(expr.ct)
45+ case expr : RawQuoted =>
46+ expr.tree
5147 }
5248
5349 /** Unpickle the tree contained in the TastyQuoted */
@@ -111,4 +107,42 @@ object PickledQuotes {
111107 }
112108 tree
113109 }
110+
111+ private def classTagToTypeTree (ct : ClassTag [_])(implicit ctx : Context ): TypeTree = {
112+ val tpe = ct match {
113+ case ClassTag .Unit => defn.UnitType
114+ case ClassTag .Byte => defn.ByteType
115+ case ClassTag .Char => defn.CharType
116+ case ClassTag .Short => defn.ShortType
117+ case ClassTag .Int => defn.IntType
118+ case ClassTag .Long => defn.LongType
119+ case ClassTag .Float => defn.FloatType
120+ case ClassTag .Double => defn.FloatType
121+ }
122+ TypeTree (tpe)
123+ }
124+
125+ private def functionAppliedTo (f : Tree , x : Tree )(implicit ctx : Context ): Tree = {
126+ val x1 = SyntheticValDef (NameKinds .UniqueName .fresh(" x" .toTermName), x)
127+ def x1Ref () = ref(x1.symbol)
128+ def rec (f : Tree ): Tree = f match {
129+ case closureDef(ddef) =>
130+ new TreeMap () {
131+ private val paramSym = ddef.vparamss.head.head.symbol
132+ override def transform (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = tree match {
133+ case tree : Ident if tree.symbol == paramSym => x1Ref().withPos(tree.pos)
134+ case _ => super .transform(tree)
135+ }
136+ }.transform(ddef.rhs)
137+ case Block (stats, expr) =>
138+ val applied = rec(expr)
139+ if (stats.isEmpty) applied
140+ else Block (stats, applied)
141+ case Inlined (call, bindings, expansion) =>
142+ Inlined (call, bindings, rec(expansion))
143+ case _ =>
144+ f.select(nme.apply).appliedTo(x1Ref())
145+ }
146+ Block (x1 :: Nil , rec(f))
147+ }
114148}
0 commit comments