Skip to content

Commit

Permalink
Factor out Dependencies::add_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Davies committed Jun 1, 2023
1 parent b8c5a89 commit 61c6816
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
20 changes: 20 additions & 0 deletions src/bindgen/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::collections::HashSet;

use crate::bindgen::ir::{ItemContainer, Path};

use super::library::Library;

/// A dependency list is used for gathering what order to output the types.
#[derive(Default)]
pub struct Dependencies {
Expand All @@ -22,6 +24,24 @@ impl Dependencies {
}
}

pub fn add_path(&mut self, library: &Library, path: &Path) {
if let Some(items) = library.get_items(path) {
if !self.items.contains(path) {
self.items.insert(path.clone());

for item in &items {
item.deref().add_dependencies(library, self);
}
self.order.extend(items);
}
} else {
warn!(
"Can't find {}. This usually means that this type was incompatible or not found.",
path
);
}
}

pub fn sort(&mut self) {
// Sort untagged enums and opaque structs into their own layers because they don't
// depend on each other or anything else.
Expand Down
7 changes: 1 addition & 6 deletions src/bindgen/ir/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,7 @@ impl Item for Enum {
let path = Path::new(tag);

// If there is an external tag enum, then add it as a dependency.
if let Some(items) = library.get_items(&path) {
if !out.items.contains(&path) {
out.items.insert(path);
out.order.extend(items);
}
}
out.add_path(library, &path);
}
}

Expand Down
19 changes: 1 addition & 18 deletions src/bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,24 +823,7 @@ impl Type {
}
let path = generic.path();
if !generic_params.iter().any(|param| param.name() == path) {
if let Some(items) = library.get_items(path) {
if !out.items.contains(path) {
out.items.insert(path.clone());

for item in &items {
item.deref().add_dependencies(library, out);
}
for item in items {
out.order.push(item);
}
}
} else {
warn!(
"Can't find {}. This usually means that this type was incompatible or \
not found.",
path
);
}
out.add_path(library, path);
}
}
Type::Primitive(_) => {}
Expand Down

0 comments on commit 61c6816

Please sign in to comment.