From 4ad6538f7d67a42747d578feaaee633c390c4cbc Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 17 Jan 2013 10:23:51 +0100 Subject: Renamed "Reference" to "Referenced". --- src/dotty/tools/dotc/core/Denotations.scala | 16 +- src/dotty/tools/dotc/core/Referenceds.scala | 357 ++++++++++++++++++++++++++ src/dotty/tools/dotc/core/References.scala | 359 --------------------------- src/dotty/tools/dotc/core/Scopes.scala | 6 +- src/dotty/tools/dotc/core/Symbols.scala | 2 +- src/dotty/tools/dotc/core/Transformers.scala | 8 +- src/dotty/tools/dotc/core/Types.scala | 56 ++--- 7 files changed, 400 insertions(+), 404 deletions(-) create mode 100644 src/dotty/tools/dotc/core/Referenceds.scala delete mode 100644 src/dotty/tools/dotc/core/References.scala (limited to 'src/dotty/tools') diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 8aae7d644..383a46ccd 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -1,7 +1,7 @@ package dotty.tools.dotc package core -import Periods._, Contexts._, Symbols._, References._, Names._ +import Periods._, Contexts._, Symbols._, Referenceds._, Names._ import Types._, Flags._, Decorators._, Transformers._ import Scopes.Scope import collection.mutable @@ -9,7 +9,7 @@ import collection.immutable.BitSet object Denotations { - abstract class Denotation extends SymRef { + abstract class Denotation extends SymRefd { def symbol: Symbol = ??? @@ -54,7 +54,7 @@ object Denotations { def withType(tp: Type): Denotation = ??? - override protected def copy(s: Symbol, i: Type): SymRef = new UniqueSymRef(s, i, validFor) + override protected def copy(s: Symbol, i: Type): SymRefd = new UniqueSymRefd(s, i, validFor) } object NameFilter { @@ -87,9 +87,9 @@ object Denotations { def typeParams: List[TypeSymbol] = ??? - private var memberCacheVar: LRU8Cache[Name, RefSet] = null + private var memberCacheVar: LRU8Cache[Name, ReferencedSet] = null - private def memberCache: LRU8Cache[Name, RefSet] = { + private def memberCache: LRU8Cache[Name, ReferencedSet] = { if (memberCacheVar == null) memberCacheVar = new LRU8Cache memberCacheVar } @@ -219,8 +219,8 @@ object Denotations { if (fp != null) fp else computeDefinedFingerPrint } - final def memberRefsNamed(name: Name)(implicit ctx: Context): RefSet = { - var refs: RefSet = memberCache lookup name + final def memberRefsNamed(name: Name)(implicit ctx: Context): ReferencedSet = { + var refs: ReferencedSet = memberCache lookup name if (refs == null) { if (containsName(definedFingerPrint, name)) { val ownRefs = decls.refsNamed(name) @@ -239,7 +239,7 @@ object Denotations { } } } else { - refs = NoRef + refs = NoRefd } memberCache enter (name, refs) } diff --git a/src/dotty/tools/dotc/core/Referenceds.scala b/src/dotty/tools/dotc/core/Referenceds.scala new file mode 100644 index 000000000..61f95e0e0 --- /dev/null +++ b/src/dotty/tools/dotc/core/Referenceds.scala @@ -0,0 +1,357 @@ +package dotty.tools.dotc +package core + +import Denotations.Denotation +import Contexts.Context +import Names.Name +import Names.TypeName +import Symbols.NoSymbol +import Symbols.Symbol +import Types._, Periods._, Flags._, Transformers._ + + +/** Classes that implement referenced items and sets of them + */ +object Referenceds { + + /** The signature of a referenced. + * Overloaded referenceds with the same name are distinguished by + * their signatures. A signature is a list of the fully qualified names + * of the type symbols of the erasure of the parameters of the + * referenced. For instance a referenced definition + * + * def f(x: Int)(y: List[String]): String + * + * would have signature + * + * List("scala.Int".toTypeName, "scala.collection.immutable.List".toTypeName) + */ + type Signature = List[TypeName] + + /** The signature of a val or parameterless def, as opposed + * to List(), which is the signature of a zero-parameter def. + */ + val NullSignature = List(Names.EmptyTypeName) + + /** A referenced is the result of resolving + * a name (either simple identifier or select) during a given period. + * + * Referenced has two subclasses: OverloadedRefd and SymRefd. + * + * A SymRefd refers to a `symbol` and a type (`info`) that the symbol has + * when seen from the reference. + * + * Referenceds can be combined with `&` and `|`. + * & is conjunction, | is disjunction. + * + * `&` will create an overloaded reference from two + * non-overloaded references if their signatures differ. + * Analogously `|` of two references with different signatures will give + * an empty reference `NoRefd`. + * + * A referenced might refer to `NoSymbol`. This is the case if the referenced + * was produced from a disjunction of two referenceds with different symbols + * and there was no common symbol in a superclass that could substitute for + * both symbols. Here is an example: + * + * Say, we have: + * + * class A { def f: A } + * class B { def f: B } + * val x: A | B = if (???) new A else new B + * val y = x.f + * + * Then the referenced of `y` is `SymRefd(NoSymbol, A | B)`. + */ + abstract class Referenced extends DotClass { + + /** The referenced symbol, exists only for non-overloaded references */ + def symbol: Symbol + + /** The type info of the reference, exists only for non-overloaded references */ + def info: Type + + /** The interval during which this reference is valid */ + def validFor: Period + + /** Is this a reference to a type symbol? */ + def isType: Boolean = false + + /** The signature of the reference */ + def signature: Signature + + /** Resolve overloaded reference to pick the one with the given signature */ + def atSignature(sig: Signature): Referenced + + /** The variant of this reference that's current in the given context. */ + def current(implicit ctx: Context): Referenced + + def exists: Boolean = true + + def orElse(that: => Referenced) = if (this.exists) this else that + + /** Form a reference by conjoining with reference `that` */ + def & (that: Referenced)(implicit ctx: Context): Referenced = + if (this eq that) this + else if (!this.exists) that + else if (!that.exists) this + else that match { + case that: SymRefd => + val r = mergeRef(this, that) + if (r ne NoRefd) r else OverloadedRef(this, that) + case that @ OverloadedRef(ref1, ref2) => + this & ref1 & ref2 + } + + /** Try to merge ref1 and ref2 without adding a new signature. + * If unsuccessful, return NoRefd. + */ + private def mergeRef(ref1: Referenced, ref2: SymRefd)(implicit ctx: Context): Referenced = ref1 match { + case ref1 @ OverloadedRef(ref11, ref12) => + val r1 = mergeRef(ref11, ref2) + if (r1 ne NoRefd) r1 else mergeRef(ref12, ref2) + case ref1: SymRefd => + if (ref1 eq ref2) ref1 + else if (ref1.signature == ref2.signature) { + def isEligible(sym1: Symbol, sym2: Symbol) = + if (sym1.isType) !sym1.isClass + else sym1.isConcrete || sym2.isDeferred || !sym2.exists + def normalize(info: Type) = + if (isType) info.bounds else info + val sym1 = ref1.symbol + val info1 = ref1.info + val sym2 = ref2.symbol + val info2 = ref2.info + val sym1Eligible = isEligible(sym1, sym2) + val sym2Eligible = isEligible(sym2, sym1) + val bounds1 = normalize(info1) + val bounds2 = normalize(info2) + if (sym2Eligible && bounds2 <:< bounds1) ref2 + else if (sym1Eligible && bounds1 <:< bounds2) ref1 + else new JointSymRefd( + if (sym2Eligible) sym2 else sym1, + bounds1 & bounds2, + ref1.validFor & ref2.validFor) + } else NoRefd + } + + def | (that: Referenced)(pre: Type)(implicit ctx: Context): Referenced = { + + def lubSym(sym1: Symbol, sym2: Symbol): Symbol = { + def qualifies(sym: Symbol) = + (sym isAccessibleFrom pre) && (sym2.owner isSubClass sym.owner) + sym1.allOverriddenSymbols find qualifies getOrElse NoSymbol + } + + def throwError = throw new MatchError(s"orRef($this, $that)") + + if (this eq that) this + else if (!this.exists) this + else if (!that.exists) that + else this match { + case ref1 @ OverloadedRef(ref11, ref12) => + ref1.derivedOverloadedRef((ref11 | that)(pre), (ref12 | that)(pre)) + case _ => + that match { + case ref2 @ OverloadedRef(ref21, ref22) => + ref2.derivedOverloadedRef((this | ref21)(pre), (this | ref22)(pre)) + case ref2: SymRefd => + this match { + case ref1: SymRefd => + if (ref1.signature != ref2.signature) NoRefd + else new JointSymRefd( + lubSym(ref1.symbol, ref2.symbol), + ref1.info | ref2.info, + ref1.validFor & ref2.validFor) + case _ => + throwError + } + case _ => + throwError + } + } + } + } + + /** The class of overloaded references + * @param variants The overloaded variants indexed by thheir signatures. + */ + case class OverloadedRef(ref1: Referenced, ref2: Referenced) extends Referenced { + def derivedOverloadedRef(r1: Referenced, r2: Referenced) = + if ((r1 eq ref1) && (r2 eq ref2)) this else OverloadedRef(r1, r2) + def symbol = unsupported("symbol") + def info = unsupported("info") + def signature = unsupported("signature") + def atSignature(sig: Signature): Referenced = + ref1.atSignature(sig) orElse ref2.atSignature(sig) + def validFor = ref1.validFor & ref2.validFor + def current(implicit ctx: Context): Referenced = + derivedOverloadedRef(ref1.current, ref2.current) + } + + abstract class SymRefd extends Referenced with ReferencedSet { + + override def isType = symbol.isType + override def signature: Signature = { + def sig(tp: Type): Signature = tp match { + case tp: PolyType => + tp.resultType match { + case mt: MethodType => mt.signature + case _ => List() + } + case mt: MethodType => mt.signature + case _ => NullSignature + } + if (isType) NullSignature else sig(info) + } + + def derivedSymRefd(s: Symbol, i: Type): SymRefd = + if ((s eq symbol) && (i eq info)) this else copy(s, i) + + protected def copy(s: Symbol, i: Type): SymRefd = this + + def atSignature(sig: Signature): Referenced = + if (sig == signature) this else NoRefd + + // ------ Transformations ----------------------------------------- + + var validFor: Period = Nowhere + + /** The next SymRefd in this run, with wrap-around from last to first. */ + var nextInRun: SymRefd = this + + /** The version of this SymRefd that was valid in the first phase + * of this run. + */ + def initial: SymRefd = { + var current = nextInRun + while (current.validFor.code > this.validFor.code) current = current.nextInRun + current + } + + def current(implicit ctx: Context): SymRefd = { + val currentPeriod = ctx.period + val valid = validFor + var current = this + if (currentPeriod.code > valid.code) { + // search for containing period as long as nextInRun increases. + var next = nextInRun + while (next.validFor.code > valid.code && + !(next.validFor contains currentPeriod)) { + current = next + next = next.nextInRun + } + if (next.validFor.code > valid.code) { + // in this case, containsPeriod(next.validFor, currentPeriod) + current = next + } else { + // not found, current points to highest existing variant + var startPid = current.validFor.lastPhaseId + 1 + val trans = ctx.root.transformersFor(current) + val endPid = trans.nextTransformer(startPid + 1).phaseId - 1 + next = trans.nextTransformer(startPid) transform current + if (next eq current) + startPid = current.validFor.firstPhaseId + else { + current.nextInRun = next + current = next + } + current.validFor = Period(currentPeriod.runId, startPid, endPid) + } + } else { + // currentPeriod < valid; in this case a version must exist + do { + current = current.nextInRun + } while (!(current.validFor contains currentPeriod)) + } + current + } + + def asDenotation = asInstanceOf[Denotation] + + // ------ ReferencedSet ops ---------------------------------------------- + + def toRef(implicit ctx: Context) = this + def containsSig(sig: Signature)(implicit ctx: Context) = + signature == sig + def filter(p: Symbol => Boolean)(implicit ctx: Context): ReferencedSet = + if (p(symbol)) this else NoRefd + def filterDisjoint(refs: ReferencedSet)(implicit ctx: Context): ReferencedSet = + if (refs.containsSig(signature)) NoRefd else this + def filterExcluded(flags: FlagSet)(implicit ctx: Context): ReferencedSet = + if (symbol.hasFlag(flags)) NoRefd else this + def filterAccessibleFrom(pre: Type)(implicit ctx: Context): ReferencedSet = + if (symbol.isAccessibleFrom(pre)) this else NoRefd + def asSeenFrom(pre: Type, owner: Symbol)(implicit ctx: Context): ReferencedSet = + derivedSymRefd(symbol, info.asSeenFrom(pre, owner)) + } + + class UniqueSymRefd(val symbol: Symbol, + val info: Type, + initValidFor: Period) extends SymRefd { + validFor = initValidFor + override protected def copy(s: Symbol, i: Type): SymRefd = new UniqueSymRefd(s, i, validFor) + } + + class JointSymRefd(val symbol: Symbol, + val info: Type, + initValidFor: Period) extends SymRefd { + validFor = initValidFor + override protected def copy(s: Symbol, i: Type): SymRefd = new JointSymRefd(s, i, validFor) + } + + class ErrorRefd(implicit ctx: Context) extends SymRefd { + val symbol = NoSymbol + val info = NoType + validFor = Period.allInRun(ctx.runId) + } + + object NoRefd extends SymRefd { + val symbol = NoSymbol + val info = NoType + validFor = Nowhere + override def exists = false + } + +// --------------- ReferencedSets ------------------------------------------------- + + /** A ReferencedSet represents a set of referenced */ + trait ReferencedSet { + def exists: Boolean + def toRef(implicit ctx: Context): Referenced + def containsSig(sig: Signature)(implicit ctx: Context): Boolean + def filter(p: Symbol => Boolean)(implicit ctx: Context): ReferencedSet + def filterDisjoint(refs: ReferencedSet)(implicit ctx: Context): ReferencedSet + def filterExcluded(flags: FlagSet)(implicit ctx: Context): ReferencedSet + def filterAccessibleFrom(pre: Type)(implicit ctx: Context): ReferencedSet + def asSeenFrom(pre: Type, owner: Symbol)(implicit ctx: Context): ReferencedSet + def union(that: ReferencedSet) = + if (!this.exists) that + else if (that.exists) this + else RefUnion(this, that) + } + + case class RefUnion(refs1: ReferencedSet, refs2: ReferencedSet) extends ReferencedSet { + assert(refs1.exists && !refs2.exists) + private def derivedUnion(s1: ReferencedSet, s2: ReferencedSet) = + if (!s1.exists) s2 + else if (!s2.exists) s1 + else if ((s1 eq refs2) && (s2 eq refs2)) this + else new RefUnion(s1, s2) + def exists = true + def toRef(implicit ctx: Context) = refs1.toRef & refs2.toRef + def containsSig(sig: Signature)(implicit ctx: Context) = + (refs1 containsSig sig) || (refs2 containsSig sig) + def filter(p: Symbol => Boolean)(implicit ctx: Context) = + derivedUnion(refs1 filter p, refs2 filter p) + def filterDisjoint(refs: ReferencedSet)(implicit ctx: Context): ReferencedSet = + derivedUnion(refs1 filterDisjoint refs, refs2 filterDisjoint refs) + def filterExcluded(flags: FlagSet)(implicit ctx: Context): ReferencedSet = + derivedUnion(refs1 filterExcluded flags, refs2 filterExcluded flags) + def filterAccessibleFrom(pre: Type)(implicit ctx: Context): ReferencedSet = + derivedUnion(refs1 filterAccessibleFrom pre, refs2 filterAccessibleFrom pre) + def asSeenFrom(pre: Type, owner: Symbol)(implicit ctx: Context): ReferencedSet = + derivedUnion(refs1.asSeenFrom(pre, owner), refs2.asSeenFrom(pre, owner)) + } +} + diff --git a/src/dotty/tools/dotc/core/References.scala b/src/dotty/tools/dotc/core/References.scala deleted file mode 100644 index d102edc77..000000000 --- a/src/dotty/tools/dotc/core/References.scala +++ /dev/null @@ -1,359 +0,0 @@ -package dotty.tools.dotc -package core - -import Denotations.Denotation -import Contexts.Context -import Names.Name -import Names.TypeName -import Symbols.NoSymbol -import Symbols.Symbol -import Types._, Periods._, Flags._, Transformers._ - - -/** Classes that implement referenced items and sets of them - */ -object References { - - /** The signature of a referenced. - * Overloaded referenceds with the same name are distinguished by - * their signatures. A signature is a list of the fully qualified names - * of the type symbols of the erasure of the parameters of the - * referenced. For instance a referenced definition - * - * def f(x: Int)(y: List[String]): String - * - * would have signature - * - * List("scala.Int".toTypeName, "scala.collection.immutable.List".toTypeName) - */ - type Signature = List[TypeName] - - /** The signature of a val or parameterless def, as opposed - * to List(), which is the signature of a zero-parameter def. - */ - val NullSignature = List(Names.EmptyTypeName) - - /** A referenced is the result of resolving - * a name (either simple identifier or select) during a given period. - * - * Referenced has two subclasses: OverloadedRefd and SymRefd. - * - * A SymRefd refers to a `symbol` and a type (`info`) that the symbol has - * when seen from the reference. - * - * References can be combined with `&` and `|`. - * & is conjunction, | is disjunction. - * - * `&` will create an overloaded reference from two - * non-overloaded references if their signatures differ. - * Analogously `|` of two references with different signatures will give - * an empty reference `NoRefd`. - * - * A referenced might refer to `NoSymbol`. This is the case if the referenced - * was produced from a disjunction of two referenceds with different symbols - * and there was no common symbol in a superclass that could substitute for - * both symbols. Here is an example: - * - * Say, we have: - * - * class A { def f: A } - * class B { def f: B } - * val x: A | B = if (???) new A else new B - * val y = x.f - * - * Then the referenced of `y` is `SymRef(NoSymbol, A | B)`. - */ - abstract class Reference extends DotClass { - - /** The referenced symbol, exists only for non-overloaded references */ - def symbol: Symbol - - /** The type info of the reference, exists only for non-overloaded references */ - def info: Type - - /** The interval during which this reference is valid */ - def validFor: Period - - /** The previous reference */ - def prev: Reference = ??? - - /** Is this a reference to a type symbol? */ - def isType: Boolean = false - - /** The signature of the reference */ - def signature: Signature - - /** Resolve overloaded reference to pick the one with the given signature */ - def atSignature(sig: Signature): Reference - - /** The variant of this reference that's current in the given context. */ - def current(implicit ctx: Context): Reference - - def exists: Boolean = true - - def orElse(that: => Reference) = if (this.exists) this else that - - /** Form a reference by conjoining with reference `that` */ - def & (that: Reference)(implicit ctx: Context): Reference = - if (this eq that) this - else if (!this.exists) that - else if (!that.exists) this - else that match { - case that: SymRef => - val r = mergeRef(this, that) - if (r ne NoRef) r else OverloadedRef(this, that) - case that @ OverloadedRef(ref1, ref2) => - this & ref1 & ref2 - } - - /** Try to merge ref1 and ref2 without adding a new signature. - * If unsuccessful, return NoRef. - */ - private def mergeRef(ref1: Reference, ref2: SymRef)(implicit ctx: Context): Reference = ref1 match { - case ref1 @ OverloadedRef(ref11, ref12) => - val r1 = mergeRef(ref11, ref2) - if (r1 ne NoRef) r1 else mergeRef(ref12, ref2) - case ref1: SymRef => - if (ref1 eq ref2) ref1 - else if (ref1.signature == ref2.signature) { - def isEligible(sym1: Symbol, sym2: Symbol) = - if (sym1.isType) !sym1.isClass - else sym1.isConcrete || sym2.isDeferred || !sym2.exists - def normalize(info: Type) = - if (isType) info.bounds else info - val sym1 = ref1.symbol - val info1 = ref1.info - val sym2 = ref2.symbol - val info2 = ref2.info - val sym1Eligible = isEligible(sym1, sym2) - val sym2Eligible = isEligible(sym2, sym1) - val bounds1 = normalize(info1) - val bounds2 = normalize(info2) - if (sym2Eligible && bounds2 <:< bounds1) ref2 - else if (sym1Eligible && bounds1 <:< bounds2) ref1 - else new JointSymRef( - if (sym2Eligible) sym2 else sym1, - bounds1 & bounds2, - ref1.validFor & ref2.validFor) - } else NoRef - } - - def | (that: Reference)(pre: Type)(implicit ctx: Context): Reference = { - - def lubSym(sym1: Symbol, sym2: Symbol): Symbol = { - def qualifies(sym: Symbol) = - (sym isAccessibleFrom pre) && (sym2.owner isSubClass sym.owner) - sym1.allOverriddenSymbols find qualifies getOrElse NoSymbol - } - - def throwError = throw new MatchError(s"orRef($this, $that)") - - if (this eq that) this - else if (!this.exists) this - else if (!that.exists) that - else this match { - case ref1 @ OverloadedRef(ref11, ref12) => - ref1.derivedOverloadedRef((ref11 | that)(pre), (ref12 | that)(pre)) - case _ => - that match { - case ref2 @ OverloadedRef(ref21, ref22) => - ref2.derivedOverloadedRef((this | ref21)(pre), (this | ref22)(pre)) - case ref2: SymRef => - this match { - case ref1: SymRef => - if (ref1.signature != ref2.signature) NoRef - else new JointSymRef( - lubSym(ref1.symbol, ref2.symbol), - ref1.info | ref2.info, - ref1.validFor & ref2.validFor) - case _ => - throwError - } - case _ => - throwError - } - } - } - } - - /** The class of overloaded references - * @param variants The overloaded variants indexed by thheir signatures. - */ - case class OverloadedRef(ref1: Reference, ref2: Reference) extends Reference { - def derivedOverloadedRef(r1: Reference, r2: Reference) = - if ((r1 eq ref1) && (r2 eq ref2)) this else OverloadedRef(r1, r2) - def symbol = unsupported("symbol") - def info = unsupported("info") - def signature = unsupported("signature") - def atSignature(sig: Signature): Reference = - ref1.atSignature(sig) orElse ref2.atSignature(sig) - def validFor = ref1.validFor & ref2.validFor - def current(implicit ctx: Context): Reference = - derivedOverloadedRef(ref1.current, ref2.current) - } - - abstract class SymRef extends Reference with RefSet { - - override def isType = symbol.isType - override def signature: Signature = { - def sig(tp: Type): Signature = tp match { - case tp: PolyType => - tp.resultType match { - case mt: MethodType => mt.signature - case _ => List() - } - case mt: MethodType => mt.signature - case _ => NullSignature - } - if (isType) NullSignature else sig(info) - } - - def derivedSymRef(s: Symbol, i: Type): SymRef = - if ((s eq symbol) && (i eq info)) this else copy(s, i) - - protected def copy(s: Symbol, i: Type): SymRef = this - - def atSignature(sig: Signature): Reference = - if (sig == signature) this else NoRef - - // ------ Transformations ----------------------------------------- - - var validFor: Period = Nowhere - - /** The next SymRef in this run, with wrap-around from last to first. */ - var nextInRun: SymRef = this - - /** The version of this SymRef that was valid in the first phase - * of this run. - */ - def initial: SymRef = { - var current = nextInRun - while (current.validFor.code > this.validFor.code) current = current.nextInRun - current - } - - def current(implicit ctx: Context): SymRef = { - val currentPeriod = ctx.period - val valid = validFor - var current = this - if (currentPeriod.code > valid.code) { - // search for containing period as long as nextInRun increases. - var next = nextInRun - while (next.validFor.code > valid.code && - !(next.validFor contains currentPeriod)) { - current = next - next = next.nextInRun - } - if (next.validFor.code > valid.code) { - // in this case, containsPeriod(next.validFor, currentPeriod) - current = next - } else { - // not found, current points to highest existing variant - var startPid = current.validFor.lastPhaseId + 1 - val trans = ctx.root.transformersFor(current) - val endPid = trans.nextTransformer(startPid + 1).phaseId - 1 - next = trans.nextTransformer(startPid) transform current - if (next eq current) - startPid = current.validFor.firstPhaseId - else { - current.nextInRun = next - current = next - } - current.validFor = Period(currentPeriod.runId, startPid, endPid) - } - } else { - // currentPeriod < valid; in this case a version must exist - do { - current = current.nextInRun - } while (!(current.validFor contains currentPeriod)) - } - current - } - - def asDenotation = asInstanceOf[Denotation] - - // ------ RefSet ops ---------------------------------------------- - - def toRef(implicit ctx: Context) = this - def containsSig(sig: Signature)(implicit ctx: Context) = - signature == sig - def filter(p: Symbol => Boolean)(implicit ctx: Context): RefSet = - if (p(symbol)) this else NoRef - def filterDisjoint(refs: RefSet)(implicit ctx: Context): RefSet = - if (refs.containsSig(signature)) NoRef else this - def filterExcluded(flags: FlagSet)(implicit ctx: Context): RefSet = - if (symbol.hasFlag(flags)) NoRef else this - def filterAccessibleFrom(pre: Type)(implicit ctx: Context): RefSet = - if (symbol.isAccessibleFrom(pre)) this else NoRef - def asSeenFrom(pre: Type, owner: Symbol)(implicit ctx: Context): RefSet = - derivedSymRef(symbol, info.asSeenFrom(pre, owner)) - } - - class UniqueSymRef(val symbol: Symbol, - val info: Type, - initValidFor: Period) extends SymRef { - validFor = initValidFor - override protected def copy(s: Symbol, i: Type): SymRef = new UniqueSymRef(s, i, validFor) - } - - class JointSymRef(val symbol: Symbol, - val info: Type, - initValidFor: Period) extends SymRef { - validFor = initValidFor - override protected def copy(s: Symbol, i: Type): SymRef = new JointSymRef(s, i, validFor) - } - - class ErrorRef(implicit ctx: Context) extends SymRef { - val symbol = NoSymbol - val info = NoType - validFor = Period.allInRun(ctx.runId) - } - - object NoRef extends SymRef { - val symbol = NoSymbol - val info = NoType - validFor = Nowhere - override def exists = false - } - -// --------------- RefSets ------------------------------------------------- - - trait RefSet { - def exists: Boolean - def toRef(implicit ctx: Context): Reference - def containsSig(sig: Signature)(implicit ctx: Context): Boolean - def filter(p: Symbol => Boolean)(implicit ctx: Context): RefSet - def filterDisjoint(refs: RefSet)(implicit ctx: Context): RefSet - def filterExcluded(flags: FlagSet)(implicit ctx: Context): RefSet - def filterAccessibleFrom(pre: Type)(implicit ctx: Context): RefSet - def asSeenFrom(pre: Type, owner: Symbol)(implicit ctx: Context): RefSet - def union(that: RefSet) = - if (!this.exists) that - else if (that.exists) this - else RefUnion(this, that) - } - - case class RefUnion(refs1: RefSet, refs2: RefSet) extends RefSet { - assert(refs1.exists && !refs2.exists) - private def derivedUnion(s1: RefSet, s2: RefSet) = - if (!s1.exists) s2 - else if (!s2.exists) s1 - else if ((s1 eq refs2) && (s2 eq refs2)) this - else new RefUnion(s1, s2) - def exists = true - def toRef(implicit ctx: Context) = refs1.toRef & refs2.toRef - def containsSig(sig: Signature)(implicit ctx: Context) = - (refs1 containsSig sig) || (refs2 containsSig sig) - def filter(p: Symbol => Boolean)(implicit ctx: Context) = - derivedUnion(refs1 filter p, refs2 filter p) - def filterDisjoint(refs: RefSet)(implicit ctx: Context): RefSet = - derivedUnion(refs1 filterDisjoint refs, refs2 filterDisjoint refs) - def filterExcluded(flags: FlagSet)(implicit ctx: Context): RefSet = - derivedUnion(refs1 filterExcluded flags, refs2 filterExcluded flags) - def filterAccessibleFrom(pre: Type)(implicit ctx: Context): RefSet = - derivedUnion(refs1 filterAccessibleFrom pre, refs2 filterAccessibleFrom pre) - def asSeenFrom(pre: Type, owner: Symbol)(implicit ctx: Context): RefSet = - derivedUnion(refs1.asSeenFrom(pre, owner), refs2.asSeenFrom(pre, owner)) - } -} - diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala index 7a827ccf1..f9fa69c1c 100644 --- a/src/dotty/tools/dotc/core/Scopes.scala +++ b/src/dotty/tools/dotc/core/Scopes.scala @@ -11,7 +11,7 @@ import Names._ import Periods._ import Decorators._ import Contexts._ -import References._ +import Referenceds._ object Scopes { @@ -195,8 +195,8 @@ object Scopes { } /** The reference set of all the symbols with given name in this scope */ - def refsNamed(name: Name)(implicit ctx: Context): RefSet = { - var syms: RefSet = NoRef + def refsNamed(name: Name)(implicit ctx: Context): ReferencedSet = { + var syms: ReferencedSet = NoRefd var e = lookupEntry(name) while (e != null) { syms = syms union e.sym.deref diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala index 3f14fd37b..331c168a8 100644 --- a/src/dotty/tools/dotc/core/Symbols.scala +++ b/src/dotty/tools/dotc/core/Symbols.scala @@ -11,7 +11,7 @@ import Symbols._ import Contexts._ import Denotations._ import Types._ -import References.{Reference, SymRef, OverloadedRef} +import Referenceds.{Referenced, SymRefd, OverloadedRef} import collection.mutable object Symbols { diff --git a/src/dotty/tools/dotc/core/Transformers.scala b/src/dotty/tools/dotc/core/Transformers.scala index 2bc475104..ae58080e4 100644 --- a/src/dotty/tools/dotc/core/Transformers.scala +++ b/src/dotty/tools/dotc/core/Transformers.scala @@ -1,14 +1,14 @@ package dotty.tools.dotc package core -import Periods._, Denotations._, Contexts._, Types._, References._ +import Periods._, Denotations._, Contexts._, Types._, Referenceds._ import java.lang.AssertionError trait Transformers { self: RootContext => import Transformers._ - def transformersFor(ref: SymRef): TransformerGroup = ref match { + def transformersFor(ref: SymRefd): TransformerGroup = ref match { case _: Denotation => denotTransformers case _ => refTransformers } @@ -28,12 +28,12 @@ object Transformers { def lastPhaseId = nextTransformer(phaseId).phaseId - 1 def validFor(implicit ctx: Context): Period = Period(ctx.runId, phaseId, lastPhaseId) - def transform(ref: SymRef)(implicit ctx: Context): SymRef + def transform(ref: SymRefd)(implicit ctx: Context): SymRefd } object NoTransformer extends Transformer { val phaseId = lastPhaseId + 1 - def transform(ref: SymRef)(implicit ctx: Context): SymRef = + def transform(ref: SymRefd)(implicit ctx: Context): SymRefd = unsupported("transform") } diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 3c5530bb0..4db037a86 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -11,7 +11,7 @@ import Constants._ import Contexts._ import Annotations._ import Denotations._ -import References._ +import Referenceds._ import Periods._ import scala.util.hashing.{ MurmurHash3 => hashing } import collection.mutable @@ -195,11 +195,11 @@ object Types { if (from.isDependent) ctx.subst(this, from, to, null) else this - /** Substitute all references of the form `This(clazz)` by `tp` */ + /** Substitute all occurrences of `This(clazz)` by `tp` */ final def substThis(clazz: ClassSymbol, tp: Type)(implicit ctx: Context): Type = ctx.substThis(this, clazz, tp, null) - /** Substitute all references of the form `RefinedThis(from)` by `tp` */ + /** Substitute all occurrences of `RefinedThis(from)` by `tp` */ final def substThis(from: RefinedType, tp: Type)(implicit ctx: Context): Type = ctx.substThis(this, from, tp, null) @@ -255,23 +255,23 @@ object Types { } /** The declaration of this type with given name */ - final def decl(name: Name)(implicit ctx: Context): Reference = + final def decl(name: Name)(implicit ctx: Context): Referenced = decls.refsNamed(name).toRef /** The member of this type with given name */ - final def member(name: Name)(implicit ctx: Context): Reference = + final def member(name: Name)(implicit ctx: Context): Referenced = findMember(name, this, Flags.Empty) /** The non-private member of this type with given name */ - final def nonPrivateMember(name: Name)(implicit ctx: Context): Reference = + final def nonPrivateMember(name: Name)(implicit ctx: Context): Referenced = findMember(name, this, Flags.Private) /** Find member of this type with given name and - * produce a reference that contains the type of the member + * produce a referenced that contains the type of the member * as seen from given prefix `pre`. Exclude all members with one * of the flags in `excluded` from consideration. */ - final def findMember(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Reference = this match { + final def findMember(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Referenced = this match { case tp: RefinedType => tp.parent.findMember(name, pre, excluded | Flags.Private) & tp.findDecl(name, pre) @@ -285,7 +285,7 @@ object Types { .filterExcluded(excluded) .asSeenFrom(pre, classd.clazz) if (resultSyms.exists) resultSyms.toRef - else new ErrorRef // todo: refine + else new ErrorRefd // todo: refine case tp: AndType => tp.tp1.findMember(name, pre, excluded) & tp.tp2.findMember(name, pre, excluded) case tp: OrType => @@ -515,37 +515,35 @@ object Types { val prefix: Type val name: Name - private[this] var referenceVar: Reference = null + private[this] var lastReferenced: Referenced = null private def checkPrefix(sym: Symbol) = sym.isAbstractType || sym.isClass - /** The reference currently denoted by this type */ - def reference(implicit ctx: Context): Reference = { + /** The referenced currently denoted by this type */ + def deref(implicit ctx: Context): Referenced = { val validPeriods = - if (referenceVar != null) referenceVar.validFor else Nowhere + if (lastReferenced != null) lastReferenced.validFor else Nowhere if (!(validPeriods contains ctx.period)) { val thisPeriod = ctx.period - referenceVar = + lastReferenced = if (validPeriods.runId == thisPeriod.runId) - referenceVar.current - //val ref @ SymRef(clazz: ClassSymbol, _) = referenceVar - //ref.derivedSymRef(clazz, ClassInfo(prefix, clazz.deref)) + lastReferenced.current else if (thisPeriod.phaseId > name.lastIntroPhaseId) ctx.atPhase(name.lastIntroPhaseId)(prefix.member(name)(_)).current else prefix.member(name) - if (checkPrefix(referenceVar.symbol) && !prefix.isLegalPrefix) - throw new MalformedType(prefix, referenceVar.symbol) + if (checkPrefix(lastReferenced.symbol) && !prefix.isLegalPrefix) + throw new MalformedType(prefix, lastReferenced.symbol) } - referenceVar + lastReferenced } def isType = name.isTypeName def isTerm = name.isTermName - def symbol(implicit ctx: Context): Symbol = reference.symbol - def info(implicit ctx: Context): Type = reference.info + def symbol(implicit ctx: Context): Symbol = deref.symbol + def info(implicit ctx: Context): Type = deref.info override def underlying(implicit ctx: Context): Type = info @@ -566,7 +564,7 @@ object Types { protected val fixedSym: Symbol override def symbol(implicit ctx: Context): Symbol = fixedSym override def info(implicit ctx: Context): Type = fixedSym.info - override def reference(implicit ctx: Context): Reference = fixedSym.deref + override def deref(implicit ctx: Context): Referenced = fixedSym.deref } final class TermRefNoPrefix(val fixedSym: TermSymbol)(implicit ctx: Context) @@ -575,8 +573,8 @@ object Types { final class TermRefWithSignature(prefix: Type, name: TermName, override val signature: Signature) extends TermRef(prefix, name) { override def computeHash = doHash((name, signature), prefix) - override def reference(implicit ctx: Context): Reference = - super.reference.atSignature(signature) + override def deref(implicit ctx: Context): Referenced = + super.deref.atSignature(signature) } final class TypeRefNoPrefix(val fixedSym: TypeSymbol)(implicit ctx: Context) @@ -687,13 +685,13 @@ object Types { infos1 map (_.substThis(this, thistp)) } - def findDecl(name: Name, pre: Type)(implicit ctx: Context): Reference = { + def findDecl(name: Name, pre: Type)(implicit ctx: Context): Referenced = { var ns = names var is = infos - var ref: Reference = NoRef - while (ns.nonEmpty && (ref eq NoRef)) { + var ref: Referenced = NoRefd + while (ns.nonEmpty && (ref eq NoRefd)) { if (ns.head == name) - ref = new JointSymRef(NoSymbol, is.head.substThis(this, pre), Period.allInRun(ctx.runId)) + ref = new JointSymRefd(NoSymbol, is.head.substThis(this, pre), Period.allInRun(ctx.runId)) ns = ns.tail is = is.tail } -- cgit v1.2.3