Exemplo n.º 1
0
 /// <summary>
 /// Helper method that synthesizes a BoundConversion, unless the conversion would be an identity conversion.
 /// </summary>
 private static BoundExpression SynthesizeConversion(SyntaxNode syntax, BoundExpression operand, Conversion conversion, TypeSymbol type)
 {
     if (type == operand.Type)
     {
         Debug.Assert(conversion.Kind == ConversionKind.Identity);
         return(operand);
     }
     else
     {
         // TODO: when the ControlFlowRewriter is merged into the LocalRewriter, switch to LocalRewriter.MakeConversion.
         return(BoundConversion.Synthesized(syntax, operand, conversion, false, false, ConstantValue.NotAvailable, type));
     }
 }
Exemplo n.º 2
0
        internal static BoundExpression ConvertToLocalType(CSharpCompilation compilation, BoundExpression expr, TypeSymbol type)
        {
            HashSet <DiagnosticInfo> unusedUseSiteDiagnostics = null;
            var conversion = compilation.Conversions.ClassifyConversionFromExpression(expr, type, ref unusedUseSiteDiagnostics);

            Debug.Assert(conversion.IsValid);
            Debug.Assert(unusedUseSiteDiagnostics == null || unusedUseSiteDiagnostics.All(d => d.Severity < DiagnosticSeverity.Error));

            return(BoundConversion.Synthesized(
                       expr.Syntax,
                       expr,
                       conversion,
                       @checked: false,
                       explicitCastInCode: false,
                       constantValueOpt: null,
                       type: type));
        }
Exemplo n.º 3
0
        internal static BoundExpression ConvertToLocalType(CSharpCompilation compilation, BoundExpression expr, TypeSymbol type, DiagnosticBag diagnostics)
        {
            // NOTE: This conversion can fail if some of the types involved are from not-yet-loaded modules.
            // For example, if System.Exception hasn't been loaded, then this call will fail for $stowedexception.
            HashSet <DiagnosticInfo> useSiteDiagnostics = null;
            var conversion = compilation.Conversions.ClassifyConversionFromExpression(expr, type, ref useSiteDiagnostics);

            diagnostics.Add(expr.Syntax, useSiteDiagnostics);

            return(BoundConversion.Synthesized(
                       expr.Syntax,
                       expr,
                       conversion,
                       @checked: false,
                       explicitCastInCode: false,
                       constantValueOpt: null,
                       type: type,
                       hasErrors: !conversion.IsValid));
        }
        private static BoundExpression ConvertToLocalTypeHelper(CSharpCompilation compilation, BoundExpression expr, TypeSymbol type, BindingDiagnosticBag diagnostics)
        {
            Debug.Assert(diagnostics.DiagnosticBag != null);

            // NOTE: This conversion can fail if some of the types involved are from not-yet-loaded modules.
            // For example, if System.Exception hasn't been loaded, then this call will fail for $stowedexception.
            var useSiteInfo = new CompoundUseSiteInfo <AssemblySymbol>(diagnostics, compilation.Assembly);
            var conversion  = compilation.Conversions.ClassifyConversionFromExpression(expr, type, isChecked: false, ref useSiteInfo);

            diagnostics.Add(expr.Syntax, useSiteInfo);
            Debug.Assert(conversion.IsValid || diagnostics.HasAnyErrors());

            return(BoundConversion.Synthesized(
                       expr.Syntax,
                       expr,
                       conversion,
                       @checked: false,
                       explicitCastInCode: false,
                       conversionGroupOpt: null,
                       constantValueOpt: null,
                       type: type,
                       hasErrors: !conversion.IsValid));
        }