]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/pretty-print.h
Merge tree-ssa-20020619-branch into mainline.
[thirdparty/gcc.git] / gcc / pretty-print.h
CommitLineData
6aaae39a 1/* Various declarations for language-independent pretty-print subroutines.
ef335eb8 2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
6aaae39a
GDR
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
4
5This file is part of GCC.
6
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.
11
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.
16
17You should have received a copy of the GNU General Public License
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. */
21
22#ifndef GCC_PRETTY_PRINT_H
23#define GCC_PRETTY_PRINT_H
24
b6fe0bb8
GDR
25#include "obstack.h"
26#include "input.h"
27
28/* The type of a text to be formatted according a format specification
29 along with a list of things. */
30typedef struct
31{
32 const char *format_spec;
33 va_list *args_ptr;
34 int err_no; /* for %m */
35} text_info;
36
37/* How often diagnostics are prefixed by their locations:
38 o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
39 o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once;
40 o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical
41 line is started. */
42typedef enum
43{
44 DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0,
45 DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1,
46 DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2
47} diagnostic_prefixing_rule_t;
48
49/* The output buffer datatype. This is best seen as an abstract datatype
50 whose fields should not be accessed directly by clients. */
51typedef struct
52{
53 /* The obstack where the text is built up. */
54 struct obstack obstack;
55
56 /* Where to output formatted text. */
57 FILE *stream;
58
59 /* The amount of characters output so far. */
60 int line_length;
61
62 /* This must be large enough to hold any printed integer or
63 floating-point value. */
64 char digit_buffer[128];
65} output_buffer;
6aaae39a 66
6aaae39a
GDR
67/* The type of pretty-printer flags passed to clients. */
68typedef unsigned int pp_flags;
69
f63c45ec 70typedef enum
6aaae39a 71{
26ff2117 72 pp_none, pp_before, pp_after
f63c45ec 73} pp_padding;
6aaae39a 74
b6fe0bb8
GDR
75/* The type of a hook that formats client-specific data onto a pretty_pinter.
76 A client-supplied formatter returns true if everything goes well,
77 otherwise it returns false. */
78typedef struct pretty_print_info pretty_printer;
79typedef bool (*printer_fn) (pretty_printer *, text_info *);
80
81/* Client supplied function used to decode formats. */
82#define pp_format_decoder(PP) pp_base (PP)->format_decoder
83
84/* TRUE if a newline character needs to be added before further
85 formatting. */
86#define pp_needs_newline(PP) pp_base (PP)->need_newline
87
88/* Maximum characters per line in automatic line wrapping mode.
89 Zero means don't wrap lines. */
90#define pp_line_cutoff(PP) pp_base (PP)->ideal_maximum_length
91
92/* True if PRETTY-PTINTER is in line-wrapping mode. */
93#define pp_is_wrapping_line(PP) (pp_line_cutoff (PP) > 0)
94
95/* Prefixing rule used in formatting a diagnostic message. */
96#define pp_prefixing_rule(PP) pp_base (PP)->prefixing_rule
97
98/* The amount of whitespace to be emitted when starting a new line. */
99#define pp_indentation(PP) pp_base (PP)->indent_skip
100
101/* The data structure that contains the bare minimum required to do
102 proper pretty-printing. Clients may derived from this structure
103 and add additional fields they need. */
6aaae39a
GDR
104struct pretty_print_info
105{
6aaae39a
GDR
106 /* Where we print external representation of ENTITY. */
107 output_buffer *buffer;
b6fe0bb8
GDR
108
109 /* The prefix for each new line. */
110 const char *prefix;
b6fe0bb8 111
f63c45ec
GDR
112 /* Where to put whitespace around the entity being formatted. */
113 pp_padding padding;
b6fe0bb8
GDR
114
115 /* The real upper bound of number of characters per line, taking into
116 account the case of a very very looong prefix. */
117 int maximum_length;
118
119 /* The ideal upper bound of number of characters per line, as suggested
120 by front-end. */
121 int ideal_maximum_length;
122
123 /* Indentation count. */
124 int indent_skip;
125
126 /* Current prefixing rule. */
127 diagnostic_prefixing_rule_t prefixing_rule;
128
129 /* If non-NULL, this function formats a TEXT into the BUFFER. When called,
130 TEXT->format_spec points to a format code. FORMAT_DECODER should call
131 pp_string (and related functions) to add data to the BUFFER.
132 FORMAT_DECODER can read arguments from *TEXT->args_pts using VA_ARG.
133 If the BUFFER needs additional characters from the format string, it
134 should advance the TEXT->format_spec as it goes. When FORMAT_DECODER
135 returns, TEXT->format_spec should point to the last character processed.
136 */
137 printer_fn format_decoder;
138
139 /* Nonzero if current PREFIX was emitted at least once. */
140 bool emitted_prefix;
141
142 /* Nonzero means one should emit a newline before outputting anything. */
143 bool need_newline;
6aaae39a
GDR
144};
145
e1a4dd13
GDR
146#define pp_set_line_maximum_length(PP, L) \
147 pp_base_set_line_maximum_length (pp_base (PP), L)
148#define pp_set_prefix(PP, P) pp_base_set_prefix (pp_base (PP), P)
149#define pp_destroy_prefix(PP) pp_base_destroy_prefix (pp_base (PP))
150#define pp_remaining_character_count_for_line(PP) \
151 pp_base_remaining_character_count_for_line (pp_base (PP))
152#define pp_clear_output_area(PP) \
153 pp_base_clear_output_area (pp_base (PP))
154#define pp_formatted_text(PP) pp_base_formatted_text (pp_base (PP))
155#define pp_last_position_in_text(PP) \
156 pp_base_last_position_in_text (pp_base (PP))
157#define pp_emit_prefix(PP) pp_base_emit_prefix (pp_base (PP))
158#define pp_append_text(PP, B, E) \
159 pp_base_append_text (pp_base (PP), B, E)
160#define pp_flush(PP) pp_base_flush (pp_base (PP))
161#define pp_format_text(PP, TI) pp_base_format_text (pp_base (PP), TI)
162#define pp_format_verbatim(PP, TI) \
163 pp_base_format_verbatim (pp_base (PP), TI)
164
8f7ace48
GDR
165#define pp_character(PP, C) pp_base_character (pp_base (PP), C)
166#define pp_string(PP, S) pp_base_string (pp_base (PP), S)
167#define pp_newline(PP) pp_base_newline (pp_base (PP))
e1a4dd13 168
8f7ace48
GDR
169#define pp_space(PP) pp_character (PP, ' ')
170#define pp_left_paren(PP) pp_character (PP, '(')
171#define pp_right_paren(PP) pp_character (PP, ')')
172#define pp_left_bracket(PP) pp_character (PP, '[')
173#define pp_right_bracket(PP) pp_character (PP, ']')
174#define pp_left_brace(PP) pp_character (PP, '{')
175#define pp_right_brace(PP) pp_character (PP, '}')
176#define pp_semicolon(PP) pp_character (PP, ';')
177#define pp_comma(PP) pp_string (PP, ", ")
178#define pp_dot(PP) pp_character (PP, '.')
179#define pp_colon(PP) pp_character (PP, ':')
180#define pp_colon_colon(PP) pp_string (PP, "::")
181#define pp_arrow(PP) pp_string (PP, "->")
182#define pp_equal(PP) pp_character (PP, '=')
183#define pp_question(PP) pp_character (PP, '?')
184#define pp_bar(PP) pp_character (PP, '|')
185#define pp_carret(PP) pp_character (PP, '^')
186#define pp_ampersand(PP) pp_character (PP, '&')
187#define pp_less(PP) pp_character (PP, '<')
188#define pp_greater(PP) pp_character (PP, '>')
189#define pp_plus(PP) pp_character (PP, '+')
190#define pp_minus(PP) pp_character (PP, '-')
191#define pp_star(PP) pp_character (PP, '*')
192#define pp_slash(PP) pp_character (PP, '/')
193#define pp_modulo(PP) pp_character (PP, '%')
194#define pp_exclamation(PP) pp_character (PP, '!')
195#define pp_complement(PP) pp_character (PP, '~')
196#define pp_quote(PP) pp_character (PP, '\'')
197#define pp_backquote(PP) pp_character (PP, '`')
198#define pp_doublequote(PP) pp_character (PP, '"')
b6fe0bb8
GDR
199#define pp_newline_and_indent(PP, N) \
200 do { \
201 pp_indentation (PP) += N; \
202 pp_newline (PP); \
4b780675
GDR
203 pp_base_indent (pp_base (PP)); \
204 pp_needs_newline (PP) = false; \
f63c45ec 205 } while (0)
12ea3302
GDR
206#define pp_maybe_newline_and_indent(PP, N) \
207 if (pp_needs_newline (PP)) pp_newline_and_indent (PP, N)
b9b44fb9 208#define pp_maybe_space(PP) pp_base_maybe_space (pp_base (PP))
b6fe0bb8
GDR
209#define pp_separate_with(PP, C) \
210 do { \
8f7ace48 211 pp_character (PP, C); \
b6fe0bb8 212 pp_space (PP); \
f63c45ec 213 } while (0)
8f7ace48
GDR
214#define pp_scalar(PP, FORMAT, SCALAR) \
215 do \
216 { \
217 sprintf (pp_buffer (PP)->digit_buffer, FORMAT, SCALAR); \
218 pp_string (PP, pp_buffer (PP)->digit_buffer); \
219 } \
b6fe0bb8
GDR
220 while (0)
221#define pp_decimal_int(PP, I) pp_scalar (PP, "%d", I)
222#define pp_wide_integer(PP, I) \
223 pp_scalar (PP, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) I)
224#define pp_pointer(PP, P) pp_scalar (PP, "%p", P)
6aaae39a 225
8f7ace48 226#define pp_identifier(PP, ID) pp_string (PP, ID)
b6fe0bb8 227#define pp_tree_identifier(PP, T) \
e1a4dd13 228 pp_append_text(PP, IDENTIFIER_POINTER (T), \
b6fe0bb8 229 IDENTIFIER_POINTER (T) + IDENTIFIER_LENGTH (T))
26ff2117 230
8f7ace48
GDR
231#define pp_unsupported_tree(PP, T) \
232 pp_verbatim (pp_base (PP), "#`%s' not supported by %s#", \
233 tree_code_name[(int) TREE_CODE (T)], __FUNCTION__)
26ff2117 234
b6fe0bb8 235
8f7ace48 236#define pp_buffer(PP) pp_base (PP)->buffer
b6fe0bb8 237/* Clients that directly derive from pretty_printer need to override
d91edf86 238 this macro to return a pointer to the base pretty_printer structure. */
b6fe0bb8
GDR
239#define pp_base(PP) (PP)
240
241extern void pp_construct (pretty_printer *, const char *, int);
e1a4dd13
GDR
242extern void pp_base_set_line_maximum_length (pretty_printer *, int);
243extern void pp_base_set_prefix (pretty_printer *, const char *);
244extern void pp_base_destroy_prefix (pretty_printer *);
245extern int pp_base_remaining_character_count_for_line (pretty_printer *);
246extern void pp_base_clear_output_area (pretty_printer *);
247extern const char *pp_base_formatted_text (pretty_printer *);
248extern const char *pp_base_last_position_in_text (const pretty_printer *);
249extern void pp_base_emit_prefix (pretty_printer *);
250extern void pp_base_append_text (pretty_printer *, const char *, const char *);
b6fe0bb8
GDR
251extern void pp_printf (pretty_printer *, const char *, ...) ATTRIBUTE_PRINTF_2;
252extern void pp_verbatim (pretty_printer *, const char *, ...);
e1a4dd13
GDR
253extern void pp_base_flush (pretty_printer *);
254extern void pp_base_format_text (pretty_printer *, text_info *);
255extern void pp_base_format_verbatim (pretty_printer *, text_info *);
b6fe0bb8 256
4b780675 257extern void pp_base_indent (pretty_printer *);
8f7ace48
GDR
258extern void pp_base_newline (pretty_printer *);
259extern void pp_base_character (pretty_printer *, int);
260extern void pp_base_string (pretty_printer *, const char *);
6de9cd9a 261extern void pp_write_text_to_stream (pretty_printer *pp);
b9b44fb9 262extern void pp_base_maybe_space (pretty_printer *);
b6fe0bb8 263
6aaae39a 264#endif /* GCC_PRETTY_PRINT_H */