From c4084665e6f6c723962f95effdf0b7345d305b2c Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Thu, 21 Sep 2023 11:34:18 +0100 Subject: [PATCH] cxx-qt-gen: pass ParsedCxxMappings to signals This allows us later to query for more than just the qualified mappings, eg the namespace. --- crates/cxx-qt-gen/src/generator/rust/mod.rs | 2 +- .../src/generator/rust/property/mod.rs | 32 +++++++++++-------- .../cxx-qt-gen/src/generator/rust/qobject.rs | 22 ++++++------- .../cxx-qt-gen/src/generator/rust/signals.rs | 20 ++++++------ 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/crates/cxx-qt-gen/src/generator/rust/mod.rs b/crates/cxx-qt-gen/src/generator/rust/mod.rs index b434267a8..5334ba1fe 100644 --- a/crates/cxx-qt-gen/src/generator/rust/mod.rs +++ b/crates/cxx-qt-gen/src/generator/rust/mod.rs @@ -53,7 +53,7 @@ impl GeneratedRustBlocks { .map(|qobject| { GeneratedRustQObject::from( qobject, - &parser.cxx_qt_data.cxx_mappings.qualified, + &parser.cxx_qt_data.cxx_mappings, &parser.passthrough_module.ident, ) }) diff --git a/crates/cxx-qt-gen/src/generator/rust/property/mod.rs b/crates/cxx-qt-gen/src/generator/rust/property/mod.rs index e1215ceda..3bbe3f61f 100644 --- a/crates/cxx-qt-gen/src/generator/rust/property/mod.rs +++ b/crates/cxx-qt-gen/src/generator/rust/property/mod.rs @@ -12,17 +12,16 @@ use crate::{ naming::{property::QPropertyName, qobject::QObjectName}, rust::qobject::GeneratedRustQObject, }, - parser::property::ParsedQProperty, + parser::{mappings::ParsedCxxMappings, property::ParsedQProperty}, }; -use std::collections::BTreeMap; -use syn::{Ident, Path, Result}; +use syn::Result; use super::signals::generate_rust_signals; pub fn generate_rust_properties( properties: &Vec, qobject_idents: &QObjectName, - qualified_mappings: &BTreeMap, + cxx_mappings: &ParsedCxxMappings, ) -> Result { let mut generated = GeneratedRustQObject::default(); let mut signals = vec![]; @@ -31,7 +30,12 @@ pub fn generate_rust_properties( let idents = QPropertyName::from(property); // Getters - let getter = getter::generate(&idents, qobject_idents, &property.ty, qualified_mappings); + let getter = getter::generate( + &idents, + qobject_idents, + &property.ty, + &cxx_mappings.qualified, + ); generated .cxx_mod_contents .append(&mut getter.cxx_bridge_as_items()?); @@ -40,7 +44,12 @@ pub fn generate_rust_properties( .append(&mut getter.implementation_as_items()?); // Setters - let setter = setter::generate(&idents, qobject_idents, &property.ty, qualified_mappings); + let setter = setter::generate( + &idents, + qobject_idents, + &property.ty, + &cxx_mappings.qualified, + ); generated .cxx_mod_contents .append(&mut setter.cxx_bridge_as_items()?); @@ -55,7 +64,7 @@ pub fn generate_rust_properties( generated.append(&mut generate_rust_signals( &signals, qobject_idents, - qualified_mappings, + cxx_mappings, )?); Ok(generated) @@ -87,12 +96,9 @@ mod tests { ]; let qobject_idents = create_qobjectname(); - let generated = generate_rust_properties( - &properties, - &qobject_idents, - &BTreeMap::::default(), - ) - .unwrap(); + let generated = + generate_rust_properties(&properties, &qobject_idents, &ParsedCxxMappings::default()) + .unwrap(); // Check that we have the expected number of blocks assert_eq!(generated.cxx_mod_contents.len(), 12); diff --git a/crates/cxx-qt-gen/src/generator/rust/qobject.rs b/crates/cxx-qt-gen/src/generator/rust/qobject.rs index 89ffa6884..a58368ad7 100644 --- a/crates/cxx-qt-gen/src/generator/rust/qobject.rs +++ b/crates/cxx-qt-gen/src/generator/rust/qobject.rs @@ -3,8 +3,6 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -use std::collections::BTreeMap; - use crate::{ generator::{ naming::{namespace::NamespaceName, qobject::QObjectName}, @@ -15,10 +13,10 @@ use crate::{ }, utils::rust::syn_ident_cxx_bridge_to_qualified_impl, }, - parser::qobject::ParsedQObject, + parser::{mappings::ParsedCxxMappings, qobject::ParsedQObject}, }; use quote::quote; -use syn::{Ident, Item, Path, Result}; +use syn::{Ident, Item, Result}; use super::qenum; @@ -39,7 +37,7 @@ impl GeneratedRustQObject { pub fn from( qobject: &ParsedQObject, - qualified_mappings: &BTreeMap, + cxx_mappings: &ParsedCxxMappings, module_ident: &Ident, ) -> Result { // Create the base object @@ -56,7 +54,7 @@ impl GeneratedRustQObject { generated.append(&mut generate_rust_properties( &qobject.properties, &qobject_idents, - qualified_mappings, + cxx_mappings, )?); generated.append(&mut generate_rust_methods( &qobject.methods, @@ -69,7 +67,7 @@ impl GeneratedRustQObject { generated.append(&mut generate_rust_signals( &qobject.signals, &qobject_idents, - qualified_mappings, + cxx_mappings, )?); generated.append(&mut qenum::generate(&qobject.qenums)); @@ -95,7 +93,7 @@ impl GeneratedRustQObject { generated.append(&mut threading::generate( &qobject_idents, &namespace_idents, - qualified_mappings, + &cxx_mappings.qualified, module_ident, )?); } @@ -107,7 +105,7 @@ impl GeneratedRustQObject { if qobject.locking { let qualified_impl = syn_ident_cxx_bridge_to_qualified_impl( &qobject_idents.cpp_class.rust, - qualified_mappings, + &cxx_mappings.qualified, ); generated.cxx_qt_mod_contents.push(syn::parse_quote! { impl cxx_qt::Locking for #qualified_impl {} @@ -118,13 +116,13 @@ impl GeneratedRustQObject { &qobject.constructors, &qobject_idents, &namespace_idents, - qualified_mappings, + &cxx_mappings.qualified, module_ident, )?); generated.append(&mut cxxqttype::generate( &qobject_idents, - qualified_mappings, + &cxx_mappings.qualified, )?); Ok(generated) @@ -202,7 +200,7 @@ mod tests { let rust = GeneratedRustQObject::from( parser.cxx_qt_data.qobjects.values().next().unwrap(), - &BTreeMap::::default(), + &ParsedCxxMappings::default(), &format_ident!("ffi"), ) .unwrap(); diff --git a/crates/cxx-qt-gen/src/generator/rust/signals.rs b/crates/cxx-qt-gen/src/generator/rust/signals.rs index 815c48219..f497ca7b3 100644 --- a/crates/cxx-qt-gen/src/generator/rust/signals.rs +++ b/crates/cxx-qt-gen/src/generator/rust/signals.rs @@ -3,8 +3,6 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -use std::collections::BTreeMap; - use crate::{ generator::{ naming::{ @@ -20,7 +18,7 @@ use crate::{ parser::{mappings::ParsedCxxMappings, signals::ParsedSignal}, }; use quote::{format_ident, quote}; -use syn::{parse_quote, FnArg, Ident, Path, Result}; +use syn::{parse_quote, FnArg, Ident, Result}; pub fn generate_rust_free_signal( signal: &ParsedSignal, @@ -151,7 +149,7 @@ pub fn generate_rust_free_signal( pub fn generate_rust_signals( signals: &Vec, qobject_idents: &QObjectName, - qualified_mappings: &BTreeMap, + cxx_mappings: &ParsedCxxMappings, ) -> Result { let mut generated = GeneratedRustQObject::default(); let qobject_name = &qobject_idents.cpp_class.rust; @@ -183,7 +181,7 @@ pub fn generate_rust_signals( .map(|mut parameter| { if let FnArg::Typed(pat_type) = &mut parameter { *pat_type.ty = - syn_type_cxx_bridge_to_qualified(&pat_type.ty, qualified_mappings); + syn_type_cxx_bridge_to_qualified(&pat_type.ty, &cxx_mappings.qualified); } parameter }) @@ -195,9 +193,9 @@ pub fn generate_rust_signals( parse_quote! { &#qobject_name } }; let self_type_qualified = - syn_type_cxx_bridge_to_qualified(&self_type_cxx, qualified_mappings); + syn_type_cxx_bridge_to_qualified(&self_type_cxx, &cxx_mappings.qualified); let qualified_impl = - syn_ident_cxx_bridge_to_qualified_impl(qobject_name, qualified_mappings); + syn_ident_cxx_bridge_to_qualified_impl(qobject_name, &cxx_mappings.qualified); let mut unsafe_block = None; let mut unsafe_call = Some(quote! { unsafe }); @@ -286,7 +284,7 @@ mod tests { let generated = generate_rust_signals( &vec![qsignal], &qobject_idents, - &BTreeMap::::default(), + &ParsedCxxMappings::default(), ) .unwrap(); @@ -366,7 +364,7 @@ mod tests { let generated = generate_rust_signals( &vec![qsignal], &qobject_idents, - &BTreeMap::::default(), + &ParsedCxxMappings::default(), ) .unwrap(); @@ -440,7 +438,7 @@ mod tests { let generated = generate_rust_signals( &vec![qsignal], &qobject_idents, - &BTreeMap::::default(), + &ParsedCxxMappings::default(), ) .unwrap(); @@ -511,7 +509,7 @@ mod tests { let generated = generate_rust_signals( &vec![qsignal], &qobject_idents, - &BTreeMap::::default(), + &ParsedCxxMappings::default(), ) .unwrap();