public virtual void VisitImplicitLiteralConversionExpression(ImplicitLiteralConversionExpression implicitLiteralConversionExpression, A args) { VisitExpression(implicitLiteralConversionExpression.Expression, args); }
/// <summary> /// Create an implicit conversion if allowed and needed /// </summary> private void InsertImplicitConversionIfNeeded( ref ExpressionSyntax expression, DataType targetType) { switch (expression.Type) { case SizedIntegerType expressionType: { switch (targetType) { case SizedIntegerType expectedType: if (expectedType.Bits > expressionType.Bits && (!expressionType.IsSigned || expectedType.IsSigned)) { expression = new ImplicitNumericConversionExpression(expression, expectedType); } break; case FloatingPointType expectedType: if (expressionType.Bits < expectedType.Bits) { expression = new ImplicitNumericConversionExpression(expression, expectedType); } break; } } break; case FloatingPointType expressionType: { if (targetType is FloatingPointType expectedType && expressionType.Bits < expectedType.Bits) { expression = new ImplicitNumericConversionExpression(expression, expectedType); } } break; case IntegerConstantType expressionType: switch (targetType) { case SizedIntegerType expectedType: var bits = expressionType.Value.GetByteCount() * 8; var requireSigned = expressionType.Value < 0; if (expectedType.Bits >= bits && (!requireSigned || expectedType.IsSigned)) { expression = new ImplicitNumericConversionExpression(expression, expectedType); } break; case FloatingPointType expectedType: throw new NotImplementedException(); } break; case StringConstantType _: { if (targetType is ObjectType objectType) { var conversionOperators = objectType.Symbol.Lookup(SpecialName.OperatorStringLiteral); if (conversionOperators.Count == 1) // TODO actually check we can call it { expression = new ImplicitLiteralConversionExpression(expression, objectType, conversionOperators.Single()); } // TODO if there is more than one } } break; } // No conversion }