From dc90608f2646be48eaf643ae7c19604b6333189c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 17 Jan 2013 11:24:33 +0100 Subject: Defined Denotation parameters. --- src/dotty/tools/dotc/core/Denotations.scala | 131 ++++++++++++++-------------- 1 file changed, 66 insertions(+), 65 deletions(-) (limited to 'src/dotty/tools/dotc/core/Denotations.scala') diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 383a46ccd..63f2976b6 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -9,39 +9,25 @@ import collection.immutable.BitSet object Denotations { - abstract class Denotation extends SymRefd { + /** A denotation represents the contents of a definition + * during a period. + */ + abstract class Denotation(initFlags: FlagSet) extends SymRefd { - def symbol: Symbol = ??? + def symbol: Symbol - def owner: Symbol = ??? + def owner: Symbol - def name: Name = ??? + def name: Name - def flags: FlagSet = ??? + private[this] var currentFlags: FlagSet = initFlags - def setFlag(flag: FlagSet): Unit = ??? + def flags: FlagSet = currentFlags - def tpe: Type = ??? + def info: Type - def info: Type = ??? - - /* Validity and instance handling: - * - * Symbols have an interval of validity, defined - * by their `valid` fields. - * - * There may be several symbols with different validity - * representing the same underlying symbol at different phases. - * These are called a "flock". Flock members are generated by - * @see SymRef.trackSym. Flock members are connected in a ring - * with their `nextInFlock` fields. - * - * There are the following invariants converning flock members - * - * 1) validity intervals must be non-overlapping - * 2) the union of all validity intervals must be a contiguous - * interval starting in FirstPhaseId. - */ + def setFlag(flag: FlagSet): Unit = + currentFlags = initFlags /** is this symbol a class? */ def isClass: Boolean = false @@ -57,36 +43,28 @@ object Denotations { override protected def copy(s: Symbol, i: Type): SymRefd = new UniqueSymRefd(s, i, validFor) } - object NameFilter { - final val WordSizeLog = 6 - final val DefinedNamesWords = 16 - final val DefinedNamesSize = DefinedNamesWords << WordSizeLog - final val DefinedNamesMask = DefinedNamesSize - 1 - - type FingerPrint = Array[Long] - - def includeName(bits: FingerPrint, name: Name): Unit = { - val hash = name.start & DefinedNamesMask - bits(hash >> 6) |= (1 << hash) - } - - def includeFingerPrint(bits1: FingerPrint, bits2: FingerPrint): Unit = - for (i <- 0 until DefinedNamesWords) bits1(i) |= bits2(i) - - def containsName(bits: FingerPrint, name: Name): Boolean = { - val hash = name.start & DefinedNamesMask - (bits(hash >> 6) & (1 << hash)) != 0 - } - - def newNameFilter: FingerPrint = new Array[Long](DefinedNamesWords) - } - - class ClassDenotation(val parents: List[Type], val decls: Scope, val clazz: ClassSymbol) extends Denotation { + class NonClassDenotation( + override val symbol: Symbol, + override val owner: Symbol, + override val name: Name, + val initFlags: FlagSet, + override val info: Type + ) extends Denotation(initFlags) + + class ClassDenotation( + override val symbol: ClassSymbol, + override val owner: Symbol, + override val name: Name, + val initFlags: FlagSet, + val parents: List[Type], + val decls: Scope)(implicit ctx: Context) extends Denotation(initFlags) { import NameFilter._ import util.LRU8Cache def typeParams: List[TypeSymbol] = ??? + val info = ClassInfo(owner.thisType, this) + private var memberCacheVar: LRU8Cache[Name, ReferencedSet] = null private def memberCache: LRU8Cache[Name, ReferencedSet] = { @@ -98,7 +76,7 @@ object Denotations { def thisType(implicit ctx: Context): Type = { if (thisTypeCache == null) - thisTypeCache = ThisType(clazz) + thisTypeCache = ThisType(symbol) thisTypeCache } @@ -106,7 +84,7 @@ object Denotations { def typeConstructor(implicit ctx: Context): Type = { if (typeConstructorCache == null) - typeConstructorCache = NamedType(thisType, clazz.name) + typeConstructorCache = NamedType(thisType, symbol.name) typeConstructorCache } @@ -129,7 +107,7 @@ object Denotations { case bc :: bcs1 => val id = bc.superId if (seen contains id) to - else if (locked contains id) throw new CyclicReference(clazz) + else if (locked contains id) throw new CyclicReference(symbol) else { locked += id val bcs1added = addBaseClasses(bcs1, to) @@ -145,7 +123,7 @@ object Denotations { case _ => to } - baseClassesVar = clazz :: addParentBaseClasses(parents, Nil) + baseClassesVar = symbol :: addParentBaseClasses(parents, Nil) superClassBitsVar = ctx.root.uniqueBits.findEntryOrUpdate(seen.toImmutable) } @@ -170,7 +148,7 @@ object Denotations { var bits = newNameFilter var e = decls.lastEntry while (e != null) { - includeName(bits, clazz.name) + includeName(bits, name) e = e.prev } var ps = parents @@ -193,7 +171,7 @@ object Denotations { * someone does a findMember on a subclass. */ def enter(sym: Symbol)(implicit ctx: Context) = { - require((clazz.flags & Frozen) == Flags.Empty) + require(!flags.hasFlagIn(Frozen)) decls enter sym if (definedFingerPrintCache != null) includeName(definedFingerPrintCache, sym.name) @@ -206,7 +184,7 @@ object Denotations { * someone does a findMember on a subclass. */ def delete(sym: Symbol)(implicit ctx: Context) = { - require((clazz.flags & Frozen) == Flags.Empty) + require((flags & Frozen) == Flags.Empty) decls unlink sym if (definedFingerPrintCache != null) computeDefinedFingerPrint @@ -265,11 +243,11 @@ object Denotations { case p :: ps1 => reduce(bt & baseTypeOf(p), ps1) case _ => bt } - if (classd.clazz == clazz) tp.typeTemplate - else reduce(NoType, classd.parents).substThis(classd.clazz, tp.prefix) + if (classd.symbol == symbol) tp.typeTemplate + else reduce(NoType, classd.parents).substThis(classd.symbol, tp.prefix) } - if (clazz.isStaticMono) clazz.typeConstructor + if (symbol.isStaticMono) symbol.typeConstructor else tp match { case tp: CachedType => if (baseTypeValid != ctx.runId) { @@ -282,7 +260,7 @@ object Denotations { basetp = computeBaseTypeOf(tp) baseTypeCache.put(tp, basetp) } else if (basetp == NoType) { - throw new CyclicReference(clazz) + throw new CyclicReference(symbol) } basetp case _ => @@ -306,11 +284,34 @@ object Denotations { } } - object NoDenotation extends Denotation { + object NoDenotation extends Denotation(Flags.Empty) { + override def symbol: Symbol = NoSymbol override def owner: Symbol = throw new AssertionError("NoDenotation.owner") override def name: Name = BootNameTable.newTermName("") - override def flags = Flags.Empty - override def tpe: Type = NoType override def info: Type = NoType } + + object NameFilter { + final val WordSizeLog = 6 + final val DefinedNamesWords = 16 + final val DefinedNamesSize = DefinedNamesWords << WordSizeLog + final val DefinedNamesMask = DefinedNamesSize - 1 + + type FingerPrint = Array[Long] + + def includeName(bits: FingerPrint, name: Name): Unit = { + val hash = name.start & DefinedNamesMask + bits(hash >> 6) |= (1 << hash) + } + + def includeFingerPrint(bits1: FingerPrint, bits2: FingerPrint): Unit = + for (i <- 0 until DefinedNamesWords) bits1(i) |= bits2(i) + + def containsName(bits: FingerPrint, name: Name): Boolean = { + val hash = name.start & DefinedNamesMask + (bits(hash >> 6) & (1 << hash)) != 0 + } + + def newNameFilter: FingerPrint = new Array[Long](DefinedNamesWords) + } } \ No newline at end of file -- cgit v1.2.3