Exemplo n.º 1
0
        public static ConstantValue Create(object value, SpecialType st)
        {
            ConstantValueTypeDiscriminator discriminator = GetDiscriminator(st);

            Debug.Assert(discriminator != ConstantValueTypeDiscriminator.Bad);
            return(Create(value, discriminator));
        }
Exemplo n.º 2
0
        public static ConstantValue Default(SpecialType st)
        {
            ConstantValueTypeDiscriminator discriminator = GetDiscriminator(st);

            Debug.Assert(discriminator != ConstantValueTypeDiscriminator.Bad);
            return(Default(discriminator));
        }
Exemplo n.º 3
0
        internal void EmitConstantValue(ConstantValue value)
        {
            ConstantValueTypeDiscriminator discriminator = value.Discriminator;

            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Null:
                EmitNullConstant();
                break;

            case ConstantValueTypeDiscriminator.SByte:
                EmitSByteConstant(value.SByteValue);
                break;

            case ConstantValueTypeDiscriminator.Byte:
                EmitByteConstant(value.ByteValue);
                break;

            case ConstantValueTypeDiscriminator.UInt16:
                EmitUShortConstant(value.UInt16Value);
                break;

            case ConstantValueTypeDiscriminator.Char:
                EmitUShortConstant(value.CharValue);
                break;

            case ConstantValueTypeDiscriminator.Int16:
                EmitShortConstant(value.Int16Value);
                break;

            case ConstantValueTypeDiscriminator.Int32:
            case ConstantValueTypeDiscriminator.UInt32:
                EmitIntConstant(value.Int32Value);
                break;

            case ConstantValueTypeDiscriminator.Int64:
            case ConstantValueTypeDiscriminator.UInt64:
                EmitLongConstant(value.Int64Value);
                break;

            case ConstantValueTypeDiscriminator.Single:
                EmitSingleConstant(value.SingleValue);
                break;

            case ConstantValueTypeDiscriminator.Double:
                EmitDoubleConstant(value.DoubleValue);
                break;

            case ConstantValueTypeDiscriminator.String:
                EmitStringConstant(value.StringValue);
                break;

            case ConstantValueTypeDiscriminator.Boolean:
                EmitBoolConstant(value.BooleanValue);
                break;

            default:
                throw ExceptionUtilities.UnexpectedValue(discriminator);
            }
        }
Exemplo n.º 4
0
        private static SpecialType GetSpecialType(ConstantValueTypeDiscriminator discriminator)
        {
            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.SByte:
                return(SpecialType.System_SByte);

            case ConstantValueTypeDiscriminator.Byte:
                return(SpecialType.System_Byte);

            case ConstantValueTypeDiscriminator.Int16:
                return(SpecialType.System_Int16);

            case ConstantValueTypeDiscriminator.UInt16:
                return(SpecialType.System_UInt16);

            case ConstantValueTypeDiscriminator.Int32:
                return(SpecialType.System_Int32);

            case ConstantValueTypeDiscriminator.UInt32:
                return(SpecialType.System_UInt32);

            case ConstantValueTypeDiscriminator.Int64:
                return(SpecialType.System_Int64);

            case ConstantValueTypeDiscriminator.UInt64:
                return(SpecialType.System_UInt64);

            case ConstantValueTypeDiscriminator.NInt:
                return(SpecialType.System_IntPtr);

            case ConstantValueTypeDiscriminator.NUInt:
                return(SpecialType.System_UIntPtr);

            case ConstantValueTypeDiscriminator.Char:
                return(SpecialType.System_Char);

            case ConstantValueTypeDiscriminator.Boolean:
                return(SpecialType.System_Boolean);

            case ConstantValueTypeDiscriminator.Single:
                return(SpecialType.System_Single);

            case ConstantValueTypeDiscriminator.Double:
                return(SpecialType.System_Double);

            case ConstantValueTypeDiscriminator.Decimal:
                return(SpecialType.System_Decimal);

            case ConstantValueTypeDiscriminator.DateTime:
                return(SpecialType.System_DateTime);

            case ConstantValueTypeDiscriminator.String:
                return(SpecialType.System_String);

            default:
                return(SpecialType.None);
            }
        }
