OSDN Git Service

* c-errors.c (pedwarn_c99): Adjust call to report_diagnostic.
[pf3gnuchains/gcc-fork.git] / gcc / diagnostic.h
1 /* Various declarations for language-independent diagnostics subroutines.
2    Copyright (C) 2000 Free Software Foundation, Inc.
3    Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #ifndef __GCC_DIAGNOSTIC_H__
23 #define __GCC_DIAGNOSTIC_H__
24
25 #include "obstack.h"
26
27 /*  Forward declarations.  */
28 typedef struct output_buffer output_buffer;
29 typedef struct diagnostic_context diagnostic_context;
30
31 #define DIAGNOSTICS_SHOW_PREFIX_ONCE       0x0
32 #define DIAGNOSTICS_SHOW_PREFIX_NEVER      0x1
33 #define DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE 0x2
34
35 /* The type of front-end specific hook that formats trees into an
36    output_buffer.  A language specific printer returns a truth value if
37    everything goes well. */
38 typedef int (*printer_fn) PARAMS ((output_buffer *));
39
40 /* This data structure encapulates an output_buffer's state.  */
41 typedef struct
42 {
43   /* The prefix for each new line.   */
44   const char *prefix;
45   /* The real upper bound of number of characters per line, taking into
46      accompt the case of a very very looong prefix.  */  
47   int maximum_length;
48   /* The ideal upper bound of number of characters per line, as suggested
49      by front-end. */  
50   int ideal_maximum_length;
51   /* Nonzero if current PREFIX was emitted at least once.  */
52   int emitted_prefix_p;
53   /* Tells how often current PREFIX should be emitted:
54      o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
55      o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit current PREFIX only once;
56      o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit current PREFIX each time
57        a physical line is started.  */
58   int prefixing_rule;
59   /* The current char to output.  Updated by front-end (*format_map) when
60      it is called to report front-end printer for a specified format.  */  
61   const char *cursor;
62   /* A pointer to the variable argument-list for formatting.  */  
63   va_list *format_args;
64 } output_state;
65
66 /* The output buffer datatype.  This is best seen as an abstract datatype.  */
67 struct output_buffer
68 {
69   /* Internal data.  These fields should not be accessed directly by
70      front-ends.  */
71
72   /* The obstack where the text is built up.  */  
73   struct obstack obstack;
74   /* The amount of characters output so far.  */  
75   int line_length;
76   /* The current state of the buffer.  */
77   output_state state;
78 };
79
80 #define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor
81 #define output_buffer_format_args(BUFFER) *((BUFFER)->state.format_args)
82
83 /* This data structure bundles altogether any information relevent to
84    the context of a diagnostic message.  */
85 struct diagnostic_context
86 {
87   /* The diagnostic message to output.  */
88   const char *message;
89
90   /* A pointer to a variable list of the arguments necessary for the
91      purpose of  message formatting.  */
92   va_list *args_ptr;
93
94   /* The name of the source file involved in the diiagnostic.  */     
95   const char *file;
96
97   /* The line-location in the source file.  */
98   int line;
99
100   /* Is it message a warning?  */
101   int warn;
102
103   /* This function is called before any message is printed out.  It is
104      respondible for preparing message prefix and such.  For example, it
105      might say:
106      In file included from "/usr/local/include/curses.h:5:
107                       from "/home/gdr/src/nifty_printer.h:56:
108                       ...
109   */
110   void (*begin_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
111
112   /* This function is called after the diagnostic message is printed.   */
113   void (*end_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
114
115   /* Hook for front-end extensions.  */
116   void *x_data;
117 };
118
119 #define diagnostic_message(DC) (DC)->message
120 #define diagnostic_argument_list(DC) (DC)->args_ptr
121 #define diagnostic_file_location(DC) (DC)->file
122 #define diagnostic_line_location(DC) (DC)->line
123 #define diagnostic_is_warning(DC) (DC)->warn
124 #define diagnostic_starter(DC) (DC)->begin_diagnostic
125 #define diagnostic_finalizer(DC) (DC)->end_diagnostic
126 #define diagnostic_auxiliary_data(DC) (DC)->x_data
127
128 /* If non-NULL, this function formats data in the BUFFER. When called,
129    output_buffer_text_cursor (BUFFER) points to a format code.  LANG_PRINTER
130    should call output_add_string (and related functions) to add data to
131    the BUFFER.  LANG_PRINTER can read arguments from
132    output_buffer_format_args (BUFFER) using VA_ARG.  If the BUFFER needs
133    additional characters from the format string, it should advance
134    the output_buffer_text_cursor (BUFFER) as it goes.  When LANG_PRINTER
135    returns, output_buffer_text_cursor (BUFFER) should point to the last
136    character processed.  */
137
138 extern printer_fn lang_printer;
139
140 extern int diagnostic_message_length_per_line;
141
142 /* This output buffer is used by front-ends that directly output
143    diagnostic messages without going through `error', `warning',
144    and simillar functions.  In general, such usage should be
145    avoided.  This global buffer will go away, once all such usage
146    has been removed.  */
147 extern output_buffer *diagnostic_buffer;
148
149 /* Prototypes */
150 void set_diagnostic_context     PARAMS ((diagnostic_context *, const char *,
151                                          va_list *, const char *, int, int));
152 void set_fatal_function         PARAMS ((void (*) PARAMS ((const char *,
153                                                            va_list *))));
154 void report_diagnostic          PARAMS ((diagnostic_context *));
155 void initialize_diagnostics     PARAMS ((void));
156 void reshape_diagnostic_buffer  PARAMS ((void));
157 void default_initialize_buffer  PARAMS ((output_buffer *));
158 void init_output_buffer         PARAMS ((output_buffer *, const char *, int));
159 void output_clear               PARAMS ((output_buffer *));
160 const char *output_get_prefix   PARAMS ((const output_buffer *));
161 void output_set_prefix          PARAMS ((output_buffer *, const char *));
162 void output_destroy_prefix      PARAMS ((output_buffer *));
163 void output_set_maximum_length  PARAMS ((output_buffer *, int));
164 void output_emit_prefix         PARAMS ((output_buffer *));
165 void output_add_newline         PARAMS ((output_buffer *));
166 void output_add_space           PARAMS ((output_buffer *));
167 int output_space_left           PARAMS ((const output_buffer *));
168 void output_append              PARAMS ((output_buffer *, const char *,
169                                          const char *));
170 void output_add_character       PARAMS ((output_buffer *, int));
171 void output_decimal             PARAMS ((output_buffer *, int));
172 void output_add_string          PARAMS ((output_buffer *, const char *));
173 const char *output_finish       PARAMS ((output_buffer *));
174 void output_printf              PARAMS ((output_buffer *, const char *,
175                                          ...)) ATTRIBUTE_PRINTF_2;
176 int output_is_line_wrapping     PARAMS ((output_buffer *));
177 void set_message_prefixing_rule PARAMS ((int));
178 void output_verbatim            PARAMS ((output_buffer *, const char *, ...))
179      ATTRIBUTE_PRINTF_2;
180 void verbatim PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1;
181
182 #endif /* __GCC_DIAGNOSTIC_H__ */