Search in sources :

Example 6 with BLangStatement

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

the class SiddhiQueryBuilder method visit.

public void visit(BLangForever foreverStatement) {
    siddhiQuery = new StringBuilder();
    streamDefinitionQuery = new StringBuilder();
    streamIds = new HashSet<>();
    inStreamRefs = new ArrayList<>();
    outStreamRefs = new ArrayList<>();
    inTableRefs = new ArrayList<>();
    outTableRefs = new ArrayList<>();
    binaryExpr = null;
    setExpr = null;
    orderByClause = null;
    whereClause = null;
    windowClause = null;
    joinStreamingInputClause = null;
    streamingInputClause = null;
    selectExprClause = null;
    selectExpr = null;
    setAssignmentClause = null;
    groupByClause = null;
    havingClause = null;
    patternStreamingClause = null;
    streamActionClause = null;
    intRangeExpr = null;
    List<VariableNode> globalVariables = foreverStatement.getGlobalVariables();
    if (globalVariables != null) {
        for (VariableNode variable : globalVariables) {
            ((BLangVariable) variable).accept(this);
        }
    }
    List<VariableSymbol> functionVariables = foreverStatement.getFunctionVariables();
    if (functionVariables != null) {
        for (VariableSymbol variable : functionVariables) {
            getStreamDefintionForFuntionVariable((BVarSymbol) variable);
        }
    }
    List<? extends StatementNode> statementNodes = foreverStatement.gettreamingQueryStatements();
    for (StatementNode statementNode : statementNodes) {
        ((BLangStatement) statementNode).accept(this);
    }
    foreverStatement.setSiddhiQuery(this.getSiddhiQuery());
    foreverStatement.setStreamIdsAsString(String.join(",", streamIds));
}
Also used : VariableNode(org.ballerinalang.model.tree.VariableNode) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) VariableSymbol(org.ballerinalang.model.symbols.VariableSymbol) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 7 with BLangStatement

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

the class SymbolEnter method visit.

