Revision: 10361
Author: [email protected]
Date: Tue Jun 21 08:09:05 2011
Log: Improve GwtAstBuilder output when stack emulation is enabled.
Fixes a couple of places where GwtAstBuilder output is significantly
different from the current output.
http://gwt-code-reviews.appspot.com/1460801/
http://code.google.com/p/google-web-toolkit/source/detail?r=10361
Modified:
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
Tue Jun 7 11:03:06 2011
+++
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
Tue Jun 21 08:09:05 2011
@@ -157,6 +157,7 @@
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 @@
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 @@
@Override
public void endVisit(JProgram x, Context ctx) {
- Collections.sort(x.getEntryMethods(), hasNameSort);
+ Collections.sort(x.getEntryMethods(), methodSort);
Collections.sort(x.getDeclaredTypes(), hasNameSort);
}
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Tue
Jun 14 15:18:26 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Tue
Jun 21 08:09:05 2011
@@ -1116,6 +1116,10 @@
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 @@
* 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);
@@ -3032,13 +3043,13 @@
binding.getExactMethod(VALUE_OF, new
TypeBinding[]{x.scope.getJavaLangString()},
curCud.scope);
assert valueOfBinding != null;
- createSynthicMethodFromBinding(info, valueOfBinding, new
String[]{"name"});
+ createSyntheticMethodFromBinding(info, valueOfBinding, new
String[]{"name"});
}
{
assert type.getMethods().size() == 4;
MethodBinding valuesBinding = binding.getExactMethod(VALUES,
NO_TYPES, curCud.scope);
assert valuesBinding != null;
- createSynthicMethodFromBinding(info, valuesBinding, null);
+ createSyntheticMethodFromBinding(info, valuesBinding, null);
}
}
@@ -3181,7 +3192,7 @@
return method;
}
- private JMethod createSynthicMethodFromBinding(SourceInfo info,
MethodBinding binding,
+ private JMethod createSyntheticMethodFromBinding(SourceInfo info,
MethodBinding binding,
String[] paramNames) {
JMethod method = typeMap.createMethod(info, binding, paramNames);
assert !method.isExternal();
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors