Search in sources :

Example 6 with BLangUnaryExpr

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

the class IterableCodeDesugar method generateFilter.

/**
 * Generates statements for filter operation.
 *
 * if(!lambda(...)){
 * next;
 * }
 *
 * @param blockStmt target
 * @param operation operation instance
 */
private void generateFilter(BLangBlockStmt blockStmt, Operation operation) {
    final DiagnosticPos pos = operation.pos;
    final BLangIf ifNode = ASTBuilderUtil.createIfStmt(pos, blockStmt);
    final BLangUnaryExpr notExpr = (BLangUnaryExpr) TreeBuilder.createUnaryExpressionNode();
    notExpr.pos = pos;
    notExpr.operator = OperatorKind.NOT;
    notExpr.opSymbol = (BOperatorSymbol) symResolver.resolveUnaryOperator(pos, notExpr.operator, symTable.booleanType);
    notExpr.expr = ASTBuilderUtil.createInvocationExpr(pos, operation.lambdaSymbol, Lists.of(operation.argVar), symResolver);
    notExpr.type = symTable.booleanType;
    ifNode.expr = notExpr;
    ifNode.body = ASTBuilderUtil.createBlockStmt(pos);
    ASTBuilderUtil.createNextStmt(pos, ifNode.body);
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangUnaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf)

Aggregations

BLangUnaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr)4 Name (org.wso2.ballerinalang.compiler.util.Name)2 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)2 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)1 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)1 BLangTypeofExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeofExpr)1 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)1 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)1 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)1 BLangIf (org.wso2.ballerinalang.compiler.tree.statements.BLangIf)1 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)1 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)1