Search in sources :

Example 16 with BInvokableType

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

the class TypeChecker method checkNamedTransformerInvocation.

private List<BType> checkNamedTransformerInvocation(BLangTypeConversionExpr conversionExpr, BType sourceType, BType targetType) {
    List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
    BLangInvocation transformerInvocation = conversionExpr.transformerInvocation;
    BSymbol transformerSymbol = symResolver.lookupSymbolInPackage(transformerInvocation.pos, env, names.fromIdNode(transformerInvocation.pkgAlias), names.fromIdNode(transformerInvocation.name), SymTag.TRANSFORMER);
    if (transformerSymbol == symTable.notFoundSymbol) {
        dlog.error(conversionExpr.pos, DiagnosticCode.UNDEFINED_TRANSFORMER, transformerInvocation.name);
    } else {
        conversionExpr.conversionSymbol = (BConversionOperatorSymbol) (transformerInvocation.symbol = transformerSymbol);
        // Check the transformer invocation. Expected type for the transformer is the target type
        // of the cast conversion operator, but not the lhs type.
        List<BType> prevExpType = expTypes;
        expTypes = Lists.of(targetType);
        checkInvocationParamAndReturnType(transformerInvocation);
        expTypes = prevExpType;
        if (transformerInvocation.type != symTable.errType) {
            BInvokableType transformerSymType = (BInvokableType) transformerSymbol.type;
            transformerInvocation.types = transformerSymType.retTypes;
            actualTypes = getActualTypesOfConversionExpr(conversionExpr, targetType, sourceType, conversionExpr.conversionSymbol);
        }
    }
    return actualTypes;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)

Example 17 with BInvokableType

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

the class TypeChecker method checkUnNamedTransformerInvocation.

private List<BType> checkUnNamedTransformerInvocation(BLangTypeConversionExpr conversionExpr, BType sourceType, BType targetType) {
    List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
    // Check whether a transformer is available for the two types
    BSymbol symbol = symResolver.resolveTransformer(env, sourceType, targetType);
    if (symbol == symTable.notFoundSymbol) {
        // check whether a casting is possible, to provide user a hint.
        BSymbol castSymbol = symResolver.resolveConversionOperator(sourceType, targetType);
        if (castSymbol == symTable.notFoundSymbol) {
            dlog.error(conversionExpr.pos, DiagnosticCode.INCOMPATIBLE_TYPES_CONVERSION, sourceType, targetType);
        } else {
            dlog.error(conversionExpr.pos, DiagnosticCode.INCOMPATIBLE_TYPES_CONVERSION_WITH_SUGGESTION, sourceType, targetType);
        }
    } else {
        BTransformerSymbol transformerSymbol = (BTransformerSymbol) symbol;
        conversionExpr.conversionSymbol = transformerSymbol;
        if (conversionExpr.conversionSymbol.safe) {
            ((BInvokableType) transformerSymbol.type).retTypes.add(symTable.errStructType);
        }
        actualTypes = getActualTypesOfConversionExpr(conversionExpr, targetType, sourceType, transformerSymbol);
    }
    return actualTypes;
}
Also used : BTransformerSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 18 with BInvokableType

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

the class SymbolTable method defineOperator.

private void defineOperator(Name name, List<BType> paramTypes, List<BType> retTypes, int opcode) {
    BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
    BOperatorSymbol symbol = new BOperatorSymbol(name, rootPkgSymbol.pkgID, opType, rootPkgSymbol, opcode);
    rootScope.define(name, symbol);
}
Also used : BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol)

Example 19 with BInvokableType

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

the class SymbolTable method defineConversionOperator.

private void defineConversionOperator(BType sourceType, BType targetType, boolean implicit, boolean safe, int opcode) {
    List<BType> paramTypes = Lists.of(sourceType, targetType);
    List<BType> retTypes = new ArrayList<>(1);
    if (safe) {
        retTypes.add(targetType);
    } else {
        if (targetType.tag == TypeTags.UNION) {
            BUnionType unionType = (BUnionType) targetType;
            unionType.memberTypes.add(this.errStructType);
            retTypes.add(targetType);
        } else {
            BUnionType unionType = new BUnionType(null, new HashSet<BType>(2) {

                {
                    add(targetType);
                    add(errStructType);
                }
            }, false);
            retTypes.add(unionType);
        }
    }
    BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
    BConversionOperatorSymbol symbol = new BConversionOperatorSymbol(this.rootPkgSymbol.pkgID, opType, this.rootPkgSymbol, implicit, safe, opcode);
    symbol.kind = SymbolKind.CONVERSION_OPERATOR;
    rootScope.define(symbol.name, symbol);
}
Also used : BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol)

Example 20 with BInvokableType

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

the class Symbols method createTypeofOperatorSymbol.

public static BOperatorSymbol createTypeofOperatorSymbol(BType exprType, Types types, SymbolTable symTable, Names names) {
    List<BType> paramTypes = Lists.of(exprType);
    List<BType> retTypes = Lists.of(symTable.typeDesc);
    BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
    if (types.isValueType(exprType)) {
        return new BOperatorSymbol(names.fromString(OperatorKind.TYPEOF.value()), symTable.rootPkgSymbol.pkgID, opType, symTable.rootPkgSymbol, InstructionCodes.TYPELOAD);
    } else {
        return new BOperatorSymbol(names.fromString(OperatorKind.TYPEOF.value()), symTable.rootPkgSymbol.pkgID, opType, symTable.rootPkgSymbol, InstructionCodes.TYPEOF);
    }
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)

Aggregations

BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)24 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)17 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)12 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)6 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)6 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)6 ArrayList (java.util.ArrayList)5 BEndpointVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol)4 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 SymbolTable (org.wso2.ballerinalang.compiler.semantics.model.SymbolTable)3 BOperatorSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol)3 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)3 BAttachedFunction (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction)3 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)3 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)3 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2