Skip to content

Commit

Permalink
cxx-qt-gen: remove field parsing stage as it's not used anymore
Browse files Browse the repository at this point in the history
Closes KDAB#559
  • Loading branch information
ahayzen-kdab committed Jun 13, 2023
1 parent f1e238d commit 10c80e1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 203 deletions.
161 changes: 0 additions & 161 deletions crates/cxx-qt-gen/src/generator/rust/field.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/cxx-qt-gen/src/generator/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0

pub mod field;
pub mod fragment;
pub mod inherit;
pub mod invokable;
Expand Down
10 changes: 3 additions & 7 deletions crates/cxx-qt-gen/src/generator/rust/qobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use crate::{
generator::{
naming::{namespace::NamespaceName, qobject::QObjectName},
rust::{
field::generate_rust_fields, fragment::RustFragmentPair, inherit,
invokable::generate_rust_invokables, property::generate_rust_properties,
signals::generate_rust_signals, threading,
fragment::RustFragmentPair, inherit, invokable::generate_rust_invokables,
property::generate_rust_properties, signals::generate_rust_signals, threading,
},
},
parser::qobject::ParsedQObject,
Expand Down Expand Up @@ -69,14 +68,11 @@ impl GeneratedRustQObject {
.cxx_qt_mod_contents
.push(syn::Item::Struct(qobject.qobject_struct.clone()));

// Generate methods for the properties, fields, invokables, signals
// Generate methods for the properties, invokables, signals
generated.blocks.append(&mut generate_rust_properties(
&qobject.properties,
&qobject_idents,
)?);
generated
.blocks
.append(&mut generate_rust_fields(&qobject.fields, &qobject_idents)?);
generated.blocks.append(&mut generate_rust_invokables(
&qobject.invokables,
&qobject_idents,
Expand Down
10 changes: 0 additions & 10 deletions crates/cxx-qt-gen/src/parser/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@

use syn::{Ident, Type, Visibility};

/// Describes a single field for a struct
pub struct ParsedRustField {
/// The [syn::Ident] of the field
pub ident: Ident,
/// The [syn::Type] of the field
pub ty: Type,
/// The [syn::Visibility] of the field
pub vis: Visibility,
}

/// Describes a single Q_PROPERTY for a struct
pub struct ParsedQProperty {
/// The [syn::Ident] of the property
Expand Down
28 changes: 4 additions & 24 deletions crates/cxx-qt-gen/src/parser/qobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use crate::syntax::{
};
use crate::{
parser::{
inherit::ParsedInheritedMethod,
invokable::ParsedQInvokable,
property::{ParsedQProperty, ParsedRustField},
inherit::ParsedInheritedMethod, invokable::ParsedQInvokable, property::ParsedQProperty,
signals::ParsedSignal,
},
syntax::path::path_compare_str,
Expand Down Expand Up @@ -60,8 +58,6 @@ pub struct ParsedQObject {
///
/// These will be exposed as Q_PROPERTY on the C++ object
pub properties: Vec<ParsedQProperty>,
/// List of Rust fields on the struct that need getters and setters generated
pub fields: Vec<ParsedRustField>,
/// List of specifiers to register with in QML
pub qml_metadata: Option<QmlElementMetadata>,
/// Whether locking is enabled for this QObject
Expand Down Expand Up @@ -99,7 +95,7 @@ impl ParsedQObject {

// Parse any properties in the struct
// and remove the #[qproperty] attribute
let (properties, _) = Self::parse_struct_fields(&mut qobject_struct.fields)?;
let properties = Self::parse_struct_fields(&mut qobject_struct.fields)?;

// Ensure that the QObject is marked as pub otherwise the error is non obvious
// https://github.com/KDAB/cxx-qt/issues/457
Expand All @@ -119,11 +115,6 @@ impl ParsedQObject {
inherited_methods: vec![],
passthrough_impl_items: vec![],
properties,
// Do not generate helpers for fields as they are going to move out of the bridge
//
// TODO: we may bring #[field(T, NAME)] as a way of doing this
// if we want to keep the unsafety vs safety of property changes with or without notify
fields: vec![],
qml_metadata,
locking: true,
threading: false,
Expand Down Expand Up @@ -265,11 +256,8 @@ impl ParsedQObject {
}

/// Extract all the properties from [syn::Fields] from a [syn::ItemStruct]
fn parse_struct_fields(
fields: &mut Fields,
) -> Result<(Vec<ParsedQProperty>, Vec<ParsedRustField>)> {
fn parse_struct_fields(fields: &mut Fields) -> Result<Vec<ParsedQProperty>> {
let mut properties = vec![];
let mut rust_fields = vec![];
for field in fields_to_named_fields_mut(fields)? {
// Try to find any properties defined within the struct
if let Some(index) = attribute_find_path(&field.attrs, &["qproperty"]) {
Expand All @@ -281,16 +269,10 @@ impl ParsedQObject {
ty: field.ty.clone(),
vis: field.vis.clone(),
});
} else {
rust_fields.push(ParsedRustField {
ident: field.ident.clone().unwrap(),
ty: field.ty.clone(),
vis: field.vis.clone(),
})
}
}

Ok((properties, rust_fields))
Ok(properties)
}
}

Expand Down Expand Up @@ -349,7 +331,6 @@ pub mod tests {

let qobject = ParsedQObject::from_struct(&qobject_struct, 0).unwrap();
assert_eq!(qobject.properties.len(), 2);
assert_eq!(qobject.qobject_struct.fields.len(), 3);
}

#[test]
Expand All @@ -363,7 +344,6 @@ pub mod tests {

let qobject = ParsedQObject::from_struct(&qobject_struct, 0).unwrap();
assert_eq!(qobject.properties.len(), 0);
assert_eq!(qobject.qobject_struct.fields.len(), 1);
}

#[test]
Expand Down

0 comments on commit 10c80e1

Please sign in to comment.