OSDN Git Service

* error.c (dump_expr): Add 0x to printed hex numbers to make
[pf3gnuchains/gcc-fork.git] / gcc / cp / error.c
index 579f584..f836ecc 100644 (file)
@@ -2,29 +2,30 @@
    This code is non-reentrant.
    Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002
    Free Software Foundation, Inc.
-   This file is part of GNU CC.
+   This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify
+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.
 
-GNU CC is distributed in the hope that it will be useful,
+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 GNU CC; see the file COPYING.  If not, write to
+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"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "tree.h"
 #include "cp-tree.h"
 #include "real.h"
-#include "obstack.h"
 #include "toplev.h"
 #include "flags.h"
 #include "diagnostic.h"
@@ -45,11 +46,6 @@ enum pad { none, before, after };
    print_non_consecutive_character ((BUFFER), '<')
 #define print_template_argument_list_end(BUFFER)  \
    print_non_consecutive_character ((BUFFER), '>')
-#define print_whitespace(BUFFER, TFI)        \
-   do {                                      \
-     output_add_space (BUFFER);              \
-     put_whitespace (TFI) = none;            \
-   } while (0)
 #define print_tree_identifier(BUFFER, TID) \
    output_add_string ((BUFFER), IDENTIFIER_POINTER (TID))
 #define print_identifier(BUFFER, ID) output_add_string ((BUFFER), (ID))
@@ -66,63 +62,60 @@ static output_buffer *scratch_buffer = &scratch_buffer_rec;
 #define reinit_global_formatting_buffer() \
    output_clear_message_text (scratch_buffer)
 
-static const char *args_to_string              PARAMS ((tree, int));
-static const char *assop_to_string             PARAMS ((enum tree_code, int));
-static const char *code_to_string              PARAMS ((enum tree_code, int));
-static const char *cv_to_string                        PARAMS ((tree, int));
-static const char *decl_to_string              PARAMS ((tree, int));
-static const char *expr_to_string              PARAMS ((tree, int));
-static const char *fndecl_to_string            PARAMS ((tree, int));
-static const char *op_to_string                        PARAMS ((enum tree_code, int));
-static const char *parm_to_string              PARAMS ((int, int));
-static const char *type_to_string              PARAMS ((tree, int));
-
-static void dump_type PARAMS ((tree, int));
-static void dump_typename PARAMS ((tree, int));
-static void dump_simple_decl PARAMS ((tree, tree, int));
-static void dump_decl PARAMS ((tree, int));
-static void dump_template_decl PARAMS ((tree, int));
-static void dump_function_decl PARAMS ((tree, int));
-static void dump_expr PARAMS ((tree, int));
-static void dump_unary_op PARAMS ((const char *, tree, int));
-static void dump_binary_op PARAMS ((const char *, tree, int));
-static void dump_aggr_type PARAMS ((tree, int));
-static enum pad dump_type_prefix PARAMS ((tree, int));
-static void dump_type_suffix PARAMS ((tree, int));
-static void dump_function_name PARAMS ((tree, int));
-static void dump_expr_list PARAMS ((tree, int));
-static void dump_global_iord PARAMS ((tree));
-static enum pad dump_qualifiers PARAMS ((tree, enum pad));
-static void dump_char PARAMS ((int));
-static void dump_parameters PARAMS ((tree, int));
-static void dump_exception_spec PARAMS ((tree, int));
-static const char *class_key_or_enum PARAMS ((tree));
-static void dump_template_argument PARAMS ((tree, int));
-static void dump_template_argument_list PARAMS ((tree, int));
-static void dump_template_parameter PARAMS ((tree, int));
-static void dump_template_bindings PARAMS ((tree, tree));
-static void dump_scope PARAMS ((tree, int));
-static void dump_template_parms PARAMS ((tree, int, int));
-
-static const char *function_category PARAMS ((tree));
-static void maybe_print_instantiation_context PARAMS ((output_buffer *));
-static void print_instantiation_full_context PARAMS ((output_buffer *));
-static void print_instantiation_partial_context PARAMS ((output_buffer *, tree,
-                                                         const char *, int));
-static void cp_diagnostic_starter PARAMS ((output_buffer *,
-                                           diagnostic_context *));
-static void cp_diagnostic_finalizer PARAMS ((output_buffer *,
-                                             diagnostic_context *));
-static void cp_print_error_function PARAMS ((output_buffer *,
-                                             diagnostic_context *));
-
-static int cp_printer PARAMS ((output_buffer *));
-static void print_non_consecutive_character PARAMS ((output_buffer *, int));
-static void print_integer PARAMS ((output_buffer *, HOST_WIDE_INT));
-static tree locate_error PARAMS ((const char *, va_list));
+static const char *args_to_string (tree, int);
+static const char *assop_to_string (enum tree_code, int);
+static const char *code_to_string (enum tree_code, int);
+static const char *cv_to_string (tree, int);
+static const char *decl_to_string (tree, int);
+static const char *expr_to_string (tree, int);
+static const char *fndecl_to_string (tree, int);
+static const char *op_to_string        (enum tree_code, int);
+static const char *parm_to_string (int, int);
+static const char *type_to_string (tree, int);
+
+static void dump_type (tree, int);
+static void dump_typename (tree, int);
+static void dump_simple_decl (tree, tree, int);
+static void dump_decl (tree, int);
+static void dump_template_decl (tree, int);
+static void dump_function_decl (tree, int);
+static void dump_expr (tree, int);
+static void dump_unary_op (const char *, tree, int);
+static void dump_binary_op (const char *, tree, int);
+static void dump_aggr_type (tree, int);
+static enum pad dump_type_prefix (tree, int);
+static void dump_type_suffix (tree, int);
+static void dump_function_name (tree, int);
+static void dump_expr_list (tree, int);
+static void dump_global_iord (tree);
+static enum pad dump_qualifiers (tree, enum pad);
+static void dump_char (int);
+static void dump_parameters (tree, int);
+static void dump_exception_spec (tree, int);
+static const char *class_key_or_enum (tree);
+static void dump_template_argument (tree, int);
+static void dump_template_argument_list (tree, int);
+static void dump_template_parameter (tree, int);
+static void dump_template_bindings (tree, tree);
+static void dump_scope (tree, int);
+static void dump_template_parms (tree, int, int);
+
+static const char *function_category (tree);
+static void maybe_print_instantiation_context (diagnostic_context *);
+static void print_instantiation_full_context (diagnostic_context *);
+static void print_instantiation_partial_context (diagnostic_context *,
+                                                 tree, const char *, int);
+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 void print_integer (output_buffer *, HOST_WIDE_INT);
+static tree locate_error (const char *, va_list);
 
 void
