Remove pedwarn_with_decl, warning_with_decl and error_with_decl from GCC.
authorGabriel Dos Reis <gdr@integrable-solutions.net>
Fri, 25 Jul 2003 09:52:32 +0000 (09:52 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Fri, 25 Jul 2003 09:52:32 +0000 (09:52 +0000)
        Remove pedwarn_with_decl, warning_with_decl and error_with_decl
        from GCC.
        * calls.c (try_to_integrate): Don't use xxx_with_decl.
        (expand_call): Likewise.
        * dwarfout.c (output_reg_number): Likewise.
        * expr.c (expand_expr): Likewise.
        * function.c (assign_temp): Likewise.
        (uninitialized_vars_warning): Likewise.
        (setjmp_args_warning): Likewise.
        (expand_function_end): Likewise.
        * stmt.c (fixup_gotos): Likewise.
        (warn_about_unused_variables): Likewise.
        (expand_end_bindings): Likewise.
        * stor-layout.c (layout_decl): Likewise.
        (place_field): Likewise.
        * toplev.c (check_global_declarations): Likewise.
        (rest_of_handle_inlining): Likewise.
        (default_tree_printer): New function.
        (general_init): Initialize diagnostic machinery before routing
        signals to the ICE machinery.  Set default tree printer.
        * toplev.h (pedwarn_with_decl): Remove declaration.
        (warning_with_decl): Likewise.
        (error_with_decl): Likewise.
        (pedwarn): Remove attribute for the time being.
        * tree-inline.c (expand_call_inline): Don't use xxx_with_decl.
        * varasm.c (named_section): Likewise.
        (make_decl_rtl): Likewise.
        (assemble_variable): Likewise.
        (merge_weak): Likewise.
        (declare_weak): Likewise.

        * diagnostic.h: Move non-diagnostic stuff into pretty-print.h.
        * diagnostic.c: Move non-diagnostic stuff into pretty-print.c.
        (format_with_decl): Remove.
        (diagnostic_for_decl): Likewise.
        (pedwarn_with_decl): Likewise.
        (warning_with_decl): Likewise.
        (error_with_decl): Likewise.
        (diagnostic_initialize): Adjust.
        (diagnostic_count_diagnostic): Likewise.
        (announce_function): Likewise.
        (lhd_print_error_function): Likewise.
        (diagnostic_report_current_module): Likewise.
        (default_diagnostic_starter): Likewise.
        (diagnostic_report_diagnostic): Likewise.
        (default_diagnostic_finalizer): Likewise.
        (verbatim): Likewise.
        (error): Likewise.
        (warning): Likewise.
        * opts.c (common_handle_option): Likewise.
        * pretty-print.c: New file.
        * c-pretty-print.h (pp_base): Override.
        * c-pretty-print.c: Adjust use of macros throughout.
        (pp_buffer): New macro.
        (pp_newline): Likewise.
        * c-objc-common.c (c_tree_printer): Adjust prototype. Tidy.
        * Makefile.in (DIAGNOSTIC_H): New variable.
        (c-errors.o): Use it.
        (c-objc-common.o): Likewise.
        (c-common.o): Likewise.
        (c-opts.o): Likewise.
        (c-format.o): Likewise.
        (diagnostic.o): Likewise.
        (opts.o): Likewise.
        (toplev.o): Likewise.
        (rtl-error.o): Likewise.
        (dwarf2out.o): Likewise.
        (jump.o): Likewise.
        (pretty-print.o): New rule.

cp/
        * Make-lang.in (cp/error.o): Depend on DIAGNOSTIC_H.
        * error.c: Use the new pretty-printer fraamework.

From-SVN: r69773

23 files changed:
gcc/ChangeLog
gcc/Makefile.in
gcc/c-objc-common.c
gcc/c-pretty-print.c
gcc/c-pretty-print.h
gcc/calls.c
gcc/cp/ChangeLog
gcc/cp/Make-lang.in
gcc/cp/error.c
gcc/diagnostic.c
gcc/diagnostic.h
gcc/dwarfout.c
gcc/expr.c
gcc/function.c
gcc/opts.c
gcc/pretty-print.c [new file with mode: 0644]
gcc/pretty-print.h
gcc/stmt.c
gcc/stor-layout.c
gcc/toplev.c
gcc/toplev.h
gcc/tree-inline.c
gcc/varasm.c

index 4a68dfb..5c90a76 100644 (file)
@@ -1,3 +1,75 @@
+2003-07-25  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       Remove pedwarn_with_decl, warning_with_decl and error_with_decl
+       from GCC. 
+       * calls.c (try_to_integrate): Don't use xxx_with_decl.
+       (expand_call): Likewise.
+       * dwarfout.c (output_reg_number): Likewise.
+       * expr.c (expand_expr): Likewise.
+       * function.c (assign_temp): Likewise.
+       (uninitialized_vars_warning): Likewise.
+       (setjmp_args_warning): Likewise.
+       (expand_function_end): Likewise.
+       * stmt.c (fixup_gotos): Likewise.
+       (warn_about_unused_variables): Likewise.
+       (expand_end_bindings): Likewise.
+       * stor-layout.c (layout_decl): Likewise.
+       (place_field): Likewise.
+       * toplev.c (check_global_declarations): Likewise.
+       (rest_of_handle_inlining): Likewise.
+       (default_tree_printer): New function.
+       (general_init): Initialize diagnostic machinery before routing
+       signals to the ICE machinery.  Set default tree printer.
+       * toplev.h (pedwarn_with_decl): Remove declaration.
+       (warning_with_decl): Likewise.
+       (error_with_decl): Likewise.
+       (pedwarn): Remove attribute for the time being. 
+       * tree-inline.c (expand_call_inline): Don't use xxx_with_decl.
+       * varasm.c (named_section): Likewise.
+       (make_decl_rtl): Likewise.
+       (assemble_variable): Likewise.
+       (merge_weak): Likewise.
+       (declare_weak): Likewise.
+
+       * diagnostic.h: Move non-diagnostic stuff into pretty-print.h.
+       * diagnostic.c: Move non-diagnostic stuff into pretty-print.c.
+       (format_with_decl): Remove.
+       (diagnostic_for_decl): Likewise.
+       (pedwarn_with_decl): Likewise.
+       (warning_with_decl): Likewise.
+       (error_with_decl): Likewise.
+       (diagnostic_initialize): Adjust.
+       (diagnostic_count_diagnostic): Likewise.
+       (announce_function): Likewise.
+       (lhd_print_error_function): Likewise.
+       (diagnostic_report_current_module): Likewise.
+       (default_diagnostic_starter): Likewise.
+       (diagnostic_report_diagnostic): Likewise.
+       (default_diagnostic_finalizer): Likewise.
+       (verbatim): Likewise.
+       (error): Likewise.
+       (warning): Likewise.
+       * opts.c (common_handle_option): Likewise.
+       * pretty-print.c: New file.
+       * c-pretty-print.h (pp_base): Override.
+       * c-pretty-print.c: Adjust use of macros throughout.
+       (pp_buffer): New macro.
+       (pp_newline): Likewise.
+       * c-objc-common.c (c_tree_printer): Adjust prototype. Tidy.
+       * Makefile.in (DIAGNOSTIC_H): New variable.
+       (c-errors.o): Use it.
+       (c-objc-common.o): Likewise.
+       (c-common.o): Likewise.
+       (c-opts.o): Likewise.
+       (c-format.o): Likewise.
+       (diagnostic.o): Likewise.
+       (opts.o): Likewise.
+       (toplev.o): Likewise.
+       (rtl-error.o): Likewise.
+       (dwarf2out.o): Likewise.
+       (jump.o): Likewise.
+       (pretty-print.o): New rule.
+
 2003-07-24  Roger Sayle  <roger@eyesopen.com>
 
        * builtins.def (BUILT_IN_PRINTF, BUILT_IN_FPRINTF): Changed from
index 41e90fb..1968f82 100644 (file)
@@ -652,6 +652,8 @@ C_TREE_H = c-tree.h $(C_COMMON_H)
 SYSTEM_H = system.h hwint.h $(srcdir)/../include/libiberty.h
 PREDICT_H = predict.h predict.def
 CPPLIB_H = cpplib.h line-map.h
+PRETTY_PRINT_H = pretty-print.h input.h $(OBSTACK_H)
+DIAGNOSTIC_H = diagnostic.h diagnostic.def $(PRETTY_PRINT_H)
 
 # sed inserts variable overrides after the following line.
 ####target overrides
@@ -821,7 +823,7 @@ OBJS-common = \
  sibcall.o simplify-rtx.o sreal.o ssa.o ssa-ccp.o ssa-dce.o stmt.o        \
  stor-layout.o stringpool.o timevar.o toplev.o tracer.o tree.o tree-dump.o \
  unroll.o varasm.o varray.o version.o vmsdbgout.o xcoffout.o              \
- alloc-pool.o et-forest.o cfghooks.o bt-load.o $(GGC)
+ alloc-pool.o et-forest.o cfghooks.o bt-load.o pretty-print.o $(GGC) 
 
 OBJS-md = $(out_object_file)
 OBJS-archive = $(EXTRA_OBJS) $(host_hook_obj) hashtable.o tree-inline.o           \
@@ -1238,7 +1240,7 @@ s-crt0:   $(CRT0_S) $(MCRT0_S) $(GCC_PASSES) $(CONFIG_H)
 # C language specific files.
 
 c-errors.o: c-errors.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
-    $(C_TREE_H) flags.h diagnostic.h $(TM_P_H)
+    $(C_TREE_H) flags.h $(DIAGNOSTIC_H) $(TM_P_H)
 c-parse.o : $(parsedir)/c-parse.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
     $(GGC_H) intl.h $(C_TREE_H) input.h flags.h toplev.h output.h $(CPPLIB_H) \
     varray.h gt-c-parse.h
@@ -1282,7 +1284,7 @@ c-ppoutput.o : c-ppoutput.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
     $(C_COMMON_H) $(TREE_H) $(CPPLIB_H) cpphash.h $(TM_P_H) c-pragma.h
 c-objc-common.o : c-objc-common.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
     $(C_TREE_H) $(RTL_H) insn-config.h $(INTEGRATE_H) $(EXPR_H) $(C_TREE_H) \
-    flags.h toplev.h tree-inline.h diagnostic.h $(VARRAY_H) \
+    flags.h toplev.h tree-inline.h $(DIAGNOSTIC_H) $(VARRAY_H) \
     langhooks.h $(GGC_H) gt-c-objc-common.h $(TARGET_H) cgraph.h
 c-aux-info.o : c-aux-info.c  $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
     $(C_TREE_H) flags.h toplev.h
@@ -1317,13 +1319,13 @@ tlink.o: tlink.c $(DEMANGLE_H) $(HASHTAB_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h
 c-common.o : c-common.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
        $(OBSTACK_H) $(C_COMMON_H) flags.h toplev.h output.h c-pragma.h intl.h \
        $(GGC_H) $(EXPR_H) $(TM_P_H) builtin-types.def builtin-attrs.def \
-       diagnostic.h gt-c-common.h langhooks.h varray.h $(RTL_H) $(TARGET_H) \
-       $(C_TREE_H)
+       $(DIAGNOSTIC_H) gt-c-common.h langhooks.h varray.h $(RTL_H) \
+       $(TARGET_H) $(C_TREE_H)
 c-pretty-print.o : c-pretty-print.c c-pretty-print.h pretty-print.h \
        $(C_COMMON_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) real.h
 
 c-opts.o : c-opts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
-        c-pragma.h flags.h toplev.h langhooks.h tree-inline.h diagnostic.h \
+        c-pragma.h flags.h toplev.h langhooks.h tree-inline.h $(DIAGNOSTIC_H) \
        intl.h debug.h $(C_COMMON_H) opts.h options.h $(PARAMS_H)
        $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
                $< $(OUTPUT_OPTION) @TARGET_SYSTEM_ROOT_DEFINE@
@@ -1339,7 +1341,7 @@ attribs.o : attribs.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) flag
        builtin-types.def $(TARGET_H) langhooks.h
 
 c-format.o : c-format.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) langhooks.h \
-       $(C_COMMON_H) flags.h toplev.h intl.h diagnostic.h
+       $(C_COMMON_H) flags.h toplev.h intl.h $(DIAGNOSTIC_H)
 
 c-semantics.o : c-semantics.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
        $(C_TREE_H) flags.h toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \
@@ -1473,14 +1475,14 @@ stor-layout.o : stor-layout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE
    langhooks.h
 fold-const.o : fold-const.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
    flags.h real.h toplev.h $(HASHTAB_H) $(EXPR_H) $(RTL_H) $(GGC_H) $(TM_P_H) langhooks.h
-diagnostic.o : diagnostic.c diagnostic.h real.h diagnostic.def \
+diagnostic.o : diagnostic.c $(DIAGNOSTIC_H) real.h \
    $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(TM_P_H) flags.h $(GGC_H) \
    input.h toplev.h intl.h langhooks.h $(LANGHOOKS_DEF_H)
 opts.o : opts.c opts.h options.h toplev.h $(CONFIG_H) $(SYSTEM_H) \
        coretypes.h $(TREE_H) $(TM_H) $(LANGHOOKS_H) $(GGC_H) $(RTL_H) \
-       output.h diagnostic.h $(TM_P_H) $(INSN_ATTR_H) intl.h
+       output.h $(DIAGNOSTIC_H) $(TM_P_H) $(INSN_ATTR_H) intl.h
 toplev.o : toplev.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(RTL_H) \
-   function.h flags.h xcoffout.h input.h $(INSN_ATTR_H) output.h diagnostic.h \
+   function.h flags.h xcoffout.h input.h $(INSN_ATTR_H) output.h $(DIAGNOSTIC_H) \
    debug.h insn-config.h intl.h $(RECOG_H) Makefile toplev.h \
    dwarf2out.h sdbout.h dbxout.h $(EXPR_H) hard-reg-set.h $(BASIC_BLOCK_H) \
    graph.h $(LOOP_H) except.h $(REGS_H) $(TIMEVAR_H) \
@@ -1496,7 +1498,7 @@ host-default.o : host-default.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
        hosthooks.h hosthooks-def.h
 
 rtl-error.o: rtl-error.c $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(INSN_ATTR_H) \
-   insn-config.h input.h toplev.h intl.h diagnostic.h $(CONFIG_H)
+   insn-config.h input.h toplev.h intl.h $(DIAGNOSTIC_H) $(CONFIG_H)
 
 rtl.o : rtl.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(GTM_H) $(RTL_H) real.h \
   $(GGC_H) errors.h
@@ -1563,7 +1565,7 @@ dwarfout.o : dwarfout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
    $(RTL_H) dwarf.h flags.h insn-config.h reload.h output.h toplev.h $(TM_P_H) \
    debug.h langhooks.h $(TARGET_H)
 dwarf2out.o : dwarf2out.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
-   $(RTL_H) dwarf2.h debug.h flags.h insn-config.h reload.h output.h diagnostic.h real.h \
+   $(RTL_H) dwarf2.h debug.h flags.h insn-config.h reload.h output.h $(DIAGNOSTIC_H) real.h \
    hard-reg-set.h $(REGS_H) $(EXPR_H) libfuncs.h toplev.h dwarf2out.h varray.h \
    $(GGC_H) except.h dwarf2asm.h $(TM_P_H) langhooks.h $(HASHTAB_H) \
    gt-dwarf2out.h $(TARGET_H)
@@ -1585,7 +1587,7 @@ integrate.o : integrate.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $
 jump.o : jump.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) flags.h \
    hard-reg-set.h $(REGS_H) insn-config.h $(RECOG_H) $(EXPR_H) real.h except.h function.h \
    toplev.h $(INSN_ATTR_H) $(TM_P_H) reload.h $(PREDICT_H) $(TIMEVAR_H) \
-   diagnostic.h
+   $(DIAGNOSTIC_H)
 
 simplify-rtx.o : simplify-rtx.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
    $(REGS_H) hard-reg-set.h flags.h real.h insn-config.h $(RECOG_H) $(EXPR_H) toplev.h \
@@ -1794,6 +1796,7 @@ ifcvt.o : ifcvt.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
    cfgloop.h
 params.o : params.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(PARAMS_H) toplev.h
 hooks.o: hooks.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(HOOKS_H)
+pretty-print.o: pretty-print.c $(PRETTY_PRINT_H)
 
 $(out_object_file): $(out_file) $(CONFIG_H) coretypes.h $(TM_H) $(TREE_H) $(GGC_H) \
    $(RTL_H) $(REGS_H) hard-reg-set.h real.h insn-config.h conditions.h \
index 0d44e1d..887175b 100644 (file)
@@ -39,7 +39,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "target.h"
 #include "cgraph.h"
 
-static bool c_tree_printer (output_buffer *, text_info *);
+static bool c_tree_printer (pretty_printer *, text_info *);
 static tree inline_forbidden_p (tree *, int *, void *);
 static void expand_deferred_fns (void);
 static tree start_cdtor (int);
@@ -416,7 +416,7 @@ c_objc_common_finish_file (void)
    Please notice when called, the `%' part was already skipped by the
    diagnostic machinery.  */
 static bool
-c_tree_printer (output_buffer *buffer, text_info *text)
+c_tree_printer (pretty_printer *pp, text_info *text)
 {
   tree t = va_arg (*text->args_ptr, tree);
 
@@ -429,14 +429,14 @@ c_tree_printer (output_buffer *buffer, text_info *text)
         const char *n = DECL_NAME (t)
           ? (*lang_hooks.decl_printable_name) (t, 2)
           : "({anonymous})";
-        output_add_string (buffer, n);
+        pp_string (pp, n);
       }
       return true;
 
     case 'E':
        if (TREE_CODE (t) == IDENTIFIER_NODE)
          {
-           output_add_string (buffer, IDENTIFIER_POINTER (t));
+           pp_string (pp, IDENTIFIER_POINTER (t));
            return true;
          }
        return false;
index 63b18b3..7bb4cb0 100644 (file)
@@ -74,6 +74,9 @@ static void pp_c_type_id (c_pretty_printer, tree);
 static void pp_c_storage_class_specifier (c_pretty_printer, tree);
 static void pp_c_function_specifier (c_pretty_printer, tree);
 
+#define pp_buffer(PP) pp_base (PP)->buffer
+#define pp_newline(PP) (pp_newline) (pp_base (PP))
+
 \f
 /* Declarations.  */
 
@@ -248,9 +251,9 @@ pp_c_init_declarator (c_pretty_printer pp, tree t)
   pp_declarator (pp, t);
   if (DECL_INITIAL (t))
     {
-      pp_whitespace (pp);
+      pp_space (pp);
       pp_equal (pp);
-      pp_whitespace (pp);
+      pp_space (pp);
       pp_c_initializer (pp, DECL_INITIAL (t));
     }
 }
@@ -336,9 +339,9 @@ pp_c_char (c_pretty_printer ppi, int c)
       break;
     default:
       if (ISPRINT (c))
-       pp_character (ppi, c);
+       pp_character (&ppi->base, c);
       else
-       pp_format_scalar (ppi, "\\%03o", (unsigned) c);
+       pp_scalar (ppi, "\\%03o", (unsigned) c);
       break;
     }
 }
@@ -1038,7 +1041,7 @@ pp_c_assignment_expression (c_pretty_printer ppi, tree e)
       pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
       pp_c_maybe_whitespace (ppi);
       pp_equal (ppi);
-      pp_whitespace (ppi);
+      pp_space (ppi);
       pp_c_assignment_expression (ppi, TREE_OPERAND (e, 1));
     }
   else
@@ -1234,7 +1237,7 @@ pp_c_statement (c_pretty_printer ppi, tree stmt)
 
     case IF_STMT:
       pp_c_identifier (ppi, "if");
-      pp_whitespace (ppi);
+      pp_space (ppi);
       pp_c_left_paren (ppi);
       pp_c_expression (ppi, IF_COND (stmt));
       pp_right_paren (ppi);
@@ -1258,7 +1261,7 @@ pp_c_statement (c_pretty_printer ppi, tree stmt)
     case SWITCH_STMT:
       pp_newline (ppi);
       pp_c_identifier (ppi, "switch");
-      pp_whitespace (ppi);
+      pp_space (ppi);
       pp_c_left_paren (ppi);
       pp_c_expression (ppi, SWITCH_COND (stmt));
       pp_right_paren (ppi);
@@ -1269,7 +1272,7 @@ pp_c_statement (c_pretty_printer ppi, tree stmt)
 
     case WHILE_STMT:
       pp_c_identifier (ppi, "while");
-      pp_whitespace (ppi);
+      pp_space (ppi);
       pp_c_left_paren (ppi);
       pp_c_expression (ppi, WHILE_COND (stmt));
       pp_right_paren (ppi);
@@ -1284,7 +1287,7 @@ pp_c_statement (c_pretty_printer ppi, tree stmt)
       pp_statement (ppi, DO_BODY (stmt));
       pp_newline_and_indent (ppi, -3);
       pp_c_identifier (ppi, "while");
-      pp_whitespace (ppi);
+      pp_space (ppi);
       pp_c_left_paren (ppi);
       pp_c_expression (ppi, DO_COND (stmt));
       pp_c_right_paren (ppi);
@@ -1294,7 +1297,7 @@ pp_c_statement (c_pretty_printer ppi, tree stmt)
 
     case FOR_STMT:
       pp_c_identifier (ppi, "for");
-      pp_whitespace (ppi);
+      pp_space (ppi);
       pp_c_left_paren (ppi);
       pp_statement (ppi, FOR_INIT_STMT (stmt));
       pp_c_whitespace (ppi);
@@ -1364,20 +1367,20 @@ pp_c_statement (c_pretty_printer ppi, tree stmt)
        pp_c_identifier (ppi, is_extended ? "__asm__" : "asm");
        if (has_volatile_p)
          pp_c_identifier (ppi, "__volatile__");
-       pp_whitespace (ppi);
+       pp_space (ppi);
        pp_c_left_paren (ppi);
        pp_c_string_literal (ppi, ASM_STRING (stmt));
        if (is_extended)
          {
-           pp_whitespace (ppi);
+           pp_space (ppi);
            pp_separate_with (ppi, ':');
            if (ASM_OUTPUTS (stmt))
              pp_c_expression (ppi, ASM_OUTPUTS (stmt));
-           pp_whitespace (ppi);
+           pp_space (ppi);
            pp_separate_with (ppi, ':');
            if (ASM_INPUTS (stmt))
              pp_c_expression (ppi, ASM_INPUTS (stmt));
-           pp_whitespace (ppi);
+           pp_space (ppi);
            pp_separate_with (ppi, ':');
            if (ASM_CLOBBERS (stmt))
              pp_c_expression (ppi, ASM_CLOBBERS (stmt));
@@ -1389,7 +1392,7 @@ pp_c_statement (c_pretty_printer ppi, tree stmt)
 
     case FILE_STMT:
       pp_c_identifier (ppi, "__FILE__");
-      pp_whitespace (ppi);
+      pp_space (ppi);
       pp_equal (ppi);
       pp_c_whitespace (ppi);
       pp_c_identifier (ppi, FILE_STMT_FILENAME (stmt));
index 95cd4ef..bdd92b1 100644 (file)
@@ -62,6 +62,9 @@ struct c_pretty_print_info
   c_pretty_print_fn assignment_expression;
 };
 
+#undef pp_base
+#define pp_base(PP)  (&pp_c_base (PP)->base)
+
 #define pp_c_left_paren(PPI)                       \
    do {                                            \
      pp_left_paren (PPI);                          \
@@ -84,7 +87,7 @@ struct c_pretty_print_info
    } while (0)
 #define pp_c_whitespace(PPI)                       \
    do {                                            \
-     pp_whitespace (PPI);                          \
+     pp_space (PPI);                               \
      pp_c_base (PPI)->base.padding = pp_none;      \
    } while (0)
 #define pp_c_maybe_whitespace(PPI)                 \
@@ -102,10 +105,6 @@ struct c_pretty_print_info
 #define pp_c_tree_identifier(PPI, ID)              \
    pp_c_identifier (PPI, IDENTIFIER_POINTER (ID))
 
-/* Returns the 'output_buffer *' associated with a PRETTY-PRINTER, the latter
-   being something digestible by pp_c_base.  */
-#define pp_buffer(PPI) pp_c_base (PPI)->base.buffer
-
 #define pp_declaration(PPI, T)                    \
    (*pp_c_base (PPI)->declaration) (pp_c_base (PPI), T)
 #define pp_declaration_specifiers(PPI, D)         \
index 7add542..135b333 100644 (file)
@@ -1808,7 +1808,8 @@ try_to_integrate (tree fndecl, tree actparms, rtx target, int ignore,
   if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
       && optimize > 0 && !TREE_ADDRESSABLE (fndecl))
     {
-      warning_with_decl (fndecl, "inlining failed in call to `%s'");
+      warning ("%Hinlining failed in call to '%F'",
+               &DECL_SOURCE_LOCATION (fndecl), fndecl);
       warning ("called from here");
     }
   (*lang_hooks.mark_addressable) (fndecl);
