- Removed some virtual overrides wonkiness with a helper method in JTypeOracle
- Reformatted TypeTightener
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1652 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
index 731306b..e6ceb60 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
@@ -238,17 +238,38 @@
return getOrCreate(superInterfaceMap, type).contains(qType);
}
- public JMethod[] getAllVirtualOverrides(JMethod method) {
+ /**
+ * References to any methods which this method implementation might override
+ * or implement in any instantiable class.
+ */
+ public Set<JMethod> getAllOverrides(JMethod method) {
Set<JMethod> results = new HashSet<JMethod>();
- Map<JClassType, Set<JMethod>> overrideMap = getOrCreateMap(virtualUpRefMap,
- method);
- for (JClassType classType : overrideMap.keySet()) {
- if (instantiatedTypes.contains(classType)) {
- Set<JMethod> set = overrideMap.get(classType);
- results.addAll(set);
- }
- }
- return results.toArray(new JMethod[results.size()]);
+ getAllRealOverrides(method, results);
+ getAllVirtualOverrides(method, results);
+ return results;
+ }
+
+ /**
+ * References to any methods which this method directly overrides. This should
+ * be an EXHAUSTIVE list, that is, if C overrides B overrides A, then C's
+ * overrides list will contain both A and B.
+ */
+ public Set<JMethod> getAllRealOverrides(JMethod method) {
+ Set<JMethod> results = new HashSet<JMethod>();
+ getAllRealOverrides(method, results);
+ return results;
+ }
+
+ /**
+ * References to any methods which this method does not directly override
+ * within the class in which it is declared; however, some instantiable
+ * subclass will cause the implementation of this method to effectively
+ * override methods with identical signatures declared in unrelated classes.
+ */
+ public Set<JMethod> getAllVirtualOverrides(JMethod method) {
+ Set<JMethod> results = new HashSet<JMethod>();
+ getAllVirtualOverrides(method, results);
+ return results;
}
public Set<JReferenceType> getInstantiatedTypes() {
@@ -429,6 +450,25 @@
}
}
+ private void getAllRealOverrides(JMethod method, Set<JMethod> results) {
+ for (JMethod possibleOverride : method.overrides) {
+ // if (instantiatedTypes.contains(possibleOverride.getEnclosingType())) {
+ results.add(possibleOverride);
+ // }
+ }
+ }
+
+ private void getAllVirtualOverrides(JMethod method, Set<JMethod> results) {
+ Map<JClassType, Set<JMethod>> overrideMap = getOrCreateMap(virtualUpRefMap,
+ method);
+ for (JClassType classType : overrideMap.keySet()) {
+ if (instantiatedTypes.contains(classType)) {
+ Set<JMethod> set = overrideMap.get(classType);
+ results.addAll(set);
+ }
+ }
+ }
+
private <K, V> Set<V> getOrCreate(Map<K, Set<V>> map, K key) {
Set<V> set = map.get(key);
if (set == null) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
index 59c9470..043de05 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
@@ -810,18 +810,8 @@
return false;
}
- for (int i = 0; i < x.overrides.size(); ++i) {
- JMethod ref = x.overrides.get(i);
- if (referencedNonTypes.contains(ref)) {
- rescuer.rescue(x);
- didRescue = true;
- return false;
- }
- }
- JMethod[] virtualOverrides = program.typeOracle.getAllVirtualOverrides(x);
- for (int i = 0; i < virtualOverrides.length; ++i) {
- JMethod ref = virtualOverrides[i];
- if (referencedNonTypes.contains(ref)) {
+ for (JMethod override : program.typeOracle.getAllOverrides(x)) {
+ if (referencedNonTypes.contains(override)) {
rescuer.rescue(x);
didRescue = true;
return false;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
index a2a877e..7d6afb6 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
@@ -103,9 +103,8 @@
if (!instance.hasSideEffects()) {
instance = program.getLiteralNull();
}
- JArrayRef arrayRef =
- new JArrayRef(program, x.getSourceInfo(), instance, program
- .getLiteralInt(0));
+ JArrayRef arrayRef = new JArrayRef(program, x.getSourceInfo(),
+ instance, program.getLiteralInt(0));
ctx.replaceMe(arrayRef);
}
}
@@ -118,18 +117,16 @@
// this doesn't really belong here, but while we're here let's remove
// non-side-effect qualifiers to statics
if (!instance.hasSideEffects()) {
- JFieldRef fieldRef =
- new JFieldRef(program, x.getSourceInfo(), null, x.getField(), x
- .getEnclosingType());
+ JFieldRef fieldRef = new JFieldRef(program, x.getSourceInfo(), null,
+ x.getField(), x.getEnclosingType());
ctx.replaceMe(fieldRef);
}
} else if (!isStatic && instance.getType() == typeNull) {
if (!instance.hasSideEffects()) {
instance = program.getLiteralNull();
}
- JFieldRef fieldRef =
- new JFieldRef(program, x.getSourceInfo(), instance, program
- .getNullField(), null);
+ JFieldRef fieldRef = new JFieldRef(program, x.getSourceInfo(),
+ instance, program.getNullField(), null);
ctx.replaceMe(fieldRef);
}
}
@@ -144,8 +141,8 @@
// this doesn't really belong here, but while we're here let's remove
// non-side-effect qualifiers to statics
if (!instance.hasSideEffects()) {
- JMethodCall newCall =
- new JMethodCall(program, x.getSourceInfo(), null, x.getTarget());
+ JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
+ null, x.getTarget());
newCall.getArgs().addAll(x.getArgs());
ctx.replaceMe(newCall);
}
@@ -154,9 +151,8 @@
if (!instance.hasSideEffects()) {
instance = program.getLiteralNull();
}
- JMethodCall newCall =
- new JMethodCall(program, x.getSourceInfo(), instance, program
- .getNullMethod());
+ JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
+ instance, program.getNullMethod());
ctx.replaceMe(newCall);
} else if (isStaticImpl && method.params.size() > 0
&& method.params.get(0).isThis() && x.getArgs().size() > 0
@@ -166,9 +162,8 @@
if (!instance.hasSideEffects()) {
instance = program.getLiteralNull();
}
- JMethodCall newCall =
- new JMethodCall(program, x.getSourceInfo(), instance, program
- .getNullMethod());
+ JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
+ instance, program.getNullMethod());
ctx.replaceMe(newCall);
}
}
@@ -228,12 +223,7 @@
@Override
public void endVisit(JMethod x, Context ctx) {
- for (JMethod method : x.overrides) {
- addOverrider(method, x);
- }
- JMethod[] allVirtualOverrides =
- program.typeOracle.getAllVirtualOverrides(x);
- for (JMethod method : allVirtualOverrides) {
+ for (JMethod method : program.typeOracle.getAllOverrides(x)) {
addOverrider(method, x);
}
currentMethod = null;
@@ -300,9 +290,8 @@
* Add an assignment to each parameter from that same parameter in every
* method this method overrides.
*/
- List<JMethod> overrides = x.overrides;
- JMethod[] virtualOverrides = program.typeOracle.getAllVirtualOverrides(x);
- if (overrides.isEmpty() && virtualOverrides.length == 0) {
+ Set<JMethod> overrides = program.typeOracle.getAllOverrides(x);
+ if (overrides.isEmpty()) {
return true;
}
for (int j = 0, c = x.params.size(); j < c; ++j) {
@@ -316,10 +305,6 @@
JParameter baseParam = baseMethod.params.get(j);
set.add(baseParam);
}
- for (JMethod baseMethod : virtualOverrides) {
- JParameter baseParam = baseMethod.params.get(j);
- set.add(baseParam);
- }
}
} else if (program.isStaticImpl(x)) {
/*
@@ -432,17 +417,15 @@
ctx.replaceMe(x.getExpr());
} else if (triviallyFalse) {
// replace with a magic NULL cast
- JCastOperation newOp =
- new JCastOperation(program, x.getSourceInfo(), program
- .getTypeNull(), x.getExpr());
+ JCastOperation newOp = new JCastOperation(program, x.getSourceInfo(),
+ program.getTypeNull(), x.getExpr());
ctx.replaceMe(newOp);
} else {
// If possible, try to use a narrower cast
JClassType concreteType = getSingleConcreteType(toType);
if (concreteType != null) {
- JCastOperation newOp =
- new JCastOperation(program, x.getSourceInfo(), concreteType, x
- .getExpr());
+ JCastOperation newOp = new JCastOperation(program, x.getSourceInfo(),
+ concreteType, x.getExpr());
ctx.replaceMe(newOp);
}
}
@@ -482,10 +465,9 @@
if (triviallyTrue) {
// replace with a simple null test
JNullLiteral nullLit = program.getLiteralNull();
- JBinaryOperation neq =
- new JBinaryOperation(program, x.getSourceInfo(), program
- .getTypePrimitiveBoolean(), JBinaryOperator.NEQ, x.getExpr(),
- nullLit);
+ JBinaryOperation neq = new JBinaryOperation(program, x.getSourceInfo(),
+ program.getTypePrimitiveBoolean(), JBinaryOperator.NEQ,
+ x.getExpr(), nullLit);
ctx.replaceMe(neq);
} else if (triviallyFalse) {
// replace with a false literal
@@ -494,9 +476,8 @@
// If possible, try to use a narrower cast
JClassType concreteType = getSingleConcreteType(toType);
if (concreteType != null) {
- JInstanceOf newOp =
- new JInstanceOf(program, x.getSourceInfo(), concreteType, x
- .getExpr());
+ JInstanceOf newOp = new JInstanceOf(program, x.getSourceInfo(),
+ concreteType, x.getExpr());
ctx.replaceMe(newOp);
}
}
@@ -581,9 +562,8 @@
public void endVisit(JMethodCall x, Context ctx) {
JMethod concreteMethod = getSingleConcreteMethod(x.getTarget());
if (concreteMethod != null) {
- JMethodCall newCall =
- new JMethodCall(program, x.getSourceInfo(), x.getInstance(),
- concreteMethod);
+ JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
+ x.getInstance(), concreteMethod);
newCall.getArgs().addAll(x.getArgs());
ctx.replaceMe(newCall);
@@ -631,7 +611,7 @@
* type.
*/
private JClassType getSingleConcreteType(JType type) {
- if (type instanceof JReferenceType) {
+ if (type instanceof JReferenceType) {
JReferenceType refType = (JReferenceType) type;
if (refType.isAbstract()) {
return getSingleConcrete((JReferenceType) type, implementors);
@@ -760,17 +740,12 @@
return toReturn;
}
- private final Map<JVariable, Set<JExpression>> assignments =
- new IdentityHashMap<JVariable, Set<JExpression>>();
- private final Map<JReferenceType, Set<JClassType>> implementors =
- new IdentityHashMap<JReferenceType, Set<JClassType>>();
- private final Map<JMethod, Set<JMethod>> overriders =
- new IdentityHashMap<JMethod, Set<JMethod>>();
- private final Map<JParameter, Set<JParameter>> paramUpRefs =
- new IdentityHashMap<JParameter, Set<JParameter>>();
+ private final Map<JVariable, Set<JExpression>> assignments = new IdentityHashMap<JVariable, Set<JExpression>>();
+ private final Map<JReferenceType, Set<JClassType>> implementors = new IdentityHashMap<JReferenceType, Set<JClassType>>();
+ private final Map<JMethod, Set<JMethod>> overriders = new IdentityHashMap<JMethod, Set<JMethod>>();
+ private final Map<JParameter, Set<JParameter>> paramUpRefs = new IdentityHashMap<JParameter, Set<JParameter>>();
private final JProgram program;
- private final Map<JMethod, Set<JExpression>> returns =
- new IdentityHashMap<JMethod, Set<JExpression>>();
+ private final Map<JMethod, Set<JExpression>> returns = new IdentityHashMap<JMethod, Set<JExpression>>();
private final JNullType typeNull;