use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol 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);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol in project ballerina by ballerina-lang.
the class Symbols method createConversionOperatorSymbol.
public static BConversionOperatorSymbol createConversionOperatorSymbol(final BType sourceType, final BType targetType, final BType errorType, boolean implicit, boolean safe, int opcode, PackageID pkgID, BSymbol owner) {
List<BType> paramTypes = Lists.of(sourceType, targetType);
List<BType> retTypes = new ArrayList<>(1);
if (safe) {
retTypes.add(targetType);
} else if (targetType.tag == TypeTags.UNION && targetType instanceof BUnionType) {
BUnionType unionType = (BUnionType) targetType;
unionType.memberTypes.add(errorType);
retTypes.add(unionType);
} else {
Set<BType> memberTypes = new HashSet<>(2);
memberTypes.add(targetType);
memberTypes.add(errorType);
BUnionType unionType = new BUnionType(null, memberTypes, false);
retTypes.add(unionType);
}
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
BConversionOperatorSymbol symbol = new BConversionOperatorSymbol(pkgID, opType, owner, implicit, safe, opcode);
symbol.kind = SymbolKind.CONVERSION_OPERATOR;
return symbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol in project ballerina by ballerina-lang.
the class ASTBuilderUtil method generateConversionExpr.
static BLangExpression generateConversionExpr(BLangExpression varRef, BType target, SymbolResolver symResolver) {
if (varRef.type.tag == target.tag || varRef.type.tag > TypeTags.TYPEDESC) {
return varRef;
}
// Box value using cast expression.
final BLangTypeConversionExpr conversion = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
conversion.pos = varRef.pos;
conversion.expr = varRef;
conversion.type = target;
conversion.targetType = target;
conversion.conversionSymbol = (BConversionOperatorSymbol) symResolver.resolveConversionOperator(varRef.type, target);
return conversion;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangTypeConversionExpr conversionExpr) {
conversionExpr.expr = rewriteExpr(conversionExpr.expr);
// Built-in conversion
if (conversionExpr.conversionSymbol.tag != SymTag.TRANSFORMER) {
result = conversionExpr;
return;
}
// Named transformer invocation
BLangInvocation transformerInvoc = conversionExpr.transformerInvocation;
if (transformerInvoc != null) {
transformerInvoc = rewriteExpr(transformerInvoc);
// Add the rExpr as the first argument
conversionExpr.transformerInvocation.requiredArgs.add(0, conversionExpr.expr);
result = new BLangTransformerInvocation(conversionExpr.pos, transformerInvoc.requiredArgs, transformerInvoc.namedArgs, transformerInvoc.restArgs, transformerInvoc.symbol, conversionExpr.types);
conversionExpr.transformerInvocation = transformerInvoc;
return;
}
// Unnamed transformer invocation
BConversionOperatorSymbol transformerSym = conversionExpr.conversionSymbol;
transformerInvoc = new BLangTransformerInvocation(conversionExpr.pos, Lists.of(conversionExpr.expr), transformerSym, conversionExpr.types);
transformerInvoc.types = transformerSym.type.getReturnTypes();
result = transformerInvoc;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol in project ballerina by ballerina-lang.
the class Desugar method createTypeConversionExpr.
private BLangExpression createTypeConversionExpr(BLangExpression expr, BType sourceType, BType targetType) {
BConversionOperatorSymbol symbol = (BConversionOperatorSymbol) symResolver.resolveConversionOperator(sourceType, targetType);
BLangTypeConversionExpr conversionExpr = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
conversionExpr.pos = expr.pos;
conversionExpr.expr = expr;
conversionExpr.type = targetType;
conversionExpr.conversionSymbol = symbol;
return conversionExpr;
}
Aggregations