示例#1
0
        public static IExpression SpecializeToSmallestType(this IExpression e)
        {
            if (e.Types.Count() == 1)
            {
                return(e);
            }

            Type smallest = null;

            foreach (var t in e.Types)
            {
                if (smallest == null)
                {
                    smallest = t;
                    continue;
                }

                var smallestIsSuperset = smallest.IsSuperSet(t);
                if (!t.IsSuperSet(smallest) && !smallestIsSuperset)
                {
                    // Neither one is smaller then the other, we can not compare them
                    return(e);
                }

                if (smallestIsSuperset)
                {
                    smallest = t;
                }
            }

            return(e.Specialize(new[] { smallest }));
        }
示例#2
0
        public static IExpression Specialize(this IExpression e, Type t)
        {
            if (t == null)
            {
                throw new NullReferenceException("Cannot specialize to null");
            }

            return(e.Specialize(new[] { t }));
        }
示例#3
0
        public Constant(Type t, object o)
        {
            Types = new List <Type> {
                t
            };
            if (o is IEnumerable <IExpression> enumerable)
            {
                o = enumerable.ToList();
                if (enumerable.Any(x => x == null))
                {
                    throw new NullReferenceException("Some subexpression is null");
                }
            }

            _o = o;
        }