fix(solc): use nodesiter when printing tree (#878)

This commit is contained in:
Matthias Seitz 2022-02-07 17:27:23 +01:00 committed by GitHub
parent 43cb521592
commit a0568fe44e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 15 deletions

View File

@ -334,19 +334,14 @@ impl Graph {
f: &mut W, f: &mut W,
) -> std::result::Result<(), std::fmt::Error> { ) -> std::result::Result<(), std::fmt::Error> {
let node = self.node(idx); let node = self.node(idx);
for dep in self.imported_nodes(idx) { write!(f, "{} ", utils::source_name(&node.path, &self.root).display(),)?;
let dep = self.node(*dep); node.data.fmt_version(f)?;
writeln!( write!(f, " imports:",)?;
f, for dep in self.node_ids(idx).skip(1) {
" {} ({:?}) imports {} ({:?})", writeln!(f)?;
utils::source_name(&node.path, &self.root).display(), let dep = self.node(dep);
node.data.version, write!(f, " {} ", utils::source_name(&dep.path, &self.root).display())?;
utils::source_name(&dep.path, &self.root).display(), dep.data.fmt_version(f)?;
dep.data.version
)?;
}
for dep in self.imported_nodes(idx) {
self.format_imports_list(*dep, f)?;
} }
Ok(()) Ok(())
@ -403,11 +398,9 @@ impl Graph {
// stores all files and the versions they're compatible with // stores all files and the versions they're compatible with
let mut all_candidates = Vec::with_capacity(self.edges.num_input_files); let mut all_candidates = Vec::with_capacity(self.edges.num_input_files);
// walking through the node's dep tree and filtering the versions along the way // walking through the node's dep tree and filtering the versions along the way
for idx in 0..self.edges.num_input_files { for idx in 0..self.edges.num_input_files {
let mut candidates = all_versions.iter().collect::<Vec<_>>(); let mut candidates = all_versions.iter().collect::<Vec<_>>();
// dbg!(candidates.len());
// remove all incompatible versions from the candidates list by checking the node and // remove all incompatible versions from the candidates list by checking the node and
// all its imports // all its imports
self.retain_compatible_versions(idx, &mut candidates); self.retain_compatible_versions(idx, &mut candidates);
@ -661,6 +654,18 @@ struct SolData {
version_req: Option<VersionReq>, version_req: Option<VersionReq>,
} }
impl SolData {
fn fmt_version<W: std::fmt::Write>(
&self,
f: &mut W,
) -> std::result::Result<(), std::fmt::Error> {
if let Some(ref version) = self.version {
write!(f, "({})", version.data)?;
}
Ok(())
}
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SolDataUnit<T> { pub struct SolDataUnit<T> {
loc: Location, loc: Location,