Rename GLOBAL_COUNTER to GRAPHVIZ_NODE_COUNTER

As GLOBAL_COUNTER could be confusing regarding what actually does it
count.
This commit is contained in:
Aodhnait Étaín 2021-05-23 10:08:53 +01:00
parent 66dc814b4b
commit ab98d50a53
1 changed files with 6 additions and 5 deletions

View File

@ -99,7 +99,7 @@ fn main() {
match output_pretty {
Some("dot" | "graphdotviz") => expr.then(|e| {
let graph = e.create_graphviz_graph(unsafe { GLOBAL_COUNTER.next() });
let graph = e.create_graphviz_graph(unsafe { GRAPHVIZ_NODE_COUNTER.next() });
let graphviz_format = "node [shape = box, style = filled, color = \"#bfd1e5\", fontname = monospace, fontsize = 12]";
eprintln!("digraph {{\n{}\n{}\n}}", graphviz_format, graph);
}),
@ -170,7 +170,8 @@ impl Counter {
}
}
static mut GLOBAL_COUNTER: Counter = Counter::new();
// Used for numbering nodes in GraphViz printer.
static mut GRAPHVIZ_NODE_COUNTER: Counter = Counter::new();
impl Expression {
pub fn create_graphviz_graph(&self, id: usize) -> String {
@ -180,7 +181,7 @@ impl Expression {
},
Expression::Literal(_) => unreachable!(),
Expression::Unary(op, expr) => {
let expr_id = unsafe { GLOBAL_COUNTER.next() };
let expr_id = unsafe { GRAPHVIZ_NODE_COUNTER.next() };
format!("Node{} -> Node{}\nNode{} [label = \"{}\"]\n{}",
id, expr_id,
@ -188,8 +189,8 @@ impl Expression {
expr.create_graphviz_graph(expr_id))
},
Expression::Binary(op, left, right) => {
let left_id = unsafe { GLOBAL_COUNTER.next() };
let right_id = unsafe { GLOBAL_COUNTER.next() };
let left_id = unsafe { GRAPHVIZ_NODE_COUNTER.next() };
let right_id = unsafe { GRAPHVIZ_NODE_COUNTER.next() };
format!("Node{} -> {{ Node{} Node{} }}\nNode{} [label = \"{}\"]\n{}\n{}",
id, left_id, right_id,