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.
- Loading branch information
1 parent
c2320fc
commit 2684a32
Showing
10 changed files
with
174 additions
and
160 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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
use quote::format_ident; | ||
use syn::ForeignItemFn; | ||
|
||
// SPDX-FileCopyrightText: 2022 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::naming::CombinedIdent, parser::method::ParsedMethod}; | ||
use convert_case::{Case, Casing}; | ||
use quote::format_ident; | ||
use syn::{ForeignItemFn, Ident}; | ||
|
||
/// Names for parts of a method (which could be a Q_INVOKABLE) | ||
pub struct QMethodName { | ||
|
@@ -22,32 +22,30 @@ impl From<&ParsedMethod> for QMethodName { | |
impl From<&ForeignItemFn> for QMethodName { | ||
fn from(method: &ForeignItemFn) -> Self { | ||
let ident = &method.sig.ident; | ||
Self { | ||
name: CombinedIdent::from_rust_function(ident.clone()), | ||
wrapper: CombinedIdent::wrapper_from_invokable(ident), | ||
} | ||
let name = CombinedIdent::from_rust_function(&method.attrs, &ident.clone()); | ||
let wrapper = CombinedIdent::wrapper_from_invokable(&name); | ||
Self { name, wrapper} | ||
} | ||
} | ||
|
||
impl CombinedIdent { | ||
/// For a given ident generate the Rust and C++ wrapper names | ||
fn wrapper_from_invokable(ident: &Ident) -> Self { | ||
let ident = format_ident!("{ident}_wrapper"); | ||
fn wrapper_from_invokable(ident: &CombinedIdent) -> Self { | ||
Self { | ||
cpp: format_ident!("{}", ident.to_string().to_case(Case::Camel)), | ||
rust: ident, | ||
cpp: format_ident!("{}Wrapper", ident.cpp), | ||
rust: format_ident!("{}_wrapper", ident.rust), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::collections::HashSet; | ||
|
||
use syn::parse_quote; | ||
|
||
use super::*; | ||
|
||
use std::collections::HashSet; | ||
|
||
#[test] | ||
fn test_from_impl_method() { | ||
let parsed = ParsedMethod { | ||
|
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
use quote::format_ident; | ||
use syn::{Ident, Result}; | ||
|
||
use crate::{generator::naming::CombinedIdent, naming::TypeNames}; | ||
// SPDX-FileCopyrightText: 2022 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::parser::signals::ParsedSignal; | ||
use crate::{generator::naming::CombinedIdent, naming::TypeNames}; | ||
use convert_case::{Case, Casing}; | ||
use quote::format_ident; | ||
use syn::{Ident, Result}; | ||
|
||
/// Names for parts of a Q_SIGNAL | ||
pub struct QSignalName { | ||
|
@@ -26,16 +26,16 @@ impl From<&ParsedSignal> for QSignalName { | |
} | ||
|
||
fn on_from_signal(ident: &Ident) -> Ident { | ||
format_ident!("on_{}", ident.to_string().to_case(Case::Snake)) | ||
format_ident!("on_{}", ident.to_string()) | ||
} | ||
|
||
impl CombinedIdent { | ||
fn connect_from_signal(ident: &CombinedIdent) -> Self { | ||
Self { | ||
// Use signalConnect instead of onSignal here so that we don't | ||
// create a C++ name that is similar to the QML naming scheme for signals | ||
cpp: format_ident!("{}Connect", ident.cpp.to_string().to_case(Case::Camel)), | ||
rust: format_ident!("connect_{}", ident.rust.to_string().to_case(Case::Snake)), | ||
cpp: format_ident!("{}Connect", ident.cpp.to_string()), | ||
rust: format_ident!("connect_{}", ident.rust.to_string()), | ||
} | ||
} | ||
} | ||
|
@@ -100,10 +100,10 @@ impl QSignalHelperName { | |
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
use syn::parse_quote; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_parsed_signal() { | ||
let qsignal = ParsedSignal { | ||
|
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.