2 Copyright (C) 2000-2014 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Niels Kristian Bech Jensen
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* Handle the inevitable errors. A major catch here is that things
22 flagged as errors in one match subroutine can conceivably be legal
23 elsewhere. This means that error messages are recorded and saved
24 for possible use later. If a line does not match a legal
25 construction, then the saved error message is reported. */
29 #include "coretypes.h"
37 #ifdef GWINSZ_IN_SYS_IOCTL
38 # include <sys/ioctl.h>
41 #include "diagnostic.h"
42 #include "diagnostic-color.h"
43 #include "tree-diagnostic.h" /* tree_diagnostics_defaults */
45 static int suppress_errors
= 0;
47 static int warnings_not_errors
= 0;
49 static int terminal_width
, buffer_flag
, errors
, warnings
;
51 static gfc_error_buf error_buffer
, warning_buffer
, *cur_error_buffer
;
54 /* Go one level deeper suppressing errors. */
57 gfc_push_suppress_errors (void)
59 gcc_assert (suppress_errors
>= 0);
64 /* Leave one level of error suppressing. */
67 gfc_pop_suppress_errors (void)
69 gcc_assert (suppress_errors
> 0);
74 /* Determine terminal width (for trimming source lines in output). */
77 get_terminal_width (void)
79 /* Only limit the width if we're outputting to a terminal. */
81 if (!isatty (STDERR_FILENO
))
85 /* Method #1: Use ioctl (not available on all systems). */
89 if (ioctl (0, TIOCGWINSZ
, &w
) == 0 && w
.ws_col
> 0)
93 /* Method #2: Query environment variable $COLUMNS. */
94 const char *p
= getenv ("COLUMNS");
102 /* If both fail, use reasonable default. */
107 /* Per-file error initialization. */
110 gfc_error_init_1 (void)
112 terminal_width
= get_terminal_width ();
119 /* Set the flag for buffering errors or not. */
122 gfc_buffer_error (int flag
)
128 /* Add a single character to the error buffer or output depending on
136 if (cur_error_buffer
->index
>= cur_error_buffer
->allocated
)
138 cur_error_buffer
->allocated
= cur_error_buffer
->allocated
139 ? cur_error_buffer
->allocated
* 2 : 1000;
140 cur_error_buffer
->message
= XRESIZEVEC (char, cur_error_buffer
->message
,
141 cur_error_buffer
->allocated
);
143 cur_error_buffer
->message
[cur_error_buffer
->index
++] = c
;
149 /* We build up complete lines before handing things
150 over to the library in order to speed up error printing. */
152 static size_t allocated
= 0, index
= 0;
154 if (index
+ 1 >= allocated
)
156 allocated
= allocated
? allocated
* 2 : 1000;
157 line
= XRESIZEVEC (char, line
, allocated
);
163 fputs (line
, stderr
);
171 /* Copy a string to wherever it needs to go. */
174 error_string (const char *p
)
181 /* Print a formatted integer to the error buffer or output. */
186 error_uinteger (unsigned long int i
)
188 char *p
, int_buf
[IBUF_LEN
];
190 p
= int_buf
+ IBUF_LEN
- 1;
202 error_string (p
+ 1);
206 error_integer (long int i
)
212 u
= (unsigned long int) -i
;
223 gfc_widechar_display_length (gfc_char_t c
)
225 if (gfc_wide_is_printable (c
) || c
== '\t')
226 /* Printable ASCII character, or tabulation (output as a space). */
228 else if (c
< ((gfc_char_t
) 1 << 8))
229 /* Displayed as \x?? */
231 else if (c
< ((gfc_char_t
) 1 << 16))
232 /* Displayed as \u???? */
235 /* Displayed as \U???????? */
240 /* Length of the ASCII representation of the wide string, escaping wide
241 characters as print_wide_char_into_buffer() does. */
244 gfc_wide_display_length (const gfc_char_t
*str
)
248 for (i
= 0, len
= 0; str
[i
]; i
++)
249 len
+= gfc_widechar_display_length (str
[i
]);
255 print_wide_char_into_buffer (gfc_char_t c
, char *buf
)
257 static const char xdigit
[16] = { '0', '1', '2', '3', '4', '5', '6',
258 '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
260 if (gfc_wide_is_printable (c
) || c
== '\t')
263 /* Tabulation is output as a space. */
264 buf
[0] = (unsigned char) (c
== '\t' ? ' ' : c
);
267 else if (c
< ((gfc_char_t
) 1 << 8))
270 buf
[3] = xdigit
[c
& 0x0F];
272 buf
[2] = xdigit
[c
& 0x0F];
278 else if (c
< ((gfc_char_t
) 1 << 16))
281 buf
[5] = xdigit
[c
& 0x0F];
283 buf
[4] = xdigit
[c
& 0x0F];
285 buf
[3] = xdigit
[c
& 0x0F];
287 buf
[2] = xdigit
[c
& 0x0F];
296 buf
[9] = xdigit
[c
& 0x0F];
298 buf
[8] = xdigit
[c
& 0x0F];
300 buf
[7] = xdigit
[c
& 0x0F];
302 buf
[6] = xdigit
[c
& 0x0F];
304 buf
[5] = xdigit
[c
& 0x0F];
306 buf
[4] = xdigit
[c
& 0x0F];
308 buf
[3] = xdigit
[c
& 0x0F];
310 buf
[2] = xdigit
[c
& 0x0F];
318 static char wide_char_print_buffer
[11];
321 gfc_print_wide_char (gfc_char_t c
)
323 print_wide_char_into_buffer (c
, wide_char_print_buffer
);
324 return wide_char_print_buffer
;
328 /* Show the file, where it was included, and the source line, give a
329 locus. Calls error_printf() recursively, but the recursion is at
330 most one level deep. */
332 static void error_printf (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
335 show_locus (locus
*loc
, int c1
, int c2
)
342 /* TODO: Either limit the total length and number of included files
343 displayed or add buffering of arbitrary number of characters in
346 /* Write out the error header line, giving the source file and error
347 location (in GNU standard "[file]:[line].[column]:" format),
348 followed by an "included by" stack and a blank line. This header
349 format is matched by a testsuite parser defined in
350 lib/gfortran-dg.exp. */
355 error_string (f
->filename
);
358 error_integer (LOCATION_LINE (lb
->location
));
360 if ((c1
> 0) || (c2
> 0))
366 if ((c1
> 0) && (c2
> 0))
377 i
= f
->inclusion_line
;
380 if (f
== NULL
) break;
382 error_printf (" Included at %s:%d:", f
->filename
, i
);
387 /* Calculate an appropriate horizontal offset of the source line in
388 order to get the error locus within the visible portion of the
389 line. Note that if the margin of 5 here is changed, the
390 corresponding margin of 10 in show_loci should be changed. */
394 /* If the two loci would appear in the same column, we shift
395 '2' one column to the right, so as to print '12' rather than
396 just '1'. We do this here so it will be accounted for in the
397 margin calculations. */
402 cmax
= (c1
< c2
) ? c2
: c1
;
403 if (cmax
> terminal_width
- 5)
404 offset
= cmax
- terminal_width
+ 5;
406 /* Show the line itself, taking care not to print more than what can
407 show up on the terminal. Tabs are converted to spaces, and
408 nonprintable characters are converted to a "\xNN" sequence. */
410 p
= &(lb
->line
[offset
]);
411 i
= gfc_wide_display_length (p
);
412 if (i
> terminal_width
)
413 i
= terminal_width
- 1;
417 static char buffer
[11];
418 i
-= print_wide_char_into_buffer (*p
++, buffer
);
419 error_string (buffer
);
424 /* Show the '1' and/or '2' corresponding to the column of the error
425 locus. Note that a value of -1 for c1 or c2 will simply cause
426 the relevant number not to be printed. */
432 p
= &(lb
->line
[offset
]);
433 for (i
= 0; i
< cmax
; i
++)
436 spaces
= gfc_widechar_display_length (*p
++);
439 error_char ('1'), spaces
--;
441 error_char ('2'), spaces
--;
443 for (j
= 0; j
< spaces
; j
++)
457 /* As part of printing an error, we show the source lines that caused
458 the problem. We show at least one, and possibly two loci; the two
459 loci may or may not be on the same source line. */
462 show_loci (locus
*l1
, locus
*l2
)
466 if (l1
== NULL
|| l1
->lb
== NULL
)
468 error_printf ("<During initialization>\n");
472 /* While calculating parameters for printing the loci, we consider possible
473 reasons for printing one per line. If appropriate, print the loci
474 individually; otherwise we print them both on the same line. */
476 c1
= l1
->nextc
- l1
->lb
->line
;
479 show_locus (l1
, c1
, -1);
483 c2
= l2
->nextc
- l2
->lb
->line
;
490 /* Note that the margin value of 10 here needs to be less than the
491 margin of 5 used in the calculation of offset in show_locus. */
493 if (l1
->lb
!= l2
->lb
|| m
> terminal_width
- 10)
495 show_locus (l1
, c1
, -1);
496 show_locus (l2
, -1, c2
);
500 show_locus (l1
, c1
, c2
);
506 /* Workhorse for the error printing subroutines. This subroutine is
507 inspired by g77's error handling and is similar to printf() with
508 the following %-codes:
510 %c Character, %d or %i Integer, %s String, %% Percent
511 %L Takes locus argument
512 %C Current locus (no argument)
514 If a locus pointer is given, the actual source line is printed out
515 and the column is indicated. Since we want the error message at
516 the bottom of any source file information, we must scan the
517 argument list twice -- once to determine whether the loci are
518 present and record this for printing, and once to print the error
519 message after and loci have been printed. A maximum of two locus
520 arguments are permitted.
522 This function is also called (recursively) by show_locus in the
523 case of included files; however, as show_locus does not resupply
524 any loci, the recursion is at most one level deep. */
528 static void ATTRIBUTE_GCC_GFC(2,0)
529 error_print (const char *type
, const char *format0
, va_list argp
)
531 enum { TYPE_CURRENTLOC
, TYPE_LOCUS
, TYPE_INTEGER
, TYPE_UINTEGER
,
532 TYPE_LONGINT
, TYPE_ULONGINT
, TYPE_CHAR
, TYPE_STRING
,
541 unsigned int uintval
;
543 unsigned long int ulongintval
;
545 const char * stringval
;
547 } arg
[MAX_ARGS
], spec
[MAX_ARGS
];
548 /* spec is the array of specifiers, in the same order as they
549 appear in the format string. arg is the array of arguments,
550 in the same order as they appear in the va_list. */
553 int i
, n
, have_l1
, pos
, maxpos
;
554 locus
*l1
, *l2
, *loc
;
557 loc
= l1
= l2
= NULL
;
566 for (i
= 0; i
< MAX_ARGS
; i
++)
568 arg
[i
].type
= NOTYPE
;
572 /* First parse the format string for position specifiers. */
585 if (ISDIGIT (*format
))
587 /* This is a position specifier. For example, the number
588 12 in the format string "%12$d", which specifies the third
589 argument of the va_list, formatted in %d format.
590 For details, see "man 3 printf". */
591 pos
= atoi(format
) - 1;
592 gcc_assert (pos
>= 0);
593 while (ISDIGIT(*format
))
595 gcc_assert (*format
== '$');
609 arg
[pos
].type
= TYPE_CURRENTLOC
;
613 arg
[pos
].type
= TYPE_LOCUS
;
618 arg
[pos
].type
= TYPE_INTEGER
;
622 arg
[pos
].type
= TYPE_UINTEGER
;
628 arg
[pos
].type
= TYPE_ULONGINT
;
629 else if (c
== 'i' || c
== 'd')
630 arg
[pos
].type
= TYPE_LONGINT
;
636 arg
[pos
].type
= TYPE_CHAR
;
640 arg
[pos
].type
= TYPE_STRING
;
650 /* Then convert the values for each %-style argument. */
651 for (pos
= 0; pos
<= maxpos
; pos
++)
653 gcc_assert (arg
[pos
].type
!= NOTYPE
);
654 switch (arg
[pos
].type
)
656 case TYPE_CURRENTLOC
:
657 loc
= &gfc_current_locus
;
661 if (arg
[pos
].type
== TYPE_LOCUS
)
662 loc
= va_arg (argp
, locus
*);
667 arg
[pos
].u
.stringval
= "(2)";
673 arg
[pos
].u
.stringval
= "(1)";
678 arg
[pos
].u
.intval
= va_arg (argp
, int);
682 arg
[pos
].u
.uintval
= va_arg (argp
, unsigned int);
686 arg
[pos
].u
.longintval
= va_arg (argp
, long int);
690 arg
[pos
].u
.ulongintval
= va_arg (argp
, unsigned long int);
694 arg
[pos
].u
.charval
= (char) va_arg (argp
, int);
698 arg
[pos
].u
.stringval
= (const char *) va_arg (argp
, char *);
706 for (n
= 0; spec
[n
].pos
>= 0; n
++)
707 spec
[n
].u
= arg
[spec
[n
].pos
].u
;
709 /* Show the current loci if we have to. */
723 for (; *format
; format
++)
727 error_char (*format
);
732 if (ISDIGIT (*format
))
734 /* This is a position specifier. See comment above. */
735 while (ISDIGIT (*format
))
738 /* Skip over the dollar sign. */
749 error_char (spec
[n
++].u
.charval
);
753 case 'C': /* Current locus */
754 case 'L': /* Specified locus */
755 error_string (spec
[n
++].u
.stringval
);
760 error_integer (spec
[n
++].u
.intval
);
764 error_uinteger (spec
[n
++].u
.uintval
);
770 error_uinteger (spec
[n
++].u
.ulongintval
);
772 error_integer (spec
[n
++].u
.longintval
);
782 /* Wrapper for error_print(). */
785 error_printf (const char *gmsgid
, ...)
789 va_start (argp
, gmsgid
);
790 error_print ("", _(gmsgid
), argp
);
795 /* Increment the number of errors, and check whether too many have
799 gfc_increment_error_count (void)
802 if ((gfc_option
.max_errors
!= 0) && (errors
>= gfc_option
.max_errors
))
803 gfc_fatal_error ("Error count reached limit of %d.", gfc_option
.max_errors
);
807 /* Issue a warning. */
810 gfc_warning (const char *gmsgid
, ...)
814 if (inhibit_warnings
)
817 warning_buffer
.flag
= 1;
818 warning_buffer
.index
= 0;
819 cur_error_buffer
= &warning_buffer
;
821 va_start (argp
, gmsgid
);
822 error_print (_("Warning:"), _(gmsgid
), argp
);
827 if (buffer_flag
== 0)
830 if (warnings_are_errors
)
831 gfc_increment_error_count();
836 /* Whether, for a feature included in a given standard set (GFC_STD_*),
837 we should issue an error or a warning, or be quiet. */
840 gfc_notification_std (int std
)
844 warning
= ((gfc_option
.warn_std
& std
) != 0) && !inhibit_warnings
;
845 if ((gfc_option
.allow_std
& std
) != 0 && !warning
)
848 return warning
? WARNING
: ERROR
;
852 /* Possibly issue a warning/error about use of a nonstandard (or deleted)
853 feature. An error/warning will be issued if the currently selected
854 standard does not contain the requested bits. Return false if
855 an error is generated. */
858 gfc_notify_std (int std
, const char *gmsgid
, ...)
862 const char *msg1
, *msg2
;
865 warning
= ((gfc_option
.warn_std
& std
) != 0) && !inhibit_warnings
;
866 if ((gfc_option
.allow_std
& std
) != 0 && !warning
)
870 return warning
? true : false;
872 cur_error_buffer
= warning
? &warning_buffer
: &error_buffer
;
873 cur_error_buffer
->flag
= 1;
874 cur_error_buffer
->index
= 0;
877 msg1
= _("Warning:");
883 case GFC_STD_F2008_TS
:
884 msg2
= "TS 29113/TS 18508:";
886 case GFC_STD_F2008_OBS
:
887 msg2
= _("Fortran 2008 obsolescent feature:");
890 msg2
= "Fortran 2008:";
893 msg2
= "Fortran 2003:";
896 msg2
= _("GNU Extension:");
899 msg2
= _("Legacy Extension:");
901 case GFC_STD_F95_OBS
:
902 msg2
= _("Obsolescent feature:");
904 case GFC_STD_F95_DEL
:
905 msg2
= _("Deleted feature:");
911 buffer
= (char *) alloca (strlen (msg1
) + strlen (msg2
) + 2);
912 strcpy (buffer
, msg1
);
913 strcat (buffer
, " ");
914 strcat (buffer
, msg2
);
916 va_start (argp
, gmsgid
);
917 error_print (buffer
, _(gmsgid
), argp
);
922 if (buffer_flag
== 0)
924 if (warning
&& !warnings_are_errors
)
927 gfc_increment_error_count();
928 cur_error_buffer
->flag
= 0;
931 return (warning
&& !warnings_are_errors
) ? true : false;
935 /* Immediate warning (i.e. do not buffer the warning). */
936 /* Use gfc_warning_now_2 instead, unless gmsgid contains a %L. */
939 gfc_warning_now (const char *gmsgid
, ...)
944 if (inhibit_warnings
)
951 va_start (argp
, gmsgid
);
952 error_print (_("Warning:"), _(gmsgid
), argp
);
957 if (warnings_are_errors
)
958 gfc_increment_error_count();
963 /* Called from output_format -- during diagnostic message processing
964 to handle Fortran specific format specifiers with the following meanings:
966 %C Current locus (no argument)
969 gfc_format_decoder (pretty_printer
*pp
,
970 text_info
*text
, const char *spec
,
971 int precision ATTRIBUTE_UNUSED
, bool wide ATTRIBUTE_UNUSED
,
972 bool plus ATTRIBUTE_UNUSED
, bool hash ATTRIBUTE_UNUSED
)
978 static const char *result
= "(1)";
979 gcc_assert (gfc_current_locus
.nextc
- gfc_current_locus
.lb
->line
>= 0);
980 unsigned int c1
= gfc_current_locus
.nextc
- gfc_current_locus
.lb
->line
;
981 gcc_assert (text
->locus
);
983 = linemap_position_for_loc_and_offset (line_table
,
984 gfc_current_locus
.lb
->location
,
986 global_dc
->caret_char
= '1';
987 pp_string (pp
, result
);
995 /* Return a malloc'd string describing a location. The caller is
996 responsible for freeing the memory. */
998 gfc_diagnostic_build_prefix (diagnostic_context
*context
,
999 const diagnostic_info
*diagnostic
)
1001 static const char *const diagnostic_kind_text
[] = {
1002 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
1003 #include "gfc-diagnostic.def"
1004 #undef DEFINE_DIAGNOSTIC_KIND
1007 static const char *const diagnostic_kind_color
[] = {
1008 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
1009 #include "gfc-diagnostic.def"
1010 #undef DEFINE_DIAGNOSTIC_KIND
1013 gcc_assert (diagnostic
->kind
< DK_LAST_DIAGNOSTIC_KIND
);
1014 const char *text
= _(diagnostic_kind_text
[diagnostic
->kind
]);
1015 const char *text_cs
= "", *text_ce
= "";
1016 pretty_printer
*pp
= context
->printer
;
1018 if (diagnostic_kind_color
[diagnostic
->kind
])
1020 text_cs
= colorize_start (pp_show_color (pp
),
1021 diagnostic_kind_color
[diagnostic
->kind
]);
1022 text_ce
= colorize_stop (pp_show_color (pp
));
1024 return build_message_string ("%s%s%s: ", text_cs
, text
, text_ce
);
1027 /* Return a malloc'd string describing a location. The caller is
1028 responsible for freeing the memory. */
1030 gfc_diagnostic_build_locus_prefix (diagnostic_context
*context
,
1031 const diagnostic_info
*diagnostic
)
1033 pretty_printer
*pp
= context
->printer
;
1034 const char *locus_cs
= colorize_start (pp_show_color (pp
), "locus");
1035 const char *locus_ce
= colorize_stop (pp_show_color (pp
));
1036 expanded_location s
= expand_location_to_spelling_point (diagnostic
->location
);
1037 if (diagnostic
->override_column
)
1038 s
.column
= diagnostic
->override_column
;
1040 return (s
.file
== NULL
1041 ? build_message_string ("%s%s:%s", locus_cs
, progname
, locus_ce
)
1042 : !strcmp (s
.file
, N_("<built-in>"))
1043 ? build_message_string ("%s%s:%s", locus_cs
, s
.file
, locus_ce
)
1044 : context
->show_column
1045 ? build_message_string ("%s%s:%d:%d:%s", locus_cs
, s
.file
, s
.line
,
1047 : build_message_string ("%s%s:%d:%s", locus_cs
, s
.file
, s
.line
, locus_ce
));
1051 gfc_diagnostic_starter (diagnostic_context
*context
,
1052 diagnostic_info
*diagnostic
)
1054 char * locus_prefix
= gfc_diagnostic_build_locus_prefix (context
, diagnostic
);
1055 char * prefix
= gfc_diagnostic_build_prefix (context
, diagnostic
);
1056 /* First we assume there is a caret line. */
1057 pp_set_prefix (context
->printer
, NULL
);
1058 if (pp_needs_newline (context
->printer
))
1059 pp_newline (context
->printer
);
1060 pp_verbatim (context
->printer
, locus_prefix
);
1061 /* Fortran uses an empty line between locus and caret line. */
1062 pp_newline (context
->printer
);
1063 diagnostic_show_locus (context
, diagnostic
);
1064 if (pp_needs_newline (context
->printer
))
1066 pp_newline (context
->printer
);
1067 /* If the caret line was shown, the prefix does not contain the
1069 pp_set_prefix (context
->printer
, prefix
);
1073 /* Otherwise, start again. */
1074 pp_clear_output_area(context
->printer
);
1075 pp_set_prefix (context
->printer
, concat (locus_prefix
, " ", prefix
, NULL
));
1078 free (locus_prefix
);
1082 gfc_diagnostic_finalizer (diagnostic_context
*context
,
1083 diagnostic_info
*diagnostic ATTRIBUTE_UNUSED
)
1085 pp_destroy_prefix (context
->printer
);
1086 pp_newline_and_flush (context
->printer
);
1089 /* Immediate warning (i.e. do not buffer the warning). */
1090 /* This function uses the common diagnostics, but does not support %L, yet. */
1093 gfc_warning_now_2 (int opt
, const char *gmsgid
, ...)
1096 diagnostic_info diagnostic
;
1099 va_start (argp
, gmsgid
);
1100 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, UNKNOWN_LOCATION
,
1102 diagnostic
.option_index
= opt
;
1103 ret
= report_diagnostic (&diagnostic
);
1108 /* Immediate warning (i.e. do not buffer the warning). */
1109 /* This function uses the common diagnostics, but does not support %L, yet. */
1112 gfc_warning_now_2 (const char *gmsgid
, ...)
1115 diagnostic_info diagnostic
;
1118 va_start (argp
, gmsgid
);
1119 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, UNKNOWN_LOCATION
,
1121 ret
= report_diagnostic (&diagnostic
);
1127 /* Immediate error (i.e. do not buffer). */
1128 /* This function uses the common diagnostics, but does not support %L, yet. */
1131 gfc_error_now_2 (const char *gmsgid
, ...)
1134 diagnostic_info diagnostic
;
1136 va_start (argp
, gmsgid
);
1137 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, UNKNOWN_LOCATION
, DK_ERROR
);
1138 report_diagnostic (&diagnostic
);
1143 /* Fatal error, never returns. */
1144 /* This function uses the common diagnostics, but does not support %L, yet. */
1147 gfc_fatal_error (const char *gmsgid
, ...)
1150 diagnostic_info diagnostic
;
1152 va_start (argp
, gmsgid
);
1153 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, UNKNOWN_LOCATION
, DK_FATAL
);
1154 report_diagnostic (&diagnostic
);
1160 /* Clear the warning flag. */
1163 gfc_clear_warning (void)
1165 warning_buffer
.flag
= 0;
1169 /* Check to see if any warnings have been saved.
1170 If so, print the warning. */
1173 gfc_warning_check (void)
1175 if (warning_buffer
.flag
)
1178 if (warning_buffer
.message
!= NULL
)
1179 fputs (warning_buffer
.message
, stderr
);
1180 warning_buffer
.flag
= 0;
1185 /* Issue an error. */
1188 gfc_error (const char *gmsgid
, ...)
1192 if (warnings_not_errors
)
1195 if (suppress_errors
)
1198 error_buffer
.flag
= 1;
1199 error_buffer
.index
= 0;
1200 cur_error_buffer
= &error_buffer
;
1202 va_start (argp
, gmsgid
);
1203 error_print (_("Error:"), _(gmsgid
), argp
);
1208 if (buffer_flag
== 0)
1209 gfc_increment_error_count();
1215 if (inhibit_warnings
)
1218 warning_buffer
.flag
= 1;
1219 warning_buffer
.index
= 0;
1220 cur_error_buffer
= &warning_buffer
;
1222 va_start (argp
, gmsgid
);
1223 error_print (_("Warning:"), _(gmsgid
), argp
);
1228 if (buffer_flag
== 0)
1231 if (warnings_are_errors
)
1232 gfc_increment_error_count();
1237 /* Immediate error. */
1238 /* Use gfc_error_now_2 instead, unless gmsgid contains a %L. */
1241 gfc_error_now (const char *gmsgid
, ...)
1246 error_buffer
.flag
= 1;
1247 error_buffer
.index
= 0;
1248 cur_error_buffer
= &error_buffer
;
1253 va_start (argp
, gmsgid
);
1254 error_print (_("Error:"), _(gmsgid
), argp
);
1259 gfc_increment_error_count();
1263 if (flag_fatal_errors
)
1264 exit (FATAL_EXIT_CODE
);
1268 /* Fatal error, never returns. */
1269 /* Use gfc_fatal_error instead, unless gmsgid contains a %L. */
1272 gfc_fatal_error_1 (const char *gmsgid
, ...)
1278 va_start (argp
, gmsgid
);
1279 error_print (_("Fatal Error:"), _(gmsgid
), argp
);
1282 exit (FATAL_EXIT_CODE
);
1286 /* This shouldn't happen... but sometimes does. */
1289 gfc_internal_error (const char *format
, ...)
1295 va_start (argp
, format
);
1297 show_loci (&gfc_current_locus
, NULL
);
1298 error_printf ("Internal Error at (1):");
1300 error_print ("", format
, argp
);
1303 exit (ICE_EXIT_CODE
);
1307 /* Clear the error flag when we start to compile a source line. */
1310 gfc_clear_error (void)
1312 error_buffer
.flag
= 0;
1313 warnings_not_errors
= 0;
1317 /* Tests the state of error_flag. */
1320 gfc_error_flag_test (void)
1322 return error_buffer
.flag
;
1326 /* Check to see if any errors have been saved.
1327 If so, print the error. Returns the state of error_flag. */
1330 gfc_error_check (void)
1334 rc
= error_buffer
.flag
;
1336 if (error_buffer
.flag
)
1338 if (error_buffer
.message
!= NULL
)
1339 fputs (error_buffer
.message
, stderr
);
1340 error_buffer
.flag
= 0;
1342 gfc_increment_error_count();
1344 if (flag_fatal_errors
)
1345 exit (FATAL_EXIT_CODE
);
1352 /* Save the existing error state. */
1355 gfc_push_error (gfc_error_buf
*err
)
1357 err
->flag
= error_buffer
.flag
;
1358 if (error_buffer
.flag
)
1359 err
->message
= xstrdup (error_buffer
.message
);
1361 error_buffer
.flag
= 0;
1365 /* Restore a previous pushed error state. */
1368 gfc_pop_error (gfc_error_buf
*err
)
1370 error_buffer
.flag
= err
->flag
;
1371 if (error_buffer
.flag
)
1373 size_t len
= strlen (err
->message
) + 1;
1374 gcc_assert (len
<= error_buffer
.allocated
);
1375 memcpy (error_buffer
.message
, err
->message
, len
);
1376 free (err
->message
);
1381 /* Free a pushed error state, but keep the current error state. */
1384 gfc_free_error (gfc_error_buf
*err
)
1387 free (err
->message
);
1391 /* Report the number of warnings and errors that occurred to the caller. */
1394 gfc_get_errors (int *w
, int *e
)
1403 /* Switch errors into warnings. */
1406 gfc_errors_to_warnings (int f
)
1408 warnings_not_errors
= (f
== 1) ? 1 : 0;
1412 gfc_diagnostics_init (void)
1414 diagnostic_starter (global_dc
) = gfc_diagnostic_starter
;
1415 diagnostic_finalizer (global_dc
) = gfc_diagnostic_finalizer
;
1416 diagnostic_format_decoder (global_dc
) = gfc_format_decoder
;
1417 global_dc
->caret_char
= '^';
1421 gfc_diagnostics_finish (void)
1423 tree_diagnostics_defaults (global_dc
);
1424 /* We still want to use the gfc starter and finalizer, not the tree
1426 diagnostic_starter (global_dc
) = gfc_diagnostic_starter
;
1427 diagnostic_finalizer (global_dc
) = gfc_diagnostic_finalizer
;
1428 global_dc
->caret_char
= '^';