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

Fix for bug #831: COPY REPLACING in listing #92

Open
wants to merge 14 commits into
base: gcos4gnucobol-3.x
Choose a base branch
from

Conversation

sbelondr
Copy link

@sbelondr sbelondr commented Mar 7, 2023

Hi @GitMensch,

I propose the following fixes for the bugs :

  • #831 (Problem for the copy replacing in listing mode) ;
  • #863 (Variable is not referenced in report).

For the bug #863, I just add a loop to check if the variable exist (codegen.c). I added a test in run_reportwriter.at.

For the bug #831 I rewrite partialy the listing mode in the cobc.c file and I add 2 struct in tree.h for manage lines and replacements.

I added a test in the listings.at file (name : Multiple replacement) and I completed two tests (just add the expect.lst file) :

  • COPY replacement with multiple partial matches ;
  • COPY replacement with partial match.

But I didn't pass the huge REPLACE test because I add more space of the default implementation (8 precisely).

I would like to know if the implementation is right for you (I remove backtracking) ?

@GitMensch
Copy link
Collaborator

GitMensch commented Mar 7, 2023

Thanks you for working on this. Note that two PRs, one for each change are commonly more easy to review.

Let's start with the most easiest one: 863.
Please adjust the check to be done in finalize_report, changing Control field %s is not referenced in report to a warning (the printf is wrong and codegen is too late in general).
It is fine to set the control field to NULL there if we don't need it in other places (the only one that comes to mind would be the symbol listing), which allows to drop the check you've added to codegen and the old check, that raised the warning via printf.

Please move also the other code fro codegen.c with printf to finalize_report and change it to raise a warning:

	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;
	}

Both places can use cb_warning (COBC_WARN_FILLER, _(warning_msg_here)); - or cb_warning_x if this is more reasonable to get the right warning position.

A PR with those adjustments can be reviewed quickly and would definitely be fine for inclusion into the 3.x branch before the upcoming RC3 (roughly planned for end of the week, maybe a bit earlier).

cobc/cobc.c Outdated
@@ -6619,8 +6675,10 @@ print_line (struct list_files *cfile, char *line, int line_num, int in_copy)
struct list_skip *skip;
int do_print;
int on_off;
char pch;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please leave local defintions in, we try to limit scope where possible

cobc/cobc.c Outdated

cmp_line[0] = 0;
bzero (cmp_line, CB_LINE_LENGTH + 2);
Copy link
Collaborator

@GitMensch GitMensch Mar 7, 2023

Choose a reason for hiding this comment

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

From its manpage:

The bzero() function is deprecated (marked as LEGACY in POSIX.1-2001); use memset(3) in new programs. POSIX.1-2008 removes the specification of bzero().

The best option is to do it before the caller:

char	cmp_line[CB_LINE_LENGTH + 2] = { 0 };

cobc/cobc.c Outdated
make_new_continuation_line (cfile_name, pline,
pline_cnt, line_num);
}
// calculation the len char
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use C89 comments here and in other places

-	// calculation the len char
+	/* calculation the len char */

cobc/cobc.c Outdated
@@ -7393,6 +7214,43 @@ cleanup_copybook_reference (struct list_files *cur)
cobc_free (cur);
}

static
char *get_word (char *str)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please move those two after get_next_nonspace to group those functions

print_line (cfile, pline[i], line_num + i, 0);
pline[i][0] = 0;
}
struct list_files *cur;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please combine the assignment into this line - nice scoping btw :-)

const int margin_a = cobc_get_margin_a (1);
int cnt_space = 0;
int j = 0;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like most of DEBUG_REPLACE is now out, was this explicit planned?
Did you use that to get an idea where the issue is?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ping @sbelondr

Copy link
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.

Please split this PR into two ones, as mentioned I think the one for the report stuff # 863 should be quite easy to get through.

We can keep this PR for # 831; so far I did make some minor review comments and get a general overview (not there yet, need to combe back to this later...); I see that the issues we had - marked as AT_XFAIL_IF (true) are solved, as you've mentioned one of the older REPLACE tests now fail, mostly because the replacement is done by starting on the next line instead of the original one. Can you adjust that?

@sbelondr
Copy link
Author

sbelondr commented Mar 8, 2023

Thank you for the feedback.
I'm working on it.

@GitMensch GitMensch changed the title Fix for the svn tickets #831 and #863 Fix for bug #831: COPY REPLACING in listing Jun 13, 2023
Copy link
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.

please check the first review parts and consider handling the new cb_partial_replace_when_literal_src setting (otherwise thi can be included later)

