Skip to content

Commit

Permalink
cxx-qt-gen: do not remove CXX attributes from original signal method
Browse files Browse the repository at this point in the history
This allows us later to pass through the original method in the
generation.

Related to KDAB#662
  • Loading branch information
ahayzen-kdab authored and Be-ing committed Aug 24, 2023
1 parent 746fb7a commit 6493b93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/cxx-qt-gen/src/parser/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

use crate::parser::parameter::ParsedFunctionParameter;
use crate::syntax::attribute::attribute_take_path;
use crate::syntax::attribute::{attribute_find_path, attribute_take_path};
use crate::syntax::expr::expr_to_string;
use crate::syntax::foreignmod;
use crate::syntax::safety::Safety;
Expand Down Expand Up @@ -70,10 +70,17 @@ impl ParsedSignal {

let mut ident = CombinedIdent::from_rust_function(method.sig.ident.clone());

if let Some(attr) = attribute_take_path(&mut method.attrs, &["cxx_name"]) {
if let Some(index) = attribute_find_path(&method.attrs, &["cxx_name"]) {
ident.cpp = format_ident!(
"{}",
expr_to_string(&attr.meta.require_name_value()?.value)?
expr_to_string(&method.attrs[index].meta.require_name_value()?.value)?
);
}

if let Some(index) = attribute_find_path(&method.attrs, &["rust_name"]) {
ident.rust = format_ident!(
"{}",
expr_to_string(&method.attrs[index].meta.require_name_value()?.value)?
);
}

Expand Down Expand Up @@ -130,6 +137,7 @@ mod tests {
let signal = ParsedSignal::parse(method, Safety::Safe).unwrap();

let expected_method: ForeignItemFn = parse_quote! {
#[cxx_name = "cppReady"]
fn ready(self: Pin<&mut MyObject>);
};
assert_eq!(signal.method, expected_method);
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-gen/test_outputs/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ mod ffi {
) -> CxxQtQMetaObjectConnection;
}
unsafe extern "C++" {
#[cxx_name = "newData"]
#[rust_name = "base_class_new_data"]
fn newData(
self: Pin<&mut MyObject>,
Expand Down

0 comments on commit 6493b93

Please sign in to comment.