Skip to content

Commit

Permalink
Merge SVN 4281
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Jun 13, 2024
1 parent 4388541 commit e140b9d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 84 deletions.
8 changes: 8 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,14 @@
* parser.y (use_reporting): check for valid identifier before use,
use common malloc for generated common

2021-05-05 Simon Sobisch <[email protected]>

* parser.y (emit_main_entry): extracted for re-use
* parser.y (emit_entry): override source location only upon
explicit request, we need entry points to be where the first
section/paragraph/statement comes to not confuse tools like GDB
with the wrong line reference (especially if we have DECLARATIVES)

2021-04-01 Ron Norman <[email protected]>

* codegen.c: Use cob_trace_get_stmt to get a number for the statement
Expand Down
77 changes: 45 additions & 32 deletions cobc/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ validate_using (cb_tree using_list)
}

static void
emit_entry (const char *name, const int encode, cb_tree using_list, cb_tree convention)
emit_entry (const char *name, const int encode, cb_tree using_list, cb_tree convention, int override_source_line)
{
cb_tree l;
cb_tree label;
Expand All @@ -510,7 +510,9 @@ emit_entry (const char *name, const int encode, cb_tree using_list, cb_tree conv
}
CB_LABEL (label)->flag_begin = 1;
CB_LABEL (label)->flag_entry = 1;
label->source_line = backup_source_line;
if (override_source_line) {
label->source_line = override_source_line;
}
emit_statement (label);

if (current_program->flag_debugging) {
Expand Down Expand Up @@ -590,6 +592,20 @@ emit_entry (const char *name, const int encode, cb_tree using_list, cb_tree conv
CB_BUILD_PAIR (label, CB_BUILD_PAIR(entry_conv, using_list)));
}

/* Main entry point and the number of its main parameters */
static void
emit_main_entry (struct cb_program *program, cb_tree using_list)
{
if (using_list) {
program->num_proc_params = cb_list_length (using_list);
}

emit_entry (program->program_id, 0, using_list, NULL, 0);
if (program->source_name) {
emit_entry (program->source_name, 1, using_list, NULL, 0);
}
}

static void
emit_entry_goto (const char *name)
{
Expand All @@ -604,7 +620,7 @@ emit_entry_goto (const char *name)
CB_LABEL (label)->flag_begin = 1;
CB_LABEL (label)->flag_entry = 1;
CB_LABEL (label)->flag_entry_for_goto = 1;
label->source_line = backup_source_line;
label->source_line = backup_source_line; /* CHECKME: is that correct? */
emit_statement (label);

for (l = current_program->entry_list_goto; l; l = CB_CHAIN (l)) {
Expand Down Expand Up @@ -1234,7 +1250,7 @@ end_scope_of_program_name (struct cb_program *program, const unsigned char type)
if (type == COB_MODULE_TYPE_FUNCTION) {
cb_error (_("FUNCTION '%s' has no PROCEDURE DIVISION"), program->program_name);
} else {
emit_entry (program->program_id, 0, NULL, NULL);
emit_main_entry (program, NULL);
}
}
program->last_source_line = backup_source_line;
Expand Down Expand Up @@ -3489,8 +3505,7 @@ start:
YYABORT;
}
if (!current_program->entry_list) {
backup_current_pos ();
emit_entry (current_program->program_id, 0, NULL, NULL);
emit_main_entry (current_program, NULL);
}
}
;
Expand Down Expand Up @@ -10255,12 +10270,8 @@ procedure_division:
}
_procedure_declaratives
{
/* Main entry point */
current_program->num_proc_params = cb_list_length ($6);
emit_entry (current_program->program_id, 0, $6, NULL);
if (current_program->source_name) {
emit_entry (current_program->source_name, 1, $6, NULL);
}

emit_main_entry (current_program, $6);
}
_procedure_list
{
Expand Down Expand Up @@ -10808,8 +10819,7 @@ statements:
}
if (check_headers_present (COBC_HD_PROCEDURE_DIVISION, 0, 0, 0) == 1) {
if (current_program->prog_type == COB_MODULE_TYPE_PROGRAM) {
backup_current_pos ();
emit_entry (current_program->program_id, 0, NULL, NULL);
emit_main_entry (current_program, NULL);
}
}

Expand Down Expand Up @@ -13106,7 +13116,7 @@ entry_body:
}
}
if (!cobc_check_valid_name ((char *)(CB_LITERAL ($2)->data), ENTRY_NAME)) {
emit_entry ((char *)(CB_LITERAL ($2)->data), 1, $4, call_conv);
emit_entry ((char *)(CB_LITERAL ($2)->data), 1, $4, call_conv, 0);
}
}
}
Expand Down Expand Up @@ -16155,14 +16165,14 @@ use_statement:

use_phrase:
use_file_exception
| use_debugging
| use_start_end
| use_reporting
| use_exception_list
| use_for_debugging
| use_at_start_end
| use_before_reporting
| use_after_exception
;

