Skip to content

Commit

Permalink
bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Oct 11, 2024
1 parent 60f9498 commit 30bad99
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn type_collect_standalone_nested(
td: metadata::TypeDef,
set: &mut std::collections::BTreeSet<metadata::Type>,
) {
for nested in td.reader().nested_types(td) {
for (_, nested) in td.reader().nested_types(td) {
type_collect_standalone_nested(writer, nested, set);

for field in nested.fields() {
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn gen_struct_with_name(
});
}

for (index, nested_type) in writer.reader.nested_types(def).enumerate() {
for (index, nested_type) in writer.reader.nested_types(def) {
let nested_name = format!("{struct_name}_{index}");
tokens.combine(&gen_struct_with_name(
writer,
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl Writer {
}
fn scoped_name(&self, def: metadata::TypeDef) -> String {
if let Some(enclosing_type) = def.enclosing_type() {
for (index, nested_type) in self.reader.nested_types(enclosing_type).enumerate() {
for (index, nested_type) in self.reader.nested_types(enclosing_type) {
if nested_type.name() == def.name() {
return format!("{}_{index}", &self.scoped_name(enclosing_type));
}
Expand Down
13 changes: 5 additions & 8 deletions crates/libs/metadata/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum Item {
pub struct Reader {
items: BTreeMap<&'static str, BTreeMap<&'static str, Vec<Item>>>,

nested: HashMap<TypeDef, BTreeMap<&'static str, TypeDef>>,
nested: HashMap<TypeDef, BTreeMap<&'static str, (usize, TypeDef)>>,

// The reader needs to store the filter since standalone code generation needs more than just the filtered items
// in order to chase dependencies automatically. This is why `Reader::filter` can't just filter everything up front.
Expand Down Expand Up @@ -85,11 +85,8 @@ impl Reader {

for key in file.table::<NestedClass>() {
let inner = key.inner();
reader
.nested
.entry(key.outer())
.or_default()
.insert(inner.name(), inner);
let types = reader.nested.entry(key.outer()).or_default();
types.insert(inner.name(), (types.len(), inner));
}
}

Expand Down Expand Up @@ -203,7 +200,7 @@ impl Reader {
})
}

pub fn nested_types(&self, type_def: TypeDef) -> impl Iterator<Item = TypeDef> + '_ {
pub fn nested_types(&self, type_def: TypeDef) -> impl Iterator<Item = (usize, TypeDef)> + '_ {
self.nested
.get(&type_def)
.map(|map| map.values().copied())
Expand Down Expand Up @@ -262,7 +259,7 @@ impl Reader {
// TODO: this needs to be deferred via a TypeName's optional nested type name?
if let Some(outer) = enclosing {
if full_name.namespace().is_empty() {
let Some(inner) = self
let Some((_, inner)) = self
.nested
.get(&outer)
.and_then(|nested| nested.get(full_name.name()))
Expand Down

0 comments on commit 30bad99

Please sign in to comment.