Search in sources :

Example 1 with LiteralConversion

use of dyvilx.tools.compiler.ast.expression.LiteralConversion in project Dyvil by Dyvil.

the class TypeChecker method convertValueDirect.

private static IValue convertValueDirect(IValue value, IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    final IValue typedValue = value.withType(type, typeContext, markers, context);
    if (typedValue != null) {
        return typedValue;
    }
    final IValue converted1 = type.convertFrom(value, value.getType(), typeContext, markers, context);
    if (converted1 != null) {
        return converted1;
    }
    final IValue converted2 = value.getType().convertTo(value, type, typeContext, markers, context);
    if (converted2 != null) {
        return converted2;
    }
    final IMethod converter = IContext.resolveImplicits(context, value, type).getBestMember();
    if (converter == null) {
        return null;
    }
    return new LiteralConversion(value, converter);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) LiteralConversion(dyvilx.tools.compiler.ast.expression.LiteralConversion) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Aggregations

IValue (dyvilx.tools.compiler.ast.expression.IValue)1 LiteralConversion (dyvilx.tools.compiler.ast.expression.LiteralConversion)1 IMethod (dyvilx.tools.compiler.ast.method.IMethod)1