diff options
author | Martin Odersky <odersky@gmail.com> | 2005-09-23 15:23:06 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2005-09-23 15:23:06 +0000 |
commit | 7554cbeb65687e131d88b70c951bc8b285ed2f3d (patch) | |
tree | 25e3dd51ed671684b5bd2864988ce441c1d44da4 | |
parent | c7cf81fcb58232236948d50ee3a13c97bbfdc23c (diff) | |
download | scala-7554cbeb65687e131d88b70c951bc8b285ed2f3d.tar.gz scala-7554cbeb65687e131d88b70c951bc8b285ed2f3d.tar.bz2 scala-7554cbeb65687e131d88b70c951bc8b285ed2f3d.zip |
*** empty log message ***
-rw-r--r-- | sources/scala/tools/nsc/ast/TreePrinters.scala | 2 | ||||
-rw-r--r-- | sources/scala/tools/nsc/symtab/Flags.scala | 2 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/Symbols.scala | 24 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/Types.scala | 12 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/typechecker/Contexts.scala | 2 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/typechecker/RefChecks.scala | 20 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/typechecker/Typers.scala | 4 |
7 files changed, 31 insertions, 35 deletions
diff --git a/sources/scala/tools/nsc/ast/TreePrinters.scala b/sources/scala/tools/nsc/ast/TreePrinters.scala index 326b4e68f5..79af31e1e2 100644 --- a/sources/scala/tools/nsc/ast/TreePrinters.scala +++ b/sources/scala/tools/nsc/ast/TreePrinters.scala @@ -259,7 +259,7 @@ abstract class TreePrinters { def print(tree: Tree): unit = printRaw( - if (tree.isDef && tree.symbol != NoSymbol && tree.symbol.isInitialized) { + if (tree.isDef && tree.symbol != NoSymbol && !tree.symbol.hasFlag(INITIALIZED)) { tree match { case ClassDef(_, _, _, _, impl) => ClassDef(tree.symbol, impl) case ModuleDef(_, _, impl) => ModuleDef(tree.symbol, impl) diff --git a/sources/scala/tools/nsc/symtab/Flags.scala b/sources/scala/tools/nsc/symtab/Flags.scala index 4fc5330461..0cadf154a9 100644 --- a/sources/scala/tools/nsc/symtab/Flags.scala +++ b/sources/scala/tools/nsc/symtab/Flags.scala @@ -64,6 +64,7 @@ object Flags { final val TRANS_FLAG = 0x2000000000l; // transient flag guaranteed to be reset after each phase. final val INCONSTRUCTOR = TRANS_FLAG; // transient flag for analyzer + final val INITIALIZED = 0x4000000000l; // symbol's definition is complete final val LOCKED = 0x8000000000l; // temporary flag to catch cyclic dependencies final val InitialFlags = 0x000000FFFFFFFFFFl; // flags that are enabled from phase 1. @@ -123,6 +124,7 @@ object Flags { else if (flag == TRANS_FLAG) "<trans-flag>" else if (flag == MIXEDIN) "<mixedin>" else if (flag == EXPANDEDNAME) "<expandedname>" + else if (flag == INITIALIZED) "<initialized>" else if (flag == LOCKED) "<locked>" else if (flag == STATICMODULE) "<staticobject>" else if (flag == STATICMEMBER) "<staticmember>" diff --git a/sources/scala/tools/nsc/symtab/Symbols.scala b/sources/scala/tools/nsc/symtab/Symbols.scala index 162bff1d57..b8bcd3e7fe 100755 --- a/sources/scala/tools/nsc/symtab/Symbols.scala +++ b/sources/scala/tools/nsc/symtab/Symbols.scala @@ -28,7 +28,6 @@ abstract class Symbols: SymbolTable { private var rawflags: long = 0; var pos = initPos; val id = { ids = ids + 1; ids } - var validForRun: int = NoRun; def setPos(pos: int): this.type = { this.pos = pos; this } @@ -195,7 +194,7 @@ abstract class Symbols: SymbolTable { !owner.isPackageClass && owner.isLocalClass); /** Symbol was preloaded from package */ - final def isExternal: boolean = pos == Position.NOPOS/* || validForRun < currentRun - 1*/; + final def isExternal: boolean = pos == Position.NOPOS; /** A a member of class `base' is incomplete if (1) it is declared deferred or * (2) it is abstract override and its super symbol in `base' is nonexistent or inclomplete. @@ -205,9 +204,6 @@ abstract class Symbols: SymbolTable { (this hasFlag DEFERRED) || (this hasFlag ABSOVERRIDE) && isIncompleteIn(superSymbol(base)); - final def isInitialized: boolean = - validForRun == currentRun; - /** The variance of this symbol as an integer */ final def variance: int = if (hasFlag(COVARIANT)) 1 @@ -251,8 +247,8 @@ abstract class Symbols: SymbolTable { */ final def info: Type = { var cnt = 0; - while (validForRun != currentRun) { - //if (settings.debug.value) System.out.println("completing " + this + " in " + this.owner);//debug + while ((rawflags & INITIALIZED) == 0) { + //if (settings.debug.value) System.out.println("completing " + this + " in " + this.owner);//DEBUG assert(infos != null, this.name); val tp = infos.info; if ((rawflags & LOCKED) != 0) { @@ -264,7 +260,7 @@ abstract class Symbols: SymbolTable { try { phase = infos.start; tp.complete(this); - // if (settings.debug.value && (validForRun == currentRun) System.out.println("completed " + this/* + ":" + info*/);//DEBUG + // if (settings.debug.value && (rawflags & INITIALIZED) != 0) System.out.println("completed " + this/* + ":" + info*/);//DEBUG rawflags = rawflags & ~LOCKED } finally { phase = current @@ -284,11 +280,11 @@ abstract class Symbols: SymbolTable { limit = phase; if (info.isComplete) { rawflags = rawflags & ~LOCKED; - validForRun = currentRun } else { - rawflags = rawflags & ~LOCKED; - validForRun = NoRun + rawflags = rawflags | INITIALIZED & ~LOCKED; } + rawflags = if (info.isComplete) rawflags | INITIALIZED & ~LOCKED; + else rawflags & ~INITIALIZED & ~LOCKED; this } @@ -303,7 +299,7 @@ abstract class Symbols: SymbolTable { /** Return info without checking for initialization or completing */ final def rawInfo: Type = { if (limit.id < phase.id) { - if (validForRun == currentRun) { + if ((rawflags & INITIALIZED) != 0) { val current = phase; var itr = infoTransformers.nextFrom(limit); infoTransformers = itr; // caching optimization @@ -330,7 +326,7 @@ abstract class Symbols: SymbolTable { /** Initialize the symbol */ final def initialize: this.type = { - if (!isInitialized) info; + if ((rawflags & INITIALIZED) == 0) info; this } @@ -798,7 +794,7 @@ abstract class Symbols: SymbolTable { if (isValid(tpePhase)) { tpePhase = phase } else { - if (isInitialized) tpePhase = phase; + if (hasFlag(INITIALIZED)) tpePhase = phase; tpeCache = NoType; val targs = if (phase.erasedTypes && this != ArrayClass) List() else unsafeTypeParams map (.tpe); diff --git a/sources/scala/tools/nsc/symtab/Types.scala b/sources/scala/tools/nsc/symtab/Types.scala index 2e770d0565..23a68176ef 100755 --- a/sources/scala/tools/nsc/symtab/Types.scala +++ b/sources/scala/tools/nsc/symtab/Types.scala @@ -294,7 +294,7 @@ abstract class Types: SymbolTable { def isComplete: boolean = true; /** If this is a lazy type, assign a new type to `sym'. */ - def complete(sym: Symbol): unit = {}//sym.setInfo(rebindMap.apply(this)); + def complete(sym: Symbol): unit = {} /** If this is a symbol loader type, load and assign a new type to `sym'. */ def load(sym: Symbol): unit = {} @@ -831,7 +831,7 @@ abstract class Types: SymbolTable { /** Rebind symbol `sym' to an overriding member in type `pre' */ private def rebind(pre: Type, sym: Symbol): Symbol = { val owner = sym.owner; - if (owner.isClass && (owner != pre.symbol && !sym.isFinal || sym.validForRun != currentRun)) { + if (owner.isClass && owner != pre.symbol && !sym.isFinal) { val rebind = pre.nonPrivateMember(sym.name).suchThat(sym => sym.isType || sym.isStable); if (rebind == NoSymbol) sym else rebind } else sym @@ -1246,14 +1246,6 @@ abstract class Types: SymbolTable { result = result.owner; } } -/* - object rebindMap extends TypeMap { - def apply(tp: Type): Type = tp match { - case SingleType(pre, sym) => - val pre1 = apply(pre); - if (sym.validForRun != currentRun) - -*/ // Helper Methods ------------------------------------------------------------- diff --git a/sources/scala/tools/nsc/typechecker/Contexts.scala b/sources/scala/tools/nsc/typechecker/Contexts.scala index ed6450b067..d09ce315b9 100755 --- a/sources/scala/tools/nsc/typechecker/Contexts.scala +++ b/sources/scala/tools/nsc/typechecker/Contexts.scala @@ -216,7 +216,7 @@ abstract class Contexts: Analyzer { if (implicitsCache == null) { val newImplicits: List[ImplicitInfo] = if (owner != outer.owner && owner.isClass && !owner.isPackageClass) { - if (!owner.isInitialized) return outer.implicitss; + if (!owner.hasFlag(INITIALIZED)) return outer.implicitss; if (settings.debug.value) log("collect member implicits " + owner + ", implicit members = " + owner.thisType.implicitMembers);//debug collectImplicits(owner.thisType.implicitMembers, owner.thisType) } else if (scope != outer.scope && !owner.isPackageClass) { diff --git a/sources/scala/tools/nsc/typechecker/RefChecks.scala b/sources/scala/tools/nsc/typechecker/RefChecks.scala index 7f1652f581..bd2785fde6 100755 --- a/sources/scala/tools/nsc/typechecker/RefChecks.scala +++ b/sources/scala/tools/nsc/typechecker/RefChecks.scala @@ -65,21 +65,24 @@ abstract class RefChecks extends InfoTransform { // def m: T = { if (m$ == null) m$ = new m$class; m$ } def newModuleAccessDef(accessor: Symbol, mvar: Symbol) = { + var mvarRef = if (mvar.owner.isClass) Select(This(mvar.owner), mvar) else Ident(mvar); DefDef(accessor, vparamss => Block( List( If( - Apply(Select(Ident(mvar), nme.eq), List(Literal(Constant(null)))), - Assign(Ident(mvar), + Apply(Select(mvarRef, nme.eq), List(Literal(Constant(null)))), + Assign(mvarRef, New(TypeTree(mvar.tpe), List(for (val pt <- mvar.tpe.symbol.primaryConstructor.info.paramTypes) yield This(accessor.owner.enclClass)))),//??? EmptyTree)), - Ident(mvar))) + mvarRef)) } class RefCheckTransformer(unit: CompilationUnit) extends Transformer { + var localTyper: analyzer.Typer = typer; + // Override checking ------------------------------------------------------------ /** 1. Check all members of class `clazz' for overriding conditions. @@ -423,7 +426,6 @@ abstract class RefChecks extends InfoTransform { def transformStat(tree: Tree, index: int): List[Tree] = tree match { case ModuleDef(mods, name, impl) => val sym = tree.symbol; - val localTyper = typer.atOwner(currentOwner); val cdef = ClassDef(mods | MODULE, name, List(), EmptyTree, impl) setPos tree.pos setSymbol sym.moduleClass @@ -443,8 +445,8 @@ abstract class RefChecks extends InfoTransform { newModuleAccessDef(sym, vdef.symbol) } } - - transformTrees(List(cdef, vdef, ddef)) + if (sym.owner.isTrait) List(transform(cdef)) + else transformTrees(List(cdef, vdef, ddef)) } case ValDef(_, _, _, _) => @@ -480,6 +482,7 @@ abstract class RefChecks extends InfoTransform { case ex: TypeError => unit.error(tree.pos, ex.getMessage()); } + val savedLocalTyper = localTyper; val sym = tree.symbol; var result = tree; tree match { @@ -500,6 +503,7 @@ abstract class RefChecks extends InfoTransform { validateVariance(sym, sym.info, CoVariance); case Template(_, _) => + localTyper = localTyper.atOwner(tree, currentOwner); validateBaseTypes(currentOwner); checkAllOverrides(currentOwner); @@ -563,7 +567,9 @@ abstract class RefChecks extends InfoTransform { } case _ => } - super.transform(result) + result = super.transform(result); + localTyper = savedLocalTyper; + result } catch { case ex: TypeError => if (settings.debug.value) ex.printStackTrace(); diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala index b6b07e9ce9..da38fff387 100755 --- a/sources/scala/tools/nsc/typechecker/Typers.scala +++ b/sources/scala/tools/nsc/typechecker/Typers.scala @@ -488,7 +488,7 @@ abstract class Typers: Analyzer { } def addGetterSetter(stat: Tree): List[Tree] = stat match { - case ValDef(mods, name, tpe, rhs) if (mods & LOCAL) == 0 => + case ValDef(mods, name, tpe, rhs) if (mods & LOCAL) == 0 && !stat.symbol.isModuleVar => val vdef = copy.ValDef(stat, mods | PRIVATE | LOCAL, nme.getterToLocal(name), tpe, rhs); val value = vdef.symbol; val getterDef: DefDef = { @@ -1166,7 +1166,7 @@ abstract class Typers: Analyzer { val enclFun = if (tree.symbol != NoSymbol) tree.symbol else context.owner.enclMethod; if (!enclFun.isMethod || enclFun.isConstructor) errorTree(tree, "return outside method definition") - else if (!context.owner.isInitialized) + else if (!context.owner.hasFlag(INITIALIZED)) errorTree(tree, "method " + context.owner + " has return statement; needs result type") else { val expr1: Tree = typed(expr, enclFun.tpe.finalResultType); |