Rolling back r8522: For synthetic this refs, use params rather than fields while in constructors
Cause build breaks.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@8523 8db76d5a-ed1c-0410-87a9-c151d255dfc7
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 279a12a..b785f08 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
@@ -25,14 +25,10 @@
* Determines whether the variable is final, volatile, or neither.
*/
public static enum Disposition {
- COMPILE_TIME_CONSTANT, FINAL, NONE, THIS_REF, VOLATILE;
+ COMPILE_TIME_CONSTANT, FINAL, NONE, VOLATILE;
public boolean isFinal() {
- return this == COMPILE_TIME_CONSTANT || this == FINAL || this == THIS_REF;
- }
-
- public boolean isThisRef() {
- return this == THIS_REF;
+ return this == COMPILE_TIME_CONSTANT || this == FINAL;
}
private boolean isCompileTimeConstant() {
@@ -47,7 +43,6 @@
private final JDeclaredType enclosingType;
private final boolean isCompileTimeConstant;
private final boolean isStatic;
- private boolean isThisRef;
private boolean isVolatile;
JField(SourceInfo info, String name, JDeclaredType enclosingType, JType type,
@@ -57,7 +52,6 @@
this.isStatic = isStatic;
this.isCompileTimeConstant = disposition.isCompileTimeConstant();
this.isVolatile = disposition.isVolatile();
- this.isThisRef = disposition.isThisRef();
// Disposition is not cached because we can be set final later.
}
@@ -81,10 +75,6 @@
return isStatic;
}
- public boolean isThisRef() {
- return isThisRef;
- }
-
public boolean isVolatile() {
return isVolatile;
}
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 4e3767b..02ee4e8 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
@@ -620,12 +620,12 @@
}
private JField createField(SyntheticArgumentBinding binding,
- JDeclaredType enclosingType, Disposition disposition) {
+ JDeclaredType enclosingType) {
JType type = getType(binding.type);
SourceInfo info = enclosingType.getSourceInfo().makeChild(
BuildDeclMapVisitor.class, "Field " + String.valueOf(binding.name));
JField field = program.createField(info, String.valueOf(binding.name),
- enclosingType, type, false, disposition);
+ enclosingType, type, false, Disposition.FINAL);
info.addCorrelation(program.getCorrelator().by(field));
if (binding.matchingField != null) {
typeMap.put(binding.matchingField, field);
@@ -841,7 +841,7 @@
for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) {
SyntheticArgumentBinding arg = nestedBinding.enclosingInstances[i];
if (arg.matchingField != null) {
- createField(arg, type, Disposition.THIS_REF);
+ createField(arg, type);
}
}
}
@@ -849,7 +849,7 @@
if (nestedBinding.outerLocalVariables != null) {
for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) {
SyntheticArgumentBinding arg = nestedBinding.outerLocalVariables[i];
- createField(arg, type, Disposition.FINAL);
+ createField(arg, type);
}
}
}
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 7849d45..31c48de 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
@@ -103,7 +103,6 @@
import com.google.gwt.dev.js.ast.JsProgram;
import com.google.gwt.dev.util.JsniRef;
import com.google.gwt.dev.util.collect.Lists;
-import com.google.gwt.dev.util.collect.Maps;
import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger.Event;
@@ -273,8 +272,6 @@
private MethodScope currentMethodScope;
- private Map<JField, JParameter> currentOuterThisRefParams;
-
private int[] currentSeparatorPositions;
private final boolean disableClassMetadata;
@@ -675,6 +672,13 @@
currentMethodBody = ctor.getBody();
currentMethodScope = x.scope;
+ JMethodCall superOrThisCall = null;
+ ExplicitConstructorCall ctorCall = x.constructorCall;
+ if (ctorCall != null) {
+ superOrThisCall = (JMethodCall) dispatch("processExpression",
+ ctorCall);
+ }
+
/*
* Determine if we have an explicit this call. The presence of an
* explicit this call indicates we can skip certain initialization steps
@@ -682,12 +686,11 @@
* steps are 1) assigning synthetic args to fields and 2) running
* initializers.
*/
- boolean hasExplicitThis = (x.constructorCall != null)
- && !x.constructorCall.isSuperAccess();
+ boolean hasExplicitThis = (ctorCall != null)
+ && !ctorCall.isSuperAccess();
JClassType enclosingType = ctor.getEnclosingType();
JBlock block = currentMethodBody.getBlock();
- currentOuterThisRefParams = Maps.create();
/*
* All synthetic fields must be assigned, unless we have an explicit
@@ -707,8 +710,6 @@
block.addStmt(JProgram.createAssignmentStmt(info,
createVariableRef(info, field), createVariableRef(info,
param)));
- currentOuterThisRefParams = Maps.put(
- currentOuterThisRefParams, field, param);
}
}
}
@@ -726,20 +727,19 @@
}
}
- // optional this or super constructor call
- if (x.constructorCall != null) {
- JMethodCall superOrThisCall = (JMethodCall) dispatch(
- "processExpression", x.constructorCall);
- // Enums: wire up synthetic name/ordinal params to the super method.
- if (enclosingType.isEnumOrSubclass() != null) {
- JVariableRef enumNameRef = createVariableRef(
- superOrThisCall.getSourceInfo(), ctor.getParams().get(0));
- superOrThisCall.addArg(0, enumNameRef);
- JVariableRef enumOrdinalRef = createVariableRef(
- superOrThisCall.getSourceInfo(), ctor.getParams().get(1));
- superOrThisCall.addArg(1, enumOrdinalRef);
- }
+ // Enums: wire up synthetic name/ordinal params to the super method.
+ if (enclosingType.isEnumOrSubclass() != null) {
+ assert (superOrThisCall != null);
+ JVariableRef enumNameRef = createVariableRef(
+ superOrThisCall.getSourceInfo(), ctor.getParams().get(0));
+ superOrThisCall.addArg(0, enumNameRef);
+ JVariableRef enumOrdinalRef = createVariableRef(
+ superOrThisCall.getSourceInfo(), ctor.getParams().get(1));
+ superOrThisCall.addArg(1, enumOrdinalRef);
+ }
+ // optional this or super constructor call
+ if (superOrThisCall != null) {
superOrThisCall.setStaticDispatchOnly();
block.addStmt(superOrThisCall.makeStatement());
}
@@ -760,7 +760,6 @@
// user code (finally!)
block.addStmts(processStatements(x.statements));
- currentOuterThisRefParams = null;
currentMethodScope = null;
currentMethod = null;
} catch (Throwable e) {
@@ -1970,21 +1969,18 @@
return call;
}
- private void addAllOuterThisRefs(List<? super JVariableRef> list,
+ private void addAllOuterThisRefs(List<? super JFieldRef> list,
JExpression expr, JClassType classType) {
- for (JField field : classType.getFields()) {
- // This fields are always first.
- if (!field.isThisRef()) {
- break;
- }
- // In a constructor, use the local param instead of the field.
- JParameter param = null;
- if (currentOuterThisRefParams != null && expr instanceof JThisRef) {
- param = currentOuterThisRefParams.get(field);
- }
- if (param != null) {
- list.add(new JParameterRef(expr.getSourceInfo(), param));
- } else {
+ if (classType.getFields().size() > 0) {
+ JField field = classType.getFields().get(0);
+ /*
+ * In some circumstances, the outer this ref can be captured as a local
+ * value (val$this), in other cases, as a this ref (this$).
+ *
+ * TODO: investigate using more JDT node information as an alternative
+ */
+ if (field.getName().startsWith("this$")
+ || field.getName().startsWith("val$this$")) {
list.add(new JFieldRef(expr.getSourceInfo(), expr, field,
currentClass));
}
@@ -1992,8 +1988,7 @@
}
private void addAllOuterThisRefsPlusSuperChain(
- List<? super JVariableRef> workList, JExpression expr,
- JClassType classType) {
+ List<? super JFieldRef> workList, JExpression expr, JClassType classType) {
for (; classType != null; classType = classType.getSuperClass()) {
addAllOuterThisRefs(workList, expr, classType);
}