@@ -28,7 +28,7 @@ pub fn generate_cpp_methods(
28
28
let mut generated = GeneratedCppQObjectBlocks :: default ( ) ;
29
29
let qobject_ident = qobject_idents. name . cxx_unqualified ( ) ;
30
30
for invokable in invokables {
31
- let idents = QMethodName :: from ( invokable) ;
31
+ let idents = QMethodName :: try_from ( invokable) ? ;
32
32
let return_cxx_ty = syn_type_to_cpp_return_type ( & invokable. method . sig . output , type_names) ?;
33
33
34
34
let parameters: Vec < CppNamedType > = invokable
@@ -63,7 +63,7 @@ pub fn generate_cpp_methods(
63
63
64
64
let body = format ! (
65
65
"{ident}({parameter_names})" ,
66
- ident = idents. wrapper. cpp ,
66
+ ident = idents. wrapper. cxx_unqualified ( ) ,
67
67
parameter_names = parameters
68
68
. iter( )
69
69
. map( |parameter| parameter. ident. as_str( ) )
@@ -85,7 +85,7 @@ pub fn generate_cpp_methods(
85
85
} else {
86
86
"void"
87
87
} ,
88
- ident = idents. name. cpp ,
88
+ ident = idents. name. cxx_unqualified ( ) ,
89
89
parameter_types = parameter_types,
90
90
is_qinvokable = if invokable. is_qinvokable {
91
91
"Q_INVOKABLE "
@@ -122,7 +122,7 @@ pub fn generate_cpp_methods(
122
122
} else {
123
123
"void"
124
124
} ,
125
- ident = idents. name. cpp ,
125
+ ident = idents. name. cxx_unqualified ( ) ,
126
126
body = if return_cxx_ty. is_some( ) {
127
127
format!( "return {body}" , body = body)
128
128
} else {
@@ -143,7 +143,7 @@ pub fn generate_cpp_methods(
143
143
} else {
144
144
"void"
145
145
} ,
146
- ident = idents. wrapper. cpp ,
146
+ ident = idents. wrapper. cxx_unqualified ( ) ,
147
147
) ) ) ;
148
148
}
149
149
@@ -155,27 +155,42 @@ mod tests {
155
155
use super :: * ;
156
156
157
157
use crate :: generator:: naming:: qobject:: tests:: create_qobjectname;
158
+ use crate :: naming:: Name ;
158
159
use crate :: parser:: parameter:: ParsedFunctionParameter ;
159
160
use indoc:: indoc;
160
161
use pretty_assertions:: assert_str_eq;
161
162
use quote:: format_ident;
162
163
use std:: collections:: HashSet ;
163
- use syn:: parse_quote;
164
+ use syn:: { parse_quote, ForeignItemFn } ;
164
165
165
166
#[ test]
166
167
fn test_generate_cpp_invokables ( ) {
168
+ let method1: ForeignItemFn = parse_quote ! { fn void_invokable( self : & MyObject ) ; } ;
169
+ let method2: ForeignItemFn =
170
+ parse_quote ! { fn trivial_invokable( self : & MyObject , param: i32 ) -> i32 ; } ;
171
+ let method3: ForeignItemFn = parse_quote ! { fn opaque_invokable( self : Pin <& mut MyObject >, param: & QColor ) -> UniquePtr <QColor >; } ;
172
+ let method4: ForeignItemFn =
173
+ parse_quote ! { fn specifiers_invokable( self : & MyObject , param: i32 ) -> i32 ; } ;
174
+ let method5: ForeignItemFn = parse_quote ! { fn cpp_method( self : & MyObject ) ; } ;
167
175
let invokables = vec ! [
168
176
ParsedMethod {
169
- method: parse_quote! { fn void_invokable ( self : & MyObject ) ; } ,
177
+ method: method1 . clone ( ) ,
170
178
qobject_ident: format_ident!( "MyObject" ) ,
171
179
mutable: false ,
172
180
safe: true ,
173
181
parameters: vec![ ] ,
174
182
specifiers: HashSet :: new( ) ,
175
183
is_qinvokable: true ,
184
+ name: Name :: from_rust_ident_and_attrs(
185
+ & method1. sig. ident,
186
+ & method1. attrs,
187
+ None ,
188
+ None ,
189
+ )
190
+ . unwrap( ) ,
176
191
} ,
177
192
ParsedMethod {
178
- method: parse_quote! { fn trivial_invokable ( self : & MyObject , param : i32 ) -> i32 ; } ,
193
+ method: method2 . clone ( ) ,
179
194
qobject_ident: format_ident!( "MyObject" ) ,
180
195
mutable: false ,
181
196
safe: true ,
@@ -185,9 +200,16 @@ mod tests {
185
200
} ] ,
186
201
specifiers: HashSet :: new( ) ,
187
202
is_qinvokable: true ,
203
+ name: Name :: from_rust_ident_and_attrs(
204
+ & method2. sig. ident,
205
+ & method2. attrs,
206
+ None ,
207
+ None ,
208
+ )
209
+ . unwrap( ) ,
188
210
} ,
189
211
ParsedMethod {
190
- method: parse_quote! { fn opaque_invokable ( self : Pin < & mut MyObject > , param : & QColor ) -> UniquePtr < QColor > ; } ,
212
+ method: method3 . clone ( ) ,
191
213
qobject_ident: format_ident!( "MyObject" ) ,
192
214
mutable: true ,
193
215
safe: true ,
@@ -197,9 +219,16 @@ mod tests {
197
219
} ] ,
198
220
specifiers: HashSet :: new( ) ,
199
221
is_qinvokable: true ,
222
+ name: Name :: from_rust_ident_and_attrs(
223
+ & method3. sig. ident,
224
+ & method3. attrs,
225
+ None ,
226
+ None ,
227
+ )
228
+ . unwrap( ) ,
200
229
} ,
201
230
ParsedMethod {
202
- method: parse_quote! { fn specifiers_invokable ( self : & MyObject , param : i32 ) -> i32 ; } ,
231
+ method: method4 . clone ( ) ,
203
232
qobject_ident: format_ident!( "MyObject" ) ,
204
233
mutable: false ,
205
234
safe: true ,
@@ -215,15 +244,29 @@ mod tests {
215
244
specifiers
216
245
} ,
217
246
is_qinvokable: true ,
247
+ name: Name :: from_rust_ident_and_attrs(
248
+ & method4. sig. ident,
249
+ & method4. attrs,
250
+ None ,
251
+ None ,
252
+ )
253
+ . unwrap( ) ,
218
254
} ,
219
255
ParsedMethod {
220
- method: parse_quote! { fn cpp_method ( self : & MyObject ) ; } ,
256
+ method: method5 . clone ( ) ,
221
257
qobject_ident: format_ident!( "MyObject" ) ,
222
258
mutable: false ,
223
259
safe: true ,
224
260
parameters: vec![ ] ,
225
261
specifiers: HashSet :: new( ) ,
226
262
is_qinvokable: false ,
263
+ name: Name :: from_rust_ident_and_attrs(
264
+ & method5. sig. ident,
265
+ & method5. attrs,
266
+ None ,
267
+ None ,
268
+ )
269
+ . unwrap( ) ,
227
270
} ,
228
271
] ;
229
272
let qobject_idents = create_qobjectname ( ) ;
@@ -385,8 +428,10 @@ mod tests {
385
428
386
429
#[ test]
387
430
fn test_generate_cpp_invokables_mapped_cxx_name ( ) {
431
+ let method: ForeignItemFn =
432
+ parse_quote ! { fn trivial_invokable( self : & MyObject , param: A ) -> B ; } ;
388
433
let invokables = vec ! [ ParsedMethod {
389
- method: parse_quote! { fn trivial_invokable ( self : & MyObject , param : A ) -> B ; } ,
434
+ method: method . clone ( ) ,
390
435
qobject_ident: format_ident!( "MyObject" ) ,
391
436
mutable: false ,
392
437
safe: true ,
@@ -396,6 +441,8 @@ mod tests {
396
441
} ] ,
397
442
specifiers: HashSet :: new( ) ,
398
443
is_qinvokable: true ,
444
+ name: Name :: from_rust_ident_and_attrs( & method. sig. ident, & method. attrs, None , None )
445
+ . unwrap( ) ,
399
446
} ] ;
400
447
let qobject_idents = create_qobjectname ( ) ;
401
448
0 commit comments