From ab98d50a5341cceae41ede770e67ab016ca24386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodhnait=20=C3=89ta=C3=ADn?= Date: Sun, 23 May 2021 10:08:53 +0100 Subject: [PATCH] Rename GLOBAL_COUNTER to GRAPHVIZ_NODE_COUNTER As GLOBAL_COUNTER could be confusing regarding what actually does it count. --- src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index c031f48..be88fc2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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,