Пример #1
0
        private static LiteralElement CreateImplicitReal(string image, IServiceProvider services)
        {
            var            options            = (ExpressionOptions)services.GetService(typeof(ExpressionOptions));
            LiteralElement createImplicitReal = null;

            switch (options.RealLiteralDataType)
            {
            case RealLiteralDataType.Single:
                createImplicitReal = SingleLiteralElement.Parse(image, services);
                break;

            case RealLiteralDataType.Double:
                createImplicitReal = DoubleLiteralElement.Parse(image, services);
                break;

            case RealLiteralDataType.Decimal:
                createImplicitReal = DecimalLiteralElement.Parse(image, services);
                break;

            default:
                Debug.Fail("Unknown value");
                break;
            }
            return(createImplicitReal);
        }
Пример #2
0
        public static LiteralElement CreateFromInteger(string image, IServiceProvider services)
        {
            LiteralElement element = CreateSingle(image, services);
            var            flag    = element != null;
            LiteralElement createFromInteger;

            if (flag)
            {
                createFromInteger = element;
            }
            else
            {
                element = CreateDecimal(image, services);
                var flag2 = element != null;
                if (flag2)
                {
                    createFromInteger = element;
                }
                else
                {
                    var options           = (ExpressionOptions)services.GetService(typeof(ExpressionOptions));
                    var integersAsDoubles = options.IntegersAsDoubles;
                    createFromInteger = integersAsDoubles ? DoubleLiteralElement.Parse(image, services) : null;
                }
            }
            return(createFromInteger);
        }
Пример #3
0
        private static void EmitLiteral(FieldInfo fi, FleeIlGenerator ilg, IServiceProvider services)
        {
            var            value = RuntimeHelpers.GetObjectValue(fi.GetValue(null));
            var            t     = value.GetType();
            LiteralElement elem;

            switch (Type.GetTypeCode(t))
            {
            case TypeCode.Boolean:
                elem = new BooleanLiteralElement((bool)value);
                goto IL_F4;

            case TypeCode.Char:
            case TypeCode.SByte:
            case TypeCode.Byte:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
                elem = new Int32LiteralElement(Convert.ToInt32(RuntimeHelpers.GetObjectValue(value)));
                goto IL_F4;

            case TypeCode.UInt32:
                elem = new UInt32LiteralElement((uint)value);
                goto IL_F4;

            case TypeCode.Int64:
                elem = new Int64LiteralElement((long)value);
                goto IL_F4;

            case TypeCode.UInt64:
                elem = new UInt64LiteralElement((ulong)value);
                goto IL_F4;

            case TypeCode.Single:
                elem = new SingleLiteralElement((float)value);
                goto IL_F4;

            case TypeCode.Double:
                elem = new DoubleLiteralElement((double)value);
                goto IL_F4;

            case TypeCode.String:
                elem = new StringLiteralElement((string)value);
                goto IL_F4;
            }
            elem = null;
            Debug.Fail("Unsupported constant type");
IL_F4:
            elem.Emit(ilg, services);
        }
Пример #4
0
        private static DoubleLiteralElement CreateDouble(string image, IServiceProvider services)
        {
            var flag = image.EndsWith("d", StringComparison.OrdinalIgnoreCase);
            DoubleLiteralElement createDouble;

            if (flag)
            {
                image        = image.Remove(image.Length - 1);
                createDouble = DoubleLiteralElement.Parse(image, services);
            }
            else
            {
                createDouble = null;
            }
            return(createDouble);
        }
Пример #5
0
        public static DoubleLiteralElement Parse(string image, IServiceProvider services)
        {
            var options = (ExpressionParserOptions)services.GetService(typeof(ExpressionParserOptions));
            var element = new DoubleLiteralElement();
            DoubleLiteralElement parse;

            try
            {
                var value = options.ParseDouble(image);
                parse = new DoubleLiteralElement(value);
            }
            catch (OverflowException expr_2F)
            {
                ProjectData.SetProjectError(expr_2F);
                element.OnParseOverflow(image);
                parse = null;
                ProjectData.ClearProjectError();
            }
            return(parse);
        }