Skip to content

Commit

Permalink
cxx-qt-gen: remove unused members from generated qobject
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab authored and Be-ing committed Jul 26, 2023
1 parent 5c555c2 commit f5fa90c
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 221 deletions.
19 changes: 8 additions & 11 deletions crates/cxx-qt-gen/src/generator/rust/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::collections::BTreeMap;
use crate::{
generator::{
naming::{namespace::NamespaceName, qobject::QObjectName, CombinedIdent},
rust::qobject::GeneratedRustQObjectBlocks,
rust::qobject::GeneratedRustQObject,
utils::rust::{
syn_ident_cxx_bridge_to_qualified_impl, syn_type_cxx_bridge_to_qualified,
syn_type_is_cxx_bridge_unsafe,
Expand Down Expand Up @@ -65,7 +65,7 @@ fn argument_members(args: &[Type]) -> Vec<TokenStream> {
fn generate_default_constructor(
qobject_idents: &QObjectName,
namespace: &NamespaceName,
) -> GeneratedRustQObjectBlocks {
) -> GeneratedRustQObject {
let rust_struct_ident = &qobject_idents.rust_struct.rust;

let create_rs_ident = format_ident!(
Expand All @@ -74,7 +74,7 @@ fn generate_default_constructor(
);
let namespace_internals = &namespace.internal;

GeneratedRustQObjectBlocks {
GeneratedRustQObject {
cxx_mod_contents: vec![parse_quote! {
extern "Rust" {
#[cxx_name = "createRs"]
Expand Down Expand Up @@ -146,12 +146,12 @@ pub fn generate(
namespace: &NamespaceName,
qualified_mappings: &BTreeMap<Ident, Path>,
module_ident: &Ident,
) -> Result<GeneratedRustQObjectBlocks> {
) -> Result<GeneratedRustQObject> {
if constructors.is_empty() {
return Ok(generate_default_constructor(qobject_idents, namespace));
}

let mut result = GeneratedRustQObjectBlocks::default();
let mut result = GeneratedRustQObject::default();
let namespace_internals = &namespace.internal;

let qobject_name = &qobject_idents.cpp_class.cpp;
Expand Down Expand Up @@ -368,7 +368,7 @@ mod tests {
NamespaceName::from_pair_str("ffi", &format_ident!("MyObject"))
}

fn generate_mocked(constructors: &[Constructor]) -> GeneratedRustQObjectBlocks {
fn generate_mocked(constructors: &[Constructor]) -> GeneratedRustQObject {
generate(
constructors,
&mock_name(),
Expand Down Expand Up @@ -430,7 +430,7 @@ mod tests {
// This is called by the `multiple_constructors` test so we don't have to
// assert this in two separate tests.
fn assert_empty_constructor_blocks(
blocks: &GeneratedRustQObjectBlocks,
blocks: &GeneratedRustQObject,
namespace_attr: &TokenStream,
) {
assert_tokens_eq(
Expand Down Expand Up @@ -528,10 +528,7 @@ mod tests {
);
}

fn assert_full_constructor_blocks(
blocks: &GeneratedRustQObjectBlocks,
namespace_attr: &TokenStream,
) {
fn assert_full_constructor_blocks(blocks: &GeneratedRustQObject, namespace_attr: &TokenStream) {
// the index here starts with 5, as this is part of the larger multiple_constructors test.
assert_tokens_eq(
&blocks.cxx_mod_contents[5],
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/src/generator/rust/cxxqttype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use std::collections::BTreeMap;

use crate::generator::{
naming::qobject::QObjectName, rust::qobject::GeneratedRustQObjectBlocks,
naming::qobject::QObjectName, rust::qobject::GeneratedRustQObject,
utils::rust::syn_ident_cxx_bridge_to_qualified_impl,
};
use quote::quote;
Expand All @@ -17,8 +17,8 @@ use super::fragment::RustFragmentPair;
pub fn generate(
qobject_ident: &QObjectName,
qualified_mappings: &BTreeMap<Ident, Path>,
) -> Result<GeneratedRustQObjectBlocks> {
let mut blocks = GeneratedRustQObjectBlocks::default();
) -> Result<GeneratedRustQObject> {
let mut blocks = GeneratedRustQObject::default();

let cpp_struct_ident = &qobject_ident.cpp_class.rust;
let rust_struct_ident = &qobject_ident.rust_struct.rust;
Expand Down
8 changes: 4 additions & 4 deletions crates/cxx-qt-gen/src/generator/rust/inherit.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::{
generator::{naming::qobject::QObjectName, rust::qobject::GeneratedRustQObjectBlocks},
generator::{naming::qobject::QObjectName, rust::qobject::GeneratedRustQObject},
parser::inherit::ParsedInheritedMethod,
};
use proc_macro2::TokenStream;
Expand All @@ -14,8 +14,8 @@ use syn::{Item, Result};
pub fn generate(
qobject_ident: &QObjectName,
methods: &[ParsedInheritedMethod],
) -> Result<GeneratedRustQObjectBlocks> {
let mut blocks = GeneratedRustQObjectBlocks::default();
) -> Result<GeneratedRustQObject> {
let mut blocks = GeneratedRustQObject::default();
let qobject_name = &qobject_ident.cpp_class.rust;

let mut bridges = methods
Expand Down Expand Up @@ -71,7 +71,7 @@ mod tests {
fn generate_from_foreign(
method: ForeignItemFn,
safety: Safety,
) -> Result<GeneratedRustQObjectBlocks> {
) -> Result<GeneratedRustQObject> {
let inherited_methods = vec![ParsedInheritedMethod::parse(method, safety).unwrap()];
generate(&create_qobjectname(), &inherited_methods)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/src/generator/rust/invokable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::{
generator::{
naming::{invokable::QInvokableName, qobject::QObjectName},
rust::{fragment::RustFragmentPair, qobject::GeneratedRustQObjectBlocks},
rust::{fragment::RustFragmentPair, qobject::GeneratedRustQObject},
},
parser::invokable::ParsedQInvokable,
};
Expand All @@ -17,8 +17,8 @@ use syn::Result;
pub fn generate_rust_invokables(
invokables: &Vec<ParsedQInvokable>,
qobject_idents: &QObjectName,
) -> Result<GeneratedRustQObjectBlocks> {
let mut generated = GeneratedRustQObjectBlocks::default();
) -> Result<GeneratedRustQObject> {
let mut generated = GeneratedRustQObject::default();
let cpp_class_name_rust = &qobject_idents.cpp_class.rust;

for invokable in invokables {
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/src/generator/rust/property/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod signal;
use crate::{
generator::{
naming::{property::QPropertyName, qobject::QObjectName},
rust::qobject::GeneratedRustQObjectBlocks,
rust::qobject::GeneratedRustQObject,
},
parser::property::ParsedQProperty,
};
Expand All @@ -23,8 +23,8 @@ pub fn generate_rust_properties(
properties: &Vec<ParsedQProperty>,
qobject_idents: &QObjectName,
qualified_mappings: &BTreeMap<Ident, Path>,
) -> Result<GeneratedRustQObjectBlocks> {
let mut generated = GeneratedRustQObjectBlocks::default();
) -> Result<GeneratedRustQObject> {
let mut generated = GeneratedRustQObject::default();
let mut signals = vec![];

for property in properties {
Expand Down
Loading

0 comments on commit f5fa90c

Please sign in to comment.