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);
}
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;
}
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;
}
Aggregations