Ejemplo n.º 1
0
        void AssertLiteralInRange(IntegerLiteralExpression literal, IType type)
        {
            bool ok = true;

            if (type == TypeSystemServices.ByteType)
            {
                ok = (literal.Value >= byte.MinValue && literal.Value <= byte.MaxValue);
            }
            else if (type == TypeSystemServices.SByteType)
            {
                ok = (literal.Value >= sbyte.MinValue && literal.Value <= sbyte.MaxValue);
            }
            else if (type == TypeSystemServices.ShortType)
            {
                ok = (literal.Value >= short.MinValue && literal.Value <= short.MaxValue);
            }
            else if (type == TypeSystemServices.UShortType)
            {
                ok = (literal.Value >= ushort.MinValue && literal.Value <= ushort.MaxValue);
            }
            else if (type == TypeSystemServices.IntType)
            {
                ok = (literal.Value >= int.MinValue && literal.Value <= int.MaxValue);
            }
            else if (type == TypeSystemServices.UIntType)
            {
                ok = (literal.Value >= uint.MinValue && literal.Value <= uint.MaxValue);
            }
            else if (type == TypeSystemServices.LongType)
            {
                ok = (literal.Value >= long.MinValue && literal.Value <= long.MaxValue);
            }

            if (!ok)
            {
                Error(CompilerErrorFactory.ConstantCannotBeConverted(literal, type));
            }
        }