@@ -15,8 +15,7 @@ use svd_parser::expand::{
15
15
16
16
use crate :: config:: Config ;
17
17
use crate :: util:: {
18
- self , ident, ident_to_path, path_segment, replace_suffix, type_path, unsuffixed, FullName ,
19
- U32Ext ,
18
+ self , ident, ident_to_path, path_segment, type_path, unsuffixed, DimSuffix , FullName , U32Ext ,
20
19
} ;
21
20
use anyhow:: { anyhow, Result } ;
22
21
use syn:: punctuated:: Punctuated ;
@@ -55,7 +54,10 @@ pub fn render(
55
54
if let MaybeArray :: Array ( info, array_info) = register {
56
55
if let Some ( dim_index) = & array_info. dim_index {
57
56
let index: Cow < str > = dim_index. first ( ) . unwrap ( ) . into ( ) ;
58
- name = replace_suffix ( & info. fullname ( config. ignore_groups ) , & index) . into ( )
57
+ name = info
58
+ . fullname ( config. ignore_groups )
59
+ . expand_dim ( & index)
60
+ . into ( )
59
61
}
60
62
}
61
63
}
@@ -465,15 +467,14 @@ fn render_register_mod_debug(
465
467
if field_access. can_read ( ) && f. read_action . is_none ( ) {
466
468
if let Field :: Array ( _, de) = & f {
467
469
for suffix in de. indexes ( ) {
468
- let f_name_n =
469
- field_accessor ( & util:: replace_suffix ( & f. name , & suffix) , config, span) ;
470
+ let f_name_n = field_accessor ( & f. name . expand_dim ( & suffix) , config, span) ;
470
471
let f_name_n_s = format ! ( "{f_name_n}" ) ;
471
472
r_debug_impl. extend ( quote ! {
472
473
. field( #f_name_n_s, & format_args!( "{}" , self . #f_name_n( ) . #bit_or_bits( ) ) )
473
474
} ) ;
474
475
}
475
476
} else {
476
- let f_name = util :: replace_suffix ( & f. name , "" ) ;
477
+ let f_name = f. name . remove_dim ( ) ;
477
478
let f_name = field_accessor ( & f_name, config, span) ;
478
479
let f_name_s = format ! ( "{f_name}" ) ;
479
480
r_debug_impl. extend ( quote ! {
@@ -641,7 +642,7 @@ pub fn fields(
641
642
return Err ( anyhow ! ( "incorrect field {}" , f. name) ) ;
642
643
}
643
644
644
- let name = util :: replace_suffix ( & f. name , "" ) ;
645
+ let name = f. name . remove_dim ( ) ;
645
646
let name_snake_case = field_accessor (
646
647
if let Field :: Array (
647
648
_,
@@ -694,7 +695,13 @@ pub fn fields(
694
695
ev = ( * index. evs . get ( epath) . unwrap ( ) ) . clone ( ) ;
695
696
}
696
697
} else if let Some ( path) = fdpath. as_ref ( ) {
697
- epath = Some ( path. new_enum ( ev. name . clone ( ) . unwrap_or_else ( || path. name . clone ( ) ) ) ) ;
698
+ epath = Some (
699
+ path. new_enum (
700
+ ev. name
701
+ . clone ( )
702
+ . unwrap_or_else ( || path. name . remove_dim ( ) . into ( ) ) ,
703
+ ) ,
704
+ ) ;
698
705
}
699
706
lookup_results. push ( ( ev, epath) ) ;
700
707
}
@@ -914,12 +921,7 @@ pub fn fields(
914
921
}
915
922
EV :: Derived ( _, base) => {
916
923
let base_ident = if config. field_names_for_enums {
917
- ident (
918
- & util:: replace_suffix ( & base. field ( ) . name , "" ) ,
919
- config,
920
- fmt,
921
- span,
922
- )
924
+ ident ( & base. field ( ) . name . remove_dim ( ) , config, fmt, span)
923
925
} else {
924
926
ident ( & base. name , config, fmt, span)
925
927
} ;
@@ -980,7 +982,7 @@ pub fn fields(
980
982
// and value if necessary.
981
983
982
984
// generate pub use field_1 reader as field_2 reader
983
- let base_field = util :: replace_suffix ( & base. field . name , "" ) ;
985
+ let base_field = base. field . name . remove_dim ( ) ;
984
986
let base_r = ident ( & base_field, config, "field_reader" , span) ;
985
987
if !reader_derives. contains ( & reader_ty) {
986
988
let base_path = base_syn_path ( base, & fpath, & base_r, config) ?;
@@ -1002,7 +1004,7 @@ pub fn fields(
1002
1004
1003
1005
if let Field :: Array ( f, de) = & f {
1004
1006
let increment = de. dim_increment ;
1005
- let doc = util :: replace_suffix ( & description, & brief_suffix) ;
1007
+ let doc = description. expand_dim ( & brief_suffix) ;
1006
1008
let first_name = svd:: array:: names ( f, de) . next ( ) . unwrap ( ) ;
1007
1009
let note = format ! ( "NOTE: `n` is number of field in register. `n == 0` corresponds to `{first_name}` field" ) ;
1008
1010
let offset_calc = calculate_offset ( increment, offset, true ) ;
@@ -1182,12 +1184,7 @@ pub fn fields(
1182
1184
}
1183
1185
EV :: Derived ( _, base) => {
1184
1186
let base_ident = if config. field_names_for_enums {
1185
- ident (
1186
- & util:: replace_suffix ( & base. field ( ) . name , "" ) ,
1187
- config,
1188
- fmt,
1189
- span,
1190
- )
1187
+ ident ( & base. field ( ) . name . remove_dim ( ) , config, fmt, span)
1191
1188
} else {
1192
1189
ident ( & base. name , config, fmt, span)
1193
1190
} ;
@@ -1260,7 +1257,7 @@ pub fn fields(
1260
1257
}
1261
1258
Some ( EV :: Derived ( _, base) ) => {
1262
1259
// generate pub use field_1 writer as field_2 writer
1263
- let base_field = util :: replace_suffix ( & base. field . name , "" ) ;
1260
+ let base_field = base. field . name . remove_dim ( ) ;
1264
1261
let base_w = ident ( & base_field, config, "field_writer" , span) ;
1265
1262
if !writer_derives. contains ( & writer_ty) {
1266
1263
let base_path = base_syn_path ( base, & fpath, & base_w, config) ?;
@@ -1301,7 +1298,7 @@ pub fn fields(
1301
1298
if let Field :: Array ( f, de) = & f {
1302
1299
let increment = de. dim_increment ;
1303
1300
let offset_calc = calculate_offset ( increment, offset, false ) ;
1304
- let doc = & util :: replace_suffix ( & description, & brief_suffix) ;
1301
+ let doc = & description. expand_dim ( & brief_suffix) ;
1305
1302
let first_name = svd:: array:: names ( f, de) . next ( ) . unwrap ( ) ;
1306
1303
let note = format ! ( "NOTE: `n` is number of field in register. `n == 0` corresponds to `{first_name}` field" ) ;
1307
1304
let dim = unsuffixed ( de. dim ) ;
@@ -1603,7 +1600,7 @@ fn base_syn_path(
1603
1600
let mut segments = Punctuated :: new ( ) ;
1604
1601
segments. push ( path_segment ( Ident :: new ( "super" , span) ) ) ;
1605
1602
segments. push ( path_segment ( ident (
1606
- & replace_suffix ( & base. register ( ) . name , "" ) ,
1603
+ & base. register ( ) . name . remove_dim ( ) ,
1607
1604
config,
1608
1605
"register_mod" ,
1609
1606
span,
0 commit comments