Revision: 7310
Author: [email protected]
Date: Mon Dec 14 10:59:09 2009
Log: ExpressionAnalyzer fix for clinit field refs.

Fixes a bug in ExpressionAnalyzer were clinit-triggering field refs were  
not being considered.  This could cause bugs in the inliner where clinits  
would be dropped.

Found by: spoon
Review by: spoon
http://code.google.com/p/google-web-toolkit/source/detail?r=7310

Modified:
  /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ExpressionAnalyzer.java
   
/trunk/dev/core/test/com/google/gwt/dev/jjs/impl/ExpressionAnalyzerTest.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ExpressionAnalyzer.java     
 
Wed Mar 26 23:49:10 2008
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ExpressionAnalyzer.java     
 
Mon Dec 14 10:59:09 2009
@@ -129,6 +129,10 @@
      if (!x.getTarget().isFinal()) {
        accessesFieldNonFinal = true;
      }
+
+    if (x.hasClinit()) {
+      recordMethodCall();
+    }

      JExpression instance = x.getInstance();
      if (instance == null) {
@@ -159,15 +163,7 @@

    @Override
    public void endVisit(JMethodCall x, Context ctx) {
-    /*
-     * We can't assume anything about method calls right now, except that  
it
-     * can't assign to one of our locals or one of our parameters. It's  
possible
-     * that it could read from a field, assign to a field or throw an  
exception
-     * that we can't see.
-     */
-    assignmentToField = true;
-    accessesField = true;
-    canThrowException = true;
+    recordMethodCall();
    }

    @Override
@@ -297,4 +293,19 @@
        assignmentToLocal = true;
      }
    }
-}
+
+  /**
+   * We can't assume anything about method calls right now, except that it  
can't
+   * access any of our locals or parameters.
+   *
+   * TODO: what about accessing arrays? Should be treated like field refs I
+   * guess.
+   */
+  private void recordMethodCall() {
+    assignmentToField = true;
+    accessesField = true;
+    accessesFieldNonFinal = true;
+    canThrowException = true;
+    createsObject = true;
+  }
+}
=======================================
---  
/trunk/dev/core/test/com/google/gwt/dev/jjs/impl/ExpressionAnalyzerTest.java    
 
Wed Oct 28 09:10:53 2009
+++  
/trunk/dev/core/test/com/google/gwt/dev/jjs/impl/ExpressionAnalyzerTest.java    
 
Mon Dec 14 10:59:09 2009
@@ -115,6 +115,22 @@
    public void testEmpty() throws Exception {
      analyzeExpression("int", "0").check();
    }
+
+  public void testFieldAccessClinit() throws Exception {
+    sourceOracle.addOrReplace(new MockJavaResource("test.Foo") {
+      @Override
+      protected CharSequence getContent() {
+        StringBuffer code = new StringBuffer();
+        code.append("package test;\n");
+        code.append("public class Foo {\n");
+        code.append("  static final boolean value = trueMethod();");
+        code.append("  static boolean trueMethod() { return true; }");
+        code.append("}\n");
+        return code;
+      }
+    });
+     
analyzeExpression("boolean", 
"Foo.value").accessesFieldNonFinal().canThrowException().createsObject().hasAssignmentToField().check();
+  }

    public void testFieldAccessInstance() throws Exception {
      sourceOracle.addOrReplace(new MockJavaResource("test.Foo") {

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

Reply via email to