Exemplo n.º 5
0
        private static SpecialType GetSpecialType(ConstantValueTypeDiscriminator discriminator)
        {
            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Int32: return(SpecialType.System_Int32);

            case ConstantValueTypeDiscriminator.String: return(SpecialType.System_String);

            default: return(SpecialType.None);
            }
        }
Exemplo n.º 6
0
        public static ConstantValue Create(object value, ConstantValueTypeDiscriminator discriminator)
        {
            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Int32: return(Create((int)value));

            case ConstantValueTypeDiscriminator.String: return(Create((string)value));

            default:
                throw new InvalidOperationException();      //Not using ExceptionUtilities.UnexpectedValue() because this failure path is tested.
            }
        }
Exemplo n.º 7
0
        public static ConstantValue Create(object value, ConstantValueTypeDiscriminator discriminator)
        {
            Debug.Assert(BitConverter.IsLittleEndian);

            return(discriminator switch
            {
                ConstantValueTypeDiscriminator.Nil => Nil,
                ConstantValueTypeDiscriminator.Int64 => Create((long)value),
                ConstantValueTypeDiscriminator.Boolean => Create((bool)value),
                ConstantValueTypeDiscriminator.Double => Create((double)value),
                ConstantValueTypeDiscriminator.String => Create((string)value),
                _ => throw new InvalidOperationException(),//Not using ExceptionUtilities.UnexpectedValue() because this failure path is tested.
            });
Exemplo n.º 8
0
        public static ConstantValue Create(object value, ConstantValueTypeDiscriminator discriminator)
        {
            Debug.Assert(BitConverter.IsLittleEndian);

            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Null: return(Null);

            case ConstantValueTypeDiscriminator.SByte: return(Create((sbyte)value));

            case ConstantValueTypeDiscriminator.Byte: return(Create((byte)value));

            case ConstantValueTypeDiscriminator.Int16: return(Create((short)value));

            case ConstantValueTypeDiscriminator.UInt16: return(Create((ushort)value));

            case ConstantValueTypeDiscriminator.Int32: return(Create((int)value));

            case ConstantValueTypeDiscriminator.UInt32: return(Create((uint)value));

            case ConstantValueTypeDiscriminator.Int64: return(Create((long)value));

            case ConstantValueTypeDiscriminator.UInt64: return(Create((ulong)value));

            case ConstantValueTypeDiscriminator.Char: return(Create((char)value));

            case ConstantValueTypeDiscriminator.Boolean: return(Create((bool)value));

            case ConstantValueTypeDiscriminator.Single:
                // values for singles may actually have double precision
                return(value is double?
                       CreateSingle((double)value) :
                           Create((float)value));

            case ConstantValueTypeDiscriminator.Double: return(Create((double)value));

            case ConstantValueTypeDiscriminator.Decimal: return(Create((decimal)value));

            case ConstantValueTypeDiscriminator.DateTime: return(Create((DateTime)value));

            case ConstantValueTypeDiscriminator.String: return(Create((string)value));

#if XSHARP
            case ConstantValueTypeDiscriminator.IntPtr: return(Create((IntPtr)value));

            case ConstantValueTypeDiscriminator.Void: return(CreateVoid());
#endif
            default:
                throw new InvalidOperationException();      //Not using ExceptionUtilities.UnexpectedValue() because this failure path is tested.
            }
        }
