| 1 | /* Various declarations for the C and C++ pretty-printers. |
| 2 | Copyright (C) 2002-2025 Free Software Foundation, Inc. |
| 3 | Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net> |
| 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_C_PRETTY_PRINTER |
| 22 | #define GCC_C_PRETTY_PRINTER |
| 23 | |
| 24 | #include "tree.h" |
| 25 | #include "c-family/c-common.h" |
| 26 | #include "pretty-print.h" |
| 27 | |
| 28 | |
| 29 | enum pp_c_pretty_print_flags |
| 30 | { |
| 31 | pp_c_flag_abstract = 1 << 1, |
| 32 | pp_c_flag_gnu_v3 = 1 << 2, |
| 33 | pp_c_flag_last_bit = 3 |
| 34 | }; |
| 35 | |
| 36 | |
| 37 | /* The data type used to bundle information necessary for pretty-printing |
| 38 | a C or C++ entity. */ |
| 39 | class c_pretty_printer; |
| 40 | |
| 41 | /* The type of a C pretty-printer 'member' function. */ |
| 42 | typedef void (*c_pretty_print_fn) (c_pretty_printer *, tree); |
| 43 | |
| 44 | /* The datatype that contains information necessary for pretty-printing |
| 45 | a tree that represents a C construct. Any pretty-printer for a |
| 46 | language using C syntax can derive from this datatype and reuse |
| 47 | facilities provided here. A derived pretty-printer can override |
| 48 | any function listed in the vtable below. See cp/cxx-pretty-print.h |
| 49 | and cp/cxx-pretty-print.cc for an example of derivation. */ |
| 50 | class c_pretty_printer : public pretty_printer |
| 51 | { |
| 52 | dump_flags_t dump_flags; |
| 53 | |
| 54 | public: |
| 55 | c_pretty_printer (dump_flags_t = TDF_NONE); |
| 56 | std::unique_ptr<pretty_printer> clone () const override; |
| 57 | |
| 58 | // Format string, possibly translated. |
| 59 | void translate_string (const char *); |
| 60 | |
| 61 | virtual void constant (tree); |
| 62 | virtual void id_expression (tree); |
| 63 | virtual void primary_expression (tree); |
| 64 | virtual void postfix_expression (tree); |
| 65 | virtual void unary_expression (tree); |
| 66 | virtual void multiplicative_expression (tree); |
| 67 | virtual void conditional_expression (tree); |
| 68 | virtual void assignment_expression (tree); |
| 69 | virtual void expression (tree); |
| 70 | |
| 71 | virtual void type_id (tree); |
| 72 | virtual void statement (tree); |
| 73 | |
| 74 | virtual void declaration (tree); |
| 75 | virtual void declaration_specifiers (tree); |
| 76 | virtual void simple_type_specifier (tree); |
| 77 | virtual void function_specifier (tree); |
| 78 | virtual void storage_class_specifier (tree); |
| 79 | virtual void declarator (tree); |
| 80 | virtual void direct_declarator (tree); |
| 81 | virtual void abstract_declarator (tree); |
| 82 | virtual void direct_abstract_declarator (tree); |
| 83 | |
| 84 | virtual void initializer (tree); |
| 85 | /* Points to the first element of an array of offset-list. |
| 86 | Not used yet. */ |
| 87 | int *offset_list; |
| 88 | |
| 89 | pp_flags flags; |
| 90 | |
| 91 | /* These must be overridden by each of the C and C++ front-end to |
| 92 | reflect their understanding of syntactic productions when they differ. */ |
| 93 | c_pretty_print_fn type_specifier_seq; |
| 94 | c_pretty_print_fn ptr_operator; |
| 95 | c_pretty_print_fn parameter_list; |
| 96 | }; |
| 97 | |
| 98 | #define pp_c_tree_identifier(PPI, ID) \ |
| 99 | pp_c_identifier (PPI, IDENTIFIER_POINTER (ID)) |
| 100 | |
| 101 | #define pp_type_specifier_seq(PP, D) (PP)->type_specifier_seq (PP, D) |
| 102 | #define pp_ptr_operator(PP, D) (PP)->ptr_operator (PP, D) |
| 103 | #define pp_parameter_list(PP, T) (PP)->parameter_list (PP, T) |
| 104 | |
| 105 | void pp_c_whitespace (c_pretty_printer *); |
| 106 | void pp_c_left_paren (c_pretty_printer *); |
| 107 | void pp_c_right_paren (c_pretty_printer *); |
| 108 | void pp_c_left_brace (c_pretty_printer *); |
| 109 | void pp_c_right_brace (c_pretty_printer *); |
| 110 | void pp_c_left_bracket (c_pretty_printer *); |
| 111 | void pp_c_right_bracket (c_pretty_printer *); |
| 112 | void pp_c_dot (c_pretty_printer *); |
| 113 | void pp_c_ampersand (c_pretty_printer *); |
| 114 | void pp_c_star (c_pretty_printer *); |
| 115 | void pp_c_arrow (c_pretty_printer *); |
| 116 | void pp_c_semicolon (c_pretty_printer *); |
| 117 | void pp_c_complement (c_pretty_printer *); |
| 118 | void pp_c_exclamation (c_pretty_printer *); |
| 119 | void pp_c_space_for_pointer_operator (c_pretty_printer *, tree); |
| 120 | |
| 121 | /* Declarations. */ |
| 122 | void pp_c_tree_decl_identifier (c_pretty_printer *, tree); |
| 123 | void pp_c_function_definition (c_pretty_printer *, tree); |
| 124 | void pp_c_attributes_display (c_pretty_printer *, tree); |
| 125 | void pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type); |
| 126 | void pp_c_type_qualifier_list (c_pretty_printer *, tree); |
| 127 | void pp_c_parameter_type_list (c_pretty_printer *, tree); |
| 128 | void pp_c_specifier_qualifier_list (c_pretty_printer *, tree); |
| 129 | /* Expressions. */ |
| 130 | void pp_c_logical_or_expression (c_pretty_printer *, tree); |
| 131 | void pp_c_expression_list (c_pretty_printer *, tree); |
| 132 | void pp_c_constructor_elts (c_pretty_printer *, vec<constructor_elt, va_gc> *); |
| 133 | void pp_c_call_argument_list (c_pretty_printer *, tree); |
| 134 | void pp_c_type_cast (c_pretty_printer *, tree); |
| 135 | void pp_c_cast_expression (c_pretty_printer *, tree); |
| 136 | void pp_c_init_declarator (c_pretty_printer *, tree); |
| 137 | void pp_c_ws_string (c_pretty_printer *, const char *); |
| 138 | void pp_c_identifier (c_pretty_printer *, const char *); |
| 139 | void pp_c_string_literal (c_pretty_printer *, tree); |
| 140 | void pp_c_integer_constant (c_pretty_printer *, tree); |
| 141 | |
| 142 | void print_c_tree (FILE *file, tree t, dump_flags_t); |
| 143 | |
| 144 | #endif /* GCC_C_PRETTY_PRINTER */ |
| 145 | |