Search in sources :

Example 1 with BLangEnumeratorAccessExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangEnumeratorAccessExpr 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;
}
Also used : BLangStructFieldAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangStructFieldAccessExpr) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEnumeratorAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangEnumeratorAccessExpr) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangMapAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr) BLangXMLAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangXMLAccessExpr) BLangJSONAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangJSONAccessExpr)

Example 2 with BLangEnumeratorAccessExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangEnumeratorAccessExpr in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

@Override
public void visit(BLangEnumeratorAccessExpr enumeratorAccessExpr) {
    Operand typeCPIndex = getTypeCPIndex(enumeratorAccessExpr.type);
    Operand varIndex = enumeratorAccessExpr.symbol.varIndex;
    emit(InstructionCodes.ENUMERATORLOAD, typeCPIndex, varIndex, calcAndGetExprRegIndex(enumeratorAccessExpr));
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand)

Aggregations

BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangEnumeratorAccessExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangEnumeratorAccessExpr)1 BLangStructFieldAccessExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangStructFieldAccessExpr)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 BLangVariableReference (org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)1 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1