This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: named warnings & individual warning control

DJ Delorie <> writes:

> > What then would example code for
> > 
> >   if (pedantic)
> >     {
> >       if (ADJ_STD (fci->std) > C_STD_VER)
> >         status_warning (status, "%s does not support the %<%%%c%> %s format",
> >                         C_STD_NAME (fci->std), format_char, fki->name);
> >     }
> if (ADJ_STD (fci->std) > C_STD_VER)
>   status_message (status, MSG_format_unsupported_std, 
> 	          C_STD_NAME (fci->std), format_char, fki->name);

Hmmm.  Ick.  The latter is harder to write and harder to understand.
It's harder to write because you have to add a message in a different
place.  It's harder to understand because many of the warnings are
going to have very cryptic MSG_* names and the relationship between
the message and the parameters is obscured.  When all the messages are
converted it's going to be tedious to bounce around looking for the
actual message text.

We already have an obvious example of a system in which we keep the
text in the source code and are still able to describe the text in
various ways, namely gettext.  Why can't we emulate that for warnings?

  if (ADJ_STD (fci->std) > C_STD_VER)
    status_warning (status, "%s does not support the %<%%%c%> %s format",
                    C_STD_NAME (fci->std), format_char, fki->name);

Then you can easily change the message text without affecting whether
the warning can be controlled or not.  We associate a string with each
WARNTYPE, and optionally emit those strings with each message.  Those
strings are used to control whether the warnings are emitted or not.
We put the WARNTYPE categories into a tree, and give people ways to
control them at various levels.

This makes it easy to add new messages, slightly harder to add new
categories.  I think it is easier to write code like this, and
definitely easier to read it.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]