diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2025-02-10 11:56:58 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2025-02-10 11:56:58 +1300 |
commit | fd6b4471955dac64b7d40b7c31992c15d52b2460 (patch) | |
tree | 5b2561150e0eac0922a8ff40dd34da6a3ca76f7c /src/reports/source_hierarchy.rs | |
parent | 2d67476d48fcb33cd1c59cbc2e0f82872bc0c217 (diff) | |
download | assembler-fd6b4471955dac64b7d40b7c31992c15d52b2460.zip |
Move report-printing structs to separate module
Diffstat (limited to 'src/reports/source_hierarchy.rs')
-rw-r--r-- | src/reports/source_hierarchy.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/reports/source_hierarchy.rs b/src/reports/source_hierarchy.rs new file mode 100644 index 0000000..9478c56 --- /dev/null +++ b/src/reports/source_hierarchy.rs @@ -0,0 +1,58 @@ +use crate::*; + +use ansi::*; + + +pub struct SourceHierarchy<'a> { + pub resolver: &'a Resolver, +} + +impl<'a> SourceHierarchy<'a> { + pub fn report(&self) { + eprintln!("."); + let len = self.resolver.root_unit_ids.len(); + for (i, id) in self.resolver.root_unit_ids.iter().enumerate() { + let end = i + 1 == len; + self.report_leaf(*id, Vec::new(), end); + } + } + + fn report_leaf(&self, id: usize, mut levels: Vec<bool>, end: bool) { + // A level entry is true if all entries in that level have been printed. + for level in &levels { + match level { + false => eprint!("│ "), + true => eprint!(" "), + } + } + // The end value is true if all siblings of this entry have been printed. + match end { + false => eprint!("├── "), + true => eprint!("└── "), + } + if let Some(unit) = self.resolver.source_units.get(id) { + let path_str = &unit.source_unit.main.path.as_os_str().to_string_lossy(); + if let Some(name_str) = unit.source_unit.name() { + eprint!("{name_str}{BLUE}"); + if unit.source_unit.head.is_some() { eprint!(" +head") } + if unit.source_unit.tail.is_some() { eprint!(" +tail") } + let mut unresolved = 0; + for symbol in &self.resolver.unresolved { + if symbol.source_id == id { unresolved += 1; } + } + if unresolved > 0 { eprint!("{RED} ({unresolved})"); } + eprintln!("{NORMAL} {DIM}({path_str}){NORMAL}"); + } else { + eprintln!("{path_str}"); + } + levels.push(end); + let len = unit.child_ids.len(); + for (i, id) in unit.child_ids.iter().enumerate() { + let end = i + 1 == len; + self.report_leaf(*id, levels.clone(), end); + } + } else { + eprintln!("<error loading source unit details>"); + } + } +} |