OSDN Git Service

2000-07-10 Gabriel Dos Reis <gdr@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / diagnostic.c
1 /* Language-independent diagnostic subroutines for the GNU C compiler
2    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21
22 /* This file implements the language independant aspect of diagnostic
23    message module.  */
24
25 #include "config.h"
26 #undef FLOAT /* This is for hpux. They should change hpux.  */
27 #undef FFS  /* Some systems define this in param.h.  */
28 #include "system.h"
29
30 #include "tree.h"
31 #include "rtl.h"
32 #include "tm_p.h"
33 #include "flags.h"
34 #include "input.h"
35 #include "insn-attr.h"
36 #include "insn-codes.h"
37 #include "insn-config.h"
38 #include "toplev.h"
39 #include "intl.h"
40 #include "diagnostic.h"
41
42 #define obstack_chunk_alloc xmalloc
43 #define obstack_chunk_free  free
44
45 #define diagnostic_args diagnostic_buffer->format_args
46 #define diagnostic_msg diagnostic_buffer->cursor
47
48 #define output_formatted_integer(BUFFER, FORMAT, INTEGER) \
49   do {                                                    \
50     sprintf (digit_buffer, FORMAT, INTEGER);              \
51     output_add_string (BUFFER, digit_buffer);             \
52   } while (0)
53
54 /* This data structure serves to save/restore an output_buffer state.  */
55 typedef struct
56 {
57   const char *prefix;
58   int maximum_length;
59   int ideal_maximum_length;
60   int emitted_prefix_p;
61   int prefixing_rule;
62   const char *cursor;
63   va_list format_args;
64 } output_state;
65
66
67 /* Prototypes. */
68 static int doing_line_wrapping PARAMS ((void));
69
70 static void finish_diagnostic PARAMS ((void));
71 static void output_do_verbatim PARAMS ((output_buffer *,
72                                         const char *, va_list));
73 static void output_to_stream PARAMS ((output_buffer *, FILE *));
74 static void output_format PARAMS ((output_buffer *));
75
76 static char *vbuild_message_string PARAMS ((const char *, va_list));
77 static char *build_message_string PARAMS ((const char *, ...))
78      ATTRIBUTE_PRINTF_1;
79 static char *context_as_prefix PARAMS ((const char *, int, int));
80 static void output_do_printf PARAMS ((output_buffer *, const char *));
81 static void line_wrapper_printf PARAMS ((FILE *, const char *, ...))
82      ATTRIBUTE_PRINTF_2;
83 static void vline_wrapper_message_with_location PARAMS ((const char *, int,
84                                                          int, const char *,
85                                                          va_list));
86 static void notice PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1;
87 static void v_message_with_file_and_line PARAMS ((const char *, int, int,
88                                                   const char *, va_list));
89 static void v_message_with_decl PARAMS ((tree, int, const char *, va_list));
90 static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
91 static void v_error_with_file_and_line PARAMS ((const char *, int,
92                                                 const char *, va_list));
93 static void v_error_with_decl PARAMS ((tree, const char *, va_list));
94 static void v_error_for_asm PARAMS ((rtx, const char *, va_list));
95 static void vfatal PARAMS ((const char *, va_list)) ATTRIBUTE_NORETURN;
96 static void v_warning_with_file_and_line PARAMS ((const char *, int,
97                                                   const char *, va_list));
98 static void v_warning_with_decl PARAMS ((tree, const char *, va_list));
99 static void v_warning_for_asm PARAMS ((rtx, const char *, va_list));
100 static void v_pedwarn_with_decl PARAMS ((tree, const char *, va_list));
101 static void v_pedwarn_with_file_and_line PARAMS ((const char *, int,
102                                                   const char *, va_list));
103 static void vsorry PARAMS ((const char *, va_list));
104 static void report_file_and_line PARAMS ((const char *, int, int));
105 static void vnotice PARAMS ((FILE *, const char *, va_list));
106 static void set_real_maximum_length PARAMS ((output_buffer *));
107
108 static void save_output_state PARAMS ((const output_buffer *, output_state *));
109 static void restore_output_state PARAMS ((const output_state *,
110                                           output_buffer *));
111                                           
112 static void output_unsigned_decimal PARAMS ((output_buffer *, unsigned int));
113 static void output_long_decimal PARAMS ((output_buffer *, long int));
114 static void output_long_unsigned_decimal PARAMS ((output_buffer *,
115                                                   long unsigned int));
116 static void output_octal PARAMS ((output_buffer *, unsigned int));
117 static void output_long_octal PARAMS ((output_buffer *, unsigned long int));
118 static void output_hexadecimal PARAMS ((output_buffer *, unsigned int));
119 static void output_long_hexadecimal PARAMS ((output_buffer *,
120                                              unsigned long int));
121 static void output_append_r PARAMS ((output_buffer *, const char *, int));
122 static void wrap_text PARAMS ((output_buffer *, const char *, const char *));
123 static void maybe_wrap_text PARAMS ((output_buffer *, const char *,
124                                      const char *));
125
126 extern int rtl_dump_and_exit;
127 extern int inhibit_warnings;
128 extern int warnings_are_errors;
129 extern int warningcount;
130 extern int errorcount;
131
132 /* Front-end specific tree formatter, if non-NULL.  */
133 printer_fn lang_printer = NULL;
134
135 /* This must be large enough to hold any printed integer or
136    floating-point value.  */
137 static char digit_buffer[128];
138
139 /* An output_buffer surrogate for stderr.  */
140 static output_buffer global_output_buffer;
141 output_buffer *diagnostic_buffer = &global_output_buffer;
142
143 static int need_error_newline;
144
145 /* Function of last error message;
146    more generally, function such that if next error message is in it
147    then we don't have to mention the function name.  */
148 static tree last_error_function = NULL;
149
150 /* Used to detect when input_file_stack has changed since last described.  */
151 static int last_error_tick;
152
153 /* Called by report_error_function to print out function name.
154  * Default may be overridden by language front-ends.  */
155
156 void (*print_error_function) PARAMS ((const char *)) =
157   default_print_error_function;
158
159 /* Maximum characters per line in automatic line wrapping mode.
160    Zero means don't wrap lines. */
161
162 int diagnostic_message_length_per_line;
163
164 /* Used to control every diagnostic message formatting.  Front-ends should
165    call set_message_prefixing_rule to set up their politics.  */
166 static int current_prefixing_rule;
167 \f
168 /* Initialize the diagnostic message outputting machinery.  */
169
170 void
171 initialize_diagnostics ()
172 {
173   /* By default, we don't line-wrap messages.  */
174   diagnostic_message_length_per_line = 0;
175   set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
176   /* Proceed to actual initialization.  */
177   default_initialize_buffer (diagnostic_buffer);
178 }
179
180 /* Predicate. Return 1 if we're in automatic line wrapping mode.  */
181
182 static int
183 doing_line_wrapping ()
184 {
185   return diagnostic_message_length_per_line > 0;
186 }
187
188 void
189 set_message_prefixing_rule (rule)
190      int rule;
191 {
192   current_prefixing_rule = rule;
193 }
194
195 /* Returns true if BUFFER is in line-wrappind mode.  */
196 int
197 output_is_line_wrapping (buffer)
198      output_buffer *buffer;
199 {
200   return buffer->ideal_maximum_length > 0;
201 }
202
203 /* Return BUFFER's prefix.  */
204 const char *
205 output_get_prefix (buffer)
206      const output_buffer *buffer;
207 {
208   return buffer->prefix;
209 }
210
211 /* Subroutine of output_set_maximum_length.  Set up BUFFER's
212    internal maximum characters per line.  */
213 static void
214 set_real_maximum_length (buffer)
215      output_buffer *buffer;
216 {
217   /* If we're told not to wrap lines then do the obvious thing.  */
218   if (! output_is_line_wrapping (buffer))
219     buffer->maximum_length = buffer->ideal_maximum_length;
220   else
221     {
222       int prefix_length = buffer->prefix ? strlen (buffer->prefix) : 0;
223       /* If the prefix is ridiculously too long, output at least
224          32 characters.  */
225       if (buffer->ideal_maximum_length - prefix_length < 32)
226         buffer->maximum_length = buffer->ideal_maximum_length + 32;
227       else
228         buffer->maximum_length = buffer->ideal_maximum_length;
229     }
230 }
231
232 /* Sets the number of maximum characters per line BUFFER can output
233    in line-wrapping mode.  A LENGTH value 0 suppresses line-wrapping.  */
234 void
235 output_set_maximum_length (buffer, length)
236      output_buffer *buffer;
237      int length;
238 {
239   buffer->ideal_maximum_length = length;
240   set_real_maximum_length (buffer);
241 }
242
243 /* Sets BUFFER's PREFIX.  */
244 void
245 output_set_prefix (buffer, prefix)
246      output_buffer *buffer;
247      const char *prefix;
248 {
249   buffer->prefix = prefix;
250   set_real_maximum_length (buffer);
251   buffer->emitted_prefix_p = 0;
252 }
253
254 /* Free BUFFER's prefix, a previously malloc()'d string.  */
255
256 void
257 output_destroy_prefix (buffer)
258      output_buffer *buffer;
259 {
260   if (buffer->prefix)
261     {
262       free ((char *) buffer->prefix);
263       buffer->prefix = NULL;
264     }
265 }
266
267 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
268    characters per line.  */
269 void
270 init_output_buffer (buffer, prefix, maximum_length)
271      output_buffer *buffer;
272      const char *prefix;
273      int maximum_length;
274 {
275   obstack_init (&buffer->obstack);
276   buffer->ideal_maximum_length = maximum_length;
277   buffer->line_length = 0;
278   output_set_prefix (buffer, prefix);
279   buffer->emitted_prefix_p = 0;
280   buffer->prefixing_rule = current_prefixing_rule;
281   
282   buffer->cursor = NULL;
283 }
284
285 /* Initialize BUFFER with a NULL prefix and current diagnostic message
286    length cutoff.  */
287 void
288 default_initialize_buffer (buffer)
289      output_buffer *buffer;
290 {
291   init_output_buffer (buffer, NULL, diagnostic_message_length_per_line);
292 }
293
294 /* Recompute diagnostic_buffer's attributes to reflect any change
295    in diagnostic formatting global options.  */
296 void
297 reshape_diagnostic_buffer ()
298 {
299   diagnostic_buffer->ideal_maximum_length = diagnostic_message_length_per_line;
300   diagnostic_buffer->prefixing_rule = current_prefixing_rule;
301   set_real_maximum_length (diagnostic_buffer);
302 }
303
304 /* Reinitialize BUFFER.  */
305 void
306 output_clear (buffer)
307      output_buffer *buffer;
308 {
309   obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
310   buffer->line_length = 0;
311   buffer->cursor = NULL;
312   buffer->emitted_prefix_p = 0;
313 }
314
315 /* Finishes to construct a NULL-terminated character string representing
316    the BUFFERed message.  */
317 const char *
318 output_finish (buffer)
319      output_buffer *buffer;
320 {
321   obstack_1grow (&buffer->obstack, '\0');
322   return (const char *) obstack_finish (&buffer->obstack);
323 }
324
325 /* Return the amount of characters BUFFER can accept to
326    make a full line.  */
327 int
328 output_space_left (buffer)
329      const output_buffer *buffer;
330 {
331   return buffer->maximum_length - buffer->line_length;
332 }
333
334 /* Write out BUFFER's prefix.  */
335 void
336 output_emit_prefix (buffer)
337      output_buffer *buffer;
338 {
339   if (buffer->prefix)
340     {
341       switch (buffer->prefixing_rule)
342         {
343         default:
344         case DIAGNOSTICS_SHOW_PREFIX_NEVER:
345           break;
346
347         case DIAGNOSTICS_SHOW_PREFIX_ONCE:
348           if (buffer->emitted_prefix_p)
349             break;
350           else
351             buffer->emitted_prefix_p = 1;
352           /* Fall through.  */
353
354         case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
355           buffer->line_length += strlen (buffer->prefix);
356           obstack_grow
357             (&buffer->obstack, buffer->prefix, buffer->line_length);
358           break;
359         }
360     }
361 }
362
363 /* Have BUFFER start a new line.  */
364 void
365 output_add_newline (buffer)
366      output_buffer *buffer;
367 {
368   obstack_1grow (&buffer->obstack, '\n');
369   buffer->line_length = 0;
370 }
371
372 /* Appends a character to BUFFER.  */
373 void
374 output_add_character (buffer, c)
375      output_buffer *buffer;
376      int c;
377 {
378   if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
379     output_add_newline (buffer);
380   obstack_1grow (&buffer->obstack, c);
381   ++buffer->line_length;
382 }
383
384 /* Adds a space to BUFFER.  */
385 void
386 output_add_space (buffer)
387      output_buffer *buffer;
388 {
389   if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
390     {
391       output_add_newline (buffer);
392       return;
393     }
394   obstack_1grow (&buffer->obstack, ' ');
395   ++buffer->line_length;
396 }
397
398 /* These functions format an INTEGER into BUFFER as suggested by their
399    names.  */
400 void
401 output_decimal (buffer, i)
402      output_buffer *buffer;
403      int i;
404 {
405   output_formatted_integer (buffer, "%d", i);
406 }
407
408 static void
409 output_long_decimal (buffer, i)
410      output_buffer *buffer;
411      long int i;
412 {
413   output_formatted_integer (buffer, "%ld", i);
414 }
415
416 static void
417 output_unsigned_decimal (buffer, i)
418      output_buffer *buffer;
419      unsigned int i;
420 {
421   output_formatted_integer (buffer, "%u", i);
422 }
423
424 static void
425 output_long_unsigned_decimal (buffer, i)
426      output_buffer *buffer;
427      long unsigned int i;
428 {
429   output_formatted_integer (buffer, "%lu", i);
430 }
431
432 static void
433 output_octal (buffer, i)
434      output_buffer *buffer;
435      unsigned int i;
436 {
437   output_formatted_integer (buffer, "%o", i);
438 }
439
440 static void
441 output_long_octal (buffer, i)
442      output_buffer *buffer;
443      unsigned long int i;
444 {
445   output_formatted_integer (buffer, "%lo", i);
446 }
447
448 static void
449 output_hexadecimal (buffer, i)
450      output_buffer *buffer;
451      unsigned int i;
452 {
453   output_formatted_integer (buffer, "%x", i);
454 }
455
456 static void
457 output_long_hexadecimal (buffer, i)
458      output_buffer *buffer;
459      unsigned long int i;
460 {
461   output_formatted_integer (buffer, "%lx", i);
462 }
463
464 /* Append to BUFFER a string specified by its STARTING character
465    and LENGTH.  */
466 static void
467 output_append_r (buffer, start, length)
468      output_buffer *buffer;
469      const char *start;
470      int length;
471 {
472   obstack_grow (&buffer->obstack, start, length);
473   buffer->line_length += length;
474 }
475
476 /* Append a string deliminated by START and END to BUFFER.  No wrapping is
477    done.  However, if beginning a new line then emit BUFFER->PREFIX and
478    skip any leading whitespace if appropriate.  The caller must ensure
479    that it is safe to do so.  */
480 void
481 output_append (buffer, start, end)
482      output_buffer *buffer;
483      const char *start;
484      const char *end;
485 {
486   /* Emit prefix and skip whitespace if we're starting a new line.  */
487   if (buffer->line_length == 0)
488     {
489       output_emit_prefix (buffer);
490       if (output_is_line_wrapping (buffer))
491         while (start != end && *start == ' ')
492           ++start;
493     }
494   output_append_r (buffer, start, end - start);
495 }
496
497 /* Wrap a text delimited by START and END into BUFFER.  */
498 static void
499 wrap_text (buffer, start, end)
500      output_buffer *buffer;
501      const char *start;
502      const char *end;
503 {
504   while (start != end)
505     {
506       /* Dump anything bodered by whitespaces.  */ 
507       {
508         const char *p = start;
509         while (p != end && *p != ' ' && *p != '\n')
510           ++p;
511         if (p - start >= output_space_left (buffer))
512           output_add_newline (buffer);
513         output_append (buffer, start, p);
514         start = p;
515       }
516
517       if (start != end && *start == ' ')
518         {
519           output_add_space (buffer);
520           ++start;
521         }
522       if (start != end && *start == '\n')
523         {
524           output_add_newline (buffer);
525           ++start;
526         }
527     }
528 }
529
530 /* Same as wrap_text but wrap text only when in line-wrapping mode.  */
531 static void
532 maybe_wrap_text (buffer, start, end)
533      output_buffer *buffer;
534      const char *start;
535      const char *end;
536 {
537   if (output_is_line_wrapping (buffer))
538     wrap_text (buffer, start, end);
539   else
540     output_append (buffer, start, end);
541 }
542
543
544 /* Append a STRING to BUFFER; the STRING maybe be line-wrapped if in
545    appropriate mode.  */
546
547 void
548 output_add_string (buffer, str)
549      output_buffer *buffer;
550      const char *str;
551 {
552   maybe_wrap_text (buffer, str, str + (str ? strlen (str) : 0));
553 }
554
555 /* Flush the content of BUFFER onto FILE and reinitialize BUFFER.  */
556
557 static void
558 output_to_stream (buffer, file)
559      output_buffer *buffer;
560      FILE *file;
561 {
562   const char *text = output_finish (buffer);
563   fputs (text, file);
564   output_clear (buffer);
565 }
566
567 /* Format a message pointed to by BUFFER->CURSOR using BUFFER->CURSOR
568    as appropriate.  The following format specifiers are recognized as
569    being language independent:
570    %d, %i: (signed) integer in base ten.
571    %u: unsigned integer in base ten.
572    %o: (signed) integer in base eight.
573    %x: (signged) integer in base sixteen.
574    %ld, %li, %lo, %lu, %lx: long versions of the above.
575    %c: character.
576    %s: string.
577    %%: `%'.
578    %*.s: a substring the length of which is specified by an integer.  */
579 static void
580 output_format (buffer)
581      output_buffer *buffer;
582 {
583   for (; *buffer->cursor; ++buffer->cursor)
584     {
585       int long_integer = 0;
586       /* Ignore text.  */
587       {
588         const char *p = buffer->cursor;
589         while (*p && *p != '%')
590           ++p;
591         maybe_wrap_text (buffer, buffer->cursor, p);
592         buffer->cursor = p;
593       }
594       if (!*buffer->cursor)
595         break;
596
597       /* We got a '%'.  Let's see what happens. Record whether we're
598          parsing a long integer format specifier.  */
599       if (*++buffer->cursor == 'l')
600         {
601           long_integer = 1;
602           ++buffer->cursor;
603         }
604
605       /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
606          %x, %.*s; %%.  And nothing else.  Front-ends should install
607          printers to grok language specific format specifiers.  */
608       switch (*buffer->cursor)
609         {
610         case 'c':
611           output_add_character
612             (buffer, va_arg (buffer->format_args, int));
613           break;
614           
615         case 'd':
616         case 'i':
617           if (long_integer)
618             output_long_decimal
619               (buffer, va_arg (buffer->format_args, long int));
620           else
621             output_decimal (buffer, va_arg (buffer->format_args, int));
622           break;
623
624         case 'o':
625           if (long_integer)
626             output_long_octal
627               (buffer, va_arg (buffer->format_args, unsigned long int));
628           else
629             output_octal (buffer, va_arg (buffer->format_args, unsigned int));
630           break;
631
632         case 's':
633           output_add_string
634             (buffer, va_arg (buffer->format_args, const char *));
635           break;
636
637         case 'u':
638           if (long_integer)
639             output_long_unsigned_decimal
640               (buffer, va_arg (buffer->format_args, long unsigned int));
641           else
642             output_unsigned_decimal
643               (buffer, va_arg (buffer->format_args, unsigned int));
644           
645         case 'x':
646           if (long_integer)
647             output_long_hexadecimal
648               (buffer, va_arg (buffer->format_args, unsigned long int));
649           else
650             output_hexadecimal
651               (buffer, va_arg (buffer->format_args, unsigned int));
652           break;
653
654         case '%':
655           output_add_character (buffer, '%');
656           break;
657
658         case '.':
659           {
660             int n;
661             const char *s;
662             /* We handle no precision specifier but `%.*s'.  */
663             if (*++buffer->cursor != '*')
664               abort ();
665             else if (*++buffer->cursor != 's')
666               abort();
667             n = va_arg (buffer->format_args, int);
668             s = va_arg (buffer->format_args, const char *);
669             output_append (buffer, s, s + n);
670           }
671           break;
672
673         default:
674           if (!lang_printer || !(*lang_printer) (buffer))
675             {
676               /* Hmmm.  The front-end failed to install a format translator
677                  but called us with an unrecognized format.  Sorry.  */
678               abort();
679             }
680         }
681     }
682 }
683
684 static char *
685 vbuild_message_string (msgid, ap)
686      const char *msgid;
687      va_list ap;
688 {
689   char *str;
690
691   vasprintf (&str, msgid, ap);
692   return str;
693 }
694
695 /*  Return a malloc'd string containing MSGID formatted a la
696     printf.  The caller is reponsible for freeing the memory.  */
697
698 static char *
699 build_message_string VPARAMS ((const char *msgid, ...))
700 {
701 #ifndef ANSI_PROTOTYPES
702   const char *msgid;
703 #endif
704   va_list ap;
705   char *str;
706
707   VA_START (ap, msgid);
708
709 #ifndef ANSI_PROTOTYPES
710   msgid = va_arg (ap, const char *);
711 #endif
712
713   str = vbuild_message_string (msgid, ap);
714
715   va_end (ap);
716
717   return str;
718 }
719
720
721 /* Return a malloc'd string describing a location.  The caller is
722    responsible for freeing the memory.  */
723
724 static char *
725 context_as_prefix (file, line, warn)
726      const char *file;
727      int line;
728      int warn;
729 {
730   if (file)
731     {
732       if (warn)
733         return build_message_string ("%s:%d: warning: ", file, line);
734       else
735         return build_message_string ("%s:%d: ", file, line);
736     }
737   else
738     {
739       if (warn)
740         return build_message_string ("%s: warning: ", progname);
741       else
742         return build_message_string ("%s: ", progname);
743     }
744 }
745
746 /* Format a MESSAGE into BUFFER.  Automatically wrap lines.  */
747
748 static void
749 output_do_printf (buffer, msgid)
750      output_buffer *buffer;
751      const char *msgid;
752 {
753   char *message = vbuild_message_string (msgid, buffer->format_args);
754
755   output_add_string (buffer, message);
756   free (message);
757 }
758
759
760 /* Format a message into BUFFER a la printf.  */
761
762 void
763 output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
764 {
765 #ifndef ANSI_PROTOTYPES
766   struct output_buffer *buffer;
767   const char *msgid;
768 #endif
769   va_list ap;
770   va_list old_args;
771
772   VA_START (ap, msgid);
773 #ifndef ANSI_PROTOTYPES
774   buffer = va_arg (ap, struct output_buffer *);
775   msgid = va_arg (ap, const char *);
776 #endif
777   va_copy (old_args, buffer->format_args);
778
779   va_copy (buffer->format_args, ap);
780   output_do_printf (buffer, msgid);
781   va_end (buffer->format_args);
782
783   va_copy (buffer->format_args, old_args);
784 }
785
786
787 /* Format a MESSAGE into FILE.  Do line wrapping, starting new lines
788    with PREFIX.  */
789
790 static void
791 line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...))
792 {
793 #ifndef ANSI_PROTOTYPES
794   FILE *file;
795   const char *msgid;
796 #endif
797   output_buffer buffer;
798   
799   default_initialize_buffer (&buffer);
800   VA_START (buffer.format_args, msgid);
801
802 #ifndef ANSI_PROTOTYPES
803   file = va_arg (buffer.format_args, FILE *);
804   msgid = va_arg (buffer.format_args, const char *);
805 #endif  
806
807   output_do_printf (&buffer, msgid);
808   output_to_stream (&buffer, file);
809
810   va_end (buffer.format_args);
811 }
812
813
814 static void
815 vline_wrapper_message_with_location (file, line, warn, msgid, ap)
816      const char *file;
817      int line;
818      int warn;
819      const char *msgid;
820      va_list ap;
821 {
822   output_buffer buffer;
823   
824   init_output_buffer (&buffer, context_as_prefix (file, line, warn),
825                       diagnostic_message_length_per_line);
826   va_copy (buffer.format_args, ap);
827   output_do_printf (&buffer, msgid);
828   output_to_stream (&buffer, stderr);
829
830   output_destroy_prefix (&buffer);
831   fputc ('\n', stderr);
832 }
833
834
835 /* Print the message MSGID in FILE.  */
836
837 static void
838 vnotice (file, msgid, ap)
839      FILE *file;
840      const char *msgid;
841      va_list ap;
842 {
843   vfprintf (file, _(msgid), ap);
844 }
845
846 /* Print MSGID on stderr.  */
847
848 static void
849 notice VPARAMS ((const char *msgid, ...))
850 {
851 #ifndef ANSI_PROTOTYPES
852   char *msgid;
853 #endif
854   va_list ap;
855
856   VA_START (ap, msgid);
857
858 #ifndef ANSI_PROTOTYPES
859   msgid = va_arg (ap, char *);
860 #endif
861
862   vnotice (stderr, msgid, ap);
863   va_end (ap);
864 }
865
866 /* Report FILE and LINE (or program name), and optionally just WARN.  */
867
868 static void
869 report_file_and_line (file, line, warn)
870      const char *file;
871      int line;
872      int warn;
873 {
874   if (file)
875     fprintf (stderr, "%s:%d: ", file, line);
876   else
877     fprintf (stderr, "%s: ", progname);
878
879   if (warn)
880     notice ("warning: ");
881 }
882
883 /* Print a message relevant to line LINE of file FILE.  */
884
885 static void
886 v_message_with_file_and_line (file, line, warn, msgid, ap)
887      const char *file;
888      int line;
889      int warn;
890      const char *msgid;
891      va_list ap;
892 {
893   report_file_and_line (file, line, warn);
894   vnotice (stderr, msgid, ap);
895   fputc ('\n', stderr);
896 }
897
898 /* Print a message relevant to the given DECL.  */
899
900 static void
901 v_message_with_decl (decl, warn, msgid, ap)
902      tree decl;
903      int warn;
904      const char *msgid;
905      va_list ap;
906 {
907   const char *p;
908   output_buffer buffer;
909
910   if (doing_line_wrapping ())
911     {
912       init_output_buffer
913         (&buffer, context_as_prefix
914          (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn),
915          diagnostic_message_length_per_line);
916     }
917   else
918     report_file_and_line (DECL_SOURCE_FILE (decl),
919                           DECL_SOURCE_LINE (decl), warn);
920
921   /* Do magic to get around lack of varargs support for insertion
922      of arguments into existing list.  We know that the decl is first;
923      we ass_u_me that it will be printed with "%s".  */
924
925   for (p = _(msgid); *p; ++p)
926     {
927       if (*p == '%')
928         {
929           if (*(p + 1) == '%')
930             ++p;
931           else if (*(p + 1) != 's')
932             abort ();
933           else
934             break;
935         }
936     }
937
938   if (p > _(msgid))                     /* Print the left-hand substring.  */
939     {
940       if (doing_line_wrapping ())
941         output_printf (&buffer, "%.*s", (int)(p - _(msgid)), _(msgid));
942       else
943         fprintf (stderr, "%.*s", (int)(p - _(msgid)), _(msgid));
944     }
945
946   if (*p == '%')                /* Print the name.  */
947     {
948       const char *n = (DECL_NAME (decl)
949                  ? (*decl_printable_name) (decl, 2)
950                  : _("((anonymous))"));
951       if (doing_line_wrapping ())
952         output_add_string (&buffer, n);
953       else
954         fputs (n, stderr);
955       while (*p)
956         {
957           ++p;
958           if (ISALPHA (*(p - 1) & 0xFF))
959             break;
960         }
961     }
962
963   if (*p)                       /* Print the rest of the message.  */
964     {
965       if (doing_line_wrapping ())
966         {
967           va_copy (buffer.format_args, ap);
968           output_do_printf (&buffer, p);
969           va_copy (ap, buffer.format_args);
970         }
971       else
972         vfprintf (stderr, p, ap);
973     }
974
975   if (doing_line_wrapping())
976     {
977       output_to_stream (&buffer, stderr);
978       output_destroy_prefix (&buffer);
979     }
980   
981   fputc ('\n', stderr);
982 }
983
984 /* Figure file and line of the given INSN.  */
985
986 static void
987 file_and_line_for_asm (insn, pfile, pline)
988      rtx insn;
989      const char **pfile;
990      int *pline;
991 {
992   rtx body = PATTERN (insn);
993   rtx asmop;
994
995   /* Find the (or one of the) ASM_OPERANDS in the insn.  */
996   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
997     asmop = SET_SRC (body);
998   else if (GET_CODE (body) == ASM_OPERANDS)
999     asmop = body;
1000   else if (GET_CODE (body) == PARALLEL
1001            && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1002     asmop = SET_SRC (XVECEXP (body, 0, 0));
1003   else if (GET_CODE (body) == PARALLEL
1004            && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1005     asmop = XVECEXP (body, 0, 0);
1006   else
1007     asmop = NULL;
1008
1009   if (asmop)
1010     {
1011       *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1012       *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1013     }
1014   else
1015     {
1016       *pfile = input_filename;
1017       *pline = lineno;
1018     }
1019 }
1020
1021 /* Report an error at line LINE of file FILE.  */
1022
1023 static void
1024 v_error_with_file_and_line (file, line, msgid, ap)
1025      const char *file;
1026      int line;
1027      const char *msgid;
1028      va_list ap;
1029 {
1030   count_error (0);
1031   report_error_function (file);
1032   if (doing_line_wrapping ())
1033     vline_wrapper_message_with_location (file, line, 0, msgid, ap);
1034   else
1035     v_message_with_file_and_line (file, line, 0, msgid, ap);
1036 }
1037
1038 /* Report an error at the declaration DECL.
1039    MSGID is a format string which uses %s to substitute the declaration
1040    name; subsequent substitutions are a la printf.  */
1041
1042 static void
1043 v_error_with_decl (decl, msgid, ap)
1044      tree decl;
1045      const char *msgid;
1046      va_list ap;
1047 {
1048   count_error (0);
1049   report_error_function (DECL_SOURCE_FILE (decl));
1050   v_message_with_decl (decl, 0, msgid, ap);
1051 }
1052
1053
1054 /* Report an error at the line number of the insn INSN.
1055    This is used only when INSN is an `asm' with operands,
1056    and each ASM_OPERANDS records its own source file and line.  */
1057
1058 static void
1059 v_error_for_asm (insn, msgid, ap)
1060      rtx insn;
1061      const char *msgid;
1062      va_list ap;
1063 {
1064   const char *file;
1065   int line;
1066
1067   count_error (0);
1068   file_and_line_for_asm (insn, &file, &line);
1069   report_error_function (file);
1070   v_message_with_file_and_line (file, line, 0, msgid, ap);
1071 }
1072
1073
1074 /* Report an error at the current line number.  */
1075
1076 void
1077 verror (msgid, ap)
1078      const char *msgid;
1079      va_list ap;
1080 {
1081   v_error_with_file_and_line (input_filename, lineno, msgid, ap);
1082 }
1083
1084
1085 /* Report a fatal error at the current line number.  Allow a front end to
1086    intercept the message.  */
1087
1088 static void (*fatal_function) PARAMS ((const char *, va_list));
1089
1090 static void
1091 vfatal (msgid, ap)
1092      const char *msgid;
1093      va_list ap;
1094 {
1095    if (fatal_function != 0)
1096      (*fatal_function) (_(msgid), ap);
1097
1098   verror (msgid, ap);
1099   exit (FATAL_EXIT_CODE);
1100 }
1101
1102 /* Report a warning at line LINE of file FILE.  */
1103
1104 static void
1105 v_warning_with_file_and_line (file, line, msgid, ap)
1106      const char *file;
1107      int line;
1108      const char *msgid;
1109      va_list ap;
1110 {
1111   if (count_error (1))
1112     {
1113       report_error_function (file);
1114       if (doing_line_wrapping ())
1115         vline_wrapper_message_with_location (file, line, 1, msgid, ap);
1116       else
1117         v_message_with_file_and_line (file, line, 1, msgid, ap);
1118     }
1119 }
1120
1121
1122 /* Report a warning at the declaration DECL.
1123    MSGID is a format string which uses %s to substitute the declaration
1124    name; subsequent substitutions are a la printf.  */
1125
1126 static void
1127 v_warning_with_decl (decl, msgid, ap)
1128      tree decl;
1129      const char *msgid;
1130      va_list ap;
1131 {
1132   if (count_error (1))
1133     {
1134       report_error_function (DECL_SOURCE_FILE (decl));
1135       v_message_with_decl (decl, 1, msgid, ap);
1136     }
1137 }
1138
1139
1140 /* Report a warning at the line number of the insn INSN.
1141    This is used only when INSN is an `asm' with operands,
1142    and each ASM_OPERANDS records its own source file and line.  */
1143
1144 static void
1145 v_warning_for_asm (insn, msgid, ap)
1146      rtx insn;
1147      const char *msgid;
1148      va_list ap;
1149 {
1150   if (count_error (1))
1151     {
1152       const char *file;
1153       int line;
1154
1155       file_and_line_for_asm (insn, &file, &line);
1156       report_error_function (file);
1157       v_message_with_file_and_line (file, line, 1, msgid, ap);
1158     }
1159 }
1160
1161
1162 /* Report a warning at the current line number.  */
1163
1164 void
1165 vwarning (msgid, ap)
1166      const char *msgid;
1167      va_list ap;
1168 {
1169   v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
1170 }
1171
1172 /* These functions issue either warnings or errors depending on
1173    -pedantic-errors.  */
1174
1175 void
1176 vpedwarn (msgid, ap)
1177      const char *msgid;
1178      va_list ap;
1179 {
1180   if (flag_pedantic_errors)
1181     verror (msgid, ap);
1182   else
1183     vwarning (msgid, ap);
1184 }
1185
1186
1187 static void
1188 v_pedwarn_with_decl (decl, msgid, ap)
1189      tree decl;
1190      const char *msgid;
1191      va_list ap;
1192 {
1193   /* We don't want -pedantic-errors to cause the compilation to fail from
1194      "errors" in system header files.  Sometimes fixincludes can't fix what's
1195      broken (eg: unsigned char bitfields - fixing it may change the alignment
1196      which will cause programs to mysteriously fail because the C library
1197      or kernel uses the original layout).  There's no point in issuing a
1198      warning either, it's just unnecessary noise.  */
1199
1200   if (! DECL_IN_SYSTEM_HEADER (decl))
1201     {
1202       if (flag_pedantic_errors)
1203         v_error_with_decl (decl, msgid, ap);
1204       else
1205         v_warning_with_decl (decl, msgid, ap);
1206     }
1207 }
1208
1209
1210 static void
1211 v_pedwarn_with_file_and_line (file, line, msgid, ap)
1212      const char *file;
1213      int line;
1214      const char *msgid;
1215      va_list ap;
1216 {
1217   if (flag_pedantic_errors)
1218     v_error_with_file_and_line (file, line, msgid, ap);
1219   else
1220     v_warning_with_file_and_line (file, line, msgid, ap);
1221 }
1222
1223
1224 /* Apologize for not implementing some feature.  */
1225
1226 static void
1227 vsorry (msgid, ap)
1228      const char *msgid;
1229      va_list ap;
1230 {
1231   sorrycount++;
1232   if (input_filename)
1233     fprintf (stderr, "%s:%d: ", input_filename, lineno);
1234   else
1235     fprintf (stderr, "%s: ", progname);
1236   notice ("sorry, not implemented: ");
1237   vnotice (stderr, msgid, ap);
1238   fputc ('\n', stderr);
1239 }
1240
1241 \f
1242 /* Count an error or warning.  Return 1 if the message should be printed.  */
1243
1244 int
1245 count_error (warningp)
1246      int warningp;
1247 {
1248   if (warningp && inhibit_warnings)
1249     return 0;
1250
1251   if (warningp && !warnings_are_errors)
1252     warningcount++;
1253   else
1254     {
1255       static int warning_message = 0;
1256
1257       if (warningp && !warning_message)
1258         {
1259           verbatim ("%s: warnings being treated as errors\n", progname);
1260           warning_message = 1;
1261         }
1262       errorcount++;
1263     }
1264
1265   return 1;
1266 }
1267
1268 /* Print a diagnistic MSGID on FILE.  */
1269 void
1270 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
1271 {
1272 #ifndef ANSI_PROTOTYPES
1273   FILE *file;
1274   const char *msgid;
1275 #endif
1276   va_list ap;
1277
1278   VA_START (ap, msgid);
1279
1280 #ifndef ANSI_PROTOTYPES
1281   file = va_arg (ap, FILE *);
1282   msgid = va_arg (ap, const char *);
1283 #endif
1284
1285   vnotice (file, msgid, ap);
1286   va_end (ap);
1287 }
1288
1289
1290 /* Print a fatal error message.  NAME is the text.
1291    Also include a system error message based on `errno'.  */
1292
1293 void
1294 pfatal_with_name (name)
1295   const char *name;
1296 {
1297   fprintf (stderr, "%s: ", progname);
1298   perror (name);
1299   exit (FATAL_EXIT_CODE);
1300 }
1301
1302 void
1303 fatal_io_error (name)
1304   const char *name;
1305 {
1306   notice ("%s: %s: I/O error\n", progname, name);
1307   exit (FATAL_EXIT_CODE);
1308 }
1309
1310 /* Issue a pedantic warning MSGID.  */
1311 void
1312 pedwarn VPARAMS ((const char *msgid, ...))
1313 {
1314 #ifndef ANSI_PROTOTYPES
1315   const char *msgid;
1316 #endif
1317   va_list ap;
1318
1319   VA_START (ap, msgid);
1320
1321 #ifndef ANSI_PROTOTYPES
1322   msgid = va_arg (ap, const char *);
1323 #endif
1324
1325   vpedwarn (msgid, ap);
1326   va_end (ap);
1327 }
1328
1329 /* Issue a pedantic waring about DECL.  */
1330 void
1331 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1332 {
1333 #ifndef ANSI_PROTOTYPES
1334   tree decl;
1335   const char *msgid;
1336 #endif
1337   va_list ap;
1338
1339   VA_START (ap, msgid);
1340
1341 #ifndef ANSI_PROTOTYPES
1342   decl = va_arg (ap, tree);
1343   msgid = va_arg (ap, const char *);
1344 #endif
1345
1346   v_pedwarn_with_decl (decl, msgid, ap);
1347   va_end (ap);
1348 }
1349
1350 /* Same as above but within the context FILE and LINE. */
1351 void
1352 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
1353                                      const char *msgid, ...))
1354 {
1355 #ifndef ANSI_PROTOTYPES
1356   const char *file;
1357   int line;
1358   const char *msgid;
1359 #endif
1360   va_list ap;
1361
1362   VA_START (ap, msgid);
1363
1364 #ifndef ANSI_PROTOTYPES
1365   file = va_arg (ap, const char *);
1366   line = va_arg (ap, int);
1367   msgid = va_arg (ap, const char *);
1368 #endif
1369
1370   v_pedwarn_with_file_and_line (file, line, msgid, ap);
1371   va_end (ap);
1372 }
1373
1374 /* Just apologize with MSGID.  */
1375 void
1376 sorry VPARAMS ((const char *msgid, ...))
1377 {
1378 #ifndef ANSI_PROTOTYPES
1379   const char *msgid;
1380 #endif
1381   va_list ap;
1382
1383   VA_START (ap, msgid);
1384
1385 #ifndef ANSI_PROTOTYPES
1386   msgid = va_arg (ap, const char *);
1387 #endif
1388
1389   vsorry (msgid, ap);
1390   va_end (ap);
1391 }
1392
1393 /* Called when the start of a function definition is parsed,
1394    this function prints on stderr the name of the function.  */
1395
1396 void
1397 announce_function (decl)
1398      tree decl;
1399 {
1400   if (! quiet_flag)
1401     {
1402       if (rtl_dump_and_exit)
1403         fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1404       else
1405         {
1406           if (doing_line_wrapping ())
1407             line_wrapper_printf
1408               (stderr, " %s", (*decl_printable_name) (decl, 2));
1409           else
1410             fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1411         }
1412       fflush (stderr);
1413       need_error_newline = 1;
1414       last_error_function = current_function_decl;
1415     }
1416 }
1417
1418 /* The default function to print out name of current function that caused
1419    an error.  */
1420
1421 void
1422 default_print_error_function (file)
1423   const char *file;
1424 {
1425   if (last_error_function != current_function_decl)
1426     {
1427       char *prefix = NULL;
1428       output_buffer buffer;
1429       
1430       if (file)
1431         prefix = build_message_string ("%s: ", file);
1432
1433       if (doing_line_wrapping ())
1434         init_output_buffer
1435           (&buffer, prefix, diagnostic_message_length_per_line);
1436       else
1437         {
1438           if (file)
1439             fprintf (stderr, "%s: ", file);
1440         }
1441       
1442       if (current_function_decl == NULL)
1443         {
1444           if (doing_line_wrapping ())
1445             output_printf (&buffer, "At top level:\n");
1446           else
1447             notice ("At top level:\n");
1448         }
1449       else
1450         {
1451           if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1452             {
1453               if (doing_line_wrapping ())
1454                 output_printf
1455                   (&buffer, "In method `%s':\n",
1456                    (*decl_printable_name) (current_function_decl, 2));
1457               else
1458                 notice ("In method `%s':\n",
1459                         (*decl_printable_name) (current_function_decl, 2));
1460             }
1461           else
1462             {
1463               if (doing_line_wrapping ())
1464                 output_printf
1465                   (&buffer, "In function `%s':\n",
1466                    (*decl_printable_name) (current_function_decl, 2));
1467               else
1468                 notice ("In function `%s':\n",
1469                         (*decl_printable_name) (current_function_decl, 2));
1470             }
1471         }
1472
1473       last_error_function = current_function_decl;
1474
1475       if (doing_line_wrapping ())
1476         output_to_stream (&buffer, stderr);
1477       
1478       free ((char*) prefix);
1479     }
1480 }
1481
1482 /* Prints out, if necessary, the name of the current function
1483   that caused an error.  Called from all error and warning functions.
1484   We ignore the FILE parameter, as it cannot be relied upon.  */
1485
1486 void
1487 report_error_function (file)
1488   const char *file ATTRIBUTE_UNUSED;
1489 {
1490   struct file_stack *p;
1491
1492   if (need_error_newline)
1493     {
1494       verbatim ("\n");
1495       need_error_newline = 0;
1496     }
1497
1498   if (input_file_stack && input_file_stack->next != 0
1499       && input_file_stack_tick != last_error_tick)
1500     {
1501       for (p = input_file_stack->next; p; p = p->next)
1502         if (p == input_file_stack->next)
1503           verbatim ("In file included from %s:%d", p->name, p->line);
1504         else
1505           verbatim (",\n                 from %s:%d", p->name, p->line);
1506       verbatim (":\n");
1507       last_error_tick = input_file_stack_tick;
1508     }
1509
1510   (*print_error_function) (input_filename);
1511 }
1512
1513 void
1514 error_with_file_and_line VPARAMS ((const char *file, int line,
1515                                    const char *msgid, ...))
1516 {
1517 #ifndef ANSI_PROTOTYPES
1518   const char *file;
1519   int line;
1520   const char *msgid;
1521 #endif
1522   va_list ap;
1523
1524   VA_START (ap, msgid);
1525
1526 #ifndef ANSI_PROTOTYPES
1527   file = va_arg (ap, const char *);
1528   line = va_arg (ap, int);
1529   msgid = va_arg (ap, const char *);
1530 #endif
1531
1532   v_error_with_file_and_line (file, line, msgid, ap);
1533   va_end (ap);
1534 }
1535
1536 void
1537 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1538 {
1539 #ifndef ANSI_PROTOTYPES
1540   tree decl;
1541   const char *msgid;
1542 #endif
1543   va_list ap;
1544
1545   VA_START (ap, msgid);
1546
1547 #ifndef ANSI_PROTOTYPES
1548   decl = va_arg (ap, tree);
1549   msgid = va_arg (ap, const char *);
1550 #endif
1551
1552   v_error_with_decl (decl, msgid, ap);
1553   va_end (ap);
1554 }
1555
1556 void
1557 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1558 {
1559 #ifndef ANSI_PROTOTYPES
1560   rtx insn;
1561   const char *msgid;
1562 #endif
1563   va_list ap;
1564
1565   VA_START (ap, msgid);
1566
1567 #ifndef ANSI_PROTOTYPES
1568   insn = va_arg (ap, rtx);
1569   msgid = va_arg (ap, const char *);
1570 #endif
1571
1572   v_error_for_asm (insn, msgid, ap);
1573   va_end (ap);
1574 }
1575
1576 void
1577 error VPARAMS ((const char *msgid, ...))
1578 {
1579 #ifndef ANSI_PROTOTYPES
1580   const char *msgid;
1581 #endif
1582   va_list ap;
1583
1584   VA_START (ap, msgid);
1585
1586 #ifndef ANSI_PROTOTYPES
1587   msgid = va_arg (ap, const char *);
1588 #endif
1589
1590   verror (msgid, ap);
1591   va_end (ap);
1592 }
1593
1594 /* Set the function to call when a fatal error occurs.  */
1595
1596 void
1597 set_fatal_function (f)
1598      void (*f) PARAMS ((const char *, va_list));
1599 {
1600   fatal_function = f;
1601 }
1602
1603 void
1604 fatal VPARAMS ((const char *msgid, ...))
1605 {
1606 #ifndef ANSI_PROTOTYPES
1607   const char *msgid;
1608 #endif
1609   va_list ap;
1610
1611   VA_START (ap, msgid);
1612
1613 #ifndef ANSI_PROTOTYPES
1614   msgid = va_arg (ap, const char *);
1615 #endif
1616
1617   vfatal (msgid, ap);
1618   va_end (ap);
1619 }
1620
1621 void
1622 _fatal_insn (msgid, insn, file, line, function)
1623      const char *msgid;
1624      rtx insn;
1625      const char *file;
1626      int line;
1627      const char *function;
1628 {
1629   error ("%s", msgid);
1630   debug_rtx (insn);
1631   fancy_abort (file, line, function);
1632 }
1633
1634 void
1635 _fatal_insn_not_found (insn, file, line, function)
1636      rtx insn;
1637      const char *file;
1638      int line;
1639      const char *function;
1640 {
1641   if (INSN_CODE (insn) < 0)
1642     _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1643   else
1644     _fatal_insn ("Insn does not satisfy its constraints:",
1645                 insn, file, line, function);
1646 }
1647
1648 void
1649 warning_with_file_and_line VPARAMS ((const char *file, int line,
1650                                      const char *msgid, ...))
1651 {
1652 #ifndef ANSI_PROTOTYPES
1653   const char *file;
1654   int line;
1655   const char *msgid;
1656 #endif
1657   va_list ap;
1658
1659   VA_START (ap, msgid);
1660
1661 #ifndef ANSI_PROTOTYPES
1662   file = va_arg (ap, const char *);
1663   line = va_arg (ap, int);
1664   msgid = va_arg (ap, const char *);
1665 #endif
1666
1667   v_warning_with_file_and_line (file, line, msgid, ap);
1668   va_end (ap);
1669 }
1670
1671 void
1672 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1673 {
1674 #ifndef ANSI_PROTOTYPES
1675   tree decl;
1676   const char *msgid;
1677 #endif
1678   va_list ap;
1679
1680   VA_START (ap, msgid);
1681
1682 #ifndef ANSI_PROTOTYPES
1683   decl = va_arg (ap, tree);
1684   msgid = va_arg (ap, const char *);
1685 #endif
1686
1687   v_warning_with_decl (decl, msgid, ap);
1688   va_end (ap);
1689 }
1690
1691 void
1692 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1693 {
1694 #ifndef ANSI_PROTOTYPES
1695   rtx insn;
1696   const char *msgid;
1697 #endif
1698   va_list ap;
1699
1700   VA_START (ap, msgid);
1701
1702 #ifndef ANSI_PROTOTYPES
1703   insn = va_arg (ap, rtx);
1704   msgid = va_arg (ap, const char *);
1705 #endif
1706
1707   v_warning_for_asm (insn, msgid, ap);
1708   va_end (ap);
1709 }
1710
1711 void
1712 warning VPARAMS ((const char *msgid, ...))
1713 {
1714 #ifndef ANSI_PROTOTYPES
1715   const char *msgid;
1716 #endif
1717   va_list ap;
1718
1719   VA_START (ap, msgid);
1720
1721 #ifndef ANSI_PROTOTYPES
1722   msgid = va_arg (ap, const char *);
1723 #endif
1724
1725   vwarning (msgid, ap);
1726   va_end (ap);
1727 }
1728
1729 /* Save BUFFER's STATE.  */
1730 static void
1731 save_output_state (buffer, state)
1732      const output_buffer *buffer;
1733      output_state *state;
1734 {
1735   state->prefix = buffer->prefix;
1736   state->maximum_length = buffer->maximum_length;
1737   state->ideal_maximum_length = buffer->ideal_maximum_length;
1738   state->emitted_prefix_p = buffer->emitted_prefix_p;
1739   state->prefixing_rule = buffer->prefixing_rule;
1740   state->cursor = buffer->cursor;
1741   va_copy (state->format_args, buffer->format_args);
1742 }
1743
1744 /* Restore BUFFER's previously saved STATE.  */
1745 static void
1746 restore_output_state (state, buffer)
1747      const output_state *state;
1748      output_buffer *buffer;
1749 {
1750   buffer->prefix = state->prefix;
1751   buffer->maximum_length = state->maximum_length;
1752   buffer->ideal_maximum_length = state->ideal_maximum_length;
1753   buffer->emitted_prefix_p = state->emitted_prefix_p;
1754   buffer->prefixing_rule = state->prefixing_rule;
1755   buffer->cursor = state->cursor;
1756   va_copy (buffer->format_args, state->format_args);
1757 }
1758
1759 /* Flush diagnostic_buffer content on stderr.  */
1760 static void
1761 finish_diagnostic ()
1762 {
1763   output_to_stream (diagnostic_buffer, stderr);
1764   fputc ('\n', stderr);
1765   fflush (stderr);
1766 }
1767
1768 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1769    settings needed by BUFFER for a verbatim formatting.  */
1770 static void
1771 output_do_verbatim (buffer, msg, args)
1772      output_buffer *buffer;
1773      const char *msg;
1774      va_list args;
1775 {
1776   output_state os;
1777
1778   save_output_state (buffer, &os);
1779   buffer->prefix = NULL;
1780   buffer->prefixing_rule = DIAGNOSTICS_SHOW_PREFIX_NEVER;
1781   buffer->cursor = msg;
1782   va_copy (buffer->format_args, args);
1783   output_set_maximum_length (buffer, 0);
1784   output_format (buffer);
1785   va_end (buffer->format_args);
1786   restore_output_state (&os, buffer);
1787 }
1788
1789 /* Output MESSAGE verbatim into BUFFER.  */
1790 void
1791 output_verbatim VPARAMS ((output_buffer *buffer, const char *msg, ...))
1792 {
1793 #ifndef ANSI_PROTOTYPES
1794   output_buffer *buffer;
1795   const char *msg;
1796 #endif
1797   va_list ap;
1798
1799   VA_START (ap, msg);
1800 #ifndef ANSI_PROTOTYPES
1801   buffer = va_arg (ap, output_buffer *);
1802   msg = va_arg (ap, const char *);
1803 #endif
1804   output_do_verbatim (buffer, msg, ap);
1805   va_end (ap);
1806 }
1807
1808 /* Same as above but use diagnostic_buffer.  */
1809 void
1810 verbatim VPARAMS ((const char *msg, ...))
1811 {
1812 #ifndef ANSI_PROTOTYPES
1813   const char *msg;
1814 #endif
1815   va_list ap;
1816
1817   VA_START (ap, msg);
1818 #ifndef ANSI_PROTOTYPES
1819   msg = va_arg (ap, const char *);
1820 #endif
1821   output_do_verbatim (diagnostic_buffer, msg, ap);
1822   output_to_stream (diagnostic_buffer, stderr);
1823   va_end (ap);
1824 }
1825
1826 /* Report a diagnostic MESSAGE (an error or a WARNING) involving
1827    entities in ARGUMENTS.  FILE and LINE indicate where the diagnostic
1828    occurs.  This function is *the* subroutine in terms of which front-ends
1829    should implement their specific diagnostic handling modules.
1830    The front-end independent format specifiers are exactly those described
1831    in the documentation of output_format.  */
1832 void
1833 report_diagnostic (msg, args, file, line, warn)
1834      const char *msg;
1835      va_list args;
1836      const char *file;
1837      int line;
1838      int warn;
1839 {
1840   output_state os;
1841
1842   save_output_state (diagnostic_buffer, &os);
1843   diagnostic_msg = msg;
1844   va_copy (diagnostic_args, args);
1845   if (count_error (warn))
1846     {
1847       report_error_function (file);
1848       output_set_prefix
1849         (diagnostic_buffer, context_as_prefix (file, line, warn));
1850       output_format (diagnostic_buffer);
1851       finish_diagnostic();
1852       output_destroy_prefix (diagnostic_buffer);
1853     }
1854   va_end (diagnostic_args);
1855   restore_output_state (&os, diagnostic_buffer);
1856 }