Beispiel #1
0
        public IState GetOptimizedOrThrow()
        {
            if (IsComparable)
            {
                if (Descedant != null)
                {
                    if (Descedant.Equals(Primitive.Char))
                    {
                        return(Primitive.Char);
                    }

                    if (Descedant is Primitive primitive && primitive.IsNumeric)
                    {
                        if (!TryAddAncestor(Primitive.Real))
                        {
                            throw new InvalidOperationException();
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("Types cannot be compared");
                    }
                }
            }
Beispiel #2
0
        public bool Fits(Primitive primitive)
        {
            if (HasAncestor)
            {
                if (!primitive.CanBeImplicitlyConvertedTo(Ancestor))
                {
                    return(false);
                }
            }

            if (HasDescendant)
            {
                if (!Descedant.CanBeImplicitlyConvertedTo(primitive))
                {
                    return(false);
                }
            }

            if (IsComparable && !primitive.IsComparable)
            {
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public bool Fits(IType type)
        {
            if (HasAncestor)
            {
                if (!type.CanBeImplicitlyConvertedTo(Ancestor))
                {
                    return(false);
                }
            }

            if (type is Primitive primitive)
            {
                if (HasDescendant)
                {
                    if (!Descedant.CanBeImplicitlyConvertedTo(primitive))
                    {
                        return(false);
                    }
                }

                if (IsComparable && !primitive.IsComparable)
                {
                    return(false);
                }
                return(true);
            }
            else if (type is Array array)
            {
                if (IsComparable)
                {
                    return(false);
                }
                if (!HasDescendant)
                {
                    return(true);
                }
                if (!(Descedant is Array descArray))
                {
                    return(false);
                }
                if (array.Element.Equals(descArray.Element))
                {
                    return(true);
                }
                if (!array.IsSolved || !descArray.IsSolved)
                {
                    return(false);
                }
            }
            else if (type is Fun fun)
            {
                if (IsComparable)
                {
                    return(false);
                }
                if (!HasDescendant)
                {
                    return(true);
                }
                if (!(Descedant is Fun descfun))
                {
                    return(false);
                }
                if (fun.Members.SequenceEqual(descfun.Members))
                {
                    return(true);
                }
                if (!fun.IsSolved || !descfun.IsSolved)
                {
                    return(false);
                }
            }
            throw new NotSupportedException();
        }