Skip to content

Commit 0bc7827

Browse files
committed
Factor out code
1 parent 8cccaff commit 0bc7827

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,16 @@ object PickledQuotes {
3434

3535
/** Transform the expression into its fully spliced Tree */
3636
def quotedToTree(expr: quoted.Quoted)(implicit ctx: Context): Tree = expr match {
37-
case expr: quoted.TastyQuoted => unpickleQuote(expr)
38-
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))
3941
case expr: quoted.Expr.FunctionAppliedTo[_, _] =>
4042
functionAppliedTo(quotedToTree(expr.f), quotedToTree(expr.x))
4143
case expr: quoted.Type.TaggedPrimitive[_] =>
42-
val tpe = expr.ct match {
43-
case ClassTag.Unit => defn.UnitType
44-
case ClassTag.Byte => defn.ByteType
45-
case ClassTag.Char => defn.CharType
46-
case ClassTag.Short => defn.ShortType
47-
case ClassTag.Int => defn.IntType
48-
case ClassTag.Long => defn.LongType
49-
case ClassTag.Float => defn.FloatType
50-
case ClassTag.Double => defn.FloatType
51-
}
52-
TypeTree(tpe)
53-
case expr: RawQuoted => expr.tree
44+
classTagToTypeTree(expr.ct)
45+
case expr: RawQuoted =>
46+
expr.tree
5447
}
5548

5649
/** Unpickle the tree contained in the TastyQuoted */
@@ -115,6 +108,20 @@ object PickledQuotes {
115108
tree
116109
}
117110

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+
118125
private def functionAppliedTo(f: Tree, x: Tree)(implicit ctx: Context): Tree = {
119126
val x1 = SyntheticValDef(NameKinds.UniqueName.fresh("x".toTermName), x)
120127
def x1Ref() = ref(x1.symbol)

0 commit comments

Comments
 (0)