please also fix the non-C89 definition - see the results of the new CI check (in detail here: https://github.com/OCamlPro/gnucobol/actions/runs/5392577360/jobs/9791122631#step:8:125)

I'll the review the result with a local checkout; the diff looks huge (and bigger as it is, while it is still big)

cobc/ChangeLog Outdated Show resolved Hide resolved
cobc/tree.h Outdated Show resolved Hide resolved
tests/ChangeLog Outdated
@@ -761,7 +767,7 @@
* testsuite.src/*.at: Added check for cobc's exit code and stderr
where missing

2014-14-04 Philipp B�hme <[email protected]>
2014-14-04 Philipp B�hme <[email protected]>
Copy link
Collaborator

Choose a reason for hiding this comment

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

somethings broken here, maybe you can revert the line (otherwise I can do it after merging)

Copy link
Author

Choose a reason for hiding this comment

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

I'll take care of that in the next commit

cobc/cobc.c Outdated
if (!str) {
return NULL;
}
while (str[i] && isspace (str[i])) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about separator commas and separator semicolons?
The old code used isspace ((unsigned char)*bp) || *bp == ',' || *bp == '.' || *bp == ';'.

Copy link
Author

Choose a reason for hiding this comment

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

I also put that before but when I read the documentation I didn't understand why these characters is understood as a space and this not change the result of the test. I'll try other test for compare old replacing with the new replacing for check the differences

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: it obviously would be good to have this in the testsuite, too.
In effect the point is that there are multiple "separators" - all "space characters", newline, separator semicolon and separator comma.
The last one is a bit tricky as, depending on DECIMAL-POINT IS COMMA this may or may not mean that "3,2" has to be separated (=2 "words"/tokens), while "3,a" would always mean two tokens. [note: the listing may "don't care" about that at all or always ignore the comma if DECIMAL-POINT IS COMMA is in effect].

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think those testcases are missing, right?

cobc/cobc.c Show resolved Hide resolved
cobc/cobc.c Outdated Show resolved Hide resolved
cobc/cobc.c Outdated Show resolved Hide resolved
cobc/cobc.c Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jun 28, 2023

Codecov Report

Merging #92 (f7e680e) into gcos4gnucobol-3.x (743651f) will increase coverage by 0.27%.
The diff coverage is 79.46%.

❗ 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      #92      +/-   ##
=====================================================
+ Coverage              65.19%   65.46%   +0.27%     
=====================================================
  Files                     31       32       +1     
  Lines                  58363    58895     +532     
  Branches               15377    15514     +137     
=====================================================
+ Hits                   38050    38558     +508     
+ Misses                 14382    14316      -66     
- Partials                5931     6021      +90     
Impacted Files Coverage Δ
cobc/scanner.l 75.44% <38.46%> (-0.40%) ⬇️
libcob/common.c 56.62% <40.00%> (-0.02%) ⬇️
cobc/pplex.l 72.26% <56.19%> (-0.26%) ⬇️
cobc/ppparse.y 61.96% <66.66%> (+0.81%) ⬆️
cobc/parser.y 68.55% <71.48%> (-0.12%) ⬇️
cobc/cobc.c 73.32% <79.38%> (+2.04%) ⬆️
cobc/typeck.c 64.81% <83.60%> (-0.13%) ⬇️
cobc/codegen.c 75.33% <84.93%> (+0.12%) ⬆️
cobc/replace.c 95.26% <95.26%> (ø)
cobc/codeoptim.c 27.44% <100.00%> (+0.56%) ⬆️
... and 2 more

... and 2 files with indirect coverage changes

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

@GitMensch
Copy link
Collaborator

@sbelondr: please adjust the testsuite changes - we moved from separate "expected.lst" to "list in stdout", so the changed expectation must be adjusted there (you currently have it just added as new AT_DATA)

cobc/cobc.c Outdated
while (line[i])
{
/* loop space */
while (line[i] && isspace (line[i]) && !is_quotes_char (line[i], &simple_quote, &double_quote) && NOT_TOO_LONG (i, start)) {
Copy link
Collaborator

@GitMensch GitMensch Aug 23, 2023

Choose a reason for hiding this comment

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

We have isspace (line[i]), so how should be (line[i]) be a quote?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it's useless. I removed that

@@ -6741,6 +6783,146 @@ print_fixed_line (const int line_num, char pch, char *line)
}
}

static int
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a doc comment before the function so it is clear what is checks/changes.

Also: does the code handle an "escaped "" quote like in x""4100"""?

Copy link
Author

Choose a reason for hiding this comment

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

I added a comment for this function but I didn't understand this format x""4100"".

I think that I'm not handling this but I can't find this in the old code.

Is this "translated" in the code to something else ?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for this ping @GitMensch, can I have more information on this ?

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.

3 participants