use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangPackageVarRef in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangPackageVarRef packageVarRef) {
Operand gvIndex = packageVarRef.symbol.varIndex;
if (varAssignment) {
int opcode = getOpcode(packageVarRef.type.tag, InstructionCodes.IGSTORE);
emit(opcode, packageVarRef.regIndex, gvIndex);
return;
}
int opcode = getOpcode(packageVarRef.type.tag, InstructionCodes.IGLOAD);
packageVarRef.regIndex = calcAndGetExprRegIndex(packageVarRef);
emit(opcode, gvIndex, packageVarRef.regIndex);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangPackageVarRef 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;
}
Aggregations