Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private static SingleLiteralElement CreateSingle(string image, IServiceProvider services)
        {
            var flag = image.EndsWith("f", StringComparison.OrdinalIgnoreCase);
            SingleLiteralElement createSingle;

            if (flag)
            {
                image        = image.Remove(image.Length - 1);
                createSingle = SingleLiteralElement.Parse(image, services);
            }
            else
            {
                createSingle = null;
            }
            return(createSingle);
        }
Ejemplo n.º 4
0
        public static SingleLiteralElement Parse(string image, IServiceProvider services)
        {
            var options = (ExpressionParserOptions)services.GetService(typeof(ExpressionParserOptions));
            var element = new SingleLiteralElement();
            SingleLiteralElement parse;

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