Skip to content

Commit 84e9300

Browse files
Add support for Self inlining in extern C++Qt blocks
1 parent 8d63f02 commit 84e9300

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

crates/cxx-qt-gen/src/parser/cxxqtdata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl ParsedCxxQtData {
7373
/// If there are unresolved methods in the list, but inline is false, it will error,
7474
/// as the self inlining is only available if there is exactly one `QObject` in the block,
7575
/// and this indicates that no inlining can be done, but some `Self` types were present.
76-
fn try_inline_self_types(
76+
pub fn try_inline_self_types(
7777
inline: bool,
7878
type_to_inline: &Option<Ident>,
7979
invokables: &mut [impl DerefMut<Target = MethodFields>],

crates/cxx-qt-gen/src/parser/externcxxqt.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
//
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

6+
use crate::parser::cxxqtdata::ParsedCxxQtData;
67
use crate::{
78
parser::{
89
externqobject::ParsedExternQObject, require_attributes, signals::ParsedSignal,
910
CaseConversion,
1011
},
1112
syntax::{attribute::attribute_get_path, expr::expr_to_string},
1213
};
14+
use quote::format_ident;
1315
use syn::{spanned::Spanned, Error, ForeignItem, Ident, ItemForeignMod, Result, Token};
1416

1517
/// Representation of an extern "C++Qt" block
@@ -54,6 +56,9 @@ impl ParsedExternCxxQt {
5456
..Default::default()
5557
};
5658

59+
let mut qobjects = vec![];
60+
let mut signals = vec![];
61+
5762
// Parse any signals, other items are passed through
5863
for item in foreign_mod.items.drain(..) {
5964
match item {
@@ -74,7 +79,7 @@ impl ParsedExternCxxQt {
7479
// extern "C++Qt" signals are always inherit = true
7580
// as they always exist on an existing QObject
7681
signal.inherit = true;
77-
extern_cxx_block.signals.push(signal);
82+
signals.push(signal);
7883
} else {
7984
extern_cxx_block
8085
.passthrough_items
@@ -89,7 +94,7 @@ impl ParsedExternCxxQt {
8994
let extern_ty =
9095
ParsedExternQObject::parse(foreign_ty, module_ident, parent_namespace)?;
9196
// Pass through types separately for generation
92-
extern_cxx_block.qobjects.push(extern_ty);
97+
qobjects.push(extern_ty);
9398
} else {
9499
return Err(Error::new(
95100
foreign_ty.span(),
@@ -103,6 +108,16 @@ impl ParsedExternCxxQt {
103108
}
104109
}
105110

111+
let inline_self = qobjects.len() == 1;
112+
let inline_ident = qobjects
113+
.last()
114+
.map(|obj| format_ident!("{}", obj.name.cxx_unqualified()));
115+
116+
ParsedCxxQtData::try_inline_self_types(inline_self, &inline_ident, &mut signals)?;
117+
118+
extern_cxx_block.qobjects.extend(qobjects);
119+
extern_cxx_block.signals.extend(signals);
120+
106121
Ok(extern_cxx_block)
107122
}
108123
}

crates/cxx-qt-gen/test_inputs/signals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod ffi {
1616

1717
/// When the QTimer timeout occurs
1818
#[qsignal]
19-
pub(self) fn timeout(self: Pin<&mut QTimer>);
19+
pub(self) fn timeout(self: Pin<&mut Self>);
2020
}
2121

2222
unsafe extern "RustQt" {

0 commit comments

Comments
 (0)