Skip to content

Commit fac4c0d

Browse files
Switch structs to storing CommonAttrs instead of just attrs
1 parent c361163 commit fac4c0d

File tree

15 files changed

+58
-61
lines changed

15 files changed

+58
-61
lines changed

crates/cxx-qt-gen/src/generator/cpp/inherit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn generate(
2727

2828
for &method in inherited_methods {
2929
// Skip if the cfg attributes are not resolved to true
30-
if !try_eval_attributes(opt.cfg_evaluator.as_ref(), &method.cfgs)? {
30+
if !try_eval_attributes(opt.cfg_evaluator.as_ref(), &method.common_attrs.cfgs)? {
3131
continue;
3232
}
3333

crates/cxx-qt-gen/src/generator/cpp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl GeneratedCppBlocks {
7272
.iter()
7373
.filter_map(|qobject| {
7474
// Skip if the cfg attributes are not resolved to true
75-
match try_eval_attributes(opt.cfg_evaluator.as_ref(), &qobject.declaration.cfgs)
75+
match try_eval_attributes(opt.cfg_evaluator.as_ref(), &qobject.declaration.common_attrs.cfgs)
7676
{
7777
Ok(true) => {
7878
Some(GeneratedCppQObject::from(qobject, &parser.type_names, opt))

crates/cxx-qt-gen/src/generator/cpp/qenum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn generate_declaration(
3939
opt: &GeneratedOpt,
4040
) -> Result<String> {
4141
// Skip if the cfg attributes are not resolved to true
42-
if !try_eval_attributes(opt.cfg_evaluator.as_ref(), &qenum.cfgs)? {
42+
if !try_eval_attributes(opt.cfg_evaluator.as_ref(), &qenum.common_attrs.cfgs)? {
4343
return Ok(String::new());
4444
}
4545

@@ -75,7 +75,7 @@ pub fn generate_on_qobject<'a>(
7575

7676
for qenum in qenums {
7777
// Skip if the cfg attributes are not resolved to true
78-
if !try_eval_attributes(opt.cfg_evaluator.as_ref(), &qenum.cfgs)? {
78+
if !try_eval_attributes(opt.cfg_evaluator.as_ref(), &qenum.common_attrs.cfgs)? {
7979
continue;
8080
}
8181

crates/cxx-qt-gen/src/generator/cpp/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn generate_cpp_signal(
8989
let mut generated = CppSignalFragment::default();
9090

9191
// Skip if the cfg attributes are not resolved to true
92-
if !try_eval_attributes(opt.cfg_evaluator.as_ref(), &signal.cfgs)? {
92+
if !try_eval_attributes(opt.cfg_evaluator.as_ref(), &signal.common_attrs.cfgs)? {
9393
return Ok(generated);
9494
}
9595

crates/cxx-qt-gen/src/generator/rust/externcxxqt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl GeneratedRustFragment {
2222
} else {
2323
quote! {}
2424
};
25-
let extern_block_docs = &extern_cxxqt_block.docs;
25+
let extern_block_docs = &extern_cxxqt_block.common_attrs.docs;
2626

2727
// Add the pass through blocks
2828
let unsafety = &extern_cxxqt_block.unsafety;
@@ -60,6 +60,7 @@ impl GeneratedRustFragment {
6060
#[cxx_name = #cxx_name]
6161
}
6262
};
63+
// TODO! Can we make extract_docs return references, and then use here?
6364
let cfgs: Vec<&Attribute> = obj
6465
.declaration
6566
.attrs

crates/cxx-qt-gen/src/generator/rust/inherit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub fn generate(
4848
if method.safe {
4949
std::mem::swap(&mut unsafe_call, &mut unsafe_block);
5050
}
51-
let doc_comments = &method.docs;
52-
let cfgs = &method.cfgs;
51+
let doc_comments = &method.common_attrs.docs;
52+
let cfgs = &method.common_attrs.cfgs;
5353
let namespace = qobject_names.namespace_tokens();
5454

5555
syn::parse2(quote_spanned! {

crates/cxx-qt-gen/src/generator/rust/qenum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub fn generate_cxx_mod_contents(qenums: &[ParsedQEnum]) -> Vec<Item> {
1616
let item = &qenum.item;
1717
let vis = &item.vis;
1818
let variants = &item.variants;
19-
let docs = &qenum.docs;
20-
let cfgs = &qenum.cfgs;
19+
let docs = &qenum.common_attrs.docs;
20+
let cfgs = &qenum.common_attrs.cfgs;
2121

2222
let cxx_namespace = if namespace.is_none() {
2323
quote! {}

crates/cxx-qt-gen/src/generator/rust/qobject.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl GeneratedRustFragment {
2828
let namespace_idents = NamespaceName::from(qobject);
2929

3030
let mut generated = vec![
31-
generate_qobject_definitions(&qobject_names, &qobject.cfgs, &qobject.docs)?,
31+
generate_qobject_definitions(&qobject_names, &qobject.common_attrs.cfgs, &qobject.common_attrs.docs)?,
3232
generate_rust_properties(
3333
&qobject.properties,
3434
&qobject_names,
@@ -57,7 +57,7 @@ impl GeneratedRustFragment {
5757
&qobject_names,
5858
&namespace_idents,
5959
type_names,
60-
&qobject.cfgs,
60+
&qobject.common_attrs.cfgs,
6161
)?);
6262
}
6363

@@ -75,9 +75,9 @@ impl GeneratedRustFragment {
7575
&qobject_names,
7676
&namespace_idents,
7777
type_names,
78-
&qobject.cfgs,
78+
&qobject.common_attrs.cfgs,
7979
)?,
80-
cxxqttype::generate(&qobject_names, type_names, &qobject.cfgs)?,
80+
cxxqttype::generate(&qobject_names, type_names, &qobject.common_attrs.cfgs)?,
8181
]);
8282

8383
Ok(GeneratedRustFragment::flatten(generated))

crates/cxx-qt-gen/src/generator/rust/signals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ pub fn generate_rust_signal(
100100
} else {
101101
Some(quote! { unsafe })
102102
};
103-
let doc_comments = &signal.docs;
104-
let cfgs = &signal.cfgs;
103+
let doc_comments = &signal.common_attrs.docs;
104+
let cfgs = &signal.common_attrs.cfgs;
105105
let namespace = if let Some(namespace) = qobject_name.namespace() {
106106
quote_spanned! { span=> #[namespace = #namespace ] }
107107
} else {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ use crate::{
1111
syntax::{attribute::attribute_get_path, expr::expr_to_string},
1212
};
1313
use syn::{
14-
spanned::Spanned, Attribute, Error, ForeignItem, ForeignItemFn, Ident, ItemForeignMod, Result,
14+
spanned::Spanned, Error, ForeignItem, ForeignItemFn, Ident, ItemForeignMod, Result,
1515
Token,
1616
};
17+
use crate::parser::CommonAttrs;
1718

1819
/// Representation of an extern "C++Qt" block
1920
#[derive(Default)]
2021
pub struct ParsedExternCxxQt {
2122
/// The namespace of the type in C++.
2223
pub namespace: Option<String>,
23-
/// The Top level docs on the module
24-
pub docs: Vec<Attribute>,
24+
/// All the universal top level attributes for the block
25+
pub common_attrs: CommonAttrs,
2526
/// Whether this block has an unsafe token
2627
pub unsafety: Option<Token![unsafe]>,
2728
/// Items which can be passed into the extern "C++Qt" block
@@ -55,7 +56,7 @@ impl ParsedExternCxxQt {
5556

5657
let mut extern_cxx_block = ParsedExternCxxQt {
5758
namespace,
58-
docs: common_attrs.docs,
59+
common_attrs,
5960
unsafety: foreign_mod.unsafety,
6061
..Default::default()
6162
};

0 commit comments

Comments
 (0)