/* * clones the entire chain */ public CH_closedScope(IEnumerable <Ref> items) { foreach (var itm in items) { LL_head = LL_head.chain(itm.name, itm.CH); } }
public static T findPay <T> (this LL <T> node_in, string search_name) => node_in.findNode(search_name).pay; // todo remove public static IEnumerable <LL <T> > LIFO <T> (this LL <T> node_in) { for (var node = node_in; node != null; node = node.prev) { yield return(node); } }
public static void Test1_basic_LL_tests() { LL <int> empty_int = null; foreach (var node in empty_int.chain("foo", 3).chain("bar", 4).LIFO()) { Console.WriteLine(node.name + " " + node.pay); // mainly to test chaining from null } // hmm thats neat :) // also single assignment. empty int is still null D.Assert(empty_int.LIFO().ToArray().SequenceEqual(new LL <int> [0])); D.Assert(empty_int.LIFO_shadowed().ToArray().SequenceEqual(new LL <int> [0])); AUX.AssertThrows <LL_Exception> (() => empty_int.findPay("any key -- the LL is empty ")); var zing = ((LL <string>)null). chain("v1", "val1"). chain("v2", "boioioioioiing"). chain("v1", "shadowed"); foreach (var node in zing.LIFO_shadowed()) { Console.WriteLine(node.name + " " + node.pay); } AUX.AssertThrows <LL_Exception> (() => zing.findNode("non present key")); Console.WriteLine("================= LL ok ============= "); }
preCH_deltaScope(CH_closedScope origScope, LL <preCH> origLL, LL <preCH> own, LL <preCH> extnls) { D.Assert(origScope != null); this.origScope = origScope; origLL_head = origLL; ownLL_head = own; externals = extnls; } // the readonlys need a detour over constructor
public preCH_deltaScope(CH_closedScope clSC) { D.Assert(clSC != null); origScope = clSC; foreach (var nodeCH in clSC.LL_head.LIFO_shadowed().Reverse()) { origLL_head = origLL_head.chain(nodeCH.name, new adapter_preCH(nodeCH.pay)); } }
public CH_deltaScope(CH_closedScope clsSc, LL <TypedCH> ll, LL <TypedCH> externals) { if (clsSc == null) { throw new ScopeException("origin scope can't be null"); } orig_scope = clsSc; this.ownLL_head = ll; this.externals = externals; }
public static IEnumerable <LL <T> > LIFO_shadowed <T> (this LL <T> node_in) { var seen = new HashSet <string>(); foreach (var node in node_in.LIFO()) { if (!seen.Contains(node.name)) { seen.Add(node.name); yield return(node); } } }
public static LL <T> findNode <T> (this LL <T> node_in, string search_name) { LL <T> node = node_in; while (true) { if (node == null) { throw new LL_Exception(); } if (search_name == node.name) { return(node); } node = node.prev; } }
public CH_deltaScope instantiate() // resolves all preCHs , triggers their instantiation to proper CHs // using the decl interface is too headscratchy, becuase the original order between decls and refs (not within them) would have to be reconstructed ( self shadowing ) { LL <TypedCH> CHdelt_own = null; foreach (var n in ownLL_head.LIFO().Reverse()) { CHdelt_own = CHdelt_own.chain(n.name, n.pay.CH); } LL <TypedCH> CHdelt_externals = null; foreach (var n in externals.LIFO().Reverse()) { CHdelt_externals = CHdelt_externals.chain(n.name, n.pay.CH); } return(new CH_deltaScope(origScope, CHdelt_own, CHdelt_externals)); }
public static Ref LL2Ref(LL <TypedCH> ll) => new Ref { name = ll.name, CH = ll.pay };
public static T findPay <T> (this LL <T> node_in, string search_name) => node_in.findNode(search_name).pay; // todo remove
public static LL <T> chain <T> (this LL <T> orig, string name, T pay) => new LL <T>(name, pay, orig);
static Ref LL2Ref(LL <preCH> ll) => new Ref { name = ll.name, pre_ch = ll.pay };
public LL(string name, T pay, LL <T> prev) { this.prev = prev; this.pay = pay; this.name = name; }
public readonly LL <TypedCH> LL_head = null; // empty scope CH_closedScope(LL <TypedCH> ll_in) { LL_head = ll_in; }