Skip to content

Commit

Permalink
Small cleanup related to overrides.
Browse files Browse the repository at this point in the history
Change-Id: I36414bae9ec13349afbc1224611e18aa94235aea
  • Loading branch information
rluble committed Mar 18, 2015
1 parent 870a0d1 commit b47e493
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
Expand Up @@ -134,11 +134,11 @@ public boolean visit(JConstructor x, Context ctx) {


@Override @Override
public boolean visit(JMethod x, Context ctx) { public boolean visit(JMethod x, Context ctx) {
Set<JMethod> overrides = x.getOverriddenMethods(); Set<JMethod> overriddenMethods = x.getOverriddenMethods();
if (!overrides.isEmpty() || program.typeOracle.isJsTypeMethod(x) if (!overriddenMethods.isEmpty() || program.typeOracle.isJsTypeMethod(x)
|| program.typeOracle.isJsFunctionMethod(x) || program.typeOracle.isJsFunctionMethod(x)
|| program.typeOracle.isExportedMethod(x)) { || program.typeOracle.isExportedMethod(x)) {
for (JMethod m : overrides) { for (JMethod m : overriddenMethods) {
rescuedMethods.add(m); rescuedMethods.add(m);
} }
rescuedMethods.add(x); rescuedMethods.add(x);
Expand Down
50 changes: 24 additions & 26 deletions dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
Expand Up @@ -336,8 +336,8 @@ public boolean visit(JMethod x, Context ctx) {
* Add an assignment to each parameter from that same parameter in every * Add an assignment to each parameter from that same parameter in every
* method this method overrides. * method this method overrides.
*/ */
Collection<JMethod> overrides = x.getOverriddenMethods(); Collection<JMethod> overriddenMethods = x.getOverriddenMethods();
if (overrides.isEmpty()) { if (overriddenMethods.isEmpty()) {
return true; return true;
} }
for (int j = 0, c = x.getParams().size(); j < c; ++j) { for (int j = 0, c = x.getParams().size(); j < c; ++j) {
Expand All @@ -347,7 +347,7 @@ public boolean visit(JMethod x, Context ctx) {
set = new LinkedHashSet<JParameter>(); set = new LinkedHashSet<JParameter>();
paramUpRefs.put(param, set); paramUpRefs.put(param, set);
} }
for (JMethod baseMethod : overrides) { for (JMethod baseMethod : overriddenMethods) {
JParameter baseParam = baseMethod.getParams().get(j); JParameter baseParam = baseMethod.getParams().get(j);
set.add(baseParam); set.add(baseParam);
} }
Expand Down Expand Up @@ -604,11 +604,9 @@ public void exit(JMethod x, Context ctx) {
typeList.add((JReferenceType) expr.getType()); typeList.add((JReferenceType) expr.getType());
} }
} }
Collection<JMethod> overridingMethods = x.getOverridingMethods();
if (overridingMethods != null) { for (JMethod method : x.getOverridingMethods()) {
for (JMethod method : overridingMethods) { typeList.add((JReferenceType) method.getType());
typeList.add((JReferenceType) method.getType());
}
} }


JReferenceType resultType = program.strengthenType(refType, typeList); JReferenceType resultType = program.strengthenType(refType, typeList);
Expand Down Expand Up @@ -643,26 +641,26 @@ public void endVisit(JMethodCall x, Context ctx) {
* Mark a call as non-polymorphic if the targeted method is the only * Mark a call as non-polymorphic if the targeted method is the only
* possible dispatch, given the qualifying instance type. * possible dispatch, given the qualifying instance type.
*/ */
if (!target.isAbstract()) { if (target.isAbstract()) {
JExpression instance = x.getInstance(); return;
assert (instance != null); }
JReferenceType instanceType = (JReferenceType) instance.getType();
Collection<JMethod> myOverriders = target.getOverridingMethods(); JExpression instance = x.getInstance();
if (myOverriders != null) { assert (instance != null);
for (JMethod override : myOverriders) { JReferenceType instanceType = (JReferenceType) instance.getType();
JReferenceType overrideType = override.getEnclosingType(); for (JMethod overridingMethod : target.getOverridingMethods()) {
if (program.typeOracle.canTheoreticallyCast(instanceType, overrideType)) { // Look for overriding methods from a type compatible with the instance type, if none is
// This call is truly polymorphic. // found, this call can be marked as static dispatch.
// TODO: composite types! :) JReferenceType overridingMethodEnclosingType = overridingMethod.getEnclosingType();
return; if (program.typeOracle.canTheoreticallyCast(
} instanceType, overridingMethodEnclosingType)) {
} // This call is truly polymorphic.
// The instance type is incompatible with all overrides. return;
} }
assert !x.isStaticDispatchOnly();
x.setCannotBePolymorphic();
madeChanges();
} }
assert !x.isStaticDispatchOnly();
x.setCannotBePolymorphic();
madeChanges();
} }


@Override @Override
Expand Down

0 comments on commit b47e493

Please sign in to comment.