On Mon, 2025-02-17 at 13:42 -0500, James K. Lowden wrote:
> On Sat, 15 Feb 2025 23:35:16 -0500
> David Malcolm <dmalc...@redhat.com> wrote:
> 
> On better messages ...
> 
> > +                  if( ($$ & $2) == $2 ) {
> > +                    error_msg(@2, "%s clause repeated", clause);
> > +                    YYERROR;
> > +                  }
> > 
> > Obviously not needed for initial release, but it would be neat to
> > have
> > a fix-it hint here that deletes the repeated token (fixit hints are
> > done via class rich_location, FWIW)
> 
> Noted, thanks, 
> 
> > +                  if( $data_clause == redefines_clause_e ) {
> > +                    error_msg(@2, "REDEFINES must appear "
> > +                             "immediately after LEVEL and NAME");
> > +                    YYERROR;
> > +                  }
> > 
> > A strict reading of our diagnostic guidelines suggests that all of
> > these keywords in these messages should be in quotes, via %{ and
> > %}, or
> > via %qs.  But given that cobol has UPPERCASE KEYWORDS THAT ALREADY
> > REALLY STAND OUT, maybe that?s overkill.
> 
> I endeavored to report every keyword in uppercase.  The user isn't
> required to use uppercase; COBOL is (despite the official name, heh)
> case-insensitive.  But the fact of the keyword is all we have.  The
> lexer doesn't capture how the user typed it in; it reports only the
> presence of the token.  
> 
> In the case of user-defined names, the actual name supplied is
> captured and reported literally.  So, the user could have e.g. 
> 
>       001-Initialization Section.
> 
> where "Section" is a token whose input string is discarded, and 
> "001-Initialization" is a user-defined name whose supplied form is
> preserved, and reported verbatim.  
> 
> With that in mind, I propose a policy that builds on your observation
> (for gcc-16, not today):  Report token names in uppercase, unquoted,
> and user-defined names vebatim, quoted.  

Sounds reasonable to me.

> 
> I have that filed under "tasks for an eager volunteer, but probably
> me".  More tedious than difficult.  
> 
> > +                      error_msg(@2, "%s is binary NUMERIC type, "
> > +                               "incompatible with SIGN IS", field-
> > >name);
> > 
> > Again, this isn?t needed for the initial release, but GCCs
> > diagnostics
> > can have ?rules? associated with them, which can have URLs (see
> > diagnostic-metadata.h)  Is there a useful public standard for Cobol
> > with such rules that the output can link to?
> 
> There is no freely available COBOL standard.  IBM and Microfocus (and
> others) do publish their documentation on the  web, but the official
> standard is copyrighted and comes at a price.  Please write to your
> congressman.  
> 
> That said, it's been my ambition to tie every relevant message to the
> ISO standard in force at time of compilation.  To that end, I want to
> move all messages to a table keyed by ISO version and section number
> (or other, for -dialect option).  The caller would refer to the table
> by the key, and error_msg() et al. would report that information
> along with the message text.

For reference, I posted a patch to do this for the C++ frontend here:
https://gcc.gnu.org/pipermail/gcc-patches/2024-November/669105.html and
we do something similar in the rust frontend with error codes (see
class rust_error_code_rule in gcc/rust/rust-diagnostics.cc).

But as I said, this isn't at all needed for the initial release, of
course; just trying to be fancy.

>   
> 
> I don't know of another compiler that does that.  I don't mind
> showing them how it's done!  

Indeed, it's good to lead :)

[...snip...]

Dave

Reply via email to