Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Separate trait parsing & structuring from QObject #1052

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/cxx-qt-gen/src/generator/cpp/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn expand_arguments(arguments: &[Type], type_names: &TypeNames) -> Result<String

pub fn generate(
qobject: &GeneratedCppQObject,
constructors: &[Constructor],
constructors: &[&Constructor],
base_class: String,
class_initializers: &[String],
type_names: &TypeNames,
Expand Down Expand Up @@ -287,7 +287,7 @@ mod tests {
fn constructor_without_base_arguments() {
let blocks = generate(
&qobject_for_testing(),
&[Constructor {
&[&Constructor {
arguments: vec![parse_quote! { i32 }, parse_quote! { *mut QObject }],
..mock_constructor()
}],
Expand Down Expand Up @@ -333,7 +333,7 @@ mod tests {
fn constructor_with_all_arguments() {
let blocks = generate(
&qobject_for_testing(),
&[Constructor {
&[&Constructor {
arguments: vec![parse_quote! { i8 }, parse_quote! { i16 }],
new_arguments: vec![parse_quote! { i16}, parse_quote! { i32 }],
initialize_arguments: vec![parse_quote! { i32 }, parse_quote! { i64 }],
Expand Down Expand Up @@ -385,11 +385,11 @@ mod tests {
let blocks = generate(
&qobject_for_testing(),
&[
Constructor {
&Constructor {
arguments: vec![],
..mock_constructor()
},
Constructor {
&Constructor {
arguments: vec![parse_quote! { *mut QObject }],
base_arguments: vec![parse_quote! { *mut QObject }],
..mock_constructor()
Expand Down
8 changes: 4 additions & 4 deletions crates/cxx-qt-gen/src/generator/cpp/qobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,23 @@ impl GeneratedCppQObject {
// If this type has threading enabled then add generation
//
// Note that threading also includes locking C++ generation
if qobject.threading {
if structured_qobject.threading {
// The parser phase should check that this is true
debug_assert!(qobject.locking);
debug_assert!(structured_qobject.locking);

let (initializer, mut blocks) = threading::generate(&qobject_idents)?;
generated.blocks.append(&mut blocks);
class_initializers.push(initializer);
// If this type has locking enabled then add generation
} else if qobject.locking {
} else if structured_qobject.locking {
let (initializer, mut blocks) = locking::generate()?;
generated.blocks.append(&mut blocks);
class_initializers.push(initializer);
}

generated.blocks.append(&mut constructor::generate(
&generated,
&qobject.constructors,
&structured_qobject.constructors,
base_class,
&class_initializers,
type_names,
Expand Down
10 changes: 5 additions & 5 deletions crates/cxx-qt-gen/src/generator/rust/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn unsafe_if(condition: bool) -> Option<TokenStream> {
}

pub fn generate(
constructors: &[Constructor],
constructors: &[&Constructor],
qobject_idents: &QObjectNames,
namespace: &NamespaceName,
type_names: &TypeNames,
Expand Down Expand Up @@ -463,7 +463,7 @@ mod tests {
NamespaceName::from_namespace_and_ident("qobject", &format_ident!("MyObject"))
}

fn generate_mocked(constructors: &[Constructor]) -> GeneratedRustFragment {
fn generate_mocked(constructors: &[&Constructor]) -> GeneratedRustFragment {
let mut type_names = TypeNames::mock();

type_names.mock_insert("QString", None, None, None);
Expand Down Expand Up @@ -768,8 +768,8 @@ mod tests {
#[test]
fn multiple_constructors() {
let blocks = generate_mocked(&[
mock_constructor(),
Constructor {
&mock_constructor(),
&Constructor {
arguments: vec![parse_quote! { *const QObject }],
new_arguments: vec![parse_quote! { i16 }],
initialize_arguments: vec![
Expand Down Expand Up @@ -801,7 +801,7 @@ mod tests {
#[test]
fn constructor_impl_with_unused_lifetime() {
let result = super::generate(
&[Constructor {
&[&Constructor {
lifetime: Some(parse_quote! { 'a }),
..mock_constructor()
}],
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/src/generator/rust/qobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl GeneratedRustFragment {
}

// If this type has threading enabled then add generation
if qobject.threading {
if structured_qobject.threading {
generated.append(&mut threading::generate(
&qobject_idents,
&namespace_idents,
Expand All @@ -94,7 +94,7 @@ impl GeneratedRustFragment {
//
// This could be implemented using an auto trait in the future once stable
// https://doc.rust-lang.org/beta/unstable-book/language-features/auto-traits.html
if qobject.locking {
if structured_qobject.locking {
let qualified_impl =
type_names.rust_qualified(qobject_idents.name.rust_unqualified())?;
generated.cxx_qt_mod_contents.push(syn::parse_quote! {
Expand All @@ -103,7 +103,7 @@ impl GeneratedRustFragment {
}

generated.append(&mut constructor::generate(
&qobject.constructors,
&structured_qobject.constructors,
&qobject_idents,
&namespace_idents,
type_names,
Expand Down
Loading
Loading