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);
}
}
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;
}
Aggregations