Commit 345ed1fe by Gabriel Dos Reis Committed by Gabriel Dos Reis

diagnostic.h: New file.

2000-04-22  Gabriel Dos Reis  <gdr@codesourcery.com>

        * diagnostic.h: New file.

        * Makefile.in (diagnostic.o): Depends on diagnostic.h

        * diagnostic.c: Tweak.  Rationalize the output logic.  Adjust
        various function prototypes.
        (diagnostic.h): #include.
        (struct output_buffer): Move into diagnostic.h.
        (get_output_prefix): Rename to output_get_prefix.  Export.
        (init_output_buffer): Export. Break out.  Ajust intialization.
        (output_space_left, output_append): Export.
        (output_newline): Rename to output_add_newline.  Export.
        (output_clear): Nullify additional output_buffer fields.
        (output_puts): Rename to output_add_string.  Export.
        (dump_output): Rename to output_flush_on.  Export.
        (build_location_prefix): Constify return-type.
        (emit_output_prefix): Rename to output_emit_prefix. Export.
        (set_real_maximum_length): New function.
        (output_set_maximum_length): Ditto
        (output_clear): Ditto.
        (output_add_character): Ditto.
        (output_add_integer): Ditto.
        (output_add_space): Ditto.
        (output_format): Ditto.
        (output_printf): Adjust buffer initialization.
        (vline_wrapper_message_with_location): Ditto.
        (v_message_with_decl): Ditto.  Adjust call to output_puts
        and get_output_prefix.
        (default_print_error_function): Adjust buffer intialization.

