From dd5f5ae3075cec1806f9691908238dcdaedaf259 Mon Sep 17 00:00:00 2001 From: Emilien Lemaire Date: Wed, 26 Nov 2025 17:09:38 +0100 Subject: [PATCH 1/2] Allow inspect with `or` conditions --- cobc/config.def | 3 +++ cobc/parser.y | 20 ++++++++++++++++++++ cobc/tree.h | 2 ++ cobc/typeck.c | 25 +++++++++++++++++++++++++ libcob/common.h | 2 ++ libcob/strings.c | 20 ++++++++++++++++++++ 6 files changed, 72 insertions(+) diff --git a/cobc/config.def b/cobc/config.def index ce587c5a4..cbec9c2ca 100644 --- a/cobc/config.def +++ b/cobc/config.def @@ -442,3 +442,6 @@ CB_CONFIG_SUPPORT (cb_record_contains_depending_clause, "record-contains-dependi CB_CONFIG_SUPPORT (cb_picture_l, "picture-l", _("PICTURE string with 'L' character")) + +CB_CONFIG_SUPPORT (cb_inspect_or, "inspect-with-or", + _("INSPECT with OR conditions")) diff --git a/cobc/parser.y b/cobc/parser.y index 281473051..49cc9b63e 100644 --- a/cobc/parser.y +++ b/cobc/parser.y @@ -15239,6 +15239,11 @@ inspect_before: { $$ = CB_BUILD_FUNCALL_1 ("cob_inspect_before", $3); } + | BEFORE _initial inspect_or_list + { + cb_verify(cb_inspect_or, _("INSPECT or")); + $$ = cb_build_inspect_or_before($3); + } ; inspect_after: @@ -15246,8 +15251,23 @@ inspect_after: { $$ = CB_BUILD_FUNCALL_1 ("cob_inspect_after", $3); } + | AFTER _initial inspect_or_list + { + cb_verify(cb_inspect_or, _("INSPECT or")); + $$ = cb_build_inspect_or_after($3); + } ; +inspect_or_list: + x OR x + { + $$ = cb_list_add (CB_LIST_INIT ($1), $3); + } + | inspect_or_list OR x + { + $$ = cb_list_add ($1, $3); + } + /* JSON GENERATE statement */ json: JSON { check_non_area_a ($1); }; diff --git a/cobc/tree.h b/cobc/tree.h index fdb2f9e89..2f182d090 100644 --- a/cobc/tree.h +++ b/cobc/tree.h @@ -2510,6 +2510,8 @@ extern cb_tree cb_build_replacing_first (cb_tree, cb_tree, cb_tree); extern cb_tree cb_build_replacing_trailing (cb_tree, cb_tree, cb_tree); extern cb_tree cb_build_converting (cb_tree, cb_tree, cb_tree); extern cb_tree cb_build_inspect_region_start (void); +extern cb_tree cb_build_inspect_or_before (cb_tree); +extern cb_tree cb_build_inspect_or_after (cb_tree); extern int validate_move (cb_tree, cb_tree, const unsigned int, int *); extern cb_tree cb_build_move (cb_tree, cb_tree); diff --git a/cobc/typeck.c b/cobc/typeck.c index f29df4c8d..a409aea0f 100644 --- a/cobc/typeck.c +++ b/cobc/typeck.c @@ -10732,6 +10732,31 @@ cb_build_inspect_region_start (void) return CB_LIST_INIT (CB_BUILD_FUNCALL_0 ("cob_inspect_start")); } +cb_tree +cb_build_inspect_or_before (cb_tree candidates) +{ + cb_tree l = candidates; + cb_tree res = CB_LIST_INIT (CB_BUILD_FUNCALL_1 ("cob_inspect_or_before", CB_VALUE(l))); + for (l = CB_CHAIN (l); l; l = CB_CHAIN(l)) { + res = cb_list_add(res, CB_BUILD_FUNCALL_1 ("cob_inspect_or_before", CB_VALUE(l))); + } + + return res; +} + +cb_tree +cb_build_inspect_or_after (cb_tree candidates) +{ + cb_tree l = candidates; + cb_tree res = CB_LIST_INIT (CB_BUILD_FUNCALL_1 ("cob_inspect_or_after", CB_VALUE(l))); + for (l = CB_CHAIN (l); l; l = CB_CHAIN(l)) { + res = cb_list_add(res, CB_BUILD_FUNCALL_1 ("cob_inspect_or_after", CB_VALUE(l))); + } + + + return res; +} + /* MOVE statement */ static void diff --git a/libcob/common.h b/libcob/common.h index 6aa3155c5..e505fdc7b 100644 --- a/libcob/common.h +++ b/libcob/common.h @@ -1948,7 +1948,9 @@ COB_EXPIMP void cob_inspect_init (cob_field *, const cob_u32_t); COB_EXPIMP void cob_inspect_init_converting (cob_field *); COB_EXPIMP void cob_inspect_start (void); COB_EXPIMP void cob_inspect_before (const cob_field *); +COB_EXPIMP void cob_inspect_or_before (const cob_field *); COB_EXPIMP void cob_inspect_after (const cob_field *); +COB_EXPIMP void cob_inspect_or_after (const cob_field *); COB_EXPIMP void cob_inspect_characters (cob_field *); COB_EXPIMP void cob_inspect_all (cob_field *, cob_field *); COB_EXPIMP void cob_inspect_leading (cob_field *, cob_field *); diff --git a/libcob/strings.c b/libcob/strings.c index ea534cdb7..971fc6652 100644 --- a/libcob/strings.c +++ b/libcob/strings.c @@ -617,6 +617,16 @@ cob_inspect_before (const cob_field *str) cob_inspect_before_intern (&share_inspect_state, str); } +void +cob_inspect_or_before (const cob_field *str) { + unsigned char *end = share_inspect_state.end; + cob_inspect_before_intern (&share_inspect_state, str); + if (end < share_inspect_state.end) { + /* We found two matches, so we choose the first one in the inspected string */ + share_inspect_state.end = end; + } +} + static void cob_inspect_after_intern (struct cob_inspect_state *st, const cob_field *str) { @@ -632,6 +642,16 @@ cob_inspect_after (const cob_field *str) cob_inspect_after_intern (&share_inspect_state, str); } +void +cob_inspect_or_after (const cob_field *str) { + unsigned char *start = share_inspect_state.start; + cob_inspect_after_intern (&share_inspect_state, str); + if (share_inspect_state.start > start) { + /* We found two matches, so we choose the first one in the inspected string */ + share_inspect_state.start = start; + } +} + static void cob_inspect_characters_intern (struct cob_inspect_state *st, cob_field *f1) { From a9695c73c706749b709429a9a3e1a2e351c25f2a Mon Sep 17 00:00:00 2001 From: Emilien Lemaire Date: Thu, 27 Nov 2025 10:08:31 +0100 Subject: [PATCH 2/2] Update config, ChangeLogs and better warning --- cobc/ChangeLog | 5 +++++ cobc/config.def | 2 +- cobc/parser.y | 2 +- config/ChangeLog | 5 +++++ config/default.conf | 1 + config/lax.conf-inc | 1 + config/mf-strict.conf | 1 + libcob/ChangeLog | 7 +++++++ 8 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 75d9c7a4a..2cf598e0f 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -1,4 +1,9 @@ +2025-11-27 Emilien Lemaire + + * parser.y, typeck.c, tree.h: add support for OR conditions in INSPECT + statements. + 2025-11-01 Simon Sobisch * codegen.c (output_xml_parse): fixed xml state to be static-local diff --git a/cobc/config.def b/cobc/config.def index cbec9c2ca..8790e5e4d 100644 --- a/cobc/config.def +++ b/cobc/config.def @@ -444,4 +444,4 @@ CB_CONFIG_SUPPORT (cb_picture_l, "picture-l", _("PICTURE string with 'L' character")) CB_CONFIG_SUPPORT (cb_inspect_or, "inspect-with-or", - _("INSPECT with OR conditions")) + _("INSPECT with OR conditions in inspect region")) diff --git a/cobc/parser.y b/cobc/parser.y index 49cc9b63e..8371c80de 100644 --- a/cobc/parser.y +++ b/cobc/parser.y @@ -15241,7 +15241,7 @@ inspect_before: } | BEFORE _initial inspect_or_list { - cb_verify(cb_inspect_or, _("INSPECT or")); + cb_verify(cb_inspect_or, _("INSPECT with OR in inspect region")); $$ = cb_build_inspect_or_before($3); } ; diff --git a/config/ChangeLog b/config/ChangeLog index 24c4bde7c..2acd3a6c6 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,4 +1,9 @@ +2025-11-27 Emilien Lemaire + + * general: add inspect-with-or dialect support option + * mf-strict.conf: set inspect-with-or to ok + 2025-04-22 Chuck Haatvedt * runtime.cfg: add runtime configuration COB_HEAP_MEMORY and diff --git a/config/default.conf b/config/default.conf index c4510e71c..a31e85c18 100644 --- a/config/default.conf +++ b/config/default.conf @@ -303,6 +303,7 @@ record-contains-depending-clause: unconformable defaultbyte: init # GC inits as INITIALIZE ALL TO VALUE THEN TO DEFAULT, # with INDEXED BY variables initialized to 1 picture-l: ok +inspect-or: warning # use complete word list; synonyms and exceptions are specified below reserved-words: default diff --git a/config/lax.conf-inc b/config/lax.conf-inc index 6f473d08d..b83b98b20 100644 --- a/config/lax.conf-inc +++ b/config/lax.conf-inc @@ -134,6 +134,7 @@ assign-ext-dyn: ok assign-disk-from: ok vsam-status: +ignore picture-l: +warning +inspect-or: +warning # use complete word list diff --git a/config/mf-strict.conf b/config/mf-strict.conf index ee5d8b8fb..b6f9e703b 100644 --- a/config/mf-strict.conf +++ b/config/mf-strict.conf @@ -284,6 +284,7 @@ self-call-recursive: skip record-contains-depending-clause: unconformable defaultbyte: " " picture-l: unconformable +inspect-with-or: ok # use fixed word list, synonyms and exceptions specified there reserved-words: MF diff --git a/libcob/ChangeLog b/libcob/ChangeLog index a0dfdc7b0..2363db3ad 100644 --- a/libcob/ChangeLog +++ b/libcob/ChangeLog @@ -1,4 +1,11 @@ +2025-11-27 Emilien Lemaire + + initial support of OR conditions in inspect regions + * common.h, strings.c: add cob_inspect_or_before and + cob_inspect_or_after to support INSPECT statements with OR + conditions in inspect regions + 2025-11-13 Simon Sobisch * coblocal.h [__GNUC__]: only use C11's _Thread_local for gcc 5+