use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName 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.BLangXMLQName 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.BLangXMLQName in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangXMLElementLiteral bLangXMLElementLiteral) {
SymbolEnv xmlElementEnv = SymbolEnv.getXMLElementEnv(bLangXMLElementLiteral, env);
// Visit in-line namespace declarations
bLangXMLElementLiteral.attributes.forEach(attribute -> {
if (attribute.name.getKind() == NodeKind.XML_QNAME && ((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
checkExpr((BLangExpression) attribute, xmlElementEnv, Lists.of(symTable.noType));
}
});
// Visit attributes.
bLangXMLElementLiteral.attributes.forEach(attribute -> {
if (attribute.name.getKind() != NodeKind.XML_QNAME || !((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
checkExpr((BLangExpression) attribute, xmlElementEnv, Lists.of(symTable.noType));
}
});
Map<Name, BXMLNSSymbol> namespaces = symResolver.resolveAllNamespaces(xmlElementEnv);
Name defaultNs = names.fromString(XMLConstants.DEFAULT_NS_PREFIX);
if (namespaces.containsKey(defaultNs)) {
bLangXMLElementLiteral.defaultNsSymbol = namespaces.remove(defaultNs);
}
bLangXMLElementLiteral.namespacesInScope.putAll(namespaces);
// Visit the tag names
validateTags(bLangXMLElementLiteral, xmlElementEnv);
// Visit the children
bLangXMLElementLiteral.modifiedChildren = concatSimilarKindXMLNodes(bLangXMLElementLiteral.children, xmlElementEnv);
resultTypes = Lists.of(types.checkType(bLangXMLElementLiteral, symTable.xmlType, expTypes.get(0)));
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName 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.BLangXMLQName in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangSimpleVarRef varRefExpr) {
BLangSimpleVarRef genVarRefExpr = varRefExpr;
// XML qualified name reference. e.g: ns0:foo
if (varRefExpr.pkgSymbol != null && varRefExpr.pkgSymbol.tag == SymTag.XMLNS) {
BLangXMLQName qnameExpr = new BLangXMLQName(varRefExpr.variableName);
qnameExpr.nsSymbol = (BXMLNSSymbol) varRefExpr.pkgSymbol;
qnameExpr.localname = varRefExpr.variableName;
qnameExpr.prefix = varRefExpr.pkgAlias;
qnameExpr.namespaceURI = qnameExpr.nsSymbol.namespaceURI;
qnameExpr.isUsedInXML = false;
qnameExpr.pos = varRefExpr.pos;
qnameExpr.type = symTable.stringType;
result = qnameExpr;
return;
}
BSymbol ownerSymbol = varRefExpr.symbol.owner;
if ((varRefExpr.symbol.tag & SymTag.FUNCTION) == SymTag.FUNCTION && varRefExpr.symbol.type.tag == TypeTags.INVOKABLE) {
genVarRefExpr = new BLangFunctionVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
// Local variable in a function/resource/action/worker
genVarRefExpr = new BLangLocalVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.CONNECTOR) == SymTag.CONNECTOR) {
// Field variable in a receiver
genVarRefExpr = new BLangFieldVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.STRUCT) == SymTag.STRUCT) {
genVarRefExpr = new BLangFieldVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.PACKAGE) == SymTag.PACKAGE || (ownerSymbol.tag & SymTag.SERVICE) == SymTag.SERVICE) {
// Package variable | service variable
// We consider both of them as package level variables
genVarRefExpr = new BLangPackageVarRef(varRefExpr.symbol);
// Only locking service level and package level variables
if (!enclLocks.isEmpty()) {
enclLocks.peek().addLockVariable(varRefExpr.symbol);
}
}
genVarRefExpr.type = varRefExpr.type;
result = genVarRefExpr;
}
Aggregations