Use the C++11 std::end utility to get a pointer past the end of an
array. This is a step towards eliminating the COUNT_OF macro.
gcc/cobol/ChangeLog:
* parse.y: Use std::end to get a pointer past the end of an
array.
* parse_util.h (function_descrs_end): Likewise.
* scan_post.h (datetime_format_of): Likewise.
* symbols.cc (symbol_table_init): Likewise.
* util.cc (valid_move, type_capacity): Likewise.
---
gcc/cobol/parse.y | 7 ++++---
gcc/cobol/parse_util.h | 2 +-
gcc/cobol/scan_post.h | 2 +-
gcc/cobol/symbols.cc | 8 ++++----
gcc/cobol/util.cc | 4 ++--
5 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index ae1dec4ecb7..5ccb4e35881 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -29,6 +29,7 @@
*/
%code requires {
#include <fstream> // Before cobol-system because it uses poisoned functions
+ #include <iterator> // For std::end
#include "cobol-system.h"
#include "../../libgcobol/io.h"
#include "../../libgcobol/ec.h"
@@ -11131,7 +11132,7 @@ int
tokenset_t::find( const cbl_name_t name, bool include_intrinsics ) {
static const cbl_name_t non_names[] = { // including CDF NAMES, and "SWITCH"
"CHECKING", "LIST", "LOCATION", "MAP", "SWITCH",
- }, * const eonames = non_names + COUNT_OF(non_names);
+ }, * const eonames = std::end(non_names);
if( std::any_of(non_names, eonames,
[candidate=name](const cbl_name_t non_name) {
@@ -11144,7 +11145,7 @@ tokenset_t::find( const cbl_name_t name, bool
include_intrinsics ) {
if( dialect_ibm() ) {
static const cbl_name_t ibm_non_names[] = {
"RESUME",
- }, * const eonames = ibm_non_names + COUNT_OF(ibm_non_names);
+ }, * const eonames = std::end(ibm_non_names);
if( std::any_of(ibm_non_names, eonames,
[candidate=name](const cbl_name_t non_name) {
@@ -12726,7 +12727,7 @@ cbl_figconst_of( const char *value ) {
{ constant_of(constant_index(LOW_VALUES))->data.initial, low_value_e },
{ constant_of(constant_index(QUOTES))->data.initial, quote_value_e },
{ constant_of(constant_index(NULLS))->data.initial, null_value_e },
- }, *eovalues = values + COUNT_OF(values);
+ }, *eovalues = std::end(values);
auto p = std::find_if( values, eovalues,
[value]( const values_t& elem ) {
diff --git a/gcc/cobol/parse_util.h b/gcc/cobol/parse_util.h
index e504f46ee40..e39c3ec17c6 100644
--- a/gcc/cobol/parse_util.h
+++ b/gcc/cobol/parse_util.h
@@ -266,7 +266,7 @@ static const function_descr_t function_descrs[] = {
};
static const
-function_descr_t *function_descrs_end = function_descrs +
COUNT_OF(function_descrs);
+function_descr_t *function_descrs_end = std::end(function_descrs);
class cname_cmp {
const char *cname;
diff --git a/gcc/cobol/scan_post.h b/gcc/cobol/scan_post.h
index dabb168ae90..1d79e8aa96a 100644
--- a/gcc/cobol/scan_post.h
+++ b/gcc/cobol/scan_post.h
@@ -101,7 +101,7 @@ datetime_format_of( const char input[] ) {
{ {}, datetime_pattern, DATETIME_FMT },
{ {}, date_pattern, DATE_FMT },
{ {}, time_pattern, TIME_FMT },
- }, * eopatterns = patterns + COUNT_OF(patterns);;
+ }, * eopatterns = std::end(patterns);;
// compile patterns
if( ! date_pattern[0] ) {
diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc
index 38c7a2ed47b..2b352ea99c9 100644
--- a/gcc/cobol/symbols.cc
+++ b/gcc/cobol/symbols.cc
@@ -2365,7 +2365,7 @@ symbol_table_init(void) {
};
struct symbol_elem_t *p = table.elems + table.nelem;
- std::transform(environs, environs + COUNT_OF(environs), p, add_token);
+ std::transform(environs, std::end(environs), p, add_token);
table.nelem += COUNT_OF(environs);
@@ -2376,13 +2376,13 @@ symbol_table_init(void) {
group_size_t group_size =
std::accumulate(debug_registers,
- debug_registers + COUNT_OF(debug_registers),
group_size_t());
+ std::end(debug_registers), group_size_t());
debug_registers[0].data.memsize =
debug_registers[0].data.capacity = group_size.capacity();
auto debug_start = p = table.elems + table.nelem;
p = std::transform(debug_registers,
- debug_registers + COUNT_OF(debug_registers), p,
elementize);
+ std::end(debug_registers), p, elementize);
table.nelem = p - table.elems;
assert(table.nelem < table.capacity);
std::for_each(debug_start+1, p, parent_elem_set(debug_start - table.elems));
@@ -2392,7 +2392,7 @@ symbol_table_init(void) {
p = table.elems + table.nelem;
p = std::transform(special_registers,
- special_registers + COUNT_OF(special_registers),
+ std::end(special_registers),
p, elementize);
table.nelem = p - table.elems;
assert(table.nelem < table.capacity);
diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc
index 62ecd98e9ef..a32c98a0c81 100644
--- a/gcc/cobol/util.cc
+++ b/gcc/cobol/util.cc
@@ -1068,7 +1068,7 @@ valid_move( const struct cbl_field_t *tgt, const struct
cbl_field_t *src )
"matrix should be square");
for( const cbl_field_t *args[] = {tgt, src}, **p=args;
- p < args + COUNT_OF(args); p++ ) {
+ p < std::end(args); p++ ) {
auto& f(**p);
switch(f.type) {
case FldClass:
@@ -1245,7 +1245,7 @@ type_capacity( enum cbl_field_type_t type, uint32_t
digits )
{ 5, 9, 4 },
{10, 18, 8 },
{19, 38, 16 },
- }, *esizes = sizes + COUNT_OF(sizes);
+ }, *esizes = std::end(sizes);
auto psize = std::find_if( sizes, esizes,
[digits]( sizes_t sizes ) {
--
2.48.1