Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analyzer] Break infinite loops #1659

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/analyzer/ConsoleDependencyGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,37 @@ public void ShowDependencies (VertexData vertex)
Console.WriteLine ("Root dependency");
} else {
int i = 0;
var visited = new HashSet<int> ();

foreach (int index in vertex.parentIndexes) {
Console.WriteLine ("Dependency #{0}", ++i);
Console.WriteLine ($"\t{vertex.value}{SizeString (vertex)}");

var childVertex = Vertex (index);
Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);

visited.Clear ();
visited.Add (index);

while (childVertex.parentIndexes != null) {
childVertex = Vertex (childVertex.parentIndexes [0]);
int pi = 0, childIdx;

do {
childIdx = childVertex.parentIndexes [pi];
pi++;
} while (visited.Contains (childIdx) && pi < childVertex.parentIndexes.Count);

childVertex = Vertex (childIdx);

if (visited.Contains (childIdx)) {
Console.WriteLine ($"\twarning: loop to {childVertex.value}");
break;
}

visited.Add (childIdx);
Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);
}

if (Tree)
break;
}
Expand Down Expand Up @@ -175,7 +197,7 @@ static void Line ()
Console.WriteLine ();
}

static public void Header (string header, params object[] values)
public static void Header (string header, params object[] values)
{
string formatted = string.Format (header, values);
Console.WriteLine ();
Expand Down