Search in sources :

Example 26 with BType

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

the class SemanticAnalyzer method analyzeNode.

BType analyzeNode(BLangNode node, SymbolEnv env, BType expType, DiagnosticCode diagCode) {
    SymbolEnv prevEnv = this.env;
    BType preExpType = this.expType;
    DiagnosticCode preDiagCode = this.diagCode;
    // TODO Check the possibility of using a try/finally here
    this.env = env;
    this.expType = expType;
    this.diagCode = diagCode;
    node.accept(this);
    this.env = prevEnv;
    this.expType = preExpType;
    this.diagCode = preDiagCode;
    return resType;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode)

Example 27 with BType

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

the class SemanticAnalyzer method visit.

@Override
public void visit(BLangEndpoint endpointNode) {
    endpointNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.ENDPOINT);
        this.analyzeDef(annotationAttachment, env);
    });
    if (endpointNode.configurationExpr == null) {
        return;
    }
    BType configType = symTable.errType;
    if (endpointNode.symbol != null && endpointNode.symbol.type.tag == TypeTags.STRUCT) {
        if (endpointNode.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
            // Init expression.
            configType = endpointSPIAnalyzer.getEndpointConfigType((BStructSymbol) endpointNode.symbol.type.tsymbol);
        } else {
            // assign Expression.
            configType = endpointNode.symbol.type;
        }
    }
    this.typeChecker.checkExpr(endpointNode.configurationExpr, env, Lists.of(configType));
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)

Example 28 with BType

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

the class SemanticAnalyzer method handleServiceTypeStruct.

private void handleServiceTypeStruct(BLangService serviceNode) {
    if (serviceNode.serviceTypeStruct != null) {
        final BType serviceStructType = symResolver.resolveTypeNode(serviceNode.serviceTypeStruct, env);
        serviceNode.endpointType = endpointSPIAnalyzer.getEndpointTypeFromServiceType(serviceNode.serviceTypeStruct.pos, serviceStructType);
        if (serviceNode.endpointType != null) {
            serviceNode.endpointClientType = endpointSPIAnalyzer.getClientType((BStructSymbol) serviceNode.endpointType.tsymbol);
        }
    }
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)

Example 29 with BType

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

the class SemanticAnalyzer method visit.

public void visit(BLangAssignment assignNode) {
    if (assignNode.isDeclaredWithVar()) {
        handleAssignNodeWithVar(assignNode);
        return;
    }
    // Check each LHS expression.
    List<BType> expTypes = new ArrayList<>();
    for (BLangExpression expr : assignNode.varRefs) {
        // In assignment, lhs supports only simpleVarRef, indexBasedAccess, filedBasedAccess expressions.
        if (expr.getKind() != NodeKind.SIMPLE_VARIABLE_REF && expr.getKind() != NodeKind.INDEX_BASED_ACCESS_EXPR && expr.getKind() != NodeKind.FIELD_BASED_ACCESS_EXPR && expr.getKind() != NodeKind.XML_ATTRIBUTE_ACCESS_EXPR) {
            dlog.error(expr.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, expr);
            expTypes.add(symTable.errType);
            continue;
        }
        // Evaluate the variable reference expression.
        BLangVariableReference varRef = (BLangVariableReference) expr;
        varRef.lhsVar = true;
        typeChecker.checkExpr(varRef, env);
        // Check whether we've got an enumerator access expression here.
        if (varRef.getKind() == NodeKind.FIELD_BASED_ACCESS_EXPR && ((BLangFieldBasedAccess) varRef).expr.type.tag == TypeTags.ENUM) {
            dlog.error(varRef.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, varRef);
            expTypes.add(symTable.errType);
            continue;
        }
        expTypes.add(varRef.type);
        checkConstantAssignment(varRef);
    }
    if (assignNode.getKind() == NodeKind.TUPLE_DESTRUCTURE) {
        BTupleType tupleType = new BTupleType(expTypes);
        expTypes = Lists.of(tupleType);
    }
    if (!assignNode.safeAssignment) {
        typeChecker.checkExpr(assignNode.expr, this.env, expTypes);
        return;
    }
    // Assume that there is only one variable reference in LHS
    // Continue the validate if this is a safe assignment operator
    handleSafeAssignment(assignNode.pos, assignNode.varRefs.get(0).type, assignNode.expr, this.env);
}
Also used : BLangFieldBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) ArrayList(java.util.ArrayList) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 30 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(BLangTypeConversionExpr conversionExpr) {
    // Set error type as the actual type.
    // List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
    List<BType> actualTypes;
    BType targetType = symResolver.resolveTypeNode(conversionExpr.typeNode, env);
    conversionExpr.targetType = targetType;
    BType sourceType = checkExpr(conversionExpr.expr, env, Lists.of(symTable.noType)).get(0);
    if (conversionExpr.transformerInvocation == null) {
        // Lookup for built-in type conversion operator symbol
        BSymbol symbol = symResolver.resolveConversionOperator(sourceType, targetType);
        if (symbol == symTable.notFoundSymbol) {
            // If not found, look for unnamed transformers for the given types
            actualTypes = checkUnNamedTransformerInvocation(conversionExpr, sourceType, targetType);
        } else {
            BConversionOperatorSymbol conversionSym = (BConversionOperatorSymbol) symbol;
            conversionExpr.conversionSymbol = conversionSym;
            actualTypes = getActualTypesOfConversionExpr(conversionExpr, targetType, sourceType, conversionSym);
        }
    } else {
        actualTypes = checkNamedTransformerInvocation(conversionExpr, sourceType, targetType);
    }
    resultTypes = types.checkTypes(conversionExpr, actualTypes, expTypes);
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol)

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