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