Search in sources :

Example 11 with BLangIndexBasedAccess

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);
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangIndexBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)

Example 12 with BLangIndexBasedAccess

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");
        }
    }
}
Also used : BLangIndexBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess)

Aggregations

BLangIndexBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess)10 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)5 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 BLangFieldBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess)2 BLangVariableReference (org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)2 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)2 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)1 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)1 BArrayType (org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType)1 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangStructFieldAccessExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangStructFieldAccessExpr)1 BLangArrayAccessExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangArrayAccessExpr)1 BLangJSONAccessExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangJSONAccessExpr)1 BLangMapAccessExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr)1 BLangXMLAccessExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangXMLAccessExpr)1 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)1 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)1