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));
}
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;
}
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);
}
}
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;
}
}
}
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);
}
}
}
Aggregations