Skip to content

Commit

Permalink
handle nested elements correctly when with attributes is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
ammaralmorsi committed Aug 30, 2024
1 parent fe28973 commit 433c294
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
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
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
.

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

0 comments on commit 433c294

Please sign in to comment.