Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

2025-11-27 Emilien Lemaire <[email protected]>

* parser.y, typeck.c, tree.h: add support for OR conditions in INSPECT
statements.

2025-11-01 Simon Sobisch <[email protected]>

* codegen.c (output_xml_parse): fixed xml state to be static-local
Expand Down
3 changes: 3 additions & 0 deletions cobc/config.def
Original file line number Diff line number Diff line change
Expand Up @@ -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 in inspect region"))
20 changes: 20 additions & 0 deletions cobc/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -15239,15 +15239,35 @@ inspect_before:
{
$$ = CB_BUILD_FUNCALL_1 ("cob_inspect_before", $3);
}
| BEFORE _initial inspect_or_list
{
cb_verify(cb_inspect_or, _("INSPECT with OR in inspect region"));
$$ = cb_build_inspect_or_before($3);
}
;

inspect_after:
AFTER _initial x
{
$$ = 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); };
Expand Down
2 changes: 2 additions & 0 deletions cobc/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions cobc/typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

2025-11-27 Emilien Lemaire <[email protected]>

* general: add inspect-with-or dialect support option
* mf-strict.conf: set inspect-with-or to ok

2025-04-22 Chuck Haatvedt <[email protected]>

* runtime.cfg: add runtime configuration COB_HEAP_MEMORY and
Expand Down
1 change: 1 addition & 0 deletions config/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/lax.conf-inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/mf-strict.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

2025-11-27 Emilien Lemaire <[email protected]>

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 <[email protected]>

* coblocal.h [__GNUC__]: only use C11's _Thread_local for gcc 5+
Expand Down
2 changes: 2 additions & 0 deletions libcob/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
20 changes: 20 additions & 0 deletions libcob/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down