Exemple #1
0
        public override CiExpr Visit(CiAggregateInitializer expr, CiPriority parent)
        {
            CiNumericType number = ((CiArrayStorageType)expr.Type).ElementType as CiNumericType;

            if (number != null)
            {
                Write("new ");
                Write(GetArrayElementType(number));
                Write("Array(");
            }
            Write("[ ");
            WriteCoercedLiterals(null, expr.Items);
            Write(" ]");
            if (number != null)
            {
                Write(')');
            }
            return(expr);
        }
Exemple #2
0
        protected static string GetArrayElementType(CiNumericType type)
        {
            if (type == CiSystem.IntType)
            {
                return("Int32");
            }
            if (type == CiSystem.DoubleType)
            {
                return("Float64");
            }
            if (type == CiSystem.FloatType)
            {
                return("Float32");
            }
            if (type == CiSystem.LongType)
            {
                // TODO: UInt32 if possible?
                return("Float64");        // no 64-bit integers in JavaScript
            }
            CiRangeType range = (CiRangeType)type;

            if (range.Min < 0)
            {
                if (range.Min < short.MinValue || range.Max > short.MaxValue)
                {
                    return("Int32");
                }
                if (range.Min < sbyte.MinValue || range.Max > sbyte.MaxValue)
                {
                    return("Int16");
                }
                return("Int8");
            }
            if (range.Max > ushort.MaxValue)
            {
                return("Int32");
            }
            if (range.Max > byte.MaxValue)
            {
                return("Uint16");
            }
            return("Uint8");
        }