< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java

Print this page
rev 51258 : imported patch switch.diff

*** 79,93 **** /** 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; --- 79,88 ----
*** 1009,1022 **** 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); genExpr(tree.init, v.erasure(types)).load(); items.makeLocalItem(v).store(); ! Assert.check(letExprDepth != 0 || code.state.stacksize == 0); } } checkDimension(tree.pos(), v.type); } --- 1004,1017 ---- VarSymbol v = tree.sym; code.newLocal(v); if (tree.init != null) { checkStringConstant(tree.init.pos(), v.getConstValue()); if (v.getConstValue() == null || varDebugInfo) { ! Assert.check(code.isStatementStart()); genExpr(tree.init, v.erasure(types)).load(); items.makeLocalItem(v).store(); ! Assert.check(code.isStatementStart()); } } checkDimension(tree.pos(), v.type); }
*** 1067,1084 **** 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); 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); 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); --- 1062,1079 ---- int startpc = code.entryPoint(); if (testFirst) { //while or for loop CondItem c; if (cond != null) { code.statBegin(cond.pos); ! 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.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,1104 **** genStats(step, loopEnv); if (code.isAlive()) { CondItem c; if (cond != null) { code.statBegin(cond.pos); ! Assert.check(code.state.stacksize == 0); c = genCond(TreeInfo.skipParens(cond), CRT_FLOW_CONTROLLER); } else { c = items.makeCondItem(goto_); } code.resolve(c.jumpTrue(), startpc); ! Assert.check(code.state.stacksize == 0); code.resolve(c.falseJumps); } } Chain exit = loopEnv.info.exit; if (exit != null) { --- 1083,1099 ---- genStats(step, loopEnv); if (code.isAlive()) { CondItem c; if (cond != null) { code.statBegin(cond.pos); ! 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.isStatementStart()); code.resolve(c.falseJumps); } } Chain exit = loopEnv.info.exit; if (exit != null) {
*** 1123,1133 **** 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); Item sel = genExpr(tree.selector, syms.intType); List<JCCase> cases = tree.cases; if (cases.isEmpty()) { // We are seeing: switch <sel> {} sel.load().drop(); --- 1118,1128 ---- 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.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,1163 **** 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(); labels[i] = val; if (val < lo) lo = val; if (hi < val) hi = val; nlabels++; } else { --- 1147,1159 ---- 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.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,1302 **** 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); genExpr(tree.lock, tree.lock.type).load().duplicate(); lockVar.store(); // Generate code to enter monitor. code.emitop0(monitorenter); --- 1288,1298 ---- 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.isStatementStart()); genExpr(tree.lock, tree.lock.type).load().duplicate(); lockVar.store(); // Generate code to enter monitor. code.emitop0(monitorenter);
*** 1554,1568 **** } public void visitIf(JCIf tree) { int limit = code.nextreg; Chain thenExit = null; ! Assert.check(code.state.stacksize == 0); CondItem c = genCond(TreeInfo.skipParens(tree.cond), CRT_FLOW_CONTROLLER); Chain elseChain = c.jumpFalse(); ! Assert.check(code.state.stacksize == 0); if (!c.isFalse()) { code.resolve(c.trueJumps); genStat(tree.thenpart, env, CRT_STATEMENT | CRT_FLOW_TARGET); thenExit = code.branch(goto_); } --- 1550,1564 ---- } public void visitIf(JCIf tree) { int limit = code.nextreg; Chain thenExit = null; ! Assert.check(code.isStatementStart()); CondItem c = genCond(TreeInfo.skipParens(tree.cond), CRT_FLOW_CONTROLLER); Chain elseChain = c.jumpFalse(); ! 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,1582 **** genStat(tree.elsepart, env,CRT_STATEMENT | CRT_FLOW_TARGET); } } code.resolve(thenExit); code.endScopes(limit); ! Assert.check(code.state.stacksize == 0); } public void visitExec(JCExpressionStatement tree) { // Optimize x++ to ++x and x-- to --x. JCExpression e = tree.expr; --- 1568,1578 ---- genStat(tree.elsepart, env,CRT_STATEMENT | CRT_FLOW_TARGET); } } code.resolve(thenExit); code.endScopes(limit); ! Assert.check(code.isStatementStart()); } public void visitExec(JCExpressionStatement tree) { // Optimize x++ to ++x and x-- to --x. JCExpression e = tree.expr;
*** 1586,1614 **** break; case POSTDEC: ((JCUnary) e).setTag(PREDEC); break; } ! Assert.check(code.state.stacksize == 0); genExpr(tree.expr, tree.expr.type).drop(); ! Assert.check(code.state.stacksize == 0); } 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); 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); targetEnv.info.addCont(code.branch(goto_)); endFinalizerGaps(env, targetEnv); } public void visitReturn(JCReturn tree) { --- 1582,1610 ---- break; case POSTDEC: ((JCUnary) e).setTag(PREDEC); break; } ! Assert.check(code.isStatementStart()); genExpr(tree.expr, tree.expr.type).drop(); ! 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.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.isStatementStart()); targetEnv.info.addCont(code.branch(goto_)); endFinalizerGaps(env, targetEnv); } public void visitReturn(JCReturn tree) {
*** 1618,1628 **** /* 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); Item r = genExpr(tree.expr, pt).load(); if (hasFinally(env.enclMethod, env)) { r = makeTemp(pt); r.store(); } --- 1614,1624 ---- /* 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.isStatementStart()); Item r = genExpr(tree.expr, pt).load(); if (hasFinally(env.enclMethod, env)) { r = makeTemp(pt); r.store(); }
*** 1638,1651 **** endFinalizerGaps(env, targetEnv); code.endScopes(limit); } public void visitThrow(JCThrow tree) { ! Assert.check(code.state.stacksize == 0); genExpr(tree.expr, tree.expr.type).load(); code.emitop0(athrow); ! Assert.check(code.state.stacksize == 0); } /* ************************************************************************ * Visitor methods for expressions *************************************************************************/ --- 1634,1647 ---- endFinalizerGaps(env, targetEnv); code.endScopes(limit); } public void visitThrow(JCThrow tree) { ! Assert.check(code.isStatementStart()); genExpr(tree.expr, tree.expr.type).load(); code.emitop0(athrow); ! Assert.check(code.isStatementStart()); } /* ************************************************************************ * Visitor methods for expressions *************************************************************************/
*** 2145,2160 **** else result = items.makeImmediateItem(tree.type, tree.value); } public void visitLetExpr(LetExpr tree) { - letExprDepth++; int limit = code.nextreg; genStats(tree.defs, env); 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) { --- 2141,2159 ---- else result = items.makeImmediateItem(tree.type, tree.value); } public void visitLetExpr(LetExpr tree) { 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); } private void generateReferencesToPrunedTree(ClassSymbol classSymbol, Pool pool) { List<JCTree> prunedInfo = lower.prunedTree.get(classSymbol); if (prunedInfo != null) {
< prev index next >