Skip to content

Commit

Permalink
Merge branch 'gcos4gnucobol-3.x' into engboris-parser-bug947
Browse files Browse the repository at this point in the history
  • Loading branch information
engboris authored Feb 20, 2024
2 parents 87581ff + 5713357 commit 32e98e0
Show file tree
Hide file tree
Showing 21 changed files with 1,141 additions and 279 deletions.
16 changes: 16 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ NEWS - user visible changes -*- outline -*-
the error output for format errors (for example invalid indicator column)
is now limitted to 5 per source file

** support the COLLATING SEQUENCE clause on indexed files
(currently only with the BDB backend)

more work in progress

* Important Bugfixes
Expand All @@ -22,6 +25,16 @@ NEWS - user visible changes -*- outline -*-

* Changes to the COBOL compiler (cobc) options:

** New option --copy COPYBOOK to load copybooks before parsing files. This
option can typically be used to perform replacements without modifying
the source code, or to add prototypes for external calls.

** New option --include FILE.h to add a #include in the generated C file.
This option can typically be used to force the C compiler to check static
calls to externals. The files are put into quotes, unless they start by
'<'. Quoted files are expected to have absolute paths, as the C compiler
is called in a temp directory instead of the project directory.

** output of unlimited errors may be requested by -fmax-errors=0,
to stop compiliation at first error use -Wfatal-errors
** default value for -fmax-errors was changed from 128 to 20
Expand All @@ -31,6 +44,9 @@ NEWS - user visible changes -*- outline -*-
build system do not correctly work together to locate files from
diagnostic output

** New option -fdefault-file-colseq to specify the default
file collating sequence

* More notable changes

** execution times were significantly reduced for the following:
Expand Down
28 changes: 28 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@


2024-02-19 Boris Eng <[email protected]>

* parser.y (screen_value_clause): replaced basic literals by literals

2024-01-25 David Declerck <[email protected]>

FR #459: support COLLATING SEQUENCE clause on SELECT / INDEXED files
* codegen.c (output_file_initialization): output the indexed
file/keys collating sequence (were already present in the AST)
* tree.c (validate_indexed_key_field): process postponed
key collating sequences
* parser.y (collating_sequence_clause, collating_sequence_clause_key):
replace CB_PENDING by CB_UNFINISHED on file and key collating sequence
* flag.def, tree.c, tree.h, cobc.c, parser.y: add and handle a new
-fdefault-file-colseq flag to specify the default collating
sequence to use for files without a collating sequence clause

2023-10-12 Fabrice Le Fessant <[email protected]>

* cobc.c, codegen.c: new option --include FILE, to #include
additional files in the C generated code. Such files can be
used to statically check the number of arguments in static
calls, for example. The files are put into quotes, unless
they start by '<'. Since C files are compiled in a temp dir,
quoted files should be absolute paths. Implementing FR #176

2023-10-11 Fabrice Le Fessant <[email protected]>

* cobc.c, pplex.l: new option --copy COPYBOOK, to include a COPYBOOK
before reading the source file

2023-11-29 Fabrice Le Fessant <[email protected]>

* cobc.c (cobc_clean_up): when save-temps specifies a directory,
Expand Down
92 changes: 71 additions & 21 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,25 @@ enum compile_level {
CB_LEVEL_EXECUTABLE = 7
};

