Search in sources :

Example 6 with BLangXMLQName

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;
}
Also used : BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) BLangLocalXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangLocalXMLNS)

Example 7 with BLangXMLQName

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;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)

Example 8 with BLangXMLQName

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);
}
Also used : BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 9 with BLangXMLQName

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);
    });
}
Also used : BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 10 with BLangXMLQName

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);
}
Also used : BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)

Aggregations

BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)6 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)3 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)2 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)2 BLangXMLAttribute (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute)2 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)2 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)2 BXMLAttributeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLAttributeSymbol)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangLocalXMLNS (org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangLocalXMLNS)1 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)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 Name (org.wso2.ballerinalang.compiler.util.Name)1