Removes JProgram reference from all nodes (and their constructors).
- Saves memory (4 bytes for every AST node) and is also much cleaner
- In the future it will enable serialization/deserialization to be decoupled
This required changing up a few spots where we really needed the JProgram ref in the past:
- JFieldRefs needed to answer whether they triggerd a clinit via cross-class static ref. This is reimplemented by keeping the state within each class type instead of in JTypeOracle. JTypeOracle recomputes the state and updates individual class types before each optimization pass.
- Primitive types, literals, and a few other singleton-type things are now true singletons
- JConditionals now have an explicit type that gets updated by TypeTightener (instead of always being recomputed on-the-fly)
Review by: spoon
Suggestions by: spoon
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5202 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
index 5244774..4ad8fe6 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
@@ -419,6 +419,7 @@
typeMap = null;
allTypeDeclarations = null;
+ Memory.maybeDumpMemory("AstOnly");
maybeDumpAST(jprogram);
// (3) Perform Java AST normalizations.
@@ -620,8 +621,8 @@
}
private static JMethodCall createReboundModuleLoad(TreeLogger logger,
- JProgram program, JReferenceType reboundEntryType,
- String originalMainClassName) throws UnableToCompleteException {
+ JReferenceType reboundEntryType, String originalMainClassName)
+ throws UnableToCompleteException {
if (!(reboundEntryType instanceof JClassType)) {
logger.log(TreeLogger.ERROR, "Module entry point class '"
+ originalMainClassName + "' must be a class", null);
@@ -654,7 +655,7 @@
JExpression qualifier = null;
if (!entryMethod.isStatic()) {
- qualifier = JGwtCreate.createInstantiationExpression(program, sourceInfo,
+ qualifier = JGwtCreate.createInstantiationExpression(sourceInfo,
entryClass);
if (qualifier == null) {
@@ -667,7 +668,7 @@
throw new UnableToCompleteException();
}
}
- return new JMethodCall(program, sourceInfo, qualifier, entryMethod);
+ return new JMethodCall(sourceInfo, qualifier, entryMethod);
}
private static void findEntryPoints(TreeLogger logger,
@@ -695,8 +696,7 @@
JMethod mainMethod = findMainMethod(mainType);
if (mainMethod != null && mainMethod.isStatic()) {
- JMethodCall onModuleLoadCall = new JMethodCall(program, null, null,
- mainMethod);
+ JMethodCall onModuleLoadCall = new JMethodCall(null, null, mainMethod);
block.addStmt(onModuleLoadCall.makeStatement());
continue;
}
@@ -715,7 +715,7 @@
throw new UnableToCompleteException();
}
- JMethodCall onModuleLoadCall = createReboundModuleLoad(logger, program,
+ JMethodCall onModuleLoadCall = createReboundModuleLoad(logger,
resultType, mainClassName);
resultTypes.add((JClassType) resultType);
entryCalls.add(onModuleLoadCall);
@@ -723,8 +723,8 @@
if (resultTypes.size() == 1) {
block.addStmt(entryCalls.get(0).makeStatement());
} else {
- JReboundEntryPoint reboundEntryPoint = new JReboundEntryPoint(program,
- null, mainType, resultTypes, entryCalls);
+ JReboundEntryPoint reboundEntryPoint = new JReboundEntryPoint(null,
+ mainType, resultTypes, entryCalls);
block.addStmt(reboundEntryPoint);
}
}
@@ -811,13 +811,13 @@
JMethod isStatsAvailableMethod = program.getIndexedMethod("Stats.isStatsAvailable");
JMethod onModuleStartMethod = program.getIndexedMethod("Stats.onModuleStart");
- JMethodCall availableCall = new JMethodCall(program, sourceInfo, null,
+ JMethodCall availableCall = new JMethodCall(sourceInfo, null,
isStatsAvailableMethod);
- JMethodCall onModuleStartCall = new JMethodCall(program, sourceInfo, null,
+ JMethodCall onModuleStartCall = new JMethodCall(sourceInfo, null,
onModuleStartMethod);
onModuleStartCall.addArg(program.getLiteralString(sourceInfo, mainClassName));
- JBinaryOperation amp = new JBinaryOperation(program, sourceInfo,
+ JBinaryOperation amp = new JBinaryOperation(sourceInfo,
program.getTypePrimitiveBoolean(), JBinaryOperator.AND, availableCall,
onModuleStartCall);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/SourceOrigin.java b/dev/core/src/com/google/gwt/dev/jjs/SourceOrigin.java
index e2722bd..65e10b0 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/SourceOrigin.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/SourceOrigin.java
@@ -57,7 +57,11 @@
}
}
- public static final SourceInfo UNKNOWN = new SourceOrigin("Unknown", 0);
+ public static final SourceInfo UNKNOWN = new SourceOrigin("Unknown", 0) {
+ private Object readResolve() {
+ return UNKNOWN;
+ }
+ };
/**
* Cache to reuse recently-created origins. This is very useful for JS nodes,
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JAbsentArrayDimension.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JAbsentArrayDimension.java
index e4cff33..29d7659 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JAbsentArrayDimension.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JAbsentArrayDimension.java
@@ -16,6 +16,7 @@
package com.google.gwt.dev.jjs.ast;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.SourceOrigin;
/**
* Represents an array dimension that was not specified in an array
@@ -23,15 +24,18 @@
*/
public class JAbsentArrayDimension extends JLiteral {
+ public static final JExpression INSTANCE = new JAbsentArrayDimension(
+ SourceOrigin.UNKNOWN);
+
/**
* These are only supposed to be constructed by JProgram.
*/
- JAbsentArrayDimension(JProgram program, SourceInfo sourceInfo) {
- super(program, sourceInfo);
+ JAbsentArrayDimension(SourceInfo sourceInfo) {
+ super(sourceInfo);
}
public JType getType() {
- return program.getTypeVoid();
+ return JPrimitiveType.VOID;
}
public void traverse(JVisitor visitor, Context ctx) {
@@ -40,4 +44,7 @@
visitor.endVisit(this, ctx);
}
+ private Object readResolve() {
+ return INSTANCE;
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JAbstractMethodBody.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JAbstractMethodBody.java
index dc2405f..5ef9145 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JAbstractMethodBody.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JAbstractMethodBody.java
@@ -23,8 +23,8 @@
public abstract class JAbstractMethodBody extends JNode {
protected JMethod method;
- protected JAbstractMethodBody(JProgram program, SourceInfo info) {
- super(program, info);
+ protected JAbstractMethodBody(SourceInfo info) {
+ super(info);
}
public JMethod getMethod() {
@@ -34,6 +34,6 @@
public abstract boolean isNative();
public void setMethod(JMethod method) {
- this.method = method;
+ this.method = method;
}
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayRef.java
index c6d368a..8d8e469 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayRef.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayRef.java
@@ -25,9 +25,8 @@
private JExpression instance;
private JExpression indexExpr;
- public JArrayRef(JProgram program, SourceInfo info, JExpression instance,
- JExpression indexExpr) {
- super(program, info);
+ public JArrayRef(SourceInfo info, JExpression instance, JExpression indexExpr) {
+ super(info);
this.instance = instance;
this.indexExpr = indexExpr;
}
@@ -42,23 +41,17 @@
public JType getType() {
JType type = instance.getType();
- JNullType typeNull = program.getTypeNull();
- if (type == typeNull) {
- return typeNull;
+ if (type instanceof JNullType) {
+ return JNullType.INSTANCE;
}
JArrayType arrayType = (JArrayType) type;
- JType elementType = arrayType.getElementType();
- if (elementType instanceof JReferenceType
- && !program.typeOracle.isInstantiatedType((JReferenceType) elementType)) {
- return typeNull;
- }
- return elementType;
+ return arrayType.getElementType();
}
public boolean hasSideEffects() {
// TODO: make the last test better when we have null tracking.
return instance.hasSideEffects() || indexExpr.hasSideEffects()
- || instance.getType() == program.getTypeNull();
+ || instance.getType() == JNullType.INSTANCE;
}
public void traverse(JVisitor visitor, Context ctx) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java
index 67869ad..4bf5750 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java
@@ -29,14 +29,16 @@
}
private int dims;
+ private JType elementType;
private JType leafType;
/**
* These are only supposed to be constructed by JProgram.
*/
- JArrayType(JProgram program, JType leafType, int dims) {
- super(program, leafType.getSourceInfo().makeChild(JArrayType.class,
- "Array type"), calcName(leafType, dims), false, false);
+ JArrayType(JType elementType, JType leafType, int dims) {
+ super(leafType.getSourceInfo().makeChild(JArrayType.class, "Array type"),
+ calcName(leafType, dims), false, false);
+ this.elementType = elementType;
this.leafType = leafType;
this.dims = dims;
}
@@ -51,10 +53,7 @@
}
public JType getElementType() {
- if (dims == 1) {
- return leafType;
- }
- return program.getTypeArray(leafType, dims - 1);
+ return elementType;
}
public String getJavahSignatureName() {
@@ -72,11 +71,16 @@
}
return s;
}
-
+
public JType getLeafType() {
return leafType;
}
+ @Override
+ public boolean hasClinit() {
+ return false;
+ }
+
public boolean isAbstract() {
return false;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JAssertStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JAssertStatement.java
index c459fcc..fbd2fcb 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JAssertStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JAssertStatement.java
@@ -25,9 +25,8 @@
private JExpression testExpr;
private JExpression arg;
- public JAssertStatement(JProgram program, SourceInfo info,
- JExpression testExpr, JExpression arg) {
- super(program, info);
+ public JAssertStatement(SourceInfo info, JExpression testExpr, JExpression arg) {
+ super(info);
this.testExpr = testExpr;
this.arg = arg;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JBinaryOperation.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JBinaryOperation.java
index 1694a80..54db51d 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JBinaryOperation.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JBinaryOperation.java
@@ -27,9 +27,9 @@
private JExpression rhs;
private JType type;
- public JBinaryOperation(JProgram program, SourceInfo info, JType type,
- JBinaryOperator op, JExpression lhs, JExpression rhs) {
- super(program, info);
+ public JBinaryOperation(SourceInfo info, JType type, JBinaryOperator op,
+ JExpression lhs, JExpression rhs) {
+ super(info);
this.op = op;
this.type = type;
this.lhs = lhs;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JBlock.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JBlock.java
index 42cfbd7..61aee39 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JBlock.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JBlock.java
@@ -28,8 +28,8 @@
private List<JStatement> statements = Collections.emptyList();
- public JBlock(JProgram program, SourceInfo info) {
- super(program, info);
+ public JBlock(SourceInfo info) {
+ super(info);
}
/**
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JBooleanLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JBooleanLiteral.java
index 34acce3..8e0142f 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JBooleanLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JBooleanLiteral.java
@@ -16,19 +16,27 @@
package com.google.gwt.dev.jjs.ast;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.SourceOrigin;
/**
* Java boolean literal expression.
*/
public class JBooleanLiteral extends JValueLiteral {
+ public static final JBooleanLiteral FALSE = new JBooleanLiteral(
+ SourceOrigin.UNKNOWN, false);
+
+ private static final JBooleanLiteral TRUE = new JBooleanLiteral(
+ SourceOrigin.UNKNOWN, true);
+
+ public static JBooleanLiteral get(boolean value) {
+ return value ? TRUE : FALSE;
+ }
+
private final boolean value;
- /**
- * These are only supposed to be constructed by JProgram.
- */
- JBooleanLiteral(JProgram program, SourceInfo sourceInfo, boolean value) {
- super(program, sourceInfo);
+ private JBooleanLiteral(SourceInfo sourceInfo, boolean value) {
+ super(sourceInfo);
this.value = value;
}
@@ -38,7 +46,7 @@
}
public JType getType() {
- return program.getTypePrimitiveBoolean();
+ return JPrimitiveType.BOOLEAN;
}
public boolean getValue() {
@@ -55,4 +63,7 @@
visitor.endVisit(this, ctx);
}
+ private Object readResolve() {
+ return get(value);
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JBreakStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JBreakStatement.java
index f67382a..62a2c94 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JBreakStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JBreakStatement.java
@@ -24,8 +24,8 @@
private final JLabel label;
- public JBreakStatement(JProgram program, SourceInfo info, JLabel label) {
- super(program, info);
+ public JBreakStatement(SourceInfo info, JLabel label) {
+ super(info);
this.label = label;
}
@@ -45,7 +45,7 @@
@Override
public boolean unconditionalControlBreak() {
// It's only an unconditional break if the label is null, because a label
- // can label the break statement itself! We could handle this case.
+ // can label the break statement itself! We could handle this case.
return label == null;
}
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JCaseStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JCaseStatement.java
index 72962f5..60d50d6 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JCaseStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JCaseStatement.java
@@ -24,8 +24,8 @@
private final JLiteral expr;
- public JCaseStatement(JProgram program, SourceInfo info, JLiteral expr) {
- super(program, info);
+ public JCaseStatement(SourceInfo info, JLiteral expr) {
+ super(info);
this.expr = expr;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JCastOperation.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JCastOperation.java
index 112c83b..40c3a3b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JCastOperation.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JCastOperation.java
@@ -25,9 +25,8 @@
private JExpression expr;
private final JType castType;
- public JCastOperation(JProgram program, SourceInfo info, JType castType,
- JExpression expr) {
- super(program, info);
+ public JCastOperation(SourceInfo info, JType castType, JExpression expr) {
+ super(info);
this.castType = castType;
this.expr = expr;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JCharLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JCharLiteral.java
index 361971d..8e4d9a5 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JCharLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JCharLiteral.java
@@ -16,19 +16,24 @@
package com.google.gwt.dev.jjs.ast;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.SourceOrigin;
/**
* Java character literal expression.
*/
public class JCharLiteral extends JValueLiteral {
+ public static final JCharLiteral NULL = new JCharLiteral(
+ SourceOrigin.UNKNOWN, (char) 0);
+
+ public static JCharLiteral get(char value) {
+ return (value == 0) ? NULL : new JCharLiteral(SourceOrigin.UNKNOWN, value);
+ }
+
private final char value;
- /**
- * These are only supposed to be constructed by JProgram.
- */
- JCharLiteral(JProgram program, SourceInfo sourceInfo, char value) {
- super(program, sourceInfo);
+ public JCharLiteral(SourceInfo sourceInfo, char value) {
+ super(sourceInfo);
this.value = value;
}
@@ -39,13 +44,13 @@
return value;
} else if (valueObj instanceof Number) {
Number number = (Number) valueObj;
- return program.getLiteralChar((char) number.intValue());
+ return new JCharLiteral(value.getSourceInfo(), (char) number.intValue());
}
return null;
}
public JType getType() {
- return program.getTypePrimitiveChar();
+ return JPrimitiveType.CHAR;
}
public char getValue() {
@@ -62,4 +67,7 @@
visitor.endVisit(this, ctx);
}
+ private Object readResolve() {
+ return (value == 0) ? NULL : this;
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
index afa5724..4bab76f 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
@@ -52,7 +52,7 @@
assert method != null;
- JMethodCall call = new JMethodCall(program, info, null, method);
+ JMethodCall call = new JMethodCall(info, null, method);
call.addArgs(program.getLiteralString(info, getPackageName(typeName)),
program.getLiteralString(info, getClassName(typeName)));
@@ -91,8 +91,8 @@
throw new InternalCompilerException(
"Could not find enum values() method");
}
- JsniMethodRef jsniMethodRef = new JsniMethodRef(program, info, null,
- valuesMethod);
+ JsniMethodRef jsniMethodRef = new JsniMethodRef(info, null,
+ valuesMethod, program.getJavaScriptObject());
call.addArg(jsniMethodRef);
} else if (isEnumOrSubclass) {
// A subclass of an enum class
@@ -142,9 +142,8 @@
/**
* This constructor is only used by {@link JProgram}.
*/
- JClassLiteral(JProgram program, SourceInfo sourceInfo, JType type,
- JField field) {
- super(program, sourceInfo);
+ JClassLiteral(SourceInfo sourceInfo, JType type, JField field) {
+ super(sourceInfo);
refType = type;
this.field = field;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java
index ebad0df..af7dd9a 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JClassType.java
@@ -25,9 +25,9 @@
private final boolean isAbstract;
private boolean isFinal;
- public JClassType(JProgram program, SourceInfo info, String name,
- boolean isAbstract, boolean isFinal) {
- super(program, info, name);
+ public JClassType(SourceInfo info, String name, boolean isAbstract,
+ boolean isFinal) {
+ super(info, name);
this.isAbstract = isAbstract;
this.isFinal = isFinal;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JConditional.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JConditional.java
index 74b2ebd..f474f25 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JConditional.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JConditional.java
@@ -20,16 +20,16 @@
/**
* Conditional expression.
*/
-public class JConditional extends JExpression {
+public class JConditional extends JExpression implements HasSettableType {
private JExpression elseExpr;
private JExpression ifTest;
private JExpression thenExpr;
- private final JType type;
+ private JType type;
- public JConditional(JProgram program, SourceInfo info, JType type,
- JExpression ifTest, JExpression thenExpr, JExpression elseExpr) {
- super(program, info);
+ public JConditional(SourceInfo info, JType type, JExpression ifTest,
+ JExpression thenExpr, JExpression elseExpr) {
+ super(info);
this.type = type;
this.ifTest = ifTest;
this.thenExpr = thenExpr;
@@ -49,13 +49,7 @@
}
public JType getType() {
- // TODO(later): allow multiple types for Type Flow?
- if (type instanceof JReferenceType) {
- return program.generalizeTypes((JReferenceType) thenExpr.getType(),
- (JReferenceType) elseExpr.getType());
- } else {
- return type;
- }
+ return type;
}
public boolean hasSideEffects() {
@@ -63,6 +57,10 @@
|| elseExpr.hasSideEffects();
}
+ public void setType(JType newType) {
+ type = newType;
+ }
+
public void traverse(JVisitor visitor, Context ctx) {
if (visitor.visit(this, ctx)) {
ifTest = visitor.accept(ifTest);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JContinueStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JContinueStatement.java
index 802c516..72d4956 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JContinueStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JContinueStatement.java
@@ -24,8 +24,8 @@
private final JLabel label;
- public JContinueStatement(JProgram program, SourceInfo info, JLabel label) {
- super(program, info);
+ public JContinueStatement(SourceInfo info, JLabel label) {
+ super(info);
this.label = label;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclarationStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclarationStatement.java
index b6fdb23..36b91ad 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclarationStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JDeclarationStatement.java
@@ -25,9 +25,9 @@
public JExpression initializer;
private JVariableRef variableRef;
- public JDeclarationStatement(JProgram program, SourceInfo info,
- JVariableRef variableRef, JExpression intializer) {
- super(program, info);
+ public JDeclarationStatement(SourceInfo info, JVariableRef variableRef,
+ JExpression intializer) {
+ super(info);
this.variableRef = variableRef;
this.initializer = intializer;
CanHaveInitializer variable = variableRef.getTarget();
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JDoStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JDoStatement.java
index d61b33a..1df4258 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JDoStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JDoStatement.java
@@ -25,9 +25,8 @@
private JStatement body;
private JExpression testExpr;
- public JDoStatement(JProgram program, SourceInfo info, JExpression testExpr,
- JStatement body) {
- super(program, info);
+ public JDoStatement(SourceInfo info, JExpression testExpr, JStatement body) {
+ super(info);
this.testExpr = testExpr;
this.body = body;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JDoubleLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JDoubleLiteral.java
index 2429c0e..6519cf2 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JDoubleLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JDoubleLiteral.java
@@ -16,19 +16,33 @@
package com.google.gwt.dev.jjs.ast;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.SourceOrigin;
/**
* Java double literal expression.
*/
public class JDoubleLiteral extends JValueLiteral {
- private final double value;
+ public static final JDoubleLiteral ZERO = new JDoubleLiteral(
+ SourceOrigin.UNKNOWN, Double.longBitsToDouble(0L));
+
+ public static JDoubleLiteral get(double value) {
+ return isZero(value) ? ZERO : new JDoubleLiteral(SourceOrigin.UNKNOWN,
+ value);
+ }
/**
- * These are only supposed to be constructed by JProgram.
+ * Does this value match the exact 0 bit pattern? (This precludes
+ * canonicalizing -0.0 as 0.0).
*/
- JDoubleLiteral(JProgram program, SourceInfo sourceInfo, double value) {
- super(program, sourceInfo);
+ private static boolean isZero(double value) {
+ return Double.doubleToRawLongBits(value) == 0L;
+ }
+
+ private final double value;
+
+ public JDoubleLiteral(SourceInfo sourceInfo, double value) {
+ super(sourceInfo);
this.value = value;
}
@@ -37,16 +51,16 @@
Object valueObj = value.getValueObj();
if (valueObj instanceof Character) {
Character character = (Character) valueObj;
- return program.getLiteralDouble(character.charValue());
+ return new JDoubleLiteral(value.getSourceInfo(), character.charValue());
} else if (valueObj instanceof Number) {
Number number = (Number) valueObj;
- return program.getLiteralDouble(number.doubleValue());
+ return new JDoubleLiteral(value.getSourceInfo(), number.doubleValue());
}
return null;
}
public JType getType() {
- return program.getTypePrimitiveDouble();
+ return JPrimitiveType.DOUBLE;
}
public double getValue() {
@@ -62,4 +76,8 @@
}
visitor.endVisit(this, ctx);
}
+
+ private Object readResolve() {
+ return isZero(value) ? ZERO : this;
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumField.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumField.java
index 3e3ebc9..4347df1 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumField.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumField.java
@@ -24,9 +24,9 @@
private int ordinal;
- public JEnumField(JProgram program, SourceInfo info, String name,
- int ordinal, JEnumType enclosingType, JClassType type) {
- super(program, info, name, enclosingType, type, true, Disposition.FINAL);
+ public JEnumField(SourceInfo info, String name, int ordinal,
+ JEnumType enclosingType, JClassType type) {
+ super(info, name, enclosingType, type, true, Disposition.FINAL);
this.ordinal = ordinal;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumType.java
index bcd5be9..8334c33 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JEnumType.java
@@ -30,9 +30,8 @@
public final List<JEnumField> enumList = new ArrayList<JEnumField>();
- public JEnumType(JProgram program, SourceInfo info, String name) {
- super(program, info, name, false, false);
- this.extnds = program.getTypeJavaLangEnum();
+ public JEnumType(SourceInfo info, String name) {
+ super(info, name, false, false);
}
@Override
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JExpression.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JExpression.java
index eee6c9a..985cda5 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JExpression.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JExpression.java
@@ -22,13 +22,13 @@
*/
public abstract class JExpression extends JNode implements HasType {
- public JExpression(JProgram program, SourceInfo info) {
- super(program, info);
+ public JExpression(SourceInfo info) {
+ super(info);
}
public abstract boolean hasSideEffects();
public JExpressionStatement makeStatement() {
- return new JExpressionStatement(program, getSourceInfo(), this);
+ return new JExpressionStatement(getSourceInfo(), this);
}
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JExpressionStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JExpressionStatement.java
index 6aa909c..27f5771 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JExpressionStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JExpressionStatement.java
@@ -27,9 +27,8 @@
/**
* Constructed via {@link JExpression#makeStatement()}.
*/
- JExpressionStatement(JProgram program, SourceInfo info,
- JExpression expr) {
- super(program, info);
+ JExpressionStatement(SourceInfo info, JExpression expr) {
+ super(info);
this.expr = expr;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java
index cede70d..ff63c3f 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java
@@ -47,10 +47,9 @@
private final boolean isStatic;
private boolean isVolatile;
- JField(JProgram program, SourceInfo info, String name,
- JReferenceType enclosingType, JType type, boolean isStatic,
- Disposition disposition) {
- super(program, info, name, type, disposition.isFinal());
+ JField(SourceInfo info, String name, JReferenceType enclosingType,
+ JType type, boolean isStatic, Disposition disposition) {
+ super(info, name, type, disposition.isFinal());
this.enclosingType = enclosingType;
this.isStatic = isStatic;
this.isCompileTimeConstant = disposition.isCompileTimeConstant();
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java
index c0b7118..1eda77b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java
@@ -39,20 +39,21 @@
/**
* An overridden type for this reference. Normally the type of a field
- * reference is the same as the type of the field itself. That default
- * can be overridden by setting this field.
+ * reference is the same as the type of the field itself. That default can be
+ * overridden by setting this field.
*/
private final JType overriddenType;
- public JFieldRef(JProgram program, SourceInfo info, JExpression instance,
- JField field, JReferenceType enclosingType) {
- this(program, info, instance, field, enclosingType, null);
+ public JFieldRef(SourceInfo info, JExpression instance, JField field,
+ JReferenceType enclosingType) {
+ this(info, instance, field, enclosingType, null);
}
-
- public JFieldRef(JProgram program, SourceInfo info, JExpression instance,
- JField field, JReferenceType enclosingType, JType overriddenType) {
- super(program, info, field);
+
+ public JFieldRef(SourceInfo info, JExpression instance, JField field,
+ JReferenceType enclosingType, JType overriddenType) {
+ super(info, field);
assert (instance != null || field.isStatic());
+ assert (enclosingType != null);
this.instance = instance;
this.field = field;
this.enclosingType = enclosingType;
@@ -70,7 +71,7 @@
public JExpression getInstance() {
return instance;
}
-
+
@Override
public JType getType() {
if (overriddenType != null) {
@@ -79,18 +80,22 @@
return super.getType();
}
+ public boolean hasClinit() {
+ // A cross-class reference to a static, non constant field forces clinit
+ if (!field.isStatic()) {
+ return false;
+ }
+ if (field.isFinal() && field.isCompileTimeConstant()) {
+ return false;
+ }
+ return getEnclosingType().checkClinitTo(field.getEnclosingType());
+ }
+
@Override
public boolean hasSideEffects() {
- // A cross-class reference to a static, non constant field forces clinit
- if (field.isStatic()
- && (!field.isFinal() || !field.isCompileTimeConstant())) {
- if (program.typeOracle.checkClinit(enclosingType,
- field.getEnclosingType())) {
- // Therefore, we have side effects
- return true;
- }
+ if (hasClinit()) {
+ return true;
}
-
JExpression expr = instance;
if (expr == null) {
return false;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JFloatLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JFloatLiteral.java
index 25efecc..a60f1aa 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JFloatLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JFloatLiteral.java
@@ -16,19 +16,33 @@
package com.google.gwt.dev.jjs.ast;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.SourceOrigin;
/**
* Java literal typed as a float.
*/
public class JFloatLiteral extends JValueLiteral {
- private final float value;
+ public static final JFloatLiteral ZERO = new JFloatLiteral(
+ SourceOrigin.UNKNOWN, Float.intBitsToFloat(0));
+
+ public static JFloatLiteral get(float value) {
+ return isZero(value) ? ZERO
+ : new JFloatLiteral(SourceOrigin.UNKNOWN, value);
+ }
/**
- * These are only supposed to be constructed by JProgram.
+ * Does this value match the exact 0 bit pattern? (This precludes
+ * canonicalizing -0.0 as 0.0).
*/
- JFloatLiteral(JProgram program, SourceInfo sourceInfo, float value) {
- super(program, sourceInfo);
+ private static boolean isZero(float value) {
+ return Float.floatToRawIntBits(value) == 0;
+ }
+
+ private final float value;
+
+ public JFloatLiteral(SourceInfo sourceInfo, float value) {
+ super(sourceInfo);
this.value = value;
}
@@ -37,16 +51,16 @@
Object valueObj = value.getValueObj();
if (valueObj instanceof Character) {
Character character = (Character) valueObj;
- return program.getLiteralFloat(character.charValue());
+ return new JFloatLiteral(value.getSourceInfo(), character.charValue());
} else if (valueObj instanceof Number) {
Number number = (Number) valueObj;
- return program.getLiteralFloat(number.floatValue());
+ return new JFloatLiteral(value.getSourceInfo(), number.floatValue());
}
return null;
}
public JType getType() {
- return program.getTypePrimitiveFloat();
+ return JPrimitiveType.FLOAT;
}
public float getValue() {
@@ -62,4 +76,8 @@
}
visitor.endVisit(this, ctx);
}
+
+ private Object readResolve() {
+ return isZero(value) ? ZERO : this;
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JForStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JForStatement.java
index 7437342..7121c8b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JForStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JForStatement.java
@@ -30,10 +30,10 @@
private List<JStatement> initializers;
private JExpression testExpr;
- public JForStatement(JProgram program, SourceInfo info,
- List<JStatement> initializers, JExpression testExpr,
- List<JExpressionStatement> increments, JStatement body) {
- super(program, info);
+ public JForStatement(SourceInfo info, List<JStatement> initializers,
+ JExpression testExpr, List<JExpressionStatement> increments,
+ JStatement body) {
+ super(info);
this.initializers = Lists.normalize(initializers);
this.testExpr = testExpr;
this.increments = Lists.normalize(increments);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java
index 52d2124..b3826ff 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JGwtCreate.java
@@ -27,8 +27,8 @@
*/
public class JGwtCreate extends JExpression implements HasSettableType {
- public static JExpression createInstantiationExpression(JProgram program,
- SourceInfo info, JClassType classType) {
+ public static JExpression createInstantiationExpression(SourceInfo info,
+ JClassType classType) {
/*
* Find the appropriate (noArg) constructor. In our AST, constructors are
* instance methods that should be qualified with a new expression.
@@ -46,15 +46,15 @@
return null;
}
// Call it, using a new expression as a qualifier
- JNewInstance newInstance = new JNewInstance(program, info, classType);
- return new JMethodCall(program, info, newInstance, noArgCtor);
+ JNewInstance newInstance = new JNewInstance(info, classType);
+ return new JMethodCall(info, newInstance, noArgCtor);
}
private static ArrayList<JExpression> createInstantiationExpressions(
- JProgram program, SourceInfo info, List<JClassType> classTypes) {
+ SourceInfo info, List<JClassType> classTypes) {
ArrayList<JExpression> exprs = new ArrayList<JExpression>();
for (JClassType classType : classTypes) {
- JExpression expr = createInstantiationExpression(program, info, classType);
+ JExpression expr = createInstantiationExpression(info, classType);
assert expr != null;
exprs.add(expr);
}
@@ -74,20 +74,19 @@
/**
* Public constructor used during AST creation.
*/
- public JGwtCreate(JProgram program, SourceInfo info,
- JReferenceType sourceType, List<JClassType> resultTypes) {
- this(program, info, sourceType, resultTypes,
- program.getTypeJavaLangObject(), createInstantiationExpressions(
- program, info, resultTypes));
+ public JGwtCreate(SourceInfo info, JReferenceType sourceType,
+ List<JClassType> resultTypes, JType type) {
+ this(info, sourceType, resultTypes, type, createInstantiationExpressions(
+ info, resultTypes));
}
/**
* Constructor used for cloning an existing node.
*/
- public JGwtCreate(JProgram program, SourceInfo info,
- JReferenceType sourceType, List<JClassType> resultTypes, JType type,
+ public JGwtCreate(SourceInfo info, JReferenceType sourceType,
+ List<JClassType> resultTypes, JType type,
ArrayList<JExpression> instantiationExpressions) {
- super(program, info);
+ super(info);
this.sourceType = sourceType;
this.resultTypes = resultTypes;
this.type = type;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JIfStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JIfStatement.java
index 604aa38..f616ec8 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JIfStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JIfStatement.java
@@ -26,9 +26,9 @@
private JExpression ifExpr;
private JStatement thenStmt;
- public JIfStatement(JProgram program, SourceInfo info, JExpression ifExpr,
- JStatement thenStmt, JStatement elseStmt) {
- super(program, info);
+ public JIfStatement(SourceInfo info, JExpression ifExpr, JStatement thenStmt,
+ JStatement elseStmt) {
+ super(info);
this.ifExpr = ifExpr;
this.thenStmt = thenStmt;
this.elseStmt = elseStmt;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JInstanceOf.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JInstanceOf.java
index 04154c2..35fe3be 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JInstanceOf.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JInstanceOf.java
@@ -25,9 +25,9 @@
private JExpression expr;
private final JReferenceType testType;
- public JInstanceOf(JProgram program, SourceInfo info,
- JReferenceType testType, JExpression expression) {
- super(program, info);
+ public JInstanceOf(SourceInfo info, JReferenceType testType,
+ JExpression expression) {
+ super(info);
this.testType = testType;
this.expr = expression;
}
@@ -41,7 +41,7 @@
}
public JType getType() {
- return program.getTypePrimitiveBoolean();
+ return JPrimitiveType.BOOLEAN;
}
public boolean hasSideEffects() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JIntLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JIntLiteral.java
index a502ffd..4d7d7a7 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JIntLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JIntLiteral.java
@@ -16,19 +16,24 @@
package com.google.gwt.dev.jjs.ast;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.SourceOrigin;
/**
* Java integer literal expression.
*/
public class JIntLiteral extends JValueLiteral {
+ public static final JIntLiteral ZERO = new JIntLiteral(SourceOrigin.UNKNOWN,
+ 0);
+
+ public static JIntLiteral get(int value) {
+ return (value == 0) ? ZERO : new JIntLiteral(SourceOrigin.UNKNOWN, value);
+ }
+
private final int value;
- /**
- * These are only supposed to be constructed by JProgram.
- */
- JIntLiteral(JProgram program, SourceInfo sourceInfo, int value) {
- super(program, sourceInfo);
+ public JIntLiteral(SourceInfo sourceInfo, int value) {
+ super(sourceInfo);
this.value = value;
}
@@ -37,16 +42,16 @@
Object valueObj = value.getValueObj();
if (valueObj instanceof Character) {
Character character = (Character) valueObj;
- return program.getLiteralInt(character.charValue());
+ return new JIntLiteral(value.getSourceInfo(), character.charValue());
} else if (valueObj instanceof Number) {
Number number = (Number) valueObj;
- return program.getLiteralInt(number.intValue());
+ return new JIntLiteral(value.getSourceInfo(), number.intValue());
}
return null;
}
public JType getType() {
- return program.getTypePrimitiveInt();
+ return JPrimitiveType.INT;
}
public int getValue() {
@@ -63,4 +68,7 @@
visitor.endVisit(this, ctx);
}
-}
+ private Object readResolve() {
+ return (value == 0) ? ZERO : this;
+ }
+}
\ No newline at end of file
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java
index 5a7c9da..ce4886c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JInterfaceType.java
@@ -22,8 +22,8 @@
*/
public class JInterfaceType extends JReferenceType {
- JInterfaceType(JProgram program, SourceInfo info, String name) {
- super(program, info, name);
+ JInterfaceType(SourceInfo info, String name) {
+ super(info, name);
}
@Override
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JLabel.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JLabel.java
index 83f9c40..40397ef 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JLabel.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JLabel.java
@@ -24,8 +24,8 @@
private final String name;
- public JLabel(JProgram program, SourceInfo info, String name) {
- super(program, info);
+ public JLabel(SourceInfo info, String name) {
+ super(info);
this.name = name;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JLabeledStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JLabeledStatement.java
index 308d51e..61b38b1 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JLabeledStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JLabeledStatement.java
@@ -25,9 +25,8 @@
private JStatement body;
private final JLabel label;
- public JLabeledStatement(JProgram program, SourceInfo info, JLabel label,
- JStatement body) {
- super(program, info);
+ public JLabeledStatement(SourceInfo info, JLabel label, JStatement body) {
+ super(info);
this.label = label;
this.body = body;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JLiteral.java
index 4798701..e67e247 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JLiteral.java
@@ -22,8 +22,8 @@
*/
public abstract class JLiteral extends JExpression {
- public JLiteral(JProgram program, SourceInfo sourceInfo) {
- super(program, sourceInfo);
+ public JLiteral(SourceInfo sourceInfo) {
+ super(sourceInfo);
}
public boolean hasSideEffects() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JLocal.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JLocal.java
index 8bcdd1e..413ac9c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JLocal.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JLocal.java
@@ -25,9 +25,9 @@
private final JMethodBody enclosingMethodBody;
- JLocal(JProgram program, SourceInfo info, String name, JType type,
- boolean isFinal, JMethodBody enclosingMethodBody) {
- super(program, info, name, type, isFinal);
+ JLocal(SourceInfo info, String name, JType type, boolean isFinal,
+ JMethodBody enclosingMethodBody) {
+ super(info, name, type, isFinal);
this.enclosingMethodBody = enclosingMethodBody;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JLocalRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JLocalRef.java
index b764d0c..196b8e6 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JLocalRef.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JLocalRef.java
@@ -27,8 +27,8 @@
*/
private JLocal local;
- public JLocalRef(JProgram program, SourceInfo info, JLocal local) {
- super(program, info, local);
+ public JLocalRef(SourceInfo info, JLocal local) {
+ super(info, local);
this.local = local;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JLongLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JLongLiteral.java
index 2e4a075..eff9ccb 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JLongLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JLongLiteral.java
@@ -16,19 +16,24 @@
package com.google.gwt.dev.jjs.ast;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.SourceOrigin;
/**
* Java literal expression that evaluates to a Long.
*/
public class JLongLiteral extends JValueLiteral {
+ public static final JLongLiteral ZERO = new JLongLiteral(
+ SourceOrigin.UNKNOWN, 0L);
+
+ public static JLongLiteral get(long value) {
+ return (value == 0) ? ZERO : new JLongLiteral(SourceOrigin.UNKNOWN, value);
+ }
+
private final long value;
- /**
- * These are only supposed to be constructed by JProgram.
- */
- JLongLiteral(JProgram program, SourceInfo sourceInfo, long value) {
- super(program, sourceInfo);
+ public JLongLiteral(SourceInfo sourceInfo, long value) {
+ super(sourceInfo);
this.value = value;
}
@@ -37,16 +42,16 @@
Object valueObj = value.getValueObj();
if (valueObj instanceof Character) {
Character character = (Character) valueObj;
- return program.getLiteralLong(character.charValue());
+ return new JLongLiteral(value.getSourceInfo(), character.charValue());
} else if (valueObj instanceof Number) {
Number number = (Number) valueObj;
- return program.getLiteralLong(number.longValue());
+ return new JLongLiteral(value.getSourceInfo(), number.longValue());
}
return null;
}
public JType getType() {
- return program.getTypePrimitiveLong();
+ return JPrimitiveType.LONG;
}
public long getValue() {
@@ -62,4 +67,8 @@
}
visitor.endVisit(this, ctx);
}
+
+ private Object readResolve() {
+ return (value == 0L) ? ZERO : this;
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
index 597d4be..97e2bfd 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
@@ -64,10 +64,10 @@
/**
* These are only supposed to be constructed by JProgram.
*/
- public JMethod(JProgram program, SourceInfo info, String name,
- JReferenceType enclosingType, JType returnType, boolean isAbstract,
- boolean isStatic, boolean isFinal, boolean isPrivate) {
- super(program, info);
+ public JMethod(SourceInfo info, String name, JReferenceType enclosingType,
+ JType returnType, boolean isAbstract, boolean isStatic, boolean isFinal,
+ boolean isPrivate) {
+ super(info);
this.name = name;
this.enclosingType = enclosingType;
this.returnType = returnType;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodBody.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodBody.java
index aa572f8..284a30c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodBody.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodBody.java
@@ -30,9 +30,9 @@
private JBlock block;
private List<JLocal> locals = Collections.emptyList();
- public JMethodBody(JProgram program, SourceInfo info) {
- super(program, info);
- block = new JBlock(program, info);
+ public JMethodBody(SourceInfo info) {
+ super(info);
+ block = new JBlock(info);
}
/**
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java
index 4602018..c27d5ab 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java
@@ -33,9 +33,8 @@
private final JType overrideReturnType;
private boolean staticDispatchOnly = false;
- public JMethodCall(JProgram program, SourceInfo info, JExpression instance,
- JMethod method) {
- super(program, info);
+ public JMethodCall(SourceInfo info, JExpression instance, JMethod method) {
+ super(info);
assert (method != null);
assert (instance != null || method.isStatic());
this.instance = instance;
@@ -44,9 +43,9 @@
this.overrideReturnType = null;
}
- public JMethodCall(JProgram program, SourceInfo info, JExpression instance,
- JMethod method, boolean staticDispatchOnly) {
- super(program, info);
+ public JMethodCall(SourceInfo info, JExpression instance, JMethod method,
+ boolean staticDispatchOnly) {
+ super(info);
this.instance = instance;
this.method = method;
this.staticDispatchOnly = staticDispatchOnly;
@@ -64,9 +63,9 @@
* allows us to preserve type information during the latter phases of
* compilation.
*/
- public JMethodCall(JProgram program, SourceInfo info, JExpression instance,
- JMethod method, JType overrideReturnType) {
- super(program, info);
+ public JMethodCall(SourceInfo info, JExpression instance, JMethod method,
+ JType overrideReturnType) {
+ super(info);
this.instance = instance;
this.method = method;
assert (overrideReturnType != null);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JNewArray.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JNewArray.java
index fbce11c..24de34a 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JNewArray.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JNewArray.java
@@ -45,15 +45,14 @@
classLiterals.add(classLit);
cur = ((JArrayType) cur).getElementType();
}
- return new JNewArray(program, info, arrayType, dims, null, classLiterals);
+ return new JNewArray(info, arrayType, dims, null, classLiterals);
}
public static JNewArray createInitializers(JProgram program, SourceInfo info,
JArrayType arrayType, List<JExpression> initializers) {
List<JClassLiteral> classLiterals = new ArrayList<JClassLiteral>();
classLiterals.add(program.getLiteralClass(arrayType));
- return new JNewArray(program, info, arrayType, null, initializers,
- classLiterals);
+ return new JNewArray(info, arrayType, null, initializers, classLiterals);
}
public final List<JExpression> dims;
@@ -67,10 +66,10 @@
*/
private final List<JClassLiteral> classLiterals;
- public JNewArray(JProgram program, SourceInfo info, JArrayType arrayType,
+ public JNewArray(SourceInfo info, JArrayType arrayType,
List<JExpression> dims, List<JExpression> initializers,
List<JClassLiteral> classLits) {
- super(program, info);
+ super(info);
this.arrayType = arrayType;
this.dims = dims;
this.initializers = initializers;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JNewInstance.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JNewInstance.java
index ac5772d..f8a11a1 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JNewInstance.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JNewInstance.java
@@ -26,8 +26,8 @@
private final JClassType classType;
- public JNewInstance(JProgram program, SourceInfo info, JClassType classType) {
- super(program, info);
+ public JNewInstance(SourceInfo info, JClassType classType) {
+ super(info);
this.classType = classType;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JNode.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JNode.java
index 5de8672..152b39b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JNode.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JNode.java
@@ -28,21 +28,11 @@
*/
public abstract class JNode implements JVisitable, HasSourceInfo, Serializable {
- protected final JProgram program;
private final SourceInfo info;
- protected JNode(JProgram program, SourceInfo info) {
+ protected JNode(SourceInfo info) {
assert info != null : "SourceInfo must be provided for JNodes";
this.info = info;
- if (program == null) {
- this.program = (JProgram) this;
- } else {
- this.program = program;
- }
- }
-
- public JProgram getProgram() {
- return program;
}
public SourceInfo getSourceInfo() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JNullLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JNullLiteral.java
index 6d9a8b2..29dcd5d 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JNullLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JNullLiteral.java
@@ -16,17 +16,18 @@
package com.google.gwt.dev.jjs.ast;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.SourceOrigin;
/**
* Java null literal expression.
*/
public class JNullLiteral extends JValueLiteral {
- /**
- * These are only supposed to be constructed by JProgram.
- */
- JNullLiteral(JProgram program, SourceInfo sourceInfo) {
- super(program, sourceInfo);
+ public static final JNullLiteral INSTANCE = new JNullLiteral(
+ SourceOrigin.UNKNOWN);
+
+ private JNullLiteral(SourceInfo sourceInfo) {
+ super(sourceInfo);
}
@Override
@@ -35,7 +36,7 @@
}
public JType getType() {
- return program.getTypeNull();
+ return JNullType.INSTANCE;
}
public Object getValueObj() {
@@ -47,4 +48,12 @@
}
visitor.endVisit(this, ctx);
}
+
+ /**
+ * Note, if this ever becomes not-a-singleton, we'll need to check the
+ * SourceInfo == SourceOrigin.UNKNOWN.
+ */
+ private Object readResolve() {
+ return INSTANCE;
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java
index 3f69adb..dc64ced 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java
@@ -17,19 +17,23 @@
import com.google.gwt.dev.jjs.InternalCompilerException;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.SourceOrigin;
/**
* Java null reference type.
*/
public class JNullType extends JReferenceType {
- public JNullType(JProgram program, SourceInfo sourceInfo) {
- super(program, sourceInfo, "<null>");
+ public static final JNullType INSTANCE = new JNullType(SourceOrigin.UNKNOWN);
+
+ private JNullType(SourceInfo sourceInfo) {
+ super(sourceInfo, "<null>");
}
@Override
public String getClassLiteralFactoryMethod() {
- throw new InternalCompilerException("Cannot get class literal for null type");
+ throw new InternalCompilerException(
+ "Cannot get class literal for null type");
}
public String getJavahSignatureName() {
@@ -40,6 +44,11 @@
return "N";
}
+ @Override
+ public boolean hasClinit() {
+ return false;
+ }
+
public boolean isAbstract() {
return false;
}
@@ -54,4 +63,7 @@
visitor.endVisit(this, ctx);
}
+ private Object readResolve() {
+ return INSTANCE;
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java
index f0b065b..f3c4971 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java
@@ -22,12 +22,25 @@
*/
public class JParameter extends JVariable implements HasEnclosingMethod {
+ public static JParameter create(SourceInfo info, String name, JType type,
+ boolean isFinal, boolean isThis, JMethod enclosingMethod) {
+ assert (name != null);
+ assert (type != null);
+ assert (enclosingMethod != null);
+
+ JParameter x = new JParameter(info, name, type, isFinal, isThis,
+ enclosingMethod);
+
+ enclosingMethod.addParam(x);
+ return x;
+ }
+
private final JMethod enclosingMethod;
private final boolean isThis;
- JParameter(JProgram program, SourceInfo info, String name, JType type,
- boolean isFinal, boolean isThis, JMethod enclosingMethod) {
- super(program, info, name, type, isFinal);
+ JParameter(SourceInfo info, String name, JType type, boolean isFinal,
+ boolean isThis, JMethod enclosingMethod) {
+ super(info, name, type, isFinal);
this.enclosingMethod = enclosingMethod;
this.isThis = isThis;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JParameterRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JParameterRef.java
index 9cbc2bc..f49b162 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JParameterRef.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JParameterRef.java
@@ -27,8 +27,8 @@
*/
private final JParameter param;
- public JParameterRef(JProgram program, SourceInfo info, JParameter param) {
- super(program, info, param);
+ public JParameterRef(SourceInfo info, JParameter param) {
+ super(info, param);
this.param = param;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JPostfixOperation.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JPostfixOperation.java
index a7c25d8..4a0955e 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JPostfixOperation.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JPostfixOperation.java
@@ -22,9 +22,8 @@
*/
public class JPostfixOperation extends JUnaryOperation {
- public JPostfixOperation(JProgram program, SourceInfo info,
- JUnaryOperator op, JExpression arg) {
- super(program, info, op, arg);
+ public JPostfixOperation(SourceInfo info, JUnaryOperator op, JExpression arg) {
+ super(info, op, arg);
}
public void traverse(JVisitor visitor, Context ctx) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JPrefixOperation.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JPrefixOperation.java
index 4130206..ecb7719 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JPrefixOperation.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JPrefixOperation.java
@@ -22,9 +22,8 @@
*/
public class JPrefixOperation extends JUnaryOperation {
- public JPrefixOperation(JProgram program, SourceInfo info,
- JUnaryOperator op, JExpression arg) {
- super(program, info, op, arg);
+ public JPrefixOperation(SourceInfo info, JUnaryOperator op, JExpression arg) {
+ super(info, op, arg);
}
public void traverse(JVisitor visitor, Context ctx) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JPrimitiveType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JPrimitiveType.java
index 903897c..bc97551 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JPrimitiveType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JPrimitiveType.java
@@ -15,23 +15,57 @@
*/
package com.google.gwt.dev.jjs.ast;
+import com.google.gwt.dev.jjs.SourceOrigin;
+import com.google.gwt.dev.util.collect.HashMap;
+
+import java.util.Map;
+
/**
* Base class for all Java primitive types.
*/
public class JPrimitiveType extends JType {
+ private static final class Singletons {
+ public static final Map<String, JPrimitiveType> map = new HashMap<String, JPrimitiveType>();
+ }
+
+ public static final JPrimitiveType BOOLEAN = new JPrimitiveType("boolean",
+ "Z", "java.lang.Boolean", JBooleanLiteral.FALSE);
+
+ public static final JPrimitiveType BYTE = new JPrimitiveType("byte", "B",
+ "java.lang.Byte", JIntLiteral.ZERO);
+
+ public static final JPrimitiveType CHAR = new JPrimitiveType("char", "C",
+ "java.lang.Character", JCharLiteral.NULL);
+
+ public static final JPrimitiveType DOUBLE = new JPrimitiveType("double", "D",
+ "java.lang.Double", JDoubleLiteral.ZERO);
+
+ public static final JPrimitiveType FLOAT = new JPrimitiveType("float", "F",
+ "java.lang.Float", JFloatLiteral.ZERO);
+
+ public static final JPrimitiveType INT = new JPrimitiveType("int", "I",
+ "java.lang.Integer", JIntLiteral.ZERO);
+
+ public static final JPrimitiveType LONG = new JPrimitiveType("long", "J",
+ "java.lang.Long", JLongLiteral.ZERO);
+
+ public static final JPrimitiveType SHORT = new JPrimitiveType("short", "S",
+ "java.lang.Short", JIntLiteral.ZERO);
+
+ public static final JPrimitiveType VOID = new JPrimitiveType("void", "V",
+ "java.lang.Void", null);
+
private final String signatureName;
+
private final String wrapperTypeName;
- /**
- * These are only supposed to be constructed by JProgram.
- */
- JPrimitiveType(JProgram program, String name, String signatureName,
+ private JPrimitiveType(String name, String signatureName,
String wrapperTypeName, JLiteral defaultValue) {
- super(program, program.createSourceInfoSynthetic(JPrimitiveType.class, name
- + " primitive type"), name, defaultValue);
+ super(SourceOrigin.UNKNOWN, name, defaultValue);
this.signatureName = signatureName;
this.wrapperTypeName = wrapperTypeName;
+ Singletons.map.put(name, this);
}
/**
@@ -74,4 +108,7 @@
visitor.endVisit(this, ctx);
}
+ private Object readResolve() {
+ return Singletons.map.get(name);
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
index 04f32c5..2f8b5ea 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
@@ -205,14 +205,6 @@
private List<JsonObject> jsonTypeTable;
- private final JAbsentArrayDimension literalAbsentArrayDim;
- private final JBooleanLiteral literalFalse;
- private final JIntLiteral literalIntNegOne;
- private final JIntLiteral literalIntOne;
- private final JIntLiteral literalIntZero;
- private final JNullLiteral literalNull;
- private final JBooleanLiteral literalTrue;
-
private JField nullField;
private JMethod nullMethod;
@@ -228,46 +220,26 @@
private final Map<JMethod, JMethod> staticToInstanceMap = new IdentityHashMap<JMethod, JMethod>();
- private final JPrimitiveType typeBoolean;
+ private final Map<String, JStringLiteral> stringLiteralMap = new HashMap<String, JStringLiteral>();
- private final JPrimitiveType typeByte;
-
- private final JPrimitiveType typeChar;
+ private final SourceInfo stringPoolSourceInfo;
private JClassType typeClass;
- private final JPrimitiveType typeDouble;
-
- private final JPrimitiveType typeFloat;
-
private Map<JClassType, Integer> typeIdMap = new HashMap<JClassType, Integer>();
- private final JPrimitiveType typeInt;
-
private JClassType typeJavaLangEnum;
private JClassType typeJavaLangObject;
- private final JPrimitiveType typeLong;
-
private final Map<String, JReferenceType> typeNameMap = new HashMap<String, JReferenceType>();
- private final JNullType typeNull;
-
- private final JPrimitiveType typeShort;
-
private JClassType typeSpecialClassLiteralHolder;
private JClassType typeSpecialJavaScriptObject;
private JClassType typeString;
- private final JPrimitiveType typeVoid;
-
- private final SourceInfo stringPoolSourceInfo;
-
- private final Map<String, JStringLiteral> stringLiteralMap = new HashMap<String, JStringLiteral>();
-
public JProgram() {
this(new CorrelationFactory.DummyCorrelationFactory());
}
@@ -281,61 +253,12 @@
* compilation cycle, but at a cost of memory and object allocations.
*/
public JProgram(CorrelationFactory correlator) {
- super(null, correlator.makeSourceInfo(SourceOrigin.create(0,
+ super(correlator.makeSourceInfo(SourceOrigin.create(0,
JProgram.class.getName())));
this.correlator = correlator;
intrinsic = createSourceInfo(0, getClass().getName());
- literalAbsentArrayDim = new JAbsentArrayDimension(this,
- createLiteralSourceInfo("Absent array dimension"));
-
- literalFalse = new JBooleanLiteral(this, createLiteralSourceInfo(
- "false literal", Literal.BOOLEAN), false);
-
- literalIntNegOne = new JIntLiteral(this, createLiteralSourceInfo(
- "-1 literal", Literal.INT), -1);
-
- literalIntOne = new JIntLiteral(this, createLiteralSourceInfo("1 literal",
- Literal.INT), 1);
-
- literalIntZero = new JIntLiteral(this, createLiteralSourceInfo("0 literal",
- Literal.INT), 0);
-
- literalNull = new JNullLiteral(this, createLiteralSourceInfo(
- "null literal", Literal.NULL));
-
- literalTrue = new JBooleanLiteral(this, createLiteralSourceInfo(
- "true literal", Literal.BOOLEAN), true);
-
- typeBoolean = new JPrimitiveType(this, "boolean", "Z", "java.lang.Boolean",
- literalFalse);
-
- typeByte = new JPrimitiveType(this, "byte", "B", "java.lang.Byte",
- literalIntZero);
-
- typeChar = new JPrimitiveType(this, "char", "C", "java.lang.Character",
- getLiteralChar((char) 0));
-
- typeDouble = new JPrimitiveType(this, "double", "D", "java.lang.Double",
- getLiteralDouble(0));
-
- typeFloat = new JPrimitiveType(this, "float", "F", "java.lang.Float",
- getLiteralFloat(0));
-
- typeInt = new JPrimitiveType(this, "int", "I", "java.lang.Integer",
- literalIntZero);
-
- typeLong = new JPrimitiveType(this, "long", "J", "java.lang.Long",
- getLiteralLong(0));
-
- typeNull = new JNullType(this, createLiteralSourceInfo("null type"));
-
- typeShort = new JPrimitiveType(this, "short", "S", "java.lang.Short",
- literalIntZero);
-
- typeVoid = new JPrimitiveType(this, "void", "V", "java.lang.Void", null);
-
stringPoolSourceInfo = createLiteralSourceInfo("String pool",
Literal.STRING);
}
@@ -369,7 +292,7 @@
*/
public JExpressionStatement createAssignmentStmt(SourceInfo info,
JExpression lhs, JExpression rhs) {
- JBinaryOperation assign = new JBinaryOperation(this, info, lhs.getType(),
+ JBinaryOperation assign = new JBinaryOperation(info, lhs.getType(),
JBinaryOperator.ASG, lhs, rhs);
return assign.makeStatement();
}
@@ -377,7 +300,7 @@
public JClassType createClass(SourceInfo info, char[][] name,
boolean isAbstract, boolean isFinal) {
String sname = dotify(name);
- JClassType x = new JClassType(this, info, sname, isAbstract, isFinal);
+ JClassType x = new JClassType(info, sname, isAbstract, isFinal);
allTypes.add(x);
putIntoTypeMap(sname, x);
@@ -407,7 +330,8 @@
public JEnumType createEnum(SourceInfo info, char[][] name) {
String sname = dotify(name);
- JEnumType x = new JEnumType(this, info, sname);
+ JEnumType x = new JEnumType(info, sname);
+ x.extnds = getTypeJavaLangEnum();
allTypes.add(x);
putIntoTypeMap(sname, x);
@@ -422,8 +346,7 @@
assert (ordinal >= 0);
String sname = String.valueOf(name);
- JEnumField x = new JEnumField(this, info, sname, ordinal, enclosingType,
- type);
+ JEnumField x = new JEnumField(info, sname, ordinal, enclosingType, type);
List<JEnumField> enumList = enclosingType.enumList;
while (ordinal >= enumList.size()) {
enumList.add(null);
@@ -443,7 +366,7 @@
assert (type != null);
String sname = String.valueOf(name);
- JField x = new JField(this, info, sname, enclosingType, type, isStatic,
+ JField x = new JField(info, sname, enclosingType, type, isStatic,
disposition);
if (indexedTypes.containsValue(enclosingType)) {
@@ -456,7 +379,7 @@
public JInterfaceType createInterface(SourceInfo info, char[][] name) {
String sname = dotify(name);
- JInterfaceType x = new JInterfaceType(this, info, sname);
+ JInterfaceType x = new JInterfaceType(info, sname);
allTypes.add(x);
putIntoTypeMap(sname, x);
@@ -474,7 +397,7 @@
assert (type != null);
assert (enclosingMethodBody != null);
- JLocal x = new JLocal(this, info, String.valueOf(name), type, isFinal,
+ JLocal x = new JLocal(info, String.valueOf(name), type, isFinal,
enclosingMethodBody);
enclosingMethodBody.addLocal(x);
@@ -489,22 +412,19 @@
assert (enclosingType != null);
assert (returnType != null);
assert (!isAbstract || !isNative);
- JMethod x = new JMethod(this, info, sname, enclosingType, returnType,
- isAbstract, isStatic, isFinal, isPrivate);
+ JMethod x = new JMethod(info, sname, enclosingType, returnType, isAbstract,
+ isStatic, isFinal, isPrivate);
if (isNative) {
x.setBody(new JsniMethodBody(this, info));
} else if (!isAbstract) {
- x.setBody(new JMethodBody(this, info));
+ x.setBody(new JMethodBody(info));
}
if (!isPrivate && indexedTypes.containsValue(enclosingType)) {
indexedMethods.put(enclosingType.getShortName() + '.' + sname, x);
}
- if (enclosingType != null) {
- enclosingType.methods.add(x);
- }
-
+ enclosingType.methods.add(x);
return x;
}
@@ -514,8 +434,8 @@
assert (type != null);
assert (enclosingMethod != null);
- JParameter x = new JParameter(this, info, String.valueOf(name), type,
- isFinal, isThis, enclosingMethod);
+ JParameter x = new JParameter(info, String.valueOf(name), type, isFinal,
+ isThis, enclosingMethod);
enclosingMethod.addParam(x);
return x;
@@ -560,472 +480,8 @@
return curType;
}
- /**
- * Returns a sorted set of array types, so the returned set can be iterated
- * over without introducing nondeterminism.
- */
- public Set<JArrayType> getAllArrayTypes() {
- return allArrayTypes;
- }
-
- public List<JMethod> getAllEntryMethods() {
- List<JMethod> allEntryMethods = new ArrayList<JMethod>();
- for (List<JMethod> entries : entryMethods) {
- allEntryMethods.addAll(entries);
- }
- return allEntryMethods;
- }
-
- public CorrelationFactory getCorrelator() {
- return correlator;
- }
-
- public List<JReferenceType> getDeclaredTypes() {
- return allTypes;
- }
-
- public int getEntryCount(int fragment) {
- return entryMethods.get(fragment).size();
- }
-
- public JThisRef getExprThisRef(SourceInfo info, JClassType enclosingType) {
- return new JThisRef(this, info, enclosingType);
- }
-
- public int getFragmentCount() {
- return entryMethods.size();
- }
-
- public JReferenceType getFromTypeMap(String qualifiedBinaryOrSourceName) {
- String srcTypeName = qualifiedBinaryOrSourceName.replace('$', '.');
-
- return typeNameMap.get(srcTypeName);
- }
-
- public JField getIndexedField(String string) {
- JField field = indexedFields.get(string);
- if (field == null) {
- throw new InternalCompilerException("Unable to locate index field: "
- + string);
- }
- return field;
- }
-
- public JMethod getIndexedMethod(String string) {
- JMethod method = indexedMethods.get(string);
- if (method == null) {
- throw new InternalCompilerException("Unable to locate index method: "
- + string);
- }
- return method;
- }
-
- public JReferenceType getIndexedType(String string) {
- JReferenceType type = indexedTypes.get(string);
- if (type == null) {
- throw new InternalCompilerException("Unable to locate index type: "
- + string);
- }
- return type;
- }
-
- public JClassType getJavaScriptObject() {
- return typeSpecialJavaScriptObject;
- }
-
- public List<JsonObject> getJsonTypeTable() {
- return jsonTypeTable;
- }
-
- public JAbsentArrayDimension getLiteralAbsentArrayDimension() {
- return literalAbsentArrayDim;
- }
-
- public JBooleanLiteral getLiteralBoolean(boolean z) {
- return z ? literalTrue : literalFalse;
- }
-
- public JCharLiteral getLiteralChar(char c) {
- // could be interned
- SourceInfo info = createSourceInfoSynthetic(JProgram.class, c + " literal");
- info.addCorrelation(correlator.by(Literal.CHAR));
- return new JCharLiteral(this, info, c);
- }
-
- /**
- * May not be called once optimizations begin; all possible class literals
- * must be created up front.
- */
- public JClassLiteral getLiteralClass(JType type) {
- JClassLiteral classLiteral = classLiterals.get(type);
- if (classLiteral == null) {
- if (optimizationsStarted) {
- throw new InternalCompilerException(
- "New class literals cannot be created once optimizations have started; type '"
- + type + "'");
- }
-
- SourceInfo info = typeSpecialClassLiteralHolder.getSourceInfo();
-
- // Create the allocation expression FIRST since this may be recursive on
- // super type (this forces the super type classLit to be created first).
- JExpression alloc = JClassLiteral.computeClassObjectAllocation(this,
- info, type);
-
- // Create a field in the class literal holder to hold the object.
- JField field = new JField(this, info, type.getJavahSignatureName()
- + "_classLit", typeSpecialClassLiteralHolder, getTypeJavaLangClass(),
- true, Disposition.FINAL);
- typeSpecialClassLiteralHolder.fields.add(field);
-
- // Initialize the field.
- JFieldRef fieldRef = new JFieldRef(this, info, null, field,
- typeSpecialClassLiteralHolder);
- JDeclarationStatement decl = new JDeclarationStatement(this, info,
- fieldRef, alloc);
- JMethodBody clinitBody = (JMethodBody) typeSpecialClassLiteralHolder.methods.get(
- 0).getBody();
- clinitBody.getBlock().addStmt(decl);
-
- SourceInfo literalInfo = createSourceInfoSynthetic(JProgram.class,
- "class literal for " + type.getName());
- literalInfo.addCorrelation(correlator.by(Literal.CLASS));
- classLiteral = new JClassLiteral(this, literalInfo, type, field);
- classLiterals.put(type, classLiteral);
- } else {
- // Make sure the field hasn't been pruned.
- JField field = classLiteral.getField();
- if (optimizationsStarted
- && !field.getEnclosingType().fields.contains(field)) {
- throw new InternalCompilerException(
- "Getting a class literal whose field holder has already been pruned; type '"
- + type + " '");
- }
- }
- return classLiteral;
- }
-
- /**
- * TODO: unreferenced; remove this and JClassSeed?
- */
- public JClassSeed getLiteralClassSeed(JClassType type) {
- // could be interned
- return new JClassSeed(this, createSourceInfoSynthetic(JProgram.class,
- "class seed"), type);
- }
-
- public JDoubleLiteral getLiteralDouble(double d) {
- // could be interned
- SourceInfo info = createSourceInfoSynthetic(JProgram.class, d + " literal");
- info.addCorrelation(correlator.by(Literal.DOUBLE));
- return new JDoubleLiteral(this, info, d);
- }
-
- public JFloatLiteral getLiteralFloat(float f) {
- // could be interned
- SourceInfo info = createSourceInfoSynthetic(JProgram.class, f + " literal");
- info.addCorrelation(correlator.by(Literal.FLOAT));
- return new JFloatLiteral(this, info, f);
- }
-
- public JIntLiteral getLiteralInt(int i) {
- switch (i) {
- case -1:
- return literalIntNegOne;
- case 0:
- return literalIntZero;
- case 1:
- return literalIntOne;
- default: {
- // could be interned
- SourceInfo info = createSourceInfoSynthetic(JProgram.class, i
- + " literal");
- info.addCorrelation(correlator.by(Literal.INT));
- return new JIntLiteral(this, info, i);
- }
- }
- }
-
- public JLongLiteral getLiteralLong(long l) {
- SourceInfo info = createSourceInfoSynthetic(JProgram.class, l + " literal");
- info.addCorrelation(correlator.by(Literal.LONG));
- return new JLongLiteral(this, info, l);
- }
-
- public JNullLiteral getLiteralNull() {
- return literalNull;
- }
-
- public JStringLiteral getLiteralString(SourceInfo sourceInfo, char[] s) {
- return getLiteralString(sourceInfo, String.valueOf(s));
- }
-
- public JStringLiteral getLiteralString(SourceInfo sourceInfo, String s) {
- JStringLiteral toReturn = stringLiteralMap.get(s);
- if (toReturn == null) {
- toReturn = new JStringLiteral(this, stringPoolSourceInfo.makeChild(
- JProgram.class, "String literal: " + s), s);
- stringLiteralMap.put(s, toReturn);
- }
- toReturn.getSourceInfo().merge(sourceInfo);
- return toReturn;
- }
-
- public JField getNullField() {
- if (nullField == null) {
- nullField = new JField(this, createSourceInfoSynthetic(JProgram.class,
- "Null field"), "nullField", null, typeNull, false, Disposition.FINAL);
- }
- return nullField;
- }
-
- public JMethod getNullMethod() {
- if (nullMethod == null) {
- nullMethod = new JMethod(this, createSourceInfoSynthetic(JProgram.class,
- "Null method"), "nullMethod", null, typeNull, false, false, true,
- true);
- }
- return nullMethod;
- }
-
- public int getQueryId(JReferenceType elementType) {
- Integer integer = queryIds.get(elementType);
- if (integer == null) {
- return 0;
- }
-
- return integer.intValue();
- }
-
- public Map<Integer, String> getSplitPointMap() {
- return splitPointMap;
- }
-
- public JMethod getStaticImpl(JMethod method) {
- return instanceToStaticMap.get(method);
- }
-
- public JArrayType getTypeArray(JType leafType, int dimensions) {
- HashMap<JType, JArrayType> typeToArrayType;
-
- // Create typeToArrayType maps for index slots that don't exist yet.
- //
- for (int i = this.dimensions.size(); i < dimensions; ++i) {
- typeToArrayType = new HashMap<JType, JArrayType>();
- this.dimensions.add(typeToArrayType);
- }
-
- // Get the map for array having this number of dimensions (biased by one
- // since we don't store non-arrays in there -- thus index 0 => 1 dim).
- //
- typeToArrayType = this.dimensions.get(dimensions - 1);
-
- JArrayType arrayType = typeToArrayType.get(leafType);
- if (arrayType == null) {
- arrayType = new JArrayType(this, leafType, dimensions);
- arrayType.extnds = typeJavaLangObject;
- allArrayTypes.add(arrayType);
-
- /*
- * TODO(later): should we setup the various array types as an inheritance
- * heirarchy? Currently we're just doing all the heavy lifting in
- * JTypeOracle. If we tried to setup inheritance, we'd have to recompute
- * JTypeOracle if anything changed, so maybe this is better.
- */
- typeToArrayType.put(leafType, arrayType);
- }
-
- return arrayType;
- }
-
- public JClassType getTypeClassLiteralHolder() {
- return typeSpecialClassLiteralHolder;
- }
-
- /**
- * Returns the JType corresponding to a JSNI type reference.
- */
- public JType getTypeFromJsniRef(String className) {
- int dim = 0;
- while (className.endsWith("[]")) {
- dim++;
- className = className.substring(0, className.length() - 2);
- }
-
- JType type;
- if ("Z".equals(className)) {
- type = program.getTypePrimitiveBoolean();
- } else if ("B".equals(className)) {
- type = program.getTypePrimitiveByte();
- } else if ("C".equals(className)) {
- type = program.getTypePrimitiveChar();
- } else if ("D".equals(className)) {
- type = program.getTypePrimitiveDouble();
- } else if ("F".equals(className)) {
- type = program.getTypePrimitiveFloat();
- } else if ("I".equals(className)) {
- type = program.getTypePrimitiveInt();
- } else if ("J".equals(className)) {
- type = program.getTypePrimitiveLong();
- } else if ("S".equals(className)) {
- type = program.getTypePrimitiveShort();
- } else if ("V".equals(className)) {
- type = program.getTypeVoid();
- } else {
- type = getFromTypeMap(className);
- }
-
- if (type == null || dim == 0) {
- return type;
- } else {
- return getTypeArray(type, dim);
- }
- }
-
- public int getTypeId(JClassType classType) {
- Integer integer = typeIdMap.get(classType);
- if (integer == null) {
- return 0;
- }
-
- return integer.intValue();
- }
-
- public JClassType getTypeJavaLangClass() {
- return typeClass;
- }
-
- public JClassType getTypeJavaLangEnum() {
- return typeJavaLangEnum;
- }
-
- public JClassType getTypeJavaLangObject() {
- return typeJavaLangObject;
- }
-
- public JClassType getTypeJavaLangString() {
- return typeString;
- }
-
- public JNullType getTypeNull() {
- return typeNull;
- }
-
- public JPrimitiveType getTypePrimitiveBoolean() {
- return typeBoolean;
- }
-
- public JPrimitiveType getTypePrimitiveByte() {
- return typeByte;
- }
-
- public JPrimitiveType getTypePrimitiveChar() {
- return typeChar;
- }
-
- public JPrimitiveType getTypePrimitiveDouble() {
- return typeDouble;
- }
-
- public JPrimitiveType getTypePrimitiveFloat() {
- return typeFloat;
- }
-
- public JPrimitiveType getTypePrimitiveInt() {
- return typeInt;
- }
-
- public JPrimitiveType getTypePrimitiveLong() {
- return typeLong;
- }
-
- public JPrimitiveType getTypePrimitiveShort() {
- return typeShort;
- }
-
- public JType getTypeVoid() {
- return typeVoid;
- }
-
- public void initTypeInfo(List<JClassType> classes,
- List<JsonObject> jsonObjects) {
- for (int i = 0, c = classes.size(); i < c; ++i) {
- typeIdMap.put(classes.get(i), new Integer(i));
- }
- this.jsonTypeTable = jsonObjects;
- }
-
- public boolean isJavaScriptObject(JType type) {
- if (type instanceof JClassType && typeSpecialJavaScriptObject != null) {
- return typeOracle.canTriviallyCast((JClassType) type,
- typeSpecialJavaScriptObject);
- }
- return false;
- }
-
- public boolean isStaticImpl(JMethod method) {
- return staticToInstanceMap.containsKey(method);
- }
-
- public void putIntoTypeMap(String qualifiedBinaryName, JReferenceType type) {
- // Make it into a source type name.
- //
- String srcTypeName = qualifiedBinaryName.replace('$', '.');
- typeNameMap.put(srcTypeName, type);
- }
-
- public void putStaticImpl(JMethod method, JMethod staticImpl) {
- instanceToStaticMap.put(method, staticImpl);
- staticToInstanceMap.put(staticImpl, method);
- if (method.isTrace()) {
- staticImpl.setTrace();
- }
- }
-
- public void recordQueryIds(Map<JReferenceType, Integer> queryIds) {
- this.queryIds = queryIds;
- }
-
- public void setSplitPointMap(Map<Integer, String> splitPointMap) {
- this.splitPointMap = splitPointMap;
- }
-
- /**
- * If <code>method</code> is a static impl method, returns the instance
- * method that <code>method</code> is the implementation of. Otherwise,
- * returns <code>null</code>.
- */
- public JMethod staticImplFor(JMethod method) {
- return staticToInstanceMap.get(method);
- }
-
- public JReferenceType strongerType(JReferenceType type1, JReferenceType type2) {
- if (type1 == type2) {
- return type1;
- }
-
- if (typeOracle.canTriviallyCast(type1, type2)) {
- return type1;
- }
-
- if (typeOracle.canTriviallyCast(type2, type1)) {
- return type2;
- }
-
- // cannot determine a strong type, just return the first one (this makes two
- // "unrelated" interfaces work correctly in TypeTightener
- return type1;
- }
-
- public void traverse(JVisitor visitor, Context ctx) {
- if (visitor.visit(this, ctx)) {
- visitor.accept(allTypes);
- visitor.accept(new ArrayList<JArrayType>(allArrayTypes));
- }
- visitor.endVisit(this, ctx);
- }
-
- JReferenceType generalizeTypes(JReferenceType type1, JReferenceType type2) {
+ public JReferenceType generalizeTypes(JReferenceType type1,
+ JReferenceType type2) {
if (type1 == type2) {
return type1;
}
@@ -1169,6 +625,453 @@
}
}
+ /**
+ * Returns a sorted set of array types, so the returned set can be iterated
+ * over without introducing nondeterminism.
+ */
+ public Set<JArrayType> getAllArrayTypes() {
+ return allArrayTypes;
+ }
+
+ public List<JMethod> getAllEntryMethods() {
+ List<JMethod> allEntryMethods = new ArrayList<JMethod>();
+ for (List<JMethod> entries : entryMethods) {
+ allEntryMethods.addAll(entries);
+ }
+ return allEntryMethods;
+ }
+
+ public CorrelationFactory getCorrelator() {
+ return correlator;
+ }
+
+ public List<JReferenceType> getDeclaredTypes() {
+ return allTypes;
+ }
+
+ public int getEntryCount(int fragment) {
+ return entryMethods.get(fragment).size();
+ }
+
+ public JThisRef getExprThisRef(SourceInfo info, JClassType enclosingType) {
+ return new JThisRef(info, enclosingType);
+ }
+
+ public int getFragmentCount() {
+ return entryMethods.size();
+ }
+
+ public JReferenceType getFromTypeMap(String qualifiedBinaryOrSourceName) {
+ String srcTypeName = qualifiedBinaryOrSourceName.replace('$', '.');
+
+ return typeNameMap.get(srcTypeName);
+ }
+
+ public JField getIndexedField(String string) {
+ JField field = indexedFields.get(string);
+ if (field == null) {
+ throw new InternalCompilerException("Unable to locate index field: "
+ + string);
+ }
+ return field;
+ }
+
+ public JMethod getIndexedMethod(String string) {
+ JMethod method = indexedMethods.get(string);
+ if (method == null) {
+ throw new InternalCompilerException("Unable to locate index method: "
+ + string);
+ }
+ return method;
+ }
+
+ public JReferenceType getIndexedType(String string) {
+ JReferenceType type = indexedTypes.get(string);
+ if (type == null) {
+ throw new InternalCompilerException("Unable to locate index type: "
+ + string);
+ }
+ return type;
+ }
+
+ public JClassType getJavaScriptObject() {
+ return typeSpecialJavaScriptObject;
+ }
+
+ public List<JsonObject> getJsonTypeTable() {
+ return jsonTypeTable;
+ }
+
+ public JExpression getLiteralAbsentArrayDimension() {
+ return JAbsentArrayDimension.INSTANCE;
+ }
+
+ public JBooleanLiteral getLiteralBoolean(boolean value) {
+ return JBooleanLiteral.get(value);
+ }
+
+ public JCharLiteral getLiteralChar(char value) {
+ return JCharLiteral.get(value);
+ }
+
+ /**
+ * May not be called once optimizations begin; all possible class literals
+ * must be created up front.
+ */
+ public JClassLiteral getLiteralClass(JType type) {
+ JClassLiteral classLiteral = classLiterals.get(type);
+ if (classLiteral == null) {
+ if (optimizationsStarted) {
+ throw new InternalCompilerException(
+ "New class literals cannot be created once optimizations have started; type '"
+ + type + "'");
+ }
+
+ SourceInfo info = typeSpecialClassLiteralHolder.getSourceInfo();
+
+ // Create the allocation expression FIRST since this may be recursive on
+ // super type (this forces the super type classLit to be created first).
+ JExpression alloc = JClassLiteral.computeClassObjectAllocation(this,
+ info, type);
+
+ // Create a field in the class literal holder to hold the object.
+ JField field = new JField(info, type.getJavahSignatureName()
+ + "_classLit", typeSpecialClassLiteralHolder, getTypeJavaLangClass(),
+ true, Disposition.FINAL);
+ typeSpecialClassLiteralHolder.fields.add(field);
+
+ // Initialize the field.
+ JFieldRef fieldRef = new JFieldRef(info, null, field,
+ typeSpecialClassLiteralHolder);
+ JDeclarationStatement decl = new JDeclarationStatement(info, fieldRef,
+ alloc);
+ JMethodBody clinitBody = (JMethodBody) typeSpecialClassLiteralHolder.methods.get(
+ 0).getBody();
+ clinitBody.getBlock().addStmt(decl);
+
+ SourceInfo literalInfo = createSourceInfoSynthetic(JProgram.class,
+ "class literal for " + type.getName());
+ literalInfo.addCorrelation(correlator.by(Literal.CLASS));
+ classLiteral = new JClassLiteral(literalInfo, type, field);
+ classLiterals.put(type, classLiteral);
+ } else {
+ // Make sure the field hasn't been pruned.
+ JField field = classLiteral.getField();
+ if (optimizationsStarted
+ && !field.getEnclosingType().fields.contains(field)) {
+ throw new InternalCompilerException(
+ "Getting a class literal whose field holder has already been pruned; type '"
+ + type + " '");
+ }
+ }
+ return classLiteral;
+ }
+
+ /**
+ * TODO: unreferenced; remove this and JClassSeed?
+ */
+ public JClassSeed getLiteralClassSeed(JClassType type) {
+ // could be interned
+ return new JClassSeed(createSourceInfoSynthetic(JProgram.class,
+ "class seed"), type, getTypeJavaLangObject());
+ }
+
+ public JDoubleLiteral getLiteralDouble(double d) {
+ return JDoubleLiteral.get(d);
+ }
+
+ public JFloatLiteral getLiteralFloat(float f) {
+ return JFloatLiteral.get(f);
+ }
+
+ public JIntLiteral getLiteralInt(int value) {
+ return JIntLiteral.get(value);
+ }
+
+ public JLongLiteral getLiteralLong(long value) {
+ return JLongLiteral.get(value);
+ }
+
+ public JNullLiteral getLiteralNull() {
+ return JNullLiteral.INSTANCE;
+ }
+
+ public JStringLiteral getLiteralString(SourceInfo sourceInfo, char[] s) {
+ return getLiteralString(sourceInfo, String.valueOf(s));
+ }
+
+ public JStringLiteral getLiteralString(SourceInfo sourceInfo, String s) {
+ JStringLiteral toReturn = stringLiteralMap.get(s);
+ if (toReturn == null) {
+ toReturn = new JStringLiteral(stringPoolSourceInfo.makeChild(
+ JProgram.class, "String literal: " + s), s, getTypeJavaLangString());
+ stringLiteralMap.put(s, toReturn);
+ }
+ toReturn.getSourceInfo().merge(sourceInfo);
+ return toReturn;
+ }
+
+ public JField getNullField() {
+ if (nullField == null) {
+ nullField = new JField(createSourceInfoSynthetic(JProgram.class,
+ "Null field"), "nullField", null, JNullType.INSTANCE, false,
+ Disposition.FINAL);
+ }
+ return nullField;
+ }
+
+ public JMethod getNullMethod() {
+ if (nullMethod == null) {
+ nullMethod = new JMethod(createSourceInfoSynthetic(JProgram.class,
+ "Null method"), "nullMethod", null, JNullType.INSTANCE, false, false,
+ true, true);
+ }
+ return nullMethod;
+ }
+
+ public int getQueryId(JReferenceType elementType) {
+ Integer integer = queryIds.get(elementType);
+ if (integer == null) {
+ return 0;
+ }
+
+ return integer.intValue();
+ }
+
+ public Map<Integer, String> getSplitPointMap() {
+ return splitPointMap;
+ }
+
+ public JMethod getStaticImpl(JMethod method) {
+ return instanceToStaticMap.get(method);
+ }
+
+ public JArrayType getTypeArray(JType leafType, int dimensions) {
+ HashMap<JType, JArrayType> typeToArrayType;
+
+ // Create typeToArrayType maps for index slots that don't exist yet.
+ //
+ for (int i = this.dimensions.size(); i < dimensions; ++i) {
+ typeToArrayType = new HashMap<JType, JArrayType>();
+ this.dimensions.add(typeToArrayType);
+ }
+
+ // Get the map for array having this number of dimensions (biased by one
+ // since we don't store non-arrays in there -- thus index 0 => 1 dim).
+ //
+ typeToArrayType = this.dimensions.get(dimensions - 1);
+
+ JArrayType arrayType = typeToArrayType.get(leafType);
+ if (arrayType == null) {
+ JType elementType;
+ if (dimensions == 1) {
+ elementType = leafType;
+ } else {
+ elementType = getTypeArray(leafType, dimensions - 1);
+ }
+ arrayType = new JArrayType(elementType, leafType, dimensions);
+ arrayType.extnds = typeJavaLangObject;
+ allArrayTypes.add(arrayType);
+
+ /*
+ * TODO(later): should we setup the various array types as an inheritance
+ * heirarchy? Currently we're just doing all the heavy lifting in
+ * JTypeOracle. If we tried to setup inheritance, we'd have to recompute
+ * JTypeOracle if anything changed, so maybe this is better.
+ */
+ typeToArrayType.put(leafType, arrayType);
+ }
+
+ return arrayType;
+ }
+
+ public JClassType getTypeClassLiteralHolder() {
+ return typeSpecialClassLiteralHolder;
+ }
+
+ /**
+ * Returns the JType corresponding to a JSNI type reference.
+ */
+ public JType getTypeFromJsniRef(String className) {
+ int dim = 0;
+ while (className.endsWith("[]")) {
+ dim++;
+ className = className.substring(0, className.length() - 2);
+ }
+
+ JType type;
+ if ("Z".equals(className)) {
+ type = getTypePrimitiveBoolean();
+ } else if ("B".equals(className)) {
+ type = getTypePrimitiveByte();
+ } else if ("C".equals(className)) {
+ type = getTypePrimitiveChar();
+ } else if ("D".equals(className)) {
+ type = getTypePrimitiveDouble();
+ } else if ("F".equals(className)) {
+ type = getTypePrimitiveFloat();
+ } else if ("I".equals(className)) {
+ type = getTypePrimitiveInt();
+ } else if ("J".equals(className)) {
+ type = getTypePrimitiveLong();
+ } else if ("S".equals(className)) {
+ type = getTypePrimitiveShort();
+ } else if ("V".equals(className)) {
+ type = getTypeVoid();
+ } else {
+ type = getFromTypeMap(className);
+ }
+
+ if (type == null || dim == 0) {
+ return type;
+ } else {
+ return getTypeArray(type, dim);
+ }
+ }
+
+ public int getTypeId(JClassType classType) {
+ Integer integer = typeIdMap.get(classType);
+ if (integer == null) {
+ return 0;
+ }
+
+ return integer.intValue();
+ }
+
+ public JClassType getTypeJavaLangClass() {
+ return typeClass;
+ }
+
+ public JClassType getTypeJavaLangEnum() {
+ return typeJavaLangEnum;
+ }
+
+ public JClassType getTypeJavaLangObject() {
+ return typeJavaLangObject;
+ }
+
+ public JClassType getTypeJavaLangString() {
+ return typeString;
+ }
+
+ public JNullType getTypeNull() {
+ return JNullType.INSTANCE;
+ }
+
+ public JPrimitiveType getTypePrimitiveBoolean() {
+ return JPrimitiveType.BOOLEAN;
+ }
+
+ public JPrimitiveType getTypePrimitiveByte() {
+ return JPrimitiveType.BYTE;
+ }
+
+ public JPrimitiveType getTypePrimitiveChar() {
+ return JPrimitiveType.CHAR;
+ }
+
+ public JPrimitiveType getTypePrimitiveDouble() {
+ return JPrimitiveType.DOUBLE;
+ }
+
+ public JPrimitiveType getTypePrimitiveFloat() {
+ return JPrimitiveType.FLOAT;
+ }
+
+ public JPrimitiveType getTypePrimitiveInt() {
+ return JPrimitiveType.INT;
+ }
+
+ public JPrimitiveType getTypePrimitiveLong() {
+ return JPrimitiveType.LONG;
+ }
+
+ public JPrimitiveType getTypePrimitiveShort() {
+ return JPrimitiveType.SHORT;
+ }
+
+ public JPrimitiveType getTypeVoid() {
+ return JPrimitiveType.VOID;
+ }
+
+ public void initTypeInfo(List<JClassType> classes,
+ List<JsonObject> jsonObjects) {
+ for (int i = 0, c = classes.size(); i < c; ++i) {
+ typeIdMap.put(classes.get(i), new Integer(i));
+ }
+ this.jsonTypeTable = jsonObjects;
+ }
+
+ public boolean isJavaScriptObject(JType type) {
+ if (type instanceof JClassType && typeSpecialJavaScriptObject != null) {
+ return typeOracle.canTriviallyCast((JClassType) type,
+ typeSpecialJavaScriptObject);
+ }
+ return false;
+ }
+
+ public boolean isStaticImpl(JMethod method) {
+ return staticToInstanceMap.containsKey(method);
+ }
+
+ public void putIntoTypeMap(String qualifiedBinaryName, JReferenceType type) {
+ // Make it into a source type name.
+ //
+ String srcTypeName = qualifiedBinaryName.replace('$', '.');
+ typeNameMap.put(srcTypeName, type);
+ }
+
+ public void putStaticImpl(JMethod method, JMethod staticImpl) {
+ instanceToStaticMap.put(method, staticImpl);
+ staticToInstanceMap.put(staticImpl, method);
+ if (method.isTrace()) {
+ staticImpl.setTrace();
+ }
+ }
+
+ public void recordQueryIds(Map<JReferenceType, Integer> queryIds) {
+ this.queryIds = queryIds;
+ }
+
+ public void setSplitPointMap(Map<Integer, String> splitPointMap) {
+ this.splitPointMap = splitPointMap;
+ }
+
+ /**
+ * If <code>method</code> is a static impl method, returns the instance
+ * method that <code>method</code> is the implementation of. Otherwise,
+ * returns <code>null</code>.
+ */
+ public JMethod staticImplFor(JMethod method) {
+ return staticToInstanceMap.get(method);
+ }
+
+ public JReferenceType strongerType(JReferenceType type1, JReferenceType type2) {
+ if (type1 == type2) {
+ return type1;
+ }
+
+ if (typeOracle.canTriviallyCast(type1, type2)) {
+ return type1;
+ }
+
+ if (typeOracle.canTriviallyCast(type2, type1)) {
+ return type2;
+ }
+
+ // cannot determine a strong type, just return the first one (this makes two
+ // "unrelated" interfaces work correctly in TypeTightener
+ return type1;
+ }
+
+ public void traverse(JVisitor visitor, Context ctx) {
+ if (visitor.visit(this, ctx)) {
+ visitor.accept(allTypes);
+ visitor.accept(new ArrayList<JArrayType>(allArrayTypes));
+ }
+ visitor.endVisit(this, ctx);
+ }
+
private int classifyType(JReferenceType type) {
if (type instanceof JNullType) {
return IS_NULL;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java
index 54693ec..41d6045 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JReboundEntryPoint.java
@@ -30,10 +30,9 @@
private final List<JClassType> resultTypes;
private final JReferenceType sourceType;
- public JReboundEntryPoint(JProgram program, SourceInfo info,
- JReferenceType sourceType, List<JClassType> resultTypes,
- List<JExpression> entryCalls) {
- super(program, info);
+ public JReboundEntryPoint(SourceInfo info, JReferenceType sourceType,
+ List<JClassType> resultTypes, List<JExpression> entryCalls) {
+ super(info);
this.sourceType = sourceType;
this.resultTypes = resultTypes;
this.entryCalls = entryCalls;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java
index 76e244a..ae9c70d 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java
@@ -25,13 +25,54 @@
*/
public abstract class JReferenceType extends JType implements CanBeAbstract {
- public List<JField> fields = new ArrayList<JField>();
- public List<JMethod> methods = new ArrayList<JMethod>();
public JClassType extnds;
+ public List<JField> fields = new ArrayList<JField>();
public List<JInterfaceType> implments = new ArrayList<JInterfaceType>();
+ public List<JMethod> methods = new ArrayList<JMethod>();
- public JReferenceType(JProgram program, SourceInfo info, String name) {
- super(program, info, name, program.getLiteralNull());
+ /**
+ * Tracks whether this class has a dynamic clinit. Defaults to true until
+ * shown otherwise.
+ */
+ private boolean hasClinit = true;
+
+ public JReferenceType(SourceInfo info, String name) {
+ super(info, name, JNullLiteral.INSTANCE);
+ }
+
+ /**
+ * Returns <code>true</code> if a static field access of
+ * <code>targetType</code> from within this type should generate a clinit
+ * call. This will be true in cases where <code>targetType</code> has a live
+ * clinit method which we cannot statically know has already run. We can
+ * statically know the clinit method has already run when:
+ * <ol>
+ * <li><code>this == targetType</code></li>
+ * <li><code>this</code> is a subclass of <code>targetType</code>,
+ * because my clinit would have already run this <code>targetType</code>'s
+ * clinit; see JLS 12.4</li>
+ * </ol>
+ */
+ public boolean checkClinitTo(JReferenceType targetType) {
+ if (this == targetType) {
+ // Call to self (very common case).
+ return false;
+ }
+ if (targetType == null || !targetType.hasClinit()) {
+ // Target has no clinit (common case).
+ return false;
+ }
+
+ // See if I'm a subclass.
+ JClassType checkType = this.extnds;
+ while (checkType != null) {
+ if (checkType == targetType) {
+ // I am a subclass.
+ return false;
+ }
+ checkType = checkType.extnds;
+ }
+ return true;
}
@Override
@@ -44,13 +85,26 @@
return "L" + name.replace('.', '/') + ';';
}
- public JProgram getProgram() {
- return program;
- }
-
public String getShortName() {
int dotpos = name.lastIndexOf('.');
return name.substring(dotpos + 1);
}
+ /**
+ * Returns <code>true</code> when this method's clinit must be run
+ * dynamically.
+ */
+ public boolean hasClinit() {
+ return hasClinit;
+ }
+
+ /**
+ * Called when this class's clinit is empty or can be run at the top level.
+ */
+ void removeClinit() {
+ assert hasClinit();
+ JMethod clinitMethod = methods.get(0);
+ assert JProgram.isClinit(clinitMethod);
+ hasClinit = false;
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JReturnStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JReturnStatement.java
index 78d6584..1f9d16d 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JReturnStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JReturnStatement.java
@@ -24,8 +24,8 @@
private JExpression expr;
- public JReturnStatement(JProgram program, SourceInfo info, JExpression expr) {
- super(program, info);
+ public JReturnStatement(SourceInfo info, JExpression expr) {
+ super(info);
this.expr = expr;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JStatement.java
index ff824bb..b36065c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JStatement.java
@@ -18,14 +18,14 @@
import com.google.gwt.dev.jjs.SourceInfo;
/**
- * Java program statement.
+ * Java program statement.
*/
public abstract class JStatement extends JNode {
- public JStatement(JProgram program, SourceInfo info) {
- super(program, info);
+ public JStatement(SourceInfo info) {
+ super(info);
}
-
+
public boolean unconditionalControlBreak() {
return false;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JStringLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JStringLiteral.java
index d6f3df2..9197a91 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JStringLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JStringLiteral.java
@@ -22,14 +22,16 @@
*/
public class JStringLiteral extends JValueLiteral {
+ private final JClassType stringType;
private final String value;
/**
* These are only supposed to be constructed by JProgram.
*/
- JStringLiteral(JProgram program, SourceInfo sourceInfo, String value) {
- super(program, sourceInfo);
+ JStringLiteral(SourceInfo sourceInfo, String value, JClassType stringType) {
+ super(sourceInfo);
this.value = value;
+ this.stringType = stringType;
}
@Override
@@ -38,7 +40,7 @@
}
public JType getType() {
- return program.getTypeJavaLangString();
+ return stringType;
}
public String getValue() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JSwitchStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JSwitchStatement.java
index 4a329e5..7124554 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JSwitchStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JSwitchStatement.java
@@ -25,9 +25,8 @@
private final JBlock body;
private JExpression expr;
- public JSwitchStatement(JProgram program, SourceInfo info, JExpression expr,
- JBlock body) {
- super(program, info);
+ public JSwitchStatement(SourceInfo info, JExpression expr, JBlock body) {
+ super(info);
this.expr = expr;
this.body = body;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JThisRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JThisRef.java
index db7ab78..d24101c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JThisRef.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JThisRef.java
@@ -24,11 +24,8 @@
private final JClassType classType;
- /**
- * These are only supposed to be constructed by JProgram.
- */
- JThisRef(JProgram program, SourceInfo info, JClassType classType) {
- super(program, info);
+ public JThisRef(SourceInfo info, JClassType classType) {
+ super(info);
this.classType = classType;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JThrowStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JThrowStatement.java
index bbc2d3d..834bec1 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JThrowStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JThrowStatement.java
@@ -24,8 +24,8 @@
private JExpression expr;
- public JThrowStatement(JProgram program, SourceInfo info, JExpression expr) {
- super(program, info);
+ public JThrowStatement(SourceInfo info, JExpression expr) {
+ super(info);
this.expr = expr;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JTryStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JTryStatement.java
index b7a41be..75c3f56 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JTryStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JTryStatement.java
@@ -29,9 +29,9 @@
private final JBlock finallyBlock;
private final JBlock tryBlock;
- public JTryStatement(JProgram program, SourceInfo info, JBlock tryBlock,
+ public JTryStatement(SourceInfo info, JBlock tryBlock,
List<JLocalRef> catchArgs, List<JBlock> catchBlocks, JBlock finallyBlock) {
- super(program, info);
+ super(info);
assert (catchArgs.size() == catchBlocks.size());
this.tryBlock = tryBlock;
this.catchArgs = catchArgs;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JType.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JType.java
index 2223750..837e727 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JType.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JType.java
@@ -25,9 +25,8 @@
protected final String name;
private final JLiteral defaultValue;
- public JType(JProgram program, SourceInfo info, String name,
- JLiteral defaultValue) {
- super(program, info);
+ public JType(SourceInfo info, String name, JLiteral defaultValue) {
+ super(info);
this.name = name;
this.defaultValue = defaultValue;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
index 29b4509..a64321e 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
@@ -212,8 +212,6 @@
private final Set<JInterfaceType> dualImpl = new IdentityHashSet<JInterfaceType>();
- private final Set<JReferenceType> hasClinitSet = new IdentityHashSet<JReferenceType>();
-
private final Map<JClassType, Set<JInterfaceType>> implementsMap = new IdentityHashMap<JClassType, Set<JInterfaceType>>();
private Set<JReferenceType> instantiatedTypes = null;
@@ -379,33 +377,6 @@
return false;
}
- /**
- * Returns <code>true</code> if a static field access of <code>toType</code>
- * from within <code>fromType</code> should generate a clinit call. This
- * will be true in cases where <code>toType</code> has a live clinit method
- * which we cannot statically know has already run. We can statically know the
- * clinit method has already run when:
- * <ol>
- * <li><code>fromType == toType</code></li>
- * <li><code>toType</code> is a superclass of <code>fromType</code>
- * (because <code>toType</code>'s clinit would have already run
- * <code>fromType</code>'s clinit; see JLS 12.4)</li>
- * </ol>
- */
- public boolean checkClinit(JReferenceType fromType, JReferenceType toType) {
- if (fromType == toType) {
- return false;
- }
- if (!hasClinit(toType)) {
- return false;
- }
- if (fromType instanceof JClassType && toType instanceof JClassType
- && isSuperClass((JClassType) fromType, (JClassType) toType)) {
- return false;
- }
- return true;
- }
-
public void computeBeforeAST() {
javaLangObject = program.getTypeJavaLangObject();
superClassMap.clear();
@@ -513,10 +484,6 @@
return Collections.unmodifiableMap(jsoSingleImpls);
}
- public boolean hasClinit(JReferenceType type) {
- return hasClinitSet.contains(type);
- }
-
/**
* Returns true if qType is an implemented interface of type, directly or
* indirectly.
@@ -548,11 +515,12 @@
* associated JProgram.
*/
public void recomputeAfterOptimizations() {
- hasClinitSet.clear();
Set<JReferenceType> computed = new IdentityHashSet<JReferenceType>();
for (int i = 0; i < program.getDeclaredTypes().size(); ++i) {
JReferenceType type = program.getDeclaredTypes().get(i);
- computeHasClinit(type, computed);
+ if (type.hasClinit()) {
+ computeHasClinit(type, computed);
+ }
}
computeSingleJsoImplData();
@@ -597,9 +565,10 @@
Set<JReferenceType> computed) {
if (computeHasClinitRecursive(type, computed,
new IdentityHashSet<JReferenceType>())) {
- hasClinitSet.add(type);
+ computed.add(type);
+ } else {
+ type.removeClinit();
}
- computed.add(type);
}
private boolean computeHasClinitRecursive(JReferenceType type,
@@ -607,11 +576,6 @@
// Track that we've been seen.
alreadySeen.add(type);
- // If we've been computed, hasClinitSet is accurate for me.
- if (computed.contains(type)) {
- return hasClinitSet.contains(type);
- }
-
JMethod method = type.methods.get(0);
assert (JProgram.isClinit(method));
CheckClinitVisitor v = new CheckClinitVisitor();
@@ -620,8 +584,24 @@
return true;
}
for (JReferenceType target : v.getClinitTargets()) {
+ if (!target.hasClinit()) {
+ // A false result is always accurate.
+ continue;
+ }
+
+ /*
+ * If target has a clinit, so do I; but only if target has already been
+ * recomputed this run.
+ */
+ if (target.hasClinit() && computed.contains(target)) {
+ return true;
+ }
+
+ /*
+ * Prevent recursion sickness: ignore this call for now since this call is
+ * being accounted for higher on the stack.
+ */
if (alreadySeen.contains(target)) {
- // Ignore this call for now.
continue;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JUnaryOperation.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JUnaryOperation.java
index 382b3b3..e9ff4a2 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JUnaryOperation.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JUnaryOperation.java
@@ -25,9 +25,8 @@
private JExpression arg;
private final JUnaryOperator op;
- public JUnaryOperation(JProgram program, SourceInfo info,
- JUnaryOperator op, JExpression arg) {
- super(program, info);
+ public JUnaryOperation(SourceInfo info, JUnaryOperator op, JExpression arg) {
+ super(info);
this.op = op;
this.arg = arg;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JValueLiteral.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JValueLiteral.java
index 35334b5..6e9c5e4 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JValueLiteral.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JValueLiteral.java
@@ -22,8 +22,8 @@
*/
public abstract class JValueLiteral extends JLiteral {
- public JValueLiteral(JProgram program, SourceInfo sourceInfo) {
- super(program, sourceInfo);
+ public JValueLiteral(SourceInfo sourceInfo) {
+ super(sourceInfo);
}
public abstract Object getValueObj();
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JVariable.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JVariable.java
index b37e953..f9d46f2 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JVariable.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JVariable.java
@@ -28,9 +28,9 @@
private final String name;
private JType type;
- JVariable(JProgram program, SourceInfo info, String name, JType type,
- boolean isFinal) {
- super(program, info);
+ JVariable(SourceInfo info, String name, JType type, boolean isFinal) {
+ super(info);
+ assert type != null;
this.name = name;
this.type = type;
this.isFinal = isFinal;
@@ -43,7 +43,7 @@
}
return null;
}
-
+
public JDeclarationStatement getDeclarationStatement() {
return declStmt;
}
@@ -76,6 +76,7 @@
}
public void setType(JType newType) {
+ assert newType != null;
type = newType;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JVariableRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JVariableRef.java
index d0a6dd9..3dcf6a3 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JVariableRef.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JVariableRef.java
@@ -24,8 +24,8 @@
protected JVariable target;
- public JVariableRef(JProgram program, SourceInfo info, JVariable target) {
- super(program, info);
+ public JVariableRef(SourceInfo info, JVariable target) {
+ super(info);
this.target = target;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JWhileStatement.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JWhileStatement.java
index a7b44a5..65b483b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JWhileStatement.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JWhileStatement.java
@@ -25,9 +25,8 @@
private JStatement body;
private JExpression testExpr;
- public JWhileStatement(JProgram program, SourceInfo info,
- JExpression testExpr, JStatement body) {
- super(program, info);
+ public JWhileStatement(SourceInfo info, JExpression testExpr, JStatement body) {
+ super(info);
this.testExpr = testExpr;
this.body = body;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JClassSeed.java b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JClassSeed.java
index 8aefa08..9644b19 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JClassSeed.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JClassSeed.java
@@ -19,7 +19,6 @@
import com.google.gwt.dev.jjs.ast.Context;
import com.google.gwt.dev.jjs.ast.JClassType;
import com.google.gwt.dev.jjs.ast.JLiteral;
-import com.google.gwt.dev.jjs.ast.JProgram;
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JVisitor;
@@ -33,10 +32,13 @@
* The class being referred to.
*/
private final JClassType refType;
+ private final JClassType objectType;
- public JClassSeed(JProgram program, SourceInfo sourceInfo, JClassType type) {
- super(program, sourceInfo);
+ public JClassSeed(SourceInfo sourceInfo, JClassType type,
+ JClassType objectType) {
+ super(sourceInfo);
refType = type;
+ this.objectType = objectType;
}
public JClassType getRefType() {
@@ -44,7 +46,7 @@
}
public JType getType() {
- return program.getTypeJavaLangObject();
+ return objectType;
}
public void traverse(JVisitor visitor, Context ctx) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JMultiExpression.java b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JMultiExpression.java
index c75271e..c87857b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JMultiExpression.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JMultiExpression.java
@@ -18,7 +18,7 @@
import com.google.gwt.dev.jjs.SourceInfo;
import com.google.gwt.dev.jjs.ast.Context;
import com.google.gwt.dev.jjs.ast.JExpression;
-import com.google.gwt.dev.jjs.ast.JProgram;
+import com.google.gwt.dev.jjs.ast.JPrimitiveType;
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JVisitor;
@@ -31,14 +31,14 @@
public ArrayList<JExpression> exprs = new ArrayList<JExpression>();
- public JMultiExpression(JProgram program, SourceInfo info) {
- super(program, info);
+ public JMultiExpression(SourceInfo info) {
+ super(info);
}
public JType getType() {
int c = exprs.size();
if (c == 0) {
- return program.getTypeVoid();
+ return JPrimitiveType.VOID;
} else {
return exprs.get(c - 1).getType();
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java
index c08c139..cbc7643 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java
@@ -19,7 +19,7 @@
import com.google.gwt.dev.jjs.ast.Context;
import com.google.gwt.dev.jjs.ast.JField;
import com.google.gwt.dev.jjs.ast.JFieldRef;
-import com.google.gwt.dev.jjs.ast.JProgram;
+import com.google.gwt.dev.jjs.ast.JNullLiteral;
import com.google.gwt.dev.jjs.ast.JReferenceType;
import com.google.gwt.dev.jjs.ast.JVisitor;
@@ -31,10 +31,10 @@
private final String ident;
private boolean isLvalue;
- public JsniFieldRef(JProgram program, SourceInfo info, String ident,
- JField field, JReferenceType enclosingType, boolean isLvalue) {
- super(program, info, field.isStatic() ? null : program.getLiteralNull(),
- field, enclosingType);
+ public JsniFieldRef(SourceInfo info, String ident, JField field,
+ JReferenceType enclosingType, boolean isLvalue) {
+ super(info, field.isStatic() ? null : JNullLiteral.INSTANCE, field,
+ enclosingType);
this.ident = ident;
this.isLvalue = isLvalue;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
index d59de78..86c7f07 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodBody.java
@@ -45,7 +45,7 @@
private Set<String> stringLiterals = Collections.emptySet();
public JsniMethodBody(JProgram program, SourceInfo info) {
- super(program, info);
+ super(info);
}
/**
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodRef.java b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodRef.java
index 9c3e18d..ab004da 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodRef.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodRef.java
@@ -20,7 +20,7 @@
import com.google.gwt.dev.jjs.ast.JClassType;
import com.google.gwt.dev.jjs.ast.JMethod;
import com.google.gwt.dev.jjs.ast.JMethodCall;
-import com.google.gwt.dev.jjs.ast.JProgram;
+import com.google.gwt.dev.jjs.ast.JNullLiteral;
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JVisitor;
@@ -30,13 +30,14 @@
public class JsniMethodRef extends JMethodCall {
private final String ident;
+ private final JClassType jsoType;
- public JsniMethodRef(JProgram program, SourceInfo info, String ident,
- JMethod method) {
+ public JsniMethodRef(SourceInfo info, String ident, JMethod method,
+ JClassType jsoType) {
// Just use a null literal as the qualifier on a non-static method
- super(program, info, method.isStatic() ? null : program.getLiteralNull(),
- method);
+ super(info, method.isStatic() ? null : JNullLiteral.INSTANCE, method);
this.ident = ident;
+ this.jsoType = jsoType;
}
public String getIdent() {
@@ -45,9 +46,7 @@
@Override
public JType getType() {
- // If JavaScriptObject type is not available, just return the Object type
- JClassType jsoType = program.getJavaScriptObject();
- return (jsoType != null) ? jsoType : program.getTypeJavaLangObject();
+ return jsoType;
}
@Override
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsonArray.java b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsonArray.java
index 9221003..641d997 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsonArray.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsonArray.java
@@ -19,7 +19,6 @@
import com.google.gwt.dev.jjs.ast.Context;
import com.google.gwt.dev.jjs.ast.JClassType;
import com.google.gwt.dev.jjs.ast.JExpression;
-import com.google.gwt.dev.jjs.ast.JProgram;
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JVisitor;
@@ -33,14 +32,15 @@
public List<JExpression> exprs = new ArrayList<JExpression>();
- public JsonArray(JProgram program, SourceInfo sourceInfo) {
- super(program, sourceInfo);
+ private final JClassType jsoType;
+
+ public JsonArray(SourceInfo sourceInfo, JClassType jsoType) {
+ super(sourceInfo);
+ this.jsoType = jsoType;
}
public JType getType() {
- // If JavaScriptObject type is not available, just return the Object type
- JClassType jsoType = program.getJavaScriptObject();
- return (jsoType != null) ? jsoType : program.getTypeJavaLangObject();
+ return jsoType;
}
public boolean hasSideEffects() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsonObject.java b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsonObject.java
index f1b8c83..a6fe9c6 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsonObject.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsonObject.java
@@ -20,7 +20,6 @@
import com.google.gwt.dev.jjs.ast.JClassType;
import com.google.gwt.dev.jjs.ast.JExpression;
import com.google.gwt.dev.jjs.ast.JNode;
-import com.google.gwt.dev.jjs.ast.JProgram;
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JVisitor;
@@ -40,9 +39,9 @@
public JExpression labelExpr;
public JExpression valueExpr;
- public JsonPropInit(JProgram program, SourceInfo sourceInfo, JExpression labelExpr,
+ public JsonPropInit(SourceInfo sourceInfo, JExpression labelExpr,
JExpression valueExpr) {
- super(program, sourceInfo);
+ super(sourceInfo);
this.labelExpr = labelExpr;
this.valueExpr = valueExpr;
}
@@ -57,15 +56,15 @@
}
public final List<JsonPropInit> propInits = new ArrayList<JsonPropInit>();
+ private final JClassType jsoType;
- public JsonObject(JProgram program, SourceInfo sourceInfo) {
- super(program, sourceInfo);
+ public JsonObject(SourceInfo sourceInfo, JClassType jsoType) {
+ super(sourceInfo);
+ this.jsoType = jsoType;
}
public JType getType() {
- // If JavaScriptObject type is not available, just return the Object type
- JClassType jsoType = program.getJavaScriptObject();
- return (jsoType != null) ? jsoType : program.getTypeJavaLangObject();
+ return jsoType;
}
public boolean hasSideEffects() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java
index 009c79d..a1e2292 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java
@@ -64,8 +64,8 @@
if (!((JReferenceType) elementType).isFinal()
|| elementType != x.getRhs().getType()) {
// replace this assignment with a call to setCheck()
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(),
- null, setCheckMethod);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null,
+ setCheckMethod);
call.addArgs(arrayRef.getInstance(), arrayRef.getIndexExpr(),
x.getRhs());
ctx.replaceMe(call);
@@ -119,8 +119,8 @@
private void processDim(JNewArray x, Context ctx, JArrayType arrayType) {
// override the type of the called method with the array's type
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- initDim, arrayType);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, initDim,
+ arrayType);
JLiteral classLit = x.getClassLiteral();
JLiteral typeIdLit = program.getLiteralInt(program.getTypeId(arrayType));
JLiteral queryIdLit = program.getLiteralInt(tryGetQueryId(arrayType));
@@ -136,12 +136,11 @@
// override the type of the called method with the array's type
SourceInfo sourceInfo = x.getSourceInfo().makeChild(ArrayVisitor.class,
"Creating dimensions");
- JMethodCall call = new JMethodCall(program, sourceInfo, null, initDims,
- arrayType);
- JsonArray classLitList = new JsonArray(program, sourceInfo);
- JsonArray typeIdList = new JsonArray(program, sourceInfo);
- JsonArray queryIdList = new JsonArray(program, sourceInfo);
- JsonArray dimList = new JsonArray(program, sourceInfo);
+ JMethodCall call = new JMethodCall(sourceInfo, null, initDims, arrayType);
+ JsonArray classLitList = new JsonArray(sourceInfo, program.getJavaScriptObject());
+ JsonArray typeIdList = new JsonArray(sourceInfo, program.getJavaScriptObject());
+ JsonArray queryIdList = new JsonArray(sourceInfo, program.getJavaScriptObject());
+ JsonArray dimList = new JsonArray(sourceInfo, program.getJavaScriptObject());
JType cur = arrayType;
for (int i = 0; i < dims; ++i) {
// Walk down each type from most dims to least.
@@ -169,12 +168,11 @@
// override the type of the called method with the array's type
SourceInfo sourceInfo = x.getSourceInfo().makeChild(ArrayVisitor.class,
"Array initializer");
- JMethodCall call = new JMethodCall(program, sourceInfo, null, initValues,
- arrayType);
+ JMethodCall call = new JMethodCall(sourceInfo, null, initValues, arrayType);
JLiteral classLit = x.getClassLiteral();
JLiteral typeIdLit = program.getLiteralInt(program.getTypeId(arrayType));
JLiteral queryIdLit = program.getLiteralInt(tryGetQueryId(arrayType));
- JsonArray initList = new JsonArray(program, sourceInfo);
+ JsonArray initList = new JsonArray(sourceInfo, program.getJavaScriptObject());
for (int i = 0; i < x.initializers.size(); ++i) {
initList.exprs.add(x.initializers.get(i));
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionNormalizer.java
index d190e77..eb8ee1a 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionNormalizer.java
@@ -43,13 +43,12 @@
String methodName = "Exceptions.throwAssertionError"
+ getAssertMethodSuffix(x.getArg());
JMethod method = program.getIndexedMethod(methodName);
- JMethodCall rhs = new JMethodCall(program, x.getSourceInfo(), null,
- method);
+ JMethodCall rhs = new JMethodCall(x.getSourceInfo(), null, method);
if (x.getArg() != null) {
rhs.addArg(x.getArg());
}
- JBinaryOperation binOp = new JBinaryOperation(program, x.getSourceInfo(),
- program.getTypePrimitiveBoolean(), JBinaryOperator.OR, lhs, rhs);
+ JBinaryOperation binOp = new JBinaryOperation(x.getSourceInfo(), program.getTypePrimitiveBoolean(),
+ JBinaryOperator.OR, lhs, rhs);
ctx.replaceMe(binOp.makeStatement());
}
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionRemover.java b/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionRemover.java
index 685de4e..dc2ae7c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionRemover.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionRemover.java
@@ -41,7 +41,7 @@
ctx.removeMe();
} else {
// empty block statement
- ctx.replaceMe(new JBlock(program, stmt.getSourceInfo()));
+ ctx.replaceMe(new JBlock(stmt.getSourceInfo()));
}
}
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/AutoboxUtils.java b/dev/core/src/com/google/gwt/dev/jjs/impl/AutoboxUtils.java
index 94c70d4..45e1077 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/AutoboxUtils.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/AutoboxUtils.java
@@ -104,8 +104,7 @@
JClassType wrapperType) {
// Add a cast to toBox if need be
if (toBox.getType() != primitiveType) {
- toBox = new JCastOperation(program, toBox.getSourceInfo(), primitiveType,
- toBox);
+ toBox = new JCastOperation(toBox.getSourceInfo(), primitiveType, toBox);
}
// Find the correct valueOf() method.
@@ -133,8 +132,7 @@
}
// Create the boxing call.
- JMethodCall call = new JMethodCall(program, toBox.getSourceInfo(), null,
- valueOfMethod);
+ JMethodCall call = new JMethodCall(toBox.getSourceInfo(), null, valueOfMethod);
call.addArg(toBox);
return call;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java b/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
index ae14c5b..dda0617 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
@@ -408,14 +408,14 @@
"new".toCharArray(), type, type, false, true, true, false, false);
// new Foo() : Create the instance
- JNewInstance newInstance = new JNewInstance(program,
+ JNewInstance newInstance = new JNewInstance(
type.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
"new instance"), type);
// (new Foo()).Foo() : Invoke the constructor method on the instance
- JMethodCall call = new JMethodCall(program,
- type.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
- "constructor invocation"), newInstance, constructor);
+ JMethodCall call = new JMethodCall(type.getSourceInfo().makeChild(
+ BuildDeclMapVisitor.class, "constructor invocation"), newInstance,
+ constructor);
/*
* If the type isn't static, make the first parameter a reference to the
* instance of the enclosing class. It's the first instance to allow the
@@ -440,16 +440,16 @@
* implicitly as the last argument to the constructor.
*/
if (enclosingInstance != null && !i.hasNext()) {
- call.addArg(new JParameterRef(program,
- synthetic.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
- "enclosing instance"), enclosingInstance));
+ call.addArg(new JParameterRef(synthetic.getSourceInfo().makeChild(
+ BuildDeclMapVisitor.class, "enclosing instance"),
+ enclosingInstance));
} else {
JParameter syntheticParam = program.createParameter(
synthetic.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
"Argument " + param.getName()),
param.getName().toCharArray(), param.getType(), true, false,
synthetic);
- call.addArg(new JParameterRef(program,
+ call.addArg(new JParameterRef(
syntheticParam.getSourceInfo().makeChild(
BuildDeclMapVisitor.class, "reference"), syntheticParam));
}
@@ -459,7 +459,7 @@
synthetic.freezeParamTypes();
// return (new Foo()).Foo() : The only statement in the function
- JReturnStatement ret = new JReturnStatement(program,
+ JReturnStatement ret = new JReturnStatement(
synthetic.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
"Return statement"), call);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java
index ed0c1cb..c883ac7 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java
@@ -104,9 +104,9 @@
// the 0th entry is the "always false" entry
classes.add(null);
- jsonObjects.add(new JsonObject(program,
- program.createSourceInfoSynthetic(AssignTypeIdsVisitor.class,
- "always-false typeinfo entry")));
+ jsonObjects.add(new JsonObject(program.createSourceInfoSynthetic(AssignTypeIdsVisitor.class,
+ "always-false typeinfo entry"),
+ program.getJavaScriptObject()));
/*
* Do String first to reserve typeIds 1 and 2 for Object and String,
@@ -265,14 +265,14 @@
// Create a sparse lookup object.
SourceInfo sourceInfo = program.createSourceInfoSynthetic(
AssignTypeIdsVisitor.class, "typeinfo lookup");
- JsonObject jsonObject = new JsonObject(program, sourceInfo);
+ JsonObject jsonObject = new JsonObject(sourceInfo, program.getJavaScriptObject());
// Start at 1; 0 is Object and always true.
for (int i = 1; i < nextQueryId; ++i) {
if (yesArray[i] != null) {
JIntLiteral labelExpr = program.getLiteralInt(i);
JIntLiteral valueExpr = program.getLiteralInt(1);
- jsonObject.propInits.add(new JsonPropInit(program, sourceInfo,
- labelExpr, valueExpr));
+ jsonObject.propInits.add(new JsonPropInit(sourceInfo, labelExpr,
+ valueExpr));
}
}
@@ -342,17 +342,17 @@
JExpression newLhs = convertString(x.getLhs());
JExpression newRhs = convertString(x.getRhs());
if (newLhs != x.getLhs() || newRhs != x.getRhs()) {
- JBinaryOperation newExpr = new JBinaryOperation(program,
- x.getSourceInfo(), program.getTypeJavaLangString(),
- JBinaryOperator.ADD, newLhs, newRhs);
+ JBinaryOperation newExpr = new JBinaryOperation(x.getSourceInfo(),
+ program.getTypeJavaLangString(), JBinaryOperator.ADD,
+ newLhs, newRhs);
ctx.replaceMe(newExpr);
}
} else if (x.getOp() == JBinaryOperator.ASG_ADD) {
JExpression newRhs = convertString(x.getRhs());
if (newRhs != x.getRhs()) {
- JBinaryOperation newExpr = new JBinaryOperation(program,
- x.getSourceInfo(), program.getTypeJavaLangString(),
- JBinaryOperator.ASG_ADD, x.getLhs(), newRhs);
+ JBinaryOperation newExpr = new JBinaryOperation(x.getSourceInfo(),
+ program.getTypeJavaLangString(), JBinaryOperator.ASG_ADD,
+ x.getLhs(), newRhs);
ctx.replaceMe(newExpr);
}
}
@@ -367,15 +367,14 @@
new char[] {charLit.getValue()});
} else {
// Replace with Cast.charToString(c)
- JMethodCall call = new JMethodCall(program, expr.getSourceInfo(),
- null, program.getIndexedMethod("Cast.charToString"));
+ JMethodCall call = new JMethodCall(expr.getSourceInfo(), null,
+ program.getIndexedMethod("Cast.charToString"));
call.addArg(expr);
return call;
}
} else if (expr.getType() == program.getTypePrimitiveLong()) {
// Replace with LongLib.toString(l)
- JMethodCall call = new JMethodCall(program, expr.getSourceInfo(), null,
- program.getIndexedMethod("LongLib.toString"));
+ JMethodCall call = new JMethodCall(expr.getSourceInfo(), null, program.getIndexedMethod("LongLib.toString"));
call.addArg(expr);
return call;
}
@@ -401,8 +400,8 @@
*/
String methodName = "Cast.narrow_" + type.getName();
JMethod castMethod = program.getIndexedMethod(methodName);
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- castMethod, type);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, castMethod,
+ type);
x.setType(program.getTypePrimitiveDouble());
call.addArg(x);
ctx.replaceMe(call);
@@ -443,8 +442,8 @@
/*
* Override the type of the magic method with the null type.
*/
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- method, program.getTypeNull());
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, method,
+ program.getTypeNull());
call.addArg(expr);
replaceExpr = call;
} else if (toType instanceof JReferenceType) {
@@ -469,8 +468,8 @@
method = program.getIndexedMethod("Cast.dynamicCast");
}
// override the type of the called method with the target cast type
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- method, toType);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, method,
+ toType);
call.addArg(curExpr);
if (!isJsoCast) {
JIntLiteral qId = program.getLiteralInt(queryIds.get(refType));
@@ -503,8 +502,8 @@
* do the narrowing conversion.
*/
JMethod castMethod = program.getIndexedMethod("LongLib.toInt");
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(),
- null, castMethod);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null,
+ castMethod);
call.addArg(expr);
expr = call;
fromType = tInt;
@@ -548,8 +547,8 @@
if (methodName != null) {
JMethod castMethod = program.getIndexedMethod(methodName);
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- castMethod, toType);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, castMethod,
+ toType);
call.addArg(expr);
replaceExpr = call;
} else {
@@ -567,9 +566,9 @@
if (program.typeOracle.canTriviallyCast(argType, toType)) {
// trivially true if non-null; replace with a null test
JNullLiteral nullLit = program.getLiteralNull();
- JBinaryOperation eq = new JBinaryOperation(program, x.getSourceInfo(),
- program.getTypePrimitiveBoolean(), JBinaryOperator.NEQ,
- x.getExpr(), nullLit);
+ JBinaryOperation eq = new JBinaryOperation(x.getSourceInfo(), program.getTypePrimitiveBoolean(),
+ JBinaryOperator.NEQ, x.getExpr(),
+ nullLit);
ctx.replaceMe(eq);
} else {
JMethod method;
@@ -581,8 +580,7 @@
} else {
method = program.getIndexedMethod("Cast.instanceOf");
}
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- method);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, method);
call.addArg(x.getExpr());
if (!isJsoCast) {
JIntLiteral qId = program.getLiteralInt(queryIds.get(toType));
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java
index 87eb406..36f6156 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java
@@ -65,11 +65,11 @@
SourceInfo catchInfo = x.getCatchBlocks().get(0).getSourceInfo();
JLocal exObj = popTempLocal();
- JLocalRef exRef = new JLocalRef(program, catchInfo, exObj);
- JBlock newCatchBlock = new JBlock(program, catchInfo);
+ JLocalRef exRef = new JLocalRef(catchInfo, exObj);
+ JBlock newCatchBlock = new JBlock(catchInfo);
// $e = Exceptions.caught($e)
JMethod caughtMethod = program.getIndexedMethod("Exceptions.caught");
- JMethodCall call = new JMethodCall(program, catchInfo, null, caughtMethod);
+ JMethodCall call = new JMethodCall(catchInfo, null, caughtMethod);
call.addArg(exRef);
JExpressionStatement asg = program.createAssignmentStmt(catchInfo, exRef,
call);
@@ -82,21 +82,21 @@
* Go backwards so we can nest the else statements in the correct order!
*/
// rethrow the current exception if no one caught it
- JStatement cur = new JThrowStatement(program, catchInfo, exRef);
+ JStatement cur = new JThrowStatement(catchInfo, exRef);
for (int i = x.getCatchBlocks().size() - 1; i >= 0; --i) {
JBlock block = x.getCatchBlocks().get(i);
JLocalRef arg = x.getCatchArgs().get(i);
catchInfo = block.getSourceInfo();
JReferenceType argType = (JReferenceType) arg.getType();
// if ($e instanceof ArgType) { userVar = $e; <user code> }
- JExpression ifTest = new JInstanceOf(program, catchInfo, argType, exRef);
+ JExpression ifTest = new JInstanceOf(catchInfo, argType, exRef);
asg = program.createAssignmentStmt(catchInfo, arg, exRef);
if (!block.getStatements().isEmpty()) {
// Only bother adding the assignment if the block is non-empty
block.addStmt(0, asg);
}
// nest the previous as an else for me
- cur = new JIfStatement(program, catchInfo, ifTest, block, cur);
+ cur = new JIfStatement(catchInfo, ifTest, block, cur);
}
newCatchBlock.addStmt(cur);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java b/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java
index c7d6e6b..6d858bf 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java
@@ -103,15 +103,15 @@
@Override
public boolean visit(JArrayRef x, Context ctx) {
- expression = new JArrayRef(program, x.getSourceInfo(),
+ expression = new JArrayRef(x.getSourceInfo(),
cloneExpression(x.getInstance()), cloneExpression(x.getIndexExpr()));
return false;
}
@Override
public boolean visit(JBinaryOperation x, Context ctx) {
- expression = new JBinaryOperation(program, x.getSourceInfo(), x.getType(),
- x.getOp(), cloneExpression(x.getLhs()), cloneExpression(x.getRhs()));
+ expression = new JBinaryOperation(x.getSourceInfo(), x.getType(), x.getOp(),
+ cloneExpression(x.getLhs()), cloneExpression(x.getRhs()));
return false;
}
@@ -123,8 +123,8 @@
@Override
public boolean visit(JCastOperation x, Context ctx) {
- expression = new JCastOperation(program, x.getSourceInfo(),
- x.getCastType(), cloneExpression(x.getExpr()));
+ expression = new JCastOperation(x.getSourceInfo(), x.getCastType(),
+ cloneExpression(x.getExpr()));
return false;
}
@@ -142,15 +142,15 @@
@Override
public boolean visit(JClassSeed x, Context ctx) {
- expression = new JClassSeed(program, x.getSourceInfo(), x.getRefType());
+ expression = new JClassSeed(x.getSourceInfo(), x.getRefType(),
+ program.getTypeJavaLangObject());
return false;
}
@Override
public boolean visit(JConditional x, Context ctx) {
- expression = new JConditional(program, x.getSourceInfo(), x.getType(),
- cloneExpression(x.getIfTest()), cloneExpression(x.getThenExpr()),
- cloneExpression(x.getElseExpr()));
+ expression = new JConditional(x.getSourceInfo(), x.getType(), cloneExpression(x.getIfTest()),
+ cloneExpression(x.getThenExpr()), cloneExpression(x.getElseExpr()));
return false;
}
@@ -162,8 +162,8 @@
@Override
public boolean visit(JFieldRef x, Context ctx) {
- expression = new JFieldRef(program, x.getSourceInfo(),
- cloneExpression(x.getInstance()), x.getField(), x.getEnclosingType());
+ expression = new JFieldRef(x.getSourceInfo(), cloneExpression(x.getInstance()),
+ x.getField(), x.getEnclosingType());
return false;
}
@@ -182,9 +182,8 @@
}
// Use the clone constructor.
- JGwtCreate gwtCreate = new JGwtCreate(program, x.getSourceInfo(),
- x.getSourceType(), x.getResultTypes(), x.getType(),
- cloneExpressions(x.getInstantiationExpressions()));
+ JGwtCreate gwtCreate = new JGwtCreate(x.getSourceInfo(), x.getSourceType(),
+ x.getResultTypes(), x.getType(), cloneExpressions(x.getInstantiationExpressions()));
expression = gwtCreate;
return false;
@@ -192,7 +191,7 @@
@Override
public boolean visit(JInstanceOf x, Context ctx) {
- expression = new JInstanceOf(program, x.getSourceInfo(), x.getTestType(),
+ expression = new JInstanceOf(x.getSourceInfo(), x.getTestType(),
cloneExpression(x.getExpr()));
return false;
}
@@ -205,7 +204,7 @@
@Override
public boolean visit(JLocalRef x, Context ctx) {
- expression = new JLocalRef(program, x.getSourceInfo(), x.getLocal());
+ expression = new JLocalRef(x.getSourceInfo(), x.getLocal());
return false;
}
@@ -217,7 +216,7 @@
@Override
public boolean visit(JMethodCall x, Context ctx) {
- JMethodCall newMethodCall = new JMethodCall(program, x.getSourceInfo(),
+ JMethodCall newMethodCall = new JMethodCall(x.getSourceInfo(),
cloneExpression(x.getInstance()), x.getTarget());
if (!x.canBePolymorphic()) {
newMethodCall.setCannotBePolymorphic();
@@ -231,7 +230,7 @@
@Override
public boolean visit(JMultiExpression x, Context ctx) {
- JMultiExpression multi = new JMultiExpression(program, x.getSourceInfo());
+ JMultiExpression multi = new JMultiExpression(x.getSourceInfo());
multi.exprs.addAll(cloneExpressions(x.exprs));
expression = multi;
return false;
@@ -239,15 +238,14 @@
@Override
public boolean visit(JNewArray x, Context ctx) {
- expression = new JNewArray(program, x.getSourceInfo(), x.getArrayType(),
- cloneExpressions(x.dims), cloneExpressions(x.initializers),
- x.getClassLiterals());
+ expression = new JNewArray(x.getSourceInfo(), x.getArrayType(), cloneExpressions(x.dims),
+ cloneExpressions(x.initializers), x.getClassLiterals());
return false;
}
@Override
public boolean visit(JNewInstance x, Context ctx) {
- expression = new JNewInstance(program, x.getSourceInfo(), x.getClassType());
+ expression = new JNewInstance(x.getSourceInfo(), x.getClassType());
return false;
}
@@ -259,21 +257,19 @@
@Override
public boolean visit(JParameterRef x, Context ctx) {
- expression = new JParameterRef(program, x.getSourceInfo(), x.getParameter());
+ expression = new JParameterRef(x.getSourceInfo(), x.getParameter());
return false;
}
@Override
public boolean visit(JPostfixOperation x, Context ctx) {
- expression = new JPostfixOperation(program, x.getSourceInfo(), x.getOp(),
- cloneExpression(x.getArg()));
+ expression = new JPostfixOperation(x.getSourceInfo(), x.getOp(), cloneExpression(x.getArg()));
return false;
}
@Override
public boolean visit(JPrefixOperation x, Context ctx) {
- expression = new JPrefixOperation(program, x.getSourceInfo(), x.getOp(),
- cloneExpression(x.getArg()));
+ expression = new JPrefixOperation(x.getSourceInfo(), x.getOp(), cloneExpression(x.getArg()));
return false;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/CompoundAssignmentNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/CompoundAssignmentNormalizer.java
index 3e7f668..4723c42 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/CompoundAssignmentNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/CompoundAssignmentNormalizer.java
@@ -92,17 +92,16 @@
*/
enterTempUsageScope();
ReplaceSideEffectsInLvalue replacer = new ReplaceSideEffectsInLvalue(
- new JMultiExpression(program, x.getSourceInfo()));
+ new JMultiExpression(x.getSourceInfo()));
JExpression newLhs = replacer.accept(x.getLhs());
exitTempUsageScope();
- JBinaryOperation operation = new JBinaryOperation(program,
- x.getSourceInfo(), newLhs.getType(), op.getNonAssignmentOf(), newLhs,
- x.getRhs());
+ JBinaryOperation operation = new JBinaryOperation(x.getSourceInfo(),
+ newLhs.getType(), op.getNonAssignmentOf(), newLhs, x.getRhs());
// newLhs is cloned below because it was used in operation
- JBinaryOperation asg = new JBinaryOperation(program, x.getSourceInfo(),
- newLhs.getType(), JBinaryOperator.ASG,
- cloner.cloneExpression(newLhs), operation);
+ JBinaryOperation asg = new JBinaryOperation(x.getSourceInfo(), newLhs.getType(),
+ JBinaryOperator.ASG, cloner.cloneExpression(newLhs),
+ operation);
JMultiExpression multiExpr = replacer.getMultiExpr();
if (multiExpr.exprs.isEmpty()) {
@@ -136,7 +135,7 @@
// First, replace the arg with a non-side-effect causing one.
enterTempUsageScope();
- JMultiExpression multi = new JMultiExpression(program, x.getSourceInfo());
+ JMultiExpression multi = new JMultiExpression(x.getSourceInfo());
ReplaceSideEffectsInLvalue replacer = new ReplaceSideEffectsInLvalue(
multi);
JExpression newArg = replacer.accept(x.getArg());
@@ -147,9 +146,9 @@
JLocal tempLocal = getTempLocal(expressionReturn.getType());
// t = x
- JLocalRef tempRef = new JLocalRef(program, x.getSourceInfo(), tempLocal);
- JBinaryOperation asg = new JBinaryOperation(program, x.getSourceInfo(),
- x.getType(), JBinaryOperator.ASG, tempRef, expressionReturn);
+ JLocalRef tempRef = new JLocalRef(x.getSourceInfo(), tempLocal);
+ JBinaryOperation asg = new JBinaryOperation(x.getSourceInfo(), x.getType(),
+ JBinaryOperator.ASG, tempRef, expressionReturn);
multi.exprs.add(asg);
// x += 1
@@ -158,7 +157,7 @@
multi.exprs.add(accept(asg));
// t
- tempRef = new JLocalRef(program, x.getSourceInfo(), tempLocal);
+ tempRef = new JLocalRef(x.getSourceInfo(), tempLocal);
multi.exprs.add(tempRef);
ctx.replaceMe(multi);
@@ -213,8 +212,8 @@
one = program.getLiteralInt(1);
}
// arg is cloned below because the caller is allowed to use it somewhere
- JBinaryOperation asg = new JBinaryOperation(program, arg.getSourceInfo(),
- arg.getType(), newOp, cloner.cloneExpression(arg), one);
+ JBinaryOperation asg = new JBinaryOperation(arg.getSourceInfo(), arg.getType(),
+ newOp, cloner.cloneExpression(arg), one);
return asg;
}
}
@@ -239,8 +238,8 @@
JExpression newInstance = possiblyReplace(x.getInstance());
JExpression newIndexExpr = possiblyReplace(x.getIndexExpr());
if (newInstance != x.getInstance() || newIndexExpr != x.getIndexExpr()) {
- JArrayRef newExpr = new JArrayRef(program, x.getSourceInfo(),
- newInstance, newIndexExpr);
+ JArrayRef newExpr = new JArrayRef(x.getSourceInfo(), newInstance,
+ newIndexExpr);
ctx.replaceMe(newExpr);
}
return false;
@@ -251,8 +250,8 @@
if (x.getInstance() != null) {
JExpression newInstance = possiblyReplace(x.getInstance());
if (newInstance != x.getInstance()) {
- JFieldRef newExpr = new JFieldRef(program, x.getSourceInfo(),
- newInstance, x.getField(), x.getEnclosingType());
+ JFieldRef newExpr = new JFieldRef(x.getSourceInfo(), newInstance,
+ x.getField(), x.getEnclosingType());
ctx.replaceMe(newExpr);
}
}
@@ -283,9 +282,9 @@
JLocal tempLocal = getTempLocal(x.getType());
// Create an assignment for this temp and add it to multi.
- JLocalRef tempRef = new JLocalRef(program, x.getSourceInfo(), tempLocal);
- JBinaryOperation asg = new JBinaryOperation(program, x.getSourceInfo(),
- x.getType(), JBinaryOperator.ASG, tempRef, x);
+ JLocalRef tempRef = new JLocalRef(x.getSourceInfo(), tempLocal);
+ JBinaryOperation asg = new JBinaryOperation(x.getSourceInfo(), x.getType(),
+ JBinaryOperator.ASG, tempRef, x);
multi.exprs.add(asg);
// Update me with the temp
return cloner.cloneExpression(tempRef);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
index 006a167..32b7018 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
@@ -32,7 +32,6 @@
import com.google.gwt.dev.jjs.ast.JDoubleLiteral;
import com.google.gwt.dev.jjs.ast.JExpression;
import com.google.gwt.dev.jjs.ast.JExpressionStatement;
-import com.google.gwt.dev.jjs.ast.JField;
import com.google.gwt.dev.jjs.ast.JFieldRef;
import com.google.gwt.dev.jjs.ast.JForStatement;
import com.google.gwt.dev.jjs.ast.JIfStatement;
@@ -318,7 +317,7 @@
*/
// We can inline the constant, but we might also need to evaluate an
// instance and run a clinit.
- JMultiExpression multi = new JMultiExpression(program, x.getSourceInfo());
+ JMultiExpression multi = new JMultiExpression(x.getSourceInfo());
JExpression instance = x.getInstance();
if (instance != null) {
@@ -348,7 +347,7 @@
// If false, replace the for statement with its initializers
if (!booleanLiteral.getValue()) {
- JBlock block = new JBlock(program, x.getSourceInfo());
+ JBlock block = new JBlock(x.getSourceInfo());
block.addStmts(x.getInitializers());
ctx.replaceMe(block);
}
@@ -403,7 +402,7 @@
tryOptimizeStringCall(x, ctx, target);
} else if (JProgram.isClinit(target)) {
// Eliminate the call if the target is now empty.
- if (!program.typeOracle.hasClinit(targetType)) {
+ if (!targetType.hasClinit()) {
ctx.replaceMe(program.getLiteralNull());
}
}
@@ -463,8 +462,8 @@
lvalues.remove(x.getArg());
}
if (ignoringExpressionOutput.contains(x)) {
- JPrefixOperation newOp = new JPrefixOperation(program,
- x.getSourceInfo(), x.getOp(), x.getArg());
+ JPrefixOperation newOp = new JPrefixOperation(x.getSourceInfo(),
+ x.getOp(), x.getArg());
ctx.replaceMe(newOp);
}
}
@@ -1176,19 +1175,12 @@
}
private JMethodCall maybeCreateClinitCall(JFieldRef x) {
- JMethodCall call;
- JField field = x.getField();
- if (field.isStatic()
- && !field.isCompileTimeConstant()
- && program.typeOracle.checkClinit(currentClass,
- field.getEnclosingType())) {
- JMethod clinit = field.getEnclosingType().methods.get(0);
+ if (x.hasClinit()) {
+ JMethod clinit = x.getField().getEnclosingType().methods.get(0);
assert (JProgram.isClinit(clinit));
- call = new JMethodCall(program, x.getSourceInfo(), null, clinit);
- } else {
- call = null;
+ return new JMethodCall(x.getSourceInfo(), null, clinit);
}
- return call;
+ return null;
}
private int numRemovableExpressions(JMultiExpression x) {
@@ -1264,7 +1256,7 @@
ctx.removeMe();
} else {
// empty block statement
- ctx.replaceMe(new JBlock(program, stmt.getSourceInfo()));
+ ctx.replaceMe(new JBlock(stmt.getSourceInfo()));
}
}
@@ -1350,8 +1342,8 @@
if (bool) {
ctx.replaceMe(exp);
} else {
- ctx.replaceMe(new JPrefixOperation(program, exp.getSourceInfo(),
- JUnaryOperator.NOT, exp));
+ ctx.replaceMe(new JPrefixOperation(exp.getSourceInfo(), JUnaryOperator.NOT,
+ exp));
}
}
@@ -1456,8 +1448,8 @@
if (original != null) {
return original;
}
- return new JPrefixOperation(program, exp.getSourceInfo(),
- JUnaryOperator.NEG, exp);
+ return new JPrefixOperation(exp.getSourceInfo(), JUnaryOperator.NEG,
+ exp);
}
private boolean simplifySub(JExpression lhs, JExpression rhs, Context ctx,
@@ -1475,8 +1467,8 @@
private void simplifyXor(JExpression lhs, JBooleanLiteral rhs, Context ctx) {
if (rhs.getValue()) {
- ctx.replaceMe(new JPrefixOperation(program, lhs.getSourceInfo(),
- JUnaryOperator.NOT, lhs));
+ ctx.replaceMe(new JPrefixOperation(lhs.getSourceInfo(), JUnaryOperator.NOT,
+ lhs));
} else {
ctx.replaceMe(lhs);
}
@@ -1677,17 +1669,17 @@
if (caseStatement.getExpr() != null) {
// Create an if statement equivalent to the single-case switch.
- JBinaryOperation compareOperation = new JBinaryOperation(program,
- x.getSourceInfo(), program.getTypePrimitiveBoolean(),
- JBinaryOperator.EQ, x.getExpr(), caseStatement.getExpr());
- JBlock block = new JBlock(program, x.getSourceInfo());
+ JBinaryOperation compareOperation = new JBinaryOperation(x.getSourceInfo(),
+ program.getTypePrimitiveBoolean(), JBinaryOperator.EQ,
+ x.getExpr(), caseStatement.getExpr());
+ JBlock block = new JBlock(x.getSourceInfo());
block.addStmt(statement);
- JIfStatement ifStatement = new JIfStatement(program,
- x.getSourceInfo(), compareOperation, block, null);
+ JIfStatement ifStatement = new JIfStatement(x.getSourceInfo(),
+ compareOperation, block, null);
ctx.replaceMe(ifStatement);
} else {
// All we have is a default case; convert to a JBlock.
- JBlock block = new JBlock(program, x.getSourceInfo());
+ JBlock block = new JBlock(x.getSourceInfo());
block.addStmt(x.getExpr().makeStatement());
block.addStmt(statement);
ctx.replaceMe(block);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/EqualityNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/EqualityNormalizer.java
index 56145f5..83578f5 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/EqualityNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/EqualityNormalizer.java
@@ -89,8 +89,8 @@
// Mask each side to prevent null === undefined.
lhs = maskUndefined(lhs);
rhs = maskUndefined(rhs);
- JBinaryOperation binOp = new JBinaryOperation(program,
- x.getSourceInfo(), x.getType(), x.getOp(), lhs, rhs);
+ JBinaryOperation binOp = new JBinaryOperation(x.getSourceInfo(),
+ x.getType(), x.getOp(), lhs, rhs);
ctx.replaceMe(binOp);
} else {
boolean lhsNullLit = lhs == program.getLiteralNull();
@@ -108,8 +108,7 @@
methodName = "Cast.isNotNull";
}
JMethod isNullMethod = program.getIndexedMethod(methodName);
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- isNullMethod);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, isNullMethod);
call.addArg(lhsNullLit ? rhs : lhs);
ctx.replaceMe(call);
} else {
@@ -121,8 +120,7 @@
methodName = "Cast.jsNotEquals";
}
JMethod eqMethod = program.getIndexedMethod(methodName);
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- eqMethod);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, eqMethod);
call.addArgs(lhs, rhs);
ctx.replaceMe(call);
}
@@ -144,8 +142,8 @@
private JExpression maskUndefined(JExpression lhs) {
JMethod maskMethod = program.getIndexedMethod("Cast.maskUndefined");
- JMethodCall lhsCall = new JMethodCall(program, lhs.getSourceInfo(), null,
- maskMethod, lhs.getType());
+ JMethodCall lhsCall = new JMethodCall(lhs.getSourceInfo(), null, maskMethod,
+ lhs.getType());
lhsCall.addArg(lhs);
return lhsCall;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/FixAssignmentToUnbox.java b/dev/core/src/com/google/gwt/dev/jjs/impl/FixAssignmentToUnbox.java
index f03b87e..14a4fbb 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/FixAssignmentToUnbox.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/FixAssignmentToUnbox.java
@@ -100,10 +100,8 @@
}
private final AutoboxUtils autoboxUtils;
- private final JProgram program;
private FixAssignmentToUnbox(JProgram program) {
- this.program = program;
this.autoboxUtils = new AutoboxUtils(program);
}
@@ -120,7 +118,7 @@
// unbox(x) = foo -> x = box(foo)
JClassType boxedType = (JClassType) boxed.getType();
- ctx.replaceMe(new JBinaryOperation(program, x.getSourceInfo(), boxedType,
+ ctx.replaceMe(new JBinaryOperation(x.getSourceInfo(), boxedType,
JBinaryOperator.ASG, boxed, autoboxUtils.box(x.getRhs(), boxedType)));
return;
}
@@ -129,9 +127,8 @@
// Assignment-to-cast-operation, e.g.
// (Foo) x = foo -> x = foo
JCastOperation cast = (JCastOperation) lhs;
- JBinaryOperation newAsg = new JBinaryOperation(program,
- x.getSourceInfo(), x.getType(), JBinaryOperator.ASG, cast.getExpr(),
- x.getRhs());
+ JBinaryOperation newAsg = new JBinaryOperation(x.getSourceInfo(),
+ x.getType(), JBinaryOperator.ASG, cast.getExpr(), x.getRhs());
ctx.replaceMe(newAsg);
}
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
index b167f50..db0d928 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
@@ -383,8 +383,8 @@
if (currentClass.extnds != null) {
JMethod myClinit = currentClass.methods.get(0);
JMethod superClinit = currentClass.extnds.methods.get(0);
- JMethodCall superClinitCall = new JMethodCall(program,
- myClinit.getSourceInfo(), null, superClinit);
+ JMethodCall superClinitCall = new JMethodCall(myClinit.getSourceInfo(),
+ null, superClinit);
JMethodBody body = (JMethodBody) myClinit.getBody();
body.getBlock().addStmt(0, superClinitCall.makeStatement());
}
@@ -469,14 +469,13 @@
JMethod nameMethod = program.getIndexedMethod("Class.getName");
// this.hashCode()
- JMethodCall hashCall = new JMethodCall(program, info,
- program.getExprThisRef(info, (JClassType) currentClass),
+ JMethodCall hashCall = new JMethodCall(info, program.getExprThisRef(info, (JClassType) currentClass),
program.getIndexedMethod("Object.hashCode"));
// "Class$" + hashCode()
- JBinaryOperation op = new JBinaryOperation(program, info,
- program.getTypeJavaLangString(), JBinaryOperator.ADD,
- program.getLiteralString(info, "Class$"), hashCall);
+ JBinaryOperation op = new JBinaryOperation(info, program.getTypeJavaLangString(),
+ JBinaryOperator.ADD, program.getLiteralString(info, "Class$"),
+ hashCall);
implementMethod(nameMethod, op);
@@ -676,8 +675,7 @@
// Call clinit; $clinit is always in position 0.
JMethod clinitMethod = enclosingType.methods.get(0);
- JMethodCall clinitCall = new JMethodCall(program, info, null,
- clinitMethod);
+ JMethodCall clinitCall = new JMethodCall(info, null, clinitMethod);
JMethodBody body = (JMethodBody) ctor.getBody();
JBlock block = body.getBlock();
block.addStmt(clinitCall.makeStatement());
@@ -743,8 +741,7 @@
if (!hasExplicitThis) {
// $init is always in position 1 (clinit is in 0)
JMethod initMethod = enclosingType.methods.get(1);
- JMethodCall initCall = new JMethodCall(program, info, thisRef,
- initMethod);
+ JMethodCall initCall = new JMethodCall(info, thisRef, initMethod);
block.addStmt(initCall.makeStatement());
}
@@ -763,7 +760,7 @@
currentMethod = null;
// synthesize a return statement to emulate returning the new object
- block.addStmt(new JReturnStatement(program, info, thisRef));
+ block.addStmt(new JReturnStatement(info, thisRef));
} catch (Throwable e) {
throw translateException(ctor, e);
}
@@ -812,10 +809,10 @@
throw new InternalCompilerException(
"String constructor error; no matching implementation.");
}
- call = new JMethodCall(program, makeSourceInfo(x), null, targetMethod);
+ call = new JMethodCall(makeSourceInfo(x), null, targetMethod);
} else {
- JNewInstance newInstance = new JNewInstance(program, info, newType);
- call = new JMethodCall(program, info, newInstance, ctor);
+ JNewInstance newInstance = new JNewInstance(info, newType);
+ call = new JMethodCall(info, newInstance, ctor);
}
// Enums: hidden arguments for the name and id.
@@ -901,8 +898,8 @@
JExpression processExpression(ArrayReference x) {
SourceInfo info = makeSourceInfo(x);
- JArrayRef arrayRef = new JArrayRef(program, info,
- dispProcessExpression(x.receiver), dispProcessExpression(x.position));
+ JArrayRef arrayRef = new JArrayRef(info, dispProcessExpression(x.receiver),
+ dispProcessExpression(x.position));
return arrayRef;
}
@@ -976,8 +973,7 @@
JExpression processExpression(CastExpression x) {
SourceInfo info = makeSourceInfo(x);
JType type = (JType) typeMap.get(x.resolvedType);
- JCastOperation cast = new JCastOperation(program, info, type,
- dispProcessExpression(x.expression));
+ JCastOperation cast = new JCastOperation(info, type, dispProcessExpression(x.expression));
return cast;
}
@@ -1043,8 +1039,8 @@
JExpression ifTest = dispProcessExpression(x.condition);
JExpression thenExpr = dispProcessExpression(x.valueIfTrue);
JExpression elseExpr = dispProcessExpression(x.valueIfFalse);
- JConditional conditional = new JConditional(program, info, type, ifTest,
- thenExpr, elseExpr);
+ JConditional conditional = new JConditional(info, type, ifTest, thenExpr,
+ elseExpr);
return conditional;
}
@@ -1093,8 +1089,7 @@
}
SourceInfo info = makeSourceInfo(x);
JExpression instance = dispProcessExpression(x.receiver);
- JExpression fieldRef = new JFieldRef(program, info, instance, field,
- currentClass);
+ JExpression fieldRef = new JFieldRef(info, instance, field, currentClass);
if (x.genericCast != null) {
JType castType = (JType) typeMap.get(x.genericCast);
@@ -1111,7 +1106,7 @@
SourceInfo info = makeSourceInfo(x);
JExpression expr = dispProcessExpression(x.expression);
JReferenceType testType = (JReferenceType) typeMap.get(x.type.resolvedType);
- return new JInstanceOf(program, info, testType, expr);
+ return new JInstanceOf(info, testType, expr);
}
JExpression processExpression(MessageSend x) {
@@ -1138,7 +1133,7 @@
qualifier = dispProcessExpression(x.receiver);
}
- JMethodCall call = new JMethodCall(program, info, qualifier, method);
+ JMethodCall call = new JMethodCall(info, qualifier, method);
// On a super ref, don't allow polymorphic dispatch. Oddly enough,
// QualifiedSuperReference not derived from SuperReference!
@@ -1187,8 +1182,7 @@
throw new InternalCompilerException("Unexpected postfix operator");
}
- JPostfixOperation postOp = new JPostfixOperation(program, info, op,
- dispProcessExpression(x.lhs));
+ JPostfixOperation postOp = new JPostfixOperation(info, op, dispProcessExpression(x.lhs));
return postOp;
}
@@ -1209,8 +1203,7 @@
throw new InternalCompilerException("Unexpected prefix operator");
}
- JPrefixOperation preOp = new JPrefixOperation(program, info, op,
- dispProcessExpression(x.lhs));
+ JPrefixOperation preOp = new JPrefixOperation(info, op, dispProcessExpression(x.lhs));
return preOp;
}
@@ -1232,8 +1225,8 @@
MethodBinding b = x.binding;
JMethod ctor = (JMethod) typeMap.get(b);
JClassType enclosingType = (JClassType) ctor.getEnclosingType();
- JNewInstance newInstance = new JNewInstance(program, info, enclosingType);
- JMethodCall call = new JMethodCall(program, info, newInstance, ctor);
+ JNewInstance newInstance = new JNewInstance(info, enclosingType);
+ JMethodCall call = new JMethodCall(info, newInstance, ctor);
JExpression qualifier = dispProcessExpression(x.enclosingInstance);
List<JExpression> qualList = new ArrayList<JExpression>();
qualList.add(qualifier);
@@ -1312,7 +1305,7 @@
} else {
field = (JField) typeMap.get(fieldBinding);
}
- curRef = new JFieldRef(program, info, curRef, field, currentClass);
+ curRef = new JFieldRef(info, curRef, field, currentClass);
if (x.otherGenericCasts != null && x.otherGenericCasts[i] != null) {
JType castType = (JType) typeMap.get(x.otherGenericCasts[i]);
curRef = maybeCast(castType, curRef);
@@ -1359,7 +1352,7 @@
JField field = (JField) variable;
if (!field.isStatic()) {
JExpression instance = createThisRef(info, field.getEnclosingType());
- result = new JFieldRef(program, info, instance, field, currentClass);
+ result = new JFieldRef(info, instance, field, currentClass);
}
}
if (result == null) {
@@ -1416,8 +1409,7 @@
"Unexpected operator for unary expression");
}
- JPrefixOperation preOp = new JPrefixOperation(program, info, op,
- dispProcessExpression(x.expression));
+ JPrefixOperation preOp = new JPrefixOperation(info, op, dispProcessExpression(x.expression));
return preOp;
}
@@ -1459,8 +1451,8 @@
if (initializer != null) {
SourceInfo info = makeSourceInfo(declaration);
// JDeclarationStatement's ctor sets up the field's initializer.
- JStatement decl = new JDeclarationStatement(program, info,
- createVariableRef(info, field), initializer);
+ JStatement decl = new JDeclarationStatement(info, createVariableRef(info, field),
+ initializer);
// will either be init or clinit
currentMethodBody.getBlock().addStmt(decl);
}
@@ -1523,7 +1515,7 @@
SourceInfo info = makeSourceInfo(x);
JExpression expr = dispProcessExpression(x.assertExpression);
JExpression arg = dispProcessExpression(x.exceptionArgument);
- return new JAssertStatement(program, info, expr, arg);
+ return new JAssertStatement(info, expr, arg);
}
JBlock processStatement(Block x) {
@@ -1532,7 +1524,7 @@
}
SourceInfo info = makeSourceInfo(x);
- JBlock block = new JBlock(program, info);
+ JBlock block = new JBlock(info);
if (x.statements != null) {
for (int i = 0, n = x.statements.length; i < n; ++i) {
JStatement jstmt = dispProcessStatement(x.statements[i]);
@@ -1546,7 +1538,7 @@
JStatement processStatement(BreakStatement x) {
SourceInfo info = makeSourceInfo(x);
- return new JBreakStatement(program, info, getOrCreateLabel(info,
+ return new JBreakStatement(info, getOrCreateLabel(info,
currentMethod, x.label));
}
@@ -1558,16 +1550,15 @@
assert (expression instanceof JFieldRef);
JFieldRef fieldRef = (JFieldRef) expression;
JEnumField field = (JEnumField) fieldRef.getField();
- return new JCaseStatement(program, info,
- program.getLiteralInt(field.ordinal()));
+ return new JCaseStatement(info, program.getLiteralInt(field.ordinal()));
} else {
- return new JCaseStatement(program, info, (JLiteral) expression);
+ return new JCaseStatement(info, (JLiteral) expression);
}
}
JStatement processStatement(ContinueStatement x) {
SourceInfo info = makeSourceInfo(x);
- return new JContinueStatement(program, info, getOrCreateLabel(info,
+ return new JContinueStatement(info, getOrCreateLabel(info,
currentMethod, x.label));
}
@@ -1575,7 +1566,7 @@
SourceInfo info = makeSourceInfo(x);
JExpression loopTest = dispProcessExpression(x.condition);
JStatement loopBody = dispProcessStatement(x.action);
- JDoStatement stmt = new JDoStatement(program, info, loopTest, loopBody);
+ JDoStatement stmt = new JDoStatement(info, loopTest, loopBody);
return stmt;
}
@@ -1592,7 +1583,7 @@
if (action instanceof JBlock) {
body = (JBlock) action;
} else {
- body = new JBlock(program, info);
+ body = new JBlock(info);
body.addStmt(action);
}
@@ -1628,29 +1619,27 @@
initializers.add(createDeclaration(info, indexVar,
program.getLiteralInt(0)));
// int i$max = i$array.length
- initializers.add(createDeclaration(info, maxVar, new JFieldRef(program,
- info, createVariableRef(info, arrayVar),
- program.getIndexedField("Array.length"), currentClass)));
+ initializers.add(createDeclaration(info, maxVar, new JFieldRef(info,
+ createVariableRef(info, arrayVar), program.getIndexedField("Array.length"),
+ currentClass)));
// i$index < i$max
- JExpression condition = new JBinaryOperation(program, info,
- program.getTypePrimitiveBoolean(), JBinaryOperator.LT,
- createVariableRef(info, indexVar), createVariableRef(info, maxVar));
+ JExpression condition = new JBinaryOperation(info, program.getTypePrimitiveBoolean(),
+ JBinaryOperator.LT, createVariableRef(info, indexVar),
+ createVariableRef(info, maxVar));
// ++i$index
List<JExpressionStatement> increments = new ArrayList<JExpressionStatement>(
1);
- increments.add(new JPrefixOperation(program, info, JUnaryOperator.INC,
- createVariableRef(info, indexVar)).makeStatement());
+ increments.add(new JPrefixOperation(info, JUnaryOperator.INC, createVariableRef(info, indexVar)).makeStatement());
// T elementVar = i$array[i$index];
- elementDecl.initializer = new JArrayRef(program, info,
- createVariableRef(info, arrayVar),
+ elementDecl.initializer = new JArrayRef(info, createVariableRef(info, arrayVar),
createVariableRef(info, indexVar));
body.addStmt(0, elementDecl);
- result = new JForStatement(program, info, initializers, condition,
- increments, body);
+ result = new JForStatement(info, initializers, condition, increments,
+ body);
} else {
/**
* <pre>
@@ -1666,17 +1655,14 @@
List<JStatement> initializers = new ArrayList<JStatement>(1);
// Iterator<T> i$iterator = collection.iterator()
initializers.add(createDeclaration(info, iteratorVar, new JMethodCall(
- program, info, dispProcessExpression(x.collection),
- program.getIndexedMethod("Iterable.iterator"))));
+ info, dispProcessExpression(x.collection), program.getIndexedMethod("Iterable.iterator"))));
// i$iterator.hasNext()
- JExpression condition = new JMethodCall(program, info,
- createVariableRef(info, iteratorVar),
+ JExpression condition = new JMethodCall(info, createVariableRef(info, iteratorVar),
program.getIndexedMethod("Iterator.hasNext"));
// T elementVar = (T) i$iterator.next();
- elementDecl.initializer = new JMethodCall(program, info,
- createVariableRef(info, iteratorVar),
+ elementDecl.initializer = new JMethodCall(info, createVariableRef(info, iteratorVar),
program.getIndexedMethod("Iterator.next"));
// Perform any implicit reference type casts (due to generics).
@@ -1699,8 +1685,8 @@
body.addStmt(0, elementDecl);
- result = new JForStatement(program, info, initializers, condition,
- Collections.<JExpressionStatement> emptyList(), body);
+ result = new JForStatement(info, initializers, condition, Collections.<JExpressionStatement> emptyList(),
+ body);
}
// May need to box or unbox the element assignment.
@@ -1731,7 +1717,7 @@
JExpression expr = dispProcessExpression(x.condition);
List<JExpressionStatement> incr = processExpressionStatements(x.increments);
JStatement body = removeBody ? null : dispProcessStatement(x.action);
- return new JForStatement(program, info, init, expr, incr, body);
+ return new JForStatement(info, init, expr, incr, body);
}
JStatement processStatement(IfStatement x) {
@@ -1747,8 +1733,7 @@
: dispProcessStatement(x.thenStatement);
JStatement elseStmt = removeElse ? null
: dispProcessStatement(x.elseStatement);
- JIfStatement ifStmt = new JIfStatement(program, info, expr, thenStmt,
- elseStmt);
+ JIfStatement ifStmt = new JIfStatement(info, expr, thenStmt, elseStmt);
return ifStmt;
}
@@ -1758,16 +1743,16 @@
return null;
}
SourceInfo info = makeSourceInfo(x);
- return new JLabeledStatement(program, info, getOrCreateLabel(info,
+ return new JLabeledStatement(info, getOrCreateLabel(info,
currentMethod, x.label), body);
}
JStatement processStatement(LocalDeclaration x) {
SourceInfo info = makeSourceInfo(x);
JLocal local = (JLocal) typeMap.get(x.binding);
- JLocalRef localRef = new JLocalRef(program, info, local);
+ JLocalRef localRef = new JLocalRef(info, local);
JExpression initializer = dispProcessExpression(x.initialization);
- return new JDeclarationStatement(program, info, localRef, initializer);
+ return new JDeclarationStatement(info, localRef, initializer);
}
JStatement processStatement(ReturnStatement x) {
@@ -1780,11 +1765,10 @@
*/
JClassType enclosingType = (JClassType) currentMethod.getEnclosingType();
assert (x.expression == null);
- return new JReturnStatement(program, info, createThisRef(info,
+ return new JReturnStatement(info, createThisRef(info,
enclosingType));
} else {
- return new JReturnStatement(program, info,
- dispProcessExpression(x.expression));
+ return new JReturnStatement(info, dispProcessExpression(x.expression));
}
}
@@ -1793,12 +1777,11 @@
JExpression expression = dispProcessExpression(x.expression);
if (expression.getType() instanceof JClassType) {
// Must be an enum; synthesize a call to ordinal().
- expression = new JMethodCall(program, info, expression,
- program.getIndexedMethod("Enum.ordinal"));
+ expression = new JMethodCall(info, expression, program.getIndexedMethod("Enum.ordinal"));
}
- JBlock block = new JBlock(program, info);
+ JBlock block = new JBlock(info);
block.addStmts(processStatements(x.statements));
- return new JSwitchStatement(program, info, expression, block);
+ return new JSwitchStatement(info, expression, block);
}
JStatement processStatement(SynchronizedStatement x) {
@@ -1811,7 +1794,7 @@
JStatement processStatement(ThrowStatement x) {
SourceInfo info = makeSourceInfo(x);
JExpression toThrow = dispProcessExpression(x.exception);
- return new JThrowStatement(program, info, toThrow);
+ return new JThrowStatement(info, toThrow);
}
JStatement processStatement(TryStatement x) {
@@ -1829,8 +1812,7 @@
}
}
JBlock finallyBlock = (JBlock) dispProcessStatement(x.finallyBlock);
- return new JTryStatement(program, info, tryBlock, catchArgs, catchBlocks,
- finallyBlock);
+ return new JTryStatement(info, tryBlock, catchArgs, catchBlocks, finallyBlock);
}
@SuppressWarnings("unused")
@@ -1847,8 +1829,7 @@
SourceInfo info = makeSourceInfo(x);
JExpression loopTest = dispProcessExpression(x.condition);
JStatement loopBody = removeBody ? null : dispProcessStatement(x.action);
- JWhileStatement stmt = new JWhileStatement(program, info, loopTest,
- loopBody);
+ JWhileStatement stmt = new JWhileStatement(info, loopTest, loopBody);
return stmt;
}
@@ -1870,7 +1851,7 @@
SourceInfo info = makeSourceInfo(x);
JMethod ctor = (JMethod) typeMap.get(x.binding);
JExpression trueQualifier = createThisRef(info, currentClass);
- JMethodCall call = new JMethodCall(program, info, trueQualifier, ctor);
+ JMethodCall call = new JMethodCall(info, trueQualifier, ctor);
addCallArgs(x.arguments, call, x.binding);
@@ -1936,7 +1917,7 @@
SourceInfo info = makeSourceInfo(x);
JMethod ctor = (JMethod) typeMap.get(x.binding);
JExpression trueQualifier = createThisRef(info, currentClass);
- JMethodCall call = new JMethodCall(program, info, trueQualifier, ctor);
+ JMethodCall call = new JMethodCall(info, trueQualifier, ctor);
assert (x.qualification == null);
@@ -1967,8 +1948,7 @@
if (classType.fields.size() > 0) {
JField field = classType.fields.get(0);
if (field.getName().startsWith("this$")) {
- list.add(new JFieldRef(program, expr.getSourceInfo(), expr, field,
- currentClass));
+ list.add(new JFieldRef(expr.getSourceInfo(), expr, field, currentClass));
}
}
}
@@ -2060,17 +2040,17 @@
bridgeMethod.freezeParamTypes();
// create a call
- JMethodCall call = new JMethodCall(program,
+ JMethodCall call = new JMethodCall(program.createSourceInfoSynthetic(GenerateJavaAST.class,
+ "call to inherited method"),
+ program.getExprThisRef(
program.createSourceInfoSynthetic(GenerateJavaAST.class,
- "call to inherited method"), program.getExprThisRef(
- program.createSourceInfoSynthetic(GenerateJavaAST.class,
- "part of a bridge method"), clazz), implmeth);
+ "part of a bridge method"), clazz), implmeth);
for (int i = 0; i < bridgeMethod.getParams().size(); i++) {
JParameter param = bridgeMethod.getParams().get(i);
- JParameterRef paramRef = new JParameterRef(program,
- program.createSourceInfoSynthetic(GenerateJavaAST.class,
- "part of a bridge method"), param);
+ JParameterRef paramRef = new JParameterRef(program.createSourceInfoSynthetic(GenerateJavaAST.class,
+ "part of a bridge method"),
+ param);
call.addArg(maybeCast(implmeth.getParams().get(i).getType(), paramRef));
}
@@ -2079,9 +2059,9 @@
if (bridgeMethod.getType() == program.getTypeVoid()) {
callOrReturn = call.makeStatement();
} else {
- callOrReturn = new JReturnStatement(program,
- program.createSourceInfoSynthetic(GenerateJavaAST.class,
- "part of a bridge method"), call);
+ callOrReturn = new JReturnStatement(program.createSourceInfoSynthetic(GenerateJavaAST.class,
+ "part of a bridge method"),
+ call);
}
// create a body that is just that call
@@ -2107,21 +2087,20 @@
private JDeclarationStatement createDeclaration(SourceInfo info,
JLocal local, JExpression value) {
- return new JDeclarationStatement(program, info, new JLocalRef(program,
- info, local), value);
+ return new JDeclarationStatement(info, new JLocalRef(info,
+ local), value);
}
private JField createEnumValueMap(JEnumType type) {
SourceInfo sourceInfo = type.getSourceInfo().makeChild(
JavaASTGenerationVisitor.class, "enum value lookup map");
- JsonObject map = new JsonObject(program, sourceInfo);
+ JsonObject map = new JsonObject(sourceInfo, program.getJavaScriptObject());
for (JEnumField field : type.enumList) {
// JSON maps require leading underscores to prevent collisions.
JStringLiteral key = program.getLiteralString(field.getSourceInfo(),
"_" + field.getName());
- JFieldRef value = new JFieldRef(program, sourceInfo, null, field, type);
- map.propInits.add(new JsonObject.JsonPropInit(program, sourceInfo, key,
- value));
+ JFieldRef value = new JFieldRef(sourceInfo, null, field, type);
+ map.propInits.add(new JsonObject.JsonPropInit(sourceInfo, key, value));
}
JField mapField = program.createField(sourceInfo,
"enum$map".toCharArray(), type, map.getType(), true,
@@ -2228,14 +2207,14 @@
throw new InternalCompilerException(
"LocalRef referencing local in a different method.");
}
- return new JLocalRef(program, info, local);
+ return new JLocalRef(info, local);
} else if (variable instanceof JParameter) {
JParameter parameter = (JParameter) variable;
if (parameter.getEnclosingMethod() != currentMethod) {
throw new InternalCompilerException(
"ParameterRef referencing param in a different method.");
}
- return new JParameterRef(program, info, parameter);
+ return new JParameterRef(info, parameter);
} else if (variable instanceof JField) {
JField field = (JField) variable;
JExpression instance = null;
@@ -2248,7 +2227,7 @@
"FieldRef referencing field in a different type.");
}
}
- return new JFieldRef(program, info.makeChild(
+ return new JFieldRef(info.makeChild(
JavaASTGenerationVisitor.class, "Reference",
variable.getSourceInfo()), instance, field, currentClass);
}
@@ -2299,7 +2278,7 @@
}
JLabel jlabel = lblMap.get(sname);
if (jlabel == null) {
- jlabel = new JLabel(program, info, sname);
+ jlabel = new JLabel(info, sname);
lblMap.put(sname, jlabel);
}
return jlabel;
@@ -2353,7 +2332,7 @@
}
block.clear();
- block.addStmt(new JReturnStatement(program, info, returnValue));
+ block.addStmt(new JReturnStatement(info, returnValue));
}
/*
@@ -2412,8 +2391,7 @@
if (expected != expression.getType()) {
// Must be a generic; insert a cast operation.
JReferenceType toType = (JReferenceType) expected;
- return new JCastOperation(program, expression.getSourceInfo(), toType,
- expression);
+ return new JCastOperation(expression.getSourceInfo(), toType, expression);
} else {
return expression;
}
@@ -2480,8 +2458,8 @@
JBinaryOperator op, JType type, Expression arg1, Expression arg2) {
JExpression exprArg1 = dispProcessExpression(arg1);
JExpression exprArg2 = dispProcessExpression(arg2);
- JBinaryOperation binaryOperation = new JBinaryOperation(program, info,
- type, op, exprArg1, exprArg2);
+ JBinaryOperation binaryOperation = new JBinaryOperation(info, type,
+ op, exprArg1, exprArg2);
return binaryOperation;
}
@@ -2652,8 +2630,8 @@
+ primitiveType.getName() + " " + valueMethodName + "()'", null);
}
- JMethodCall unboxCall = new JMethodCall(program, toUnbox.getSourceInfo(),
- toUnbox, valueMethod);
+ JMethodCall unboxCall = new JMethodCall(toUnbox.getSourceInfo(), toUnbox,
+ valueMethod);
return unboxCall;
}
@@ -2661,15 +2639,14 @@
// return Enum.valueOf(map, name);
SourceInfo sourceInfo = mapField.getSourceInfo().makeChild(
JavaASTGenerationVisitor.class, "enum accessor method");
- JFieldRef mapRef = new JFieldRef(program, sourceInfo, null, mapField,
- type);
+ JFieldRef mapRef = new JFieldRef(sourceInfo, null, mapField, type);
JVariableRef nameRef = createVariableRef(sourceInfo,
currentMethod.getParams().get(0));
JMethod delegateTo = program.getIndexedMethod("Enum.valueOf");
- JMethodCall call = new JMethodCall(program, sourceInfo, null, delegateTo);
+ JMethodCall call = new JMethodCall(sourceInfo, null, delegateTo);
call.addArgs(mapRef, nameRef);
currentMethodBody.getBlock().addStmt(
- new JReturnStatement(program, sourceInfo, call));
+ new JReturnStatement(sourceInfo, call));
}
private void writeEnumValuesMethod(JEnumType type) {
@@ -2678,14 +2655,13 @@
JavaASTGenerationVisitor.class, "enum values method");
List<JExpression> initializers = new ArrayList<JExpression>();
for (JEnumField field : type.enumList) {
- JFieldRef fieldRef = new JFieldRef(program, sourceInfo, null, field,
- type);
+ JFieldRef fieldRef = new JFieldRef(sourceInfo, null, field, type);
initializers.add(fieldRef);
}
JNewArray newExpr = JNewArray.createInitializers(program, sourceInfo,
program.getTypeArray(type, 1), initializers);
currentMethodBody.getBlock().addStmt(
- new JReturnStatement(program, sourceInfo, newExpr));
+ new JReturnStatement(sourceInfo, newExpr));
}
}
@@ -2867,8 +2843,8 @@
}
// Normal: create a jsniRef.
- JsniFieldRef fieldRef = new JsniFieldRef(program, info,
- nameRef.getIdent(), field, currentClass, ctx.isLvalue());
+ JsniFieldRef fieldRef = new JsniFieldRef(info, nameRef.getIdent(),
+ field, currentClass, ctx.isLvalue());
nativeMethodBody.addJsniRef(fieldRef);
}
@@ -2909,8 +2885,8 @@
+ method.getName());
}
- JsniMethodRef methodRef = new JsniMethodRef(program, info,
- nameRef.getIdent(), method);
+ JsniMethodRef methodRef = new JsniMethodRef(info, nameRef.getIdent(),
+ method, program.getJavaScriptObject());
nativeMethodBody.addJsniRef(methodRef);
}
@@ -2963,6 +2939,12 @@
public void endVisit(JsniMethodBody x, Context ctx) {
new JsniRefResolver(jsniMethodMap.get(x), x).accept(x.getFunc());
}
+
+ @Override
+ public boolean visit(JClassType x, Context ctx) {
+ currentClass = x;
+ return true;
+ }
}
/**
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
index f95c9d0..2ea57f3 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
@@ -567,7 +567,7 @@
List<JsFunction> jsFuncs = popList(x.methods.size()); // methods
List<JsNode> jsFields = popList(x.fields.size()); // fields
- if (typeOracle.hasClinit(x)) {
+ if (x.hasClinit()) {
JsFunction superClinit = clinitMap.get(x.extnds);
JsFunction myClinit = jsFuncs.get(0);
handleClinit(myClinit, superClinit);
@@ -820,7 +820,7 @@
List<JsVar> jsFields = popList(x.fields.size()); // fields
List<JsStatement> globalStmts = jsProgram.getGlobalBlock().getStatements();
- if (typeOracle.hasClinit(x)) {
+ if (x.hasClinit()) {
JsFunction clinitFunc = jsFuncs.get(0);
handleClinit(clinitFunc, null);
globalStmts.add(clinitFunc.makeStmt());
@@ -1643,15 +1643,14 @@
return null;
}
- JReferenceType enclosingType = x.getEnclosingType();
- if (!typeOracle.checkClinit(currentMethod.getEnclosingType(),
- enclosingType)) {
+ JReferenceType targetType = x.getEnclosingType();
+ if (!currentMethod.getEnclosingType().checkClinitTo(targetType)) {
return null;
- } else if (enclosingType.equals(program.getTypeClassLiteralHolder())) {
+ } else if (targetType.equals(program.getTypeClassLiteralHolder())) {
return null;
}
- JMethod clinitMethod = enclosingType.methods.get(0);
+ JMethod clinitMethod = targetType.methods.get(0);
SourceInfo sourceInfo = x.getSourceInfo().makeChild(
GenerateJavaScriptVisitor.class, "clinit invocation");
JsInvocation jsInvocation = new JsInvocation(sourceInfo);
@@ -1667,11 +1666,11 @@
return null;
}
JReferenceType enclosingType = x.getEnclosingType();
- if (!typeOracle.hasClinit(enclosingType)) {
+ if (enclosingType == null || !enclosingType.hasClinit()) {
return null;
}
// avoid recursion sickness
- if (x == enclosingType.methods.get(0)) {
+ if (JProgram.isClinit(x)) {
return null;
}
@@ -1752,7 +1751,7 @@
public void endVisit(JMethodCall x, Context ctx) {
JReferenceType sourceType = currentMethod.getEnclosingType();
JReferenceType targetType = x.getTarget().getEnclosingType();
- if (typeOracle.checkClinit(sourceType, targetType)) {
+ if (sourceType.checkClinitTo(targetType)) {
crossClassTargets.add(x.getTarget());
}
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/JavaScriptObjectNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/JavaScriptObjectNormalizer.java
index 67346c9..07ed412 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/JavaScriptObjectNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/JavaScriptObjectNormalizer.java
@@ -58,8 +58,7 @@
public void endVisit(JCastOperation x, Context ctx) {
JType newType = translate(x.getCastType());
if (newType != x.getCastType()) {
- ctx.replaceMe(new JCastOperation(program, x.getSourceInfo(), newType,
- x.getExpr()));
+ ctx.replaceMe(new JCastOperation(x.getSourceInfo(), newType, x.getExpr()));
}
}
@@ -80,8 +79,7 @@
public void endVisit(JInstanceOf x, Context ctx) {
JReferenceType newType = (JReferenceType) translate(x.getTestType());
if (newType != x.getTestType()) {
- ctx.replaceMe(new JInstanceOf(program, x.getSourceInfo(), newType,
- x.getExpr()));
+ ctx.replaceMe(new JInstanceOf(x.getSourceInfo(), newType, x.getExpr()));
}
}
@@ -126,20 +124,19 @@
/*
* This is the special-case code to handle interfaces.
*/
- JMultiExpression multi = new JMultiExpression(program, info);
+ JMultiExpression multi = new JMultiExpression(info);
JExpression instance = maybeMakeTempAssignment(multi, x.getInstance());
// instance.method(arg, arg)
- JMethodCall localCall = new JMethodCall(program, info, instance,
- x.getTarget());
+ JMethodCall localCall = new JMethodCall(info, instance, x.getTarget());
localCall.addArgs(x.getArgs());
// We need a second copy of the arguments for the else expression
CloneExpressionVisitor cloner = new CloneExpressionVisitor(program);
// instance.jsoMethod(arg, arg)
- JMethodCall jsoCall = new JMethodCall(program, info,
- cloner.cloneExpression(instance), jsoMethod);
+ JMethodCall jsoCall = new JMethodCall(info, cloner.cloneExpression(instance),
+ jsoMethod);
jsoCall.addArgs(cloner.cloneExpressions(x.getArgs()));
// Cast.isJavaScriptObject() ? instance.jsoMethod() :
@@ -155,8 +152,7 @@
* ... otherwise, if there's only a JSO implementation, we'll just
* call that directly.
*/
- JMethodCall jsoCall = new JMethodCall(program, info, x.getInstance(),
- jsoMethod);
+ JMethodCall jsoCall = new JMethodCall(info, x.getInstance(), jsoMethod);
jsoCall.addArgs(x.getArgs());
ctx.replaceMe(jsoCall);
}
@@ -198,11 +194,10 @@
JExpression notJsoExpr) {
// Cast.isJavaScriptObjectOrString(instance)
JMethod isJavaScriptObjectMethod = program.getIndexedMethod("Cast.isJavaScriptObjectOrString");
- JMethodCall isJavaScriptObjectExpr = new JMethodCall(program, info, null,
- isJavaScriptObjectMethod);
+ JMethodCall isJavaScriptObjectExpr = new JMethodCall(info, null, isJavaScriptObjectMethod);
isJavaScriptObjectExpr.addArg(instance);
- return new JConditional(program, info, conditionalType,
- isJavaScriptObjectExpr, isJsoExpr, notJsoExpr);
+ return new JConditional(info, conditionalType, isJavaScriptObjectExpr,
+ isJsoExpr, notJsoExpr);
}
private JExpression maybeMakeTempAssignment(JMultiExpression multi,
@@ -220,9 +215,9 @@
"maybeJsoInvocation".toCharArray(), instance.getType(), true,
currentMethodBody.peek());
multi.exprs.add(program.createAssignmentStmt(info,
- new JLocalRef(program, info, local), instance).getExpr());
+ new JLocalRef(info, local), instance).getExpr());
- instance = new JLocalRef(program, info, local);
+ instance = new JLocalRef(info, local);
}
return instance;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/JsoDevirtualizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/JsoDevirtualizer.java
index ce50ebc..01898e4 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/JsoDevirtualizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/JsoDevirtualizer.java
@@ -145,28 +145,28 @@
newMethod.freezeParamTypes();
// Build from bottom up.
- JMethodCall condition = new JMethodCall(program, sourceInfo, null,
+ JMethodCall condition = new JMethodCall(sourceInfo, null,
isJavaObjectMethod);
- condition.addArg(new JParameterRef(program, sourceInfo, thisParam));
+ condition.addArg(new JParameterRef(sourceInfo, thisParam));
- JMethodCall thenValue = new JMethodCall(program, sourceInfo,
- new JParameterRef(program, sourceInfo, thisParam), objectMethod);
+ JMethodCall thenValue = new JMethodCall(sourceInfo, new JParameterRef(
+ sourceInfo, thisParam), objectMethod);
for (JParameter param : newMethod.getParams()) {
if (param != thisParam) {
- thenValue.addArg(new JParameterRef(program, sourceInfo, param));
+ thenValue.addArg(new JParameterRef(sourceInfo, param));
}
}
- JMethodCall elseValue = new JMethodCall(program, sourceInfo, null, jsoImpl);
+ JMethodCall elseValue = new JMethodCall(sourceInfo, null, jsoImpl);
for (JParameter param : newMethod.getParams()) {
- elseValue.addArg(new JParameterRef(program, sourceInfo, param));
+ elseValue.addArg(new JParameterRef(sourceInfo, param));
}
- JConditional conditional = new JConditional(program, sourceInfo,
- objectMethod.getType(), condition, thenValue, elseValue);
+ JConditional conditional = new JConditional(sourceInfo, objectMethod.getType(),
+ condition, thenValue, elseValue);
- JReturnStatement returnStatement = new JReturnStatement(program,
- sourceInfo, conditional);
+ JReturnStatement returnStatement = new JReturnStatement(sourceInfo,
+ conditional);
((JMethodBody) newMethod.getBody()).getBlock().addStmt(returnStatement);
return newMethod;
}
@@ -187,7 +187,7 @@
return;
}
- CreateStaticImplsVisitor creator = new CreateStaticImplsVisitor();
+ CreateStaticImplsVisitor creator = new CreateStaticImplsVisitor(program);
for (JMethod method : virtualJsoMethods) {
// Ensure staticImpls exist for any instance methods.
JMethod jsoStaticImpl = program.getStaticImpl(method);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/LongCastNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/LongCastNormalizer.java
index 4788ef1..8e4f00e 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/LongCastNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/LongCastNormalizer.java
@@ -92,8 +92,8 @@
JExpression newLhs = checkAndReplace(x.getLhs(), lhsType);
JExpression newRhs = checkAndReplace(x.getRhs(), rhsType);
if (newLhs != x.getLhs() || newRhs != x.getRhs()) {
- JBinaryOperation binOp = new JBinaryOperation(program,
- x.getSourceInfo(), resultType, x.getOp(), newLhs, newRhs);
+ JBinaryOperation binOp = new JBinaryOperation(x.getSourceInfo(),
+ resultType, x.getOp(), newLhs, newRhs);
ctx.replaceMe(binOp);
}
}
@@ -103,8 +103,8 @@
JExpression newThen = checkAndReplace(x.getThenExpr(), x.getType());
JExpression newElse = checkAndReplace(x.getElseExpr(), x.getType());
if (newThen != x.getThenExpr() || newElse != x.getElseExpr()) {
- JConditional newCond = new JConditional(program, x.getSourceInfo(),
- x.getType(), x.getIfTest(), newThen, newElse);
+ JConditional newCond = new JConditional(x.getSourceInfo(), x.getType(),
+ x.getIfTest(), newThen, newElse);
ctx.replaceMe(newCond);
}
}
@@ -115,8 +115,8 @@
if (init != null) {
init = checkAndReplace(init, x.getVariableRef().getType());
if (init != x.getInitializer()) {
- JDeclarationStatement newStmt = new JDeclarationStatement(program,
- x.getSourceInfo(), x.getVariableRef(), init);
+ JDeclarationStatement newStmt = new JDeclarationStatement(x.getSourceInfo(),
+ x.getVariableRef(), init);
ctx.replaceMe(newStmt);
}
}
@@ -163,8 +163,8 @@
if (expr != null) {
JExpression newExpr = checkAndReplace(expr, currentMethod.getType());
if (expr != newExpr) {
- JReturnStatement newStmt = new JReturnStatement(program,
- x.getSourceInfo(), newExpr);
+ JReturnStatement newStmt = new JReturnStatement(x.getSourceInfo(),
+ newExpr);
ctx.replaceMe(newStmt);
}
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/LongEmulationNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/LongEmulationNormalizer.java
index 6fa52a6..5019920 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/LongEmulationNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/LongEmulationNormalizer.java
@@ -83,8 +83,8 @@
}
JMethod method = program.getIndexedMethod("LongLib." + methodName);
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- method, x.getType());
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, method,
+ x.getType());
call.addArgs(x.getLhs(), x.getRhs());
ctx.replaceMe(call);
}
@@ -107,8 +107,8 @@
String methodName = getEmulationMethod(x.getOp());
JMethod method = program.getIndexedMethod("LongLib." + methodName);
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- method, x.getType());
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), null, method,
+ x.getType());
call.addArg(x.getArg());
ctx.replaceMe(call);
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
index cfde638..6346f1e 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
@@ -113,21 +113,27 @@
@Override
public void endVisit(JParameterRef x, Context ctx) {
JParameter param = varMap.get(x.getTarget());
- JParameterRef paramRef = new JParameterRef(x.getProgram(),
- x.getSourceInfo().makeChild(RewriteMethodBody.class,
- "Reference to devirtualized parameter"), param);
+ JParameterRef paramRef = new JParameterRef(x.getSourceInfo().makeChild(
+ RewriteMethodBody.class, "Reference to devirtualized parameter"),
+ param);
ctx.replaceMe(paramRef);
}
@Override
public void endVisit(JThisRef x, Context ctx) {
- JParameterRef paramRef = new JParameterRef(x.getProgram(),
- x.getSourceInfo().makeChild(RewriteMethodBody.class,
- "Reference to devirtualized instance"), thisParam);
+ JParameterRef paramRef = new JParameterRef(x.getSourceInfo().makeChild(
+ RewriteMethodBody.class, "Reference to devirtualized instance"),
+ thisParam);
ctx.replaceMe(paramRef);
}
}
+ private JProgram program;
+
+ CreateStaticImplsVisitor(JProgram program) {
+ this.program = program;
+ }
+
@Override
public boolean visit(JMethod x, Context ctx) {
// Let's do it!
@@ -144,21 +150,20 @@
* Don't use the JProgram helper because it auto-adds the new method to
* its enclosing class.
*/
- JProgram program = x.getProgram();
- JMethod newMethod = new JMethod(program, sourceInfo.makeChild(
+ JMethod newMethod = new JMethod(sourceInfo.makeChild(
CreateStaticImplsVisitor.class, "Devirtualized function"), newName,
enclosingType, returnType, false, true, true, x.isPrivate());
// Setup parameters; map from the old params to the new params
- JParameter thisParam = program.createParameter(sourceInfo.makeChild(
- CreateStaticImplsVisitor.class, "Instance parameter"),
- "this$static".toCharArray(), enclosingType, true, true, newMethod);
+ JParameter thisParam = JParameter.create(sourceInfo.makeChild(
+ CreateStaticImplsVisitor.class, "Instance parameter"), "this$static",
+ enclosingType, true, true, newMethod);
Map<JParameter, JParameter> varMap = new IdentityHashMap<JParameter, JParameter>();
for (int i = 0; i < x.getParams().size(); ++i) {
JParameter oldVar = x.getParams().get(i);
- JParameter newVar = program.createParameter(oldVar.getSourceInfo(),
- oldVar.getName().toCharArray(), oldVar.getType(), oldVar.isFinal(),
- false, newMethod);
+ JParameter newVar = JParameter.create(oldVar.getSourceInfo(),
+ oldVar.getName(), oldVar.getType(), oldVar.isFinal(), false,
+ newMethod);
varMap.put(oldVar, newVar);
}
@@ -175,23 +180,20 @@
// Create a new body for the instance method that delegates to the static
SourceInfo delegateCallSourceInfo = sourceInfo.makeChild(
CreateStaticImplsVisitor.class, "Degelgating to devirtualized method");
- JMethodBody newBody = new JMethodBody(program, delegateCallSourceInfo);
+ JMethodBody newBody = new JMethodBody(delegateCallSourceInfo);
x.setBody(newBody);
- JMethodCall newCall = new JMethodCall(program, delegateCallSourceInfo,
- null, newMethod);
- newCall.addArg(
- program.getExprThisRef(delegateCallSourceInfo, enclosingType));
+ JMethodCall newCall = new JMethodCall(delegateCallSourceInfo, null,
+ newMethod);
+ newCall.addArg(new JThisRef(delegateCallSourceInfo, enclosingType));
for (int i = 0; i < x.getParams().size(); ++i) {
JParameter param = x.getParams().get(i);
- newCall.addArg(
- new JParameterRef(program, delegateCallSourceInfo, param));
+ newCall.addArg(new JParameterRef(delegateCallSourceInfo, param));
}
JStatement statement;
if (returnType == program.getTypeVoid()) {
statement = newCall.makeStatement();
} else {
- statement = new JReturnStatement(program, delegateCallSourceInfo,
- newCall);
+ statement = new JReturnStatement(delegateCallSourceInfo, newCall);
}
newBody.getBlock().addStmt(statement);
@@ -295,9 +297,8 @@
static JMethodCall makeStaticCall(JMethodCall x, JMethod newMethod) {
// Update the call site
- JMethodCall newCall = new JMethodCall(x.getProgram(),
- x.getSourceInfo().makeChild(MakeCallsStatic.class,
- "Devirtualized function call"), null, newMethod);
+ JMethodCall newCall = new JMethodCall(x.getSourceInfo().makeChild(
+ MakeCallsStatic.class, "Devirtualized function call"), null, newMethod);
// The qualifier becomes the first arg
newCall.addArg(x.getInstance());
@@ -317,7 +318,7 @@
FindStaticDispatchSitesVisitor finder = new FindStaticDispatchSitesVisitor();
finder.accept(program);
- CreateStaticImplsVisitor creator = new CreateStaticImplsVisitor();
+ CreateStaticImplsVisitor creator = new CreateStaticImplsVisitor(program);
for (JMethod method : toBeMadeStatic) {
creator.accept(method);
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodCallTightener.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodCallTightener.java
index 08d304e..c9d9b60 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodCallTightener.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodCallTightener.java
@@ -101,8 +101,8 @@
* Replace the call to the original method with a call to the same method
* on the tighter type.
*/
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(),
- x.getInstance(), foundMethod);
+ JMethodCall call = new JMethodCall(x.getSourceInfo(), x.getInstance(),
+ foundMethod);
call.addArgs(x.getArgs());
ctx.replaceMe(call);
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
index e223c2b..4f96422 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
@@ -148,8 +148,7 @@
private JMethodCall createClinitCall(JMethodCall x) {
JReferenceType targetEnclosingType = x.getTarget().getEnclosingType();
- if (!program.typeOracle.checkClinit(currentMethod.getEnclosingType(),
- targetEnclosingType)) {
+ if (!currentMethod.getEnclosingType().checkClinitTo(targetEnclosingType)) {
// Access from this class to the target class won't trigger a clinit
return null;
}
@@ -170,7 +169,7 @@
return null;
}
- return new JMethodCall(program, x.getSourceInfo(), null, clinit);
+ return new JMethodCall(x.getSourceInfo(), null, clinit);
}
/**
@@ -180,7 +179,7 @@
*/
private JMultiExpression createMultiExpressionForInstanceAndClinit(
JMethodCall x) {
- JMultiExpression multi = new JMultiExpression(program, x.getSourceInfo());
+ JMultiExpression multi = new JMultiExpression(x.getSourceInfo());
// Any instance expression goes first (this can happen even with statics).
if (x.getInstance() != null) {
@@ -207,8 +206,7 @@
*/
private JMultiExpression createMultiExpressionFromBody(JMethodBody body,
boolean ignoringReturnValue) {
- JMultiExpression multi = new JMultiExpression(program,
- body.getSourceInfo());
+ JMultiExpression multi = new JMultiExpression(body.getSourceInfo());
CloneCalleeExpressionVisitor cloner = new CloneCalleeExpressionVisitor();
for (JStatement stmt : body.getStatements()) {
@@ -458,8 +456,7 @@
* later, but in some cases it will force correct math evaluation.
*/
if (clone.getType() != x.getType()) {
- clone = new JCastOperation(program, clone.getSourceInfo(), x.getType(),
- clone);
+ clone = new JCastOperation(clone.getSourceInfo(), x.getType(), clone);
}
ctx.replaceMe(clone);
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
index 2e315aa..3948954 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
@@ -166,7 +166,7 @@
// This must be a static method
assert method.isStatic();
- JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
+ JMethodCall newCall = new JMethodCall(x.getSourceInfo(),
x.getInstance(), method);
if (!x.canBePolymorphic()) {
newCall.setCannotBePolymorphic();
@@ -193,7 +193,7 @@
} else if (arg.hasSideEffects()) {
// The argument is only needed for side effects, add it to a multi.
if (currentMulti == null) {
- currentMulti = new JMultiExpression(program, x.getSourceInfo());
+ currentMulti = new JMultiExpression(x.getSourceInfo());
}
currentMulti.exprs.add(arg);
}
@@ -214,9 +214,8 @@
String ident = x.getIdent();
JField nullField = program.getNullField();
program.jsniMap.put(ident, nullField);
- JsniFieldRef nullFieldRef = new JsniFieldRef(program,
- x.getSourceInfo(), ident, nullField, x.getEnclosingType(),
- x.isLvalue());
+ JsniFieldRef nullFieldRef = new JsniFieldRef(x.getSourceInfo(), ident,
+ nullField, x.getEnclosingType(), x.isLvalue());
ctx.replaceMe(nullFieldRef);
}
}
@@ -228,8 +227,8 @@
String ident = x.getIdent();
JMethod nullMethod = program.getNullMethod();
program.jsniMap.put(ident, nullMethod);
- JsniMethodRef nullMethodRef = new JsniMethodRef(program,
- x.getSourceInfo(), ident, nullMethod);
+ JsniMethodRef nullMethodRef = new JsniMethodRef(x.getSourceInfo(),
+ ident, nullMethod, program.getJavaScriptObject());
ctx.replaceMe(nullMethodRef);
}
}
@@ -267,7 +266,7 @@
private JExpression makeReplacementForAssignment(SourceInfo info,
JVariableRef variableRef, JExpression rhs) {
// Replace with a multi, which may wind up empty.
- JMultiExpression multi = new JMultiExpression(program, info);
+ JMultiExpression multi = new JMultiExpression(info);
// If the lhs is a field ref, evaluate it first.
if (variableRef instanceof JFieldRef) {
@@ -526,7 +525,7 @@
instance = program.getLiteralNull();
}
- JFieldRef fieldRef = new JFieldRef(program, x.getSourceInfo(), instance,
+ JFieldRef fieldRef = new JFieldRef(x.getSourceInfo(), instance,
program.getNullField(), x.getEnclosingType(), primitiveTypeOrNullType(
program, x.getType()));
return fieldRef;
@@ -568,7 +567,7 @@
instance = program.getLiteralNull();
}
- JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(), instance,
+ JMethodCall newCall = new JMethodCall(x.getSourceInfo(), instance,
program.getNullMethod(), primitiveTypeOrNullType(program, x.getType()));
// Retain the original arguments, they will be evaluated for side effects.
newCall.addArgs(args);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRebinds.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRebinds.java
index b95f1b8..eccd7e5 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRebinds.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRebinds.java
@@ -56,8 +56,8 @@
JClassLiteral classLiteral = (JClassLiteral) arg;
JReferenceType sourceType = (JReferenceType) classLiteral.getRefType();
List<JClassType> allRebindResults = getAllPossibleRebindResults(sourceType);
- JGwtCreate gwtCreate = new JGwtCreate(program, x.getSourceInfo(),
- sourceType, allRebindResults);
+ JGwtCreate gwtCreate = new JGwtCreate(x.getSourceInfo(), sourceType,
+ allRebindResults, program.getTypeJavaLangObject());
if (allRebindResults.size() == 1) {
// Just replace with the instantiation expression.
ctx.replaceMe(gwtCreate.getInstantiationExpressions().get(0));
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRunAsyncs.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRunAsyncs.java
index f5d2257..9a1cc8b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRunAsyncs.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceRunAsyncs.java
@@ -68,8 +68,8 @@
JMethod loadMethod = getRunAsyncMethod(loader);
assert loadMethod != null;
- JMethodCall methodCall = new JMethodCall(program, x.getSourceInfo(),
- null, loadMethod);
+ JMethodCall methodCall = new JMethodCall(x.getSourceInfo(), null,
+ loadMethod);
methodCall.addArg(asyncCallback);
program.addEntryMethod(getOnLoadMethod(loader), entryNumber);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Simplifier.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Simplifier.java
index 260b91f..e376f3b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/Simplifier.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Simplifier.java
@@ -113,7 +113,7 @@
if (original != null) {
return original;
}
- return new JCastOperation(program, exp.getSourceInfo(), type, exp);
+ return new JCastOperation(sourceInfo, type, exp);
}
public JExpression cast(JType type, JExpression exp) {
@@ -127,7 +127,7 @@
// (a,b,c)?d:e -> a,b,(c?d:e)
// TODO(spoon): do this outward multi movement for all AST nodes
JMultiExpression condMulti = (JMultiExpression) condExpr;
- JMultiExpression newMulti = new JMultiExpression(program, sourceInfo);
+ JMultiExpression newMulti = new JMultiExpression(sourceInfo);
newMulti.exprs.addAll(allButLast(condMulti.exprs));
newMulti.exprs.add(conditional(null, sourceInfo, type,
last(condMulti.exprs), thenExpr, elseExpr));
@@ -145,37 +145,36 @@
} else if (thenExpr instanceof JBooleanLiteral) {
if (((JBooleanLiteral) thenExpr).getValue()) {
// e.g. (cond ? true : else) -> cond || else
- JBinaryOperation binOp = new JBinaryOperation(program, sourceInfo,
- type, JBinaryOperator.OR, condExpr, elseExpr);
+ JBinaryOperation binOp = new JBinaryOperation(sourceInfo, type,
+ JBinaryOperator.OR, condExpr, elseExpr);
return binOp;
} else {
// e.g. (cond ? false : else) -> !cond && else
- JPrefixOperation notCondExpr = new JPrefixOperation(program,
+ JPrefixOperation notCondExpr = new JPrefixOperation(
condExpr.getSourceInfo(), JUnaryOperator.NOT, condExpr);
- JBinaryOperation binOp = new JBinaryOperation(program, sourceInfo,
- type, JBinaryOperator.AND, notCondExpr, elseExpr);
+ JBinaryOperation binOp = new JBinaryOperation(sourceInfo, type,
+ JBinaryOperator.AND, notCondExpr, elseExpr);
return binOp;
}
} else if (elseExpr instanceof JBooleanLiteral) {
if (((JBooleanLiteral) elseExpr).getValue()) {
// e.g. (cond ? then : true) -> !cond || then
- JPrefixOperation notCondExpr = new JPrefixOperation(program,
+ JPrefixOperation notCondExpr = new JPrefixOperation(
condExpr.getSourceInfo(), JUnaryOperator.NOT, condExpr);
- JBinaryOperation binOp = new JBinaryOperation(program, sourceInfo,
- type, JBinaryOperator.OR, notCondExpr, thenExpr);
+ JBinaryOperation binOp = new JBinaryOperation(sourceInfo, type,
+ JBinaryOperator.OR, notCondExpr, thenExpr);
return binOp;
} else {
// e.g. (cond ? then : false) -> cond && then
- JBinaryOperation binOp = new JBinaryOperation(program, sourceInfo,
- type, JBinaryOperator.AND, condExpr, thenExpr);
+ JBinaryOperation binOp = new JBinaryOperation(sourceInfo, type,
+ JBinaryOperator.AND, condExpr, thenExpr);
return binOp;
}
} else {
// e.g. (!cond ? then : else) -> (cond ? else : then)
JExpression unflipped = maybeUnflipBoolean(condExpr);
if (unflipped != null) {
- return new JConditional(program, sourceInfo, type, unflipped, elseExpr,
- thenExpr);
+ return new JConditional(sourceInfo, type, unflipped, elseExpr, thenExpr);
}
}
@@ -183,8 +182,7 @@
if (original != null) {
return original;
}
- return new JConditional(program, sourceInfo, type, condExpr, thenExpr,
- elseExpr);
+ return new JConditional(sourceInfo, type, condExpr, thenExpr, elseExpr);
}
public JStatement ifStatement(JIfStatement original, SourceInfo sourceInfo,
@@ -192,12 +190,12 @@
if (condExpr instanceof JMultiExpression) {
// if(a,b,c) d else e -> {a; b; if(c) d else e; }
JMultiExpression condMulti = (JMultiExpression) condExpr;
- JBlock newBlock = new JBlock(program, sourceInfo);
+ JBlock newBlock = new JBlock(sourceInfo);
for (JExpression expr : allButLast(condMulti.exprs)) {
newBlock.addStmt(expr.makeStatement());
}
- newBlock.addStmt(ifStatement(null, sourceInfo,
- last(condMulti.exprs), thenStmt, elseStmt));
+ newBlock.addStmt(ifStatement(null, sourceInfo, last(condMulti.exprs),
+ thenStmt, elseStmt));
// TODO(spoon): immediately simplify the resulting block
return newBlock;
}
@@ -237,8 +235,8 @@
if (original != null) {
return original;
}
- return new JIfStatement(program, condExpr.getSourceInfo(), condExpr,
- thenStmt, elseStmt);
+ return new JIfStatement(condExpr.getSourceInfo(), condExpr, thenStmt,
+ elseStmt);
}
public JExpression not(JPrefixOperation original, SourceInfo sourceInfo,
@@ -246,7 +244,7 @@
if (arg instanceof JMultiExpression) {
// !(a,b,c) -> (a,b,!c)
JMultiExpression argMulti = (JMultiExpression) arg;
- JMultiExpression newMulti = new JMultiExpression(program, sourceInfo);
+ JMultiExpression newMulti = new JMultiExpression(sourceInfo);
newMulti.exprs.addAll(allButLast(argMulti.exprs));
newMulti.exprs.add(not(null, sourceInfo, last(argMulti.exprs)));
// TODO(spoon): immediately simplify the newMulti
@@ -277,9 +275,8 @@
newOp = JBinaryOperator.GTE;
}
if (newOp != null) {
- JBinaryOperation newBinOp = new JBinaryOperation(program,
- argOp.getSourceInfo(), argOp.getType(), newOp, argOp.getLhs(),
- argOp.getRhs());
+ JBinaryOperation newBinOp = new JBinaryOperation(argOp.getSourceInfo(),
+ argOp.getType(), newOp, argOp.getLhs(), argOp.getRhs());
return newBinOp;
}
} else if (arg instanceof JPrefixOperation) {
@@ -296,13 +293,12 @@
if (original != null) {
return original;
}
- return new JPrefixOperation(program, arg.getSourceInfo(),
- JUnaryOperator.NOT, arg);
+ return new JPrefixOperation(arg.getSourceInfo(), JUnaryOperator.NOT, arg);
}
private JStatement ensureBlock(JStatement stmt) {
if (!(stmt instanceof JBlock)) {
- JBlock block = new JBlock(program, stmt.getSourceInfo());
+ JBlock block = new JBlock(stmt.getSourceInfo());
block.addStmt(stmt);
stmt = block;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
index 6aa1af7..465d05d 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
@@ -18,10 +18,12 @@
import com.google.gwt.dev.jjs.ast.CanBeAbstract;
import com.google.gwt.dev.jjs.ast.Context;
import com.google.gwt.dev.jjs.ast.JArrayRef;
+import com.google.gwt.dev.jjs.ast.JArrayType;
import com.google.gwt.dev.jjs.ast.JBinaryOperation;
import com.google.gwt.dev.jjs.ast.JBinaryOperator;
import com.google.gwt.dev.jjs.ast.JCastOperation;
import com.google.gwt.dev.jjs.ast.JClassType;
+import com.google.gwt.dev.jjs.ast.JConditional;
import com.google.gwt.dev.jjs.ast.JDeclarationStatement;
import com.google.gwt.dev.jjs.ast.JExpression;
import com.google.gwt.dev.jjs.ast.JField;
@@ -105,7 +107,7 @@
// this doesn't really belong here, but while we're here let's remove
// non-side-effect qualifiers to statics
if (!instance.hasSideEffects()) {
- JFieldRef fieldRef = new JFieldRef(program, x.getSourceInfo(), null,
+ JFieldRef fieldRef = new JFieldRef(x.getSourceInfo(), null,
x.getField(), x.getEnclosingType());
ctx.replaceMe(fieldRef);
}
@@ -129,8 +131,8 @@
// this doesn't really belong here, but while we're here let's remove
// non-side-effect qualifiers to statics
if (!instance.hasSideEffects()) {
- JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
- null, x.getTarget());
+ JMethodCall newCall = new JMethodCall(x.getSourceInfo(), null,
+ x.getTarget());
newCall.addArgs(x.getArgs());
ctx.replaceMe(newCall);
}
@@ -249,7 +251,7 @@
// Fake an assignment-to-self on all args to prevent tightening
JMethod method = x.getTarget();
for (JParameter param : method.getParams()) {
- addAssignment(param, new JParameterRef(program,
+ addAssignment(param, new JParameterRef(
program.createSourceInfoSynthetic(RecordVisitor.class,
"Fake assignment"), param));
}
@@ -368,8 +370,8 @@
public class TightenTypesVisitor extends JModVisitor {
/**
- * <code>true</code> if this visitor has changed the AST apart from calls to
- * Context.
+ * <code>true</code> if this visitor has changed the AST apart from calls
+ * to Context.
*/
private boolean myDidChange = false;
@@ -406,14 +408,14 @@
ctx.replaceMe(x.getExpr());
} else if (triviallyFalse) {
// replace with a magic NULL cast
- JCastOperation newOp = new JCastOperation(program, x.getSourceInfo(),
+ JCastOperation newOp = new JCastOperation(x.getSourceInfo(),
program.getTypeNull(), x.getExpr());
ctx.replaceMe(newOp);
} else {
// If possible, try to use a narrower cast
JClassType concreteType = getSingleConcreteType(toType);
if (concreteType != null) {
- JCastOperation newOp = new JCastOperation(program, x.getSourceInfo(),
+ JCastOperation newOp = new JCastOperation(x.getSourceInfo(),
concreteType, x.getExpr());
ctx.replaceMe(newOp);
}
@@ -421,6 +423,19 @@
}
@Override
+ public void endVisit(JConditional x, Context ctx) {
+ if (x.getType() instanceof JReferenceType) {
+ JReferenceType newType = program.generalizeTypes(
+ (JReferenceType) x.getThenExpr().getType(),
+ (JReferenceType) x.getElseExpr().getType());
+ if (newType != x.getType()) {
+ x.setType(newType);
+ didChange = true;
+ }
+ }
+ }
+
+ @Override
public void endVisit(JField x, Context ctx) {
if (!x.isVolatile()) {
tighten(x);
@@ -471,7 +486,7 @@
if (triviallyTrue) {
// replace with a simple null test
JNullLiteral nullLit = program.getLiteralNull();
- JBinaryOperation neq = new JBinaryOperation(program, x.getSourceInfo(),
+ JBinaryOperation neq = new JBinaryOperation(x.getSourceInfo(),
program.getTypePrimitiveBoolean(), JBinaryOperator.NEQ,
x.getExpr(), nullLit);
ctx.replaceMe(neq);
@@ -482,8 +497,8 @@
// If possible, try to use a narrower cast
JClassType concreteType = getSingleConcreteType(toType);
if (concreteType != null) {
- JInstanceOf newOp = new JInstanceOf(program, x.getSourceInfo(),
- concreteType, x.getExpr());
+ JInstanceOf newOp = new JInstanceOf(x.getSourceInfo(), concreteType,
+ x.getExpr());
ctx.replaceMe(newOp);
}
}
@@ -569,7 +584,7 @@
JMethod target = x.getTarget();
JMethod concreteMethod = getSingleConcreteMethod(target);
if (concreteMethod != null) {
- JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
+ JMethodCall newCall = new JMethodCall(x.getSourceInfo(),
x.getInstance(), concreteMethod);
newCall.addArgs(x.getArgs());
ctx.replaceMe(newCall);
@@ -657,6 +672,21 @@
return null;
}
+ private JArrayType nullifyArrayType(JArrayType arrayType) {
+ JType elementType = arrayType.getElementType();
+ if (elementType instanceof JReferenceType) {
+ JReferenceType refType = (JReferenceType) elementType;
+ if (!program.typeOracle.isInstantiatedType(refType)) {
+ return program.getTypeArray(JNullType.INSTANCE, 1);
+ } else if (elementType instanceof JArrayType) {
+ JArrayType newElementType = nullifyArrayType((JArrayType) elementType);
+ return program.getTypeArray(newElementType.getLeafType(),
+ newElementType.getDims() + 1);
+ }
+ }
+ return arrayType;
+ }
+
/**
* Tighten based on assignment, and for parameters, callArgs as well.
*/
@@ -677,6 +707,15 @@
return;
}
+ if (refType instanceof JArrayType) {
+ JArrayType arrayType = (JArrayType) refType;
+ JArrayType newArrayType = nullifyArrayType(arrayType);
+ if (arrayType != newArrayType) {
+ x.setType(newArrayType);
+ myDidChange = true;
+ }
+ }
+
// tighten based on leaf types
JClassType leafType = getSingleConcreteType(refType);
if (leafType != null) {