summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-10-02 11:03:51 +0000
committerpaltherr <paltherr@epfl.ch>2003-10-02 11:03:51 +0000
commit57a845d6766e58396184af3897915db42dfb6f6f (patch)
tree01b5f567bf59c37fd507224052413e1fb0e42dfc /sources
parent7449ae53ec7afbc0dcfa7210182a36f93d644f3a (diff)
downloadscala-57a845d6766e58396184af3897915db42dfb6f6f.tar.gz
scala-57a845d6766e58396184af3897915db42dfb6f6f.tar.bz2
scala-57a845d6766e58396184af3897915db42dfb6f6f.zip
- Added a constructor to AbsTypeSymbols
- Changed ExplicitOuter to replace all TypeRefs prefixes by - localThisTypes. Adapted ExpandMixins and Type to the new TypeRefs
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/symtab/Symbol.java21
-rw-r--r--sources/scalac/symtab/Type.java16
-rw-r--r--sources/scalac/transformer/ExpandMixins.java7
-rw-r--r--sources/scalac/transformer/ExplicitOuterClassesPhase.java22
4 files changed, 35 insertions, 31 deletions
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index cc070c24af..6fa6a0db04 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -1358,8 +1358,7 @@ public abstract class TypeSymbol extends Symbol {
public TypeSymbol(int kind, int pos, Name name, Symbol owner, int flags) {
super(kind, pos, name, owner, flags);
assert name.isTypeName() : this;
- if (kind != TYPE)
- this.constructor = TermSymbol.newConstructor(this, flags & ~MODUL);
+ this.constructor = TermSymbol.newConstructor(this, flags & ~MODUL);
}
protected void update(int pos, int flags) {
@@ -1371,12 +1370,10 @@ public abstract class TypeSymbol extends Symbol {
*/
public void copyTo(Symbol sym) {
super.copyTo(sym);
- if (kind != TYPE) {
- Symbol symconstr = ((TypeSymbol) sym).constructor;
- constructor.copyTo(symconstr);
- if (constructor.isInitialized())
- symconstr.setInfo(fixConstrType(symconstr.type(), sym));
- }
+ Symbol symconstr = ((TypeSymbol) sym).constructor;
+ constructor.copyTo(symconstr);
+ if (constructor.isInitialized())
+ symconstr.setInfo(fixConstrType(symconstr.type(), sym));
}
protected void copyConstructorInfo(TypeSymbol other) {
@@ -1423,18 +1420,17 @@ public abstract class TypeSymbol extends Symbol {
/** Get primary constructor */
public Symbol primaryConstructor() {
- return (kind == TYPE) ? Symbol.NONE : constructor.firstAlternative();
+ return constructor.firstAlternative();
}
/** Get all constructors */
public Symbol allConstructors() {
- return (kind == TYPE) ? Symbol.NONE : constructor;
+ return constructor;
}
/** Get type parameters */
public Symbol[] typeParams() {
- return (kind == TYPE) ? Symbol.EMPTY_ARRAY
- : primaryConstructor().info().typeParams();
+ return primaryConstructor().info().typeParams();
}
/** Get value parameters */
@@ -1611,6 +1607,7 @@ public class AbsTypeSymbol extends TypeSymbol {
/** Constructor */
public AbsTypeSymbol(int pos, Name name, Symbol owner, int flags) {
super(TYPE, pos, name, owner, flags);
+ allConstructors().setType(Type.MethodType(EMPTY_ARRAY, thisType()));
}
public static AbsTypeSymbol define(
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java
index bb4a63f7ce..8be3dcd00a 100644
--- a/sources/scalac/symtab/Type.java
+++ b/sources/scalac/symtab/Type.java
@@ -1011,11 +1011,14 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags {
*/
static class AsSeenFromMap extends Map {
- private Type pre;
- private Symbol clazz;
+ private final Type pre;
+ private final Symbol clazz;
+ private final boolean local;
AsSeenFromMap(Type pre, Symbol clazz) {
this.pre = pre; this.clazz = clazz;
+ Global global = Global.instance;
+ this.local =global.PHASE.EXPLICITOUTER.id()<global.currentPhase.id;
}
public Type apply(Type t) {
@@ -1036,12 +1039,13 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags {
//System.out.println(t + ".toInstance(" + pre + "," + clazz + ") = " + t1);//DEBUG
return t1;
} else {
+ if (local) prefix = sym.owner().thisType();
Type prefix1 = apply(prefix);
- Symbol sym1 = (prefix1 == prefix || (sym.flags & MODUL) != 0)
- ? sym : prefix1.rebind(sym);
Type[] args1 = map(args);
if (prefix1 == prefix && args1 == args) return t;
- else return typeRef(prefix1, sym1, args1);
+ Symbol sym1 = (sym.flags & MODUL) == 0 ? prefix1.rebind(sym) : sym;
+ if (local) prefix1 = localThisType;
+ return typeRef(prefix1, sym1, args1);
}
case SingleType(Type prefix, Symbol sym):
@@ -1086,7 +1090,7 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags {
Type toPrefix(Symbol sym, Type pre, Symbol clazz) {
if (pre == NoType || clazz.kind != CLASS)
return this;
- else if (sym.isSubClass(clazz) &&
+ else if ((sym.isSubClass(clazz) || clazz.isSubClass(sym)) &&
pre.widen().symbol().isSubClass(sym))
return pre;
else
diff --git a/sources/scalac/transformer/ExpandMixins.java b/sources/scalac/transformer/ExpandMixins.java
index a907743ff2..fcd173c9eb 100644
--- a/sources/scalac/transformer/ExpandMixins.java
+++ b/sources/scalac/transformer/ExpandMixins.java
@@ -140,9 +140,6 @@ public class ClassExpander {
switch (type) {
case TypeRef(Type prefix, Symbol symbol, Type[] args):
map.insertType(symbol.typeParams(), args);
- // !!! symbols could be equal but args different? need to rebind ?
- if (prefix.symbol() != symbol.owner())
- inlineMixinTParams(prefix.baseType(symbol.owner()));
return;
default:
throw Debug.abort("illegal case", type);
@@ -183,6 +180,10 @@ public class ClassExpander {
for (SymbolIterator i = symbols.iterator(true); i.hasNext();) {
Symbol member = i.next();
if (member.kind != scalac.symtab.Kinds.TYPE) continue;
+ // !!! use same trick as in erasure?
+ //Symbol clone = member.cloneSymbol(clasz);
+ //clone.setInfo(clasz.thisType().memberInfo(member));
+ //Symbol subst = clasz.thisType().memberType(clone).symbol();
Symbol subst = clasz.thisType().memberType(member).symbol();
if (subst == member) continue;
Symbol subst1 = map.lookupSymbol(member);
diff --git a/sources/scalac/transformer/ExplicitOuterClassesPhase.java b/sources/scalac/transformer/ExplicitOuterClassesPhase.java
index 011904cf77..4efb1dced7 100644
--- a/sources/scalac/transformer/ExplicitOuterClassesPhase.java
+++ b/sources/scalac/transformer/ExplicitOuterClassesPhase.java
@@ -33,12 +33,14 @@ import scalac.util.Names;
* - In every nested class, adds to each of its constructor a new
* value parameter that contains a link to the outer class.
*
- * - In every nested class, adds to each of its constructor a new type
- * parameter for every type parameter appearing in outer classes.
+ * - In every nested type, adds to each of its constructor a new type
+ * parameter for every type parameter appearing in outer types.
*
* - In every class, adds a forwarding "super" method for every method
* that is accessed via "super" in a nested class.
*
+ * - Replaces all prefixes of TypeRefs by localThisTypes.
+ *
* - Adds all missing qualifiers.
*/
public class ExplicitOuterClassesPhase extends Phase {
@@ -91,7 +93,7 @@ public class ExplicitOuterClassesPhase extends Phase {
: symbol.enclClass();
//System.out.println("!!! debug2 = " + Debug.show(symbol) + " - " + Debug.show(owner) + " --- " + (owner == Symbol.NONE) + " -- #" + owner.name + "#");
//if (onwer.isJava() && owner != Symbol.NONE && owner.name.length() > 0) // !!!
- if (owner.isClass() || owner.isConstructor())
+ if (owner.isType() || owner.isConstructor())
type = getOuterTypeSubst(owner, true).apply(type);
}
@@ -121,9 +123,9 @@ public class ExplicitOuterClassesPhase extends Phase {
//########################################################################
// Private Methods - Outer class
- /** Returns the outer class of the given class or constructor. */
+ /** Returns the outer class of the given type or constructor. */
private Symbol getOuterClass(Symbol symbol) {
- assert symbol.isClass() || symbol.isConstructor(): Debug.show(symbol);
+ assert symbol.isType() || symbol.isConstructor(): Debug.show(symbol);
return symbol.owner();
}
@@ -140,12 +142,12 @@ public class ExplicitOuterClassesPhase extends Phase {
return nextValueParams(symbol)[0];
}
- /** Has the given class or constructor outer type links? */
+ /** Has the given type or constructor outer type links? */
private boolean hasOuterTypeLinks(Symbol symbol) {
- assert symbol.isClass() || symbol.isConstructor(): Debug.show(symbol);
+ assert symbol.isType() || symbol.isConstructor(): Debug.show(symbol);
if (symbol.isJava()) return false;
Symbol outer = getOuterClass(symbol);
- return outer.isClass() && nextTypeParams(outer).length != 0;
+ return outer.isType() && nextTypeParams(outer).length != 0;
}
/** Returns the type substitution for the given class or constructor. */
@@ -212,11 +214,11 @@ public class ExplicitOuterClassesPhase extends Phase {
public Type apply(Type type) {
switch (type) {
case TypeRef(Type prefix, Symbol symbol, Type[] targs):
- if (!symbol.isClass()) break;
+ if (!symbol.owner().isType()) break;
prefix = apply(prefix);
targs = map(targs);
targs = Type.concat(getOuterTypeArgs(prefix, symbol), targs);
- return Type.TypeRef(prefix, symbol, targs);
+ return Type.TypeRef(Type.localThisType, symbol, targs);
}
return map(type);
}