2 Copyright (C) 2000-2024 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. */
27 #define INCLUDE_MEMORY
30 #include "coretypes.h"
34 #include "diagnostic.h"
35 #include "diagnostic-color.h"
36 #include "tree-diagnostic.h" /* tree_diagnostics_defaults */
37 #include "diagnostic-format-text.h"
39 static int suppress_errors
= 0;
41 static bool warnings_not_errors
= false;
43 /* True if the error/warnings should be buffered. */
44 static bool buffered_p
;
46 static gfc_error_buffer
*error_buffer
;
47 static diagnostic_buffer
*pp_error_buffer
, *pp_warning_buffer
;
49 gfc_error_buffer::gfc_error_buffer ()
50 : flag (false), buffer (*global_dc
)
54 /* Return a location_t suitable for 'tree' for a gfortran locus. During
55 parsing in gfortran, loc->u.lb->location contains only the line number
56 and LOCATION_COLUMN is 0; hence, the column has to be added when generating
57 locations for 'tree'. If available, return location_t directly, which
61 gfc_get_location_with_offset (locus
*loc
, unsigned offset
)
63 if (loc
->nextc
== (gfc_char_t
*) -1)
65 gcc_checking_assert (offset
== 0);
66 return loc
->u
.location
;
68 gcc_checking_assert (loc
->nextc
>= loc
->u
.lb
->line
);
69 return linemap_position_for_loc_and_offset (line_table
, loc
->u
.lb
->location
,
70 loc
->nextc
- loc
->u
.lb
->line
74 /* Convert a locus to a range. */
77 gfc_get_location_range (locus
*caret_loc
, unsigned caret_offset
,
78 locus
*start_loc
, unsigned start_offset
,
82 location_t start
= gfc_get_location_with_offset (start_loc
, start_offset
);
83 location_t end
= gfc_get_location_with_offset (end_loc
, 0);
86 caret
= gfc_get_location_with_offset (caret_loc
, caret_offset
);
89 range
.nextc
= (gfc_char_t
*) -1;
90 range
.u
.location
= make_location (caret_loc
? caret
: start
, start
, end
);
94 /* Return buffered_p. */
101 /* Go one level deeper suppressing errors. */
104 gfc_push_suppress_errors (void)
106 gcc_assert (suppress_errors
>= 0);
111 gfc_error_opt (int opt
, const char *gmsgid
, va_list ap
) ATTRIBUTE_GCC_GFC(2,0);
114 gfc_warning (int opt
, const char *gmsgid
, va_list ap
) ATTRIBUTE_GCC_GFC(2,0);
117 /* Leave one level of error suppressing. */
120 gfc_pop_suppress_errors (void)
122 gcc_assert (suppress_errors
> 0);
127 /* Query whether errors are suppressed. */
130 gfc_query_suppress_errors (void)
132 return suppress_errors
> 0;
136 /* Per-file error initialization. */
139 gfc_error_init_1 (void)
141 gfc_buffer_error (false);
145 /* Set the flag for buffering errors or not. */
148 gfc_buffer_error (bool flag
)
155 print_wide_char_into_buffer (gfc_char_t c
, char *buf
)
157 static const char xdigit
[16] = { '0', '1', '2', '3', '4', '5', '6',
158 '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
160 if (gfc_wide_is_printable (c
) || c
== '\t')
163 /* Tabulation is output as a space. */
164 buf
[0] = (unsigned char) (c
== '\t' ? ' ' : c
);
167 else if (c
< ((gfc_char_t
) 1 << 8))
170 buf
[3] = xdigit
[c
& 0x0F];
172 buf
[2] = xdigit
[c
& 0x0F];
178 else if (c
< ((gfc_char_t
) 1 << 16))
181 buf
[5] = xdigit
[c
& 0x0F];
183 buf
[4] = xdigit
[c
& 0x0F];
185 buf
[3] = xdigit
[c
& 0x0F];
187 buf
[2] = xdigit
[c
& 0x0F];
196 buf
[9] = xdigit
[c
& 0x0F];
198 buf
[8] = xdigit
[c
& 0x0F];
200 buf
[7] = xdigit
[c
& 0x0F];
202 buf
[6] = xdigit
[c
& 0x0F];
204 buf
[5] = xdigit
[c
& 0x0F];
206 buf
[4] = xdigit
[c
& 0x0F];
208 buf
[3] = xdigit
[c
& 0x0F];
210 buf
[2] = xdigit
[c
& 0x0F];
218 static char wide_char_print_buffer
[11];
221 gfc_print_wide_char (gfc_char_t c
)
223 print_wide_char_into_buffer (c
, wide_char_print_buffer
);
224 return wide_char_print_buffer
;
228 /* Clear any output buffered in THIS_BUFFER without issuing
232 gfc_clear_diagnostic_buffer (diagnostic_buffer
*this_buffer
)
234 gcc_assert (this_buffer
);
235 global_dc
->clear_diagnostic_buffer (*this_buffer
);
238 /* The currently-printing diagnostic, for use by gfc_format_decoder,
239 for colorizing %C and %L. */
241 static diagnostic_info
*curr_diagnostic
;
243 /* A helper function to call diagnostic_report_diagnostic, while setting
244 curr_diagnostic for the duration of the call. */
247 gfc_report_diagnostic (diagnostic_info
*diagnostic
)
249 gcc_assert (diagnostic
!= NULL
);
250 curr_diagnostic
= diagnostic
;
251 bool ret
= diagnostic_report_diagnostic (global_dc
, diagnostic
);
252 curr_diagnostic
= NULL
;
256 /* This is just a helper function to avoid duplicating the logic of
260 gfc_warning (int opt
, const char *gmsgid
, va_list ap
)
265 diagnostic_info diagnostic
;
266 rich_location
rich_loc (line_table
, UNKNOWN_LOCATION
);
267 diagnostic_buffer
*old_buffer
= global_dc
->get_diagnostic_buffer ();
268 gcc_assert (!old_buffer
);
270 gfc_clear_diagnostic_buffer (pp_warning_buffer
);
273 global_dc
->set_diagnostic_buffer (pp_warning_buffer
);
275 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, &rich_loc
,
277 diagnostic
.option_id
= opt
;
278 bool ret
= gfc_report_diagnostic (&diagnostic
);
281 global_dc
->set_diagnostic_buffer (old_buffer
);
287 /* Issue a warning. */
290 gfc_warning (int opt
, const char *gmsgid
, ...)
294 va_start (argp
, gmsgid
);
295 bool ret
= gfc_warning (opt
, gmsgid
, argp
);
301 /* Whether, for a feature included in a given standard set (GFC_STD_*),
302 we should issue an error or a warning, or be quiet. */
305 gfc_notification_std (int std
)
309 warning
= ((gfc_option
.warn_std
& std
) != 0) && !inhibit_warnings
;
310 if ((gfc_option
.allow_std
& std
) != 0 && !warning
)
313 return warning
? WARNING
: ERROR
;
317 /* Return a string describing the nature of a standard violation
318 * and/or the relevant version of the standard. */
321 notify_std_msg(int std
)
324 if (std
& GFC_STD_F2023_DEL
)
325 return _("Prohibited in Fortran 2023:");
326 else if (std
& GFC_STD_F2023
)
327 return _("Fortran 2023:");
328 else if (std
& GFC_STD_F2018_DEL
)
329 return _("Fortran 2018 deleted feature:");
330 else if (std
& GFC_STD_F2018_OBS
)
331 return _("Fortran 2018 obsolescent feature:");
332 else if (std
& GFC_STD_F2018
)
333 return _("Fortran 2018:");
334 else if (std
& GFC_STD_F2008_OBS
)
335 return _("Fortran 2008 obsolescent feature:");
336 else if (std
& GFC_STD_F2008
)
337 return "Fortran 2008:";
338 else if (std
& GFC_STD_F2003
)
339 return "Fortran 2003:";
340 else if (std
& GFC_STD_GNU
)
341 return _("GNU Extension:");
342 else if (std
& GFC_STD_LEGACY
)
343 return _("Legacy Extension:");
344 else if (std
& GFC_STD_F95_OBS
)
345 return _("Obsolescent feature:");
346 else if (std
& GFC_STD_F95_DEL
)
347 return _("Deleted feature:");
348 else if (std
& GFC_STD_UNSIGNED
)
349 return _("Unsigned:");
355 /* Possibly issue a warning/error about use of a nonstandard (or deleted)
356 feature. An error/warning will be issued if the currently selected
357 standard does not contain the requested bits. Return false if
358 an error is generated. */
361 gfc_notify_std (int std
, const char *gmsgid
, ...)
364 const char *msg
, *msg2
;
367 /* Determine whether an error or a warning is needed. */
368 const int wstd
= std
& gfc_option
.warn_std
; /* Standard to warn about. */
369 const int estd
= std
& ~gfc_option
.allow_std
; /* Standard to error about. */
370 const bool warning
= (wstd
!= 0) && !inhibit_warnings
;
371 const bool error
= (estd
!= 0);
373 if (!error
&& !warning
)
379 msg
= notify_std_msg (estd
);
381 msg
= notify_std_msg (wstd
);
384 buffer
= (char *) alloca (strlen (msg
) + strlen (msg2
) + 2);
385 strcpy (buffer
, msg
);
386 strcat (buffer
, " ");
387 strcat (buffer
, msg2
);
389 va_start (argp
, gmsgid
);
391 gfc_error_opt (0, buffer
, argp
);
393 gfc_warning (0, buffer
, argp
);
399 return (warning
&& !warnings_are_errors
);
403 /* Called from output_format -- during diagnostic message processing
404 to handle Fortran specific format specifiers with the following meanings:
406 %C Current locus (no argument)
407 %L Takes locus argument
410 gfc_format_decoder (pretty_printer
*pp
, text_info
*text
, const char *spec
,
411 int precision
, bool wide
, bool set_locus
, bool hash
,
412 bool *quoted
, pp_token_list
&formatted_token_list
)
420 static const char *result
[2] = { "(1)", "(2)" };
424 loc
= &gfc_current_locus
;
425 /* Point %C first offending character not the last good one. */
426 if (*loc
->nextc
!= '\0')
430 loc
= va_arg (*text
->m_args_ptr
, locus
*);
432 /* If location[0] != UNKNOWN_LOCATION means that we already
433 processed one of %C/%L. */
434 int loc_num
= text
->get_location (0) == UNKNOWN_LOCATION
? 0 : 1;
435 location_t src_loc
= gfc_get_location_with_offset (loc
, offset
);
436 text
->set_location (loc_num
, src_loc
, SHOW_RANGE_WITH_CARET
);
437 /* Colorize the markers to match the color choices of
438 diagnostic_show_locus (the initial location has a color given
439 by the "kind" of the diagnostic, the secondary location has
441 gcc_assert (curr_diagnostic
!= NULL
);
445 : diagnostic_get_color_for_kind (curr_diagnostic
->kind
));
446 pp_string (pp
, colorize_start (pp_show_color (pp
), color
));
447 pp_string (pp
, result
[loc_num
]);
448 pp_string (pp
, colorize_stop (pp_show_color (pp
)));
452 /* Fall through info the middle-end decoder, as e.g. stor-layout.cc
453 etc. diagnostics can use the FE printer while the FE is still
455 return default_tree_printer (pp
, text
, spec
, precision
, wide
,
456 set_locus
, hash
, quoted
,
457 formatted_token_list
);
461 /* Return a malloc'd string describing the kind of diagnostic. The
462 caller is responsible for freeing the memory. */
464 gfc_diagnostic_build_kind_prefix (diagnostic_context
*context
,
465 const diagnostic_info
*diagnostic
)
467 static const char *const diagnostic_kind_text
[] = {
468 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
469 #include "gfc-diagnostic.def"
470 #undef DEFINE_DIAGNOSTIC_KIND
473 static const char *const diagnostic_kind_color
[] = {
474 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
475 #include "gfc-diagnostic.def"
476 #undef DEFINE_DIAGNOSTIC_KIND
479 gcc_assert (diagnostic
->kind
< DK_LAST_DIAGNOSTIC_KIND
);
480 const char *text
= _(diagnostic_kind_text
[diagnostic
->kind
]);
481 const char *text_cs
= "", *text_ce
= "";
482 pretty_printer
*const pp
= context
->get_reference_printer ();
484 if (diagnostic_kind_color
[diagnostic
->kind
])
486 text_cs
= colorize_start (pp_show_color (pp
),
487 diagnostic_kind_color
[diagnostic
->kind
]);
488 text_ce
= colorize_stop (pp_show_color (pp
));
490 return build_message_string ("%s%s:%s ", text_cs
, text
, text_ce
);
493 /* Return a malloc'd string describing a location. The caller is
494 responsible for freeing the memory. */
496 gfc_diagnostic_build_locus_prefix (const diagnostic_location_print_policy
&loc_policy
,
500 const char *locus_cs
= colorize_start (colorize
, "locus");
501 const char *locus_ce
= colorize_stop (colorize
);
502 return (s
.file
== NULL
503 ? build_message_string ("%s%s:%s", locus_cs
, progname
, locus_ce
)
504 : !strcmp (s
.file
, special_fname_builtin ())
505 ? build_message_string ("%s%s:%s", locus_cs
, s
.file
, locus_ce
)
506 : loc_policy
.show_column_p ()
507 ? build_message_string ("%s%s:%d:%d:%s", locus_cs
, s
.file
, s
.line
,
509 : build_message_string ("%s%s:%d:%s", locus_cs
, s
.file
, s
.line
, locus_ce
));
512 /* Return a malloc'd string describing two locations. The caller is
513 responsible for freeing the memory. */
515 gfc_diagnostic_build_locus_prefix (const diagnostic_location_print_policy
&loc_policy
,
516 expanded_location s
, expanded_location s2
,
519 const char *locus_cs
= colorize_start (colorize
, "locus");
520 const char *locus_ce
= colorize_stop (colorize
);
522 return (s
.file
== NULL
523 ? build_message_string ("%s%s:%s", locus_cs
, progname
, locus_ce
)
524 : !strcmp (s
.file
, special_fname_builtin ())
525 ? build_message_string ("%s%s:%s", locus_cs
, s
.file
, locus_ce
)
526 : loc_policy
.show_column_p ()
527 ? build_message_string ("%s%s:%d:%d-%d:%s", locus_cs
, s
.file
, s
.line
,
528 MIN (s
.column
, s2
.column
),
529 MAX (s
.column
, s2
.column
), locus_ce
)
530 : build_message_string ("%s%s:%d:%s", locus_cs
, s
.file
, s
.line
,
534 /* This function prints the locus (file:line:column), the diagnostic kind
535 (Error, Warning) and (optionally) the relevant lines of code with
536 annotation lines with '1' and/or '2' below them.
538 With -fdiagnostic-show-caret (the default) it prints:
540 [locus of primary range]:
544 Error: Some error at (1)
546 With -fno-diagnostic-show-caret or if the primary range is not
549 [locus of primary range]: Error: Some error at (1) and (2)
552 gfc_diagnostic_text_starter (diagnostic_text_output_format
&text_output
,
553 const diagnostic_info
*diagnostic
)
555 diagnostic_context
*const context
= &text_output
.get_context ();
556 pretty_printer
*const pp
= text_output
.get_printer ();
557 char * kind_prefix
= gfc_diagnostic_build_kind_prefix (context
, diagnostic
);
559 expanded_location s1
= diagnostic_expand_location (diagnostic
);
560 expanded_location s2
;
561 bool one_locus
= diagnostic
->richloc
->get_num_locations () < 2;
562 bool same_locus
= false;
566 s2
= diagnostic_expand_location (diagnostic
, 1);
567 same_locus
= diagnostic_same_line (context
, s1
, s2
);
570 diagnostic_location_print_policy
loc_policy (text_output
);
571 const bool colorize
= pp_show_color (pp
);
572 char * locus_prefix
= (one_locus
|| !same_locus
)
573 ? gfc_diagnostic_build_locus_prefix (loc_policy
, s1
, colorize
)
574 : gfc_diagnostic_build_locus_prefix (loc_policy
, s1
, s2
, colorize
);
576 if (!context
->m_source_printing
.enabled
577 || diagnostic_location (diagnostic
, 0) <= BUILTINS_LOCATION
578 || diagnostic_location (diagnostic
, 0) == context
->m_last_location
)
581 concat (locus_prefix
, " ", kind_prefix
, NULL
));
584 if (one_locus
|| same_locus
)
589 /* In this case, we print the previous locus and prefix as:
591 [locus]:[prefix]: (1)
593 and we flush with a new line before setting the new prefix. */
594 pp_string (pp
, "(1)");
596 locus_prefix
= gfc_diagnostic_build_locus_prefix (loc_policy
, s2
, colorize
);
598 concat (locus_prefix
, " ", kind_prefix
, NULL
));
604 pp_verbatim (pp
, "%s", locus_prefix
);
606 /* Fortran uses an empty line between locus and caret line. */
608 pp_set_prefix (pp
, NULL
);
610 diagnostic_show_locus (context
, diagnostic
->richloc
, diagnostic
->kind
,
612 /* If the caret line was shown, the prefix does not contain the
614 pp_set_prefix (pp
, kind_prefix
);
619 gfc_diagnostic_start_span (const diagnostic_location_print_policy
&loc_policy
,
621 expanded_location exploc
)
623 const bool colorize
= pp_show_color (pp
);
625 = gfc_diagnostic_build_locus_prefix (loc_policy
, exploc
, colorize
);
626 pp_verbatim (pp
, "%s", locus_prefix
);
629 /* Fortran uses an empty line between locus and caret line. */
635 gfc_diagnostic_text_finalizer (diagnostic_text_output_format
&text_output
,
636 const diagnostic_info
*diagnostic ATTRIBUTE_UNUSED
,
637 diagnostic_t orig_diag_kind ATTRIBUTE_UNUSED
)
639 pretty_printer
*const pp
= text_output
.get_printer ();
640 pp_destroy_prefix (pp
);
641 pp_newline_and_flush (pp
);
644 /* Immediate warning (i.e. do not buffer the warning) with an explicit
648 gfc_warning_now_at (location_t loc
, int opt
, const char *gmsgid
, ...)
651 diagnostic_info diagnostic
;
652 rich_location
rich_loc (line_table
, loc
);
655 va_start (argp
, gmsgid
);
656 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, &rich_loc
, DK_WARNING
);
657 diagnostic
.option_id
= opt
;
658 ret
= gfc_report_diagnostic (&diagnostic
);
663 /* Immediate warning (i.e. do not buffer the warning). */
666 gfc_warning_now (int opt
, const char *gmsgid
, ...)
669 diagnostic_info diagnostic
;
670 rich_location
rich_loc (line_table
, UNKNOWN_LOCATION
);
673 va_start (argp
, gmsgid
);
674 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, &rich_loc
,
676 diagnostic
.option_id
= opt
;
677 ret
= gfc_report_diagnostic (&diagnostic
);
682 /* Internal warning, do not buffer. */
685 gfc_warning_internal (int opt
, const char *gmsgid
, ...)
688 diagnostic_info diagnostic
;
689 rich_location
rich_loc (line_table
, UNKNOWN_LOCATION
);
692 va_start (argp
, gmsgid
);
693 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, &rich_loc
,
695 diagnostic
.option_id
= opt
;
696 ret
= gfc_report_diagnostic (&diagnostic
);
701 /* Immediate error (i.e. do not buffer). */
704 gfc_error_now (const char *gmsgid
, ...)
707 diagnostic_info diagnostic
;
708 rich_location
rich_loc (line_table
, UNKNOWN_LOCATION
);
710 error_buffer
->flag
= true;
712 va_start (argp
, gmsgid
);
713 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, &rich_loc
, DK_ERROR
);
714 gfc_report_diagnostic (&diagnostic
);
719 /* Fatal error, never returns. */
722 gfc_fatal_error (const char *gmsgid
, ...)
725 diagnostic_info diagnostic
;
726 rich_location
rich_loc (line_table
, UNKNOWN_LOCATION
);
728 va_start (argp
, gmsgid
);
729 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, &rich_loc
, DK_FATAL
);
730 gfc_report_diagnostic (&diagnostic
);
736 /* Clear the warning flag. */
739 gfc_clear_warning (void)
741 gfc_clear_diagnostic_buffer (pp_warning_buffer
);
745 /* Check to see if any warnings have been saved.
746 If so, print the warning. */
749 gfc_warning_check (void)
751 if (! pp_warning_buffer
->empty_p ())
752 global_dc
->flush_diagnostic_buffer (*pp_warning_buffer
);
756 /* Issue an error. */
759 gfc_error_opt (int opt
, const char *gmsgid
, va_list ap
)
764 if (warnings_not_errors
)
766 gfc_warning (opt
, gmsgid
, argp
);
777 diagnostic_info diagnostic
;
778 rich_location
richloc (line_table
, UNKNOWN_LOCATION
);
779 diagnostic_buffer
*old_buffer
= global_dc
->get_diagnostic_buffer ();
780 gcc_assert (!old_buffer
);
782 gfc_clear_diagnostic_buffer (pp_error_buffer
);
785 global_dc
->set_diagnostic_buffer (pp_error_buffer
);
787 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, &richloc
, DK_ERROR
);
788 gfc_report_diagnostic (&diagnostic
);
791 global_dc
->set_diagnostic_buffer (old_buffer
);
798 gfc_error_opt (int opt
, const char *gmsgid
, ...)
801 va_start (argp
, gmsgid
);
802 gfc_error_opt (opt
, gmsgid
, argp
);
808 gfc_error (const char *gmsgid
, ...)
811 va_start (argp
, gmsgid
);
812 gfc_error_opt (0, gmsgid
, argp
);
817 /* This shouldn't happen... but sometimes does. */
820 gfc_internal_error (const char *gmsgid
, ...)
824 diagnostic_info diagnostic
;
825 rich_location
rich_loc (line_table
, UNKNOWN_LOCATION
);
827 gfc_get_errors (&w
, &e
);
831 va_start (argp
, gmsgid
);
832 diagnostic_set_info (&diagnostic
, gmsgid
, &argp
, &rich_loc
, DK_ICE
);
833 gfc_report_diagnostic (&diagnostic
);
840 /* Clear the error flag when we start to compile a source line. */
843 gfc_clear_error (void)
845 error_buffer
->flag
= false;
846 warnings_not_errors
= false;
847 gfc_clear_diagnostic_buffer (pp_error_buffer
);
851 /* Tests the state of error_flag. */
854 gfc_error_flag_test (void)
856 return (error_buffer
->flag
857 || !pp_error_buffer
->empty_p ());
861 /* Check to see if any errors have been saved.
862 If so, print the error. Returns the state of error_flag. */
865 gfc_error_check (void)
867 if (error_buffer
->flag
868 || ! pp_error_buffer
->empty_p ())
870 error_buffer
->flag
= false;
871 global_dc
->flush_diagnostic_buffer (*pp_error_buffer
);
878 /* Move the text buffered from FROM to TO, then clear
879 FROM. Independently if there was text in FROM, TO is also
883 gfc_move_error_buffer_from_to (gfc_error_buffer
* buffer_from
,
884 gfc_error_buffer
* buffer_to
)
886 diagnostic_buffer
* from
= &(buffer_from
->buffer
);
887 diagnostic_buffer
* to
= &(buffer_to
->buffer
);
889 buffer_to
->flag
= buffer_from
->flag
;
890 buffer_from
->flag
= false;
892 gfc_clear_diagnostic_buffer (to
);
894 if (! from
->empty_p ())
897 gfc_clear_diagnostic_buffer (from
);
901 /* Save the existing error state. */
904 gfc_push_error (gfc_error_buffer
*err
)
906 gfc_move_error_buffer_from_to (error_buffer
, err
);
910 /* Restore a previous pushed error state. */
913 gfc_pop_error (gfc_error_buffer
*err
)
915 gfc_move_error_buffer_from_to (err
, error_buffer
);
919 /* Free a pushed error state, but keep the current error state. */
922 gfc_free_error (gfc_error_buffer
*err
)
924 gfc_clear_diagnostic_buffer (&(err
->buffer
));
928 /* Report the number of warnings and errors that occurred to the caller. */
931 gfc_get_errors (int *w
, int *e
)
934 *w
= warningcount
+ werrorcount
;
936 *e
= errorcount
+ sorrycount
+ werrorcount
;
940 /* Switch errors into warnings. */
943 gfc_errors_to_warnings (bool f
)
945 warnings_not_errors
= f
;
949 gfc_diagnostics_init (void)
951 diagnostic_text_starter (global_dc
) = gfc_diagnostic_text_starter
;
952 diagnostic_start_span (global_dc
) = gfc_diagnostic_start_span
;
953 diagnostic_text_finalizer (global_dc
) = gfc_diagnostic_text_finalizer
;
954 global_dc
->set_format_decoder (gfc_format_decoder
);
955 global_dc
->m_source_printing
.caret_chars
[0] = '1';
956 global_dc
->m_source_printing
.caret_chars
[1] = '2';
957 pp_warning_buffer
= new diagnostic_buffer (*global_dc
);
958 error_buffer
= new gfc_error_buffer ();
959 pp_error_buffer
= &(error_buffer
->buffer
);
963 gfc_diagnostics_finish (void)
965 tree_diagnostics_defaults (global_dc
);
966 /* We still want to use the gfc starter and finalizer, not the tree
968 diagnostic_text_starter (global_dc
) = gfc_diagnostic_text_starter
;
969 diagnostic_text_finalizer (global_dc
) = gfc_diagnostic_text_finalizer
;
970 global_dc
->m_source_printing
.caret_chars
[0] = '^';
971 global_dc
->m_source_printing
.caret_chars
[1] = '^';
973 error_buffer
= nullptr;
974 pp_error_buffer
= nullptr;