コード例 #1
0
        private static SingleLiteralElement?CreateSingle(string image)
        {
            if (image.EndsWith("f", StringComparison.OrdinalIgnoreCase))
            {
                image = image.Remove(image.Length - 1);
                return(SingleLiteralElement.Parse(image));
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Emit the load of a constant field.  We can't emit a ldsfld/ldfld of a constant so we have to get its value
        /// and then emit a ldc.
        /// </summary>
        /// <param name="fi"></param>
        /// <param name="ilg"></param>
        /// <param name="services"></param>
        private static void EmitLiteral(System.Reflection.FieldInfo fi, FleeILGenerator ilg, IServiceProvider services)
        {
            object         value = fi.GetValue(null);
            Type           t     = value.GetType();
            TypeCode       code  = Type.GetTypeCode(t);
            LiteralElement elem  = default(LiteralElement);

            switch (code)
            {
            case TypeCode.Char:
            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
                elem = new Int32LiteralElement(System.Convert.ToInt32(value));
                break;

            case TypeCode.UInt32:
                elem = new UInt32LiteralElement((UInt32)value);
                break;

            case TypeCode.Int64:
                elem = new Int64LiteralElement((Int64)value);
                break;

            case TypeCode.UInt64:
                elem = new UInt64LiteralElement((UInt64)value);
                break;

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

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

            case TypeCode.Boolean:
                elem = new BooleanLiteralElement((bool)value);
                break;

            case TypeCode.String:
                elem = new StringLiteralElement((string)value);
                break;

            default:
                elem = null;
                Debug.Fail("Unsupported constant type");
                break;
            }

            elem.Emit(ilg, services);
        }
コード例 #3
0
        /// <summary>
        /// Emit the load of a constant field.
        /// </summary>
        /// <remarks>
        /// We can't emit a ldsfld/ldfld of a constant so we have to get its value and then emit a ldc.
        /// </remarks>
        /// <param name="fi"></param>
        /// <param name="ilg"></param>
        /// <param name="context"></param>
        private static void EmitLiteral(FieldInfo fi, YaleIlGenerator ilg, ExpressionContext context)
        {
            var            value    = fi.GetValue(null);
            var            type     = value.GetType();
            var            typeCode = Type.GetTypeCode(type);
            LiteralElement elem;

            switch (typeCode)
            {
            case TypeCode.Char:
            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
                elem = new Int32LiteralElement(Convert.ToInt32(value));
                break;

            case TypeCode.UInt32:
                elem = new UInt32LiteralElement((UInt32)value);
                break;

            case TypeCode.Int64:
                elem = new Int64LiteralElement((Int64)value);
                break;

            case TypeCode.UInt64:
                elem = new UInt64LiteralElement((UInt64)value);
                break;

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

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

            case TypeCode.Boolean:
                elem = new BooleanLiteralElement((bool)value);
                break;

            case TypeCode.String:
                elem = new StringLiteralElement((string)value);
                break;

            default:
                elem = null;
                Debug.Fail("Unsupported constant type");
                break;
            }

            elem.Emit(ilg, context);
        }
コード例 #4
0
 private static SingleLiteralElement CreateSingle(string image, IServiceProvider services)
 {
     if (image.EndsWith("f", StringComparison.OrdinalIgnoreCase) == true)
     {
         image = image.Remove(image.Length - 1);
         return(SingleLiteralElement.Parse(image, services));
     }
     else
     {
         return(null);
     }
 }
コード例 #5
0
        private static LiteralElement?CreateImplicitReal(string image)
        {
            var realType = builderOptions.RealLiteralDataType;

            switch (realType)
            {
            case RealLiteralDataType.Double:
                return(DoubleLiteralElement.Parse(image));

            case RealLiteralDataType.Single:
                return(SingleLiteralElement.Parse(image));

            case RealLiteralDataType.Decimal:
                return(DecimalLiteralElement.Parse(image));

            default:
                Debug.Fail("Unknown value");
                return(null);
            }
        }
コード例 #6
0
        private static LiteralElement CreateImplicitReal(string image, IServiceProvider services)
        {
            ExpressionOptions   options  = (ExpressionOptions)services.GetService(typeof(ExpressionOptions));
            RealLiteralDataType realType = options.RealLiteralDataType;

            switch (realType)
            {
            case RealLiteralDataType.Double:
                return(DoubleLiteralElement.Parse(image, services));

            case RealLiteralDataType.Single:
                return(SingleLiteralElement.Parse(image, services));

            case RealLiteralDataType.Decimal:
                return(DecimalLiteralElement.Parse(image, services));

            default:
                Debug.Fail("Unknown value");
                return(null);
            }
        }