This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
More patch to diagnostic.[hc]
- To: gcc-patches at gcc dot gnu dot org
- Subject: More patch to diagnostic.[hc]
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- Date: 10 Jul 2000 00:50:49 +0200
- Organization: CodeSourcery, LLC
This patch adds infratructure that lets front-ends to implement their
specific diagnostic subroutines. The main subroutine is
report_diagnostic (see documentation).
While I was at it, I made some clean-up.
Bootstrapped and tested on i686-pc-linux. Installed.
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com
2000-07-10 Gabriel Dos Reis <gdr@codesourcery.com>
* diagnostic.c (wrap_text): New function.
(maybe_wrap_text): Likewise.
(output_add_string): Use it.
(output_format): Likewise.
(count_error): Use verbatim instead of notice.
(report_error_function): Likewise. Don't use plain fprintf.
(finish_diagnostic): New function.
(output_do_verbatim): Tweak. Commonalize functionalities in
output_verbatim and verbatim.
(output_verbatim): Adjust.
(verbatim): Likewise.
(report_diagnostic): Define.
* diagnostic.h (report_diagnostic): Prototype.
Index: diagnostic.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/diagnostic.h,v
retrieving revision 1.5
diff -p -r1.5 diagnostic.h
*** diagnostic.h 2000/07/09 07:51:26 1.5
--- diagnostic.h 2000/07/09 22:38:38
*************** extern int diagnostic_message_length_per
*** 94,99 ****
--- 94,101 ----
extern output_buffer *diagnostic_buffer;
/* Prototypes */
+ void report_diagnostic PARAMS ((const char *, va_list,
+ const char *, int, int));
void initialize_diagnostics PARAMS ((void));
void reshape_diagnostic_buffer PARAMS ((void));
void default_initialize_buffer PARAMS ((output_buffer *));
Index: diagnostic.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/diagnostic.c,v
retrieving revision 1.19
diff -p -r1.19 diagnostic.c
*** diagnostic.c 2000/07/09 07:51:26 1.19
--- diagnostic.c 2000/07/09 22:38:39
*************** typedef struct
*** 67,73 ****
/* Prototypes. */
static int doing_line_wrapping PARAMS ((void));
! static void output_do_verbatim PARAMS ((output_buffer *));
static void output_to_stream PARAMS ((output_buffer *, FILE *));
static void output_format PARAMS ((output_buffer *));
--- 67,75 ----
/* Prototypes. */
static int doing_line_wrapping PARAMS ((void));
! static void finish_diagnostic PARAMS ((void));
! static void output_do_verbatim PARAMS ((output_buffer *,
! const char *, va_list));
static void output_to_stream PARAMS ((output_buffer *, FILE *));
static void output_format PARAMS ((output_buffer *));
*************** static void output_long_octal PARAMS ((o
*** 116,121 ****
--- 118,126 ----
static void output_hexadecimal PARAMS ((output_buffer *, int));
static void output_long_hexadecimal PARAMS ((output_buffer *, long int));
static void output_append_r PARAMS ((output_buffer *, const char *, int));
+ static void wrap_text PARAMS ((output_buffer *, const char *, const char *));
+ static void maybe_wrap_text PARAMS ((output_buffer *, const char *,
+ const char *));
extern int rtl_dump_and_exit;
extern int inhibit_warnings;
*************** output_append (buffer, start, end)
*** 488,527 ****
output_append_r (buffer, start, end - start);
}
! /* Wrap a STRing into BUFFER. */
!
! void
! output_add_string (buffer, str)
output_buffer *buffer;
! const char *str;
{
! const char *p = str;
!
! if (!output_is_line_wrapping (buffer))
! output_append (buffer, str, str + strlen (str));
! else while (*str)
{
! while (*p && *p != ' ' && *p != '\n')
! ++p;
!
! if (p - str < output_space_left (buffer))
! output_append (buffer, str, p);
! else
! {
output_add_newline (buffer);
! output_append (buffer, str, p);
}
!
! while (*p && *p == '\n')
{
output_add_newline (buffer);
! ++p;
}
-
- str = p++;
}
}
/* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
static void
--- 493,556 ----
output_append_r (buffer, start, end - start);
}
! /* Wrap a text delimited by START and END into BUFFER. */
! static void
! wrap_text (buffer, start, end)
output_buffer *buffer;
! const char *start;
! const char *end;
{
! while (start != end)
{
! /* Dump anything bodered by whitespaces. */
! {
! const char *p = start;
! while (p != end && *p != ' ' && *p != '\n')
! ++p;
! if (p - start >= output_space_left (buffer))
output_add_newline (buffer);
! output_append (buffer, start, p);
! start = p;
! }
!
! if (start != end && *start == ' ')
! {
! output_add_space (buffer);
! ++start;
}
! if (start != end && *start == '\n')
{
output_add_newline (buffer);
! ++start;
}
}
}
+ /* Same as wrap_text but wrap text only when in line-wrapping mode. */
+ static void
+ maybe_wrap_text (buffer, start, end)
+ output_buffer *buffer;
+ const char *start;
+ const char *end;
+ {
+ if (output_is_line_wrapping (buffer))
+ wrap_text (buffer, start, end);
+ else
+ output_append (buffer, start, end);
+ }
+
+
+ /* Append a STRING to BUFFER; the STRING maybe be line-wrapped if in
+ appropriate mode. */
+
+ void
+ output_add_string (buffer, str)
+ output_buffer *buffer;
+ const char *str;
+ {
+ maybe_wrap_text (buffer, str, str + (str ? strlen (str) : 0));
+ }
+
/* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
static void
*************** output_format (buffer)
*** 555,565 ****
{
int long_integer = 0;
/* Ignore text. */
! if (*buffer->cursor != '%')
! {
! output_add_character (buffer, *buffer->cursor);
! continue;
! }
/* We got a '%'. Let's see what happens. Record whether we're
parsing a long integer format specifier. */
--- 584,598 ----
{
int long_integer = 0;
/* Ignore text. */
! {
! const char *p = buffer->cursor;
! while (*p && *p != '%')
! ++p;
! maybe_wrap_text (buffer, buffer->cursor, p);
! buffer->cursor = p;
! }
! if (!*buffer->cursor)
! break;
/* We got a '%'. Let's see what happens. Record whether we're
parsing a long integer format specifier. */
*************** output_format (buffer)
*** 643,649 ****
}
}
}
- output_finish (buffer);
}
static char *
--- 676,681 ----
*************** count_error (warningp)
*** 1221,1227 ****
if (warningp && !warning_message)
{
! notice ("%s: warnings being treated as errors\n", progname);
warning_message = 1;
}
errorcount++;
--- 1253,1259 ----
if (warningp && !warning_message)
{
! verbatim ("%s: warnings being treated as errors\n", progname);
warning_message = 1;
}
errorcount++;
*************** report_error_function (file)
*** 1456,1462 ****
if (need_error_newline)
{
! fprintf (stderr, "\n");
need_error_newline = 0;
}
--- 1488,1494 ----
if (need_error_newline)
{
! verbatim ("\n");
need_error_newline = 0;
}
*************** report_error_function (file)
*** 1465,1474 ****
{
for (p = input_file_stack->next; p; p = p->next)
if (p == input_file_stack->next)
! notice ("In file included from %s:%d", p->name, p->line);
else
! notice (",\n from %s:%d", p->name, p->line);
! fprintf (stderr, ":\n");
last_error_tick = input_file_stack_tick;
}
--- 1497,1506 ----
{
for (p = input_file_stack->next; p; p = p->next)
if (p == input_file_stack->next)
! verbatim ("In file included from %s:%d", p->name, p->line);
else
! verbatim (",\n from %s:%d", p->name, p->line);
! verbatim (":\n");
last_error_tick = input_file_stack_tick;
}
*************** restore_output_state (state, buffer)
*** 1721,1736 ****
va_copy (buffer->format_args, state->format_args);
}
/* Helper subroutine of output_verbatim and verbatim. Do the approriate
settings needed by BUFFER for a verbatim formatting. */
static void
! output_do_verbatim (buffer)
output_buffer *buffer;
{
buffer->prefix = NULL;
buffer->prefixing_rule = DIAGNOSTICS_SHOW_PREFIX_NEVER;
output_set_maximum_length (buffer, 0);
output_format (buffer);
}
/* Output MESSAGE verbatim into BUFFER. */
--- 1753,1786 ----
va_copy (buffer->format_args, state->format_args);
}
+ /* Flush diagnostic_buffer content on stderr. */
+ static void
+ finish_diagnostic ()
+ {
+ output_to_stream (diagnostic_buffer, stderr);
+ fputc ('\n', stderr);
+ fflush (stderr);
+ }
+
/* Helper subroutine of output_verbatim and verbatim. Do the approriate
settings needed by BUFFER for a verbatim formatting. */
static void
! output_do_verbatim (buffer, msg, args)
output_buffer *buffer;
+ const char *msg;
+ va_list args;
{
+ output_state os;
+
+ save_output_state (buffer, &os);
buffer->prefix = NULL;
buffer->prefixing_rule = DIAGNOSTICS_SHOW_PREFIX_NEVER;
+ buffer->cursor = msg;
+ va_copy (buffer->format_args, args);
output_set_maximum_length (buffer, 0);
output_format (buffer);
+ va_end (buffer->format_args);
+ restore_output_state (&os, buffer);
}
/* Output MESSAGE verbatim into BUFFER. */
*************** output_verbatim VPARAMS ((output_buffer
*** 1741,1747 ****
output_buffer *buffer;
const char *msg;
#endif
- output_state previous_state;
va_list ap;
VA_START (ap, msg);
--- 1791,1796 ----
*************** output_verbatim VPARAMS ((output_buffer
*** 1749,1760 ****
buffer = va_arg (ap, output_buffer *);
msg = va_arg (ap, const char *);
#endif
! save_output_state (buffer, &previous_state);
! buffer->cursor = msg;
! va_copy (buffer->format_args, ap);
! output_do_verbatim(buffer);
! va_end (buffer->format_args);
! restore_output_state (&previous_state, buffer);
}
/* Same as above but use diagnostic_buffer. */
--- 1798,1804 ----
buffer = va_arg (ap, output_buffer *);
msg = va_arg (ap, const char *);
#endif
! output_do_verbatim (buffer, msg, ap);
}
/* Same as above but use diagnostic_buffer. */
*************** verbatim VPARAMS ((const char *msg, ...)
*** 1764,1778 ****
#ifndef ANSI_PROTOTYPES
const char *msg;
#endif
! output_state previous_state;
! save_output_state (diagnostic_buffer, &previous_state);
! VA_START (diagnostic_args, msg);
#ifndef ANSI_PROTOTYPES
! msg = va_arg (diagnostic_args, const char *);
#endif
! diagnostic_msg = msg;
! output_do_verbatim (diagnostic_buffer);
output_to_stream (diagnostic_buffer, stderr);
va_end (diagnostic_args);
! restore_output_state (&previous_state, diagnostic_buffer);
}
--- 1808,1849 ----
#ifndef ANSI_PROTOTYPES
const char *msg;
#endif
! va_list ap;
!
! VA_START (ap, msg);
#ifndef ANSI_PROTOTYPES
! msg = va_arg (ap, const char *);
#endif
! output_do_verbatim (diagnostic_buffer, msg, ap);
output_to_stream (diagnostic_buffer, stderr);
+ }
+
+ /* Report a diagnostic MESSAGE (an error or a WARNING) involving
+ entities in ARGUMENTS. FILE and LINE indicate where the diagnostic
+ occurs. This function is *the* subroutine in terms of which front-ends
+ should implement their specific diagnostic handling modules. */
+ void
+ report_diagnostic (msg, args, file, line, warn)
+ const char *msg;
+ va_list args;
+ const char *file;
+ int line;
+ int warn;
+ {
+ output_state os;
+
+ save_output_state (diagnostic_buffer, &os);
+ diagnostic_msg = msg;
+ va_copy (diagnostic_args, args);
+ if (count_error (warn))
+ {
+ report_error_function (file);
+ output_set_prefix
+ (diagnostic_buffer, context_as_prefix (file, line, warn));
+ output_format (diagnostic_buffer);
+ finish_diagnostic();
+ output_destroy_prefix (diagnostic_buffer);
+ }
va_end (diagnostic_args);
! restore_output_state (&os, diagnostic_buffer);
}