summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-09-07 16:43:26 +0000
committerpaltherr <paltherr@epfl.ch>2003-09-07 16:43:26 +0000
commitdcf7886f78daecbd684aca4ab6b2edb89023f1d7 (patch)
treed202ef8ee2eaa31f318d686b6cdc3b0e43551a70 /sources
parent97d8a84895c9fefeec108668d555f55eea665eb4 (diff)
downloadscala-dcf7886f78daecbd684aca4ab6b2edb89023f1d7.tar.gz
scala-dcf7886f78daecbd684aca4ab6b2edb89023f1d7.tar.bz2
scala-dcf7886f78daecbd684aca4ab6b2edb89023f1d7.zip
- Added class UpdateSubstTypeMap
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/symtab/Type.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java
index 38ae8d8613..5fa9d9e745 100644
--- a/sources/scalac/symtab/Type.java
+++ b/sources/scalac/symtab/Type.java
@@ -1191,6 +1191,47 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags {
}
}
+
+ /** A map for symbol/symbol substitutions which, instead of
+ * cloning parameters, updates their symbol's types.
+ */
+ public static class UpdateSubstSymMap extends SubstSymMap {
+ protected UpdateSubstSymMap(Symbol[] from, Symbol[] to) {
+ super(from, to);
+ }
+ public Type apply(Type t) {
+ switch (t) {
+ case PolyType(Symbol[] params, Type result):
+ // !!! Also update loBounds? How? loBound can only be set!
+ for (int i = 0; i < params.length; i++) {
+ Type tp = params[i].nextType();
+ Type tp1 = apply(tp);
+ if (tp != tp1) params[i].updateInfo(tp1);
+ }
+ Type result1 = apply(result);
+ if (result1 == result) return t;
+ else return Type.PolyType(params, result1);
+ case MethodType(Symbol[] params, Type result):
+ for (int i = 0; i < params.length; i++) {
+ Type tp = params[i].nextType();
+ Type tp1 = apply(tp);
+ if (tp != tp1) params[i].updateInfo(tp1);
+ }
+ Type result1 = apply(result);
+ if (result1 == result) return t;
+ else return Type.MethodType(params, result1);
+ default:
+ return super.apply(t);
+ }
+ }
+ }
+
+ /** Returns an updating substitution map for given arguments. */
+ public static Map getUpdateSubst(Symbol[] from, Symbol[] to) {
+ if (from.length == 0 && to.length == 0) return IdMap;
+ return new UpdateSubstSymMap(from, to);
+ }
+
/** Substitute symbols `to' for occurrences of symbols `from' in this type.
*/
public Type subst(Symbol[] from, Symbol[] to) {