diff options
Diffstat (limited to 'src/dotty/tools/dotc/transform/SamplePhase.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/SamplePhase.scala | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/transform/SamplePhase.scala b/src/dotty/tools/dotc/transform/SamplePhase.scala index 137ab2eda..ed4ac113f 100644 --- a/src/dotty/tools/dotc/transform/SamplePhase.scala +++ b/src/dotty/tools/dotc/transform/SamplePhase.scala @@ -4,33 +4,52 @@ package transform import TreeTransforms._ import core.DenotTransformers._ import core.Denotations._ +import core.SymDenotations._ import core.Contexts._ +import core.Types._ import ast.Trees._ import ast.tpd.{Apply, Tree, cpy} -class SamplePhase extends TreeTransformer { - - def init(implicit ctx: Context) = { - ctx.base.denotTransformers.install(id, new UncurryDenotTransform(_)) - } - +class SamplePhase extends TreeTransformer with DenotTransformer { def name = "sample" - def transformations = Array(new UncurryTreeTransform(_, _)) -} - -class UncurryDenotTransform(group: DenotTransformerGroup) extends DenotTransformer(group) { - - def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = ??? + def uncurry(tp: Type)(implicit ctx: Context): Type = tp match { + case tp @ MethodType(pnames1, ptypes1) => + tp.resultType match { + case rt @ MethodType(pnames2, ptypes2) => + tp.derivedMethodType(pnames1 ++ pnames2, ptypes1 ++ ptypes2, rt.resultType) + case _ => + tp + } + case tp: PolyType => + tp.derivedPolyType(tp.paramNames, tp.paramBounds, uncurry(tp.resultType)) + case _ => + tp + } + def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = { + val info1 = uncurry(ref.info) + if (info1 eq ref.info) ref + else ref match { + case ref: SymDenotation => ref.copySymDenotation(info = info1) + case _ => ref.derivedSingleDenotation(ref.symbol, info1) + } + } } class UncurryTreeTransform(group: TreeTransformer, idx: Int) extends TreeTransform(group, idx) { override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo): Tree = - tree match { - case Apply(fn, args) => cpy.Apply(tree, fn, args ++ tree.args) + ctx.traceIndented(s"transforming ${tree.show}", show = true) { + tree.fun match { + case Apply(fn, args) => + def showType(implicit ctx: Context) = + ctx.log(s"at ${ctx.phase} ${fn.symbol} has type ${fn.symbol.info.widen.show}") + showType + ctx.atNextPhase(showType(_)) + showType + cpy.Apply(tree, fn, args ++ tree.args) case _ => tree - } + }} }
\ No newline at end of file |