Search in sources :

Example 1 with BTransformerSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

@Override
public void visit(BLangTransformer transformerNode) {
    validateTransformerMappingTypes(transformerNode);
    boolean safeConversion = transformerNode.retParams.size() == 1;
    Name name = getTransformerSymbolName(transformerNode);
    BTransformerSymbol transformerSymbol = Symbols.createTransformerSymbol(Flags.asMask(transformerNode.flagSet), name, env.enclPkg.symbol.pkgID, null, safeConversion, env.scope.owner);
    transformerNode.symbol = transformerSymbol;
    // If this is a default transformer, check whether this transformer conflicts with a built-in conversion
    if (transformerNode.name.value.isEmpty()) {
        BType targetType = transformerNode.retParams.get(0).type;
        BSymbol symbol = symResolver.resolveConversionOperator(transformerNode.source.type, targetType);
        if (symbol != symTable.notFoundSymbol) {
            dlog.error(transformerNode.pos, DiagnosticCode.TRANSFORMER_CONFLICTS_WITH_CONVERSION, transformerNode.source.type, targetType);
            return;
        }
    }
    // Define the transformer
    SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerSymbol.scope, env);
    transformerNode.symbol = transformerSymbol;
    defineSymbol(transformerNode.pos, transformerSymbol);
    transformerEnv.scope = transformerSymbol.scope;
    // Define transformer source.
    defineNode(transformerNode.source, transformerEnv);
}
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) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 2 with BTransformerSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol 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 3 with BTransformerSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol in project ballerina by ballerina-lang.

the class Symbols method createTransformerSymbol.

public static BTransformerSymbol createTransformerSymbol(int flags, Name name, PackageID pkgID, BType type, boolean safe, BSymbol owner) {
    BTransformerSymbol symbol = new BTransformerSymbol(name, pkgID, type, owner, safe);
    symbol.kind = SymbolKind.TRANSFORMER;
    symbol.scope = new Scope(symbol);
    return symbol;
}
Also used : Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope)

Aggregations

BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)2 BTransformerSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol)2 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)1 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)1 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)1 Name (org.wso2.ballerinalang.compiler.util.Name)1