Skip to content

Commit 84359ec

Browse files
committed
Merge remote-tracking branch 'upstream/gnucobol-3.x' into gcos4gnucobol-3.x
2 parents cdb87a8 + 79c65d0 commit 84359ec

File tree

19 files changed

+582
-168
lines changed

19 files changed

+582
-168
lines changed

.github/workflows/windows-msvc.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,14 @@ jobs:
187187
# sed -i '/AT_SETUP(\[runtime check: write to internal storage (1)\])/a AT_SKIP_IF(\[true\])' tests/testsuite.src/run_misc.at
188188
sed -i '/run_misc/{N;/write to internal storage (1)/{N;N;N;N;s/traceon/traceon; echo "workflow:1">"$at_check_line_file"; at_fn_check_skip 77/;}}' tests/testsuite
189189
190-
# Fail two tests that behave differently under MSVC Debug
190+
# Fail tests that behave differently under MSVC Debug
191191
# - System routine CBL_GC_HOSTED: fails because libcob is linked with the debug version
192192
# of the C runtime while the generated module is linked with the release version
193-
# - PROGRAM COLLATING SEQUENCE: fails because of a data loss in a cast, due
194-
# to lack of specific handling of LOW/HIGH-VALUE for NATIONAL alphabets
195-
# (see typeck.c:cb_validate_collating)
196193
- name: Adjust testsuite for Debug target
197194
if: ${{ matrix.target == 'Debug' }}
198195
shell: C:\shells\msys2bash.cmd {0}
199196
run: |
200197
sed -i '/run_extensions/{N;/System routine CBL_GC_HOSTED/{N;s/at_xfail=no/at_xfail=yes/;}}' tests/testsuite
201-
sed -i '/syn_definition/{N;/PROGRAM COLLATING SEQUENCE/{N;s/at_xfail=no/at_xfail=yes/;}}' tests/testsuite
202198
203199
- name: Run testsuite
204200
run: |

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ NEWS - user visible changes -*- outline -*-
4343
later binary comparison of the field as well as on group MOVEs
4444
** #918: COB_LS_VALIDATE (io status 09 and 71) partial broken
4545

46+
** #948: Comparison with HIGH-VALUE in presence of collating sequences
47+
using a non-native program collating sequence together with the
48+
-febcdic-table option might now alter LOW/HIGH-VALUE
49+
4650
* Changes to the COBOL compiler (cobc) options:
4751

4852
** New option --copy COPYBOOK to load copybooks before parsing files. This

