PageRenderTime 66ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/plugin/include/pretty-print.h

https://gitlab.com/abhishekr700/android_prebuilt_toolchains
C Header | 337 lines | 210 code | 38 blank | 89 comment | 0 complexity | cbecbc4bddb122eeb23711cac156153d MD5 | raw file
  1. /* Various declarations for language-independent pretty-print subroutines.
  2. Copyright (C) 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
  3. Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_PRETTY_PRINT_H
  17. #define GCC_PRETTY_PRINT_H
  18. #include "obstack.h"
  19. #include "input.h"
  20. /* Maximum number of format string arguments. */
  21. #define PP_NL_ARGMAX 30
  22. /* The type of a text to be formatted according a format specification
  23. along with a list of things. */
  24. typedef struct
  25. {
  26. const char *format_spec;
  27. va_list *args_ptr;
  28. int err_no; /* for %m */
  29. location_t *locus;
  30. tree *abstract_origin;
  31. } text_info;
  32. /* How often diagnostics are prefixed by their locations:
  33. o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
  34. o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once;
  35. o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical
  36. line is started. */
  37. typedef enum
  38. {
  39. DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0,
  40. DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1,
  41. DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2
  42. } diagnostic_prefixing_rule_t;
  43. /* The chunk_info data structure forms a stack of the results from the
  44. first phase of formatting (pp_base_format) which have not yet been
  45. output (pp_base_output_formatted_text). A stack is necessary because
  46. the diagnostic starter may decide to generate its own output by way
  47. of the formatter. */
  48. struct chunk_info
  49. {
  50. /* Pointer to previous chunk on the stack. */
  51. struct chunk_info *prev;
  52. /* Array of chunks to output. Each chunk is a NUL-terminated string.
  53. In the first phase of formatting, even-numbered chunks are
  54. to be output verbatim, odd-numbered chunks are format specifiers.
  55. The second phase replaces all odd-numbered chunks with formatted
  56. text, and the third phase simply emits all the chunks in sequence
  57. with appropriate line-wrapping. */
  58. const char *args[PP_NL_ARGMAX * 2];
  59. };
  60. /* The output buffer datatype. This is best seen as an abstract datatype
  61. whose fields should not be accessed directly by clients. */
  62. typedef struct
  63. {
  64. /* Obstack where the text is built up. */
  65. struct obstack formatted_obstack;
  66. /* Obstack containing a chunked representation of the format
  67. specification plus arguments. */
  68. struct obstack chunk_obstack;
  69. /* Currently active obstack: one of the above two. This is used so
  70. that the text formatters don't need to know which phase we're in. */
  71. struct obstack *obstack;
  72. /* Stack of chunk arrays. These come from the chunk_obstack. */
  73. struct chunk_info *cur_chunk_array;
  74. /* Where to output formatted text. */
  75. FILE *stream;
  76. /* The amount of characters output so far. */
  77. int line_length;
  78. /* This must be large enough to hold any printed integer or
  79. floating-point value. */
  80. char digit_buffer[128];
  81. } output_buffer;
  82. /* The type of pretty-printer flags passed to clients. */
  83. typedef unsigned int pp_flags;
  84. typedef enum
  85. {
  86. pp_none, pp_before, pp_after
  87. } pp_padding;
  88. /* Structure for switching in and out of verbatim mode in a convenient
  89. manner. */
  90. typedef struct
  91. {
  92. /* Current prefixing rule. */
  93. diagnostic_prefixing_rule_t rule;
  94. /* The ideal upper bound of number of characters per line, as suggested
  95. by front-end. */
  96. int line_cutoff;
  97. } pp_wrapping_mode_t;
  98. /* Maximum characters per line in automatic line wrapping mode.
  99. Zero means don't wrap lines. */
  100. #define pp_line_cutoff(PP) pp_base (PP)->wrapping.line_cutoff
  101. /* Prefixing rule used in formatting a diagnostic message. */
  102. #define pp_prefixing_rule(PP) pp_base (PP)->wrapping.rule
  103. /* Get or set the wrapping mode as a single entity. */
  104. #define pp_wrapping_mode(PP) pp_base (PP)->wrapping
  105. /* The type of a hook that formats client-specific data onto a pretty_pinter.
  106. A client-supplied formatter returns true if everything goes well,
  107. otherwise it returns false. */
  108. typedef struct pretty_print_info pretty_printer;
  109. typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *,
  110. int, bool, bool, bool);
  111. /* Client supplied function used to decode formats. */
  112. #define pp_format_decoder(PP) pp_base (PP)->format_decoder
  113. /* TRUE if a newline character needs to be added before further
  114. formatting. */
  115. #define pp_needs_newline(PP) pp_base (PP)->need_newline
  116. /* True if PRETTY-PRINTER is in line-wrapping mode. */
  117. #define pp_is_wrapping_line(PP) (pp_line_cutoff (PP) > 0)
  118. /* The amount of whitespace to be emitted when starting a new line. */
  119. #define pp_indentation(PP) pp_base (PP)->indent_skip
  120. /* The data structure that contains the bare minimum required to do
  121. proper pretty-printing. Clients may derived from this structure
  122. and add additional fields they need. */
  123. struct pretty_print_info
  124. {
  125. /* Where we print external representation of ENTITY. */
  126. output_buffer *buffer;
  127. /* The prefix for each new line. */
  128. const char *prefix;
  129. /* Where to put whitespace around the entity being formatted. */
  130. pp_padding padding;
  131. /* The real upper bound of number of characters per line, taking into
  132. account the case of a very very looong prefix. */
  133. int maximum_length;
  134. /* Indentation count. */
  135. int indent_skip;
  136. /* Current wrapping mode. */
  137. pp_wrapping_mode_t wrapping;
  138. /* If non-NULL, this function formats a TEXT into the BUFFER. When called,
  139. TEXT->format_spec points to a format code. FORMAT_DECODER should call
  140. pp_string (and related functions) to add data to the BUFFER.
  141. FORMAT_DECODER can read arguments from *TEXT->args_pts using VA_ARG.
  142. If the BUFFER needs additional characters from the format string, it
  143. should advance the TEXT->format_spec as it goes. When FORMAT_DECODER
  144. returns, TEXT->format_spec should point to the last character processed.
  145. */
  146. printer_fn format_decoder;
  147. /* Nonzero if current PREFIX was emitted at least once. */
  148. bool emitted_prefix;
  149. /* Nonzero means one should emit a newline before outputting anything. */
  150. bool need_newline;
  151. };
  152. #define pp_set_line_maximum_length(PP, L) \
  153. pp_base_set_line_maximum_length (pp_base (PP), L)
  154. #define pp_set_prefix(PP, P) pp_base_set_prefix (pp_base (PP), P)
  155. #define pp_destroy_prefix(PP) pp_base_destroy_prefix (pp_base (PP))
  156. #define pp_remaining_character_count_for_line(PP) \
  157. pp_base_remaining_character_count_for_line (pp_base (PP))
  158. #define pp_clear_output_area(PP) \
  159. pp_base_clear_output_area (pp_base (PP))
  160. #define pp_formatted_text(PP) pp_base_formatted_text (pp_base (PP))
  161. #define pp_last_position_in_text(PP) \
  162. pp_base_last_position_in_text (pp_base (PP))
  163. #define pp_emit_prefix(PP) pp_base_emit_prefix (pp_base (PP))
  164. #define pp_append_text(PP, B, E) \
  165. pp_base_append_text (pp_base (PP), B, E)
  166. #define pp_flush(PP) pp_base_flush (pp_base (PP))
  167. #define pp_format(PP, TI) pp_base_format (pp_base (PP), TI)
  168. #define pp_output_formatted_text(PP) \
  169. pp_base_output_formatted_text (pp_base (PP))
  170. #define pp_format_verbatim(PP, TI) \
  171. pp_base_format_verbatim (pp_base (PP), TI)
  172. #define pp_character(PP, C) pp_base_character (pp_base (PP), C)
  173. #define pp_string(PP, S) pp_base_string (pp_base (PP), S)
  174. #define pp_newline(PP) pp_base_newline (pp_base (PP))
  175. #define pp_space(PP) pp_character (PP, ' ')
  176. #define pp_left_paren(PP) pp_character (PP, '(')
  177. #define pp_right_paren(PP) pp_character (PP, ')')
  178. #define pp_left_bracket(PP) pp_character (PP, '[')
  179. #define pp_right_bracket(PP) pp_character (PP, ']')
  180. #define pp_left_brace(PP) pp_character (PP, '{')
  181. #define pp_right_brace(PP) pp_character (PP, '}')
  182. #define pp_semicolon(PP) pp_character (PP, ';')
  183. #define pp_comma(PP) pp_string (PP, ", ")
  184. #define pp_dot(PP) pp_character (PP, '.')
  185. #define pp_colon(PP) pp_character (PP, ':')
  186. #define pp_colon_colon(PP) pp_string (PP, "::")
  187. #define pp_arrow(PP) pp_string (PP, "->")
  188. #define pp_equal(PP) pp_character (PP, '=')
  189. #define pp_question(PP) pp_character (PP, '?')
  190. #define pp_bar(PP) pp_character (PP, '|')
  191. #define pp_carret(PP) pp_character (PP, '^')
  192. #define pp_ampersand(PP) pp_character (PP, '&')
  193. #define pp_less(PP) pp_character (PP, '<')
  194. #define pp_greater(PP) pp_character (PP, '>')
  195. #define pp_plus(PP) pp_character (PP, '+')
  196. #define pp_minus(PP) pp_character (PP, '-')
  197. #define pp_star(PP) pp_character (PP, '*')
  198. #define pp_slash(PP) pp_character (PP, '/')
  199. #define pp_modulo(PP) pp_character (PP, '%')
  200. #define pp_exclamation(PP) pp_character (PP, '!')
  201. #define pp_complement(PP) pp_character (PP, '~')
  202. #define pp_quote(PP) pp_character (PP, '\'')
  203. #define pp_backquote(PP) pp_character (PP, '`')
  204. #define pp_doublequote(PP) pp_character (PP, '"')
  205. #define pp_newline_and_indent(PP, N) \
  206. do { \
  207. pp_indentation (PP) += N; \
  208. pp_newline (PP); \
  209. pp_base_indent (pp_base (PP)); \
  210. pp_needs_newline (PP) = false; \
  211. } while (0)
  212. #define pp_maybe_newline_and_indent(PP, N) \
  213. if (pp_needs_newline (PP)) pp_newline_and_indent (PP, N)
  214. #define pp_maybe_space(PP) pp_base_maybe_space (pp_base (PP))
  215. #define pp_separate_with(PP, C) \
  216. do { \
  217. pp_character (PP, C); \
  218. pp_space (PP); \
  219. } while (0)
  220. #define pp_scalar(PP, FORMAT, SCALAR) \
  221. do \
  222. { \
  223. sprintf (pp_buffer (PP)->digit_buffer, FORMAT, SCALAR); \
  224. pp_string (PP, pp_buffer (PP)->digit_buffer); \
  225. } \
  226. while (0)
  227. #define pp_decimal_int(PP, I) pp_scalar (PP, "%d", I)
  228. #define pp_wide_integer(PP, I) \
  229. pp_scalar (PP, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) I)
  230. #define pp_widest_integer(PP, I) \
  231. pp_scalar (PP, HOST_WIDEST_INT_PRINT_DEC, (HOST_WIDEST_INT) I)
  232. #define pp_pointer(PP, P) pp_scalar (PP, "%p", P)
  233. #define pp_identifier(PP, ID) pp_string (PP, ID)
  234. #define pp_tree_identifier(PP, T) \
  235. pp_append_text(PP, IDENTIFIER_POINTER (T), \
  236. IDENTIFIER_POINTER (T) + IDENTIFIER_LENGTH (T))
  237. #define pp_unsupported_tree(PP, T) \
  238. pp_verbatim (pp_base (PP), "#%qs not supported by %s#", \
  239. tree_code_name[(int) TREE_CODE (T)], __FUNCTION__)
  240. #define pp_buffer(PP) pp_base (PP)->buffer
  241. /* Clients that directly derive from pretty_printer need to override
  242. this macro to return a pointer to the base pretty_printer structure. */
  243. #define pp_base(PP) (PP)
  244. extern void pp_construct (pretty_printer *, const char *, int);
  245. extern void pp_base_set_line_maximum_length (pretty_printer *, int);
  246. extern void pp_base_set_prefix (pretty_printer *, const char *);
  247. extern void pp_base_destroy_prefix (pretty_printer *);
  248. extern int pp_base_remaining_character_count_for_line (pretty_printer *);
  249. extern void pp_base_clear_output_area (pretty_printer *);
  250. extern const char *pp_base_formatted_text (pretty_printer *);
  251. extern const char *pp_base_last_position_in_text (const pretty_printer *);
  252. extern void pp_base_emit_prefix (pretty_printer *);
  253. extern void pp_base_append_text (pretty_printer *, const char *, const char *);
  254. /* This header may be included before toplev.h, hence the duplicate
  255. definitions to allow for GCC-specific formats. */
  256. #if GCC_VERSION >= 3005
  257. #define ATTRIBUTE_GCC_PPDIAG(m, n) __attribute__ ((__format__ (__gcc_diag__, m ,n))) ATTRIBUTE_NONNULL(m)
  258. #else
  259. #define ATTRIBUTE_GCC_PPDIAG(m, n) ATTRIBUTE_NONNULL(m)
  260. #endif
  261. extern void pp_printf (pretty_printer *, const char *, ...)
  262. ATTRIBUTE_GCC_PPDIAG(2,3);
  263. extern void pp_verbatim (pretty_printer *, const char *, ...)
  264. ATTRIBUTE_GCC_PPDIAG(2,3);
  265. extern void pp_base_flush (pretty_printer *);
  266. extern void pp_base_format (pretty_printer *, text_info *);
  267. extern void pp_base_output_formatted_text (pretty_printer *);
  268. extern void pp_base_format_verbatim (pretty_printer *, text_info *);
  269. extern void pp_base_indent (pretty_printer *);
  270. extern void pp_base_newline (pretty_printer *);
  271. extern void pp_base_character (pretty_printer *, int);
  272. extern void pp_base_string (pretty_printer *, const char *);
  273. extern void pp_write_text_to_stream (pretty_printer *pp);
  274. extern void pp_base_maybe_space (pretty_printer *);
  275. /* Switch into verbatim mode and return the old mode. */
  276. static inline pp_wrapping_mode_t
  277. pp_set_verbatim_wrapping_ (pretty_printer *pp)
  278. {
  279. pp_wrapping_mode_t oldmode = pp_wrapping_mode (pp);
  280. pp_line_cutoff (pp) = 0;
  281. pp_prefixing_rule (pp) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
  282. return oldmode;
  283. }
  284. #define pp_set_verbatim_wrapping(PP) pp_set_verbatim_wrapping_ (pp_base (PP))
  285. #endif /* GCC_PRETTY_PRINT_H */