use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol in project ballerina by ballerina-lang.
the class SymbolResolver method resolveImplicitConversionOp.
public BSymbol resolveImplicitConversionOp(BType sourceType, BType targetType) {
BSymbol symbol = resolveOperator(Names.CONVERSION_OP, Lists.of(sourceType, targetType));
if (symbol == symTable.notFoundSymbol) {
return symbol;
}
BConversionOperatorSymbol castSymbol = (BConversionOperatorSymbol) symbol;
if (castSymbol.implicit) {
return symbol;
}
return symTable.notFoundSymbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol 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;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol in project ballerina by ballerina-lang.
the class Types method setImplicitCastExpr.
public void setImplicitCastExpr(BLangExpression expr, BType actualType, BType expType) {
BSymbol symbol = symResolver.resolveImplicitConversionOp(actualType, expType);
if (expType.tag == TypeTags.UNION && isValueType(actualType)) {
symbol = symResolver.resolveImplicitConversionOp(actualType, symTable.anyType);
}
if (symbol == symTable.notFoundSymbol) {
return;
}
BConversionOperatorSymbol conversionSym = (BConversionOperatorSymbol) symbol;
BLangTypeConversionExpr implicitConversionExpr = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
implicitConversionExpr.pos = expr.pos;
implicitConversionExpr.expr = expr.impConversionExpr == null ? expr : expr.impConversionExpr;
implicitConversionExpr.type = expType;
implicitConversionExpr.targetType = expType;
implicitConversionExpr.conversionSymbol = conversionSym;
expr.impConversionExpr = implicitConversionExpr;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol 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);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol in project ballerina by ballerina-lang.
the class Symbols method createUnboxValueTypeOpSymbol.
public static BConversionOperatorSymbol createUnboxValueTypeOpSymbol(BType sourceType, BType targetType) {
int opcode;
switch(targetType.tag) {
case TypeTags.INT:
opcode = InstructionCodes.ANY2I;
break;
case TypeTags.FLOAT:
opcode = InstructionCodes.ANY2F;
break;
case TypeTags.STRING:
opcode = InstructionCodes.ANY2S;
break;
case TypeTags.BOOLEAN:
opcode = InstructionCodes.ANY2B;
break;
default:
opcode = InstructionCodes.ANY2L;
break;
}
List<BType> paramTypes = Lists.of(sourceType, targetType);
List<BType> retTypes = Lists.of(targetType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
BConversionOperatorSymbol symbol = new BConversionOperatorSymbol(null, opType, null, false, true, opcode);
symbol.kind = SymbolKind.CONVERSION_OPERATOR;
return symbol;
}
Aggregations