Search in sources :

Example 51 with SymbolEnv

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)));
}
Also used : BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 52 with SymbolEnv

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;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 53 with SymbolEnv

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);
}
Also used : LocalVariableInfo(org.wso2.ballerinalang.programfile.LocalVariableInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo)

Example 54 with SymbolEnv

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);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 55 with SymbolEnv

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;
}
Also used : RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)125 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)47 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)30 Name (org.wso2.ballerinalang.compiler.util.Name)26 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)25 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)25 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)24 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)22 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)20 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)20 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)20 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)19 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)18 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)18 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)17 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)17 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)17 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)17 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)17