use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
public void visit(BLangXMLAttribute bLangXMLAttribute) {
if (!(bLangXMLAttribute.name.getKind() == NodeKind.XML_QNAME)) {
return;
}
BLangXMLQName qname = (BLangXMLQName) bLangXMLAttribute.name;
// If no duplicates, then define this attribute symbol.
if (!bLangXMLAttribute.isNamespaceDeclr) {
BXMLAttributeSymbol attrSymbol = new BXMLAttributeSymbol(qname.localname.value, qname.namespaceURI, env.enclPkg.symbol.pkgID, env.scope.owner);
if (symResolver.checkForUniqueMemberSymbol(bLangXMLAttribute.pos, env, attrSymbol)) {
env.scope.define(attrSymbol.name, attrSymbol);
bLangXMLAttribute.symbol = attrSymbol;
}
return;
}
List<BLangExpression> exprs = bLangXMLAttribute.value.textFragments;
String nsURI = null;
// TODO: find a better way to get the statically defined URI.
if (exprs.size() == 1 && exprs.get(0).getKind() == NodeKind.LITERAL) {
nsURI = (String) ((BLangLiteral) exprs.get(0)).value;
}
String symbolName = qname.localname.value;
if (symbolName.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
symbolName = XMLConstants.DEFAULT_NS_PREFIX;
}
BXMLNSSymbol xmlnsSymbol = new BXMLNSSymbol(names.fromString(symbolName), nsURI, env.enclPkg.symbol.pkgID, env.scope.owner);
if (symResolver.checkForUniqueMemberSymbol(bLangXMLAttribute.pos, env, xmlnsSymbol)) {
env.scope.define(xmlnsSymbol.name, xmlnsSymbol);
bLangXMLAttribute.symbol = xmlnsSymbol;
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangXMLAttribute xmlAttribute) {
SymbolEnv xmlAttributeEnv = SymbolEnv.getXMLAttributeEnv(xmlAttribute, env);
xmlAttribute.name.accept(this);
boolean attrNameTainedStatus = getObservedTaintedStatus();
xmlAttribute.value.accept(this);
boolean attrValueTainedStatus = getObservedTaintedStatus();
setTaintedStatusList(attrNameTainedStatus || attrValueTainedStatus);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangXMLElementLiteral xmlElementLiteral) {
SymbolEnv xmlElementEnv = SymbolEnv.getXMLElementEnv(xmlElementLiteral, env);
// Visit in-line namespace declarations
boolean inLineNamespaceTainted = false;
for (BLangXMLAttribute attribute : xmlElementLiteral.attributes) {
if (attribute.name.getKind() == NodeKind.XML_QNAME && ((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
attribute.accept(this);
attribute.symbol.tainted = getObservedTaintedStatus();
if (attribute.symbol.tainted) {
inLineNamespaceTainted = true;
}
}
}
// Visit attributes.
boolean attributesTainted = false;
for (BLangXMLAttribute attribute : xmlElementLiteral.attributes) {
if (attribute.name.getKind() == NodeKind.XML_QNAME && !((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
attribute.accept(this);
attribute.symbol.tainted = getObservedTaintedStatus();
if (attribute.symbol.tainted) {
attributesTainted = true;
}
}
}
// Visit the tag names
xmlElementLiteral.startTagName.accept(this);
boolean startTagTaintedStatus = getObservedTaintedStatus();
boolean endTagTaintedStatus = false;
if (xmlElementLiteral.endTagName != null) {
xmlElementLiteral.endTagName.accept(this);
endTagTaintedStatus = getObservedTaintedStatus();
}
boolean tagNamesTainted = startTagTaintedStatus || endTagTaintedStatus;
// Visit the children
boolean childrenTainted = false;
for (BLangExpression expr : xmlElementLiteral.children) {
expr.accept(this);
if (getObservedTaintedStatus()) {
childrenTainted = true;
}
}
setTaintedStatusList(inLineNamespaceTainted || attributesTainted || tagNamesTainted || childrenTainted);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute 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.tree.expressions.BLangXMLAttribute 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