Author: [EMAIL PROTECTED]
Date: Mon Sep  8 13:25:47 2008
New Revision: 3627

Modified:
     
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
     
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
     
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/js/ast/JsProgram.java

Log:
Updates ControlFlowAnalyzer to track liveness of string literals.

Modified:  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
==============================================================================
---  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
    
(original)
+++  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
    
Mon Sep  8 13:25:47 2008
@@ -20,10 +20,16 @@
  import com.google.gwt.dev.jjs.ast.JAbstractMethodBody;
  import com.google.gwt.dev.jjs.ast.JProgram;
  import com.google.gwt.dev.jjs.ast.JVisitor;
+import com.google.gwt.dev.js.ast.JsContext;
+import com.google.gwt.dev.js.ast.JsExpression;
  import com.google.gwt.dev.js.ast.JsFunction;
+import com.google.gwt.dev.js.ast.JsStringLiteral;
+import com.google.gwt.dev.js.ast.JsVisitor;

  import java.util.ArrayList;
+import java.util.HashSet;
  import java.util.List;
+import java.util.Set;

  /**
   * Represents a the body of a method. Can be Java or JSNI.
@@ -31,8 +37,8 @@
  public class JsniMethodBody extends JAbstractMethodBody {

    public final List<JsniFieldRef> jsniFieldRefs = new  
ArrayList<JsniFieldRef>();
-
    public final List<JsniMethodRef> jsniMethodRefs = new  
ArrayList<JsniMethodRef>();
+  private final Set<String> stringLiterals = new HashSet<String>();

    private JsFunction jsFunction = null;

@@ -44,7 +50,12 @@
      assert (this.jsFunction != null);
      return jsFunction;
    }
+
+  public Set<String> getUsedStrings() {
+    return stringLiterals;
+  }

+  @Override
    public boolean isNative() {
      return true;
    }
@@ -52,6 +63,13 @@
    public void setFunc(JsFunction jsFunction) {
      assert (this.jsFunction == null);
      this.jsFunction = jsFunction;
+    class RecordStrings extends JsVisitor {
+      @Override
+      public void endVisit(JsStringLiteral lit,  JsContext<JsExpression>  
ctx) {
+        stringLiterals.add(lit.getValue());
+      }
+    }
+    (new RecordStrings()).accept(jsFunction);
    }

    public void traverse(JVisitor visitor, Context ctx) {

Modified:  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
==============================================================================
---  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
         
(original)
+++  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
         
Mon Sep  8 13:25:47 2008
@@ -345,6 +345,12 @@
        // JsniFieldRef rescues as JFieldRef
        return visit((JFieldRef) x, ctx);
      }
+
+    @Override
+    public boolean visit(JsniMethodBody body, Context ctx) {
+      liveStrings.addAll(body.getUsedStrings());
+      return true;
+    }

      @Override
      public boolean visit(JsniMethodRef x, Context ctx) {
@@ -375,6 +381,8 @@

      @Override
      public boolean visit(JStringLiteral literal, Context ctx) {
+      liveStrings.add(literal.getValue());
+
        // rescue and instantiate java.lang.String
        rescue(program.getTypeJavaLangString(), true, true);
        return true;
@@ -560,6 +568,7 @@
    private final RescueVisitor rescuer = new RescueVisitor();
    private JMethod stringValueOfChar = null;
    private final UpRefVisitor upRefer = new UpRefVisitor();
+  private Set<String> liveStrings = new HashSet<String>();

    public ControlFlowAnalyzer(JProgram program) {
      this.program = program;
@@ -576,6 +585,7 @@
      clone.liveFieldsAndMethods = new HashSet<JNode>(liveFieldsAndMethods);
      clone.referencedTypes = new HashSet<JReferenceType>(referencedTypes);
      clone.stringValueOfChar = stringValueOfChar;
+    clone.liveStrings = new HashSet<String>(liveStrings);
      return clone;
    }

@@ -643,5 +653,9 @@
      do {
        upRefer.accept(program);
      } while (upRefer.didRescue());
+  }
+
+  public Set<String> getLiveStrings() {
+    return liveStrings;
    }
  }

Modified:  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/js/ast/JsProgram.java
==============================================================================
---  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/js/ast/JsProgram.java    
 
(original)
+++  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/js/ast/JsProgram.java    
 
Mon Sep  8 13:25:47 2008
@@ -132,6 +132,11 @@
      return topScope;
    }

+  /**
+   * Note: This is currently assumed not to be called after
+   * GenerateJavaScriptAST has finished. If it ever is, then GWT.runAsync  
needs
+   * to be updated to account for such string literals.
+   */
    public JsStringLiteral getStringLiteral(String value) {
      JsStringLiteral lit = stringLiteralMap.get(value);
      if (lit == null) {

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

Reply via email to