コード例 #1
0
        public override BoundNode VisitConversion(BoundConversion node)
        {
            Debug.Assert(node != null);

            BoundExpression operand = (BoundExpression)this.Visit(node.Operand);

            switch (node.ConversionKind)
            {
            case ConversionKind.ImplicitNumeric:
            case ConversionKind.ExplicitNumeric:
                if (node.Type.SpecialType == SpecialType.System_Decimal)
                {
                    return(RewriteNumericToDecimalConversion(node.Syntax, operand, operand.Type));
                }
                else if (operand.Type.SpecialType == SpecialType.System_Decimal)
                {
                    return(RewriteDecimalToNumericConversion(node.Syntax, operand, node.Type));
                }
                break;

            default:
                break;
            }

            return(node.Update(operand, node.ConversionKind, node.SymbolOpt, node.Checked, node.ExplicitCastInCode, node.IsExtensionMethod, node.ConstantValueOpt, node.ResultKind, node.Type));
        }
コード例 #2
0
        public override BoundNode VisitConversion(BoundConversion node)
        {
            Debug.Assert(node != null);

            BoundExpression operand = (BoundExpression)this.Visit(node.Operand);

            switch (node.ConversionKind)
            {
                case ConversionKind.ImplicitNumeric:
                case ConversionKind.ExplicitNumeric:
                    if (node.Type.SpecialType == SpecialType.System_Decimal)
                    {
                        return RewriteNumericToDecimalConversion(node.Syntax, operand, operand.Type);
                    }
                    else if (operand.Type.SpecialType == SpecialType.System_Decimal)
                    {
                        return RewriteDecimalToNumericConversion(node.Syntax, operand, node.Type);
                    }
                    break;
                default:
                    break;
            }

            return node.Update(operand, node.ConversionKind, node.SymbolOpt, node.Checked, node.ExplicitCastInCode, node.IsExtensionMethod, node.ConstantValueOpt, node.ResultKind, node.Type);
        }
コード例 #3
0
        private BoundNode RewriteMethodGroupConversion(BoundConversion conversion)
        {
            // in a method group conversion, we may need to rewrite the selected method
            BoundMethodGroup operand             = (BoundMethodGroup)conversion.Operand;
            BoundExpression  originalReceiverOpt = operand.ReceiverOpt;
            BoundExpression  receiverOpt;

            if (originalReceiverOpt == null)
            {
                receiverOpt = null;
            }
            else if (!conversion.IsExtensionMethod && conversion.SymbolOpt.IsStatic)
            {
                receiverOpt = new BoundTypeExpression(originalReceiverOpt.Syntax, null, VisitType(originalReceiverOpt.Type));
            }
            else
            {
                receiverOpt = (BoundExpression)Visit(originalReceiverOpt);
            }

            TypeSymbol type = this.VisitType(conversion.Type);

            MethodSymbol method = conversion.SymbolOpt;

            //  if the original receiver was a base access and is was rewritten,
            //  change the method to point to the wrapper method
            if (BaseReferenceInReceiverWasRewritten(originalReceiverOpt, receiverOpt) && method.IsMetadataVirtual())
            {
                method = GetMethodWrapperForBaseNonVirtualCall(method, conversion.Syntax);
            }

            method  = VisitMethodSymbol(method);
            operand = operand.Update(
                TypeMap.SubstituteTypesWithoutModifiers(operand.TypeArgumentsOpt),
                method.Name,
                operand.Methods,
                operand.LookupSymbolOpt,
                operand.LookupError,
                operand.Flags,
                receiverOpt,
                operand.ResultKind);

            var conversionInfo = conversion.Conversion;

            if (conversionInfo.Method != (object)method)
            {
                conversionInfo = conversionInfo.SetConversionMethod(method);
            }

            return(conversion.Update(
                       operand,
                       conversionInfo,
                       isBaseConversion: conversion.IsBaseConversion,
                       @checked: conversion.Checked,
                       explicitCastInCode: conversion.ExplicitCastInCode,
                       constantValueOpt: conversion.ConstantValueOpt,
                       type: type));
        }
