Search in sources :

Example 1 with BLangXMLAttributeAccess

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess in project ballerina by ballerina-lang.

the class TypeChecker method visit.

public void visit(BLangXMLAttributeAccess xmlAttributeAccessExpr) {
    BType actualType = symTable.errType;
    // First analyze the variable reference expression.
    checkExpr(xmlAttributeAccessExpr.expr, env, Lists.of(symTable.xmlType));
    // Then analyze the index expression.
    BLangExpression indexExpr = xmlAttributeAccessExpr.indexExpr;
    if (indexExpr == null) {
        if (xmlAttributeAccessExpr.lhsVar) {
            dlog.error(xmlAttributeAccessExpr.pos, DiagnosticCode.XML_ATTRIBUTE_MAP_UPDATE_NOT_ALLOWED);
        } else {
            actualType = symTable.xmlAttributesType;
        }
        resultTypes = types.checkTypes(xmlAttributeAccessExpr, Lists.of(actualType), expTypes);
        return;
    }
    checkExpr(indexExpr, env, Lists.of(symTable.stringType)).get(0);
    if (indexExpr.getKind() == NodeKind.XML_QNAME) {
        ((BLangXMLQName) indexExpr).isUsedInXML = true;
    }
    if (indexExpr.type.tag == TypeTags.STRING) {
        actualType = symTable.stringType;
    }
    xmlAttributeAccessExpr.namespaces.putAll(symResolver.resolveAllNamespaces(env));
    resultTypes = types.checkTypes(xmlAttributeAccessExpr, Lists.of(actualType), expTypes);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 2 with BLangXMLAttributeAccess

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

@Override
public void visit(BLangXMLAttributeAccess xmlAttributeAccessExpr) {
    boolean variableStore = this.varAssignment;
    this.varAssignment = false;
    genNode(xmlAttributeAccessExpr.expr, this.env);
    RegIndex varRefRegIndex = xmlAttributeAccessExpr.expr.regIndex;
    if (xmlAttributeAccessExpr.indexExpr == null) {
        RegIndex xmlValueRegIndex = calcAndGetExprRegIndex(xmlAttributeAccessExpr);
        emit(InstructionCodes.XML2XMLATTRS, varRefRegIndex, xmlValueRegIndex);
        return;
    }
    BLangExpression indexExpr = xmlAttributeAccessExpr.indexExpr;
    genNode(xmlAttributeAccessExpr.indexExpr, this.env);
    RegIndex qnameRegIndex = xmlAttributeAccessExpr.indexExpr.regIndex;
    // If this is a string representation of qname
    if (indexExpr.getKind() != NodeKind.XML_QNAME) {
        RegIndex localNameRegIndex = getRegIndex(TypeTags.STRING);
        RegIndex uriRegIndex = getRegIndex(TypeTags.STRING);
        emit(InstructionCodes.S2QNAME, qnameRegIndex, localNameRegIndex, uriRegIndex);
        qnameRegIndex = getRegIndex(TypeTags.XML);
        generateURILookupInstructions(xmlAttributeAccessExpr.namespaces, localNameRegIndex, uriRegIndex, qnameRegIndex, indexExpr.pos, env);
    }
    if (variableStore) {
        emit(InstructionCodes.XMLATTRSTORE, varRefRegIndex, qnameRegIndex, xmlAttributeAccessExpr.regIndex);
    } else {
        RegIndex xmlValueRegIndex = calcAndGetExprRegIndex(xmlAttributeAccessExpr);
        emit(InstructionCodes.XMLATTRLOAD, varRefRegIndex, qnameRegIndex, xmlValueRegIndex);
    }
}
Also used : BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 3 with BLangXMLAttributeAccess

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess in project ballerina by ballerina-lang.

the class BLangPackageBuilder method createXmlAttributesRefExpr.

public void createXmlAttributesRefExpr(DiagnosticPos pos, Set<Whitespace> ws, boolean singleAttribute) {
    BLangXMLAttributeAccess xmlAttributeAccess = (BLangXMLAttributeAccess) TreeBuilder.createXMLAttributeAccessNode();
    xmlAttributeAccess.pos = pos;
    xmlAttributeAccess.addWS(ws);
    if (singleAttribute) {
        xmlAttributeAccess.indexExpr = (BLangExpression) exprNodeStack.pop();
    }
    xmlAttributeAccess.expr = (BLangVariableReference) exprNodeStack.pop();
    addExpressionNode(xmlAttributeAccess);
}
Also used : BLangXMLAttributeAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess)

Aggregations

BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangXMLAttributeAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess)1 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)1