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: [PATCH] Support %N$/*N$ style format arguments in GCC diagnostics (take 2)


On Sat, Jun 04, 2005 at 02:34:58PM -0700, Zack Weinberg wrote:
> Jakub Jelinek <jakub@redhat.com> writes:
> 
> > It doesn't seem to be much simpler, because it needs to play ugly games
> > with changing the pretty printer in place (passing a scratch printer
> > to the format decoder routine does not work, because the original
> > printer is usually embedded into some larger structure and relies on
> > the other fields).  Anyway, I have implemented that below.
> 
> Sorry for the delay getting back to you here.  I do not understand the
> problem with passing a scratch printer, even after staring at the
> code.  Could you expand a little?

Suppose you have a scratch printer in pretty-print.c:
static pretty_printer arg_printer;
initialized somewhere and suppose you pass it to the format decoder routine:
ok = pp_format_decoder (pp) (&arg_printer, text);
so that the string is printed to a separate obstack, isn't flushed to any
stream, wrapped etc.
Now, consider say C %D format.  c_tree_printer does:
c_pretty_printer *cpp = (c_pretty_printer *) pp;
...
pp_c_expression (cpp, t);
and
typedef struct c_pretty_print_info c_pretty_printer;
struct c_pretty_print_info
{
  pretty_printer base;
  /* Points to the first element of an array of offset-list.
     Not used yet.  */
  int *offset_list;

  pp_flags flags;

  /* These must be overridden by each of the C and C++ front-end to
     reflect their understanding of syntactic productions when they differ.  */
  c_pretty_print_fn declaration;
  c_pretty_print_fn declaration_specifiers;
...
};
and pp_c_expression etc. use the various hooks in struct
c_pretty_print_info.  But we passed &arg_printer to the format
decoder routine, so these fields contain garbage (something from objects
following arg_printer).

	Jakub


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