From 129208361df6ba90b0b6adab4ed4402d14b23e9e Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Wed, 26 Jul 2023 18:07:08 +0100 Subject: [PATCH] cxx-qt-gen: split populating mappings from extern blocks into helper This allows us to reuse it for extern "C++Qt" blocks later. Related to #577 --- crates/cxx-qt-gen/src/parser/cxxqtdata.rs | 31 +++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/crates/cxx-qt-gen/src/parser/cxxqtdata.rs b/crates/cxx-qt-gen/src/parser/cxxqtdata.rs index df379dfe2..bab4f55ee 100644 --- a/crates/cxx-qt-gen/src/parser/cxxqtdata.rs +++ b/crates/cxx-qt-gen/src/parser/cxxqtdata.rs @@ -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(())