use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv 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.SymbolEnv in project ballerina by ballerina-lang.
the class TypeChecker method concatSimilarKindXMLNodes.
/**
* Concatenate the consecutive text type nodes, and get the reduced set of children.
*
* @param exprs Child nodes
* @param xmlElementEnv
* @return Reduced set of children
*/
private List<BLangExpression> concatSimilarKindXMLNodes(List<BLangExpression> exprs, SymbolEnv xmlElementEnv) {
List<BLangExpression> newChildren = new ArrayList<BLangExpression>();
BLangExpression strConcatExpr = null;
for (BLangExpression expr : exprs) {
BType exprType = checkExpr((BLangExpression) expr, xmlElementEnv).get(0);
if (exprType == symTable.xmlType) {
if (strConcatExpr != null) {
newChildren.add(getXMLTextLiteral(strConcatExpr));
strConcatExpr = null;
}
newChildren.add(expr);
continue;
}
BSymbol opSymbol = symResolver.resolveBinaryOperator(OperatorKind.ADD, symTable.stringType, exprType);
if (opSymbol == symTable.notFoundSymbol && exprType != symTable.errType) {
dlog.error(expr.pos, DiagnosticCode.INCOMPATIBLE_TYPES, symTable.xmlType, exprType);
}
if (strConcatExpr == null) {
strConcatExpr = expr;
continue;
}
strConcatExpr = getBinaryAddExpr(strConcatExpr, expr, opSymbol);
}
// Add remaining concatenated text nodes as children
if (strConcatExpr != null) {
newChildren.add(getXMLTextLiteral(strConcatExpr));
}
return newChildren;
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class CodeGenerator method visitForkJoinParameterDefs.
private void visitForkJoinParameterDefs(BLangVariable parameterDef, SymbolEnv forkJoinEnv) {
LocalVariableAttributeInfo localVariableAttributeInfo = new LocalVariableAttributeInfo(1);
parameterDef.symbol.varIndex = getLVIndex(parameterDef.type.tag);
this.genNode(parameterDef, forkJoinEnv);
LocalVariableInfo localVariableDetails = this.getLocalVarAttributeInfo(parameterDef.symbol);
localVariableAttributeInfo.localVars.add(localVariableDetails);
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class CodeGenerator method genPackage.
private void genPackage(BPackageSymbol pkgSymbol) {
// TODO First check whether this symbol is from a BALO file.
SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgSymbol);
genNode(pkgEnv.node, pkgEnv);
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv 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