use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangLocalXMLNS xmlnsNode) {
RegIndex lvIndex = getLVIndex(TypeTags.STRING);
BLangExpression nsURIExpr = xmlnsNode.namespaceURI;
nsURIExpr.regIndex = createLHSRegIndex(lvIndex);
genNode(nsURIExpr, env);
BXMLNSSymbol nsSymbol = (BXMLNSSymbol) xmlnsNode.symbol;
nsSymbol.nsURIIndex = lvIndex;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol in project ballerina by ballerina-lang.
the class CodeGenerator method generateURILookupInstructions.
private void generateURILookupInstructions(Map<Name, BXMLNSSymbol> namespaces, RegIndex localNameRegIndex, RegIndex uriRegIndex, RegIndex targetQNameRegIndex, DiagnosticPos pos, SymbolEnv symbolEnv) {
if (namespaces.isEmpty()) {
createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
return;
}
Stack<Operand> endJumpInstrStack = new Stack<>();
String prefix;
for (Entry<Name, BXMLNSSymbol> keyValues : namespaces.entrySet()) {
prefix = keyValues.getKey().getValue();
// skip the default namespace
if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
continue;
}
// Below section creates the condition to compare the namespace URIs
// store the comparing uri as string
BXMLNSSymbol nsSymbol = keyValues.getValue();
int opcode = getOpcode(TypeTags.STRING, InstructionCodes.IEQ);
RegIndex conditionExprIndex = getRegIndex(TypeTags.BOOLEAN);
emit(opcode, uriRegIndex, getNamespaceURIIndex(nsSymbol, symbolEnv), conditionExprIndex);
Operand ifCondJumpAddr = getOperand(-1);
emit(InstructionCodes.BR_FALSE, conditionExprIndex, ifCondJumpAddr);
// Below section creates instructions to be executed, if the above condition succeeds (then body)
// create the prefix literal
RegIndex prefixIndex = createStringLiteral(prefix, null, env);
// create a qname
emit(InstructionCodes.NEWQNAME, localNameRegIndex, uriRegIndex, prefixIndex, targetQNameRegIndex);
Operand endJumpAddr = getOperand(-1);
emit(InstructionCodes.GOTO, endJumpAddr);
endJumpInstrStack.add(endJumpAddr);
ifCondJumpAddr.value = nextIP();
}
// else part. create a qname with empty prefix
createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
while (!endJumpInstrStack.isEmpty()) {
endJumpInstrStack.pop().value = nextIP();
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangXMLAttribute xmlAttribute) {
SymbolEnv xmlAttributeEnv = SymbolEnv.getXMLAttributeEnv(xmlAttribute, env);
BLangExpression attrNameExpr = xmlAttribute.name;
attrNameExpr.regIndex = calcAndGetExprRegIndex(attrNameExpr);
genNode(attrNameExpr, xmlAttributeEnv);
RegIndex attrQNameRegIndex = attrNameExpr.regIndex;
// If the attribute name is a string representation of qname
if (attrNameExpr.getKind() != NodeKind.XML_QNAME) {
RegIndex localNameRegIndex = getRegIndex(TypeTags.STRING);
RegIndex uriRegIndex = getRegIndex(TypeTags.STRING);
emit(InstructionCodes.S2QNAME, attrQNameRegIndex, localNameRegIndex, uriRegIndex);
attrQNameRegIndex = getRegIndex(TypeTags.XML);
generateURILookupInstructions(((BLangXMLElementLiteral) env.node).namespacesInScope, localNameRegIndex, uriRegIndex, attrQNameRegIndex, xmlAttribute.pos, xmlAttributeEnv);
attrNameExpr.regIndex = attrQNameRegIndex;
}
BLangExpression attrValueExpr = xmlAttribute.value;
genNode(attrValueExpr, env);
if (xmlAttribute.isNamespaceDeclr) {
((BXMLNSSymbol) xmlAttribute.symbol).nsURIIndex = attrValueExpr.regIndex;
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol 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.semantics.model.symbols.BXMLNSSymbol in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangXMLElementLiteral xmlElementLiteral) {
xmlElementLiteral.startTagName = rewriteExpr(xmlElementLiteral.startTagName);
xmlElementLiteral.endTagName = rewriteExpr(xmlElementLiteral.endTagName);
xmlElementLiteral.modifiedChildren = rewriteExprs(xmlElementLiteral.modifiedChildren);
xmlElementLiteral.attributes = rewriteExprs(xmlElementLiteral.attributes);
// Separate the in-line namepsace declarations and attributes.
Iterator<BLangXMLAttribute> attributesItr = xmlElementLiteral.attributes.iterator();
while (attributesItr.hasNext()) {
BLangXMLAttribute attribute = attributesItr.next();
if (!attribute.isNamespaceDeclr) {
continue;
}
// Create local namepace declaration for all in-line namespace declarations
BLangLocalXMLNS xmlns = new BLangLocalXMLNS();
xmlns.namespaceURI = attribute.value.concatExpr;
xmlns.prefix = ((BLangXMLQName) attribute.name).localname;
xmlns.symbol = (BXMLNSSymbol) attribute.symbol;
xmlElementLiteral.inlineNamespaces.add(xmlns);
attributesItr.remove();
}
result = xmlElementLiteral;
}
Aggregations