mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
chore: add ModuleGraph::display
This commit is contained in:
parent
03a45de495
commit
2f924527f0
2 changed files with 41 additions and 0 deletions
|
@ -336,6 +336,7 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
|
|||
log!(info "Start dependency resolution process");
|
||||
let _ = self.resolve(&mut ast, &cfg);
|
||||
log!(info "Dependency resolution process completed");
|
||||
log!("graph:\n{}", self.shared.graph.display());
|
||||
if self.parse_errors.errors.is_empty() {
|
||||
self.shared.warns.extend(self.parse_errors.warns.flush());
|
||||
} else {
|
||||
|
|
|
@ -160,6 +160,42 @@ impl ModuleGraph {
|
|||
pub fn initialize(&mut self) {
|
||||
self.0.clear();
|
||||
}
|
||||
|
||||
pub fn display_parents(
|
||||
&self,
|
||||
lev: usize,
|
||||
id: &NormalizedPathBuf,
|
||||
appeared: &mut Set<NormalizedPathBuf>,
|
||||
) -> String {
|
||||
let mut s = String::new();
|
||||
let Some(parents) = self.parents(id) else {
|
||||
return s;
|
||||
};
|
||||
for parent in parents.iter() {
|
||||
s.push_str(&format!("{}-> {}\n", " ".repeat(lev), parent.display()));
|
||||
if appeared.contains(parent) {
|
||||
continue;
|
||||
}
|
||||
s.push_str(&self.display_parents(lev + 1, parent, appeared));
|
||||
appeared.insert(parent.clone());
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
pub fn display(&self) -> String {
|
||||
let mut s = String::new();
|
||||
let mut appeared = set! {};
|
||||
for node in self.0.iter() {
|
||||
let children = self.children(&node.id);
|
||||
if !children.is_empty() || appeared.contains(&node.id) {
|
||||
continue;
|
||||
}
|
||||
s.push_str(&format!("{}\n", node.id.display()));
|
||||
s.push_str(&self.display_parents(1, &node.id, &mut appeared));
|
||||
appeared.insert(node.id.clone());
|
||||
}
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
@ -248,4 +284,8 @@ impl SharedModuleGraph {
|
|||
pub fn clone_inner(&self) -> ModuleGraph {
|
||||
self.0.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn display(&self) -> String {
|
||||
self.0.borrow().display()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue