use of kalang.ast.CatchBlock in project kalang by kasonyang.
the class InitializationAnalyzer method visitTryStmt.
@Override
public Type visitTryStmt(TryStmt node) {
List<VarTable<LocalVarNode, Void>> assignedList = new ArrayList(node.getCatchStmts().size() + 1);
enterNewFrame();
assignedList.add(assignedVars);
visit(node.getExecStmt());
exitFrame();
for (CatchBlock cs : node.getCatchStmts()) {
enterNewFrame();
assignedList.add(assignedVars);
visit(cs);
exitFrame();
}
addIntersectedAssignedVar(assignedList.toArray(new VarTable[assignedList.size()]));
Statement finallyStmt = node.getFinallyStmt();
if (finallyStmt != null) {
visit(finallyStmt);
}
return null;
}
use of kalang.ast.CatchBlock in project kalang by kasonyang.
the class Ast2Class method visitTryStmt.
@Override
public Object visitTryStmt(TryStmt node) {
Label startLabel = new Label();
Label endLabel = new Label();
Label stopLabel = new Label();
md.visitLabel(startLabel);
visit(node.getExecStmt());
md.visitJumpInsn(GOTO, stopLabel);
md.visitLabel(endLabel);
if (node.getCatchStmts() != null) {
for (CatchBlock s : node.getCatchStmts()) {
this.newFrame();
Label handler = new Label();
md.visitLabel(handler);
visit(s);
md.visitJumpInsn(GOTO, stopLabel);
String type = asmType(s.catchVar.getType()).getInternalName();
md.visitTryCatchBlock(startLabel, endLabel, handler, type);
this.popFrame();
}
}
if (node.getFinallyStmt() != null) {
this.newFrame();
Label handler = new Label();
md.visitLabel(handler);
visit(node.getFinallyStmt());
md.visitJumpInsn(GOTO, stopLabel);
md.visitTryCatchBlock(startLabel, endLabel, handler, null);
this.popFrame();
}
md.visitLabel(stopLabel);
return null;
}
use of kalang.ast.CatchBlock in project kalang by kasonyang.
the class AstBuilder method visitTryStat.
@Override
public AstNode visitTryStat(TryStatContext ctx) {
// TODO handle multi-branched assign
BlockStmt tryExecStmt = requireBlock(ctx.exec);
boolean tryReturned = this.returned;
List<CatchBlock> tryCatchBlocks = new LinkedList<>();
if (ctx.catchTypes != null) {
for (int i = 0; i < ctx.catchTypes.size(); i++) {
this.newFrame();
this.returned = false;
String vName = ctx.catchVarNames.get(i).getText();
String vType = ctx.catchTypes.get(i).getText();
LocalVarNode vo = this.declareLocalVar(vName, requireClassType(vType, ctx.catchTypes.get(i).start), Modifier.FINAL, ctx);
if (vo == null)
return null;
BlockStmt catchExecStmt = requireBlock(ctx.catchExec.get(i));
CatchBlock catchStmt = new CatchBlock(vo, catchExecStmt);
tryCatchBlocks.add(catchStmt);
this.returned = this.returned && tryReturned;
this.popFrame();
}
}
BlockStmt tryFinallyStmt = null;
if (ctx.finallyExec != null) {
tryFinallyStmt = requireBlock(ctx.finallyExec);
}
TryStmt tryStmt = new TryStmt(tryExecStmt, tryCatchBlocks, tryFinallyStmt);
mapAst(tryStmt, ctx);
return tryStmt;
}
Aggregations