Search in sources :

Example 6 with BLangBinaryExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr 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 7 with BLangBinaryExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr in project ballerina by ballerina-lang.

the class SiddhiQueryBuilder method visit.

@Override
public void visit(BLangJoinStreamingInput joinStreamingInput) {
    BLangBinaryExpr expr = (BLangBinaryExpr) joinStreamingInput.getOnExpression();
    BLangStreamingInput streamingInput = (BLangStreamingInput) joinStreamingInput.getStreamingInput();
    joinStreamingInputClause = new StringBuilder();
    streamingInput.accept(this);
    if (joinStreamingInput.isUnidirectionalBeforeJoin()) {
        joinStreamingInputClause.append(" unidirectional ");
    }
    String joinType = joinStreamingInput.getJoinType();
    joinStreamingInputClause.append(" ").append(joinType).append(" ");
    if (joinStreamingInput.isUnidirectionalAfterJoin()) {
        joinStreamingInputClause.append(" unidirectional ");
    }
    joinStreamingInputClause.append(streamingInputClause).append(" on ");
    binaryExpr = new StringBuilder();
    expr.accept(this);
    joinStreamingInputClause.append(binaryExpr);
}
Also used : BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr) BLangStreamingInput(org.wso2.ballerinalang.compiler.tree.clauses.BLangStreamingInput)

Example 8 with BLangBinaryExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr in project ballerina by ballerina-lang.

the class SqlQueryBuilder method visit.

@Override
public void visit(BLangHaving having) {
    BLangBinaryExpr expr = (BLangBinaryExpr) having.getExpression();
    havingClause = new StringBuilder("having ");
    addParametrizedSQL(expr, havingClause, havingExprParams);
}
Also used : BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)

Example 9 with BLangBinaryExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

public void visit(BLangBinaryExpr binaryExpr) {
    ExpressionNode leftExpression = binaryExpr.getLeftExpression();
    ((BLangExpression) leftExpression).accept(this);
    ExpressionNode rightExpression = binaryExpr.getRightExpression();
    ((BLangExpression) rightExpression).accept(this);
}
Also used : SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode) ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 10 with BLangBinaryExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr in project ballerina by ballerina-lang.

the class TypeChecker method getBinaryAddExpr.

private BLangExpression getBinaryAddExpr(BLangExpression lExpr, BLangExpression rExpr, BSymbol opSymbol) {
    BLangBinaryExpr binaryExpressionNode = (BLangBinaryExpr) TreeBuilder.createBinaryExpressionNode();
    binaryExpressionNode.lhsExpr = lExpr;
    binaryExpressionNode.rhsExpr = rExpr;
    binaryExpressionNode.pos = rExpr.pos;
    binaryExpressionNode.opKind = OperatorKind.ADD;
    if (opSymbol != symTable.notFoundSymbol) {
        binaryExpressionNode.type = opSymbol.type.getReturnTypes().get(0);
        binaryExpressionNode.opSymbol = (BOperatorSymbol) opSymbol;
    } else {
        binaryExpressionNode.type = symTable.errType;
    }
    types.checkType(binaryExpressionNode, binaryExpressionNode.type, symTable.stringType);
    return binaryExpressionNode;
}
Also used : BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)

Aggregations

BLangBinaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)15 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)5 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)5 BLangStreamingInput (org.wso2.ballerinalang.compiler.tree.clauses.BLangStreamingInput)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)2 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)2 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)1 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)1 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)1 BLangTernaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangTernaryExpr)1 BLangIf (org.wso2.ballerinalang.compiler.tree.statements.BLangIf)1 BLangReturn (org.wso2.ballerinalang.compiler.tree.statements.BLangReturn)1