/* Various declarations for language-independent pretty-print subroutines.
- Copyright (C) 2002-2016 Free Software Foundation, Inc.
+ Copyright (C) 2002-2020 Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
This file is part of GCC.
#define GCC_PRETTY_PRINT_H
#include "obstack.h"
-#include "wide-int-print.h"
+#include "diagnostic-url.h"
/* Maximum number of format string arguments. */
#define PP_NL_ARGMAX 30
void **x_data;
rich_location *m_richloc;
- void set_location (unsigned int idx, location_t loc, bool caret_p);
+ void set_location (unsigned int idx, location_t loc,
+ enum range_display_kind range_display_kind);
location_t get_location (unsigned int index_of_location) const;
};
/* The output buffer datatype. This is best seen as an abstract datatype
whose fields should not be accessed directly by clients. */
-struct output_buffer
+class output_buffer
{
+public:
output_buffer ();
~output_buffer ();
{
gcc_checking_assert (start);
obstack_grow (buff->obstack, start, length);
- buff->line_length += length;
+ for (int i = 0; i < length; i++)
+ if (start[i] == '\n')
+ buff->line_length = 0;
+ else
+ buff->line_length++;
}
/* Return a pointer to the last character emitted in the
A client-supplied formatter returns true if everything goes well,
otherwise it returns false. */
typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *,
- int, bool, bool, bool);
+ int, bool, bool, bool, bool *, const char **);
/* Client supplied function used to decode formats. */
#define pp_format_decoder(PP) (PP)->format_decoder
+/* Base class for an optional client-supplied object for doing additional
+ processing between stages 2 and 3 of formatted printing. */
+class format_postprocessor
+{
+ public:
+ virtual ~format_postprocessor () {}
+ virtual format_postprocessor *clone() const = 0;
+ virtual void handle (pretty_printer *) = 0;
+};
+
/* TRUE if a newline character needs to be added before further
formatting. */
#define pp_needs_newline(PP) (PP)->need_newline
/* The data structure that contains the bare minimum required to do
proper pretty-printing. Clients may derived from this structure
and add additional fields they need. */
-struct pretty_printer
+class pretty_printer
{
- // Default construct a pretty printer with specified prefix
- // and a maximum line length cut off limit.
- explicit pretty_printer (const char* = NULL, int = 0);
+public:
+ /* Default construct a pretty printer with specified
+ maximum line length cut off limit. */
+ explicit pretty_printer (int = 0);
+ explicit pretty_printer (const pretty_printer &other);
virtual ~pretty_printer ();
+ virtual pretty_printer *clone () const;
+
/* Where we print external representation of ENTITY. */
output_buffer *buffer;
- /* The prefix for each new line. */
- const char *prefix;
+ /* The prefix for each new line. If non-NULL, this is "owned" by the
+ pretty_printer, and will eventually be free-ed. */
+ char *prefix;
/* Where to put whitespace around the entity being formatted. */
pp_padding padding;
If the BUFFER needs additional characters from the format string, it
should advance the TEXT->format_spec as it goes. When FORMAT_DECODER
returns, TEXT->format_spec should point to the last character processed.
- */
+ The QUOTE and BUFFER_PTR are passed in, to allow for deferring-handling
+ of format codes (e.g. %H and %I in the C++ frontend). */
printer_fn format_decoder;
+ /* If non-NULL, this is called by pp_format once after all format codes
+ have been processed, to allow for client-specific postprocessing.
+ This is used by the C++ frontend for handling the %H and %I
+ format codes (which interract with each other). */
+ format_postprocessor *m_format_postprocessor;
+
/* Nonzero if current PREFIX was emitted at least once. */
bool emitted_prefix;
/* Nonzero means that text should be colorized. */
bool show_color;
+
+ /* Whether URLs should be emitted, and which terminator to use. */
+ diagnostic_url_format url_format;
};
static inline const char *
pp_string (PP, pp_buffer (PP)->digit_buffer); \
} \
while (0)
-#define pp_wide_integer(PP, I) \
- pp_scalar (PP, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) I)
+#define pp_double(PP, F) pp_scalar (PP, "%f", F)
#define pp_pointer(PP, P) pp_scalar (PP, "%p", P)
#define pp_identifier(PP, ID) pp_string (PP, (pp_translate_identifiers (PP) \
#define pp_buffer(PP) (PP)->buffer
extern void pp_set_line_maximum_length (pretty_printer *, int);
-extern void pp_set_prefix (pretty_printer *, const char *);
+extern void pp_set_prefix (pretty_printer *, char *);
+extern char *pp_take_prefix (pretty_printer *);
extern void pp_destroy_prefix (pretty_printer *);
extern int pp_remaining_character_count_for_line (pretty_printer *);
extern void pp_clear_output_area (pretty_printer *);
extern void pp_newline (pretty_printer *);
extern void pp_character (pretty_printer *, int);
extern void pp_string (pretty_printer *, const char *);
+
extern void pp_write_text_to_stream (pretty_printer *);
extern void pp_write_text_as_dot_label_to_stream (pretty_printer *, bool);
+extern void pp_write_text_as_html_like_dot_to_stream (pretty_printer *pp);
+
extern void pp_maybe_space (pretty_printer *);
+extern void pp_begin_quote (pretty_printer *, bool);
+extern void pp_end_quote (pretty_printer *, bool);
+
+extern void pp_begin_url (pretty_printer *pp, const char *url);
+extern void pp_end_url (pretty_printer *pp);
+
/* Switch into verbatim mode and return the old mode. */
static inline pp_wrapping_mode_t
pp_set_verbatim_wrapping_ (pretty_printer *pp)
extern void *(*identifier_to_locale_alloc) (size_t);
extern void (*identifier_to_locale_free) (void *);
+/* Print I to PP in decimal. */
+
+inline void
+pp_wide_integer (pretty_printer *pp, HOST_WIDE_INT i)
+{
+ pp_scalar (pp, HOST_WIDE_INT_PRINT_DEC, i);
+}
+
+template<unsigned int N, typename T>
+void pp_wide_integer (pretty_printer *pp, const poly_int_pod<N, T> &);
+
#endif /* GCC_PRETTY_PRINT_H */