summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-05-01 09:01:16 +0000
committerMartin Odersky <odersky@gmail.com>2003-05-01 09:01:16 +0000
commita5d85a9e9620699775e77ca0bfc4f1390e05229f (patch)
treebf493aa060133fb138dbc805b7ebf1ca7359fd7b /sources/scalac/symtab
parentd02f69f6023d73f6c6a956db5fbd9dd9dd7c91d2 (diff)
downloadscala-a5d85a9e9620699775e77ca0bfc4f1390e05229f.tar.gz
scala-a5d85a9e9620699775e77ca0bfc4f1390e05229f.tar.bz2
scala-a5d85a9e9620699775e77ca0bfc4f1390e05229f.zip
*** empty log message ***
Diffstat (limited to 'sources/scalac/symtab')
-rw-r--r--sources/scalac/symtab/Definitions.java4
-rw-r--r--sources/scalac/symtab/SymbolMapApplier.java3
-rw-r--r--sources/scalac/symtab/Type.java178
-rw-r--r--sources/scalac/symtab/classfile/AttributeParser.java9
4 files changed, 34 insertions, 160 deletions
diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java
index 5f2bf4735c..b2dc7ac8ae 100644
--- a/sources/scalac/symtab/Definitions.java
+++ b/sources/scalac/symtab/Definitions.java
@@ -424,7 +424,7 @@ public class Definitions {
public Type functionType(Type[] argtps, Type restp) {
Type[] argtps1 = new Type[argtps.length + 1];
System.arraycopy(argtps, 0, argtps1, 0, argtps.length);
- argtps1[argtps.length] = Type.covarType(restp);
+ argtps1[argtps.length] = restp;
return Type.appliedType(
getType(Name.fromString("scala.Function" + argtps.length)),
argtps1);
@@ -433,7 +433,7 @@ public class Definitions {
public Type partialFunctionType(Type argtpe, Type restpe) {
Type[] argtps1 = new Type[2];
argtps1[0] = argtpe;
- argtps1[1] = Type.covarType(restpe);
+ argtps1[1] = restpe;
return Type.appliedType(PARTIALFUNCTION_CLASS.typeConstructor(), argtps1);
}
diff --git a/sources/scalac/symtab/SymbolMapApplier.java b/sources/scalac/symtab/SymbolMapApplier.java
index b8f0b6978f..56d01ff9e6 100644
--- a/sources/scalac/symtab/SymbolMapApplier.java
+++ b/sources/scalac/symtab/SymbolMapApplier.java
@@ -71,9 +71,6 @@ public class SymbolMapApplier {
case OverloadedType(Symbol[] alts, Type[] alttypes):
return new Type.OverloadedType(apply(alts), apply(alttypes));
- case CovarType(Type result):
- return Type.CovarType(apply(result));
-
default:
throw new ApplicationError("unknown type " + type);
}
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java
index f61720c44d..ae0f830304 100644
--- a/sources/scalac/symtab/Type.java
+++ b/sources/scalac/symtab/Type.java
@@ -41,12 +41,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
public case PolyType(Symbol[] tparams, Type result);
public case OverloadedType(Symbol[] alts, Type[] alttypes);
- /** Type such as +T. Only used as type arguments.
- */
- public case CovarType(Type tp) {
- assert !(tp instanceof CovarType);
- }
-
/** Hidden case to implement delayed evaluation of types.
* No need to pattern match on this type; it will never come up.
*/
@@ -100,11 +94,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
}
}
- public static CovarType covarType(Type tp) {
- if (tp instanceof CovarType) return (CovarType)tp;
- else return CovarType(tp);
- }
-
public static CompoundType compoundType(Type[] parts, Scope members,
Symbol clazz) {
ExtCompoundType res = new ExtCompoundType(parts, members);
@@ -445,19 +434,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
return this;
}
- /** If this is a covariant type, its underlying type, otherwise the type itself.
- */
- public Type dropVariance() {
- switch (this) {
- case CovarType(Type tp): return tp;
- default: return this;
- }
- }
-
- public static Map dropVarianceMap = new Map() {
- public Type apply(Type t) { return t.dropVariance(); }
- };
-
// Tests --------------------------------------------------------------------
/** Is this type a this type or singleton type?
@@ -504,17 +480,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
}
}
- /** Is this type a covariant type?
- */
- public boolean isCovarType() {
- switch (this) {
- case CovarType(_):
- return true;
- default:
- return false;
- }
- }
-
/** Is this type of the form scala.FunctionN[T_1, ..., T_n, +T] or
* scala.Object with scala.FunctionN[T_1, ..., T_n, +T]?
*/
@@ -522,9 +487,7 @@ public class Type implements Modifiers, Kinds, TypeTags {
switch (this) {
case TypeRef(Type pre, Symbol sym, Type[] args):
if (sym.fullName().startsWith(Names.scala_Function)) {
- for (int i = 0; i < args.length - 1; i++)
- if (args[i].isCovarType()) return false;
- return args.length > 0; // !!! && args[args.length - 1].isCovarType();
+ return args.length > 0;
}
break;
case CompoundType(Type[] parents, Scope members):
@@ -626,8 +589,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
*/
public abstract static class Map {
- boolean covariantOK = true;
-
public abstract Type apply(Type t);
/** Apply map to all top-level components of this type.
@@ -677,16 +638,12 @@ public class Type implements Modifiers, Kinds, TypeTags {
}
case MethodType(Symbol[] vparams, Type result):
- covariantOK = false;
Symbol[] vparams1 = map(vparams);
- covariantOK = true;
Type result1 = apply(result);
if (vparams1 == vparams && result1 == result) return tp;
else return MethodType(vparams1, result1);
case PolyType(Symbol[] tparams, Type result):
- covariantOK = false;
Symbol[] tparams1 = map(tparams);
- covariantOK = true;
Type result1 = apply(result);
if (tparams1 != tparams) result1 = result1.subst(tparams, tparams1);
if (tparams1 == tparams && result1 == result) return tp;
@@ -695,10 +652,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
Type[] alttypes1 = map(alttypes);
if (alttypes1 == alttypes) return tp;
else return OverloadedType(alts, alttypes1);
- case CovarType(Type t):
- Type t1 = apply(t);
- if (t1 == t) return tp;
- else return covarType(t1);
case UnboxedArrayType(Type elemtp):
Type elemtp1 = apply(elemtp);
if (elemtp1 == elemtp) return tp;
@@ -831,8 +784,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
private Type pre;
private Symbol clazz;
- private Type illegalType = NoType;
- private boolean typeArg = false;
AsSeenFromMap(Type pre, Symbol clazz) {
this.pre = pre; this.clazz = clazz;
@@ -858,24 +809,13 @@ public class Type implements Modifiers, Kinds, TypeTags {
assert sym.kind == TYPE;
Type t1 = t.toInstance(pre, clazz);
//System.out.println(t + ".toInstance(" + pre + "," + clazz + ") = " + t1);//DEBUG
- switch (t1) {
- case CovarType(Type tp):
- if (!covariantOK) {
- if (illegalType == NoType) illegalType = t1;
- } else if (!typeArg) {
- t1 = tp;
- }
- }
return t1;
} else {
//Type prefix1 = prefix.toPrefix(pre, clazz);
Type prefix1 = apply(prefix);
Symbol sym1 = (prefix1 == prefix || (sym.flags & MODUL) != 0)
? sym : prefix1.rebind(sym);
- boolean prevTypeArg = typeArg;
- typeArg = true;
Type[] args1 = map(args);
- typeArg = prevTypeArg;
if (prefix1 == prefix && args1 == args) return t;
else return typeRef(prefix1, sym1, args1);
}
@@ -893,14 +833,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
return map(t);
}
}
-
- void checkLegal(Type tp) {
- if (illegalType != NoType) {
- throw new ApplicationError(
- "malformed type: " + tp + "; " +
- illegalType + " does not occur in covariant position");
- }
- }
}
//where
Type toInstance(Type pre, Symbol clazz) {
@@ -944,20 +876,13 @@ public class Type implements Modifiers, Kinds, TypeTags {
*/
public Type asSeenFrom(Type pre, Symbol clazz) {
//System.out.println("computing asseenfrom of " + this + " with " + pre + "," + clazz);//DEBUG
- AsSeenFromMap f = new AsSeenFromMap(pre, clazz);
- Type t = f.apply(this);
- f.checkLegal(t);
- return t;
+ return new AsSeenFromMap(pre, clazz).apply(this);
}
/** Types `these' as seen from prefix `pre' and class `clazz'.
*/
public static Type[] asSeenFrom(Type[] these, Type pre, Symbol clazz) {
- AsSeenFromMap f = new AsSeenFromMap(pre, clazz);
- Type[] these1 = f.map(these);
- for (int i = 0; i < these1.length; i++)
- f.checkLegal(these1[i]);
- return these1;
+ return new AsSeenFromMap(pre, clazz).map(these);
}
/** The info of `sym', seen as a member of this type.
@@ -1337,7 +1262,7 @@ public class Type implements Modifiers, Kinds, TypeTags {
//todo: should we test for equality with origin?
if (constr.inst != NoType) {
return this.isSubType(constr.inst);
- } else if (!this.isCovarType()) {
+ } else {
constr.lobounds = new List(this, constr.lobounds);
return true;
}
@@ -1358,8 +1283,7 @@ public class Type implements Modifiers, Kinds, TypeTags {
if (constr.inst != NoType) {
return constr.inst.isSubType(that);
} else {
- constr.hibounds = new List(that.dropVariance(), constr.hibounds);
- assert that.dropVariance().symbol() != Global.instance.definitions.ALL_CLASS;//debug
+ constr.hibounds = new List(that, constr.hibounds);
return true;
}
@@ -1412,23 +1336,12 @@ public class Type implements Modifiers, Kinds, TypeTags {
static boolean isSubArgs(Type[] these, Type[] those, Symbol[] tparams) {
if (these.length != those.length) return false;
for (int i = 0; i < these.length; i++) {
- switch (those[i]) {
- case CovarType(Type tp1):
- switch (these[i]) {
- case CovarType(Type tp):
- if (!tp.isSubType(tp1)) return false;
- break;
- default:
- if (!these[i].isSubType(tp1)) return false;
- }
- break;
- default:
- if (these[i].isCovarType()) return false;
- if ((tparams[i].flags & COVARIANT) != 0) {
- if (!these[i].isSubType(those[i])) return false;
- } else {
- if (!these[i].isSameAs(those[i])) return false;
- }
+ if ((tparams[i].flags & COVARIANT) != 0) {
+ if (!these[i].isSubType(those[i])) return false;
+ } else if ((tparams[i].flags & CONTRAVARIANT) != 0) {
+ if (!those[i].isSubType(these[i])) return false;
+ } else {
+ if (!these[i].isSameAs(those[i])) return false;
}
}
return true;
@@ -1539,7 +1452,7 @@ public class Type implements Modifiers, Kinds, TypeTags {
case TypeRef(Type pre, Symbol sym, Type[] args):
switch (that) {
case TypeRef(Type pre1, Symbol sym1, Type[] args1):
- if (sym == sym1 && pre.isSameAs(pre1) && isSameArgs(args, args1))
+ if (sym == sym1 && pre.isSameAs(pre1) && isSameAs(args, args1))
return true;
}
break;
@@ -1610,23 +1523,19 @@ public class Type implements Modifiers, Kinds, TypeTags {
case NoType:
return false;
case TypeVar(Type origin, Constraint constr):
- if (constr.inst != NoType)
- return constr.inst.isSameAs(this);
- else if (!this.isCovarType())
- return constr.instantiate(this.any2typevar());
+ if (constr.inst != NoType) return constr.inst.isSameAs(this);
+ else return constr.instantiate(this.any2typevar());
}
switch (this) {
case NoType:
return false;
- case TypeVar(Type origin, Constraint constr):
- if (constr.inst != NoType)
- return constr.inst.isSameAs(that);
- else if (!that.isCovarType())
- return constr.instantiate(that.any2typevar());
- break;
case TypeRef(_, Symbol sym, _):
if (sym.kind == ALIAS) return this.unalias().isSameAs(that);
+ break;
+ case TypeVar(Type origin, Constraint constr):
+ if (constr.inst != NoType) return constr.inst.isSameAs(that);
+ else return constr.instantiate(that.any2typevar());
}
switch (that) {
@@ -1637,19 +1546,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
return false;
}
- /** Is this type argument that same as `that'?
- */
- public boolean isSameArg(Type that) {
- switch (this) {
- case CovarType(Type tp):
- switch (that) {
- case CovarType(Type tp1):
- return tp.isSameAs(tp1);
- }
- }
- return this.isSameAs(that);
- }
-
/** Are types `these' the same as corresponding types `those'?
*/
public static boolean isSameAs(Type[] these, Type[] those) {
@@ -1660,16 +1556,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
return true;
}
- /** Are type arguments `these' the same as corresponding types `those'?
- */
- public static boolean isSameArgs(Type[] these, Type[] those) {
- if (these.length != those.length) return false;
- for (int i = 0; i < these.length; i++) {
- if (!these[i].isSameArg(those[i])) return false;
- }
- return true;
- }
-
/** Do scopes `s1' and `s2' define he same symbols with the same kinds and infos?
*/
public boolean isSameAs(Scope s1, Scope s2) {
@@ -1852,14 +1738,10 @@ public class Type implements Modifiers, Kinds, TypeTags {
}
}
for (int j = 0; j < args.length; j++) {
- if ((tparams[j].flags & COVARIANT) != 0) {
- args[j] = commonType(argss[j]);
- if (args[j] == NoType)
- args[j] = lub(argss[j]);
- } else { //todo: test if all same, return notype otherwise.
- args[j] = commonType(argss[j]);
- if (args[j] == NoType)
- args[j] = CovarType(lub(argss[j]));
+ args[j] = commonType(argss[j]);
+ if (args[j] == NoType) {
+ if ((tparams[j].flags & COVARIANT) != 0) args[j] = lub(argss[j]);
+ else return NoType;
}
}
return typeRef(pre, sym, args);
@@ -2139,8 +2021,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
case CompoundType(Type[] parents, _):
if (parents.length > 0) return parents[0].erasure();
else return this;
- case CovarType(Type tp):
- return tp.erasure(); // note: needed because of UnboxedArrayType
case MethodType(Symbol[] params, Type tp):
Symbol[] params1 = erasureMap.map(params);
Type tp1 = tp.fullErasure();
@@ -2198,7 +2078,7 @@ public class Type implements Modifiers, Kinds, TypeTags {
Type[] params = new Type[args.length - 1];
System.arraycopy(args, 0, params, 0, params.length);
return ArrayApply.toString(params, "(", ",", ") => ") +
- args[params.length].dropVariance();
+ args[params.length];
} else if (sym.isAnonymousClass()) {
return "<template: " +
ArrayApply.toString(
@@ -2245,8 +2125,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
case PolyType(Symbol[] tparams, Type result):
return ArrayApply.toString(Symbol.defString(tparams), "[", ",", "]") +
result;
- case CovarType(Type tp):
- return "+" + tp;
case OverloadedType(Symbol[] alts, Type[] alttypes):
return ArrayApply.toString(alttypes, "", " <and> ", "");
case TypeVar(Type origin, Constraint constr):
@@ -2344,9 +2222,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
return POLYtpe
^ (hashCode(tparams) * 41)
^ (result.hashCode() * (41 * 41));
- case CovarType(Type tp):
- return COVARtpe
- ^ (tp.hashCode() * (41));
case OverloadedType(Symbol[] alts, Type[] alttypes):
return OVERLOADEDtpe
^ (hashCode(alts) * 41)
@@ -2428,12 +2303,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
return equals(tparams, tparams1) && result.equals(result1);
default: return false;
}
- case CovarType(Type tp):
- switch (that) {
- case CovarType(Type tp1):
- return tp.equals(tp1);
- default: return false;
- }
case OverloadedType(Symbol[] alts, Type[] alttypes):
switch (that) {
case OverloadedType(Symbol[] alts1, Type[] alttypes1):
@@ -2559,6 +2428,5 @@ public class Type implements Modifiers, Kinds, TypeTags {
case MethodType(Symbol[] vparams, Type result):
case PolyType(Symbol[] tparams, Type result):
case OverloadedType(Symbol[] alts, Type[] alttypes):
- case CovarType(Type tp):
*/
diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java
index dba5daa3de..0d585bf836 100644
--- a/sources/scalac/symtab/classfile/AttributeParser.java
+++ b/sources/scalac/symtab/classfile/AttributeParser.java
@@ -232,10 +232,19 @@ public class AttributeParser implements ClassfileConstants {
Vector syms = new Vector();
do {
nextToken();
+ int vflag = 0;
+ if (token.equals("+")) {
+ nextToken();
+ vflag = Modifiers.COVARIANT;
+ } else if (token.equals("-")) {
+ nextToken();
+ vflag = Modifiers.CONTRAVARIANT;
+ }
assert token.startsWith("?");
Symbol s = getTVar(token);
if (s == Symbol.NONE)
return defaultType;
+ s.flags |= vflag;
nextToken();
//System.out.println("new var " + s + ", " + token);//DEBUG
if (token.equals("<")) {