use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol 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.semantics.model.symbols.BXMLNSSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangXMLNS xmlnsNode) {
String nsURI = (String) ((BLangLiteral) xmlnsNode.namespaceURI).value;
if (xmlnsNode.prefix.value != null && nsURI.isEmpty()) {
dlog.error(xmlnsNode.pos, DiagnosticCode.INVALID_NAMESPACE_DECLARATION, xmlnsNode.prefix);
}
// set the prefix of the default namespace
if (xmlnsNode.prefix.value == null) {
xmlnsNode.prefix.value = XMLConstants.DEFAULT_NS_PREFIX;
}
BXMLNSSymbol xmlnsSymbol = Symbols.createXMLNSSymbol(names.fromIdNode(xmlnsNode.prefix), nsURI, env.enclPkg.symbol.pkgID, env.scope.owner);
xmlnsNode.symbol = xmlnsSymbol;
// First check for package-imports with the same alias.
// Here we do not check for owner equality, since package import is always at the package
// level, but the namespace declaration can be at any level.
BSymbol foundSym = symResolver.lookupSymbol(env, xmlnsSymbol.name, SymTag.PACKAGE);
if (foundSym != symTable.notFoundSymbol) {
dlog.error(xmlnsNode.pos, DiagnosticCode.REDECLARED_SYMBOL, xmlnsSymbol.name);
return;
}
// Define it in the enclosing scope. Here we check for the owner equality,
// to support overriding of namespace declarations defined at package level.
defineSymbol(xmlnsNode.pos, xmlnsSymbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol in project ballerina by ballerina-lang.
the class SymbolResolver method addNamespacesInScope.
private void addNamespacesInScope(Map<Name, BXMLNSSymbol> namespaces, SymbolEnv env) {
if (env == null) {
return;
}
env.scope.entries.forEach((name, scopeEntry) -> {
if (scopeEntry.symbol.kind == SymbolKind.XMLNS) {
BXMLNSSymbol nsSymbol = (BXMLNSSymbol) scopeEntry.symbol;
// Skip if the namespace is already added, by a child scope. That means it has been overridden.
if (!namespaces.containsKey(name)) {
namespaces.put(name, nsSymbol);
}
}
});
addNamespacesInScope(namespaces, env.enclEnv);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol 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.semantics.model.symbols.BXMLNSSymbol in project ballerina by ballerina-lang.
the class CodeGenerator method getNamespaceURIIndex.
private RegIndex getNamespaceURIIndex(BXMLNSSymbol namespaceSymbol, SymbolEnv env) {
if (namespaceSymbol == null && env.node.getKind() == NodeKind.XML_ATTRIBUTE) {
return createStringLiteral(XMLConstants.NULL_NS_URI, null, env);
}
if (namespaceSymbol == null) {
return createStringLiteral(null, null, env);
}
// Otherwise get the URI index in the global var registry.
if ((namespaceSymbol.owner.tag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
return (RegIndex) namespaceSymbol.nsURIIndex;
}
RegIndex index = getRegIndex(TypeTags.STRING);
emit(InstructionCodes.SGLOAD, namespaceSymbol.nsURIIndex, index);
return index;
}
Aggregations