Exemplo n.º 9
0
        public static bool IsUnsignedIntegralType(ConstantValueTypeDiscriminator discriminator)
        {
            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Byte:
            case ConstantValueTypeDiscriminator.UInt16:
            case ConstantValueTypeDiscriminator.UInt32:
            case ConstantValueTypeDiscriminator.UInt64:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 10
0
        public static ConstantValue Default(ConstantValueTypeDiscriminator discriminator)
        {
            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Bad: return(Bad);

            case ConstantValueTypeDiscriminator.SByte: return(ConstantValueDefault.SByte);

            case ConstantValueTypeDiscriminator.Byte: return(ConstantValueDefault.Byte);

            case ConstantValueTypeDiscriminator.Int16: return(ConstantValueDefault.Int16);

            case ConstantValueTypeDiscriminator.UInt16: return(ConstantValueDefault.UInt16);

            case ConstantValueTypeDiscriminator.Int32: return(ConstantValueDefault.Int32);

            case ConstantValueTypeDiscriminator.UInt32: return(ConstantValueDefault.UInt32);

            case ConstantValueTypeDiscriminator.Int64: return(ConstantValueDefault.Int64);

            case ConstantValueTypeDiscriminator.UInt64: return(ConstantValueDefault.UInt64);

            case ConstantValueTypeDiscriminator.Char: return(ConstantValueDefault.Char);

            case ConstantValueTypeDiscriminator.Boolean: return(ConstantValueDefault.Boolean);

            case ConstantValueTypeDiscriminator.Single: return(ConstantValueDefault.Single);

            case ConstantValueTypeDiscriminator.Double: return(ConstantValueDefault.Double);

            case ConstantValueTypeDiscriminator.Decimal: return(ConstantValueDefault.Decimal);

            case ConstantValueTypeDiscriminator.DateTime: return(ConstantValueDefault.DateTime);

#if XSHARP
            case ConstantValueTypeDiscriminator.IntPtr: return(ConstantValueDefault.IntPtr);

            case ConstantValueTypeDiscriminator.Void: return(Null);
#endif

            case ConstantValueTypeDiscriminator.Null:
            case ConstantValueTypeDiscriminator.String: return(Null);
            }

            throw ExceptionUtilities.UnexpectedValue(discriminator);
        }
Exemplo n.º 11
0
        // TODO: Do these fields need to be offset at 8 and 16 for alignment on x64?
        // TODO: Decimal is not here because it's awful.

        public ConstantValue(object value)
        {
            Debug.Assert(BitConverter.IsLittleEndian);

            this = default(ConstantValue);
            var discriminator = GetTypeDiscriminator(value);

            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Null: break;

            case ConstantValueTypeDiscriminator.SByte: this.sbyteValue = (sbyte)value; break;

            case ConstantValueTypeDiscriminator.Byte: this.byteValue = (byte)value; break;

            case ConstantValueTypeDiscriminator.Int16: this.int16Value = (short)value; break;

            case ConstantValueTypeDiscriminator.UInt16: this.uint16Value = (ushort)value; break;

            case ConstantValueTypeDiscriminator.Int32: this.int32Value = (int)value; break;

            case ConstantValueTypeDiscriminator.UInt32: this.uint32Value = (uint)value; break;

            case ConstantValueTypeDiscriminator.Int64: this.int64Value = (long)value; break;

            case ConstantValueTypeDiscriminator.UInt64: this.uint64Value = (ulong)value; break;

            case ConstantValueTypeDiscriminator.Char: this.charValue = (char)value; break;

            case ConstantValueTypeDiscriminator.Boolean: this.booleanValue = (bool)value; break;

            case ConstantValueTypeDiscriminator.Single: this.singleValue = (float)value; break;

            case ConstantValueTypeDiscriminator.Double: this.doubleValue = (double)value; break;

            case ConstantValueTypeDiscriminator.String: this.stringValue = (string)value; break;

            default: throw new InvalidOperationException();
            }

            this.discriminator = discriminator;
        }
Exemplo n.º 12
0
        public static ConstantValue Default(ConstantValueTypeDiscriminator discriminator)
        {
            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Bad: return(Bad);

            case ConstantValueTypeDiscriminator.Int: return(ConstantValueDefault.Int);

            case ConstantValueTypeDiscriminator.Int8: return(ConstantValueDefault.Int8);

            case ConstantValueTypeDiscriminator.UInt8: return(ConstantValueDefault.UInt8);

            case ConstantValueTypeDiscriminator.Int16: return(ConstantValueDefault.Int16);

            case ConstantValueTypeDiscriminator.UInt16: return(ConstantValueDefault.UInt16);

            case ConstantValueTypeDiscriminator.Int32: return(ConstantValueDefault.Int32);

            case ConstantValueTypeDiscriminator.UInt32: return(ConstantValueDefault.UInt32);

            case ConstantValueTypeDiscriminator.Int64: return(ConstantValueDefault.Int64);

            case ConstantValueTypeDiscriminator.UInt64: return(ConstantValueDefault.UInt64);

            case ConstantValueTypeDiscriminator.Rune: return(ConstantValueDefault.Rune);

            case ConstantValueTypeDiscriminator.Boolean: return(ConstantValueDefault.Boolean);

            case ConstantValueTypeDiscriminator.Single: return(ConstantValueDefault.Float32);

            case ConstantValueTypeDiscriminator.Double: return(ConstantValueDefault.Float64);

            case ConstantValueTypeDiscriminator.Null:
            case ConstantValueTypeDiscriminator.String: return(Null);
            }

            throw ExceptionUtilities.UnexpectedValue(discriminator);
        }