-init_error ()
+init_error (void)
 {
   diagnostic_starter (global_dc) = cp_diagnostic_starter;
   diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer;
@@ -134,9 +127,7 @@ init_error ()
 /* Dump a scope, if deemed necessary.  */
 
 static void
-dump_scope (scope, flags)
-     tree scope;
-     int flags;
+dump_scope (tree scope, int flags)
 {
   int f = ~TFF_RETURN_TYPE & (flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF));
 
@@ -167,9 +158,7 @@ dump_scope (scope, flags)
    indication of whether we dumped something.  */
 
 static enum pad
-dump_qualifiers (t, p)
-     tree t;
-     enum pad p;
+dump_qualifiers (tree t, enum pad p)
 {
   static const int masks[] =
     {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
@@ -204,9 +193,7 @@ static char digit_buffer[128];
 /* Dump the template ARGument under control of FLAGS.  */
 
 static void
-dump_template_argument (arg, flags)
-     tree arg;
-     int flags;
+dump_template_argument (tree arg, int flags)
 {
   if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
     dump_type (arg, flags & ~TFF_CLASS_KEY_OR_ENUM);
@@ -218,9 +205,7 @@ dump_template_argument (arg, flags)
    of FLAGS.  */
 
 static void
-dump_template_argument_list (args, flags)
-     tree args;
-     int flags;
+dump_template_argument_list (tree args, int flags)
 {
   int n = TREE_VEC_LENGTH (args);
   int need_comma = 0;
@@ -238,9 +223,7 @@ dump_template_argument_list (args, flags)
 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS.  */
 
 static void
-dump_template_parameter (parm, flags)
-     tree parm;
-     int flags;
+dump_template_parameter (tree parm, int flags)
 {
   tree p = TREE_VALUE (parm);
   tree a = TREE_PURPOSE (parm);
@@ -279,8 +262,7 @@ dump_template_parameter (parm, flags)
    TREE_VEC.  */
 
 static void
-dump_template_bindings (parms, args)
-     tree parms, args;
+dump_template_bindings (tree parms, tree args)
 {
   int need_comma = 0;
 
@@ -320,13 +302,11 @@ dump_template_bindings (parms, args)
     }
 }
 
-/* Dump into the obstack a human-readable equivalent of TYPE.  FLAGS
-   controls the format.  */
+/* Dump a human-readable equivalent of TYPE.  FLAGS controls the
+   format.  */
 
 static void
-dump_type (t, flags)
-     tree t;
-     int flags;
+dump_type (tree t, int flags)
 {
   if (t == NULL_TREE)
     return;
@@ -415,7 +395,7 @@ dump_type (t, flags)
       break;
 
     case TEMPLATE_TEMPLATE_PARM:
-      /* For parameters inside template signature. */
+      /* For parameters inside template signature.  */
       if (TYPE_IDENTIFIER (t))
        print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
       else
@@ -457,8 +437,8 @@ dump_type (t, flags)
       break;
     }
     case TYPENAME_TYPE:
-      if (!IMPLICIT_TYPENAME_P (t))
-        output_add_string (scratch_buffer, "typename ");
+      dump_qualifiers (t, after);
+      output_add_string (scratch_buffer, "typename ");
       dump_typename (t, flags);
       break;
 
@@ -472,12 +452,12 @@ dump_type (t, flags)
     case TYPEOF_TYPE:
       output_add_string (scratch_buffer, "__typeof (");
       dump_expr (TYPE_FIELDS (t), flags & ~TFF_EXPR_IN_PARENS);
-      print_left_paren (scratch_buffer);
+      print_right_paren (scratch_buffer);
       break;
 
     default:
       sorry_for_unsupported_tree (t);
-      /* Fall through to error. */
+      /* Fall through to error.  */
 
     case ERROR_MARK:
       print_identifier (scratch_buffer, "<type error>");
@@ -489,9 +469,7 @@ dump_type (t, flags)
    a TYPENAME_TYPE.  */
 
 static void
-dump_typename (t, flags)
-     tree t;
-     int flags;
+dump_typename (tree t, int flags)
 {
   tree ctx = TYPE_CONTEXT (t);
 
@@ -506,8 +484,7 @@ dump_typename (t, flags)
 /* Return the name of the supplied aggregate, or enumeral type.  */
 
 static const char *
-class_key_or_enum (t)
-     tree t;
+class_key_or_enum (tree t)
 {
   if (TREE_CODE (t) == ENUMERAL_TYPE)
     return "enum";
@@ -523,9 +500,7 @@ class_key_or_enum (t)
    in the form `class foo'.  */
 
 static void
-dump_aggr_type (t, flags)
-     tree t;
-     int flags;
+dump_aggr_type (tree t, int flags)
 {
   tree name;
   const char *variety = class_key_or_enum (t);
@@ -598,9 +573,7 @@ dump_aggr_type (t, flags)
    want to pad non-*, non-& cores, but not pad * or & types.  */
 
 static enum pad
-dump_type_prefix (t, flags)
-     tree t;
-     int flags;
+dump_type_prefix (tree t, int flags)
 {
   enum pad padding = before;
 
@@ -690,6 +663,7 @@ dump_type_prefix (t, flags)
     case TYPENAME_TYPE:
     case COMPLEX_TYPE:
     case VECTOR_TYPE:
+    case TYPEOF_TYPE:
       dump_type (t, flags);
       padding = before;
       break;
@@ -708,9 +682,7 @@ dump_type_prefix (t, flags)
    which appears after the identifier (or function parms).  */
 
 static void
-dump_type_suffix (t, flags)
-     tree t;
-     int flags;
+dump_type_suffix (tree t, int flags)
 {
   if (TYPE_PTRMEMFUNC_P (t))
     t = TYPE_PTRMEMFUNC_FN_TYPE (t);
@@ -786,6 +758,7 @@ dump_type_suffix (t, flags)
     case TYPENAME_TYPE:
     case COMPLEX_TYPE:
     case VECTOR_TYPE:
+    case TYPEOF_TYPE:
       break;
 
     default:
@@ -798,8 +771,7 @@ dump_type_suffix (t, flags)
 }
 
 static void
-dump_global_iord (t)
-     tree t;
+dump_global_iord (tree t)
 {
   const char *p = NULL;
 
@@ -814,10 +786,7 @@ dump_global_iord (t)
 }
 
 static void
-dump_simple_decl (t, type, flags)
-     tree t;
-     tree type;
-     int flags;
+dump_simple_decl (tree t, tree type, int flags)
 {
   if (flags & TFF_DECL_SPECIFIERS)
     {
@@ -837,9 +806,7 @@ dump_simple_decl (t, type, flags)
 /* Dump a human readable string for the decl T under control of FLAGS.  */
 
 static void
-dump_decl (t, flags)
-     tree t;
-     int flags;
+dump_decl (tree t, int flags)
 {
   if (t == NULL_TREE)
     return;
@@ -853,7 +820,7 @@ dump_decl (t, flags)
          {
            if ((flags & TFF_DECL_SPECIFIERS)
                && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
-             /* Say `class T' not just `T'. */
+             /* Say `class T' not just `T'.  */
              output_add_string (scratch_buffer, "class ");
 
            dump_type (TREE_TYPE (t), flags);
@@ -933,6 +900,25 @@ dump_decl (t, flags)
       break;
 
     case OVERLOAD:
+      if (OVL_CHAIN (t))
+       {
+         t = OVL_CURRENT (t);
+         if (DECL_CLASS_SCOPE_P (t))
+           {
+             dump_type (DECL_CONTEXT (t), flags);
+             output_add_string (scratch_buffer, "::");
+           }
+         else if (DECL_CONTEXT (t))
+           {
+             dump_decl (DECL_CONTEXT (t), flags);
+             output_add_string (scratch_buffer, "::");
+           }
+         dump_decl (DECL_NAME (t), flags);
+         break;
+       }
+      
+      /* If there's only one function, just treat it like an ordinary
+        FUNCTION_DECL.  */
       t = OVL_CURRENT (t);
       /* Fall through.  */
 
@@ -985,7 +971,7 @@ dump_decl (t, flags)
       else if (DECL_INITIAL (t))
        dump_expr (DECL_INITIAL (t), flags | TFF_EXPR_IN_PARENS);
       else
-       print_identifier (scratch_buffer, "enumerator");
+       print_identifier (scratch_buffer, "<enumerator>");
       break;
 
     case USING_DECL:
@@ -995,6 +981,10 @@ dump_decl (t, flags)
       print_tree_identifier (scratch_buffer, DECL_NAME (t));
       break;
 
+    case BASELINK:
+      dump_decl (BASELINK_FUNCTIONS (t), flags);
+      break;
+
     default:
       sorry_for_unsupported_tree (t);
       /* Fallthrough to error.  */
@@ -1009,9 +999,7 @@ dump_decl (t, flags)
    'template <...> leaders plus the 'class X' or 'void fn(...)' part.  */
 
 static void
-dump_template_decl (t, flags)
-     tree t;
-     int flags;
+dump_template_decl (tree t, int flags)
 {
   tree orig_parms = DECL_TEMPLATE_PARMS (t);
   tree parms;
@@ -1044,7 +1032,7 @@ dump_template_decl (t, flags)
       nreverse(orig_parms);
 
       if (DECL_TEMPLATE_TEMPLATE_PARM_P (t))
-       /* Say `template<arg> class TT' not just `template<arg> TT'. */
+       /* Say `template<arg> class TT' not just `template<arg> TT'.  */
        output_add_string (scratch_buffer, "class ");
     }
 
@@ -1064,7 +1052,7 @@ dump_template_decl (t, flags)
         dump_function_decl (t, flags | TFF_TEMPLATE_NAME);
         break;
       default:
-        /* This case can occur with some illegal code.  */
+        /* This case can occur with some invalid code.  */
         dump_type (TREE_TYPE (t),
                    (flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
                    | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0));
@@ -1074,12 +1062,10 @@ dump_template_decl (t, flags)
 /* Pretty print a function decl. There are several ways we want to print a
    function declaration. The TFF_ bits in FLAGS tells us how to behave.
    As error can only apply the '#' flag once to give 0 and 1 for V, there
-   is %D which doesn't print the throw specs, and %F which does. */
+   is %D which doesn't print the throw specs, and %F which does.  */
 
 static void
-dump_function_decl (t, flags)
-     tree t;
-     int flags;
+dump_function_decl (tree t, int flags)
 {
   tree fntype;
   tree parmtypes;
@@ -1168,12 +1154,10 @@ dump_function_decl (t, flags)
 
 /* Print a parameter list. If this is for a member function, the
    member object ptr (and any other hidden args) should have
-   already been removed. */
+   already been removed.  */
 
 static void
-dump_parameters (parmtypes, flags)
-     tree parmtypes;
-     int flags;
+dump_parameters (tree parmtypes, int flags)
 {
   int first;
 
@@ -1202,12 +1186,10 @@ dump_parameters (parmtypes, flags)
   print_right_paren (scratch_buffer);
 }
 
-/* Print an exception specification. T is the exception specification. */
+/* Print an exception specification. T is the exception specification.  */
 
 static void
-dump_exception_spec (t, flags)
-     tree t;
-     int flags;
+dump_exception_spec (tree t, int flags)
 {
   if (t)
     {
@@ -1229,12 +1211,13 @@ dump_exception_spec (t, flags)
    and destructors properly.  */
 
 static void
-dump_function_name (t, flags)
-     tree t;
-     int flags;
+dump_function_name (tree t, int flags)
 {
   tree name = DECL_NAME (t);
 
+  if (TREE_CODE (t) == TEMPLATE_DECL)
+    t = DECL_TEMPLATE_RESULT (t);
+
   /* Don't let the user see __comp_ctor et al.  */
   if (DECL_CONSTRUCTOR_P (t)
       || DECL_DESTRUCTOR_P (t))
@@ -1277,10 +1260,7 @@ dump_function_name (t, flags)
    decoration.  */
 
 static void
-dump_template_parms (info, primary, flags)
-     tree info;
-     int primary;
-     int flags;
+dump_template_parms (tree info, int primary, int flags)
 {
   tree args = info ? TI_ARGS (info) : NULL_TREE;
 
@@ -1353,8 +1333,7 @@ dump_template_parms (info, primary, flags)
 }
 
 static void
-dump_char (c)
-     int c;
+dump_char (int c)
 {
   switch (c)
     {
@@ -1402,9 +1381,7 @@ dump_char (c)
 /* Print out a list of initializers (subr of dump_expr) */
 
 static void
-dump_expr_list (l, flags)
-     tree l;
-     int flags;
+dump_expr_list (tree l, int flags)
 {
   while (l)
     {
@@ -1415,13 +1392,14 @@ dump_expr_list (l, flags)
     }
 }
 
-/* Print out an expression E under control of FLAGS. */
+/* Print out an expression E under control of FLAGS.  */
 
 static void
-dump_expr (t, flags)
-     tree t;
-     int flags;
+dump_expr (tree t, int flags)
 {
+  if (t == 0)
+    return;
+  
   switch (TREE_CODE (t))
     {
     case VAR_DECL:
@@ -1432,6 +1410,7 @@ dump_expr (t, flags)
     case TEMPLATE_DECL:
     case NAMESPACE_DECL:
     case OVERLOAD:
+    case IDENTIFIER_NODE:
       dump_decl (t, flags & ~TFF_DECL_SPECIFIERS);
       break;
 
@@ -1471,7 +1450,11 @@ dump_expr (t, flags)
        else if (type == char_type_node)
          {
            output_add_character (scratch_buffer, '\'');
-           dump_char (tree_low_cst (t, 0));
+           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, '\'');
          }
        else
@@ -1491,9 +1474,9 @@ dump_expr (t, flags)
                /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
                   systems?  */
                {
-                 static char format[10]; /* "%x%09999x\0" */
+                 static char format[12]; /* "0x%x%09999x\0" */
                  if (!format[0])
-                   sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
+                   sprintf (format, "0x%%x%%0%dx", HOST_BITS_PER_INT / 4);
                  sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
                           TREE_INT_CST_LOW (val));
                  output_add_string (scratch_buffer, digit_buffer);
@@ -1506,13 +1489,8 @@ dump_expr (t, flags)
       break;
 
     case REAL_CST:
-      {
-       const unsigned char *p = (const unsigned char *) &TREE_REAL_CST (t);
-       size_t i;
-       strcpy (digit_buffer, "0x");
-       for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
-         sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
-      }
+      real_to_decimal (digit_buffer, &TREE_REAL_CST (t),
+                      sizeof (digit_buffer), 0, 1);
       output_add_string (scratch_buffer, digit_buffer);
       break;
 
@@ -1828,7 +1806,7 @@ dump_expr (t, flags)
     case CONSTRUCTOR:
       if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
        {
-         tree idx = build_component_ref (t, pfn_identifier, NULL_TREE, 0);
+         tree idx = build_ptrmemfunc_access_expr (t, pfn_identifier);
 
          if (integer_zerop (idx))
            {
@@ -1866,9 +1844,19 @@ dump_expr (t, flags)
                }
            }
        }
-      output_add_character (scratch_buffer, '{');
-      dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
-      output_add_character (scratch_buffer, '}');
+      if (TREE_TYPE (t) && !CONSTRUCTOR_ELTS (t))
+       {
+         dump_type (TREE_TYPE (t), 0);
+         output_add_character (scratch_buffer, '(');
+         output_add_character (scratch_buffer, ')');
+       }
+      else
+       {
+         output_add_character (scratch_buffer, '{');
+         dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
+         output_add_character (scratch_buffer, '}');
+       }
+      
       break;
 
     case OFFSET_REF:
@@ -1881,7 +1869,8 @@ dump_expr (t, flags)
              /* A::f */
              dump_expr (t, flags | TFF_EXPR_IN_PARENS);
            else if (BASELINK_P (t))
-             dump_expr (OVL_CURRENT (TREE_VALUE (t)), flags | TFF_EXPR_IN_PARENS);
+             dump_expr (OVL_CURRENT (BASELINK_FUNCTIONS (t)), 
+                        flags | TFF_EXPR_IN_PARENS);
            else
              dump_decl (t, flags);
          }
@@ -1906,10 +1895,6 @@ dump_expr (t, flags)
       dump_decl (TEMPLATE_PARM_DECL (t), flags & ~TFF_DECL_SPECIFIERS);
       break;
 
-    case IDENTIFIER_NODE:
-      print_tree_identifier (scratch_buffer, t);
-      break;
-
     case SCOPE_REF:
       dump_type (TREE_OPERAND (t, 0), flags);
       print_scope_operator (scratch_buffer);
@@ -2024,12 +2009,10 @@ dump_expr (t, flags)
       output_add_string (scratch_buffer, ") break; ");
       break;
 
-    case TREE_LIST:
-      if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
-       {
-         print_tree_identifier (scratch_buffer, DECL_NAME (TREE_VALUE (t)));
-         break;
-       }
+    case BASELINK:
+      dump_expr (get_first_fn (t), flags & ~TFF_EXPR_IN_PARENS);
+      break;
+
       /* else fall through */
 
       /*  This list is incomplete, but should suffice for now.
@@ -2045,10 +2028,7 @@ dump_expr (t, flags)
 }
 
 static void
-dump_binary_op (opstring, t, flags)
-     const char *opstring;
-     tree t;
-     int flags;
+dump_binary_op (const char *opstring, tree t, int flags)
 {
   print_left_paren (scratch_buffer);
   dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
@@ -2063,10 +2043,7 @@ dump_binary_op (opstring, t, flags)
 }
 
 static void
-dump_unary_op (opstring, t, flags)
-     const char *opstring;
-     tree t;
-     int flags;
+dump_unary_op (const char *opstring, tree t, int flags)
 {
   if (flags & TFF_EXPR_IN_PARENS)
     print_left_paren (scratch_buffer);
@@ -2080,9 +2057,7 @@ dump_unary_op (opstring, t, flags)
    control.  */
 
 const char *
-type_as_string (typ, flags)
-     tree typ;
-     int flags;
+type_as_string (tree typ, int flags)
 {
   reinit_global_formatting_buffer ();
 
@@ -2092,9 +2067,7 @@ type_as_string (typ, flags)
 }
 
 const char *
-expr_as_string (decl, flags)
-     tree decl;
-     int flags;
+expr_as_string (tree decl, int flags)
 {
   reinit_global_formatting_buffer ();
 
@@ -2104,9 +2077,7 @@ expr_as_string (decl, flags)
 }
 
 const char *
-decl_as_string (decl, flags)
-     tree decl;
-     int flags;
+decl_as_string (tree decl, int flags)
 {
   reinit_global_formatting_buffer ();
 
@@ -2116,9 +2087,7 @@ decl_as_string (decl, flags)
 }
 
 const char *
-context_as_string (context, flags)
-     tree context;
-     int flags;
+context_as_string (tree context, int flags)
 {
   reinit_global_formatting_buffer ();
 
@@ -2130,9 +2099,7 @@ context_as_string (context, flags)
 /* Generate the three forms of printable names for cxx_printable_name.  */
 
 const char *
-lang_decl_name (decl, v)
-     tree decl;
-     int v;
+lang_decl_name (tree decl, int v)
 {
   if (v >= 2)
     return decl_as_string (decl, TFF_DECL_SPECIFIERS);
@@ -2154,8 +2121,7 @@ lang_decl_name (decl, v)
 }
 
 const char *
-cp_file_of (t)
-     tree t;
+cp_file_of (tree t)
 {
   if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
     return DECL_SOURCE_FILE (DECL_CONTEXT (t));
@@ -2168,8 +2134,7 @@ cp_file_of (t)
 }
 
 int
-cp_line_of (t)
-     tree t;
+cp_line_of (tree t)
 {
   int line = 0;
   if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
@@ -2196,9 +2161,7 @@ cp_line_of (t)
    function.  */
 
 static const char *
-decl_to_string (decl, verbose)
-     tree decl;
-     int verbose;
+decl_to_string (tree decl, int verbose)
 {
   int flags = 0;
 
@@ -2219,9 +2182,7 @@ decl_to_string (decl, verbose)
 }
 
 static const char *
-expr_to_string (decl, verbose)
-     tree decl;
-     int verbose ATTRIBUTE_UNUSED;
+expr_to_string (tree decl, int verbose ATTRIBUTE_UNUSED)
 {
   reinit_global_formatting_buffer ();
 
@@ -2231,9 +2192,7 @@ expr_to_string (decl, verbose)
 }
 
 static const char *
-fndecl_to_string (fndecl, verbose)
-     tree fndecl;
-     int verbose;
+fndecl_to_string (tree fndecl, int verbose)
 {
   int flags;
 
@@ -2249,17 +2208,13 @@ fndecl_to_string (fndecl, verbose)
 
 
 static const char *
-code_to_string (c, v)
-     enum tree_code c;
-     int v ATTRIBUTE_UNUSED;
+code_to_string (enum tree_code c, int v ATTRIBUTE_UNUSED)
 {
   return tree_code_name [c];
 }
 
 const char *
-language_to_string (c, v)
-     enum languages c;
-     int v ATTRIBUTE_UNUSED;
+language_to_string (enum languages c, int v ATTRIBUTE_UNUSED)
 {
   switch (c)
     {
@@ -2281,9 +2236,7 @@ language_to_string (c, v)
 /* Return the proper printed version of a parameter to a C++ function.  */
 
 static const char *
-parm_to_string (p, v)
-     int p;
-     int v ATTRIBUTE_UNUSED;
+parm_to_string (int p, int v ATTRIBUTE_UNUSED)
 {
   if (p < 0)
     return "`this'";
@@ -2293,9 +2246,7 @@ parm_to_string (p, v)
 }
 
 static const char *
-op_to_string (p, v)
-     enum tree_code p;
-     int v ATTRIBUTE_UNUSED;
+op_to_string (enum tree_code p, int v ATTRIBUTE_UNUSED)
 {
   tree id;
 
@@ -2304,9 +2255,7 @@ op_to_string (p, v)
 }
 
 static const char *
-type_to_string (typ, verbose)
-     tree typ;
-     int verbose;
+type_to_string (tree typ, int verbose)
 {
   int flags;
 
@@ -2323,9 +2272,7 @@ type_to_string (typ, verbose)
 }
 
 static const char *
-assop_to_string (p, v)
-     enum tree_code p;
-     int v ATTRIBUTE_UNUSED;
+assop_to_string (enum tree_code p, int v ATTRIBUTE_UNUSED)
 {
   tree id;
 
@@ -2334,9 +2281,7 @@ assop_to_string (p, v)
 }
 
 static const char *
-args_to_string (p, verbose)
-     tree p;
-     int verbose;
+args_to_string (tree p, int verbose)
 {
   int flags = 0;
   if (verbose)
@@ -2362,9 +2307,7 @@ args_to_string (p, verbose)
 }
 
 static const char *
-cv_to_string (p, v)
-     tree p;
-     int v;
+cv_to_string (tree p, int v)
 {
   reinit_global_formatting_buffer ();
 
@@ -2375,76 +2318,62 @@ cv_to_string (p, v)
 
 /* Langhook for print_error_function.  */
 void
-cxx_print_error_function (context, file)
-     diagnostic_context *context;
-     const char *file;
+cxx_print_error_function (diagnostic_context *context, const char *file)
 {
-  output_state os;
-
   lhd_print_error_function (context, file);
-  os = output_buffer_state (context);
-  output_set_prefix ((output_buffer *)context, file);
-  maybe_print_instantiation_context ((output_buffer *)context);
-  output_buffer_state (context) = os;
+  output_set_prefix (&context->buffer, file);
+  maybe_print_instantiation_context (context);
 }
 
 static void
-cp_diagnostic_starter (buffer, dc)
-     output_buffer *buffer;
-     diagnostic_context *dc;
+cp_diagnostic_starter (diagnostic_context *context,
+                       diagnostic_info *diagnostic)
 {
-  report_problematic_module (buffer);
-  cp_print_error_function (buffer, dc);
-  maybe_print_instantiation_context (buffer);
-  output_set_prefix (buffer,
-                     context_as_prefix (diagnostic_file_location (dc),
-                                        diagnostic_line_location (dc),
-                                        diagnostic_is_warning (dc)));
+  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));
 }
 
 static void
-cp_diagnostic_finalizer (buffer, dc)
-     output_buffer *buffer;
-     diagnostic_context *dc __attribute__ ((__unused__));
+cp_diagnostic_finalizer (diagnostic_context *context,
+                         diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
 {
-  output_destroy_prefix (buffer);
+  output_destroy_prefix (&context->buffer);
 }
 
 /* Print current function onto BUFFER, in the process of reporting
    a diagnostic message.  Called from cp_diagnostic_starter.  */
 static void
-cp_print_error_function (buffer, dc)
-     output_buffer *buffer;
-     diagnostic_context *dc;
+cp_print_error_function (diagnostic_context *context,
+                         diagnostic_info *diagnostic)
 {
-  if (error_function_changed ())
+  if (diagnostic_last_function_changed (context))
     {
-      char *prefix = diagnostic_file_location (dc)
-        ? file_name_as_prefix (diagnostic_file_location (dc))
+      const char *old_prefix = output_prefix (&context->buffer);
+      char *new_prefix = diagnostic->location.file
+        ? file_name_as_prefix (diagnostic->location.file)
         : NULL;
-      output_state os;
 
-      os = output_buffer_state (buffer);
-      output_set_prefix (buffer, prefix);
+      output_set_prefix (&context->buffer, new_prefix);
 
       if (current_function_decl == NULL)
-        output_add_string (buffer, "At global scope:");
+        output_add_string (&context->buffer, "At global scope:");
       else
-        output_printf
-          (buffer, "In %s `%s':", function_category (current_function_decl),
-           cxx_printable_name (current_function_decl, 2));
-      output_add_newline (buffer);
-
-      record_last_error_function ();
-      output_destroy_prefix (buffer);
-      output_buffer_state (buffer) = os;
+        output_printf (&context->buffer, "In %s `%s':",
+                       function_category (current_function_decl),
+                       cxx_printable_name (current_function_decl, 2));
+      output_add_newline (&context->buffer);
+
+      diagnostic_set_last_function (context);
+      output_destroy_prefix (&context->buffer);
+      context->buffer.state.prefix = old_prefix;
     }
 }
 
 /* Returns a description of FUNCTION using standard terminology.  */
 static const char *
-function_category (fn)
-     tree fn;
+function_category (tree fn)
 {
   if (DECL_FUNCTION_MEMBER_P (fn))
     {
@@ -2466,8 +2395,7 @@ function_category (fn)
 /* Report the full context of a current template instantiation,
    onto BUFFER.  */
 static void
-print_instantiation_full_context (buffer)
-     output_buffer *buffer;
+print_instantiation_full_context (diagnostic_context *context)
 {
   tree p = current_instantiation ();
   int line = lineno;
@@ -2486,7 +2414,8 @@ print_instantiation_full_context (buffer)
          if (current_function_decl == TINST_DECL (p))
            /* Avoid redundancy with the the "In function" line.  */;
          else
-           output_verbatim (buffer, "%s: In instantiation of `%s':\n", file,
+           output_verbatim (&context->buffer,
+                             "%s: In instantiation of `%s':\n", file,
                              decl_as_string (TINST_DECL (p),
                                              TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
 
@@ -2496,47 +2425,43 @@ print_instantiation_full_context (buffer)
        }
     }
 
-  print_instantiation_partial_context (buffer, p, file, line);
+  print_instantiation_partial_context (context, p, file, line);
 }
 
 /* Same as above but less verbose.  */
 static void
-print_instantiation_partial_context (buffer, t, file, line)
-     output_buffer *buffer;
-     tree t;
-     const char *file;
-     int line;
+print_instantiation_partial_context (diagnostic_context *context,
+                                     tree t, const char *file, int line)
 {
   for (; t; t = TREE_CHAIN (t))
     {
       output_verbatim
-        (buffer, "%s:%d:   instantiated from `%s'\n", file, line,
+        (&context->buffer, "%s:%d:   instantiated from `%s'\n", file, line,
          decl_as_string (TINST_DECL (t), TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
       line = TINST_LINE (t);
       file = TINST_FILE (t);
     }
-  output_verbatim (buffer, "%s:%d:   instantiated from here\n", file, line);
+  output_verbatim (&context->buffer, "%s:%d:   instantiated from here\n", file, line);
 }
 
 /* Called from cp_thing to print the template context for an error.  */
 static void
-maybe_print_instantiation_context (buffer)
-     output_buffer *buffer;
+maybe_print_instantiation_context (diagnostic_context *context)
 {
   if (!problematic_instantiation_changed () || current_instantiation () == 0)
     return;
 
   record_last_problematic_instantiation ();
-  print_instantiation_full_context (buffer);
+  print_instantiation_full_context (context);
 }
 
 /* Report the bare minimum context of a template instantiation.  */
 void
-print_instantiation_context ()
+print_instantiation_context (void)
 {
   print_instantiation_partial_context
-    (diagnostic_buffer, current_instantiation (), input_filename, lineno);
-  flush_diagnostic_buffer ();
+    (global_dc, current_instantiation (), input_filename, lineno);
+  diagnostic_flush_buffer (global_dc);
 }
 \f
 /* Called from output_format -- during diagnostic message processing --
@@ -2552,26 +2477,25 @@ print_instantiation_context ()
    %Q  assignment operator.
    %T   type.
    %V   cv-qualifier.  */
-static int
-cp_printer (buffer)
-     output_buffer *buffer;
+static bool
+cp_printer (output_buffer *buffer, text_info *text)
 {
   int verbose = 0;
   const char *result;
-#define next_tree    va_arg (output_buffer_format_args (buffer), tree)
-#define next_tcode   va_arg (output_buffer_format_args (buffer), enum tree_code)
-#define next_lang    va_arg (output_buffer_format_args (buffer), enum languages)
-#define next_int     va_arg (output_buffer_format_args (buffer), int)
-
-  if (*output_buffer_text_cursor (buffer) == '+')
-    ++output_buffer_text_cursor (buffer);
-  if (*output_buffer_text_cursor (buffer) == '#')
+#define next_tree    va_arg (*text->args_ptr, tree)
+#define next_tcode   va_arg (*text->args_ptr, enum tree_code)
+#define next_lang    va_arg (*text->args_ptr, enum languages)
+#define next_int     va_arg (*text->args_ptr, int)
+
+  if (*text->format_spec == '+')
+    ++text->format_spec;
+  if (*text->format_spec == '#')
     {
       verbose = 1;
-      ++output_buffer_text_cursor (buffer);
+      ++text->format_spec;
     }
 
-  switch (*output_buffer_text_cursor (buffer))
+  switch (*text->format_spec)
     {
     case 'A': result = args_to_string (next_tree, verbose);    break;
     case 'C': result = code_to_string (next_tcode, verbose);   break;
@@ -2586,11 +2510,11 @@ cp_printer (buffer)
     case 'V': result = cv_to_string (next_tree, verbose);      break;
  
     default:
-      return 0;
+      return false;
     }
 
   output_add_string (buffer, result);
-  return 1;
+  return true;
 #undef next_tree
 #undef next_tcode
 #undef next_lang
@@ -2598,18 +2522,14 @@ cp_printer (buffer)
 }
 
 static void
-print_integer (buffer, i)
-     output_buffer *buffer;
-     HOST_WIDE_INT i;
+print_integer (output_buffer *buffer, HOST_WIDE_INT i)
 {
   sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) i);
   output_add_string (buffer, digit_buffer);
 }
 
 static void
-print_non_consecutive_character (buffer, c)
-     output_buffer *buffer;
-     int c;
+print_non_consecutive_character (output_buffer *buffer, int c)
 {
   const char *p = output_last_position (buffer);
 
@@ -2622,9 +2542,7 @@ print_non_consecutive_character (buffer, c)
    behavior of cp_*_at.  */
 
 static tree
-locate_error (msgid, ap)
-     const char *msgid;
-     va_list ap;
+locate_error (const char *msgid, va_list ap)
 {
   tree here = 0, t;
   int plus = 0;
@@ -2684,7 +2602,7 @@ void
 cp_error_at VPARAMS ((const char *msgid, ...))
 {
   tree here;
-  diagnostic_context dc;
+  diagnostic_info diagnostic;
 
   VA_OPEN (ap, msgid);
   VA_FIXEDARG (ap, const char *, msgid);
@@ -2694,10 +2612,9 @@ cp_error_at VPARAMS ((const char *msgid, ...))
   VA_OPEN (ap, msgid);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  set_diagnostic_context (&dc, msgid, &ap,
-                         cp_file_of (here),
-                         cp_line_of (here), /* warning = */ 0);
-  report_diagnostic (&dc);
+  diagnostic_set_info (&diagnostic, msgid, &ap,
+                       cp_file_of (here), cp_line_of (here), DK_ERROR);
+  report_diagnostic (&diagnostic);
   VA_CLOSE (ap);
 }
 
@@ -2705,7 +2622,7 @@ void
 cp_warning_at VPARAMS ((const char *msgid, ...))
 {
   tree here;
-  diagnostic_context dc;
+  diagnostic_info diagnostic;
 
   VA_OPEN (ap, msgid);
   VA_FIXEDARG (ap, const char *, msgid);
@@ -2715,10 +2632,9 @@ cp_warning_at VPARAMS ((const char *msgid, ...))
   VA_OPEN (ap, msgid);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  set_diagnostic_context (&dc, msgid, &ap,
-                         cp_file_of (here),
-                         cp_line_of (here), /* warning = */ 1);
-  report_diagnostic (&dc);
+  diagnostic_set_info (&diagnostic, msgid, &ap,
+                       cp_file_of (here), cp_line_of (here), DK_WARNING);
+  report_diagnostic (&diagnostic);
   VA_CLOSE (ap);
 }
 
@@ -2726,7 +2642,7 @@ void
 cp_pedwarn_at VPARAMS ((const char *msgid, ...))
 {
   tree here;
-  diagnostic_context dc;
+  diagnostic_info diagnostic;
 
   VA_OPEN (ap, msgid);
   VA_FIXEDARG (ap, const char *, msgid);
@@ -2736,10 +2652,9 @@ cp_pedwarn_at VPARAMS ((const char *msgid, ...))
   VA_OPEN (ap, msgid);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  set_diagnostic_context (&dc, msgid, &ap,
-                         cp_file_of (here),
-                         cp_line_of (here),
-                         /* warning = */ !flag_pedantic_errors);
-  report_diagnostic (&dc);
+  diagnostic_set_info (&diagnostic, msgid, &ap,
+                       cp_file_of (here), cp_line_of (here),
+                       pedantic_error_kind());
+  report_diagnostic (&diagnostic);
   VA_CLOSE (ap);
 }