Search in sources :

Example 26 with BLangBlockStmt

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

the class BLangPackageBuilder method addLockStmt.

public void addLockStmt(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangLock lockNode = (BLangLock) TreeBuilder.createLockNode();
    lockNode.pos = pos;
    lockNode.addWS(ws);
    BLangBlockStmt lockBlock = (BLangBlockStmt) this.blockNodeStack.pop();
    lockBlock.pos = pos;
    lockNode.setBody(lockBlock);
    addStmtToCurrentBlock(lockNode);
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock)

Example 27 with BLangBlockStmt

use of org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt 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 28 with BLangBlockStmt

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

the class BLangPackageBuilder method addWhileStmt.

public void addWhileStmt(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangWhile whileNode = (BLangWhile) TreeBuilder.createWhileNode();
    whileNode.setCondition(exprNodeStack.pop());
    whileNode.pos = pos;
    whileNode.addWS(ws);
    BLangBlockStmt whileBlock = (BLangBlockStmt) this.blockNodeStack.pop();
    whileBlock.pos = pos;
    whileNode.setBody(whileBlock);
    addStmtToCurrentBlock(whileNode);
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile)

Example 29 with BLangBlockStmt

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

the class BLangPackageBuilder method addJoinCause.

public void addJoinCause(Set<Whitespace> ws, String identifier) {
    BLangForkJoin forkJoin = (BLangForkJoin) this.forkJoinNodesStack.peek();
    forkJoin.joinedBody = (BLangBlockStmt) this.blockNodeStack.pop();
    Set<Whitespace> varWS = removeNthFromLast(ws, 3);
    forkJoin.addWS(ws);
    forkJoin.joinResultVar = (BLangVariable) this.generateBasicVarNode((DiagnosticPos) this.typeNodeStack.peek().getPosition(), varWS, identifier, false);
}
Also used : BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) Whitespace(org.ballerinalang.model.Whitespace)

Example 30 with BLangBlockStmt

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

the class TreeVisitor method visit.

@Override
public void visit(BLangForkJoin forkJoin) {
    SymbolEnv folkJoinEnv = SymbolEnv.createFolkJoinEnv(forkJoin, this.symbolEnv);
    // TODO: check the symbolEnter.defineNode
    forkJoin.workers.forEach(e -> this.symbolEnter.defineNode(e, folkJoinEnv));
    forkJoin.workers.forEach(e -> this.acceptNode(e, folkJoinEnv));
    // if (!this.isJoinResultType(forkJoin.joinResultVar)) {
    // this.dlog.error(forkJoin.joinResultVar.pos, DiagnosticCode.INVALID_WORKER_JOIN_RESULT_TYPE);
    // }
    /* create code black and environment for join result section, i.e. (map results) */
    BLangBlockStmt joinResultsBlock = this.generateCodeBlock(this.createVarDef(forkJoin.joinResultVar));
    SymbolEnv joinResultsEnv = SymbolEnv.createBlockEnv(joinResultsBlock, this.symbolEnv);
    this.acceptNode(joinResultsBlock, joinResultsEnv);
    /* create an environment for the join body, making the enclosing environment the earlier
         * join result's environment */
    SymbolEnv joinBodyEnv = SymbolEnv.createBlockEnv(forkJoin.joinedBody, joinResultsEnv);
    this.acceptNode(forkJoin.joinedBody, joinBodyEnv);
    if (forkJoin.timeoutExpression != null) {
        /* create code black and environment for timeout section */
        BLangBlockStmt timeoutVarBlock = this.generateCodeBlock(this.createVarDef(forkJoin.timeoutVariable));
        SymbolEnv timeoutVarEnv = SymbolEnv.createBlockEnv(timeoutVarBlock, this.symbolEnv);
        this.acceptNode(timeoutVarBlock, timeoutVarEnv);
        /* create an environment for the timeout body, making the enclosing environment the earlier
             * timeout var's environment */
        SymbolEnv timeoutBodyEnv = SymbolEnv.createBlockEnv(forkJoin.timeoutBody, timeoutVarEnv);
        this.acceptNode(forkJoin.timeoutBody, timeoutBodyEnv);
    }
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Aggregations

BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)33 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)22 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)19 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)16 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)12 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)9 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)8 BLangIf (org.wso2.ballerinalang.compiler.tree.statements.BLangIf)8 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)7 BLangBinaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)6 BLangIndexBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess)6 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)6 BLangReturn (org.wso2.ballerinalang.compiler.tree.statements.BLangReturn)6 Name (org.wso2.ballerinalang.compiler.util.Name)6 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)5 BLangMatchStmtPatternClause (org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause)5 ArrayList (java.util.ArrayList)4 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)4 BLangForeach (org.wso2.ballerinalang.compiler.tree.statements.BLangForeach)4 Whitespace (org.ballerinalang.model.Whitespace)3