@@ -684,12 +684,10 @@ fn expand_cluster(
684684 ( array_info. dim == 1 ) || ( cluster_size == array_info. dim_increment * BITS_PER_BYTE ) ;
685685
686686 // 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 ( ) ;
693691
694692 let convert_list = match config. keep_list {
695693 true => match & array_info. dim_name {
@@ -702,7 +700,7 @@ fn expand_cluster(
702700 let array_convertible = sequential_addresses && convert_list;
703701
704702 if array_convertible {
705- if sequential_indexes {
703+ if sequential_indexes_from0 {
706704 cluster_expanded. push ( RegisterBlockField {
707705 syn_field : convert_svd_cluster ( cluster, name) ?,
708706 description : info. description . as_ref ( ) . unwrap_or ( & info. name ) . into ( ) ,
@@ -711,16 +709,16 @@ fn expand_cluster(
711709 accessors : None ,
712710 } ) ;
713711 } else {
712+ let span = Span :: call_site ( ) ;
714713 let mut accessors = TokenStream :: new ( ) ;
715714 let nb_name = util:: replace_suffix ( & info. name , "" ) ;
716715 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) ;
719717 let description = info. description . as_ref ( ) . unwrap_or ( & info. name ) ;
720718 for ( i, idx) in array_info. indexes ( ) . enumerate ( ) {
721719 let idx_name = Ident :: new (
722720 & util:: replace_suffix ( & info. name , & idx) . to_sanitized_snake_case ( ) ,
723- Span :: call_site ( ) ,
721+ span ,
724722 ) ;
725723 let comment = make_comment (
726724 cluster_size,
@@ -744,7 +742,7 @@ fn expand_cluster(
744742 accessors : Some ( accessors) ,
745743 } ) ;
746744 }
747- } else if sequential_indexes && config. const_generic {
745+ } else if sequential_indexes_from0 && config. const_generic {
748746 // Include a ZST ArrayProxy giving indexed access to the
749747 // elements.
750748 cluster_expanded. push ( array_proxy ( info, array_info, name) ?) ;
@@ -794,14 +792,6 @@ fn expand_register(
794792 let sequential_addresses = ( array_info. dim == 1 )
795793 || ( register_size == array_info. dim_increment * BITS_PER_BYTE ) ;
796794
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-
805795 let convert_list = match config. keep_list {
806796 true => match & array_info. dim_name {
807797 Some ( dim_name) => dim_name. contains ( "[%s]" ) ,
@@ -813,7 +803,13 @@ fn expand_register(
813803 let array_convertible = sequential_addresses && convert_list;
814804
815805 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 {
817813 register_expanded. push ( RegisterBlockField {
818814 syn_field : convert_svd_register ( register, name, config. ignore_groups ) ?,
819815 description : info. description . clone ( ) . unwrap_or_default ( ) ,
@@ -943,7 +939,7 @@ fn cluster_block(
943939
944940 // name_snake_case needs to take into account array type.
945941 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 ) ) ) ;
947943
948944 let name_snake_case = Ident :: new ( & mod_name. to_sanitized_snake_case ( ) , Span :: call_site ( ) ) ;
949945
0 commit comments