@@ -2147,7 +2148,8 @@ expand_call (tree exp, rtx target, int ignore)
          if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
              && optimize > 0)
            {
-             warning_with_decl (fndecl, "can't inline call to `%s'");
+             warning ("%Hcan't inline call to '%F'",
+                       &DECL_SOURCE_LOCATION (fndecl), fndecl);
              warning ("called from here");
            }
          (*lang_hooks.mark_addressable) (fndecl);
index 7abf46b..0487cba 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-25 Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       * Make-lang.in (cp/error.o): Depend on DIAGNOSTIC_H.
+       * error.c: Use the new pretty-printer fraamework.
+
 2003-07-24  Per Bothner  <pbothner@apple.com>
 
        * decl.c (pushdecl_class_level):   Don't use push_srcloc/pop_srcloc
index df1d8a7..d16a5bc 100644 (file)
@@ -265,8 +265,8 @@ cp/expr.o: cp/expr.c $(CXX_TREE_H) $(TM_H) $(RTL_H) flags.h $(EXPR_H) toplev.h \
   except.h $(TM_P_H)
 cp/pt.o: cp/pt.c $(CXX_TREE_H) $(TM_H) cp/decl.h cp/lex.h \
   toplev.h $(RTL_H) except.h tree-inline.h gt-cp-pt.h
-cp/error.o: cp/error.c $(CXX_TREE_H) $(TM_H) toplev.h diagnostic.h flags.h real.h \
-  $(LANGHOOKS_DEF_H)
+cp/error.o: cp/error.c $(CXX_TREE_H) $(TM_H) toplev.h $(DIAGNOSTIC_H) \
+  flags.h real.h $(LANGHOOKS_DEF_H)
 cp/repo.o: cp/repo.c $(CXX_TREE_H) $(TM_H) toplev.h diagnostic.h \
   gt-cp-repo.h
 cp/semantics.o: cp/semantics.c $(CXX_TREE_H) $(TM_H) cp/lex.h except.h toplev.h \
index 11a548b..86b336e 100644 (file)
@@ -30,32 +30,21 @@ Boston, MA 02111-1307, USA.  */
 #include "flags.h"
 #include "diagnostic.h"
 #include "langhooks-def.h"
+#include "pretty-print.h"
 
 enum pad { none, before, after };
 
-#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_template_argument_list_start(BUFFER) \
-   print_non_consecutive_character ((BUFFER), '<')
-#define print_template_argument_list_end(BUFFER)  \
-   print_non_consecutive_character ((BUFFER), '>')
-#define print_tree_identifier(BUFFER, TID) \
-   output_add_string ((BUFFER), IDENTIFIER_POINTER (TID))
-#define print_identifier(BUFFER, ID) output_add_string ((BUFFER), (ID))
-#define separate_with_comma(BUFFER) output_add_string ((BUFFER), ", ")
+#define pp_template_argument_list_start(PP) \
+   pp_non_consecutive_character (PP, '<')
+#define pp_template_argument_list_end(PP)  \
+   pp_non_consecutive_character (PP, '>')
+#define pp_separate_with_comma(PP) pp_string (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 output_buffer scratch_buffer_rec;
-static output_buffer *scratch_buffer = &scratch_buffer_rec;
+static pretty_printer scratch_pretty_printer;
+#define cxx_pp (&scratch_pretty_printer)
 
 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
 
@@ -109,8 +98,8 @@ 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 (output_buffer *, text_info *);
-static void print_non_consecutive_character (output_buffer *, int);
+static bool cp_printer (pretty_printer *, text_info *);
+static void pp_non_consecutive_character (pretty_printer *, int);
 static tree locate_error (const char *, va_list);
 static location_t location_of (tree);
 
@@ -121,7 +110,7 @@ init_error (void)
   diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer;
   diagnostic_format_decoder (global_dc) = cp_printer;
 
-  init_output_buffer (scratch_buffer, /* prefix */NULL, /* line-width */0);
+  pp_construct (cxx_pp, NULL, 0);
 }
 
 /* Dump a scope, if deemed necessary.  */
@@ -139,18 +128,18 @@ dump_scope (tree scope, int flags)
       if (scope != global_namespace)
         {
           dump_decl (scope, f);
-          print_scope_operator (scratch_buffer);
+          pp_colon_colon (cxx_pp);
         }
     }
   else if (AGGREGATE_TYPE_P (scope))
     {
       dump_type (scope, f);
-      print_scope_operator (scratch_buffer);
+      pp_colon_colon (cxx_pp);
     }
   else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL)
     {
       dump_function_decl (scope, f);
-      print_scope_operator (scratch_buffer);
+      pp_colon_colon (cxx_pp);
     }
 }
 
@@ -174,12 +163,12 @@ dump_qualifiers (tree t, enum pad p)
         if (masks[ix] & quals)
           {
             if (p == before)
-              output_add_space (scratch_buffer);
+              pp_space (cxx_pp);
             p = before;
-            print_identifier (scratch_buffer, names[ix]);
+            pp_identifier (cxx_pp, names[ix]);
           }
       if (do_after)
-        output_add_space (scratch_buffer);
+        pp_space (cxx_pp);
     }
   else
     p = none;
@@ -210,7 +199,7 @@ dump_template_argument_list (tree args, int flags)
   for (i = 0; i< n; ++i)
     {
       if (need_comma)
-        separate_with_comma (scratch_buffer);
+        pp_separate_with_comma (cxx_pp);
       dump_template_argument (TREE_VEC_ELT (args, i), flags);
       need_comma = 1;
     }
@@ -228,24 +217,24 @@ dump_template_parameter (tree parm, int flags)
     {
       if (flags & TFF_DECL_SPECIFIERS)
         {
-          print_identifier (scratch_buffer, "class");
+          pp_identifier (cxx_pp, "class");
           if (DECL_NAME (p))
             {
-              output_add_space (scratch_buffer);
-              print_tree_identifier (scratch_buffer, DECL_NAME (p));
+              pp_space (cxx_pp);
+              pp_tree_identifier (cxx_pp, DECL_NAME (p));
             }
         }
       else if (DECL_NAME (p))
-        print_tree_identifier (scratch_buffer, DECL_NAME (p));
+        pp_tree_identifier (cxx_pp, DECL_NAME (p));
       else
-        print_identifier (scratch_buffer, "{template default argument error}");
+        pp_identifier (cxx_pp, "<template default argument error>");
     }
   else
     dump_decl (p, flags | TFF_DECL_SPECIFIERS);
 
   if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && a != NULL_TREE)
     {
-      output_add_string (scratch_buffer, " = ");
+      pp_string (cxx_pp, " = ");
       if (TREE_CODE (p) == TYPE_DECL || TREE_CODE (p) == TEMPLATE_DECL)
         dump_type (a, flags & ~TFF_CHASE_TYPEDEF);
       else
@@ -282,13 +271,13 @@ dump_template_bindings (tree parms, tree args)
            }
 
          if (need_comma)
-           separate_with_comma (scratch_buffer);
+           pp_separate_with_comma (cxx_pp);
          dump_template_parameter (TREE_VEC_ELT (p, i), TFF_PLAIN_IDENTIFIER);
-         output_add_string (scratch_buffer, " = ");
+         pp_string (cxx_pp, " = ");
          if (arg)
            dump_template_argument (arg, TFF_PLAIN_IDENTIFIER);
          else
-           print_identifier (scratch_buffer, "<missing>");
+           pp_identifier (cxx_pp, "<missing>");
 
          ++arg_idx;
          need_comma = 1;
@@ -313,7 +302,7 @@ dump_type (tree t, int flags)
   switch (TREE_CODE (t))
     {
     case UNKNOWN_TYPE:
-      print_identifier (scratch_buffer, "<unknown type>");
+      pp_identifier (cxx_pp, "<unknown type>");
       break;
 
     case TREE_LIST:
@@ -322,7 +311,7 @@ dump_type (tree t, int flags)
       break;
 
     case IDENTIFIER_NODE:
-      print_tree_identifier (scratch_buffer, t);
+      pp_tree_identifier (cxx_pp, t);
       break;
 
     case TREE_VEC:
@@ -350,12 +339,12 @@ dump_type (tree t, int flags)
       break;
 
     case COMPLEX_TYPE:
-      output_add_string (scratch_buffer, "__complex__ ");
+      pp_string (cxx_pp, "__complex__ ");
       dump_type (TREE_TYPE (t), flags);
       break;
 
     case VECTOR_TYPE:
-      output_add_string (scratch_buffer, "__vector__ ");
+      pp_string (cxx_pp, "__vector__ ");
       {
        /* The subtype of a VECTOR_TYPE is something like intQI_type_node,
           which has no name and is not very useful for diagnostics.  So
@@ -368,9 +357,9 @@ dump_type (tree t, int flags)
 
     case INTEGER_TYPE:
       if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
-       output_add_string (scratch_buffer, "unsigned ");
+       pp_string (cxx_pp, "unsigned ");
       else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
-       output_add_string (scratch_buffer, "signed ");
+       pp_string (cxx_pp, "signed ");
 
       /* fall through.  */
     case REAL_TYPE:
@@ -381,41 +370,39 @@ dump_type (tree t, int flags)
        dump_qualifiers (t, after);
        type = flags & TFF_CHASE_TYPEDEF ? TYPE_MAIN_VARIANT (t) : t;
        if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
-         print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (type));
+         pp_tree_identifier (cxx_pp, TYPE_IDENTIFIER (type));
        else
          /* Types like intQI_type_node and friends have no names.
             These don't come up in user error messages, but it's nice
             to be able to print them from the debugger.  */
-         print_identifier (scratch_buffer, "<anonymous>");
+         pp_identifier (cxx_pp, "<anonymous>");
       }
       break;
 
     case TEMPLATE_TEMPLATE_PARM:
       /* For parameters inside template signature.  */
       if (TYPE_IDENTIFIER (t))
-       print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
+       pp_tree_identifier (cxx_pp, TYPE_IDENTIFIER (t));
       else
-       print_identifier
-          (scratch_buffer, "<anonymous template template parameter>");
+       pp_identifier (cxx_pp, "<anonymous template template parameter>");
       break;
 
     case BOUND_TEMPLATE_TEMPLATE_PARM:
       {
        tree args = TYPE_TI_ARGS (t);
-       print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
-       print_template_argument_list_start (scratch_buffer);
+       pp_tree_identifier (cxx_pp, TYPE_IDENTIFIER (t));
+       pp_template_argument_list_start (cxx_pp);
         dump_template_argument_list (args, flags);
-       print_template_argument_list_end (scratch_buffer);
+       pp_template_argument_list_end (cxx_pp);
       }
       break;
 
     case TEMPLATE_TYPE_PARM:
       dump_qualifiers (t, after);
       if (TYPE_IDENTIFIER (t))
-       print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
+       pp_tree_identifier (cxx_pp, TYPE_IDENTIFIER (t));
       else
-       print_identifier
-          (scratch_buffer, "<anonymous template type parameter>");
+       pp_identifier (cxx_pp, "<anonymous template type parameter>");
       break;
 
       /* This is not always necessary for pointers and such, but doing this
@@ -434,29 +421,29 @@ dump_type (tree t, int flags)
     }
     case TYPENAME_TYPE:
       dump_qualifiers (t, after);
-      output_add_string (scratch_buffer, "typename ");
+      pp_string (cxx_pp, "typename ");
       dump_typename (t, flags);
       break;
 
     case UNBOUND_CLASS_TEMPLATE:
       dump_type (TYPE_CONTEXT (t), flags);
-      print_scope_operator (scratch_buffer);
-      print_identifier (scratch_buffer, "template ");
+      pp_colon_colon (cxx_pp);
+      pp_identifier (cxx_pp, "template ");
       dump_type (DECL_NAME (TYPE_NAME (t)), flags);
       break;
 
     case TYPEOF_TYPE:
-      output_add_string (scratch_buffer, "__typeof (");
+      pp_string (cxx_pp, "__typeof (");
       dump_expr (TYPE_FIELDS (t), flags & ~TFF_EXPR_IN_PARENS);
-      print_right_paren (scratch_buffer);
+      pp_right_paren (cxx_pp);
       break;
 
     default:
-      sorry_for_unsupported_tree (t);
+      pp_unsupported_tree (cxx_pp, t);
       /* Fall through to error.  */
 
     case ERROR_MARK:
-      print_identifier (scratch_buffer, "<type error>");
+      pp_identifier (cxx_pp, "<type error>");
       break;
     }
 }
@@ -473,7 +460,7 @@ dump_typename (tree t, int flags)
     dump_typename (ctx, flags);
   else
     dump_type (ctx, flags & ~TFF_CLASS_KEY_OR_ENUM);
-  print_scope_operator (scratch_buffer);
+  pp_colon_colon (cxx_pp);
   dump_decl (TYPENAME_TYPE_FULLNAME (t), flags);
 }
 
@@ -507,8 +494,8 @@ dump_aggr_type (tree t, int flags)
 
   if (flags & TFF_CLASS_KEY_OR_ENUM)
     {
-      print_identifier (scratch_buffer, variety);
-      output_add_space (scratch_buffer);
+      pp_identifier (cxx_pp, variety);
+      pp_space (cxx_pp);
     }
 
   if (flags & TFF_CHASE_TYPEDEF)
@@ -542,12 +529,12 @@ dump_aggr_type (tree t, int flags)
   if (name == 0 || ANON_AGGRNAME_P (name))
     {
       if (flags & TFF_CLASS_KEY_OR_ENUM)
-        print_identifier (scratch_buffer, "<anonymous>");
+        pp_identifier (cxx_pp, "<anonymous>");
       else
-        output_printf (scratch_buffer, "<anonymous %s>", variety);
+        pp_printf (cxx_pp, "<anonymous %s>", variety);
     }
   else
-    print_tree_identifier (scratch_buffer, name);
+    pp_tree_identifier (cxx_pp, name);
   if (tmplate)
     dump_template_parms (TYPE_TEMPLATE_INFO (t),
                          !CLASSTYPE_USE_TEMPLATE (t),
@@ -589,11 +576,10 @@ dump_type_prefix (tree t, int flags)
        padding = dump_type_prefix (sub, flags);
        if (TREE_CODE (sub) == ARRAY_TYPE)
          {
-           output_add_space (scratch_buffer);
-           print_left_paren (scratch_buffer);
+           pp_space (cxx_pp);
+           pp_left_paren (cxx_pp);
          }
-       output_add_character
-         (scratch_buffer, "&*"[TREE_CODE (t) == POINTER_TYPE]);
+       pp_character (cxx_pp, "&*"[TREE_CODE (t) == POINTER_TYPE]);
        padding = dump_qualifiers (t, before);
       }
       break;
@@ -604,11 +590,11 @@ dump_type_prefix (tree t, int flags)
       if (TREE_CODE (t) == OFFSET_TYPE)        /* pmfs deal with this in d_t_p */
        {
          if (padding != none)
-           output_add_space (scratch_buffer);
+           pp_space (cxx_pp);
          dump_type (TYPE_OFFSET_BASETYPE (t), flags);
-         print_scope_operator (scratch_buffer);
+         pp_colon_colon (cxx_pp);
        }
-      output_add_character (scratch_buffer, '*');
+      pp_star (cxx_pp);
       padding = dump_qualifiers (t, none);
       break;
 
@@ -617,19 +603,19 @@ dump_type_prefix (tree t, int flags)
     case FUNCTION_TYPE:
       padding = dump_type_prefix (TREE_TYPE (t), flags);
       if (padding != none)
-        output_add_space (scratch_buffer);
-      print_left_paren (scratch_buffer);
+        pp_space (cxx_pp);
+      pp_left_paren (cxx_pp);
       padding = none;
       break;
 
     case METHOD_TYPE:
       padding = dump_type_prefix (TREE_TYPE (t), flags);
       if (padding != none)
-        output_add_space (scratch_buffer);
-      print_left_paren (scratch_buffer);
+        pp_space (cxx_pp);
+      pp_left_paren (cxx_pp);
       padding = none;
       dump_aggr_type (TYPE_METHOD_BASETYPE (t), flags);
-      print_scope_operator (scratch_buffer);
+      pp_colon_colon (cxx_pp);
       break;
 
     case ARRAY_TYPE:
@@ -660,10 +646,10 @@ dump_type_prefix (tree t, int flags)
       break;
 
     default:
-      sorry_for_unsupported_tree (t);
+      pp_unsupported_tree (cxx_pp, t);
       /* fall through.  */
     case ERROR_MARK:
-      print_identifier (scratch_buffer, "<typeprefixerror>");
+      pp_identifier (cxx_pp, "<typeprefixerror>");
       break;
     }
   return padding;
@@ -684,7 +670,7 @@ dump_type_suffix (tree t, int flags)
     case REFERENCE_TYPE:
     case OFFSET_TYPE:
       if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
-       print_right_paren (scratch_buffer);
+       pp_right_paren (cxx_pp);
       dump_type_suffix (TREE_TYPE (t), flags);
       break;
 
@@ -693,7 +679,7 @@ dump_type_suffix (tree t, int flags)
     case METHOD_TYPE:
       {
        tree arg;
-        print_right_paren (scratch_buffer);
+        pp_right_paren (cxx_pp);
        arg = TYPE_ARG_TYPES (t);
        if (TREE_CODE (t) == METHOD_TYPE)
          arg = TREE_CHAIN (arg);
@@ -711,13 +697,12 @@ dump_type_suffix (tree t, int flags)
       }
 
     case ARRAY_TYPE:
-      print_left_bracket (scratch_buffer);
+      pp_left_bracket (cxx_pp);
       if (TYPE_DOMAIN (t))
        {
          if (host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0))
-           output_host_wide_integer
-              (scratch_buffer,
-               tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0) + 1);
+           pp_wide_integer
+              (cxx_pp, tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0) + 1);
          else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
            dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0),
                       flags & ~TFF_EXPR_IN_PARENS);
@@ -727,7 +712,7 @@ dump_type_suffix (tree t, int flags)
                              integer_one_node)),
                       flags & ~TFF_EXPR_IN_PARENS);
        }
-      print_right_bracket (scratch_buffer);
+      pp_right_bracket (cxx_pp);
       dump_type_suffix (TREE_TYPE (t), flags);
       break;
 
@@ -753,7 +738,7 @@ dump_type_suffix (tree t, int flags)
       break;
 
     default:
-      sorry_for_unsupported_tree (t);
+      pp_unsupported_tree (cxx_pp, t);
     case ERROR_MARK:
       /* Don't mark it here, we should have already done in
          dump_type_prefix.  */
