Search in sources :

Example 16 with BLangSimpleVarRef

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;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangTernaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTernaryExpr) BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)

Example 17 with BLangSimpleVarRef

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);
    }
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangWindow(org.wso2.ballerinalang.compiler.tree.clauses.BLangWindow) WhereNode(org.ballerinalang.model.tree.clauses.WhereNode) WindowClauseNode(org.ballerinalang.model.tree.clauses.WindowClauseNode) BLangWhere(org.wso2.ballerinalang.compiler.tree.clauses.BLangWhere) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 18 with BLangSimpleVarRef

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);
    }
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)

Example 19 with BLangSimpleVarRef

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);
    }
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)

Example 20 with BLangSimpleVarRef

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);
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)

Aggregations

BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)36 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)11 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)9 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)8 Name (org.wso2.ballerinalang.compiler.util.Name)8 ArrayList (java.util.ArrayList)7 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)6 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)5 BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)4 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)4 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)3 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)3 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)3 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)2 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)2 BLangFieldBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess)2 BLangJSONLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral)2 BLangMapLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral)2