Search in sources :

Example 1 with BLangJSONArrayLiteral

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

the class CodeGenerator method visit.

@Override
public void visit(BLangJSONArrayLiteral arrayLiteral) {
    arrayLiteral.regIndex = calcAndGetExprRegIndex(arrayLiteral);
    List<BLangExpression> argExprs = arrayLiteral.exprs;
    BLangLiteral arraySizeLiteral = new BLangLiteral();
    arraySizeLiteral.pos = arrayLiteral.pos;
    arraySizeLiteral.value = (long) argExprs.size();
    arraySizeLiteral.type = symTable.intType;
    genNode(arraySizeLiteral, this.env);
    emit(InstructionCodes.JSONNEWARRAY, arrayLiteral.regIndex, arraySizeLiteral.regIndex);
    for (int i = 0; i < argExprs.size(); i++) {
        BLangExpression argExpr = argExprs.get(i);
        genNode(argExpr, this.env);
        BLangLiteral indexLiteral = new BLangLiteral();
        indexLiteral.pos = arrayLiteral.pos;
        indexLiteral.value = (long) i;
        indexLiteral.type = symTable.intType;
        genNode(indexLiteral, this.env);
        emit(InstructionCodes.JSONASTORE, arrayLiteral.regIndex, indexLiteral.regIndex, argExpr.regIndex);
    }
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 2 with BLangJSONArrayLiteral

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

the class Desugar method visit.

@Override
public void visit(BLangArrayLiteral arrayLiteral) {
    arrayLiteral.exprs = rewriteExprs(arrayLiteral.exprs);
    if (arrayLiteral.type.tag == TypeTags.JSON || getElementType(arrayLiteral.type).tag == TypeTags.JSON) {
        result = new BLangJSONArrayLiteral(arrayLiteral.exprs, arrayLiteral.type);
        return;
    }
    result = arrayLiteral;
}
Also used : BLangJSONArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral.BLangJSONArrayLiteral)

Aggregations

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangJSONArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral.BLangJSONArrayLiteral)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)1