| 1 |
/* Various declarations for language-independent pretty-print subroutines. |
| 2 |
Copyright (C) 2002-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Gabriel Dos Reis <[email protected]> |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 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 |
| 10 |
version. |
| 11 |
|
| 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 |
| 15 |
for more details. |
| 16 |
|
| 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/>. */ |
| 20 |
|
| 21 |
#ifndef GCC_PRETTY_PRINT_H |
| 22 |
#define GCC_PRETTY_PRINT_H |
| 23 |
|
| 24 |
#include "obstack.h" |
| 25 |
#include "rich-location.h" |
| 26 |
#include "diagnostic-url.h" |
| 27 |
|
| 28 |
/* Maximum number of format string arguments. */ |
| 29 |
#define PP_NL_ARGMAX 30 |
| 30 |
|
| 31 |
/* The type of a text to be formatted according a format specification |
| 32 |
along with a list of things. */ |
| 33 |
struct text_info |
| 34 |
{ |
| 35 |
text_info () = default; |
| 36 |
text_info (const char *format_spec, |
| 37 |
va_list *args_ptr, |
| 38 |
int err_no, |
| 39 |
void **data = nullptr, |
| 40 |
rich_location *rich_loc = nullptr) |
| 41 |
: m_format_spec (format_spec), |
| 42 |
m_args_ptr (args_ptr), |
| 43 |
m_err_no (err_no), |
| 44 |
m_data (data), |
| 45 |
m_richloc (rich_loc) |
| 46 |
{ |
| 47 |
} |
| 48 |
|
| 49 |
void set_location (unsigned int idx, location_t loc, |
| 50 |
enum range_display_kind range_display_kind); |
| 51 |
location_t get_location (unsigned int index_of_location) const; |
| 52 |
|
| 53 |
const char *m_format_spec; |
| 54 |
va_list *m_args_ptr; |
| 55 |
int m_err_no; /* for %m */ |
| 56 |
void **m_data; |
| 57 |
rich_location *m_richloc; |
| 58 |
}; |
| 59 |
|
| 60 |
/* How often diagnostics are prefixed by their locations: |
| 61 |
o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported; |
| 62 |
o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once; |
| 63 |
o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical |
| 64 |
line is started. */ |
| 65 |
enum diagnostic_prefixing_rule_t |
| 66 |
{ |
| 67 |
DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0, |
| 68 |
DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1, |
| 69 |
DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2 |
| 70 |
}; |
| 71 |
|
| 72 |
class pp_formatted_chunks; |
| 73 |
class output_buffer; |
| 74 |
class pp_token_list; |
| 75 |
class urlifier; |
| 76 |
|
| 77 |
namespace pp_markup { |
| 78 |
class context; |
| 79 |
} // namespace pp_markup |
| 80 |
|
| 81 |
/* The output buffer datatype. This is best seen as an abstract datatype |
| 82 |
whose fields should not be accessed directly by clients. */ |
| 83 |
class output_buffer |
| 84 |
{ |
| 85 |
public: |
| 86 |
output_buffer (); |
| 87 |
output_buffer (const output_buffer &) = delete; |
| 88 |
output_buffer (output_buffer &&) = delete; |
| 89 |
~output_buffer (); |
| 90 |
output_buffer & operator= (const output_buffer &) = delete; |
| 91 |
output_buffer & operator= (output_buffer &&) = delete; |
| 92 |
|
| 93 |
pp_formatted_chunks *push_formatted_chunks (); |
| 94 |
void pop_formatted_chunks (); |
| 95 |
|
| 96 |
void dump (FILE *out, int indent) const; |
| 97 |
void DEBUG_FUNCTION dump () const { dump (stderr, 0); } |
| 98 |
|
| 99 |
/* Obstack where the text is built up. */ |
| 100 |
struct obstack m_formatted_obstack; |
| 101 |
|
| 102 |
/* Obstack containing a chunked representation of the format |
| 103 |
specification plus arguments. */ |
| 104 |
struct obstack m_chunk_obstack; |
| 105 |
|
| 106 |
/* Currently active obstack: one of the above two. This is used so |
| 107 |
that the text formatters don't need to know which phase we're in. */ |
| 108 |
struct obstack *m_obstack; |
| 109 |
|
| 110 |
/* Topmost element in a stack of arrays of formatted chunks. |
| 111 |
These come from the chunk_obstack. */ |
| 112 |
pp_formatted_chunks *m_cur_formatted_chunks; |
| 113 |
|
| 114 |
/* Where to output formatted text. */ |
| 115 |
FILE *m_stream; |
| 116 |
|
| 117 |
/* The amount of characters output so far. */ |
| 118 |
int m_line_length; |
| 119 |
|
| 120 |
/* This must be large enough to hold any printed integer or |
| 121 |
floating-point value. */ |
| 122 |
char m_digit_buffer[128]; |
| 123 |
|
| 124 |
/* Nonzero means that text should be flushed when |
| 125 |
appropriate. Otherwise, text is buffered until either |
| 126 |
pp_really_flush or pp_clear_output_area are called. */ |
| 127 |
bool m_flush_p; |
| 128 |
}; |
| 129 |
|
| 130 |
/* Finishes constructing a NULL-terminated character string representing |
| 131 |
the buffered text. */ |
| 132 |
inline const char * |
| 133 |
output_buffer_formatted_text (output_buffer *buff) |
| 134 |
{ |
| 135 |
obstack_1grow (buff->m_obstack, '\0'); |
| 136 |
return (const char *) obstack_base (buff->m_obstack); |
| 137 |
} |
| 138 |
|
| 139 |
/* Append to the output buffer a string specified by its |
| 140 |
STARTing character and LENGTH. */ |
| 141 |
inline void |
| 142 |
output_buffer_append_r (output_buffer *buff, const char *start, int length) |
| 143 |
{ |
| 144 |
gcc_checking_assert (start); |
| 145 |
obstack_grow (buff->m_obstack, start, length); |
| 146 |
for (int i = 0; i < length; i++) |
| 147 |
if (start[i] == '\n') |
| 148 |
buff->m_line_length = 0; |
| 149 |
else |
| 150 |
buff->m_line_length++; |
| 151 |
} |
| 152 |
|
| 153 |
/* Return a pointer to the last character emitted in the |
| 154 |
output_buffer. A NULL pointer means no character available. */ |
| 155 |
inline const char * |
| 156 |
output_buffer_last_position_in_text (const output_buffer *buff) |
| 157 |
{ |
| 158 |
const char *p = NULL; |
| 159 |
struct obstack *text = buff->m_obstack; |
| 160 |
|
| 161 |
if (obstack_base (text) != obstack_next_free (text)) |
| 162 |
p = ((const char *) obstack_next_free (text)) - 1; |
| 163 |
return p; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
/* The type of pretty-printer flags passed to clients. */ |
| 168 |
typedef unsigned int pp_flags; |
| 169 |
|
| 170 |
enum pp_padding |
| 171 |
{ |
| 172 |
pp_none, pp_before, pp_after |
| 173 |
}; |
| 174 |
|
| 175 |
/* Structure for switching in and out of verbatim mode in a convenient |
| 176 |
manner. */ |
| 177 |
struct pp_wrapping_mode_t |
| 178 |
{ |
| 179 |
/* Current prefixing rule. */ |
| 180 |
diagnostic_prefixing_rule_t rule; |
| 181 |
|
| 182 |
/* The ideal upper bound of number of characters per line, as suggested |
| 183 |
by front-end. */ |
| 184 |
int line_cutoff; |
| 185 |
}; |
| 186 |
|
| 187 |
/* The type of a hook that formats client-specific data onto a pretty_printer. |
| 188 |
A client-supplied formatter returns true if everything goes well, |
| 189 |
otherwise it returns false. */ |
| 190 |
typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *, |
| 191 |
int, bool, bool, bool, bool *, pp_token_list &); |
| 192 |
|
| 193 |
/* Base class for an optional client-supplied object for doing additional |
| 194 |
processing between stages 2 and 3 of formatted printing. */ |
| 195 |
class format_postprocessor |
| 196 |
{ |
| 197 |
public: |
| 198 |
virtual ~format_postprocessor () {} |
| 199 |
virtual format_postprocessor *clone() const = 0; |
| 200 |
virtual void handle (pretty_printer *) = 0; |
| 201 |
}; |
| 202 |
|
| 203 |
/* Abstract base class for writing formatted tokens to the pretty_printer's |
| 204 |
text buffer, allowing for output formats and dumpfiles to override |
| 205 |
how different kinds of tokens are handled. */ |
| 206 |
|
| 207 |
class token_printer |
| 208 |
{ |
| 209 |
public: |
| 210 |
virtual ~token_printer () {} |
| 211 |
virtual void print_tokens (pretty_printer *pp, |
| 212 |
const pp_token_list &tokens) = 0; |
| 213 |
}; |
| 214 |
|
| 215 |
inline bool & pp_needs_newline (pretty_printer *pp); |
| 216 |
|
| 217 |
/* True if PRETTY-PRINTER is in line-wrapping mode. */ |
| 218 |
#define pp_is_wrapping_line(PP) (pp_line_cutoff (PP) > 0) |
| 219 |
|
| 220 |
inline output_buffer *&pp_buffer (pretty_printer *pp); |
| 221 |
inline output_buffer *pp_buffer (const pretty_printer *pp); |
| 222 |
inline const char *pp_get_prefix (const pretty_printer *pp); |
| 223 |
extern char *pp_take_prefix (pretty_printer *); |
| 224 |
extern void pp_destroy_prefix (pretty_printer *); |
| 225 |
inline int &pp_line_cutoff (pretty_printer *pp); |
| 226 |
inline diagnostic_prefixing_rule_t &pp_prefixing_rule (pretty_printer *pp); |
| 227 |
inline pp_wrapping_mode_t &pp_wrapping_mode (pretty_printer *pp); |
| 228 |
inline int & pp_indentation (pretty_printer *pp); |
| 229 |
inline bool & pp_translate_identifiers (pretty_printer *pp); |
| 230 |
inline bool & pp_show_color (pretty_printer *pp); |
| 231 |
inline printer_fn &pp_format_decoder (pretty_printer *pp); |
| 232 |
inline format_postprocessor *& pp_format_postprocessor (pretty_printer *pp); |
| 233 |
inline bool & pp_show_highlight_colors (pretty_printer *pp); |
| 234 |
|
| 235 |
class urlifier; |
| 236 |
|
| 237 |
/* The data structure that contains the bare minimum required to do |
| 238 |
proper pretty-printing. Clients may derive from this structure |
| 239 |
and add additional fields they need. */ |
| 240 |
class pretty_printer |
| 241 |
{ |
| 242 |
public: |
| 243 |
friend inline output_buffer *&pp_buffer (pretty_printer *pp); |
| 244 |
friend inline output_buffer *pp_buffer (const pretty_printer *pp); |
| 245 |
friend inline const char *pp_get_prefix (const pretty_printer *pp); |
| 246 |
friend char *pp_take_prefix (pretty_printer *); |
| 247 |
friend void pp_destroy_prefix (pretty_printer *); |
| 248 |
friend inline int &pp_line_cutoff (pretty_printer *pp); |
| 249 |
friend inline diagnostic_prefixing_rule_t & |
| 250 |
pp_prefixing_rule (pretty_printer *pp); |
| 251 |
friend inline const diagnostic_prefixing_rule_t & |
| 252 |
pp_prefixing_rule (const pretty_printer *pp); |
| 253 |
friend inline pp_wrapping_mode_t &pp_wrapping_mode (pretty_printer *pp); |
| 254 |
friend bool & pp_needs_newline (pretty_printer *pp); |
| 255 |
friend int & pp_indentation (pretty_printer *pp); |
| 256 |
friend bool & pp_translate_identifiers (pretty_printer *pp); |
| 257 |
friend bool & pp_show_color (pretty_printer *pp); |
| 258 |
friend printer_fn &pp_format_decoder (pretty_printer *pp); |
| 259 |
friend format_postprocessor *& pp_format_postprocessor (pretty_printer *pp); |
| 260 |
friend bool & pp_show_highlight_colors (pretty_printer *pp); |
| 261 |
|
| 262 |
friend void pp_output_formatted_text (pretty_printer *, |
| 263 |
const urlifier *); |
| 264 |
|
| 265 |
/* Default construct a pretty printer with specified |
| 266 |
maximum line length cut off limit. */ |
| 267 |
explicit pretty_printer (int = 0); |
| 268 |
explicit pretty_printer (const pretty_printer &other); |
| 269 |
|
| 270 |
virtual ~pretty_printer (); |
| 271 |
|
| 272 |
virtual std::unique_ptr<pretty_printer> clone () const; |
| 273 |
|
| 274 |
void set_output_stream (FILE *outfile) |
| 275 |
{ |
| 276 |
m_buffer->m_stream = outfile; |
| 277 |
} |
| 278 |
|
| 279 |
void set_token_printer (token_printer* tp) |
| 280 |
{ |
| 281 |
m_token_printer = tp; // borrowed |
| 282 |
} |
| 283 |
|
| 284 |
void set_prefix (char *prefix); |
| 285 |
|
| 286 |
void emit_prefix (); |
| 287 |
|
| 288 |
void format (text_info &text); |
| 289 |
|
| 290 |
void maybe_space (); |
| 291 |
|
| 292 |
bool supports_urls_p () const { return m_url_format != URL_FORMAT_NONE; } |
| 293 |
diagnostic_url_format get_url_format () const { return m_url_format; } |
| 294 |
void set_url_format (diagnostic_url_format url_format) |
| 295 |
{ |
| 296 |
m_url_format = url_format; |
| 297 |
} |
| 298 |
|
| 299 |
void begin_url (const char *url); |
| 300 |
void end_url (); |
| 301 |
|
| 302 |
/* Switch into verbatim mode and return the old mode. */ |
| 303 |
pp_wrapping_mode_t |
| 304 |
set_verbatim_wrapping () |
| 305 |
{ |
| 306 |
const pp_wrapping_mode_t oldmode = pp_wrapping_mode (this); |
| 307 |
pp_line_cutoff (this) = 0; |
| 308 |
pp_prefixing_rule (this) = DIAGNOSTICS_SHOW_PREFIX_NEVER; |
| 309 |
return oldmode; |
| 310 |
} |
| 311 |
|
| 312 |
void set_padding (pp_padding padding) { m_padding = padding; } |
| 313 |
pp_padding get_padding () const { return m_padding; } |
| 314 |
|
| 315 |
void clear_state (); |
| 316 |
void set_real_maximum_length (); |
| 317 |
int remaining_character_count_for_line (); |
| 318 |
|
| 319 |
void dump (FILE *out, int indent) const; |
| 320 |
void DEBUG_FUNCTION dump () const { dump (stderr, 0); } |
| 321 |
|
| 322 |
private: |
| 323 |
/* Where we print external representation of ENTITY. */ |
| 324 |
output_buffer *m_buffer; |
| 325 |
|
| 326 |
/* The prefix for each new line. If non-NULL, this is "owned" by the |
| 327 |
pretty_printer, and will eventually be free-ed. */ |
| 328 |
char *m_prefix; |
| 329 |
|
| 330 |
/* Where to put whitespace around the entity being formatted. */ |
| 331 |
pp_padding m_padding; |
| 332 |
|
| 333 |
/* The real upper bound of number of characters per line, taking into |
| 334 |
account the case of a very very looong prefix. */ |
| 335 |
int m_maximum_length; |
| 336 |
|
| 337 |
/* Indentation count. */ |
| 338 |
int m_indent_skip; |
| 339 |
|
| 340 |
/* Current wrapping mode. */ |
| 341 |
pp_wrapping_mode_t m_wrapping; |
| 342 |
|
| 343 |
/* If non-NULL, this function formats a TEXT into the BUFFER. When called, |
| 344 |
TEXT->format_spec points to a format code. FORMAT_DECODER should call |
| 345 |
pp_string (and related functions) to add data to the BUFFER. |
| 346 |
FORMAT_DECODER can read arguments from *TEXT->args_pts using VA_ARG. |
| 347 |
If the BUFFER needs additional characters from the format string, it |
| 348 |
should advance the TEXT->format_spec as it goes. When FORMAT_DECODER |
| 349 |
returns, TEXT->format_spec should point to the last character processed. |
| 350 |
The QUOTE and FORMATTED_TOKEN_LIST are passed in, to allow for |
| 351 |
deferring-handling of format codes (e.g. %H and %I in |
| 352 |
the C++ frontend). */ |
| 353 |
printer_fn m_format_decoder; |
| 354 |
|
| 355 |
/* If non-NULL, this is called by pp_format once after all format codes |
| 356 |
have been processed, to allow for client-specific postprocessing. |
| 357 |
This is used by the C++ frontend for handling the %H and %I |
| 358 |
format codes (which interract with each other). */ |
| 359 |
format_postprocessor *m_format_postprocessor; |
| 360 |
|
| 361 |
/* This is used by pp_output_formatted_text after it has converted all |
| 362 |
formatted chunks into a single list of tokens. |
| 363 |
Can be nullptr. |
| 364 |
Borrowed from the output format or from dump_pretty_printer. */ |
| 365 |
token_printer *m_token_printer; |
| 366 |
|
| 367 |
/* Nonzero if current PREFIX was emitted at least once. */ |
| 368 |
bool m_emitted_prefix; |
| 369 |
|
| 370 |
/* Nonzero means one should emit a newline before outputting anything. */ |
| 371 |
bool m_need_newline; |
| 372 |
|
| 373 |
/* Nonzero means identifiers are translated to the locale character |
| 374 |
set on output. */ |
| 375 |
bool m_translate_identifiers; |
| 376 |
|
| 377 |
/* Nonzero means that text should be colorized. */ |
| 378 |
bool m_show_color; |
| 379 |
|
| 380 |
/* True means that pertinent sections within the text should be |
| 381 |
highlighted with color. */ |
| 382 |
bool m_show_highlight_colors; |
| 383 |
|
| 384 |
/* Whether URLs should be emitted, and which terminator to use. */ |
| 385 |
diagnostic_url_format m_url_format; |
| 386 |
|
| 387 |
/* If true, then we've had a begin_url (nullptr), and so the |
| 388 |
next end_url should be a no-op. */ |
| 389 |
bool m_skipping_null_url; |
| 390 |
}; |
| 391 |
|
| 392 |
inline output_buffer *& |
| 393 |
pp_buffer (pretty_printer *pp) |
| 394 |
{ |
| 395 |
return pp->m_buffer; |
| 396 |
} |
| 397 |
|
| 398 |
inline output_buffer * |
| 399 |
pp_buffer (const pretty_printer *pp) |
| 400 |
{ |
| 401 |
return pp->m_buffer; |
| 402 |
} |
| 403 |
|
| 404 |
inline const char * |
| 405 |
pp_get_prefix (const pretty_printer *pp) |
| 406 |
{ |
| 407 |
return pp->m_prefix; |
| 408 |
} |
| 409 |
|
| 410 |
/* TRUE if a newline character needs to be added before further |
| 411 |
formatting. */ |
| 412 |
inline bool & |
| 413 |
pp_needs_newline (pretty_printer *pp) |
| 414 |
{ |
| 415 |
return pp->m_need_newline; |
| 416 |
} |
| 417 |
|
| 418 |
/* The amount of whitespace to be emitted when starting a new line. */ |
| 419 |
inline int & |
| 420 |
pp_indentation (pretty_printer *pp) |
| 421 |
{ |
| 422 |
return pp->m_indent_skip; |
| 423 |
} |
| 424 |
|
| 425 |
/* True if identifiers are translated to the locale character set on |
| 426 |
output. */ |
| 427 |
inline bool & |
| 428 |
pp_translate_identifiers (pretty_printer *pp) |
| 429 |
{ |
| 430 |
return pp->m_translate_identifiers; |
| 431 |
} |
| 432 |
|
| 433 |
/* True if colors should be shown. */ |
| 434 |
inline bool & |
| 435 |
pp_show_color (pretty_printer *pp) |
| 436 |
{ |
| 437 |
return pp->m_show_color; |
| 438 |
} |
| 439 |
|
| 440 |
inline printer_fn & |
| 441 |
pp_format_decoder (pretty_printer *pp) |
| 442 |
{ |
| 443 |
return pp->m_format_decoder; |
| 444 |
} |
| 445 |
|
| 446 |
inline format_postprocessor *& |
| 447 |
pp_format_postprocessor (pretty_printer *pp) |
| 448 |
{ |
| 449 |
return pp->m_format_postprocessor; |
| 450 |
} |
| 451 |
|
| 452 |
inline bool & |
| 453 |
pp_show_highlight_colors (pretty_printer *pp) |
| 454 |
{ |
| 455 |
return pp->m_show_highlight_colors; |
| 456 |
} |
| 457 |
|
| 458 |
/* Maximum characters per line in automatic line wrapping mode. |
| 459 |
Zero means don't wrap lines. */ |
| 460 |
inline int & |
| 461 |
pp_line_cutoff (pretty_printer *pp) |
| 462 |
{ |
| 463 |
return pp->m_wrapping.line_cutoff; |
| 464 |
} |
| 465 |
|
| 466 |
/* Prefixing rule used in formatting a diagnostic message. */ |
| 467 |
inline diagnostic_prefixing_rule_t & |
| 468 |
pp_prefixing_rule (pretty_printer *pp) |
| 469 |
{ |
| 470 |
return pp->m_wrapping.rule; |
| 471 |
} |
| 472 |
inline const diagnostic_prefixing_rule_t & |
| 473 |
pp_prefixing_rule (const pretty_printer *pp) |
| 474 |
{ |
| 475 |
return pp->m_wrapping.rule; |
| 476 |
} |
| 477 |
|
| 478 |
/* Get or set the wrapping mode as a single entity. */ |
| 479 |
inline pp_wrapping_mode_t & |
| 480 |
pp_wrapping_mode (pretty_printer *pp) |
| 481 |
{ |
| 482 |
return pp->m_wrapping; |
| 483 |
} |
| 484 |
|
| 485 |
#define pp_space(PP) pp_character (PP, ' ') |
| 486 |
#define pp_left_paren(PP) pp_character (PP, '(') |
| 487 |
#define pp_right_paren(PP) pp_character (PP, ')') |
| 488 |
#define pp_left_bracket(PP) pp_character (PP, '[') |
| 489 |
#define pp_right_bracket(PP) pp_character (PP, ']') |
| 490 |
#define pp_left_brace(PP) pp_character (PP, '{') |
| 491 |
#define pp_right_brace(PP) pp_character (PP, '}') |
| 492 |
#define pp_semicolon(PP) pp_character (PP, ';') |
| 493 |
#define pp_comma(PP) pp_character (PP, ',') |
| 494 |
#define pp_dot(PP) pp_character (PP, '.') |
| 495 |
#define pp_colon(PP) pp_character (PP, ':') |
| 496 |
#define pp_colon_colon(PP) pp_string (PP, "::") |
| 497 |
#define pp_arrow(PP) pp_string (PP, "->") |
| 498 |
#define pp_equal(PP) pp_character (PP, '=') |
| 499 |
#define pp_question(PP) pp_character (PP, '?') |
| 500 |
#define pp_bar(PP) pp_character (PP, '|') |
| 501 |
#define pp_bar_bar(PP) pp_string (PP, "||") |
| 502 |
#define pp_carret(PP) pp_character (PP, '^') |
| 503 |
#define pp_ampersand(PP) pp_character (PP, '&') |
| 504 |
#define pp_ampersand_ampersand(PP) pp_string (PP, "&&") |
| 505 |
#define pp_less(PP) pp_character (PP, '<') |
| 506 |
#define pp_less_equal(PP) pp_string (PP, "<=") |
| 507 |
#define pp_greater(PP) pp_character (PP, '>') |
| 508 |
#define pp_greater_equal(PP) pp_string (PP, ">=") |
| 509 |
#define pp_plus(PP) pp_character (PP, '+') |
| 510 |
#define pp_minus(PP) pp_character (PP, '-') |
| 511 |
#define pp_star(PP) pp_character (PP, '*') |
| 512 |
#define pp_slash(PP) pp_character (PP, '/') |
| 513 |
#define pp_modulo(PP) pp_character (PP, '%') |
| 514 |
#define pp_exclamation(PP) pp_character (PP, '!') |
| 515 |
#define pp_complement(PP) pp_character (PP, '~') |
| 516 |
#define pp_quote(PP) pp_character (PP, '\'') |
| 517 |
#define pp_backquote(PP) pp_character (PP, '`') |
| 518 |
#define pp_doublequote(PP) pp_character (PP, '"') |
| 519 |
#define pp_underscore(PP) pp_character (PP, '_') |
| 520 |
#define pp_maybe_newline_and_indent(PP, N) \ |
| 521 |
if (pp_needs_newline (PP)) pp_newline_and_indent (PP, N) |
| 522 |
#define pp_scalar(PP, FORMAT, SCALAR) \ |
| 523 |
do \ |
| 524 |
{ \ |
| 525 |
sprintf (pp_buffer (PP)->m_digit_buffer, FORMAT, SCALAR); \ |
| 526 |
pp_string (PP, pp_buffer (PP)->m_digit_buffer); \ |
| 527 |
} \ |
| 528 |
while (0) |
| 529 |
#define pp_decimal_int(PP, I) pp_scalar (PP, "%d", I) |
| 530 |
#define pp_unsigned_wide_integer(PP, I) \ |
| 531 |
pp_scalar (PP, HOST_WIDE_INT_PRINT_UNSIGNED, (unsigned HOST_WIDE_INT) I) |
| 532 |
#define pp_vrange(PP, R) \ |
| 533 |
do \ |
| 534 |
{ \ |
| 535 |
vrange_printer vrange_pp (PP); \ |
| 536 |
(R)->accept (vrange_pp); \ |
| 537 |
} \ |
| 538 |
while (0) |
| 539 |
#define pp_double(PP, F) pp_scalar (PP, "%f", F) |
| 540 |
#define pp_pointer(PP, P) pp_scalar (PP, "%p", P) |
| 541 |
|
| 542 |
#define pp_identifier(PP, ID) pp_string (PP, (pp_translate_identifiers (PP) \ |
| 543 |
? identifier_to_locale (ID) \ |
| 544 |
: (ID))) |
| 545 |
|
| 546 |
|
| 547 |
extern void pp_set_line_maximum_length (pretty_printer *, int); |
| 548 |
inline void pp_set_prefix (pretty_printer *pp, char *prefix) |
| 549 |
{ |
| 550 |
pp->set_prefix (prefix); |
| 551 |
} |
| 552 |
extern void pp_clear_output_area (pretty_printer *); |
| 553 |
extern const char *pp_formatted_text (pretty_printer *); |
| 554 |
extern const char *pp_last_position_in_text (const pretty_printer *); |
| 555 |
inline void pp_emit_prefix (pretty_printer *pp) |
| 556 |
{ |
| 557 |
pp->emit_prefix (); |
| 558 |
} |
| 559 |
extern void pp_append_text (pretty_printer *, const char *, const char *); |
| 560 |
extern void pp_newline_and_flush (pretty_printer *); |
| 561 |
extern void pp_newline_and_indent (pretty_printer *, int); |
| 562 |
extern void pp_separate_with (pretty_printer *, char); |
| 563 |
|
| 564 |
/* If we haven't already defined a front-end-specific diagnostics |
| 565 |
style, use the generic one. */ |
| 566 |
#ifdef GCC_DIAG_STYLE |
| 567 |
#define GCC_PPDIAG_STYLE GCC_DIAG_STYLE |
| 568 |
#else |
| 569 |
#define GCC_PPDIAG_STYLE __gcc_diag__ |
| 570 |
#endif |
| 571 |
|
| 572 |
/* This header may be included before diagnostics-core.h, hence the duplicate |
| 573 |
definitions to allow for GCC-specific formats. */ |
| 574 |
#if GCC_VERSION >= 3005 |
| 575 |
#define ATTRIBUTE_GCC_PPDIAG(m, n) __attribute__ ((__format__ (GCC_PPDIAG_STYLE, m ,n))) ATTRIBUTE_NONNULL(m) |
| 576 |
#else |
| 577 |
#define ATTRIBUTE_GCC_PPDIAG(m, n) ATTRIBUTE_NONNULL(m) |
| 578 |
#endif |
| 579 |
extern void pp_printf (pretty_printer *, const char *, ...) |
| 580 |
ATTRIBUTE_GCC_PPDIAG(2,3); |
| 581 |
|
| 582 |
extern void pp_printf_n (pretty_printer *, unsigned HOST_WIDE_INT n, |
| 583 |
const char *, const char *, ...) |
| 584 |
ATTRIBUTE_GCC_PPDIAG(3,5) |
| 585 |
ATTRIBUTE_GCC_PPDIAG(4,5); |
| 586 |
|
| 587 |
extern void pp_verbatim (pretty_printer *, const char *, ...) |
| 588 |
ATTRIBUTE_GCC_PPDIAG(2,3); |
| 589 |
extern void pp_flush (pretty_printer *); |
| 590 |
extern void pp_really_flush (pretty_printer *); |
| 591 |
inline void pp_format (pretty_printer *pp, text_info *text) |
| 592 |
{ |
| 593 |
gcc_assert (text); |
| 594 |
pp->format (*text); |
| 595 |
} |
| 596 |
extern void pp_output_formatted_text (pretty_printer *, |
| 597 |
const urlifier * = nullptr); |
| 598 |
extern void pp_format_verbatim (pretty_printer *, text_info *); |
| 599 |
|
| 600 |
extern void pp_indent (pretty_printer *); |
| 601 |
extern void pp_newline (pretty_printer *); |
| 602 |
extern void pp_character (pretty_printer *, int); |
| 603 |
extern void pp_string (pretty_printer *, const char *); |
| 604 |
extern void pp_string_n (pretty_printer *, const char *, size_t); |
| 605 |
extern void pp_unicode_character (pretty_printer *, unsigned); |
| 606 |
|
| 607 |
extern void pp_write_text_to_stream (pretty_printer *); |
| 608 |
extern void pp_write_text_as_dot_label_to_stream (pretty_printer *, bool); |
| 609 |
extern void pp_write_text_as_html_like_dot_to_stream (pretty_printer *pp); |
| 610 |
|
| 611 |
inline void pp_maybe_space (pretty_printer *pp) |
| 612 |
{ |
| 613 |
pp->maybe_space (); |
| 614 |
} |
| 615 |
|
| 616 |
extern void pp_begin_quote (pretty_printer *, bool); |
| 617 |
extern void pp_end_quote (pretty_printer *, bool); |
| 618 |
|
| 619 |
inline void |
| 620 |
pp_begin_url (pretty_printer *pp, const char *url) |
| 621 |
{ |
| 622 |
pp->begin_url (url); |
| 623 |
} |
| 624 |
|
| 625 |
inline void |
| 626 |
pp_end_url (pretty_printer *pp) |
| 627 |
{ |
| 628 |
pp->end_url (); |
| 629 |
} |
| 630 |
|
| 631 |
/* Switch into verbatim mode and return the old mode. */ |
| 632 |
inline pp_wrapping_mode_t |
| 633 |
pp_set_verbatim_wrapping (pretty_printer *pp) |
| 634 |
{ |
| 635 |
return pp->set_verbatim_wrapping (); |
| 636 |
} |
| 637 |
|
| 638 |
extern const char *identifier_to_locale (const char *); |
| 639 |
extern void *(*identifier_to_locale_alloc) (size_t); |
| 640 |
extern void (*identifier_to_locale_free) (void *); |
| 641 |
|
| 642 |
/* Print I to PP in decimal. */ |
| 643 |
|
| 644 |
inline void |
| 645 |
pp_wide_integer (pretty_printer *pp, HOST_WIDE_INT i) |
| 646 |
{ |
| 647 |
pp_scalar (pp, HOST_WIDE_INT_PRINT_DEC, i); |
| 648 |
} |
| 649 |
|
| 650 |
inline void |
| 651 |
pp_wide_int (pretty_printer *pp, const wide_int_ref &w, signop sgn) |
| 652 |
{ |
| 653 |
unsigned int len; |
| 654 |
print_dec_buf_size (w, sgn, &len); |
| 655 |
if (UNLIKELY (len > sizeof (pp_buffer (pp)->m_digit_buffer))) |
| 656 |
pp_wide_int_large (pp, w, sgn); |
| 657 |
else |
| 658 |
{ |
| 659 |
print_dec (w, pp_buffer (pp)->m_digit_buffer, sgn); |
| 660 |
pp_string (pp, pp_buffer (pp)->m_digit_buffer); |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
template<unsigned int N, typename T> |
| 665 |
void pp_wide_integer (pretty_printer *pp, const poly_int<N, T> &); |
| 666 |
|
| 667 |
#endif /* GCC_PRETTY_PRINT_H */ |