#define CB_FLAG_GETOPT_STACK_SIZE 1
#define CB_FLAG_GETOPT_IF_CUTOFF 2
#define CB_FLAG_GETOPT_SIGN 3
#define CB_FLAG_GETOPT_FOLD_COPY 4
#define CB_FLAG_GETOPT_FOLD_CALL 5
#define CB_FLAG_GETOPT_TTITLE 6
#define CB_FLAG_GETOPT_MAX_ERRORS 7
#define CB_FLAG_GETOPT_DUMP 8
#define CB_FLAG_GETOPT_CALLFH 9
#define CB_FLAG_GETOPT_INTRINSICS 10
#define CB_FLAG_GETOPT_EC 11
#define CB_FLAG_GETOPT_NO_EC 12
#define CB_FLAG_GETOPT_NO_DUMP 13
#define CB_FLAG_GETOPT_EBCDIC_TABLE 14
#define CB_FLAG_GETOPT_DEFAULT_COLSEQ 15
#define CB_FLAG_MEMORY_CHECK 16
#define CB_FLAG_GETOPT_STACK_SIZE 1
#define CB_FLAG_GETOPT_IF_CUTOFF 2
#define CB_FLAG_GETOPT_SIGN 3
#define CB_FLAG_GETOPT_FOLD_COPY 4
#define CB_FLAG_GETOPT_FOLD_CALL 5
#define CB_FLAG_GETOPT_TTITLE 6
#define CB_FLAG_GETOPT_MAX_ERRORS 7
#define CB_FLAG_GETOPT_DUMP 8
#define CB_FLAG_GETOPT_CALLFH 9
#define CB_FLAG_GETOPT_INTRINSICS 10
#define CB_FLAG_GETOPT_EC 11
#define CB_FLAG_GETOPT_NO_EC 12
#define CB_FLAG_GETOPT_NO_DUMP 13
#define CB_FLAG_GETOPT_EBCDIC_TABLE 14
#define CB_FLAG_GETOPT_DEFAULT_COLSEQ 15
#define CB_FLAG_GETOPT_DEFAULT_FILE_COLSEQ 16
#define CB_FLAG_GETOPT_MEMORY_CHECK 17
#define CB_FLAG_GETOPT_COPY_FILE 18
#define CB_FLAG_GETOPT_INCLUDE_FILE 19


