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 1 commit
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
@@ -1,4 +1,14 @@

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 @@ -8333,14 +8331,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
4 changes: 4 additions & 0 deletions tests/ChangeLog
GitMensch marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

2024-08-30 Ammar Almorsi <[email protected]>
* testsuite.src/run_ml.at: Added new test case to verify the correct
generation of nested XML attributes

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

* testsuite.src/run_file.at, testsuite.src/run_misc.at:
Expand Down
15 changes: 15 additions & 0 deletions tests/testsuite.src/run_ml.at
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ AT_DATA([prog.cob], [
05 name PIC X(10) value "Someone".
05 dept PIC X(10) value "Marketing".

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".

PROCEDURE DIVISION.
XML GENERATE out
FROM rec
Expand Down Expand Up @@ -117,6 +124,14 @@ AT_DATA([prog.cob], [
DISPLAY 'Test 10 failed: ' FUNCTION TRIM (out)
END-IF
.

GitMensch marked this conversation as resolved.
Show resolved Hide resolved
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], [], [])
Expand Down
Loading