Skip to content

Commit

Permalink
cxx-qt-gen: simplify CppType to only have cxx_type
Browse files Browse the repository at this point in the history
Related to KDAB#289
  • Loading branch information
ahayzen-kdab committed May 29, 2023
1 parent 2c18515 commit 7ba8837
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
22 changes: 5 additions & 17 deletions crates/cxx-qt-gen/src/generator/cpp/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&parameter.ty, cxx_mappings)?;
Expand All @@ -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
Expand All @@ -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#"
Expand All @@ -85,14 +71,16 @@ 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,
},
});

// 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());

Expand Down
7 changes: 0 additions & 7 deletions crates/cxx-qt-gen/src/generator/cpp/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CppType> {
Ok(CppType {
Expand Down Expand Up @@ -267,7 +262,6 @@ mod tests {
let ty = parse_quote! { UniquePtr<QColor> };
let cxx_ty = CppType::from(&ty, &ParsedCxxMappings::default()).unwrap();
assert_eq!(cxx_ty.as_cxx_ty(), "::std::unique_ptr<QColor>");
assert_eq!(cxx_ty.as_rust_ty(), "::std::unique_ptr<QColor>");
}

#[test]
Expand All @@ -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]
Expand Down

0 comments on commit 7ba8837

Please sign in to comment.