diff --git a/cobc/ChangeLog b/cobc/ChangeLog index bbfb4836d..514a36369 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -1,9 +1,9 @@ 2023-07-09 Fabrice Le Fessant - * parser.y: fix code generation for INPUT/CLOSE with double arg - where DECLARATIVES for both arguments were called when only one - failed + * parser.y: fix code generation for OPEN/CLOSE with multiple + filenames, where DECLARATIVES for all arguments were called when + only one argument failed 2023-07-07 Simon Sobisch diff --git a/cobc/parser.y b/cobc/parser.y index 3de5618ad..d06d92491 100644 --- a/cobc/parser.y +++ b/cobc/parser.y @@ -447,17 +447,23 @@ begin_statement_at_tree_pos (enum cob_statement statement, const unsigned int te cobc_in_area_a = backup_in_area_a; } -/* create a new statement with base attributes of current_statement - and set this as new current_statement */ +/* create a new statement with base attributes of real_statement, the + location of pos and set this as new current_statement */ static void -begin_implicit_statement (void) +begin_implicit_statement (struct cb_statement* real_statement, cb_tree pos) { struct cb_statement *new_statement; - new_statement = cb_build_statement (current_statement->statement); + new_statement = cb_build_statement (real_statement->statement); new_statement->common = current_statement->common; new_statement->flag_in_debug = !!in_debugging; new_statement->flag_implicit = 1; - current_statement->body = cb_list_add (current_statement->body, + if (pos){ + cb_tree stmt_tree; + stmt_tree = CB_TREE (new_statement); + stmt_tree->source_file = pos->source_file; + stmt_tree->source_line = pos->source_line; + } + real_statement->body = cb_list_add (real_statement->body, CB_TREE (new_statement)); current_statement = new_statement; } @@ -12905,14 +12911,14 @@ close_files: is what would happen if we don't save the current statement and restore it. */ struct cb_statement * saved_current_statement = current_statement ; - begin_implicit_statement (); + begin_implicit_statement (current_statement, $1); cb_emit_close ($1, $2); current_statement = saved_current_statement ; } | close_files file_name _close_option { struct cb_statement * saved_current_statement = current_statement ; - begin_implicit_statement (); + begin_implicit_statement (current_statement, $2); cb_emit_close ($2, $3); current_statement = saved_current_statement ; } @@ -13081,13 +13087,13 @@ delete_file_list: file_name { #if 0 /* CHECKME: likely not needed */ - begin_implicit_statement (); + begin_implicit_statement (current_statement, $1); #endif cb_emit_delete_file ($1); } | delete_file_list file_name { - begin_implicit_statement (); + begin_implicit_statement (current_statement, $2); cb_emit_delete_file ($2); } ; @@ -14489,7 +14495,7 @@ generate_body: qualified_word { #if 0 /* CHECKME: likely not needed */ - begin_implicit_statement (); + begin_implicit_statement (current_statement, $1); #endif if ($1 != cb_error_node) { cb_emit_generate ($1); @@ -14743,7 +14749,7 @@ initiate_body: report_name { #if 0 /* CHECKME: likely not needed */ - begin_implicit_statement (); + begin_implicit_statement (current_statement, $1); #endif if ($1 != cb_error_node) { cb_emit_initiate ($1); @@ -14751,7 +14757,7 @@ initiate_body: } | initiate_body report_name { - begin_implicit_statement (); + begin_implicit_statement (current_statement, $2); if ($2 != cb_error_node) { cb_emit_initiate ($2); } @@ -15345,12 +15351,11 @@ open_file_entry: x = $1; } + struct cb_statement * top_statement = current_statement ; for (l = $5; l; l = CB_CHAIN (l)) { if (CB_VALID_TREE (CB_VALUE (l))) { - struct cb_statement * saved_current_statement = current_statement ; - begin_implicit_statement (); + begin_implicit_statement (top_statement, CB_VALUE(l)); cb_emit_open (CB_VALUE (l), $2, x); - current_statement = saved_current_statement ; } } } @@ -16940,7 +16945,7 @@ terminate_body: report_name { #if 0 /* CHECKME: likely not needed */ - begin_implicit_statement (); + begin_implicit_statement (current_statement, $1); #endif if ($1 != cb_error_node) { cb_emit_terminate ($1); @@ -16948,7 +16953,7 @@ terminate_body: } | terminate_body report_name { - begin_implicit_statement (); + begin_implicit_statement (current_statement, $2); if ($2 != cb_error_node) { cb_emit_terminate ($2); }