@@ -773,7 +758,7 @@ dump_global_iord (tree t)
   else
     abort ();
 
-  output_printf (scratch_buffer, "(static %s for %s)", p, input_filename);
+  pp_printf (cxx_pp, "(static %s for %s)", p, input_filename);
 }
 
 static void
@@ -782,14 +767,14 @@ dump_simple_decl (tree t, tree type, int flags)
   if (flags & TFF_DECL_SPECIFIERS)
     {
       if (dump_type_prefix (type, flags) != none)
-        output_add_space (scratch_buffer);
+        pp_space (cxx_pp);
     }
   if (!DECL_INITIAL (t) || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)
     dump_scope (CP_DECL_CONTEXT (t), flags);
   if (DECL_NAME (t))
     dump_decl (DECL_NAME (t), flags);
   else
-    print_identifier (scratch_buffer, "<anonymous>");
+    pp_identifier (cxx_pp, "<anonymous>");
   if (flags & TFF_DECL_SPECIFIERS)
     dump_type_suffix (type, flags);
 }
@@ -812,14 +797,14 @@ dump_decl (tree t, int flags)
            if ((flags & TFF_DECL_SPECIFIERS)
                && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
              /* Say `class T' not just `T'.  */
-             output_add_string (scratch_buffer, "class ");
+             pp_string (cxx_pp, "class ");
 
            dump_type (TREE_TYPE (t), flags);
            break;
          }
       }
       if (flags & TFF_DECL_SPECIFIERS)
-       output_add_string (scratch_buffer, "typedef ");
+       pp_string (cxx_pp, "typedef ");
       dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
                        ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
                        flags);
@@ -828,7 +813,7 @@ dump_decl (tree t, int flags)
     case VAR_DECL:
       if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
        {
-         output_add_string (scratch_buffer, "vtable for ");
+         pp_string (cxx_pp, "vtable for ");
          my_friendly_assert (TYPE_P (DECL_CONTEXT (t)), 20010720);
          dump_type (DECL_CONTEXT (t), flags);
          break;
@@ -840,29 +825,29 @@ dump_decl (tree t, int flags)
       break;
 
     case RESULT_DECL:
-      output_add_string (scratch_buffer, "<return value> ");
+      pp_string (cxx_pp, "<return value> ");
       dump_simple_decl (t, TREE_TYPE (t), flags);
       break;
 
     case NAMESPACE_DECL:
       dump_scope (CP_DECL_CONTEXT (t), flags);
       if (DECL_NAME (t) == anonymous_namespace_name)
-       print_identifier (scratch_buffer, "<unnamed>");
+       pp_identifier (cxx_pp, "<unnamed>");
       else
-       print_tree_identifier (scratch_buffer, DECL_NAME (t));
+       pp_tree_identifier (cxx_pp, DECL_NAME (t));
       break;
 
     case SCOPE_REF:
       dump_decl (TREE_OPERAND (t, 0), flags & ~TFF_DECL_SPECIFIERS);
-      print_scope_operator (scratch_buffer); 
+      pp_colon_colon (cxx_pp); 
       dump_decl (TREE_OPERAND (t, 1), flags);
       break;
 
     case ARRAY_REF:
       dump_decl (TREE_OPERAND (t, 0), flags);
-      print_left_bracket (scratch_buffer);
+      pp_left_bracket (cxx_pp);
       dump_decl (TREE_OPERAND (t, 1), flags);
-      print_right_bracket (scratch_buffer);
+      pp_right_bracket (cxx_pp);
       break;
 
       /* So that we can do dump_decl on an aggr type.  */
@@ -875,7 +860,7 @@ dump_decl (tree t, int flags)
     case BIT_NOT_EXPR:
       /* This is a pseudo destructor call which has not been folded into
          a PSEUDO_DTOR_EXPR yet.  */
-      output_add_character (scratch_buffer, '~');
+      pp_complement (cxx_pp);
       dump_type (TREE_OPERAND (t, 0), flags);
       break;
 
@@ -888,13 +873,13 @@ dump_decl (tree t, int flags)
     case IDENTIFIER_NODE:
       if (IDENTIFIER_TYPENAME_P (t))
        {
-         output_add_string (scratch_buffer, "operator ");
+         pp_string (cxx_pp, "operator ");
          /* Not exactly IDENTIFIER_TYPE_VALUE.  */
          dump_type (TREE_TYPE (t), flags);
          break;
        }
       else
-       print_tree_identifier (scratch_buffer, t);
+       pp_tree_identifier (cxx_pp, t);
       break;
 
     case OVERLOAD:
@@ -904,12 +889,12 @@ dump_decl (tree t, int flags)
          if (DECL_CLASS_SCOPE_P (t))
            {
              dump_type (DECL_CONTEXT (t), flags);
-             output_add_string (scratch_buffer, "::");
+              pp_colon_colon (cxx_pp);
            }
          else if (DECL_CONTEXT (t))
            {
              dump_decl (DECL_CONTEXT (t), flags);
-             output_add_string (scratch_buffer, "::");
+              pp_colon_colon (cxx_pp);
            }
          dump_decl (DECL_NAME (t), flags);
          break;
@@ -924,7 +909,7 @@ dump_decl (tree t, int flags)
       if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
        dump_global_iord (t);
       else if (! DECL_LANG_SPECIFIC (t))
-       print_identifier (scratch_buffer, "<internal>");
+       pp_identifier (cxx_pp, "<internal>");
       else
         dump_function_decl (t, flags);
       break;
@@ -940,19 +925,19 @@ dump_decl (tree t, int flags)
        if (is_overloaded_fn (name))
          name = DECL_NAME (get_first_fn (name));
        dump_decl (name, flags);
-       print_template_argument_list_start (scratch_buffer);
+       pp_template_argument_list_start (cxx_pp);
        for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
          {
            dump_template_argument (TREE_VALUE (args), flags);
            if (TREE_CHAIN (args))
-             separate_with_comma (scratch_buffer);
+             pp_separate_with_comma (cxx_pp);
          }
-       print_template_argument_list_end (scratch_buffer);
+       pp_template_argument_list_end (cxx_pp);
       }
       break;
 
     case LABEL_DECL:
-      print_tree_identifier (scratch_buffer, DECL_NAME (t));
+      pp_tree_identifier (cxx_pp, DECL_NAME (t));
       break;
 
     case CONST_DECL:
@@ -965,13 +950,13 @@ dump_decl (tree t, int flags)
       else if (DECL_INITIAL (t))
        dump_expr (DECL_INITIAL (t), flags | TFF_EXPR_IN_PARENS);
       else
-       print_identifier (scratch_buffer, "<enumerator>");
+       pp_identifier (cxx_pp, "<enumerator>");
       break;
 
     case USING_DECL:
-      output_add_string (scratch_buffer, "using ");
+      pp_string (cxx_pp, "using ");
       dump_type (DECL_INITIAL (t), flags);
-      print_scope_operator (scratch_buffer);
+      pp_colon_colon (cxx_pp);
       dump_decl (DECL_NAME (t), flags);
       break;
 
@@ -984,11 +969,11 @@ dump_decl (tree t, int flags)
       break;
 
     default:
-      sorry_for_unsupported_tree (t);
+      pp_unsupported_tree (cxx_pp, t);
       /* Fallthrough to error.  */
 
     case ERROR_MARK:
-      print_identifier (scratch_buffer, "<declaration error>");
+      pp_identifier (cxx_pp, "<declaration error>");
       break;
     }
 }
@@ -1012,7 +997,7 @@ dump_template_decl (tree t, int flags)
          tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
           int len = TREE_VEC_LENGTH (inner_parms);
 
-          output_add_string (scratch_buffer, "template<");
+          pp_string (cxx_pp, "template<");
 
          /* If we've shown the template prefix, we'd better show the
             parameters' and decl's type too.  */
@@ -1021,17 +1006,17 @@ dump_template_decl (tree t, int flags)
           for (i = 0; i < len; i++)
             {
               if (i)
-                separate_with_comma (scratch_buffer);
+                pp_separate_with_comma (cxx_pp);
               dump_template_parameter (TREE_VEC_ELT (inner_parms, i), flags);
             }
-          print_template_argument_list_end (scratch_buffer);
-          output_add_space (scratch_buffer);
+          pp_template_argument_list_end (cxx_pp);
+          pp_space (cxx_pp);
         }
       nreverse(orig_parms);
 
       if (DECL_TEMPLATE_TEMPLATE_PARM_P (t))
        /* Say `template<arg> class TT' not just `template<arg> TT'.  */
-       output_add_string (scratch_buffer, "class ");
+       pp_string (cxx_pp, "class ");
     }
 
   if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
@@ -1101,9 +1086,9 @@ dump_function_decl (tree t, int flags)
   if (!(flags & TFF_DECL_SPECIFIERS))
     /* OK */;
   else if (DECL_STATIC_FUNCTION_P (t))
-    print_identifier (scratch_buffer, "static ");
+    pp_identifier (cxx_pp, "static ");
   else if (DECL_VIRTUAL_P (t))
-    print_identifier (scratch_buffer, "virtual ");
+    pp_identifier (cxx_pp, "virtual ");
 
   /* Print the return type?  */
   if (show_return)
@@ -1112,14 +1097,14 @@ dump_function_decl (tree t, int flags)
   if (show_return)
     {
       dump_type_prefix (TREE_TYPE (fntype), flags);
-      output_add_space (scratch_buffer);
+      pp_space (cxx_pp);
     }
 
   /* Print the function name.  */
   if (cname)
     {
       dump_type (cname, flags);
-      print_scope_operator (scratch_buffer);
+      pp_colon_colon (cxx_pp);
     }
   else
     dump_scope (CP_DECL_CONTEXT (t), flags);
@@ -1144,9 +1129,9 @@ dump_function_decl (tree t, int flags)
   /* If T is a template instantiation, dump the parameter binding.  */
   if (template_parms != NULL_TREE && template_args != NULL_TREE)
     {
-      output_add_string (scratch_buffer, " [with ");
+      pp_string (cxx_pp, " [with ");
       dump_template_bindings (template_parms, template_args);
-      print_right_bracket (scratch_buffer);
+      pp_right_bracket (cxx_pp);
     }
 }
 
@@ -1159,29 +1144,29 @@ dump_parameters (tree parmtypes, int flags)
 {
   int first;
 
-  print_left_paren (scratch_buffer);
+  pp_left_paren (cxx_pp);
 
   for (first = 1; parmtypes != void_list_node;
        parmtypes = TREE_CHAIN (parmtypes))
     {
       if (!first)
-        separate_with_comma (scratch_buffer);
+        pp_separate_with_comma (cxx_pp);
       first = 0;
       if (!parmtypes)
         {
-          print_identifier (scratch_buffer, "...");
+          pp_identifier (cxx_pp, "...");
           break;
         }
       dump_type (TREE_VALUE (parmtypes), flags);
 
       if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && TREE_PURPOSE (parmtypes))
         {
-          output_add_string (scratch_buffer, " = ");
+          pp_string (cxx_pp, " = ");
           dump_expr (TREE_PURPOSE (parmtypes), flags | TFF_EXPR_IN_PARENS);
         }
     }
 
-  print_right_paren (scratch_buffer);
+  pp_right_paren (cxx_pp);
 }
 
 /* Print an exception specification. T is the exception specification.  */
@@ -1191,7 +1176,7 @@ dump_exception_spec (tree t, int flags)
 {
   if (t)
     {
-      output_add_string (scratch_buffer, " throw (");
+      pp_string (cxx_pp, " throw (");
       if (TREE_VALUE (t) != NULL_TREE)
         while (1)
           {
@@ -1199,9 +1184,9 @@ dump_exception_spec (tree t, int flags)
             t = TREE_CHAIN (t);
             if (!t)
               break;
-            separate_with_comma (scratch_buffer);
+            pp_separate_with_comma (cxx_pp);
           }
-      print_right_paren (scratch_buffer);
+      pp_right_paren (cxx_pp);
     }
 }
 
@@ -1223,7 +1208,7 @@ dump_function_name (tree t, int flags)
 
   if (DECL_DESTRUCTOR_P (t))
     {
-      output_add_character (scratch_buffer, '~');
+      pp_complement (cxx_pp);
       dump_decl (name, TFF_PLAIN_IDENTIFIER);
     }
   else if (DECL_CONV_FN_P (t))
@@ -1234,11 +1219,11 @@ dump_function_name (tree t, int flags)
         declarations, both will have the same name, yet
         the types will be different, hence the TREE_TYPE field
         of the first name will be clobbered by the second.  */
-      output_add_string (scratch_buffer, "operator ");
+      pp_string (cxx_pp, "operator ");
       dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
     }
   else if (IDENTIFIER_OPNAME_P (name))
-    print_tree_identifier (scratch_buffer, name);
+    pp_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1265,7 +1250,7 @@ dump_template_parms (tree info, int primary, int flags)
   if (primary && flags & TFF_TEMPLATE_NAME)
     return;
   flags &= ~(TFF_CLASS_KEY_OR_ENUM | TFF_TEMPLATE_NAME);
-  print_template_argument_list_start (scratch_buffer);
+  pp_template_argument_list_start (cxx_pp);
 
   /* Be careful only to print things when we have them, so as not
         to crash producing error messages.  */
@@ -1299,10 +1284,10 @@ dump_template_parms (tree info, int primary, int flags)
               args = TREE_CHAIN (args);
             }
           if (need_comma)
-            separate_with_comma (scratch_buffer);
+            pp_separate_with_comma (cxx_pp);
           
           if (!arg)
-            print_identifier (scratch_buffer, "<template parameter error>");
+            pp_identifier (cxx_pp, "<template parameter error>");
           else
             dump_template_argument (arg, flags);
           need_comma = 1;
@@ -1322,12 +1307,12 @@ dump_template_parms (tree info, int primary, int flags)
           tree parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
 
           if (ix)
-            separate_with_comma (scratch_buffer);
+            pp_separate_with_comma (cxx_pp);
 
           dump_decl (parm, flags & ~TFF_DECL_SPECIFIERS);
         }
     }
-  print_template_argument_list_end (scratch_buffer);
+  pp_template_argument_list_end (cxx_pp);
 }
 
 static void
@@ -1336,40 +1321,40 @@ dump_char (int c)
   switch (c)
     {
     case TARGET_NEWLINE:
-      output_add_string (scratch_buffer, "\\n");
+      pp_string (cxx_pp, "\\n");
       break;
     case TARGET_TAB:
-      output_add_string (scratch_buffer, "\\t");
+      pp_string (cxx_pp, "\\t");
       break;
     case TARGET_VT:
-      output_add_string (scratch_buffer, "\\v");
+      pp_string (cxx_pp, "\\v");
       break;
     case TARGET_BS:
-      output_add_string (scratch_buffer, "\\b");
+      pp_string (cxx_pp, "\\b");
       break;
     case TARGET_CR:
-      output_add_string (scratch_buffer, "\\r");
+      pp_string (cxx_pp, "\\r");
       break;
     case TARGET_FF:
-      output_add_string (scratch_buffer, "\\f");
+      pp_string (cxx_pp, "\\f");
       break;
     case TARGET_BELL:
-      output_add_string (scratch_buffer, "\\a");
+      pp_string (cxx_pp, "\\a");
       break;
     case '\\':
-      output_add_string (scratch_buffer, "\\\\");
+      pp_string (cxx_pp, "\\\\");
       break;
     case '\'':
-      output_add_string (scratch_buffer, "\\'");
+      pp_string (cxx_pp, "\\'");
       break;
     case '\"':
-      output_add_string (scratch_buffer, "\\\"");
+      pp_string (cxx_pp, "\\\"");
       break;
     default:
       if (ISPRINT (c))
-       output_add_character (scratch_buffer, c);
+       pp_character (cxx_pp, c);
       else
-        output_formatted_scalar (scratch_buffer, "\\%03o", (unsigned) c);
+        pp_scalar (cxx_pp, "\\%03o", (unsigned) c);
       break;
     }
 }
@@ -1384,7 +1369,7 @@ dump_expr_list (tree l, int flags)
       dump_expr (TREE_VALUE (l), flags | TFF_EXPR_IN_PARENS);
       l = TREE_CHAIN (l);
       if (l)
-       separate_with_comma (scratch_buffer);
+       pp_separate_with_comma (cxx_pp);
     }
 }
 
@@ -1426,32 +1411,32 @@ dump_expr (tree t, int flags)
                break;
 
            if (values)
-             print_tree_identifier (scratch_buffer, TREE_PURPOSE (values));
+             pp_tree_identifier (cxx_pp, TREE_PURPOSE (values));
            else
              {
                 /* Value must have been cast.  */
-                print_left_paren (scratch_buffer);
+                pp_left_paren (cxx_pp);
                 dump_type (type, flags);
-                print_right_paren (scratch_buffer);
+                pp_right_paren (cxx_pp);
                 goto do_int;
              }
          }
        else if (type == boolean_type_node)
          {
            if (t == boolean_false_node || integer_zerop (t))
-             print_identifier (scratch_buffer, "false");
+             pp_identifier (cxx_pp, "false");
            else if (t == boolean_true_node)
-             print_identifier (scratch_buffer, "true");
+             pp_identifier (cxx_pp, "true");
          }
        else if (type == char_type_node)
          {
-           output_add_character (scratch_buffer, '\'');
+            pp_quote (cxx_pp);
            if (host_integerp (t, TREE_UNSIGNED (type)))
              dump_char (tree_low_cst (t, TREE_UNSIGNED (type)));
            else
-             output_printf (scratch_buffer, "\\x%x",
-                            (unsigned int) TREE_INT_CST_LOW (t));
-           output_add_character (scratch_buffer, '\'');
+             pp_printf (cxx_pp, "\\x%x",
+                         (unsigned int) TREE_INT_CST_LOW (t));
+            pp_quote (cxx_pp);
          }
        else
          {
@@ -1462,35 +1447,33 @@ dump_expr (tree t, int flags)
 
                if (tree_int_cst_sgn (val) < 0)
                  {
-                   output_add_character (scratch_buffer, '-');
+                    pp_minus (cxx_pp);
                    val = build_int_2 (-TREE_INT_CST_LOW (val),
                                       ~TREE_INT_CST_HIGH (val)
                                       + !TREE_INT_CST_LOW (val));
                  }
-               sprintf (scratch_buffer->digit_buffer,
+               sprintf (cxx_pp->buffer->digit_buffer,
                          HOST_WIDE_INT_PRINT_DOUBLE_HEX,
                         TREE_INT_CST_HIGH (val), TREE_INT_CST_LOW (val));
-               output_add_string
-                  (scratch_buffer, scratch_buffer->digit_buffer);
+               pp_string (cxx_pp, cxx_pp->buffer->digit_buffer);
              }
            else
-             output_host_wide_integer (scratch_buffer, TREE_INT_CST_LOW (t));
+             pp_wide_integer (cxx_pp, TREE_INT_CST_LOW (t));
          }
       }
       break;
 
     case REAL_CST:
-      real_to_decimal (scratch_buffer->digit_buffer, &TREE_REAL_CST (t),
-                      sizeof (scratch_buffer->digit_buffer), 0, 1);
-      output_add_string (scratch_buffer, scratch_buffer->digit_buffer);
+      real_to_decimal (cxx_pp->buffer->digit_buffer, &TREE_REAL_CST (t),
+                      sizeof (cxx_pp->buffer->digit_buffer), 0, 1);
+      pp_string (cxx_pp, cxx_pp->buffer->digit_buffer);
       break;
 
     case PTRMEM_CST:
-      output_add_character (scratch_buffer, '&');
+      pp_ampersand (cxx_pp);
       dump_type (PTRMEM_CST_CLASS (t), flags);
-      print_scope_operator (scratch_buffer);
-      print_tree_identifier
-        (scratch_buffer, DECL_NAME (PTRMEM_CST_MEMBER (t)));
+      pp_colon_colon (cxx_pp);
+      pp_tree_identifier (cxx_pp, DECL_NAME (PTRMEM_CST_MEMBER (t)));
       break;
 
     case STRING_CST:
@@ -1499,15 +1482,15 @@ dump_expr (tree t, int flags)
        int len = TREE_STRING_LENGTH (t) - 1;
        int i;
 
-       output_add_character (scratch_buffer, '\"');
+       pp_doublequote (cxx_pp);
        for (i = 0; i < len; i++)
          dump_char (p[i]);
-       output_add_character (scratch_buffer, '\"');
+       pp_doublequote (cxx_pp);
       }
       break;
 
     case COMPOUND_EXPR:
-      print_left_paren (scratch_buffer);
+      pp_left_paren (cxx_pp);
       /* Within templates, a COMPOUND_EXPR has only one operand,
          containing a TREE_LIST of the two operands.  */
       if (TREE_CODE (TREE_OPERAND (t, 0)) == TREE_LIST)
@@ -1519,32 +1502,30 @@ dump_expr (tree t, int flags)
       else
       {
         dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
-        separate_with_comma (scratch_buffer);
+        pp_separate_with_comma (cxx_pp);
         dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
       }
-      print_right_paren (scratch_buffer);
+      pp_right_paren (cxx_pp);
       break;
 
     case COND_EXPR:
-      print_left_paren (scratch_buffer);
+      pp_left_paren (cxx_pp);
       dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
-      output_add_string (scratch_buffer, " ? ");
+      pp_string (cxx_pp, " ? ");
       dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
-      output_add_string (scratch_buffer, " : ");
+      pp_string (cxx_pp, " : ");
       dump_expr (TREE_OPERAND (t, 2), flags | TFF_EXPR_IN_PARENS);
