Skip to content

Commit f265f9e

Browse files
committed
Resolve the order of dependencies in the clike language backend.
1 parent bd78bbe commit f265f9e

17 files changed

+923
-19
lines changed

.clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Specify the minimum supported Rust version
2-
msrv = "1.70"
2+
msrv = "1.74"

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ exclude = [
2222
clap = { version = "4.3", optional = true }
2323
indexmap = "2.1.0"
2424
log = "0.4"
25+
multimap = "0.10"
2526
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
2627
serde_json = "1.0"
2728
tempfile = "3"

src/bindgen/ir/item.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub enum ItemContainer {
6464
Union(Union),
6565
Enum(Enum),
6666
Typedef(Typedef),
67+
/// Generated by the language backend to resolve the order of dependencies.
68+
Declaration(Box<ItemContainer>),
6769
}
6870

6971
impl ItemContainer {
@@ -76,6 +78,7 @@ impl ItemContainer {
7678
ItemContainer::Union(ref x) => x,
7779
ItemContainer::Enum(ref x) => x,
7880
ItemContainer::Typedef(ref x) => x,
81+
ItemContainer::Declaration(ref x) => x.deref(),
7982
}
8083
}
8184
}

src/bindgen/ir/ty.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl Type {
568568
}
569569

570570
pub fn simplify_standard_types(&mut self, config: &Config) {
571-
self.visit_types(|ty| ty.simplify_standard_types(config));
571+
self.visit_types_mut(|ty| ty.simplify_standard_types(config));
572572
if let Some(ty) = self.simplified_type(config) {
573573
*self = ty;
574574
}
@@ -578,10 +578,33 @@ impl Type {
578578
if let Type::Path(ref mut generic_path) = *self {
579579
generic_path.replace_self_with(self_ty);
580580
}
581-
self.visit_types(|ty| ty.replace_self_with(self_ty))
581+
self.visit_types_mut(|ty| ty.replace_self_with(self_ty))
582582
}
583583

584-
fn visit_types(&mut self, mut visitor: impl FnMut(&mut Type)) {
584+
fn visit_types(&self, mut visitor: impl FnMut(&Type)) {
585+
match *self {
586+
Type::Array(ref ty, ..) | Type::Ptr { ref ty, .. } => visitor(ty),
587+
Type::Path(ref path) => {
588+
for generic in path.generics() {
589+
match *generic {
590+
GenericArgument::Type(ref ty) => visitor(ty),
591+
GenericArgument::Const(_) => {}
592+
}
593+
}
594+
}
595+
Type::Primitive(..) => {}
596+
Type::FuncPtr {
597+
ref ret, ref args, ..
598+
} => {
599+
visitor(ret);
600+
for arg in args {
601+
visitor(&arg.1)
602+
}
603+
}
604+
}
605+
}
606+
607+
fn visit_types_mut(&mut self, mut visitor: impl FnMut(&mut Type)) {
585608
match *self {
586609
Type::Array(ref mut ty, ..) | Type::Ptr { ref mut ty, .. } => visitor(ty),
587610
Type::Path(ref mut path) => {
@@ -627,6 +650,19 @@ impl Type {
627650
}
628651
}
629652

653+
/// Visit root paths.
654+
/// Includes self and inner types.
655+
pub fn visit_root_paths(&self, mut visitor: impl FnMut(Path)) {
656+
if let Some(path) = self.get_root_path() {
657+
visitor(path);
658+
}
659+
self.visit_types(|ty| {
660+
if let Some(path) = ty.get_root_path() {
661+
visitor(path);
662+
}
663+
});
664+
}
665+
630666
pub fn specialize(&self, mappings: &[(&Path, &GenericArgument)]) -> Type {
631667
match *self {
632668
Type::Ptr {

0 commit comments

Comments
 (0)