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: add Rust generator and writer of extern "C++Qt"
Related to KDAB#577
- Loading branch information
1 parent
6493b93
commit 6d3f0cc
Showing
6 changed files
with
359 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use crate::{ | ||
generator::rust::{fragment::RustFragmentPair, signals::generate_rust_free_signal}, | ||
parser::{externcxxqt::ParsedExternCxxQt, mappings::ParsedCxxMappings}, | ||
}; | ||
use quote::quote; | ||
use syn::{Ident, Item, Result}; | ||
|
||
#[derive(Default)] | ||
pub struct GeneratedExternCxxQt { | ||
/// Module for the CXX bridge | ||
pub cxx_mod_contents: Vec<Item>, | ||
/// Items for the CXX-Qt module | ||
pub cxx_qt_mod_contents: Vec<Item>, | ||
} | ||
|
||
impl GeneratedExternCxxQt { | ||
pub fn append(&mut self, other: &mut Self) { | ||
self.cxx_mod_contents.append(&mut other.cxx_mod_contents); | ||
self.cxx_qt_mod_contents | ||
.append(&mut other.cxx_qt_mod_contents); | ||
} | ||
|
||
pub fn from( | ||
extern_cxxqt_block: &ParsedExternCxxQt, | ||
cxx_mappings: &ParsedCxxMappings, | ||
module_ident: &Ident, | ||
) -> Result<Self> { | ||
let mut generated = GeneratedExternCxxQt::default(); | ||
|
||
// 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 fragment = RustFragmentPair { | ||
cxx_bridge: vec![quote! { | ||
#(#attrs)* | ||
#unsafety extern "C++" { | ||
#(#items)* | ||
} | ||
}], | ||
implementation: vec![], | ||
}; | ||
generated | ||
.cxx_mod_contents | ||
.append(&mut fragment.cxx_bridge_as_items()?); | ||
|
||
// Build the signals | ||
for signal in &extern_cxxqt_block.signals { | ||
generated.append(&mut generate_rust_free_signal( | ||
signal, | ||
cxx_mappings, | ||
module_ident, | ||
)?); | ||
} | ||
|
||
Ok(generated) | ||
} | ||
} |
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
Oops, something went wrong.