OSDN Git Service

2000-07-12 Gabriel Dos Reis <gdr@codesourcery.com>
[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
30 #define DIAGNOSTICS_SHOW_PREFIX_ONCE       0x0
31 #define DIAGNOSTICS_SHOW_PREFIX_NEVER      0x1
32 #define DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE 0x2
33
34 /* The type of front-end specific hook that formats trees into an
35    output_buffer.  A language specific printer returns a truth value if
36    everything goes well. */
37 typedef int (*printer_fn) PARAMS ((output_buffer *));
38
39 /* This data structure encapulates an output_buffer's state.  */
40 typedef struct
41 {
42   /* The prefix for each new line.   */
43   const char *prefix;
44   /* The real upper bound of number of characters per line, taking into
45      accompt the case of a very very looong prefix.  */  
46   int maximum_length;
47   /* The ideal upper bound of number of characters per line, as suggested
48      by front-end. */  
49   int ideal_maximum_length;
50   /* Nonzero if current PREFIX was emitted at least once.  */
51   int emitted_prefix_p;
52   /* Tells how often current PREFIX should be emitted:
53      o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
54      o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit current PREFIX only once;
55      o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit current PREFIX each time
56        a physical line is started.  */
57   int prefixing_rule;
58   /* The current char to output.  Updated by front-end (*format_map) when
59      it is called to report front-end printer for a specified format.  */  
60   const char *cursor;
61   /* A pointer to the variable argument-list for formatting.  */  
62   va_list *format_args;
63 } output_state;
64
65 /* The output buffer datatype.  This is best seen as an abstract datatype.  */
66 struct output_buffer
67 {
68   /* Internal data.  These fields should not be accessed directly by
69      front-ends.  */
70
71   /* The obstack where the text is built up.  */  
72   struct obstack obstack;
73   /* The amount of characters output so far.  */  
74   int line_length;
75   /* The current state of the buffer.  */
76   output_state state;
77 };
78
79 #define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor
80 #define output_buffer_format_args(BUFFER) *((BUFFER)->state.format_args)
81
82 /* If non-NULL, this function formats data in the BUFFER. When called,
83    output_buffer_text_cursor (BUFFER) points to a format code.  LANG_PRINTER
84    should call output_add_string (and related functions) to add data to
85    the BUFFER.  LANG_PRINTER can read arguments from
86    output_buffer_format_args (BUFFER) using VA_ARG.  If the BUFFER needs
87    additional characters from the format string, it should advance
88    the output_buffer_text_cursor (BUFFER) as it goes.  When LANG_PRINTER
89    returns, output_buffer_text_cursor (BUFFER) should point to the last
90    character processed.  */
91
92 extern printer_fn lang_printer;
93
94 extern int diagnostic_message_length_per_line;
95
96 /* This output buffer is used by front-ends that directly output
97    diagnostic messages without going through `error', `warning',
98    and simillar functions.  In general, such usage should be
99    avoided.  This global buffer will go away, once all such usage
100    has been removed.  */
101 extern output_buffer *diagnostic_buffer;
102
103 /* Prototypes */
104 void report_diagnostic          PARAMS ((const char *, va_list,
105                                          const char *, int, int));
106 void initialize_diagnostics     PARAMS ((void));
107 void reshape_diagnostic_buffer  PARAMS ((void));
108 void default_initialize_buffer  PARAMS ((output_buffer *));
109 void init_output_buffer         PARAMS ((output_buffer *, const char *, int));
110 void output_clear               PARAMS ((output_buffer *));
111 const char *output_get_prefix   PARAMS ((const output_buffer *));
112 void output_set_prefix          PARAMS ((output_buffer *, const char *));
113 void output_destroy_prefix      PARAMS ((output_buffer *));
114 void output_set_maximum_length  PARAMS ((output_buffer *, int));
115 void output_emit_prefix         PARAMS ((output_buffer *));
116 void output_add_newline         PARAMS ((output_buffer *));
117 void output_add_space           PARAMS ((output_buffer *));
118 int output_space_left           PARAMS ((const output_buffer *));
119 void output_append              PARAMS ((output_buffer *, const char *,
120                                          const char *));
121 void output_add_character       PARAMS ((output_buffer *, int));
122 void output_decimal             PARAMS ((output_buffer *, int));
123 void output_add_string          PARAMS ((output_buffer *, const char *));
124 const char *output_finish       PARAMS ((output_buffer *));
125 void output_printf              PARAMS ((output_buffer *, const char *,
126                                          ...)) ATTRIBUTE_PRINTF_2;
127 int output_is_line_wrapping     PARAMS ((output_buffer *));
128 void set_message_prefixing_rule PARAMS ((int));
129 void output_verbatim            PARAMS ((output_buffer *, const char *, ...))
130      ATTRIBUTE_PRINTF_2;
131 void verbatim PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1;
132
133 #endif /* __GCC_DIAGNOSTIC_H__ */