summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2005-10-31 09:08:21 +0000
committerMartin Odersky <odersky@gmail.com>2005-10-31 09:08:21 +0000
commit56d62194cdc8e393397051a259ac22f84f69ff52 (patch)
treeb7a0d7be254f334ad9c461b6b882f35709f55a63
parent75971d2afe735c6a25f5ba4ae440c28ba9a0a77f (diff)
downloadscala-56d62194cdc8e393397051a259ac22f84f69ff52.tar.gz
scala-56d62194cdc8e393397051a259ac22f84f69ff52.tar.bz2
scala-56d62194cdc8e393397051a259ac22f84f69ff52.zip
*** empty log message ***
-rwxr-xr-xsources/scala/tools/nsc/Global.scala8
-rwxr-xr-xsources/scala/tools/nsc/symtab/SymbolLoaders.scala6
-rwxr-xr-xsources/scala/tools/nsc/symtab/classfile/UnPickler.scala18
-rwxr-xr-xsources/scala/tools/nsc/transform/ExplicitOuter.scala76
-rwxr-xr-xsources/scala/tools/nsc/transform/Mixin.scala12
-rwxr-xr-xsources/scala/tools/nsc/typechecker/Typers.scala33
6 files changed, 33 insertions, 120 deletions
diff --git a/sources/scala/tools/nsc/Global.scala b/sources/scala/tools/nsc/Global.scala
index 9e0631b96f..38d7032bce 100755
--- a/sources/scala/tools/nsc/Global.scala
+++ b/sources/scala/tools/nsc/Global.scala
@@ -176,6 +176,10 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
val global: Global.this.type = Global.this;
}
+ object superAccessors extends SuperAccessors {
+ val global: Global.this.type = Global.this
+ }
+
object pickler extends Pickler {
val global: Global.this.type = Global.this
}
@@ -248,8 +252,8 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
def phaseDescriptors: List[SubComponent] = List(
analyzer.namerFactory,
analyzer.typerFactory,
+ superAccessors,
pickler,
-// syntheticMethods,
refchecks,
uncurry,
tailCalls,
@@ -358,7 +362,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
} else {
for (val Pair(sym, file) <- symSource.elements) {
sym.reset(new loaders.SourcefileLoader(file));
- if (sym.isTerm) sym.moduleClass.reset(loaders.errorLoader);
+ if (sym.isTerm) sym.moduleClass.reset(loaders.moduleClassLoader);
}
}
informTime("total", startTime);
diff --git a/sources/scala/tools/nsc/symtab/SymbolLoaders.scala b/sources/scala/tools/nsc/symtab/SymbolLoaders.scala
index ba59532556..91914cf73e 100755
--- a/sources/scala/tools/nsc/symtab/SymbolLoaders.scala
+++ b/sources/scala/tools/nsc/symtab/SymbolLoaders.scala
@@ -95,7 +95,7 @@ abstract class SymbolLoaders {
val module = owner.newModule(Position.NOPOS, name);
clazz.setInfo(completer);
module.setInfo(completer);
- module.moduleClass.setInfo(errorLoader);
+ module.moduleClass.setInfo(moduleClassLoader);
owner.info.decls.enter(clazz);
owner.info.decls.enter(module);
assert(clazz.linkedModule == module, module);
@@ -173,9 +173,9 @@ abstract class SymbolLoaders {
protected def kindString: String = "source file";
}
- object errorLoader extends SymbolLoader(null) {
+ object moduleClassLoader extends SymbolLoader(null) {
protected def doComplete(root: Symbol): unit =
- throw new Error(" loading " + root + " without loading module first");
+ root.sourceModule.initialize;
protected def kindString: String = "";
}
}
diff --git a/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala b/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala
index 23a523f87b..7c3f231397 100755
--- a/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala
+++ b/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala
@@ -20,7 +20,7 @@ abstract class UnPickler {
} catch {
case ex: Throwable =>
ex.printStackTrace();//debug
- System.out.println("EX");//debug
+
throw new RuntimeException("error reading Scala signature of " + classRoot.nameString + ": " + ex.getMessage());
}
@@ -45,7 +45,21 @@ abstract class UnPickler {
/** Does entry represent an (internal) symbol */
private def isSymbolEntry(i: int): boolean = {
val tag = bytes(index(i));
- firstSymTag <= tag && tag <= lastSymTag
+ firstSymTag <= tag && tag <= lastSymTag &&
+ (tag != CLASSsym || !isRefinementSymbolEntry(i))
+ }
+
+ /** Does entry represent a refinement symbol?
+ * pre: Entry is a class symbol
+ */
+ private def isRefinementSymbolEntry(i: int): boolean = {
+ val savedIndex = readIndex;
+ readIndex = index(i);
+ assert(readByte() == CLASSsym);
+ readNat();
+ val result = readNameRef() == nme.REFINE_CLASS_NAME.toTypeName;
+ readIndex = savedIndex;
+ result
}
/** If entry at `i' is undefined, define it by performing operation `op' with
diff --git a/sources/scala/tools/nsc/transform/ExplicitOuter.scala b/sources/scala/tools/nsc/transform/ExplicitOuter.scala
index 58304cdb7b..0aaa923b67 100755
--- a/sources/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/sources/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -21,8 +21,6 @@ abstract class ExplicitOuter extends InfoTransform {
val phaseName: String = "explicitouter";
override def changesBaseClasses = false;
- final val needSuperAccessors = false;
-
protected def newTransformer(unit: CompilationUnit): Transformer =
new ExplicitOuterTransformer(unit);
@@ -138,47 +136,6 @@ abstract class ExplicitOuter extends InfoTransform {
class ExplicitOuterTransformer(unit: CompilationUnit) extends Transformer {
- /** A map that takes triples consisting of
- * - the class symbol that contains the accessor
- * - the symbol accessed by the accessor
- * - the mixin qualifier of the symbol
- * to super accessor symbols.
- * //todo: not clear whether we need to this for all super calls symbols, or just
- * protected ones (or all calls to protected from inner classes)?
- * (controled by switch `needSuperAccessors')
- */
- private val superAccessors = new HashMap[Triple[Symbol, Symbol, Name], Symbol];
-
- /** Generate a superclass accessor symbol and enter in `superAccessors' unless one
- * exists already.
- */
- def superAccessor(clazz: Symbol, accessed: Symbol, mix: Name): Symbol =
- superAccessors.get(Triple(clazz, accessed, mix)) match {
- case Some(accessor) =>
- accessor
- case None =>
- val accessor = makeSuperAccessor(clazz, accessed, mix);
- superAccessors(Triple(clazz, accessed, mix)) = accessor;
- accessor
- }
-
- /** Generate a superclass acessor symbol named `NAME$super$MIX' in class `class'
- * where NAME is the name of the accessed symbol `accessed'
- * and MIX is the mixin qualifier of the super call `mix'.
- * The method is initially `private'; will be widened later
- */
- def makeSuperAccessor(clazz: Symbol, accessed: Symbol, mix: Name): Symbol = {
- assert(accessed.isMethod);
- val accessorName = newTermName(
- accessed.name.toString() + "$super" +
- (if (mix == nme.EMPTY.toTypeName) "" else "$" + mix));
- val accessor = clazz.newMethod(clazz.pos, accessorName)
- setFlag PRIVATE
- setInfo clazz.tpe.memberType(accessed);
- clazz.info.decls enter accessor;
- accessor
- }
-
/** The first step performs the following transformations:
* 1. A class which is not an interface and is not static gets an outer link
* (@see outerDefs)
@@ -189,10 +146,6 @@ abstract class ExplicitOuter extends InfoTransform {
* 4. A constructor of a class with an outer link gets an outer parameter.
* 5. A reference C.this where C refers to an outer class is replaced by a selection
* this.$outer ... .$outer (@see outerPath)
- * 6. A reference C.super.M where C refers to an outer class and M is a term member of C
- * is replaced by a selection
- * this.$outer ... .$outer.M$super
- * where M$super is the super accessor symbol of M (@see superAccessor).
* 7. A call to a constructor Q.<init>(args) or Q.$init$(args) where Q != this and
* the constructor belongs to a non-static class is augmented by an outer argument.
* E.g. Q.<init>(args, OUTER) where OUTER is the qualifier corresponding to the
@@ -297,16 +250,6 @@ abstract class ExplicitOuter extends InfoTransform {
case This(qual) =>
if (sym == currentOwner.enclClass || (sym hasFlag MODULE) && sym.isStatic) tree
else atPos(tree.pos)(outerPath(outerValue, sym)); // (5)
- case Select(qual @ Super(_, mix), name) =>
- val qsym = qual.symbol;
- if (!needSuperAccessors || tree.symbol.isType || qsym == currentOwner.enclClass)
- tree
- else atPos(tree.pos) { // (6)
- val accessor = superAccessor(qsym, tree.symbol, mix);
- Select(if (qsym.isStatic) This(qsym)
- else outerPath(outerValue, qsym), accessor)
- setType accessor.tpe
- }
case Apply(sel @ Select(qual, name), args)
if ((name == nme.CONSTRUCTOR || name == nme.MIXIN_CONSTRUCTOR)
&& !sel.symbol.owner.isStatic) =>
@@ -325,8 +268,6 @@ abstract class ExplicitOuter extends InfoTransform {
}
/** The second step performs the following transformations:
- * 1. Add definitions of superaccessors to the members of a class
- * (@see makeSuperAccessorDefs)
* 2. Remove private modifiers from members M of mixins T. (@see makeNotPrivate)
* 3. Remove `private' modifier from class members M that are accessed from an inner class.
* 4. Remove `protected' modifier from class members M that are accessed
@@ -335,28 +276,11 @@ abstract class ExplicitOuter extends InfoTransform {
*/
private val secondTransformer = new Transformer {
- /** Add a definition for each super accessor in `clazz':
- * def NAME$super$MIX(args) = super[MIX].NAME(args)
- */
- def makeSuperAccessorDefs(clazz: Symbol, typer: analyzer.Typer): List[Tree] =
- (for (val Pair(Triple(owner, accessed, mix), accessor) <- superAccessors.elements;
- owner == clazz) yield
- typer.typed {
- atPos(clazz.pos) {
- DefDef(accessor, vparamss =>
- Apply(Select(Super(clazz, mix), accessed), vparamss.head map Ident))
- }
- }).toList;
-
/** The second-step transformation method */
override def transform(tree: Tree): Tree = {
val sym = tree.symbol;
val tree1 = super.transform(tree);
tree1 match {
- case Template(parents, stats) => // (1)
- val accessors = makeSuperAccessorDefs(sym.owner, typer.atOwner(tree1, currentOwner));
- if (accessors.isEmpty) tree1
- else copy.Template(tree1, parents, stats ::: accessors)
case DefDef(_, _, _, _, _, _) =>
if (sym.owner.isTrait && (sym hasFlag (ACCESSOR | SUPERACCESSOR)))
sym.makeNotPrivate(sym.owner);
diff --git a/sources/scala/tools/nsc/transform/Mixin.scala b/sources/scala/tools/nsc/transform/Mixin.scala
index 9f960a9d70..6bcaaa8b98 100755
--- a/sources/scala/tools/nsc/transform/Mixin.scala
+++ b/sources/scala/tools/nsc/transform/Mixin.scala
@@ -248,7 +248,6 @@ abstract class Mixin extends InfoTransform {
def completeSuperAccessor(stat: Tree) = stat match {
case DefDef(mods, name, tparams, List(vparams), tpt, EmptyTree)
if (stat.symbol hasFlag SUPERACCESSOR) =>
- assert(stat.symbol hasFlag MIXEDIN, stat);
val rhs0 =
Apply(Select(Super(clazz, nme.EMPTY.toTypeName), stat.symbol.alias),
vparams map (vparam => Ident(vparam.symbol)));
@@ -323,12 +322,15 @@ abstract class Mixin extends InfoTransform {
} else {
tree
}
+
case This(_) if tree.symbol.isImplClass =>
assert(tree.symbol == currentOwner.enclClass, "" + tree + " " + tree.symbol + " " + currentOwner.enclClass);
selfRef(tree.pos)
case Select(qual @ Super(_, mix), name) =>
if (currentOwner.enclClass.isImplClass) {
- if (mix == nme.EMPTY.toTypeName) {
+ if (mix == nme.EMPTY.toTypeName)
+ assert(false, "illegal super in mixin class: " + currentOwner.enclClass + " " + tree);
+/*
val superAccName = enclInterface.expandedName(nme.superName(sym.name));
val superAcc = enclInterface.info.decl(superAccName) suchThat (.alias.==(sym));
assert(superAcc != NoSymbol, tree);//debug
@@ -337,10 +339,8 @@ abstract class Mixin extends InfoTransform {
Select(selfRef(qual.pos), superAcc)
}
}
- } else {
- copy.Select(tree, selfRef(qual.pos), name)
- }
-
+*/
+ copy.Select(tree, selfRef(qual.pos), name)
} else {
if (mix == nme.EMPTY.toTypeName) tree
else copy.Select(tree, gen.This(currentOwner.enclClass) setPos qual.pos, name)
diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala
index f946cca77e..6a29c53241 100755
--- a/sources/scala/tools/nsc/typechecker/Typers.scala
+++ b/sources/scala/tools/nsc/typechecker/Typers.scala
@@ -260,29 +260,6 @@ import collection.mutable.HashMap;
} else tree
}
- class AddSuperAccessors(clazz: Symbol, accdefs: ListBuffer[Tree]) extends Traverser {
- override def traverse(tree: Tree) = tree match {
- case Select(Super(_, mix), _) =>
- if (tree.isTerm && mix == nme.EMPTY.toTypeName) {
- val supername = nme.superName(tree.symbol.name);
- if (clazz.info.decl(supername).suchThat(.alias.==(tree.symbol)) == NoSymbol) {
- if (settings.debug.value) log("add super acc " + tree.symbol + tree.symbol.locationString + " to " + clazz);//debug
- val superAcc =
- clazz.newMethod(tree.pos, supername)
- .setFlag(SUPERACCESSOR | PRIVATE)
- .setAlias(tree.symbol)
- .setInfo(clazz.thisType.memberType(tree.symbol));
- clazz.info.decls enter superAcc;
- accdefs += typed(DefDef(superAcc, vparamss => EmptyTree));
- }
- }
- case Template(_, _) =>
- ;
- case _ =>
- super.traverse(tree)
- }
- }
-
/** Perform the following adaptations of expression, pattern or type `tree' wrt to
* given mode `mode' and given prototype `pt':
* (0) Convert expressions with constant types to literals
@@ -585,14 +562,8 @@ import collection.mutable.HashMap;
// the following is necessary for templates generated later
new Namer(context.outer.make(templ, clazz, clazz.info.decls)).enterSyms(templ.body);
validateParentClasses(parents1, selfType);
- val body1 = templ.body flatMap addGetterSetter;
- var body2 = typedStats(body1, templ.symbol);
- if (clazz.isTrait && phase.id <= currentRun.typerPhase.id) {
- val superAccs = new ListBuffer[Tree];
- new AddSuperAccessors(clazz, superAccs).traverseTrees(body2);
- body2 = superAccs.toList ::: body2;
- }
- copy.Template(templ, parents1, body2) setType clazz.tpe
+ val body1 = typedStats(templ.body flatMap addGetterSetter, templ.symbol);
+ copy.Template(templ, parents1, body1) setType clazz.tpe
}
def typedValDef(vdef: ValDef): ValDef = {