/* Info display limits */
Expand Down Expand Up @@ -171,8 +174,8 @@ enum compile_level {
#define GC_C_VERSION _("unknown")
#endif

#define CB_TEXT_LIST_ADD(y,z) y = cb_text_list_add (y, z)
#define CB_TEXT_LIST_CHK(y,z) y = cb_text_list_chk (y, z)
#define CB_TEXT_LIST_ADD(list,z) list = cb_text_list_add (list, z)
#define CB_TEXT_LIST_CHK(list,z) list = cb_text_list_chk (list, z)

#ifdef _MSC_VER
#define CB_COPT_0 " /Od"
Expand Down Expand Up @@ -232,6 +235,8 @@ const char *cb_cobc_build_stamp = NULL;
const char *demangle_name = NULL;
const char *cb_storage_file_name = NULL;
const char *cb_call_extfh = NULL;
struct cb_text_list *cb_copy_list = NULL;
struct cb_text_list *cb_include_file_list = NULL;
struct cb_text_list *cb_include_list = NULL;
struct cb_text_list *cb_depend_list = NULL;
struct cb_text_list *cb_intrinsic_list = NULL;
Expand Down Expand Up @@ -595,6 +600,8 @@ static const struct option long_options[] = {
{"save-temps", CB_OP_ARG, NULL, '_'},
{"std", CB_RQ_ARG, NULL, '$'},
{"conf", CB_RQ_ARG, NULL, '&'},
{"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'},
{"ext", CB_RQ_ARG, NULL, 'e'}, /* note: kept *undocumented* until GC4, will be changed to '.' */
{"free", CB_NO_ARG, NULL, 'F'}, /* note: not assigned directly as this is only valid for */
Expand Down Expand Up @@ -3282,12 +3289,12 @@ process_command_line (const int argc, char **argv)
cobc_wants_debug = 1;
break;

case 8:
case CB_FLAG_GETOPT_DUMP: /* 8 */
/* -fdump=<scope> : Add sections for dump code generation */
cobc_def_dump_opts (cob_optarg, 1);
break;

case 13:
case CB_FLAG_GETOPT_NO_DUMP: /* 13 */
/* -fno-dump=<scope> : Suppress sections in dump code generation */
if (cob_optarg) {
cobc_def_dump_opts (cob_optarg, 0);
Expand Down Expand Up @@ -3813,6 +3820,13 @@ process_command_line (const int argc, char **argv)
}
break;

case CB_FLAG_GETOPT_DEFAULT_FILE_COLSEQ: /* 16 */
/* -fdefault-file-colseq=<ASCII/EBCDIC/NATIVE> */
if (cb_deciph_default_file_colseq_name (cob_optarg)) {
cobc_err_exit (COBC_INV_PAR, "-fdefault-file-colseq");
}
break;

case CB_FLAG_GETOPT_FOLD_COPY: /* 4 */
/* -ffold-copy=<UPPER/LOWER> : COPY fold case */
if (!cb_strcasecmp (cob_optarg, "UPPER")) {
Expand Down Expand Up @@ -3892,7 +3906,7 @@ process_command_line (const int argc, char **argv)
}
break;

case CB_FLAG_MEMORY_CHECK: /* 16 */
case CB_FLAG_GETOPT_MEMORY_CHECK: /* 17 */
/* -fmemory-check=<scope> : */
if (!cob_optarg) {
cb_flag_memory_check = CB_MEMCHK_ALL;
Expand All @@ -3901,6 +3915,26 @@ process_command_line (const int argc, char **argv)
}
break;

case CB_FLAG_GETOPT_COPY_FILE: /* 18 */
/* --copy=<file> : COPY file at beginning */
if (strlen (cob_optarg) > (COB_MINI_MAX)) {
cobc_err_exit (COBC_INV_PAR, "--copy");
}
CB_TEXT_LIST_ADD (cb_copy_list,
cobc_strdup (cob_optarg));
break;

case CB_FLAG_GETOPT_INCLUDE_FILE: /* 19 */
/* -include=<file.h> : add #include "file.h" to
generated C file */
if (strlen (cob_optarg) > (COB_MINI_MAX)) {
cobc_err_exit (COBC_INV_PAR, "--include");
}
CB_TEXT_LIST_ADD (cb_include_file_list,
cobc_strdup (cob_optarg));
cb_flag_c_decl_for_static_call = 0;
break;

case 'A':
/* -A <xx> : Add options to C compile phase */
COBC_ADD_STR (cobc_cflags, " ", cob_optarg, NULL);
Expand Down Expand Up @@ -9266,6 +9300,22 @@ main (int argc, char **argv)
finish_setup_compiler_env ();
finish_setup_internal_env ();

{
struct cb_text_list *l;
for (l = cb_copy_list; l; l=l->next){
const char *filename;
int has_ext;
char name[COB_MINI_BUFF];
int len = strlen (l->text);
memcpy (name, l->text, len+1);
has_ext = (strchr (name, '.') != NULL);
filename = cb_copy_find_file (name, has_ext);
if (!filename){
cobc_err_exit (_("fatal error: could not find --copy argument %s"), name);
}
}
}

/* Reset source format in case text column has been configured manually. */
cobc_set_source_format (cobc_get_source_format ());

Expand Down
3 changes: 3 additions & 0 deletions cobc/cobc.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ extern FILE *cb_listing_file;
extern FILE *cb_src_list_file;
extern FILE *cb_depend_file;
extern struct cb_text_list *cb_depend_list;
extern struct cb_text_list *cb_copy_list;
extern struct cb_text_list *cb_include_file_list;
extern struct cb_text_list *cb_include_list;
extern struct cb_text_list *cb_intrinsic_list;
extern struct cb_text_list *cb_extension_list;
Expand Down Expand Up @@ -652,6 +654,7 @@ extern void cb_plex_error (const size_t,
const char *, ...) COB_A_FORMAT23;
extern unsigned int cb_plex_verify (const size_t, const enum cb_support,
const char *);
extern const char *cb_copy_find_file (char *name, int has_ext);
extern void configuration_warning (const char *, const int,
const char *, ...) COB_A_FORMAT34;
extern void configuration_error (const char *, const int,
Expand Down
50 changes: 50 additions & 0 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,17 @@ output_gnucobol_defines (const char *formatted_date)
current_compile_tm.tm_sec;
output_line ("#define COB_MODULE_TIME\t\t%d", i);

{
struct cb_text_list *l = cb_include_file_list ;
for (;l;l=l->next){
if (l->text[0] == '<'){
output_line ("#include %s", l->text);
} else {
output_line ("#include \"%s\"", l->text);
}
}
}

}

/* CALL cache */
Expand Down Expand Up @@ -9260,6 +9271,39 @@ output_key_components (struct cb_file* f, struct cb_key_component* key_component
}
}


static void
output_indexed_file_key_colseq (const struct cb_file *f, const struct cb_alt_key *ak, int idx)
{
const cb_tree key = ak ? ak->key : f->key;
const cb_tree key_col = ak ? ak->collating_sequence_key : f->collating_sequence_key;
const int type = cb_tree_type (key, cb_code_field (key));
cb_tree col = NULL;

/* We only apply a collating sequence if the key is alphanumeric / display */
if ((type & COB_TYPE_ALNUM) || (type == COB_TYPE_NUMERIC_DISPLAY)) {
col = key_col ? key_col : f->collating_sequence;
#if 0 /* TODO: this should be done for national, when available */
} else if (type & COB_TYPE_NATIONAL) {
col = key_col_n ? key_col_n : f->collating_sequence_n;
#endif
}

output_prefix ();
if (idx == 0) {
output ("%s%s->collating_sequence = ", CB_PREFIX_KEYS, f->cname);
} else {
output ("(%s%s + %d)->collating_sequence = ", CB_PREFIX_KEYS, f->cname, idx);
}
if (col != NULL && CB_REFERENCE_P (col)) {
output_param (cb_ref(col), -1);
output (";");
} else {
output ("NULL;");
}
output_newline ();
}

static void
output_file_initialization (struct cb_file *f)
{
Expand Down Expand Up @@ -9320,6 +9364,9 @@ output_file_initialization (struct cb_file *f)
} else {
output_line ("%s%s->offset = 0;", CB_PREFIX_KEYS, f->cname);
}
if (f->organization == COB_ORG_INDEXED) {
output_indexed_file_key_colseq (f, NULL, 0);
}
nkeys = 1;
for (l = f->alt_key_list; l; l = l->next) {
output_prefix ();
Expand All @@ -9342,6 +9389,9 @@ output_file_initialization (struct cb_file *f)
f->cname, nkeys);
output_key_components (f, l->component_list, nkeys);
}
if (f->organization == COB_ORG_INDEXED) {
output_indexed_file_key_colseq (f, l, nkeys);
}
nkeys++;
}
#if 0 /* now done in cob_file_malloc / cob_file_external_addr */
Expand Down
6 changes: 5 additions & 1 deletion cobc/flag.def
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ CB_FLAG_NQ (1, "default-colseq", CB_FLAG_GETOPT_DEFAULT_COLSEQ,
_(" -fdefault-colseq=[ASCII|EBCDIC|NATIVE]\tdefine default collating sequence\n"
" * default: NATIVE"))

