use of org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangTableLiteral tableLiteral) {
tableLiteral.regIndex = calcAndGetExprRegIndex(tableLiteral);
Operand typeCPIndex = getTypeCPIndex(tableLiteral.type);
emit(InstructionCodes.NEWTABLE, tableLiteral.regIndex, typeCPIndex);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral in project ballerina by ballerina-lang.
the class Desugar method getInitExpr.
private BLangExpression getInitExpr(BType type) {
// Don't need to create an empty init expressions if the type allows null.
if (type.isNullable()) {
return null;
}
switch(type.tag) {
case TypeTags.INT:
case TypeTags.FLOAT:
case TypeTags.BOOLEAN:
case TypeTags.STRING:
case TypeTags.BLOB:
// Int, float, boolean, string, blob types will get default values from VM side.
break;
case TypeTags.JSON:
return new BLangJSONLiteral(new ArrayList<>(), type);
case TypeTags.XML:
return new BLangXMLSequenceLiteral(type);
case TypeTags.TABLE:
return new BLangTableLiteral(type);
case TypeTags.STREAM:
return new BLangStreamLiteral(type, null);
case TypeTags.MAP:
return new BLangMapLiteral(new ArrayList<>(), type);
case TypeTags.STRUCT:
if (((BStructSymbol) type.tsymbol).isObject) {
return new BLangTypeInit();
}
return new BLangStructLiteral(new ArrayList<>(), type);
case TypeTags.ARRAY:
BLangArrayLiteral array = new BLangArrayLiteral();
array.exprs = new ArrayList<>();
array.type = type;
return rewriteExpr(array);
default:
break;
}
return null;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangRecordLiteral recordLiteral) {
recordLiteral.keyValuePairs.forEach(keyValue -> {
BLangExpression keyExpr = keyValue.key.expr;
if (keyExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
BLangSimpleVarRef varRef = (BLangSimpleVarRef) keyExpr;
keyValue.key.expr = createStringLiteral(varRef.pos, varRef.variableName.value);
} else {
keyValue.key.expr = rewriteExpr(keyValue.key.expr);
}
keyValue.valueExpr = rewriteExpr(keyValue.valueExpr);
});
BLangExpression expr;
if (recordLiteral.type.tag == TypeTags.STRUCT) {
expr = new BLangStructLiteral(recordLiteral.keyValuePairs, recordLiteral.type);
} else if (recordLiteral.type.tag == TypeTags.MAP) {
expr = new BLangMapLiteral(recordLiteral.keyValuePairs, recordLiteral.type);
} else if (recordLiteral.type.tag == TypeTags.TABLE) {
expr = new BLangTableLiteral(recordLiteral.type);
} else if (recordLiteral.type.tag == TypeTags.STREAM) {
expr = new BLangStreamLiteral(recordLiteral.type, recordLiteral.name);
} else {
expr = new BLangJSONLiteral(recordLiteral.keyValuePairs, recordLiteral.type);
}
result = rewriteExpr(expr);
}
Aggregations