forked from KDAB/cxx-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cxx-qt-gen: Improve attribute parsing
* Refactor so that all unknown attrributes cause errors. WIP * Refactor has_invalid_attrs function - Rename to check_attribute_validity - Refactor to return `Result<()>` and use with ? operator - Update some comments * Use check_attribute_validity when parsing bridge * Update error message to be closer to cxx message * Remove passing through attributes * Removing mutating attributes * Fix extern types generation error * Add parse_attributes function which not only checks for invalid attributes, but returns a BTreeMap of the attributes found - Started using in this in a few places to try it out - Removed check_attribute_validity function * Remove taking attributes * Add PassthroughMod struct and refactor methods - PassthroughMod is a struct which stores the components of a mod to pass through to cxx - It is parsed from the ItemMod originally stored in Parser, and then in generation, rebuilt correctly - Separate_docs has been renamed to extract_docs as it no longer mutates, and the mutable references used for it have been removed in the code - Tests have been refactored for the new PassthroughMod * Add namespace to signals and inherited
- Loading branch information
1 parent
4b23a7b
commit 8ac1f79
Showing
35 changed files
with
670 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,17 @@ | |
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use crate::{ | ||
generator::rust::{ | ||
fragment::{GeneratedRustFragment, RustFragmentPair}, | ||
signals::generate_rust_signal, | ||
}, | ||
naming::TypeNames, | ||
parser::externcxxqt::ParsedExternCxxQt, | ||
syntax::path::path_compare_str, | ||
}; | ||
use quote::quote; | ||
use syn::Result; | ||
use syn::{Attribute, Result}; | ||
|
||
impl GeneratedRustFragment { | ||
pub fn from_extern_cxx_qt( | ||
|
@@ -21,15 +21,58 @@ impl GeneratedRustFragment { | |
) -> Result<Self> { | ||
let mut generated = Self::default(); | ||
|
||
let extern_block_namespace = if let Some(namespace) = &extern_cxxqt_block.namespace { | ||
quote! { #[namespace = #namespace ] } | ||
} else { | ||
quote! {} | ||
}; | ||
|
||
// Add the pass through blocks | ||
let attrs = &extern_cxxqt_block.attrs; | ||
let unsafety = &extern_cxxqt_block.unsafety; | ||
let items = &extern_cxxqt_block.passthrough_items; | ||
let types = &extern_cxxqt_block | ||
.qobjects | ||
.iter() | ||
.map(|ty| { | ||
let namespace = if let Some(namespace) = &ty.name.namespace() { | ||
quote! { #[namespace = #namespace ] } | ||
} else { | ||
quote! {} | ||
}; | ||
let cpp_name = &ty.name.cxx_unqualified(); | ||
let rust_name = &ty.name.rust_unqualified(); | ||
let vis = &ty.declaration.vis; | ||
let ident = &ty.name.rust_unqualified(); | ||
let cxx_name = if &rust_name.to_string() == cpp_name { | ||
quote! {} | ||
} else { | ||
let cxx_name = cpp_name.to_string(); | ||
quote! { | ||
#[cxx_name = #cxx_name] | ||
} | ||
}; | ||
let docs: Vec<&Attribute> = ty | ||
.declaration | ||
.attrs | ||
.iter() | ||
.filter(|attr| path_compare_str(attr.meta.path(), &["doc"])) | ||
.collect(); | ||
quote! { | ||
#namespace | ||
#cxx_name | ||
#(#docs)* | ||
#vis type #ident; | ||
} | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
let fragment = RustFragmentPair { | ||
cxx_bridge: vec![quote! { | ||
#(#attrs)* | ||
#extern_block_namespace | ||
#unsafety extern "C++" { | ||
#(#items)* | ||
|
||
#(#types)* | ||
} | ||
}], | ||
implementation: vec![], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.