Skip to content

Variable is not referenced in report (SVN ticket : #863)#94

Open
SBelondrade wants to merge 8 commits intoOCamlPro:gcos4gnucobol-3.xfrom
SBelondrade:gcos4gnucobol-3.x
Open

Variable is not referenced in report (SVN ticket : #863)#94
SBelondrade wants to merge 8 commits intoOCamlPro:gcos4gnucobol-3.xfrom
SBelondrade:gcos4gnucobol-3.x

Conversation

@SBelondrade
Copy link
Copy Markdown

Hi Simon, I'm using my second account for this pull request.

Reference svn ticket : #863.

I replaced printf by cb_warning_x but I think I have some problems of understanding.

If I understand, I have to remove two checks and this condition in codegen.c :

if((f->report_flag & COB_REPORT_LINE)
	&& f->children
	&& (f->children->report_flag & COB_REPORT_LINE)) {
		printf("Warning: Ignoring nested LINE %s %d\n",
			(f->report_flag & COB_REPORT_LINE_PLUS)?"PLUS":"",
			f->report_line);
		f->report_line = 0;
		f->report_flag &= ~COB_REPORT_LINE_PLUS;
		f->report_flag &= ~COB_REPORT_LINE;
	}

I added a new function and I called it finalize_report :

static  void
check_report (struct  cb_report *r, cb_tree  ctl)
{
	if (!ctl) {
		return ;
	}
	
	cb_tree  nx = CB_CHAIN(ctl);
	
	if (nx) {
		check_report(r, nx);
	}
	int  bfound = 0;
	cb_tree  x = CB_VALUE (ctl);
	struct  cb_field *s = cb_code_field(x);
	if((s->report_flag & COB_REPORT_LINE)
	  && s->children
	  && (s->children->report_flag & COB_REPORT_LINE)) {
		cb_warning_x (COBC_WARN_FILLER,
		CB_TREE(s), _("Warning: Ignoring nested LINE %s  %d"),
		  (s->report_flag & COB_REPORT_LINE_PLUS)?"PLUS":"",
			s->report_line);
			s->report_line = 0;
			s->report_flag &= ~COB_REPORT_LINE_PLUS;
			s->report_flag &= ~COB_REPORT_LINE;
	}
	for(int  i = r->num_lines-1; i >= 0; i--) {
		if(r->line_ids[i]->report_control) {
			struct  cb_field *c = cb_code_field (r->line_ids[i]->report_control);
			if(c == s) {
				bfound = 1;
				break;
			}
		}
	}
	if (!bfound) {
		cb_warning_x (COBC_WARN_FILLER,
		CB_TREE(ctl), _("Control field %s is not referenced in report"),
			s->name);
		ctl = NULL;
	}
}

But I don't pass some unit test. Please tell me if I haven´t understood what I had to do ?

Comment thread cobc/codegen.c Outdated
if (!bfound) {
cb_warning_x (COBC_WARN_FILLER,
CB_TREE(ctl), _("Control field %s is not referenced in report"), s->name);
ctl = NULL;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctl = NULL; is useless as ctl is a local variable.

Comment thread cobc/codegen.c Outdated
CB_TREE(ctl), _("Control field %s is not referenced in report"), s->name);
ctl = NULL;
p->controls = NULL;
return ;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if there is a list of more than one controls, and the first one is not used. If you only issue a warning and not an error, your code has to handle correctly such a case.

I would advise to clean up the controls at the beginning of the output_report_definition function, so that p->controls only contains controls that are used within the report.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify: output_control_report is called on nx recursively just before your test, for other controls, so if you set p->controls = NULL, you discard all of them. The list of controls is used several times, so doing the test every time would be too complex, the only solution I see is to cleanup the list once at the beginning.

Copy link
Copy Markdown
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my review comments for reasons that may be related to the test suite. Sorry for not paying that earlier (while I wrote those notes directly after you PR, I somehow missed to click on "submit review").

Furthermore please rebase.

Comment thread cobc/codegen.c Outdated
if(!bfound) {
printf("Control field %s is not referenced in report\n",s->name);
cb_warning_x (COBC_WARN_FILLER,
CB_TREE(ctl), _("Control field %s is not referenced in report"), s->name);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both this and the part above? Seem duplicated.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please start (nearly every) diagnostic with a lower-case letter; the only reason that this did not showed itself before is that it wasn't marked as msgid (the _() part that leads to translatable strings).

Comment thread cobc/codegen.c Outdated
&& (f->children->report_flag & COB_REPORT_LINE)) {
printf("Warning: Ignoring nested LINE %s %d\n",
cb_warning_x (COBC_WARN_FILLER,
CB_TREE(f), _("Warning: Ignoring nested LINE %s %d"),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "warning" prefix already is in by cb_warning, pleas drop that and start with lowercase letter.

Comment thread tests/testsuite.src/run_reportwriter.at Outdated
09 ERROR-2 PIC 9(3).
])

AT_CHECK([$COMPILE prog.cob], [0], [], [prog.cob:18: warning: Control field ERROR-1 is not referenced in report
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just minor style: please add a line break after [],

Comment thread tests/testsuite.src/run_reportwriter.at Outdated

AT_CLEANUP

AT_SETUP([Check if the variable is referenced in the report])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a syntax check, please move to syn_reportwriter, using $COMPILE_ONLY.

Please also add a test for the "ignoring nested line".

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #94 (bb2edcf) into gcos4gnucobol-3.x (6b44051) will increase coverage by 0.01%.
The diff coverage is 88.23%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@                  Coverage Diff                  @@
##           gcos4gnucobol-3.x      #94      +/-   ##
=====================================================
+ Coverage              65.39%   65.40%   +0.01%     
=====================================================
  Files                     32       32              
  Lines                  58797    58808      +11     
  Branches               15492    15496       +4     
=====================================================
+ Hits                   38449    38463      +14     
+ Misses                 14362    14361       -1     
+ Partials                5986     5984       -2     
Impacted Files Coverage Δ
cobc/codegen.c 75.39% <88.23%> (+0.06%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Copy Markdown
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked: this issue still happens both in 3.2 release (and therefore current 3.x branch) and trunk. it would be nice if this PR can be finished so that we can include it upstream.

Comment thread cobc/codegen.c Outdated
}
}
}
if (!bfound) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check, the warning and likely also the setting to null (or dropping the single unused control, as @lefessan pointed out) must be moved to typeck.c.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I moved this

Comment thread tests/testsuite.src/syn_reportwriter.at
Comment thread cobc/codegen.c Outdated
@@ -10229,7 +10246,8 @@ output_report_define_lines (int top, struct cb_field *f, struct cb_report *r)
if ((f->report_flag & COB_REPORT_LINE)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(originating lines 10229-10235) This should be moved to typeck.c, at least the warning.

sbelondr and others added 2 commits September 7, 2023 16:18
dropped trailing whiutespace - mostly to get the CI running...
@TimVold
Copy link
Copy Markdown

TimVold commented Mar 24, 2026

This fix does not appear to have been merged to trunk, yet.
I have not "up-voted" the bug on SourceForge, yet, either.
However, I'm wondering if there is a work-around that may be applied to a user's COBOL code?

Thanks in advance for any insights and all your fabulous work on GnuCOBOL.

Cheers,
Tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants