Author: [EMAIL PROTECTED]
Date: Tue Sep 16 19:18:10 2008
New Revision: 3659

Modified:
     
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
     
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
     
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/JavaToJavaScriptMap.java

Log:
Improves the map between Java methods and JavaScript functions
for instance methods.

Modified:  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
==============================================================================
---  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
         
(original)
+++  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
         
Tue Sep 16 19:18:10 2008
@@ -585,6 +585,10 @@
      }

      JavaToJavaScriptMap postStringInterningMap = new JavaToJavaScriptMap()  
{
+      public JsName nameForType(JReferenceType type) {
+        return map.nameForType(type);
+      }
+
        public JMethod nameToMethod(JsName name) {
          return map.nameToMethod(name);
        }
@@ -595,6 +599,10 @@

        public JReferenceType typeForStat(JsStatement stat) {
          return map.typeForStat(stat);
+      }
+
+      public JMethod vtableInitToMethod(JsStatement stat) {
+        return map.vtableInitToMethod(stat);
        }
      };


Modified:  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
==============================================================================
---  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
       
(original)
+++  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
       
Tue Sep 16 19:18:10 2008
@@ -316,8 +316,8 @@
        } else {
          // create a new peer JsFunction
          jsFunction = new JsFunction(topScope, globalName, true);
-        methodBodyMap.put(x.getBody(), jsFunction);
        }
+      methodBodyMap.put(x.getBody(), jsFunction);
        push(jsFunction.getScope());
        return true;
      }
@@ -518,7 +518,6 @@
                  + " does belong in a fragment";
              JsExprStmt funcStmt = func.makeStmt();
              globalStmts.add(funcStmt);
-            typeForStatMap.put(funcStmt, x);
            }
          }
        }
@@ -1556,7 +1555,7 @@
            JsExpression asg = createAssignment(lhs, rhs);
            JsExprStmt asgStat = new JsExprStmt(asg);
            globalStmts.add(asgStat);
-          typeForStatMap.put(asgStat, x);
+          vtableInitForMethodMap.put(asgStat, method);
          }
        }
      }
@@ -1740,6 +1739,8 @@
      return generateJavaScriptAST.execImpl();
    }

+  public Map<JsStatement, JMethod> vtableInitForMethodMap = new  
HashMap<JsStatement, JMethod>();
+
    private final Map<JBlock, JsCatch> catchMap = new  
IdentityHashMap<JBlock, JsCatch>();

    private final Map<JClassType, JsScope> classScopes = new  
IdentityHashMap<JClassType, JsScope>();
@@ -1749,6 +1750,7 @@
     * clinit).
     */
    private Set<JMethod> crossClassTargets = new HashSet<JMethod>();
+
    /**
     * Contains JsNames for all interface methods. A special scope is needed  
so
     * that independent classes will obfuscate their interface implementation
@@ -1762,12 +1764,11 @@
     * Sorted to avoid nondeterministic iteration.
     */
    private final Map<Long, JsName> longLits = new TreeMap<Long, JsName>();
-
    private final Map<JsName, JsExpression> longObjects = new  
IdentityHashMap<JsName, JsExpression>();
    private final Map<JAbstractMethodBody, JsFunction> methodBodyMap = new  
IdentityHashMap<JAbstractMethodBody, JsFunction>();
    private final Map<HasName, JsName> names = new IdentityHashMap<HasName,  
JsName>();
-  private JsName nullMethodName;

+  private JsName nullMethodName;
    /**
     * Contains JsNames for the Object instance methods, such as equals,  
hashCode,
     * and toString. All other class scopes have this scope as an ultimate  
parent.
@@ -1798,6 +1799,7 @@
     * Contains JsNames for all globals, such as static fields and methods.
     */
    private final JsScope topScope;
+
    private final Map<JsStatement, JReferenceType> typeForStatMap = new  
HashMap<JsStatement, JReferenceType>();

    private final JTypeOracle typeOracle;
@@ -1950,7 +1952,14 @@
        }
      }

+    // TODO(spoon): avoid capturing a reference to GenerateJavaScriptAST;  
that's
+    // wasteful of memory.
      return new JavaToJavaScriptMap() {
+      public JsName nameForType(JReferenceType type) {
+        // TODO(spoon): use a smaller map than this whole thing
+        return names.get(type);
+      }
+
        public JMethod nameToMethod(JsName name) {
          return nameToMethodMap.get(name);
        }
@@ -1965,6 +1974,10 @@

        public JReferenceType typeForStat(JsStatement stat) {
          return typeForStatMap.get(stat);
+      }
+
+      public JMethod vtableInitToMethod(JsStatement stat) {
+        return vtableInitForMethodMap.get(stat);
        }
      };
    }

Modified:  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/JavaToJavaScriptMap.java
==============================================================================
---  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/JavaToJavaScriptMap.java
         
(original)
+++  
changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/JavaToJavaScriptMap.java
         
Tue Sep 16 19:18:10 2008
@@ -21,12 +21,35 @@
  import com.google.gwt.dev.js.ast.JsStatement;

  /**
- * A map from chunks of Java to chunks of JavaScript.
+ * A map between chunks of JavaScript to chunks of Java.
   */
  public interface JavaToJavaScriptMap {
+  /**
+   * Return the JavaScript name corresponding to a Java type.
+   */
+  JsName nameForType(JReferenceType type);
+
+  /**
+   * If <code>name</code> is the name of a function that corresponds to a  
Java
+   * method, then return that method. Otherwise, return null.
+   */
    JMethod nameToMethod(JsName name);

+  /**
+   * If <code>var</code> is the name of the variable used to hold an  
interned
+   * string literal, then return the string it interns. Otherwise, return  
null.
+   */
    String stringLiteralForName(JsName var);
-
+
+  /**
+   * If <code>stat</code> is used to set up the definition of some class,
+   * return that class. Otherwise, return null.
+   */
    JReferenceType typeForStat(JsStatement stat);
+
+  /**
+   * If <code>stat</code> is used to set up a vtable entry for a method,
+   * then return that method.  Otherwise return null.
+   */
+  JMethod vtableInitToMethod(JsStatement stat);
  }

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

Reply via email to