Replace COUNT_OF(cbl_declarative_t::files) with
cbl_declarative_t::files_max which is the constant used to defined the
bounds of that array.

Replace all other uses of COUNT_OF with the ARRAY_SIZE macro used by the
rest of GCC.

gcc/cobol/ChangeLog:

        * parse.y: Use static data member instead of COUNT_OF.
        * genapi.cc (parser_bitop): Use ARRAY_SIZE instead of COUNT_OF.
        (parser_bitwise_op): Likewise.
        * scan_post.h (datetime_format_of): Likewise.
        * symbols.cc (symbol_table_init): Likewise.
        (file_status_status_of): Likewise.
        * util.cc (normalize_picture): Likewise.
        (match): Likewise.
        (valid_move): Likewise.
        (date_time_fmt): Likewise.
        (verify_format): Likewise.
        (cobol_fileline_set): Likewise.
---
 gcc/cobol/genapi.cc   |  4 ++--
 gcc/cobol/parse.y     |  2 +-
 gcc/cobol/scan_post.h |  2 +-
 gcc/cobol/symbols.cc  |  8 ++++----
 gcc/cobol/util.cc     | 12 ++++++------
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc
index a4abbd13ab6..29c28796381 100644
--- a/gcc/cobol/genapi.cc
+++ b/gcc/cobol/genapi.cc
@@ -12723,7 +12723,7 @@ parser_bitop( struct cbl_field_t *tgt,  // tgt has to 
be a FldConditional
   // This is clumsy:  The ops[] array has to match bitop_t
   static const char *ops[] = { "SET", "CLEAR", "ON", "OFF",
                                "AND", "OR",    "XOR" };
-  gcc_assert( op < COUNT_OF(ops) );
+  gcc_assert( op < ARRAY_SIZE(ops) );
   SHOW_PARSE
     {
     SHOW_PARSE_HEADER
@@ -12807,7 +12807,7 @@ parser_bitwise_op(struct cbl_field_t *tgt,
   // This is clumsy:  The ops[] array has to match bitop_t
   static const char *ops[] = { "SET", "CLEAR", "ON", "OFF",
                                "AND", "OR",    "XOR" };
-  gcc_assert( op < COUNT_OF(ops) );
+  gcc_assert( op < ARRAY_SIZE(ops) );
   SHOW_PARSE
     {
     SHOW_PARSE_HEADER
diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index e82ad73ede2..47cff81848a 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -7360,7 +7360,7 @@ perform_ec:       EXCEPTION filenames {
                  auto p = $filenames->files.begin();
                  auto pend = p;
                  while( pend != $filenames->files.end() ) {
-                   for( size_t i=0; i < COUNT_OF(cbl_declarative_t::files); 
i++ ) {
+                   for( size_t i=0; i < cbl_declarative_t::files_max; i++ ) {
                      if( ++pend == $filenames->files.end() ) break;
                    }
                    std::list<size_t> files;
diff --git a/gcc/cobol/scan_post.h b/gcc/cobol/scan_post.h
index 1d79e8aa96a..9723ba4190d 100644
--- a/gcc/cobol/scan_post.h
+++ b/gcc/cobol/scan_post.h
@@ -136,7 +136,7 @@ datetime_format_of( const char input[] ) {
     auto p = std::find_if( patterns, eopatterns,
                            [input, &matches]( auto& pattern ) {
                              auto erc = regexec( &pattern.re, input,
-                                                 COUNT_OF(matches), matches, 0 
);
+                                                 ARRAY_SIZE(matches), matches, 
0 );
                              return erc == 0;
                            } );
 
diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc
index 67a9f039bc0..85875d815f4 100644
--- a/gcc/cobol/symbols.cc
+++ b/gcc/cobol/symbols.cc
@@ -2366,12 +2366,12 @@ symbol_table_init(void) {
   struct symbol_elem_t *p = table.elems + table.nelem;
   std::transform(environs, std::end(environs), p, add_token);
 
-  table.nelem += COUNT_OF(environs);
+  table.nelem += ARRAY_SIZE(environs);
 
   assert(table.nelem < table.capacity);
 
   // debug registers
-  assert(table.nelem + COUNT_OF(debug_registers) < table.capacity);
+  assert(table.nelem + ARRAY_SIZE(debug_registers) < table.capacity);
 
   group_size_t group_size =
     std::accumulate(debug_registers,
@@ -2387,7 +2387,7 @@ symbol_table_init(void) {
   std::for_each(debug_start+1, p, parent_elem_set(debug_start - table.elems));
 
   // special registers
-  assert(table.nelem + COUNT_OF(special_registers) < table.capacity);
+  assert(table.nelem + ARRAY_SIZE(special_registers) < table.capacity);
 
   p = table.elems + table.nelem;
   p = std::transform(special_registers,
@@ -4816,7 +4816,7 @@ cbl_file_status_cmp( const void *K, const void *E ) {
 
 static long
 file_status_status_of( file_status_t status ) {
-  size_t n = COUNT_OF(file_status_fields);
+  size_t n = ARRAY_SIZE(file_status_fields);
   file_status_field_t *fs, key { status };
 
   fs = (file_status_field_t*)lfind( &key, file_status_fields,
diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc
index a32c98a0c81..50cc8aa32ad 100644
--- a/gcc/cobol/util.cc
+++ b/gcc/cobol/util.cc
@@ -332,7 +332,7 @@ normalize_picture( char picture[] )
         return picture;
     }
 
-    while( (erc = regexec(preg, picture, COUNT_OF(pmatch), pmatch, 0)) == 0 ) {
+    while( (erc = regexec(preg, picture, ARRAY_SIZE(pmatch), pmatch, 0)) == 0 
) {
         assert(pmatch[1].rm_so != -1 && pmatch[1].rm_so < pmatch[1].rm_eo);
         size_t len = pmatch[1].rm_eo - pmatch[1].rm_so;
         assert(len == 1);
@@ -405,7 +405,7 @@ match( const char picture[], const char pattern[] )
         return picture;
     }
 
-    if( (erc = regexec(preg, picture, COUNT_OF(pmatch), pmatch, 0)) != 0 ) {
+    if( (erc = regexec(preg, picture, ARRAY_SIZE(pmatch), pmatch, 0)) != 0 ) {
         assert(erc == REG_NOMATCH);
         return NULL;
     }
@@ -1064,7 +1064,7 @@ valid_move( const struct cbl_field_t *tgt, const struct 
cbl_field_t *src )
         { 0, 1, 6, 1, 1, 1, 1, 1, 1, 2, 0, 0, },  // FldLiteralN       
(numeric)
     };
   /* Needs C++11 */
-  static_assert(sizeof(matrix[0]) == COUNT_OF(matrix[0]),
+  static_assert(sizeof(matrix[0]) == ARRAY_SIZE(matrix[0]),
                 "matrix should be square");
 
   for( const cbl_field_t *args[] = {tgt, src}, **p=args;
@@ -1708,7 +1708,7 @@ date_time_fmt( const char input[] ) {
   }
 
   for( auto& fmt : fmts ) {
-    if( 0 == regexec(&fmt.reg, input, COUNT_OF(m), m, eflags) ) {
+    if( 0 == regexec(&fmt.reg, input, ARRAY_SIZE(m), m, eflags) ) {
       result = fmt.type;
       break;
     }
@@ -1907,7 +1907,7 @@ verify_format( const char gmsgid[] ) {
 
   regmatch_t rm[30];
 
-  if( REG_NOMATCH != regexec(&re, gmsgid, COUNT_OF(rm), rm, 0) ){
+  if( REG_NOMATCH != regexec(&re, gmsgid, ARRAY_SIZE(rm), rm, 0) ){
     fprintf(stderr, "bad diagnositic format: '%s'\n", gmsgid);
   }
 }
@@ -2076,7 +2076,7 @@ cobol_fileline_set( const char line[] ) {
     }
     preg = &re;
   }
-  if( (erc = regexec(preg, line, COUNT_OF(pmatch), pmatch, 0)) != 0 ) {
+  if( (erc = regexec(preg, line, ARRAY_SIZE(pmatch), pmatch, 0)) != 0 ) {
     if( erc != REG_NOMATCH ) {
       regerror(erc, preg, regexmsg, sizeof(regexmsg));
       dbgmsg( "%s:%d: could not compile regex: %s", __func__, __LINE__, 
regexmsg );
-- 
2.48.1

Reply via email to