Model JGwtCreate/JReboundEntryPoint request/result types as strings. The actual types aren't important, the rebind logic is all about matching up request/result type. Removing the types here makes things simpler. http://gwt-code-reviews.appspot.com/1427808/ Review by: cromwellian@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10093 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java index 94be737..12531fc 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java
@@ -16,8 +16,10 @@ package com.google.gwt.dev.jjs.ast; import com.google.gwt.dev.jjs.SourceInfo; +import com.google.gwt.dev.util.collect.Lists; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -49,8 +51,24 @@ return new JNewInstance(info, noArgCtor, enclosingType); } + static List<String> nameOf(Collection<? extends JType> types) { + List<String> result = Lists.create(); + for (JType type : types) { + result = Lists.add(result, nameOf(type)); + } + return Lists.normalizeUnmodifiable(result); + } + + /** + * Rebinds are always on a source type name. + */ + static String nameOf(JType type) { + // TODO: replace with BinaryName.toSourceName(type.getName())? + return type.getName().replace('$', '.'); + } + private static ArrayList<JExpression> createInstantiationExpressions(SourceInfo info, - List<JClassType> classTypes, JDeclaredType enclosingType) { + Collection<JClassType> classTypes, JDeclaredType enclosingType) { ArrayList<JExpression> exprs = new ArrayList<JExpression>(); for (JClassType classType : classTypes) { JExpression expr = createInstantiationExpression(info, classType, enclosingType); @@ -61,8 +79,10 @@ } private final ArrayList<JExpression> instantiationExpressions; - private final List<JClassType> resultTypes; - private final JReferenceType sourceType; + + private final List<String> resultTypes; + + private final String sourceType; /* * Initially object; will be updated by type tightening. @@ -70,10 +90,19 @@ private JType type; /** + * Public constructor used during AST creation. + */ + public JGwtCreate(SourceInfo info, JReferenceType sourceType, Collection<JClassType> resultTypes, + JType type, JDeclaredType enclosingType) { + this(info, nameOf(sourceType), nameOf(resultTypes), type, createInstantiationExpressions(info, + resultTypes, enclosingType)); + } + + /** * Constructor used for cloning an existing node. */ - public JGwtCreate(SourceInfo info, JReferenceType sourceType, List<JClassType> resultTypes, - JType type, ArrayList<JExpression> instantiationExpressions) { + public JGwtCreate(SourceInfo info, String sourceType, List<String> resultTypes, JType type, + ArrayList<JExpression> instantiationExpressions) { super(info); this.sourceType = sourceType; this.resultTypes = resultTypes; @@ -81,24 +110,15 @@ this.instantiationExpressions = instantiationExpressions; } - /** - * Public constructor used during AST creation. - */ - public JGwtCreate(SourceInfo info, JReferenceType sourceType, List<JClassType> resultTypes, - JType type, JDeclaredType enclosingType) { - this(info, sourceType, resultTypes, type, createInstantiationExpressions(info, resultTypes, - enclosingType)); - } - public ArrayList<JExpression> getInstantiationExpressions() { return instantiationExpressions; } - public List<JClassType> getResultTypes() { + public List<String> getResultTypes() { return resultTypes; } - public JReferenceType getSourceType() { + public String getSourceType() { return sourceType; }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java index c93e3ec..a3f2a48 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java +++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java
@@ -27,14 +27,14 @@ public class JReboundEntryPoint extends JStatement { private final List<JExpression> entryCalls; - private final List<JClassType> resultTypes; - private final JDeclaredType sourceType; + private final List<String> resultTypes; + private final String sourceType; - public JReboundEntryPoint(SourceInfo info, JDeclaredType sourceType, + public JReboundEntryPoint(SourceInfo info, JReferenceType sourceType, List<JClassType> resultTypes, List<JExpression> entryCalls) { super(info); - this.sourceType = sourceType; - this.resultTypes = resultTypes; + this.sourceType = JGwtCreate.nameOf(sourceType); + this.resultTypes = JGwtCreate.nameOf(resultTypes); this.entryCalls = entryCalls; } @@ -42,11 +42,11 @@ return entryCalls; } - public List<JClassType> getResultTypes() { + public List<String> getResultTypes() { return resultTypes; } - public JDeclaredType getSourceType() { + public String getSourceType() { return sourceType; }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/RecordRebinds.java b/dev/core/src/com/google/gwt/dev/jjs/impl/RecordRebinds.java index 5a360c1..080bc631 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/RecordRebinds.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/RecordRebinds.java
@@ -34,14 +34,12 @@ private class RebindVisitor extends JVisitor { @Override public void endVisit(JGwtCreate x, Context ctx) { - String reqType = x.getSourceType().getName().replace('$', '.'); - liveRebindRequests.add(reqType); + liveRebindRequests.add(x.getSourceType()); } @Override public void endVisit(JReboundEntryPoint x, Context ctx) { - String reqType = x.getSourceType().getName().replace('$', '.'); - liveRebindRequests.add(reqType); + liveRebindRequests.add(x.getSourceType()); } }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRebinds.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRebinds.java index e69fded..c21fdf9 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRebinds.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRebinds.java
@@ -17,12 +17,10 @@ import com.google.gwt.dev.jjs.InternalCompilerException; import com.google.gwt.dev.jjs.SourceInfo; -import com.google.gwt.dev.jjs.SourceOrigin; import com.google.gwt.dev.jjs.ast.Context; import com.google.gwt.dev.jjs.ast.JBlock; import com.google.gwt.dev.jjs.ast.JCaseStatement; import com.google.gwt.dev.jjs.ast.JClassType; -import com.google.gwt.dev.jjs.ast.JDeclaredType; import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JGwtCreate; import com.google.gwt.dev.jjs.ast.JMethod; @@ -31,15 +29,12 @@ import com.google.gwt.dev.jjs.ast.JModVisitor; import com.google.gwt.dev.jjs.ast.JProgram; import com.google.gwt.dev.jjs.ast.JReboundEntryPoint; -import com.google.gwt.dev.jjs.ast.JReferenceType; import com.google.gwt.dev.jjs.ast.JReturnStatement; import com.google.gwt.dev.jjs.ast.JSwitchStatement; -import com.google.gwt.dev.jjs.ast.JType; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.IdentityHashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -63,11 +58,11 @@ return; } - JClassType rebindResult = rebind(x.getSourceType()); - List<JClassType> rebindResults = x.getResultTypes(); + String rebindResult = rebind(x.getSourceType()); + List<String> rebindResults = x.getResultTypes(); for (int i = 0; i < rebindResults.size(); ++i) { // Find the matching rebound type. - if (rebindResult == rebindResults.get(i)) { + if (rebindResult.equals(rebindResults.get(i))) { // Replace with the associated instantiation expression. ctx.replaceMe(x.getInstantiationExpressions().get(i)); return; @@ -86,11 +81,11 @@ return; } - JClassType rebindResult = rebind(x.getSourceType()); - List<JClassType> rebindResults = x.getResultTypes(); + String rebindResult = rebind(x.getSourceType()); + List<String> rebindResults = x.getResultTypes(); for (int i = 0; i < rebindResults.size(); ++i) { // Find the matching rebound type. - if (rebindResult == rebindResults.get(i)) { + if (rebindResult.equals(rebindResults.get(i))) { // Replace with the associated instantiation expression. ctx.replaceMe(x.getEntryCalls().get(i).makeStatement()); return; @@ -128,8 +123,7 @@ private final Map<String, String>[] orderedRebindAnswers; private final JMethod permutationIdMethod; private final JProgram program; - private final Map<JReferenceType, JMethod> rebindMethods = - new IdentityHashMap<JReferenceType, JMethod>(); + private final Map<String, JMethod> rebindMethods = new HashMap<String, JMethod>(); private ResolveRebinds(JProgram program, Map<String, String>[] orderedRebindAnswers) { this.program = program; @@ -140,9 +134,8 @@ this.permutationIdMethod = program.getIndexedMethod("CollapsedPropertyHolder.getPermutationId"); } - public JClassType rebind(JType type) { + public String rebind(String reqType) { // Rebinds are always on a source type name. - String reqType = type.getName().replace('$', '.'); String reboundClassName = hardRebindAnswers.get(reqType); if (reboundClassName == null) { // The fact that we already compute every rebind permutation before @@ -150,9 +143,8 @@ // throw new InternalCompilerException("Unexpected failure to rebind '" + reqType + "'"); } - JDeclaredType result = program.getFromTypeMap(reboundClassName); - assert (result != null); - return (JClassType) result; + assert program.getFromTypeMap(reboundClassName) != null; + return reboundClassName; } private boolean execImpl() { @@ -161,12 +153,11 @@ return rebinder.didChange(); } - private boolean isSoftRebind(JType type) { - String reqType = type.getName().replace('$', '.'); - return !hardRebindAnswers.containsKey(reqType); + private boolean isSoftRebind(String requestType) { + return !hardRebindAnswers.containsKey(requestType); } - private JMethod rebindMethod(JReferenceType requestType, List<JClassType> resultTypes, + private JMethod rebindMethod(String requestType, List<String> resultTypes, List<JExpression> instantiationExpressions) { assert resultTypes.size() == instantiationExpressions.size(); @@ -175,18 +166,12 @@ return toReturn; } - SourceInfo info = requestType.getSourceInfo().makeChild(SourceOrigin.UNKNOWN); - // Maps the result types to the various virtual permutation ids - Map<JClassType, List<Integer>> resultsToPermutations = - new LinkedHashMap<JClassType, List<Integer>>(); + Map<String, List<Integer>> resultsToPermutations = new LinkedHashMap<String, List<Integer>>(); for (int i = 0, j = orderedRebindAnswers.length; i < j; i++) { Map<String, String> answerMap = orderedRebindAnswers[i]; - String answerTypeName = answerMap.get(requestType.getName().replace('$', '.')); - // We take an answer class, e.g. DOMImplSafari ... - JClassType answerType = (JClassType) program.getFromTypeMap(answerTypeName); - + String answerType = answerMap.get(requestType); List<Integer> list = resultsToPermutations.get(answerType); if (list == null) { list = new ArrayList<Integer>(); @@ -197,10 +182,10 @@ } // Pick the most-used result type to emit less code - JClassType mostUsed = null; + String mostUsed = null; { int max = 0; - for (Map.Entry<JClassType, List<Integer>> entry : resultsToPermutations.entrySet()) { + for (Map.Entry<String, List<Integer>> entry : resultsToPermutations.entrySet()) { int size = entry.getValue().size(); if (size > max) { max = size; @@ -211,10 +196,10 @@ assert mostUsed != null; // c_g_g_d_c_i_DOMImpl + SourceInfo info = program.createSourceInfoSynthetic(getClass()); toReturn = - program.createMethod(info, requestType.getName().replace("_", "_1").replace('.', '_'), - holderType, program.getTypeJavaLangObject().getNonNull(), false, true, true, false, - false); + program.createMethod(info, requestType.replace("_", "_1").replace('.', '_'), holderType, + program.getTypeJavaLangObject().getNonNull(), false, true, true, false, false); toReturn.freezeParamTypes(); info.addCorrelation(info.getCorrelator().by(toReturn)); rebindMethods.put(requestType, toReturn); @@ -224,14 +209,14 @@ JBlock switchBody = new JBlock(info); for (int i = 0, j = resultTypes.size(); i < j; i++) { - JClassType resultType = resultTypes.get(i); + String resultType = resultTypes.get(i); JExpression instantiation = instantiationExpressions.get(i); List<Integer> permutations = resultsToPermutations.get(resultType); if (permutations == null) { // This rebind result is unused in this permutation continue; - } else if (resultType == mostUsed) { + } else if (resultType.equals(mostUsed)) { // Save off the fallback expression and go onto the next type mostUsedExpression = instantiation; continue; @@ -248,7 +233,7 @@ } assert switchBody.getStatements().size() > 0 : "No case statement emitted " - + "for supposedly soft-rebind type " + requestType.getName(); + + "for supposedly soft-rebind type " + requestType; // switch (CollapsedPropertyHolder.getPermutationId()) { ... } JSwitchStatement sw =
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java index 399b749..9394827 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java
@@ -499,7 +499,7 @@ @Override public boolean visit(JGwtCreate x, Context ctx) { print("GWT.create("); - printTypeName(x.getSourceType()); + print(x.getSourceType()); print(".class)"); return false; } @@ -775,7 +775,7 @@ @Override public boolean visit(JReboundEntryPoint x, Context ctx) { print("<JReboundEntryPoint>"); - printTypeName(x.getSourceType()); + print(x.getSourceType()); return false; }