Exemplo n.º 13
0
        private static SpecialType GetSpecialType(ConstantValueTypeDiscriminator discriminator)
        {
            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Int: return(SpecialType.System_Int);

            case ConstantValueTypeDiscriminator.UInt: return(SpecialType.System_UInt);

            case ConstantValueTypeDiscriminator.Int8: return(SpecialType.System_Int8);

            case ConstantValueTypeDiscriminator.UInt8: return(SpecialType.System_UInt8);

            case ConstantValueTypeDiscriminator.Int16: return(SpecialType.System_Int16);

            case ConstantValueTypeDiscriminator.UInt16: return(SpecialType.System_UInt16);

            case ConstantValueTypeDiscriminator.Int32: return(SpecialType.System_Int32);

            case ConstantValueTypeDiscriminator.UInt32: return(SpecialType.System_UInt32);

            case ConstantValueTypeDiscriminator.Int64: return(SpecialType.System_Int64);

            case ConstantValueTypeDiscriminator.UInt64: return(SpecialType.System_UInt64);

            case ConstantValueTypeDiscriminator.Rune: return(SpecialType.System_Rune);

            case ConstantValueTypeDiscriminator.Boolean: return(SpecialType.System_Boolean);

            case ConstantValueTypeDiscriminator.Single: return(SpecialType.System_Float32);

            case ConstantValueTypeDiscriminator.Double: return(SpecialType.System_Float64);

            case ConstantValueTypeDiscriminator.String: return(SpecialType.System_String);

            default: return(SpecialType.None);
            }
        }
Exemplo n.º 14
0
 public ConstantValueDiscriminated(ConstantValueTypeDiscriminator discriminator)
 {
     _discriminator = discriminator;
 }
Exemplo n.º 15
0
        internal void EmitConstantValue(ConstantValue value)
        {
            ConstantValueTypeDiscriminator discriminator = value.Discriminator;

            switch (discriminator)
            {
            case ConstantValueTypeDiscriminator.Null:
                EmitNullConstant();
                break;

            case ConstantValueTypeDiscriminator.SByte:
                EmitSByteConstant(value.SByteValue);
                break;

            case ConstantValueTypeDiscriminator.Byte:
                EmitByteConstant(value.ByteValue);
                break;

            case ConstantValueTypeDiscriminator.UInt16:
                EmitUShortConstant(value.UInt16Value);
                break;

            case ConstantValueTypeDiscriminator.Char:
                EmitUShortConstant(value.CharValue);
                break;

            case ConstantValueTypeDiscriminator.Int16:
                EmitShortConstant(value.Int16Value);
                break;

            case ConstantValueTypeDiscriminator.Int32:
            case ConstantValueTypeDiscriminator.UInt32:
                EmitIntConstant(value.Int32Value);
                break;

            case ConstantValueTypeDiscriminator.Int64:
            case ConstantValueTypeDiscriminator.UInt64:
                EmitLongConstant(value.Int64Value);
                break;

            case ConstantValueTypeDiscriminator.Single:
                EmitSingleConstant(value.SingleValue);
                break;

            case ConstantValueTypeDiscriminator.Double:
                EmitDoubleConstant(value.DoubleValue);
                break;

            case ConstantValueTypeDiscriminator.String:
                EmitStringConstant(value.StringValue);
                break;

            case ConstantValueTypeDiscriminator.Boolean:
                EmitBoolConstant(value.BooleanValue);
                break;

#if XSHARP
            case ConstantValueTypeDiscriminator.IntPtr:
                unchecked
                {
                    int intvalue = (int)((long)value.IntPtrValue & 0xFFFFFFFF);
                    EmitIntConstant(intvalue);
                }
                break;

            case ConstantValueTypeDiscriminator.Void:
                EmitNullConstant();
                break;
#endif
            default:
                throw ExceptionUtilities.UnexpectedValue(discriminator);
            }
        }
