Search in sources :

Example 1 with BLangBlockStmt

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

the class SignatureTreeVisitor method visit.

@Override
public void visit(BLangBlockStmt blockNode) {
    SymbolEnv blockEnv = SymbolEnv.createBlockEnv(blockNode, symbolEnv);
    blockNode.stmts.forEach(stmt -> this.acceptNode(stmt, blockEnv));
    if (!terminateVisitor && this.isCursorWithinBlock()) {
        Map<Name, Scope.ScopeEntry> visibleSymbolEntries = symbolResolver.getAllVisibleInScopeSymbols(blockEnv);
        this.populateSymbols(visibleSymbolEntries);
    }
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 2 with BLangBlockStmt

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

the class SymbolEnter method addInitReturnStatement.

private void addInitReturnStatement(BLangBlockStmt bLangBlockStmt) {
    // Add return statement to the init function
    BLangReturn returnStmt = (BLangReturn) TreeBuilder.createReturnNode();
    returnStmt.pos = bLangBlockStmt.pos;
    bLangBlockStmt.addStatement(returnStmt);
}
Also used : BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn)

Example 3 with BLangBlockStmt

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

the class SymbolEnter method createInitFunction.

private BLangFunction createInitFunction(DiagnosticPos pos, String name, Name sufix) {
    BLangFunction initFunction = (BLangFunction) TreeBuilder.createFunctionNode();
    initFunction.setName(createIdentifier(name + sufix.getValue()));
    initFunction.flagSet = EnumSet.of(Flag.PUBLIC);
    initFunction.pos = pos;
    // Create body of the init function
    BLangBlockStmt body = (BLangBlockStmt) TreeBuilder.createBlockNode();
    body.pos = pos;
    initFunction.setBody(body);
    return initFunction;
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction)

Example 4 with BLangBlockStmt

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

the class SemanticAnalyzer method visit.

@Override
public void visit(BLangForkJoin forkJoin) {
    SymbolEnv forkJoinEnv = SymbolEnv.createFolkJoinEnv(forkJoin, this.env);
    forkJoin.workers.forEach(e -> this.symbolEnter.defineNode(e, forkJoinEnv));
    forkJoin.workers.forEach(e -> this.analyzeDef(e, forkJoinEnv));
    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.env);
    this.analyzeNode(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.analyzeNode(forkJoin.joinedBody, joinBodyEnv);
    if (forkJoin.timeoutExpression != null) {
        if (!this.isJoinResultType(forkJoin.timeoutVariable)) {
            this.dlog.error(forkJoin.timeoutVariable.pos, DiagnosticCode.INVALID_WORKER_TIMEOUT_RESULT_TYPE);
        }
        /* create code black and environment for timeout section */
        BLangBlockStmt timeoutVarBlock = this.generateCodeBlock(this.createVarDef(forkJoin.timeoutVariable));
        SymbolEnv timeoutVarEnv = SymbolEnv.createBlockEnv(timeoutVarBlock, this.env);
        this.typeChecker.checkExpr(forkJoin.timeoutExpression, timeoutVarEnv, Arrays.asList(symTable.intType));
        this.analyzeNode(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.analyzeNode(forkJoin.timeoutBody, timeoutBodyEnv);
    }
    this.validateJoinWorkerList(forkJoin, forkJoinEnv);
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 5 with BLangBlockStmt

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

the class CodeGenerator method visit.

public void visit(BLangBlockStmt blockNode) {
    SymbolEnv blockEnv = SymbolEnv.createBlockEnv(blockNode, this.env);
    for (BLangStatement stmt : blockNode.stmts) {
        if (stmt.getKind() != NodeKind.TRY && stmt.getKind() != NodeKind.CATCH && stmt.getKind() != NodeKind.IF) {
            addLineNumberInfo(stmt.pos);
        }
        genNode(stmt, blockEnv);
        // Update the maxRegIndexes structure
        setMaxRegIndexes(regIndexes, maxRegIndexes);
        // Reset the regIndexes structure for every statement
        regIndexes = new VariableIndex(REG);
    }
}
Also used : BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) 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