use of org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateCountAggregator.
/**
* Generates following.
*
* variable = variable + 1;
*
* @param blockStmt target
* @param variable variable to increment
*/
private void generateCountAggregator(BLangBlockStmt blockStmt, BLangVariable variable) {
final DiagnosticPos pos = blockStmt.pos;
// create count = count + 1;
final BLangBinaryExpr add = (BLangBinaryExpr) TreeBuilder.createBinaryExpressionNode();
add.pos = pos;
add.type = symTable.intType;
add.opKind = OperatorKind.ADD;
add.lhsExpr = ASTBuilderUtil.createVariableRef(pos, variable.symbol);
add.rhsExpr = ASTBuilderUtil.createLiteral(pos, symTable.intType, 1L);
add.opSymbol = (BOperatorSymbol) symResolver.resolveBinaryOperator(OperatorKind.ADD, symTable.intType, symTable.intType);
final BLangAssignment countAdd = ASTBuilderUtil.createAssignmentStmt(pos, blockStmt);
countAdd.varRefs.add(ASTBuilderUtil.createVariableRef(pos, variable.symbol));
countAdd.expr = add;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateMapAggregator.
/**
* Generates following.
*
* result[key] = value;
*
* @param blockStmt target
* @param ctx current context
*/
private void generateMapAggregator(BLangBlockStmt blockStmt, IterableContext ctx) {
final DiagnosticPos pos = blockStmt.pos;
// create assignment result[key] = value
final BLangIndexBasedAccess indexAccessNode = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
indexAccessNode.pos = pos;
indexAccessNode.indexExpr = ASTBuilderUtil.createVariableRef(pos, ctx.iteratorResultVariables.get(0).symbol);
indexAccessNode.expr = ASTBuilderUtil.createVariableRef(pos, ctx.resultVar.symbol);
indexAccessNode.type = ctx.iteratorResultVariables.get(1).symbol.type;
final BLangAssignment valueAssign = ASTBuilderUtil.createAssignmentStmt(pos, blockStmt);
valueAssign.varRefs.add(indexAccessNode);
valueAssign.expr = ASTBuilderUtil.generateConversionExpr(ASTBuilderUtil.createVariableRef(pos, ctx.iteratorResultVariables.get(1).symbol), symTable.anyType, symResolver);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateArrayAggregator.
/**
* Generates following.
*
* result[count] = value;
* count = count + 1;
*
* @param blockStmt target
* @param ctx current context
*/
private void generateArrayAggregator(BLangBlockStmt blockStmt, IterableContext ctx) {
final DiagnosticPos pos = blockStmt.pos;
// create assignment result[count] = value;
final BLangIndexBasedAccess indexAccessNode = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
indexAccessNode.pos = pos;
indexAccessNode.indexExpr = ASTBuilderUtil.createVariableRef(pos, ctx.countVar.symbol);
indexAccessNode.expr = ASTBuilderUtil.createVariableRef(pos, ctx.resultVar.symbol);
indexAccessNode.type = ctx.iteratorResultVariables.get(0).symbol.type;
final BLangAssignment valueAssign = ASTBuilderUtil.createAssignmentStmt(pos, blockStmt);
valueAssign.varRefs.add(indexAccessNode);
valueAssign.expr = ASTBuilderUtil.createVariableRef(pos, ctx.iteratorResultVariables.get(0).symbol);
// create count = count + 1;
generateCountAggregator(blockStmt, ctx.countVar);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateForeach.
/**
* Generates statements for foreach operation.
*
* lambda(...)
*
* @param blockStmt target
* @param operation operation instance
*/
private void generateForeach(BLangBlockStmt blockStmt, Operation operation) {
final DiagnosticPos pos = operation.pos;
final BLangExpressionStmt exprStmt = ASTBuilderUtil.createExpressionStmt(pos, blockStmt);
exprStmt.expr = ASTBuilderUtil.createInvocationExpr(pos, operation.lambdaSymbol, Lists.of(operation.argVar), symResolver);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addTryClause.
public void addTryClause(DiagnosticPos pos) {
BLangBlockStmt tryBlock = (BLangBlockStmt) this.blockNodeStack.pop();
tryBlock.pos = pos;
tryCatchFinallyNodesStack.peek().tryBody = tryBlock;
}
Aggregations