Skip to content

Commit

Permalink
Merged revisions 5109-5113, 5427 from branches/gnucobol-3.x:
Browse files Browse the repository at this point in the history
........
Fix bad typeck.c indentation introduced by [r5112]
........
cobc: fixing warnings in parser.y and pplex.l which got in by the last commits
........
follow-up to [r5109] Use a two-pass algorithm for COPY-REPLACING and then REPLACE

build_windows:
* general for cobc: include new replace.c
* version_cobc.rc: updated date + rev
........
preparser cleanup, including fixes for [bugs:#23] "several replacement values create parser errors" and [bugs:#890] "wrong reference in COPY diagnostic" and improved error handling

cobc:
* ppparse.y: error recovery for COPY and REPLACE (consume until DOT instead of until EOF)
* ppparse.y: renamed "TOKEN" from "Identifier" to "Word", adjust some terminals prefixing it with leading underscore as optional
* ppparse.y: switch to new buffer after parsing DOT, not before
* pplex.l: split REPLACE_STATE and REPLACING_STATE from COPY_STATE to limit their reserved word list to the applicable ones and to improve error handling
* ppparse.y: explicit parse IN and OF as single replacement words
........
parser cleanup

* parser.y
  * (check_non_area_a_of): new function used to do the area check for all terminators and during error recovery
  * check area A for END FUNCTION
  * (begin_statement_internal): extracted from begin_statement and begin_statement_from_backup_pos
  * explicit creation of "comment note" tokens to store the start position for tokens used later, either direct for diagnostics or by assigning it with the new function copy_pos instead of using a global "backup position" or using the current position
  * (emit_entry): removed unused parameter override_source_line
  * explicit check for missing imperative statements in several places that need one to generate a clean error
  * fix several possible bad uses of "ALLOCATE identifier", including "no identifier at all" and use of subscripting / ref-mod which previously were all silently ignored

* typeck.c (cb_emit_call), tree.h, parser.y: remove passing the CALL's original line number as extra parameter, instead use the statement's (now correct) position
........
Use a two-pass algorithm for COPY-REPLACING and then REPLACE

* Change alt_space to always pass space-equivalent tokens into listings
* Move the replacement code for COPY-REPLACING and REPLACE into a file replace.c
* Use a two-pass algorithm to perform first COPY REPLACING replacements
  and the REPLACE replacements.
* For -P flag, use - to mean stdout
........
  • Loading branch information
ddeclerck committed Jan 13, 2025
1 parent dc3e791 commit bea5f96
Show file tree
Hide file tree
Showing 30 changed files with 1,735 additions and 543 deletions.
12 changes: 11 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ Open Plans:
callee modules that use BY VALUE must be compiled with the same version of
GnuCOBOL, either prior this release, or since.

** cobc now uses a two-pass preprocessing algorithm, where replacements for
COPY-REPLACING are done in a first pass, and the replacements for
REPLACE are done in a second pass. Note that, however, both
statements are parsed before the first replacement pass, so
COPY-REPLACING cannot impact a REPLACE statement itself.

* Changes to the COBOL compiler (cobc) options:

** new -fformat dialect option, and extended SOURCE FORMAT directives,
Expand Down Expand Up @@ -386,7 +392,9 @@ Open Plans:
and fatality `cobc --list-exceptions`

** new compiler command line option -ftcmd to enable printing of the command
line in the source listing
line in the source listing, -fno-timestamp to suppress printing of the time
and -ftittle to set a title instead of GnuCOBOL and version (_ chars are
replaced by spaces in the title)

** new compiler command line option --coverage to instrument binaries
for coverage checks
Expand Down Expand Up @@ -414,6 +422,8 @@ Open Plans:
the option -fdiagnostics-plain-output was added to request that diagnostic
output look as plain as possible and stay more stable over time

** the -P flag accepts - as argument for stdout

* Important Bugfixes:

** for dialects other than the GnuCOBOL default different reserved "alias" words
Expand Down
5 changes: 5 additions & 0 deletions build_windows/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
* makedist.cmd: cater for new different library names
* version_cobc.rc, version_libcob.rc: updated date + rev

2023-07-07 Simon Sobisch <[email protected]>

* general for cobc: include new replace.c
* version_cobc.rc: updated date + rev

2023-06-30 Simon Sobisch <[email protected]>

* config.h.in: updated for OrangeC 6.0.70.2
Expand Down
1 change: 1 addition & 0 deletions build_windows/ocide/cobc.exe.cpj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<FILE NAME="..\..\cobc\ppparse.y" TITLE="ppparse.y" CLEAN="0"/>
<FILE NAME="..\..\cobc\reserved.c" TITLE="reserved.c" CLEAN="0"/>
<FILE NAME="..\..\cobc\sqlxfdgen.c" TITLE="sqlxfdgen.c" CLEAN="0"/>
<FILE NAME="..\..\cobc\replace.c" TITLE="replace.c" CLEAN="0"/>
<FILE NAME="..\..\cobc\tree.c" TITLE="tree.c" CLEAN="0"/>
<FILE NAME="..\..\cobc\typeck.c" TITLE="typeck.c" CLEAN="0"/>
</FOLDER>
Expand Down
4 changes: 4 additions & 0 deletions build_windows/vs2008/cobc.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@
RelativePath="..\..\cobc\sqlxfdgen.c"
>
</File>
<File
RelativePath="..\..\cobc\replace.c"
>
</File>
<File
RelativePath="..\..\cobc\reserved.c"
>
Expand Down
1 change: 1 addition & 0 deletions build_windows/vs2010/cobc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<ClCompile Include="..\..\cobc\error.c" />
<ClCompile Include="..\..\cobc\field.c" />
<ClCompile Include="..\..\cobc\help.c" />
<ClCompile Include="..\..\cobc\replace.c" />
<ClCompile Include="..\..\cobc\reserved.c" />
<ClCompile Include="..\..\cobc\sqlxfdgen.c" />
<ClCompile Include="..\..\cobc\tree.c" />
Expand Down
3 changes: 3 additions & 0 deletions build_windows/vs2010/cobc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="..\..\cobc\field.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\replace.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\reserved.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions build_windows/vs2012/cobc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
<ClCompile Include="..\..\cobc\error.c" />
<ClCompile Include="..\..\cobc\field.c" />
<ClCompile Include="..\..\cobc\help.c" />
<ClCompile Include="..\..\cobc\replace.c" />
<ClCompile Include="..\..\cobc\reserved.c" />
<ClCompile Include="..\..\cobc\sqlxfdgen.c" />
<ClCompile Include="..\..\cobc\tree.c" />
Expand Down
3 changes: 3 additions & 0 deletions build_windows/vs2012/cobc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="..\..\cobc\field.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\replace.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\reserved.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions build_windows/vs2013/cobc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<ClCompile Include="..\..\cobc\error.c" />
<ClCompile Include="..\..\cobc\field.c" />
<ClCompile Include="..\..\cobc\help.c" />
<ClCompile Include="..\..\cobc\replace.c" />
<ClCompile Include="..\..\cobc\reserved.c" />
<ClCompile Include="..\..\cobc\sqlxfdgen.c" />
<ClCompile Include="..\..\cobc\tree.c" />
Expand Down
3 changes: 3 additions & 0 deletions build_windows/vs2013/cobc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="..\..\cobc\field.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\replace.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\reserved.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions build_windows/vs2015/cobc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
<ClCompile Include="..\..\cobc\error.c" />
<ClCompile Include="..\..\cobc\field.c" />
<ClCompile Include="..\..\cobc\help.c" />
<ClCompile Include="..\..\cobc\replace.c" />
<ClCompile Include="..\..\cobc\reserved.c" />
<ClCompile Include="..\..\cobc\sqlxfdgen.c" />
<ClCompile Include="..\..\cobc\tree.c" />
Expand Down
3 changes: 3 additions & 0 deletions build_windows/vs2015/cobc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="..\..\cobc\field.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\replace.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\reserved.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions build_windows/vs2017/cobc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<ClCompile Include="..\..\cobc\error.c" />
<ClCompile Include="..\..\cobc\field.c" />
<ClCompile Include="..\..\cobc\help.c" />
<ClCompile Include="..\..\cobc\replace.c" />
<ClCompile Include="..\..\cobc\reserved.c" />
<ClCompile Include="..\..\cobc\sqlxfdgen.c" />
<ClCompile Include="..\..\cobc\tree.c" />
Expand Down
3 changes: 3 additions & 0 deletions build_windows/vs2017/cobc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="..\..\cobc\field.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\replace.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\reserved.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions build_windows/vs2019/cobc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<ClCompile Include="..\..\cobc\error.c" />
<ClCompile Include="..\..\cobc\field.c" />
<ClCompile Include="..\..\cobc\help.c" />
<ClCompile Include="..\..\cobc\replace.c" />
<ClCompile Include="..\..\cobc\reserved.c" />
<ClCompile Include="..\..\cobc\sqlxfdgen.c" />
<ClCompile Include="..\..\cobc\tree.c" />
Expand Down
3 changes: 3 additions & 0 deletions build_windows/vs2019/cobc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="..\..\cobc\field.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\replace.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\cobc\reserved.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
49 changes: 49 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@
* error.c, cobc.c (print_program_trailer), flag.def:
implemented -fmax-errors=0 as unlimited

2023-07-07 Simon Sobisch <[email protected]>

common preparser cleanup
* ppparse.y: error recovery for COPY and REPLACE (consume until DOT
instead of until EOF)
* ppparse.y: renamed "TOKEN" from "Identifier" to "Word", adjust
some terminals prefixing it with leading underscore as optional
Bug #890 wrong reference in COPY diagnostic
* ppparse.y: switch to new buffer after parsing DOT, not before
Bug #23 several replacement values create parser errors
* pplex.l: split REPLACE_STATE and REPLACING_STATE from COPY_STATE
to limit their reserved word list to the applicable ones and to
improve error handling
* ppparse.y: explicit parse IN and OF as single replacement words

2023-07-06 Fabrice Le Fessant <[email protected]>

* replace.c: rewrite the code for preprocessing with a two-phase
algorithm. The first phase performs COPY REPLACING on the stream
of tokens, while the second phase perform REPLACE on the resulting
stream of tokens. This rewriting is closer to the COBOL standard
and fixes bug #831 partially.
* cobc.c: flag -P now accepts - as argument to mean stdout

2023-07-05 Fabrice Le Fessant <[email protected]>

* flag.def/cobc.c: new flags -fno-ttimestamp to suppress timestamp
Expand All @@ -47,6 +71,13 @@
CB_FLAG_GETOPT_. Remove unused 'case 6:' for -fdefaultbyte that is
now handled in config.c

2023-07-02 Fabrice Le Fessant <[email protected]>

* pplex.l (ppecho, ppecho_direct): replace alt_space by passing a
second equivalent token
* pplex.l, replace.c: move the preprocessing code performing
COPY REPLACING and REPLACE from pplex.l to replace.c

2023-07-04 Simon Sobisch <[email protected]>

* codegen.c (output_char): extracted usage of disabled code for
Expand Down Expand Up @@ -347,18 +378,36 @@

* typeck.c (cb_build_move_field): generate optimized code for
reference-modification with same ref-mod length
* parser.y: fix several possible bad uses of "ALLOCATE identifier",
including "no identifier at all" and use of subscripting / ref-mod
which previously were all silently ignored

2023-03-08 Emilien Lemaire <[email protected]>

* reserved.c (get_user_specified_reserved_word): add check for
context sensitivity in aliases
* parser.y (begin_statement_internal): extracted from begin_statement and
begin_statement_from_backup_pos
* parser.y: explicit creation of "comment note" tokens to store the start
position for tokens used later, either direct for diagnostics or by
assigning it with the new function copy_pos instead of using a global
"backup position" or using the current position
* parser.y: explicit check for missing imperative statements in several
places that need one to generate a clean error
* parser.y (emit_entry): removed unused parameter override_source_line
* typeck.c (cb_emit_call), tree.h, parser.y: remove passing the CALL's
original line number as extra parameter, instead use the statement's
(now correct) position

2023-03-03 Simon Sobisch <[email protected]>

* typeck.c (cb_build_cond_fields): optimize comparison between field and
ZEROES up to COB_ZEROES_ALPHABETIC_BYTE_LENGTH
* pplex.l (ppopen): fixes for auto-detection of reference-format FR #45
handling tabs, dos eol and empty lines correctly
* parser.y (check_non_area_a_of): new function used to do the area check
for all terminators and during error recovery
* parser.y: check area A for END FUNCTION

2023-02-28 Simon Sobisch <[email protected]>

Expand Down
2 changes: 1 addition & 1 deletion cobc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bin_PROGRAMS = cobc
cobc_SOURCES = cobc.c cobc.h ppparse.y pplex.c parser.y scanner.c \
config.c reserved.c error.c tree.c tree.h field.c typeck.c \
codegen.c help.c sqlxfdgen.c config.def flag.def warning.def \
codeoptim.def ppparse.def codeoptim.c
codeoptim.def ppparse.def codeoptim.c replace.c

#cobc_SOURCES = cobc.c cobc.h ppparse.y pplex.l parser.y scanner.l config.c

Expand Down
54 changes: 52 additions & 2 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ static const char *const cob_csyns[] = {

#define COB_NUM_CSYNS sizeof(cob_csyns) / sizeof(cob_csyns[0])

static const char short_options[] = "hVivqECScbmxjdFOPgGwo:t:T:I:L:l:D:K:k:";
static const char short_options[] = "hVivqECScbmxjdFOgGwo:P:t:T:I:L:l:D:K:k:";

#define CB_NO_ARG no_argument
#define CB_RQ_ARG required_argument
Expand Down Expand Up @@ -1240,6 +1240,50 @@ cobc_plex_strdup (const char *dupstr)
return p;
}

/* Return a newly allocated zero-terminated string with only the first
* len chars of the first argument */
void *
cobc_plex_strsub (const char *s, const int len)
{
void *p;
int n;

n = strlen (s);

#ifdef COB_TREE_DEBUG
/* LCOV_EXCL_START */
if ( len>n ) {
cobc_err_msg ("call to %s with bad argument len=%d>%d=strlen(s)",
"cobc_plex_strsub", len, n);
cobc_abort_terminate (1);
}
/* LCOV_EXCL_STOP */
#endif

p = cobc_plex_malloc (len + 1);
memcpy (p, s, len);
return p;
}

/* Returns a newly allocated zero-terminated string containing the
* concatenation of str1 and str2. str1 and str2 may be freed
* afterwards.
*/
char *
cobc_plex_stradd (const char *str1, const char *str2)
{
char *p;
size_t m, n;

m = strlen (str1);
n = strlen (str2);
p = cobc_plex_malloc (m + n + 1);
memcpy (p, str1, m);
memcpy (p + m, str2, n);
return p;
}


/* variant of strcpy which copies max 'max_size' bytes from 'src' to 'dest',
if the size of 'src' is too long only its last/last bytes are copied and an
eliding "..." is placed in front or at end depending on 'elide_at_end' */
Expand Down Expand Up @@ -9256,6 +9300,9 @@ main (int argc, char **argv)
memset (cb_listing_header, 0, sizeof (cb_listing_header));
/* If -P=file specified, all lists go to this file */
if (cobc_list_file) {
if (strcmp (cobc_list_file, COB_DASH) == 0) {
cb_listing_file = stdout;
} else
if (cb_unix_lf) {
cb_listing_file = fopen (cobc_list_file, "wb");
} else {
Expand Down Expand Up @@ -9344,7 +9391,10 @@ main (int argc, char **argv)
}

if (cobc_list_file) {
fclose (cb_listing_file);
if (cb_listing_file != stdout)
fclose (cb_listing_file);
else
fflush (stdout);
cb_listing_file = NULL;
}

Expand Down
2 changes: 2 additions & 0 deletions cobc/cobc.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ extern void cobc_parse_free (void *);

extern void *cobc_plex_malloc (const size_t);
extern void *cobc_plex_strdup (const char *);
extern void *cobc_plex_strsub (const char *, const int len);
extern char *cobc_plex_stradd (const char *str1, const char *str2);

extern void *cobc_check_string (const char *);
extern void cobc_err_msg (const char *, ...) COB_A_FORMAT12;
Expand Down
Loading

0 comments on commit bea5f96

Please sign in to comment.