/// <summary> /// Process all of the reachable children and return the list of found items /// </summary> /// <param name="originalToProcess"></param> /// <remarks></remarks> private List <NativeSymbolRelationship> FindAllReachableChildrenImpl(IEnumerable <NativeSymbol> originalToProcess) { List <NativeSymbolRelationship> found = new List <NativeSymbolRelationship>(); Dictionary <NativeSymbol, bool> map = new Dictionary <NativeSymbol, bool>(); Queue <NativeSymbol> toVisit = new Queue <NativeSymbol>(originalToProcess); // First add in all of the original symbols with no parents foreach (NativeSymbol orig in originalToProcess) { found.Add(new NativeSymbolRelationship(null, orig)); } while (toVisit.Count > 0) { NativeSymbol cur = toVisit.Dequeue(); if (map.ContainsKey(cur)) { continue; } map[cur] = true; foreach (NativeSymbol child in cur.GetChildren()) { found.Add(new NativeSymbolRelationship(cur, child)); toVisit.Enqueue(child); } } return(found); }
public static string Convert(NativeSymbol sym) { string str = sym.Name; foreach (NativeSymbol child in sym.GetChildren()) { str += "(" + Convert(child) + ")"; } return(str); }
private bool IsResolved(NativeSymbol ns, Dictionary <NativeSymbol, bool?> map) { ThrowIfNull(ns); ThrowIfNull(map); // See if this has already been calculated bool?ret = false; if (map.TryGetValue(ns, out ret)) { if (ret.HasValue) { return(ret.Value); } else { // We're in a recursive call to the same type. Return true here because if another type is // not resolved then this will fall out return(true); } } // If there are no immediate children then the type is most definately resolved NativeSymbolIterator it = new NativeSymbolIterator(); List <NativeSymbol> children = new List <NativeSymbol>(ns.GetChildren()); if (children.Count == 0) { return(true); } // Add an entry into the map to indicate that we are exploring this type map.Add(ns, null); ret = true; foreach (NativeSymbol child in children) { if (!child.IsImmediateResolved || !IsResolved(child, map)) { ret = false; break; } } // Save the success map[ns] = ret; return(ret.Value); }
private string Print(NativeSymbol ns) { if (ns == null) { return("<Nothing>"); } string str = ns.Name; foreach (NativeSymbol child in ns.GetChildren()) { str += "(" + Print(child) + ")"; } return(str); }