use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateCompareAggregator.
/**
* Generates following.
*
* result = result (Operator) value ? result : value
*
* @param blockStmt target
* @param ctx current context
* @param operator compare operator
*/
private void generateCompareAggregator(BLangBlockStmt blockStmt, IterableContext ctx, OperatorKind operator) {
final DiagnosticPos pos = blockStmt.pos;
final BLangSimpleVarRef resultVar = ASTBuilderUtil.createVariableRef(pos, ctx.resultVar.symbol);
final BLangSimpleVarRef valueVar = ASTBuilderUtil.createVariableRef(pos, ctx.iteratorResultVariables.get(0).symbol);
final BLangBinaryExpr compare = (BLangBinaryExpr) TreeBuilder.createBinaryExpressionNode();
compare.pos = pos;
compare.type = symTable.booleanType;
compare.opKind = operator;
compare.lhsExpr = resultVar;
compare.rhsExpr = valueVar;
compare.opSymbol = (BOperatorSymbol) symResolver.resolveBinaryOperator(operator, resultVar.symbol.type, valueVar.symbol.type);
final BLangTernaryExpr ternaryExpr = (BLangTernaryExpr) TreeBuilder.createTernaryExpressionNode();
ternaryExpr.pos = pos;
ternaryExpr.expr = compare;
ternaryExpr.thenExpr = resultVar;
ternaryExpr.elseExpr = valueVar;
ternaryExpr.type = compare.type;
final BLangAssignment countAdd = ASTBuilderUtil.createAssignmentStmt(pos, blockStmt);
countAdd.varRefs.add(resultVar);
countAdd.expr = ternaryExpr;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SiddhiQueryBuilder method visit.
@Override
public void visit(BLangStreamingInput streamingInput) {
streamingInputClause = new StringBuilder();
streamingInputClause.append(((BLangSimpleVarRef) streamingInput.getStreamReference()).getVariableName().value);
WhereNode beforeWhereNode = streamingInput.getBeforeStreamingCondition();
WhereNode afterWhereNode = streamingInput.getAfterStreamingCondition();
WindowClauseNode windowClauseNode = streamingInput.getWindowClause();
if (beforeWhereNode != null) {
((BLangWhere) beforeWhereNode).accept(this);
streamingInputClause.append(" ").append(whereClause);
}
if (windowClauseNode != null) {
((BLangWindow) windowClauseNode).accept(this);
streamingInputClause.append(" ").append(windowClause);
}
if (afterWhereNode != null) {
((BLangWhere) afterWhereNode).accept(this);
streamingInputClause.append(" ").append(whereClause);
}
if (streamingInput.getAlias() != null) {
streamingInputClause.append(" as ").append(streamingInput.getAlias()).append(" ");
}
BLangExpression streamReference = (BLangExpression) streamingInput.getStreamReference();
if (streamReference != null) {
streamReference.accept(this);
streamIds.add(varRef);
varRef = "";
addInRefs(streamReference);
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SiddhiQueryBuilder method visit.
@Override
public void visit(BLangOrderBy orderBy) {
List<? extends ExpressionNode> varRefs = orderBy.getVariables();
Iterator<? extends ExpressionNode> iterator = varRefs.iterator();
BLangSimpleVarRef variableRef = (BLangSimpleVarRef) iterator.next();
orderByClause = new StringBuilder("order by ");
addVarRefToClauseBuilder(variableRef, orderByClause);
while (iterator.hasNext()) {
orderByClause.append(",").append(" ");
variableRef = (BLangSimpleVarRef) iterator.next();
addVarRefToClauseBuilder(variableRef, orderByClause);
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SiddhiQueryBuilder method visit.
@Override
public void visit(BLangGroupBy groupBy) {
List<? extends ExpressionNode> varList = groupBy.getVariables();
Iterator<? extends ExpressionNode> iterator = varList.iterator();
groupByClause = new StringBuilder("group by ");
BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) iterator.next();
addVarRefToClauseBuilder(simpleVarRef, groupByClause);
while (iterator.hasNext()) {
simpleVarRef = (BLangSimpleVarRef) iterator.next();
groupByClause.append(", ");
addVarRefToClauseBuilder(simpleVarRef, groupByClause);
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SqlQueryBuilder method visit.
@Override
public void visit(BLangFieldBasedAccess fieldAccessExpr) {
BLangSimpleVarRef expr = (BLangSimpleVarRef) fieldAccessExpr.expr;
String sqlExpr = expr.variableName.value + "." + fieldAccessExpr.field.value;
exprStack.push(sqlExpr);
}
Aggregations