From 7ba88377bb677912a0346c98953b69d14cc996ed Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Mon, 29 May 2023 14:43:00 +0100 Subject: [PATCH] cxx-qt-gen: simplify CppType to only have cxx_type Related to #289 --- crates/cxx-qt-gen/src/generator/cpp/signal.rs | 22 +++++-------------- crates/cxx-qt-gen/src/generator/cpp/types.rs | 7 ------ 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/crates/cxx-qt-gen/src/generator/cpp/signal.rs b/crates/cxx-qt-gen/src/generator/cpp/signal.rs index 886cd5dd0..d63b53306 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/signal.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/signal.rs @@ -27,9 +27,7 @@ pub fn generate_cpp_signals( for signal in signals { // Generate the parameters let mut parameter_types_cpp = vec![]; - let mut parameter_types_rust = vec![]; let mut parameter_values_emitter = vec![]; - let mut parameter_values_connection = vec![]; for parameter in &signal.parameters { let cxx_ty = CppType::from(¶meter.ty, cxx_mappings)?; @@ -39,19 +37,7 @@ pub fn generate_cpp_signals( ident = parameter.ident, cxx_ty = cxx_ty.as_cxx_ty(), )); - parameter_types_rust.push(format!( - "{rust_ty} {ident}", - ident = parameter.ident, - rust_ty = cxx_ty.as_rust_ty(), - )); - parameter_values_emitter.push(format!( - "::std::move({ident})", - ident = ident_str, - )); - parameter_values_connection.push(format!( - "::std::move({ident})", - ident = ident_str, - )); + parameter_values_emitter.push(format!("::std::move({ident})", ident = ident_str,)); } // Prepare the idents @@ -74,7 +60,7 @@ pub fn generate_cpp_signals( header: format!( "void {ident}({parameters});", ident = emit_ident, - parameters = parameter_types_rust.join(", "), + parameters = parameter_types_cpp.join(", "), ), source: formatdoc! { r#" @@ -85,7 +71,7 @@ pub fn generate_cpp_signals( }} "#, ident = signal_ident, - parameters = parameter_types_rust.join(", "), + parameters = parameter_types_cpp.join(", "), parameter_values = parameter_values_emitter.join(", "), emit_ident = emit_ident, qobject_ident = qobject_ident, @@ -93,6 +79,8 @@ pub fn generate_cpp_signals( }); // Generate connection + let mut parameter_types_rust = parameter_types_cpp.clone(); + let mut parameter_values_connection = parameter_values_emitter.clone(); parameter_types_rust.insert(0, format!("{qobject_ident}&")); parameter_values_connection.insert(0, "*this".to_owned()); diff --git a/crates/cxx-qt-gen/src/generator/cpp/types.rs b/crates/cxx-qt-gen/src/generator/cpp/types.rs index 33c8761f3..c4190a8da 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/types.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/types.rs @@ -20,11 +20,6 @@ impl CppType { &self.ty } - /// Retrieve the Rust type in C++ form - pub fn as_rust_ty(&self) -> &str { - &self.ty - } - /// Construct a [CppType] from a given [syn::Type] and [ParsedCxxMappings]. pub fn from(ty: &Type, cxx_mapping: &ParsedCxxMappings) -> Result { Ok(CppType { @@ -267,7 +262,6 @@ mod tests { let ty = parse_quote! { UniquePtr }; let cxx_ty = CppType::from(&ty, &ParsedCxxMappings::default()).unwrap(); assert_eq!(cxx_ty.as_cxx_ty(), "::std::unique_ptr"); - assert_eq!(cxx_ty.as_rust_ty(), "::std::unique_ptr"); } #[test] @@ -279,7 +273,6 @@ mod tests { .insert("A".to_owned(), "A1".to_owned()); let cxx_ty = CppType::from(&ty, &cxx_mappings).unwrap(); assert_eq!(cxx_ty.as_cxx_ty(), "A1"); - assert_eq!(cxx_ty.as_rust_ty(), "A1"); } #[test]