Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sezna committed May 22, 2024
1 parent 7dd13be commit 0bcd6ef
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions compiler/qsc_data_structures/src/namespaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ pub struct NamespaceTreeRoot {
impl std::fmt::Debug for NamespaceTreeRoot {
// manual implementation to avoid infinite loops in printing
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "NamespaceTreeRoot\n{}", self.tree.borrow().debug_print(0, &mut FxHashSet::default()))
write!(
f,
"NamespaceTreeRoot\n{}",
self.tree.borrow().debug_print(0, &mut FxHashSet::default())
)
}
}

Expand All @@ -95,7 +99,6 @@ impl std::fmt::Debug for NamespaceTreeNode {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.debug_print(0, &mut FxHashSet::default()))
}

}

impl NamespaceTreeRoot {
Expand Down Expand Up @@ -330,7 +333,11 @@ impl NamespaceTreeNode {
None
}

fn debug_print(&self, indentation_level: usize, visited_nodes: &mut FxHashSet<NamespaceId>) -> String {
fn debug_print(
&self,
indentation_level: usize,
visited_nodes: &mut FxHashSet<NamespaceId>,
) -> String {
let indentation = " ".repeat(indentation_level);

if visited_nodes.contains(&self.id) {
Expand All @@ -339,16 +346,25 @@ impl NamespaceTreeNode {

visited_nodes.insert(self.id);


let mut result = String::new();

if self.children.is_empty() {
result.push_str("empty node");
} else {
result.push_str(&format!("\n{} children: [", indentation));
for (name, node) in &self.children {
result.push_str(&format!("\n{} {}(id {}) {{", indentation, name, Into::<usize>::into(node.borrow().id)));
result.push_str(&node.borrow().debug_print(indentation_level + 2, visited_nodes).as_str());
result.push_str(&format!(
"\n{} {}(id {}) {{",
indentation,
name,
Into::<usize>::into(node.borrow().id)
));
result.push_str(
&node
.borrow()
.debug_print(indentation_level + 2, visited_nodes)
.as_str(),
);
result.push_str(",");
}
result.push_str(&format!("\n{} ]", indentation));
Expand Down

0 comments on commit 0bcd6ef

Please sign in to comment.