summaryrefslogtreecommitdiff
path: root/sources/scalac
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-07-11 18:30:27 +0000
committerpaltherr <paltherr@epfl.ch>2003-07-11 18:30:27 +0000
commit195efaee57bfd9ebb67b02a6512e87e7026202a2 (patch)
tree0337d81fa12af12683ca3fad4a7658a635bbaae7 /sources/scalac
parent8e54f08fa4e78a464e2601c7da79001046b2bcc5 (diff)
downloadscala-195efaee57bfd9ebb67b02a6512e87e7026202a2.tar.gz
scala-195efaee57bfd9ebb67b02a6512e87e7026202a2.tar.bz2
scala-195efaee57bfd9ebb67b02a6512e87e7026202a2.zip
- Changed getClassSubst to return SymbolSubstTy...
- Changed getClassSubst to return SymbolSubstTypeMap Removed identSubst - (using typeSubst instead)
Diffstat (limited to 'sources/scalac')
-rw-r--r--sources/scalac/transformer/AddInterfaces.java30
-rw-r--r--sources/scalac/transformer/AddInterfacesPhase.java35
2 files changed, 28 insertions, 37 deletions
diff --git a/sources/scalac/transformer/AddInterfaces.java b/sources/scalac/transformer/AddInterfaces.java
index aea4c37b69..71b159faf7 100644
--- a/sources/scalac/transformer/AddInterfaces.java
+++ b/sources/scalac/transformer/AddInterfaces.java
@@ -52,8 +52,7 @@ class AddInterfaces extends Transformer {
protected LinkedList/*<Pair<Symbol,Symbol>>*/ ownerSubstStack =
new LinkedList();
protected Pair/*<Symbol,Symbol>*/ ownerSubst = null;
- protected StackedHashMap identSubst = new StackedHashMap();
- protected SymbolSubstTypeMap typeSubst = new SymbolSubstTypeMap();
+ protected SymbolSubstTypeMap typeSubst = null;
protected Type.SubstThisMap thisTypeSubst = null;
protected LinkedList/*<List<Tree>>*/ bodyStack = new LinkedList();
@@ -74,11 +73,10 @@ class AddInterfaces extends Transformer {
public Tree transform(Tree tree) {
// Update tree type, to take into account the new (type)
// symbols of enclosing classes / methods.
- Type newTp = typeSubst.apply(tree.type());
- if (thisTypeSubst != null)
- tree.setType(thisTypeSubst.apply(newTp));
- else
- tree.setType(newTp);
+ Type newTp = tree.type();
+ if (typeSubst != null) newTp = typeSubst.apply(newTp);
+ if (thisTypeSubst != null) newTp = thisTypeSubst.apply(newTp);
+ tree.setType(newTp);
if (tree.definesSymbol() && !(tree instanceof ClassDef)) {
// Update symbol's owner, if needed.
@@ -105,12 +103,9 @@ class AddInterfaces extends Transformer {
List/*<Tree>*/ enclosingBody = (List)bodyStack.getFirst();
enclosingBody.add(makeInterface(classDef));
- Map classSubst = phase.getClassSubst(classSym);
- identSubst.push(classSubst);
- typeSubst.insertSymbol(classSubst);
+ typeSubst = phase.getClassSubst(classSym);
Tree newTree = makeClass(classDef);
- typeSubst.removeSymbol(classSubst.keySet());
- identSubst.pop();
+ typeSubst = null;
return newTree;
} else
@@ -135,17 +130,16 @@ class AddInterfaces extends Transformer {
global.nextPhase();
typeSubst.insertSymbol(sym.typeParams(), newSym.typeParams());
- identSubst.putAll(sym.valueParams(), newSym.valueParams());
+ typeSubst.insertSymbol(sym.valueParams(), newSym.valueParams());
global.prevPhase();
- identSubst.push();
pushOwnerSubst(sym, newSym);
newTree = gen.DefDef(newSym, transform(rhs));
popOwnerSubst();
- identSubst.pop();
+ typeSubst.removeSymbol(sym.valueParams());
typeSubst.removeSymbol(sym.typeParams());
} else
newTree = super.transform(tree);
@@ -196,12 +190,14 @@ class AddInterfaces extends Transformer {
return gen.Ident(phase.getClassSymbol(clsSym).constructor());
else
return super.transform(tree);
- } else {
- Symbol newSym = (Symbol)identSubst.get(tree.symbol());
+ } else if (typeSubst != null) {
+ Symbol newSym = (Symbol)typeSubst.lookupSymbol(tree.symbol());
if (newSym != null)
return gen.Ident(newSym);
else
return super.transform(tree);
+ } else {
+ return super.transform(tree);
}
}
diff --git a/sources/scalac/transformer/AddInterfacesPhase.java b/sources/scalac/transformer/AddInterfacesPhase.java
index 07c47eb63a..9f294e6ea1 100644
--- a/sources/scalac/transformer/AddInterfacesPhase.java
+++ b/sources/scalac/transformer/AddInterfacesPhase.java
@@ -233,25 +233,21 @@ public class AddInterfacesPhase extends PhaseDescriptor {
new Type.SubstThisMap(ifaceSym, classSym);
// Clone type and value parameters of constructor.
- Map classSubst = newClassSubst(classSym);
+ SymbolSubstTypeMap classSubst = newClassSubst(classSym);
Symbol[] tparams = classConstrSym.typeParams();
for (int i = 0; i < tparams.length; ++i) {
Symbol newParam = tparams[i].cloneSymbol(classConstrSym);
- classSubst.put(tparams[i], newParam);
+ classSubst.insertSymbol(tparams[i], newParam);
}
- SymbolSubstTypeMap paramsSubst =
- new SymbolSubstTypeMap(classSubst, Collections.EMPTY_MAP);
- // Play it safe and make sure that classSubst won't be
- // modified anymore.
- classSubst = Collections.unmodifiableMap(classSubst);
-
Symbol[] vparams = classConstrSym.valueParams();
for (int i = 0; i < vparams.length; ++i) {
vparams[i].setOwner(classConstrSym);
- vparams[i].updateInfo(paramsSubst.apply(vparams[i].info()));
+ vparams[i].updateInfo(classSubst.apply(vparams[i].info()));
}
+
+
// Clone all members, entering them in the class scope.
Map classMembersMap = newClassMemberMap(classSym);
Scope classMembers = new Scope();
@@ -275,7 +271,7 @@ public class AddInterfacesPhase extends PhaseDescriptor {
classMemberSym = ifaceMemberSym.cloneSymbol(classSym);
classMemberSym.setInfo(
thisTypeMap.applyParams(
- paramsSubst.applyParams(
+ classSubst.applyParams(
classMemberSym.info().cloneType(
ifaceMemberSym, classMemberSym))));
classMembersMap.put(ifaceMemberSym, classMemberSym);
@@ -288,7 +284,7 @@ public class AddInterfacesPhase extends PhaseDescriptor {
classMemberSym.setOwner(classSym);
classMemberSym.updateInfo(
thisTypeMap.apply(
- paramsSubst.apply(
+ classSubst.apply(
classMemberSym.info())));
}
@@ -307,13 +303,13 @@ public class AddInterfacesPhase extends PhaseDescriptor {
switch (oldClassParents[i]) {
case TypeRef(Type pre, Symbol sym, Type[] args):
Type newTp = Type.typeRef(pre, getClassSymbol(sym), args);
- newClassParents[i] = paramsSubst.apply(newTp);
+ newClassParents[i] = classSubst.apply(newTp);
break;
default:
throw Debug.abort("unexpected type for parent", oldClassParents[i]);
}
}
- newClassParents[oldParentsCount] = paramsSubst.apply(ifaceSym.type());
+ newClassParents[oldParentsCount] = classSubst.apply(ifaceSym.type());
// TODO setInfo cannot be used here because the type then
// goes through transformInfo. Maybe setInfo should behave
// like updateInfo.
@@ -321,10 +317,9 @@ public class AddInterfacesPhase extends PhaseDescriptor {
classMembers,
classSym));
classConstrSym.updateInfo(substResType(substParams(classConstrSym.info(),
- paramsSubst),
+ classSubst),
ifaceSym,
classSym));
-
ifaceToClass.put(ifaceSym, classSym);
classToIFace.put(classSym, ifaceSym);
}
@@ -339,9 +334,9 @@ public class AddInterfacesPhase extends PhaseDescriptor {
return (Symbol)classToIFace.get(classSym);
}
- HashMap/*<Symbol,HashMap>*/ classSubstitutions = new HashMap();
- protected HashMap newClassSubst(Symbol classSym) {
- HashMap subst = new HashMap();
+ HashMap/*<Symbol,SymbolSubstTypeMap>*/ classSubstitutions = new HashMap();
+ protected SymbolSubstTypeMap newClassSubst(Symbol classSym) {
+ SymbolSubstTypeMap subst = new SymbolSubstTypeMap();
classSubstitutions.put(classSym, subst);
return subst;
}
@@ -349,8 +344,8 @@ public class AddInterfacesPhase extends PhaseDescriptor {
/** Return symbol substitution for the class (a mapping from the
* interface's type and value parameters to the class' equivalent)
*/
- public Map getClassSubst(Symbol classSym) {
- Map classSubst = (Map)classSubstitutions.get(classSym);
+ public SymbolSubstTypeMap getClassSubst(Symbol classSym) {
+ SymbolSubstTypeMap classSubst = (SymbolSubstTypeMap)classSubstitutions.get(classSym);
assert classSubst != null;
return classSubst;
}