This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [mainline] PATCH to diagnostic.[hc]
"Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:
| > Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
| >
| > > This was suggested by Kaveh.
| >
| > Can you maybe make 'w' a size qualifier, so %wd / %wi / %wu / %wx all
| > work? That would supersede *all* of the HOST_WIDE_INT_PRINT_* macros.
|
|
| Actually Gaby, Zack's proposal *is* what I suggested. I.e. instead
| of this:
|
| %o: unsigned integer in base eight.
| %x: unsigned integer in base sixteen.
| %ld, %li, %lo, %lu, %lx: long versions of the above.
| + %ll: long long int.
| + %w: and integer of type HOST_WIDE_INT.
|
| I meant it should be this:
|
| %o: unsigned integer in base eight.
| %x: unsigned integer in base sixteen.
| %ld, %li, %lo, %lu, %lx: long versions of the above.
| + %lld, %lli, %llo, %llu, %llx: long versions of the above.
| + %wd, %wi, %wo, %wu, %wx: HOST_WIDE_INT versions of the above.
Here we go.
-- Gaby
2003-06-28 Gabriel Dos Reis <gdr@integrable-solutions.net>
* diagnostic.c (output_integer_with_precision): New macro.
(output_format): Use it. Handle more format specifiers.
(output_long_decimal): Remove.
(output_unsigned_decimal): Likewise.
(output_long_unsigned_decimal): Likewise.
(output_octal): Likewise.
(output_long_octal): Likewise.
(output_hexadecimal): Likewise.
(output_long_hexadecimal): Likewise.
(output_long_long_decimal): Likewise.
Index: diagnostic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/diagnostic.c,v
retrieving revision 1.118
diff -p -r1.118 diagnostic.c
*** diagnostic.c 23 Jun 2003 15:27:35 -0000 1.118
--- diagnostic.c 28 Jun 2003 13:37:29 -0000
*************** Software Foundation, 59 Temple Place - S
*** 44,49 ****
--- 44,77 ----
#define line_wrap_cutoff(BUFFER) (BUFFER)->state.maximum_length
#define prefix_was_emitted_for(BUFFER) (BUFFER)->state.emitted_prefix_p
+ /* Format an integer given by va_arg (ARG, type-specifier T) where
+ type-specifier is a precision modifier as indicated by PREC. F is
+ a string used to construct the appropciate format-specifier. */
+ #define output_integer_with_precision(BUFFER, ARG, PREC, T, F) \
+ do \
+ switch (PREC) \
+ { \
+ case 0: \
+ output_formatted_scalar \
+ (BUFFER, "%" F, va_arg (ARG, T)); \
+ break; \
+ \
+ case 1: \
+ output_formatted_scalar \
+ (BUFFER, "%l" F, va_arg (ARG, long T)); \
+ break; \
+ \
+ case 2: \
+ output_formatted_scalar \
+ (BUFFER, "%ll" F, va_arg (ARG, long long T)); \
+ break; \
+ \
+ default: \
+ break; \
+ } \
+ while (0)
+
+
/* Prototypes. */
static void output_flush (output_buffer *);
static void output_do_verbatim (output_buffer *, text_info *);
*************** static void format_with_decl (output_buf
*** 57,71 ****
static void diagnostic_for_decl (diagnostic_context *, diagnostic_info *,
tree);
static void set_real_maximum_length (output_buffer *);
-
- static void output_unsigned_decimal (output_buffer *, unsigned int);
- static void output_long_decimal (output_buffer *, long int);
- static void output_long_unsigned_decimal (output_buffer *,
- long unsigned int);
- static void output_octal (output_buffer *, unsigned int);
- static void output_long_octal (output_buffer *, unsigned long int);
- static void output_hexadecimal (output_buffer *, unsigned int);
- static void output_long_hexadecimal (output_buffer *, unsigned long int);
static void output_append_r (output_buffer *, const char *, int);
static void wrap_text (output_buffer *, const char *, const char *);
static void maybe_wrap_text (output_buffer *, const char *, const char *);
--- 85,90 ----
*************** output_decimal (output_buffer *buffer, i
*** 292,345 ****
output_formatted_scalar (buffer, "%d", i);
}
- static inline void
- output_long_decimal (output_buffer *buffer, long int i)
- {
- output_formatted_scalar (buffer, "%ld", i);
- }
-
- static inline void
- output_unsigned_decimal (output_buffer *buffer, unsigned int i)
- {
- output_formatted_scalar (buffer, "%u", i);
- }
-
- static inline void
- output_long_unsigned_decimal (output_buffer *buffer, long unsigned int i)
- {
- output_formatted_scalar (buffer, "%lu", i);
- }
-
- static inline void
- output_octal (output_buffer *buffer, unsigned int i)
- {
- output_formatted_scalar (buffer, "%o", i);
- }
-
- static inline void
- output_long_octal (output_buffer *buffer, long unsigned int i)
- {
- output_formatted_scalar (buffer, "%lo", i);
- }
-
- static inline void
- output_hexadecimal (output_buffer *buffer, unsigned int i)
- {
- output_formatted_scalar (buffer, "%x", i);
- }
-
- static inline void
- output_long_hexadecimal (output_buffer *buffer, long unsigned int i)
- {
- output_formatted_scalar (buffer, "%lx", i);
- }
-
- static inline void
- output_long_long_decimal (output_buffer *buffer, long long int i)
- {
- output_formatted_scalar (buffer, "%lld", i);
- }
-
void
output_host_wide_integer (output_buffer *buffer, HOST_WIDE_INT i)
{
--- 311,316 ----
*************** output_buffer_to_stream (output_buffer *
*** 469,476 ****
%o: unsigned integer in base eight.
%x: unsigned integer in base sixteen.
%ld, %li, %lo, %lu, %lx: long versions of the above.
! %ll: long long int.
! %w: and integer of type HOST_WIDE_INT.
%c: character.
%s: string.
%p: pointer.
--- 440,447 ----
%o: unsigned integer in base eight.
%x: unsigned integer in base sixteen.
%ld, %li, %lo, %lu, %lx: long versions of the above.
! %lld, %lli, %llo, %llu, %llx: long long versions.
! %wd, %wi, %wo, %wu, %wx: HOST_WIDE_INT versions.
%c: character.
%s: string.
%p: pointer.
*************** output_format (output_buffer *buffer, te
*** 483,489 ****
{
for (; *text->format_spec; ++text->format_spec)
{
! bool long_integer = 0;
/* Ignore text. */
{
--- 454,461 ----
{
for (; *text->format_spec; ++text->format_spec)
{
! int precision = 0;
! bool wide = false;
/* Ignore text. */
{
*************** output_format (output_buffer *buffer, te
*** 497,513 ****
if (*text->format_spec == '\0')
break;
! /* We got a '%'. Let's see what happens. Record whether we're
! parsing a long integer format specifier. */
! if (*++text->format_spec == 'l')
! {
! long_integer = true;
! ++text->format_spec;
! }
- /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %m, %o, %s, %u,
- %x, %p, %.*s; %%. And nothing else. Front-ends should install
- printers to grok language specific format specifiers. */
switch (*text->format_spec)
{
case 'c':
--- 469,495 ----
if (*text->format_spec == '\0')
break;
! /* We got a '%'. Parse precision modifiers, if any. */
! switch (*++text->format_spec)
! {
! case 'w':
! wide = true;
! ++text->format_spec;
! break;
!
! case 'l':
! do
! ++precision;
! while (*++text->format_spec == 'l');
! break;
!
! default:
! break;
! }
! /* We don't support precision behond that of "long long". */
! if (precision > 2)
! abort();
switch (*text->format_spec)
{
case 'c':
*************** output_format (output_buffer *buffer, te
*** 516,533 ****
case 'd':
case 'i':
! if (long_integer)
! output_long_decimal (buffer, va_arg (*text->args_ptr, long int));
! else
! output_decimal (buffer, va_arg (*text->args_ptr, int));
break;
case 'o':
! if (long_integer)
! output_long_octal (buffer,
! va_arg (*text->args_ptr, unsigned long int));
! else
! output_octal (buffer, va_arg (*text->args_ptr, unsigned int));
break;
case 's':
--- 498,520 ----
case 'd':
case 'i':
! if (wide)
! output_formatted_scalar
! (buffer, HOST_WIDE_INT_PRINT_DEC,
! va_arg (*text->args_ptr, HOST_WIDE_INT));
! else
! output_integer_with_precision
! (buffer, *text->args_ptr, precision, int, "d");
break;
case 'o':
! if (wide)
! output_formatted_scalar
! (buffer, "%" HOST_WIDE_INT_PRINT "o",
! va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
! else
! output_integer_with_precision
! (buffer, *text->args_ptr, precision, unsigned, "u");
break;
case 's':
*************** output_format (output_buffer *buffer, te
*** 539,569 ****
break;
case 'u':
! if (long_integer)
! output_long_unsigned_decimal
! (buffer, va_arg (*text->args_ptr, long unsigned int));
! else
! output_unsigned_decimal
! (buffer, va_arg (*text->args_ptr, unsigned int));
break;
case 'x':
! if (long_integer)
! output_long_hexadecimal
! (buffer, va_arg (*text->args_ptr, unsigned long int));
! else
! output_hexadecimal
! (buffer, va_arg (*text->args_ptr, unsigned int));
! break;
!
! case 'l':
! if (long_integer)
! output_long_long_decimal
! (buffer, va_arg (*text->args_ptr, long long));
else
! /* Sould not happen. */
! abort();
! break;
case 'm':
output_add_string (buffer, xstrerror (text->err_no));
--- 526,549 ----
break;
case 'u':
! if (wide)
! output_formatted_scalar
! (buffer, HOST_WIDE_INT_PRINT_UNSIGNED,
! va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
! else
! output_integer_with_precision
! (buffer, *text->args_ptr, precision, unsigned, "u");
break;
case 'x':
! if (wide)
! output_formatted_scalar
! (buffer, HOST_WIDE_INT_PRINT_HEX,
! va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
else
! output_integer_with_precision
! (buffer, *text->args_ptr, precision, unsigned, "x");
! break;
case 'm':
output_add_string (buffer, xstrerror (text->err_no));
*************** output_format (output_buffer *buffer, te
*** 597,607 ****
output_append (buffer, s, s + n);
}
break;
-
- case 'w':
- output_host_wide_integer
- (buffer, va_arg (*text->args_ptr, HOST_WIDE_INT));
- break;
default:
if (!buffer->format_decoder
--- 577,582 ----