build_windows/makedist.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ if exist "%cob_source_path%doc\*.html" (
120120

121121
echo Copying configuration files...
122122
mkdir config
123-
set "config_ext_list=conf conf-inc words cfg"
123+
set "config_ext_list=conf conf-inc words cfg ttbl"
124124
for %%f in (%config_ext_list%) do (
125125
copy "%cob_source_path%config\*.%%f" config\ 1>nul
126126
)

cobc/ChangeLog

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
2025-04-04 David Declerck <[email protected]>
3+
4+
* cobc.c (process_filename): ensure we don't keep the preprocessed
5+
file when using -M or -fcopybook-deps
6+
* cobc.c, cobc.h, help.c, pplex.l: make -fcopybook-deps an experimental
7+
feature, activable with the EXPERIMENTAL_COPYBOOK_DEPS_OPTION flag
8+
29
2025-03-26 David Declerck <[email protected]>
310

411
* gentable.c: generate EBCDIC/ASCII translation tables
@@ -215,6 +222,30 @@
215222
also forces -E, -foneline-deps, -MT=copybooks, disables errors on
216223
missing copybooks and removes output on stdout
217224

225+
2024-02-26 David Declerck <[email protected]>
226+
227+
BUG #948: comparison with HIGH-VALUE in presence of collating sequences
228+
* tree.h (cb_program): add low_value and high_value fields to hold
229+
the low and high values used by the program collating sequence
230+
* tree.c (cb_build_program): initialize the low_value and
231+
high_value fields to reasonable default values
232+
* typeck.c: replace hard-coded cob_refer_ascii and
233+
cob_refer_ebcdic by ebcdic_to_ascii and ascii_to_ebcdic
234+
* typeck.c (cb_validate_collating): set the program's
235+
low_value and high_value fields
236+
* typeck.c (validate_alphabet): use the new tables,
237+
set the alphabet's low and high values
238+
* cobc.h: export the new symbols defined in typeck.c
239+
* cobc.c (process_command_line): always load the collating table
240+
* scanner.l (scan_ebcdic_char): remove code that loads and use a
241+
local collating table, use the table defined in typeck.c instead
242+
* codegen.c: replace hard-coded 0 and 255 / 0xff contants with
243+
the low_value and high_value fields where appropriate
244+
* codegen.c (output_low_value, output_high_value): move the
245+
cob_all_low and cob_all_high fields from global to local
246+
* codegen.c (output_collating_tables): remove local tables and code
247+
that loads the tables, since they are now loaded from cobc.c
248+
218249
2024-02-19 Boris Eng <[email protected]>
219250

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

cobc/cobc.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ int cb_depend_output_only = 0;
261261
int cb_depend_add_phony = 0;
262262
int cb_depend_keep_missing = 0;
263263
int cb_depend_target_auto = 0;
264+
#ifdef EXPERIMENTAL_COPYBOOK_DEPS_OPTION
264265
int cb_flag_copybook_deps = 0;
266+
#endif
265267

266268
/* set by option -fttitle=<title> */
267269
char *cb_listing_with_title = NULL;
@@ -634,7 +636,9 @@ static const struct option long_options[] = {
634636
{"MP", CB_NO_ARG, NULL, CB_FLAG_GETOPT_DEPEND_ADD_PHONY},
635637
{"MG", CB_NO_ARG, NULL, CB_FLAG_GETOPT_DEPEND_KEEP_MISSING},
636638
{"MD", CB_NO_ARG, NULL, CB_FLAG_GETOPT_DEPEND_ON_THE_SIDE},
639+
#ifdef EXPERIMENTAL_COPYBOOK_DEPS_OPTION
637640
{"fcopybook-deps", CB_NO_ARG, &cb_flag_copybook_deps, 1},
641+
#endif
638642
{"gentable", CB_RQ_ARG, NULL, CB_FLAG_GETOPT_GENTABLE},
639643
{"coverage", CB_NO_ARG, &cb_coverage_enabled, 1},
640644
{"P", CB_OP_ARG, NULL, 'P'},
@@ -4193,6 +4197,7 @@ process_command_line (const int argc, char **argv)
41934197
}
41944198
}
41954199

4200+
#ifdef EXPERIMENTAL_COPYBOOK_DEPS_OPTION
41964201
if (cb_flag_copybook_deps) {
41974202
/* same as -M, but only COPYBOOK names */
41984203
cb_depend_output = 1;
@@ -4201,6 +4206,7 @@ process_command_line (const int argc, char **argv)
42014206
cb_depend_add_phony = 0;
42024207
cb_compile_level = CB_LEVEL_PREPROCESS;
42034208
}
4209+
#endif
42044210
if (!cb_depend_output &&
42054211
(cb_depend_filename || cb_depend_add_phony || cb_depend_target
42064212
|| cb_depend_keep_missing)) {
@@ -4257,6 +4263,10 @@ process_command_line (const int argc, char **argv)
42574263
cb_flag_alt_ebcdic ? "alternate" : "default");
42584264
}
42594265

