diff options
author | Martin Odersky <odersky@gmail.com> | 2005-09-20 17:45:45 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2005-09-20 17:45:45 +0000 |
commit | 3761cb4b3a1c03f5daa2fac28d19f6f398072ffe (patch) | |
tree | af915e38284d71f68b9986f7050e0aa5555345f0 /sources/scala/tools/nsc/symtab | |
parent | a2231f55a00c96ecf670e0f02ed026c0ff956ecc (diff) | |
download | scala-3761cb4b3a1c03f5daa2fac28d19f6f398072ffe.tar.gz scala-3761cb4b3a1c03f5daa2fac28d19f6f398072ffe.tar.bz2 scala-3761cb4b3a1c03f5daa2fac28d19f6f398072ffe.zip |
*** empty log message ***
Diffstat (limited to 'sources/scala/tools/nsc/symtab')
-rw-r--r-- | sources/scala/tools/nsc/symtab/InfoTransformers.scala | 5 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/Scopes.scala | 11 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/SymbolTable.scala | 1 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/Symbols.scala | 27 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/Types.scala | 39 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala | 2 |
6 files changed, 54 insertions, 31 deletions
diff --git a/sources/scala/tools/nsc/symtab/InfoTransformers.scala b/sources/scala/tools/nsc/symtab/InfoTransformers.scala index d74a099537..bb03eaac8e 100644 --- a/sources/scala/tools/nsc/symtab/InfoTransformers.scala +++ b/sources/scala/tools/nsc/symtab/InfoTransformers.scala @@ -8,10 +8,11 @@ package scala.tools.nsc.symtab; abstract class InfoTransformers: SymbolTable { abstract class InfoTransformer { - private var prev: InfoTransformer = this; - private var next: InfoTransformer = this; + var prev: InfoTransformer = this; + var next: InfoTransformer = this; val phase: Phase; + val changesBaseClasses: boolean; def transform(sym: Symbol, tpe: Type): Type; def insert(that: InfoTransformer): unit = { diff --git a/sources/scala/tools/nsc/symtab/Scopes.scala b/sources/scala/tools/nsc/symtab/Scopes.scala index cc2da304c0..47c1bcb226 100755 --- a/sources/scala/tools/nsc/symtab/Scopes.scala +++ b/sources/scala/tools/nsc/symtab/Scopes.scala @@ -7,7 +7,7 @@ package scala.tools.nsc.symtab; abstract class Scopes: SymbolTable { - abstract class ScopeEntry(val sym: Symbol, val owner: Scope) { + class ScopeEntry(val sym: Symbol, val owner: Scope) { /** the next entry in the hash bucket */ @@ -21,9 +21,11 @@ abstract class Scopes: SymbolTable { override def toString(): String = sym.toString(); } - def newScopeEntry(sym: Symbol, owner: Scope) = new ScopeEntry(sym, owner) { - next = owner.elems; - owner.elems = this; + def newScopeEntry(sym: Symbol, owner: Scope): ScopeEntry = { + val e = new ScopeEntry(sym, owner); + e.next = owner.elems; + owner.elems = e; + e } object NoScopeEntry extends ScopeEntry(NoSymbol, null); @@ -98,7 +100,6 @@ abstract class Scopes: SymbolTable { /** enter a scope entry */ def enter(e: ScopeEntry): unit = { - elems = e; elemsCache = null; if (hashtable != null) { val i = e.sym.name.start & HASHMASK; diff --git a/sources/scala/tools/nsc/symtab/SymbolTable.scala b/sources/scala/tools/nsc/symtab/SymbolTable.scala index a7c0a61328..ba15a14b19 100755 --- a/sources/scala/tools/nsc/symtab/SymbolTable.scala +++ b/sources/scala/tools/nsc/symtab/SymbolTable.scala @@ -37,6 +37,7 @@ abstract class SymbolTable extends Names var infoTransformers = new InfoTransformer { val phase = NoPhase; + val changesBaseClasses = true; def transform(sym: Symbol, tpe: Type): Type = tpe; } } diff --git a/sources/scala/tools/nsc/symtab/Symbols.scala b/sources/scala/tools/nsc/symtab/Symbols.scala index 0a27a03948..abd68a107c 100755 --- a/sources/scala/tools/nsc/symtab/Symbols.scala +++ b/sources/scala/tools/nsc/symtab/Symbols.scala @@ -115,6 +115,7 @@ abstract class Symbols: SymbolTable { final def isMixinConstructor = isTerm && (name == nme.MIXIN_CONSTRUCTOR); final def isConstructor = isTerm && (name == nme.CONSTRUCTOR) || (name == nme.MIXIN_CONSTRUCTOR); final def isModule = isTerm && hasFlag(MODULE); + final def isStaticModule = isModule && isStatic && !isMethod; final def isPackage = isModule && hasFlag(PACKAGE); final def isThisSym = isTerm && name == nme.this_; final def isError = hasFlag(IS_ERROR); @@ -128,6 +129,7 @@ abstract class Symbols: SymbolTable { final def isModuleClass = isClass && hasFlag(MODULE); final def isPackageClass = isClass && hasFlag(PACKAGE); final def isRoot = isPackageClass && name == nme.ROOT.toTypeName; + final def isRootPackage = isPackage && name == nme.ROOT; final def isEmptyPackage = isPackage && name == nme.EMPTY_PACKAGE_NAME; final def isEmptyPackageClass = isPackageClass && name == nme.EMPTY_PACKAGE_NAME.toTypeName; @@ -483,7 +485,7 @@ abstract class Symbols: SymbolTable { */ final def linkedClass: Symbol = { if (owner.isPackageClass) - owner.info.decl(name.toTypeName).suchThat(sym => sym.rawInfo != NoType) + owner.info.decl(name.toTypeName).suchThat(sym => sym.rawInfo ne NoType) else NoSymbol; } @@ -493,7 +495,7 @@ abstract class Symbols: SymbolTable { final def linkedModule: Symbol = if (owner.isPackageClass) owner.info.decl(name.toTermName).suchThat( - sym => (sym hasFlag MODULE) && (sym.rawInfo != NoType)); + sym => (sym hasFlag MODULE) && (sym.rawInfo ne NoType)); else NoSymbol; /** The top-level class containing this symbol */ @@ -504,7 +506,7 @@ abstract class Symbols: SymbolTable { final def linkedSym: Symbol = if (isTerm) linkedClass else if (isClass && owner.isPackageClass) - owner.info.decl(name.toTermName).suchThat(sym => sym.rawInfo != NoType) + owner.info.decl(name.toTermName).suchThat(sym => sym.rawInfo ne NoType) else NoSymbol; final def toInterface: Symbol = @@ -723,6 +725,17 @@ abstract class Symbols: SymbolTable { private var referenced: Symbol = NoSymbol; + override def owner: Symbol = + if (phase.flatClasses && hasFlag(MODULE) && !hasFlag(METHOD) && + rawowner != NoSymbol && !rawowner.isPackageClass) rawowner.owner + else rawowner; + + override def name: Name = + if (phase.flatClasses && hasFlag(MODULE) && !hasFlag(METHOD) && + rawowner != NoSymbol && !rawowner.isPackageClass) + newTermName(rawowner.name.toString() + "$" + rawname); + else rawname; + def cloneSymbolImpl(owner: Symbol): Symbol = { val clone = new TermSymbol(owner, pos, name); clone.referenced = referenced; @@ -758,7 +771,7 @@ abstract class Symbols: SymbolTable { private var tpeCache: Type = _; private var tpePhase: Phase = null; override def tpe: Type = { - assert(tpeCache != NoType, this); + assert(tpeCache ne NoType, this); if (tpePhase != phase) { if (isValid(tpePhase)) { tpePhase = phase @@ -805,12 +818,12 @@ abstract class Symbols: SymbolTable { thissym = this; } + private var flatname = nme.EMPTY; + override def owner: Symbol = if (phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass) rawowner.owner else rawowner; - private var flatname = nme.EMPTY; - override def name: Name = if (phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass) { if (flatname == nme.EMPTY) { @@ -875,7 +888,7 @@ abstract class Symbols: SymbolTable { /** An object repreesenting a missing symbol */ object NoSymbol extends Symbol(null, Position.NOPOS, nme.NOSYMBOL) { super.setInfo(NoType); - override def setInfo(info: Type): this.type = { assert(info == NoType); this } + override def setInfo(info: Type): this.type = { assert(info eq NoType); this } override def enclClass: Symbol = this; override def toplevelClass: Symbol = this; override def enclMethod: Symbol = this; diff --git a/sources/scala/tools/nsc/symtab/Types.scala b/sources/scala/tools/nsc/symtab/Types.scala index 366d9995b2..31126f8169 100755 --- a/sources/scala/tools/nsc/symtab/Types.scala +++ b/sources/scala/tools/nsc/symtab/Types.scala @@ -194,12 +194,12 @@ abstract class Types: SymbolTable { /** Is this type a subtype of that type? */ def <:<(that: Type): boolean = if (explainSwitch) explain("<", isSubType, this, that) - else this == that || isSubType(this, that); + else (this eq that) || isSubType(this, that); /** Is this type equivalent to that type? */ def =:=(that: Type): boolean = if (explainSwitch) explain("<", isSameType, this, that) - else this == that || isSameType(this, that); + else (this eq that) || isSameType(this, that); /** Does this type implement symbol `sym' with same or stronger type? */ def specializes(sym: Symbol): boolean = @@ -494,9 +494,6 @@ abstract class Types: SymbolTable { /** A common base class for intersection types and class types */ abstract class CompoundType extends Type { - override val parents: List[Type]; - override val decls: Scope; - assert(!parents.exists (.isInstanceOf[TypeBounds]), this);//debug private var closureCache: Array[Type] = _; @@ -519,7 +516,7 @@ abstract class Types: SymbolTable { val p = closurePhase; if (p != phase) { closurePhase = phase; - if (!isValid(p)) { + if (!isValidForBaseClasses(p)) { closureCache = null; closureCache = computeClosure } @@ -559,7 +556,7 @@ abstract class Types: SymbolTable { val p = baseClassesPhase; if (p != phase) { baseClassesPhase = phase; - if (!isValid(p)) { + if (!isValidForBaseClasses(p)) { baseClassesCache = null; baseClassesCache = computeBaseClasses; } @@ -639,7 +636,7 @@ abstract class Types: SymbolTable { val p = parentsPhase; if (p != phase) { parentsPhase = phase; - if (!isValid(p)) { + if (!isValidForBaseClasses(p)) { parentsCache = sym.info.parents map transform } } @@ -668,7 +665,7 @@ abstract class Types: SymbolTable { val p = closurePhase; if (p != phase) { closurePhase = phase; - if (!isValid(p)) { + if (!isValidForBaseClasses(p)) { typerefClosureCount = typerefClosureCount + 1; closureCache = if (sym.isAbstractType) addClosure(this, transform(bounds.hi).closure) @@ -770,7 +767,7 @@ abstract class Types: SymbolTable { case class TypeVar(origin: Type, constr: TypeConstraint) extends Type { override def symbol = origin.symbol; override def toString(): String = - if (constr.inst == NoType) "?" + origin else constr.inst.toString(); + if (constr.inst eq NoType) "?" + origin else constr.inst.toString(); } /** A class representing an as-yet unevaluated type. @@ -1114,17 +1111,17 @@ abstract class Types: SymbolTable { /** A map to compute the asSeenFrom method */ class AsSeenFromMap(pre: Type, clazz: Symbol) extends TypeMap { def apply(tp: Type): Type = - if (pre == NoType || pre == NoPrefix || !clazz.isClass) tp + if ((pre eq NoType) || (pre eq NoPrefix) || !clazz.isClass) tp else tp match { case ThisType(sym) => def toPrefix(pre: Type, clazz: Symbol): Type = - if (pre == NoType || pre == NoPrefix || !clazz.isClass) tp + if ((pre eq NoType) || (pre eq NoPrefix) || !clazz.isClass) tp else if ((sym isSubClass clazz) && (pre.widen.symbol isSubClass sym)) pre else toPrefix(pre.baseType(clazz).prefix, clazz.owner); toPrefix(pre, clazz) case TypeRef(prefix, sym, args) if (sym.isTypeParameter) => def toInstance(pre: Type, clazz: Symbol): Type = - if (pre == NoType || pre == NoPrefix || !clazz.isClass) tp + if ((pre eq NoType) || (pre eq NoPrefix) || !clazz.isClass) tp else { val symclazz = sym.owner; def throwError = @@ -1256,10 +1253,20 @@ abstract class Types: SymbolTable { // Helper Methods ------------------------------------------------------------- final def isValid(p: Phase): boolean = - p != null && - (if (phase.id > p.id) infoTransformers.nextFrom(p).phase.id >= phase.id - else infoTransformers.nextFrom(phase).phase.id >= p.id); + p != null && { + if (phase.id > p.id) infoTransformers.nextFrom(p).phase.id >= phase.id + else infoTransformers.nextFrom(phase).phase.id >= p.id + } + final def isValidForBaseClasses(p: Phase): boolean = { + def noChangeInBaseClasses(it: InfoTransformer, limit: Phase): boolean = + it.phase.id >= limit.id || + !it.changesBaseClasses && noChangeInBaseClasses(it.next, limit); + p != null && { + if (phase.id > p.id) noChangeInBaseClasses(infoTransformers.nextFrom(p), phase) + else noChangeInBaseClasses(infoTransformers.nextFrom(phase), p) + } + } /** Do tp1 and tp2 denote equivalent types? */ def isSameType(tp1: Type, tp2: Type): boolean = (tp1 eq tp2) || { diff --git a/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index a1da6db8fa..beb70991a5 100755 --- a/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -289,7 +289,7 @@ abstract class ClassfileParser { if (name == nme.CONSTRUCTOR) info match { case MethodType(formals, restpe) => - assert(restpe == definitions.UnitClass.tpe); + assert(restpe.symbol == definitions.UnitClass); info = MethodType(formals, clazz.tpe) } val sym = getOwner(jflags) |