use of kalang.ast.TryStmt 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