Ejemplo n.º 1
0
        private bool IsTypeDefaultConstructable(CheezType type)
        {
            if (type.IsDefaultConstructableComputed())
            {
                return(type.GetIsDefaultConstructable());
            }
            var path = new List <CheezType>();

            return(ComputeIsDefaultConstructableOfType(type, path));
        }
Ejemplo n.º 2
0
        private bool ComputeIsDefaultConstructableOfType(CheezType type, List <CheezType> path)
        {
            if (type.IsDefaultConstructableComputed())
            {
                return(type.GetIsDefaultConstructable());
            }

            if (path.Contains(type))
            {
                ReportError($"Failed to calculate default constructability of type {type} because it has a circular dependency on its own default constructability");
                return(false);
            }

            path.Add(type);

            try
            {
                switch (type)
                {
                case StructType s:
                {
                    ComputeStructMembers(s.Declaration);
                    bool isDefaultConstructable = true;
                    foreach (var m in s.Declaration.Members)
                    {
                        isDefaultConstructable &= m.Decl.Initializer != null;
                        //isDefaultConstructable &= ComputeIsDefaultConstructableOfType(m.Type, path);
                    }

                    s.SetIsDefaultConstructable(isDefaultConstructable);
                    return(isDefaultConstructable);
                }

                case TupleType t:
                {
                    bool isDefaultConstructable = true;
                    foreach (var m in t.Members)
                    {
                        isDefaultConstructable &= ComputeIsDefaultConstructableOfType(m.type, path);
                    }

                    t.SetIsDefaultConstructable(isDefaultConstructable);
                    return(isDefaultConstructable);
                }

                case ArrayType t:
                {
                    bool isDefaultConstructable = ComputeIsDefaultConstructableOfType(t.TargetType, path);
                    t.SetIsDefaultConstructable(isDefaultConstructable);
                    return(isDefaultConstructable);
                }

                case RangeType r:
                {
                    bool isDefaultConstructable = ComputeIsDefaultConstructableOfType(r.TargetType, path);
                    r.SetIsDefaultConstructable(isDefaultConstructable);
                    return(isDefaultConstructable);
                }

                case SumType _:
                    return(false);

                default:
                    ReportError($"ERROR? {type}");
                    return(false);
                }
            }
            finally
            {
                path.Remove(type);
            }
        }