Exemplo n.º 1
0
        public void EmptyStructTypeAndSingleMemeberTypesAreNotEqual()
        {
            var t1 = FunnyType.StructOf("name", FunnyType.Text);
            var t2 = FunnyType.StructOf();

            Assert.AreNotEqual(t1, t2);
        }
Exemplo n.º 2
0
        public void TwoStructTypesWithSingleMemberOfDifferentNamesAreNotEqual()
        {
            var t1 = FunnyType.StructOf("name", FunnyType.Text);
            var t2 = FunnyType.StructOf("nick", FunnyType.Text);

            Assert.AreNotEqual(t1, t2);
        }
Exemplo n.º 3
0
        public void TwoStructTypesWithSingleMemberAreEqual()
        {
            var t1 = FunnyType.StructOf("name", FunnyType.Text);
            var t2 = FunnyType.StructOf("name", FunnyType.Text);

            Assert.AreEqual(t1, t2);
        }
Exemplo n.º 4
0
        public void TwoStructTypesWithNoMembersAreEqual()
        {
            var empty1 = FunnyType.StructOf();
            var empty2 = FunnyType.StructOf();

            Assert.AreEqual(empty1, empty2);
        }
Exemplo n.º 5
0
        public IExpressionNode Visit(StructInitSyntaxNode node)
        {
            var types = new Dictionary <string, FunnyType>(node.Fields.Count);
            var names = new string[node.Fields.Count];
            var nodes = new IExpressionNode[node.Fields.Count];

            for (int i = 0; i < node.Fields.Count; i++)
            {
                var field = node.Fields[i];
                nodes[i] = ReadNode(field.Node);
                names[i] = field.Name;
                types.Add(field.Name, field.Node.OutputType);
            }

            foreach (var field in node.OutputType.StructTypeSpecification)
            {
                if (!types.ContainsKey(field.Key))
                {
                    throw FunParseException.ErrorStubToDo($"Field {field.Key} is missed in struct");
                }
            }
            return(new StructInitExpressionNode(names, nodes, node.Interval, FunnyType.StructOf(types)));
        }
Exemplo n.º 6
0
            public override FunnyType Convert(ITicNodeState type)
            {
                switch (type)
                {
                case StateRefTo refTo:
                    return(Convert(refTo.Element));

                case StatePrimitive primitive:
                    return(ToConcrete(primitive.Name));

                case ConstrainsState constrains when constrains.Prefered != null:
                    return(ToConcrete(constrains.Prefered.Name));

                case ConstrainsState constrains when !constrains.HasAncestor:
                {
                    if (constrains.IsComparable)
                    {
                        return(FunnyType.Real);
                    }
                    return(FunnyType.Anything);
                }

                case ConstrainsState constrains:
                {
                    if (constrains.Ancestor.Name.HasFlag(PrimitiveTypeName._isAbstract))
                    {
                        switch (constrains.Ancestor.Name)
                        {
                        case PrimitiveTypeName.I96:
                        {
                            if (constrains.HasDescendant || constrains.Descedant.CanBeImplicitlyConvertedTo(StatePrimitive.I32))
                            {
                                return(FunnyType.Int32);
                            }
                            return(FunnyType.Int64);
                        }

                        case PrimitiveTypeName.I48:
                        {
                            if (constrains.HasDescendant || constrains.Descedant.CanBeImplicitlyConvertedTo(StatePrimitive.I32))
                            {
                                return(FunnyType.Int32);
                            }
                            return(FunnyType.UInt32);
                        }

                        case PrimitiveTypeName.U48: return(FunnyType.UInt32);

                        case PrimitiveTypeName.U24: return(FunnyType.UInt16);

                        case PrimitiveTypeName.U12: return(FunnyType.UInt8);

                        default: throw new NotSupportedException();
                        }
                    }
                    return(ToConcrete(constrains.Ancestor.Name));
                }

                case StateArray array:
                    return(FunnyType.ArrayOf(Convert(array.Element)));

                case StateFun fun:
                    return(FunnyType.Fun(Convert(fun.ReturnType), fun.ArgNodes.SelectToArray(a => Convert(a.State))));

                case StateStruct str:
                    return(FunnyType.StructOf(str.Fields.ToDictionary(f => f.Key, f => Convert(f.Value.State))));

                default:
                    throw new NotSupportedException();
                }
            }