Revision: 10093
Author:   sco...@google.com
Date:     Wed Apr 27 14:46:52 2011
Log: 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: cromwell...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10093

Modified:
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/RecordRebinds.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRebinds.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java Tue Apr 19 10:10:18 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java Wed Apr 27 14:46:52 2011
@@ -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;

 /**
@@ -48,9 +50,25 @@
     // Call it, using a new expression as a qualifier
     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,44 +79,46 @@
   }

   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.
    */
   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;
     this.type = type;
     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;
   }

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java Wed Dec 9 09:10:40 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java Wed Apr 27 14:46:52 2011
@@ -27,14 +27,14 @@
 public class JReboundEntryPoint extends JStatement {

   private final List<JExpression> entryCalls;
-  private final List<JClassType> resultTypes;
-  private final JDeclaredType sourceType;
-
-  public JReboundEntryPoint(SourceInfo info, JDeclaredType sourceType,
+  private final List<String> resultTypes;
+  private final String 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;
   }

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/RecordRebinds.java Tue Apr 19 10:10:18 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/RecordRebinds.java Wed Apr 27 14:46:52 2011
@@ -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());
     }
   }

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRebinds.java Tue Apr 19 10:10:18 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRebinds.java Wed Apr 27 14:46:52 2011
@@ -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();

@@ -174,19 +165,13 @@
     if (toReturn != null) {
       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 =
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java Tue Apr 19 10:10:18 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java Wed Apr 27 14:46:52 2011
@@ -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;
   }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to