From-SVN: r33337
parent 219fe898
2000-04-22 Gabriel Dos Reis <gdr@codesourcery.com>
* diagnostic.h: New file.
* Makefile.in (diagnostic.o): Depends on diagnostic.h
* diagnostic.c: Tweak. Rationalize the output logic. Adjust
various function prototypes.
(diagnostic.h): #include.
(struct output_buffer): Move into diagnostic.h.
(get_output_prefix): Rename to output_get_prefix. Export.
(init_output_buffer): Export. Break out. Ajust intialization.
(output_space_left, output_append): Export.
(output_newline): Rename to output_add_newline. Export.
(output_clear): Nullify additional output_buffer fields.
(output_puts): Rename to output_add_string. Export.
(dump_output): Rename to output_flush_on. Export.
(build_location_prefix): Constify return-type.
(emit_output_prefix): Rename to output_emit_prefix. Export.
(set_real_maximum_length): New function.
(output_set_maximum_length): Ditto
(output_clear): Ditto.
(output_add_character): Ditto.
(output_add_integer): Ditto.
(output_add_space): Ditto.
(output_format): Ditto.
(output_printf): Adjust buffer initialization.
(vline_wrapper_message_with_location): Ditto.
(v_message_with_decl): Ditto. Adjust call to output_puts
and get_output_prefix.
(default_print_error_function): Adjust buffer intialization.
Sat Apr 22 06:45:04 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> Sat Apr 22 06:45:04 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* expr.c (preexpand_calls, case CALL_EXPR): Don't look at TYPE_SIZE * expr.c (preexpand_calls, case CALL_EXPR): Don't look at TYPE_SIZE
......
...@@ -1497,9 +1497,10 @@ print-tree.o : print-tree.c $(CONFIG_H) system.h $(TREE_H) $(GGC_H) ...@@ -1497,9 +1497,10 @@ print-tree.o : print-tree.c $(CONFIG_H) system.h $(TREE_H) $(GGC_H)
stor-layout.o : stor-layout.c $(CONFIG_H) system.h $(TREE_H) flags.h \ stor-layout.o : stor-layout.c $(CONFIG_H) system.h $(TREE_H) flags.h \
function.h $(EXPR_H) $(RTL_H) toplev.h $(GGC_H) function.h $(EXPR_H) $(RTL_H) toplev.h $(GGC_H)
fold-const.o : fold-const.c $(CONFIG_H) system.h $(TREE_H) flags.h toplev.h \ fold-const.o : fold-const.c $(CONFIG_H) system.h $(TREE_H) flags.h toplev.h \
$(RTL_H) $(GGC_H) $(RTL_H) ggc.h
diagnostic.o : diagnostic.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) tm_p.h flags.h \ diagnostic.o : diagnostic.c diagnostic.h \
input.h insn-attr.h insn-codes.h insn-config.h toplev.h intl.h $(CONFIG_H) system.h $(TREE_H) $(RTL_H) tm_p.h flags.h \
$(GGC_H) input.h insn-attr.h insn-codes.h insn-config.h toplev.h intl.h
toplev.o : toplev.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) function.h \ toplev.o : toplev.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) function.h \
flags.h input.h insn-attr.h xcoffout.h defaults.h output.h \ flags.h input.h insn-attr.h xcoffout.h defaults.h output.h \
insn-codes.h insn-config.h intl.h $(RECOG_H) Makefile toplev.h dwarfout.h \ insn-codes.h insn-config.h intl.h $(RECOG_H) Makefile toplev.h dwarfout.h \
......
/* Top level of GNU C compiler /* Language-independent diagnostic subroutines for the GNU C compiler
Copyright (C) 1999, 2000 Free Software Foundation, Inc. Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU CC. This file is part of GNU CC.
...@@ -37,38 +37,19 @@ Boston, MA 02111-1307, USA. */ ...@@ -37,38 +37,19 @@ Boston, MA 02111-1307, USA. */
#include "insn-config.h" #include "insn-config.h"
#include "toplev.h" #include "toplev.h"
#include "intl.h" #include "intl.h"
#include "obstack.h" #include "diagnostic.h"
#define obstack_chunk_alloc xmalloc #define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free #define obstack_chunk_free free
struct output_buffer
{
struct obstack obstack; /* where we build the text to output */
char *prefix; /* prefix of every new line */
int line_length; /* current line length (in characters) */
int max_length; /* maximum characters per line */
};
/* Prototypes. */ /* Prototypes. */
static int doing_line_wrapping PARAMS ((void)); static int doing_line_wrapping PARAMS ((void));
static void init_output_buffer PARAMS ((struct output_buffer*, char *, int));
static char *get_output_prefix PARAMS ((const struct output_buffer *)); static const char *vbuild_message_string PARAMS ((const char *, va_list));
static int output_space_left PARAMS ((const struct output_buffer *)); static const char *build_message_string PARAMS ((const char *, ...))
static void emit_output_prefix PARAMS ((struct output_buffer *));
static void output_newline PARAMS ((struct output_buffer *));
static void output_append PARAMS ((struct output_buffer *, const char *,
const char *));
static void output_puts PARAMS ((struct output_buffer *, const char *));
static void dump_output PARAMS ((struct output_buffer *, FILE *));
static char *vbuild_message_string PARAMS ((const char *, va_list));
static char *build_message_string PARAMS ((const char *, ...))
ATTRIBUTE_PRINTF_1; ATTRIBUTE_PRINTF_1;
static char *build_location_prefix PARAMS ((const char *, int, int)); static const char *build_location_prefix PARAMS ((const char *, int, int));
static void voutput_notice PARAMS ((struct output_buffer *, const char *, static void output_notice PARAMS ((output_buffer *, const char *));
va_list));
static void output_printf PARAMS ((struct output_buffer *, const char *, ...))
ATTRIBUTE_PRINTF_2;
static void line_wrapper_printf PARAMS ((FILE *, const char *, ...)) static void line_wrapper_printf PARAMS ((FILE *, const char *, ...))
ATTRIBUTE_PRINTF_2; ATTRIBUTE_PRINTF_2;
static void vline_wrapper_message_with_location PARAMS ((const char *, int, static void vline_wrapper_message_with_location PARAMS ((const char *, int,
...@@ -98,13 +79,15 @@ static void vsorry PARAMS ((const char *, va_list)); ...@@ -98,13 +79,15 @@ static void vsorry PARAMS ((const char *, va_list));
static void report_file_and_line PARAMS ((const char *, int, int)); static void report_file_and_line PARAMS ((const char *, int, int));
static void vnotice PARAMS ((FILE *, const char *, va_list)); static void vnotice PARAMS ((FILE *, const char *, va_list));
extern int rtl_dump_and_exit; extern int rtl_dump_and_exit;
extern int inhibit_warnings; extern int inhibit_warnings;
extern int warnings_are_errors; extern int warnings_are_errors;
extern int warningcount; extern int warningcount;
extern int errorcount; extern int errorcount;
/* Front-end specific tree formatter, if non-NULL. */
printer_fn lang_printer = NULL;
static int need_error_newline; static int need_error_newline;
/* Function of last error message; /* Function of last error message;
...@@ -143,52 +126,115 @@ set_message_length (n) ...@@ -143,52 +126,115 @@ set_message_length (n)
output_maximum_width = n; output_maximum_width = n;
} }
/* Construct an output BUFFER with PREFIX and of MAX_LENGTH characters /* Returns true if BUFFER is in line-wrappind mode. */
per line. */ int
output_is_line_wrapping (buffer)
output_buffer *buffer;
{
return buffer->ideal_maximum_length > 0;
}
/* Return BUFFER's prefix. */
const char *
output_get_prefix (buffer)
const output_buffer *buffer;
{
return buffer->prefix;
}
/* Subroutine of output_set_maximum_length. Set up BUFFER's
internal maximum characters per line. */
static void static void
init_output_buffer (buffer, prefix, max_length) set_real_maximum_length (buffer)
struct output_buffer *buffer; output_buffer *buffer;
char *prefix; {
int max_length; /* If we're told not to wrap lines then do the obvious thing. */
if (! output_is_line_wrapping (buffer))
buffer->maximum_length = buffer->ideal_maximum_length;
else
{
int prefix_length = buffer->prefix ? strlen (buffer->prefix) : 0;
/* If the prefix is ridiculously too long, output at least
32 characters. */
if (buffer->ideal_maximum_length - prefix_length < 32)
buffer->maximum_length = buffer->ideal_maximum_length + 32;
else
buffer->maximum_length = buffer->ideal_maximum_length;
}
}
/* Sets the number of maximum characters per line BUFFER can output
in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
void
output_set_maximum_length (buffer, length)
output_buffer *buffer;
int length;
{ {
int prefix_length = prefix == 0 ? 0 : strlen (prefix); buffer->ideal_maximum_length = length;
set_real_maximum_length (buffer);
}
obstack_init (&buffer->obstack); /* Sets BUFFER's PREFIX. */
void
output_set_prefix (buffer, prefix)
output_buffer *buffer;
const char *prefix;
{
buffer->prefix = prefix; buffer->prefix = prefix;
set_real_maximum_length (buffer);
}
/* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
characters per line. */
void
init_output_buffer (buffer, prefix, maximum_length)
output_buffer *buffer;
const char *prefix;
int maximum_length;
{
obstack_init (&buffer->obstack);
buffer->ideal_maximum_length = maximum_length;
buffer->line_length = 0; buffer->line_length = 0;
/* If the prefix is ridiculously too long, output at least output_set_prefix (buffer, prefix);
32 characters. */
if (max_length - prefix_length < 32) buffer->cursor = NULL;
buffer->max_length = max_length + 32; buffer->format_args = NULL;
else
buffer->max_length = max_length;
} }
/* Return BUFFER's prefix. */ /* Reinitialize BUFFER. */
void
output_clear (buffer)
output_buffer *buffer;
{
obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
buffer->line_length = 0;
buffer->cursor = NULL;
buffer->format_args = NULL;
}
static char * /* Finishes to construct a NULL-terminated character string representing
get_output_prefix (buffer) the BUFFERed message. */
const struct output_buffer *buffer; const char *
output_finish (buffer)
output_buffer *buffer;
{ {
return buffer->prefix; obstack_1grow (&buffer->obstack, '\0');
return (const char *) obstack_finish (&buffer->obstack);
} }
/* Return the amount of characters BUFFER can accept to /* Return the amount of characters BUFFER can accept to
make a full line. */ make a full line. */
int
static int
output_space_left (buffer) output_space_left (buffer)
const struct output_buffer *buffer; const output_buffer *buffer;
{ {
return buffer->max_length - buffer->line_length; return buffer->maximum_length - buffer->line_length;
} }
/* Dump BUFFER's prefix. */ /* Write out BUFFER's prefix. */
void
static void output_emit_prefix (buffer)
emit_output_prefix (buffer) output_buffer *buffer;
struct output_buffer *buffer;
{ {
if (buffer->prefix) if (buffer->prefix)
{ {
...@@ -198,21 +244,60 @@ emit_output_prefix (buffer) ...@@ -198,21 +244,60 @@ emit_output_prefix (buffer)
} }
/* Have BUFFER start a new line. */ /* Have BUFFER start a new line. */
void
static void output_add_newline (buffer)
output_newline (buffer) output_buffer *buffer;
struct output_buffer *buffer;
{ {
obstack_1grow (&buffer->obstack, '\n'); obstack_1grow (&buffer->obstack, '\n');
buffer->line_length = 0; buffer->line_length = 0;
} }
/* Appends a character to BUFFER. */
void
output_add_character (buffer, c)
output_buffer *buffer;
int c;
{
if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
output_add_newline (buffer);
obstack_1grow (&buffer->obstack, c);
++buffer->line_length;
}
/* Adds a space to BUFFER. */
void
output_add_space (buffer)
output_buffer *buffer;
{
if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
{
output_add_newline (buffer);
return;
}
obstack_1grow (&buffer->obstack, ' ');
++buffer->line_length;
}
/* Add the stringified version of an integer to BUFFER. */
void
output_add_integer (buffer, i)
output_buffer *buffer;
HOST_WIDE_INT i;
{
/* This must be large enough to hold any printed integer or
floating-point value. */
static char digit_buffer[128];
sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, i);
output_add_string (buffer, digit_buffer);
}
/* Append a string deliminated by START and END to BUFFER. No wrapping is /* Append a string deliminated by START and END to BUFFER. No wrapping is
done. The caller must ensure that it is safe to do so. */ done. The caller must ensure that it is safe to do so. */
static void void
output_append (buffer, start, end) output_append (buffer, start, end)
struct output_buffer *buffer; output_buffer *buffer;
const char *start; const char *start;
const char *end; const char *end;
{ {
...@@ -221,7 +306,7 @@ output_append (buffer, start, end) ...@@ -221,7 +306,7 @@ output_append (buffer, start, end)
/* Emit prefix and skip whitespace if we're starting a new line. */ /* Emit prefix and skip whitespace if we're starting a new line. */
if (buffer->line_length == 0) if (buffer->line_length == 0)
{ {
emit_output_prefix (buffer); output_emit_prefix (buffer);
while (start != end && *start == ' ') while (start != end && *start == ' ')
++start; ++start;
} }
...@@ -232,14 +317,16 @@ output_append (buffer, start, end) ...@@ -232,14 +317,16 @@ output_append (buffer, start, end)
/* Wrap a STRing into BUFFER. */ /* Wrap a STRing into BUFFER. */
static void void
output_puts (buffer, str) output_add_string (buffer, str)
struct output_buffer *buffer; output_buffer *buffer;
const char *str; const char *str;
{ {
const char *p = str; const char *p = str;
while (*str) if (!output_is_line_wrapping (buffer))
output_append (buffer, str, str + strlen (str));
else while (*str)
{ {
while (*p && *p != ' ' && *p != '\n') while (*p && *p != ' ' && *p != '\n')
++p; ++p;
...@@ -248,13 +335,13 @@ output_puts (buffer, str) ...@@ -248,13 +335,13 @@ output_puts (buffer, str)
output_append (buffer, str, p); output_append (buffer, str, p);
else else
{ {
output_newline (buffer); output_add_newline (buffer);
output_append (buffer, str, p); output_append (buffer, str, p);
} }
while (*p && *p == '\n') while (*p && *p == '\n')
{ {
output_newline (buffer); output_add_newline (buffer);
++p; ++p;
} }
...@@ -262,23 +349,57 @@ output_puts (buffer, str) ...@@ -262,23 +349,57 @@ output_puts (buffer, str)
} }
} }
/* Dump the content of BUFFER into FILE. */ /* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
static void void
dump_output (buffer, file) output_flush_on (buffer, file)
struct output_buffer *buffer; output_buffer *buffer;
FILE *file; FILE *file;
{ {
char *text; const char *text = output_finish (buffer);
obstack_1grow (&buffer->obstack, '\0');
text = obstack_finish (&buffer->obstack);
fputs (text, file); fputs (text, file);
obstack_free (&buffer->obstack, text); output_clear (buffer);
buffer->line_length = 0; }
/* Format MESSAGE into BUFFER. */
void
output_format (buffer, msg)
output_buffer *buffer;
const char *msg;
{
for (buffer->cursor = msg; *buffer->cursor; ++buffer->cursor)
{
/* Ignore text. */
if (*buffer->cursor != '%')
{
output_add_character (buffer, *buffer->cursor);
continue;
}
/* We got a '%'. Let's see what happens. */
++buffer->cursor;
/* Let's handle the traditional cases. */
if (*buffer->cursor == 's')
output_add_string (buffer, va_arg (buffer->format_args, const char *));
else if (*buffer->cursor == 'd')
output_add_integer (buffer, va_arg (buffer->format_args, int));
else if (*buffer->cursor == '%')
/* It was a '%%'. Just output a '%'. */
output_add_character (buffer, '%');
else if (lang_printer)
(*lang_printer) (buffer);
else
{
/* Hmmm. The front-end failed to install a format translator
but called us with an unrecognized format. Sorry. */
abort();
}
}
output_finish (buffer);
} }
static char * static const char *
vbuild_message_string (msgid, ap) vbuild_message_string (msgid, ap)
const char *msgid; const char *msgid;
va_list ap; va_list ap;
...@@ -292,14 +413,14 @@ vbuild_message_string (msgid, ap) ...@@ -292,14 +413,14 @@ vbuild_message_string (msgid, ap)
/* Return a malloc'd string containing MSGID formatted a la /* Return a malloc'd string containing MSGID formatted a la
printf. The caller is reponsible for freeing the memory. */ printf. The caller is reponsible for freeing the memory. */
static char * static const char *
build_message_string VPARAMS ((const char *msgid, ...)) build_message_string VPARAMS ((const char *msgid, ...))
{ {
#ifndef ANSI_PROTOTYPES #ifndef ANSI_PROTOTYPES
const char *msgid; const char *msgid;
#endif #endif
va_list ap; va_list ap;
char *str; const char *str;
VA_START (ap, msgid); VA_START (ap, msgid);
...@@ -318,7 +439,7 @@ build_message_string VPARAMS ((const char *msgid, ...)) ...@@ -318,7 +439,7 @@ build_message_string VPARAMS ((const char *msgid, ...))
/* Return a malloc'd string describing a location. The caller is /* Return a malloc'd string describing a location. The caller is
responsible for freeing the memory. */ responsible for freeing the memory. */
static char * static const char *
build_location_prefix (file, line, warn) build_location_prefix (file, line, warn)
const char *file; const char *file;
int line; int line;
...@@ -343,21 +464,20 @@ build_location_prefix (file, line, warn) ...@@ -343,21 +464,20 @@ build_location_prefix (file, line, warn)
/* Format a MESSAGE into BUFFER. Automatically wrap lines. */ /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
static void static void
voutput_notice (buffer, msgid, ap) output_notice (buffer, msgid)
struct output_buffer *buffer; output_buffer *buffer;
const char *msgid; const char *msgid;
va_list ap;
{ {
char *message = vbuild_message_string (msgid, ap); const char *message = vbuild_message_string (msgid, buffer->format_args);
output_puts (buffer, message); output_add_string (buffer, message);
free (message); free ((char *) message);
} }
/* Format a message into BUFFER a la printf. */ /* Format a message into BUFFER a la printf. */
static void void
output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...)) output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
{ {
#ifndef ANSI_PROTOTYPES #ifndef ANSI_PROTOTYPES
...@@ -373,8 +493,9 @@ output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...)) ...@@ -373,8 +493,9 @@ output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
msgid = va_arg (ap, const char *); msgid = va_arg (ap, const char *);
#endif #endif
voutput_notice (buffer, msgid, ap); buffer->format_args = ap;
va_end (ap); output_notice (buffer, msgid);
va_end (buffer->format_args);
} }
...@@ -388,7 +509,7 @@ line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...)) ...@@ -388,7 +509,7 @@ line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...))
FILE *file; FILE *file;
const char *msgid; const char *msgid;
#endif #endif
struct output_buffer buffer; output_buffer buffer;
va_list ap; va_list ap;
VA_START (ap, msgid); VA_START (ap, msgid);
...@@ -399,10 +520,11 @@ line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...)) ...@@ -399,10 +520,11 @@ line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...))
#endif #endif
init_output_buffer (&buffer, NULL, output_maximum_width); init_output_buffer (&buffer, NULL, output_maximum_width);
voutput_notice (&buffer, msgid, ap); buffer.format_args = ap;
dump_output (&buffer, file); output_notice (&buffer, msgid);
output_flush_on (&buffer, file);
va_end (ap); va_end (buffer.format_args);
} }
...@@ -414,13 +536,15 @@ vline_wrapper_message_with_location (file, line, warn, msgid, ap) ...@@ -414,13 +536,15 @@ vline_wrapper_message_with_location (file, line, warn, msgid, ap)
const char *msgid; const char *msgid;
va_list ap; va_list ap;
{ {
struct output_buffer buffer; output_buffer buffer;
init_output_buffer init_output_buffer
(&buffer, build_location_prefix (file, line, warn), output_maximum_width); (&buffer, build_location_prefix (file, line, warn), output_maximum_width);
voutput_notice (&buffer, msgid, ap); buffer.format_args = ap;
dump_output (&buffer, stderr); output_notice (&buffer, msgid);
free ((char*)get_output_prefix (&buffer)); output_flush_on (&buffer, stderr);
free ((char*) output_get_prefix (&buffer));
fputc ('\n', stderr); fputc ('\n', stderr);
} }
...@@ -498,14 +622,15 @@ v_message_with_decl (decl, warn, msgid, ap) ...@@ -498,14 +622,15 @@ v_message_with_decl (decl, warn, msgid, ap)
va_list ap; va_list ap;
{ {
const char *p; const char *p;
struct output_buffer buffer; output_buffer buffer;
if (doing_line_wrapping ()) if (doing_line_wrapping ())
init_output_buffer {
(&buffer, init_output_buffer
build_location_prefix (DECL_SOURCE_FILE (decl), (&buffer, build_location_prefix
DECL_SOURCE_LINE (decl), warn), (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn),
output_maximum_width); output_maximum_width);
}
else else
report_file_and_line (DECL_SOURCE_FILE (decl), report_file_and_line (DECL_SOURCE_FILE (decl),
DECL_SOURCE_LINE (decl), warn); DECL_SOURCE_LINE (decl), warn);
...@@ -541,7 +666,7 @@ v_message_with_decl (decl, warn, msgid, ap) ...@@ -541,7 +666,7 @@ v_message_with_decl (decl, warn, msgid, ap)
? (*decl_printable_name) (decl, 2) ? (*decl_printable_name) (decl, 2)
: "((anonymous))"); : "((anonymous))");
if (doing_line_wrapping ()) if (doing_line_wrapping ())
output_puts (&buffer, n); output_add_string (&buffer, n);
else else
fputs (n, stderr); fputs (n, stderr);
while (*p) while (*p)
...@@ -555,15 +680,19 @@ v_message_with_decl (decl, warn, msgid, ap) ...@@ -555,15 +680,19 @@ v_message_with_decl (decl, warn, msgid, ap)
if (*p) /* Print the rest of the message. */ if (*p) /* Print the rest of the message. */
{ {
if (doing_line_wrapping ()) if (doing_line_wrapping ())
voutput_notice (&buffer, p, ap); {
buffer.format_args = ap;
output_notice (&buffer, p);
ap = buffer.format_args;
}
else else
vfprintf (stderr, p, ap); vfprintf (stderr, p, ap);
} }
if (doing_line_wrapping()) if (doing_line_wrapping())
{ {
dump_output (&buffer, stderr); output_flush_on (&buffer, stderr);
free ((char *)get_output_prefix (&buffer)); free ((char *) output_get_prefix (&buffer));
} }
fputc ('\n', stderr); fputc ('\n', stderr);
...@@ -1012,8 +1141,8 @@ default_print_error_function (file) ...@@ -1012,8 +1141,8 @@ default_print_error_function (file)
{ {
if (last_error_function != current_function_decl) if (last_error_function != current_function_decl)
{ {
char *prefix = NULL; const char *prefix = NULL;
struct output_buffer buffer; output_buffer buffer;
if (file) if (file)
prefix = build_message_string ("%s: ", file); prefix = build_message_string ("%s: ", file);
...@@ -1060,9 +1189,9 @@ default_print_error_function (file) ...@@ -1060,9 +1189,9 @@ default_print_error_function (file)
last_error_function = current_function_decl; last_error_function = current_function_decl;
if (doing_line_wrapping ()) if (doing_line_wrapping ())
dump_output (&buffer, stderr); output_flush_on (&buffer, stderr);
free (prefix); free ((char*) prefix);
} }
} }
......
/* Various declarations for language-independent diagnostics subroutines.
Copyright (C) 2000 Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef __GCC_DIAGNOSTIC_H__
#define __GCC_DIAGNOSTIC_H__
#include "obstack.h"
/* Forward declarations. */
typedef struct output_buffer output_buffer;
/* The type of front-end specific hook that formats trees into an
output_buffer. */
typedef void (*printer_fn) PARAMS ((output_buffer *));
/* The output buffer datatype. This is best seen as an abstract datatype. */
struct output_buffer
{
/* Internal data. These fields should not be accessed directly by
front-ends. */
/* The obstack where the text is built up. */
struct obstack obstack;
/* The prefix for each new line. */
const char *prefix;
/* The amount of characters output so far. */
int line_length;
/* The real upper bound of number of characters per line, taking into
accompt the case of a very very looong prefix. */
int maximum_length;
/* The ideal upper bound of number of characters per line, as suggested
by front-end. */
int ideal_maximum_length;
/* Public fields. These are used by front-ends to extract formats and
arguments from the variable argument-list passed to output_format. */
/* The current char to output. Updated by front-end (*format_map) when
it is called to report front-end printer for a specified format. */
const char *cursor;
/* Variable argument-list for formatting. */
va_list format_args;
};
/* If non-NULL, this function formats data in the BUFFER.
BUFFER->CURSOR points to a format code. LANG_PRINTER should
call output_add_string (and related functions) to add data to
the BUFFER. LANG_PRINTER can read arguments from
BUFFER->FORMAT_ARGS using VA_ARG. If the BUFFER needs
additional characters from the format string, it should advance
the BUFFER->CURSOR as it goes. When LANG_PRINTER returns,
BUFFER->CURSOR should point to the last character processed. */
extern printer_fn lang_printer;
/* Prototypes */
void init_output_buffer PARAMS ((output_buffer *, const char *, int));
void output_clear PARAMS ((output_buffer *));
const char *output_get_prefix PARAMS ((const output_buffer *));
void output_set_prefix PARAMS ((output_buffer *, const char *));
void output_set_maximum_length PARAMS ((output_buffer *, int));
void output_emit_prefix PARAMS ((output_buffer *));
void output_add_newline PARAMS ((output_buffer *));
void output_add_space PARAMS ((output_buffer *));
int output_space_left PARAMS ((const output_buffer *));
void output_append PARAMS ((output_buffer *, const char *,
const char *));
void output_add_character PARAMS ((output_buffer *, int));
void output_add_integer PARAMS ((output_buffer *, HOST_WIDE_INT));
void output_add_string PARAMS ((output_buffer *, const char *));
const char *output_finish PARAMS ((output_buffer *));
void output_flush_on PARAMS ((output_buffer *, FILE *));
void output_printf PARAMS ((output_buffer *, const char *,
...)) ATTRIBUTE_PRINTF_2;
void output_format PARAMS ((output_buffer *, const char *));
int output_is_line_wrapping PARAMS ((output_buffer *));
#endif /* __GCC_DIAGNOSTIC_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment