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"
44 static int suppress_errors
= 0;
46 static int warnings_not_errors
= 0;
48 static int terminal_width
, buffer_flag
, errors
, warnings
;
50 static gfc_error_buf error_buffer
, warning_buffer
, *cur_error_buffer
;
53 /* Go one level deeper suppressing errors. */
56 gfc_push_suppress_errors (void)
58 gcc_assert (suppress_errors
>= 0);
63 /* Leave one level of error suppressing. */
66 gfc_pop_suppress_errors (void)
68 gcc_assert (suppress_errors
> 0);
73 /* Determine terminal width (for trimming source lines in output). */
76 get_terminal_width (void)
78 /* Only limit the width if we're outputting to a terminal. */
80 if (!isatty (STDERR_FILENO
))
84 /* Method #1: Use ioctl (not available on all systems). */
88 if (ioctl (0, TIOCGWINSZ
, &w
) == 0 && w
.ws_col
> 0)
92 /* Method #2: Query environment variable $COLUMNS. */
93 const char *p
= getenv ("COLUMNS");
101 /* If both fail, use reasonable default. */
106 /* Per-file error initialization. */
109 gfc_error_init_1 (void)
111 terminal_width
= get_terminal_width ();
118 /* Set the flag for buffering errors or not. */
121 gfc_buffer_error (int flag
)
127 /* Add a single character to the error buffer or output depending on
135 if (cur_error_buffer
->index
>= cur_error_buffer
->allocated
)
137 cur_error_buffer
->allocated
= cur_error_buffer
->allocated
138 ? cur_error_buffer
->allocated
* 2 : 1000;
139 cur_error_buffer
->message
= XRESIZEVEC (char, cur_error_buffer
->message
,
140 cur_error_buffer
->allocated
);
142 cur_error_buffer
->message
[cur_error_buffer
->index
++] = c
;
148 /* We build up complete lines before handing things
149 over to the library in order to speed up error printing. */
151 static size_t allocated
= 0, index
= 0;
153 if (index
+ 1 >= allocated
)
155 allocated
= allocated
? allocated
* 2 : 1000;
156 line
= XRESIZEVEC (char, line
, allocated
);
162 fputs (line
, stderr
);
170 /* Copy a string to wherever it needs to go. */
173 error_string (const char *p
)
180 /* Print a formatted integer to the error buffer or output. */
185 error_uinteger (unsigned long int i
)
187 char *p
, int_buf
[IBUF_LEN
];
189 p
= int_buf
+ IBUF_LEN
- 1;
201 error_string (p
+ 1);
205 error_integer (long int i
)
211 u
= (unsigned long int) -i
;
222 gfc_widechar_display_length (gfc_char_t c
)
224 if (gfc_wide_is_printable (c
) || c
== '\t')
225 /* Printable ASCII character, or tabulation (output as a space). */
227 else if (c
< ((gfc_char_t
) 1 << 8))
228 /* Displayed as \x?? */
230 else if (c
< ((gfc_char_t
) 1 << 16))
231 /* Displayed as \u???? */
234 /* Displayed as \U???????? */
239 /* Length of the ASCII representation of the wide string, escaping wide
240 characters as print_wide_char_into_buffer() does. */
243 gfc_wide_display_length (const gfc_char_t
*str
)
247 for (i
= 0, len
= 0; str
[i
]; i
++)
248 len
+= gfc_widechar_display_length (str
[i
]);
254 print_wide_char_into_buffer (gfc_char_t c
, char *buf
)
256 static const char xdigit
[16] = { '0', '1', '2', '3', '4', '5', '6',
257 '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
259 if (gfc_wide_is_printable (c
) || c
== '\t')
262 /* Tabulation is output as a space. */
263 buf
[0] = (unsigned char) (c
== '\t' ? ' ' : c
);
266 else if (c
< ((gfc_char_t
) 1 << 8))
269 buf
[3] = xdigit
[c
& 0x0F];
271 buf
[2] = xdigit
[c
& 0x0F];
277 else if (c
< ((gfc_char_t
) 1 << 16))
280 buf
[5] = xdigit
[c
& 0x0F];
282 buf
[4] = xdigit
[c
& 0x0F];
284 buf
[3] = xdigit
[c
& 0x0F];
286 buf
[2] = xdigit
[c
& 0x0F];
295 buf
[9] = xdigit
[c
& 0x0F];
297 buf
[8] = xdigit
[c
& 0x0F];
299 buf
[7] = xdigit
[c
& 0x0F];
301 buf
[6] = xdigit
[c
& 0x0F];
303 buf
[5] = xdigit
[c
& 0x0F];
305 buf
[4] = xdigit
[c
& 0x0F];
307 buf
[3] = xdigit
[c
& 0x0F];
309 buf
[2] = xdigit
[c
& 0x0F];
317 static char wide_char_print_buffer
[11];
320 gfc_print_wide_char (gfc_char_t c
)
322 print_wide_char_into_buffer (c
, wide_char_print_buffer
);
323 return wide_char_print_buffer
;
327 /* Show the file, where it was included, and the source line, give a
328 locus. Calls error_printf() recursively, but the recursion is at
329 most one level deep. */
331 static void error_printf (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
334 show_locus (locus
*loc
, int c1
, int c2
)
341 /* TODO: Either limit the total length and number of included files
342 displayed or add buffering of arbitrary number of characters in
345 /* Write out the error header line, giving the source file and error
346 location (in GNU standard "[file]:[line].[column]:" format),
347 followed by an "included by" stack and a blank line. This header
348 format is matched by a testsuite parser defined in
349 lib/gfortran-dg.exp. */
354 error_string (f
->filename
);
357 error_integer (LOCATION_LINE (lb
->location
));
359 if ((c1
> 0) || (c2
> 0))
365 if ((c1
> 0) && (c2
> 0))
376 i
= f
->inclusion_line
;
379 if (f
== NULL
) break;
381 error_printf (" Included at %s:%d:", f
->filename
, i
);
386 /* Calculate an appropriate horizontal offset of the source line in
387 order to get the error locus within the visible portion of the
388 line. Note that if the margin of 5 here is changed, the
389 corresponding margin of 10 in show_loci should be changed. */
393 /* If the two loci would appear in the same column, we shift
394 '2' one column to the right, so as to print '12' rather than
395 just '1'. We do this here so it will be accounted for in the
396 margin calculations. */
401 cmax
= (c1
< c2
) ? c2
: c1
;
402 if (cmax
> terminal_width
- 5)
403 offset
= cmax
- terminal_width
+ 5;
405 /* Show the line itself, taking care not to print more than what can
406 show up on the terminal. Tabs are converted to spaces, and
407 nonprintable characters are converted to a "\xNN" sequence. */
409 p
= &(lb
->line
[offset
]);
410 i
= gfc_wide_display_length (p
);
411 if (i
> terminal_width
)
412 i
= terminal_width
- 1;
416 static char buffer
[11];
417 i
-= print_wide_char_into_buffer (*p
++, buffer
);
418 error_string (buffer
);
423 /* Show the '1' and/or '2' corresponding to the column of the error
424 locus. Note that a value of -1 for c1 or c2 will simply cause
425 the relevant number not to be printed. */
431 p
= &(lb
->line
[offset
]);
432 for (i
= 0; i
< cmax
; i
++)
435 spaces
= gfc_widechar_display_length (*p
++);
438 error_char ('1'), spaces
--;
440 error_char ('2'), spaces
--;
442 for (j
= 0; j
< spaces
; j
++)
456 /* As part of printing an error, we show the source lines that caused
457 the problem. We show at least one, and possibly two loci; the two
458 loci may or may not be on the same source line. */
461 show_loci (locus
*l1
, locus
*l2
)
465 if (l1
== NULL
|| l1
->lb
== NULL
)
467 error_printf ("<During initialization>\n");
471 /* While calculating parameters for printing the loci, we consider possible
472 reasons for printing one per line. If appropriate, print the loci
473 individually; otherwise we print them both on the same line. */
475 c1
= l1
->nextc
- l1
->lb
->line
;
478 show_locus (l1
, c1
, -1);
482 c2
= l2
->nextc
- l2
->lb
->line
;
489 /* Note that the margin value of 10 here needs to be less than the
490 margin of 5 used in the calculation of offset in show_locus. */
492 if (l1
->lb
!= l2
->lb
|| m
> terminal_width
- 10)
494 show_locus (l1
, c1
, -1);
495 show_locus (l2
, -1, c2
);
499 show_locus (l1
, c1
, c2
);
505 /* Workhorse for the error printing subroutines. This subroutine is
506 inspired by g77's error handling and is similar to printf() with
507 the following %-codes:
509 %c Character, %d or %i Integer, %s String, %% Percent
510 %L Takes locus argument
511 %C Current locus (no argument)
513 If a locus pointer is given, the actual source line is printed out
514 and the column is indicated. Since we want the error message at
515 the bottom of any source file information, we must scan the
516 argument list twice -- once to determine whether the loci are
517 present and record this for printing, and once to print the error
518 message after and loci have been printed. A maximum of two locus
519 arguments are permitted.
521 This function is also called (recursively) by show_locus in the
522 case of included files; however, as show_locus does not resupply
523 any loci, the recursion is at most one level deep. */
527 static void ATTRIBUTE_GCC_GFC(2,0)
528 error_print (const char *type
, const char *format0
, va_list argp
)
530 enum { TYPE_CURRENTLOC
, TYPE_LOCUS
, TYPE_INTEGER
, TYPE_UINTEGER
,
531 TYPE_LONGINT
, TYPE_ULONGINT
, TYPE_CHAR
, TYPE_STRING
,
540 unsigned int uintval
;
542 unsigned long int ulongintval
;
544 const char * stringval
;
546 } arg
[MAX_ARGS
], spec
[MAX_ARGS
];
547 /* spec is the array of specifiers, in the same order as they
548 appear in the format string. arg is the array of arguments,
549 in the same order as they appear in the va_list. */
552 int i
, n
, have_l1
, pos
, maxpos
;
553 locus
*l1
, *l2
, *loc
;
556 loc
= l1
= l2
= NULL
;
565 for (i
= 0; i
< MAX_ARGS
; i
++)
567 arg
[i
].type
= NOTYPE
;
571 /* First parse the format string for position specifiers. */
584 if (ISDIGIT (*format
))
586 /* This is a position specifier. For example, the number
587 12 in the format string "%12$d", which specifies the third
588 argument of the va_list, formatted in %d format.
589 For details, see "man 3 printf". */
590 pos
= atoi(format
) - 1;
591 gcc_assert (pos
>= 0);
592 while (ISDIGIT(*format
))
594 gcc_assert (*format
== '$');
608 arg
[pos
].type
= TYPE_CURRENTLOC
;
612 arg
[pos
].type
= TYPE_LOCUS
;
617 arg
[pos
].type
= TYPE_INTEGER
;
621 arg
[pos
].type
= TYPE_UINTEGER
;
627 arg
[pos
].type
= TYPE_ULONGINT
;
628 else if (c
== 'i' || c
== 'd')
629 arg
[pos
].type
= TYPE_LONGINT
;
635 arg
[pos
].type
= TYPE_CHAR
;
639 arg
[pos
].type
= TYPE_STRING
;
649 /* Then convert the values for each %-style argument. */
650 for (pos
= 0; pos
<= maxpos
; pos
++)
652 gcc_assert (arg
[pos
].type
!= NOTYPE
);
653 switch (arg
[pos
].type
)
655 case TYPE_CURRENTLOC
:
656 loc
= &gfc_current_locus
;
660 if (arg
[pos
].type
== TYPE_LOCUS
)
661 loc
= va_arg (argp
, locus
*);
666 arg
[pos
].u
.stringval
= "(2)";
672 arg
[pos
].u
.stringval
= "(1)";
677 arg
[pos
].u
.intval
= va_arg (argp
, int);
681 arg
[pos
].u
.uintval
= va_arg (argp
, unsigned int);
685 arg
[pos
].u
.longintval
= va_arg (argp
, long int);
689 arg
[pos
].u
.ulongintval
= va_arg (argp
, unsigned long int);
693 arg
[pos
].u
.charval
= (char) va_arg (argp
, int);
697 arg
[pos
].u
.stringval
= (const char *) va_arg (argp
, char *);
705 for (n
= 0; spec
[n
].pos
>= 0; n
++)
706 spec
[n
].u
= arg
[spec
[n
].pos
].u
;
708 /* Show the current loci if we have to. */
722 for (; *format
; format
++)
726 error_char (*format
);
731 if (ISDIGIT (*format
))
733 /* This is a position specifier. See comment above. */
734 while (ISDIGIT (*format
))
737 /* Skip over the dollar sign. */
748 error_char (spec
[n
++].u
.charval
);
752 case 'C': /* Current locus */
753 case 'L': /* Specified locus */
754 error_string (spec
[n
++].u
.stringval
);
759 error_integer (spec
[n
++].u
.intval
);
763 error_uinteger (spec
[n
++].u
.uintval
);
769 error_uinteger (spec
[n
++].u
.ulongintval
);
771 error_integer (spec
[n
++].u
.longintval
);
781 /* Wrapper for error_print(). */
784 error_printf (const char *gmsgid
, ...)
788 va_start (argp
, gmsgid
);
789 error_print ("", _(gmsgid
), argp
);
794 /* Increment the number of errors, and check whether too many have
798 gfc_increment_error_count (void)
801 if ((gfc_option
.max_errors
!= 0) && (errors
>= gfc_option
.max_errors
))
802 gfc_fatal_error ("Error count reached limit of %d.", gfc_option
.max_errors
);
806 /* Issue a warning. */
809 gfc_warning (const char *gmsgid
, ...)
813 if (inhibit_warnings
)
816 warning_buffer
.flag
= 1;
817 warning_buffer
.index
= 0;
818 cur_error_buffer
= &warning_buffer
;
820 va_start (argp
, gmsgid
);
821 error_print (_("Warning:"), _(gmsgid
), argp
);
826 if (buffer_flag
== 0)
829 if (warnings_are_errors
)
830 gfc_increment_error_count();
835 /* Whether, for a feature included in a given standard set (GFC_STD_*),
836 we should issue an error or a warning, or be quiet. */
839 gfc_notification_std (int std
)
843 warning
= ((gfc_option
.warn_std
& std
) != 0) && !inhibit_warnings
;
844 if ((gfc_option
.allow_std
& std
) != 0 && !warning
)
847 return warning
? WARNING
: ERROR
;
851 /* Possibly issue a warning/error about use of a nonstandard (or deleted)
852 feature. An error/warning will be issued if the currently selected
853 standard does not contain the requested bits. Return false if
854 an error is generated. */
857 gfc_notify_std (int std
, const char *gmsgid
, ...)
861 const char *msg1
, *msg2
;
864 warning
= ((gfc_option
.warn_std
& std
) != 0) && !inhibit_warnings
;
865 if ((gfc_option
.allow_std
& std
) != 0 && !warning
)
869 return warning
? true : false;
871 cur_error_buffer
= warning
? &warning_buffer
: &error_buffer
;
872 cur_error_buffer
->flag
= 1;
873 cur_error_buffer
->index
= 0;
876 msg1
= _("Warning:");
882 case GFC_STD_F2008_TS
:
883 msg2
= "TS 29113/TS 18508:";
885 case GFC_STD_F2008_OBS
:
886 msg2
= _("Fortran 2008 obsolescent feature:");
889 msg2
= "Fortran 2008:";
892 msg2
= "Fortran 2003:";
895 msg2
= _("GNU Extension:");
898 msg2
= _("Legacy Extension:");
900 case GFC_STD_F95_OBS
:
901 msg2
= _("Obsolescent feature:");
903 case GFC_STD_F95_DEL
:
904 msg2
= _("Deleted feature:");
910 buffer
= (char *) alloca (strlen (msg1
) + strlen (msg2
) + 2);
911 strcpy (buffer
, msg1
);
912 strcat (buffer
, " ");
913 strcat (buffer
, msg2
);
915 va_start (argp
, gmsgid
);
916 error_print (buffer
, _(gmsgid
), argp
);
921 if (buffer_flag
== 0)
923 if (warning
&& !warnings_are_errors
)
926 gfc_increment_error_count();
927 cur_error_buffer
->flag
= 0;
930 return (warning
&& !warnings_are_errors
) ? true : false;
934 /* Immediate warning (i.e. do not buffer the warning). */
937 gfc_warning_now (const char *gmsgid
, ...)
942 if (inhibit_warnings
)
949 va_start (argp
, gmsgid
);
950 error_print (_("Warning:"), _(gmsgid
), argp
);
955 if (warnings_are_errors
)
956 gfc_increment_error_count();
961 /* Return a malloc'd string describing a location. The caller is
962 responsible for freeing the memory. */
964 gfc_diagnostic_build_prefix (diagnostic_context
*context
,
965 const diagnostic_info
*diagnostic
)
967 static const char *const diagnostic_kind_text
[] = {
968 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
969 #include "gfc-diagnostic.def"
970 #undef DEFINE_DIAGNOSTIC_KIND
973 static const char *const diagnostic_kind_color
[] = {
974 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
975 #include "gfc-diagnostic.def"
976 #undef DEFINE_DIAGNOSTIC_KIND
979 gcc_assert (diagnostic
->kind
< DK_LAST_DIAGNOSTIC_KIND
);
980 const char *text
= _(diagnostic_kind_text
[diagnostic
->kind
]);
981 const char *text_cs
= "", *text_ce
= "";
982 pretty_printer
*pp
= context
->printer
;
984 if (diagnostic_kind_color
[diagnostic
->kind
])
986 text_cs
= colorize_start (pp_show_color (pp
),
987 diagnostic_kind_color
[diagnostic
->kind
]);
988 text_ce
= colorize_stop (pp_show_color (pp
));
990 return build_message_string ("%s%s%s: ", text_cs
, text
, text_ce
);
993 /* Return a malloc'd string describing a location. The caller is
994 responsible for freeing the memory. */
996 gfc_diagnostic_build_locus_prefix (diagnostic_context
*context
,
997 const diagnostic_info
*diagnostic
)
999 pretty_printer
*pp
= context
->printer
;
1000 const char *locus_cs
= colorize_start (pp_show_color (pp
), "locus");
1001 const char *locus_ce
= colorize_stop (pp_show_color (pp
));
1002 expanded_location s
= expand_location_to_spelling_point (diagnostic
->location
);
1003 if (diagnostic
->override_column
)
1004 s
.column
= diagnostic
->override_column
;
1006 return (s
.file
== NULL
1007 ? build_message_string ("%s%s:%s ", locus_cs
, progname
, locus_ce
)
1008 : !strcmp (s
.file
, N_("<built-in>"))
1009 ? build_message_string ("%s%s:%s ", locus_cs
, s
.file
, locus_ce
)
1010 : context
->show_column
1011 ? build_message_string ("%s%s:%d:%d:%s ", locus_cs
, s
.file
, s
.line
,
1013 : build_message_string ("%s%s:%d:%s ", locus_cs
, s
.file
, s
.line
, locus_ce
));
1017 gfc_diagnostic_starter (diagnostic_context
*context
,
1018 diagnostic_info
*diagnostic
)
1020 char * locus_prefix
= gfc_diagnostic_build_locus_prefix (context
, diagnostic
);
1021 char * prefix
= gfc_diagnostic_build_prefix (context
, diagnostic
);
1022 /* First we assume there is a caret line. */
1023 pp_set_prefix (context
->printer
, NULL
);
1024 if (pp_needs_newline (context
->printer
))
1025 pp_newline (context
->printer
);
1026 pp_verbatim (context
->printer
, locus_prefix
);
1027 /* Fortran uses an empty line between locus and caret line. */
1028 pp_newline (context
->printer
);
1029 diagnostic_show_locus (context
, diagnostic
);
1030 if (pp_needs_newline (context
->printer
))
1032 pp_newline (context
->printer
);
1033 /* If the caret line was shown, the prefix does not contain the
1035 pp_set_prefix (context
->printer
, prefix
);
1039 /* Otherwise, start again. */
1040 pp_clear_output_area(context
->printer
);
1041 pp_set_prefix (context
->printer
, concat (locus_prefix
, prefix
, NULL
));
1044 free (locus_prefix
);
1048 gfc_diagnostic_finalizer (diagnostic_context
*context
,
1049 diagnostic_info
*diagnostic ATTRIBUTE_UNUSED
)
1051 pp_destroy_prefix (context
->printer
);
1052 pp_newline_and_flush (context
->printer
);
1055 /* Give a warning about the command-line. */
1058 gfc_warning_cmdline (int opt
, const char *gmsgid
, ...)
1061 diagnostic_info diagnostic
;
1064 va_start (argp
, gmsgid
);
1065 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, UNKNOWN_LOCATION
,
1067 diagnostic
.option_index
= opt
;
1068 ret
= report_diagnostic (&diagnostic
);
1074 /* Give a warning about the command-line. */
1077 gfc_warning_cmdline (const char *gmsgid
, ...)
1080 diagnostic_info diagnostic
;
1083 va_start (argp
, gmsgid
);
1084 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, UNKNOWN_LOCATION
,
1086 ret
= report_diagnostic (&diagnostic
);
1092 /* Give an error about the command-line. */
1095 gfc_error_cmdline (const char *gmsgid
, ...)
1098 diagnostic_info diagnostic
;
1100 va_start (argp
, gmsgid
);
1101 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, UNKNOWN_LOCATION
, DK_ERROR
);
1102 report_diagnostic (&diagnostic
);
1106 /* Clear the warning flag. */
1109 gfc_clear_warning (void)
1111 warning_buffer
.flag
= 0;
1115 /* Check to see if any warnings have been saved.
1116 If so, print the warning. */
1119 gfc_warning_check (void)
1121 if (warning_buffer
.flag
)
1124 if (warning_buffer
.message
!= NULL
)
1125 fputs (warning_buffer
.message
, stderr
);
1126 warning_buffer
.flag
= 0;
1131 /* Issue an error. */
1134 gfc_error (const char *gmsgid
, ...)
1138 if (warnings_not_errors
)
1141 if (suppress_errors
)
1144 error_buffer
.flag
= 1;
1145 error_buffer
.index
= 0;
1146 cur_error_buffer
= &error_buffer
;
1148 va_start (argp
, gmsgid
);
1149 error_print (_("Error:"), _(gmsgid
), argp
);
1154 if (buffer_flag
== 0)
1155 gfc_increment_error_count();
1161 if (inhibit_warnings
)
1164 warning_buffer
.flag
= 1;
1165 warning_buffer
.index
= 0;
1166 cur_error_buffer
= &warning_buffer
;
1168 va_start (argp
, gmsgid
);
1169 error_print (_("Warning:"), _(gmsgid
), argp
);
1174 if (buffer_flag
== 0)
1177 if (warnings_are_errors
)
1178 gfc_increment_error_count();
1183 /* Immediate error. */
1186 gfc_error_now (const char *gmsgid
, ...)
1191 error_buffer
.flag
= 1;
1192 error_buffer
.index
= 0;
1193 cur_error_buffer
= &error_buffer
;
1198 va_start (argp
, gmsgid
);
1199 error_print (_("Error:"), _(gmsgid
), argp
);
1204 gfc_increment_error_count();
1208 if (flag_fatal_errors
)
1209 exit (FATAL_EXIT_CODE
);
1213 /* Fatal error, never returns. */
1216 gfc_fatal_error (const char *gmsgid
, ...)
1222 va_start (argp
, gmsgid
);
1223 error_print (_("Fatal Error:"), _(gmsgid
), argp
);
1226 exit (FATAL_EXIT_CODE
);
1230 /* This shouldn't happen... but sometimes does. */
1233 gfc_internal_error (const char *format
, ...)
1239 va_start (argp
, format
);
1241 show_loci (&gfc_current_locus
, NULL
);
1242 error_printf ("Internal Error at (1):");
1244 error_print ("", format
, argp
);
1247 exit (ICE_EXIT_CODE
);
1251 /* Clear the error flag when we start to compile a source line. */
1254 gfc_clear_error (void)
1256 error_buffer
.flag
= 0;
1257 warnings_not_errors
= 0;
1261 /* Tests the state of error_flag. */
1264 gfc_error_flag_test (void)
1266 return error_buffer
.flag
;
1270 /* Check to see if any errors have been saved.
1271 If so, print the error. Returns the state of error_flag. */
1274 gfc_error_check (void)
1278 rc
= error_buffer
.flag
;
1280 if (error_buffer
.flag
)
1282 if (error_buffer
.message
!= NULL
)
1283 fputs (error_buffer
.message
, stderr
);
1284 error_buffer
.flag
= 0;
1286 gfc_increment_error_count();
1288 if (flag_fatal_errors
)
1289 exit (FATAL_EXIT_CODE
);
1296 /* Save the existing error state. */
1299 gfc_push_error (gfc_error_buf
*err
)
1301 err
->flag
= error_buffer
.flag
;
1302 if (error_buffer
.flag
)
1303 err
->message
= xstrdup (error_buffer
.message
);
1305 error_buffer
.flag
= 0;
1309 /* Restore a previous pushed error state. */
1312 gfc_pop_error (gfc_error_buf
*err
)
1314 error_buffer
.flag
= err
->flag
;
1315 if (error_buffer
.flag
)
1317 size_t len
= strlen (err
->message
) + 1;
1318 gcc_assert (len
<= error_buffer
.allocated
);
1319 memcpy (error_buffer
.message
, err
->message
, len
);
1320 free (err
->message
);
1325 /* Free a pushed error state, but keep the current error state. */
1328 gfc_free_error (gfc_error_buf
*err
)
1331 free (err
->message
);
1335 /* Report the number of warnings and errors that occurred to the caller. */
1338 gfc_get_errors (int *w
, int *e
)
1347 /* Switch errors into warnings. */
1350 gfc_errors_to_warnings (int f
)
1352 warnings_not_errors
= (f
== 1) ? 1 : 0;
1356 gfc_diagnostics_init (void)
1358 diagnostic_starter (global_dc
) = gfc_diagnostic_starter
;
1359 diagnostic_finalizer (global_dc
) = gfc_diagnostic_finalizer
;
1360 global_dc
->caret_char
= '^';