]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/diagnostic.h
Merge tree-ssa-20020619-branch into mainline.
[thirdparty/gcc.git] / gcc / diagnostic.h
CommitLineData
993ca5a5 1/* Various declarations for language-independent diagnostics subroutines.
093936a9 2 Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
993ca5a5 3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4
f12b58b3 5This file is part of GCC.
993ca5a5 6
f12b58b3 7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
993ca5a5 11
f12b58b3 12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
993ca5a5 16
17You should have received a copy of the GNU General Public License
f12b58b3 18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
993ca5a5 21
2a281353 22#ifndef GCC_DIAGNOSTIC_H
23#define GCC_DIAGNOSTIC_H
993ca5a5 24
aa6db498 25#include "pretty-print.h"
993ca5a5 26
917bbcab 27/* Constants used to discriminate diagnostics. */
79bef68a 28typedef enum
29{
32a99bf2 30#define DEFINE_DIAGNOSTIC_KIND(K, msgid) K,
79bef68a 31#include "diagnostic.def"
32#undef DEFINE_DIAGNOSTIC_KIND
33 DK_LAST_DIAGNOSTIC_KIND
34} diagnostic_t;
35
25e2ffe1 36/* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
37 its context and its KIND (ice, error, warning, note, ...) See complete
38 list in diagnostic.def. */
39typedef struct
40{
41 text_info message;
42 location_t location;
43 /* The kind of diagnostic it is about. */
44 diagnostic_t kind;
45} diagnostic_info;
46
79bef68a 47#define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
48
b38e286c 49
25e2ffe1 50/* Forward declarations. */
51typedef struct diagnostic_context diagnostic_context;
d598ad0d 52typedef void (*diagnostic_starter_fn) (diagnostic_context *,
53 diagnostic_info *);
25e2ffe1 54typedef diagnostic_starter_fn diagnostic_finalizer_fn;
55
b52baaa6 56/* This data structure bundles altogether any information relevant to
92d99247 57 the context of a diagnostic message. */
58struct diagnostic_context
59{
ca1fae79 60 /* Where most of the diagnostic formatting work is done. */
aa6db498 61 pretty_printer *printer;
ce601f29 62
5397e5a3 63 /* The number of times we have issued diagnostics. */
64 int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
65
a787dd05 66 /* True if we should display the "warnings are being tread as error"
67 message, usually displayed once per compiler run. */
68 bool warnings_are_errors_message;
69
5f07bab0 70 /* True if we should raise a SIGABRT on errors. */
71 bool abort_on_error;
72
92d99247 73 /* This function is called before any message is printed out. It is
b52baaa6 74 responsible for preparing message prefix and such. For example, it
92d99247 75 might say:
76 In file included from "/usr/local/include/curses.h:5:
77 from "/home/gdr/src/nifty_printer.h:56:
78 ...
79 */
25e2ffe1 80 diagnostic_starter_fn begin_diagnostic;
92d99247 81
a7dce381 82 /* This function is called after the diagnostic message is printed. */
25e2ffe1 83 diagnostic_finalizer_fn end_diagnostic;
92d99247 84
c003992a 85 /* Client hook to report an internal error. */
d598ad0d 86 void (*internal_error) (const char *, va_list *);
c003992a 87
25e2ffe1 88 /* Function of last diagnostic message; more generally, function such that
89 if next diagnostic message is in it then we don't have to mention the
90 function name. */
91 tree last_function;
92
93 /* Used to detect when input_file_stack has changed since last described. */
94 int last_module;
95
96 int lock;
97
92d99247 98 /* Hook for front-end extensions. */
99 void *x_data;
100};
101
910f6d8f 102/* Client supplied function to announce a diagnostic. */
92d99247 103#define diagnostic_starter(DC) (DC)->begin_diagnostic
910f6d8f 104
105/* Client supplied function called after a diagnostic message is
106 displayed. */
92d99247 107#define diagnostic_finalizer(DC) (DC)->end_diagnostic
910f6d8f 108
dd5b4b36 109/* Extension hook for client. */
92d99247 110#define diagnostic_auxiliary_data(DC) (DC)->x_data
910f6d8f 111
aa6db498 112/* Same as pp_format_decoder. Works on 'diagnostic_context *'. */
0de2b732 113#define diagnostic_format_decoder(DC) ((DC)->printer->format_decoder)
910f6d8f 114
06c7407c 115/* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */
aa6db498 116#define diagnostic_prefixing_rule(DC) ((DC)->printer->prefixing_rule)
92d99247 117
b165d8b0 118/* Maximum characters per line in automatic line wrapping mode.
88b5b080 119 Zero means don't wrap lines. */
aa6db498 120#define diagnostic_line_cutoff(DC) ((DC)->printer->ideal_maximum_length)
121
0de2b732 122#define diagnostic_flush_buffer(DC) pp_base_flush ((DC)->printer)
06c7407c 123
25e2ffe1 124/* True if the last function in which a diagnostic was reported is
125 different from the current one. */
126#define diagnostic_last_function_changed(DC) \
127 ((DC)->last_function != current_function_decl)
128
129/* Remember the current function as being the last one in which we report
130 a diagnostic. */
131#define diagnostic_set_last_function(DC) \
132 (DC)->last_function = current_function_decl
133
134/* True if the last module or file in which a diagnostic was reported is
135 different from the current one. */
136#define diagnostic_last_module_changed(DC) \
137 ((DC)->last_module != input_file_stack_tick)
06c7407c 138
25e2ffe1 139/* Remember the current module or file as being the last one in which we
140 report a diagnostic. */
141#define diagnostic_set_last_module(DC) \
142 (DC)->last_module = input_file_stack_tick
990339dd 143
5f07bab0 144/* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
145#define diagnostic_abort_on_error(DC) \
146 (DC)->abort_on_error = true
147
5397e5a3 148/* This diagnostic_context is used by front-ends that directly output
990339dd 149 diagnostic messages without going through `error', `warning',
910f6d8f 150 and similar functions. */
ce601f29 151extern diagnostic_context *global_dc;
990339dd 152
5f07bab0 153/* The total count of a KIND of diagnostics emitted so far. */
5397e5a3 154#define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)]
a587b03b 155
156/* The number of errors that have been issued so far. Ideally, these
5397e5a3 157 would take a diagnostic_context as an argument. */
910f6d8f 158#define errorcount diagnostic_kind_count (global_dc, DK_ERROR)
a587b03b 159/* Similarly, but for warnings. */
910f6d8f 160#define warningcount diagnostic_kind_count (global_dc, DK_WARNING)
a587b03b 161/* Similarly, but for sorrys. */
910f6d8f 162#define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
a587b03b 163
6ef828f9 164/* Returns nonzero if warnings should be emitted. */
a587b03b 165#define diagnostic_report_warnings_p() \
166 (!inhibit_warnings \
167 && !(in_system_header && !warn_system_headers))
168
25e2ffe1 169#define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D)
a587b03b 170
d716ce75 171/* Diagnostic related functions. */
d598ad0d 172extern void diagnostic_initialize (diagnostic_context *);
173extern void diagnostic_report_current_module (diagnostic_context *);
174extern void diagnostic_report_current_function (diagnostic_context *);
d598ad0d 175extern void diagnostic_report_diagnostic (diagnostic_context *,
176 diagnostic_info *);
177extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
648a8029 178 location_t, diagnostic_t);
d598ad0d 179extern char *diagnostic_build_prefix (diagnostic_info *);
25e2ffe1 180
181/* Pure text formatting support functions. */
00d25971 182extern void verbatim (const char *, ...);
d598ad0d 183extern char *file_name_as_prefix (const char *);
993ca5a5 184
4ee9c684 185extern void debug_output_buffer (pretty_printer *);
186
187/* In tree-pretty-print.c */
188extern int dump_generic_node (pretty_printer *, tree, int, int, bool);
189extern void print_generic_stmt (FILE *, tree, int);
190extern void print_generic_stmt_indented (FILE *, tree, int, int);
191extern void print_generic_expr (FILE *, tree, int);
192extern void print_generic_decl (FILE *, tree, int);
193
194extern void debug_generic_expr (tree);
195extern void debug_generic_stmt (tree);
196extern void debug_c_tree (tree);
2a281353 197#endif /* ! GCC_DIAGNOSTIC_H */