Exemple #1
0
        void UpdateIndices(ResolveContext rc)
        {
            int i = 0;

            for (var probe = initializers; probe != null;)
            {
                Expression e = new IntConstant(probe.Count, Location.Null);
                arguments.Add(e);
                bounds[i++] = probe.Count;

                if (probe.Count > 0 && probe[0] is ArrayInitializer)
                {
                    probe = (ArrayInitializer)probe[0];
                }
                else if (dimensions > i)
                {
                    continue;
                }
                else
                {
                    return;
                }
            }
        }
Exemple #2
0
        public static Constant CreateConstantFromValue(ICompilation rc, IType t, object v, Location loc)
        {
            Constant c = null;

            switch ((t as ITypeDefinition).KnownTypeCode)
            {
            case KnownTypeCode.Int32:
                c = new IntConstant((int)v, loc);
                break;

            case KnownTypeCode.String:
                c = new StringConstant((string)v, loc); break;

            case KnownTypeCode.UInt32:
                c = new UIntConstant((uint)v, loc); break;

            case KnownTypeCode.Int64:
                c = new LongConstant((long)v, loc); break;

            case KnownTypeCode.UInt64:
                c = new ULongConstant((ulong)v, loc); break;

            case KnownTypeCode.Single:
                c = new FloatConstant((float)v, loc); break;

            case KnownTypeCode.Double:
                c = new DoubleConstant((double)v, loc); break;

            case KnownTypeCode.Int16:
                c = new ShortConstant((short)v, loc); break;

            case KnownTypeCode.UInt16:
                c = new UShortConstant((ushort)v, loc); break;

            case KnownTypeCode.SByte:
                c = new SByteConstant((sbyte)v, loc); break;

            case KnownTypeCode.Byte:
                c = new ByteConstant((byte)v, loc); break;

            case KnownTypeCode.Char:
                c = new CharConstant((char)v, loc); break;

            case KnownTypeCode.Boolean:
                c = new BoolConstant((bool)v, loc); break;
            }


            if (t.Kind == TypeKind.Enum)
            {
                var real_type = ResolveContext.GetEnumUnderlyingType(t);
                return(CreateConstantFromValue(rc, real_type, v, loc));
            }

            if (v == null)
            {
                // TODO:Support nullable constant ?

                if (t.IsReferenceType.HasValue && t.IsReferenceType.Value)
                {
                    c = new NullConstant(t, loc);
                }
            }

            if (c != null)
            {
                c = ((Constant)c).ResolveType(rc);
            }

            return(c);
        }