use_file_exception:
use_global _after _standard exception_or_error _procedure
_use_global _after _standard exception_or_error _procedure
_on use_file_exception_target
{
if (!in_declaratives) {
Expand All @@ -16188,7 +16198,7 @@ use_file_exception:
}
;

use_global:
_use_global:
/* empty */
{
use_global_ind = 0;
Expand Down Expand Up @@ -16237,7 +16247,7 @@ use_file_exception_target:
}
;

use_debugging:
use_for_debugging:
_for DEBUGGING _on debugging_list
{
cb_tree plabel;
Expand Down Expand Up @@ -16382,7 +16392,7 @@ _all_refs:
| OF
;

use_start_end:
use_at_start_end:
_at PROGRAM program_start_end
{
if (current_program->nested_level) {
Expand All @@ -16395,22 +16405,20 @@ program_start_end:
START
{
emit_statement (cb_build_comment ("USE AT PROGRAM START"));
backup_current_pos ();
CB_PENDING ("USE AT PROGRAM START");
/* emit_entry ("_AT_START", 0, NULL, NULL); */
/* emit_entry ("_AT_START", 0, NULL, NULL, 0); */
}
| END
{
emit_statement (cb_build_comment ("USE AT PROGRAM END"));
backup_current_pos ();
CB_PENDING ("USE AT PROGRAM END");
/* emit_entry ("_AT_END", 0, NULL, NULL); */
/* emit_entry ("_AT_END", 0, NULL, NULL, 0); */
}
;


use_reporting:
use_global BEFORE REPORTING identifier
use_before_reporting:
_use_global BEFORE REPORTING identifier
{
current_section->flag_real_label = 1;
current_section->flag_declaratives = 1;
Expand All @@ -16435,23 +16443,28 @@ use_reporting:
}
;

use_after_exception:
/* FIXME: should get optional _after */
use_ex_keyw use_exception_list
;

use_exception_list:
use_exception
| use_exception_list use_exception
;

use_exception:
use_ex_keyw exception_name
exception_name
{
current_section->flag_real_label = 1;
emit_statement (cb_build_comment ("USE AFTER EXCEPTION CONDITION"));
CB_PENDING ("USE AFTER EXCEPTION CONDITION");
}
| use_ex_keyw exception_name file_file_name_list
| exception_name file_file_name_list
{
cb_tree l;

for (l = $3; l; l = CB_CHAIN (l)) {
for (l = $2; l; l = CB_CHAIN (l)) {
if (CB_VALID_TREE (CB_VALUE (l))) {
setup_use_file (CB_FILE (cb_ref (CB_VALUE (l))));
}
Expand Down
10 changes: 5 additions & 5 deletions tests/testsuite.src/listings.at
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ blah 7 *10 11 14 x3

LABEL DEFINED REFERENCES

E prog__1 9
E prog__1 10
P EX 16 12 x1
GnuCOBOL V.R.P prog-1.cob DDD MMM dd HH:MM:SS YYYY Page 0005

Expand Down Expand Up @@ -1813,7 +1813,7 @@ stuff 9 *10 12 *16 x3

LABEL DEFINED REFERENCES

E prog__2 10
E prog__2 11
P MAIN 11 not referenced
P EX 18 14 x1

Expand Down Expand Up @@ -4767,7 +4767,7 @@ NEXT-JOB-SELECT 148 not referenced

LABEL DEFINED REFERENCES

E EDITOR 150
E EDITOR 152
P START-SECTION 152 not referenced
P TOP-OF-PAGE-ROUTINE 167 242 262 290 308 316
x5
Expand Down Expand Up @@ -5338,7 +5338,7 @@ NEXT-JOB-SELECT 148 not referenced

LABEL DEFINED REFERENCES

E EDITOR 150
E EDITOR 152
P START-SECTION 152 not referenced
P TOP-OF-PAGE-ROUTINE 167 242 262 290 308 316 x5
P READ-A-COMMAND 173 195 205 251 271 x4
Expand Down Expand Up @@ -5678,7 +5678,7 @@ CHARGE-DETAIL 65 99 x1

LABEL DEFINED REFERENCES

E prog 73
E prog 75
P 000-INITIATE 75 not referenced
P 000-TERMINATE 90 not referenced
P 100-PROCESS-TRANSACTION-DATA 98 87 x1
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite.src/run_file.at
Original file line number Diff line number Diff line change
Expand Up @@ -13881,7 +13881,7 @@ AT_CAPTURE_FILE(./trace.txt)
AT_DATA([reference],
[Source: 'prog.cob'
Program-Id: prog
Line: 279 Entry: prog
Line: 281 Entry: prog
Line: 281Paragraph: MAINFILE
Line: 282 OPEN
OPEN OUTPUT TSPFILE -> 'testisam' Status: 00
Expand Down Expand Up @@ -15336,7 +15336,7 @@ AT_CAPTURE_FILE(./trace.txt)
AT_DATA([reference],
[Source: 'prog.cob'
Program-Id: prog
Line: 290 Entry: prog
Line: 292 Entry: prog
Line: 292 Paragraph: MAINFILE
Line: 293 OPEN
OPEN OUTPUT TSPFILE -> 'testisam' Status: 00
Expand Down
Loading

0 comments on commit e140b9d

Please sign in to comment.