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