summaryrefslogtreecommitdiff
path: root/gcc/pretty-print.h
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-30 23:09:06 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-30 23:09:06 +0000
commitc907c5b1c101b68b89d1530b7ae8b47dff169617 (patch)
treeaaf251a28f0a2167060005edc8eb763baadddd63 /gcc/pretty-print.h
parenta55dc2cd86f718c1ad76ce7d418c9a8a44b2440b (diff)
downloadgcc-c907c5b1c101b68b89d1530b7ae8b47dff169617.tar.gz
gcc:
* pretty-print.h (PP_NL_ARGMAX): New. (text_info): Add locus. (struct chunk_info): New. (output_buffer): Add formatted_obstack, chunk_obstack, and cur_chunk_array. Change obstack to a pointer. (pp_wrapping_mode_t, pp_wrapping_mode, pp_set_verbatim_wrapping): New. (struct pretty_print_info): Replace ideal_maximum_length and prefixing_rule with wrapping. (pp_line_cutoff, pp_prefixing_rule): Update to match. Update prototypes and wrapper macros throughout. * pretty-print.c (pp_formatted_text_data, pp_append_r) (pp_base_clear_output_area, pp_construct, pp_base_formatted_text) (pp_base_last_position_in_text, pp_base_newline, pp_base_character): Update for changes to pp structure. (pp_base_prepare_to_format, pp_base_format_text): Delete. (pp_base_format, pp_base_output_formatted_text): New functions. (pp_base_format_verbatim): Use pp_set_verbatim_wrapping. (pp_verbatim): Clear text.locus. (pp_printf): Likewise. Use pp_format and pp_output_formatted_text. * c-objc-common.c (c_tree_printer): Update function signature. * diagnostic.c (diagnostic_initialize): Update for changes to pp structure. (diagnostic_report_diagnostic): Call pp_format and then pp_output_formatted_text. (verbatim): Clear text.locus. * diagnostic.h (diagnostic_prefixing_rule, diagnostic_line_cutoff): Update for changes to pp structure. * c-lang.c: No need to include c-pretty-print.h. * Makefile.in: Remove bogus line containing only a tab. (c-lang.o): Update dependencies. * toplev.c (announce_function): Don't use verbatim. (default_tree_printer): Update signature. * objc/objc-lang.c: No need to include c-pretty-print.h. * objc/Make-lang.in: Update dependencies. gcc/cp: * cp-lang.c: No need to include cxx-pretty-print.h. * error.c (cp_printer): Update signature. No need to process flags. (print_instantiation_partial_context): Output last newline with pp_base_newline. * Make-lang.in: Update dependencies. gcc/objcp: * objcp-lang.c: No need to include cxx-pretty-print.h. * Make-lang.in: Update dependencies. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101481 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/pretty-print.h')
-rw-r--r--gcc/pretty-print.h100
1 files changed, 78 insertions, 22 deletions
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h
index f71541871d3..b587e600882 100644
--- a/gcc/pretty-print.h
+++ b/gcc/pretty-print.h
@@ -25,6 +25,9 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
#include "obstack.h"
#include "input.h"
+/* Maximum number of format string arguments. */
+#define PP_NL_ARGMAX 30
+
/* The type of a text to be formatted according a format specification
along with a list of things. */
typedef struct
@@ -32,6 +35,7 @@ typedef struct
const char *format_spec;
va_list *args_ptr;
int err_no; /* for %m */
+ location_t *locus;
} text_info;
/* How often diagnostics are prefixed by their locations:
@@ -46,12 +50,42 @@ typedef enum
DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2
} diagnostic_prefixing_rule_t;
+/* The chunk_info data structure forms a stack of the results from the
+ first phase of formatting (pp_base_format) which have not yet been
+ output (pp_base_output_formatted_text). A stack is necessary because
+ the diagnostic starter may decide to generate its own output by way
+ of the formatter. */
+struct chunk_info
+{
+ /* Pointer to previous chunk on the stack. */
+ struct chunk_info *prev;
+
+ /* Array of chunks to output. Each chunk is a NUL-terminated string.
+ In the first phase of formatting, even-numbered chunks are
+ to be output verbatim, odd-numbered chunks are format specifiers.
+ The second phase replaces all odd-numbered chunks with formatted
+ text, and the third phase simply emits all the chunks in sequence
+ with appropriate line-wrapping. */
+ const char *args[PP_NL_ARGMAX * 2];
+};
+
/* The output buffer datatype. This is best seen as an abstract datatype
whose fields should not be accessed directly by clients. */
typedef struct
{
- /* The obstack where the text is built up. */
- struct obstack obstack;
+ /* Obstack where the text is built up. */
+ struct obstack formatted_obstack;
+
+ /* Obstack containing a chunked representation of the format
+ specification plus arguments. */
+ struct obstack chunk_obstack;
+
+ /* Currently active obstack: one of the above two. This is used so
+ that the text formatters don't need to know which phase we're in. */
+ struct obstack *obstack;
+
+ /* Stack of chunk arrays. These come from the chunk_obstack. */
+ struct chunk_info *cur_chunk_array;
/* Where to output formatted text. */
FILE *stream;
@@ -72,11 +106,34 @@ typedef enum
pp_none, pp_before, pp_after
} pp_padding;
+/* Structure for switching in and out of verbatim mode in a convenient
+ manner. */
+typedef struct
+{
+ /* Current prefixing rule. */
+ diagnostic_prefixing_rule_t rule;
+
+ /* The ideal upper bound of number of characters per line, as suggested
+ by front-end. */
+ int line_cutoff;
+} pp_wrapping_mode_t;
+
+/* Maximum characters per line in automatic line wrapping mode.
+ Zero means don't wrap lines. */
+#define pp_line_cutoff(PP) pp_base (PP)->wrapping.line_cutoff
+
+/* Prefixing rule used in formatting a diagnostic message. */
+#define pp_prefixing_rule(PP) pp_base (PP)->wrapping.rule
+
+/* Get or set the wrapping mode as a single entity. */
+#define pp_wrapping_mode(PP) pp_base (PP)->wrapping
+
/* The type of a hook that formats client-specific data onto a pretty_pinter.
A client-supplied formatter returns true if everything goes well,
otherwise it returns false. */
typedef struct pretty_print_info pretty_printer;
-typedef bool (*printer_fn) (pretty_printer *, text_info *);
+typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *,
+ int, bool, bool, bool);
/* Client supplied function used to decode formats. */
#define pp_format_decoder(PP) pp_base (PP)->format_decoder
@@ -85,16 +142,9 @@ typedef bool (*printer_fn) (pretty_printer *, text_info *);
formatting. */
#define pp_needs_newline(PP) pp_base (PP)->need_newline
-/* Maximum characters per line in automatic line wrapping mode.
- Zero means don't wrap lines. */
-#define pp_line_cutoff(PP) pp_base (PP)->ideal_maximum_length
-
/* True if PRETTY-PTINTER is in line-wrapping mode. */
#define pp_is_wrapping_line(PP) (pp_line_cutoff (PP) > 0)
-/* Prefixing rule used in formatting a diagnostic message. */
-#define pp_prefixing_rule(PP) pp_base (PP)->prefixing_rule
-
/* The amount of whitespace to be emitted when starting a new line. */
#define pp_indentation(PP) pp_base (PP)->indent_skip
@@ -116,15 +166,11 @@ struct pretty_print_info
account the case of a very very looong prefix. */
int maximum_length;
- /* The ideal upper bound of number of characters per line, as suggested
- by front-end. */
- int ideal_maximum_length;
-
/* Indentation count. */
int indent_skip;
- /* Current prefixing rule. */
- diagnostic_prefixing_rule_t prefixing_rule;
+ /* Current wrapping mode. */
+ pp_wrapping_mode_t wrapping;
/* If non-NULL, this function formats a TEXT into the BUFFER. When called,
TEXT->format_spec points to a format code. FORMAT_DECODER should call
@@ -158,9 +204,9 @@ struct pretty_print_info
#define pp_append_text(PP, B, E) \
pp_base_append_text (pp_base (PP), B, E)
#define pp_flush(PP) pp_base_flush (pp_base (PP))
-#define pp_prepare_to_format(PP, TI, LOC) \
- pp_base_prepare_to_format (pp_base (PP), TI, LOC)
-#define pp_format_text(PP, TI) pp_base_format_text (pp_base (PP), TI)
+#define pp_format(PP, TI) pp_base_format (pp_base (PP), TI)
+#define pp_output_formatted_text(PP) \
+ pp_base_output_formatted_text (pp_base (PP))
#define pp_format_verbatim(PP, TI) \
pp_base_format_verbatim (pp_base (PP), TI)
@@ -264,9 +310,8 @@ extern void pp_printf (pretty_printer *, const char *, ...)
extern void pp_verbatim (pretty_printer *, const char *, ...)
ATTRIBUTE_GCC_PPDIAG(2,3);
extern void pp_base_flush (pretty_printer *);
-extern void pp_base_prepare_to_format (pretty_printer *, text_info *,
- location_t *);
-extern void pp_base_format_text (pretty_printer *, text_info *);
+extern void pp_base_format (pretty_printer *, text_info *);
+extern void pp_base_output_formatted_text (pretty_printer *);
extern void pp_base_format_verbatim (pretty_printer *, text_info *);
extern void pp_base_indent (pretty_printer *);
@@ -276,4 +321,15 @@ extern void pp_base_string (pretty_printer *, const char *);
extern void pp_write_text_to_stream (pretty_printer *pp);
extern void pp_base_maybe_space (pretty_printer *);
+/* Switch into verbatim mode and return the old mode. */
+static inline pp_wrapping_mode_t
+pp_set_verbatim_wrapping_ (pretty_printer *pp)
+{
+ pp_wrapping_mode_t oldmode = pp_wrapping_mode (pp);
+ pp_line_cutoff (pp) = 0;
+ pp_prefixing_rule (pp) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
+ return oldmode;
+}
+#define pp_set_verbatim_wrapping(PP) pp_set_verbatim_wrapping_ (pp_base (PP))
+
#endif /* GCC_PRETTY_PRINT_H */