summaryrefslogtreecommitdiff
path: root/sources/scalac/transformer/LambdaLiftPhase.java
diff options
context:
space:
mode:
authorMatthias Zenger <mzenger@gmail.com>2003-07-02 12:40:42 +0000
committerMatthias Zenger <mzenger@gmail.com>2003-07-02 12:40:42 +0000
commit5bcdedd615aaa18c44b408db74776949f09e307d (patch)
treedffc1b3bbbe517a818c44cb19686fd0f5e6f876a /sources/scalac/transformer/LambdaLiftPhase.java
parent478c334b562ff810f424b8ac3cdfd7f9c868feab (diff)
downloadscala-5bcdedd615aaa18c44b408db74776949f09e307d.tar.gz
scala-5bcdedd615aaa18c44b408db74776949f09e307d.tar.bz2
scala-5bcdedd615aaa18c44b408db74776949f09e307d.zip
Added a new apply method to each phase which al...
Added a new apply method to each phase which allows to apply only a single compilation unit. For some phases this might probably not work as it is right now. At some stage, these phases have to be adapted accordingly.
Diffstat (limited to 'sources/scalac/transformer/LambdaLiftPhase.java')
-rw-r--r--sources/scalac/transformer/LambdaLiftPhase.java198
1 files changed, 101 insertions, 97 deletions
diff --git a/sources/scalac/transformer/LambdaLiftPhase.java b/sources/scalac/transformer/LambdaLiftPhase.java
index df31745da5..73e26e7986 100644
--- a/sources/scalac/transformer/LambdaLiftPhase.java
+++ b/sources/scalac/transformer/LambdaLiftPhase.java
@@ -22,8 +22,8 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers
public void initialize(Global global, int id) {
super.initialize(global, id);
- this.global = global;
- this.nextPhase = id + 1;
+ this.global = global;
+ this.nextPhase = id + 1;
}
public String name () {
@@ -42,88 +42,92 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers
new LambdaLift(global, this).apply();
}
- public Type transformInfo(Symbol sym, Type tp) {
- if (global.debug)
- global.log("transform info for " + sym + ":" + tp + sym.locationString());
- Type tp1 = tp;
- if (sym != Symbol.NONE) {
- switch (tp) {
- case MethodType(_, _):
- case PolyType(_, _):
- tp1 = transform(tp, sym);
- break;
- default:
- if (sym.kind == CLASS)
- tp1 = transform(tp, sym);
- else
- tp1 = transform(tp, sym.owner());
- }
+ public void apply(Unit unit) {
+ new LambdaLift(unit.global, this).apply(unit);
}
- if ((sym.flags & Modifiers.CAPTURED) != 0) return refType(tp1);
- else return tp1;
+
+ public Type transformInfo(Symbol sym, Type tp) {
+ if (global.debug)
+ global.log("transform info for " + sym + ":" + tp + sym.locationString());
+ Type tp1 = tp;
+ if (sym != Symbol.NONE) {
+ switch (tp) {
+ case MethodType(_, _):
+ case PolyType(_, _):
+ tp1 = transform(tp, sym);
+ break;
+ default:
+ if (sym.kind == CLASS)
+ tp1 = transform(tp, sym);
+ else
+ tp1 = transform(tp, sym.owner());
+ }
+ }
+ if ((sym.flags & Modifiers.CAPTURED) != 0) return refType(tp1);
+ else return tp1;
}
/** Add proxies as type arguments for propagated type parameters.
*/
Type transform(Type tp, Symbol owner) {
- return transformTypeMap.setOwner(owner).apply(tp);
+ return transformTypeMap.setOwner(owner).apply(tp);
}
private class TransformTypeMap extends Type.MapOnlyTypes {
- Symbol owner;
-// ArrayList/*<Symbol>*/ excluded = new ArrayList();
+ Symbol owner;
+// ArrayList/*<Symbol>*/ excluded = new ArrayList();
Type.Map setOwner(Symbol owner) { this.owner = owner; return this; }
- public Type apply(Type tp) {
- switch (tp) {
- case TypeRef(Type pre, Symbol sym, Type[] targs):
- switch (pre) {
- case ThisType(_):
- if (sym.kind == CLASS && sym.constructor().isUpdated(nextPhase)) {
- Symbol[] tparams =
- sym.constructor().infoAt(nextPhase).typeParams();
- int i = tparams.length;
- while (i > 0 && (tparams[i-1].flags & SYNTHETIC) != 0)
- i--;
- if (i < tparams.length) {
- if (global.debug)
- global.log("adding proxies for " + sym + ": " + ArrayApply.toString(tparams));
-
- Type[] targs1 = new Type[tparams.length];
- System.arraycopy(map(targs), 0, targs1, 0, targs.length);
- while (i < tparams.length) {
- targs1[i] = proxy(tparams[i], owner).type();
- i++;
- }
- return Type.TypeRef(pre, sym, targs1);
- }
- } else if (sym.isLocal()) {
- assert targs.length == 0;
- return proxy(sym, owner).type();
- }
- }
- break;
+ public Type apply(Type tp) {
+ switch (tp) {
+ case TypeRef(Type pre, Symbol sym, Type[] targs):
+ switch (pre) {
+ case ThisType(_):
+ if (sym.kind == CLASS && sym.constructor().isUpdated(nextPhase)) {
+ Symbol[] tparams =
+ sym.constructor().infoAt(nextPhase).typeParams();
+ int i = tparams.length;
+ while (i > 0 && (tparams[i-1].flags & SYNTHETIC) != 0)
+ i--;
+ if (i < tparams.length) {
+ if (global.debug)
+ global.log("adding proxies for " + sym + ": " + ArrayApply.toString(tparams));
+
+ Type[] targs1 = new Type[tparams.length];
+ System.arraycopy(map(targs), 0, targs1, 0, targs.length);
+ while (i < tparams.length) {
+ targs1[i] = proxy(tparams[i], owner).type();
+ i++;
+ }
+ return Type.TypeRef(pre, sym, targs1);
+ }
+ } else if (sym.isLocal()) {
+ assert targs.length == 0;
+ return proxy(sym, owner).type();
+ }
+ }
+ break;
/*
- case PolyType(Symbol[] tparams, _):
- if (tparams.length != 0) {
- int len = excluded.size();
- for (int i = 0; i < tparams.length; i++)
- excluded.add(tparams[i]);
- Type tp1 = map(tp);
- for (int i = 0; i < tparams.length; i++)
- excluded.remove(excluded.size() - 1);
- return tp1;
- }
+ case PolyType(Symbol[] tparams, _):
+ if (tparams.length != 0) {
+ int len = excluded.size();
+ for (int i = 0; i < tparams.length; i++)
+ excluded.add(tparams[i]);
+ Type tp1 = map(tp);
+ for (int i = 0; i < tparams.length; i++)
+ excluded.remove(excluded.size() - 1);
+ return tp1;
+ }
*/
- }
- return map(tp);
- }
-
- /** All symbols are mapped to themselves.
- */
- public Scope map(Scope s) { return s; }
- public Symbol map(Symbol s) { return s; }
- public Symbol[] map(Symbol[] ss) { return ss; }
+ }
+ return map(tp);
+ }
+
+ /** All symbols are mapped to themselves.
+ */
+ public Scope map(Scope s) { return s; }
+ public Symbol map(Symbol s) { return s; }
+ public Symbol[] map(Symbol[] ss) { return ss; }
}
private TransformTypeMap transformTypeMap = new TransformTypeMap();
@@ -132,36 +136,36 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers
* or `fv' itself if this is the closest definition.
*/
Symbol proxy(Symbol fv, Symbol owner) {
- if (global.debug)
- global.log("proxy " + fv + " of " + fv.owner() + " in " + LambdaLift.asFunction(owner));
- Symbol o = owner;
- while (o.kind != NONE) {
- if (global.debug)
- global.log("looking in " + LambdaLift.asFunction(o) + " " +
- ArrayApply.toString(o.typeParams()));
- Symbol fowner = LambdaLift.asFunction(o);
- if (fv.owner() == fowner) return fv;
- Type ft = (fowner.isUpdated(nextPhase)) ? fowner.typeAt(nextPhase)
- : fowner.type();
- Symbol[] ownerparams = fv.isType() ? ft.typeParams()
- : ft.firstParams();
- for (int i = 0; i < ownerparams.length; i++) {
- if (ownerparams[i].name == fv.name)
- return ownerparams[i];
- }
- assert o.owner() != o;
- o = o.owner();
- }
- return fv;
- //throw new ApplicationError("proxy " + fv + " in " + owner);
+ if (global.debug)
+ global.log("proxy " + fv + " of " + fv.owner() + " in " + LambdaLift.asFunction(owner));
+ Symbol o = owner;
+ while (o.kind != NONE) {
+ if (global.debug)
+ global.log("looking in " + LambdaLift.asFunction(o) + " " +
+ ArrayApply.toString(o.typeParams()));
+ Symbol fowner = LambdaLift.asFunction(o);
+ if (fv.owner() == fowner) return fv;
+ Type ft = (fowner.isUpdated(nextPhase)) ? fowner.typeAt(nextPhase)
+ : fowner.type();
+ Symbol[] ownerparams = fv.isType() ? ft.typeParams()
+ : ft.firstParams();
+ for (int i = 0; i < ownerparams.length; i++) {
+ if (ownerparams[i].name == fv.name)
+ return ownerparams[i];
+ }
+ assert o.owner() != o;
+ o = o.owner();
+ }
+ return fv;
+ //throw new ApplicationError("proxy " + fv + " in " + owner);
}
/** The type scala.Ref[tp]
*/
Type refType(Type tp) {
- Symbol refClass = global.definitions.getClass(Names.scala_Ref);
- assert refClass.kind == Kinds.CLASS;
- return Type.TypeRef(global.definitions.SCALA_TYPE, refClass, new Type[]{tp});
+ Symbol refClass = global.definitions.getClass(Names.scala_Ref);
+ assert refClass.kind == Kinds.CLASS;
+ return Type.TypeRef(global.definitions.SCALA_TYPE, refClass, new Type[]{tp});
}
public Checker[] postCheckers(Global global) {
@@ -169,7 +173,7 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers
new CheckSymbols(global),
new CheckTypes(global),
new CheckOwners(global),
- new CheckNames(global)
+ new CheckNames(global)
};
}
}