4266+
if (cob_load_collation (cb_ebcdic_table, ebcdic_to_ascii, ascii_to_ebcdic) < 0) {
4267+
cobc_err_exit (_("invalid parameter: %s"), "-febcdic-table");
4268+
}
4269+
42604270
/* Exit on missing options */
42614271
#ifdef COB_INTERNAL_XREF
42624272
if (cb_listing_xref && !cb_listing_outputfile) {
@@ -4640,7 +4650,7 @@ process_filename (const char *filename)
46404650
fn->preprocess = cobc_main_strdup (output_name);
46414651
} else
46424652
if (save_all_src || save_temps
4643-
|| cb_compile_level == CB_LEVEL_PREPROCESS) {
4653+
|| (cb_compile_level == CB_LEVEL_PREPROCESS && !cb_depend_output_only)) {
46444654
fn->preprocess = cobc_main_stradd_dup (fbasename, ".i");
46454655
} else {
46464656
fn->preprocess = cobc_main_malloc (COB_FILE_MAX);
@@ -9335,9 +9345,11 @@ process_file (struct filename *fn, int status)
93359345
const char *sep = " \\\n";
93369346
FILE *file = NULL;
93379347

9348+
#ifdef EXPERIMENTAL_COPYBOOK_DEPS_OPTION
93389349
if (cb_flag_copybook_deps) {
93399350
sep = "";
93409351
}
9352+
#endif
93419353
if (cb_depend_file) {
93429354
file = cb_depend_file;
93439355
} else {
@@ -9354,9 +9366,14 @@ process_file (struct filename *fn, int status)
93549366
fprintf (file, "%s:%s", basename, sep);
93559367
}
93569368

9357-
for (l = cb_depend_list; l; l = l->next) {
9358-
fprintf (file, " %s%s", l->text, l->next ? sep : "\n\n");
9369+
if (cb_depend_list) {
9370+
for (l = cb_depend_list; l; l = l->next) {
9371+
fprintf (file, " %s%s", l->text, l->next ? sep : "\n\n");
9372+
}
9373+
} else {
9374+
fprintf (file, "\n\n");
93599375
}
9376+
93609377
/* These lines should only be added with -MP */
93619378
if (cb_depend_add_phony) {
93629379
for (l = cb_depend_list; l; l = l->next) {

cobc/cobc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,9 @@ extern FILE *cb_src_list_file;
475475
extern FILE *cb_depend_file;
476476
extern int cb_depend_output;
477477
extern int cb_depend_keep_missing;
478+
#ifdef EXPERIMENTAL_COPYBOOK_DEPS_OPTION
478479
extern int cb_flag_copybook_deps;
480+
#endif
479481
extern struct cb_text_list *cb_depend_list;
480482
extern struct cb_text_list *cb_copy_list;
481483
extern struct cb_text_list *cb_include_file_list; /* global */
@@ -625,6 +627,9 @@ extern int yyparse (void);
625627
/* typeck.c */
626628
extern size_t suppress_warn; /* no warnings for internal generated stuff */
627629

630+
extern cob_u8_t ebcdic_to_ascii[256];
631+
extern cob_u8_t ascii_to_ebcdic[256];
632+
628633
/* error.c */
629634
#define CB_MSG_STYLE_GCC 0
630635
#define CB_MSG_STYLE_MSC 1U

cobc/codegen.c

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,23 +2522,23 @@ static void
25222522
output_low_value (void)
25232523
{
25242524
if (gen_figurative & CB_NEED_LOW) {
2525-
output ("static cob_field cob_all_low\t= ");
2526-
output ("{1, ");
2527-
output ("(cob_u8_ptr)\"\\0\", ");
2528-
output ("&cob_all_attr};");
2529-
output_newline ();
2525+
output_local ("static cob_field cob_all_low\t= ");
2526+
output_local ("{1, ");
2527+
output_local ("(cob_u8_ptr)\"\\x%02x\", ", current_prog->low_value);
2528+
output_local ("&cob_all_attr};");
2529+
output_local ("\n");
25302530
}
25312531
}
25322532

25332533
static void
25342534
output_high_value (void)
25352535
{
25362536
if (gen_figurative & CB_NEED_HIGH) {
2537-
output ("static cob_field cob_all_high\t= ");
2538-
output ("{1, ");
2539-
output ("(cob_u8_ptr)\"\\xff\", ");
2540-
output ("&cob_all_attr};");
2541-
output_newline ();
2537+
output_local ("static cob_field cob_all_high\t= ");
2538+
output_local ("{1, ");
2539+
output_local ("(cob_u8_ptr)\"\\x%02x\", ", current_prog->high_value);
2540+
output_local ("&cob_all_attr};");
2541+
output_local ("\n");
25422542
}
25432543
}
25442544

@@ -2622,8 +2622,6 @@ output_literals_figuratives_and_constants (void)
26222622

26232623
if (gen_figurative) {
26242624
output_newline ();
2625-
output_low_value ();
2626-
output_high_value ();
26272625
output_quote ();
26282626
output_space ();
26292627
output_zero ();
@@ -2661,18 +2659,6 @@ output_colseq_table_field (const char * field_name, const char * table_name)
26612659
static void
26622660
output_collating_tables (void)
26632661
{
2664-
cob_u8_t ebcdic_to_ascii[256];
2665-
cob_u8_t ascii_to_ebcdic[256];
2666-
2667-
/* Load the collating tables if needed */
2668-
if (gen_ascii_ebcdic || gen_ebcdic_ascii) {
2669-
if (cob_load_collation (cb_ebcdic_table,
2670-
gen_ebcdic_ascii ? ebcdic_to_ascii : NULL,
2671-
gen_ascii_ebcdic ? ascii_to_ebcdic : NULL) < 0) {
2672-
cobc_err_exit (_("invalid parameter: %s"), "-febcdic-table");
2673-
}
2674-
}
2675-
26762662
if (gen_native) {
26772663
output_storage ("\n/* NATIVE table */\n");
26782664
output_colseq_table ("cob_native", NULL);
@@ -4282,9 +4268,9 @@ output_funcall_typed (struct cb_funcall *p, const char type)
42824268
} else if (p->argv[1] == cb_zero) {
42834269
output (") - '0')");
42844270
} else if (p->argv[1] == cb_low) {
4285-
output ("))");
4271+
output (") - 0x%02x)", current_prog->low_value);
42864272
} else if (p->argv[1] == cb_high) {
4287-
output (") - 255)");
4273+
output (") - 0x%02x)", current_prog->high_value);
42884274
} else if (CB_LITERAL_P (p->argv[1])) {
42894275
output_char (") - ", CB_LITERAL (p->argv[1])->data[0], ")");
42904276
} else {
@@ -5069,10 +5055,10 @@ output_initialize_to_value (struct cb_field *f, cb_tree x,
50695055
output_figurative (x, f, ' ', init_occurs);
50705056
return;
50715057
} else if (value == cb_low) {
5072-
output_figurative (x, f, 0, init_occurs);
5058+
output_figurative (x, f, current_prog->low_value, init_occurs);
50735059
return;
50745060
} else if (value == cb_high) {
5075-
output_figurative (x, f, 255, init_occurs);
5061+
output_figurative (x, f, current_prog->high_value, init_occurs);
50765062
return;
50775063
} else if (value == cb_quote) {
50785064
if (cb_flag_apostrophe) {
@@ -10815,9 +10801,9 @@ output_class_name_definition (struct cb_class_name *p)
1081510801
} else if (x == cb_null) {
1081610802
vals[0] = 1;
1081710803
} else if (x == cb_low) {
10818-
vals[0] = 1;
10804+
vals[current_prog->low_value] = 1;
1081910805
} else if (x == cb_high) {
10820-
vals[255] = 1;
10806+
vals[current_prog->high_value] = 1;
1082110807
} else {
1082210808
size = CB_LITERAL (x)->size;
1082310809
data = CB_LITERAL (x)->data;
@@ -14162,6 +14148,9 @@ codegen_internal (struct cb_program *prog, const int subsequent_call)
1416214148
output_local ("\n");
1416314149
}
1416414150
}
14151+
14152+
output_low_value ();
14153+
output_high_value ();
1416514154
}
1416614155

1416714156
void

cobc/help.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ cobc_print_usage_common_options (void)
149149
puts (_(" -MG output missing dependencies without complaining"));
150150
puts (_(" -MD output dependencies in .d files while compiling"));
151151
puts (_(" -ext <extension> add file extension for resolving COPY"));
152+
#ifdef EXPERIMENTAL_COPYBOOK_DEPS_OPTION
152153
puts (_(" -fcopybook-deps output copybook names as dependencies"));
154+
#endif
153155
puts (_(" --gentable=<ebcdic-enc>,<ascii-enc>[+]\toutput a translation table between the\n"
154156
" given encodings to stdout and exit"));
155157
putchar ('\n');

cobc/pplex.l

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,11 @@ ppopen (const char *name, struct cb_replace_list *replacing_list)
14741474
}
14751475

14761476
/* add opened file to dependency list */
1477-
if (cb_depend_output && !cb_flag_copybook_deps) {
1477+
if (cb_depend_output
1478+
#ifdef EXPERIMENTAL_COPYBOOK_DEPS_OPTION
1479+
&& !cb_flag_copybook_deps
1480+
#endif
1481+
) {
14781482
cb_depend_list = pp_text_list_add (cb_depend_list, name, strlen (name));
14791483
}
14801484

@@ -1677,6 +1681,7 @@ ppcopy (const char *name, const char *lib, struct cb_replace_list *replace_list)
16771681
plexbuff1 = cobc_malloc ((size_t)COB_SMALL_BUFF);
16781682
}
16791683

1684+
#ifdef EXPERIMENTAL_COPYBOOK_DEPS_OPTION
16801685
if (cb_depend_output && cb_flag_copybook_deps) {
16811686

16821687
if (lib) {
@@ -1690,6 +1695,7 @@ ppcopy (const char *name, const char *lib, struct cb_replace_list *replace_list)
16901695
pp_text_list_add (cb_depend_list, plexbuff1,
16911696
strlen (plexbuff1));
16921697
}
1698+
#endif
16931699

16941700
/* TODO: open with path relative to the current file's path,
16951701
if any (applies both to with and without "lib") */
@@ -1762,12 +1768,14 @@ ppcopy (const char *name, const char *lib, struct cb_replace_list *replace_list)
17621768
/* otherwise fall-trough to error handling */
17631769
} else {
17641770
/* do not output error if looking only for copybook deps */
1765-
if (!cb_flag_copybook_deps){
1771+
#ifdef EXPERIMENTAL_COPYBOOK_DEPS_OPTION
1772+
if (!cb_flag_copybook_deps)
1773+
#endif
1774+
{
17661775

17671776
/* add opened file to dependency list */
17681777
if (cb_depend_output && cb_depend_keep_missing) {
17691778
const char *depname = cobc_plex_stradd (plexbuff1, cb_extension_list->text);
1770-
17711779
cb_depend_list = pp_text_list_add (cb_depend_list, depname, strlen (depname));
17721780
} else {
17731781

cobc/scanner.l

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,6 @@ static cob_u8_t
13571357
scan_ebcdic_char (int c)
13581358
{
13591359
char buff[10]; /* Arbitrary limit, mostly for error-reporting */
1360-
#ifndef COB_EBCDIC_MACHINE
1361-
static cob_u8_t ebcdic_to_ascii[256] ;
1362-
static int ebcdic_to_ascii_initialized = 0 ;
1363-
#endif
13641360
unsigned int j = 0;
13651361
do {
13661362
buff[j++] = (char)c;
@@ -1377,20 +1373,7 @@ scan_ebcdic_char (int c)
13771373
#ifdef COB_EBCDIC_MACHINE
13781374
return (cob_u8_t) c;
13791375
#else
1380-
if (!ebcdic_to_ascii_initialized ) {
1381-
if (cob_load_collation (cb_ebcdic_table, ebcdic_to_ascii, NULL) < 0) {
1382-
cb_error (_("invalid parameter: %s"), "-febcdic-table");
1383-
ebcdic_to_ascii_initialized = -1;
1384-
} else {
1385-
ebcdic_to_ascii_initialized = 1;
1386-
}
1387-
}
1388-
1389-
if (ebcdic_to_ascii_initialized > 0) {
1390-
return ebcdic_to_ascii[c];
1391-
} else {
1392-
return '?';
1393-
}
1376+
return ebcdic_to_ascii[c];
13941377
#endif
13951378
}
13961379

0 commit comments

Comments
 (0)