diff options
author | Robert Dubner <rdubner@symas.com> | 2025-08-07 15:52:02 -0400 |
---|---|---|
committer | Robert Dubner <rdubner@symas.com> | 2025-08-07 16:12:32 -0400 |
commit | c684053fc0f0a159f4ddbc7d023fdcc61752b58d (patch) | |
tree | 22cb4c18fe39bfe167e5cd4f80bb0f67d649b93b /gcc | |
parent | 932b764be40bc675a65b89111bd28f31e99fcdbd (diff) | |
download | gcc-c684053fc0f0a159f4ddbc7d023fdcc61752b58d.zip gcc-c684053fc0f0a159f4ddbc7d023fdcc61752b58d.tar.gz gcc-c684053fc0f0a159f4ddbc7d023fdcc61752b58d.tar.bz2 |
cobol: Improve binary-to-string conversion.
COBOL often requires the conversion of binary integers to string of characters.
These changes replace a naive routine that peels decimal digits from a binary
value one digit at a time, with a divide-and-conquer algorithm that is twice as
fast even for a couple of digits, and is about eight times faster past ten
digits.
Included here are some minor fixes to the lexer and parser.
gcc/cobol/ChangeLog:
* cbldiag.h (location_dump): Source code formatting.
* parse.y: error_msg formatting.
* scan.l: Remove UTF-8 character from regex pattern.
* scan_ante.h (numstr_of): error_msg formatting.
* show_parse.h (class ANALYZE): Suppress cppcheck error.
* util.cc (cbl_field_t::report_invalid_initial_value):
error_msg formatting.
libgcobol/ChangeLog:
* Makefile.am: Include new stringbin.cc file.
* Makefile.in: Regenerated.
* libgcobol.cc (__gg__power_of_ten): Improve error message.
(__gg__binary_to_string): Deleted.
(__gg__binary_to_string_internal): Deleted.
(int128_to_field): Use new conversion routine.
(__gg__move): Use new conversion routine.
* stringbin.cc: New file. Implements new conversion routine.
* stringbin.h: New file. Likewise.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cobol/cbldiag.h | 4 | ||||
-rw-r--r-- | gcc/cobol/parse.y | 4 | ||||
-rw-r--r-- | gcc/cobol/scan.l | 2 | ||||
-rw-r--r-- | gcc/cobol/scan_ante.h | 2 | ||||
-rw-r--r-- | gcc/cobol/show_parse.h | 2 | ||||
-rw-r--r-- | gcc/cobol/util.cc | 4 |
6 files changed, 9 insertions, 9 deletions
diff --git a/gcc/cobol/cbldiag.h b/gcc/cobol/cbldiag.h index dd16190..2554deb 100644 --- a/gcc/cobol/cbldiag.h +++ b/gcc/cobol/cbldiag.h @@ -122,8 +122,8 @@ static void location_dump( const char func[], int line, const char tag[], const LOC& loc) { extern int yy_flex_debug; // cppcheck-suppress shadowVariable if( yy_flex_debug ) { - const char *detail = gcobol_getenv("update_location"); // cppcheck-suppress knownConditionTrueFalse - if( detail ) { + const char *detail = gcobol_getenv("update_location"); + if( detail ) { // cppcheck-suppress knownConditionTrueFalse fprintf(stderr, "%s:%d: %s location (%d,%d) to (%d,%d)\n", func, line, tag, loc.first_line, loc.first_column, loc.last_line, loc.last_column); diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index fae96ed..59cc64d 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -10336,8 +10336,8 @@ intrinsic: function_udf if( p != NULL ) { auto loc = symbol_field_location(field_index(p->field)); error_msg(loc, "FUNCTION %qs has " - "inconsistent parameter type %td (%qs)", - keyword_str($1), p - args.data(), name_of(p->field) ); + "inconsistent parameter type %ld (%qs)", + keyword_str($1), (long)(p - args.data()), name_of(p->field) ); YYERROR; } $$ = is_numeric(args[0].field)? diff --git a/gcc/cobol/scan.l b/gcc/cobol/scan.l index ba4c044..5773f09 100644 --- a/gcc/cobol/scan.l +++ b/gcc/cobol/scan.l @@ -123,7 +123,7 @@ NUMEDCHAR [BPVZ90/,]+{COUNT}? NUMEDCHARS {NUMEDCHAR}([.]?{NUMEDCHAR})* NUMED ([+-]{NUMEDCHARS}+)|({NUMEDCHARS}+[+-]) CURRENCY [A-Zfhijklmoqtuwy\x80-\xFF]{-}[ABCDEGNPRSVXZ] -NUMEDCUR (([.]?[-$0B/Z*+,P9()V+–]|{CURRENCY}+|{COUNT})+([.][$0B/Z*+P9()V+\–])*)+ +NUMEDCUR (([.]?[$0B/Z*+,P9()V+-]|{CURRENCY}+|{COUNT})+([.][$0B/Z*+P9()V+-])*)+ NUMEDITED {NUMED}|{NUMEDCUR} EDITED {ALPHED}|{NUMED}|{NUMEDCUR} diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h index 31093a6..c00826d 100644 --- a/gcc/cobol/scan_ante.h +++ b/gcc/cobol/scan_ante.h @@ -149,7 +149,7 @@ numstr_of( const char string[], radix_t radix = decimal_e ) { } auto nx = std::count_if(input, p, fisdigit); if( 36 < nx ) { - error_msg(yylloc, "significand of %s has more than 36 digits (%td)", input, nx); + error_msg(yylloc, "significand of %s has more than 36 digits (%ld)", input, (long)nx); return NO_CONDITION; } diff --git a/gcc/cobol/show_parse.h b/gcc/cobol/show_parse.h index bd0e16f..e1a8cb2 100644 --- a/gcc/cobol/show_parse.h +++ b/gcc/cobol/show_parse.h @@ -500,7 +500,7 @@ class ANALYZE int level; inline static int analyze_level=1; public: - ANALYZE(const char *func_) : func(func_) + ANALYZE(const char *func_) : func(func_) // cppcheck-suppress noExplicitConstructor { level = 0; if( getenv("Analyze") ) diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc index aed9483..2a7bf2b 100644 --- a/gcc/cobol/util.cc +++ b/gcc/cobol/util.cc @@ -1049,8 +1049,8 @@ cbl_field_t::report_invalid_initial_value(const YYLTYPE& loc) const { return TOUPPER(ch) == 'E'; } ); if( !has_exponent && data.precision() < pend - p ) { - error_msg(loc, "%s cannot represent VALUE %qs exactly (max %c%td)", - name, data.initial, '.', pend - p); + error_msg(loc, "%s cannot represent VALUE %qs exactly (max %c%ld)", + name, data.initial, '.', (long)(pend - p)); } } } |