From 103beef6ab89d6138ec7462fcf85ee3f93cf2b52 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 14 Apr 2014 14:38:57 +0200 Subject: InfoTransformers as specific DenotTransformers Factored out denot transformer behavior where the we transform types in a uniform way into InfoTransformers. --- src/dotty/tools/dotc/core/DenotTransformers.scala | 16 ++++++++++++++++ src/dotty/tools/dotc/transform/InterceptedMethods.scala | 2 -- src/dotty/tools/dotc/transform/PatternMatcher.scala | 1 - src/dotty/tools/dotc/transform/TypeTestsCasts.scala | 1 - .../tools/dotc/transform/UncurryTreeTransform.scala | 13 ++++--------- 5 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/DenotTransformers.scala b/src/dotty/tools/dotc/core/DenotTransformers.scala index e1ee355d8..6daa028fc 100644 --- a/src/dotty/tools/dotc/core/DenotTransformers.scala +++ b/src/dotty/tools/dotc/core/DenotTransformers.scala @@ -5,6 +5,7 @@ import Periods._ import SymDenotations._ import Contexts._ import Types._ +import Symbols._ import Denotations._ import Phases._ import java.lang.AssertionError @@ -30,4 +31,19 @@ object DenotTransformers { /** The transformation method */ def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation } + + trait InfoTransformer extends DenotTransformer { + + def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type + + /** The transformation method */ + def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = { + val info1 = transformInfo(ref.info, ref.symbol) + if (info1 eq ref.info) ref + else ref match { + case ref: SymDenotation => ref.copySymDenotation(info = info1) + case _ => ref.derivedSingleDenotation(ref.symbol, info1) + } + } + } } diff --git a/src/dotty/tools/dotc/transform/InterceptedMethods.scala b/src/dotty/tools/dotc/transform/InterceptedMethods.scala index b56985ffe..d5a4377d0 100644 --- a/src/dotty/tools/dotc/transform/InterceptedMethods.scala +++ b/src/dotty/tools/dotc/transform/InterceptedMethods.scala @@ -2,7 +2,6 @@ package dotty.tools.dotc package transform import TreeTransforms._ -import core.DenotTransformers._ import core.Denotations._ import core.SymDenotations._ import core.Contexts._ @@ -27,7 +26,6 @@ import dotty.runtime.LazyVals import scala.collection.mutable.ListBuffer import dotty.tools.dotc.core.Denotations.SingleDenotation import dotty.tools.dotc.core.SymDenotations.SymDenotation -import dotty.tools.dotc.core.DenotTransformers.DenotTransformer import StdNames._ /** Replace member references as follows: diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index ff25a94de..40a157483 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -2,7 +2,6 @@ package dotty.tools.dotc package transform import TreeTransforms._ -import core.DenotTransformers._ import core.Denotations._ import core.SymDenotations._ import core.Contexts._ diff --git a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index aba674d1c..a36bf6500 100644 --- a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -2,7 +2,6 @@ package dotty.tools.dotc package transform import TreeTransforms._ -import core.DenotTransformers._ import core.Denotations._ import core.SymDenotations._ import core.Contexts._ diff --git a/src/dotty/tools/dotc/transform/UncurryTreeTransform.scala b/src/dotty/tools/dotc/transform/UncurryTreeTransform.scala index fe50e41cd..ccfaaa0dc 100644 --- a/src/dotty/tools/dotc/transform/UncurryTreeTransform.scala +++ b/src/dotty/tools/dotc/transform/UncurryTreeTransform.scala @@ -7,10 +7,11 @@ import core.Denotations._ import core.SymDenotations._ import core.Contexts._ import core.Types._ +import core.Symbols._ import ast.Trees._ import ast.tpd.{Apply, Tree, cpy} -class UncurryTreeTransform extends TreeTransform with DenotTransformer { +class UncurryTreeTransform extends TreeTransform with InfoTransformer { override def name: String = "uncurry" override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo): Tree = @@ -40,12 +41,6 @@ class UncurryTreeTransform extends TreeTransform with DenotTransformer { 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) - } - } + def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type = + uncurry(tp) } \ No newline at end of file -- cgit v1.2.3