@@ -684,12 +684,10 @@ fn expand_cluster(
684
684
( array_info. dim == 1 ) || ( cluster_size == array_info. dim_increment * BITS_PER_BYTE ) ;
685
685
686
686
// if dimIndex exists, test if it is a sequence of numbers from 0 to dim
687
- let sequential_indexes = array_info. dim_index . as_ref ( ) . map_or ( true , |dim_index| {
688
- dim_index
689
- . iter ( )
690
- . map ( |element| element. parse :: < u32 > ( ) )
691
- . eq ( ( 0 ..array_info. dim ) . map ( Ok ) )
692
- } ) ;
687
+ let sequential_indexes_from0 = array_info
688
+ . indexes_as_range ( )
689
+ . filter ( |r| * r. start ( ) == 0 )
690
+ . is_some ( ) ;
693
691
694
692
let convert_list = match config. keep_list {
695
693
true => match & array_info. dim_name {
@@ -702,7 +700,7 @@ fn expand_cluster(
702
700
let array_convertible = sequential_addresses && convert_list;
703
701
704
702
if array_convertible {
705
- if sequential_indexes {
703
+ if sequential_indexes_from0 {
706
704
cluster_expanded. push ( RegisterBlockField {
707
705
syn_field : convert_svd_cluster ( cluster, name) ?,
708
706
description : info. description . as_ref ( ) . unwrap_or ( & info. name ) . into ( ) ,
@@ -711,16 +709,16 @@ fn expand_cluster(
711
709
accessors : None ,
712
710
} ) ;
713
711
} else {
712
+ let span = Span :: call_site ( ) ;
714
713
let mut accessors = TokenStream :: new ( ) ;
715
714
let nb_name = util:: replace_suffix ( & info. name , "" ) ;
716
715
let ty = name_to_ty ( & nb_name, name) ?;
717
- let nb_name_cs =
718
- Ident :: new ( & nb_name. to_sanitized_snake_case ( ) , Span :: call_site ( ) ) ;
716
+ let nb_name_cs = Ident :: new ( & nb_name. to_sanitized_snake_case ( ) , span) ;
719
717
let description = info. description . as_ref ( ) . unwrap_or ( & info. name ) ;
720
718
for ( i, idx) in array_info. indexes ( ) . enumerate ( ) {
721
719
let idx_name = Ident :: new (
722
720
& util:: replace_suffix ( & info. name , & idx) . to_sanitized_snake_case ( ) ,
723
- Span :: call_site ( ) ,
721
+ span ,
724
722
) ;
725
723
let comment = make_comment (
726
724
cluster_size,
@@ -744,7 +742,7 @@ fn expand_cluster(
744
742
accessors : Some ( accessors) ,
745
743
} ) ;
746
744
}
747
- } else if sequential_indexes && config. const_generic {
745
+ } else if sequential_indexes_from0 && config. const_generic {
748
746
// Include a ZST ArrayProxy giving indexed access to the
749
747
// elements.
750
748
cluster_expanded. push ( array_proxy ( info, array_info, name) ?) ;
@@ -794,14 +792,6 @@ fn expand_register(
794
792
let sequential_addresses = ( array_info. dim == 1 )
795
793
|| ( register_size == array_info. dim_increment * BITS_PER_BYTE ) ;
796
794
797
- // if dimIndex exists, test if it is a sequence of numbers from 0 to dim
798
- let sequential_indexes = array_info. dim_index . as_ref ( ) . map_or ( true , |dim_index| {
799
- dim_index
800
- . iter ( )
801
- . map ( |element| element. parse :: < u32 > ( ) )
802
- . eq ( ( 0 ..array_info. dim ) . map ( Ok ) )
803
- } ) ;
804
-
805
795
let convert_list = match config. keep_list {
806
796
true => match & array_info. dim_name {
807
797
Some ( dim_name) => dim_name. contains ( "[%s]" ) ,
@@ -813,7 +803,13 @@ fn expand_register(
813
803
let array_convertible = sequential_addresses && convert_list;
814
804
815
805
if array_convertible {
816
- if sequential_indexes {
806
+ // if dimIndex exists, test if it is a sequence of numbers from 0 to dim
807
+ let sequential_indexes_from0 = array_info
808
+ . indexes_as_range ( )
809
+ . filter ( |r| * r. start ( ) == 0 )
810
+ . is_some ( ) ;
811
+
812
+ if sequential_indexes_from0 {
817
813
register_expanded. push ( RegisterBlockField {
818
814
syn_field : convert_svd_register ( register, name, config. ignore_groups ) ?,
819
815
description : info. description . clone ( ) . unwrap_or_default ( ) ,
@@ -943,7 +939,7 @@ fn cluster_block(
943
939
944
940
// name_snake_case needs to take into account array type.
945
941
let description =
946
- util:: escape_brackets ( util:: respace ( c. description . as_ref ( ) . unwrap_or ( & c. name ) ) . as_ref ( ) ) ;
942
+ util:: escape_brackets ( & util:: respace ( c. description . as_ref ( ) . unwrap_or ( & c. name ) ) ) ;
947
943
948
944
let name_snake_case = Ident :: new ( & mod_name. to_sanitized_snake_case ( ) , Span :: call_site ( ) ) ;
949
945
0 commit comments