< prev index next >
src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java
Print this page
rev 51258 : imported patch switch
@@ -79,15 +79,10 @@
/** A type that serves as the expected type for all method expressions.
*/
private final Type methodType;
- /**
- * Are we presently traversing a let expression ? Yes if depth != 0
- */
- private int letExprDepth;
-
public static Gen instance(Context context) {
Gen instance = context.get(genKey);
if (instance == null)
instance = new Gen(context);
return instance;
@@ -1009,14 +1004,14 @@
VarSymbol v = tree.sym;
code.newLocal(v);
if (tree.init != null) {
checkStringConstant(tree.init.pos(), v.getConstValue());
if (v.getConstValue() == null || varDebugInfo) {
- Assert.check(letExprDepth != 0 || code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
genExpr(tree.init, v.erasure(types)).load();
items.makeLocalItem(v).store();
- Assert.check(letExprDepth != 0 || code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
}
}
checkDimension(tree.pos(), v.type);
}
@@ -1067,18 +1062,18 @@
int startpc = code.entryPoint();
if (testFirst) { //while or for loop
CondItem c;
if (cond != null) {
code.statBegin(cond.pos);
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
c = genCond(TreeInfo.skipParens(cond), CRT_FLOW_CONTROLLER);
} else {
c = items.makeCondItem(goto_);
}
Chain loopDone = c.jumpFalse();
code.resolve(c.trueJumps);
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET);
code.resolve(loopEnv.info.cont);
genStats(step, loopEnv);
code.resolve(code.branch(goto_), startpc);
code.resolve(loopDone);
@@ -1088,17 +1083,17 @@
genStats(step, loopEnv);
if (code.isAlive()) {
CondItem c;
if (cond != null) {
code.statBegin(cond.pos);
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
c = genCond(TreeInfo.skipParens(cond), CRT_FLOW_CONTROLLER);
} else {
c = items.makeCondItem(goto_);
}
code.resolve(c.jumpTrue(), startpc);
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
code.resolve(c.falseJumps);
}
}
Chain exit = loopEnv.info.exit;
if (exit != null) {
@@ -1123,11 +1118,11 @@
public void visitSwitch(JCSwitch tree) {
int limit = code.nextreg;
Assert.check(!tree.selector.type.hasTag(CLASS));
int startpcCrt = genCrt ? code.curCP() : 0;
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
Item sel = genExpr(tree.selector, syms.intType);
List<JCCase> cases = tree.cases;
if (cases.isEmpty()) {
// We are seeing: switch <sel> {}
sel.load().drop();
@@ -1152,12 +1147,13 @@
int[] labels = new int[cases.length()]; // the label array.
int defaultIndex = -1; // the index of the default clause.
List<JCCase> l = cases;
for (int i = 0; i < labels.length; i++) {
- if (l.head.pat != null) {
- int val = ((Number)l.head.pat.type.constValue()).intValue();
+ if (l.head.pats.nonEmpty()) {
+ Assert.check(l.head.pats.size() == 1);
+ int val = ((Number)l.head.pats.head.type.constValue()).intValue();
labels[i] = val;
if (val < lo) lo = val;
if (hi < val) hi = val;
nlabels++;
} else {
@@ -1292,11 +1288,11 @@
public void visitSynchronized(JCSynchronized tree) {
int limit = code.nextreg;
// Generate code to evaluate lock and save in temporary variable.
final LocalItem lockVar = makeTemp(syms.objectType);
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
genExpr(tree.lock, tree.lock.type).load().duplicate();
lockVar.store();
// Generate code to enter monitor.
code.emitop0(monitorenter);
@@ -1554,15 +1550,15 @@
}
public void visitIf(JCIf tree) {
int limit = code.nextreg;
Chain thenExit = null;
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
CondItem c = genCond(TreeInfo.skipParens(tree.cond),
CRT_FLOW_CONTROLLER);
Chain elseChain = c.jumpFalse();
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
if (!c.isFalse()) {
code.resolve(c.trueJumps);
genStat(tree.thenpart, env, CRT_STATEMENT | CRT_FLOW_TARGET);
thenExit = code.branch(goto_);
}
@@ -1572,11 +1568,11 @@
genStat(tree.elsepart, env,CRT_STATEMENT | CRT_FLOW_TARGET);
}
}
code.resolve(thenExit);
code.endScopes(limit);
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
}
public void visitExec(JCExpressionStatement tree) {
// Optimize x++ to ++x and x-- to --x.
JCExpression e = tree.expr;
@@ -1586,29 +1582,29 @@
break;
case POSTDEC:
((JCUnary) e).setTag(PREDEC);
break;
}
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
genExpr(tree.expr, tree.expr.type).drop();
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
}
public void visitBreak(JCBreak tree) {
int tmpPos = code.pendingStatPos;
Env<GenContext> targetEnv = unwind(tree.target, env);
code.pendingStatPos = tmpPos;
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
targetEnv.info.addExit(code.branch(goto_));
endFinalizerGaps(env, targetEnv);
}
public void visitContinue(JCContinue tree) {
int tmpPos = code.pendingStatPos;
Env<GenContext> targetEnv = unwind(tree.target, env);
code.pendingStatPos = tmpPos;
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
targetEnv.info.addCont(code.branch(goto_));
endFinalizerGaps(env, targetEnv);
}
public void visitReturn(JCReturn tree) {
@@ -1618,11 +1614,11 @@
/* Save and then restore the location of the return in case a finally
* is expanded (with unwind()) in the middle of our bytecodes.
*/
int tmpPos = code.pendingStatPos;
if (tree.expr != null) {
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
Item r = genExpr(tree.expr, pt).load();
if (hasFinally(env.enclMethod, env)) {
r = makeTemp(pt);
r.store();
}
@@ -1638,14 +1634,14 @@
endFinalizerGaps(env, targetEnv);
code.endScopes(limit);
}
public void visitThrow(JCThrow tree) {
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
genExpr(tree.expr, tree.expr.type).load();
code.emitop0(athrow);
- Assert.check(code.state.stacksize == 0);
+ Assert.check(code.isStatementStart());
}
/* ************************************************************************
* Visitor methods for expressions
*************************************************************************/
@@ -2145,16 +2141,19 @@
else
result = items.makeImmediateItem(tree.type, tree.value);
}
public void visitLetExpr(LetExpr tree) {
- letExprDepth++;
int limit = code.nextreg;
+ int prevLetExprStart = code.setLetExprStackPos(code.state.stacksize);
+ try {
genStats(tree.defs, env);
+ } finally {
+ code.setLetExprStackPos(prevLetExprStart);
+ }
result = genExpr(tree.expr, tree.expr.type).load();
code.endScopes(limit);
- letExprDepth--;
}
private void generateReferencesToPrunedTree(ClassSymbol classSymbol, Pool pool) {
List<JCTree> prunedInfo = lower.prunedTree.get(classSymbol);
if (prunedInfo != null) {
< prev index next >