use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class EndpointDesugar method defineGlobalEndpoint.
void defineGlobalEndpoint(BLangEndpoint ep, SymbolEnv env) {
final BLangVariable epVariable = ASTBuilderUtil.createVariable(ep.pos, ep.name.value, ep.symbol.type);
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(ep.pos, env.enclPkg.symbol.scope, env, names.fromIdNode(ep.name), SymTag.VARIABLE);
env.enclPkg.globalVars.add(epVariable);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class EndpointDesugar method generateEndpointInit.
private BLangBlockStmt generateEndpointInit(BLangEndpoint endpoint, SymbolEnv env, BSymbol encSymbol) {
final String epName = endpoint.name.value;
final DiagnosticPos pos = endpoint.pos;
BLangBlockStmt temp = new BLangBlockStmt();
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, names.fromString(epName), SymTag.VARIABLE);
final BLangExpression newExpr;
if (endpoint.configurationExpr != null && endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
// Handle Endpoint Assignment.
newExpr = endpoint.configurationExpr;
} else if (endpoint.configurationExpr != null && endpoint.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
// Handle Endpoint initialization.
newExpr = ASTBuilderUtil.createEmptyRecordLiteral(pos, endpoint.symbol.type);
} else {
newExpr = null;
}
// EPType ep_name = {};
if (env.enclInvokable != null) {
// In callable unit, endpoint is same scope variable.
final BLangVariableDef epNewStmt = ASTBuilderUtil.createVariableDefStmt(pos, temp);
epNewStmt.var = epVariable;
epNewStmt.var.expr = newExpr;
} else {
// This is an init function. ep variable is defined in outside.
if (env.enclService != null) {
// Add to endpoint variable to relevant location
final BLangVariableDef epVarDef = ASTBuilderUtil.createVariableDef(pos);
epVarDef.var = epVariable;
env.enclService.vars.add(epVarDef);
}
final BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(pos, temp);
assignmentStmt.varRefs.add(ASTBuilderUtil.createVariableRef(pos, epVariable.symbol));
assignmentStmt.expr = newExpr;
}
return temp;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class EndpointDesugar method generateEndpointStartOrStop.
private BLangBlockStmt generateEndpointStartOrStop(BLangEndpoint endpoint, BInvokableSymbol funSymbol, SymbolEnv env, BSymbol encSymbol) {
BLangBlockStmt temp = new BLangBlockStmt();
if (funSymbol == null || endpoint.configurationExpr == null || endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
// 2: If endpoint in initialized
return temp;
}
final DiagnosticPos pos = endpoint.pos;
final String epName = endpoint.name.value;
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
final Name name = names.fromIdNode(endpoint.name);
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, name, SymTag.VARIABLE);
List<BLangVariable> args = new ArrayList<>();
if (funSymbol.params.size() == 1) {
// Endpoint is already desugared. Fix this correctly.
args.add(0, epVariable);
}
final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, funSymbol, args, symResolver);
if (funSymbol.params.size() != 1) {
iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
}
expressionStmt.expr = iExpr;
return temp;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class EndpointDesugar method generateEndpointInitFunctionCall.
private BLangBlockStmt generateEndpointInitFunctionCall(BLangEndpoint endpoint, SymbolEnv env, BSymbol encSymbol, BSymbol varEncSymbol) {
BLangBlockStmt temp = new BLangBlockStmt();
if (endpoint.configurationExpr == null || endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
return temp;
}
final String epName = endpoint.name.value;
final DiagnosticPos pos = endpoint.pos;
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, names.fromString(epName), SymTag.VARIABLE);
// EPConfigType ep_nameConf = { ep-config-expr };
final BLangVariableDef epConfigNewStmt = ASTBuilderUtil.createVariableDefStmt(pos, temp);
epConfigNewStmt.var = ASTBuilderUtil.createVariable(pos, epName + "Conf", endpoint.configurationExpr.type);
epConfigNewStmt.var.expr = endpoint.configurationExpr;
ASTBuilderUtil.defineVariable(epConfigNewStmt.var, varEncSymbol, names);
List<BLangVariable> args = Lists.of(epConfigNewStmt.var);
if (endpoint.symbol.initFunction != null && endpoint.symbol.initFunction.params.size() == 2) {
// Endpoint is already desugared. Fix this correctly.
args.add(0, epVariable);
}
// epName.init(ep_nameConf);
final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, endpoint.symbol.initFunction, args, symResolver);
if (endpoint.symbol.initFunction != null && endpoint.symbol.initFunction.params.size() != 2) {
iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
}
expressionStmt.expr = iExpr;
return temp;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol 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));
}
Aggregations