Search in sources :

Example 1 with BLangCatch

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

the class TaintAnalyzer method visit.

public void visit(BLangCatch catchNode) {
    SymbolEnv catchBlockEnv = SymbolEnv.createBlockEnv(catchNode.body, env);
    analyzeNode(catchNode.body, catchBlockEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 2 with BLangCatch

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

the class SemanticAnalyzer method visit.

public void visit(BLangCatch bLangCatch) {
    SymbolEnv catchBlockEnv = SymbolEnv.createBlockEnv(bLangCatch.body, env);
    analyzeNode(bLangCatch.param, catchBlockEnv);
    if (!this.types.checkStructEquivalency(bLangCatch.param.type, symTable.errStructType)) {
        dlog.error(bLangCatch.param.pos, DiagnosticCode.INCOMPATIBLE_TYPES, symTable.errStructType, bLangCatch.param.type);
    }
    analyzeStmt(bLangCatch.body, catchBlockEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 3 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(BLangTryCatchFinally tryNode) {
    Operand gotoTryCatchEndAddr = getOperand(-1);
    Instruction instructGotoTryCatchEnd = InstructionFactory.get(InstructionCodes.GOTO, gotoTryCatchEndAddr);
    List<int[]> unhandledErrorRangeList = new ArrayList<>();
    ErrorTableAttributeInfo errorTable = createErrorTableIfAbsent(currentPkgInfo);
    // Handle try block.
    int fromIP = nextIP();
    genNode(tryNode.tryBody, env);
    int toIP = nextIP() - 1;
    // Append finally block instructions.
    if (tryNode.finallyBody != null) {
        genNode(tryNode.finallyBody, env);
    }
    emit(instructGotoTryCatchEnd);
    unhandledErrorRangeList.add(new int[] { fromIP, toIP });
    // Handle catch blocks.
    int order = 0;
    for (BLangCatch bLangCatch : tryNode.getCatchBlocks()) {
        addLineNumberInfo(bLangCatch.pos);
        int targetIP = nextIP();
        genNode(bLangCatch, env);
        unhandledErrorRangeList.add(new int[] { targetIP, nextIP() - 1 });
        // Append finally block instructions.
        if (tryNode.finallyBody != null) {
            genNode(tryNode.finallyBody, env);
        }
        emit(instructGotoTryCatchEnd);
        // Create Error table entry for this catch block
        BTypeSymbol structSymbol = bLangCatch.param.symbol.type.tsymbol;
        BPackageSymbol packageSymbol = (BPackageSymbol) bLangCatch.param.symbol.type.tsymbol.owner;
        int pkgCPIndex = addPackageRefCPEntry(currentPkgInfo, packageSymbol.pkgID);
        int structNameCPIndex = addUTF8CPEntry(currentPkgInfo, structSymbol.name.value);
        StructureRefCPEntry structureRefCPEntry = new StructureRefCPEntry(pkgCPIndex, structNameCPIndex);
        int structCPEntryIndex = currentPkgInfo.addCPEntry(structureRefCPEntry);
        StructInfo errorStructInfo = this.programFile.packageInfoMap.get(packageSymbol.pkgID.bvmAlias()).getStructInfo(structSymbol.name.value);
        ErrorTableEntry errorTableEntry = new ErrorTableEntry(fromIP, toIP, targetIP, order++, structCPEntryIndex);
        errorTableEntry.setError(errorStructInfo);
        errorTable.addErrorTableEntry(errorTableEntry);
    }
    if (tryNode.finallyBody != null) {
        // Create Error table entry for unhandled errors in try and catch(s) blocks
        for (int[] range : unhandledErrorRangeList) {
            ErrorTableEntry errorTableEntry = new ErrorTableEntry(range[0], range[1], nextIP(), order++, -1);
            errorTable.addErrorTableEntry(errorTableEntry);
        }
        // Append finally block instruction.
        genNode(tryNode.finallyBody, env);
        emit(InstructionFactory.get(InstructionCodes.THROW, getOperand(-1)));
    }
    gotoTryCatchEndAddr.value = nextIP();
}
Also used : StructInfo(org.wso2.ballerinalang.programfile.StructInfo) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) ArrayList(java.util.ArrayList) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) Instruction(org.wso2.ballerinalang.programfile.Instruction) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) ErrorTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo) StructureRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry) ErrorTableEntry(org.wso2.ballerinalang.programfile.ErrorTableEntry)

Example 4 with BLangCatch

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

the class BLangPackageBuilder method addCatchClause.

public void addCatchClause(DiagnosticPos poc, Set<Whitespace> ws, String paramName) {
    BLangVariable variableNode = (BLangVariable) TreeBuilder.createVariableNode();
    variableNode.typeNode = (BLangType) this.typeNodeStack.pop();
    variableNode.name = (BLangIdentifier) createIdentifier(paramName);
    variableNode.pos = variableNode.typeNode.pos;
    variableNode.addWS(removeNthFromLast(ws, 3));
    BLangCatch catchNode = (BLangCatch) TreeBuilder.createCatchNode();
    catchNode.pos = poc;
    catchNode.addWS(ws);
    catchNode.body = (BLangBlockStmt) this.blockNodeStack.pop();
    catchNode.param = variableNode;
    tryCatchFinallyNodesStack.peek().catchBlocks.add(catchNode);
}
Also used : BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 5 with BLangCatch

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

the class TreeVisitor method visit.

@Override
public void visit(BLangCatch bLangCatch) {
    if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(bLangCatch.getPosition(), bLangCatch, this, this.documentServiceContext)) {
        SymbolEnv catchBlockEnv = SymbolEnv.createBlockEnv(bLangCatch.body, symbolEnv);
        this.acceptNode(bLangCatch.param, catchBlockEnv);
        this.blockOwnerStack.push(bLangCatch);
        this.acceptNode(bLangCatch.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