コード例 #4
0
 private BoundConversion MakeImplicitReferenceConversionExplicit(BoundConversion implicitConv)
 {
     Debug.Assert(implicitConv.ConversionKind == ConversionKind.ImplicitReference);
     Debug.Assert(implicitConv.Type.TypeKind == TypeKind.Interface);
     return(implicitConv.Update(
                operand: (BoundExpression)Visit(implicitConv.Operand), //NB: visit
                conversionKind: ConversionKind.ExplicitReference,
                symbolOpt: null,
                @checked: false,
                explicitCastInCode: false,
                constantValueOpt: implicitConv.ConstantValueOpt,
                type: implicitConv.Type));
 }
コード例 #5
0
        public override BoundNode?VisitConversion(BoundConversion node)
        {
            var conversion = node.Conversion;

            if (conversion.Method is not null)
            {
                conversion = conversion.SetConversionMethod(VisitMethodSymbol(conversion.Method));
            }

            return(node.Update(
                       (BoundExpression)Visit(node.Operand),
                       conversion,
                       node.IsBaseConversion,
                       node.Checked,
                       node.ExplicitCastInCode,
                       node.ConstantValueOpt,
                       node.ConversionGroupOpt,
                       VisitType(node.Type)));
        }
コード例 #6
0
        private BoundNode RewriteMethodGroupConversion(BoundConversion conversion)
        {
            // in a method group conversion, we may need to rewrite the selected method
            BoundMethodGroup operand = (BoundMethodGroup)conversion.Operand;
            BoundExpression originalReceiverOpt = operand.ReceiverOpt;
            BoundExpression receiverOpt;

            if (originalReceiverOpt == null)
            {
                receiverOpt = null;
            }
            else if (!conversion.IsExtensionMethod && conversion.SymbolOpt.IsStatic)
            {
                receiverOpt = new BoundTypeExpression(originalReceiverOpt.Syntax, null, VisitType(originalReceiverOpt.Type));
            }
            else
            {
                receiverOpt = (BoundExpression)Visit(originalReceiverOpt);
            }

            TypeSymbol type = this.VisitType(conversion.Type);

            MethodSymbol method = conversion.SymbolOpt;

            //  if the original receiver was a base access and is was rewritten, 
            //  change the method to point to the wrapper method
            if (BaseReferenceInReceiverWasRewritten(originalReceiverOpt, receiverOpt) && method.IsMetadataVirtual())
            {
                method = GetMethodWrapperForBaseNonVirtualCall(method, conversion.Syntax);
            }

            method = VisitMethodSymbol(method);
            operand = operand.Update(
                TypeMap.SubstituteTypesWithoutModifiers(operand.TypeArgumentsOpt),
                method.Name,
                operand.Methods,
                operand.LookupSymbolOpt,
                operand.LookupError,
                operand.Flags,
                receiverOpt,
                operand.ResultKind);

            var conversionInfo = conversion.Conversion;
            if (conversionInfo.Method != (object)method)
            {
                conversionInfo = conversionInfo.SetConversionMethod(method);
            }

            return conversion.Update(
                operand,
                conversionInfo,
                isBaseConversion: conversion.IsBaseConversion,
                @checked: conversion.Checked,
                explicitCastInCode: conversion.ExplicitCastInCode,
                constantValueOpt: conversion.ConstantValueOpt,
                type: type);
        }
コード例 #7
0
 private BoundConversion MakeImplicitReferenceConversionExplicit(BoundConversion implicitConv)
 {
     Debug.Assert(implicitConv.ConversionKind == ConversionKind.ImplicitReference);
     Debug.Assert(implicitConv.Type.TypeKind == TypeKind.Interface);
     return implicitConv.Update(
         operand: (BoundExpression)Visit(implicitConv.Operand), //NB: visit
         conversionKind: ConversionKind.ExplicitReference,
         symbolOpt: null,
         @checked: false,
         explicitCastInCode: false,
         constantValueOpt: implicitConv.ConstantValueOpt,
         type: implicitConv.Type);
 }