Revision: 10229
Author:   [email protected]
Date:     Thu May 26 06:00:55 2011
Log:      Misc GWT compiler bugfixes and cleanups.

http://gwt-code-reviews.appspot.com/1452802/

http://code.google.com/p/google-web-toolkit/source/detail?r=10229

Modified:
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JConstructor.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JStringLiteral.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ReferenceMapper.java
 /trunk/dev/core/src/com/google/gwt/dev/util/collect/Lists.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java Tue Apr 19 10:10:18 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java Thu May 26 06:00:55 2011
@@ -33,9 +33,7 @@
     }

     private Object readResolve() {
- JClassType result = new JClassType(SourceOrigin.UNKNOWN, name, false, false);
-      result.setExternal(true);
-      return result;
+      return new JClassType(name);
     }
   }

@@ -48,6 +46,15 @@
     this.isAbstract = isAbstract;
     this.isFinal = isFinal;
   }
+
+  /**
+   * Construct a bare-bones deserialized external class.
+   */
+  private JClassType(String name) {
+    super(SourceOrigin.UNKNOWN, name);
+    isAbstract = false;
+    setExternal(true);
+  }

   @Override
   public String getClassLiteralFactoryMethod() {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JConstructor.java Tue Apr 19 10:10:18 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JConstructor.java Thu May 26 06:00:55 2011
@@ -128,7 +128,7 @@

   @Override
   protected Object writeReplace() {
-    if (getEnclosingType() != null && getEnclosingType().isExternal()) {
+    if (isExternal()) {
       return new ExternalSerializedForm(this);
     } else {
       return this;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java Fri May 13 08:44:36 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java Thu May 26 06:00:55 2011
@@ -122,6 +122,10 @@
   public boolean isCompileTimeConstant() {
     return isCompileTimeConstant;
   }
+
+  public boolean isExternal() {
+    return getEnclosingType() != null && getEnclosingType().isExternal();
+  }

   public boolean isStatic() {
     return isStatic;
@@ -162,7 +166,7 @@
   }

   protected Object writeReplace() {
-    if (enclosingType != null && enclosingType.isExternal()) {
+    if (isExternal()) {
       return new ExternalSerializedForm(this);
     } else if (this == NULL_FIELD) {
       return ExternalSerializedNullField.INSTANCE;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java Tue Apr 19 10:10:18 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java Thu May 26 06:00:55 2011
@@ -27,11 +27,6 @@
    */
   private final JDeclaredType enclosingType;

-  /**
-   * The referenced field.
-   */
-  private final JField field;
-
   /**
    * This can only be null if the referenced field is static.
    */
@@ -54,7 +49,6 @@
     assert (instance != null || field.isStatic());
     assert (enclosingType != null);
     this.instance = instance;
-    this.field = field;
     this.enclosingType = enclosingType;
     this.overriddenType = overriddenType;
   }
@@ -64,7 +58,7 @@
   }

   public JField getField() {
-    return field;
+    return (JField) getTarget();
   }

   public JExpression getInstance() {
@@ -80,6 +74,7 @@
   }

   public boolean hasClinit() {
+    JField field = getField();
// A cross-class reference to a static, non constant field forces clinit
     if (!field.isStatic()) {
       return false;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java Wed Apr 27 14:46:52 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java Thu May 26 06:00:55 2011
@@ -38,7 +38,7 @@
     JConstructor noArgCtor = null;
     for (JMethod ctor : classType.getMethods()) {
       if (ctor instanceof JConstructor) {
-        if (ctor.getParams().size() == 0) {
+        if (ctor.getOriginalParamTypes().size() == 0) {
           noArgCtor = (JConstructor) ctor;
           break;
         }
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java Tue Apr 19 07:13:00 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java Thu May 26 06:00:55 2011
@@ -33,15 +33,21 @@
     }

     private Object readResolve() {
- JInterfaceType result = new JInterfaceType(SourceOrigin.UNKNOWN, name);
-      result.setExternal(true);
-      return result;
+      return new JInterfaceType(name);
     }
   }

   public JInterfaceType(SourceInfo info, String name) {
     super(info, name);
   }
+
+  /**
+   * Construct a bare-bones deserialized external interface.
+   */
+  private JInterfaceType(String name) {
+    super(SourceOrigin.UNKNOWN, name);
+    setExternal(true);
+  }

   @Override
   public String getClassLiteralFactoryMethod() {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java Fri May 13 08:44:36 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java Thu May 26 06:00:55 2011
@@ -47,11 +47,7 @@
     }

     private Object readResolve() {
-      String name = signature.substring(0, signature.indexOf('('));
-      JMethod result =
- new JMethod(SourceOrigin.UNKNOWN, name, enclosingType, null, false, false, false, false);
-      result.signature = signature;
-      return result;
+      return new JMethod(signature, enclosingType);
     }
   }

@@ -123,6 +119,19 @@
     this.isFinal = isFinal;
     this.isPrivate = isPrivate;
   }
+
+  /**
+   * Construct a bare-bones deserialized external method.
+   */
+  private JMethod(String signature, JDeclaredType enclosingType) {
+    super(SourceOrigin.UNKNOWN);
+    this.name = signature.substring(0, signature.indexOf('('));
+    this.enclosingType = enclosingType;
+    this.signature = signature;
+    this.isAbstract = false;
+    this.isStatic = false;
+    this.isPrivate = false;
+  }

   /**
    * Add a method that this method overrides.
@@ -173,7 +182,7 @@
   }

   public JAbstractMethodBody getBody() {
- assert !enclosingType.isExternal() : "External types do not have method bodies.";
+    assert !isExternal() : "External types do not have method bodies.";
     return body;
   }

@@ -233,6 +242,10 @@
   public boolean isAbstract() {
     return isAbstract;
   }
+
+  public boolean isExternal() {
+    return getEnclosingType() != null && getEnclosingType().isExternal();
+  }

   public boolean isFinal() {
     return isFinal;
@@ -366,7 +379,7 @@
   }

   protected Object writeReplace() {
-    if (enclosingType != null && enclosingType.isExternal()) {
+    if (isExternal()) {
       return new ExternalSerializedForm(this);
     } else if (this == NULL_METHOD) {
       return ExternalSerializedNullMethod.INSTANCE;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JStringLiteral.java Tue Apr 19 10:10:18 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JStringLiteral.java Thu May 26 06:00:55 2011
@@ -29,6 +29,7 @@
     super(sourceInfo);
     this.value = value;
     this.stringType = stringType;
+    assert stringType.getName().equals("java.lang.String");
   }

   @Override
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java Tue Apr 19 10:10:18 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java Thu May 26 06:00:55 2011
@@ -281,7 +281,7 @@
         method = (JMethod) typeMap.get(referenceMethod.binding);
       }
       assert !method.isNative() && !method.isAbstract();
- return (JMethodBody) (method.getEnclosingType().isExternal() ? null : method.getBody());
+      return (JMethodBody) (method.isExternal() ? null : method.getBody());
     }

private SourceInfo makeSourceInfo(AbstractMethodDeclaration methodDecl, HasSourceInfo enclosing) {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Fri May 13 08:44:36 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Thu May 26 06:00:55 2011
@@ -448,7 +448,7 @@
           op = JBinaryOperator.SHRU;
           break;
         case OperatorIds.PLUS:
-          if (x.resolvedType instanceof ReferenceBinding) {
+          if (javaLangString == typeMap.get(x.resolvedType)) {
             op = JBinaryOperator.CONCAT;
           } else {
             op = JBinaryOperator.ADD;
@@ -578,7 +578,7 @@
       JBinaryOperator op;
       switch (x.operator) {
         case OperatorIds.PLUS:
-          if (x.resolvedType instanceof ReferenceBinding) {
+          if (javaLangString == typeMap.get(x.resolvedType)) {
             op = JBinaryOperator.ASG_CONCAT;
           } else {
             op = JBinaryOperator.ASG_ADD;
@@ -1542,7 +1542,7 @@
     public boolean visit(ConstructorDeclaration x, ClassScope scope) {
       try {
         JConstructor method = (JConstructor) typeMap.get(x.binding);
-        assert !method.getEnclosingType().isExternal();
+        assert !method.isExternal();
         JMethodBody body = new JMethodBody(method.getSourceInfo());
         method.setBody(body);
         pushMethodInfo(new MethodInfo(method, body, x.scope));
@@ -1606,7 +1606,7 @@
     @Override
     public boolean visit(FieldDeclaration x, MethodScope scope) {
       try {
-        assert !typeMap.get(x.binding).getEnclosingType().isExternal();
+        assert !typeMap.get(x.binding).isExternal();
         pushInitializerMethodInfo(x, scope);
         return true;
       } catch (Throwable e) {
@@ -1663,7 +1663,7 @@
     public boolean visit(MethodDeclaration x, ClassScope scope) {
       try {
         JMethod method = typeMap.get(x.binding);
-        assert !method.getEnclosingType().isExternal();
+        assert !method.isExternal();
         JMethodBody body = null;
         if (!method.isNative()) {
           body = new JMethodBody(method.getSourceInfo());
@@ -3170,7 +3170,7 @@
private JMethod createSynthicMethodFromBinding(SourceInfo info, MethodBinding binding,
       String[] paramNames) {
     JMethod method = typeMap.createMethod(info, binding, paramNames);
-    assert !method.getEnclosingType().isExternal();
+    assert !method.isExternal();
     method.setBody(new JMethodBody(info));
     typeMap.setMethod(binding, method);
     return method;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java Fri May 13 08:44:36 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java Thu May 26 06:00:55 2011
@@ -110,6 +110,7 @@
     this.typeClassLiteralHolder = program.getTypeClassLiteralHolder();
     this.classLiteralHolderClinitBody =
         (JMethodBody) typeClassLiteralHolder.getMethods().get(0).getBody();
+    assert program.getDeclaredTypes().contains(typeClassLiteralHolder);
   }

   /**
@@ -217,17 +218,19 @@
         JMethod valuesMethod = null;
         JMethod valueOfMethod = null;
         for (JMethod methodIt : enumType.getMethods()) {
-          if ("values".equals(methodIt.getName())) {
-            if (methodIt.getParams().size() != 0) {
-              continue;
-            }
-            valuesMethod = methodIt;
-          } else if ("valueOf".equals(methodIt.getName())) {
-            if (methodIt.getParams().size() != 1
- || methodIt.getParams().get(0).getType() != program.getTypeJavaLangString()) {
-              continue;
-            }
-            valueOfMethod = methodIt;
+          if (methodIt.isStatic()) {
+            if ("values".equals(methodIt.getName())) {
+              if (methodIt.getOriginalParamTypes().size() != 0) {
+                continue;
+              }
+              valuesMethod = methodIt;
+            } else if ("valueOf".equals(methodIt.getName())) {
+              if (methodIt.getOriginalParamTypes().size() != 1
+ || methodIt.getOriginalParamTypes().get(0) != program.getTypeJavaLangString()) {
+                continue;
+              }
+              valueOfMethod = methodIt;
+            }
           }
         }
         if (valuesMethod == null) {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java Tue May 24 12:34:23 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java Thu May 26 06:00:55 2011
@@ -233,13 +233,11 @@
     public void endVisit(JMethodCall x, Context ctx) {
       JMethod method = x.getTarget();

-      if (method.getEnclosingType() != null) {
-        if (method.getEnclosingType().isExternal()) {
- // Staticifying a method requires modifying the type, which we can't - // do for external types. Theoretically we could put the static method
-          // in some generated code, but what does that really buy us?
-          return;
-        }
+      if (method.isExternal()) {
+ // Staticifying a method requires modifying the type, which we can't + // do for external types. Theoretically we could put the static method
+        // in some generated code, but what does that really buy us?
+        return;
       }

       // Did we already do this one?
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ReferenceMapper.java Tue Apr 19 07:13:00 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ReferenceMapper.java Thu May 26 06:00:55 2011
@@ -30,6 +30,7 @@
 import com.google.gwt.dev.jjs.ast.JNullType;
 import com.google.gwt.dev.jjs.ast.JParameter;
 import com.google.gwt.dev.jjs.ast.JPrimitiveType;
+import com.google.gwt.dev.jjs.ast.JReferenceType;
 import com.google.gwt.dev.jjs.ast.JType;
 import com.google.gwt.dev.util.StringInterner;

@@ -58,7 +59,7 @@
private final Map<String, JMethod> methods = new HashMap<String, JMethod>(); private final Map<String, JField> sourceFields = new HashMap<String, JField>(); private final Map<String, JMethod> sourceMethods = new HashMap<String, JMethod>(); - private final Map<String, JDeclaredType> sourceTypes = new HashMap<String, JDeclaredType>(); + private final Map<String, JReferenceType> sourceTypes = new HashMap<String, JReferenceType>();
   private final StringInterner stringInterner = StringInterner.get();
   private final Map<String, JType> types = new HashMap<String, JType>();

@@ -79,13 +80,13 @@
     String key = signature(binding);
     JField sourceField = sourceFields.get(key);
     if (sourceField != null) {
-      assert !sourceField.getEnclosingType().isExternal();
+      assert !sourceField.isExternal();
       return sourceField;
     }
     JField field = fields.get(key);
     if (field == null) {
       field = createField(binding);
-      assert field.getEnclosingType().isExternal();
+      assert field.isExternal();
       fields.put(key, field);
     }
     return field;
@@ -96,7 +97,7 @@
     String key = signature(binding);
     JMethod sourceMethod = sourceMethods.get(key);
     if (sourceMethod != null) {
-      assert !sourceMethod.getEnclosingType().isExternal();
+      assert !sourceMethod.isExternal();
       return sourceMethod;
     }
     JMethod method = methods.get(key);
@@ -106,7 +107,7 @@
       } else {
         method = createMethod(SourceOrigin.UNKNOWN, binding, null);
       }
-      assert method.getEnclosingType().isExternal();
+      assert method.isExternal();
       methods.put(key, method);
     }
     return method;
@@ -115,47 +116,54 @@
   public JType get(TypeBinding binding) {
     binding = binding.erasure();
     String key = signature(binding);
-    JDeclaredType sourceType = sourceTypes.get(key);
+    JReferenceType sourceType = sourceTypes.get(key);
     if (sourceType != null) {
       assert !sourceType.isExternal();
       return sourceType;
     }
+
     JType type = types.get(key);
-    if (type == null) {
-      assert !(binding instanceof BaseTypeBinding);
-      if (binding instanceof ArrayBinding) {
-        ArrayBinding arrayBinding = (ArrayBinding) binding;
-        type = new JArrayType(get(arrayBinding.elementsType()));
+    if (type != null) {
+ assert type instanceof JPrimitiveType || type == JNullType.INSTANCE | | type.isExternal();
+      return type;
+    }
+    assert !(binding instanceof BaseTypeBinding);
+
+    if (binding instanceof ArrayBinding) {
+      ArrayBinding arrayBinding = (ArrayBinding) binding;
+ JArrayType arrayType = new JArrayType(get(arrayBinding.elementsType()));
+      if (arrayType.isExternal()) {
+        types.put(key, arrayType);
       } else {
-        ReferenceBinding refBinding = (ReferenceBinding) binding;
-        type = createType(refBinding);
-        if (type instanceof JClassType) {
-          ReferenceBinding superclass = refBinding.superclass();
-          if (superclass != null) {
- ((JClassType) type).setSuperClass((JClassType) get(superclass));
-          }
-        }
-        if (type instanceof JDeclaredType) {
- ReferenceBinding[] superInterfaces = refBinding.superInterfaces();
-          JDeclaredType declType = (JDeclaredType) type;
-          if (superInterfaces != null) {
-            for (ReferenceBinding intf : superInterfaces) {
-              declType.addImplements((JInterfaceType) get(intf));
-            }
-          }
-          declType.setExternal(true);
-          // Emulate clinit method for super clinit calls.
-          JMethod clinit =
- new JMethod(SourceOrigin.UNKNOWN, "$clinit", declType, JPrimitiveType.VOID, false,
-                  true, true, true);
-          clinit.freezeParamTypes();
-          clinit.setSynthetic();
-          declType.addMethod(clinit);
+        sourceTypes.put(key, arrayType);
+      }
+      return arrayType;
+    } else {
+      ReferenceBinding refBinding = (ReferenceBinding) binding;
+      JDeclaredType declType = createType(refBinding);
+      if (declType instanceof JClassType) {
+        ReferenceBinding superclass = refBinding.superclass();
+        if (superclass != null) {
+ ((JClassType) declType).setSuperClass((JClassType) get(superclass));
+        }
+      }
+      ReferenceBinding[] superInterfaces = refBinding.superInterfaces();
+      if (superInterfaces != null) {
+        for (ReferenceBinding intf : superInterfaces) {
+          declType.addImplements((JInterfaceType) get(intf));
         }
       }
-      types.put(key, type);
-    }
-    return type;
+      // Emulate clinit method for super clinit calls.
+      JMethod clinit =
+ new JMethod(SourceOrigin.UNKNOWN, "$clinit", declType, JPrimitiveType.VOID, false, true,
+              true, true);
+      clinit.freezeParamTypes();
+      clinit.setSynthetic();
+      declType.addMethod(clinit);
+      declType.setExternal(true);
+      types.put(key, declType);
+      return declType;
+    }
   }

   public void setField(FieldBinding binding, JField field) {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/util/collect/Lists.java Wed Aug 18 12:45:57 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/util/collect/Lists.java Thu May 26 06:00:55 2011
@@ -179,8 +179,10 @@

   public static <T> List<T> create(Collection<T> collection) {
     switch (collection.size()) {
-      case 0 :
+      case 0:
         return create();
+      case 1:
+        return create(collection.iterator().next());
       default:
         return new ArrayList<T>(collection);
     }

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

Reply via email to