use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName 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;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangXMLQName bLangXMLQName) {
String prefix = bLangXMLQName.prefix.value;
resultTypes = Lists.of(types.checkType(bLangXMLQName, symTable.stringType, expTypes.get(0)));
if (env.node.getKind() == NodeKind.XML_ATTRIBUTE && prefix.isEmpty() && bLangXMLQName.localname.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
((BLangXMLAttribute) env.node).isNamespaceDeclr = true;
return;
}
if (env.node.getKind() == NodeKind.XML_ATTRIBUTE && prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
((BLangXMLAttribute) env.node).isNamespaceDeclr = true;
return;
}
if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
dlog.error(bLangXMLQName.pos, DiagnosticCode.INVALID_NAMESPACE_PREFIX, prefix);
bLangXMLQName.type = symTable.errType;
return;
}
BSymbol xmlnsSymbol = symResolver.lookupSymbol(env, names.fromIdNode(bLangXMLQName.prefix), SymTag.XMLNS);
if (prefix.isEmpty() && xmlnsSymbol == symTable.notFoundSymbol) {
return;
}
if (!prefix.isEmpty() && xmlnsSymbol == symTable.notFoundSymbol) {
dlog.error(bLangXMLQName.pos, DiagnosticCode.UNDEFINED_SYMBOL, prefix);
bLangXMLQName.type = symTable.errType;
return;
}
bLangXMLQName.namespaceURI = ((BXMLNSSymbol) xmlnsSymbol).namespaceURI;
bLangXMLQName.nsSymbol = (BXMLNSSymbol) xmlnsSymbol;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangXMLQName xmlQName) {
// If the QName is use outside of XML, treat it as string.
if (!xmlQName.isUsedInXML) {
xmlQName.regIndex = calcAndGetExprRegIndex(xmlQName);
String qName = xmlQName.namespaceURI == null ? xmlQName.localname.value : ("{" + xmlQName.namespaceURI + "}" + xmlQName.localname);
xmlQName.regIndex = createStringLiteral(qName, xmlQName.regIndex, env);
return;
}
// Else, treat it as QName
RegIndex nsURIIndex = getNamespaceURIIndex(xmlQName.nsSymbol, env);
RegIndex localnameIndex = createStringLiteral(xmlQName.localname.value, null, env);
RegIndex prefixIndex = createStringLiteral(xmlQName.prefix.value, null, env);
xmlQName.regIndex = calcAndGetExprRegIndex(xmlQName.regIndex, TypeTags.XML);
emit(InstructionCodes.NEWQNAME, localnameIndex, nsURIIndex, prefixIndex, xmlQName.regIndex);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangXMLElementLiteral xmlElementLiteral) {
SymbolEnv xmlElementEnv = SymbolEnv.getXMLElementEnv(xmlElementLiteral, env);
xmlElementLiteral.regIndex = calcAndGetExprRegIndex(xmlElementLiteral);
// Visit in-line namespace declarations. These needs to be visited first before visiting the
// attributes, start and end tag names of the element.
xmlElementLiteral.inlineNamespaces.forEach(xmlns -> {
genNode(xmlns, xmlElementEnv);
});
// Create start tag name
BLangExpression startTagName = (BLangExpression) xmlElementLiteral.getStartTagName();
RegIndex startTagNameRegIndex = visitXMLTagName(startTagName, xmlElementEnv, xmlElementLiteral);
// Create end tag name. If there is no endtag name (empty XML tag),
// then consider start tag name as the end tag name too.
BLangExpression endTagName = (BLangExpression) xmlElementLiteral.getEndTagName();
RegIndex endTagNameRegIndex = endTagName == null ? startTagNameRegIndex : visitXMLTagName(endTagName, xmlElementEnv, xmlElementLiteral);
// Create an XML with the given QName
RegIndex defaultNsURIIndex = getNamespaceURIIndex(xmlElementLiteral.defaultNsSymbol, xmlElementEnv);
emit(InstructionCodes.NEWXMLELEMENT, xmlElementLiteral.regIndex, startTagNameRegIndex, endTagNameRegIndex, defaultNsURIIndex);
// Add namespaces decelerations visible to this element.
xmlElementLiteral.namespacesInScope.forEach((name, symbol) -> {
BLangXMLQName nsQName = new BLangXMLQName(name.getValue(), XMLConstants.XMLNS_ATTRIBUTE);
genNode(nsQName, xmlElementEnv);
RegIndex uriIndex = getNamespaceURIIndex(symbol, xmlElementEnv);
emit(InstructionCodes.XMLATTRSTORE, xmlElementLiteral.regIndex, nsQName.regIndex, uriIndex);
});
// Add attributes
xmlElementLiteral.attributes.forEach(attribute -> {
genNode(attribute, xmlElementEnv);
emit(InstructionCodes.XMLATTRSTORE, xmlElementLiteral.regIndex, attribute.name.regIndex, attribute.value.regIndex);
});
// Add children
xmlElementLiteral.modifiedChildren.forEach(child -> {
genNode(child, xmlElementEnv);
emit(InstructionCodes.XMLSEQSTORE, xmlElementLiteral.regIndex, child.regIndex);
});
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createXMLQName.
public void createXMLQName(DiagnosticPos pos, Set<Whitespace> ws, String localname, String prefix) {
BLangXMLQName qname = (BLangXMLQName) TreeBuilder.createXMLQNameNode();
qname.localname = (BLangIdentifier) createIdentifier(localname);
qname.prefix = (BLangIdentifier) createIdentifier(prefix);
qname.pos = pos;
qname.addWS(ws);
addExpressionNode(qname);
}
Aggregations