This is the mail archive of the gcc-patches@gcc.gnu.org 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: add "%J" for diagnostics (Redux. Positional format specifierfor diagnostic)


Richard Henderson wrote:
On Tue, Sep 23, 2003 at 06:42:23AM +0900, Chiaki wrote:

The way I read text_specifies_location() and routines in
pretty-print.c suggests that the similar handling now performed for
"%H" at the beginning of a format string needs to be done for '%J'.

Or am I missing something here?


You are missing something.

  /* Extract the location information if any.  */
  if (p[0] == '%' && p[1] == 'H')
    {
      *locus = *va_arg (*text->args_ptr, location_t *);
      text->format_spec = p + 2;
      return true;
    }
  else if (p[0] == '%' && p[1] == 'J')
    {
      tree t = va_arg (*text->args_ptr, tree);
      *locus = DECL_SOURCE_LOCATION (t);
      text->format_spec = p + 2;
      return true;
    }

The code IS present.


I assume that like "%H", "%J" is meant to come only at the beginning
of a format string.  Am I correct in this assumpition?


Yes.

Thank you for the quick response (and sorry for the mistyped e-mail addresses in the original posting.)


The code which I think is missing is NOT in diagnostic.c but
in pretty-print.c: Namely  shouldn't we add
case 'J': before (or immediately after)
case 'H' in pp_base_format_text() in pretty-print.c?

Actually, now come to think of it,
if I recall correctly, the portion of the code in
pretty-print.c is NOT executed if we don't support
positional format specifier (and %J comes only at the beginning of
the format string.) We can possibly use %J in the middle of a format string
and see what it prints or not.).
However, if we need to support positional format specifier,
then we need to make sure that it gets handled properly all the time (basically
ignored explicitly if %J is the first specifier at the beginning.).
And in that case,
the handling inside text_specifies_location needs to become
something like below. (I should update the reference to %H to include
%J, too.)


/* Returns true if the next format specifier in TEXT is a format specifier
   for a location_t.  If so, update the object pointed by LOCUS to reflect
   the specified location in *TEXT->args_ptr.

   To bring consistency to positional format specifier support,
   we restore the original args_ptr before returning
   so that the subsequent call to pp_text_format() can access %H (or %1$H).
   and  we don't remove the %H reference.

   pp_format_text() doesn't formats/prints the first %H reference.
   It merely bumps the arg pointer. */
static bool
text_specifies_location (text_info *text, location_t *locus)
{
  const char *p;
  /* Skip any leading text.  */
  for (p = text->format_spec; *p && *p != '%'; ++p)
    ;

  /* assert *p == NUL
     || *p == '%' */

  /* Extract the location information if any.
     We now match either %H or %1$H, and
     don't skip in the format_spec either. */

  if (strncmp (p, "%H", 2) == 0
      || strncmp (p, "%1$H", 4) == 0)
    {
      va_list saved_ptr =  *text->args_ptr; /* save */
      *locus = *va_arg (*text->args_ptr, location_t *);
      *text->args_ptr = saved_ptr; /* restore */
      return true;
    }
  else if (    strncmp (p, "%J",   2)   == 0
	    || strncmp (p, "%1$J", 4) == 0 )
    {
      va_list saved_ptr =  *text->args_ptr; /* save */
      tree t = va_arg (*text->args_ptr, tree);
      *locus = DECL_SOURCE_LOCATION (t);
      *text->args_ptr = saved_ptr; /* restore */
      return true;
    }

  return false;
}

pp_base_format() in pretty-print.c needs to handle
'H' and 'J' accordingly.
 Again, I will post the regenerated full patch maybe tomorrow when
the CVS problem is gone.


Hope this helps.







-- int main(void){int j=2003;/*(c)2003 cishikawa. */ char t[] ="<CI> @abcdefghijklmnopqrstuvwxyz.,\n\""; char *i ="g>qtCIuqivb,gCwe\np@.ietCIuqi\"tqkvv is>dnamz"; while(*i)((j+=strchr(t,*i++)-(int)t),(j%=sizeof t-1), (putchar(t[j])));return 0;}/* under GPL */


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