Reviewers: jbrosenberg, zundel,

http://gwt-code-reviews.appspot.com/1460801/diff/1/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
File dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
(right):

http://gwt-code-reviews.appspot.com/1460801/diff/1/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java#newcode2097
dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java:2097:
};
This provides a much more consistent sort than simple name by forcing
overloads to be precisely ordered.  Makes it easier to diff between
slightly different compiler outputs.

http://gwt-code-reviews.appspot.com/1460801/diff/1/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
File dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
(right):

http://gwt-code-reviews.appspot.com/1460801/diff/1/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java#newcode1122
dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java:1122:
receiver = new JThisRef(info, oldRef.getClassType());
GenerateJavaAST does this in a different way, but the upshot is that
without this fixup in here, the implicit this ref on a method call
causes the stack emulation to jump to line 1 of the file, and back,
which generates a lot more code than needed.

http://gwt-code-reviews.appspot.com/1460801/diff/1/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java#newcode2020
dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java:2020:
bridgeMethod.freezeParamTypes();
I'm replacing my more recent code with code copied from GenerateJavaAST.
 The original code is slightly cleaner, but ultimately leads to worse
stack emulation, because we weren't being tidy with source infos.

Description:
Fixes a couple of places where GwtAstBuilder output is significantly
different from the current output.

Please review this at http://gwt-code-reviews.appspot.com/1460801/

Affected files:
  M dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
  M dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java


Index: dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java index 4bb1c7d3e021db4a3de8a6ee97b04e8a5848eaee..287f1c1c17d3f66b72c420c7f272ee4abf417ae2 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
@@ -157,6 +157,7 @@ import com.google.gwt.dev.util.collect.Maps;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -2088,16 +2089,23 @@ public class GenerateJavaScriptAST {

     private final HasNameSort hasNameSort = new HasNameSort();

+ private final Comparator<JMethod> methodSort = new Comparator<JMethod>() {
+      @Override
+      public int compare(JMethod m1, JMethod m2) {
+        return m1.getSignature().compareTo(m2.getSignature());
+      }
+    };
+
     @Override
     public void endVisit(JClassType x, Context ctx) {
       x.sortFields(hasNameSort);
-      x.sortMethods(hasNameSort);
+      x.sortMethods(methodSort);
     }

     @Override
     public void endVisit(JInterfaceType x, Context ctx) {
       x.sortFields(hasNameSort);
-      x.sortMethods(hasNameSort);
+      x.sortMethods(methodSort);
     }

     @Override
@@ -2107,7 +2115,7 @@ public class GenerateJavaScriptAST {

     @Override
     public void endVisit(JProgram x, Context ctx) {
-      Collections.sort(x.getEntryMethods(), hasNameSort);
+      Collections.sort(x.getEntryMethods(), methodSort);
       Collections.sort(x.getDeclaredTypes(), hasNameSort);
     }
   }
Index: dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java index 8fad08b23374d44acff2e3d512f1a5a995c05039..4083b1cbf5e921fa8b0ecd3aeefda808cd8fbffa 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
@@ -1116,6 +1116,10 @@ public class GwtAstBuilder {
                 scope.enclosingSourceType().enclosingTypeAt(
                     (x.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
             receiver = makeThisReference(info, targetType, true, scope);
+          } else if (x.receiver.sourceStart == 0) {
+            // Synthetic this ref with bad source info; fix the info.
+            JThisRef oldRef = (JThisRef) receiver;
+            receiver = new JThisRef(info, oldRef.getClassType());
           }
         }

@@ -1991,25 +1995,32 @@ public class GwtAstBuilder {
      * arguments, but with a different type signature.
      */
private void createBridgeMethod(SyntheticMethodBinding jdtBridgeMethod) {
-      JMethod implMethod = typeMap.get(jdtBridgeMethod.targetMethod);
-      SourceInfo info = implMethod.getSourceInfo();
-      String[] paramNames = null;
-      List<JParameter> implParams = implMethod.getParams();
-      if (jdtBridgeMethod.parameters != null) {
-        int paramCount = implParams.size();
-        assert paramCount == jdtBridgeMethod.parameters.length;
-        paramNames = new String[paramCount];
-        for (int i = 0; i < paramCount; ++i) {
-          paramNames[i] = implParams.get(i).getName();
-        }
-      }
- JMethod bridgeMethod = createSynthicMethodFromBinding(info, jdtBridgeMethod, paramNames);
-      if (implMethod.isFinal()) {
-        bridgeMethod.setFinal();
-      }
+      JMethod implmeth = typeMap.get(jdtBridgeMethod.targetMethod);
+      SourceInfo info = implmeth.getSourceInfo();
+      JMethod bridgeMethod =
+          new JMethod(info, implmeth.getName(), curClass.type, typeMap
+ .get(jdtBridgeMethod.returnType), false, false, implmeth.isFinal(), false);
+      typeMap.setMethod(jdtBridgeMethod, bridgeMethod);
+      bridgeMethod.setBody(new JMethodBody(info));
+      curClass.type.addMethod(bridgeMethod);
+      bridgeMethod.setSynthetic();
+      int paramIdx = 0;
+      List<JParameter> implParams = implmeth.getParams();
+      for (TypeBinding jdtParamType : jdtBridgeMethod.parameters) {
+        JParameter param = implParams.get(paramIdx++);
+        JType paramType = typeMap.get(jdtParamType.erasure());
+        JParameter newParam =
+ new JParameter(param.getSourceInfo(), param.getName(), paramType, true, false,
+                bridgeMethod);
+        bridgeMethod.addParam(newParam);
+      }
+ for (ReferenceBinding exceptionReference : jdtBridgeMethod.thrownExceptions) { + bridgeMethod.addThrownException((JClassType) typeMap.get(exceptionReference.erasure()));
+      }
+      bridgeMethod.freezeParamTypes();

       // create a call and pass all arguments through, casting if necessary
- JMethodCall call = new JMethodCall(info, makeThisRef(info), implMethod); + JMethodCall call = new JMethodCall(info, makeThisRef(info), implmeth);
       for (int i = 0; i < bridgeMethod.getParams().size(); i++) {
         JParameter param = bridgeMethod.getParams().get(i);
         JParameterRef paramRef = new JParameterRef(info, param);


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

Reply via email to