Search in sources :

Example 1 with TryStmt

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;
}
Also used : CatchBlock(kalang.ast.CatchBlock) BlockStmt(kalang.ast.BlockStmt) TryStmt(kalang.ast.TryStmt) LocalVarNode(kalang.ast.LocalVarNode) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 BlockStmt (kalang.ast.BlockStmt)1 CatchBlock (kalang.ast.CatchBlock)1 LocalVarNode (kalang.ast.LocalVarNode)1 TryStmt (kalang.ast.TryStmt)1