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

Allow paragraph names to redefine field and section names #31

Draft
wants to merge 1 commit into
base: gcos4gnucobol-3.x
Choose a base branch
from

Conversation

ddeclerck
Copy link
Contributor

@ddeclerck ddeclerck commented Mar 28, 2022

This allows a paragraph to have the same name as a previous field or section.

It is not clear whether this is actually allowed or not by the standard or the GCOS dialect, however our customer does have Cobol programs where some paragraphs have the same name as fields or sections. Further discussion is probably required.

Below are the relevant excerpt from the standards for reference.

Both the COBOL 85 standard and GCOS say :

Within a given source program, but excluding any contained program, the user-defined words are grouped into the following disjoint sets:
{ ..., data-names, ..., paragraph-names, ..., section-names, ... }
All user-defined words, except segment-numbers and level-numbers, can belong to one and only one of these disjoint sets. Further, all user-defined words within a given disjoint set must be unique, except as specified in the rules for uniqueness of reference.

(nb: these rules say nothing about paragraphs)

The 2014 standard is a bit different :

Within a source element, a given user-defined word may be used as only one type of user-defined word with the
following exceptions:

  1. a compilation-variable-name may be the same as any other type of user-defined word
  2. a level-number may be the same as a paragraph-name or a section-name
  3. the same name may be used as any of the following types of user-defined words:
  • constant-name
  • data-name
  • property-name
  • record-key-name
  • record-name

The wording in item 3 is rather ambiguous...

@GitMensch
Copy link
Collaborator

It seems this is https://sourceforge.net/p/gnucobol/feature-requests/260 - in this case please check the discussion there and let us discuss the issue itself there (patches and changes here are still ok).

@ddeclerck ddeclerck force-pushed the relax_paragraph_section_name_uniqueness branch 3 times, most recently from 8846569 to b9125e9 Compare March 29, 2022 12:23
@nberth nberth changed the title Allow paragraph names to redefine field and section names [WIP] Allow paragraph names to redefine field and section names May 20, 2022
@nberth
Copy link
Contributor

nberth commented May 20, 2022

(Marked as WIP as awaiting a rebase w.r.t gcos4gnucobol-3.x)

@GitMensch
Copy link
Collaborator

You've likely done that - but the actual syntax test is missing; it should cover:

  • data name and paragraph name identical
  • data name and section name identical

is there more? I think this can go "upstream" very soon, I guess you want to commit a GCOS base commit with NEWS entry and -std (so conf and words) first.

@GitMensch
Copy link
Collaborator

GitMensch commented May 25, 2022

The test from the FR may be used - word.cob

       identification division.
       program-id. word.
       data division.
       working-storage section.
      *-----------------------------------------------------------------
       77 word  pic 9.
       77 word2 pic x.
      *-----------------------------------------------------------------
       PROCEDURE DIVISION.
       main section.
      *
           move 0 to word
           perform word
      *
           exit program returning word.
      *-----------------------------------------------------------------
       entry "word2".
       word section.
      *
           add 1 to word
           if word = 2 goto word2.
           add 1 to word.
      *
       word2.
      *
           continue.
      *-----------------------------------------------------------------

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.

Some minor adjustments needed, but nearly finished - the SF feature-request is now assigned to you, too :-)

@ddeclerck ddeclerck force-pushed the relax_paragraph_section_name_uniqueness branch from b9125e9 to 1d1b32f Compare May 30, 2022 08:28
@ddeclerck ddeclerck changed the base branch from old-gcos4gnucobol-3.x to gnucobol-3.x May 30, 2022 08:29
@ddeclerck ddeclerck changed the base branch from gnucobol-3.x to gcos4gnucobol-3.x May 30, 2022 08:30
@ddeclerck ddeclerck force-pushed the relax_paragraph_section_name_uniqueness branch 2 times, most recently from 8677b94 to ceaa925 Compare May 30, 2022 15:01
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.

in general this could be either committed before or after the GCOS "base commit"

cobc/error.c Outdated
default:
return 0;
}
#ifndef _MSC_VER
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be necessary because of the default above returns like all other paths. But if I remember correctly the "multiple case, then default" will raise a warning with different compilers, maybe drop that #ifndef and the case statements before the default?
Note: I'm always open to learn something new, maybe I've missed something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just an occurrence of careless copy-paste (I made this function by copying cb_verify_x). Indeed the #ifndef should not be necessary.
I'm not aware of compilers specifically warning for falling through "into" the default case, though some compilers do have warnings (usually disabled) for fall-through in general.
Anyways, I'll just remove the default case and let the function return 0.

