OSDN Git Service

a847df490efa46fe8d7941c07fc14a3d777e4320
[pf3gnuchains/gcc-fork.git] / gcc / cp / error.c
1 /* Call-backs for C++ error reporting.
2    This code is non-reentrant.
3    Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
4    Free Software Foundation, Inc.
5    This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "tree.h"
25 #include "cp-tree.h"
26 #include "obstack.h"
27 #include "toplev.h"
28 #include "diagnostic.h"
29
30 enum pad { none, before, after };
31
32 /* These constants can used as bit flags in the process of tree formatting.
33
34    TFF_PLAIN_IDENTIFER: unqualified part of a name.
35    TFF_NAMESPACE_SCOPE: the complete qualified-id form of a name.
36    TFF_CLASS_SCOPE: if possible, include the class-name part of a
37         qualified-id.  This flag may be implied in some circumstances by
38         TFF_NAMESPACE_SCOPE.
39    TFF_SCOPE: the combinaison of the two above.
40    TFF_CHASE_TYPDEF: print the original type-id instead of the typedef-name.
41    TFF_DECL_SPECIFIERS: print decl-specifiers.
42    TFF_CLASS_KEY_OR_ENUM: precede a class-type name (resp. enum name) with
43        a class-key (resp. `enum').
44    TFF_RETURN_TYPE: include function return type.
45    TFF_FUNCTION_DEFAULT_ARGUMENTS: include function default parameter values.
46    TFF_EXCEPTION_SPECIFICATION: show function exception specification.
47    TFF_TEMPLATE_HEADER: show the template<...> hearder in a
48        template-declaration.
49    TFF_TEMPLATE_DEFAULT_ARGUMENTS: show template paramter default values.  */
50
51 #define TFF_PLAIN_IDENTIFIER               (0)
52 #define TFF_NAMESPACE_SCOPE                (1)
53 #define TFF_CLASS_SCOPE                    (1 << 1)
54 #define TFF_CHASE_NAMESPACE_ALIAS          (1 << 2)
55 #define TFF_CHASE_TYPEDEF                  (1 << 3)
56 #define TFF_DECL_SPECIFIERS                (1 << 4)
57 #define TFF_CLASS_KEY_OR_ENUM              (1 << 5)
58 #define TFF_RETURN_TYPE                    (1 << 6)
59 #define TFF_FUNCTION_DEFAULT_ARGUMENTS     (1 << 7)
60 #define TFF_EXCEPTION_SPECIFICATION        (1 << 8)
61 #define TFF_TEMPLATE_HEADER                (1 << 9)
62 #define TFF_TEMPLATE_DEFAULT_ARGUMENTS     (1 << 10)
63 #define TFF_SCOPE (TFF_NAMESPACE_SCOPE | TFF_CLASS_SCOPE)
64
65 /* This data structure bundles altogether, all the information necessary
66    for pretty-printing a C++ source-level entity represented by a tree.  */
67 typedef struct
68 {
69   tree decl;
70   int flags;
71   enum pad pad;
72 } tree_formatting_info, *tfi_t;
73
74 #define tree_being_formatted(TFI) (TFI)->decl
75 #define tree_formatting_flags(TFI) (TFI)->flags
76 #define put_whitespace(TFI) (TFI)->pad
77
78 #define sorry_for_unsupported_tree(T)                                      \
79    sorry ("`%s' not supported by %s", tree_code_name[(int) TREE_CODE (T)], \
80              __FUNCTION__)
81
82 #define print_scope_operator(BUFFER)  output_add_string (BUFFER, "::")
83 #define print_left_paren(BUFFER)      output_add_character (BUFFER, '(')
84 #define print_right_paren(BUFFER)     output_add_character (BUFFER, ')')
85 #define print_left_bracket(BUFFER)    output_add_character (BUFFER, '[')
86 #define print_right_bracket(BUFFER)   output_add_character (BUFFER, ']')
87 #define print_whitespace(BUFFER, TFI)        \
88    do {                                      \
89      output_add_space (BUFFER);              \
90      put_whitespace (TFI) = none;            \
91    } while (0)
92
93 #define obstack_chunk_alloc xmalloc
94 #define obstack_chunk_free free
95
96 #define print_tree_identifier(BUFFER, TID) \
97    output_add_string (BUFFER, IDENTIFIER_POINTER (TID))
98 #define print_identifier(BUFFER, ID) output_add_string (BUFFER, ID)
99
100 /* Obstack where we build text strings for overloading, etc.  */
101 static struct obstack scratch_obstack;
102 static char *scratch_firstobj;
103
104 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
105 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
106 # define OB_PUTC2(C1,C2)        \
107   (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
108 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
109 # define OB_PUTID(ID)  \
110   (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID),     \
111                  IDENTIFIER_LENGTH (ID)))
112 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
113 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
114 # define OB_PUTI(CST) do { sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(CST)); \
115                            OB_PUTCP (digit_buffer); } while (0)
116
117 # define OB_END_TEMPLATE_ID()                                               \
118   (((obstack_next_free (&scratch_obstack) != obstack_base (&scratch_obstack) \
119     && obstack_next_free (&scratch_obstack)[-1] == '>')                     \
120    ? OB_PUTC (' ') : (void)0), OB_PUTC ('>'))
121
122 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
123
124 static const char *args_to_string               PARAMS ((tree, int));
125 static const char *assop_to_string              PARAMS ((enum tree_code, int));
126 static const char *code_to_string               PARAMS ((enum tree_code, int));
127 static const char *cv_to_string                 PARAMS ((tree, int));
128 static const char *decl_to_string               PARAMS ((tree, int));
129 static const char *expr_to_string               PARAMS ((tree, int));
130 static const char *fndecl_to_string             PARAMS ((tree, int));
131 static const char *op_to_string                 PARAMS ((enum tree_code, int));
132 static const char *parm_to_string               PARAMS ((int, int));
133 static const char *type_to_string               PARAMS ((tree, int));
134
135 static void dump_type PARAMS ((tree, enum tree_string_flags));
136 static void dump_typename PARAMS ((tree, enum tree_string_flags));
137 static void dump_simple_decl PARAMS ((tree, tree, enum tree_string_flags));
138 static void dump_decl PARAMS ((tree, enum tree_string_flags));
139 static void dump_template_decl PARAMS ((tree, enum tree_string_flags));
140 static void dump_function_decl PARAMS ((tree, enum tree_string_flags));
141 static void dump_expr PARAMS ((tree, enum tree_string_flags));
142 static void dump_unary_op PARAMS ((const char *, tree, enum tree_string_flags));
143 static void dump_binary_op PARAMS ((const char *, tree, enum tree_string_flags));
144 static void dump_aggr_type PARAMS ((tree, enum tree_string_flags));
145 static enum pad dump_type_prefix PARAMS ((tree, enum tree_string_flags));
146 static void dump_type_suffix PARAMS ((tree, enum tree_string_flags));
147 static void dump_function_name PARAMS ((tree, enum tree_string_flags));
148 static void dump_expr_list PARAMS ((tree, enum tree_string_flags));
149 static void dump_global_iord PARAMS ((tree));
150 static enum pad dump_qualifiers PARAMS ((tree, enum pad));
151 static void dump_char PARAMS ((int));
152 static void dump_parameters PARAMS ((tree, enum tree_string_flags));
153 static void dump_exception_spec PARAMS ((tree, enum tree_string_flags));
154 static const char *class_key_or_enum PARAMS ((tree));
155 static tree ident_fndecl PARAMS ((tree));
156 static void dump_template_argument PARAMS ((tree, enum tree_string_flags));
157 static void dump_template_argument_list PARAMS ((tree, enum tree_string_flags));
158 static void dump_template_parameter PARAMS ((tree, enum tree_string_flags));
159 static void dump_template_bindings PARAMS ((tree, tree));
160 static void dump_scope PARAMS ((tree, enum tree_string_flags));
161 static void dump_template_parms PARAMS ((tree, int, enum tree_string_flags));
162
163 static const char *function_category PARAMS ((tree));
164 static void lang_print_error_function PARAMS ((const char *));
165 static void maybe_print_instantiation_context PARAMS ((output_buffer *));
166 static void print_instantiation_full_context PARAMS ((output_buffer *));
167 static void print_instantiation_partial_context PARAMS ((output_buffer *, tree,
168                                                          const char *, int));
169 static void cp_diagnostic_starter PARAMS ((output_buffer *,
170                                            diagnostic_context *));
171 static void cp_diagnostic_finalizer PARAMS ((output_buffer *,
172                                              diagnostic_context *));
173 static void cp_print_error_function PARAMS ((output_buffer *,
174                                              diagnostic_context *));
175
176 static int cp_tree_printer PARAMS ((output_buffer *));
177 static void print_function_argument_list PARAMS ((output_buffer *, tfi_t));
178 static void print_declaration PARAMS ((output_buffer *, tfi_t));
179 static void print_expression PARAMS ((output_buffer *, tfi_t));
180 static void print_function_declaration PARAMS ((output_buffer *, tfi_t));
181 static void print_function_parameter PARAMS ((output_buffer *, int));
182 static void print_type_id PARAMS ((output_buffer *, tfi_t));
183 static void print_cv_qualifier_seq PARAMS ((output_buffer *, tfi_t));
184 static void print_type_specifier_seq PARAMS ((output_buffer *, tfi_t));
185 static void print_simple_type_specifier PARAMS ((output_buffer *, tfi_t));
186 static void print_elaborated_type_specifier PARAMS ((output_buffer *, tfi_t));
187 static void print_rest_of_abstract_declarator PARAMS ((output_buffer *,
188                                                        tfi_t));
189 static void print_parameter_declaration_clause PARAMS ((output_buffer *,
190                                                         tfi_t));
191 static void print_exception_specification PARAMS ((output_buffer *, tfi_t));
192 static void print_nested_name_specifier PARAMS ((output_buffer *, tfi_t));
193 static void print_template_id PARAMS ((output_buffer *, tfi_t));
194 static void print_template_argument_list_start PARAMS ((output_buffer *));
195 static void print_template_argument_list_end PARAMS ((output_buffer *));
196 static tree typedef_original_name PARAMS ((tree));
197
198 #define A args_to_string
199 #define C code_to_string
200 #define D decl_to_string
201 #define E expr_to_string
202 #define F fndecl_to_string
203 #define L language_to_string
204 #define O op_to_string
205 #define P parm_to_string
206 #define Q assop_to_string
207 #define T type_to_string
208 #define V cv_to_string
209
210 #define o (cp_printer *) 0
211 cp_printer * cp_printers[256] =
212 {
213 /*0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F */
214   o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x00 */
215   o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x10 */
216   o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x20 */
217   o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x30 */
218   o, A, o, C, D, E, F, o, o, o, o, o, L, o, o, O, /* 0x40 */
219   P, Q, o, o, T, o, V, o, o, o, o, o, o, o, o, o, /* 0x50 */
220   o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x60 */
221   o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x70 */
222 };
223 #undef C
224 #undef D
225 #undef E
226 #undef F
227 #undef L
228 #undef O
229 #undef P
230 #undef Q
231 #undef T
232 #undef V
233 #undef o
234
235 void
236 init_error ()
237 {
238   gcc_obstack_init (&scratch_obstack);
239   scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
240
241   print_error_function = lang_print_error_function;
242   lang_diagnostic_starter = cp_diagnostic_starter;
243   lang_diagnostic_finalizer = cp_diagnostic_finalizer;
244
245   lang_printer = cp_tree_printer;
246 }
247
248 /* Dump a scope, if deemed necessary.  */
249
250 static void
251 dump_scope (scope, flags)
252      tree scope;
253      enum tree_string_flags flags;
254 {
255   if (scope == NULL_TREE)
256     return;
257
258   if (TREE_CODE (scope) == NAMESPACE_DECL)
259     {
260       if (scope != global_namespace)
261         {
262           dump_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
263                              | TS_FUNC_NORETURN | TS_DECL_TYPE);
264           OB_PUTS ("::");
265         }
266       else if (flags & TS_PEDANTIC_NAME)
267         OB_PUTS ("::");
268     }
269   else if (AGGREGATE_TYPE_P (scope))
270     {
271       dump_type (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
272                            | TS_FUNC_NORETURN | TS_DECL_TYPE);
273       OB_PUTS ("::");
274     }
275   else if ((flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE))
276             && TREE_CODE (scope) == FUNCTION_DECL)
277     {
278       dump_function_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
279                            | TS_FUNC_NORETURN | TS_DECL_TYPE);
280       OB_PUTS ("::");
281     }
282 }
283
284 /* Dump type qualifiers, providing padding as requested. Return an
285    indication of whether we dumped something.  */
286
287 static enum pad
288 dump_qualifiers (t, p)
289      tree t;
290      enum pad p;
291 {
292   static const int masks[] =
293     {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
294   static const char *const names[] =
295     {"const", "volatile", "__restrict"};
296   int ix;
297   int quals = TYPE_QUALS (t);
298   int do_after = p == after;
299
300   if (quals)
301     {
302       for (ix = 0; ix != 3; ix++)
303         if (masks[ix] & quals)
304           {
305             if (p == before)
306               OB_PUTC (' ');
307             p = before;
308             OB_PUTCP (names[ix]);
309           }
310       if (do_after)
311         OB_PUTC (' ');
312     }
313   else
314     p = none;
315   return p;
316 }
317
318 /* This must be large enough to hold any printed integer or floating-point
319    value.  */
320 static char digit_buffer[128];
321
322 /* Dump the template ARGument under control of FLAGS.  */
323
324 static void
325 dump_template_argument (arg, flags)
326      tree arg;
327      enum tree_string_flags flags;
328 {
329   if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
330     dump_type (arg, flags & ~TS_AGGR_TAGS);
331   else
332     dump_expr (arg, (flags | TS_EXPR_PARENS) & ~TS_AGGR_TAGS);
333 }
334
335 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
336    of FLAGS.  */
337
338 static void
339 dump_template_argument_list (args, flags)
340      tree args;
341      enum tree_string_flags flags;
342 {
343   int n = TREE_VEC_LENGTH (args);
344   int need_comma = 0;
345   int i;
346
347   for (i = 0; i< n; ++i)
348     {
349       if (need_comma)
350         OB_PUTS (", ");
351       dump_template_argument (TREE_VEC_ELT (args, i), flags);
352       need_comma = 1;
353     }
354 }
355
356 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS.  */
357
358 static void
359 dump_template_parameter (parm, flags)
360      tree parm;
361      enum tree_string_flags flags;
362 {
363   tree p = TREE_VALUE (parm);
364   tree a = TREE_PURPOSE (parm);
365
366   if (TREE_CODE (p) == TYPE_DECL)
367     {
368       if (flags & TS_DECL_TYPE)
369         {
370           OB_PUTS ("class");
371           if (DECL_NAME (p))
372             {
373               OB_PUTC (' ');
374               OB_PUTID (DECL_NAME (p));
375             }
376         }
377       else if (DECL_NAME (p))
378         OB_PUTID (DECL_NAME (p));
379       else
380         OB_PUTS ("{template default argument error}");
381     }
382   else
383     dump_decl (p, flags | TS_DECL_TYPE);
384
385   if ((flags & TS_PARM_DEFAULTS) && a != NULL_TREE)
386     {
387       OB_PUTS (" = ");
388       if (TREE_CODE (a) == TYPE_DECL || TREE_CODE (a) == TEMPLATE_DECL)
389         dump_type (a, flags & ~TS_CHASE_TYPEDEFS);
390       else
391         dump_expr (a, flags | TS_EXPR_PARENS);
392     }
393 }
394
395 /* Dump, under control of FLAGS, a template-parameter-list binding.
396    PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
397    TREE_VEC.  */
398
399 static void
400 dump_template_bindings (parms, args)
401      tree parms, args;
402 {
403   int need_comma = 0;
404
405   while (parms)
406     {
407       tree p = TREE_VALUE (parms);
408       int lvl = TMPL_PARMS_DEPTH (parms);
409       int arg_idx = 0;
410       int i;
411
412       for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
413         {
414           tree arg = NULL_TREE;
415
416           /* Don't crash if we had an invalid argument list.  */
417           if (TMPL_ARGS_DEPTH (args) >= lvl)
418             {
419               tree lvl_args = TMPL_ARGS_LEVEL (args, lvl);
420               if (NUM_TMPL_ARGS (lvl_args) > arg_idx)
421                 arg = TREE_VEC_ELT (lvl_args, arg_idx);
422             }
423
424           if (need_comma)
425             OB_PUTS (", ");
426           dump_template_parameter (TREE_VEC_ELT (p, i), TS_PLAIN);
427           OB_PUTS (" = ");
428           if (arg)
429             dump_template_argument (arg, TS_PLAIN);
430           else
431             OB_PUTS ("{missing}");
432
433           ++arg_idx;
434           need_comma = 1;
435         }
436
437       parms = TREE_CHAIN (parms);
438     }
439 }
440
441 /* Dump into the obstack a human-readable equivalent of TYPE.  FLAGS
442    controls the format.  */
443
444 static void
445 dump_type (t, flags)
446      tree t;
447      enum tree_string_flags flags;
448 {
449   if (t == NULL_TREE)
450     return;
451
452   if (TYPE_PTRMEMFUNC_P (t))
453     goto offset_type;
454
455   switch (TREE_CODE (t))
456     {
457     case UNKNOWN_TYPE:
458       OB_PUTS ("{unknown type}");
459       break;
460
461     case TREE_LIST:
462       /* A list of function parms.  */
463       dump_parameters (t, flags);
464       break;
465
466     case IDENTIFIER_NODE:
467       OB_PUTID (t);
468       break;
469
470     case TREE_VEC:
471       dump_type (BINFO_TYPE (t), flags);
472       break;
473
474     case RECORD_TYPE:
475     case UNION_TYPE:
476     case ENUMERAL_TYPE:
477       dump_aggr_type (t, flags);
478       break;
479
480     case TYPE_DECL:
481       if (flags & TS_CHASE_TYPEDEFS)
482         {
483           dump_type (DECL_ORIGINAL_TYPE (t)
484                      ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags);
485           break;
486         }
487       /* else fallthrough */
488
489     case TEMPLATE_DECL:
490     case NAMESPACE_DECL:
491       dump_decl (t, flags & ~TS_DECL_TYPE);
492       break;
493
494     case COMPLEX_TYPE:
495       OB_PUTS ("complex ");
496       dump_type (TREE_TYPE (t), flags);
497       break;
498
499     case INTEGER_TYPE:
500       if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
501         OB_PUTS ("unsigned ");
502       else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
503         OB_PUTS ("signed ");
504
505       /* fall through.  */
506     case REAL_TYPE:
507     case VOID_TYPE:
508     case BOOLEAN_TYPE:
509       {
510         tree type;
511         dump_qualifiers (t, after);
512         type = flags & TS_CHASE_TYPEDEFS ? TYPE_MAIN_VARIANT (t) : t;
513         if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
514           OB_PUTID (TYPE_IDENTIFIER (type));
515         else
516           /* Types like intQI_type_node and friends have no names.
517              These don't come up in user error messages, but it's nice
518              to be able to print them from the debugger.  */
519           OB_PUTS ("{anonymous}");
520       }
521       break;
522
523     case TEMPLATE_TEMPLATE_PARM:
524       /* For parameters inside template signature. */
525       if (TYPE_IDENTIFIER (t))
526         OB_PUTID (TYPE_IDENTIFIER (t));
527       else
528         OB_PUTS ("{anonymous template template parameter}");
529       break;
530
531     case BOUND_TEMPLATE_TEMPLATE_PARM:
532       {
533         tree args = TYPE_TI_ARGS (t);
534         OB_PUTID (TYPE_IDENTIFIER (t));
535         OB_PUTC ('<');
536         dump_template_argument_list (args, flags);
537         OB_END_TEMPLATE_ID ();
538       }
539       break;
540
541     case TEMPLATE_TYPE_PARM:
542       dump_qualifiers (t, after);
543       if (TYPE_IDENTIFIER (t))
544         OB_PUTID (TYPE_IDENTIFIER (t));
545       else
546         OB_PUTS ("{anonymous template type parameter}");
547       break;
548
549       /* This is not always necessary for pointers and such, but doing this
550          reduces code size.  */
551     case ARRAY_TYPE:
552     case POINTER_TYPE:
553     case REFERENCE_TYPE:
554     case OFFSET_TYPE:
555     offset_type:
556     case FUNCTION_TYPE:
557     case METHOD_TYPE:
558     {
559       dump_type_prefix (t, flags);
560       dump_type_suffix (t, flags);
561       break;
562     }
563     case TYPENAME_TYPE:
564       OB_PUTS ("typename ");
565       dump_typename (t, flags);
566       break;
567
568     case TYPEOF_TYPE:
569       OB_PUTS ("__typeof (");
570       dump_expr (TYPE_FIELDS (t), flags & ~TS_EXPR_PARENS);
571       OB_PUTC (')');
572       break;
573
574     default:
575       sorry ("`%s' not supported by dump_type",
576              tree_code_name[(int) TREE_CODE (t)]);
577       /* Fall through to error. */
578
579     case ERROR_MARK:
580       OB_PUTS ("{type error}");
581       break;
582     }
583 }
584
585 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
586    a TYPENAME_TYPE.  */
587
588 static void
589 dump_typename (t, flags)
590      tree t;
591      enum tree_string_flags flags;
592 {
593   tree ctx = TYPE_CONTEXT (t);
594
595   if (TREE_CODE (ctx) == TYPENAME_TYPE)
596     dump_typename (ctx, flags);
597   else
598     dump_type (ctx, flags & ~TS_AGGR_TAGS);
599   OB_PUTS ("::");
600   dump_decl (TYPENAME_TYPE_FULLNAME (t), flags);
601 }
602
603 /* Return the name of the supplied aggregate, or enumeral type.  */
604
605 static const char *
606 class_key_or_enum (t)
607      tree t;
608 {
609   if (TREE_CODE (t) == ENUMERAL_TYPE)
610     return "enum";
611   else if (TREE_CODE (t) == UNION_TYPE)
612     return "union";
613   else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
614     return "class";
615   else
616     return "struct";
617 }
618
619 /* Print out a class declaration T under the control of FLAGS,
620    in the form `class foo'.  */
621
622 static void
623 dump_aggr_type (t, flags)
624      tree t;
625      enum tree_string_flags flags;
626 {
627   tree name;
628   const char *variety = class_key_or_enum (t);
629   int typdef = 0;
630   int tmplate = 0;
631
632   dump_qualifiers (t, after);
633
634   if (flags & TS_AGGR_TAGS)
635     {
636       OB_PUTCP (variety);
637       OB_PUTC (' ');
638     }
639
640   if (flags & TS_CHASE_TYPEDEFS)
641     t = TYPE_MAIN_VARIANT (t);
642
643   name = TYPE_NAME (t);
644
645   if (name)
646     {
647       typdef = !DECL_ARTIFICIAL (name);
648       tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE
649                 && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t)
650                 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t)
651                     || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL
652                     || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t))
653                     || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
654       dump_scope (CP_DECL_CONTEXT (name), flags | TS_FUNC_SCOPE);
655       if (tmplate)
656         {
657           /* Because the template names are mangled, we have to locate
658              the most general template, and use that name.  */
659           tree tpl = CLASSTYPE_TI_TEMPLATE (t);
660
661           while (DECL_TEMPLATE_INFO (tpl))
662             tpl = DECL_TI_TEMPLATE (tpl);
663           name = tpl;
664         }
665       name = DECL_NAME (name);
666     }
667
668   if (name == 0 || ANON_AGGRNAME_P (name))
669     {
670       OB_PUTS ("{anonymous");
671       if (!(flags & TS_AGGR_TAGS))
672         {
673           OB_PUTC (' ');
674           OB_PUTCP (variety);
675         }
676       OB_PUTC ('}');
677     }
678   else
679     OB_PUTID (name);
680   if (tmplate)
681     dump_template_parms (TYPE_TEMPLATE_INFO (t),
682                          !CLASSTYPE_USE_TEMPLATE (t),
683                          flags & ~TS_TEMPLATE_PREFIX);
684 }
685
686 /* Dump into the obstack the initial part of the output for a given type.
687    This is necessary when dealing with things like functions returning
688    functions.  Examples:
689
690    return type of `int (* fee ())()': pointer -> function -> int.  Both
691    pointer (and reference and offset) and function (and member) types must
692    deal with prefix and suffix.
693
694    Arrays must also do this for DECL nodes, like int a[], and for things like
695    int *[]&.
696
697    Return indicates how you should pad an object name after this. I.e. you
698    want to pad non-*, non-& cores, but not pad * or & types.  */
699
700 static enum pad
701 dump_type_prefix (t, flags)
702      tree t;
703      enum tree_string_flags flags;
704 {
705   enum pad padding = before;
706
707   if (TYPE_PTRMEMFUNC_P (t))
708     {
709       t = TYPE_PTRMEMFUNC_FN_TYPE (t);
710       goto offset_type;
711     }
712
713   switch (TREE_CODE (t))
714     {
715     case POINTER_TYPE:
716     case REFERENCE_TYPE:
717       {
718         tree sub = TREE_TYPE (t);
719
720         padding = dump_type_prefix (sub, flags);
721         /* A tree for a member pointer looks like pointer to offset,
722            so let the OFFSET_TYPE case handle it.  */
723         if (!TYPE_PTRMEM_P (t))
724           {
725             if (padding != none)
726               OB_PUTC (' ');
727             if (TREE_CODE (sub) == ARRAY_TYPE)
728               OB_PUTC ('(');
729             OB_PUTC ("&*"[TREE_CODE (t) == POINTER_TYPE]);
730             padding = dump_qualifiers (t, none);
731           }
732       }
733       break;
734
735     case OFFSET_TYPE:
736     offset_type:
737       padding = dump_type_prefix (TREE_TYPE (t), flags);
738       if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
739         {
740           if (padding != none)
741             OB_PUTC (' ');
742           dump_type (TYPE_OFFSET_BASETYPE (t), flags);
743           OB_PUTS ("::");
744         }
745       OB_PUTC ('*');
746       padding = dump_qualifiers (t, none);
747       break;
748
749       /* Can only be reached through function pointer -- this would not be
750          correct if FUNCTION_DECLs used it.  */
751     case FUNCTION_TYPE:
752       padding = dump_type_prefix (TREE_TYPE (t), flags);
753       if (padding != none)
754         OB_PUTC (' ');
755       OB_PUTC ('(');
756       padding = none;
757       break;
758
759     case METHOD_TYPE:
760       padding = dump_type_prefix (TREE_TYPE (t), flags);
761       if (padding != none)
762         OB_PUTC (' ');
763       OB_PUTC ('(');
764       padding = none;
765       dump_aggr_type (TYPE_METHOD_BASETYPE (t), flags);
766       OB_PUTS ("::");
767       break;
768
769     case ARRAY_TYPE:
770       padding = dump_type_prefix (TREE_TYPE (t), flags);
771       break;
772
773     case ENUMERAL_TYPE:
774     case IDENTIFIER_NODE:
775     case INTEGER_TYPE:
776     case BOOLEAN_TYPE:
777     case REAL_TYPE:
778     case RECORD_TYPE:
779     case TEMPLATE_TYPE_PARM:
780     case TEMPLATE_TEMPLATE_PARM:
781     case BOUND_TEMPLATE_TEMPLATE_PARM:
782     case TREE_LIST:
783     case TYPE_DECL:
784     case TREE_VEC:
785     case UNION_TYPE:
786     case UNKNOWN_TYPE:
787     case VOID_TYPE:
788     case TYPENAME_TYPE:
789     case COMPLEX_TYPE:
790       dump_type (t, flags);
791       padding = before;
792       break;
793
794     default:
795       sorry ("`%s' not supported by dump_type_prefix",
796              tree_code_name[(int) TREE_CODE (t)]);
797
798     case ERROR_MARK:
799       OB_PUTS ("{typeprefixerror}");
800       break;
801     }
802   return padding;
803 }
804
805 /* Dump the suffix of type T, under control of FLAGS.  This is the part
806    which appears after the identifier (or function parms).  */
807
808 static void
809 dump_type_suffix (t, flags)
810      tree t;
811      enum tree_string_flags flags;
812 {
813   if (TYPE_PTRMEMFUNC_P (t))
814     t = TYPE_PTRMEMFUNC_FN_TYPE (t);
815
816   switch (TREE_CODE (t))
817     {
818     case POINTER_TYPE:
819     case REFERENCE_TYPE:
820     case OFFSET_TYPE:
821       if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
822         OB_PUTC (')');
823       dump_type_suffix (TREE_TYPE (t), flags);
824       break;
825
826       /* Can only be reached through function pointer */
827     case FUNCTION_TYPE:
828     case METHOD_TYPE:
829       {
830         tree arg;
831         OB_PUTC (')');
832         arg = TYPE_ARG_TYPES (t);
833         if (TREE_CODE (t) == METHOD_TYPE)
834           arg = TREE_CHAIN (arg);
835
836         /* Function pointers don't have default args.  Not in standard C++,
837            anyway; they may in g++, but we'll just pretend otherwise.  */
838         dump_parameters (arg, flags & ~TS_PARM_DEFAULTS);
839
840         if (TREE_CODE (t) == METHOD_TYPE)
841           dump_qualifiers
842             (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
843         dump_type_suffix (TREE_TYPE (t), flags);
844         dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t), flags);
845         break;
846       }
847
848     case ARRAY_TYPE:
849       OB_PUTC ('[');
850       if (TYPE_DOMAIN (t))
851         {
852           if (host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0))
853             OB_PUTI (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0) + 1);
854           else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
855             dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0),
856                        flags & ~TS_EXPR_PARENS);
857           else
858             dump_expr (fold (cp_build_binary_op
859                              (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
860                               integer_one_node)),
861                        flags & ~TS_EXPR_PARENS);
862         }
863       OB_PUTC (']');
864       dump_type_suffix (TREE_TYPE (t), flags);
865       break;
866
867     case ENUMERAL_TYPE:
868     case IDENTIFIER_NODE:
869     case INTEGER_TYPE:
870     case BOOLEAN_TYPE:
871     case REAL_TYPE:
872     case RECORD_TYPE:
873     case TEMPLATE_TYPE_PARM:
874     case TEMPLATE_TEMPLATE_PARM:
875     case BOUND_TEMPLATE_TEMPLATE_PARM:
876     case TREE_LIST:
877     case TYPE_DECL:
878     case TREE_VEC:
879     case UNION_TYPE:
880     case UNKNOWN_TYPE:
881     case VOID_TYPE:
882     case TYPENAME_TYPE:
883     case COMPLEX_TYPE:
884       break;
885
886     default:
887       sorry ("`%s' not supported by dump_type_suffix",
888              tree_code_name[(int) TREE_CODE (t)]);
889
890     case ERROR_MARK:
891       /* Don't mark it here, we should have already done in
892          dump_type_prefix.  */
893       break;
894     }
895 }
896
897 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
898    argument.  */
899
900 static tree
901 ident_fndecl (t)
902      tree t;
903 {
904   tree n = lookup_name (t, 0);
905
906   if (n == NULL_TREE)
907     return NULL_TREE;
908
909   if (TREE_CODE (n) == FUNCTION_DECL)
910     return n;
911   else if (TREE_CODE (n) == TREE_LIST
912            && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
913     return TREE_VALUE (n);
914
915   my_friendly_abort (66);
916   return NULL_TREE;
917 }
918
919 #ifndef NO_DOLLAR_IN_LABEL
920 #  define GLOBAL_THING "_GLOBAL_$"
921 #else
922 #  ifndef NO_DOT_IN_LABEL
923 #    define GLOBAL_THING "_GLOBAL_."
924 #  else
925 #    define GLOBAL_THING "_GLOBAL__"
926 #  endif
927 #endif
928
929 #define GLOBAL_IORD_P(NODE) \
930   ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
931
932 static void
933 dump_global_iord (t)
934      tree t;
935 {
936   const char *name = IDENTIFIER_POINTER (t);
937
938   OB_PUTS ("(static ");
939   if (name [sizeof (GLOBAL_THING) - 1] == 'I')
940     OB_PUTS ("initializers");
941   else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
942     OB_PUTS ("destructors");
943   else
944     my_friendly_abort (352);
945
946   OB_PUTS (" for ");
947   OB_PUTCP (input_filename);
948   OB_PUTC (')');
949 }
950
951 static void
952 dump_simple_decl (t, type, flags)
953      tree t;
954      tree type;
955      enum tree_string_flags flags;
956 {
957   if (flags & TS_DECL_TYPE)
958     {
959       if (dump_type_prefix (type, flags) != none)
960         OB_PUTC (' ');
961     }
962   if (!DECL_INITIAL (t) || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)
963     dump_scope (CP_DECL_CONTEXT (t), flags);
964   if (DECL_NAME (t))
965     dump_decl (DECL_NAME (t), flags);
966   else
967     OB_PUTS ("{anonymous}");
968   if (flags & TS_DECL_TYPE)
969     dump_type_suffix (type, flags);
970 }
971
972 /* Dump a human readable string for the decl T under control of FLAGS.  */
973
974 static void
975 dump_decl (t, flags)
976      tree t;
977      enum tree_string_flags flags;
978 {
979   if (t == NULL_TREE)
980     return;
981
982   switch (TREE_CODE (t))
983     {
984     case TYPE_DECL:
985       {
986         /* Don't say 'typedef class A' */
987         if (DECL_ARTIFICIAL (t))
988           {
989             if ((flags & TS_DECL_TYPE)
990                 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
991               /* Say `class T' not just `T'. */
992               OB_PUTS ("class ");
993
994             dump_type (TREE_TYPE (t), flags);
995             break;
996           }
997       }
998       if (flags & TS_DECORATE)
999         OB_PUTS ("typedef ");
1000       dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
1001                         ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
1002                         flags);
1003       break;
1004
1005     case VAR_DECL:
1006       if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
1007         {
1008           OB_PUTS ("vtable for ");
1009           if (TYPE_P (DECL_CONTEXT (t)))
1010             dump_type (DECL_CONTEXT (t), flags);
1011           else
1012             /* This case can arise with -fno-vtable-thunks.  See
1013                expand_upcast_fixups.  It's not clear what to print
1014                here.  */
1015             OB_PUTS ("{unknown type}");
1016           break;
1017         }
1018       /* else fall through */
1019     case FIELD_DECL:
1020     case PARM_DECL:
1021       dump_simple_decl (t, TREE_TYPE (t), flags);
1022       break;
1023
1024     case RESULT_DECL:
1025       OB_PUTS ("{return} ");
1026       dump_simple_decl (t, TREE_TYPE (t), flags);
1027       break;
1028
1029     case NAMESPACE_DECL:
1030       dump_scope (CP_DECL_CONTEXT (t), flags);
1031       if (DECL_NAME (t) == anonymous_namespace_name)
1032         OB_PUTS ("{unnamed}");
1033       else
1034         OB_PUTID (DECL_NAME (t));
1035       break;
1036
1037     case SCOPE_REF:
1038       dump_decl (TREE_OPERAND (t, 0), flags & ~TS_DECL_TYPE);
1039       OB_PUTS ("::");
1040       dump_decl (TREE_OPERAND (t, 1), flags);
1041       break;
1042
1043     case ARRAY_REF:
1044       dump_decl (TREE_OPERAND (t, 0), flags);
1045       OB_PUTC ('[');
1046       dump_decl (TREE_OPERAND (t, 1), flags);
1047       OB_PUTC (']');
1048       break;
1049
1050       /* So that we can do dump_decl on an aggr type.  */
1051     case RECORD_TYPE:
1052     case UNION_TYPE:
1053     case ENUMERAL_TYPE:
1054       dump_type (t, flags);
1055       break;
1056
1057     case TYPE_EXPR:
1058       my_friendly_abort (69);
1059       break;
1060
1061       /* These special cases are duplicated here so that other functions
1062          can feed identifiers to cp_error and get them demangled properly.  */
1063     case IDENTIFIER_NODE:
1064       { tree f;
1065         if (DESTRUCTOR_NAME_P (t)
1066             && (f = ident_fndecl (t))
1067             && DECL_LANGUAGE (f) == lang_cplusplus)
1068           {
1069             OB_PUTC ('~');
1070             dump_decl (DECL_NAME (f), flags);
1071           }
1072         else if (IDENTIFIER_TYPENAME_P (t))
1073           {
1074             OB_PUTS ("operator ");
1075             /* Not exactly IDENTIFIER_TYPE_VALUE.  */
1076             dump_type (TREE_TYPE (t), flags);
1077             break;
1078           }
1079         else
1080           OB_PUTID (t);
1081       }
1082       break;
1083
1084     case OVERLOAD:
1085       t = OVL_CURRENT (t);
1086       /* Fall through.  */
1087
1088     case FUNCTION_DECL:
1089       if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
1090         dump_global_iord (DECL_ASSEMBLER_NAME (t));
1091       else if (! DECL_LANG_SPECIFIC (t))
1092         OB_PUTS ("{internal}");
1093       else if (flags & TS_PEDANTIC_NAME)
1094         dump_function_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
1095       else
1096         dump_function_decl (t, flags);
1097       break;
1098
1099     case TEMPLATE_DECL:
1100       if (flags & TS_PEDANTIC_NAME)
1101         dump_template_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
1102       else
1103         dump_template_decl (t, flags);
1104       break;
1105
1106     case TEMPLATE_ID_EXPR:
1107       {
1108         tree args;
1109         tree name = TREE_OPERAND (t, 0);
1110         if (is_overloaded_fn (name))
1111           name = DECL_NAME (get_first_fn (name));
1112         dump_decl (name, flags);
1113         OB_PUTC ('<');
1114         for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
1115           {
1116             dump_template_argument (TREE_VALUE (args), flags);
1117             if (TREE_CHAIN (args))
1118               OB_PUTS (", ");
1119           }
1120         OB_END_TEMPLATE_ID ();
1121       }
1122       break;
1123
1124     case LOOKUP_EXPR:
1125       dump_decl (TREE_OPERAND (t, 0), flags);
1126       break;
1127
1128     case LABEL_DECL:
1129       OB_PUTID (DECL_NAME (t));
1130       break;
1131
1132     case CONST_DECL:
1133       if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
1134           || (DECL_INITIAL (t) &&
1135               TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
1136         dump_simple_decl (t, TREE_TYPE (t), flags);
1137       else if (DECL_NAME (t))
1138         dump_decl (DECL_NAME (t), flags);
1139       else if (DECL_INITIAL (t))
1140         dump_expr (DECL_INITIAL (t), flags | TS_EXPR_PARENS);
1141       else
1142         OB_PUTS ("enumerator");
1143       break;
1144
1145     case USING_DECL:
1146       OB_PUTS ("using ");
1147       dump_type (DECL_INITIAL (t), flags);
1148       OB_PUTS ("::");
1149       OB_PUTID (DECL_NAME (t));
1150       break;
1151
1152     default:
1153       sorry ("`%s' not supported by dump_decl",
1154              tree_code_name[(int) TREE_CODE (t)]);
1155       /* Fallthrough to error.  */
1156
1157     case ERROR_MARK:
1158       OB_PUTS ("{declaration error}");
1159       break;
1160     }
1161 }
1162
1163 /* Dump a template declaration T under control of FLAGS. This means the
1164    'template <...> leaders plus the 'class X' or 'void fn(...)' part.  */
1165
1166 static void
1167 dump_template_decl (t, flags)
1168      tree t;
1169      enum tree_string_flags flags;
1170 {
1171   tree orig_parms = DECL_TEMPLATE_PARMS (t);
1172   tree parms;
1173   int i;
1174
1175   if (flags & TS_TEMPLATE_PREFIX)
1176     {
1177       for (parms = orig_parms = nreverse (orig_parms);
1178            parms;
1179            parms = TREE_CHAIN (parms))
1180         {
1181           tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
1182           int len = TREE_VEC_LENGTH (inner_parms);
1183
1184           OB_PUTS ("template <");
1185           for (i = 0; i < len; i++)
1186             {
1187               if (i)
1188                 OB_PUTS (", ");
1189               dump_template_parameter (TREE_VEC_ELT (inner_parms, i), flags);
1190             }
1191           OB_END_TEMPLATE_ID ();
1192           OB_PUTC (' ');
1193         }
1194       nreverse(orig_parms);
1195       /* If we've shown the template<args> prefix, we'd better show the
1196          decl's type too.  */
1197       flags |= TS_DECL_TYPE;
1198     }
1199   if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
1200     dump_type (TREE_TYPE (t),
1201                ((flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1202                 | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0)));
1203   else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
1204     dump_decl (DECL_TEMPLATE_RESULT (t), flags | TS_TEMPLATE_PLAIN);
1205   else if (TREE_TYPE (t) == NULL_TREE)
1206     my_friendly_abort (353);
1207   else
1208     switch (NEXT_CODE (t))
1209     {
1210       case METHOD_TYPE:
1211       case FUNCTION_TYPE:
1212         dump_function_decl (t, flags | TS_TEMPLATE_PLAIN);
1213         break;
1214       default:
1215         /* This case can occur with some illegal code.  */
1216         dump_type (TREE_TYPE (t),
1217                    (flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1218                    | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0));
1219     }
1220 }
1221
1222 /* Pretty print a function decl. There are several ways we want to print a
1223    function declaration. The TS_FUNC bits in FLAGS tells us how to behave.
1224    As cp_error can only apply the '#' flag once to give 0 and 1 for V, there
1225    is %D which doesn't print the throw specs, and %F which does. */
1226
1227 static void
1228 dump_function_decl (t, flags)
1229      tree t;
1230      enum tree_string_flags flags;
1231 {
1232   tree fntype;
1233   tree parmtypes;
1234   tree cname = NULL_TREE;
1235   tree template_args = NULL_TREE;
1236   tree template_parms = NULL_TREE;
1237   int show_return = !(flags & TS_FUNC_NORETURN) && (flags & TS_DECL_TYPE);
1238
1239   if (TREE_CODE (t) == TEMPLATE_DECL)
1240     t = DECL_TEMPLATE_RESULT (t);
1241
1242   /* Pretty print template instantiations only.  */
1243   if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t))
1244     {
1245       tree tmpl;
1246
1247       template_args = DECL_TI_ARGS (t);
1248       tmpl = most_general_template (t);
1249       if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL)
1250         {
1251           template_parms = DECL_TEMPLATE_PARMS (tmpl);
1252           t = tmpl;
1253         }
1254     }
1255
1256   fntype = TREE_TYPE (t);
1257   parmtypes = TYPE_ARG_TYPES (fntype);
1258
1259   if (DECL_CLASS_SCOPE_P (t))
1260     cname = DECL_CONTEXT (t);
1261   /* this is for partially instantiated template methods */
1262   else if (TREE_CODE (fntype) == METHOD_TYPE)
1263     cname = TREE_TYPE (TREE_VALUE (parmtypes));
1264
1265   if (!(flags & TS_DECORATE))
1266     /* OK */;
1267   else if (DECL_STATIC_FUNCTION_P (t))
1268     OB_PUTS ("static ");
1269   else if (TYPE_POLYMORPHIC_P (t))
1270     OB_PUTS ("virtual ");
1271
1272   /* Print the return type?  */
1273   if (show_return)
1274     show_return = !DECL_CONV_FN_P (t)  && !DECL_CONSTRUCTOR_P (t)
1275                   && !DECL_DESTRUCTOR_P (t);
1276   if (show_return)
1277     {
1278       if (dump_type_prefix (TREE_TYPE (fntype), flags) != none)
1279         OB_PUTC (' ');
1280     }
1281
1282   /* Print the function name.  */
1283   if (cname)
1284     {
1285       dump_type (cname, flags);
1286       OB_PUTS ("::");
1287     }
1288   else
1289     dump_scope (CP_DECL_CONTEXT (t), flags);
1290
1291   dump_function_name (t, flags);
1292
1293   if (!(flags & TS_DECL_TYPE))
1294     return;
1295   if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
1296     /* Skip "this" parameter.  */
1297     parmtypes = TREE_CHAIN (parmtypes);
1298
1299   /* Skip past the "in_charge" parameter.  */
1300   if (DECL_HAS_IN_CHARGE_PARM_P (t))
1301     parmtypes = TREE_CHAIN (parmtypes);
1302
1303   dump_parameters (parmtypes, flags);
1304
1305   if (show_return)
1306     dump_type_suffix (TREE_TYPE (fntype), flags);
1307
1308   if (TREE_CODE (fntype) == METHOD_TYPE)
1309     dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))),
1310                      before);
1311
1312   if (flags & TS_FUNC_THROW)
1313     dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype), flags);
1314
1315   /* If T is a template instantiation, dump the parameter binding.  */
1316   if (template_parms != NULL_TREE && template_args != NULL_TREE)
1317     {
1318       OB_PUTS (" [with ");
1319       dump_template_bindings (template_parms, template_args);
1320       OB_PUTC (']');
1321     }
1322 }
1323
1324 /* Print a parameter list. If this is for a member function, the
1325    member object ptr (and any other hidden args) should have
1326    already been removed. */
1327
1328 static void
1329 dump_parameters (parmtypes, flags)
1330      tree parmtypes;
1331      enum tree_string_flags flags;
1332 {
1333   int first;
1334   OB_PUTS (" (");
1335
1336   for (first = 1; parmtypes != void_list_node;
1337        parmtypes = TREE_CHAIN (parmtypes))
1338     {
1339       if (!first)
1340         OB_PUTS (", ");
1341       first = 0;
1342       if (!parmtypes)
1343         {
1344           OB_PUTS ("...");
1345           break;
1346         }
1347       dump_type (TREE_VALUE (parmtypes), flags);
1348
1349       if ((flags & TS_PARM_DEFAULTS) && TREE_PURPOSE (parmtypes))
1350         {
1351           OB_PUTS (" = ");
1352           dump_expr (TREE_PURPOSE (parmtypes), flags | TS_EXPR_PARENS);
1353         }
1354     }
1355
1356   OB_PUTC (')');
1357 }
1358
1359 /* Print an exception specification. T is the exception specification. */
1360
1361 static void
1362 dump_exception_spec (t, flags)
1363      tree t;
1364      enum tree_string_flags flags;
1365 {
1366   if (t)
1367     {
1368       OB_PUTS (" throw (");
1369       if (TREE_VALUE (t) != NULL_TREE)
1370         while (1)
1371           {
1372             dump_type (TREE_VALUE (t), flags);
1373             t = TREE_CHAIN (t);
1374             if (!t)
1375               break;
1376             OB_PUTS (", ");
1377           }
1378       OB_PUTC (')');
1379     }
1380 }
1381
1382 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1383    and destructors properly.  */
1384
1385 static void
1386 dump_function_name (t, flags)
1387      tree t;
1388      enum tree_string_flags flags;
1389 {
1390   tree name = DECL_NAME (t);
1391
1392   if (DECL_DESTRUCTOR_P (t))
1393     {
1394       OB_PUTC ('~');
1395       dump_decl (name, TS_PLAIN);
1396     }
1397   else if (DECL_CONV_FN_P (t))
1398     {
1399       /* This cannot use the hack that the operator's return
1400          type is stashed off of its name because it may be
1401          used for error reporting.  In the case of conflicting
1402          declarations, both will have the same name, yet
1403          the types will be different, hence the TREE_TYPE field
1404          of the first name will be clobbered by the second.  */
1405       OB_PUTS ("operator ");
1406       dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1407     }
1408   else if (IDENTIFIER_OPNAME_P (name))
1409     OB_PUTID (name);
1410   else
1411     dump_decl (name, flags);
1412
1413   if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)
1414       && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
1415       && (DECL_TEMPLATE_SPECIALIZATION (t)
1416           || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
1417           || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t))
1418           || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
1419     dump_template_parms (DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), flags);
1420 }
1421
1422 /* Dump the template parameters from the template info INFO under control of
1423    FLAGS. PRIMARY indicates whether this is a primary template decl, or
1424    specialization (partial or complete). For partial specializations we show
1425    the specialized parameter values. For a primary template we show no
1426    decoration.  */
1427
1428 static void
1429 dump_template_parms (info, primary, flags)
1430      tree info;
1431      int primary;
1432      enum tree_string_flags flags;
1433 {
1434   tree args = info ? TI_ARGS (info) : NULL_TREE;
1435
1436   if (primary && flags & TS_TEMPLATE_PLAIN)
1437     return;
1438   flags &= ~(TS_AGGR_TAGS | TS_TEMPLATE_PLAIN);
1439   OB_PUTC ('<');
1440
1441   /* Be careful only to print things when we have them, so as not
1442          to crash producing error messages.  */
1443   if (args && !primary)
1444     {
1445       int len = 0;
1446       int ix = 0;
1447       int need_comma = 0;
1448
1449       if (TREE_CODE (args) == TREE_VEC)
1450         {
1451           if (TREE_VEC_LENGTH (args) > 0
1452               && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1453             args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
1454
1455           len = TREE_VEC_LENGTH (args);
1456         }
1457       else if (TREE_CODE (args) == TREE_LIST)
1458         len = -1;
1459       while (ix != len && args)
1460         {
1461           tree arg;
1462           if (len >= 0)
1463             {
1464               arg = TREE_VEC_ELT (args, ix);
1465               ix++;
1466             }
1467           else
1468             {
1469               arg = TREE_VALUE (args);
1470               args = TREE_CHAIN (args);
1471             }
1472           if (need_comma)
1473             OB_PUTS (", ");
1474
1475           if (!arg)
1476             OB_PUTS ("{template parameter error}");
1477           else
1478             dump_template_argument (arg, flags);
1479           need_comma = 1;
1480         }
1481     }
1482   else if (primary)
1483     {
1484       tree tpl = TI_TEMPLATE (info);
1485       tree parms = DECL_TEMPLATE_PARMS (tpl);
1486       int len, ix;
1487
1488       parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE;
1489       len = parms ? TREE_VEC_LENGTH (parms) : 0;
1490
1491       for (ix = 0; ix != len; ix++)
1492         {
1493           tree parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
1494
1495           if (ix)
1496             OB_PUTS (", ");
1497
1498           dump_decl (parm, flags & ~TS_DECL_TYPE);
1499         }
1500     }
1501   OB_END_TEMPLATE_ID ();
1502 }
1503
1504 static void
1505 dump_char (c)
1506      int c;
1507 {
1508   switch (c)
1509     {
1510     case TARGET_NEWLINE:
1511       OB_PUTS ("\\n");
1512       break;
1513     case TARGET_TAB:
1514       OB_PUTS ("\\t");
1515       break;
1516     case TARGET_VT:
1517       OB_PUTS ("\\v");
1518       break;
1519     case TARGET_BS:
1520       OB_PUTS ("\\b");
1521       break;
1522     case TARGET_CR:
1523       OB_PUTS ("\\r");
1524       break;
1525     case TARGET_FF:
1526       OB_PUTS ("\\f");
1527       break;
1528     case TARGET_BELL:
1529       OB_PUTS ("\\a");
1530       break;
1531     case '\\':
1532       OB_PUTS ("\\\\");
1533       break;
1534     case '\'':
1535       OB_PUTS ("\\'");
1536       break;
1537     case '\"':
1538       OB_PUTS ("\\\"");
1539       break;
1540     default:
1541       if (ISPRINT (c))
1542         OB_PUTC (c);
1543       else
1544         {
1545           sprintf (digit_buffer, "\\%03o", (int) c);
1546           OB_PUTCP (digit_buffer);
1547         }
1548     }
1549 }
1550
1551 /* Print out a list of initializers (subr of dump_expr) */
1552
1553 static void
1554 dump_expr_list (l, flags)
1555      tree l;
1556      enum tree_string_flags flags;
1557 {
1558   while (l)
1559     {
1560       dump_expr (TREE_VALUE (l), flags | TS_EXPR_PARENS);
1561       l = TREE_CHAIN (l);
1562       if (l)
1563         OB_PUTS (", ");
1564     }
1565 }
1566
1567 /* Print out an expression E under control of FLAGS. */
1568
1569 static void
1570 dump_expr (t, flags)
1571      tree t;
1572      enum tree_string_flags flags;
1573 {
1574   switch (TREE_CODE (t))
1575     {
1576     case VAR_DECL:
1577     case PARM_DECL:
1578     case FIELD_DECL:
1579     case CONST_DECL:
1580     case FUNCTION_DECL:
1581     case TEMPLATE_DECL:
1582     case NAMESPACE_DECL:
1583     case OVERLOAD:
1584       dump_decl (t, flags & ~TS_DECL_TYPE);
1585       break;
1586
1587     case INTEGER_CST:
1588       {
1589         tree type = TREE_TYPE (t);
1590         my_friendly_assert (type != 0, 81);
1591
1592         /* If it's an enum, output its tag, rather than its value.  */
1593         if (TREE_CODE (type) == ENUMERAL_TYPE)
1594           {
1595             tree values = TYPE_VALUES (type);
1596
1597             for (; values;
1598                  values = TREE_CHAIN (values))
1599               if (tree_int_cst_equal (TREE_VALUE (values), t))
1600                 break;
1601
1602             if (values)
1603               OB_PUTID (TREE_PURPOSE (values));
1604             else
1605               {
1606                 /* Value must have been cast.  */
1607                 OB_PUTC ('(');
1608                 dump_type (type, flags);
1609                 OB_PUTC (')');
1610                 goto do_int;
1611               }
1612           }
1613         else if (type == boolean_type_node)
1614           {
1615             if (t == boolean_false_node || integer_zerop (t))
1616               OB_PUTS ("false");
1617             else if (t == boolean_true_node)
1618               OB_PUTS ("true");
1619           }
1620         else if (type == char_type_node)
1621           {
1622             OB_PUTC ('\'');
1623             dump_char (tree_low_cst (t, 0));
1624             OB_PUTC ('\'');
1625           }
1626         else
1627           {
1628             do_int:
1629             if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (t)
1630                 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1631               {
1632                 tree val = t;
1633
1634                 if (tree_int_cst_sgn (val) < 0)
1635                   {
1636                     OB_PUTC ('-');
1637                     val = build_int_2 (-TREE_INT_CST_LOW (val),
1638                                        ~TREE_INT_CST_HIGH (val)
1639                                        + !TREE_INT_CST_LOW (val));
1640                   }
1641                 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1642                    systems?  */
1643                 {
1644                   static char format[10]; /* "%x%09999x\0" */
1645                   if (!format[0])
1646                     sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1647                   sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1648                            TREE_INT_CST_LOW (val));
1649                   OB_PUTCP (digit_buffer);
1650                 }
1651               }
1652             else
1653               OB_PUTI (TREE_INT_CST_LOW (t));
1654           }
1655       }
1656       break;
1657
1658     case REAL_CST:
1659 #ifndef REAL_IS_NOT_DOUBLE
1660       sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1661 #else
1662       {
1663         const unsigned char *p = (const unsigned char *) &TREE_REAL_CST (t);
1664         size_t i;
1665         strcpy (digit_buffer, "0x");
1666         for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1667           sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1668       }
1669 #endif
1670       OB_PUTCP (digit_buffer);
1671       break;
1672
1673     case PTRMEM_CST:
1674       OB_PUTC ('&');
1675       dump_type (PTRMEM_CST_CLASS (t), flags);
1676       OB_PUTS ("::");
1677       OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t)));
1678       break;
1679
1680     case STRING_CST:
1681       {
1682         const char *p = TREE_STRING_POINTER (t);
1683         int len = TREE_STRING_LENGTH (t) - 1;
1684         int i;
1685
1686         OB_PUTC ('\"');
1687         for (i = 0; i < len; i++)
1688           dump_char (p[i]);
1689         OB_PUTC ('\"');
1690       }
1691       break;
1692
1693     case COMPOUND_EXPR:
1694       OB_PUTC ('(');
1695       dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1696       OB_PUTS (", ");
1697       dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1698       OB_PUTC (')');
1699       break;
1700
1701     case COND_EXPR:
1702       OB_PUTC ('(');
1703       dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1704       OB_PUTS (" ? ");
1705       dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1706       OB_PUTS (" : ");
1707       dump_expr (TREE_OPERAND (t, 2), flags | TS_EXPR_PARENS);
1708       OB_PUTC (')');
1709       break;
1710
1711     case SAVE_EXPR:
1712       if (TREE_HAS_CONSTRUCTOR (t))
1713         {
1714           OB_PUTS ("new ");
1715           dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1716         }
1717       else
1718         {
1719           dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1720         }
1721       break;
1722
1723     case AGGR_INIT_EXPR:
1724       {
1725         tree fn = NULL_TREE;
1726
1727         if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
1728           fn = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
1729
1730         if (fn && TREE_CODE (fn) == FUNCTION_DECL)
1731           {
1732             if (DECL_CONSTRUCTOR_P (fn))
1733               OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1734             else
1735               dump_decl (fn, 0);
1736           }
1737         else
1738           dump_expr (TREE_OPERAND (t, 0), 0);
1739       }
1740       OB_PUTC ('(');
1741       if (TREE_OPERAND (t, 1))
1742         dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1743       OB_PUTC (')');
1744       break;
1745
1746     case CALL_EXPR:
1747       {
1748         tree fn = TREE_OPERAND (t, 0);
1749         tree args = TREE_OPERAND (t, 1);
1750
1751         if (TREE_CODE (fn) == ADDR_EXPR)
1752           fn = TREE_OPERAND (fn, 0);
1753
1754         if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1755           {
1756             tree ob = TREE_VALUE (args);
1757             if (TREE_CODE (ob) == ADDR_EXPR)
1758               {
1759                 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
1760                 OB_PUTC ('.');
1761               }
1762             else if (TREE_CODE (ob) != PARM_DECL
1763                      || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1764               {
1765                 dump_expr (ob, flags | TS_EXPR_PARENS);
1766                 OB_PUTS ("->");
1767               }
1768             args = TREE_CHAIN (args);
1769           }
1770         dump_expr (fn, flags | TS_EXPR_PARENS);
1771         OB_PUTC ('(');
1772         dump_expr_list (args, flags);
1773         OB_PUTC (')');
1774       }
1775       break;
1776
1777     case NEW_EXPR:
1778       {
1779         tree type = TREE_OPERAND (t, 1);
1780         if (NEW_EXPR_USE_GLOBAL (t))
1781           OB_PUTS ("::");
1782         OB_PUTS ("new ");
1783         if (TREE_OPERAND (t, 0))
1784           {
1785             OB_PUTC ('(');
1786             dump_expr_list (TREE_OPERAND (t, 0), flags);
1787             OB_PUTS (") ");
1788           }
1789         if (TREE_CODE (type) == ARRAY_REF)
1790           type = build_cplus_array_type
1791             (TREE_OPERAND (type, 0),
1792              build_index_type (fold (build (MINUS_EXPR, integer_type_node,
1793                                             TREE_OPERAND (type, 1),
1794                                             integer_one_node))));
1795         dump_type (type, flags);
1796         if (TREE_OPERAND (t, 2))
1797           {
1798             OB_PUTC ('(');
1799             dump_expr_list (TREE_OPERAND (t, 2), flags);
1800             OB_PUTC (')');
1801           }
1802       }
1803       break;
1804
1805     case TARGET_EXPR:
1806       /* Note that this only works for G++ target exprs.  If somebody
1807          builds a general TARGET_EXPR, there's no way to represent that
1808          it initializes anything other that the parameter slot for the
1809          default argument.  Note we may have cleared out the first
1810          operand in expand_expr, so don't go killing ourselves.  */
1811       if (TREE_OPERAND (t, 1))
1812         dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1813       break;
1814
1815     case INIT_EXPR:
1816     case MODIFY_EXPR:
1817     case PLUS_EXPR:
1818     case MINUS_EXPR:
1819     case MULT_EXPR:
1820     case TRUNC_DIV_EXPR:
1821     case TRUNC_MOD_EXPR:
1822     case MIN_EXPR:
1823     case MAX_EXPR:
1824     case LSHIFT_EXPR:
1825     case RSHIFT_EXPR:
1826     case BIT_IOR_EXPR:
1827     case BIT_XOR_EXPR:
1828     case BIT_AND_EXPR:
1829     case BIT_ANDTC_EXPR:
1830     case TRUTH_ANDIF_EXPR:
1831     case TRUTH_ORIF_EXPR:
1832     case LT_EXPR:
1833     case LE_EXPR:
1834     case GT_EXPR:
1835     case GE_EXPR:
1836     case EQ_EXPR:
1837     case NE_EXPR:
1838     case EXACT_DIV_EXPR:
1839       dump_binary_op (operator_name_info[(int) TREE_CODE (t)].name, t, flags);
1840       break;
1841
1842     case CEIL_DIV_EXPR:
1843     case FLOOR_DIV_EXPR:
1844     case ROUND_DIV_EXPR:
1845       dump_binary_op ("/", t, flags);
1846       break;
1847
1848     case CEIL_MOD_EXPR:
1849     case FLOOR_MOD_EXPR:
1850     case ROUND_MOD_EXPR:
1851       dump_binary_op ("%", t, flags);
1852       break;
1853
1854     case COMPONENT_REF:
1855       {
1856         tree ob = TREE_OPERAND (t, 0);
1857         if (TREE_CODE (ob) == INDIRECT_REF)
1858           {
1859             ob = TREE_OPERAND (ob, 0);
1860             if (TREE_CODE (ob) != PARM_DECL
1861                 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1862               {
1863                 dump_expr (ob, flags | TS_EXPR_PARENS);
1864                 OB_PUTS ("->");
1865               }
1866           }
1867         else
1868           {
1869             dump_expr (ob, flags | TS_EXPR_PARENS);
1870             OB_PUTC ('.');
1871           }
1872         dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
1873       }
1874       break;
1875
1876     case ARRAY_REF:
1877       dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1878       OB_PUTC ('[');
1879       dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1880       OB_PUTC (']');
1881       break;
1882
1883     case CONVERT_EXPR:
1884       if (VOID_TYPE_P (TREE_TYPE (t)))
1885         {
1886           OB_PUTC ('(');
1887           dump_type (TREE_TYPE (t), flags);
1888           OB_PUTC (')');
1889           dump_expr (TREE_OPERAND (t, 0), flags);
1890         }
1891       else
1892         dump_unary_op ("+", t, flags);
1893       break;
1894
1895     case ADDR_EXPR:
1896       if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1897           || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST
1898           /* An ADDR_EXPR can have reference type.  In that case, we
1899              shouldn't print the `&' doing so indicates to the user
1900              that the expression has pointer type.  */
1901           || (TREE_TYPE (t)
1902               && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE))
1903         dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1904       else
1905         dump_unary_op ("&", t, flags);
1906       break;
1907
1908     case INDIRECT_REF:
1909       if (TREE_HAS_CONSTRUCTOR (t))
1910         {
1911           t = TREE_OPERAND (t, 0);
1912           my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1913           dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1914           OB_PUTC ('(');
1915           dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1916           OB_PUTC (')');
1917         }
1918       else
1919         {
1920           if (TREE_OPERAND (t,0) != NULL_TREE
1921               && TREE_TYPE (TREE_OPERAND (t, 0))
1922               && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1923             dump_expr (TREE_OPERAND (t, 0), flags);
1924           else
1925             dump_unary_op ("*", t, flags);
1926         }
1927       break;
1928
1929     case NEGATE_EXPR:
1930     case BIT_NOT_EXPR:
1931     case TRUTH_NOT_EXPR:
1932     case PREDECREMENT_EXPR:
1933     case PREINCREMENT_EXPR:
1934       dump_unary_op (operator_name_info [(int)TREE_CODE (t)].name, t, flags);
1935       break;
1936
1937     case POSTDECREMENT_EXPR:
1938     case POSTINCREMENT_EXPR:
1939       OB_PUTC ('(');
1940       dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1941       OB_PUTCP (operator_name_info[(int)TREE_CODE (t)].name);
1942       OB_PUTC (')');
1943       break;
1944
1945     case NON_LVALUE_EXPR:
1946       /* FIXME: This is a KLUDGE workaround for a parsing problem.  There
1947          should be another level of INDIRECT_REF so that I don't have to do
1948          this.  */
1949       if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1950         {
1951           tree next = TREE_TYPE (TREE_TYPE (t));
1952
1953           while (TREE_CODE (next) == POINTER_TYPE)
1954             next = TREE_TYPE (next);
1955
1956           if (TREE_CODE (next) == FUNCTION_TYPE)
1957             {
1958               if (flags & TS_EXPR_PARENS)
1959                 OB_PUTC ('(');
1960               OB_PUTC ('*');
1961               dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
1962               if (flags & TS_EXPR_PARENS)
1963                 OB_PUTC (')');
1964               break;
1965             }
1966           /* else FALLTHRU */
1967         }
1968       dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1969       break;
1970
1971     case NOP_EXPR:
1972       dump_expr (TREE_OPERAND (t, 0), flags);
1973       break;
1974
1975     case EXPR_WITH_FILE_LOCATION:
1976       dump_expr (EXPR_WFL_NODE (t), flags);
1977       break;
1978
1979     case CONSTRUCTOR:
1980       if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1981         {
1982           tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1983
1984           if (integer_all_onesp (idx))
1985             {
1986               tree pfn = PFN_FROM_PTRMEMFUNC (t);
1987               dump_unary_op ("&", pfn, flags | TS_EXPR_PARENS);
1988               break;
1989             }
1990           else if (TREE_CODE (idx) == INTEGER_CST
1991                    && tree_int_cst_equal (idx, integer_zero_node))
1992             {
1993               /* A NULL pointer-to-member constant.  */
1994               OB_PUTS ("((");
1995               dump_type (TREE_TYPE (t), flags);
1996               OB_PUTS (") 0)");
1997               break;
1998             }
1999           else if (host_integerp (idx, 0))
2000             {
2001               tree virtuals;
2002               unsigned HOST_WIDE_INT n;
2003
2004               t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
2005               t = TYPE_METHOD_BASETYPE (t);
2006               virtuals = TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t));
2007
2008               n = tree_low_cst (idx, 0) - first_vfun_index (t);
2009
2010               /* Map vtable index back one, to allow for the null pointer to
2011                  member.  */
2012               --n;
2013
2014               while (n > 0 && virtuals)
2015                 {
2016                   --n;
2017                   virtuals = TREE_CHAIN (virtuals);
2018                 }
2019               if (virtuals)
2020                 {
2021                   dump_expr (BV_FN (virtuals),
2022                              flags | TS_EXPR_PARENS);
2023                   break;
2024                 }
2025             }
2026         }
2027       OB_PUTC ('{');
2028       dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
2029       OB_PUTC ('}');
2030       break;
2031
2032     case OFFSET_REF:
2033       {
2034         tree ob = TREE_OPERAND (t, 0);
2035         if (is_dummy_object (ob))
2036           {
2037             t = TREE_OPERAND (t, 1);
2038             if (TREE_CODE (t) == FUNCTION_DECL)
2039               /* A::f */
2040               dump_expr (t, flags | TS_EXPR_PARENS);
2041             else if (BASELINK_P (t))
2042               dump_expr (OVL_CURRENT (TREE_VALUE (t)), flags | TS_EXPR_PARENS);
2043             else
2044               dump_decl (t, flags);
2045           }
2046         else
2047           {
2048             if (TREE_CODE (ob) == INDIRECT_REF)
2049               {
2050                 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
2051                 OB_PUTS (" ->* ");
2052               }
2053             else
2054               {
2055                 dump_expr (ob, flags | TS_EXPR_PARENS);
2056                 OB_PUTS (" .* ");
2057               }
2058             dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
2059           }
2060         break;
2061       }
2062
2063     case TEMPLATE_PARM_INDEX:
2064       dump_decl (TEMPLATE_PARM_DECL (t), flags & ~TS_DECL_TYPE);
2065       break;
2066
2067     case IDENTIFIER_NODE:
2068       OB_PUTID (t);
2069       break;
2070
2071     case SCOPE_REF:
2072       dump_type (TREE_OPERAND (t, 0), flags);
2073       OB_PUTS ("::");
2074       dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
2075       break;
2076
2077     case CAST_EXPR:
2078       if (TREE_OPERAND (t, 0) == NULL_TREE
2079           || TREE_CHAIN (TREE_OPERAND (t, 0)))
2080         {
2081           dump_type (TREE_TYPE (t), flags);
2082           OB_PUTC ('(');
2083           dump_expr_list (TREE_OPERAND (t, 0), flags);
2084           OB_PUTC (')');
2085         }
2086       else
2087         {
2088           OB_PUTC ('(');
2089           dump_type (TREE_TYPE (t), flags);
2090           OB_PUTC (')');
2091           OB_PUTC ('(');
2092           dump_expr_list (TREE_OPERAND (t, 0), flags);
2093           OB_PUTC (')');
2094         }
2095       break;
2096
2097     case LOOKUP_EXPR:
2098       OB_PUTID (TREE_OPERAND (t, 0));
2099       break;
2100
2101     case ARROW_EXPR:
2102       dump_expr (TREE_OPERAND (t, 0), flags);
2103       OB_PUTS ("->");
2104       break;
2105
2106     case SIZEOF_EXPR:
2107     case ALIGNOF_EXPR:
2108       if (TREE_CODE (t) == SIZEOF_EXPR)
2109         OB_PUTS ("sizeof (");
2110       else
2111         {
2112           my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
2113           OB_PUTS ("__alignof__ (");
2114         }
2115       if (TYPE_P (TREE_OPERAND (t, 0)))
2116         dump_type (TREE_OPERAND (t, 0), flags);
2117       else
2118         dump_unary_op ("*", t, flags | TS_EXPR_PARENS);
2119       OB_PUTC (')');
2120       break;
2121
2122     case DEFAULT_ARG:
2123       OB_PUTS ("{unparsed}");
2124       break;
2125
2126     case TRY_CATCH_EXPR:
2127     case WITH_CLEANUP_EXPR:
2128     case CLEANUP_POINT_EXPR:
2129       dump_expr (TREE_OPERAND (t, 0), flags);
2130       break;
2131
2132     case PSEUDO_DTOR_EXPR:
2133       dump_expr (TREE_OPERAND (t, 2), flags);
2134       OB_PUTS (".");
2135       dump_type (TREE_OPERAND (t, 0), flags);
2136       OB_PUTS ("::~");
2137       dump_type (TREE_OPERAND (t, 1), flags);
2138       break;
2139
2140     case TEMPLATE_ID_EXPR:
2141       dump_decl (t, flags);
2142       break;
2143
2144     case STMT_EXPR:
2145       /* We don't yet have a way of dumping statements in a
2146          human-readable format.  */
2147       OB_PUTS ("{ ... }");
2148       break;
2149
2150     case BIND_EXPR:
2151       OB_PUTS ("{ ");
2152       dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
2153       OB_PUTS ("} ");
2154       break;
2155
2156     case LOOP_EXPR:
2157       OB_PUTS ("while (1) { ");
2158       dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2159       OB_PUTS ("} ");
2160       break;
2161
2162     case EXIT_EXPR:
2163       OB_PUTS ("if (");
2164       dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2165       OB_PUTS (") break; ");
2166       break;
2167
2168     case TREE_LIST:
2169       if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
2170         {
2171           OB_PUTID (DECL_NAME (TREE_VALUE (t)));
2172           break;
2173         }
2174       /* else fall through */
2175
2176       /*  This list is incomplete, but should suffice for now.
2177           It is very important that `sorry' does not call
2178           `report_error_function'.  That could cause an infinite loop.  */
2179     default:
2180       sorry ("`%s' not supported by dump_expr",
2181              tree_code_name[(int) TREE_CODE (t)]);
2182
2183       /* fall through to ERROR_MARK...  */
2184     case ERROR_MARK:
2185       OB_PUTCP ("{expression error}");
2186       break;
2187     }
2188 }
2189
2190 static void
2191 dump_binary_op (opstring, t, flags)
2192      const char *opstring;
2193      tree t;
2194      enum tree_string_flags flags;
2195 {
2196   OB_PUTC ('(');
2197   dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
2198   OB_PUTC (' ');
2199   if (opstring)
2200     OB_PUTCP (opstring);
2201   else
2202     OB_PUTS ("<unknown operator>");
2203   OB_PUTC (' ');
2204   dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
2205   OB_PUTC (')');
2206 }
2207
2208 static void
2209 dump_unary_op (opstring, t, flags)
2210      const char *opstring;
2211      tree t;
2212      enum tree_string_flags flags;
2213 {
2214   if (flags & TS_EXPR_PARENS)
2215     OB_PUTC ('(');
2216   OB_PUTCP (opstring);
2217   dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2218   if (flags & TS_EXPR_PARENS)
2219     OB_PUTC (')');
2220 }
2221
2222 /* Exported interface to stringifying types, exprs and decls under TS_*
2223    control.  */
2224
2225 const char *
2226 type_as_string (typ, flags)
2227      tree typ;
2228      enum tree_string_flags flags;
2229 {
2230   OB_INIT ();
2231
2232   dump_type (typ, flags);
2233
2234   OB_FINISH ();
2235
2236   return (char *)obstack_base (&scratch_obstack);
2237 }
2238
2239 const char *
2240 expr_as_string (decl, flags)
2241      tree decl;
2242      enum tree_string_flags flags;
2243 {
2244   OB_INIT ();
2245
2246   dump_expr (decl, flags);
2247
2248   OB_FINISH ();
2249
2250   return (char *)obstack_base (&scratch_obstack);
2251 }
2252
2253 const char *
2254 decl_as_string (decl, flags)
2255      tree decl;
2256      enum tree_string_flags flags;
2257 {
2258   OB_INIT ();
2259
2260   dump_decl (decl, flags);
2261
2262   OB_FINISH ();
2263
2264   return (char *)obstack_base (&scratch_obstack);
2265 }
2266
2267 const char *
2268 context_as_string (context, flags)
2269      tree context;
2270      enum tree_string_flags flags;
2271 {
2272   OB_INIT ();
2273
2274   dump_scope (context, flags);
2275
2276   OB_FINISH ();
2277
2278   return (char *)obstack_base (&scratch_obstack);
2279 }
2280
2281 /* Generate the three forms of printable names for lang_printable_name.  */
2282
2283 const char *
2284 lang_decl_name (decl, v)
2285      tree decl;
2286      int v;
2287 {
2288   if (v >= 2)
2289     return decl_as_string (decl, TS_DECL_TYPE);
2290
2291   OB_INIT ();
2292
2293   if (v == 1 && DECL_CLASS_SCOPE_P (decl))
2294     {
2295       dump_type (CP_DECL_CONTEXT (decl), TS_PLAIN);
2296       OB_PUTS ("::");
2297     }
2298
2299   if (TREE_CODE (decl) == FUNCTION_DECL)
2300     dump_function_name (decl, TS_PLAIN);
2301   else
2302     dump_decl (DECL_NAME (decl), TS_PLAIN);
2303
2304   OB_FINISH ();
2305
2306   return (char *)obstack_base (&scratch_obstack);
2307 }
2308
2309 const char *
2310 cp_file_of (t)
2311      tree t;
2312 {
2313   if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2314     return DECL_SOURCE_FILE (DECL_CONTEXT (t));
2315   else if (TYPE_P (t))
2316     return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
2317   else if (TREE_CODE (t) == OVERLOAD)
2318     return DECL_SOURCE_FILE (OVL_FUNCTION (t));
2319   else
2320     return DECL_SOURCE_FILE (t);
2321 }
2322
2323 int
2324 cp_line_of (t)
2325      tree t;
2326 {
2327   int line = 0;
2328   if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2329     line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
2330   if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
2331       && TYPE_MAIN_DECL (TREE_TYPE (t)))
2332     t = TREE_TYPE (t);
2333
2334   if (TYPE_P (t))
2335     line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
2336   else if (TREE_CODE (t) == OVERLOAD)
2337     line = DECL_SOURCE_LINE (OVL_FUNCTION (t));
2338   else
2339     line = DECL_SOURCE_LINE (t);
2340
2341   if (line == 0)
2342     return lineno;
2343
2344   return line;
2345 }
2346
2347 /* Now the interfaces from cp_error et al to dump_type et al. Each takes an
2348    on/off VERBOSE flag and supply the appropriate TS_ flags to a dump_
2349    function.  */
2350
2351 static const char *
2352 decl_to_string (decl, verbose)
2353      tree decl;
2354      int verbose;
2355 {
2356   enum tree_string_flags flags = 0;
2357
2358   if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE
2359       || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
2360     flags = TS_AGGR_TAGS;
2361   if (verbose)
2362     flags |= TS_DECL_TYPE | TS_DECORATE | TS_PARM_DEFAULTS;
2363   else if (TREE_CODE (decl) == FUNCTION_DECL)
2364     flags |= TS_DECL_TYPE | TS_FUNC_NORETURN;
2365   flags |= TS_TEMPLATE_PREFIX;
2366
2367   OB_INIT ();
2368
2369   dump_decl (decl, flags);
2370
2371   OB_FINISH ();
2372
2373   return (char *)obstack_base (&scratch_obstack);
2374 }
2375
2376 static const char *
2377 expr_to_string (decl, verbose)
2378      tree decl;
2379      int verbose ATTRIBUTE_UNUSED;
2380 {
2381   OB_INIT ();
2382
2383   dump_expr (decl, 0);
2384
2385   OB_FINISH ();
2386
2387   return (char *)obstack_base (&scratch_obstack);
2388 }
2389
2390 static const char *
2391 fndecl_to_string (fndecl, verbose)
2392      tree fndecl;
2393      int verbose;
2394 {
2395   enum tree_string_flags flags;
2396
2397   flags = TS_FUNC_THROW | TS_DECL_TYPE;
2398   if (verbose)
2399     flags |= TS_PARM_DEFAULTS;
2400   OB_INIT ();
2401
2402   dump_decl (fndecl, flags);
2403
2404   OB_FINISH ();
2405
2406   return (char *)obstack_base (&scratch_obstack);
2407 }
2408
2409
2410 static const char *
2411 code_to_string (c, v)
2412      enum tree_code c;
2413      int v ATTRIBUTE_UNUSED;
2414 {
2415   return tree_code_name [c];
2416 }
2417
2418 const char *
2419 language_to_string (c, v)
2420      enum languages c;
2421      int v ATTRIBUTE_UNUSED;
2422 {
2423   switch (c)
2424     {
2425     case lang_c:
2426       return "C";
2427
2428     case lang_cplusplus:
2429       return "C++";
2430
2431     case lang_java:
2432       return "Java";
2433
2434     default:
2435       my_friendly_abort (355);
2436       return 0;
2437     }
2438 }
2439
2440 /* Return the proper printed version of a parameter to a C++ function.  */
2441
2442 static const char *
2443 parm_to_string (p, v)
2444      int p;
2445      int v ATTRIBUTE_UNUSED;
2446 {
2447   if (p < 0)
2448     return "`this'";
2449
2450   sprintf (digit_buffer, "%d", p+1);
2451   return digit_buffer;
2452 }
2453
2454 static const char *
2455 op_to_string (p, v)
2456      enum tree_code p;
2457      int v ATTRIBUTE_UNUSED;
2458 {
2459   tree id;
2460
2461   id = operator_name_info[(int) p].identifier;
2462   return id ? IDENTIFIER_POINTER (id) : "{unknown}";
2463 }
2464
2465 static const char *
2466 type_to_string (typ, verbose)
2467      tree typ;
2468      int verbose;
2469 {
2470   enum tree_string_flags flags;
2471
2472   flags = 0;
2473   if (verbose)
2474     flags |= TS_AGGR_TAGS;
2475   flags |= TS_TEMPLATE_PREFIX;
2476
2477   OB_INIT ();
2478
2479   dump_type (typ, flags);
2480
2481   OB_FINISH ();
2482
2483   return (char *)obstack_base (&scratch_obstack);
2484 }
2485
2486 static const char *
2487 assop_to_string (p, v)
2488      enum tree_code p;
2489      int v ATTRIBUTE_UNUSED;
2490 {
2491   tree id;
2492
2493   id = assignment_operator_name_info[(int) p].identifier;
2494   return id ? IDENTIFIER_POINTER (id) : "{unknown}";
2495 }
2496
2497 static const char *
2498 args_to_string (p, verbose)
2499      tree p;
2500      int verbose;
2501 {
2502   enum tree_string_flags flags = 0;
2503   if (verbose)
2504     flags |= TS_AGGR_TAGS;
2505
2506   if (p == NULL_TREE)
2507     return "";
2508
2509   if (TYPE_P (TREE_VALUE (p)))
2510     return type_as_string (p, flags);
2511
2512   OB_INIT ();
2513   for (; p; p = TREE_CHAIN (p))
2514     {
2515       if (TREE_VALUE (p) == null_node)
2516         OB_PUTS ("NULL");
2517       else
2518         dump_type (error_type (TREE_VALUE (p)), flags);
2519       if (TREE_CHAIN (p))
2520         OB_PUTS (", ");
2521     }
2522   OB_FINISH ();
2523   return (char *)obstack_base (&scratch_obstack);
2524 }
2525
2526 static const char *
2527 cv_to_string (p, v)
2528      tree p;
2529      int v ATTRIBUTE_UNUSED;
2530 {
2531   OB_INIT ();
2532
2533   dump_qualifiers (p, before);
2534
2535   OB_FINISH ();
2536
2537   return (char *)obstack_base (&scratch_obstack);
2538 }
2539
2540 static void
2541 lang_print_error_function (file)
2542      const char *file;
2543 {
2544   output_state os;
2545
2546   default_print_error_function (file);
2547   os = output_buffer_state (diagnostic_buffer);
2548   output_set_prefix (diagnostic_buffer, file);
2549   maybe_print_instantiation_context (diagnostic_buffer);
2550   output_buffer_state (diagnostic_buffer) = os;
2551 }
2552
2553 static void
2554 cp_diagnostic_starter (buffer, dc)
2555      output_buffer *buffer;
2556      diagnostic_context *dc;
2557 {
2558   report_problematic_module (buffer);
2559   cp_print_error_function (buffer, dc);
2560   maybe_print_instantiation_context (buffer);
2561   output_set_prefix (buffer,
2562                      context_as_prefix (diagnostic_file_location (dc),
2563                                         diagnostic_line_location (dc),
2564                                         diagnostic_is_warning (dc)));
2565 }
2566
2567 static void
2568 cp_diagnostic_finalizer (buffer, dc)
2569      output_buffer *buffer;
2570      diagnostic_context *dc __attribute__ ((__unused__));
2571 {
2572   output_destroy_prefix (buffer);
2573 }
2574
2575 /* Print current function onto BUFFER, in the process of reporting
2576    a diagnostic message.  Called from cp_diagnostic_starter.  */
2577 static void
2578 cp_print_error_function (buffer, dc)
2579      output_buffer *buffer;
2580      diagnostic_context *dc;
2581 {
2582   if (error_function_changed ())
2583     {
2584       char *prefix = diagnostic_file_location (dc)
2585         ? file_name_as_prefix (diagnostic_file_location (dc))
2586         : NULL;
2587       output_state os;
2588
2589       os = output_buffer_state (buffer);
2590       output_set_prefix (buffer, prefix);
2591
2592       if (current_function_decl == NULL)
2593         output_add_string (buffer, "At global scope:");
2594       else
2595         output_printf
2596           (buffer, "In %s `%s':", function_category (current_function_decl),
2597            (*decl_printable_name) (current_function_decl, 2));
2598       output_add_newline (buffer);
2599
2600       record_last_error_function ();
2601       output_destroy_prefix (buffer);
2602       output_buffer_state (buffer) = os;
2603     }
2604 }
2605
2606 /* Returns a description of FUNCTION using standard terminology.  */
2607 static const char *
2608 function_category (fn)
2609      tree fn;
2610 {
2611   if (DECL_FUNCTION_MEMBER_P (fn))
2612     {
2613       if (DECL_STATIC_FUNCTION_P (fn))
2614         return "static member function";
2615       else if (DECL_COPY_CONSTRUCTOR_P (fn))
2616         return "copy constructor";
2617       else if (DECL_CONSTRUCTOR_P (fn))
2618         return "constructor";
2619       else if (DECL_DESTRUCTOR_P (fn))
2620         return "destructor";
2621       else
2622         return "member function";
2623     }
2624   else
2625     return "function";
2626 }
2627
2628 /* Report the full context of a current template instantiation,
2629    onto BUFFER.  */
2630 static void
2631 print_instantiation_full_context (buffer)
2632      output_buffer *buffer;
2633 {
2634   tree p = current_instantiation ();
2635   int line = lineno;
2636   const char *file = input_filename;
2637
2638   if (p)
2639     {
2640       if (current_function_decl != TINST_DECL (p)
2641           && current_function_decl != NULL_TREE)
2642         /* We can get here during the processing of some synthesized
2643            method.  Then, TINST_DECL (p) will be the function that's causing
2644            the synthesis.  */
2645         ;
2646       else
2647         {
2648           if (current_function_decl == TINST_DECL (p))
2649             /* Avoid redundancy with the the "In function" line.  */;
2650           else
2651             output_verbatim (buffer, "%s: In instantiation of `%s':\n", file,
2652                              decl_as_string (TINST_DECL (p),
2653                                              TS_DECL_TYPE | TS_FUNC_NORETURN));
2654
2655           line = TINST_LINE (p);
2656           file = TINST_FILE (p);
2657           p = TREE_CHAIN (p);
2658         }
2659     }
2660
2661   print_instantiation_partial_context (buffer, p, file, line);
2662 }
2663
2664 /* Same as above but less verbose.  */
2665 static void
2666 print_instantiation_partial_context (buffer, t, file, line)
2667      output_buffer *buffer;
2668      tree t;
2669      const char *file;
2670      int line;
2671 {
2672   for (; t; t = TREE_CHAIN (t))
2673     {
2674       output_verbatim
2675         (buffer, "%s:%d:   instantiated from `%s'\n", file, line,
2676          decl_as_string (TINST_DECL (t), TS_DECL_TYPE | TS_FUNC_NORETURN));
2677       line = TINST_LINE (t);
2678       file = TINST_FILE (t);
2679     }
2680   output_verbatim (buffer, "%s:%d:   instantiated from here\n", file, line);
2681 }
2682
2683 /* Called from cp_thing to print the template context for an error.  */
2684 static void
2685 maybe_print_instantiation_context (buffer)
2686      output_buffer *buffer;
2687 {
2688   if (!problematic_instantiation_changed () || current_instantiation () == 0)
2689     return;
2690
2691   record_last_problematic_instantiation ();
2692   print_instantiation_full_context (buffer);
2693 }
2694
2695 /* Report the bare minimum context of a template instantiation.  */
2696 void
2697 print_instantiation_context ()
2698 {
2699   print_instantiation_partial_context
2700     (diagnostic_buffer, current_instantiation (), input_filename, lineno);
2701   flush_diagnostic_buffer ();
2702 }
2703 \f
2704 /* Called from output_format -- during diagnostic message processing --
2705    to handle C++ specific format specifier with the following meanings:
2706    %A   function argument-list.
2707    %D   declaration.
2708    %E   expression.
2709    %F   function declaration.
2710    %P   function parameter whose position is indicated by an integer.
2711    %T   type.
2712    %V   cv-qualifier.  */
2713 static int
2714 cp_tree_printer (buffer)
2715      output_buffer *buffer;
2716 {
2717   int be_verbose = 0;
2718   tree_formatting_info tfi;
2719
2720   bzero (&tfi, sizeof (tree_formatting_info));
2721
2722   if (*output_buffer_text_cursor (buffer) == '+')
2723     ++output_buffer_text_cursor (buffer);
2724   if (*output_buffer_text_cursor (buffer) == '#')
2725     {
2726       be_verbose = 1;
2727       ++output_buffer_text_cursor (buffer);
2728     }
2729
2730   switch (*output_buffer_text_cursor (buffer))
2731     {
2732     case 'A':
2733       tree_being_formatted (&tfi) =
2734         va_arg (output_buffer_format_args (buffer), tree);
2735       if (be_verbose)
2736         tree_formatting_flags (&tfi) = TFF_SCOPE
2737           | TFF_FUNCTION_DEFAULT_ARGUMENTS;
2738       print_function_argument_list (buffer, &tfi);
2739       break;
2740
2741     case 'D':
2742       tree_being_formatted (&tfi) =
2743         va_arg (output_buffer_format_args (buffer), tree);
2744       if (be_verbose)
2745         tree_formatting_flags (&tfi) = TFF_SCOPE | TFF_DECL_SPECIFIERS
2746           | TFF_CLASS_KEY_OR_ENUM | TFF_RETURN_TYPE
2747           | TFF_FUNCTION_DEFAULT_ARGUMENTS | TFF_TEMPLATE_DEFAULT_ARGUMENTS
2748           | TFF_EXCEPTION_SPECIFICATION | TFF_CHASE_NAMESPACE_ALIAS;
2749       print_declaration (buffer, &tfi);
2750       break;
2751
2752     case 'E':
2753       tree_being_formatted (&tfi) =
2754         va_arg (output_buffer_format_args (buffer), tree);
2755       if (be_verbose)
2756         tree_formatting_flags (&tfi) = TFF_SCOPE;
2757       print_expression (buffer, &tfi);
2758       break;
2759
2760     case 'F':
2761       tree_being_formatted (&tfi) =
2762         va_arg (output_buffer_format_args (buffer), tree);
2763       if (be_verbose)
2764         tree_formatting_flags (&tfi) = TFF_SCOPE | TFF_DECL_SPECIFIERS
2765           | TFF_RETURN_TYPE | TFF_FUNCTION_DEFAULT_ARGUMENTS
2766           | TFF_EXCEPTION_SPECIFICATION;
2767       print_function_declaration (buffer, &tfi);
2768       break;
2769
2770     case 'P':
2771       print_function_parameter
2772         (buffer, va_arg (output_buffer_format_args (buffer), int));
2773       break;
2774
2775     case 'T':
2776       tree_being_formatted (&tfi) =
2777         va_arg (output_buffer_format_args (buffer), tree);
2778       if (be_verbose)
2779         tree_formatting_flags (&tfi) = TFF_SCOPE | TFF_CLASS_KEY_OR_ENUM
2780           | TFF_RETURN_TYPE | TFF_EXCEPTION_SPECIFICATION;
2781       print_type_id (buffer, &tfi);
2782       break;
2783
2784     case 'V':
2785       tree_being_formatted (&tfi) =
2786         va_arg (output_buffer_format_args (buffer), tree);
2787       print_cv_qualifier_seq (buffer, &tfi);
2788       break;
2789
2790     default:
2791       return 0;
2792     }
2793
2794   return 1;
2795 }
2796
2797 /* Print a function argument-list represented by tree_being_formatted (TFI)
2798    onto BUFFER.  */
2799 static void
2800 print_function_argument_list (buffer, tfi)
2801      output_buffer *buffer __attribute__ ((__unused__));
2802      tfi_t tfi __attribute__  ((__unused__));
2803 {
2804 }
2805
2806 /* Print a declaration represented by tree_being_formatted (TFI)
2807    onto buffer.  */
2808 static void
2809 print_declaration (buffer, tfi)
2810      output_buffer *buffer __attribute__ ((__unused__));
2811      tfi_t tfi __attribute__ ((__unused__));
2812 {
2813 }
2814
2815 /* Print an expression represented by tree_being_formatted (TFI)
2816    onto BUFFER.  */
2817 static void
2818 print_expression (buffer, tfi)
2819      output_buffer *buffer __attribute__ ((__unused__));
2820      tfi_t tfi __attribute__ ((__unused__));
2821 {
2822 }
2823
2824 /* Print a function declaration represented by tree_being_formatted (TFI)
2825    onto BUFFER.  */
2826 static void
2827 print_function_declaration (buffer, tfi)
2828      output_buffer *buffer __attribute__ ((__unused__));
2829      tfi_t tfi __attribute__ ((__unused__));
2830 {
2831 }
2832
2833 /* Print the N'th function parameter onto BUFFER.  A negative value of N
2834    means the implicit "this" parameter of a member function.  */
2835 static void
2836 print_function_parameter (buffer, n)
2837      output_buffer *buffer;
2838      int n;
2839 {
2840   if (n < 0)
2841     print_identifier (buffer, "this");
2842   else
2843     output_decimal (buffer, n + 1);
2844 }
2845 \f
2846 /* Print a type represented by tree_being_formatted (TFI) onto BUFFER.  */
2847 static void
2848 print_type_id (buffer, tfi)
2849      output_buffer *buffer;
2850      tfi_t tfi;
2851 {
2852   tree t = tree_being_formatted (tfi);
2853   int flags = tree_formatting_flags (tfi);
2854   if (t == NULL_TREE)
2855     return;
2856
2857   if (flags & TFF_CHASE_TYPEDEF)
2858     tree_being_formatted (tfi) =
2859       typedef_original_name (tree_being_formatted (tfi));
2860
2861   /* A type-id is of the form:
2862      type-id:
2863         type-specifier-seq abstract-declarator(opt)  */
2864   print_type_specifier_seq (buffer, tfi);
2865
2866   if (TYPE_PTRMEMFUNC_P (t))
2867     goto ptr_mem_fun;
2868
2869   /* For types with abstract-declarator, print_type_specifier_seq prints
2870      the start of the abstract-declarator.  Fiinish the job.  */
2871   switch (TREE_CODE (t))
2872     {
2873     case ARRAY_TYPE:
2874     case POINTER_TYPE:
2875     case REFERENCE_TYPE:
2876     case OFFSET_TYPE:
2877     case METHOD_TYPE:
2878     case FUNCTION_TYPE:
2879     ptr_mem_fun:
2880       print_rest_of_abstract_declarator (buffer, tfi);
2881
2882     default:
2883       break;
2884     }
2885
2886   tree_being_formatted (tfi) = t;
2887 }
2888
2889 /* Print the type-specifier-seq part of a type-id.  If appropriate, print
2890  also the prefix of the abstract-declarator.  */
2891 static void
2892 print_type_specifier_seq (buffer, tfi)
2893      output_buffer *buffer;
2894      tfi_t tfi;
2895 {
2896   int flags = tree_formatting_flags (tfi);
2897   tree t = tree_being_formatted (tfi);
2898   enum tree_code code = TREE_CODE (t);
2899
2900   /* A type-speficier-seq is:
2901          type-specifier type-specifier-seq(opt)
2902      where
2903          type-specifier:
2904              simple-type-specifier
2905              class-specifier
2906              enum-specifier
2907              elaborated-type-specifier
2908              cv-qualifier
2909
2910      We do not, however, pretty-print class-specifier nor enum-specifier.  */
2911
2912   switch (code)
2913     {
2914     case UNKNOWN_TYPE:
2915     case IDENTIFIER_NODE:
2916     case VOID_TYPE:
2917     case INTEGER_TYPE:
2918     case REAL_TYPE:
2919     case COMPLEX_TYPE:
2920     case ENUMERAL_TYPE:
2921     case BOOLEAN_TYPE:
2922     case UNION_TYPE:
2923     case TYPE_DECL:
2924     case TEMPLATE_DECL:
2925     case TEMPLATE_TYPE_PARM:
2926     case TYPEOF_TYPE:
2927     case TEMPLATE_TEMPLATE_PARM:
2928     case TYPENAME_TYPE:
2929     class_type:
2930       print_cv_qualifier_seq (buffer, tfi);
2931       if ((flags & TFF_DECL_SPECIFIERS)
2932           && (code ==  TYPENAME_TYPE || IS_AGGR_TYPE (t)))
2933         print_elaborated_type_specifier (buffer, tfi);
2934       else
2935         print_simple_type_specifier (buffer, tfi);
2936       break;
2937
2938       /* Because the abstract-declarator can modify the type-specifier-seq
2939          in a highly non linear manner, we pretty-print its prefix here.
2940          The suffix part is handled by print_rest_of_abstract_declarator.  */
2941
2942       /* A RECORD_TYPE is also used to represent a pointer to member
2943          function.  */
2944     case RECORD_TYPE:
2945       if (TYPE_PTRMEMFUNC_P (t))
2946         {
2947           /* Print the return type.  */
2948           tree_being_formatted (tfi) =
2949             TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (t));
2950           print_type_id (buffer, tfi);
2951           print_whitespace (buffer, tfi);
2952
2953           /* Then the beginning of the abstract-declarator part.  */
2954           tree_being_formatted (tfi) =
2955             TYPE_METHOD_BASETYPE (TYPE_PTRMEMFUNC_FN_TYPE (t));
2956           print_left_paren (buffer);
2957           print_nested_name_specifier (buffer, tfi);
2958         }
2959       else
2960         goto class_type;
2961       break;
2962
2963     case POINTER_TYPE:
2964       if (TYPE_PTRMEM_P (t))
2965         goto ptr_data_member;
2966       else
2967         goto non_ptr_data_member;
2968       break;
2969
2970     case ARRAY_TYPE:
2971     case REFERENCE_TYPE:
2972     case FUNCTION_TYPE:
2973     case METHOD_TYPE:
2974     non_ptr_data_member:
2975       tree_being_formatted (tfi) = TREE_TYPE (t);
2976       print_type_specifier_seq (buffer, tfi);
2977       if (code == POINTER_TYPE || code == REFERENCE_TYPE)
2978         {
2979           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
2980             print_left_paren (buffer);
2981         }
2982       else if (code == FUNCTION_TYPE || code == METHOD_TYPE)
2983         {
2984           print_whitespace (buffer, tfi);
2985           print_left_paren (buffer);
2986           if (code == METHOD_TYPE)
2987             {
2988               tree_being_formatted (tfi) = TYPE_METHOD_BASETYPE (t);
2989               print_nested_name_specifier (buffer, tfi);
2990               tree_being_formatted (tfi) = t;
2991             }
2992         }
2993       tree_being_formatted (tfi) = t;
2994       break;
2995
2996     ptr_data_member:
2997     case OFFSET_TYPE:
2998       /* Firstly, the type of the member.  */
2999       tree_being_formatted (tfi) = TREE_TYPE (t);
3000       print_type_id (buffer, tfi);
3001       print_whitespace (buffer, tfi);
3002
3003       /* Then, the containing class.  */
3004       tree_being_formatted (tfi) = TYPE_OFFSET_BASETYPE (t);
3005       print_nested_name_specifier (buffer, tfi);
3006       tree_being_formatted (tfi) = t;
3007       break;
3008
3009     default:
3010       sorry_for_unsupported_tree (t);
3011       /* fall throught  */
3012
3013     case ERROR_MARK:
3014       print_identifier (buffer, "{type-specifier-seq error}");
3015       break;
3016     }
3017
3018   tree_being_formatted (tfi) = t;
3019 }
3020
3021 /* Print the simpe-type-specifier component of a type-specifier.  */
3022 static void
3023 print_simple_type_specifier (buffer, tfi)
3024      output_buffer *buffer;
3025      tfi_t tfi;
3026 {
3027   int flags = tree_formatting_flags (tfi);
3028   tree t = tree_being_formatted (tfi);
3029   enum tree_code code = TREE_CODE (t);
3030
3031   switch (code)
3032     {
3033     case UNKNOWN_TYPE:
3034       print_identifier (buffer, "{unknown type}");
3035       break;
3036
3037     case IDENTIFIER_NODE:
3038       print_tree_identifier (buffer, t);
3039       break;
3040
3041     case COMPLEX_TYPE:
3042       print_identifier (buffer, "__complex__ ");
3043       tree_being_formatted (tfi) = TREE_TYPE (t);
3044       print_type_id (buffer, tfi);
3045       break;
3046
3047     case TYPENAME_TYPE:
3048       tree_being_formatted (tfi) = TYPE_CONTEXT (t);
3049       print_nested_name_specifier (buffer, tfi);
3050       tree_being_formatted (tfi) = TYPENAME_TYPE_FULLNAME (t);
3051       tree_formatting_flags (tfi) |= ~TFF_CHASE_TYPEDEF;
3052       print_type_id (buffer, tfi);
3053       break;
3054
3055     case TYPEOF_TYPE:
3056       print_identifier (buffer, "__typeof__");
3057       tree_being_formatted (tfi) = TYPE_FIELDS (t);
3058       print_left_paren (buffer);
3059       print_expression (buffer, tfi);
3060       print_right_paren (buffer);
3061       break;
3062
3063     case INTEGER_TYPE:
3064       if (TREE_UNSIGNED (t))
3065         {
3066           if (TYPE_MAIN_VARIANT (t) == integer_type_node)
3067             /* We don't want pedantry like `unsigned int'.  */;
3068           else if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)))
3069             {
3070               print_identifier (buffer, "unsigned");
3071               print_whitespace (buffer, tfi);
3072             }
3073         }
3074       else if (TYPE_MAIN_VARIANT (t) == char_type_node)
3075         {
3076           print_identifier (buffer, "signed");
3077           print_whitespace (buffer, tfi);
3078         }
3079     case REAL_TYPE:
3080     case BOOLEAN_TYPE:
3081     case VOID_TYPE:
3082       {
3083         tree s = (flags & TFF_CHASE_TYPEDEF) ? TYPE_MAIN_VARIANT (t) : t;
3084
3085         if (TYPE_NAME (s) && TYPE_IDENTIFIER (s))
3086           print_tree_identifier (buffer, TYPE_IDENTIFIER (s));
3087         else
3088           /* Types like intQI_type_node and friends have no names.
3089              These don't come up in user error messages, but it's nice
3090              to be able to print them from the debugger.  */
3091           print_identifier (buffer, "{anonymous}");
3092       }
3093       break;
3094
3095     case TEMPLATE_TEMPLATE_PARM:
3096       if (TYPE_IDENTIFIER (t))
3097         print_tree_identifier (buffer, TYPE_IDENTIFIER (t));
3098       else
3099         print_identifier (buffer, "{anonymous template template parameter}");
3100       break;
3101
3102     case TYPE_DECL:
3103       if (flags & TFF_CHASE_TYPEDEF)
3104         print_type_id (buffer, tfi);
3105       else
3106         print_tree_identifier (buffer, DECL_NAME (t));
3107       break;
3108
3109     case BOUND_TEMPLATE_TEMPLATE_PARM:
3110     case TEMPLATE_DECL:
3111       print_template_id (buffer, tfi);
3112       break;
3113
3114     case TEMPLATE_TYPE_PARM:
3115       if (TYPE_IDENTIFIER (t))
3116         print_tree_identifier (buffer, TYPE_IDENTIFIER (t));
3117       else
3118         print_identifier (buffer, "{anonymous template type parameter}");
3119       break;
3120
3121     default:
3122       break;
3123     }
3124
3125   tree_being_formatted (tfi) = t;
3126   tree_formatting_flags (tfi) = flags;
3127 }
3128
3129 /* Print the elaborated-type-specifier form of a type-specifier.  */
3130 static void
3131 print_elaborated_type_specifier (buffer, tfi)
3132      output_buffer *buffer;
3133      tfi_t tfi;
3134 {
3135   int flags = tree_formatting_flags (tfi);
3136   tree t = tree_being_formatted (tfi);
3137
3138   switch (TREE_CODE (t))
3139     {
3140     case TYPENAME_TYPE:
3141       print_identifier (buffer, "typename");
3142       print_whitespace (buffer, tfi);
3143       tree_formatting_flags (tfi) |= ~TFF_DECL_SPECIFIERS;
3144       print_simple_type_specifier (buffer, tfi);
3145       break;
3146
3147     case UNION_TYPE:
3148     case RECORD_TYPE:
3149       {
3150         tree name = NULL_TREE;
3151
3152         if (flags & TFF_CHASE_TYPEDEF)
3153           tree_being_formatted (tfi) = typedef_original_name (t);
3154
3155         print_identifier
3156           (buffer, class_key_or_enum (tree_being_formatted (tfi)));
3157         print_whitespace (buffer, tfi);
3158
3159         name = TYPE_NAME (tree_being_formatted (tfi));
3160         if (name)
3161           {
3162             if (flags & TFF_SCOPE)
3163               {
3164                 tree_being_formatted (tfi) = CP_DECL_CONTEXT (name);
3165                 print_nested_name_specifier (buffer, tfi);
3166               }
3167             print_tree_identifier (buffer, DECL_NAME (name));
3168           }
3169         else
3170           print_identifier (buffer, "{anonymous}");
3171       }
3172       break;
3173
3174     default:
3175       sorry_for_unsupported_tree (t);
3176       break;
3177     }
3178
3179   tree_being_formatted (tfi) = t;
3180   tree_formatting_flags (tfi) = flags;
3181 }
3182
3183 /* Finish the job of printing the abstract-declarator part of a
3184    type-id.  */
3185 static void
3186 print_rest_of_abstract_declarator (buffer, tfi)
3187      output_buffer *buffer;
3188      tfi_t tfi;
3189 {
3190   tree t = tree_being_formatted (tfi);
3191   enum tree_code code = TREE_CODE (t);
3192
3193   /* An abstract-declarator has the form:
3194
3195      abstract-declarator:
3196           ptr-operator abstract-declarator(opt)
3197           direct-abstract-declarator
3198
3199      direct-abstract-declarator:
3200           direct-abstract-declarator(opt)
3201               ( parameter-declaration-clause ) cv-qualifier-seq(opt)
3202                     exception-specification(opt)
3203           direct-abstract-declarator(opt) [ constant-expression(opt) ]
3204           ( direct-abstract-declarator )   */
3205
3206   switch (code)
3207     {
3208     case ARRAY_TYPE:
3209       print_left_bracket (buffer);
3210       if (TYPE_DOMAIN (t))
3211         {
3212           tree s = TYPE_DOMAIN (t);
3213
3214           if (host_integerp (TYPE_MAX_VALUE (s), 0))
3215             output_decimal (buffer, tree_low_cst (TYPE_MAX_VALUE (s), 0) + 1);
3216           else if (TREE_CODE (TYPE_MAX_VALUE (s)) == MINUS_EXPR)
3217             {
3218               tree_being_formatted (tfi) =
3219                 TREE_OPERAND (TYPE_MAX_VALUE (s), 0);
3220               print_expression (buffer, tfi);
3221               tree_being_formatted (tfi) = t;
3222             }
3223           else
3224             {
3225               tree_being_formatted (tfi) = fold
3226                 (cp_build_binary_op (PLUS_EXPR, TYPE_MAX_VALUE (s),
3227                                      integer_one_node));
3228               print_expression (buffer, tfi);
3229               tree_being_formatted (tfi) = t;
3230             }
3231         }
3232       print_right_bracket (buffer);
3233       put_whitespace (tfi) = none;
3234       tree_being_formatted (tfi) = TREE_TYPE (t);
3235       print_rest_of_abstract_declarator (buffer, tfi);
3236       tree_being_formatted (tfi) = t;
3237       break;
3238
3239     case POINTER_TYPE:
3240     case REFERENCE_TYPE:
3241     case OFFSET_TYPE:
3242       if (code == POINTER_TYPE || code == REFERENCE_TYPE)
3243         {
3244           output_add_character (buffer, "&*"[code == POINTER_TYPE]);
3245           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
3246             print_right_paren (buffer);
3247         }
3248       put_whitespace (tfi) = before;
3249       print_cv_qualifier_seq (buffer, tfi);
3250       tree_being_formatted (tfi) = TREE_TYPE (t);
3251       print_rest_of_abstract_declarator (buffer, tfi);
3252       tree_being_formatted (tfi) = t;
3253       break;
3254
3255     case FUNCTION_TYPE:
3256     case METHOD_TYPE:
3257       print_right_paren (buffer);
3258       print_whitespace (buffer, tfi);
3259
3260       /* Skip the `this' implicit parameter if present.  */
3261       tree_being_formatted (tfi) = TYPE_ARG_TYPES (t);
3262       if (code == METHOD_TYPE)
3263         tree_being_formatted (tfi) = TREE_CHAIN (tree_being_formatted (tfi));
3264
3265       /* Print the parameter-list.  */
3266       print_left_paren (buffer);
3267       print_parameter_declaration_clause (buffer, tfi);
3268       print_right_paren (buffer);
3269
3270       print_whitespace (buffer, tfi);
3271
3272       if (code == METHOD_TYPE)
3273         {
3274           tree_being_formatted (tfi) =
3275             TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t)));
3276           print_cv_qualifier_seq (buffer, tfi);
3277         }
3278
3279       /* Finish the abstract-declarator.  */
3280       tree_being_formatted (tfi) = TREE_TYPE (t);
3281       print_rest_of_abstract_declarator (buffer, tfi);
3282
3283       /* Print the exception-specification for documentaion purpose.  */
3284       tree_being_formatted (tfi) = TYPE_RAISES_EXCEPTIONS (t);
3285       print_exception_specification (buffer, tfi);
3286       tree_being_formatted (tfi) = t;
3287       break;
3288
3289       /* These types don't have abstract-declarator.  */
3290     case UNKNOWN_TYPE:
3291     case IDENTIFIER_NODE:
3292     case VOID_TYPE:
3293     case INTEGER_TYPE:
3294     case REAL_TYPE:
3295     case COMPLEX_TYPE:
3296     case ENUMERAL_TYPE:
3297     case BOOLEAN_TYPE:
3298     case UNION_TYPE:
3299     case TYPE_DECL:
3300     case TEMPLATE_DECL:
3301     case TEMPLATE_TYPE_PARM:
3302     case TYPEOF_TYPE:
3303     case TEMPLATE_TEMPLATE_PARM:
3304     case TYPENAME_TYPE:
3305       break;
3306
3307     default:
3308       sorry_for_unsupported_tree (t);
3309       /* fall throught.  */
3310     case ERROR_MARK:
3311       break;
3312     }
3313 }
3314
3315 /* Print the cv-quafilers of tree_being_formatted (TFI) onto BUFFER.  */
3316 static void
3317 print_cv_qualifier_seq (buffer, tfi)
3318      output_buffer *buffer;
3319      tree_formatting_info *tfi;
3320 {
3321   int cv = TYPE_QUALS (tree_being_formatted (tfi));
3322   int pad_after = after == put_whitespace (tfi);
3323   static const int mask[]
3324     = {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
3325   static const char *const qualifier[]
3326     = { "const", "volatile", "__restrict__" };
3327
3328   if (cv != 0)
3329     {
3330       int i;
3331       for (i = 0; i != 3; ++i)
3332         if (mask[i] & cv)
3333           {
3334             if (put_whitespace (tfi) == before)
3335               output_add_space (buffer);
3336             print_identifier (buffer, qualifier[i]);
3337             put_whitespace (tfi) = before;
3338           }
3339
3340       if (pad_after)
3341         {
3342           output_add_space (buffer);
3343           put_whitespace (tfi) = none;
3344         }
3345     }
3346 }
3347
3348 static void
3349 print_parameter_declaration_clause (buffer, tfi)
3350      output_buffer *buffer __attribute__ ((__unused__));
3351      tfi_t tfi __attribute__ ((__unused__));
3352 {
3353 }
3354
3355 static void
3356 print_exception_specification (buffer, tfi)
3357      output_buffer *buffer __attribute__ ((__unused__));
3358      tfi_t tfi __attribute__ ((__unused__));
3359 {
3360 }
3361
3362 static void
3363 print_nested_name_specifier (buffer, tfi)
3364      output_buffer *buffer;
3365      tfi_t tfi;
3366 {
3367   int flags = tree_formatting_flags (tfi);
3368   tree t = tree_being_formatted (tfi);
3369   /* A nested-name-specifier is:
3370         class-or-namespace-name :: nested-name-specifier(opt)
3371         class-or-namespace-name :: template nested-name-specifier
3372
3373      The latter form being the correct syntax for a name  designating
3374      a template member, where the preceding class-or-namespace-name part
3375      is name-dependent.  For the time being, we do not do such a
3376      sophisticated pretty-printing.
3377
3378      class-or-namespace-name:
3379         class-name
3380         namespace-name  */
3381
3382   if (t == NULL_TREE || t == global_namespace)
3383     return;
3384
3385   if (CLASS_TYPE_P (t) && !(flags & TFF_CLASS_SCOPE))
3386     return;
3387
3388   if (TREE_CODE (t) == NAMESPACE_DECL && !(flags & TFF_NAMESPACE_SCOPE))
3389     return;
3390
3391   tree_being_formatted (tfi) = DECL_CONTEXT (t);
3392   print_nested_name_specifier (buffer, tfi);
3393   print_scope_operator (buffer);
3394   if (TREE_CODE (t) == NAMESPACE_DECL)
3395     print_tree_identifier (buffer, DECL_NAME (t));
3396   else if (CLASS_TYPE_P (t))
3397     {
3398       if (!DECL_USE_TEMPLATE (t))
3399         print_tree_identifier (buffer, TYPE_IDENTIFIER (t));
3400       else
3401         {
3402           tree_being_formatted (tfi) = t;
3403           print_template_id (buffer, tfi);
3404         }
3405     }
3406
3407   tree_being_formatted (tfi) = t;
3408 }
3409
3410 static void
3411 print_template_id (buffer, tfi)
3412      output_buffer *buffer;
3413      tfi_t tfi __attribute__ ((__unused__));
3414 {
3415   print_template_argument_list_start (buffer);
3416   /* ... */
3417   print_template_argument_list_end (buffer);
3418 }
3419
3420 static tree
3421 typedef_original_name (t)
3422      tree t;
3423 {
3424   return DECL_ORIGINAL_TYPE (t) ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t);
3425 }
3426
3427 static void
3428 print_template_argument_list_start (buffer)
3429      output_buffer *buffer __attribute__ ((__unused__));
3430 {
3431 }
3432
3433 static void
3434 print_template_argument_list_end (buffer)
3435      output_buffer *buffer __attribute__ ((__unused__));
3436 {
3437 }