-
-enum pad { none, before, after };
-
-/* These constants can used as bit flags in the process of tree formatting.
-
- TFF_PLAIN_IDENTIFER: unqualified part of a name.
- TFF_NAMESPACE_SCOPE: the complete qualified-id form of a name.
- TFF_CLASS_SCOPE: if possible, include the class-name part of a
- qualified-id. This flag may be implied in some circumstances by
- TFF_NAMESPACE_SCOPE.
- TFF_SCOPE: the combinaison of the two above.
- TFF_CHASE_TYPDEF: print the original type-id instead of the typedef-name.
- TFF_DECL_SPECIFIERS: print decl-specifiers.
- TFF_CLASS_KEY_OR_ENUM: precede a class-type name (resp. enum name) with
- a class-key (resp. `enum').
- TFF_RETURN_TYPE: include function return type.
- TFF_FUNCTION_DEFAULT_ARGUMENTS: include function default parameter values.
- TFF_EXCEPTION_SPECIFICATION: show function exception specification.
- TFF_TEMPLATE_HEADER: show the template<...> hearder in a
- template-declaration.
- TFF_TEMPLATE_DEFAULT_ARGUMENTS: show template paramter default values. */
-
-#define TFF_PLAIN_IDENTIFIER (0)
-#define TFF_NAMESPACE_SCOPE (1)
-#define TFF_CLASS_SCOPE (1 << 1)
-#define TFF_CHASE_NAMESPACE_ALIAS (1 << 2)
-#define TFF_CHASE_TYPEDEF (1 << 3)
-#define TFF_DECL_SPECIFIERS (1 << 4)
-#define TFF_CLASS_KEY_OR_ENUM (1 << 5)
-#define TFF_RETURN_TYPE (1 << 6)
-#define TFF_FUNCTION_DEFAULT_ARGUMENTS (1 << 7)
-#define TFF_EXCEPTION_SPECIFICATION (1 << 8)
-#define TFF_TEMPLATE_HEADER (1 << 9)
-#define TFF_TEMPLATE_DEFAULT_ARGUMENTS (1 << 10)
-#define TFF_SCOPE (TFF_NAMESPACE_SCOPE | TFF_CLASS_SCOPE)
-
-/* This data structure bundles altogether, all the information necessary
- for pretty-printing a C++ source-level entity represented by a tree. */
-typedef struct
-{
- tree decl;
- int flags;
- enum pad pad;
-} tree_formatting_info, *tfi_t;
-
-#define tree_being_formatted(TFI) (TFI)->decl
-#define tree_formatting_flags(TFI) (TFI)->flags
-#define put_whitespace(TFI) (TFI)->pad
-
-#define sorry_for_unsupported_tree(T) \
- sorry ("`%s' not supported by %s", tree_code_name[(int) TREE_CODE (T)], \
- __FUNCTION__)
-
-#define print_scope_operator(BUFFER) output_add_string (BUFFER, "::")
-#define print_left_paren(BUFFER) output_add_character (BUFFER, '(')
-#define print_right_paren(BUFFER) output_add_character (BUFFER, ')')
-#define print_left_bracket(BUFFER) output_add_character (BUFFER, '[')
-#define print_right_bracket(BUFFER) output_add_character (BUFFER, ']')
-#define print_whitespace(BUFFER, TFI) \
- do { \
- output_add_space (BUFFER); \
- put_whitespace (TFI) = none; \
- } while (0)
-
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free free
-
-#define print_tree_identifier(BUFFER, TID) \
- output_add_string (BUFFER, IDENTIFIER_POINTER (TID))
-#define print_identifier(BUFFER, ID) output_add_string (BUFFER, ID)
-
-/* Obstack where we build text strings for overloading, etc. */
-static struct obstack scratch_obstack;
-static char *scratch_firstobj;
-
-# define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
-# define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
-# define OB_PUTC2(C1,C2) \
- (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
-# define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
-# define OB_PUTID(ID) \
- (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
- IDENTIFIER_LENGTH (ID)))
-# define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
-# define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
-# define OB_PUTI(CST) do { sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(CST)); \
- OB_PUTCP (digit_buffer); } while (0)
-
-# define OB_END_TEMPLATE_ID() \
- (((obstack_next_free (&scratch_obstack) != obstack_base (&scratch_obstack) \
- && obstack_next_free (&scratch_obstack)[-1] == '>') \
- ? OB_PUTC (' ') : (void)0), OB_PUTC ('>'))
-
-# define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
-
-static const char *args_to_string PARAMS ((tree, int));
-static const char *assop_to_string PARAMS ((enum tree_code, int));
-static const char *code_to_string PARAMS ((enum tree_code, int));
-static const char *cv_to_string PARAMS ((tree, int));
-static const char *decl_to_string PARAMS ((tree, int));
-static const char *expr_to_string PARAMS ((tree, int));
-static const char *fndecl_to_string PARAMS ((tree, int));
-static const char *op_to_string PARAMS ((enum tree_code, int));
-static const char *parm_to_string PARAMS ((int, int));
-static const char *type_to_string PARAMS ((tree, int));
-
-static void dump_type PARAMS ((tree, enum tree_string_flags));
-static void dump_typename PARAMS ((tree, enum tree_string_flags));
-static void dump_simple_decl PARAMS ((tree, tree, enum tree_string_flags));
-static void dump_decl PARAMS ((tree, enum tree_string_flags));
-static void dump_template_decl PARAMS ((tree, enum tree_string_flags));
-static void dump_function_decl PARAMS ((tree, enum tree_string_flags));
-static void dump_expr PARAMS ((tree, enum tree_string_flags));
-static void dump_unary_op PARAMS ((const char *, tree, enum tree_string_flags));
-static void dump_binary_op PARAMS ((const char *, tree, enum tree_string_flags));
-static void dump_aggr_type PARAMS ((tree, enum tree_string_flags));
-static enum pad dump_type_prefix PARAMS ((tree, enum tree_string_flags));
-static void dump_type_suffix PARAMS ((tree, enum tree_string_flags));
-static void dump_function_name PARAMS ((tree, enum tree_string_flags));
-static void dump_expr_list PARAMS ((tree, enum tree_string_flags));
-static void dump_global_iord PARAMS ((tree));
-static enum pad dump_qualifiers PARAMS ((tree, enum pad));
-static void dump_char PARAMS ((int));
-static void dump_parameters PARAMS ((tree, enum tree_string_flags));
-static void dump_exception_spec PARAMS ((tree, enum tree_string_flags));
-static const char *class_key_or_enum PARAMS ((tree));
-static tree ident_fndecl PARAMS ((tree));
-static void dump_template_argument PARAMS ((tree, enum tree_string_flags));
-static void dump_template_argument_list PARAMS ((tree, enum tree_string_flags));
-static void dump_template_parameter PARAMS ((tree, enum tree_string_flags));
-static void dump_template_bindings PARAMS ((tree, tree));
-static void dump_scope PARAMS ((tree, enum tree_string_flags));
-static void dump_template_parms PARAMS ((tree, int, enum tree_string_flags));
-
-static const char *function_category PARAMS ((tree));
-static void lang_print_error_function PARAMS ((const char *));
-static void maybe_print_instantiation_context PARAMS ((output_buffer *));
-static void print_instantiation_full_context PARAMS ((output_buffer *));
-static void print_instantiation_partial_context PARAMS ((output_buffer *, tree,
- const char *, int));
-static void cp_diagnostic_starter PARAMS ((output_buffer *,
- diagnostic_context *));
-static void cp_diagnostic_finalizer PARAMS ((output_buffer *,
- diagnostic_context *));
-static void cp_print_error_function PARAMS ((output_buffer *,
- diagnostic_context *));
-
-static int cp_tree_printer PARAMS ((output_buffer *));
-static void print_function_argument_list PARAMS ((output_buffer *, tfi_t));
-static void print_declaration PARAMS ((output_buffer *, tfi_t));
-static void print_expression PARAMS ((output_buffer *, tfi_t));
-static void print_function_declaration PARAMS ((output_buffer *, tfi_t));
-static void print_function_parameter PARAMS ((output_buffer *, int));
-static void print_type_id PARAMS ((output_buffer *, tfi_t));
-static void print_cv_qualifier_seq PARAMS ((output_buffer *, tfi_t));
-static void print_type_specifier_seq PARAMS ((output_buffer *, tfi_t));
-static void print_simple_type_specifier PARAMS ((output_buffer *, tfi_t));
-static void print_elaborated_type_specifier PARAMS ((output_buffer *, tfi_t));
-static void print_rest_of_abstract_declarator PARAMS ((output_buffer *,
- tfi_t));
-static void print_parameter_declaration_clause PARAMS ((output_buffer *,
- tfi_t));
-static void print_exception_specification PARAMS ((output_buffer *, tfi_t));
-static void print_nested_name_specifier PARAMS ((output_buffer *, tfi_t));
-static void print_template_id PARAMS ((output_buffer *, tfi_t));
-static void print_template_argument_list_start PARAMS ((output_buffer *));
-static void print_template_argument_list_end PARAMS ((output_buffer *));
-static tree typedef_original_name PARAMS ((tree));
-
-#define A args_to_string
-#define C code_to_string
-#define D decl_to_string
-#define E expr_to_string
-#define F fndecl_to_string
-#define L language_to_string
-#define O op_to_string
-#define P parm_to_string
-#define Q assop_to_string
-#define T type_to_string
-#define V cv_to_string
-
-#define o (cp_printer *) 0
-cp_printer * cp_printers[256] =
-{
-/*0 1 2 3 4 5 6 7 8 9 A B C D E F */
- o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x00 */
- o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x10 */
- o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x20 */
- o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x30 */
- o, A, o, C, D, E, F, o, o, o, o, o, L, o, o, O, /* 0x40 */
- P, Q, o, o, T, o, V, o, o, o, o, o, o, o, o, o, /* 0x50 */
- o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x60 */
- o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x70 */
-};
-#undef C
-#undef D
-#undef E
-#undef F
-#undef L
-#undef O
-#undef P
-#undef Q
-#undef T
-#undef V
-#undef o
+#include "langhooks-def.h"
+#include "cxx-pretty-print.h"
+
+#define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
+
+/* The global buffer where we dump everything. It is there only for
+ transitional purpose. It is expected, in the near future, to be
+ completely removed. */
+static cxx_pretty_printer scratch_pretty_printer;
+#define cxx_pp (&scratch_pretty_printer)
+
+# define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
+
+static const char *args_to_string (tree, int);
+static const char *assop_to_string (enum tree_code);
+static const char *code_to_string (enum tree_code);
+static const char *cv_to_string (tree, int);
+static const char *decl_to_string (tree, int);
+static const char *expr_to_string (tree);
+static const char *fndecl_to_string (tree, int);
+static const char *op_to_string (enum tree_code);
+static const char *parm_to_string (int);
+static const char *type_to_string (tree, int);
+
+static void dump_type (tree, int);
+static void dump_typename (tree, int);
+static void dump_simple_decl (tree, tree, int);
+static void dump_decl (tree, int);
+static void dump_template_decl (tree, int);
+static void dump_function_decl (tree, int);
+static void dump_expr (tree, int);
+static void dump_unary_op (const char *, tree, int);
+static void dump_binary_op (const char *, tree, int);
+static void dump_aggr_type (tree, int);
+static void dump_type_prefix (tree, int);
+static void dump_type_suffix (tree, int);
+static void dump_function_name (tree, int);
+static void dump_expr_list (tree, int);
+static void dump_global_iord (tree);
+static void dump_parameters (tree, int);
+static void dump_exception_spec (tree, int);
+static void dump_template_argument (tree, int);
+static void dump_template_argument_list (tree, int);
+static void dump_template_parameter (tree, int);
+static void dump_template_bindings (tree, tree);
+static void dump_scope (tree, int);
+static void dump_template_parms (tree, int, int);
+
+static const char *function_category (tree);
+static void maybe_print_instantiation_context (diagnostic_context *);
+static void print_instantiation_full_context (diagnostic_context *);
+static void print_instantiation_partial_context (diagnostic_context *,
+ tree, location_t);
+static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *);
+static void cp_diagnostic_finalizer (diagnostic_context *, diagnostic_info *);
+static void cp_print_error_function (diagnostic_context *, diagnostic_info *);
+
+static bool cp_printer (pretty_printer *, text_info *);
+static tree locate_error (const char *, va_list);
+static location_t location_of (tree);