This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Diagnostic.c: Add support for %H as location specifier
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: 13 Jun 2002 14:43:36 +0200
- Subject: Diagnostic.c: Add support for %H as location specifier
- Organization: CodeSourcery, LLC
This patchlet adds support for %H in the language-independent
diagnostic library as a format specifier for a location (see
definition of location_t in diagnostic.h). It is a preliminary step
towards getting rid of {error, warning, pedwarn}_with_file_and_line
which bring nothing but code duplication.
I choosed %H (to mean "here") as opposed to %L (for location) because
the latter is already taken by the C++ front-end for "the language
used in a language-specification".
Bootstrapped and tested on an i686-pc-linux
-- Gaby
2002-06-13 Gabriel Dos Reis <gdr@codesourcery.com>
* diagnostic.c (output_format): Recognize "%H" as a format
specifier for a location_t.
(text_specifies_location): New function.
(diagnostic_set_info): Use it.
Index: diagnostic.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/diagnostic.c,v
retrieving revision 1.89
diff -p -r1.89 diagnostic.c
*** diagnostic.c 11 Jun 2002 23:11:29 -0000 1.89
--- diagnostic.c 13 Jun 2002 12:38:11 -0000
*************** static void default_diagnostic_finalizer
*** 89,94 ****
--- 89,95 ----
diagnostic_info *));
static void error_recursion PARAMS ((diagnostic_context *)) ATTRIBUTE_NORETURN;
+ static bool text_specifies_location PARAMS ((text_info *, location_t *));
extern int rtl_dump_and_exit;
extern int warnings_are_errors;
*************** output_buffer_to_stream (buffer)
*** 495,501 ****
%c: character.
%s: string.
%%: `%'.
! %*.s: a substring the length of which is specified by an integer. */
static void
output_format (buffer, text)
output_buffer *buffer;
--- 496,503 ----
%c: character.
%s: string.
%%: `%'.
! %*.s: a substring the length of which is specified by an integer.
! %H: location_t. */
static void
output_format (buffer, text)
output_buffer *buffer;
*************** output_format (buffer, text)
*** 576,581 ****
--- 578,593 ----
output_add_character (buffer, '%');
break;
+ case 'H':
+ {
+ const location_t *locus = va_arg (*text->args_ptr, location_t *);
+ output_add_string (buffer, "file '");
+ output_add_string (buffer, locus->file);
+ output_add_string (buffer, "', line ");
+ output_decimal (buffer, locus->file);
+ }
+ break;
+
case '.':
{
int n;
*************** diagnostic_initialize (context)
*** 769,774 ****
--- 781,810 ----
context->warnings_are_errors_message = warnings_are_errors;
}
+ /* Returns true if the next format specifier in TEXT is a format specifier
+ for a location_t. If so, update the object pointed by LOCUS to reflect
+ the specified location in *TEXT->args_ptr. */
+ static bool
+ text_specifies_location (text, locus)
+ text_info *text;
+ location_t *locus;
+ {
+ const char *p;
+ /* Skip any leading text. */
+ for (p = text->format_spec; *p && *p != '%'; ++p)
+ ;
+
+ /* Extract the location information if any. */
+ if (*p == '%' && *++p == 'H')
+ {
+ *locus = *va_arg (*text->args_ptr, location_t *);
+ text->format_spec = p + 1;
+ return true;
+ }
+
+ return false;
+ }
+
void
diagnostic_set_info (diagnostic, msgid, args, file, line, kind)
diagnostic_info *diagnostic;
*************** diagnostic_set_info (diagnostic, msgid,
*** 780,787 ****
{
diagnostic->message.format_spec = msgid;
diagnostic->message.args_ptr = args;
! diagnostic->location.file = file;
! diagnostic->location.line = line;
diagnostic->kind = kind;
}
--- 816,828 ----
{
diagnostic->message.format_spec = msgid;
diagnostic->message.args_ptr = args;
! /* If the diagnostic message doesn't specify a loccation,
! use FILE and LINE. */
! if (!text_specifies_location (&diagnostic->message, &diagnostic->location))
! {
! diagnostic->location.file = file;
! diagnostic->location.line = line;
! }
diagnostic->kind = kind;
}