diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-28 19:04:47 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-28 19:04:47 +0100 |
commit | 9c77f0ec16c8e1f6555590a531783e193d3dc7ea (patch) | |
tree | b3aa4a9e9505f90b3a21bf968bbcdd2fc43f9618 /src/dotty/tools/dotc/core/Transformers.scala | |
parent | fe8ee1143f7aabc57212506b3bdd10d7abb63d67 (diff) | |
download | dotty-9c77f0ec16c8e1f6555590a531783e193d3dc7ea.tar.gz dotty-9c77f0ec16c8e1f6555590a531783e193d3dc7ea.tar.bz2 dotty-9c77f0ec16c8e1f6555590a531783e193d3dc7ea.zip |
Polishing of Denotations and Transformers.
Diffstat (limited to 'src/dotty/tools/dotc/core/Transformers.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Transformers.scala | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/core/Transformers.scala b/src/dotty/tools/dotc/core/Transformers.scala index 1244ddfac..ba26c8be8 100644 --- a/src/dotty/tools/dotc/core/Transformers.scala +++ b/src/dotty/tools/dotc/core/Transformers.scala @@ -11,37 +11,54 @@ object Transformers { trait TransformerBase { self: ContextBase => def transformersFor(ref: SingleDenotation): TransformerGroup = ref match { - case _: SymDenotation => denotTransformers + case _: SymDenotation => symTransformers case _ => refTransformers } - val denotTransformers = new TransformerGroup + val symTransformers = new TransformerGroup val refTransformers = new TransformerGroup } - val lastPhaseId = 31 - + /** 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 { + /** A transformer transforms denotations at a given phase */ abstract class Transformer extends DotClass { + + /** The phase at the start of which the denotations are transformed */ val phaseId: Int + + /** The last phase during which the transformed denotations are valid */ def lastPhaseId = 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 } + /** A sentinel transformer object */ object NoTransformer extends Transformer { - val phaseId = Transformers.lastPhaseId + 1 - override def lastPhaseId = phaseId - 1 // TODO JZ Probably off-by-N error here. + val 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") } private val nxTransformer = - Array.fill[Transformer](lastPhaseId + 1)(NoTransformer) + Array.fill[Transformer](MaxPossiblePhaseId + 1)(NoTransformer) - def nextTransformer(i: Int) = nxTransformer(i) + def nextTransformer(pid: PhaseId) = nxTransformer(pid) def install(pid: PhaseId, trans: Transformer): Unit = if ((pid > NoPhaseId) && (nxTransformer(pid).phaseId > pid)) { |