Esempio n. 1
0
        public static void AssertGenericType(this SolvingNode node, Primitive desc, Primitive anc,
                                             bool isComparable = false)
        {
            var generic = node.State as Constrains;

            Assert.IsNotNull(generic);
            if (desc == null)
            {
                Assert.IsFalse(generic.HasDescendant);
            }
            else
            {
                Assert.AreEqual(desc, generic.Descedant);
            }

            if (anc == null)
            {
                Assert.IsFalse(generic.HasAncestor);
            }
            else
            {
                Assert.AreEqual(anc, generic.Ancestor);
            }

            Assert.AreEqual(isComparable, generic.IsComparable, "IsComparable claim missed");
        }
Esempio n. 2
0
        public void GetLastCommonAncestorOrNull_ConcreteAndNotConcreteType_ReturnsNull()
        {
            var funA = Fun.Of(CreateConstrainsNode(), SolvingNode.CreateTypeNode(Primitive.I32));
            var funB = Fun.Of(Primitive.U16, Primitive.U64);

            Assert.IsNull(funA.GetLastCommonAncestorOrNull(funB));
            Assert.IsNull(funB.GetLastCommonAncestorOrNull(funA));
        }
Esempio n. 3
0
 public static void AssertAreGenerics(this FinalizationResults result, SolvingNode targetGenericNode,
                                      params string[] varNames)
 {
     foreach (var varName in varNames)
     {
         Assert.AreEqual(targetGenericNode, result.GetVariableNode(varName).GetNonReference());
     }
 }
Esempio n. 4
0
        private static SolvingNode[] GetNonReferenced(IList <SolvingNode> nodes)
        {
            SolvingNode[] ans = new SolvingNode[nodes.Count];
            for (int i = 0; i < nodes.Count; i++)
            {
                var node = nodes[i];
                if (node.State is RefTo)
                {
                    ans[i] = node.GetNonReference();
                }
                else
                {
                    ans[i] = node;
                }
            }

            return(ans);
        }
Esempio n. 5
0
        public static Fun Of(IState[] argTypes, IState returnType)
        {
            SolvingNode[] argNodes = new SolvingNode[argTypes.Length];
            SolvingNode   retNode  = null;

            if (returnType is IType rt)
            {
                retNode = SolvingNode.CreateTypeNode(rt);
            }
            else if (returnType is RefTo retRef)
            {
                retNode = retRef.Node;
            }
            else
            {
                throw new InvalidOperationException();
            }

            for (int i = 0; i < argTypes.Length; i++)
            {
                if (argTypes[i] is IType at)
                {
                    argNodes[i] = SolvingNode.CreateTypeNode(at);
                }
                else if (argTypes[i] is RefTo aRef)
                {
                    argNodes[i] = aRef.Node;
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }


            return(new Fun(argNodes, retNode));
        }
Esempio n. 6
0
 private Fun(SolvingNode[] argNodes, SolvingNode retNode)
 {
     ArgNodes = argNodes;
     RetNode  = retNode;
 }
Esempio n. 7
0
 public static Fun Of(SolvingNode argNode, SolvingNode returnNode)
 => new Fun(new [] { argNode }, returnNode);
Esempio n. 8
0
 public static Fun Of(SolvingNode[] argNodes, SolvingNode returnNode)
 => new Fun(argNodes, returnNode);
Esempio n. 9
0
 public static Fun Of(IType[] argTypes, IType retType)
 {
     return(new Fun(
                argNodes: argTypes.Select(SolvingNode.CreateTypeNode).ToArray(),
                retNode: SolvingNode.CreateTypeNode(retType)));
 }
Esempio n. 10
0
 public Array(SolvingNode elementNode)
 {
     ElementNode = elementNode;
 }
Esempio n. 11
0
 public static Array Of(IType type)
 => new Array(SolvingNode.CreateTypeNode(type));
Esempio n. 12
0
 public static Array Of(SolvingNode node)
 => new Array(node);
Esempio n. 13
0
 public RefTo(SolvingNode node)
 {
     Node = node;
 }
Esempio n. 14
0
 public static void AssertGenericTypeIsArith(this SolvingNode node)
 {
     AssertGenericType(node, Primitive.U24, Primitive.Real, false);
 }