CB_FLAG_NQ (1, "default-file-colseq", CB_FLAG_GETOPT_DEFAULT_FILE_COLSEQ,
_(" -fdefault-file-colseq=[ASCII|EBCDIC|NATIVE]\tdefine default file collating sequence\n"
" * default: NATIVE"))

/* Binary flags */

/* Flags with suppressed help */
Expand Down Expand Up @@ -166,7 +170,7 @@ CB_FLAG (cb_flag_stack_check, 1, "stack-check",
_(" -fstack-check PERFORM stack checking\n"
" * turned on by --debug/-g"))

CB_FLAG_OP (1, "memory-check", CB_FLAG_MEMORY_CHECK,
CB_FLAG_OP (1, "memory-check", CB_FLAG_GETOPT_MEMORY_CHECK,
_(" -fmemory-check=<scope> checks for invalid writes to internal storage,\n"
" <scope> may be one of: all, pointer, using, none\n"
" * default: none, set to all by --debug"))
Expand Down
4 changes: 4 additions & 0 deletions cobc/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ cobc_print_usage_common_options (void)
puts (_(" -X, --Xref specify cross reference in listing"));
#endif
puts (_(" -I <directory> add <directory> to copy/include search path"));
puts (_(" --copy <copybook> include <copybook> at beginning of file,\n"
" as would COPY copybook."));
puts (_(" -L <directory> add <directory> to library search path"));
puts (_(" --include <file.h> add a #include \"file.h\" at the beginning of the C\n"
" generated file (implies -fno-gen-c-decl-static-call)"));
puts (_(" -l <lib> link the library <lib>"));
puts (_(" -K <entry> generate CALL to <entry> as static"));
puts (_(" -D <define> define <define> for COBOL compilation"));
Expand Down
Loading

0 comments on commit 32e98e0

Please sign in to comment.