<li>javassist.expr.Expr.indexOfBytecode() has been added.
<li>javassist.Loader has been modified so that getPackage() returns
a package object.
- <li>Now, the compiler can correctly compile a try statement.
+ <li>Now, the compiler can correctly compile a try statement and an
+ infinite while-loop.
</ul>
<p>- version 2.5.1 in May, 2003.
hasReturned = false;
s.accept(this);
- if (isVoid && !hasReturned) {
- bytecode.addOpcode(Opcode.RETURN);
- hasReturned = true;
- }
+ if (!hasReturned)
+ if (isVoid) {
+ bytecode.addOpcode(Opcode.RETURN);
+ hasReturned = true;
+ }
+ else
+ throw new CompileError("no return statement");
}
private boolean needsSuperCall(Stmnt body) throws CompileError {
if (notDo)
bytecode.write16bit(pc, pc3 - pc + 1);
- booleanExpr(true, expr);
+ boolean alwaysBranch = booleanExpr(true, expr);
bytecode.addIndex(pc2 - bytecode.currentPc() + 1);
patchGoto(breakList, bytecode.currentPc());
patchGoto(continueList, pc3);
continueList = prevContList;
breakList = prevBreakList;
- hasReturned = false;
+ hasReturned = alwaysBranch;
}
private void patchGoto(ArrayList list, int targetPc) {
/* Produces the opcode to branch if the condition is true.
* The oprand is not produced.
*
- * If false is returned, the branch occurs if the condition is
- * false.
+ * @return true if the compiled code is GOTO (always branch).
*/
- private void booleanExpr(boolean branchIf, ASTree expr)
+ private boolean booleanExpr(boolean branchIf, ASTree expr)
throws CompileError
{
boolean isAndAnd;
bytecode.addOpcode(Opcode.GOTO);
}
}
+ else if (isAlwaysBranch(expr, branchIf)) {
+ bytecode.addOpcode(Opcode.GOTO);
+ return true; // always branch
+ }
else { // others
expr.accept(this);
bytecode.addOpcode(branchIf ? IFNE : IFEQ);
exprType = BOOLEAN;
arrayDim = 0;
+ return false;
+ }
+
+
+ private static boolean isAlwaysBranch(ASTree expr, boolean branchIf) {
+ if (expr instanceof Keyword) {
+ int t = ((Keyword)expr).get();
+ return branchIf ? t == TRUE : t == FALSE;
+ }
+
+ return false;
}
private static int getCompOperator(ASTree expr) throws CompileError {