Exemplo n.º 16
0
 protected ConstantValueOne(ConstantValueTypeDiscriminator discriminator)
     : base(discriminator)
 {
 }
Exemplo n.º 17
0
 protected ConstantValueDefault(ConstantValueTypeDiscriminator discriminator)
     : base(discriminator)
 {
 }
Exemplo n.º 18
0
 public ConstantValueDiscriminated(ConstantValueTypeDiscriminator discriminator)
 {
     _discriminator = discriminator;
 }
Exemplo n.º 19
0
 public static bool IsRuneType(ConstantValueTypeDiscriminator discriminator)
 {
     return(discriminator == ConstantValueTypeDiscriminator.Rune);
 }
Exemplo n.º 20
0
 public static bool IsBooleanType(ConstantValueTypeDiscriminator discriminator)
 {
     return(discriminator == ConstantValueTypeDiscriminator.Boolean);
 }
Exemplo n.º 21
0
 public static bool IsDateTimeType(ConstantValueTypeDiscriminator discriminator)
 {
     return(discriminator == ConstantValueTypeDiscriminator.DateTime);
 }
Exemplo n.º 22
0
 public static bool IsStringType(ConstantValueTypeDiscriminator discriminator)
 {
     return(discriminator == ConstantValueTypeDiscriminator.String);
 }
Exemplo n.º 23
0
 public static bool IsCharType(ConstantValueTypeDiscriminator discriminator)
 {
     return(discriminator == ConstantValueTypeDiscriminator.Char);
 }
Exemplo n.º 24
0
 protected ConstantValueDefault(ConstantValueTypeDiscriminator discriminator)
     : base(discriminator)
 {
 }
Exemplo n.º 25
0
 public static bool IsDecimalType(ConstantValueTypeDiscriminator discriminator)
 {
     return(discriminator == ConstantValueTypeDiscriminator.Decimal);
 }
Exemplo n.º 26
0
 protected ConstantValueOne(ConstantValueTypeDiscriminator discriminator)
     : base(discriminator)
 {
 }
Exemplo n.º 27
0
 public static bool IsFloatingType(ConstantValueTypeDiscriminator discriminator)
 {
     return(discriminator == ConstantValueTypeDiscriminator.Double ||
            discriminator == ConstantValueTypeDiscriminator.Single);
 }
Exemplo n.º 28
0
        // TODO: Do these fields need to be offset at 8 and 16 for alignment on x64?
        // TODO: Decimal is not here because it's awful.

        public ConstantValue(object value)
        {
            Debug.Assert(BitConverter.IsLittleEndian);

            this = default(ConstantValue);
            var discriminator = GetTypeDiscriminator(value);
            switch (discriminator)
            {
                case ConstantValueTypeDiscriminator.Null: break;
                case ConstantValueTypeDiscriminator.SByte: this.sbyteValue = (sbyte)value; break;
                case ConstantValueTypeDiscriminator.Byte: this.byteValue = (byte)value; break;
                case ConstantValueTypeDiscriminator.Int16: this.int16Value = (short)value; break;
                case ConstantValueTypeDiscriminator.UInt16: this.uint16Value = (ushort)value; break;
                case ConstantValueTypeDiscriminator.Int32: this.int32Value = (int)value; break;
                case ConstantValueTypeDiscriminator.UInt32: this.uint32Value = (uint)value; break;
                case ConstantValueTypeDiscriminator.Int64: this.int64Value = (long)value; break;
                case ConstantValueTypeDiscriminator.UInt64: this.uint64Value = (ulong)value; break;
                case ConstantValueTypeDiscriminator.Char: this.charValue = (char)value; break;
                case ConstantValueTypeDiscriminator.Boolean: this.booleanValue = (bool)value; break;
                case ConstantValueTypeDiscriminator.Single: this.singleValue = (float)value; break;
                case ConstantValueTypeDiscriminator.Double: this.doubleValue = (double)value; break;
                case ConstantValueTypeDiscriminator.String: this.stringValue = (string)value; break;
                default: throw new InvalidOperationException();
            }

            this.discriminator = discriminator;
        }