Revision: 10171
Author: [email protected]
Date: Tue May 10 05:59:20 2011
Log: Remove JProgram.jsniMap in favor of local accounting.
http://gwt-code-reviews.appspot.com/1445801/
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=10171
Added:
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniClassLiteral.java
Modified:
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
/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/Pruner.java
=======================================
--- /dev/null
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniClassLiteral.java
Tue May 10 05:59:20 2011
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.dev.jjs.ast.js;
+
+import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.ast.JClassLiteral;
+import com.google.gwt.dev.jjs.ast.JType;
+
+/**
+ * JSNI reference to a Java class literal.
+ */
+public class JsniClassLiteral extends JClassLiteral {
+
+ private final String ident;
+
+ public JsniClassLiteral(SourceInfo info, String ident, JType type) {
+ super(info, type);
+ this.ident = ident;
+ }
+
+ public String getIdent() {
+ return ident;
+ }
+}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java Tue Apr 19
10:10:18 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java Tue May 10
05:59:20 2011
@@ -311,8 +311,6 @@
*/
public final List<List<JMethod>> entryMethods = new
ArrayList<List<JMethod>>();
- public final Map<String, JNode> jsniMap = new HashMap<String, JNode>();
-
public final JTypeOracle typeOracle = new JTypeOracle(this);
/**
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
Thu Mar 3 14:34:14 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
Tue May 10 05:59:20 2011
@@ -18,7 +18,6 @@
import com.google.gwt.dev.jjs.SourceInfo;
import com.google.gwt.dev.jjs.ast.Context;
import com.google.gwt.dev.jjs.ast.JAbstractMethodBody;
-import com.google.gwt.dev.jjs.ast.JClassLiteral;
import com.google.gwt.dev.jjs.ast.JVisitor;
import com.google.gwt.dev.js.ast.JsContext;
import com.google.gwt.dev.js.ast.JsFunction;
@@ -37,7 +36,7 @@
*/
public class JsniMethodBody extends JAbstractMethodBody {
- private List<JClassLiteral> classRefs = Collections.emptyList();
+ private List<JsniClassLiteral> classRefs = Collections.emptyList();
private JsFunction jsFunction = null;
private List<JsniFieldRef> jsniFieldRefs = Collections.emptyList();
private List<JsniMethodRef> jsniMethodRefs = Collections.emptyList();
@@ -51,7 +50,7 @@
/**
* Adds a reference from this method to a Java class literal.
*/
- public void addClassRef(JClassLiteral ref) {
+ public void addClassRef(JsniClassLiteral ref) {
classRefs = Lists.add(classRefs, ref);
}
@@ -72,7 +71,7 @@
/**
* Return this method's references to Java class literals.
*/
- public List<JClassLiteral> getClassRefs() {
+ public List<JsniClassLiteral> getClassRefs() {
return classRefs;
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
Thu May 5 06:03:58 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
Tue May 10 05:59:20 2011
@@ -90,6 +90,7 @@
import com.google.gwt.dev.jjs.ast.JVariable;
import com.google.gwt.dev.jjs.ast.JVariableRef;
import com.google.gwt.dev.jjs.ast.JWhileStatement;
+import com.google.gwt.dev.jjs.ast.js.JsniClassLiteral;
import com.google.gwt.dev.jjs.ast.js.JsniFieldRef;
import com.google.gwt.dev.jjs.ast.js.JsniMethodBody;
import com.google.gwt.dev.jjs.ast.js.JsniMethodRef;
@@ -2843,8 +2844,9 @@
});
}
- private void processClassLiteral(JClassLiteral classLiteral,
JsContext ctx) {
+ private void processClassLiteral(JsNameRef nameRef, SourceInfo info,
JType type, JsContext ctx) {
assert !ctx.isLvalue();
+ JsniClassLiteral classLiteral = new JsniClassLiteral(info,
nameRef.getIdent(), type);
nativeMethodBody.addClassRef(classLiteral);
}
@@ -2885,24 +2887,21 @@
// TODO: make this tighter when we have real source info
// JSourceInfo info = translateInfo(nameRef.getInfo());
String ident = nameRef.getIdent();
- JNode node = program.jsniMap.get(ident);
+ JNode node = jsniMap.get(ident);
if (node == null) {
node = findJsniRefTarget(info, ident);
if (node == null) {
return; // already reported error
}
- if (node instanceof JType) {
- node = new JClassLiteral(info.makeChild(), (JType) node);
- }
- program.jsniMap.put(ident, node);
+ jsniMap.put(ident, node);
}
if (node instanceof JField) {
processField(nameRef, info, (JField) node, ctx);
} else if (node instanceof JMethod) {
processMethod(nameRef, info, (JMethod) node, ctx);
- } else if (node instanceof JClassLiteral) {
- processClassLiteral((JClassLiteral) node, ctx);
+ } else if (node instanceof JType) {
+ processClassLiteral(nameRef, info, (JType) node, ctx);
} else {
throw new InternalCompilerException(node,
"JSNI reference to something other than a class, field, or
method?", null);
@@ -2912,6 +2911,8 @@
private JDeclaredType currentClass;
+ private final Map<String, JNode> jsniMap = new HashMap<String,
JNode>();
+
private final Map<JsniMethodBody, AbstractMethodDeclaration>
jsniMethodMap;
private final JProgram program;
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
Thu May 5 06:03:58 2011
+++
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
Tue May 10 05:59:20 2011
@@ -86,6 +86,8 @@
import com.google.gwt.dev.jjs.ast.JVisitor;
import com.google.gwt.dev.jjs.ast.JWhileStatement;
import com.google.gwt.dev.jjs.ast.js.JMultiExpression;
+import com.google.gwt.dev.jjs.ast.js.JsniClassLiteral;
+import com.google.gwt.dev.jjs.ast.js.JsniFieldRef;
import com.google.gwt.dev.jjs.ast.js.JsniMethodBody;
import com.google.gwt.dev.jjs.ast.js.JsniMethodRef;
import com.google.gwt.dev.jjs.ast.js.JsonArray;
@@ -1312,6 +1314,17 @@
@Override
public boolean visit(JsniMethodBody x, Context ctx) {
+ final Map<String, JNode> jsniMap = new HashMap<String, JNode>();
+ for (JsniClassLiteral ref : x.getClassRefs()) {
+ jsniMap.put(ref.getIdent(), ref.getField());
+ }
+ for (JsniFieldRef ref : x.getJsniFieldRefs()) {
+ jsniMap.put(ref.getIdent(), ref.getField());
+ }
+ for (JsniMethodRef ref : x.getJsniMethodRefs()) {
+ jsniMap.put(ref.getIdent(), ref.getTarget());
+ }
+
final JsFunction jsFunc = x.getFunc();
// replace all JSNI idents with a real JsName now that we know it
@@ -1331,7 +1344,7 @@
JsNameRef ref = (JsNameRef) x.getQualifier();
String ident = ref.getIdent();
if (isJsniIdent(ident)) {
- JNode node = program.jsniMap.get(ident);
+ JNode node = jsniMap.get(ident);
assert node instanceof JConstructor;
assert ref.getQualifier() == null;
JsName jsName = names.get(node);
@@ -1348,12 +1361,8 @@
public void endVisit(JsNameRef x, JsContext ctx) {
String ident = x.getIdent();
if (isJsniIdent(ident)) {
- JNode node = program.jsniMap.get(ident);
+ JNode node = jsniMap.get(ident);
assert (node != null);
- if (node instanceof JClassLiteral) {
- node = ((JClassLiteral) node).getField();
- assert node != null;
- }
if (node instanceof JField) {
JField field = (JField) node;
JsName jsName = names.get(field);
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Tue
Apr 19 10:10:18 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Tue
May 10 05:59:20 2011
@@ -88,6 +88,7 @@
import com.google.gwt.dev.jjs.ast.JUnaryOperator;
import com.google.gwt.dev.jjs.ast.JVariable;
import com.google.gwt.dev.jjs.ast.JWhileStatement;
+import com.google.gwt.dev.jjs.ast.js.JsniClassLiteral;
import com.google.gwt.dev.jjs.ast.js.JsniFieldRef;
import com.google.gwt.dev.jjs.ast.js.JsniMethodBody;
import com.google.gwt.dev.jjs.ast.js.JsniMethodRef;
@@ -232,9 +233,6 @@
/**
* Resolves local references to function parameters, and JSNI
references.
- *
- * TODO: move more error reporting to
- * {@link com.google.gwt.dev.javac.JsniChecker}.
*/
private class JsniResolver extends JsModVisitor {
private final JsniMethodBody nativeMethodBody;
@@ -253,7 +251,7 @@
assert ident.startsWith("@null::");
} else if (binding instanceof TypeBinding) {
JType type = typeMap.get((TypeBinding) binding);
- processClassLiteral(type, info, ctx);
+ processClassLiteral(x, info, type, ctx);
} else if (binding instanceof FieldBinding) {
JField field = typeMap.get((FieldBinding) binding);
processField(x, info, field, ctx);
@@ -264,9 +262,9 @@
}
}
- private void processClassLiteral(JType type, SourceInfo info,
JsContext ctx) {
+ private void processClassLiteral(JsNameRef nameRef, SourceInfo info,
JType type, JsContext ctx) {
assert !ctx.isLvalue();
- JClassLiteral classLiteral = new JClassLiteral(info, type);
+ JsniClassLiteral classLiteral = new JsniClassLiteral(info,
nameRef.getIdent(), type);
nativeMethodBody.addClassRef(classLiteral);
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java Thu May 5
06:03:58 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java Tue May 10
05:59:20 2011
@@ -209,7 +209,6 @@
if (isPruned(x.getField())) {
String ident = x.getIdent();
JField nullField = program.getNullField();
- program.jsniMap.put(ident, nullField);
JsniFieldRef nullFieldRef =
new JsniFieldRef(x.getSourceInfo(), ident, nullField,
x.getEnclosingType(), x
.isLvalue());
@@ -223,7 +222,6 @@
if (isPruned(x.getTarget())) {
String ident = x.getIdent();
JMethod nullMethod = program.getNullMethod();
- program.jsniMap.put(ident, nullMethod);
JsniMethodRef nullMethodRef =
new JsniMethodRef(x.getSourceInfo(), ident, nullMethod,
program.getJavaScriptObject());
ctx.replaceMe(nullMethodRef);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors