On 25 November 2014 at 23:42, Tobias Burnus <bur...@net-b.de> wrote: > FX: >>> >>> (a) those majority which might need buffering (gfc_error, gfc_warning); >> >> Is there a plan for those in the longer term? > > > Well, the long-term solution is of course to support them. That requires > adding buffering+discarding support to the common machinery and to use it > then in gfortran. It's on Manuel's to-do list, but he suffers from the > generic problem of finding the time to actually do it. Maybe he manages to > finish that part by early next year - which might or might not be suitable > for GCC 5 inclusion.
I think the changes to the common diagnostics part could be as simple as: Index: gcc/pretty-print.c =================================================================== --- gcc/pretty-print.c (revision 218090) +++ gcc/pretty-print.c (working copy) @@ -677,19 +677,33 @@ pp_format_verbatim (pretty_printer *pp, /* Restore previous settings. */ pp_wrapping_mode (pp) = oldmode; } -/* Flush the content of BUFFER onto the attached stream. */ +/* Flush the content of BUFFER onto the attached stream. This + function does nothing unless pp->output_buffer->flush_p. */ void pp_flush (pretty_printer *pp) { + if (!pp->output_buffer->flush_p) + return; pp_write_text_to_stream (pp); pp_clear_state (pp); fflush (pp_buffer (pp)->stream); } +/* Flush the content of BUFFER onto the attached stream independently + of the value of pp->output_buffer->flush_p. */ +void +pp_really_flush (pretty_printer *pp) +{ + pp_write_text_to_stream (pp); + pp_clear_state (pp); + fflush (pp_buffer (pp)->stream); +} + + /* Sets the number of maximum characters per line PRETTY-PRINTER can output in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */ void pp_set_line_maximum_length (pretty_printer *pp, int length) @@ -772,11 +786,12 @@ pretty_printer::pretty_printer (const ch wrapping (), format_decoder (), emitted_prefix (), need_newline (), translate_identifiers (true), - show_color () + show_color (), + flush_p (true) { pp_line_cutoff (this) = l; /* By default, we emit prefixes once per message. */ pp_prefixing_rule (this) = DIAGNOSTICS_SHOW_PREFIX_ONCE; pp_set_prefix (this, p); Index: gcc/pretty-print.h =================================================================== --- gcc/pretty-print.h (revision 218090) +++ gcc/pretty-print.h (working copy) @@ -98,10 +98,15 @@ struct output_buffer int line_length; /* This must be large enough to hold any printed integer or floating-point value. */ char digit_buffer[128]; + + /* Nonzero means that text should be flushed when + appropriate. Otherwise, text is buffered until either + pp_pp_really_flush or pp_clear_output_area are called. */ + bool flush_p; }; /* The type of pretty-printer flags passed to clients. */ typedef unsigned int pp_flags; However, I'm less familiar with the Fortran buffering mechanism. So far, I understood that: * gfc uses two gfc_error_buf (error_buffer, warning_buffer) and pointer *cur_error_buffer; to switch between them. These are equivalent to pretty-printer output_buffer, thus my idea is to create a gfc_pretty_printer that contains three output_buffer (two for buffering and another for the _now variants). * There seems to be a global buffer_flag that controls when to buffer. However, each gfc_error_buf has a variable "flag", that is also checked sometimes. Unfortunately, nothing in gfc_error_buf has comments, so I have no idea how these flags are supposed to interact. It would be great if a Fortran person could explain it in detail. * I am not sure how to handle the error/warnings counts. The Fortran code seems to not care about how many errors or warnings are given when buffering, only whether there was any error at all. Is that right? It also seems to not care about -fmax-errors (similarly -Wfatal-errors will only take care after flushing, thus potentially many errors can be given before stopping). Is this correct? Not having to handle those would simplify a first version a lot. * I assume that ICEs and other such fatal_errors are never buffered. For normal errors converted to fatal by Wfatal-errors, I just need to be careful in the buffered variants, that is disable it before going through the common machinery and re-enable it after returning from it. (This is a note to myself). Cheers, Manuel.