Skip to content

Commit

Permalink
cxx-qt-gen: split populating mappings from extern blocks into helper
Browse files Browse the repository at this point in the history
This allows us to reuse it for extern "C++Qt" blocks later.

Related to KDAB#577
  • Loading branch information
ahayzen-kdab committed Jul 26, 2023
1 parent d22007d commit 1292083
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions crates/cxx-qt-gen/src/parser/cxxqtdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,27 @@ impl ParsedCxxQtData {

// If there is a foreign mod then process it
if let Item::ForeignMod(foreign_mod) = &item {
// Retrieve a namespace from the mod or the bridge
let block_namespace =
if let Some(index) = attribute_find_path(&foreign_mod.attrs, &["namespace"]) {
expr_to_string(&foreign_mod.attrs[index].meta.require_name_value()?.value)?
} else {
bridge_namespace.to_owned()
};
self.populate_mappings_from_foreign_mod_item(foreign_mod)?;
}

// Read each of the types in the mod (type A;)
for foreign_type in foreign_mod_to_foreign_item_types(foreign_mod)? {
self.populate_mappings(&foreign_type.ident, &foreign_type.attrs, &block_namespace)?;
}
Ok(())
}

fn populate_mappings_from_foreign_mod_item(
&mut self,
foreign_mod: &ItemForeignMod,
) -> Result<()> {
// Retrieve a namespace from the mod or the bridge
let block_namespace =
if let Some(index) = attribute_find_path(&foreign_mod.attrs, &["namespace"]) {
expr_to_string(&foreign_mod.attrs[index].meta.require_name_value()?.value)?
} else {
self.namespace.to_owned()
};

// Read each of the types in the mod (type A;)
for foreign_type in foreign_mod_to_foreign_item_types(foreign_mod)? {
self.populate_mappings(&foreign_type.ident, &foreign_type.attrs, &block_namespace)?;
}

Ok(())
Expand Down

0 comments on commit 1292083

Please sign in to comment.