public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) { return(cachedGraph); } cachedGraph = new DependencyGraph(); foreach (var method in Methods) { cachedGraph.AddVertex(new DependencyVertex(method)); } foreach (var field in Fields) { cachedGraph.AddVertex(new DependencyVertex(field)); } foreach (var method in Methods) { foreach (var methodUse in method.MethodUses) { cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(methodUse))); } foreach (var fieldUse in method.FieldUses) { cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(fieldUse))); } } return(cachedGraph); }
public DependencyGraph BuildDependencyGraph() { if (_graphCache != null) { return(_graphCache); } var g = new DependencyGraph(); foreach (var method in Methods) { g.AddVertex(new DependencyVertex(method)); } foreach (var field in Fields) { g.AddVertex(new DependencyVertex(field)); } foreach (var method in Methods) { foreach (var methodUse in method.MethodUses) { g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(methodUse))); } foreach (var fieldUse in method.FieldUses) { g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(fieldUse))); } } _graphCache = g; return(g); }
public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) { return(cachedGraph); } this.cachedGraph = new DependencyGraph(); foreach (var t in types) { cachedGraph.AddVertex(new DependencyVertex(t)); } foreach (var t in types) { foreach (var dependType in t.GetUsedTypes()) { if (dependType != t && dependType.Namespace == t.Namespace) { cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(t), new DependencyVertex(dependType))); } } } return(cachedGraph); }
public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) { return(cachedGraph); } cachedGraph = new DependencyGraph(); foreach (var ns in Namespaces) { cachedGraph.AddVertex(new DependencyVertex(ns)); foreach (var type in ns.Types) { var types = type.GetUsedTypes(); foreach (var dependType in types) { if (dependType != type && dependType.Namespace.Assembly == type.Namespace.Assembly) { cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(type.Namespace), new DependencyVertex(dependType.Namespace))); } } } } return(cachedGraph); }
public DependencyGraph BuildDependencyGraph() { if (_graphCache != null) return _graphCache; var g = new DependencyGraph(); foreach (var ns in Namespaces) { g.AddVertex(new DependencyVertex(ns)); } foreach (var ns in Namespaces) { foreach (var type in ns.Types) { var types = type.GetUses(); foreach (var dependType in types) { if (dependType != type && dependType.Namespace.Module == type.Namespace.Module) g.AddEdge(new DependencyEdge(new DependencyVertex(type.Namespace), new DependencyVertex(dependType.Namespace))); } } } _graphCache = g; return g; }
public DependencyGraph BuildDependencyGraph() { if (_graphCache != null) { return(_graphCache); } var g = new DependencyGraph(); foreach (var type in Types) { g.AddVertex(new DependencyVertex(type)); } foreach (var type in Types) { var types = type.GetUses(); foreach (var dependType in types) { if (dependType != type && dependType.Namespace == type.Namespace) { g.AddEdge(new DependencyEdge(new DependencyVertex(type), new DependencyVertex(dependType))); } } } _graphCache = g; return(g); }
private void FilterByType(string typeName, DependencyGraph newGraph) { TypeInfo previousType = null; var thisType = _currentGraph.Edges.FirstOrDefault(x => string.Equals(x.Source.Name, typeName))?.Source ?? _currentGraph.Edges.FirstOrDefault(x => string.Equals(x.Target.Name, typeName))?.Target; while (thisType != null && !string.Equals(thisType.Type.FullName, _selectedType.FullName)) { var type = thisType; var parent = previousType; var edgesToUse = previousType == null ? _currentGraph.Edges.Where(x => string.Equals(x.Source.Name, type.Name)) : _currentGraph.Edges.Where(x => string.Equals(x.Target.Name, parent.Name) && string.Equals(x.Source.Name, type.Name)); foreach (var edge in edgesToUse) { if (!newGraph.Vertices.Contains(edge.Source)) { newGraph.AddVertex(edge.Source); } if (!newGraph.Vertices.Contains(edge.Target)) { newGraph.AddVertex(edge.Target); } newGraph.AddEdge(edge); } previousType = thisType; thisType = thisType.Parent; } }
private void FilterByAssemblies(DependencyGraph newGraph) { var matchingEdges = _currentGraph.Edges.Where(x => ReferencedAssemblies.Any(y => y.ShouldShow && x.Source.Assembly == y.AssemblyName) && ReferencedAssemblies.Any(y => y.ShouldShow && x.Target.Assembly == y.AssemblyName)); foreach (var edge in matchingEdges) { if (!newGraph.Vertices.Contains(edge.Source)) { newGraph.AddVertex(edge.Source); } if (!newGraph.Vertices.Contains(edge.Target)) { newGraph.AddVertex(edge.Target); } newGraph.AddEdge(edge); } }
public Day14() { foreach (string line in File.ReadAllLines("Inputs/Day14.txt")) { (string node, int value) ParseNode(string entry) { string[] parts = entry.Split(); return(parts[1], int.Parse(parts[0])); } string[] split = line.Split(" => "); string sources = split[0]; string sink = split[1]; (string sinkName, int sinkValue2) = ParseNode(sink); foreach (string source in sources.Split(", ")) { (string sourceName, int sourceValue2) = ParseNode(source); _graph.AddEdge(sourceName, sinkName, sourceValue2, sinkValue2); } } }
private void BuildDepGraph(DependencyGraph <string> graph, Dictionary <string, string> loadedClauses, IClause clause, string queryName, bool unCheckHasNode, bool notSetToNode = false) { if (unCheckHasNode || !graph.HasNode(queryName)) { foreach (var depend in this.Factory.GetDependNames(clause.Query)) { if (!loadedClauses.ContainsKey(depend)) { var newClause = new NamedClause(this.Factory, depend); loadedClauses.Add(newClause.QueryName, newClause.Query); BuildDepGraph(graph, loadedClauses, newClause, newClause.QueryName, false); } if (notSetToNode) { graph.AddNode(depend); } else { graph.AddEdge(depend, queryName); } } } }
private static void EmitStructures() { StreamWriter file = GetOutputFile("types"); // build dependency graph DependencyGraph dg = new DependencyGraph(); foreach (Peer peer in peer_map.Peers) { dg.AddNode(peer); // peer depends on nearest base if (peer.NearestBase != null) { dg.AddEdge(peer.NearestBase, peer); } // peer depends on any value types used for fields foreach (PeerField field in peer.Fields) { if (field.Peer.IsValueType) { dg.AddEdge(field.Peer, peer); } } } // write structures in order foreach (Peer peer in dg.TopologicalSort()) { if (peer.IsOpaque) { continue; } if (peer.IsEnum) { file.WriteLine("typedef {0} {1};", peer.UnderlyingPeer.Name, peer.Name); file.WriteLine("enum _{0} {{", peer.Name); ArrayList enum_lines = new ArrayList(); foreach (string name in peer.EnumConstants.Keys) { enum_lines.Add(String.Format("\t{0}_{1} = {2}", peer.Name, name, peer.EnumConstants[name] )); } file.WriteLine("{0}\n}};\n", Join(",\n", enum_lines)); } else { file.WriteLine("typedef struct _{0} {{", peer.Name); // base type if (peer.NearestBase != null) { file.WriteLine("\t{0} __base;", peer.NearestBase.Name); file.WriteLine(); } // fields foreach (PeerField field in peer.Fields) { bool use_struct = true; if (field.Peer.IsValueType || field.Peer.IsOpaque) { use_struct = false; } file.WriteLine("\t{0}{1}{2};", use_struct ? "struct _" : "", field.Peer.GetTypedef(field.Peer.IsValueType ? 0 : 1), field.Name ); } file.WriteLine("}} {0};\n", peer.Name); } } }
public DependencyGraph BuildDependencyGraph() { if (_graphCache != null) return _graphCache; var g = new DependencyGraph(); foreach (var method in Methods) { g.AddVertex(new DependencyVertex(method)); } foreach (var field in Fields) { g.AddVertex(new DependencyVertex(field)); } foreach (var method in Methods) { foreach (var methodUse in method.MethodUses) { g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(methodUse))); } foreach (var fieldUse in method.FieldUses) { g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(fieldUse))); } } _graphCache = g; return g; }
public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) return cachedGraph; this.cachedGraph = new DependencyGraph(); foreach (var t in types) { cachedGraph.AddVertex(new DependencyVertex(t)); } foreach (var t in types) { foreach (var dependType in t.GetUsedTypes()) { if (dependType != t && dependType.Namespace == t.Namespace) cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(t), new DependencyVertex(dependType))); } } return cachedGraph; }
private static void EmitStructures () { StreamWriter file = GetOutputFile ("types"); // build dependency graph DependencyGraph dg = new DependencyGraph (); foreach (Peer peer in peer_map.Peers) { dg.AddNode (peer); // peer depends on nearest base if (peer.NearestBase != null) dg.AddEdge (peer.NearestBase, peer); // peer depends on any value types used for fields foreach (PeerField field in peer.Fields) { if (field.Peer.IsValueType) dg.AddEdge (field.Peer, peer); } } // write structures in order foreach (Peer peer in dg.TopologicalSort ()) { if (peer.IsOpaque) continue; if (peer.IsEnum) { file.WriteLine ("typedef {0} {1};", peer.UnderlyingPeer.Name, peer.Name); file.WriteLine ("enum _{0} {{", peer.Name); ArrayList enum_lines = new ArrayList (); foreach (string name in peer.EnumConstants.Keys) { enum_lines.Add (String.Format ("\t{0}_{1} = {2}", peer.Name, name, peer.EnumConstants[name] )); } file.WriteLine ("{0}\n}};\n", Join (",\n", enum_lines)); } else { file.WriteLine ("typedef struct _{0} {{", peer.Name); // base type if (peer.NearestBase != null) { file.WriteLine ("\t{0} __base;", peer.NearestBase.Name); file.WriteLine (); } // fields foreach (PeerField field in peer.Fields) { bool use_struct = true; if (field.Peer.IsValueType || field.Peer.IsOpaque) use_struct = false; file.WriteLine ("\t{0}{1}{2};", use_struct ? "struct _" : "", field.Peer.GetTypedef (field.Peer.IsValueType ? 0 : 1), field.Name ); } file.WriteLine ("}} {0};\n", peer.Name); } } }
internal void Validate() { foreach (Binding binding in bindings) binding.Validate(); foreach (Resource resource in resources.Values) resource.Validate(); DependencyGraph graph = new DependencyGraph(controllers); foreach (Resource resource in resources.Values) foreach (ControllerType providingController in resource.Providers) { foreach (ControllerType consumer in resource.Dependents) graph.AddEdge(consumer, providingController); foreach (ControllerType consumer in resource.RequiredBy) graph.AddEdge(consumer, providingController); } if (!graph.TopologicalSort()) engine.RaiseResourceLoop(verb + ' ' + fullBindingUrl, controllers); }
/// <summary> /// Method to set bindpoints order depending on the parameters, priority, etc... /// </summary> private void SortBindPoints() { DependencyGraph graph = new DependencyGraph(engine, bindPointsList); foreach (Resource resource in resources.Values) { resource.Validate(); foreach (IMethodsBindPointDesc providingBindPoint in resource.Providers) { foreach (IMethodsBindPointDesc consumer in resource.Dependents) graph.AddEdge(providingBindPoint, consumer); foreach (IMethodsBindPointDesc consumer in resource.RequiredBy) graph.AddEdge(providingBindPoint, consumer); } } if (!graph.TopologicalSort(out bindPointsList)) { engine.RaiseResourceLoop(string.Empty, bindPointsList.Select(bpd => bpd.Controller)); } StringBuilder tempsb = bindPointsList.Aggregate(new StringBuilder(),(oldStr,bpd) => oldStr.Append(bpd.Controller.ControllerTypeName).Append(":").Append(bpd.Target).Append("\r\n")); var securityControllers = new List<IMethodsBindPointDesc>(); int i = 0; while (i < bindPointsList.Count) if (bindPointsList[i].Controller.IsSecurity) { securityControllers.Add(bindPointsList[i]); bindPointsList.RemoveAt(i); } else i++; // we can't just sort, because the standard sort may re-arrange the existing order. // we just want to move all security controllers to the top of the chain bindPointsList.InsertRange(0, securityControllers); }
private void FillTypeInfoGraph(Type type, DependencyGraph rootTypeInfo, TypeInfo parent = null) { try { var enumerableEntryType = IsTypeOfEnumerableKind(type) ? GetEnumerableEntryType(type) : null; if (!ShouldProcessType(type, enumerableEntryType)) { return; } var typeInfo = GenerateTypeInfo(type, parent, enumerableEntryType); if (rootTypeInfo.Vertices.Any(x => x.Equals(typeInfo)) && parent != null) { var vert = rootTypeInfo.Vertices.First(x => x.Equals(typeInfo)); var matchingEdge = rootTypeInfo.Edges.FirstOrDefault(x => x.Source.Equals(parent) && x.Target.Equals(vert)); if (matchingEdge == null && !parent.Equals(vert)) { rootTypeInfo.AddEdge(new Edge <TypeInfo>(parent, vert)); } } else { rootTypeInfo.AddVertex(typeInfo); if (parent != null) { var matchingEdge = rootTypeInfo.Edges.FirstOrDefault(x => x.Source.Equals(parent) && x.Target.Equals(typeInfo)); if (matchingEdge == null) { rootTypeInfo.AddEdge(new Edge <TypeInfo>(parent, typeInfo)); } } if (typeInfo.DeepDigType) { ProcessBaseTypes(type, rootTypeInfo, typeInfo); ProcessInterfaces(type, rootTypeInfo, typeInfo); ProcessKnownTypeAttributes(type, rootTypeInfo, typeInfo); ProcessCustomAttributes(type, rootTypeInfo, typeInfo); ProcessConstructors(type, rootTypeInfo, typeInfo); ProcessFields(type, rootTypeInfo, typeInfo); ProcessMethods(type, rootTypeInfo, typeInfo); ProcessEvents(type, rootTypeInfo, typeInfo); ProcessGenericArguments(type, rootTypeInfo, typeInfo); ProcessNetstedTypes(type, rootTypeInfo, typeInfo); ProcessProperties(type, rootTypeInfo, typeInfo); ProcessMembersAttributes(type.GetMembers(), rootTypeInfo, typeInfo); //ProcessChilds(type, rootTypeInfo, typeInfo); } if (enumerableEntryType != null) { FillTypeInfoGraph(enumerableEntryType, rootTypeInfo, typeInfo); } } } catch { } }
private void FillTypeInfoGraph(MemberInfo type, DependencyGraph rootTypeInfo, TypeInfo parent = null) { var typeInfo = GenerateTypeInfo(type, parent); if (rootTypeInfo.Vertices.Any(x => x.Equals(typeInfo)) && parent != null) { var vert = rootTypeInfo.Vertices.First(x => x.Equals(typeInfo)); var matchingEdge = rootTypeInfo.Edges.FirstOrDefault(x => x.Source.Equals(parent) && x.Target.Equals(vert)); if (matchingEdge == null && !parent.Equals(vert)) { rootTypeInfo.AddEdge(new Edge <TypeInfo>(parent, vert)); } } else { rootTypeInfo.AddVertex(typeInfo); if (parent != null) { var matchingEdge = rootTypeInfo.Edges.FirstOrDefault(x => x.Source.Equals(parent) && x.Target.Equals(typeInfo)); if (matchingEdge == null) { rootTypeInfo.AddEdge(new Edge <TypeInfo>(parent, typeInfo)); } } switch (type.MemberType) { case MemberTypes.Property: FillTypeInfoGraph(((PropertyInfo)type).PropertyType, rootTypeInfo, typeInfo); break; case MemberTypes.Constructor: break; case MemberTypes.Event: FillTypeInfoGraph(((EventInfo)type).EventHandlerType, rootTypeInfo, typeInfo); break; case MemberTypes.Field: FillTypeInfoGraph(((FieldInfo)type).FieldType, rootTypeInfo, typeInfo); break; case MemberTypes.Method: var methodInfo = type as MethodInfo; FillTypeInfoGraph(methodInfo.ReturnType, rootTypeInfo, typeInfo); var methodParameters = methodInfo.GetParameters(); foreach (var parameter in methodParameters) { FillTypeInfoGraph(parameter.ParameterType, rootTypeInfo, typeInfo); } var methodBody = methodInfo.GetMethodBody(); if (methodBody == null) { break; } foreach (var localVariable in methodBody.LocalVariables) { FillTypeInfoGraph(localVariable.LocalType, rootTypeInfo, typeInfo); } break; case MemberTypes.TypeInfo: break; case MemberTypes.Custom: break; case MemberTypes.NestedType: break; case MemberTypes.All: break; default: throw new ArgumentOutOfRangeException(); } } }
public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) return cachedGraph; cachedGraph = new DependencyGraph(); foreach (var method in Methods) cachedGraph.AddVertex(new DependencyVertex(method)); foreach (var field in Fields) cachedGraph.AddVertex(new DependencyVertex(field)); foreach (var method in Methods) { foreach (var methodUse in method.MethodUses) cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(methodUse))); foreach (var fieldUse in method.FieldUses) cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(fieldUse))); } return cachedGraph; }
public DependencyGraph Build() { projs.Keys.ForEach(p => { p.Project = new Project(p.Name, p.LibraryName, p.Guid, p.Filename, p.Languages); p.Project.Names.AddRange(p.Names.Where(n => !p.Project.Names.Contains(n)) .OrderBy(n => n, StringComparer.CurrentCultureIgnoreCase)); p.Project.LibraryNames.AddRange(p.LibraryNames.Where(n => !p.Project.LibraryNames.Contains(n)) .OrderBy(n => n, StringComparer.CurrentCultureIgnoreCase)); p.Ignored = Ignore(p.Project); }); CreateInitialProjects(); // Create project references first so we can create the entries as Project if possible CreateProjectReferences(); CreateLibraryReferences(); var libraries = db.QueryAll(); libraries.Where(l => !l.Languages.Any()) .ForEach(l => l.Languages.Add("Unknown")); libraries.ForEach(UpdateIsLocal); libraries.Sort(Library.NaturalOrdering); dependencies.Sort(Dependency.NaturalOrdering); RuleUtils.ReportUnusedConfig(warnings, "ignore", config.Ignores.Select(i => i.Location), usedIgnores); var graph = new DependencyGraph(); libraries.ForEach(p => graph.AddVertex(p)); dependencies.ForEach(d => graph.AddEdge(d)); return graph; }