use of org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess 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.expressions.BLangIndexBasedAccess in project ballerina by ballerina-lang.
the class SiddhiQueryBuilder method visit.
@Override
public void visit(BLangFieldBasedAccess fieldAccessExpr) {
varRef = fieldAccessExpr.toString();
if (fieldAccessExpr.expr instanceof BLangIndexBasedAccess) {
BLangIndexBasedAccess indexBasedAccess = (BLangIndexBasedAccess) fieldAccessExpr.expr;
String exprName = indexBasedAccess.expr.toString() + ".length";
if (varRef.contains(exprName)) {
varRef = varRef.replaceFirst(exprName, "last");
}
}
}
Aggregations