Search in sources :

Example 6 with BLangCatch

use of org.wso2.ballerinalang.compiler.tree.statements.BLangCatch in project ballerina by ballerina-lang.

the class CodeAnalyzer method visit.

public void visit(BLangTryCatchFinally tryNode) {
    this.checkStatementExecutionValidity(tryNode);
    tryNode.tryBody.accept(this);
    this.resetStatementReturns();
    List<BType> caughtTypes = new ArrayList<>();
    for (BLangCatch bLangCatch : tryNode.getCatchBlocks()) {
        if (caughtTypes.contains(bLangCatch.getParameter().type)) {
            dlog.error(bLangCatch.getParameter().pos, DiagnosticCode.DUPLICATED_ERROR_CATCH, bLangCatch.getParameter().type);
        }
        caughtTypes.add(bLangCatch.getParameter().type);
        bLangCatch.body.accept(this);
        this.resetStatementReturns();
    }
    if (tryNode.finallyBody != null) {
        tryNode.finallyBody.accept(this);
        this.resetStatementReturns();
    }
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch)

Example 7 with BLangCatch

use of org.wso2.ballerinalang.compiler.tree.statements.BLangCatch in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangCatch bLangCatch) {
    // Define local variable index for Error.
    BLangVariable variable = bLangCatch.param;
    RegIndex lvIndex = getLVIndex(variable.symbol.type.tag);
    variable.symbol.varIndex = lvIndex;
    emit(InstructionFactory.get(InstructionCodes.ERRSTORE, lvIndex));
    // Visit Catch Block.
    genNode(bLangCatch.body, env);
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 8 with BLangCatch

use of org.wso2.ballerinalang.compiler.tree.statements.BLangCatch in project ballerina by ballerina-lang.

the class SignatureTreeVisitor method visit.

@Override
public void visit(BLangCatch catchNode) {
    SymbolEnv catchBlockEnv = SymbolEnv.createBlockEnv(catchNode.body, symbolEnv);
    this.acceptNode(catchNode.param, catchBlockEnv);
    this.blockOwnerStack.push(catchNode);
    this.acceptNode(catchNode.body, catchBlockEnv);
    this.blockOwnerStack.pop();
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Aggregations

SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)4 BLangCatch (org.wso2.ballerinalang.compiler.tree.statements.BLangCatch)3 ArrayList (java.util.ArrayList)2 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)2 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)1 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 ErrorTableEntry (org.wso2.ballerinalang.programfile.ErrorTableEntry)1 Instruction (org.wso2.ballerinalang.programfile.Instruction)1 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)1 StructInfo (org.wso2.ballerinalang.programfile.StructInfo)1 ErrorTableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo)1 StructureRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry)1