Renamed the linkedFooOfBar methods in Symbol to be internally

consistent and in line with modern nomenclature.  No review.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@21067 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
extempore 2010-03-04 20:18:41 +00:00
parent 111359b28c
commit bf28cafac2
17 changed files with 59 additions and 73 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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: " +

View File

@ -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 + "$"))

View File

@ -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))
}

View File

@ -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

View File

@ -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)
}
/**

View File

@ -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
* (5) companionSymbol
*/
/** 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.
*/
/** 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)

View File

@ -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
}
}

View File

@ -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 _ =>
}

View File

@ -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()

View File

@ -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
}

View File

@ -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 =>

View File

@ -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)

View File

@ -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) {

View File

@ -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)
}
}

View File

@ -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