Commit 24805e80 by Gabriel Dos Reis

diagnostic.c (context_as_prefix): Export.

	* diagnostic.c (context_as_prefix): Export.
	(need_error_newline): Remove.
	(lang_diagnostic_starter, lang_diagnostic_finalizer): New objects.
	(error_module_changed, record_last_error_module,
	error_function_changed, record_last_error_function): New functions.
	(initialize_diagnostics): Default intialize
	lang_diagnostic_starter, lang_diagnostic_finalizer.
	(init_output_buffer): Tweak.
	(file_name_as_prefix): New function.
	(announce_function, default_print_error_function,
	report_error_function, set_diagnostic_context): Tweak.

cp/
	* lex.c (lang_init_options): Default diagnostic message maximum
	length to 80, when line-wrapping.

From-SVN: r35836
parent 056b6841
2000-08-21 Gabriel Dos Reis <gdr@merlin.codesourcery.com>
* diagnostic.c (context_as_prefix): Export.
(need_error_newline): Remove.
(lang_diagnostic_starter, lang_diagnostic_finalizer): New objects.
(error_module_changed, record_last_error_module,
error_function_changed, record_last_error_function): New functions.
(initialize_diagnostics): Default intialize
lang_diagnostic_starter, lang_diagnostic_finalizer.
(init_output_buffer): Tweak.
(file_name_as_prefix): New function.
(announce_function, default_print_error_function,
report_error_function, set_diagnostic_context): Tweak.
2000-08-21 Richard Earnshaw <rearnsha@arm.com> 2000-08-21 Richard Earnshaw <rearnsha@arm.com>
* flow.c (init_propagate_block_info): Handle SUBREG in a jump * flow.c (init_propagate_block_info): Handle SUBREG in a jump
......
2000-08-21 Gabriel Dos Reis <gdr@codesourcery.com>
* lex.c (lang_init_options): Default diagnostic message maximum
length to 80, when line-wrapping.
2000-08-20 Mark Mitchell <mark@codesourcery.com> 2000-08-20 Mark Mitchell <mark@codesourcery.com>
* class.c (build_vtbl_initializer): Clear the entire * class.c (build_vtbl_initializer): Clear the entire
......
...@@ -385,8 +385,9 @@ lang_init_options () ...@@ -385,8 +385,9 @@ lang_init_options ()
flag_exceptions = 1; flag_exceptions = 1;
/* Mark as "unspecified". */ /* Mark as "unspecified". */
flag_bounds_check = -1; flag_bounds_check = -1;
/* By default wrap lines at 72 characters. */ /* By default wrap lines at 80 characters. Is getenv ("COLUMNS")
diagnostic_message_length_per_line = 72; preferable? */
diagnostic_message_length_per_line = 80;
/* By default, emit location information once for every /* By default, emit location information once for every
diagnostic message. */ diagnostic message. */
set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE); set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
......
...@@ -71,7 +71,6 @@ static void output_format PARAMS ((output_buffer *)); ...@@ -71,7 +71,6 @@ static void output_format PARAMS ((output_buffer *));
static char *vbuild_message_string PARAMS ((const char *, va_list)); static char *vbuild_message_string PARAMS ((const char *, va_list));
static char *build_message_string PARAMS ((const char *, ...)) static char *build_message_string PARAMS ((const char *, ...))
ATTRIBUTE_PRINTF_1; ATTRIBUTE_PRINTF_1;
static char *context_as_prefix PARAMS ((const char *, int, int));
static void output_do_printf PARAMS ((output_buffer *, const char *)); static void output_do_printf PARAMS ((output_buffer *, const char *));
static void format_with_decl PARAMS ((output_buffer *, tree)); static void format_with_decl PARAMS ((output_buffer *, tree));
static void file_and_line_for_asm PARAMS ((rtx, const char **, int *)); static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
...@@ -121,8 +120,6 @@ static char digit_buffer[128]; ...@@ -121,8 +120,6 @@ static char digit_buffer[128];
static output_buffer global_output_buffer; static output_buffer global_output_buffer;
output_buffer *diagnostic_buffer = &global_output_buffer; output_buffer *diagnostic_buffer = &global_output_buffer;
static int need_error_newline;
/* Function of last error message; /* Function of last error message;
more generally, function such that if next error message is in it more generally, function such that if next error message is in it
then we don't have to mention the function name. */ then we don't have to mention the function name. */
...@@ -137,6 +134,10 @@ static int last_error_tick; ...@@ -137,6 +134,10 @@ static int last_error_tick;
void (*print_error_function) PARAMS ((const char *)) = void (*print_error_function) PARAMS ((const char *)) =
default_print_error_function; default_print_error_function;
/* Hooks for language specific diagnostic messages pager and finalizer. */
diagnostic_starter_fn lang_diagnostic_starter;
diagnostic_finalizer_fn lang_diagnostic_finalizer;
/* Maximum characters per line in automatic line wrapping mode. /* Maximum characters per line in automatic line wrapping mode.
Zero means don't wrap lines. */ Zero means don't wrap lines. */
...@@ -150,6 +151,36 @@ static int current_prefixing_rule; ...@@ -150,6 +151,36 @@ static int current_prefixing_rule;
static int diagnostic_lock; static int diagnostic_lock;
/* Return truthvalue if current input file is different from the most recent
file involved in a diagnostic message. */
int
error_module_changed ()
{
return last_error_tick != input_file_stack_tick;
}
/* Remember current file as being the most recent file involved in a
diagnostic message. */
void
record_last_error_module ()
{
last_error_tick = input_file_stack_tick;
}
/* Same as error_module_changed, but for function. */
int
error_function_changed ()
{
return last_error_function != current_function_decl;
}
/* Same as record_last_error_module, but for function. */
void
record_last_error_function ()
{
last_error_function = current_function_decl;
}
/* Initialize the diagnostic message outputting machinery. */ /* Initialize the diagnostic message outputting machinery. */
void void
...@@ -161,6 +192,9 @@ initialize_diagnostics () ...@@ -161,6 +192,9 @@ initialize_diagnostics ()
/* Proceed to actual initialization. */ /* Proceed to actual initialization. */
default_initialize_buffer (diagnostic_buffer); default_initialize_buffer (diagnostic_buffer);
lang_diagnostic_starter = default_diagnostic_starter;
lang_diagnostic_finalizer = default_diagnostic_finalizer;
} }
void void
...@@ -278,6 +312,7 @@ init_output_buffer (buffer, prefix, maximum_length) ...@@ -278,6 +312,7 @@ init_output_buffer (buffer, prefix, maximum_length)
const char *prefix; const char *prefix;
int maximum_length; int maximum_length;
{ {
bzero (buffer, sizeof (output_buffer));
obstack_init (&buffer->obstack); obstack_init (&buffer->obstack);
ideal_line_wrap_cutoff (buffer) = maximum_length; ideal_line_wrap_cutoff (buffer) = maximum_length;
prefixing_policy (buffer) = current_prefixing_rule; prefixing_policy (buffer) = current_prefixing_rule;
...@@ -744,11 +779,9 @@ build_message_string VPARAMS ((const char *msgid, ...)) ...@@ -744,11 +779,9 @@ build_message_string VPARAMS ((const char *msgid, ...))
return str; return str;
} }
/* 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. */
char *
static char *
context_as_prefix (file, line, warn) context_as_prefix (file, line, warn)
const char *file; const char *file;
int line; int line;
...@@ -770,6 +803,14 @@ context_as_prefix (file, line, warn) ...@@ -770,6 +803,14 @@ context_as_prefix (file, line, warn)
} }
} }
/* Same as context_as_prefix, but only the source FILE is given. */
char *
file_name_as_prefix (f)
const char *f;
{
return build_message_string ("%s: ", f);
}
/* Format a MESSAGE into BUFFER. Automatically wrap lines. */ /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
static void static void
...@@ -1150,8 +1191,8 @@ announce_function (decl) ...@@ -1150,8 +1191,8 @@ announce_function (decl)
else else
verbatim (" %s", (*decl_printable_name) (decl, 2)); verbatim (" %s", (*decl_printable_name) (decl, 2));
fflush (stderr); fflush (stderr);
need_error_newline = 1; output_needs_newline (diagnostic_buffer) = 1;
last_error_function = current_function_decl; record_last_error_function ();
} }
} }
...@@ -1162,7 +1203,7 @@ void ...@@ -1162,7 +1203,7 @@ void
default_print_error_function (file) default_print_error_function (file)
const char *file; const char *file;
{ {
if (last_error_function != current_function_decl) if (error_function_changed ())
{ {
char *prefix = file ? build_message_string ("%s: ", file) : NULL; char *prefix = file ? build_message_string ("%s: ", file) : NULL;
output_state os; output_state os;
...@@ -1187,7 +1228,7 @@ default_print_error_function (file) ...@@ -1187,7 +1228,7 @@ default_print_error_function (file)
(*decl_printable_name) (current_function_decl, 2)); (*decl_printable_name) (current_function_decl, 2));
} }
last_error_function = current_function_decl; record_last_error_function ();
output_to_stream (diagnostic_buffer, stderr); output_to_stream (diagnostic_buffer, stderr);
diagnostic_buffer->state = os; diagnostic_buffer->state = os;
free ((char*) prefix); free ((char*) prefix);
...@@ -1204,14 +1245,14 @@ report_error_function (file) ...@@ -1204,14 +1245,14 @@ report_error_function (file)
{ {
struct file_stack *p; struct file_stack *p;
if (need_error_newline) if (output_needs_newline (diagnostic_buffer))
{ {
verbatim ("\n"); verbatim ("\n");
need_error_newline = 0; output_needs_newline (diagnostic_buffer) = 0;
} }
if (input_file_stack && input_file_stack->next != 0 if (input_file_stack && input_file_stack->next != 0
&& input_file_stack_tick != last_error_tick) && error_function_changed ())
{ {
for (p = input_file_stack->next; p; p = p->next) for (p = input_file_stack->next; p; p = p->next)
if (p == input_file_stack->next) if (p == input_file_stack->next)
...@@ -1219,7 +1260,7 @@ report_error_function (file) ...@@ -1219,7 +1260,7 @@ report_error_function (file)
else else
verbatim (",\n from %s:%d", p->name, p->line); verbatim (",\n from %s:%d", p->name, p->line);
verbatim (":\n"); verbatim (":\n");
last_error_tick = input_file_stack_tick; record_last_error_function ();
} }
(*print_error_function) (input_filename); (*print_error_function) (input_filename);
...@@ -1616,8 +1657,7 @@ See %s for instructions.", ...@@ -1616,8 +1657,7 @@ See %s for instructions.",
/* Setup DC for reporting a diagnostic MESSAGE (an error of a WARNING), /* Setup DC for reporting a diagnostic MESSAGE (an error of a WARNING),
using arguments pointed to by ARGS_PTR, issued at a location specified using arguments pointed to by ARGS_PTR, issued at a location specified
by FILE and LINE. Front-ends may override the defaut diagnostic pager by FILE and LINE. */
and finalizer *after* this subroutine completes. */
void void
set_diagnostic_context (dc, message, args_ptr, file, line, warn) set_diagnostic_context (dc, message, args_ptr, file, line, warn)
diagnostic_context *dc; diagnostic_context *dc;
...@@ -1633,8 +1673,8 @@ set_diagnostic_context (dc, message, args_ptr, file, line, warn) ...@@ -1633,8 +1673,8 @@ set_diagnostic_context (dc, message, args_ptr, file, line, warn)
diagnostic_file_location (dc) = file; diagnostic_file_location (dc) = file;
diagnostic_line_location (dc) = line; diagnostic_line_location (dc) = line;
diagnostic_is_warning (dc) = warn; diagnostic_is_warning (dc) = warn;
diagnostic_starter (dc) = default_diagnostic_starter; diagnostic_starter (dc) = lang_diagnostic_starter;
diagnostic_finalizer (dc) = default_diagnostic_finalizer; diagnostic_finalizer (dc) = lang_diagnostic_finalizer;
} }
static void static void
......
...@@ -27,6 +27,9 @@ Boston, MA 02111-1307, USA. */ ...@@ -27,6 +27,9 @@ Boston, MA 02111-1307, USA. */
/* Forward declarations. */ /* Forward declarations. */
typedef struct output_buffer output_buffer; typedef struct output_buffer output_buffer;
typedef struct diagnostic_context diagnostic_context; typedef struct diagnostic_context diagnostic_context;
typedef void (*diagnostic_starter_fn) PARAMS ((output_buffer *,
diagnostic_context *));
typedef diagnostic_starter_fn diagnostic_finalizer_fn;
#define DIAGNOSTICS_SHOW_PREFIX_ONCE 0x0 #define DIAGNOSTICS_SHOW_PREFIX_ONCE 0x0
#define DIAGNOSTICS_SHOW_PREFIX_NEVER 0x1 #define DIAGNOSTICS_SHOW_PREFIX_NEVER 0x1
...@@ -50,6 +53,10 @@ typedef struct ...@@ -50,6 +53,10 @@ typedef struct
int ideal_maximum_length; int ideal_maximum_length;
/* Nonzero if current PREFIX was emitted at least once. */ /* Nonzero if current PREFIX was emitted at least once. */
int emitted_prefix_p; int emitted_prefix_p;
/* Nonzero means one should emit a newline before outputing anything. */
int need_newline_p;
/* Tells how often current PREFIX should be emitted: /* Tells how often current PREFIX should be emitted:
o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported; o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit current PREFIX only once; o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit current PREFIX only once;
...@@ -79,6 +86,7 @@ struct output_buffer ...@@ -79,6 +86,7 @@ struct output_buffer
#define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor #define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor
#define output_buffer_format_args(BUFFER) *((BUFFER)->state.format_args) #define output_buffer_format_args(BUFFER) *((BUFFER)->state.format_args)
#define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
/* This data structure bundles altogether any information relevent to /* This data structure bundles altogether any information relevent to
the context of a diagnostic message. */ the context of a diagnostic message. */
...@@ -137,6 +145,9 @@ struct diagnostic_context ...@@ -137,6 +145,9 @@ struct diagnostic_context
extern printer_fn lang_printer; extern printer_fn lang_printer;
extern diagnostic_starter_fn lang_diagnostic_starter;
extern diagnostic_finalizer_fn lang_diagnostic_finalizer;
extern int diagnostic_message_length_per_line; extern int diagnostic_message_length_per_line;
/* This output buffer is used by front-ends that directly output /* This output buffer is used by front-ends that directly output
...@@ -178,5 +189,12 @@ void set_message_prefixing_rule PARAMS ((int)); ...@@ -178,5 +189,12 @@ void set_message_prefixing_rule PARAMS ((int));
void output_verbatim PARAMS ((output_buffer *, const char *, ...)) void output_verbatim PARAMS ((output_buffer *, const char *, ...))
ATTRIBUTE_PRINTF_2; ATTRIBUTE_PRINTF_2;
void verbatim PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1; void verbatim PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1;
char *context_as_prefix PARAMS ((const char *, int, int));
char *file_name_as_prefix PARAMS ((const char *));
int error_module_changed PARAMS ((void));
void record_last_error_module PARAMS ((void));
int error_function_changed PARAMS ((void));
void record_last_error_function PARAMS ((void));
#endif /* __GCC_DIAGNOSTIC_H__ */ #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