@@ -12,7 +12,6 @@ use crate::ParseResult;
12
12
use proc_macro2:: { Delimiter , Group , Ident , Literal , Punct , Spacing , TokenStream , TokenTree } ;
13
13
use quote:: spanned:: Spanned ;
14
14
use quote:: { format_ident, quote, ToTokens , TokenStreamExt } ;
15
- use venial:: { Attribute , Path , PathSegment } ;
16
15
17
16
mod kv_parser;
18
17
mod list_parser;
@@ -248,14 +247,17 @@ pub(crate) fn extract_cfg_attrs(
248
247
let Some ( attr_name) = attr. get_single_path_segment ( ) else {
249
248
return false ;
250
249
} ;
250
+
251
251
// #[cfg(condition)]
252
252
if attr_name == "cfg" {
253
253
return true ;
254
254
}
255
- // #[cfg_attr(condition, attributes...)], note that there can be multiple attributes seperated by comma.
255
+
256
+ // #[cfg_attr(condition, attributes...)]. Multiple attributes can be seperated by comma.
256
257
if attr_name == "cfg_attr" && attr. value . to_token_stream ( ) . to_string ( ) . contains ( "cfg(" ) {
257
258
return true ;
258
259
}
260
+
259
261
false
260
262
} )
261
263
}
@@ -320,7 +322,10 @@ pub fn venial_parse_meta(
320
322
321
323
// util functions for handling #[func]s and #[var(get=f, set=f)]
322
324
323
- pub fn make_func_name_constants ( funcs : & [ FuncDefinition ] , class_name : & Ident ) -> Vec < TokenStream > {
325
+ pub fn make_funcs_collection_constants (
326
+ funcs : & [ FuncDefinition ] ,
327
+ class_name : & Ident ,
328
+ ) -> Vec < TokenStream > {
324
329
funcs
325
330
. iter ( )
326
331
. map ( |func| {
@@ -329,7 +334,7 @@ pub fn make_func_name_constants(funcs: &[FuncDefinition], class_name: &Ident) ->
329
334
. into_iter ( )
330
335
. collect :: < Vec < _ > > ( ) ;
331
336
332
- make_func_name_constant (
337
+ make_funcs_collection_constant (
333
338
class_name,
334
339
& func. signature_info . method_name ,
335
340
func. registered_name . as_ref ( ) ,
@@ -339,15 +344,17 @@ pub fn make_func_name_constants(funcs: &[FuncDefinition], class_name: &Ident) ->
339
344
. collect ( )
340
345
}
341
346
342
- /// Funcs can be renamed with `#[func(rename=new_name) fn f();`.
343
- /// To be able to access the renamed function name at a later point, it is saved in a string constant.
344
- pub fn make_func_name_constant (
347
+ /// Returns a `const` declaration for the funcs collection struct.
348
+ ///
349
+ /// User-defined functions can be renamed with `#[func(rename=new_name)]`. To be able to access the renamed function name from another macro,
350
+ /// a constant is used as indirection.
351
+ pub fn make_funcs_collection_constant (
345
352
class_name : & Ident ,
346
353
func_name : & Ident ,
347
354
registered_name : Option < & String > ,
348
- attributes : & [ & Attribute ] ,
355
+ attributes : & [ & venial :: Attribute ] ,
349
356
) -> TokenStream {
350
- let const_name = format_func_name_constant_name ( class_name, func_name) ;
357
+ let const_name = format_funcs_collection_constant ( class_name, func_name) ;
351
358
let const_value = match & registered_name {
352
359
Some ( renamed) => renamed. to_string ( ) ,
353
360
None => func_name. to_string ( ) ,
@@ -365,14 +372,14 @@ pub fn make_func_name_constant(
365
372
}
366
373
}
367
374
368
- /// Converts " path::class" to " path::new_class" .
369
- pub fn replace_class_in_path ( path : Path , new_class : Ident ) -> Path {
375
+ /// Converts ` path::class` to ` path::new_class` .
376
+ pub fn replace_class_in_path ( path : venial :: Path , new_class : Ident ) -> venial :: Path {
370
377
match path. segments . as_slice ( ) {
371
378
// Can't happen, you have at least one segment (the class name).
372
- [ ] => panic ! ( "unexpected: empty path" ) ,
379
+ [ ] => unreachable ! ( "empty path" ) ,
373
380
374
- [ _single] => Path {
375
- segments : vec ! [ PathSegment {
381
+ [ _single] => venial :: Path {
382
+ segments : vec ! [ venial :: PathSegment {
376
383
ident: new_class,
377
384
generic_args: None ,
378
385
tk_separator_colons: None ,
@@ -382,25 +389,25 @@ pub fn replace_class_in_path(path: Path, new_class: Ident) -> Path {
382
389
[ path @ .., _last] => {
383
390
let mut segments = vec ! [ ] ;
384
391
segments. extend ( path. iter ( ) . cloned ( ) ) ;
385
- segments. push ( PathSegment {
392
+ segments. push ( venial :: PathSegment {
386
393
ident : new_class,
387
394
generic_args : None ,
388
395
tk_separator_colons : Some ( [
389
396
Punct :: new ( ':' , Spacing :: Joint ) ,
390
397
Punct :: new ( ':' , Spacing :: Alone ) ,
391
398
] ) ,
392
399
} ) ;
393
- Path { segments }
400
+ venial :: Path { segments }
394
401
}
395
402
}
396
403
}
397
404
398
- /// Returns the name of the constant that will be autogenerated .
399
- pub fn format_func_name_constant_name ( _class_name : & Ident , func_name : & Ident ) -> Ident {
405
+ /// Returns the name of the constant inside the func "collection" struct .
406
+ pub fn format_funcs_collection_constant ( _class_name : & Ident , func_name : & Ident ) -> Ident {
400
407
format_ident ! ( "{func_name}" )
401
408
}
402
409
403
- /// Returns the name of the dummy struct that's used as container for all function name constants.
404
- pub fn format_func_name_struct_name ( class_name : & Ident ) -> Ident {
405
- format_ident ! ( "__gdext_{class_name}_Functions " )
410
+ /// Returns the name of the struct used as collection for all function name constants.
411
+ pub fn format_funcs_collection_struct ( class_name : & Ident ) -> Ident {
412
+ format_ident ! ( "__gdext_{class_name}_Funcs " )
406
413
}
0 commit comments