summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2003-07-30 09:07:59 +0000
committerschinz <schinz@epfl.ch>2003-07-30 09:07:59 +0000
commit5850ec1c8b66becf2fe3304da06c7d7b52ee50f6 (patch)
tree3feb0dc076d54267d8509fbc8747a3104e14de32 /sources
parent41e6216426ad03eb2f4bf77e8bc1a0d9d71dc792 (diff)
downloadscala-5850ec1c8b66becf2fe3304da06c7d7b52ee50f6.tar.gz
scala-5850ec1c8b66becf2fe3304da06c7d7b52ee50f6.tar.bz2
scala-5850ec1c8b66becf2fe3304da06c7d7b52ee50f6.zip
- modified phase to make it compatible with sep...
- modified phase to make it compatible with separate compilation: transformInfo now adds the outer argument to the constructor type, and this is no longer done during the tree transformation
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/transformer/ExplicitOuterClasses.java67
-rw-r--r--sources/scalac/transformer/ExplicitOuterClassesPhase.java59
2 files changed, 73 insertions, 53 deletions
diff --git a/sources/scalac/transformer/ExplicitOuterClasses.java b/sources/scalac/transformer/ExplicitOuterClasses.java
index 8933ca5d1e..1bb6288cf6 100644
--- a/sources/scalac/transformer/ExplicitOuterClasses.java
+++ b/sources/scalac/transformer/ExplicitOuterClasses.java
@@ -27,56 +27,24 @@ import Tree.*;
*/
public class ExplicitOuterClasses extends Transformer {
+ protected final ExplicitOuterClassesPhase phase;
+
// Mapping from class constructor symbols to owner field symbols.
- protected HashMap/*<Symbol,Symbol>*/ outerMap;
+ protected final HashMap/*<Symbol,Symbol>*/ outerMap;
public ExplicitOuterClasses(Global global) {
super(global);
- outerMap = global.PHASE.EXPLICITOUTER.outerMap;
- }
-
- protected Type addValueParam(Type oldType, Symbol newValueParam) {
- switch (oldType) {
- case MethodType(Symbol[] vparams, Type result): {
- Symbol[] newVParams = new Symbol[vparams.length + 1];
- newVParams[0] = newValueParam;
- System.arraycopy(vparams, 0, newVParams, 1, vparams.length);
- return new Type.MethodType(newVParams, result);
- }
-
- case PolyType(Symbol[] tparams, Type result):
- return new Type.PolyType(tparams, addValueParam(result, newValueParam));
-
- default:
- throw global.fail("invalid type", oldType);
- }
- }
-
- protected Symbol outerSym(Symbol constSym) {
- if (! outerMap.containsKey(constSym)) {
- Symbol ownerSym = constSym.enclClass();
- Symbol outerSym =
- new TermSymbol(constSym.pos, freshOuterName(), constSym, 0);
- outerSym.setInfo(ownerSym.type());
-
- outerMap.put(constSym, outerSym);
- }
- return (Symbol)outerMap.get(constSym);
- }
-
- protected Type newConstType(Symbol constSym) {
- return addValueParam(constSym.info(), outerSym(constSym));
+ this.phase = global.PHASE.EXPLICITOUTER;
+ this.outerMap = phase.outerMap;
}
protected LinkedList/*<Symbol>*/ classStack = new LinkedList();
protected LinkedList/*<Symbol>*/ outerLinks = new LinkedList();
- protected Name freshOuterName() {
- return global.freshNameCreator.newName(Names.OUTER_PREFIX);
- }
-
- // Return the number of outer links to follow to find the given
- // symbol.
+ /**
+ * Return the number of outer links to follow to find the given
+ * symbol.
+ */
protected int outerLevel(Symbol sym) {
Iterator classIt = classStack.iterator();
for (int level = 0; classIt.hasNext(); ++level) {
@@ -87,7 +55,9 @@ public class ExplicitOuterClasses extends Transformer {
return -1;
}
- // Return a tree referencing the "level"th outer class.
+ /**
+ * Return a tree referencing the "level"th outer class.
+ */
protected Tree outerRef(int level) {
assert level >= 0 : level;
@@ -145,13 +115,13 @@ public class ExplicitOuterClasses extends Transformer {
outerLinks.addFirst(null);
newVParams = classDef.vparams;
} else {
- // Add the outer parameter, both to the type and the tree.
+ // Add the outer parameter to the tree (it is added to
+ // the type by transformInfo).
Symbol constSym = classSym.constructor();
- Symbol outerSym = outerSym(constSym);
+ Symbol outerSym = phase.outerSym(constSym);
assert (outerSym.owner() == constSym) : outerSym;
outerLinks.addFirst(outerSym);
- Type newConstType = newConstType(constSym);
ValDef[][] vparams = classDef.vparams;
ValDef[] newVParamsI;
if (vparams.length == 0)
@@ -163,8 +133,6 @@ public class ExplicitOuterClasses extends Transformer {
}
newVParams = new ValDef[][] { newVParamsI };
- constSym.updateInfo(newConstType);
-
classSym.flags |= Modifiers.STATIC;
}
@@ -294,8 +262,9 @@ public class ExplicitOuterClasses extends Transformer {
else
finalFun = newFun;
- finalFun.type = addValueParam(finalFun.type,
- outerSym(realFun.symbol()));
+ finalFun.type =
+ phase.addValueParam(finalFun.type,
+ phase.outerSym(realFun.symbol()));
return copy.Apply(tree, finalFun, transform(newArgs));
} else
return super.transform(tree);
diff --git a/sources/scalac/transformer/ExplicitOuterClassesPhase.java b/sources/scalac/transformer/ExplicitOuterClassesPhase.java
index 92125339a6..805530bcd3 100644
--- a/sources/scalac/transformer/ExplicitOuterClassesPhase.java
+++ b/sources/scalac/transformer/ExplicitOuterClassesPhase.java
@@ -11,11 +11,13 @@ package scalac.transformer;
import scalac.*;
import scalac.checkers.*;
+import scalac.symtab.*;
+import scalac.util.*;
import java.util.HashMap;
public class ExplicitOuterClassesPhase extends PhaseDescriptor {
// Mapping from class constructor symbols to owner field symbols.
- public HashMap/*<Symbol,Symbol>*/ outerMap = new HashMap();
+ protected HashMap/*<Symbol,Symbol>*/ outerMap = new HashMap();
public String name () {
return "explicitouterclasses";
@@ -33,9 +35,9 @@ public class ExplicitOuterClassesPhase extends PhaseDescriptor {
new ExplicitOuterClasses(global).apply();
}
- public void apply(Unit unit) {
- new ExplicitOuterClasses(unit.global).apply(unit);
- }
+ public void apply(Unit unit) {
+ new ExplicitOuterClasses(unit.global).apply(unit);
+ }
public Checker[] postCheckers(Global global) {
return new Checker[] {
@@ -45,4 +47,53 @@ public class ExplicitOuterClassesPhase extends PhaseDescriptor {
new CheckNames(global)
};
}
+
+ public Type transformInfo(Symbol sym, Type tp) {
+ if (sym != Symbol.NONE
+ && sym.isConstructor()
+ && sym.owner().isClass()
+ && !(sym.isJava() || sym.owner().isRoot())) {
+ return addValueParam(tp, outerSym(sym));
+ } else
+ return tp;
+ }
+
+ /**
+ * Return the symbol for the outer parameter corresponding to the
+ * given constructor.
+ */
+ protected Symbol outerSym(Symbol constSym) {
+ if (! outerMap.containsKey(constSym)) {
+ Symbol ownerSym = constSym.enclClass();
+ Name outerName =
+ Global.instance.freshNameCreator.newName(Names.OUTER_PREFIX);
+ Symbol outerSym =
+ new TermSymbol(constSym.pos, outerName, constSym, 0);
+ outerSym.setInfo(ownerSym.type());
+
+ outerMap.put(constSym, outerSym);
+ }
+ return (Symbol)outerMap.get(constSym);
+ }
+
+ /**
+ * Add the given value parameter to the type, which must be the
+ * type of a method, as the first argument.
+ */
+ protected Type addValueParam(Type oldType, Symbol newValueParam) {
+ switch (oldType) {
+ case MethodType(Symbol[] vparams, Type result): {
+ Symbol[] newVParams = new Symbol[vparams.length + 1];
+ newVParams[0] = newValueParam;
+ System.arraycopy(vparams, 0, newVParams, 1, vparams.length);
+ return new Type.MethodType(newVParams, result);
+ }
+
+ case PolyType(Symbol[] tparams, Type result):
+ return new Type.PolyType(tparams, addValueParam(result, newValueParam));
+
+ default:
+ throw Global.instance.fail("invalid type", oldType);
+ }
+ }
}