-      print_right_paren (scratch_buffer);
+      pp_right_paren (cxx_pp);
       break;
 
     case SAVE_EXPR:
       if (TREE_HAS_CONSTRUCTOR (t))
        {
-         output_add_string (scratch_buffer, "new ");
+         pp_string (cxx_pp, "new ");
          dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
        }
       else
-       {
-         dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
-       }
+        dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
       break;
 
     case AGGR_INIT_EXPR:
@@ -1557,18 +1538,17 @@ dump_expr (tree t, int flags)
        if (fn && TREE_CODE (fn) == FUNCTION_DECL)
          {
            if (DECL_CONSTRUCTOR_P (fn))
-             print_tree_identifier
-                (scratch_buffer, TYPE_IDENTIFIER (TREE_TYPE (t)));
+             pp_tree_identifier (cxx_pp, TYPE_IDENTIFIER (TREE_TYPE (t)));
            else
              dump_decl (fn, 0);
          }
        else
          dump_expr (TREE_OPERAND (t, 0), 0);
       }
-      print_left_paren (scratch_buffer);
+      pp_left_paren (cxx_pp);
       if (TREE_OPERAND (t, 1))
        dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
-      print_right_paren (scratch_buffer);
+      pp_right_paren (cxx_pp);
       break;
 
     case CALL_EXPR:
@@ -1585,20 +1565,20 @@ dump_expr (tree t, int flags)
            if (TREE_CODE (ob) == ADDR_EXPR)
              {
                dump_expr (TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS);
-               output_add_character (scratch_buffer, '.');
+               pp_dot (cxx_pp);
              }
            else if (TREE_CODE (ob) != PARM_DECL
                     || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
              {
                dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
-               output_add_string (scratch_buffer, "->");
+               pp_arrow (cxx_pp);
              }
            args = TREE_CHAIN (args);
          }
        dump_expr (fn, flags | TFF_EXPR_IN_PARENS);
-       print_left_paren (scratch_buffer);
+       pp_left_paren (cxx_pp);
        dump_expr_list (args, flags);
-       print_right_paren (scratch_buffer);
+       pp_right_paren (cxx_pp);
       }
       break;
 
@@ -1607,13 +1587,13 @@ dump_expr (tree t, int flags)
        tree type = TREE_OPERAND (t, 1);
        tree init = TREE_OPERAND (t, 2);
        if (NEW_EXPR_USE_GLOBAL (t))
-         print_scope_operator (scratch_buffer);
-       output_add_string (scratch_buffer, "new ");
+          pp_colon_colon (cxx_pp);
+       pp_string (cxx_pp, "new ");
        if (TREE_OPERAND (t, 0))
          {
-           print_left_paren (scratch_buffer);
+           pp_left_paren (cxx_pp);
            dump_expr_list (TREE_OPERAND (t, 0), flags);
-           output_add_string (scratch_buffer, ") ");
+           pp_string (cxx_pp, ") ");
          }
        if (TREE_CODE (type) == ARRAY_REF)
          type = build_cplus_array_type
@@ -1624,7 +1604,7 @@ dump_expr (tree t, int flags)
        dump_type (type, flags);
        if (init)
          {
-           print_left_paren (scratch_buffer);
+           pp_left_paren (cxx_pp);
            if (TREE_CODE (init) == TREE_LIST)
              dump_expr_list (init, flags);
            else if (init == void_zero_node)
@@ -1633,7 +1613,7 @@ dump_expr (tree t, int flags)
              ;
            else
              dump_expr (init, flags);
-           print_right_paren (scratch_buffer);
+           pp_right_paren (cxx_pp);
          }
       }
       break;
@@ -1697,13 +1677,13 @@ dump_expr (tree t, int flags)
                || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
              {
                dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
-               output_add_string (scratch_buffer, "->");
+               pp_arrow (cxx_pp);
              }
          }
        else
          {
            dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
-           output_add_character (scratch_buffer, '.');
+           pp_dot (cxx_pp);
          }
        dump_expr (TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
       }
@@ -1711,17 +1691,17 @@ dump_expr (tree t, int flags)
 
     case ARRAY_REF:
       dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
-      print_left_bracket (scratch_buffer);
+      pp_left_bracket (cxx_pp);
       dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
-      print_right_bracket (scratch_buffer);
+      pp_right_bracket (cxx_pp);
       break;
 
     case CONVERT_EXPR:
       if (TREE_TYPE (t) && VOID_TYPE_P (TREE_TYPE (t)))
        {
-         print_left_paren (scratch_buffer);
+         pp_left_paren (cxx_pp);
          dump_type (TREE_TYPE (t), flags);
-         print_right_paren (scratch_buffer);
+         pp_right_paren (cxx_pp);
          dump_expr (TREE_OPERAND (t, 0), flags);
        }
       else
@@ -1747,9 +1727,9 @@ dump_expr (tree t, int flags)
          t = TREE_OPERAND (t, 0);
          my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
          dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
-         print_left_paren (scratch_buffer);
+         pp_left_paren (cxx_pp);
          dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
-         print_right_paren (scratch_buffer);
+         pp_right_paren (cxx_pp);
        }
       else
        {
@@ -1772,11 +1752,10 @@ dump_expr (tree t, int flags)
 
     case POSTDECREMENT_EXPR:
     case POSTINCREMENT_EXPR:
-      print_left_paren (scratch_buffer);
+      pp_left_paren (cxx_pp);
       dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
-      print_identifier
-        (scratch_buffer, operator_name_info[(int)TREE_CODE (t)].name);
-      print_right_paren (scratch_buffer);
+      pp_identifier (cxx_pp, operator_name_info[(int)TREE_CODE (t)].name);
+      pp_right_paren (cxx_pp);
       break;
 
     case NON_LVALUE_EXPR:
@@ -1793,11 +1772,11 @@ dump_expr (tree t, int flags)
          if (TREE_CODE (next) == FUNCTION_TYPE)
            {
              if (flags & TFF_EXPR_IN_PARENS)
-               print_left_paren (scratch_buffer);
-             output_add_character (scratch_buffer, '*');
+               pp_left_paren (cxx_pp);
+             pp_star (cxx_pp);
              dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
              if (flags & TFF_EXPR_IN_PARENS)
-               print_right_paren (scratch_buffer);
+               pp_right_paren (cxx_pp);
              break;
            }
          /* else FALLTHRU */
@@ -1821,9 +1800,11 @@ dump_expr (tree t, int flags)
          if (integer_zerop (idx))
            {
              /* A NULL pointer-to-member constant.  */
-             output_add_string (scratch_buffer, "((");
+              pp_left_paren (cxx_pp);
+              pp_left_paren (cxx_pp);
              dump_type (TREE_TYPE (t), flags);
-             output_add_string (scratch_buffer, ") 0)");
+              pp_right_paren (cxx_pp);
+              pp_string (cxx_pp, ")0)");
              break;
            }
          else if (host_integerp (idx, 0))
@@ -1857,14 +1838,14 @@ dump_expr (tree t, int flags)
       if (TREE_TYPE (t) && !CONSTRUCTOR_ELTS (t))
        {
          dump_type (TREE_TYPE (t), 0);
-         output_add_character (scratch_buffer, '(');
-         output_add_character (scratch_buffer, ')');
+          pp_left_paren (cxx_pp);
+          pp_right_paren (cxx_pp);
        }
       else
        {
-         output_add_character (scratch_buffer, '{');
+          pp_left_brace (cxx_pp);
          dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
-         output_add_character (scratch_buffer, '}');
+          pp_right_brace (cxx_pp);
        }
       
       break;
@@ -1889,12 +1870,12 @@ dump_expr (tree t, int flags)
            if (TREE_CODE (ob) == INDIRECT_REF)
              {
                dump_expr (TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS);
-               output_add_string (scratch_buffer, "->*");
+               pp_string (cxx_pp, "->*");
              }
            else
              {
                dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
-               output_add_string (scratch_buffer, ".*");
+               pp_string (cxx_pp, ".*");
              }
            dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
          }
@@ -1907,7 +1888,7 @@ dump_expr (tree t, int flags)
 
     case SCOPE_REF:
       dump_type (TREE_OPERAND (t, 0), flags);
-      print_scope_operator (scratch_buffer);
+      pp_colon_colon (cxx_pp);
       dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
       break;
 
@@ -1916,69 +1897,68 @@ dump_expr (tree t, int flags)
          || TREE_CHAIN (TREE_OPERAND (t, 0)))
        {
          dump_type (TREE_TYPE (t), flags);
-         print_left_paren (scratch_buffer);
+         pp_left_paren (cxx_pp);
          dump_expr_list (TREE_OPERAND (t, 0), flags);
-         print_right_paren (scratch_buffer);
+         pp_right_paren (cxx_pp);
        }
       else
        {
-         print_left_paren (scratch_buffer);
+         pp_left_paren (cxx_pp);
          dump_type (TREE_TYPE (t), flags);
-          output_add_string (scratch_buffer, ")(");
+          pp_string (cxx_pp, ")(");
          dump_expr_list (TREE_OPERAND (t, 0), flags);
-         print_right_paren (scratch_buffer);
+         pp_right_paren (cxx_pp);
        }
       break;
 
     case STATIC_CAST_EXPR:
-      output_add_string (scratch_buffer, "static_cast<");
+      pp_string (cxx_pp, "static_cast<");
       goto cast;
     case REINTERPRET_CAST_EXPR:
-      output_add_string (scratch_buffer, "reinterpret_cast<");
+      pp_string (cxx_pp, "reinterpret_cast<");
       goto cast;
     case CONST_CAST_EXPR:
-      output_add_string (scratch_buffer, "const_cast<");
+      pp_string (cxx_pp, "const_cast<");
       goto cast;
     case DYNAMIC_CAST_EXPR:
-      output_add_string (scratch_buffer, "dynamic_cast<");
+      pp_string (cxx_pp, "dynamic_cast<");
     cast:
       dump_type (TREE_TYPE (t), flags);
-      output_add_string (scratch_buffer, ">(");
+      pp_string (cxx_pp, ">(");
       dump_expr (TREE_OPERAND (t, 0), flags);
-      print_right_paren (scratch_buffer);
+      pp_right_paren (cxx_pp);
       break;
 
     case ARROW_EXPR:
       dump_expr (TREE_OPERAND (t, 0), flags);
-      output_add_string (scratch_buffer, "->");
+      pp_arrow (cxx_pp);
       break;
 
     case SIZEOF_EXPR:
     case ALIGNOF_EXPR:
       if (TREE_CODE (t) == SIZEOF_EXPR)
-       output_add_string (scratch_buffer, "sizeof (");
+       pp_string (cxx_pp, "sizeof (");
       else
        {
          my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
-         output_add_string (scratch_buffer, "__alignof__ (");
+         pp_string (cxx_pp, "__alignof__ (");
        }
       if (TYPE_P (TREE_OPERAND (t, 0)))
        dump_type (TREE_OPERAND (t, 0), flags);
       else
         dump_expr (TREE_OPERAND (t, 0), flags);
-      print_right_paren (scratch_buffer);
+      pp_right_paren (cxx_pp);
       break;
 
     case REALPART_EXPR:
     case IMAGPART_EXPR:
-      print_identifier (scratch_buffer,
-                        operator_name_info[TREE_CODE (t)].name);
-      output_add_space (scratch_buffer);
+      pp_identifier (cxx_pp, operator_name_info[TREE_CODE (t)].name);
+      pp_space (cxx_pp);
       dump_expr (TREE_OPERAND (t, 0), flags);
       break;
 
     case DEFAULT_ARG:
-      print_identifier (scratch_buffer, "<unparsed>");
+      pp_identifier (cxx_pp, "<unparsed>");
       break;
 
     case TRY_CATCH_EXPR:
@@ -1989,9 +1969,10 @@ dump_expr (tree t, int flags)
 
     case PSEUDO_DTOR_EXPR:
       dump_expr (TREE_OPERAND (t, 2), flags);
-      output_add_character (scratch_buffer, '.');
+      pp_dot (cxx_pp);
       dump_type (TREE_OPERAND (t, 0), flags);
-      output_add_string (scratch_buffer, "::~");
+      pp_colon_colon (cxx_pp);
+      pp_complement (cxx_pp);
       dump_type (TREE_OPERAND (t, 1), flags);
       break;
 
@@ -2002,25 +1983,25 @@ dump_expr (tree t, int flags)
     case STMT_EXPR:
       /* We don't yet have a way of dumping statements in a
         human-readable format.  */
-      output_add_string (scratch_buffer, "({...})");
+      pp_string (cxx_pp, "({...})");
       break;
 
     case BIND_EXPR:
-      output_add_character (scratch_buffer, '{');
+      pp_left_brace (cxx_pp);
       dump_expr (TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
-      output_add_character (scratch_buffer, '}');
+      pp_right_brace (cxx_pp);
       break;
 
     case LOOP_EXPR:
-      output_add_string (scratch_buffer, "while (1) { ");
+      pp_string (cxx_pp, "while (1) { ");
       dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
-      output_add_character (scratch_buffer, '}');
+      pp_right_brace (cxx_pp);
       break;
 
     case EXIT_EXPR:
-      output_add_string (scratch_buffer, "if (");
+      pp_string (cxx_pp, "if (");
       dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
-      output_add_string (scratch_buffer, ") break; ");
+      pp_string (cxx_pp, ") break; ");
       break;
 
     case BASELINK:
@@ -2029,24 +2010,24 @@ dump_expr (tree t, int flags)
 
     case EMPTY_CLASS_EXPR:
       dump_type (TREE_TYPE (t), flags);
-      print_left_paren (scratch_buffer);
-      print_right_paren (scratch_buffer);
+      pp_left_paren (cxx_pp);
+      pp_right_paren (cxx_pp);
       break;
 
     case NON_DEPENDENT_EXPR:
-      output_add_string (scratch_buffer, "<expression of type ");
+      pp_string (cxx_pp, "<expression of type ");
       dump_type (TREE_TYPE (t), flags);
-      output_add_character (scratch_buffer, '>');
+      pp_greater (cxx_pp);
       break;
 
       /*  This list is incomplete, but should suffice for now.
          It is very important that `sorry' does not call
          `report_error_function'.  That could cause an infinite loop.  */
     default:
-      sorry_for_unsupported_tree (t);
+      pp_unsupported_tree (cxx_pp, t);
       /* fall through to ERROR_MARK...  */
     case ERROR_MARK:
-      print_identifier (scratch_buffer, "<expression error>");
+      pp_identifier (cxx_pp, "<expression error>");
       break;
     }
 }
@@ -2054,27 +2035,27 @@ dump_expr (tree t, int flags)
 static void
 dump_binary_op (const char *opstring, tree t, int flags)
 {
-  print_left_paren (scratch_buffer);
+  pp_left_paren (cxx_pp);
   dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
-  output_add_space (scratch_buffer);
+  pp_space (cxx_pp);
   if (opstring)
-    print_identifier (scratch_buffer, opstring);
+    pp_identifier (cxx_pp, opstring);
   else
-    print_identifier (scratch_buffer, "<unknown operator>");
-  output_add_space (scratch_buffer);
+    pp_identifier (cxx_pp, "<unknown operator>");
+  pp_space (cxx_pp);
   dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
-  print_right_paren (scratch_buffer);
+  pp_right_paren (cxx_pp);
 }
 
 static void
 dump_unary_op (const char *opstring, tree t, int flags)
 {
   if (flags & TFF_EXPR_IN_PARENS)
-    print_left_paren (scratch_buffer);
-  print_identifier (scratch_buffer, opstring);
+    pp_left_paren (cxx_pp);
+  pp_identifier (cxx_pp, opstring);
   dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
   if (flags & TFF_EXPR_IN_PARENS)
-    print_right_paren (scratch_buffer);
+    pp_right_paren (cxx_pp);
 }
 
 /* Exported interface to stringifying types, exprs and decls under TFF_*
@@ -2083,41 +2064,33 @@ dump_unary_op (const char *opstring, tree t, int flags)
 const char *
 type_as_string (tree typ, int flags)
 {
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   dump_type (typ, flags);
-
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 const char *
 expr_as_string (tree decl, int flags)
 {
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   dump_expr (decl, flags);
-
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 const char *
 decl_as_string (tree decl, int flags)
 {
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   dump_decl (decl, flags);
-
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 const char *
 context_as_string (tree context, int flags)
 {
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   dump_scope (context, flags);
-
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 /* Generate the three forms of printable names for cxx_printable_name.  */
@@ -2128,12 +2101,11 @@ lang_decl_name (tree decl, int v)
   if (v >= 2)
     return decl_as_string (decl, TFF_DECL_SPECIFIERS);
 
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   if (v == 1 && DECL_CLASS_SCOPE_P (decl))
     {
       dump_type (CP_DECL_CONTEXT (decl), TFF_PLAIN_IDENTIFIER);
-      print_scope_operator (scratch_buffer);
+      pp_colon_colon (cxx_pp);
     }
 
   if (TREE_CODE (decl) == FUNCTION_DECL)