@@ -1938,8 +1938,15 @@ cb_build_section_name (cb_tree name, const int sect_or_para)
if (!CB_LABEL_P (x) || sect_or_para == 0 ||
(sect_or_para && CB_LABEL_P (x) &&
CB_LABEL (x)->flag_section)) {
redefinition_error (name);
return cb_error_node;
if (cb_is_supported(cb_non_unique_procedure_names) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be something like:

			if ((CB_FIELD_P (x) ||
			     (CB_LABEL_P (x) && CB_LABEL (x)->flag_section))) {
			        cb_verify (cb_non_unique_procedure_names, _("non-unique procedure-name"));
			} else {
				redefinition_error (name);
				return cb_error_node;
			}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered that first, but that would generate a different error message when a field or section name redefinition is forbidden by the non-unique-procedure-name option being set to error or unconformable (I wanted the error message to remain the same, regardless of the reason why the redefinition is forbidden).

[prog.cob: in section 'L':
prog.cob:6: warning: non-unique section or paragraph name used
])
AT_CHECK([$COMPILE_ONLY -fnon-unique-procedure-names=error prog.cob], [1], [],
[prog.cob: in section 'L':
prog.cob:6: error: redefinition of 'L'
prog.cob:5: note: 'L' previously defined here
Copy link
Collaborator

Choose a reason for hiding this comment

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

the FIXME below can be removed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is everything of https://github.com/OCamlPro/gnucobol/pull/31#issuecomment-1137626598 already covered? If not then please add it as new testcase compiling once without std (expected warning with zero status) and with -std-cobol2002 (expecting error -> status 1)

Copy link
Contributor

Choose a reason for hiding this comment

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

I've added the new test; for now it does not pass and reports an ambiguity. We are currently checking whether this one should indeed pass on GCOS.

On that note, the FR links to a former implementation are all broken. Is there another place where that previous attempt can be investigated?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, yes these are the old artifact links, just replace "open-cobol" in the URL with "gnucobol" to fix those manually.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes indeed; somehow I had forgotten that was a former name for gnucobol.

Anyways, as far as our tests go, GCOS appears to subject uses of identical names for sections/paragraphs and data to syntactic scoping rules (as mentioned by David in the FR). This is the behavior of the current implementation.
For this reason we should expect the test cases imported from the FR to fail.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If there's a section and a paragraph defined and you have PERFORM same-name in GCOS that is auto-scoped?
So if you do it from main section it will call the section with that name, but if you call it from other-section that has the same-name paragraph defined it uses that?
I'm a bit skeptic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If there's a section and a paragraph defined and you have PERFORM same-name in GCOS that is auto-scoped?
So if you do it from main section it will call the section with that name, but if you call it from other-section that has the same-name paragraph defined it uses that?
I'm a bit skeptic.

The part "what does GCOS do if there is both a section and a paragraph name with the same word" is the most important one not answered (or - totally possible: answered but I've overlooked that).

Would it be useful to go with a lesser version first that matches the old FR? This would be procedure-shares-data-name or similar.

@nberth nberth force-pushed the relax_paragraph_section_name_uniqueness branch 2 times, most recently from b7e3028 to d9b858f Compare June 22, 2022 07:54
@nberth nberth force-pushed the relax_paragraph_section_name_uniqueness branch from d9b858f to 5a44c20 Compare June 22, 2022 08:50
@nberth nberth marked this pull request as draft July 8, 2022 09:04
@nberth nberth changed the title [WIP] Allow paragraph names to redefine field and section names Allow paragraph names to redefine field and section names Jul 8, 2022
@GitMensch
Copy link
Collaborator

GitMensch commented Oct 4, 2022

Would it be useful to go with a lesser version first that matches the old FR? This would be procedure-shares-data-name or similar [hopefully with a better name, because once found we should not change it in any 3.x].

friendly ping

@nberth
Copy link
Contributor

nberth commented Oct 5, 2022

friendly ping

Our migration project does not appear to require this anymore. As this may still be quite useful for other cases, I'll try to see if I can do something quick after a rebase/merge on gcos4gnucobol-3.x in the coming days; if not I'm afraid this will need to wait as I do not have much time to allocate on that in the short term.

@GitMensch
Copy link
Collaborator

friendly ping to recheck if this can be rebased and possibly "slimmed down" a bit for now

Would it be useful to go with a lesser version first that matches the old FR? This would be procedure-shares-data-name or similar [hopefully with a better name, because once found we should not change it in any 3.x].

... actually it would then likely be more reasonable to start in a new (recent) branch and "only" add the "slimmed down" code there, handling the rebase here after we merged that new "slim" version

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