Search in sources :

Example 36 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.

the class TypeChecker method visit.

public void visit(BLangTypeofExpr accessExpr) {
    BType actualType = symTable.typeDesc;
    accessExpr.resolvedType = symResolver.resolveTypeNode(accessExpr.typeNode, env);
    resultTypes = types.checkTypes(accessExpr, Lists.of(actualType), expTypes);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 37 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.

the class TypeChecker method checkInvocationArgs.

private List<BType> checkInvocationArgs(BLangInvocation iExpr, List<BType> paramTypes, int requiredParamsCount, BLangExpression vararg) {
    List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
    BInvokableSymbol invocableSymbol = (BInvokableSymbol) iExpr.symbol;
    // Check whether the expected param count and the actual args counts are matching.
    if (requiredParamsCount > iExpr.requiredArgs.size()) {
        dlog.error(iExpr.pos, DiagnosticCode.NOT_ENOUGH_ARGS_FUNC_CALL, iExpr.name.value);
        return actualTypes;
    } else if (invocableSymbol.restParam == null && (vararg != null || !iExpr.restArgs.isEmpty())) {
        dlog.error(iExpr.pos, DiagnosticCode.TOO_MANY_ARGS_FUNC_CALL, iExpr.name.value);
        return actualTypes;
    }
    // formal parameters of the outer function.
    if (iExpr.argExprs.size() == 1 && iExpr.argExprs.get(0).getKind() == NodeKind.INVOCATION) {
        checkExpr(iExpr.requiredArgs.get(0), this.env, ((BInvokableType) invocableSymbol.type).paramTypes);
    } else {
        checkRequiredArgs(iExpr.requiredArgs, paramTypes);
    }
    checkNamedArgs(iExpr.namedArgs, invocableSymbol.defaultableParams);
    checkRestArgs(iExpr.restArgs, vararg, invocableSymbol.restParam);
    if (iExpr.async) {
        return Arrays.asList(this.generateFutureType(invocableSymbol));
    } else {
        return invocableSymbol.type.getReturnTypes();
    }
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)

Example 38 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.

the class TypeChecker method setExprType.

private void setExprType(BLangExpression expr, List<BType> expTypes) {
    int expected = expTypes.size();
    if (expr instanceof MultiReturnExpr) {
        MultiReturnExpr multiReturnExpr = (MultiReturnExpr) expr;
        multiReturnExpr.setTypes(resultTypes);
    } else {
        if (expected > 1) {
            dlog.error(expr.pos, DiagnosticCode.ASSIGNMENT_COUNT_MISMATCH, expected, 1);
            resultTypes = getListWithErrorTypes(expected);
        }
    }
    if (resultTypes.size() > 0) {
        expr.type = resultTypes.get(0);
    }
}
Also used : MultiReturnExpr(org.wso2.ballerinalang.compiler.tree.expressions.MultiReturnExpr)

Example 39 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.

the class TypeChecker method visit.

public void visit(BLangTernaryExpr ternaryExpr) {
    BType expType = checkExpr(ternaryExpr.expr, env, Lists.of(this.symTable.booleanType)).get(0);
    BType thenType = checkExpr(ternaryExpr.thenExpr, env, expTypes).get(0);
    BType elseType = checkExpr(ternaryExpr.elseExpr, env, expTypes).get(0);
    if (expType == symTable.errType || thenType == symTable.errType || elseType == symTable.errType) {
        resultTypes = Lists.of(symTable.errType);
    } else if (expTypes.get(0) == symTable.noType) {
        if (thenType == elseType) {
            resultTypes = Lists.of(thenType);
        } else {
            dlog.error(ternaryExpr.pos, DiagnosticCode.INCOMPATIBLE_TYPES, thenType, elseType);
            resultTypes = Lists.of(symTable.errType);
        }
    } else {
        resultTypes = expTypes;
    }
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 40 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType 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);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Aggregations

BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)97 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)34 ArrayList (java.util.ArrayList)30 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)30 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)25 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)23 Name (org.wso2.ballerinalang.compiler.util.Name)20 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)18 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)17 BArrayType (org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType)17 BUnionType (org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType)17 List (java.util.List)16 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)16 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)16 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)15 Collectors (java.util.stream.Collectors)14 BConversionOperatorSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol)13 BStructType (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType)13 Set (java.util.Set)12 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)12