@@ -2141,7 +2113,7 @@ lang_decl_name (tree decl, int v)
   else
     dump_decl (DECL_NAME (decl), TFF_PLAIN_IDENTIFIER);
 
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 static location_t
@@ -2175,21 +2147,17 @@ decl_to_string (tree decl, int verbose)
     flags |= TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE;
   flags |= TFF_TEMPLATE_HEADER;
 
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   dump_decl (decl, flags);
-
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 static const char *
 expr_to_string (tree decl)
 {
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   dump_expr (decl, 0);
-
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 static const char *
@@ -2200,11 +2168,9 @@ fndecl_to_string (tree fndecl, int verbose)
   flags = TFF_EXCEPTION_SPECIFICATION | TFF_DECL_SPECIFIERS;
   if (verbose)
     flags |= TFF_FUNCTION_DEFAULT_ARGUMENTS;
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   dump_decl (fndecl, flags);
-
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 
@@ -2239,48 +2205,38 @@ language_to_string (enum languages c)
 static const char *
 parm_to_string (int p)
 {
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   if (p < 0)
-    output_add_string (scratch_buffer, "'this'");
+    pp_string (cxx_pp, "'this'");
   else
-    output_decimal (scratch_buffer, p + 1);
-
-  return output_finalize_message (scratch_buffer);
+    pp_decimal_int (cxx_pp, p + 1);
+  return pp_formatted_text (cxx_pp);
 }
 
 static const char *
 op_to_string (enum tree_code p)
 {
-  tree id;
-
-  id = operator_name_info[(int) p].identifier;
+  tree id = operator_name_info[(int) p].identifier;
   return id ? IDENTIFIER_POINTER (id) : "<unknown>";
 }
 
 static const char *
 type_to_string (tree typ, int verbose)
 {
-  int flags;
-
-  flags = 0;
+  int flags = 0;
   if (verbose)
     flags |= TFF_CLASS_KEY_OR_ENUM;
   flags |= TFF_TEMPLATE_HEADER;
 
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   dump_type (typ, flags);
-
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 static const char *
 assop_to_string (enum tree_code p)
 {
-  tree id;
-
-  id = assignment_operator_name_info[(int) p].identifier;
+  tree id = assignment_operator_name_info[(int) p].identifier;
   return id ? IDENTIFIER_POINTER (id) : "{unknown}";
 }
 
@@ -2297,27 +2253,25 @@ args_to_string (tree p, int verbose)
   if (TYPE_P (TREE_VALUE (p)))
     return type_as_string (p, flags);
 
-  reinit_global_formatting_buffer ();
+  pp_clear_output_area (cxx_pp);
   for (; p; p = TREE_CHAIN (p))
     {
       if (TREE_VALUE (p) == null_node)
-       print_identifier (scratch_buffer, "NULL");
+       pp_identifier (cxx_pp, "NULL");
       else
        dump_type (error_type (TREE_VALUE (p)), flags);
       if (TREE_CHAIN (p))
-       separate_with_comma (scratch_buffer);
+       pp_separate_with_comma (cxx_pp);
     }
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 static const char *
 cv_to_string (tree p, int v)
 {
-  reinit_global_formatting_buffer ();
-
+  pp_clear_output_area (cxx_pp);
   dump_qualifiers (p, v ? before : none);
-
-  return output_finalize_message (scratch_buffer);
+  return pp_formatted_text (cxx_pp);
 }
 
 /* Langhook for print_error_function.  */
@@ -2325,7 +2279,7 @@ void
 cxx_print_error_function (diagnostic_context *context, const char *file)
 {
   lhd_print_error_function (context, file);
-  output_set_prefix (&context->buffer, file);
+  pp_set_prefix (context->printer, file);
   maybe_print_instantiation_context (context);
 }
 
@@ -2336,14 +2290,14 @@ cp_diagnostic_starter (diagnostic_context *context,
   diagnostic_report_current_module (context);
   cp_print_error_function (context, diagnostic);
   maybe_print_instantiation_context (context);
-  output_set_prefix (&context->buffer, diagnostic_build_prefix (diagnostic));
+  pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
 }
 
 static void
 cp_diagnostic_finalizer (diagnostic_context *context,
                          diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
 {
-  output_destroy_prefix (&context->buffer);
+  pp_destroy_prefix (context->printer);
 }
 
 /* Print current function onto BUFFER, in the process of reporting
@@ -2354,24 +2308,24 @@ cp_print_error_function (diagnostic_context *context,
 {
   if (diagnostic_last_function_changed (context))
     {
-      const char *old_prefix = output_prefix (&context->buffer);
+      const char *old_prefix = context->printer->prefix;
       char *new_prefix = diagnostic->location.file
         ? file_name_as_prefix (diagnostic->location.file)
         : NULL;
 
-      output_set_prefix (&context->buffer, new_prefix);
+      pp_set_prefix (context->printer, new_prefix);
 
       if (current_function_decl == NULL)
-        output_add_string (&context->buffer, "At global scope:");
+        pp_string (context->printer, "At global scope:");
       else
-        output_printf (&context->buffer, "In %s `%s':",
-                       function_category (current_function_decl),
-                       cxx_printable_name (current_function_decl, 2));
-      output_add_newline (&context->buffer);
+        pp_printf (context->printer, "In %s `%s':",
+                   function_category (current_function_decl),
+                   cxx_printable_name (current_function_decl, 2));
+      pp_newline (context->printer);
 
       diagnostic_set_last_function (context);
-      output_destroy_prefix (&context->buffer);
-      context->buffer.state.prefix = old_prefix;
+      pp_destroy_prefix (context->printer);
+      context->printer->prefix = old_prefix;
     }
 }
 
@@ -2417,10 +2371,10 @@ print_instantiation_full_context (diagnostic_context *context)
          if (current_function_decl == TINST_DECL (p))
            /* Avoid redundancy with the the "In function" line.  */;
          else
-           output_verbatim (&context->buffer,
-                             "%s: In instantiation of `%s':\n", location.file,
-                             decl_as_string (TINST_DECL (p),
-                                             TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
+           pp_verbatim (context->printer,
+                         "%s: In instantiation of `%s':\n", location.file,
+                         decl_as_string (TINST_DECL (p),
+                                         TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
 
          location.line = TINST_LINE (p);
          location.file = TINST_FILE (p);
@@ -2438,16 +2392,15 @@ print_instantiation_partial_context (diagnostic_context *context,
 {
   for (; t; t = TREE_CHAIN (t))
     {
-      output_verbatim
-        (&context->buffer, "%s:%d:   instantiated from `%s'\n",
-        loc.file, loc.line,
-         decl_as_string (TINST_DECL (t),
-                        TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
+      pp_verbatim (context->printer, "%s:%d:   instantiated from `%s'\n",
+                   loc.file, loc.line,
+                   decl_as_string (TINST_DECL (t),
+                                   TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
       loc.line = TINST_LINE (t);
       loc.file = TINST_FILE (t);
     }
-  output_verbatim (&context->buffer, "%s:%d:   instantiated from here\n",
-                  loc.file, loc.line);
+  pp_verbatim (context->printer, "%s:%d:   instantiated from here\n",
+               loc.file, loc.line);
 }
 
 /* Called from cp_thing to print the template context for an error.  */
@@ -2484,7 +2437,7 @@ print_instantiation_context (void)
    %T   type.
    %V   cv-qualifier.  */
 static bool
-cp_printer (output_buffer *buffer, text_info *text)
+cp_printer (pretty_printer *pp, text_info *text)
 {
   int verbose = 0;
   const char *result;
@@ -2519,7 +2472,7 @@ cp_printer (output_buffer *buffer, text_info *text)
       return false;
     }
 
-  output_add_string (buffer, result);
+  pp_string (pp, result);
   return true;
 #undef next_tree
 #undef next_tcode
@@ -2528,13 +2481,13 @@ cp_printer (output_buffer *buffer, text_info *text)
 }
 
 static void
-print_non_consecutive_character (output_buffer *buffer, int c)
+pp_non_consecutive_character (pretty_printer *pp, int c)
 {
-  const char *p = output_last_position (buffer);
+  const char *p = pp_last_position_in_text (pp);
 
   if (p != NULL && *p == c)
-    output_add_space (buffer);
-  output_add_character (buffer, c);
+    pp_space (pp);
+  pp_character (pp, c);
 }
 
 /* These are temporary wrapper functions which handle the historic
index cae8046..c226815 100644 (file)
@@ -39,56 +39,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "langhooks.h"
 #include "langhooks-def.h"
 
-#define output_text_length(BUFFER) (BUFFER)->line_length
-#define is_starting_newline(BUFFER) (output_text_length (BUFFER) == 0)
-#define line_wrap_cutoff(BUFFER) (BUFFER)->state.maximum_length
-#define prefix_was_emitted_for(BUFFER) (BUFFER)->state.emitted_prefix_p
-
-/* Format an integer given by va_arg (ARG, type-specifier T) where
-   type-specifier is a precision modifier as indicated by PREC.  F is
-   a string used to construct the appropriate format-specifier.  */
-#define output_integer_with_precision(BUFFER, ARG, PREC, T, F)  \
-  do                                                            \
-    switch (PREC)                                               \
-      {                                                         \
-      case 0:                                                   \
-        output_formatted_scalar                                 \
-          (BUFFER, "%" F, va_arg (ARG, T));                     \
-        break;                                                  \
-                                                                \
-      case 1:                                                   \
-        output_formatted_scalar                                 \
-          (BUFFER, "%l" F, va_arg (ARG, long T));               \
-        break;                                                  \
-                                                                \
-      case 2:                                                   \
-        output_formatted_scalar                                 \
-          (BUFFER, "%ll" F, va_arg (ARG, long long T));         \
-        break;                                                  \
-                                                                \
-      default:                                                  \
-        break;                                                  \
-      }                                                         \
-  while (0)
-
 
 /* Prototypes.  */
-static void output_flush (output_buffer *);
-static void output_do_verbatim (output_buffer *, text_info *);
-static void output_buffer_to_stream (output_buffer *);
-static void output_format (output_buffer *, text_info *);
-static void output_indent (output_buffer *);
-
-static char *build_message_string (const char *, ...)
-     ATTRIBUTE_PRINTF_1;
-static void format_with_decl (output_buffer *, text_info *, tree);
-static void diagnostic_for_decl (diagnostic_context *, diagnostic_info *,
-                                tree);
-static void set_real_maximum_length (output_buffer *);
-static void output_append_r (output_buffer *, const char *, int);
-static void wrap_text (output_buffer *, const char *, const char *);
-static void maybe_wrap_text (output_buffer *, const char *, const char *);
-static void output_clear_data (output_buffer *);
+static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
 
 static void default_diagnostic_starter (diagnostic_context *,
                                        diagnostic_info *);
@@ -116,482 +69,6 @@ with preprocessed source if appropriate.\n\
 See %s for instructions.\n"
 
 \f
-/* Subroutine of output_set_maximum_length.  Set up BUFFER's
-   internal maximum characters per line.  */
-static void
-set_real_maximum_length (output_buffer *buffer)
-{
-  /* If we're told not to wrap lines then do the obvious thing.  In case
-   we'll emit prefix only once per diagnostic message, it is appropriate
-  not to increase unnecessarily the line-length cut-off.  */
-  if (!output_is_line_wrapping (buffer)
-      || output_prefixing_rule (buffer) == DIAGNOSTICS_SHOW_PREFIX_ONCE
-      || output_prefixing_rule (buffer) == DIAGNOSTICS_SHOW_PREFIX_NEVER)
-    line_wrap_cutoff (buffer) = output_line_cutoff (buffer);
-  else
-    {
-      int prefix_length = buffer->state.prefix ?
-        strlen (buffer->state.prefix) : 0;
-      /* If the prefix is ridiculously too long, output at least
-         32 characters.  */
-      if (output_line_cutoff (buffer) - prefix_length < 32)
-       line_wrap_cutoff (buffer) = output_line_cutoff (buffer) + 32;
-      else
-       line_wrap_cutoff (buffer) = output_line_cutoff (buffer);
-    }
-}
-
-/* Sets the number of maximum characters per line BUFFER can output
-   in line-wrapping mode.  A LENGTH value 0 suppresses line-wrapping.  */
-void
-output_set_maximum_length (output_buffer *buffer, int length)
-{
-  output_line_cutoff (buffer) = length;
-  set_real_maximum_length (buffer);
-}
-
-/* Sets BUFFER's PREFIX.  */
-void
-output_set_prefix (output_buffer *buffer, const char *prefix)
-{
-  buffer->state.prefix = prefix;
-  set_real_maximum_length (buffer);
-  prefix_was_emitted_for (buffer) = false;
-  output_indentation (buffer) = 0;
-}
-
-/*  Return a pointer to the last character emitted in the output
-    BUFFER area.  A NULL pointer means no character available.  */
-const char *
-output_last_position (const output_buffer *buffer)
-{
-  const char *p = NULL;
-
-  if (obstack_base (&buffer->obstack) != obstack_next_free (&buffer->obstack))
-    p = ((const char *) obstack_next_free (&buffer->obstack)) - 1;
-  return p;
-}
-
-/* Free BUFFER's prefix, a previously malloc'd string.  */
-void
-output_destroy_prefix (output_buffer *buffer)
-{
-  if (buffer->state.prefix != NULL)
-    {
-      free ((char *) buffer->state.prefix);
-      buffer->state.prefix = NULL;
-    }
-}
-
-/* Zero out any text output so far in BUFFER.  */
-void
-output_clear_message_text (output_buffer *buffer)
-{
-  obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
-  output_text_length (buffer) = 0;
-}
-
-/* Zero out any formatting data used so far by BUFFER.  */
-static void
-output_clear_data (output_buffer *buffer)
-{
-  prefix_was_emitted_for (buffer) = false;
-  output_indentation (buffer) = 0;
-}
-
-/* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
-   characters per line.  */
-void
-init_output_buffer (output_buffer *buffer, const char *prefix,
-                   int maximum_length)
-{
-  memset (buffer, 0, sizeof (output_buffer));
-  obstack_init (&buffer->obstack);
-  output_buffer_attached_stream (buffer) = stderr;
-  output_line_cutoff (buffer) = maximum_length;
-  output_prefixing_rule (buffer) = diagnostic_prefixing_rule (global_dc);
-  output_set_prefix (buffer, prefix);
-  output_text_length (buffer) = 0;
-  output_clear_data (buffer);
-}
-
-/* Reinitialize BUFFER.  */
-void
-output_clear (output_buffer *buffer)
-{
-  output_clear_message_text (buffer);
-  output_clear_data (buffer);
-}
-
-/* Finishes constructing a NULL-terminated character string representing
-   the BUFFERed message.  */
-const char *
-output_finalize_message (output_buffer *buffer)
-{
-  obstack_1grow (&buffer->obstack, '\0');
-  return output_message_text (buffer);
-}
-
-/* Return the amount of characters BUFFER can accept to
-   make a full line.  */
-int
-output_space_left (const output_buffer *buffer)
-{
-  return line_wrap_cutoff (buffer) - output_text_length (buffer);
-}
-
-/* Write out BUFFER's prefix.  */
-void
-output_emit_prefix (output_buffer *buffer)
-{
-  if (buffer->state.prefix != NULL)
-    {
-      switch (output_prefixing_rule (buffer))
-       {
-       default:
-       case DIAGNOSTICS_SHOW_PREFIX_NEVER:
-         break;
-
-       case DIAGNOSTICS_SHOW_PREFIX_ONCE:
-         if (prefix_was_emitted_for (buffer))
-           {
-             output_indent (buffer);
-             break;
-           }
-         output_indentation (buffer) += 3;
-         /* Fall through.  */
-
-       case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
-         {
-           int prefix_length = strlen (buffer->state.prefix);
-           output_append_r (buffer, buffer->state.prefix, prefix_length);
-           prefix_was_emitted_for (buffer) = true;
-         }
-         break;
-       }
-    }
-}
-
-/* Have BUFFER start a new line.  */
-void
-output_add_newline (output_buffer *buffer)
-{
-  obstack_1grow (&buffer->obstack, '\n');
-  output_text_length (buffer) = 0;
-}
-
-/* Appends a character to BUFFER.  */
-void
-output_add_character (output_buffer *buffer, int c)
-{
-  if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
-    output_add_newline (buffer);
-  obstack_1grow (&buffer->obstack, c);
-  ++output_text_length (buffer);
-}
-
-/* Adds a space to BUFFER.  */
-void
-output_add_space (output_buffer *buffer)
-{
-  if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
-    {
-      output_add_newline (buffer);
-      return;
-    }
-  obstack_1grow (&buffer->obstack, ' ');
-  ++output_text_length (buffer);
-}
-
-/* These functions format an INTEGER into BUFFER as suggested by their
-   names.  */
-void
-output_decimal (output_buffer *buffer, int i)
-{
-  output_formatted_scalar (buffer, "%d", i);
-}
-
-void
-output_host_wide_integer (output_buffer *buffer, HOST_WIDE_INT i)
-{
-  output_formatted_scalar (buffer, HOST_WIDE_INT_PRINT_DEC, i);
-}
-
-static inline void
-output_pointer (output_buffer *buffer, void *p)
-{
-  output_formatted_scalar (buffer, HOST_PTR_PRINTF, p);
-}
-
-/* Append to BUFFER a string specified by its STARTING character
-   and LENGTH.  */
-static void
-output_append_r (output_buffer *buffer, const char *start, int length)
-{
-  obstack_grow (&buffer->obstack, start, length);
-  output_text_length (buffer) += length;
-}
-
-/* Append a string delimited by START and END to BUFFER.  No wrapping is
-   done.  However, if beginning a new line then emit BUFFER->state.prefix
-   and skip any leading whitespace if appropriate.  The caller must ensure
-   that it is safe to do so.  */
-void
-output_append (output_buffer *buffer, const char *start, const char *end)
-{
-  /* Emit prefix and skip whitespace if we're starting a new line.  */
-  if (is_starting_newline (buffer))
-    {
-      output_emit_prefix (buffer);
-      if (output_is_line_wrapping (buffer))
-       while (start != end && *start == ' ')
-         ++start;
-    }
-  output_append_r (buffer, start, end - start);
-}
-
-/* Insert enough spaces into BUFFER to bring the column position to
-   the current indentation level, assuming that a newline has just
-   been written to the buffer.  */
-static void
-output_indent (output_buffer *buffer)
-{
-  int n = output_indentation (buffer);
-  int i;
-
-  for (i = 0; i < n; ++i)
-    output_add_character (buffer, ' ');
-}
-
-/* Wrap a text delimited by START and END into BUFFER.  */
-static void
-wrap_text (output_buffer *buffer, const char *start, const char *end)
-{
-  bool is_wrapping = output_is_line_wrapping (buffer);
-
-  while (start != end)
-    {
-      /* Dump anything bordered by whitespaces.  */
-      {
-       const char *p = start;
-       while (p != end && *p != ' ' && *p != '\n')
-         ++p;
-       if (is_wrapping && p - start >= output_space_left (buffer))
-         output_add_newline (buffer);
-       output_append (buffer, start, p);
-       start = p;
-      }
-
-      if (start != end && *start == ' ')
-       {
-         output_add_space (buffer);
-         ++start;
-       }
-      if (start != end && *start == '\n')
-       {
-         output_add_newline (buffer);
-         ++start;
-       }
-    }
-}
-
-/* Same as wrap_text but wrap text only when in line-wrapping mode.  */
-static void
-maybe_wrap_text (output_buffer *buffer, const char *start, const char *end)
-{
-  if (output_is_line_wrapping (buffer))
-    wrap_text (buffer, start, end);
-  else
-    output_append (buffer, start, end);
-}
-
-
-/* Append a STRING to BUFFER; the STRING might be line-wrapped if in
-   appropriate mode.  */
-void
-output_add_string (output_buffer *buffer, const char *str)
-{
-  maybe_wrap_text (buffer, str, str + (str ? strlen (str) : 0));
-}
-
-/* Append an identifier ID to BUFFER.  */
-void
-output_add_identifier (output_buffer *buffer, tree id)
-{
-  output_append (buffer, IDENTIFIER_POINTER (id),
-                IDENTIFIER_POINTER (id) + IDENTIFIER_LENGTH (id));
-}
-
-/* Flush the content of BUFFER onto the attached stream,
-   and reinitialize.  */
-
-static void
-output_buffer_to_stream (output_buffer *buffer)
-{
-  const char *text = output_finalize_message (buffer);
-  fputs (text, output_buffer_attached_stream (buffer));
-  output_clear_message_text (buffer);
-}
-
-/* Format a message pointed to by TEXT.  The following format specifiers are
-   recognized as being language independent:
-   %d, %i: (signed) integer in base ten.
-   %u: unsigned integer in base ten.
-   %o: unsigned integer in base eight.
-   %x: unsigned integer in base sixteen.
-   %ld, %li, %lo, %lu, %lx: long versions of the above.
-   %lld, %lli, %llo, %llu, %llx: long long versions.
-   %wd, %wi, %wo, %wu, %wx: HOST_WIDE_INT versions.
-   %c: character.
-   %s: string.
-   %p: pointer.
-   %m: strerror(text->err_no) - does not consume a value from args_ptr.
-   %%: `%'.
-   %*.s: a substring the length of which is specified by an integer.
-   %H: location_t.  */
-static void
-output_format (output_buffer *buffer, text_info *text)
-{
-  for (; *text->format_spec; ++text->format_spec)
-    {
-      int precision = 0;
-      bool wide = false;
-
-      /* Ignore text.  */
-      {
-       const char *p = text->format_spec;
-       while (*p && *p != '%')
-         ++p;
-       wrap_text (buffer, text->format_spec, p);
-        text->format_spec = p;
-      }
-
-      if (*text->format_spec == '\0')
-       break;
-
-      /* We got a '%'.  Parse precision modifiers, if any.  */
-      switch (*++text->format_spec)
-        {
-        case 'w':
-          wide = true;
-          ++text->format_spec;
-          break;
-
-        case 'l':
-          do
-            ++precision;
-          while (*++text->format_spec == 'l');
-          break;
-
-        default:
-          break;
-        }
-      /* We don't support precision behond that of "long long".  */
-      if (precision > 2)
-        abort();
-
-      switch (*text->format_spec)
-       {
-       case 'c':
-         output_add_character (buffer, va_arg (*text->args_ptr, int));
-         break;
-
-       case 'd':
-       case 'i':
-          if (wide)
-            output_formatted_scalar
-              (buffer, HOST_WIDE_INT_PRINT_DEC,
-               va_arg (*text->args_ptr, HOST_WIDE_INT));
-          else
-            output_integer_with_precision
-              (buffer, *text->args_ptr, precision, int, "d");
-         break;
-
-       case 'o':
-          if (wide)
-            output_formatted_scalar
-              (buffer, "%" HOST_WIDE_INT_PRINT "o",
-               va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
-          else
-            output_integer_with_precision
-              (buffer, *text->args_ptr, precision, unsigned, "u");
-         break;
-
-       case 's':
-         output_add_string (buffer, va_arg (*text->args_ptr, const char *));
-         break;
-
-        case 'p':
-          output_pointer (buffer, va_arg (*text->args_ptr, void *));
-          break;
-
-       case 'u':
-          if (wide)
-            output_formatted_scalar
-              (buffer, HOST_WIDE_INT_PRINT_UNSIGNED,
-               va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
-          else
-            output_integer_with_precision
-              (buffer, *text->args_ptr, precision, unsigned, "u");
-         break;
-
-       case 'x':
-          if (wide)
-            output_formatted_scalar
-              (buffer, HOST_WIDE_INT_PRINT_HEX,
-               va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
-          else
-            output_integer_with_precision
-              (buffer, *text->args_ptr, precision, unsigned, "x");
-         break;
-
-       case 'm':
-         output_add_string (buffer, xstrerror (text->err_no));
-         break;
-
-       case '%':
-         output_add_character (buffer, '%');
-         break;
-
-        case 'H':
-          {
-            const location_t *locus = va_arg (*text->args_ptr, location_t *);
-            output_add_string (buffer, "file '");
-            output_add_string (buffer, locus->file);
-            output_add_string (buffer, "', line ");
-            output_decimal (buffer, locus->line);
-          }
-          break;
-
-       case '.':
-         {
-           int n;
-           const char *s;
-           /* We handle no precision specifier but `%.*s'.  */
-           if (*++text->format_spec != '*')
-             abort ();
-           else if (*++text->format_spec != 's')
-             abort ();
-           n = va_arg (*text->args_ptr, int);
-           s = va_arg (*text->args_ptr, const char *);
-           output_append (buffer, s, s + n);
-         }
-         break;
-
-       default:
-         if (!buffer->format_decoder
-              || !(*buffer->format_decoder) (buffer, text))
-           {
-             /* Hmmm.  The front-end failed to install a format translator
-                 but called us with an unrecognized format.  Or, maybe, the
-                 translated string just contains an invalid format, or
-                 has formats in the wrong order.  Sorry.  */
-             abort ();
-           }
-       }
-    }
-}
-
 /* Return a malloc'd string containing MSG formatted a la printf.  The
    caller is responsible for freeing the memory.  */
 static char *
@@ -614,127 +91,31 @@ file_name_as_prefix (const char *f)
   return build_message_string ("%s: ", f);
 }
 
-/* Format a message into BUFFER a la printf.  */
-void
-output_printf (struct output_buffer *buffer, const char *msgid, ...)
-{
-  text_info text;
-  va_list ap;
-
-  va_start (ap, msgid);
-  text.err_no = errno;
-  text.args_ptr = &ap;
-  text.format_spec = _(msgid);
-  output_format (buffer, &text);
-  va_end (ap);
-}
-
-/* Print a message relevant to the given DECL.  */
-static void
-format_with_decl (output_buffer *buffer, text_info *text, tree decl)
-{
-  const char *p;
-
-  /* Do magic to get around lack of varargs support for insertion
-     of arguments into existing list.  We know that the decl is first;
-     we ass_u_me that it will be printed with "%s".  */
-  for (p = text->format_spec; *p; ++p)
-    {
-      if (*p == '%')
-       {
-         if (*(p + 1) == '%')
-           ++p;
-         else if (*(p + 1) != 's')
-           abort ();
-         else
-           break;
-       }
-    }
-
-  /* Print the left-hand substring.  */
-  maybe_wrap_text (buffer, text->format_spec, p);
-
-  if (*p == '%')               /* Print the name.  */
-    {
-      const char *const n = (DECL_NAME (decl)
-                            ? (*lang_hooks.decl_printable_name) (decl, 2)
-                            : _("((anonymous))"));
-      output_add_string (buffer, n);
-      while (*p)
-       {
-         ++p;
-         if (ISALPHA (*(p - 1) & 0xFF))
-           break;
-       }
-    }
-
-  if (*p)                      /* Print the rest of the message.  */
-    {
-      text->format_spec = p;
-      output_format (buffer, text);
-    }
-}
-
-/* Flush the content of BUFFER onto the attached stream.  */
-static void
-output_flush (output_buffer *buffer)
-{
-  output_buffer_to_stream (buffer);
-  output_clear_data (buffer);
-  fputc ('\n', output_buffer_attached_stream (buffer));
-  fflush (output_buffer_attached_stream (buffer));
-}
-
-/* Helper subroutine of output_verbatim and verbatim. Do the appropriate
-   settings needed by BUFFER for a verbatim formatting.  */
-static void
-output_do_verbatim (output_buffer *buffer, text_info *text)
-{
-  diagnostic_prefixing_rule_t rule = output_prefixing_rule (buffer);
-  int line_cutoff = output_line_cutoff (buffer);
-
-  /* Set verbatim mode.  */
-  output_prefixing_rule (buffer) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
-  output_line_cutoff (buffer) = 0;
-  /* Do the actual formatting.  */
-  output_format (buffer, text);
-  /* Restore previous settings.  */
-  output_prefixing_rule (buffer) = rule;
-  output_line_cutoff (buffer) = line_cutoff;
-}
-
-/* Output MESSAGE verbatim into BUFFER.  */
-void
-output_verbatim (output_buffer *buffer, const char *msgid, ...)
-{
-  text_info text;
-  va_list ap;
-
-  va_start (ap, msgid);
-  text.err_no = errno;
-  text.args_ptr = &ap;
-  text.format_spec = _(msgid);
-  output_do_verbatim (buffer, &text);
-  va_end (ap);
-}
 
 \f
 /* Initialize the diagnostic message outputting machinery.  */
 void
 diagnostic_initialize (diagnostic_context *context)
 {
-  memset (context, 0, sizeof *context);
-  obstack_init (&context->buffer.obstack);
-
+  /* Allocate a basic pretty-printer.  Clients will replace this a
+     much more elaborated pretty-printer if they wish.  */
+  context->printer = xmalloc (sizeof (pretty_printer));
+  pp_construct (context->printer, NULL, 0);
   /* By default, diagnostics are sent to stderr.  */
-  output_buffer_attached_stream (&context->buffer) = stderr;
-
+  context->printer->buffer->stream = stderr;
   /* By default, we emit prefixes once per message.  */
-  diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
+  context->printer->prefixing_rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
 
+  memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
+  context->warnings_are_errors_message = warnings_are_errors;
+  context->abort_on_error = false;
+  context->internal_error = NULL;
   diagnostic_starter (context) = default_diagnostic_starter;
   diagnostic_finalizer (context) = default_diagnostic_finalizer;
-  context->warnings_are_errors_message = warnings_are_errors;
+  context->last_module = 0;
+  context->last_function = NULL;
+  context->lock = 0;
+  context->x_data = NULL;
 }
 
 /* Returns true if the next format specifier in TEXT is a format specifier
@@ -797,13 +178,6 @@ diagnostic_build_prefix (diagnostic_info *diagnostic)
                             _(diagnostic_kind_text[diagnostic->kind]));
 }
 
-void
-diagnostic_flush_buffer (diagnostic_context *context)
-{
-  output_buffer_to_stream (&context->buffer);
-  fflush (output_buffer_attached_stream (&context->buffer));
-}
-
 /* Count a diagnostic.  Return true if the message should be printed.  */
 static bool
 diagnostic_count_diagnostic (diagnostic_context *context,
@@ -852,8 +226,8 @@ diagnostic_count_diagnostic (diagnostic_context *context,
 
       if (context->warnings_are_errors_message)
         {
-         output_verbatim (&context->buffer,
-                           "%s: warnings being treated as errors\n", progname);
+         pp_verbatim (context->printer,
+                       "%s: warnings being treated as errors\n", progname);
           context->warnings_are_errors_message = false;
         }
 
@@ -917,7 +291,7 @@ announce_function (tree decl)
       else
        verbatim (" %s", (*lang_hooks.decl_printable_name) (decl, 2));
       fflush (stderr);
-      output_needs_newline (&global_dc->buffer) = true;
+      global_dc->printer->need_newline = true;
       diagnostic_set_last_function (global_dc);
     }
 }
@@ -929,29 +303,29 @@ lhd_print_error_function (diagnostic_context *context, const char *file)
 {
   if (diagnostic_last_function_changed (context))
     {
-      const char *old_prefix = output_prefix (&context->buffer);
+      const char *old_prefix = context->printer->prefix;
       char *new_prefix = file ? build_message_string ("%s: ", file) : NULL;
 
-      output_set_prefix (&context->buffer, new_prefix);
+      pp_set_prefix (context->printer, new_prefix);
 
       if (current_function_decl == NULL)
-       output_add_string (&context->buffer, _("At top level:"));
+       pp_string (context->printer, _("At top level:"));
       else
        {
          if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
-           output_printf
-             (&context->buffer, "In member function `%s':",
+           pp_printf
+             (context->printer, "In member function `%s':",
               (*lang_hooks.decl_printable_name) (current_function_decl, 2));
          else
-           output_printf
-             (&context->buffer, "In function `%s':",
+           pp_printf
+             (context->printer, "In function `%s':",
               (*lang_hooks.decl_printable_name) (current_function_decl, 2));
        }
-      output_add_newline (&context->buffer);
+      pp_newline (context->printer);
 
       diagnostic_set_last_function (context);
-      output_buffer_to_stream (&context->buffer);
-      context->buffer.state.prefix = old_prefix;
+      pp_flush (context->printer);
+      context->printer->prefix = old_prefix;
       free ((char*) new_prefix);
     }
 }
@@ -972,23 +346,23 @@ diagnostic_report_current_module (diagnostic_context *context)
 {
   struct file_stack *p;
 
-  if (output_needs_newline (&context->buffer))
+  if (pp_needs_newline (context->printer))
     {
-      output_add_newline (&context->buffer);
-      output_needs_newline (&context->buffer) = false;
+      pp_newline (context->printer);
+      pp_needs_newline (context->printer) = false;
     }
 
   if (input_file_stack && diagnostic_last_module_changed (context))
     {
       p = input_file_stack;
-      output_verbatim (&context->buffer,
-                      "In file included from %s:%d",
-                      p->location.file, p->location.line);
+      pp_verbatim (context->printer,
+                   "In file included from %s:%d",
+                   p->location.file, p->location.line);
       while ((p = p->next) != NULL)
-       output_verbatim (&context->buffer,
-                        ",\n                 from %s:%d",
-                        p->location.file, p->location.line);
-      output_verbatim (&context->buffer, ":\n");
+       pp_verbatim (context->printer,
+                     ",\n                 from %s:%d",
+                     p->location.file, p->location.line);
+      pp_verbatim (context->printer, ":\n");
       diagnostic_set_last_module (context);
     }
 }
@@ -998,14 +372,14 @@ default_diagnostic_starter (diagnostic_context *context,
                            diagnostic_info *diagnostic)
 {
   diagnostic_report_current_function (context);
-  output_set_prefix (&context->buffer, diagnostic_build_prefix (diagnostic));
+  pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
 }
 
 static void
 default_diagnostic_finalizer (diagnostic_context *context,
                              diagnostic_info *diagnostic __attribute__((unused)))
 {
-  output_destroy_prefix (&context->buffer);
+  pp_destroy_prefix (context->printer);
 }
 
 /* Report a diagnostic message (an error or a warning) as specified by
@@ -1024,31 +398,9 @@ diagnostic_report_diagnostic (diagnostic_context *context,
   if (diagnostic_count_diagnostic (context, diagnostic))
     {
       (*diagnostic_starter (context)) (context, diagnostic);
-      output_format (&context->buffer, &diagnostic->message);
-      (*diagnostic_finalizer (context)) (context, diagnostic);
-      output_flush (&context->buffer);
-      diagnostic_action_after_output (context, diagnostic);
-    }
-
-  context->lock--;
-}
-
-/* Report a diagnostic MESSAGE at the declaration DECL.
-   MSG is a format string which uses %s to substitute the declaration
-   name; subsequent substitutions are a la output_format.  */
-static void
-diagnostic_for_decl (diagnostic_context *context,
-                    diagnostic_info *diagnostic, tree decl)
-{
-  if (context->lock++ && diagnostic->kind < DK_SORRY)
-    error_recursion (context);
-
-  if (diagnostic_count_diagnostic (context, diagnostic))
-    {
-      (*diagnostic_starter (context)) (context, diagnostic);
-      format_with_decl (&context->buffer, &diagnostic->message, decl);
+      pp_format_text (context->printer, &diagnostic->message);
       (*diagnostic_finalizer (context)) (context, diagnostic);
-      output_flush (&context->buffer);
+      pp_flush (context->printer);
       diagnostic_action_after_output (context, diagnostic);
     }
 
@@ -1114,8 +466,8 @@ verbatim (const char *msgid, ...)
   text.err_no = errno;
   text.args_ptr = &ap;
   text.format_spec = _(msgid);
-  output_do_verbatim (&global_dc->buffer, &text);
-  output_buffer_to_stream (&global_dc->buffer);
+  pp_format_verbatim (global_dc->printer, &text);
+  pp_flush (global_dc->printer);
   va_end (ap);
 }
 
@@ -1234,61 +586,6 @@ internal_error (const char *msgid, ...)
   real_abort ();
 }
 \f
-/* Variants of some of the above, which make reference to a particular
-   DECL node.  These are deprecated.  */
-
-void
-warning_with_decl (tree decl, const char *msgid, ...)
-{
-  diagnostic_info diagnostic;
-  va_list ap;
-
-  va_start (ap, msgid);
-
-  /* Do not issue a warning about a decl which came from a system header,
-     unless -Wsystem-headers.  */
-  if (DECL_IN_SYSTEM_HEADER (decl) && !warn_system_headers)
-    return;
-
-  diagnostic_set_info (&diagnostic, msgid, &ap,
-                       DECL_SOURCE_LOCATION (decl), DK_WARNING);
-  diagnostic_for_decl (global_dc, &diagnostic, decl);
-  va_end (ap);
-}
-
-void
-pedwarn_with_decl (tree decl, const char *msgid, ...)
-{
-  diagnostic_info diagnostic;
-  va_list ap;
-
-  va_start (ap, msgid);
-
-  /* Do not issue a warning about a decl which came from a system header,
-     unless -Wsystem-headers.  */
-  if (DECL_IN_SYSTEM_HEADER (decl) && !warn_system_headers)
-    return;
-
-  diagnostic_set_info (&diagnostic, msgid, &ap,
-                       DECL_SOURCE_LOCATION (decl), pedantic_error_kind ());
-  diagnostic_for_decl (global_dc, &diagnostic, decl);
-
-  va_end (ap);
-}
-
-void
-error_with_decl (tree decl, const char *msgid, ...)
-{
-  diagnostic_info diagnostic;
-  va_list ap;
-
-  va_start (ap, msgid);
-  diagnostic_set_info (&diagnostic, msgid, &ap,
-                       DECL_SOURCE_LOCATION (decl), DK_ERROR);
-  diagnostic_for_decl (global_dc, &diagnostic, decl);
-  va_end (ap);
-}
-\f
 /* Special case error functions.  Most are implemented in terms of the
    above, or should be.  */
 
@@ -1351,7 +648,7 @@ static void
 error_recursion (diagnostic_context *context)
 {
   if (context->lock < 3)
-    output_flush (&context->buffer);
+    pp_flush (context->printer);
 
   fnotice (stderr,
           "Internal compiler error: Error reporting routines re-entered.\n");
index cd0ceba..1a26553 100644 (file)
@@ -22,17 +22,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #ifndef GCC_DIAGNOSTIC_H
 #define GCC_DIAGNOSTIC_H
 
-#include "obstack.h"
-#include "input.h"
-
-/* The type of a text to be formatted according a format specification
-   along with a list of things.  */
-typedef struct
-{
-  const char *format_spec;
-  va_list *args_ptr;
-  int err_no;  /* for %m */
-} text_info;
+#include "pretty-print.h"
 
 /* Constants used to discriminate diagnostics.  */
 typedef enum
@@ -56,118 +46,6 @@ typedef struct
 
 #define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
 
-/* How often diagnostics are prefixed by their locations:
-   o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
-   o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once;
-   o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical
-   line is started.  */
-typedef enum
-{
-  DIAGNOSTICS_SHOW_PREFIX_ONCE       = 0x0,
-  DIAGNOSTICS_SHOW_PREFIX_NEVER      = 0x1,
-  DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2
-} diagnostic_prefixing_rule_t;
-
-/* This data structure encapsulates an output_buffer's state.  */
-typedef struct
-{
-  /* The prefix for each new line.  */
-  const char *prefix;
-
-  /* The real upper bound of number of characters per line, taking into
-     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;
-
-  /* Nonzero if current PREFIX was emitted at least once.  */
-  bool emitted_prefix_p;
-
-  /* Nonzero means one should emit a newline before outputting anything.  */
-  bool need_newline_p;
-
-  /* Current prefixing rule.  */
-  diagnostic_prefixing_rule_t prefixing_rule;
-} output_state;
-
-/* The type of a hook that formats client-specific data (trees mostly) into
-   an output_buffer.  A client-supplied formatter returns true if everything
-   goes well.  */
-typedef struct output_buffer output_buffer;
-typedef bool (*printer_fn) (output_buffer *, text_info *);
-
-/* The output buffer datatype.  This is best seen as an abstract datatype
-   whose fields should not be accessed directly by clients.  */
-struct output_buffer
-{
-  /* The current state of the buffer.  */
-  output_state state;
-
-  /* Where to output formatted text.  */
-  FILE* stream;
-
-  /* The obstack where the text is built up.  */  
-  struct obstack obstack;
-
-  /* The amount of characters output so far.  */  
-  int line_length;
-
-  /* This must be large enough to hold any printed integer or
-     floating-point value.  */
-  char digit_buffer[128];
-
-  /* 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
-     output_add_string (and related functions) to add data to the BUFFER.
-     FORMAT_DECODER can read arguments from *TEXT->args_pts using VA_ARG.
-     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.
-  */
-  printer_fn format_decoder;
-} ;
-
-#define output_prefix(BUFFER) (BUFFER)->state.prefix
-
-/* The stream attached to the output_buffer, where the formatted
-   diagnostics will ultimately go.  Works only on `output_buffer *'.  */
-#define output_buffer_attached_stream(BUFFER) (BUFFER)->stream
-
-/* In line-wrapping mode, whether we should start a new line.  */
-#define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
-
-/* The amount of whitespace to be emitted when starting a new line.  */
-#define output_indentation(BUFFER) (BUFFER)->state.indent_skip
-
-/* A pointer to the formatted diagnostic message.  */
-#define output_message_text(BUFFER) \
-   ((const char *) obstack_base (&(BUFFER)->obstack))
-
-/* Client supplied function used to decode formats.  */
-#define output_format_decoder(BUFFER)     (BUFFER)->format_decoder
-
-/* Prefixing rule used in formatting a diagnostic message.  */
-#define output_prefixing_rule(BUFFER)  (BUFFER)->state.prefixing_rule
-
-/* Maximum characters per line in automatic line wrapping mode.
-   Zero means don't wrap lines.  */
-#define output_line_cutoff(BUFFER)  (BUFFER)->state.ideal_maximum_length
-
-/* True if BUFFER is in line-wrapping mode.  */
-#define output_is_line_wrapping(BUFFER) (output_line_cutoff (BUFFER) > 0)
-
-#define output_formatted_scalar(BUFFER, FORMAT, SCALAR)        \
-  do                                                           \
-    {                                                          \
-      sprintf ((BUFFER)->digit_buffer, FORMAT, SCALAR);        \
-      output_add_string (BUFFER, (BUFFER)->digit_buffer);      \
-    }                                                          \
-  while (0)
 
 /*  Forward declarations.  */
 typedef struct diagnostic_context diagnostic_context;
@@ -179,10 +57,8 @@ typedef diagnostic_starter_fn diagnostic_finalizer_fn;
    the context of a diagnostic message.  */
 struct diagnostic_context
 {
-  /* Where most of the diagnostic formatting work is done.  In Object
-     Oriented terms, we'll say that diagnostic_context is a sub-class of
-     output_buffer.  */
-  output_buffer buffer;
+  /* Where most of the diagnostic formatting work is done.   */
+  pretty_printer *printer;
 
   /* The number of times we have issued diagnostics.  */
   int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
@@ -233,15 +109,17 @@ struct diagnostic_context
 /* Extension hook for client.  */
 #define diagnostic_auxiliary_data(DC) (DC)->x_data
 
-/* Same as output_format_decoder.  Works on 'diagnostic_context *'.  */
-#define diagnostic_format_decoder(DC) output_format_decoder (&(DC)->buffer)
+/* Same as pp_format_decoder.  Works on 'diagnostic_context *'.  */
+#define diagnostic_format_decoder(DC) pp_format_decoder ((DC)->printer)
 
 /* Same as output_prefixing_rule.  Works on 'diagnostic_context *'.  */
-#define diagnostic_prefixing_rule(DC) output_prefixing_rule (&(DC)->buffer)
+#define diagnostic_prefixing_rule(DC) ((DC)->printer->prefixing_rule)
 
 /* Maximum characters per line in automatic line wrapping mode.
    Zero means don't wrap lines.  */
-#define diagnostic_line_cutoff(DC) output_line_cutoff (&(DC)->buffer)
+#define diagnostic_line_cutoff(DC) ((DC)->printer->ideal_maximum_length)
+
+#define diagnostic_flush_buffer(DC) pp_flush ((DC)->printer)
 
 /* True if the last function in which a diagnostic was reported is
    different from the current one.  */
@@ -294,7 +172,6 @@ extern diagnostic_context *global_dc;
 extern void diagnostic_initialize (diagnostic_context *);
 extern void diagnostic_report_current_module (diagnostic_context *);
 extern void diagnostic_report_current_function (diagnostic_context *);
-extern void diagnostic_flush_buffer (diagnostic_context *);
 extern void diagnostic_report_diagnostic (diagnostic_context *,
                                          diagnostic_info *);
 extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
@@ -302,27 +179,6 @@ extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
 extern char *diagnostic_build_prefix (diagnostic_info *);
 
 /* Pure text formatting support functions.  */
-extern void init_output_buffer (output_buffer *, const char *, int);
-extern void output_clear (output_buffer *);
-extern const char *output_last_position (const output_buffer *);
-extern void output_set_prefix (output_buffer *, const char *);
-extern void output_destroy_prefix (output_buffer *);
-extern void output_set_maximum_length (output_buffer *, int);
-extern void output_emit_prefix (output_buffer *);
-extern void output_add_newline (output_buffer *);
-extern void output_add_space (output_buffer *);
-extern int output_space_left (const output_buffer *);
-extern void output_append (output_buffer *, const char *, const char *);
-extern void output_add_character (output_buffer *, int);
-extern void output_decimal (output_buffer *, int);
-extern void output_host_wide_integer (output_buffer *, HOST_WIDE_INT);
-extern void output_add_string (output_buffer *, const char *);
-extern void output_add_identifier (output_buffer *, tree);
-extern const char *output_finalize_message (output_buffer *);
-extern void output_clear_message_text (output_buffer *);
-extern void output_printf (output_buffer *, const char *, ...)
-     ATTRIBUTE_PRINTF_2;
-extern void output_verbatim (output_buffer *, const char *, ...);
 extern void verbatim (const char *, ...);
 extern char *file_name_as_prefix (const char *);
 
index ab80df1..769c0ea 100644 (file)
@@ -2036,9 +2036,9 @@ output_reg_number (rtx rtl)
 
   if (regno >= DWARF_FRAME_REGISTERS)
     {
-      warning_with_decl (dwarf_last_decl,
-                        "internal regno botch: `%s' has regno = %d\n",
-                        regno);
+      warning ("%Hinternal regno botch: '%D' has regno = %d\n",
+               &DECL_SOURCE_LOCATION (dwarf_last_decl), dwarf_last_decl,
+               regno);
       regno = 0;
     }
   dw2_assemble_integer (4, GEN_INT (DBX_REGISTER_NUMBER (regno)));
index e76e364..f95678f 100644 (file)
@@ -6734,7 +6734,8 @@ expand_expr (tree exp, rtx target, enum machine_mode tmode, enum expand_modifier
     case PARM_DECL:
       if (!DECL_RTL_SET_P (exp))
        {
-         error_with_decl (exp, "prior parameter's size depends on `%s'");
+         error ("%Hprior parameter's size depends on '%D'",
+                 &DECL_SOURCE_LOCATION (exp), exp);
          return CONST0_RTX (mode);
        }
 
index f8cc5a5..84c1e6f 100644 (file)
@@ -877,7 +877,8 @@ assign_temp (tree type_or_decl, int keep, int memory_required,
       if (decl && size == -1
          && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
        {
-         error_with_decl (decl, "size of variable `%s' is too large");
+         error ("%Hsize of variable '%D' is too large",
+                 &DECL_SOURCE_LOCATION (decl), decl);
          size = 1;
        }
 
@@ -5567,15 +5568,15 @@ uninitialized_vars_warning (tree block)
             not worry that it may be a dangling pointer.  */
          && DECL_INITIAL (decl) == NULL_TREE
          && regno_uninitialized (REGNO (DECL_RTL (decl))))
-       warning_with_decl (decl,
-                          "`%s' might be used uninitialized in this function");
+       warning ("%H'%D' might be used uninitialized in this function",
+                 &DECL_SOURCE_LOCATION (decl), decl);
       if (extra_warnings
          && TREE_CODE (decl) == VAR_DECL
          && DECL_RTL (decl) != 0
          && GET_CODE (DECL_RTL (decl)) == REG
          && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
-       warning_with_decl (decl,
-                          "variable `%s' might be clobbered by `longjmp' or `vfork'");
+       warning ("%Hvariable '%D' might be clobbered by `longjmp' or `vfork'",
+                 &DECL_SOURCE_LOCATION (decl), decl);
     }
   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
     uninitialized_vars_warning (sub);
@@ -5593,8 +5594,8 @@ setjmp_args_warning (void)
     if (DECL_RTL (decl) != 0
        && GET_CODE (DECL_RTL (decl)) == REG
        && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
-      warning_with_decl (decl,
-                        "argument `%s' might be clobbered by `longjmp' or `vfork'");
+      warning ("%Hargument '%D' might be clobbered by `longjmp' or `vfork'",
+               &DECL_SOURCE_LOCATION (decl), decl);
 }
 
 /* If this function call setjmp, put all vars into the stack
@@ -6919,7 +6920,8 @@ expand_function_end (void)
           decl; decl = TREE_CHAIN (decl))
        if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
            && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
-         warning_with_decl (decl, "unused parameter `%s'");
+          warning ("%Hunused parameter '%D'",
+                   &DECL_SOURCE_LOCATION (decl), decl);
     }
 
   /* Delete handlers for nonlocal gotos if nothing uses them.  */
index 5659d2a..7c24921 100644 (file)
@@ -1071,7 +1071,7 @@ common_handle_option (size_t scode, const char *arg,
       break;
 
     case OPT_fmessage_length_:
-      output_set_maximum_length (&global_dc->buffer, value);
+      pp_set_line_maximum_length (global_dc->printer, value);
       break;
 
     case OPT_fmove_all_movables:
diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
new file mode 100644 (file)
index 0000000..b119063
--- /dev/null
@@ -0,0 +1,547 @@
+/* Various declarations for language-independent pretty-print subroutines.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+   Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+#include "config.h"
+#undef FLOAT /* This is for hpux. They should change hpux.  */
+#undef FFS  /* Some systems define this in param.h.  */
+#include "system.h"
+#include "coretypes.h"
+#include "pretty-print.h"
+
+#define obstack_chunk_alloc xmalloc
+#define obstack_chunk_free  free
+
+/* A pointer to the formatted diagnostic message.  */
+#define pp_formatted_text_data(PP) \
+   ((const char *) obstack_base (&pp_base (PP)->buffer->obstack))
+
+/* Format an integer given by va_arg (ARG, type-specifier T) where
+   type-specifier is a precision modifier as indicated by PREC.  F is
+   a string used to construct the appropriate format-specifier.  */
+#define pp_integer_with_precision(PP, ARG, PREC, T, F)       \
+  do                                                         \
+    switch (PREC)                                            \
+      {                                                      \
+      case 0:                                                \
+        pp_scalar (PP, "%" F, va_arg (ARG, T));              \
+        break;                                               \
+                                                             \
+      case 1:                                                \
+        pp_scalar (PP, "%l" F, va_arg (ARG, long T));        \
+        break;                                               \
+                                                             \
+      case 2:                                                \
+        pp_scalar (PP, "%ll" F, va_arg (ARG, long long T));  \
+        break;                                               \
+                                                             \
+      default:                                               \
+        break;                                               \
+      }                                                      \
+  while (0)
+
+
+/* Subroutine of pp_set_maximum_length.  Set up PRETTY-PRINTER's
+   internal maximum characters per line.  */
+static void
+pp_set_real_maximum_length (pretty_printer *pp)
+{
+  /* If we're told not to wrap lines then do the obvious thing.  In case
+     we'll emit prefix only once per message, it is appropriate
+     not to increase unnecessarily the line-length cut-off.  */
+  if (!pp_is_wrapping_line (pp)
+      || pp_prefixing_rule (pp) == DIAGNOSTICS_SHOW_PREFIX_ONCE
+      || pp_prefixing_rule (pp) == DIAGNOSTICS_SHOW_PREFIX_NEVER)
+    pp->maximum_length = pp_line_cutoff (pp);
+  else
+    {
+      int prefix_length = pp->prefix ? strlen (pp->prefix) : 0;
+      /* If the prefix is ridiculously too long, output at least
+         32 characters.  */
+      if (pp_line_cutoff (pp) - prefix_length < 32)
+       pp->maximum_length = pp_line_cutoff (pp) + 32;
+      else
+       pp->maximum_length = pp_line_cutoff (pp);
+    }
+}
+
+/* Clear PRETTY-PRINTER's output state.  */
+static inline void
+pp_clear_state (pretty_printer *pp)
+{
+  pp->emitted_prefix = false;
+  pp_indentation (pp) = 0;
+}
+
+/* Insert enough spaces into the output area of PRETTY-PRINTER to bring
+   the column position to the current indentation level, assuming that a
+   newline has just been written to the buffer.  */
+static void
+pp_indent (pretty_printer *pp)
+{
+  int n = pp_indentation (pp);
+  int i;
+
+  for (i = 0; i < n; ++i)
+    pp_space (pp);
+}
+
+/* Flush the formatted text of PRETTY-PRINTER onto the attached stream.  */
+static inline void
+pp_write_text_to_stream (pretty_printer *pp)
+{
+  const char *text = pp_formatted_text (pp);
+  fputs (text, pp->buffer->stream);
+  pp_clear_output_area (pp);
+}
+
+/* Wrap a text delimited by START and END into PRETTY-PRINTER.  */
+static void
+pp_wrap_text (pretty_printer *pp, const char *start, const char *end)
+{
+  bool wrapping_line = pp_is_wrapping_line (pp);
+
+  while (start != end)
+    {
+      /* Dump anything bordered by whitespaces.  */
+      {
+       const char *p = start;
+       while (p != end && !ISBLANK (*p) && *p != '\n')
+         ++p;
+       if (wrapping_line
+            && p - start >= pp_remaining_character_count_for_line (pp))
+         pp_newline (pp);
+       pp_append_text (pp, start, p);
+       start = p;
+      }
+
+      if (start != end && ISBLANK (*start))
+       {
+         pp_space (pp);
+         ++start;
+       }
+      if (start != end && *start == '\n')
+       {
+         pp_newline (pp);
+         ++start;
+       }
+    }
+}
+
+/* Same as pp_wrap_text but wrap text only when in line-wrapping mode.  */
+static inline void
+pp_maybe_wrap_text (pretty_printer *pp, const char *start, const char *end)
+{
+  if (pp_is_wrapping_line (pp))
+    pp_wrap_text (pp, start, end);
+  else
+    pp_append_text (pp, start, end);
+}
+
+/* Append to the output area of PRETTY-PRINTER a string specified by its
+   STARTing character and LENGTH.  */
+static inline void
+pp_append_r (pretty_printer *pp, const char *start, int length)
+{
+  obstack_grow (&pp->buffer->obstack, start, length);
+  pp->buffer->line_length += length;
+}
+
+/* Format a message pointed to by TEXT.  The following format specifiers are
+   recognized as being client independent:
+   %d, %i: (signed) integer in base ten.
+   %u: unsigned integer in base ten.
+   %o: unsigned integer in base eight.
+   %x: unsigned integer in base sixteen.
+   %ld, %li, %lo, %lu, %lx: long versions of the above.
+   %lld, %lli, %llo, %llu, %llx: long long versions.
+   %wd, %wi, %wo, %wu, %wx: HOST_WIDE_INT versions.
+   %c: character.
+   %s: string.
+   %p: pointer.
+   %m: strerror(text->err_no) - does not consume a value from args_ptr.
+   %%: `%'.
+   %*.s: a substring the length of which is specified by an integer.
+   %H: location_t.  */
+void
+pp_format_text (pretty_printer *pp, text_info *text)
+{
+  for (; *text->format_spec; ++text->format_spec)
+    {
+      int precision = 0;
+      bool wide = false;
+
+      /* Ignore text.  */
+      {
+       const char *p = text->format_spec;
+       while (*p && *p != '%')
+         ++p;
+       pp_wrap_text (pp, text->format_spec, p);
+        text->format_spec = p;
+      }
+
+      if (*text->format_spec == '\0')
+       break;
+
+      /* We got a '%'.  Parse precision modifiers, if any.  */
+      switch (*++text->format_spec)
+        {
+        case 'w':
+          wide = true;
+          ++text->format_spec;
+          break;
+
+        case 'l':
+          do
+            ++precision;
+          while (*++text->format_spec == 'l');
+          break;
+
+        default:
+          break;
+        }
+      /* We don't support precision behond that of "long long".  */
+      if (precision > 2)
+        abort();
+
+      switch (*text->format_spec)
+       {
+       case 'c':
+         pp_character (pp, va_arg (*text->args_ptr, int));
+         break;
+
+       case 'd':
+       case 'i':
+          if (wide)
+            pp_wide_integer (pp, va_arg (*text->args_ptr, HOST_WIDE_INT));
+          else
+            pp_integer_with_precision
+              (pp, *text->args_ptr, precision, int, "d");
+         break;
+
+       case 'o':
+          if (wide)
+            pp_scalar (pp, "%" HOST_WIDE_INT_PRINT "o",
+                       va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
+          else
+            pp_integer_with_precision
+              (pp, *text->args_ptr, precision, unsigned, "u");
+         break;
+
+       case 's':
+         pp_string (pp, va_arg (*text->args_ptr, const char *));
+         break;
+
+        case 'p':
+          pp_pointer (pp, va_arg (*text->args_ptr, void *));
+          break;
+
+       case 'u':
+          if (wide)
+            pp_scalar (pp, HOST_WIDE_INT_PRINT_UNSIGNED,
+                       va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
+          else
+            pp_integer_with_precision
+              (pp, *text->args_ptr, precision, unsigned, "u");
+         break;
+
+       case 'x':
+          if (wide)
+            pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX,
+                       va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
+          else
+            pp_integer_with_precision
+              (pp, *text->args_ptr, precision, unsigned, "x");
+         break;
+
+       case 'm':
+         pp_string (pp, xstrerror (text->err_no));
+         break;
+
+       case '%':
+         pp_character (pp, '%');
+         break;
+
+        case 'H':
+          {
+            const location_t *locus = va_arg (*text->args_ptr, location_t *);
+            pp_string (pp, "file '");
+            pp_string (pp, locus->file);
+            pp_string (pp, "', line ");
+            pp_decimal_int (pp, locus->line);
+          }
+          break;
+
+       case '.':
+         {
+           int n;
+           const char *s;
+           /* We handle no precision specifier but `%.*s'.  */
+           if (*++text->format_spec != '*')
+             abort ();
+           else if (*++text->format_spec != 's')
+             abort ();
+           n = va_arg (*text->args_ptr, int);
+           s = va_arg (*text->args_ptr, const char *);
+           pp_append_text (pp, s, s + n);
+         }
+         break;
+
+       default:
+          if (!pp_format_decoder (pp) || !(*pp_format_decoder (pp)) (pp, text))
+           {
+             /* Hmmm.  The client failed to install a format translator
+                 but called us with an unrecognized format.  Or, maybe, the
+                 translated string just contains an invalid format, or
+                 has formats in the wrong order.  Sorry.  */
+             abort ();
+           }
+       }
+    }
+}
+
+/* Helper subroutine of output_verbatim and verbatim. Do the appropriate
+   settings needed by BUFFER for a verbatim formatting.  */
+void
+pp_format_verbatim (pretty_printer *pp, text_info *text)
+{
+  diagnostic_prefixing_rule_t rule = pp_prefixing_rule (pp);
+  int line_cutoff = pp_line_cutoff (pp);
+
+  /* Set verbatim mode.  */
+  pp->prefixing_rule = DIAGNOSTICS_SHOW_PREFIX_NEVER;
+  pp_line_cutoff (pp) = 0;
+  /* Do the actual formatting.  */
+  pp_format_text (pp, text);
+  /* Restore previous settings.  */
+  pp_prefixing_rule (pp) = rule;
+  pp_line_cutoff (pp) = line_cutoff;
+}
+
+/* Flush the content of BUFFER onto the attached stream.  */
+void
+pp_flush (pretty_printer *pp)
+{
+  pp_write_text_to_stream (pp);
+  pp_clear_state (pp);
+  fputc ('\n', pp->buffer->stream);
+  fflush (pp->buffer->stream);
+}
+
+/* Sets the number of maximum characters per line PRETTY-PRINTER can
+   output in line-wrapping mode.  A LENGTH value 0 suppresses
+   line-wrapping.  */
+void
+pp_set_line_maximum_length (pretty_printer *pp, int length)
+{
+  pp_line_cutoff (pp) = length;
+  pp_set_real_maximum_length (pp);
+}
+
+/* Clear PRETTY-PRINTER output area text info.  */
+void
+pp_clear_output_area (pretty_printer *pp)
+{
+  obstack_free (&pp->buffer->obstack, obstack_base (&pp->buffer->obstack));
+  pp->buffer->line_length = 0;
+}
+
+/* Set PREFIX for PRETTY-PRINTER.  */
+void
+pp_set_prefix (pretty_printer *pp, const char *prefix)
+{
+  pp->prefix = prefix;
+  pp_set_real_maximum_length (pp);
+  pp->emitted_prefix = false;
+  pp_indentation (pp) = 0;
+}
+
+/* Free PRETTY-PRINTER's prefix, a previously malloc()'d string.  */
+void
+pp_destroy_prefix (pretty_printer *pp)
+{
+  if (pp->prefix != NULL)
+    {
+      free ((char *) pp->prefix);
+      pp->prefix = NULL;
+    }
+}
+
+/* Write out PRETTY-PRINTER's prefix.  */
+void
+pp_emit_prefix (pretty_printer *pp)
+{
+  if (pp->prefix != NULL)
+    {
+      switch (pp_prefixing_rule (pp))
+       {
+       default:
+       case DIAGNOSTICS_SHOW_PREFIX_NEVER:
+         break;
+
+       case DIAGNOSTICS_SHOW_PREFIX_ONCE:
+         if (pp->emitted_prefix)
+           {
+             pp_indent (pp);
+             break;
+           }
+         pp_indentation (pp) += 3;
+         /* Fall through.  */
+
+       case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
+         {
+           int prefix_length = strlen (pp->prefix);
+           pp_append_r (pp, pp->prefix, prefix_length);
+           pp->emitted_prefix = true;
+         }
+         break;
+       }
+    }
+}
+
+/* Construct a PRETTY-PRINTER with PREFIX and of MAXIMUM_LENGTH
+   characters per line.  */
+void
+pp_construct (pretty_printer *pp, const char *prefix, int maximum_length)
+{
+  memset (pp, 0, sizeof (pretty_printer));
+  pp->buffer = xmalloc (sizeof (output_buffer));
+  obstack_init (&pp->buffer->obstack);
+  pp->buffer->stream = stderr;
+  pp_line_cutoff (pp) = maximum_length;
+  pp_prefixing_rule (pp) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
+  pp_set_prefix (pp, prefix);
+}
+
+/* Append a string delimited by START and END to the output area of
+   PRETTY-PRINTER.  No line wrapping is done.  However, if beginning a
+   new line then emit PRETTY-PRINTER's prefix and skip any leading
+   whitespace if appropriate.  The caller must ensure that it is
+   safe to do so.  */
+void
+pp_append_text (pretty_printer *pp, const char *start, const char *end)
+{
+  /* Emit prefix and skip whitespace if we're starting a new line.  */
+  if (pp->buffer->line_length == 0)
+    {
+      pp_emit_prefix (pp);
+      if (pp_is_wrapping_line (pp))
+       while (start != end && *start == ' ')
+         ++start;
+    }
+  pp_append_r (pp, start, end - start);
+}
+
+/* Finishes constructing a NULL-terminated character string representing
+   the PRETTY-PRINTED text.  */
+const char *
+pp_formatted_text (pretty_printer *pp)
+{
+  obstack_1grow (&pp->buffer->obstack, '\0');
+  return pp_formatted_text_data (pp);
+}
+
+/*  Return a pointer to the last character emitted in PRETTY-PRINTER's
+    output area.  A NULL pointer means no character available.  */
+const char *
+pp_last_position_in_text (const pretty_printer *pp)
+{
+  const char *p = NULL;
+  struct obstack *text = &pp->buffer->obstack;
+
+  if (obstack_base (text) != obstack_next_free (text))
+    p = ((const char *) obstack_next_free (text)) - 1;
+  return p;
+}
+
+/* Return the amount of characters PRETTY-PRINTER can accept to
+   make a full line.  Meaningfull only in line-wrapping mode.  */
+int
+pp_remaining_character_count_for_line (pretty_printer *pp)
+{
+  return pp->maximum_length - pp->buffer->line_length;
+}
+
+
+/* Format a message into BUFFER a la printf.  */
+void
+pp_printf (pretty_printer *pp, const char *msg, ...)
+{
+  text_info text;
+  va_list ap;
+
+  va_start (ap, msg);
+  text.err_no = errno;
+  text.args_ptr = &ap;
+  text.format_spec = msg;
+  pp_format_text (pp, &text);
+  va_end (ap);
+}
+
+
+/* Output MESSAGE verbatim into BUFFER.  */
+void
+pp_verbatim (pretty_printer *pp, const char *msg, ...)
+{
+  text_info text;
+  va_list ap;
+
+  va_start (ap, msg);
+  text.err_no = errno;
+  text.args_ptr = &ap;
+  text.format_spec = msg;
+  pp_format_verbatim (pp, &text);
+  va_end (ap);
+}
+
+
+
+/* Have PRETTY-PRINTER start a new line.  */
+void
+pp_newline (pretty_printer *pp)
+{
+  obstack_1grow (&pp->buffer->obstack, '\n');
+  pp->buffer->line_length = 0;
+}
+
+/* Have PRETTY-PRINTER add a CHARACTER.  */
+void
+pp_character (pretty_printer *pp, int c)
+{
+  if (pp_is_wrapping_line (pp)
+      && pp_remaining_character_count_for_line (pp) <= 0)
+    {
+      pp_newline (pp);
+      if (ISSPACE (c))
+        return;
+    }
+  obstack_1grow (&pp->buffer->obstack, c);
+  ++pp->buffer->line_length;
+}
+
+/* Append a STRING to the output area of PRETTY-PRINTER; the STRING may
+   be line-wrapped if in appropriate mode.  */
+void
+pp_string (pretty_printer *pp, const char *str)
+{
+  pp_maybe_wrap_text (pp, str, str + (str ? strlen (str) : 0));
+}
+
+
index 5efb9e7..2b4e559 100644 (file)
@@ -1,5 +1,5 @@
 /* Various declarations for language-independent pretty-print subroutines.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
 
 This file is part of GCC.
@@ -22,7 +22,47 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #ifndef GCC_PRETTY_PRINT_H
 #define GCC_PRETTY_PRINT_H
 
-#include "diagnostic.h"
+#include "obstack.h"
+#include "input.h"
+
+/* The type of a text to be formatted according a format specification
+   along with a list of things.  */
+typedef struct
+{
+  const char *format_spec;
+  va_list *args_ptr;
+  int err_no;  /* for %m */
+} text_info;
+
+/* How often diagnostics are prefixed by their locations:
+   o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
+   o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once;
+   o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical
+   line is started.  */
+typedef enum
+{
+  DIAGNOSTICS_SHOW_PREFIX_ONCE       = 0x0,
+  DIAGNOSTICS_SHOW_PREFIX_NEVER      = 0x1,
+  DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2
+} diagnostic_prefixing_rule_t;
+
+/* 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;
+
+  /* Where to output formatted text.  */
+  FILE *stream;
+
+  /* The amount of characters output so far.  */  
+  int line_length;
+
+  /* This must be large enough to hold any printed integer or
+     floating-point value.  */
+  char digit_buffer[128];
+} output_buffer;
 
 /* The type of pretty-printer flags passed to clients.  */
 typedef unsigned int pp_flags;
@@ -32,69 +72,163 @@ typedef enum
   pp_none, pp_before, pp_after
 } pp_padding;
 
+/* 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 *);
+
+/* Client supplied function used to decode formats.  */
+#define pp_format_decoder(PP) pp_base (PP)->format_decoder
+
+/* TRUE if a newline character needs to be added before further
+   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
+
+/* 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_print_info
 {
   /* Where we print external representation of ENTITY.  */
   output_buffer *buffer;
+
+  /* The prefix for each new line.  */
+  const char *prefix;
+
   pp_flags flags;
+  
   /* Where to put whitespace around the entity being formatted.  */
   pp_padding padding;
+  
+  /* The real upper bound of number of characters per line, taking into
+     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;
+
+  /* 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
+     pp_string (and related functions) to add data to the BUFFER.
+     FORMAT_DECODER can read arguments from *TEXT->args_pts using VA_ARG.
+     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.
+  */
+  printer_fn format_decoder;
+
+  /* Nonzero if current PREFIX was emitted at least once.  */
+  bool emitted_prefix;
+
+  /* Nonzero means one should emit a newline before outputting anything.  */
+  bool need_newline;
 };
 
-#define pp_left_paren(PPI)      output_add_character (pp_buffer (PPI), '(')
-#define pp_right_paren(PPI)     output_add_character (pp_buffer (PPI), ')')
-#define pp_left_bracket(PPI)    output_add_character (pp_buffer (PPI), '[')
-#define pp_right_bracket(PPI)   output_add_character (pp_buffer (PPI), ']')
-#define pp_left_brace(PPI)      output_add_character (pp_buffer (PPI), '{')
-#define pp_right_brace(PPI)     output_add_character (pp_buffer (PPI), '}')
-#define pp_semicolon(PPI)       output_add_character (pp_buffer (PPI), ';')
-#define pp_comma(PPI)           output_add_string (pp_buffer (PPI), ", ")
-#define pp_dot(PPI)             output_add_character (pp_buffer (PPI), '.')
-#define pp_colon(PPI)           output_add_character (pp_buffer (PPI), ':')
-#define pp_colon_colon(PPI)     output_add_string (pp_buffer (PPI), "::")
-#define pp_arrow(PPI)           output_add_string (pp_buffer (PPI), "->")
-#define pp_equal(PPI)           output_add_character (pp_buffer (PPI), '=')
-#define pp_question(PPI)        output_add_character (pp_buffer (PPI), '?')
-#define pp_bar(PPI)             output_add_character (pp_buffer (PPI), '|')
-#define pp_carret(PPI)          output_add_character (pp_buffer (PPI), '^')
-#define pp_ampersand(PPI)       output_add_character (pp_buffer (PPI), '&')
-#define pp_less(PPI)            output_add_character (pp_buffer (PPI), '<')
-#define pp_greater(PPI)         output_add_character (pp_buffer (PPI), '>')
-#define pp_plus(PPI)            output_add_character (pp_buffer (PPI), '+')
-#define pp_minus(PPI)           output_add_character (pp_buffer (PPI), '-')
-#define pp_star(PPI)            output_add_character (pp_buffer (PPI), '*')
-#define pp_slash(PPI)           output_add_character (pp_buffer (PPI), '/')
-#define pp_modulo(PPI)          output_add_character (pp_buffer (PPI), '%')
-#define pp_exclamation(PPI)     output_add_character (pp_buffer (PPI), '!')
-#define pp_complement(PPI)      output_add_character (pp_buffer (PPI), '~')
-#define pp_quote(PPI)           output_add_character (pp_buffer (PPI), '\'')
-#define pp_backquote(PPI)       output_add_character (pp_buffer (PPI), '`')
-#define pp_doublequote(PPI)     output_add_character (pp_buffer (PPI), '"')
-#define pp_newline(PPI)         output_add_newline (pp_buffer (PPI))
-#define pp_character(PPI, C)    output_add_character (pp_buffer (PPI), C)
-#define pp_whitespace(PPI)      output_add_space (pp_buffer (PPI))
-#define pp_indentation(PPI)     output_indentation (pp_buffer (PPI))
-#define pp_newline_and_indent(PPI, N) \
-  do {                                \
-    pp_indentation (PPI) += N;        \
-    pp_newline (PPI);                 \
+#define pp_space(PP)            pp_character (pp_base (PP), ' ')
+#define pp_left_paren(PP)       pp_character (pp_base (PP), '(')
+#define pp_right_paren(PP)      pp_character (pp_base (PP), ')')
+#define pp_left_bracket(PP)     pp_character (pp_base (PP), '[')
+#define pp_right_bracket(PP)    pp_character (pp_base (PP), ']')
+#define pp_left_brace(PP)       pp_character (pp_base (PP), '{')
+#define pp_right_brace(PP)      pp_character (pp_base (PP), '}')
+#define pp_semicolon(PP)        pp_character (pp_base (PP), ';')
+#define pp_comma(PP)            pp_string (pp_base (PP), ", ")
+#define pp_dot(PP)              pp_character (pp_base (PP), '.')
+#define pp_colon(PP)            pp_character (pp_base (PP), ':')
+#define pp_colon_colon(PP)      pp_string (pp_base (PP), "::")
+#define pp_arrow(PP)            pp_string (pp_base (PP), "->")
+#define pp_equal(PP)            pp_character (pp_base (PP), '=')
+#define pp_question(PP)         pp_character (pp_base (PP), '?')
+#define pp_bar(PP)              pp_character (pp_base (PP), '|')
+#define pp_carret(PP)           pp_character (pp_base (PP), '^')
+#define pp_ampersand(PP)        pp_character (pp_base (PP), '&')
+#define pp_less(PP)             pp_character (pp_base (PP), '<')
+#define pp_greater(PP)          pp_character (pp_base (PP), '>')
+#define pp_plus(PP)             pp_character (pp_base (PP), '+')
+#define pp_minus(PP)            pp_character (pp_base (PP), '-')
+#define pp_star(PP)             pp_character (pp_base (PP), '*')
+#define pp_slash(PP)            pp_character (pp_base (PP), '/')
+#define pp_modulo(PP)           pp_character (pp_base (PP), '%')
+#define pp_exclamation(PP)      pp_character (pp_base (PP), '!')
+#define pp_complement(PP)       pp_character (pp_base (PP), '~')
+#define pp_quote(PP)            pp_character (pp_base (PP), '\'')
+#define pp_backquote(PP)        pp_character (pp_base (PP), '`')
+#define pp_doublequote(PP)      pp_character (pp_base (PP), '"')
+#define pp_newline_and_indent(PP, N) \
+  do {                               \
+    pp_indentation (PP) += N;        \
+    pp_newline (PP);                 \
   } while (0)
-#define pp_separate_with(PPI, C) \
-   do {                          \
-     pp_character (PPI, C);      \
-     pp_whitespace (PPI);        \
+#define pp_separate_with(PP, C)     \
+   do {                             \
+     pp_character (pp_base (PP), C);\
+     pp_space (PP);                 \
    } while (0)
-#define pp_format_scalar(PPI, F, S) \
-   output_formatted_scalar (pp_buffer (PPI), F, S)
-#define pp_wide_integer(PPI, I) \
-   pp_format_scalar (PPI, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) I)
-#define pp_pointer(PPI, P) pp_format_scalar (PPI, "%p", p)
+#define pp_scalar(PP, FORMAT, SCALAR)                              \
+  do                                                               \
+    {                                                              \
+      sprintf (pp_base (PP)->buffer->digit_buffer, FORMAT, SCALAR); \
+      pp_string (pp_base (PP), pp_base (PP)->buffer->digit_buffer); \
+    }                                                              \
+  while (0)
+#define pp_decimal_int(PP, I)  pp_scalar (PP, "%d", I)
+#define pp_wide_integer(PP, I) \
+   pp_scalar (PP, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) I)
+#define pp_pointer(PP, P)      pp_scalar (PP, "%p", P)
 
-#define pp_identifier(PPI, ID)  output_add_string (pp_buffer (PPI), ID)
-#define pp_tree_identifier(PPI, T) pp_identifier(PPI, IDENTIFIER_POINTER (T))
+#define pp_identifier(PP, ID)  pp_string (pp_base (PP), ID)
+#define pp_tree_identifier(PP, T)                      \
+  pp_append_text(pp_base (PP), IDENTIFIER_POINTER (T), \
+                 IDENTIFIER_POINTER (T) + IDENTIFIER_LENGTH (T))
 
-#define pp_unsupported_tree(PPI, T) \
-  output_verbatim (pp_buffer(PPI), "#`%s' not supported by %s#",\
+#define pp_unsupported_tree(PP, T) \
+  pp_verbatim (pp_base (PP), "#`%s' not supported by %s#",\
                    tree_code_name[(int) TREE_CODE (T)], __FUNCTION__)
 
+
+/* Clients that directly derive from pretty_printer need to override
+   this macro to return a pointer to the base pretty_printer structrure.  */
+#define pp_base(PP) (PP)
+
+extern void pp_construct (pretty_printer *, const char *, int);
+extern void pp_set_line_maximum_length (pretty_printer *, int);
+extern void pp_set_prefix (pretty_printer *, const char *);
+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 const char *pp_formatted_text (pretty_printer *);
+extern const char *pp_last_position_in_text (const pretty_printer *);
+extern void pp_emit_prefix (pretty_printer *);
+extern void pp_append_text (pretty_printer *, const char *, const char *);
+extern void pp_printf (pretty_printer *, const char *, ...) ATTRIBUTE_PRINTF_2;
+extern void pp_verbatim (pretty_printer *, const char *, ...);
+extern void pp_flush (pretty_printer *);
+extern void pp_format_text (pretty_printer *, text_info *);
+extern void pp_format_verbatim (pretty_printer *, text_info *);
+
+extern void pp_newline (pretty_printer *);
+extern void pp_character (pretty_printer *, int);
+extern void pp_string (pretty_printer *, const char *);
+
 #endif /* GCC_PRETTY_PRINT_H */
index 7dba030..a4900ec 100644 (file)
@@ -986,8 +986,8 @@ fixup_gotos (struct nesting *thisblock, rtx stack_level,
              && INSN_UID (first_insn) > INSN_UID (f->before_jump)
              && ! DECL_ERROR_ISSUED (f->target))
            {
-             error_with_decl (f->target,
-                              "label `%s' used before containing binding contour");
+             error ("%Hlabel '%D' used before containing binding contour",
+                     &DECL_SOURCE_LOCATION (f->target), f->target);
              /* Prevent multiple errors for one label.  */
              DECL_ERROR_ISSUED (f->target) = 1;
            }
@@ -3636,7 +3636,7 @@ warn_about_unused_variables (tree vars)
          && ! TREE_USED (decl)
          && ! DECL_IN_SYSTEM_HEADER (decl)
          && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
-       warning_with_decl (decl, "unused variable `%s'");
+       warning ("%Hunused variable '%D'", &DECL_SOURCE_LOCATION (decl), decl);
 }
 
 /* Generate RTL code to terminate a binding contour.
@@ -3696,8 +3696,8 @@ expand_end_bindings (tree vars, int mark_ends, int dont_jump_in)
             that must be an error, because gotos without fixups
             come from outside all saved stack-levels.  */
          if (TREE_ADDRESSABLE (chain->label))
-           error_with_decl (chain->label,
-                            "label `%s' used before containing binding contour");
+           error ("%Hlabel '%D' used before containing binding contour",
+                   &DECL_SOURCE_LOCATION (chain->label), chain->label);
        }
     }
 
index d334374..e2395c4 100644 (file)
@@ -515,10 +515,11 @@ layout_decl (tree decl, unsigned int known_align)
          int size_as_int = TREE_INT_CST_LOW (size);
 
          if (compare_tree_int (size, size_as_int) == 0)
-           warning_with_decl (decl, "size of `%s' is %d bytes", size_as_int);
+           warning ("%Hsize of '%D' is %d bytes",
+                     &DECL_SOURCE_LOCATION (decl), decl, size_as_int);
          else
-           warning_with_decl (decl, "size of `%s' is larger than %d bytes",
-                              larger_than_size);
+           warning ("size of '%D' is larger than %d bytes",
+                     &DECL_SOURCE_LOCATION (decl), decl, larger_than_size);
        }
     }
 
@@ -883,9 +884,11 @@ place_field (record_layout_info rli, tree field)
          if (TYPE_ALIGN (type) > desired_align)
            {
              if (STRICT_ALIGNMENT)
-               warning_with_decl (field, "packed attribute causes inefficient alignment for `%s'");
+               warning ("%Hpacked attribute causes inefficient alignment "
+                         "for '%D'", &DECL_SOURCE_LOCATION (field), field);
              else
-               warning_with_decl (field, "packed attribute is unnecessary for `%s'");
+               warning ("%Hpacked attribute is unnecessary for '%D'",
+                         &DECL_SOURCE_LOCATION (field), field);
            }
        }
       else
@@ -900,7 +903,8 @@ place_field (record_layout_info rli, tree field)
         Bump the cumulative size to multiple of field alignment.  */
 
       if (warn_padded)
-       warning_with_decl (field, "padding struct to align `%s'");
+       warning ("%Hpadding struct to align '%D'",
+                 &DECL_SOURCE_LOCATION (field), field);
 
       /* If the alignment is still within offset_align, just align
         the bit position.  */
index 93fc185..144db98 100644 (file)
@@ -1659,11 +1659,11 @@ check_global_declarations (tree *vec, int len)
          && ! TREE_PUBLIC (decl))
        {
          if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
-           pedwarn_with_decl (decl,
-                              "`%s' used but never defined");
+           pedwarn ("%H'%F' used but never defined",
+                     &DECL_SOURCE_LOCATION (decl), decl);
          else
-           warning_with_decl (decl,
-                              "`%s' declared `static' but never defined");
+           warning ("%H'%F' declared `static' but never defined",
+                     &DECL_SOURCE_LOCATION (decl), decl);
          /* This symbol is effectively an "extern" declaration now.  */
          TREE_PUBLIC (decl) = 1;
          assemble_external (decl);
@@ -1684,7 +1684,8 @@ check_global_declarations (tree *vec, int len)
          && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
          /* Otherwise, ask the language.  */
          && (*lang_hooks.decls.warn_unused_global) (decl))
-       warning_with_decl (decl, "`%s' defined but not used");
+       warning ("%H'%D' defined but not used",
+                 &DECL_SOURCE_LOCATION (decl), decl);
 
       /* Avoid confusing the debug information machinery when there are
         errors.  */
@@ -2512,8 +2513,15 @@ rest_of_handle_inlining (tree decl)
       timevar_pop (TV_INTEGRATION);
       if (lose || ! optimize)
        {
-         if (warn_inline && DECL_INLINE (decl))
-           warning_with_decl (decl, lose);
+         if (warn_inline && lose && DECL_INLINE (decl))
+            {
+              char *msg = xmalloc (2 + strlen (lose) + 1);
+              msg[0] = '%';
+              msg[1] = 'H';
+              strcpy(msg + 2, lose);
+              warning (msg, &DECL_SOURCE_LOCATION (decl));
+              free (msg);
+            }
          DECL_ABSTRACT_ORIGIN (decl) = 0;
          /* Don't really compile an extern inline function.
             If we can't make it inline, pretend
@@ -4091,6 +4099,29 @@ init_asm_output (const char *name)
     }
 }
 
+/* Default tree printer.   Handles declarations only.  */
+static bool
+default_tree_printer (pretty_printer * pp, text_info *text)
+{
+  switch (*text->format_spec)
+    {
+    case 'D':
+    case 'F':
+    case 'T':
+      {
+        tree t = va_arg (*text->args_ptr, tree);
+        const char *n = DECL_NAME (t)
+          ? (*lang_hooks.decl_printable_name) (t, 2)
+          : "<anonymous>";
+        pp_string (pp, n);
+      }
+      return true;
+
+    default:
+      return false;
+    }
+}
+
 /* Initialization of the front end environment, before command line
    options are parsed.  Signal handlers, internationalization etc.
    ARGV0 is main's argv[0].  */
@@ -4110,6 +4141,13 @@ general_init (const char *argv0)
 
   gcc_init_libintl ();
 
+  /* Initialize the diagnostics reporting machinery, so option parsing
+     can give warnings and errors.  */
+  diagnostic_initialize (global_dc);
+  /* Set a default printer.  Language specific initializations will
+     override it later.  */
+  pp_format_decoder (global_dc->printer) = &default_tree_printer;
+
   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
 #ifdef SIGSEGV
   signal (SIGSEGV, crash_signal);
@@ -4133,10 +4171,6 @@ general_init (const char *argv0)
   /* Other host-specific signal setup.  */
   (*host_hooks.extra_signals)();
 
-  /* Initialize the diagnostics reporting machinery, so option parsing
-     can give warnings and errors.  */
-  diagnostic_initialize (global_dc);
-
   /* Initialize the garbage-collector, string pools and tree type hash
      table.  */
   init_ggc ();
index 75bf64c..c45105c 100644 (file)
@@ -56,10 +56,10 @@ extern void _fatal_insn (const char *, rtx, const char *, int, const char *)
 extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
      ATTRIBUTE_NORETURN;
 extern void warning (const char *, ...);
-extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+extern void error (const char *, ...);
 extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
      ATTRIBUTE_NORETURN;
-extern void pedwarn (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+extern void pedwarn (const char *, ...);
 extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 extern void inform (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 
@@ -67,10 +67,6 @@ extern void rest_of_decl_compilation (tree, const char *, int, int);
 extern void rest_of_type_compilation (tree, int);
 extern void rest_of_compilation (tree);
 
-extern void pedwarn_with_decl (tree, const char *, ...);
-extern void warning_with_decl (tree, const char *, ...);
-extern void error_with_decl (tree, const char *, ...);
-
 extern void announce_function (tree);
 
 extern void error_for_asm (rtx, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
index 4a468a6..759dc07 100644 (file)
@@ -1171,7 +1171,8 @@ expand_call_inline (tree *tp, int *walk_subtrees, void *data)
       if (warn_inline && DECL_INLINE (fn) && !DID_INLINE_FUNC (fn)
          && !DECL_IN_SYSTEM_HEADER (fn))
        {
-         warning_with_decl (fn, "inlining failed in call to `%s'");
+         warning ("%Hinlining failed in call to '%F'",
+                   &DECL_SOURCE_LOCATION (fn), fn);
          warning ("called from here");
        }
       return NULL_TREE;
index 847cf77..a8ff36f 100644 (file)
@@ -432,7 +432,8 @@ named_section (tree decl, const char *name, int reloc)
     {
       flags = get_named_section_flags (name);
       if ((flags & SECTION_OVERRIDE) == 0)
-       error_with_decl (decl, "%s causes a section type conflict");
+       error ("%H%D causes a section type conflict",
+               &DECL_SOURCE_LOCATION (decl), decl);
     }
 
   named_section_flags (name, flags);
@@ -802,15 +803,17 @@ make_decl_rtl (tree decl, const char *asmspec)
     {
       /* First detect errors in declaring global registers.  */
       if (reg_number == -1)
-       error_with_decl (decl, "register name not specified for `%s'");
+       error ("%Hregister name not specified for '%D'",
+               &DECL_SOURCE_LOCATION (decl), decl);
       else if (reg_number < 0)
-       error_with_decl (decl, "invalid register name for `%s'");
+       error ("%Hinvalid register name for '%D'",
+               &DECL_SOURCE_LOCATION (decl), decl);
       else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
-       error_with_decl (decl,
-                        "data type of `%s' isn't suitable for a register");
+       error ("%Hdata type of '%D' isn't suitable for a register",
+               &DECL_SOURCE_LOCATION (decl), decl);
       else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
-       error_with_decl (decl,
-                        "register specified for `%s' isn't suitable for data type");
+       error ("%Hregister specified for '%D' isn't suitable for data type",
+               &DECL_SOURCE_LOCATION (decl), decl);
       /* Now handle properly declared static register variables.  */
       else
        {
@@ -854,8 +857,8 @@ make_decl_rtl (tree decl, const char *asmspec)
      Also handle vars declared register invalidly.  */
 
   if (reg_number >= 0 || reg_number == -3)
-    error_with_decl (decl,
-                    "register name given for non-register variable `%s'");
+    error ("%Hregister name given for non-register variable '%D'",
+           &DECL_SOURCE_LOCATION (decl), decl);
 
   /* Specifying a section attribute on a variable forces it into a
      non-.bss section, and thus it cannot be common.  */
@@ -1391,7 +1394,8 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
   if (! dont_output_data
       && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
     {
-      error_with_decl (decl, "size of variable `%s' is too large");
+      error ("%Hsize of variable '%D' is too large",
+             &DECL_SOURCE_LOCATION (decl), decl);
       return;
     }
 
@@ -1429,9 +1433,9 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
 #endif
   if (align > MAX_OFILE_ALIGNMENT)
     {
-      warning_with_decl (decl,
-       "alignment of `%s' is greater than maximum object file alignment. Using %d",
-                        MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
+      warning ("%Halignment of '%D' is greater than maximum object "
+               "file alignment.  Using %d", &DECL_SOURCE_LOCATION (decl),
+               decl, MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
       align = MAX_OFILE_ALIGNMENT;
     }
 
@@ -1497,8 +1501,9 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
 
 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
       if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
-       warning_with_decl
-         (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded);
+       warning ("%Hrequested alignment for '%D' is greater than "
+                 "implemented alignment of %d", &DECL_SOURCE_LOCATION (decl),
+                 decl, rounded);
 #endif
 
       /* If the target cannot output uninitialized but not common global data
@@ -4169,15 +4174,17 @@ merge_weak (tree newdecl, tree olddecl)
         declare_weak because the NEWDECL and OLDDECL was not yet
         been merged; therefore, TREE_ASM_WRITTEN was not set.  */
       if (TREE_ASM_WRITTEN (olddecl))
-       error_with_decl (newdecl,
-                        "weak declaration of `%s' must precede definition");
+       error ("%Hweak declaration of '%D' must precede definition",
+               &DECL_SOURCE_LOCATION (newdecl), newdecl);
 
       /* If we've already generated rtl referencing OLDDECL, we may
         have done so in a way that will not function properly with
         a weak symbol.  */
       else if (TREE_USED (olddecl)
               && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
-       warning_with_decl (newdecl, "weak declaration of `%s' after first use results in unspecified behavior");
+       warning ("%Hweak declaration of '%D' after first use results "
+                 "in unspecified behavior",
+                 &DECL_SOURCE_LOCATION (newdecl), newdecl);
 
       if (SUPPORTS_WEAK)
        {
@@ -4210,16 +4217,19 @@ void
 declare_weak (tree decl)
 {
   if (! TREE_PUBLIC (decl))
-    error_with_decl (decl, "weak declaration of `%s' must be public");
+    error ("%Hweak declaration of '%D' must be public",
+           &DECL_SOURCE_LOCATION (decl), decl);
   else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
-    error_with_decl (decl, "weak declaration of `%s' must precede definition");
+    error ("%Hweak declaration of '%D' must precede definition",
+           &DECL_SOURCE_LOCATION (decl), decl);
   else if (SUPPORTS_WEAK)
     {
       if (! DECL_WEAK (decl))
        weak_decls = tree_cons (NULL, decl, weak_decls);
     }
   else
-    warning_with_decl (decl, "weak declaration of `%s' not supported");
+    warning ("%Hweak declaration of '%D' not supported",
+             &DECL_SOURCE_LOCATION (decl), decl);
 
   mark_weak (decl);
 }