From 76ea699ac1a76ee6048d7fe8239d0a1126581429 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 15 Mar 2014 11:05:42 +0100 Subject: Renaming core.Transformer(s) -> core.DenotTransformer(s) To bring in line with TreeTransformer terminology. --- src/dotty/tools/dotc/core/Contexts.scala | 2 +- src/dotty/tools/dotc/core/DenotTransformers.scala | 69 +++++++++++++++++++++++ src/dotty/tools/dotc/core/Denotations.scala | 4 +- src/dotty/tools/dotc/core/Periods.scala | 2 +- src/dotty/tools/dotc/core/SymDenotations.scala | 2 +- src/dotty/tools/dotc/core/Symbols.scala | 1 - src/dotty/tools/dotc/core/Transformers.scala | 69 ----------------------- 7 files changed, 74 insertions(+), 75 deletions(-) create mode 100644 src/dotty/tools/dotc/core/DenotTransformers.scala delete mode 100644 src/dotty/tools/dotc/core/Transformers.scala (limited to 'src/dotty/tools/dotc/core') diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 9be2e2f43..0d6e341a6 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -361,7 +361,7 @@ object Contexts { * compiler run. */ class ContextBase extends ContextState - with Transformers.TransformerBase + with DenotTransformers.DenotTransformerBase with Denotations.DenotationsBase with Phases.PhasesBase { diff --git a/src/dotty/tools/dotc/core/DenotTransformers.scala b/src/dotty/tools/dotc/core/DenotTransformers.scala new file mode 100644 index 000000000..f41f1d171 --- /dev/null +++ b/src/dotty/tools/dotc/core/DenotTransformers.scala @@ -0,0 +1,69 @@ +package dotty.tools.dotc +package core + +import Periods._ +import SymDenotations._ +import Contexts._ +import Types._ +import Denotations._ +import java.lang.AssertionError +import dotty.tools.dotc.util.DotClass + +object DenotTransformers { + + trait DenotTransformerBase { self: ContextBase => + val denotTransformers = new DenotTransformerGroup + } + + /** A transformer group contains a sequence of transformers, + * ordered by the phase where they apply. Transformers are added + * to a group via `install`. + * + * There are two transformerGroups in a context base: + * symTransformers and refTransformers. symTransformers translate + * full symbol denotations, refTransformers translate only symbol references + * of type Unique/JointRefDenotation. + */ + class DenotTransformerGroup { + + private val nxTransformer = + Array.fill[DenotTransformer](MaxPossiblePhaseId + 1)(NoTransformer) + + def nextTransformer(pid: PhaseId) = nxTransformer(pid) + + def install(pid: PhaseId, transFn: DenotTransformerGroup => DenotTransformer): Unit = + if ((pid > NoPhaseId) && (nxTransformer(pid).phaseId > pid)) { + val trans = transFn(this) + trans._phaseId = pid + nxTransformer(pid) = transFn(this) + install(pid - 1, transFn) + } + + /** A sentinel transformer object */ + object NoTransformer extends DenotTransformer(this) { + _phaseId = MaxPossiblePhaseId + 1 + override def lastPhaseId = phaseId - 1 // TODO JZ Probably off-by-N error here. MO: Don't think so: we want empty validity period. + def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = + unsupported("transform") + } + } + + /** A transformer transforms denotations at a given phase */ + abstract class DenotTransformer(group: DenotTransformerGroup) extends DotClass { + + private[DenotTransformers] var _phaseId: PhaseId = _ + + /** The phase at the start of which the denotations are transformed */ + def phaseId: PhaseId = _phaseId + + /** The last phase during which the transformed denotations are valid */ + def lastPhaseId = group.nextTransformer(phaseId).phaseId - 1 + + /** The validity period of the transformer in the given context */ + def validFor(implicit ctx: Context): Period = + Period(ctx.runId, phaseId, lastPhaseId) + + /** The transformation method */ + def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation + } +} diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index fce5b1a16..bd1aedd75 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -11,7 +11,7 @@ import Symbols._ import Types._ import Periods._ import Flags._ -import Transformers._ +import DenotTransformers._ import Decorators._ import transform.Erasure import printing.Texts._ @@ -518,7 +518,7 @@ object Denotations { } else { // not found, cur points to highest existing variant var startPid = cur.validFor.lastPhaseId + 1 - val transformer = ctx.infoTransformers.nextTransformer(startPid) + val transformer = ctx.denotTransformers.nextTransformer(startPid) next = transformer.transform(cur).syncWithParents if (next eq cur) startPid = cur.validFor.firstPhaseId diff --git a/src/dotty/tools/dotc/core/Periods.scala b/src/dotty/tools/dotc/core/Periods.scala index 31fde2dac..592516531 100644 --- a/src/dotty/tools/dotc/core/Periods.scala +++ b/src/dotty/tools/dotc/core/Periods.scala @@ -34,7 +34,7 @@ abstract class Periods extends DotClass { self: Context => */ def stablePeriod = { var first = phaseId - val transformers = base.infoTransformers + val transformers = base.denotTransformers val nxTrans = transformers.nextTransformer(first) while (first - 1 > NoPhaseId && (transformers.nextTransformer(first - 1) eq nxTrans)) { diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 7fd5cdacc..08566e3db 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -2,7 +2,7 @@ package dotty.tools.dotc package core import Periods._, Contexts._, Symbols._, Denotations._, Names._, NameOps._, Annotations._ -import Types._, Flags._, Decorators._, Transformers._, StdNames._, Scopes._ +import Types._, Flags._, Decorators._, DenotTransformers._, StdNames._, Scopes._ import NameOps._ import Scopes.Scope import collection.mutable diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala index 3fc8a4f2c..ff70679b8 100644 --- a/src/dotty/tools/dotc/core/Symbols.scala +++ b/src/dotty/tools/dotc/core/Symbols.scala @@ -3,7 +3,6 @@ package dotc package core import Periods._ -import Transformers._ import Names._ import Scopes._ import Flags._ diff --git a/src/dotty/tools/dotc/core/Transformers.scala b/src/dotty/tools/dotc/core/Transformers.scala deleted file mode 100644 index 9b8bb65a4..000000000 --- a/src/dotty/tools/dotc/core/Transformers.scala +++ /dev/null @@ -1,69 +0,0 @@ -package dotty.tools.dotc -package core - -import Periods._ -import SymDenotations._ -import Contexts._ -import Types._ -import Denotations._ -import java.lang.AssertionError -import dotty.tools.dotc.util.DotClass - -object Transformers { - - trait TransformerBase { self: ContextBase => - val infoTransformers = new TransformerGroup - } - - /** A transformer group contains a sequence of transformers, - * ordered by the phase where they apply. Transformers are added - * to a group via `install`. - * - * There are two transformerGroups in a context base: - * symTransformers and refTransformers. symTransformers translate - * full symbol denotations, refTransformers translate only symbol references - * of type Unique/JointRefDenotation. - */ - class TransformerGroup { - - private val nxTransformer = - Array.fill[Transformer](MaxPossiblePhaseId + 1)(NoTransformer) - - def nextTransformer(pid: PhaseId) = nxTransformer(pid) - - def install(pid: PhaseId, transFn: TransformerGroup => Transformer): Unit = - if ((pid > NoPhaseId) && (nxTransformer(pid).phaseId > pid)) { - val trans = transFn(this) - trans._phaseId = pid - nxTransformer(pid) = transFn(this) - install(pid - 1, transFn) - } - - /** A sentinel transformer object */ - object NoTransformer extends Transformer(this) { - _phaseId = MaxPossiblePhaseId + 1 - override def lastPhaseId = phaseId - 1 // TODO JZ Probably off-by-N error here. MO: Don't think so: we want empty validity period. - def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = - unsupported("transform") - } - } - - /** A transformer transforms denotations at a given phase */ - abstract class Transformer(group: TransformerGroup) extends DotClass { - - private[Transformers] var _phaseId: PhaseId = _ - - /** The phase at the start of which the denotations are transformed */ - def phaseId: PhaseId = _phaseId - - /** The last phase during which the transformed denotations are valid */ - def lastPhaseId = group.nextTransformer(phaseId).phaseId - 1 - - /** The validity period of the transformer in the given context */ - def validFor(implicit ctx: Context): Period = - Period(ctx.runId, phaseId, lastPhaseId) - - /** The transformation method */ - def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation - } -} -- cgit v1.2.3