Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nested elements correctly when with attributes is specified #176

Open
wants to merge 3 commits into
base: gcos4gnucobol-3.x
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@

* pplex.l (cb_text_list): prevent duplicates

2024-08-30 Ammar Almorsi <[email protected]>

BUG #961: Nested Elements Mishandled Despite 'with attributes' Specification
* tree.c (set_ml_attrs_and_children): Enhanced the function to handle
the case where a child has attributes
* codegen.c (output_ml_suppress_checks): Modified the starting point
to start from the last attribute if present
* codegen.c (get_prev_ml_tree_entry): Removed the fallback case to
prevent infinite loops

2024-08-28 David Declerck <[email protected]>

* tree.c (char_to_precedence_idx, get_char_type_description, valid_char_order):
Expand Down
12 changes: 5 additions & 7 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -3485,8 +3485,6 @@ get_prev_ml_tree_entry (const struct cb_ml_generate_tree * const s)
} else {
return s->prev_sibling;
}
} else if (s->attrs) {
return get_last_attr (s);
} else if (s->parent) {
return s->parent;
} else {
Expand Down Expand Up @@ -8342,14 +8340,14 @@ output_ml_suppress_checks (struct cb_ml_suppress_checks * const suppress_checks)
struct cb_ml_generate_tree *tree;

/*
To resolve dependency problems, start from last child of last element.
To resolve dependency problems, start from last child/attribute of last element.
*/
if (orig_tree->children) {
tree = orig_tree;
if (tree->children) {
tree = get_last_child (orig_tree);
} else if (orig_tree->attrs) {
}
if (tree->attrs) {
tree = get_last_attr (orig_tree);
} else {
tree = orig_tree;
}

for (;;) {
Expand Down
16 changes: 12 additions & 4 deletions cobc/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1300,10 +1300,18 @@ set_ml_attrs_and_children (struct cb_field *record, const int children_are_attrs
continue;
}

child_tree_or_null = cb_build_ml_tree (child, 0,
children_are_attrs,
name_list, type_list,
suppress_list);
if (child->children) {
child_tree_or_null = cb_build_ml_tree (child, children_are_attrs,
0,
name_list, type_list,
suppress_list);
} else {
child_tree_or_null = cb_build_ml_tree (child, 0,
children_are_attrs,
name_list, type_list,
suppress_list);
}

if (!child_tree_or_null) {
continue;
}
Expand Down
34 changes: 34 additions & 0 deletions tests/testsuite.src/run_ml.at
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,40 @@ AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], [])
AT_CLEANUP


AT_SETUP([XML GENERATE WITH ATTRIBUTES])
AT_KEYWORDS([extensions])

AT_SKIP_IF([test "$COB_HAS_XML2" = "no"])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 out PIC X(200).
01 NSTD.
05 ATT1 pic x(4) value "ATT1".
05 CHLD1.
10 NSTD_ATT1 pic x(9) value "NSTD_ATT1".
10 NSTD_ATT2 pic x(9) value "NSTD_ATT2".
05 ATT2 pic x(4) value "ATT2".

GitMensch marked this conversation as resolved.
Show resolved Hide resolved
PROCEDURE DIVISION.
XML GENERATE out FROM NSTD WITH ATTRIBUTES
IF out <> '<NSTD ATT1="ATT1" ATT2="ATT2">'-
'<CHLD1 NSTD_ATT1="NSTD_ATT1" '-
'NSTD_ATT2="NSTD_ATT2"/></NSTD>'
DISPLAY 'Test 11 failed: ' FUNCTION TRIM (out)
END-IF
.
])

AT_CHECK([$COMPILE -fnot-reserved=ID prog.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], [])
AT_CLEANUP


AT_SETUP([XML GENERATE SUPPRESS])
AT_KEYWORDS([extensions])

Expand Down
Loading