summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-08-25 09:09:32 +0000
committerpaltherr <paltherr@epfl.ch>2004-08-25 09:09:32 +0000
commitd53ff4ce6a696a3c08c9a2ac4e1ce45569e77312 (patch)
tree0939ea256873450464c4200b5e7d35966022b99f /sources
parentaf125e6f83269e670aa017c416a663434be630ce (diff)
downloadscala-d53ff4ce6a696a3c08c9a2ac4e1ce45569e77312.tar.gz
scala-d53ff4ce6a696a3c08c9a2ac4e1ce45569e77312.tar.bz2
scala-d53ff4ce6a696a3c08c9a2ac4e1ce45569e77312.zip
- Added code in Symbol to clone thisSyms
- Removed special case for thisSyms in AddInterfaces Changed - ExplicitOuter to handle compoundSyms differently from normal classes
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/symtab/Symbol.java54
-rw-r--r--sources/scalac/transformer/AddInterfacesPhase.java11
-rw-r--r--sources/scalac/transformer/ExplicitOuterClassesPhase.java19
3 files changed, 67 insertions, 17 deletions
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index a66fb5b2be..5325107000 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -2153,10 +2153,62 @@ public class ClassSymbol extends TypeSymbol {
protected final TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs) {
assert !isModuleClass(): Debug.show(this);
ClassSymbol clone = new ClassSymbol(owner, pos, flags, name, attrs);
- if (thisSym != this) clone.setTypeOfThis(typeOfThis());
+ if (thisSym != this) clone.setTypeOfThis(new ClonedThisSymLazyType());
return clone;
}
+ private final class ClonedThisSymLazyType extends Type.LazyType {
+
+ public Type fix(Type type, Symbol clasz, Symbol clone, Type.Map map) {
+ switch (type) {
+ case ThisType(_):
+ return type;
+ case SingleType(_, _):
+ return map.apply(type);
+ case TypeRef(Type prefix, Symbol symbol, Type[] args):
+ if (symbol == clasz) type = Type.typeRef(prefix, clone, args);
+ return map.apply(type);
+ default:
+ throw Debug.abortIllegalCase(type);
+ }
+ }
+
+ public Type getTypeFor(Symbol symbol) {
+ Symbol clasz = ClassSymbol.this;
+ Symbol clone = symbol.owner();
+ Type.Map map =
+ Type.getSubst(clasz.typeParams(), clone.typeParams());
+ Type type = clasz.typeOfThis();
+ Type self = clone.type();
+ switch (type) {
+ case CompoundType(Type[] parents1, Scope members):
+ assert members.isEmpty(): Debug.show(clasz, type);
+ int length = parents1.length;
+ Type[] parents2 = new Type[parents1.length];
+ for (int i = 0; i < parents2.length; i++) {
+ parents2[i] = fix(parents1[i], clasz, clone, map);
+ if (i != parents2.length - 1)
+ assert !self.isSubType(parents2[i]):
+ Debug.show(clasz, clone, type, ""+i, parents2[i]);
+ }
+ if (!self.isSubType(parents2[parents2.length - 1]))
+ parents2 = Type.cloneArray(parents2, 1);
+ parents2[parents2.length - 1] = self;
+ return Type.compoundTypeWithOwner(clone, parents2, members);
+ default:
+ type = fix(type, clasz, clone, map);
+ if (self.isSubType(type)) return self;
+ Type[] parents = new Type[]{type, self};
+ return Type.compoundTypeWithOwner(clone, parents, new Scope());
+ }
+ }
+
+ public void complete(Symbol symbol) {
+ symbol.setInfo(getTypeFor(symbol));
+ }
+
+ }
+
}
/**
diff --git a/sources/scalac/transformer/AddInterfacesPhase.java b/sources/scalac/transformer/AddInterfacesPhase.java
index 6cf968bfef..388510059d 100644
--- a/sources/scalac/transformer/AddInterfacesPhase.java
+++ b/sources/scalac/transformer/AddInterfacesPhase.java
@@ -97,17 +97,6 @@ public class AddInterfacesPhase extends Phase {
}
return Type.compoundType(newParents, newMembers, sym);
- } else if (sym.isThisSym() && hasInterfaceSymbol(sym.owner())) {
- switch (tp) {
- case TypeRef(_, _, _):
- return sym.owner().nextType();
- case CompoundType(Type[] parents, Scope members):
- parents = Type.cloneArray(parents);
- parents[parents.length - 1] = sym.owner().nextType();
- return Type.compoundTypeWithOwner(sym.owner(), parents, members);
- default:
- throw Debug.abort("illegal case", tp +" -- "+ Debug.show(sym));
- }
} else
return tp;
}
diff --git a/sources/scalac/transformer/ExplicitOuterClassesPhase.java b/sources/scalac/transformer/ExplicitOuterClassesPhase.java
index c79ff1ae29..9cb4837033 100644
--- a/sources/scalac/transformer/ExplicitOuterClassesPhase.java
+++ b/sources/scalac/transformer/ExplicitOuterClassesPhase.java
@@ -81,7 +81,7 @@ public class ExplicitOuterClassesPhase extends Phase {
if (show && !symbol.isPackageClass()) System.out.println("!!! <<< transformInfo - type : " + Debug.show(type));
if (symbol.isPackageClass()) return type; // !!!
TypeContext context = getTypeContextFor(symbol);
- if (symbol.isConstructor() && symbol.constructorClass().isClassType()) { // !!! isClassType -> isClass ?
+ if (symbol.isConstructor() && symbol.constructorClass().isClassType() && !symbol.constructorClass().isCompoundSym()) { // !!! isClassType -> isClass ?
Symbol clasz = symbol.constructorClass();
Symbol[] tparams = type.typeParams();
Symbol[] vparams = type.valueParams();
@@ -144,8 +144,16 @@ public class ExplicitOuterClassesPhase extends Phase {
/** Returns the type context for the given symbol. */
private TypeContext getTypeContextFor(Symbol symbol) {
- while (!symbol.isClassType() && !(symbol.isConstructor() && symbol.constructorClass().isClassType())) // !!! isClassType -> isClass ?
+ while (true) {
+ Symbol test = symbol;
+ if (test.isConstructor()) test = test.constructorClass();
+ // !!! isClassType -> isClass ?
+ if (test.isClassType() && !test.isCompoundSym()) break;
symbol = symbol.owner();
+ }
+// !!!
+// while (!symbol.isClassType() && !(symbol.isConstructor() && symbol.constructorClass().isClassType())) // !!! isClassType -> isClass ?
+// symbol = symbol.owner();
if (symbol.isClassType())
symbol = symbol.primaryConstructor();
TypeContext context = (TypeContext)contexts.get(symbol);
@@ -349,7 +357,7 @@ public class ExplicitOuterClassesPhase extends Phase {
Object value = tparams.get(symbol);
return value != null ? (Type)value : type;
}
- if (symbol.isClass()) {
+ if (symbol.isClass() && !symbol.isCompoundSym()) {
args = map(getNewArgsOf(context, prefix, symbol, args));
prefix = Type.NoPrefix;
return Type.typeRef(prefix, symbol, args);
@@ -363,11 +371,12 @@ public class ExplicitOuterClassesPhase extends Phase {
case SingleType(Type prefix, Symbol symbol):
return Type.singleType(apply(prefix), symbol);
case ThisType(Symbol clasz):
- if (clasz == context.clasz) return type;
+ // !!! || clasz.isCompoundSym()
+ if (clasz == context.clasz || clasz.isCompoundSym()) return type;
for (int i = 0; i < context.outers.length; i++)
if (clasz == context.outers[i].clasz)
return context.getTypeLink(i);
- throw Debug.abort("illegal ThisType", type);
+ throw Debug.abort("illegal ThisType", clasz);
case CompoundType(Type[] parents, Scope members):
// !!! this case should not be needed
return Type.compoundType(map(parents), members, type.symbol());