import java.util.*;
import java.io.*;
+import MCC.Compiler;
public class GraphNode {
- public static boolean useEdgeLabels;
-
/* NodeStatus enumeration pattern ***********/
-
+
public static final NodeStatus UNVISITED = new NodeStatus("UNVISITED");
public static final NodeStatus PROCESSING = new NodeStatus("PROCESSING");
public static final NodeStatus FINISHED = new NodeStatus("FINISHED");
/* Edge *****************/
public static class Edge {
-
+
private String label;
private GraphNode target;
private GraphNode source;
int discoverytime = -1;
int finishingtime = -1; /* used for searches */
- Vector edges = new Vector();
+ Vector edges = new Vector();
Vector inedges = new Vector();
String nodelabel;
String textlabel;
- NodeStatus status = UNVISITED;
+ NodeStatus status = UNVISITED;
String dotnodeparams = new String();
Object owner = null;
boolean merge=false;
dotnodeparams = new String();
}
}
-
+
public void setStatus(NodeStatus status) {
if (status == null) {
throw new NullPointerException();
public String getTextLabel() {
return textlabel;
}
-
+
public NodeStatus getStatus() {
return this.status;
}
public static class DOTVisitor {
-
+
java.io.PrintWriter output;
int tokennumber;
int color;
-
+
private DOTVisitor(java.io.OutputStream output) {
tokennumber = 0;
color = 0;
this.output = new java.io.PrintWriter(output, true);
}
-
+
private String getNewID(String name) {
tokennumber = tokennumber + 1;
return new String (name+tokennumber);
Collection nodes;
Collection special;
-
+
public static void visit(java.io.OutputStream output, Collection nodes) {
visit(output,nodes,null);
}
visitor.nodes = nodes;
visitor.make();
}
-
+
private void make() {
output.println("digraph dotvisitor {");
output.println("\trotate=90;");
traverse();
output.println("}\n");
}
-
- private void traverse() {
+
+ private void traverse() {
Set cycleset=GraphNode.findcycles(nodes);
Iterator i = nodes.iterator();
if (nodes.contains(node)) {
for(Iterator nodeit=nonmerge(node).iterator();nodeit.hasNext();) {
GraphNode node2=(GraphNode)nodeit.next();
- String edgelabel = useEdgeLabels ? "label=\"" + edge.getLabel() + "\"" : "label=\"\"";
+ String edgelabel = Compiler.DEBUGGRAPH ? "label=\"" + edge.getLabel() + "\"" : "label=\"\"";
output.println("\t" + gn.getLabel() + " -> " + node2.getLabel() + " [" + edgelabel + edge.dotnodeparams + "];");
}
}
}
- /** This function returns the set of nodes involved in cycles.
+ /** This function returns the set of nodes involved in cycles.
* It only considers cycles containing nodes in the set 'nodes'.
*/
public static Set findcycles(Collection nodes) {
}
/**
- * DFS encapsulates the depth first search algorithm
+ * DFS encapsulates the depth first search algorithm
*/
public static class DFS {
HashMap sccmap;
HashMap sccmaprev;
- private DFS(Collection nodes) {
+ private DFS(Collection nodes) {
this.nodes = nodes;
}
/** Calculates the strong connected components for the graph composed
if (nodes == null) {
throw new NullPointerException();
}
-
+
DFS dfs = new DFS(nodes);
return dfs.go();
}
- private boolean go() {
+ private boolean go() {
Iterator i;
time = 0;
boolean acyclic=true;
i = nodes.iterator();
while (i.hasNext()) {
GraphNode gn = (GraphNode) i.next();
- gn.reset();
- }
+ gn.reset();
+ }
i = nodes.iterator();
while (i.hasNext()) {
GraphNode gn = (GraphNode) i.next();
- assert gn.getStatus() != PROCESSING;
+ assert gn.getStatus() != PROCESSING;
if (gn.getStatus() == UNVISITED) {
if (!dfs(gn))
acyclic=false;
- }
+ }
}
return acyclic;
}