diff options
author | Paul Phillips <paulp@improving.org> | 2010-03-04 20:18:41 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-03-04 20:18:41 +0000 |
commit | cb39da4caff8ff3c2f085d8913507cb205ae7f7b (patch) | |
tree | fbc02dc1d737fcd82eb4651bd370b2b8b43229ab /src | |
parent | f9c2792695a80e6a20414bc2008bc33bcb9d8cc9 (diff) | |
download | scala-cb39da4caff8ff3c2f085d8913507cb205ae7f7b.tar.gz scala-cb39da4caff8ff3c2f085d8913507cb205ae7f7b.tar.bz2 scala-cb39da4caff8ff3c2f085d8913507cb205ae7f7b.zip |
Renamed the linkedFooOfBar methods in Symbol to...
Renamed the linkedFooOfBar methods in Symbol to be internally consistent
and in line with modern nomenclature. No review.
Diffstat (limited to 'src')
17 files changed, 59 insertions, 73 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala b/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala index cf3be7c8cd..6df158c411 100644 --- a/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala +++ b/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala @@ -31,6 +31,6 @@ trait MSILPlatform extends Platform[MSILType] { genMSIL // generate .msil files ) - lazy val externalEquals = getMember(ComparatorClass.linkedModuleOfClass, nme.equals_) + lazy val externalEquals = getMember(ComparatorClass.companionModule, nme.equals_) def isMaybeBoxed(sym: Symbol) = sym isNonBottomSubClass BoxedNumberClass } diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index 0b5028980e..5929b45369 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -133,7 +133,7 @@ abstract class GenJVM extends SubComponent { pickledBytes = pickledBytes + pickle.writeIndex jclass.addAttribute(scalaAttr) currentRun.symData -= sym - currentRun.symData -= sym.linkedSym + currentRun.symData -= sym.companionSymbol //System.out.println("Generated ScalaSig Attr for " + sym)//debug case _ => val markerAttr = getMarkerAttr(jclass) @@ -205,7 +205,7 @@ abstract class GenJVM extends SubComponent { addStaticInit(jclass, c.lookupStaticCtor) if (isTopLevelModule(c.symbol)) { - if (c.symbol.linkedClassOfModule == NoSymbol) + if (c.symbol.companionClass == NoSymbol) dumpMirrorClass(c.symbol, c.cunit.source.toString); else log("No mirror class for module with linked class: " + @@ -221,7 +221,7 @@ abstract class GenJVM extends SubComponent { !(sym.name.toString contains '$') && (sym hasFlag Flags.MODULE) && !sym.isImplClass && !sym.isNestedClass } - val lmoc = c.symbol.linkedModuleOfClass + val lmoc = c.symbol.companionModule // add static forwarders if there are no name conflicts; see bugs #363 and #1735 if (lmoc != NoSymbol && !c.symbol.hasFlag(Flags.INTERFACE)) { if (isCandidateForForwarders(lmoc) && !settings.noForwarders.value) { @@ -830,7 +830,7 @@ abstract class GenJVM extends SubComponent { * for methods defined there - bug #1804 */ lazy val commonParents = { val cps = module.info.baseClasses - val mps = module.linkedClassOfModule.info.baseClasses + val mps = module.companionClass.info.baseClasses cps.filter(mps contains) } /* The setter doesn't show up in members so we inspect the name @@ -851,10 +851,10 @@ abstract class GenJVM extends SubComponent { && !m.isConstructor && !m.isStaticMember && !(m.owner == definitions.AnyClass) - && !module.isSubClass(module.linkedClassOfModule) + && !module.isSubClass(module.companionClass) && !conflictsIn(definitions.ObjectClass, m.name) && !conflictsInCommonParent(m.name) - && !conflictsIn(module.linkedClassOfModule, m.name) + && !conflictsIn(module.companionClass, m.name) ) assert(module.isModuleClass) diff --git a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala index c7b1fc1dd8..2bf4f51806 100644 --- a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala +++ b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala @@ -292,7 +292,7 @@ abstract class GenMSIL extends SubComponent { tBuilder.SetCustomAttribute(SYMTAB_ATTRIBUTE_CONSTRUCTOR, symtab) currentRun.symData -= sym - currentRun.symData -= sym.linkedSym + currentRun.symData -= sym.companionSymbol case _ => addMarker() @@ -513,7 +513,7 @@ abstract class GenMSIL extends SubComponent { tBuilder.setPosition(line, iclass.cunit.source.file.name) if (isTopLevelModule(sym)) { - if (sym.linkedClassOfModule == NoSymbol) + if (sym.companionClass == NoSymbol) dumpMirrorClass(sym) else log("No mirror class for module with linked class: " + diff --git a/src/compiler/scala/tools/nsc/dependencies/DependencyAnalysis.scala b/src/compiler/scala/tools/nsc/dependencies/DependencyAnalysis.scala index 11861d54fc..c84e608bb7 100644 --- a/src/compiler/scala/tools/nsc/dependencies/DependencyAnalysis.scala +++ b/src/compiler/scala/tools/nsc/dependencies/DependencyAnalysis.scala @@ -134,7 +134,7 @@ trait DependencyAnalysis extends SubComponent with Files { atPhase (currentRun.picklerPhase.next) { !s.isImplClass && !s.isNestedClass } - if (isTopLevelModule && (s.linkedModuleOfClass != NoSymbol)) { + if (isTopLevelModule && (s.companionModule != NoSymbol)) { dependencies.emits(source, nameToFile(unit.source.file, name)) } dependencies.emits(source, nameToFile(unit.source.file, name + "$")) diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala index 8a646d2288..44b542db0a 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala @@ -197,7 +197,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { extractor = val aliasTypes = members partialMap { case t: AliasType => t } override def isTemplate = true def isDocTemplate = true - def companion = sym.linkedSym match { + def companion = sym.companionSymbol match { case NoSymbol => None case comSym => Some(makeDocTemplate(comSym, inTpl)) } diff --git a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala index 28f4c06bf2..d3dddbfaaf 100644 --- a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala +++ b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala @@ -160,7 +160,7 @@ trait MatrixAdditions extends ast.TreeDSL def cmpSymbols(t1: Type, t2: Type) = t1.typeSymbol eq t2.typeSymbol def coversSym = { val tpe = decodedEqualsType(p.tpe) - lazy val lmoc = sym.linkedModuleOfClass + lazy val lmoc = sym.companionModule val symtpe = if ((sym hasFlag Flags.MODULE) && (lmoc ne NoSymbol)) singleType(sym.tpe.prefix, lmoc) // e.g. None, Nil diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala index a3751f0c48..d44c1ac514 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala @@ -64,7 +64,7 @@ abstract class SymbolLoaders { informTime("loaded " + description, start) ok = true setSource(root) - setSource(root.linkedSym) // module -> class, class -> module + setSource(root.companionSymbol) // module -> class, class -> module } catch { case ex: IOException => ok = false @@ -75,7 +75,7 @@ abstract class SymbolLoaders { else "error while loading " + root.name + ", " + msg); } initRoot(root) - if (!root.isPackageClass) initRoot(root.linkedSym) + if (!root.isPackageClass) initRoot(root.companionSymbol) } override def load(root: Symbol) { complete(root) } @@ -118,8 +118,8 @@ abstract class SymbolLoaders { module.moduleClass setInfo moduleClassLoader owner.info.decls enter clazz owner.info.decls enter module - assert(clazz.linkedModuleOfClass == module, module) - assert(module.linkedClassOfModule == clazz, clazz) + assert(clazz.companionModule == module, module) + assert(module.companionClass == clazz, clazz) } /** diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index f7075a4f72..021478a23d 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -384,7 +384,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => /** Term symbols with the exception of static parts of Java classes and packages * and the faux companion objects of primitives. (See tickets #1392 and #3123.) */ - final def isValue = isTerm && !(isModule && (hasFlag(PACKAGE | JAVA) || isValueClass(linkedClassOfModule))) + final def isValue = isTerm && !(isModule && (hasFlag(PACKAGE | JAVA) || isValueClass(companionClass))) final def isVariable = isTerm && hasFlag(MUTABLE) && !isMethod @@ -1175,7 +1175,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => && !packSym.isPackageClass) packSym = packSym.owner if (packSym != NoSymbol) - packSym = packSym.linkedModuleOfClass + packSym = packSym.companionModule packSym } @@ -1208,7 +1208,9 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => } /** @PP: Added diagram because every time I come through here I end up - * losing my train of thought. Any errors are mine. + * losing my train of thought. [Renaming occurs.] This diagram is a + * bit less necessary since the renaming, but leaving in place + * due to high artistic merit. * * class Foo < * ^ ^ (2) \ @@ -1218,30 +1220,17 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => * (1) v v \ * object Foo (4)-> > class Foo$ * - * (1) linkedClassOfModule - * (2) linkedModuleOfClass + * (1) companionClass + * (2) companionModule * (3) linkedClassOfClass * (4) moduleClass - * (5) linkedSym - */ - - /** I propose to rename these, as I at least would find it - * a lot less confusing to call them: - * - * def companionModule - * def companionClass - * def companionModuleClass - * def companionSymbol (bidirectional between companionModule + companionClass) - * def linkedClassOfClass (bidirectional between companionClass + companionModuleClass) - * - * linkedClassOfClass ceases to be confusing after in the context of - * the first four names. + * (5) companionSymbol */ /** The class with the same name in the same package as this module or - * case class factory. A better name would be companionClassOfModule. + * case class factory. */ - final def linkedClassOfModule: Symbol = { + final def companionClass: Symbol = { if (this != NoSymbol) flatOwnerInfo.decl(name.toTypeName).suchThat(_ isCoDefinedWith this) else NoSymbol @@ -1250,38 +1239,35 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => /** A helper method that factors the common code used the discover a companion module of a class. If a companion * module exists, its symbol is returned, otherwise, `NoSymbol` is returned. The method assumes that `this` * symbol has already been checked to be a class (using `isClass`). */ - private final def linkedModuleOfClass0: Symbol = + private final def companionModule0: Symbol = flatOwnerInfo.decl(name.toTermName).suchThat( sym => (sym hasFlag MODULE) && (sym isCoDefinedWith this)) /** The module or case class factory with the same name in the same - * package as this class. A better name would be companionModuleOfClass. + * package as this class. */ - final def linkedModuleOfClass: Symbol = + final def companionModule: Symbol = if (this.isClass && !this.isAnonymousClass && !this.isRefinementClass) - linkedModuleOfClass0 + companionModule0 else NoSymbol /** For a module its linked class, for a class its linked module or case * factory otherwise. */ - final def linkedSym: Symbol = - if (isTerm) linkedClassOfModule + final def companionSymbol: Symbol = + if (isTerm) companionClass else if (isClass) - linkedModuleOfClass0 + companionModule0 else NoSymbol - /** For a module class its linked class, for a plain class - * the module class of its linked module. - * For instance: - * object Foo - * class Foo + /** For a module class: its linked class + * For a plain class: the module class of its linked module. * * Then object Foo has a `moduleClass' (invisible to the user, the backend calls it Foo$ * linkedClassOfClass goes from class Foo$ to class Foo, and back. */ final def linkedClassOfClass: Symbol = - if (isModuleClass) linkedClassOfModule else linkedModuleOfClass.moduleClass + if (isModuleClass) companionClass else companionModule.moduleClass /** * Returns the rawInfo of the owner. If the current phase has flat classes, it first @@ -1991,7 +1977,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => } override def sourceModule = - if (isModuleClass) linkedModuleOfClass else NoSymbol + if (isModuleClass) companionModule else NoSymbol private var childSet: Set[Symbol] = Set() override def children: List[Symbol] = childSet.toList sortBy (_.sealedSortName) diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index edf81a97ad..6412efd8a2 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -83,11 +83,11 @@ abstract class ClassfileParser { */ this.in = new AbstractFileReader(file) if (root.isModule) { - this.clazz = root.linkedClassOfModule + this.clazz = root.companionClass this.staticModule = root } else { this.clazz = root - this.staticModule = root.linkedModuleOfClass + this.staticModule = root.companionModule } this.isScala = false this.hasMeta = false @@ -842,7 +842,7 @@ abstract class ClassfileParser { case ENUM_TAG => val t = pool.getType(index) val n = pool.getName(in.nextChar) - val s = t.typeSymbol.linkedModuleOfClass.info.decls.lookup(n) + val s = t.typeSymbol.companionModule.info.decls.lookup(n) assert(s != NoSymbol, t) Some(LiteralAnnotArg(Constant(s))) case ARRAY_TAG => @@ -1041,7 +1041,7 @@ abstract class ClassfileParser { def getMember(sym: Symbol, name: Name): Symbol = if (static) if (sym == clazz) staticDefs.lookup(name) - else sym.linkedModuleOfClass.info.member(name) + else sym.companionModule.info.member(name) else if (sym == clazz) instanceDefs.lookup(name) else sym.info.member(name) @@ -1059,13 +1059,13 @@ abstract class ClassfileParser { atPhase(currentRun.typerPhase)(getMember(sym, innerName.toTypeName)) else getMember(sym, innerName.toTypeName) - assert(s ne NoSymbol, sym + "." + innerName + " linkedModule: " + sym.linkedModuleOfClass + sym.linkedModuleOfClass.info.members) + assert(s ne NoSymbol, sym + "." + innerName + " linkedModule: " + sym.companionModule + sym.companionModule.info.members) s case None => val cls = classNameToSymbol(externalName) cls - //if (static) cls.linkedClassOfModule else cls + //if (static) cls.companionClass else cls } } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala index ba45165d52..09756d0ef1 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala @@ -51,7 +51,7 @@ abstract class Pickler extends SubComponent { val sym = tree.symbol val pickle = new Pickle(sym, sym.name.toTermName, sym.owner) add(sym, pickle) - add(sym.linkedSym, pickle) + add(sym.companionSymbol, pickle) pickle.finish case _ => } diff --git a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala index 92ff741b20..4d9c0ffc92 100644 --- a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala @@ -50,11 +50,11 @@ abstract class TypeParser { busy = true if (root.isModule) { - this.clazz = root.linkedClassOfModule + this.clazz = root.companionClass this.staticModule = root } else { this.clazz = root - this.staticModule = root.linkedModuleOfClass + this.staticModule = root.companionModule } try { parseClass(typ) @@ -119,8 +119,8 @@ abstract class TypeParser { staticDefs.enter(nclazz) staticDefs.enter(nmodule) - assert(nclazz.linkedModuleOfClass == nmodule, nmodule) - assert(nmodule.linkedClassOfModule == nclazz, nclazz) + assert(nclazz.companionModule == nmodule, nmodule) + assert(nmodule.companionClass == nclazz, nclazz) } val fields = typ.getFields() diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 614879b137..e6c6d8a4a3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -332,7 +332,7 @@ trait Contexts { self: Analyzer => var c = this.enclClass while (c != NoContext && !clazz.isNonBottomSubClass(c.owner) && - !(c.owner.isModuleClass && clazz.isNonBottomSubClass(c.owner.linkedClassOfModule))) + !(c.owner.isModuleClass && clazz.isNonBottomSubClass(c.owner.companionClass))) c = c.outer.enclClass c } diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index adafcb2617..bc9c52072f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -728,7 +728,7 @@ self: Analyzer => val buf = new ListBuffer[List[ImplicitInfo]] for ((clazz, pre) <- partMap) { if (pre != NoType) { - val companion = clazz.linkedModuleOfClass + val companion = clazz.companionModule companion.moduleClass match { case mc: ModuleClassSymbol => buf += (mc.implicitMembers map (im => diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 3883031d08..bd0dc448fb 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -90,10 +90,10 @@ trait Namers { self: Analyzer => if (sym.isModule && sym.moduleClass != NoSymbol) updatePosFlags(sym.moduleClass, pos, moduleClassFlags(flags)) if (sym.owner.isPackageClass && - (sym.linkedSym.rawInfo.isInstanceOf[loaders.SymbolLoader] || - sym.linkedSym.rawInfo.isComplete && runId(sym.validTo) != currentRunId)) + (sym.companionSymbol.rawInfo.isInstanceOf[loaders.SymbolLoader] || + sym.companionSymbol.rawInfo.isComplete && runId(sym.validTo) != currentRunId)) // pre-set linked symbol to NoType, in case it is not loaded together with this symbol. - sym.linkedSym.setInfo(NoType) + sym.companionSymbol.setInfo(NoType) sym } @@ -726,7 +726,7 @@ trait Namers { self: Analyzer => // add the copy method to case classes; this needs to be done here, not in SyntheticMethods, because // the namer phase must traverse this copy method to create default getters for its parameters. - Namers.this.caseClassOfModuleClass get clazz.linkedModuleOfClass.moduleClass match { + Namers.this.caseClassOfModuleClass get clazz.companionModule.moduleClass match { case Some(cdef) => def hasCopy(decls: Scope) = { decls.iterator exists (_.name == nme.copy) @@ -983,7 +983,7 @@ trait Namers { self: Analyzer => val parentNamer = if (isConstr) { val (cdef, nmr) = moduleNamer.getOrElse { - val module = meth.owner.linkedModuleOfClass + val module = meth.owner.companionModule module.initialize // call type completer (typedTemplate), adds the // module's templateNamer to classAndNamerOfModule val (cdef, nmr) = classAndNamerOfModule(module) diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index 273e8b1d97..3978ea263b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -179,7 +179,7 @@ trait NamesDefaults { self: Analyzer => } def moduleQual(pos: Position, tree: Symbol => Tree) = { - val module = baseFun.symbol.owner.linkedModuleOfClass + val module = baseFun.symbol.owner.companionModule if (module == NoSymbol) None else Some(atPos(pos.focus)(tree(module))) } @@ -373,7 +373,7 @@ trait NamesDefaults { self: Analyzer => if (i > 0) { if (param.owner.isConstructor) { val defGetterName = "init$default$"+ i - param.owner.owner.linkedModuleOfClass.info.member(defGetterName) + param.owner.owner.companionModule.info.member(defGetterName) } else { val defGetterName = param.owner.name +"$default$"+ i if (param.owner.owner.isClass) { diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 252b1571a4..95c79eb97e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -71,7 +71,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT other = linked.info.decl(sym.name.toTermName).filter(_.isModule) if (other != NoSymbol) unit.error(sym.pos, "name clash: "+sym.owner+" defines "+sym+ - "\nand its companion "+sym.owner.linkedModuleOfClass+" also defines "+ + "\nand its companion "+sym.owner.companionModule+" also defines "+ other) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1554566bac..b0afda02f1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1326,7 +1326,7 @@ trait Typers { self: Analyzer => // attributes(mdef) // initialize all constructors of the linked class: the type completer (Namer.methodSig) // might add default getters to this object. example: "object T; class T(x: Int = 1)" - val linkedClass = mdef.symbol.linkedClassOfModule + val linkedClass = mdef.symbol.companionClass if (linkedClass != NoSymbol) for (c <- linkedClass.info.decl(nme.CONSTRUCTOR).alternatives) c.initialize |