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"); }
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)); }
public static void AssertAreGenerics(this FinalizationResults result, SolvingNode targetGenericNode, params string[] varNames) { foreach (var varName in varNames) { Assert.AreEqual(targetGenericNode, result.GetVariableNode(varName).GetNonReference()); } }
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); }
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)); }
private Fun(SolvingNode[] argNodes, SolvingNode retNode) { ArgNodes = argNodes; RetNode = retNode; }
public static Fun Of(SolvingNode argNode, SolvingNode returnNode) => new Fun(new [] { argNode }, returnNode);
public static Fun Of(SolvingNode[] argNodes, SolvingNode returnNode) => new Fun(argNodes, returnNode);
public static Fun Of(IType[] argTypes, IType retType) { return(new Fun( argNodes: argTypes.Select(SolvingNode.CreateTypeNode).ToArray(), retNode: SolvingNode.CreateTypeNode(retType))); }
public Array(SolvingNode elementNode) { ElementNode = elementNode; }
public static Array Of(IType type) => new Array(SolvingNode.CreateTypeNode(type));
public static Array Of(SolvingNode node) => new Array(node);
public RefTo(SolvingNode node) { Node = node; }
public static void AssertGenericTypeIsArith(this SolvingNode node) { AssertGenericType(node, Primitive.U24, Primitive.Real, false); }