Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9a895d7
Added initial EXEC preprocessor handling logic in pplex and ppparse
utam-1 Mar 16, 2026
119e265
Modified approach based on review comments
utam-1 Mar 16, 2026
e492b07
Deleted unreleated files, and fixed inconsistencies
utam-1 Mar 17, 2026
31c0601
Refined the test cases based on feedback
utam-1 Mar 18, 2026
a946047
Applied the changes based on feedback
utam-1 May 27, 2026
88a2960
Modified test cases and added support for EOF
utam-1 May 30, 2026
b645b64
Added new test cases and subsytem token
utam-1 May 31, 2026
632cc07
Restored to previous commit with modified test cases
utam-1 May 31, 2026
5909d70
Modified subsystem handling for dotted names and improved test cases
utam-1 Jun 1, 2026
f037357
Implementation of step 4, 5 and 6 after baseline integration.
utam-1 Jun 14, 2026
3f1ef75
windows-msvc: fix env var reference for dependencies
GitMensch Mar 23, 2026
0a8d46a
workflow updates
GitMensch May 5, 2026
4694240
Rename is_test to cob_is_test in libcob as it is an extern value
Mar 2, 2026
f28fec5
Config option tab-width can receive a list of comma-separated widths
May 26, 2026
39f8299
Fix handling of some special contexts, and provide room for more
Jun 8, 2026
6ca36c7
Performed modifications based on feedback.
utam-1 Jul 31, 2026
4054ab6
Refactored config parser approach and modified test expectations
utam-1 Aug 6, 2026
65bde01
Config option tab-width can receive a list of comma-separated widths
May 26, 2026
89a2526
Fix handling of some special contexts, and provide room for more
Jun 8, 2026
7b34538
Fix and update CI
ddeclerck Aug 4, 2026
ed29d25
Placed tests in config.at and modified approach for msvc error
utam-1 Aug 7, 2026
546813b
Revert "Placed tests in config.at and modified approach for msvc error"
utam-1 Aug 7, 2026
126eb25
Changed position of test cases and updated preparser conf
utam-1 Aug 7, 2026
0058c20
Modified common.c to resolve the build errors.
utam-1 Aug 7, 2026
b9f9d96
Merge branch 'gitside-gnucobol-3.x' into exec-preprocessor-beyond-bas…
utam-1 Aug 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ NEWS - user visible changes -*- outline -*-
The VFILE64 functions are a GnuCOBOL extension to allow for access beyond the
4 GB offset when using the 64 bit environment.

** EXEC blocks (EXEC SQL, EXEC CICS, etc.) are now recognized by the
internal preprocessor; EXEC <TAG> INCLUDE is handled as COPY with
full -I and -ffold-copy support; all other EXEC blocks raise an
"unsupported" diagnostic (defaulting to error) but can be handled
by registering an external preparser via --preparser.
External preparsers are registered using --preparser=<file> where
<file> is a configuration file specifying the subsystem tag,
command, and optional cflags/ldflags; see the manual for details.

more work in progress

* Changes that potentially effect recompilation of existing programs:
Expand Down
33 changes: 33 additions & 0 deletions cobc/ChangeLog

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want one entry for the baseline (with the old date) and another one for the follow-up work, which then outlines the changes in config.c, tree.h, ...

Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@

2026-07-31 Uttam Singh Bhadauriya <uttamsinghbhadoriya23@gmail.com>

* cobc.c, config.c, tree.h, pplex.l:
refactor external preparser: move struct cb_preparser_entry
to tree.h; rename tag->subsystem; move config loading
functions to config.c; share line-parsing with cb_config_entry;
fix indentation; fix cmd_len calculation
* help.c: add --preparser option documentation

2026-05-24 Fabrice Le Fessant <fabrice.le_fessant@ocamlpro.com>

* config.def: "tab-width" option is changed to a comma-separated
list of tab widths, for example "6,1,4", the last one being reused.
This new meaning is backward compatible.
Implements FR #498 " Adjust tab-width to optionally be a list of
tab-stop positions"
* config.c: initialize cb_tab_width as a string,
each position indicating the number of spaces to insert for a tab
at that position
* pplex.l,cobc.c: use the new type of cb_tab_width
2026-06-08 Nicolas Berthier <nicolas.berthier@ocamlpro.com>

* tree.h, parser.y: change type of cobc_cs_check flags to permit
Expand All @@ -25,6 +45,19 @@
at that position
* pplex.c,cobc.c: use the new type of cb_tab_width

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* pplex.c,cobc.c: use the new type of cb_tab_width
* pplex.l, cobc.c: use the new type of cb_tab_width

... but I'm a but confused where that entry comes from...


