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);
}
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);
}
}
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);
}
Aggregations