OSDN Git Service

2000-02-21 Gabriel Dos Reis <gdr@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / diagnostic.c
1 /* Top level of 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 "obstack.h"
41
42 #define obstack_chunk_alloc xmalloc
43 #define obstack_chunk_free  free
44
45 struct output_buffer
46 {
47   struct obstack obstack;       /* where we build the text to output */
48   char *prefix;                 /* prefix of every new line  */
49   int line_length;              /* current line length (in characters) */
50   int max_length;               /* maximum characters per line */
51 };
52
53 /* Prototypes. */
54 static int doing_line_wrapping PARAMS ((void));
55 static void init_output_buffer PARAMS ((struct output_buffer*, char *, int));
56 static char *get_output_prefix PARAMS ((const struct output_buffer *));
57 static int output_space_left PARAMS ((const struct output_buffer *));
58 static void emit_output_prefix PARAMS ((struct output_buffer *));
59 static void output_newline PARAMS ((struct output_buffer *));
60 static void output_append PARAMS ((struct output_buffer *, const char *,
61                                    const char *));
62 static void output_puts PARAMS ((struct output_buffer *, const char *));
63 static void dump_output PARAMS ((struct output_buffer *, FILE *));
64 static char *vbuild_message_string PARAMS ((const char *, va_list));
65 static char *build_message_string PARAMS ((const char *, ...))
66      ATTRIBUTE_PRINTF_1;
67 static char *build_location_prefix PARAMS ((const char *, int, int));
68 static void voutput_notice PARAMS ((struct output_buffer *, const char *,
69                                     va_list));
70 static void output_printf PARAMS ((struct output_buffer *, const char *, ...))
71      ATTRIBUTE_PRINTF_2;
72 static void line_wrapper_printf PARAMS ((FILE *, const char *, ...))
73      ATTRIBUTE_PRINTF_2;
74 static void vline_wrapper_message_with_location PARAMS ((const char *, int,
75                                                          int, const char *,
76                                                          va_list));
77 static void notice PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1;
78 static void v_message_with_file_and_line PARAMS ((const char *, int, int,
79                                                   const char *, va_list));
80 static void v_message_with_decl PARAMS ((tree, int, const char *, va_list));
81 static void file_and_line_for_asm PARAMS ((rtx, char **, int *));
82 static void v_error_with_file_and_line PARAMS ((const char *, int,
83                                                 const char *, va_list));
84 static void v_error_with_decl PARAMS ((tree, const char *, va_list));
85 static void v_error_for_asm PARAMS ((rtx, const char *, va_list));
86 static void verror PARAMS ((const char *, va_list));
87 static void vfatal PARAMS ((const char *, va_list)) ATTRIBUTE_NORETURN;
88 static void v_warning_with_file_and_line PARAMS ((const char *, int,
89                                                   const char *, va_list));
90 static void v_warning_with_decl PARAMS ((tree, const char *, va_list));
91 static void v_warning_for_asm PARAMS ((rtx, const char *, va_list));
92 static void vwarning PARAMS ((const char *, va_list));
93 static void vpedwarn PARAMS ((const char *, va_list));
94 static void v_pedwarn_with_decl PARAMS ((tree, const char *, va_list));
95 static void v_pedwarn_with_file_and_line PARAMS ((const char *, int,
96                                                   const char *, va_list));
97 static void vsorry PARAMS ((const char *, va_list));
98 static void report_file_and_line PARAMS ((const char *, int, int));
99 static void vnotice PARAMS ((FILE *, const char *, va_list));
100
101
102 extern int rtl_dump_and_exit;
103 extern int inhibit_warnings;
104 extern int warnings_are_errors;
105 extern int warningcount;
106 extern int errorcount;
107
108 static int need_error_newline;
109
110 /* Function of last error message;
111    more generally, function such that if next error message is in it
112    then we don't have to mention the function name.  */
113 static tree last_error_function = NULL;
114
115 /* Used to detect when input_file_stack has changed since last described.  */
116 static int last_error_tick;
117
118 /* Called by report_error_function to print out function name.
119  * Default may be overridden by language front-ends.  */
120
121 void (*print_error_function) PARAMS ((const char *)) =
122   default_print_error_function;
123
124 /* Maximum characters per line in automatic line wrapping mode.
125    Non Zero means don't wrap lines. */
126
127 static int output_maximum_width = 0;
128 \f
129 /* Predicate. Return 1 if we're in automatic line wrapping mode.  */
130
131 static int
132 doing_line_wrapping ()
133 {
134   return output_maximum_width > 0;
135 }
136
137 /* Set Maximum characters per line in automatic line wrapping mode.  */
138
139 void
140 set_message_length (n)
141      int n;
142 {
143     output_maximum_width = n;
144 }
145
146 /* Construct an output BUFFER with PREFIX and of MAX_LENGTH characters
147    per line.  */
148
149 static void
150 init_output_buffer (buffer, prefix, max_length)
151      struct output_buffer *buffer;
152      char *prefix;
153      int max_length;
154 {
155   int prefix_length = strlen (prefix);
156
157   obstack_init (&buffer->obstack);
158   buffer->prefix = prefix;
159   buffer->line_length = 0;
160   /* If the prefix is ridiculously too long, output at least
161      32 characters.  */
162   if (max_length - prefix_length < 32)
163     buffer->max_length = max_length + 32;
164   else
165     buffer->max_length = max_length;
166 }
167
168 /* Return BUFFER's prefix.  */
169
170 static char *
171 get_output_prefix (buffer)
172      const struct output_buffer *buffer;
173 {
174   return buffer->prefix;
175 }
176
177 /* Return the amount of characters BUFFER can accept to
178    make a full line.  */
179
180 static int
181 output_space_left (buffer)
182      const struct output_buffer *buffer;
183 {
184   return buffer->max_length - buffer->line_length;
185 }
186
187 /* Dump BUFFER's prefix.  */
188
189 static void
190 emit_output_prefix (buffer)
191      struct output_buffer *buffer;
192 {
193   if (buffer->prefix)
194     {
195       buffer->line_length = strlen (buffer->prefix);
196       obstack_grow (&buffer->obstack, buffer->prefix, buffer->line_length);
197     }
198 }
199
200 /* Have BUFFER start a new line.  */
201
202 static void
203 output_newline (buffer)
204      struct output_buffer *buffer;
205 {
206   obstack_1grow (&buffer->obstack, '\n');
207   buffer->line_length = 0;
208 }
209
210 /* Append a string deliminated by START and END to BUFFER.  No wrapping is
211    done.  The caller must ensure that it is safe to do so.  */
212
213 static void
214 output_append (buffer, start, end)
215      struct output_buffer *buffer;
216      const char *start;
217      const char *end;
218 {
219   int n;
220
221   /* Emit prefix and skip whitespace if we're starting a new line.  */
222   if (buffer->line_length == 0)
223     {
224       emit_output_prefix (buffer);
225       while (start != end && *start == ' ')
226         ++start;
227     }
228   n = end - start;
229   obstack_grow (&buffer->obstack, start, n);
230   buffer->line_length += n;
231 }
232
233 /* Wrap a STRing into BUFFER.  */
234
235 static void
236 output_puts (buffer, str)
237      struct output_buffer *buffer;
238      const char *str;
239 {
240   const char *p = str;
241   
242   while (*str)
243     {
244       while (*p && *p != ' ' && *p != '\n')
245         ++p;
246       
247       if (p - str < output_space_left (buffer))
248         output_append (buffer, str, p);
249       else
250         {
251           output_newline (buffer);
252           output_append (buffer, str, p);
253         }
254       
255       while (*p && *p == '\n')
256         {
257           output_newline (buffer);
258           ++p;
259         }
260
261       str = p++;
262     }
263 }
264
265 /* Dump the content of BUFFER into FILE.  */
266
267 static void
268 dump_output (buffer, file)
269      struct output_buffer *buffer;
270      FILE *file;
271 {
272   char *text;
273   
274   obstack_1grow (&buffer->obstack, '\0');
275   text = obstack_finish (&buffer->obstack);
276   fputs (text, file);
277   obstack_free (&buffer->obstack, text);
278   buffer->line_length = 0;
279 }
280
281 static char *
282 vbuild_message_string (msgid, ap)
283      const char *msgid;
284      va_list ap;
285 {
286   char *str;
287
288   vasprintf (&str, msgid, ap);
289   return str;
290 }
291
292 /*  Return a malloc'd string containing MSGID formatted a la
293     printf.  The caller is reponsible for freeing the memory.  */
294
295 static char *
296 build_message_string VPARAMS ((const char *msgid, ...))
297 {
298 #ifndef ANSI_PROTOTYPES
299   const char *msgid;
300 #endif
301   va_list ap;
302   char *str;
303
304   VA_START (ap, msgid);
305
306 #ifndef ANSI_PROTOTYPES
307   msgid = va_arg (ap, const char *);
308 #endif
309
310   str = vbuild_message_string (msgid, ap);
311
312   va_end (ap);
313
314   return str;
315 }
316
317
318 /* Return a malloc'd string describing a location.  The caller is
319    responsible for freeing the memory.  */
320
321 static char *
322 build_location_prefix (file, line, warn)
323      const char *file;
324      int line;
325      int warn;
326 {
327   if (file)
328     {
329       if (warn)
330         return build_message_string ("%s:%d: warning: ", file, line);
331       else
332         return build_message_string ("%s:%d: ", file, line);
333     }
334   else
335     {
336       if (warn)
337         return build_message_string ("%s: warning: ", progname);
338       else
339         return build_message_string ("%s: ", progname);
340     }
341 }
342
343 /* Format a MESSAGE into BUFFER.  Automatically wrap lines.  */
344
345 static void
346 voutput_notice (buffer, msgid, ap)
347      struct output_buffer *buffer;
348      const char *msgid;
349      va_list ap;
350 {
351   char *message = vbuild_message_string (msgid, ap);
352
353   output_puts (buffer, message);
354   free (message);
355 }
356
357
358 /* Format a message into BUFFER a la printf.  */
359
360 static void
361 output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
362 {
363 #ifndef ANSI_PROTOTYPES
364   struct output_buffer *buffer;
365   const char *msgid;
366 #endif
367   va_list ap;
368
369   VA_START (ap, msgid);
370
371 #ifndef ANSI_PROTOTYPES
372   buffer = va_arg (ap, struct output_buffer *);
373   msgid = va_arg (ap, const char *);
374 #endif
375
376   voutput_notice (buffer, msgid, ap);
377   va_end (ap);
378 }
379
380
381 /* Format a MESSAGE into FILE.  Do line wrapping, starting new lines
382    with PREFIX.  */
383
384 static void
385 line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...))
386 {
387 #ifndef ANSI_PROTOTYPES
388   FILE *file;
389   const char *msgid;
390 #endif
391   struct output_buffer buffer;
392   va_list ap;
393   
394   VA_START (ap, msgid);
395
396 #ifndef ANSI_PROTOTYPES
397   file = va_arg (ap, FILE *);
398   msgid = va_arg (ap, const char *);
399 #endif  
400
401   init_output_buffer (&buffer, NULL, output_maximum_width);
402   voutput_notice (&buffer, msgid, ap);
403   dump_output (&buffer, file);
404
405   va_end (ap);
406 }
407
408
409 static void
410 vline_wrapper_message_with_location (file, line, warn, msgid, ap)
411      const char *file;
412      int line;
413      int warn;
414      const char *msgid;
415      va_list ap;
416 {
417   struct output_buffer buffer;
418   
419   init_output_buffer
420     (&buffer, build_location_prefix (file, line, warn), output_maximum_width);
421   voutput_notice (&buffer, msgid, ap);
422   dump_output (&buffer, stderr);
423   free ((char*)get_output_prefix (&buffer));
424   fputc ('\n', stderr);
425 }
426
427
428 /* Print the message MSGID in FILE.  */
429
430 static void
431 vnotice (file, msgid, ap)
432      FILE *file;
433      const char *msgid;
434      va_list ap;
435 {
436   vfprintf (file, _(msgid), ap);
437 }
438
439 /* Print MSGID on stderr.  */
440
441 static void
442 notice VPARAMS ((const char *msgid, ...))
443 {
444 #ifndef ANSI_PROTOTYPES
445   char *msgid;
446 #endif
447   va_list ap;
448
449   VA_START (ap, msgid);
450
451 #ifndef ANSI_PROTOTYPES
452   msgid = va_arg (ap, char *);
453 #endif
454
455   vnotice (stderr, msgid, ap);
456   va_end (ap);
457 }
458
459 /* Report FILE and LINE (or program name), and optionally just WARN.  */
460
461 static void
462 report_file_and_line (file, line, warn)
463      const char *file;
464      int line;
465      int warn;
466 {
467   if (file)
468     fprintf (stderr, "%s:%d: ", file, line);
469   else
470     fprintf (stderr, "%s: ", progname);
471
472   if (warn)
473     notice ("warning: ");
474 }
475
476 /* Print a message relevant to line LINE of file FILE.  */
477
478 static void
479 v_message_with_file_and_line (file, line, warn, msgid, ap)
480      const char *file;
481      int line;
482      int warn;
483      const char *msgid;
484      va_list ap;
485 {
486   report_file_and_line (file, line, warn);
487   vnotice (stderr, msgid, ap);
488   fputc ('\n', stderr);
489 }
490
491 /* Print a message relevant to the given DECL.  */
492
493 static void
494 v_message_with_decl (decl, warn, msgid, ap)
495      tree decl;
496      int warn;
497      const char *msgid;
498      va_list ap;
499 {
500   const char *p;
501   struct output_buffer buffer;
502
503   if (doing_line_wrapping ())
504     init_output_buffer
505       (&buffer,
506        build_location_prefix (DECL_SOURCE_FILE (decl),
507                               DECL_SOURCE_LINE (decl), warn),
508        output_maximum_width);
509   else
510     report_file_and_line (DECL_SOURCE_FILE (decl),
511                           DECL_SOURCE_LINE (decl), warn);
512
513   /* Do magic to get around lack of varargs support for insertion
514      of arguments into existing list.  We know that the decl is first;
515      we ass_u_me that it will be printed with "%s".  */
516
517   for (p = _(msgid); *p; ++p)
518     {
519       if (*p == '%')
520         {
521           if (*(p + 1) == '%')
522             ++p;
523           else if (*(p + 1) != 's')
524             abort ();
525           else
526             break;
527         }
528     }
529
530   if (p > _(msgid))                     /* Print the left-hand substring.  */
531     {
532       if (doing_line_wrapping ())
533         output_printf (&buffer, "%.*s", (int)(p - _(msgid)), _(msgid));
534       else
535         fprintf (stderr, "%.*s", (int)(p - _(msgid)), _(msgid));
536     }
537
538   if (*p == '%')                /* Print the name.  */
539     {
540       const char *n = (DECL_NAME (decl)
541                  ? (*decl_printable_name) (decl, 2)
542                  : "((anonymous))");
543       if (doing_line_wrapping ())
544         output_puts (&buffer, n);
545       else
546         fputs (n, stderr);
547       while (*p)
548         {
549           ++p;
550           if (ISALPHA (*(p - 1) & 0xFF))
551             break;
552         }
553     }
554
555   if (*p)                       /* Print the rest of the message.  */
556     {
557       if (doing_line_wrapping ())
558         voutput_notice (&buffer, p, ap);
559       else
560         vfprintf (stderr, p, ap);
561     }
562
563   if (doing_line_wrapping())
564     {
565       dump_output (&buffer, stderr);
566       free ((char *)get_output_prefix (&buffer));
567     }
568   
569   fputc ('\n', stderr);
570 }
571
572 /* Figure file and line of the given INSN.  */
573
574 static void
575 file_and_line_for_asm (insn, pfile, pline)
576      rtx insn;
577      char **pfile;
578      int *pline;
579 {
580   rtx body = PATTERN (insn);
581   rtx asmop;
582
583   /* Find the (or one of the) ASM_OPERANDS in the insn.  */
584   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
585     asmop = SET_SRC (body);
586   else if (GET_CODE (body) == ASM_OPERANDS)
587     asmop = body;
588   else if (GET_CODE (body) == PARALLEL
589            && GET_CODE (XVECEXP (body, 0, 0)) == SET)
590     asmop = SET_SRC (XVECEXP (body, 0, 0));
591   else if (GET_CODE (body) == PARALLEL
592            && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
593     asmop = XVECEXP (body, 0, 0);
594   else
595     asmop = NULL;
596
597   if (asmop)
598     {
599       *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
600       *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
601     }
602   else
603     {
604       *pfile = input_filename;
605       *pline = lineno;
606     }
607 }
608
609 /* Report an error at line LINE of file FILE.  */
610
611 static void
612 v_error_with_file_and_line (file, line, msgid, ap)
613      const char *file;
614      int line;
615      const char *msgid;
616      va_list ap;
617 {
618   count_error (0);
619   report_error_function (file);
620   if (doing_line_wrapping ())
621     vline_wrapper_message_with_location (file, line, 0, msgid, ap);
622   else
623     v_message_with_file_and_line (file, line, 0, msgid, ap);
624 }
625
626 /* Report an error at the declaration DECL.
627    MSGID is a format string which uses %s to substitute the declaration
628    name; subsequent substitutions are a la printf.  */
629
630 static void
631 v_error_with_decl (decl, msgid, ap)
632      tree decl;
633      const char *msgid;
634      va_list ap;
635 {
636   count_error (0);
637   report_error_function (DECL_SOURCE_FILE (decl));
638   v_message_with_decl (decl, 0, msgid, ap);
639 }
640
641
642 /* Report an error at the line number of the insn INSN.
643    This is used only when INSN is an `asm' with operands,
644    and each ASM_OPERANDS records its own source file and line.  */
645
646 static void
647 v_error_for_asm (insn, msgid, ap)
648      rtx insn;
649      const char *msgid;
650      va_list ap;
651 {
652   char *file;
653   int line;
654
655   count_error (0);
656   file_and_line_for_asm (insn, &file, &line);
657   report_error_function (file);
658   v_message_with_file_and_line (file, line, 0, msgid, ap);
659 }
660
661
662 /* Report an error at the current line number.  */
663
664 static void
665 verror (msgid, ap)
666      const char *msgid;
667      va_list ap;
668 {
669   v_error_with_file_and_line (input_filename, lineno, msgid, ap);
670 }
671
672
673 /* Report a fatal error at the current line number.  Allow a front end to
674    intercept the message.  */
675
676 static void (*fatal_function) PARAMS ((const char *, va_list));
677
678 static void
679 vfatal (msgid, ap)
680      const char *msgid;
681      va_list ap;
682 {
683    if (fatal_function != 0)
684      (*fatal_function) (_(msgid), ap);
685
686   verror (msgid, ap);
687   exit (FATAL_EXIT_CODE);
688 }
689
690 /* Report a warning at line LINE of file FILE.  */
691
692 static void
693 v_warning_with_file_and_line (file, line, msgid, ap)
694      const char *file;
695      int line;
696      const char *msgid;
697      va_list ap;
698 {
699   if (count_error (1))
700     {
701       report_error_function (file);
702       if (doing_line_wrapping ())
703         vline_wrapper_message_with_location (file, line, 1, msgid, ap);
704       else
705         v_message_with_file_and_line (file, line, 1, msgid, ap);
706     }
707 }
708
709
710 /* Report a warning at the declaration DECL.
711    MSGID is a format string which uses %s to substitute the declaration
712    name; subsequent substitutions are a la printf.  */
713
714 static void
715 v_warning_with_decl (decl, msgid, ap)
716      tree decl;
717      const char *msgid;
718      va_list ap;
719 {
720   if (count_error (1))
721     {
722       report_error_function (DECL_SOURCE_FILE (decl));
723       v_message_with_decl (decl, 1, msgid, ap);
724     }
725 }
726
727
728 /* Report a warning at the line number of the insn INSN.
729    This is used only when INSN is an `asm' with operands,
730    and each ASM_OPERANDS records its own source file and line.  */
731
732 static void
733 v_warning_for_asm (insn, msgid, ap)
734      rtx insn;
735      const char *msgid;
736      va_list ap;
737 {
738   if (count_error (1))
739     {
740       char *file;
741       int line;
742
743       file_and_line_for_asm (insn, &file, &line);
744       report_error_function (file);
745       v_message_with_file_and_line (file, line, 1, msgid, ap);
746     }
747 }
748
749
750 /* Report a warning at the current line number.  */
751
752 static void
753 vwarning (msgid, ap)
754      const char *msgid;
755      va_list ap;
756 {
757   v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
758 }
759
760 /* These functions issue either warnings or errors depending on
761    -pedantic-errors.  */
762
763 static void
764 vpedwarn (msgid, ap)
765      const char *msgid;
766      va_list ap;
767 {
768   if (flag_pedantic_errors)
769     verror (msgid, ap);
770   else
771     vwarning (msgid, ap);
772 }
773
774
775 static void
776 v_pedwarn_with_decl (decl, msgid, ap)
777      tree decl;
778      const char *msgid;
779      va_list ap;
780 {
781   /* We don't want -pedantic-errors to cause the compilation to fail from
782      "errors" in system header files.  Sometimes fixincludes can't fix what's
783      broken (eg: unsigned char bitfields - fixing it may change the alignment
784      which will cause programs to mysteriously fail because the C library
785      or kernel uses the original layout).  There's no point in issuing a
786      warning either, it's just unnecessary noise.  */
787
788   if (! DECL_IN_SYSTEM_HEADER (decl))
789     {
790       if (flag_pedantic_errors)
791         v_error_with_decl (decl, msgid, ap);
792       else
793         v_warning_with_decl (decl, msgid, ap);
794     }
795 }
796
797
798 static void
799 v_pedwarn_with_file_and_line (file, line, msgid, ap)
800      const char *file;
801      int line;
802      const char *msgid;
803      va_list ap;
804 {
805   if (flag_pedantic_errors)
806     v_error_with_file_and_line (file, line, msgid, ap);
807   else
808     v_warning_with_file_and_line (file, line, msgid, ap);
809 }
810
811
812 /* Apologize for not implementing some feature.  */
813
814 static void
815 vsorry (msgid, ap)
816      const char *msgid;
817      va_list ap;
818 {
819   sorrycount++;
820   if (input_filename)
821     fprintf (stderr, "%s:%d: ", input_filename, lineno);
822   else
823     fprintf (stderr, "%s: ", progname);
824   notice ("sorry, not implemented: ");
825   vnotice (stderr, msgid, ap);
826   fputc ('\n', stderr);
827 }
828
829 \f
830 /* Count an error or warning.  Return 1 if the message should be printed.  */
831
832 int
833 count_error (warningp)
834      int warningp;
835 {
836   if (warningp && inhibit_warnings)
837     return 0;
838
839   if (warningp && !warnings_are_errors)
840     warningcount++;
841   else
842     {
843       static int warning_message = 0;
844
845       if (warningp && !warning_message)
846         {
847           notice ("%s: warnings being treated as errors\n", progname);
848           warning_message = 1;
849         }
850       errorcount++;
851     }
852
853   return 1;
854 }
855
856 /* Print a diagnistic MSGID on FILE.  */
857 void
858 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
859 {
860 #ifndef ANSI_PROTOTYPES
861   FILE *file;
862   const char *msgid;
863 #endif
864   va_list ap;
865
866   VA_START (ap, msgid);
867
868 #ifndef ANSI_PROTOTYPES
869   file = va_arg (ap, FILE *);
870   msgid = va_arg (ap, const char *);
871 #endif
872
873   vnotice (file, msgid, ap);
874   va_end (ap);
875 }
876
877
878 /* Print a fatal error message.  NAME is the text.
879    Also include a system error message based on `errno'.  */
880
881 void
882 pfatal_with_name (name)
883   const char *name;
884 {
885   fprintf (stderr, "%s: ", progname);
886   perror (name);
887   exit (FATAL_EXIT_CODE);
888 }
889
890 void
891 fatal_io_error (name)
892   const char *name;
893 {
894   notice ("%s: %s: I/O error\n", progname, name);
895   exit (FATAL_EXIT_CODE);
896 }
897
898 /* Issue a pedantic warning MSGID.  */
899 void
900 pedwarn VPARAMS ((const char *msgid, ...))
901 {
902 #ifndef ANSI_PROTOTYPES
903   const char *msgid;
904 #endif
905   va_list ap;
906
907   VA_START (ap, msgid);
908
909 #ifndef ANSI_PROTOTYPES
910   msgid = va_arg (ap, const char *);
911 #endif
912
913   vpedwarn (msgid, ap);
914   va_end (ap);
915 }
916
917 /* Issue a pedantic waring about DECL.  */
918 void
919 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
920 {
921 #ifndef ANSI_PROTOTYPES
922   tree decl;
923   const char *msgid;
924 #endif
925   va_list ap;
926
927   VA_START (ap, msgid);
928
929 #ifndef ANSI_PROTOTYPES
930   decl = va_arg (ap, tree);
931   msgid = va_arg (ap, const char *);
932 #endif
933
934   v_pedwarn_with_decl (decl, msgid, ap);
935   va_end (ap);
936 }
937
938 /* Same as above but within the context FILE and LINE. */
939 void
940 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
941                                      const char *msgid, ...))
942 {
943 #ifndef ANSI_PROTOTYPES
944   const char *file;
945   int line;
946   const char *msgid;
947 #endif
948   va_list ap;
949
950   VA_START (ap, msgid);
951
952 #ifndef ANSI_PROTOTYPES
953   file = va_arg (ap, const char *);
954   line = va_arg (ap, int);
955   msgid = va_arg (ap, const char *);
956 #endif
957
958   v_pedwarn_with_file_and_line (file, line, msgid, ap);
959   va_end (ap);
960 }
961
962 /* Just apologize with MSGID.  */
963 void
964 sorry VPARAMS ((const char *msgid, ...))
965 {
966 #ifndef ANSI_PROTOTYPES
967   const char *msgid;
968 #endif
969   va_list ap;
970
971   VA_START (ap, msgid);
972
973 #ifndef ANSI_PROTOTYPES
974   msgid = va_arg (ap, const char *);
975 #endif
976
977   vsorry (msgid, ap);
978   va_end (ap);
979 }
980
981 /* Called when the start of a function definition is parsed,
982    this function prints on stderr the name of the function.  */
983
984 void
985 announce_function (decl)
986      tree decl;
987 {
988   if (! quiet_flag)
989     {
990       if (rtl_dump_and_exit)
991         fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
992       else
993         {
994           if (doing_line_wrapping ())
995             line_wrapper_printf
996               (stderr, " %s", (*decl_printable_name) (decl, 2));
997           else
998             fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
999         }
1000       fflush (stderr);
1001       need_error_newline = 1;
1002       last_error_function = current_function_decl;
1003     }
1004 }
1005
1006 /* The default function to print out name of current function that caused
1007    an error.  */
1008
1009 void
1010 default_print_error_function (file)
1011   const char *file;
1012 {
1013   if (last_error_function != current_function_decl)
1014     {
1015       char *prefix = NULL;
1016       struct output_buffer buffer;
1017       
1018       if (file)
1019         prefix = build_message_string ("%s: ", file);
1020
1021       if (doing_line_wrapping ())
1022         init_output_buffer (&buffer, prefix, output_maximum_width);
1023       else
1024         {
1025           if (file)
1026             fprintf (stderr, "%s: ", file);
1027         }
1028       
1029       if (current_function_decl == NULL)
1030         {
1031           if (doing_line_wrapping ())
1032             output_printf (&buffer, "At top level:\n");
1033           else
1034             notice ("At top level:\n");
1035         }
1036       else
1037         {
1038           if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1039             {
1040               if (doing_line_wrapping ())
1041                 output_printf
1042                   (&buffer, "In method `%s':\n",
1043                    (*decl_printable_name) (current_function_decl, 2));
1044               else
1045                 notice ("In method `%s':\n",
1046                         (*decl_printable_name) (current_function_decl, 2));
1047             }
1048           else
1049             {
1050               if (doing_line_wrapping ())
1051                 output_printf
1052                   (&buffer, "In function `%s':\n",
1053                    (*decl_printable_name) (current_function_decl, 2));
1054               else
1055                 notice ("In function `%s':\n",
1056                         (*decl_printable_name) (current_function_decl, 2));
1057             }
1058         }
1059
1060       last_error_function = current_function_decl;
1061
1062       if (doing_line_wrapping ())
1063         dump_output (&buffer, stderr);
1064       
1065       free (prefix);
1066     }
1067 }
1068
1069 /* Prints out, if necessary, the name of the current function
1070   that caused an error.  Called from all error and warning functions.
1071   We ignore the FILE parameter, as it cannot be relied upon.  */
1072
1073 void
1074 report_error_function (file)
1075   const char *file ATTRIBUTE_UNUSED;
1076 {
1077   struct file_stack *p;
1078
1079   if (need_error_newline)
1080     {
1081       fprintf (stderr, "\n");
1082       need_error_newline = 0;
1083     }
1084
1085   if (input_file_stack && input_file_stack->next != 0
1086       && input_file_stack_tick != last_error_tick)
1087     {
1088       for (p = input_file_stack->next; p; p = p->next)
1089         if (p == input_file_stack->next)
1090           notice ("In file included from %s:%d", p->name, p->line);
1091         else
1092           notice (",\n                 from %s:%d", p->name, p->line);
1093       fprintf (stderr, ":\n");
1094       last_error_tick = input_file_stack_tick;
1095     }
1096
1097   (*print_error_function) (input_filename);
1098 }
1099
1100 void
1101 error_with_file_and_line VPARAMS ((const char *file, int line,
1102                                    const char *msgid, ...))
1103 {
1104 #ifndef ANSI_PROTOTYPES
1105   const char *file;
1106   int line;
1107   const char *msgid;
1108 #endif
1109   va_list ap;
1110
1111   VA_START (ap, msgid);
1112
1113 #ifndef ANSI_PROTOTYPES
1114   file = va_arg (ap, const char *);
1115   line = va_arg (ap, int);
1116   msgid = va_arg (ap, const char *);
1117 #endif
1118
1119   v_error_with_file_and_line (file, line, msgid, ap);
1120   va_end (ap);
1121 }
1122
1123 void
1124 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1125 {
1126 #ifndef ANSI_PROTOTYPES
1127   tree decl;
1128   const char *msgid;
1129 #endif
1130   va_list ap;
1131
1132   VA_START (ap, msgid);
1133
1134 #ifndef ANSI_PROTOTYPES
1135   decl = va_arg (ap, tree);
1136   msgid = va_arg (ap, const char *);
1137 #endif
1138
1139   v_error_with_decl (decl, msgid, ap);
1140   va_end (ap);
1141 }
1142
1143 void
1144 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1145 {
1146 #ifndef ANSI_PROTOTYPES
1147   rtx insn;
1148   const char *msgid;
1149 #endif
1150   va_list ap;
1151
1152   VA_START (ap, msgid);
1153
1154 #ifndef ANSI_PROTOTYPES
1155   insn = va_arg (ap, rtx);
1156   msgid = va_arg (ap, const char *);
1157 #endif
1158
1159   v_error_for_asm (insn, msgid, ap);
1160   va_end (ap);
1161 }
1162
1163 void
1164 error VPARAMS ((const char *msgid, ...))
1165 {
1166 #ifndef ANSI_PROTOTYPES
1167   const char *msgid;
1168 #endif
1169   va_list ap;
1170
1171   VA_START (ap, msgid);
1172
1173 #ifndef ANSI_PROTOTYPES
1174   msgid = va_arg (ap, const char *);
1175 #endif
1176
1177   verror (msgid, ap);
1178   va_end (ap);
1179 }
1180
1181 /* Set the function to call when a fatal error occurs.  */
1182
1183 void
1184 set_fatal_function (f)
1185      void (*f) PARAMS ((const char *, va_list));
1186 {
1187   fatal_function = f;
1188 }
1189
1190 void
1191 fatal VPARAMS ((const char *msgid, ...))
1192 {
1193 #ifndef ANSI_PROTOTYPES
1194   const char *msgid;
1195 #endif
1196   va_list ap;
1197
1198   VA_START (ap, msgid);
1199
1200 #ifndef ANSI_PROTOTYPES
1201   msgid = va_arg (ap, const char *);
1202 #endif
1203
1204   vfatal (msgid, ap);
1205   va_end (ap);
1206 }
1207
1208 void
1209 _fatal_insn (msgid, insn, file, line, function)
1210      const char *msgid;
1211      rtx insn;
1212      const char *file;
1213      int line;
1214      const char *function;
1215 {
1216   error ("%s", msgid);
1217   debug_rtx (insn);
1218   fancy_abort (file, line, function);
1219 }
1220
1221 void
1222 _fatal_insn_not_found (insn, file, line, function)
1223      rtx insn;
1224      const char *file;
1225      int line;
1226      const char *function;
1227 {
1228   if (INSN_CODE (insn) < 0)
1229     _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1230   else
1231     _fatal_insn ("Insn does not satisfy its constraints:",
1232                 insn, file, line, function);
1233 }
1234
1235 void
1236 warning_with_file_and_line VPARAMS ((const char *file, int line,
1237                                      const char *msgid, ...))
1238 {
1239 #ifndef ANSI_PROTOTYPES
1240   const char *file;
1241   int line;
1242   const char *msgid;
1243 #endif
1244   va_list ap;
1245
1246   VA_START (ap, msgid);
1247
1248 #ifndef ANSI_PROTOTYPES
1249   file = va_arg (ap, const char *);
1250   line = va_arg (ap, int);
1251   msgid = va_arg (ap, const char *);
1252 #endif
1253
1254   v_warning_with_file_and_line (file, line, msgid, ap);
1255   va_end (ap);
1256 }
1257
1258 void
1259 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1260 {
1261 #ifndef ANSI_PROTOTYPES
1262   tree decl;
1263   const char *msgid;
1264 #endif
1265   va_list ap;
1266
1267   VA_START (ap, msgid);
1268
1269 #ifndef ANSI_PROTOTYPES
1270   decl = va_arg (ap, tree);
1271   msgid = va_arg (ap, const char *);
1272 #endif
1273
1274   v_warning_with_decl (decl, msgid, ap);
1275   va_end (ap);
1276 }
1277
1278 void
1279 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1280 {
1281 #ifndef ANSI_PROTOTYPES
1282   rtx insn;
1283   const char *msgid;
1284 #endif
1285   va_list ap;
1286
1287   VA_START (ap, msgid);
1288
1289 #ifndef ANSI_PROTOTYPES
1290   insn = va_arg (ap, rtx);
1291   msgid = va_arg (ap, const char *);
1292 #endif
1293
1294   v_warning_for_asm (insn, msgid, ap);
1295   va_end (ap);
1296 }
1297
1298 void
1299 warning VPARAMS ((const char *msgid, ...))
1300 {
1301 #ifndef ANSI_PROTOTYPES
1302   const char *msgid;
1303 #endif
1304   va_list ap;
1305
1306   VA_START (ap, msgid);
1307
1308 #ifndef ANSI_PROTOTYPES
1309   msgid = va_arg (ap, const char *);
1310 #endif
1311
1312   vwarning (msgid, ap);
1313   va_end (ap);
1314 }
1315