@Override
public void visit(BLangVariable varNode) {
    // this is a field variable defined for object init function
    if (varNode.isField) {
        Name varName = names.fromIdNode(varNode.name);
        BVarSymbol fieldVar = (BVarSymbol) symResolver.resolveObjectField(varNode.pos, env, varName, env.enclObject.symbol.type.tsymbol);
        varNode.type = fieldVar.type;
        varName = getFieldSymbolName(((BLangFunction) env.enclInvokable).receiver, varNode);
        BVarSymbol varSymbol = defineVarSymbol(varNode.pos, varNode.flagSet, varNode.type, varName, env);
        env.enclObject.initFunction.initFunctionStmts.put(fieldVar, (BLangStatement) createAssignmentStmt(varNode, varSymbol, fieldVar));
        varSymbol.docTag = varNode.docTag;
        varNode.symbol = varSymbol;
        return;
    }
    // assign the type to var type node
    if (varNode.type == null) {
        varNode.type = symResolver.resolveTypeNode(varNode.typeNode, env);
    }
    Name varName = names.fromIdNode(varNode.name);
    if (varName == Names.EMPTY || varName == Names.IGNORE) {
        // e.g. function foo() (int);
        return;
    }
    BVarSymbol varSymbol = defineVarSymbol(varNode.pos, varNode.flagSet, varNode.type, varName, env);
    varSymbol.docTag = varNode.docTag;
    varNode.symbol = varSymbol;
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 8 with BLangStatement

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

the class CodeAnalyzer method validateWorkerInteractions.

private void validateWorkerInteractions(WorkerActionSystem workerActionSystem) {
    BLangStatement currentAction;
    WorkerActionStateMachine currentSM;
    String currentWorkerId;
    boolean systemRunning;
    do {
        systemRunning = false;
        for (Map.Entry<String, WorkerActionStateMachine> entry : workerActionSystem.entrySet()) {
            currentWorkerId = entry.getKey();
            currentSM = entry.getValue();
            if (currentSM.done()) {
                continue;
            }
            currentAction = currentSM.currentAction();
            if (isWorkerSend(currentAction)) {
                if (isWorkerForkSend(currentAction)) {
                    currentSM.next();
                    systemRunning = true;
                } else {
                    WorkerActionStateMachine otherSM = workerActionSystem.get(this.extractWorkerId(currentAction));
                    if (otherSM.currentIsReceive(currentWorkerId)) {
                        this.validateWorkerActionParameters((BLangWorkerSend) currentAction, (BLangWorkerReceive) otherSM.currentAction());
                        otherSM.next();
                        currentSM.next();
                        systemRunning = true;
                    }
                }
            }
        }
    } while (systemRunning);
    if (!workerActionSystem.everyoneDone()) {
        this.reportInvalidWorkerInteractionDiagnostics(workerActionSystem);
    }
}
Also used : BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with BLangStatement

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

the class CodeAnalyzer method visit.

public void visit(BLangTransformer transformerNode) {
    List<BVarSymbol> inputs = new ArrayList<>();
    inputs.add(transformerNode.source.symbol);
    transformerNode.requiredParams.forEach(param -> inputs.add(param.symbol));
    List<BVarSymbol> outputs = new ArrayList<>();
    transformerNode.retParams.forEach(param -> outputs.add(param.symbol));
    for (BLangStatement stmt : transformerNode.body.stmts) {
        switch(stmt.getKind()) {
            case VARIABLE_DEF:
                BLangVariableDef variableDefStmt = (BLangVariableDef) stmt;
                variableDefStmt.var.expr.accept(new TransformerVarRefValidator(outputs, DiagnosticCode.TRANSFORMER_INVALID_OUTPUT_USAGE));
                inputs.add(variableDefStmt.var.symbol);
                break;
            case ASSIGNMENT:
                BLangAssignment assignStmt = (BLangAssignment) stmt;
                assignStmt.varRefs.forEach(varRef -> {
                    varRef.accept(new TransformerVarRefValidator(inputs, DiagnosticCode.TRANSFORMER_INVALID_INPUT_UPDATE));
                    // If the stmt is declared using var, all the variable refs on lhs should be treated as inputs
                    if (assignStmt.declaredWithVar && varRef.getKind() == NodeKind.SIMPLE_VARIABLE_REF && !inputs.contains(((BLangSimpleVarRef) varRef).symbol)) {
                        inputs.add(((BLangSimpleVarRef) varRef).symbol);
                    }
                });
                assignStmt.expr.accept(new TransformerVarRefValidator(outputs, DiagnosticCode.TRANSFORMER_INVALID_OUTPUT_USAGE));
                break;
            case EXPRESSION_STATEMENT:
                // Here we have assumed that the invocation expression is the only expression-statement available.
                // TODO: support other types, once they are implemented.
                dlog.error(stmt.pos, DiagnosticCode.INVALID_STATEMENT_IN_TRANSFORMER, "invocation");
                break;
            default:
                dlog.error(stmt.pos, DiagnosticCode.INVALID_STATEMENT_IN_TRANSFORMER, stmt.getKind().name().toLowerCase().replace('_', ' '));
                break;
        }
    }
}
Also used : BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) ArrayList(java.util.ArrayList) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 10 with BLangStatement

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

the class SemanticAnalyzer method visit.

// Streaming related methods.
public void visit(BLangForever foreverStatement) {
    for (StreamingQueryStatementNode streamingQueryStatement : foreverStatement.gettreamingQueryStatements()) {
        analyzeStmt((BLangStatement) streamingQueryStatement, env);
    }
    List<BLangVariable> globalVariableList = this.env.enclPkg.globalVars;
    if (globalVariableList != null) {
        for (BLangVariable variable : globalVariableList) {
            if (((variable).type.tsymbol) != null) {
                if ("stream".equals((((variable).type.tsymbol)).name.value)) {
                    foreverStatement.addGlobalVariable(variable);
                }
            }
        }
    }
    List<BVarSymbol> functionParameterList = ((BInvokableSymbol) this.env.scope.owner).getParameters();
    for (BVarSymbol varSymbol : functionParameterList) {
        if ("stream".equals((((varSymbol).type.tsymbol)).name.value)) {
            foreverStatement.addFunctionVariable(varSymbol);
        }
    }
}
Also used : StreamingQueryStatementNode(org.ballerinalang.model.tree.statements.StreamingQueryStatementNode) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Aggregations

BLangStatement (org.wso2.ballerinalang.compiler.tree.statements.BLangStatement)10 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)6 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)5 NodeKind (org.ballerinalang.model.tree.NodeKind)3 StatementNode (org.ballerinalang.model.tree.statements.StatementNode)3 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)3 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)3 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)3 BLangMatchStmtPatternClause (org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)2 TreeBuilder (org.ballerinalang.model.TreeBuilder)2 StreamingQueryStatementNode (org.ballerinalang.model.tree.statements.StreamingQueryStatementNode)2 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2