use of org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangFieldBasedAccess fieldAccessExpr) {
BLangVariableReference targetVarRef = fieldAccessExpr;
if (fieldAccessExpr.expr.type.tag == TypeTags.ENUM) {
targetVarRef = new BLangEnumeratorAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.field, fieldAccessExpr.symbol);
} else {
fieldAccessExpr.expr = rewriteExpr(fieldAccessExpr.expr);
BType varRefType = fieldAccessExpr.expr.type;
if (varRefType.tag == TypeTags.STRUCT) {
targetVarRef = new BLangStructFieldAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.expr, fieldAccessExpr.symbol);
} else if (varRefType.tag == TypeTags.MAP) {
BLangLiteral stringLit = createStringLiteral(fieldAccessExpr.pos, fieldAccessExpr.field.value);
targetVarRef = new BLangMapAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.expr, stringLit);
} else if (varRefType.tag == TypeTags.JSON) {
BLangLiteral stringLit = createStringLiteral(fieldAccessExpr.pos, fieldAccessExpr.field.value);
targetVarRef = new BLangJSONAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.expr, stringLit);
} else if (varRefType.tag == TypeTags.XML) {
BLangLiteral stringLit = createStringLiteral(fieldAccessExpr.pos, fieldAccessExpr.field.value);
targetVarRef = new BLangXMLAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.expr, stringLit, fieldAccessExpr.fieldType);
}
}
targetVarRef.lhsVar = fieldAccessExpr.lhsVar;
targetVarRef.type = fieldAccessExpr.type;
result = targetVarRef;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangIndexBasedAccess indexAccessExpr) {
BLangVariableReference targetVarRef = indexAccessExpr;
indexAccessExpr.indexExpr = rewriteExpr(indexAccessExpr.indexExpr);
indexAccessExpr.expr = rewriteExpr(indexAccessExpr.expr);
BType varRefType = indexAccessExpr.expr.type;
if (varRefType.tag == TypeTags.STRUCT) {
targetVarRef = new BLangStructFieldAccessExpr(indexAccessExpr.pos, indexAccessExpr.expr, indexAccessExpr.symbol);
} else if (varRefType.tag == TypeTags.MAP) {
targetVarRef = new BLangMapAccessExpr(indexAccessExpr.pos, indexAccessExpr.expr, indexAccessExpr.indexExpr);
} else if (varRefType.tag == TypeTags.JSON || getElementType(varRefType).tag == TypeTags.JSON) {
targetVarRef = new BLangJSONAccessExpr(indexAccessExpr.pos, indexAccessExpr.expr, indexAccessExpr.indexExpr);
} else if (varRefType.tag == TypeTags.ARRAY) {
targetVarRef = new BLangArrayAccessExpr(indexAccessExpr.pos, indexAccessExpr.expr, indexAccessExpr.indexExpr);
} else if (varRefType.tag == TypeTags.XML) {
targetVarRef = new BLangXMLAccessExpr(indexAccessExpr.pos, indexAccessExpr.expr, indexAccessExpr.indexExpr);
}
targetVarRef.lhsVar = indexAccessExpr.lhsVar;
targetVarRef.type = indexAccessExpr.type;
result = targetVarRef;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangMapAccessExpr mapKeyAccessExpr) {
boolean variableStore = this.varAssignment;
this.varAssignment = false;
genNode(mapKeyAccessExpr.expr, this.env);
Operand varRefRegIndex = mapKeyAccessExpr.expr.regIndex;
genNode(mapKeyAccessExpr.indexExpr, this.env);
Operand keyRegIndex = mapKeyAccessExpr.indexExpr.regIndex;
BMapType mapType = (BMapType) mapKeyAccessExpr.expr.type;
if (variableStore) {
int opcode = getValueToRefTypeCastOpcode(mapType.constraint.tag);
if (opcode == InstructionCodes.NOP) {
emit(InstructionCodes.MAPSTORE, varRefRegIndex, keyRegIndex, mapKeyAccessExpr.regIndex);
} else {
RegIndex refRegMapValue = getRegIndex(TypeTags.ANY);
emit(opcode, mapKeyAccessExpr.regIndex, refRegMapValue);
emit(InstructionCodes.MAPSTORE, varRefRegIndex, keyRegIndex, refRegMapValue);
}
} else {
int opcode = getRefToValueTypeCastOpcode(mapType.constraint.tag);
if (opcode == InstructionCodes.NOP) {
emit(InstructionCodes.MAPLOAD, varRefRegIndex, keyRegIndex, calcAndGetExprRegIndex(mapKeyAccessExpr));
} else {
RegIndex refRegMapValue = getRegIndex(TypeTags.ANY);
emit(InstructionCodes.MAPLOAD, varRefRegIndex, keyRegIndex, refRegMapValue);
emit(opcode, refRegMapValue, calcAndGetExprRegIndex(mapKeyAccessExpr));
}
}
this.varAssignment = variableStore;
}
Aggregations