Search in sources :

Example 1 with BLangFieldVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFieldVarRef in project ballerina by ballerina-lang.

the class Desugar method visit.

@Override
public void visit(BLangSimpleVarRef varRefExpr) {
    BLangSimpleVarRef genVarRefExpr = varRefExpr;
    // XML qualified name reference. e.g: ns0:foo
    if (varRefExpr.pkgSymbol != null && varRefExpr.pkgSymbol.tag == SymTag.XMLNS) {
        BLangXMLQName qnameExpr = new BLangXMLQName(varRefExpr.variableName);
        qnameExpr.nsSymbol = (BXMLNSSymbol) varRefExpr.pkgSymbol;
        qnameExpr.localname = varRefExpr.variableName;
        qnameExpr.prefix = varRefExpr.pkgAlias;
        qnameExpr.namespaceURI = qnameExpr.nsSymbol.namespaceURI;
        qnameExpr.isUsedInXML = false;
        qnameExpr.pos = varRefExpr.pos;
        qnameExpr.type = symTable.stringType;
        result = qnameExpr;
        return;
    }
    BSymbol ownerSymbol = varRefExpr.symbol.owner;
    if ((varRefExpr.symbol.tag & SymTag.FUNCTION) == SymTag.FUNCTION && varRefExpr.symbol.type.tag == TypeTags.INVOKABLE) {
        genVarRefExpr = new BLangFunctionVarRef(varRefExpr.symbol);
    } else if ((ownerSymbol.tag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
        // Local variable in a function/resource/action/worker
        genVarRefExpr = new BLangLocalVarRef(varRefExpr.symbol);
    } else if ((ownerSymbol.tag & SymTag.CONNECTOR) == SymTag.CONNECTOR) {
        // Field variable in a receiver
        genVarRefExpr = new BLangFieldVarRef(varRefExpr.symbol);
    } else if ((ownerSymbol.tag & SymTag.STRUCT) == SymTag.STRUCT) {
        genVarRefExpr = new BLangFieldVarRef(varRefExpr.symbol);
    } else if ((ownerSymbol.tag & SymTag.PACKAGE) == SymTag.PACKAGE || (ownerSymbol.tag & SymTag.SERVICE) == SymTag.SERVICE) {
        // Package variable | service variable
        // We consider both of them as package level variables
        genVarRefExpr = new BLangPackageVarRef(varRefExpr.symbol);
        // Only locking service level and package level variables
        if (!enclLocks.isEmpty()) {
            enclLocks.peek().addLockVariable(varRefExpr.symbol);
        }
    }
    genVarRefExpr.type = varRefExpr.type;
    result = genVarRefExpr;
}
Also used : BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangPackageVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangPackageVarRef) BLangFunctionVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFunctionVarRef) BLangLocalVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef) BLangFieldVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFieldVarRef)

Example 2 with BLangFieldVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFieldVarRef in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

@Override
public void visit(BLangFieldVarRef fieldVarRef) {
    RegIndex fieldIndex = fieldVarRef.symbol.varIndex;
    // This is a connector field.
    // the connector reference must be stored in the current reference register index.
    Operand varRegIndex = getOperand(0);
    if (varAssignment) {
        int opcode = getOpcode(fieldVarRef.type.tag, InstructionCodes.IFIELDSTORE);
        emit(opcode, varRegIndex, fieldIndex, fieldVarRef.regIndex);
        return;
    }
    int opcode = getOpcode(fieldVarRef.type.tag, InstructionCodes.IFIELDLOAD);
    RegIndex exprRegIndex = calcAndGetExprRegIndex(fieldVarRef);
    emit(opcode, varRegIndex, fieldIndex, exprRegIndex);
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)1 BLangFieldVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFieldVarRef)1 BLangFunctionVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFunctionVarRef)1 BLangLocalVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef)1 BLangPackageVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangPackageVarRef)1 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)1 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)1