summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab/SymbolCloner.java
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-03-02 09:12:42 +0000
committerpaltherr <paltherr@epfl.ch>2004-03-02 09:12:42 +0000
commit5c4179270fe4469a502a6f9050ccd7c54270f552 (patch)
treea878efb4c47a5f56b6aaeb378ae1b9d0a173a3a3 /sources/scalac/symtab/SymbolCloner.java
parentebd6149d9cc1edbd0a23873cb9fa7ec97bad7e56 (diff)
downloadscala-5c4179270fe4469a502a6f9050ccd7c54270f552.tar.gz
scala-5c4179270fe4469a502a6f9050ccd7c54270f552.tar.bz2
scala-5c4179270fe4469a502a6f9050ccd7c54270f552.zip
- Added type cloning in SymbolCloner
- Changed Type.cloneType to use a SymbolCloner
Diffstat (limited to 'sources/scalac/symtab/SymbolCloner.java')
-rw-r--r--sources/scalac/symtab/SymbolCloner.java115
1 files changed, 98 insertions, 17 deletions
diff --git a/sources/scalac/symtab/SymbolCloner.java b/sources/scalac/symtab/SymbolCloner.java
index 01674923ef..4ccca73d33 100644
--- a/sources/scalac/symtab/SymbolCloner.java
+++ b/sources/scalac/symtab/SymbolCloner.java
@@ -66,42 +66,123 @@ public class SymbolCloner {
return (Symbol)newowner;
}
- /** Clones the given symbol. */
- public Symbol cloneSymbol(Symbol symbol) {
- assert !symbol.isPrimaryConstructor() : Debug.show(symbol);
- assert !symbol.isClassType() : Debug.show(symbol);
- assert !symbol.isModule() : Debug.show(symbol);
- assert !owners.containsKey(symbol) : Debug.show(symbol);
- assert !clones.containsKey(symbol) :
+ /** Clones the given symbol but not its type. */
+ public Symbol cloneSymbolWithoutType(Symbol symbol) {
+ assert !symbol.isPrimaryConstructor(): Debug.show(symbol);
+ assert !symbol.isClassType() || symbol.isCompoundSym(): Debug.show(symbol); // !!! isCompoundSym()
+ assert !symbol.isModule(): Debug.show(symbol);
+ assert !owners.containsKey(symbol): Debug.show(symbol);
+ assert !clones.containsKey(symbol):
Debug.show(symbol) + " -> " + Debug.show(clones.get(symbol));
Symbol clone = symbol.cloneSymbol(getOwnerFor(symbol));
clones.put(symbol, clone);
- clone.setType(cloneType(symbol.info()));
return clone;
}
- /** Clones the given symbols. */
- public Symbol[] cloneSymbols(Symbol[] symbols) {
+ /** Clones the given symbols but not their types. */
+ public Symbol[] cloneSymbolsWithoutTypes(Symbol[] symbols) {
if (symbols.length == 0) return Symbol.EMPTY_ARRAY;
Symbol[] clones = new Symbol[symbols.length];
for (int i = 0; i < clones.length; i++)
- clones[i] = cloneSymbol(symbols[i]);
+ clones[i] = cloneSymbolWithoutType(symbols[i]);
return clones;
}
+ /** Clones the given scope but not the type of its members. */
+ public Scope cloneScopeWithoutTypes(Scope scope) {
+ Scope clone = new Scope();
+ for (Scope.SymbolIterator i = scope.iterator(true); i.hasNext(); ) {
+ clone.enterOrOverload(cloneSymbolWithoutType(i.next()));
+ }
+ return clone;
+ }
+
+ /** Clones the given symbol and its type. */
+ public Symbol cloneSymbol(Symbol symbol) {
+ Symbol clone = cloneSymbolWithoutType(symbol);
+ clone.setType(cloneType(symbol.info()));
+ return clone;
+ }
+
+ /** Clones the given symbols and their types. */
+ public Symbol[] cloneSymbols(Symbol[] symbols) {
+ Symbol[] clones = cloneSymbolsWithoutTypes(symbols);
+ for (int i = 0; i < clones.length; i++)
+ clones[i].setType(cloneType(symbols[i].info()));
+ return clones;
+ }
+
+ /** Clones the given scope and the type of its members. */
+ public Scope cloneScope(Scope scope) {
+ Scope clone = cloneScopeWithoutTypes(scope);
+ for (Scope.SymbolIterator i = scope.iterator(true); i.hasNext(); ) {
+ Symbol member = i.next();
+ member.setType(cloneType(member.info()));
+ }
+ return clone;
+ }
+
/** Clones the given type. */
public Type cloneType(Type type) {
+ return typer.apply(type);
+ }
+
+ //########################################################################
+ // Private Method
+
+ private Symbol getCompoundClone(Symbol symbol) {
+ assert symbol.isCompoundSym(): Debug.show(symbol);
+ assert !owners.containsKey(symbol): Debug.show(symbol);
+ assert !clones.containsKey(symbol):
+ Debug.show(symbol) + " -> " + Debug.show(clones.get(symbol));
+ Symbol owner = (Symbol)clones.get(symbol.owner());
+ if (owner == null) owner = (Symbol)owners.get(symbol.owner());
+ if (owner == null) owner = symbol.owner();
+ Symbol clone = symbol.cloneSymbol(owner);
+ clones.put(symbol, clone);
+ return clone;
+ }
+
+ //########################################################################
+ // Private Class - Type cloner
+
+ /** The type cloner Type.Map */
+ private final Type.Map typer = new Type.Map(){public Type apply(Type type){
switch (type) {
+ case ErrorType:
+ case NoType:
+ return type;
+ case ThisType(Symbol symbol):
+ Symbol clone = (Symbol)clones.get(symbol);
+ if (clone == null) return type;
+ return Type.ThisType(clone);
+ case SingleType(Type prefix, Symbol symbol):
+ Symbol clone = (Symbol)clones.get(symbol);
+ if (clone == null) return map(type);
+ return Type.singleType(apply(prefix), clone);
+ case ConstantType(_, _):
+ return map(type);
+ case TypeRef(Type prefix, Symbol symbol, Type[] args):
+ Symbol clone = (Symbol)clones.get(symbol);
+ if (clone == null) return map(type);
+ return Type.typeRef(apply(prefix), clone, map(args));
+ case CompoundType(Type[] parts, Scope members):
+ Symbol clone = /* !!! getCompoundClone */(type.symbol());
+ return Type.compoundType(map(parts), /* !!! cloneScope */(members), clone);
+ case MethodType(Symbol[] vparams, Type result):
+ Symbol[] clones = cloneSymbols(vparams);
+ return Type.MethodType(clones, apply(result));
case PolyType(Symbol[] tparams, Type result):
Symbol[] clones = cloneSymbols(tparams);
- Type clone = Type.PolyType(clones, cloneType(result));
- return Type.getSubst(tparams, clones).applyParams(clone);
- case MethodType(Symbol[] vparams, Type result):
- return Type.MethodType(cloneSymbols(vparams), cloneType(result));
- default:
+ return Type.PolyType(clones, apply(result));
+ case UnboxedType(_):
return type;
+ case UnboxedArrayType(_):
+ return map(type);
+ default:
+ throw Debug.abort("illegal case", type);
}
- }
+ }};
//########################################################################
}