Search in sources :

Example 1 with CatchBlock

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;
}
Also used : VarTable(kalang.core.VarTable) CatchBlock(kalang.ast.CatchBlock) Statement(kalang.ast.Statement) ArrayList(java.util.ArrayList)

Example 2 with CatchBlock

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;
}
Also used : CatchBlock(kalang.ast.CatchBlock) Label(org.objectweb.asm.Label)

Example 3 with CatchBlock

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

Aggregations

CatchBlock (kalang.ast.CatchBlock)3 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 BlockStmt (kalang.ast.BlockStmt)1 LocalVarNode (kalang.ast.LocalVarNode)1 Statement (kalang.ast.Statement)1 TryStmt (kalang.ast.TryStmt)1 VarTable (kalang.core.VarTable)1 Label (org.objectweb.asm.Label)1