2026-03-16 Uttam Singh Bhadauriya <uttamsinghbhadoriya23@gmail.com>

* pplex.l: add EXEC_STATE exclusive start condition to
tokenize EXEC <TAG> ... END-EXEC blocks; add AREA_A lookahead
rule for EXEC; return INCLUDE token for INCLUDE keyword,
plain TOKEN for words; consume all other content silently
* ppparse.y: add exec_statement grammar rule dispatched
from statement_no_replace; EXEC TAG INCLUDE handled as COPY
(full copybook expansion with -I and -ffold-copy support);
all other EXEC TAG blocks warn at "unsupported" level
(defaulting to error) and are ignored; add _exec_token_list
to consume body tokens for parsing purposes only

2025-12-29 Roger Bowler <rbowler@snipix.net>

* tree.c (finalize_file): if file is EXTFH enabled then don't warn for
Expand Down
109 changes: 105 additions & 4 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ enum compile_level {
#define CB_FLAG_GETOPT_DEPEND_KEEP_MISSING 25
#define CB_FLAG_GETOPT_DEPEND_ON_THE_SIDE 26
#define CB_FLAG_GETOPT_GENTABLE 27
#define CB_FLAG_GETOPT_PREPARSER 28

/* Info display limits */
#define CB_IMSG_SIZE 24
Expand Down Expand Up @@ -250,6 +251,8 @@ struct cb_text_list *cb_intrinsic_list = NULL;
struct cb_text_list *cb_extension_list = NULL;
struct cb_text_list *cb_static_call_list = NULL;
struct cb_text_list *cb_early_exit_list = NULL;
struct cb_preparser_entry *cb_preparser_list = NULL;
struct cb_preparser_entry *cb_active_preparser = NULL;
char **cb_saveargv = NULL;
const char *cob_config_dir = NULL;
FILE *cb_storage_file = NULL;
Expand Down Expand Up @@ -617,6 +620,7 @@ static const struct option long_options[] = {
{"save-temps", CB_OP_ARG, NULL, '_'},
{"std", CB_RQ_ARG, NULL, '$'},
{"conf", CB_RQ_ARG, NULL, '&'},
{"preparser", CB_RQ_ARG, NULL, CB_FLAG_GETOPT_PREPARSER},
{"copy", CB_RQ_ARG, NULL, CB_FLAG_GETOPT_COPY_FILE},
{"include", CB_RQ_ARG, NULL, CB_FLAG_GETOPT_INCLUDE_FILE},
{"debug", CB_NO_ARG, NULL, 'd'},
Expand Down Expand Up @@ -3118,6 +3122,7 @@ file_replace_extension (const char *file, const char *ext)
return cobc_main_stradd_dup (file, ext);
}


/* process command line options */
static int
process_command_line (const int argc, char **argv)
Expand Down Expand Up @@ -3335,6 +3340,14 @@ process_command_line (const int argc, char **argv)
conf_ret |= cb_load_std (ext);
break;

case CB_FLAG_GETOPT_PREPARSER:
/* --preparser <name|path> : register external preparser config */
if (strlen (cob_optarg) > COB_SMALL_MAX) {
cobc_err_exit (COBC_INV_PAR, "--preparser");
}
conf_ret |= cb_load_preparser_conf (cob_optarg);
break;

case '&':
/* -conf=<xx> : Specify dialect configuration file */
if (strlen (cob_optarg) > COB_SMALL_MAX) {
Expand Down Expand Up @@ -3649,11 +3662,13 @@ process_command_line (const int argc, char **argv)
/* -Os : Optimize */
case 'g':
/* -g : Generate C debug code */
case '$':
/* -std=<xx> : Specify dialect */
case CB_FLAG_GETOPT_PREPARSER:
/* --preparser : register external preparser config */
/* These options were all processed in the first getopt-run */
break;
Comment on lines +3669 to +3670

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* These options were all processed in the first getopt-run */
break;


case '$':
/* -std=<xx> : Specify dialect */
case '&':
/* -conf=<xx> : Specify dialect configuration file */
/* These options were all processed in the first getopt-run */
Expand Down Expand Up @@ -5372,7 +5387,8 @@ preprocess (struct filename *fn)
const size_t exception_table_size = sizeof (struct cb_exception) * COB_EC_MAX;
int save_source_format, save_fold_copy, save_fold_call,
save_ref_mod_zero_length;

struct cb_preparser_entry *p_reset;
Comment thread
GitMensch marked this conversation as resolved.
int preparser_pass = 1;
#ifndef COB_INTERNAL_XREF
#ifdef _WIN32
const char *envname = "%PATH%";
Expand All @@ -5382,6 +5398,7 @@ preprocess (struct filename *fn)
int ret;
#endif

restart_preprocess:
if (output_name
|| cb_compile_level > CB_LEVEL_PREPROCESS
|| cb_depend_output_only) {
Expand Down Expand Up @@ -5436,6 +5453,7 @@ preprocess (struct filename *fn)
save_ref_mod_zero_length = cb_ref_mod_zero_length;

/* Preprocess */
cb_active_preparser = NULL;
ppparse ();

/* Restore default exceptions and flags */
Expand All @@ -5460,6 +5478,86 @@ preprocess (struct filename *fn)
/* Release flex buffers - After file close */
plex_call_destroy ();

if (cb_active_preparser) {
int ret_sys;

/* Build include-path argument string: "-I path1 -I path2 ..." */
char *include_args = NULL;
{
const struct cb_text_list *il;
size_t inc_len = 0;
/* First pass: compute total length */
for (il = cb_include_list; il; il = il->next) {
inc_len += 3 + strlen (il->text) + 1; /* "-I " + path + space */
}
if (inc_len > 0) {
char *p;
include_args = cobc_malloc (inc_len + 1);
p = include_args;
for (il = cb_include_list; il; il = il->next) {
p += sprintf (p, "-I %s ", il->text);
}
/* remove trailing space */
if (p > include_args) {
*(p - 1) = '\0';
}
}
}

{
const char *inc_str = include_args ? include_args : "";
const size_t cmd_len = strlen (cb_active_preparser->command)
+ strlen (fn->source) + strlen (fn->preprocess)
+ strlen (inc_str) + 6;
char *cmd = cobc_malloc (cmd_len);
if (include_args) {
snprintf (cmd, cmd_len, "%s %s %s \"%s\"",
cb_active_preparser->command,
fn->source, fn->preprocess, inc_str);
} else {
snprintf (cmd, cmd_len, "%s %s %s",
cb_active_preparser->command,
fn->source, fn->preprocess);
}

ret_sys = call_system (cmd);
cobc_free (cmd);
}
if (include_args) {
cobc_free (include_args);
}

if (ret_sys == 0) {
/* success path — generate unique intermediate filename */
{
char ext_buf[16];
preparser_pass++;
snprintf (ext_buf, sizeof (ext_buf), ".i%d", preparser_pass);
fn->source = cobc_strdup (fn->preprocess);
fn->preprocess = file_replace_extension (
(char *)fn->source, ext_buf);
}
if (cb_active_preparser->cflags) {
COBC_ADD_STR (cobc_cflags, " ", cb_active_preparser->cflags, NULL);
}
if (cb_active_preparser->ldflags) {
COBC_ADD_STR (cobc_ldflags, " ", cb_active_preparser->ldflags, NULL);
}
} else {
/* failure path */
cb_source_file = fn->source;
if (!cb_active_preparser->warn_only) {
cobc_err_exit (_("external preparser '%s' failed with exit status %d"),
cb_active_preparser->subsystem, ret_sys);
}
cb_warning (cb_warn_unsupported,
_("external preparser '%s' failed; falling back to baseline"),
cb_active_preparser->subsystem);
cb_active_preparser->disabled = 1;
}
goto restart_preprocess;
}

if (cobc_gen_listing && !cobc_list_file) {
if (unlikely (fclose (cb_listing_file) != 0)) {
cobc_terminate (fn->listing_file);
Expand Down Expand Up @@ -5509,7 +5607,10 @@ preprocess (struct filename *fn)
#endif
cb_listing_file = NULL;
}

/* This prevents trying the same subsystem again for the current file */
for (p_reset = cb_preparser_list; p_reset; p_reset = p_reset->next) {
p_reset->disabled = 0;
}
output_return (errorcount);
return !!errorcount;
}
Expand Down
6 changes: 6 additions & 0 deletions cobc/cobc.h
Comment thread
GitMensch marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ struct cb_text_list {
char *text;
};


/* Structure for extended filenames */
struct local_filename {
struct local_filename *next; /* next pointer */
Expand Down Expand Up @@ -496,6 +497,11 @@ extern struct cb_text_list *cb_extension_list;
extern struct cb_text_list *cb_static_call_list;
extern struct cb_text_list *cb_early_exit_list;

extern struct cb_preparser_entry *cb_preparser_list;
extern struct cb_preparser_entry *cb_find_preparser (const char *subsystem);
extern int cb_load_preparser_conf (const char *name);
extern struct cb_preparser_entry *cb_active_preparser;

extern struct cb_program *current_program;
extern struct cb_statement *current_statement;
extern struct cb_label *current_section;
Expand Down
Loading
Loading