Include string.h in common-defs.h
[external/binutils.git] / gdb / c-typeprint.c
1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2    Copyright (C) 1986-2014 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #include "defs.h"
20 #include "gdb_obstack.h"
21 #include "bfd.h"                /* Binary File Description.  */
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "expression.h"
25 #include "value.h"
26 #include "gdbcore.h"
27 #include "target.h"
28 #include "language.h"
29 #include "demangle.h"
30 #include "c-lang.h"
31 #include "typeprint.h"
32 #include "cp-abi.h"
33 #include "jv-lang.h"
34 #include <errno.h>
35 #include "cp-support.h"
36
37 static void c_type_print_varspec_prefix (struct type *,
38                                          struct ui_file *,
39                                          int, int, int,
40                                          const struct type_print_options *);
41
42 /* Print "const", "volatile", or address space modifiers.  */
43 static void c_type_print_modifier (struct type *,
44                                    struct ui_file *,
45                                    int, int);
46 \f
47
48 /* A callback function for cp_canonicalize_string_full that uses
49    find_typedef_in_hash.  */
50
51 static const char *
52 find_typedef_for_canonicalize (struct type *t, void *data)
53 {
54   return find_typedef_in_hash (data, t);
55 }
56
57 /* Print NAME on STREAM.  If the 'raw' field of FLAGS is not set,
58    canonicalize NAME using the local typedefs first.  */
59
60 static void
61 print_name_maybe_canonical (const char *name,
62                             const struct type_print_options *flags,
63                             struct ui_file *stream)
64 {
65   char *s = NULL;
66
67   if (!flags->raw)
68     s = cp_canonicalize_string_full (name,
69                                      find_typedef_for_canonicalize,
70                                      (void *) flags);
71
72   fputs_filtered (s ? s : name, stream);
73   xfree (s);
74 }
75
76 \f
77
78 /* LEVEL is the depth to indent lines by.  */
79
80 void
81 c_print_type (struct type *type,
82               const char *varstring,
83               struct ui_file *stream,
84               int show, int level,
85               const struct type_print_options *flags)
86 {
87   enum type_code code;
88   int demangled_args;
89   int need_post_space;
90   const char *local_name;
91
92   if (show > 0)
93     CHECK_TYPEDEF (type);
94
95   local_name = find_typedef_in_hash (flags, type);
96   if (local_name != NULL)
97     {
98       fputs_filtered (local_name, stream);
99       if (varstring != NULL && *varstring != '\0')
100         fputs_filtered (" ", stream);
101     }
102   else
103     {
104       c_type_print_base (type, stream, show, level, flags);
105       code = TYPE_CODE (type);
106       if ((varstring != NULL && *varstring != '\0')
107           /* Need a space if going to print stars or brackets;
108              but not if we will print just a type name.  */
109           || ((show > 0 || TYPE_NAME (type) == 0)
110               && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
111                   || code == TYPE_CODE_METHOD
112                   || (code == TYPE_CODE_ARRAY
113                       && !TYPE_VECTOR (type))
114                   || code == TYPE_CODE_MEMBERPTR
115                   || code == TYPE_CODE_METHODPTR
116                   || code == TYPE_CODE_REF)))
117         fputs_filtered (" ", stream);
118       need_post_space = (varstring != NULL && strcmp (varstring, "") != 0);
119       c_type_print_varspec_prefix (type, stream, show, 0, need_post_space,
120                                    flags);
121     }
122
123   if (varstring != NULL)
124     {
125       fputs_filtered (varstring, stream);
126
127       /* For demangled function names, we have the arglist as part of
128          the name, so don't print an additional pair of ()'s.  */
129       if (local_name == NULL)
130         {
131           demangled_args = strchr (varstring, '(') != NULL;
132           c_type_print_varspec_suffix (type, stream, show,
133                                        0, demangled_args,
134                                        flags);
135         }
136     }
137 }
138
139 /* Print a typedef using C syntax.  TYPE is the underlying type.
140    NEW_SYMBOL is the symbol naming the type.  STREAM is the stream on
141    which to print.  */
142
143 void
144 c_print_typedef (struct type *type,
145                  struct symbol *new_symbol,
146                  struct ui_file *stream)
147 {
148   CHECK_TYPEDEF (type);
149   fprintf_filtered (stream, "typedef ");
150   type_print (type, "", stream, 0);
151   if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0
152       || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))),
153                  SYMBOL_LINKAGE_NAME (new_symbol)) != 0
154       || TYPE_CODE (SYMBOL_TYPE (new_symbol)) == TYPE_CODE_TYPEDEF)
155     fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol));
156   fprintf_filtered (stream, ";\n");
157 }
158
159 /* If TYPE is a derived type, then print out derivation information.
160    Print only the actual base classes of this type, not the base
161    classes of the base classes.  I.e. for the derivation hierarchy:
162
163    class A { int a; };
164    class B : public A {int b; };
165    class C : public B {int c; };
166
167    Print the type of class C as:
168
169    class C : public B {
170    int c;
171    }
172
173    Not as the following (like gdb used to), which is not legal C++
174    syntax for derived types and may be confused with the multiple
175    inheritance form:
176
177    class C : public B : public A {
178    int c;
179    }
180
181    In general, gdb should try to print the types as closely as
182    possible to the form that they appear in the source code.  */
183
184 static void
185 cp_type_print_derivation_info (struct ui_file *stream,
186                                struct type *type,
187                                const struct type_print_options *flags)
188 {
189   const char *name;
190   int i;
191
192   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
193     {
194       wrap_here ("        ");
195       fputs_filtered (i == 0 ? ": " : ", ", stream);
196       fprintf_filtered (stream, "%s%s ",
197                         BASETYPE_VIA_PUBLIC (type, i)
198                         ? "public" : (TYPE_FIELD_PROTECTED (type, i)
199                                       ? "protected" : "private"),
200                         BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
201       name = type_name_no_tag (TYPE_BASECLASS (type, i));
202       if (name)
203         print_name_maybe_canonical (name, flags, stream);
204       else
205         fprintf_filtered (stream, "(null)");
206     }
207   if (i > 0)
208     {
209       fputs_filtered (" ", stream);
210     }
211 }
212
213 /* Print the C++ method arguments ARGS to the file STREAM.  */
214
215 static void
216 cp_type_print_method_args (struct type *mtype, const char *prefix,
217                            const char *varstring, int staticp,
218                            struct ui_file *stream,
219                            const struct type_print_options *flags)
220 {
221   struct field *args = TYPE_FIELDS (mtype);
222   int nargs = TYPE_NFIELDS (mtype);
223   int varargs = TYPE_VARARGS (mtype);
224   int i;
225
226   fprintf_symbol_filtered (stream, prefix,
227                            language_cplus, DMGL_ANSI);
228   fprintf_symbol_filtered (stream, varstring,
229                            language_cplus, DMGL_ANSI);
230   fputs_filtered ("(", stream);
231
232   /* Skip the class variable.  */
233   i = staticp ? 0 : 1;
234   if (nargs > i)
235     {
236       while (i < nargs)
237         {
238           c_print_type (args[i++].type, "", stream, 0, 0, flags);
239
240           if (i == nargs && varargs)
241             fprintf_filtered (stream, ", ...");
242           else if (i < nargs)
243             {
244               fprintf_filtered (stream, ", ");
245               wrap_here ("        ");
246             }
247         }
248     }
249   else if (varargs)
250     fprintf_filtered (stream, "...");
251   else if (current_language->la_language == language_cplus)
252     fprintf_filtered (stream, "void");
253
254   fprintf_filtered (stream, ")");
255
256   /* For non-static methods, read qualifiers from the type of
257      THIS.  */
258   if (!staticp)
259     {
260       struct type *domain;
261
262       gdb_assert (nargs > 0);
263       gdb_assert (TYPE_CODE (args[0].type) == TYPE_CODE_PTR);
264       domain = TYPE_TARGET_TYPE (args[0].type);
265
266       if (TYPE_CONST (domain))
267         fprintf_filtered (stream, " const");
268
269       if (TYPE_VOLATILE (domain))
270         fprintf_filtered (stream, " volatile");
271
272       if (TYPE_RESTRICT (domain))
273         fprintf_filtered (stream, " restrict");
274     }
275 }
276
277
278 /* Print any asterisks or open-parentheses needed before the
279    variable name (to describe its type).
280
281    On outermost call, pass 0 for PASSED_A_PTR.
282    On outermost call, SHOW > 0 means should ignore
283    any typename for TYPE and show its details.
284    SHOW is always zero on recursive calls.
285    
286    NEED_POST_SPACE is non-zero when a space will be be needed
287    between a trailing qualifier and a field, variable, or function
288    name.  */
289
290 static void
291 c_type_print_varspec_prefix (struct type *type,
292                              struct ui_file *stream,
293                              int show, int passed_a_ptr,
294                              int need_post_space,
295                              const struct type_print_options *flags)
296 {
297   const char *name;
298
299   if (type == 0)
300     return;
301
302   if (TYPE_NAME (type) && show <= 0)
303     return;
304
305   QUIT;
306
307   switch (TYPE_CODE (type))
308     {
309     case TYPE_CODE_PTR:
310       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
311                                    stream, show, 1, 1, flags);
312       fprintf_filtered (stream, "*");
313       c_type_print_modifier (type, stream, 1, need_post_space);
314       break;
315
316     case TYPE_CODE_MEMBERPTR:
317       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
318                                    stream, show, 0, 0, flags);
319       name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
320       if (name)
321         print_name_maybe_canonical (name, flags, stream);
322       else
323         c_type_print_base (TYPE_DOMAIN_TYPE (type),
324                            stream, -1, passed_a_ptr, flags);
325       fprintf_filtered (stream, "::*");
326       break;
327
328     case TYPE_CODE_METHODPTR:
329       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
330                                    stream, show, 0, 0, flags);
331       fprintf_filtered (stream, "(");
332       name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
333       if (name)
334         print_name_maybe_canonical (name, flags, stream);
335       else
336         c_type_print_base (TYPE_DOMAIN_TYPE (type),
337                            stream, -1, passed_a_ptr, flags);
338       fprintf_filtered (stream, "::*");
339       break;
340
341     case TYPE_CODE_REF:
342       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
343                                    stream, show, 1, 0, flags);
344       fprintf_filtered (stream, "&");
345       c_type_print_modifier (type, stream, 1, need_post_space);
346       break;
347
348     case TYPE_CODE_METHOD:
349     case TYPE_CODE_FUNC:
350       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
351                                    stream, show, 0, 0, flags);
352       if (passed_a_ptr)
353         fprintf_filtered (stream, "(");
354       break;
355
356     case TYPE_CODE_ARRAY:
357       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
358                                    stream, show, 0, 0, flags);
359       if (passed_a_ptr)
360         fprintf_filtered (stream, "(");
361       break;
362
363     case TYPE_CODE_TYPEDEF:
364       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
365                                    stream, show, passed_a_ptr, 0, flags);
366       break;
367
368     case TYPE_CODE_UNDEF:
369     case TYPE_CODE_STRUCT:
370     case TYPE_CODE_UNION:
371     case TYPE_CODE_ENUM:
372     case TYPE_CODE_INT:
373     case TYPE_CODE_FLT:
374     case TYPE_CODE_VOID:
375     case TYPE_CODE_ERROR:
376     case TYPE_CODE_CHAR:
377     case TYPE_CODE_BOOL:
378     case TYPE_CODE_SET:
379     case TYPE_CODE_RANGE:
380     case TYPE_CODE_STRING:
381     case TYPE_CODE_COMPLEX:
382     case TYPE_CODE_NAMESPACE:
383     case TYPE_CODE_DECFLOAT:
384       /* These types need no prefix.  They are listed here so that
385          gcc -Wall will reveal any types that haven't been handled.  */
386       break;
387     default:
388       error (_("type not handled in c_type_print_varspec_prefix()"));
389       break;
390     }
391 }
392
393 /* Print out "const" and "volatile" attributes,
394    and address space id if present.
395    TYPE is a pointer to the type being printed out.
396    STREAM is the output destination.
397    NEED_PRE_SPACE = 1 indicates an initial white space is needed.
398    NEED_POST_SPACE = 1 indicates a final white space is needed.  */
399
400 static void
401 c_type_print_modifier (struct type *type, struct ui_file *stream,
402                        int need_pre_space, int need_post_space)
403 {
404   int did_print_modifier = 0;
405   const char *address_space_id;
406
407   /* We don't print `const' qualifiers for references --- since all
408      operators affect the thing referenced, not the reference itself,
409      every reference is `const'.  */
410   if (TYPE_CONST (type)
411       && TYPE_CODE (type) != TYPE_CODE_REF)
412     {
413       if (need_pre_space)
414         fprintf_filtered (stream, " ");
415       fprintf_filtered (stream, "const");
416       did_print_modifier = 1;
417     }
418
419   if (TYPE_VOLATILE (type))
420     {
421       if (did_print_modifier || need_pre_space)
422         fprintf_filtered (stream, " ");
423       fprintf_filtered (stream, "volatile");
424       did_print_modifier = 1;
425     }
426
427   if (TYPE_RESTRICT (type))
428     {
429       if (did_print_modifier || need_pre_space)
430         fprintf_filtered (stream, " ");
431       fprintf_filtered (stream, "restrict");
432       did_print_modifier = 1;
433     }
434
435   address_space_id = address_space_int_to_name (get_type_arch (type),
436                                                 TYPE_INSTANCE_FLAGS (type));
437   if (address_space_id)
438     {
439       if (did_print_modifier || need_pre_space)
440         fprintf_filtered (stream, " ");
441       fprintf_filtered (stream, "@%s", address_space_id);
442       did_print_modifier = 1;
443     }
444
445   if (did_print_modifier && need_post_space)
446     fprintf_filtered (stream, " ");
447 }
448
449
450 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
451    or TYPE_CODE_FUNC, to STREAM.  Artificial arguments, such as "this"
452    in non-static methods, are displayed if LINKAGE_NAME is zero.  If
453    LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
454    parameter types get removed their possible const and volatile qualifiers to
455    match demangled linkage name parameters part of such function type.
456    LANGUAGE is the language in which TYPE was defined.  This is a necessary
457    evil since this code is used by the C, C++, and Java backends.  */
458
459 void
460 c_type_print_args (struct type *type, struct ui_file *stream,
461                    int linkage_name, enum language language,
462                    const struct type_print_options *flags)
463 {
464   int i;
465   int printed_any = 0;
466
467   fprintf_filtered (stream, "(");
468
469   for (i = 0; i < TYPE_NFIELDS (type); i++)
470     {
471       struct type *param_type;
472
473       if (TYPE_FIELD_ARTIFICIAL (type, i) && linkage_name)
474         continue;
475
476       if (printed_any)
477         {
478           fprintf_filtered (stream, ", ");
479           wrap_here ("    ");
480         }
481
482       param_type = TYPE_FIELD_TYPE (type, i);
483
484       if (language == language_cplus && linkage_name)
485         {
486           /* C++ standard, 13.1 Overloadable declarations, point 3, item:
487              - Parameter declarations that differ only in the presence or
488                absence of const and/or volatile are equivalent.
489
490              And the const/volatile qualifiers are not present in the mangled
491              names as produced by GCC.  */
492
493           param_type = make_cv_type (0, 0, param_type, NULL);
494         }
495
496       if (language == language_java)
497         java_print_type (param_type, "", stream, -1, 0, flags);
498       else
499         c_print_type (param_type, "", stream, -1, 0, flags);
500       printed_any = 1;
501     }
502
503   if (printed_any && TYPE_VARARGS (type))
504     {
505       /* Print out a trailing ellipsis for varargs functions.  Ignore
506          TYPE_VARARGS if the function has no named arguments; that
507          represents unprototyped (K&R style) C functions.  */
508       if (printed_any && TYPE_VARARGS (type))
509         {
510           fprintf_filtered (stream, ", ");
511           wrap_here ("    ");
512           fprintf_filtered (stream, "...");
513         }
514     }
515   else if (!printed_any
516            && ((TYPE_PROTOTYPED (type) && language != language_java)
517                || language == language_cplus))
518     fprintf_filtered (stream, "void");
519
520   fprintf_filtered (stream, ")");
521 }
522
523 /* Return true iff the j'th overloading of the i'th method of TYPE
524    is a type conversion operator, like `operator int () { ... }'.
525    When listing a class's methods, we don't print the return type of
526    such operators.  */
527
528 static int
529 is_type_conversion_operator (struct type *type, int i, int j)
530 {
531   /* I think the whole idea of recognizing type conversion operators
532      by their name is pretty terrible.  But I don't think our present
533      data structure gives us any other way to tell.  If you know of
534      some other way, feel free to rewrite this function.  */
535   const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
536
537   if (strncmp (name, "operator", 8) != 0)
538     return 0;
539
540   name += 8;
541   if (! strchr (" \t\f\n\r", *name))
542     return 0;
543
544   while (strchr (" \t\f\n\r", *name))
545     name++;
546
547   if (!('a' <= *name && *name <= 'z')
548       && !('A' <= *name && *name <= 'Z')
549       && *name != '_')
550     /* If this doesn't look like the start of an identifier, then it
551        isn't a type conversion operator.  */
552     return 0;
553   else if (strncmp (name, "new", 3) == 0)
554     name += 3;
555   else if (strncmp (name, "delete", 6) == 0)
556     name += 6;
557   else
558     /* If it doesn't look like new or delete, it's a type conversion
559        operator.  */
560     return 1;
561
562   /* Is that really the end of the name?  */
563   if (('a' <= *name && *name <= 'z')
564       || ('A' <= *name && *name <= 'Z')
565       || ('0' <= *name && *name <= '9')
566       || *name == '_')
567     /* No, so the identifier following "operator" must be a type name,
568        and this is a type conversion operator.  */
569     return 1;
570
571   /* That was indeed the end of the name, so it was `operator new' or
572      `operator delete', neither of which are type conversion
573      operators.  */
574   return 0;
575 }
576
577 /* Given a C++ qualified identifier QID, strip off the qualifiers,
578    yielding the unqualified name.  The return value is a pointer into
579    the original string.
580
581    It's a pity we don't have this information in some more structured
582    form.  Even the author of this function feels that writing little
583    parsers like this everywhere is stupid.  */
584
585 static char *
586 remove_qualifiers (char *qid)
587 {
588   int quoted = 0;       /* Zero if we're not in quotes;
589                            '"' if we're in a double-quoted string;
590                            '\'' if we're in a single-quoted string.  */
591   int depth = 0;        /* Number of unclosed parens we've seen.  */
592   char *parenstack = (char *) alloca (strlen (qid));
593   char *scan;
594   char *last = 0;       /* The character after the rightmost
595                            `::' token we've seen so far.  */
596
597   for (scan = qid; *scan; scan++)
598     {
599       if (quoted)
600         {
601           if (*scan == quoted)
602             quoted = 0;
603           else if (*scan == '\\' && *(scan + 1))
604             scan++;
605         }
606       else if (scan[0] == ':' && scan[1] == ':')
607         {
608           /* If we're inside parenthesis (i.e., an argument list) or
609              angle brackets (i.e., a list of template arguments), then
610              we don't record the position of this :: token, since it's
611              not relevant to the top-level structure we're trying to
612              operate on.  */
613           if (depth == 0)
614             {
615               last = scan + 2;
616               scan++;
617             }
618         }
619       else if (*scan == '"' || *scan == '\'')
620         quoted = *scan;
621       else if (*scan == '(')
622         parenstack[depth++] = ')';
623       else if (*scan == '[')
624         parenstack[depth++] = ']';
625       /* We're going to treat <> as a pair of matching characters,
626          since we're more likely to see those in template id's than
627          real less-than characters.  What a crock.  */
628       else if (*scan == '<')
629         parenstack[depth++] = '>';
630       else if (*scan == ')' || *scan == ']' || *scan == '>')
631         {
632           if (depth > 0 && parenstack[depth - 1] == *scan)
633             depth--;
634           else
635             {
636               /* We're going to do a little error recovery here.  If
637                  we don't find a match for *scan on the paren stack,
638                  but there is something lower on the stack that does
639                  match, we pop the stack to that point.  */
640               int i;
641
642               for (i = depth - 1; i >= 0; i--)
643                 if (parenstack[i] == *scan)
644                   {
645                     depth = i;
646                     break;
647                   }
648             }
649         }
650     }
651
652   if (last)
653     return last;
654   else
655     /* We didn't find any :: tokens at the top level, so declare the
656        whole thing an unqualified identifier.  */
657     return qid;
658 }
659
660 /* Print any array sizes, function arguments or close parentheses
661    needed after the variable name (to describe its type).
662    Args work like c_type_print_varspec_prefix.  */
663
664 void
665 c_type_print_varspec_suffix (struct type *type,
666                              struct ui_file *stream,
667                              int show, int passed_a_ptr,
668                              int demangled_args,
669                              const struct type_print_options *flags)
670 {
671   if (type == 0)
672     return;
673
674   if (TYPE_NAME (type) && show <= 0)
675     return;
676
677   QUIT;
678
679   switch (TYPE_CODE (type))
680     {
681     case TYPE_CODE_ARRAY:
682       {
683         LONGEST low_bound, high_bound;
684         int is_vector = TYPE_VECTOR (type);
685
686         if (passed_a_ptr)
687           fprintf_filtered (stream, ")");
688
689         fprintf_filtered (stream, (is_vector ?
690                                    " __attribute__ ((vector_size(" : "["));
691         /* Bounds are not yet resolved, print a bounds placeholder instead.  */
692         if (TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCEXPR
693             || TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCLIST)
694           fprintf_filtered (stream, "variable length");
695         else if (get_array_bounds (type, &low_bound, &high_bound))
696           fprintf_filtered (stream, "%s", 
697                             plongest (high_bound - low_bound + 1));
698         fprintf_filtered (stream, (is_vector ? ")))" : "]"));
699
700         c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
701                                      show, 0, 0, flags);
702       }
703       break;
704
705     case TYPE_CODE_MEMBERPTR:
706       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
707                                    show, 0, 0, flags);
708       break;
709
710     case TYPE_CODE_METHODPTR:
711       fprintf_filtered (stream, ")");
712       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
713                                    show, 0, 0, flags);
714       break;
715
716     case TYPE_CODE_PTR:
717     case TYPE_CODE_REF:
718       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
719                                    show, 1, 0, flags);
720       break;
721
722     case TYPE_CODE_METHOD:
723     case TYPE_CODE_FUNC:
724       if (passed_a_ptr)
725         fprintf_filtered (stream, ")");
726       if (!demangled_args)
727         c_type_print_args (type, stream, 0, current_language->la_language,
728                            flags);
729       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
730                                    show, passed_a_ptr, 0, flags);
731       break;
732
733     case TYPE_CODE_TYPEDEF:
734       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
735                                    show, passed_a_ptr, 0, flags);
736       break;
737
738     case TYPE_CODE_UNDEF:
739     case TYPE_CODE_STRUCT:
740     case TYPE_CODE_UNION:
741     case TYPE_CODE_ENUM:
742     case TYPE_CODE_INT:
743     case TYPE_CODE_FLT:
744     case TYPE_CODE_VOID:
745     case TYPE_CODE_ERROR:
746     case TYPE_CODE_CHAR:
747     case TYPE_CODE_BOOL:
748     case TYPE_CODE_SET:
749     case TYPE_CODE_RANGE:
750     case TYPE_CODE_STRING:
751     case TYPE_CODE_COMPLEX:
752     case TYPE_CODE_NAMESPACE:
753     case TYPE_CODE_DECFLOAT:
754       /* These types do not need a suffix.  They are listed so that
755          gcc -Wall will report types that may not have been
756          considered.  */
757       break;
758     default:
759       error (_("type not handled in c_type_print_varspec_suffix()"));
760       break;
761     }
762 }
763
764 /* A helper for c_type_print_base that displays template
765    parameters and their bindings, if needed.
766
767    TABLE is the local bindings table to use.  If NULL, no printing is
768    done.  Note that, at this point, TABLE won't have any useful
769    information in it -- but it is also used as a flag to
770    print_name_maybe_canonical to activate searching the global typedef
771    table.
772
773    TYPE is the type whose template arguments are being displayed.
774
775    STREAM is the stream on which to print.  */
776
777 static void
778 c_type_print_template_args (const struct type_print_options *flags,
779                             struct type *type, struct ui_file *stream)
780 {
781   int first = 1, i;
782
783   if (flags->raw)
784     return;
785
786   for (i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
787     {
788       struct symbol *sym = TYPE_TEMPLATE_ARGUMENT (type, i);
789
790       if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
791         continue;
792
793       if (first)
794         {
795           wrap_here ("    ");
796           fprintf_filtered (stream, _("[with %s = "),
797                             SYMBOL_LINKAGE_NAME (sym));
798           first = 0;
799         }
800       else
801         {
802           fputs_filtered (", ", stream);
803           wrap_here ("         ");
804           fprintf_filtered (stream, "%s = ", SYMBOL_LINKAGE_NAME (sym));
805         }
806
807       c_print_type (SYMBOL_TYPE (sym), "", stream, -1, 0, flags);
808     }
809
810   if (!first)
811     fputs_filtered (_("] "), stream);
812 }
813
814 /* Print the name of the type (or the ultimate pointer target,
815    function value or array element), or the description of a structure
816    or union.
817
818    SHOW positive means print details about the type (e.g. enum
819    values), and print structure elements passing SHOW - 1 for show.
820
821    SHOW negative means just print the type name or struct tag if there
822    is one.  If there is no name, print something sensible but concise
823    like "struct {...}".
824
825    SHOW zero means just print the type name or struct tag if there is
826    one.  If there is no name, print something sensible but not as
827    concise like "struct {int x; int y;}".
828
829    LEVEL is the number of spaces to indent by.
830    We increase it for some recursive calls.  */
831
832 void
833 c_type_print_base (struct type *type, struct ui_file *stream,
834                    int show, int level, const struct type_print_options *flags)
835 {
836   int i;
837   int len, real_len;
838   enum
839     {
840       s_none, s_public, s_private, s_protected
841     }
842   section_type;
843   int need_access_label = 0;
844   int j, len2;
845
846   QUIT;
847
848   if (type == NULL)
849     {
850       fputs_filtered (_("<type unknown>"), stream);
851       return;
852     }
853
854   /* When SHOW is zero or less, and there is a valid type name, then
855      always just print the type name directly from the type.  */
856   /* If we have "typedef struct foo {. . .} bar;" do we want to print
857      it as "struct foo" or as "bar"?  Pick the latter, because C++
858      folk tend to expect things like "class5 *foo" rather than "struct
859      class5 *foo".  */
860
861   if (show <= 0
862       && TYPE_NAME (type) != NULL)
863     {
864       c_type_print_modifier (type, stream, 0, 1);
865       print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
866       return;
867     }
868
869   CHECK_TYPEDEF (type);
870
871   switch (TYPE_CODE (type))
872     {
873     case TYPE_CODE_TYPEDEF:
874       /* If we get here, the typedef doesn't have a name, and we
875          couldn't resolve TYPE_TARGET_TYPE.  Not much we can do.  */
876       gdb_assert (TYPE_NAME (type) == NULL);
877       gdb_assert (TYPE_TARGET_TYPE (type) == NULL);
878       fprintf_filtered (stream, _("<unnamed typedef>"));
879       break;
880
881     case TYPE_CODE_ARRAY:
882     case TYPE_CODE_PTR:
883     case TYPE_CODE_MEMBERPTR:
884     case TYPE_CODE_REF:
885     case TYPE_CODE_FUNC:
886     case TYPE_CODE_METHOD:
887     case TYPE_CODE_METHODPTR:
888       c_type_print_base (TYPE_TARGET_TYPE (type),
889                          stream, show, level, flags);
890       break;
891
892     case TYPE_CODE_STRUCT:
893     case TYPE_CODE_UNION:
894       {
895         struct type_print_options local_flags = *flags;
896         struct type_print_options semi_local_flags = *flags;
897         struct cleanup *local_cleanups = make_cleanup (null_cleanup, NULL);
898
899         local_flags.local_typedefs = NULL;
900         semi_local_flags.local_typedefs = NULL;
901
902         if (!flags->raw)
903           {
904             if (flags->local_typedefs)
905               local_flags.local_typedefs
906                 = copy_typedef_hash (flags->local_typedefs);
907             else
908               local_flags.local_typedefs = create_typedef_hash ();
909
910             make_cleanup_free_typedef_hash (local_flags.local_typedefs);
911           }
912
913         c_type_print_modifier (type, stream, 0, 1);
914         if (TYPE_CODE (type) == TYPE_CODE_UNION)
915           fprintf_filtered (stream, "union ");
916         else if (TYPE_DECLARED_CLASS (type))
917           fprintf_filtered (stream, "class ");
918         else
919           fprintf_filtered (stream, "struct ");
920
921         /* Print the tag if it exists.  The HP aCC compiler emits a
922            spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
923            enum}" tag for unnamed struct/union/enum's, which we don't
924            want to print.  */
925         if (TYPE_TAG_NAME (type) != NULL
926             && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
927           {
928             /* When printing the tag name, we are still effectively
929                printing in the outer context, hence the use of FLAGS
930                here.  */
931             print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
932             if (show > 0)
933               fputs_filtered (" ", stream);
934           }
935
936         if (show < 0)
937           {
938             /* If we just printed a tag name, no need to print anything
939                else.  */
940             if (TYPE_TAG_NAME (type) == NULL)
941               fprintf_filtered (stream, "{...}");
942           }
943         else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
944           {
945             struct type *basetype;
946             int vptr_fieldno;
947
948             c_type_print_template_args (&local_flags, type, stream);
949
950             /* Add in template parameters when printing derivation info.  */
951             add_template_parameters (local_flags.local_typedefs, type);
952             cp_type_print_derivation_info (stream, type, &local_flags);
953
954             /* This holds just the global typedefs and the template
955                parameters.  */
956             semi_local_flags.local_typedefs
957               = copy_typedef_hash (local_flags.local_typedefs);
958             if (semi_local_flags.local_typedefs)
959               make_cleanup_free_typedef_hash (semi_local_flags.local_typedefs);
960
961             /* Now add in the local typedefs.  */
962             recursively_update_typedef_hash (local_flags.local_typedefs, type);
963
964             fprintf_filtered (stream, "{\n");
965             if (TYPE_NFIELDS (type) == 0 && TYPE_NFN_FIELDS (type) == 0
966                 && TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
967               {
968                 if (TYPE_STUB (type))
969                   fprintfi_filtered (level + 4, stream,
970                                      _("<incomplete type>\n"));
971                 else
972                   fprintfi_filtered (level + 4, stream,
973                                      _("<no data fields>\n"));
974               }
975
976             /* Start off with no specific section type, so we can print
977                one for the first field we find, and use that section type
978                thereafter until we find another type.  */
979
980             section_type = s_none;
981
982             /* For a class, if all members are private, there's no need
983                for a "private:" label; similarly, for a struct or union
984                masquerading as a class, if all members are public, there's
985                no need for a "public:" label.  */
986
987             if (TYPE_DECLARED_CLASS (type))
988               {
989                 QUIT;
990                 len = TYPE_NFIELDS (type);
991                 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
992                   if (!TYPE_FIELD_PRIVATE (type, i))
993                     {
994                       need_access_label = 1;
995                       break;
996                     }
997                 QUIT;
998                 if (!need_access_label)
999                   {
1000                     len2 = TYPE_NFN_FIELDS (type);
1001                     for (j = 0; j < len2; j++)
1002                       {
1003                         len = TYPE_FN_FIELDLIST_LENGTH (type, j);
1004                         for (i = 0; i < len; i++)
1005                           if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
1006                                                                           j), i))
1007                             {
1008                               need_access_label = 1;
1009                               break;
1010                             }
1011                         if (need_access_label)
1012                           break;
1013                       }
1014                   }
1015               }
1016             else
1017               {
1018                 QUIT;
1019                 len = TYPE_NFIELDS (type);
1020                 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1021                   if (TYPE_FIELD_PRIVATE (type, i)
1022                       || TYPE_FIELD_PROTECTED (type, i))
1023                     {
1024                       need_access_label = 1;
1025                       break;
1026                     }
1027                 QUIT;
1028                 if (!need_access_label)
1029                   {
1030                     len2 = TYPE_NFN_FIELDS (type);
1031                     for (j = 0; j < len2; j++)
1032                       {
1033                         QUIT;
1034                         len = TYPE_FN_FIELDLIST_LENGTH (type, j);
1035                         for (i = 0; i < len; i++)
1036                           if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type,
1037                                                                            j), i)
1038                               || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
1039                                                                             j),
1040                                                         i))
1041                             {
1042                               need_access_label = 1;
1043                               break;
1044                             }
1045                         if (need_access_label)
1046                           break;
1047                       }
1048                   }
1049               }
1050
1051             /* If there is a base class for this type,
1052                do not print the field that it occupies.  */
1053
1054             len = TYPE_NFIELDS (type);
1055             vptr_fieldno = get_vptr_fieldno (type, &basetype);
1056             for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1057               {
1058                 QUIT;
1059
1060                 /* If we have a virtual table pointer, omit it.  Even if
1061                    virtual table pointers are not specifically marked in
1062                    the debug info, they should be artificial.  */
1063                 if ((i == vptr_fieldno && type == basetype)
1064                     || TYPE_FIELD_ARTIFICIAL (type, i))
1065                   continue;
1066
1067                 if (need_access_label)
1068                   {
1069                     if (TYPE_FIELD_PROTECTED (type, i))
1070                       {
1071                         if (section_type != s_protected)
1072                           {
1073                             section_type = s_protected;
1074                             fprintfi_filtered (level + 2, stream,
1075                                                "protected:\n");
1076                           }
1077                       }
1078                     else if (TYPE_FIELD_PRIVATE (type, i))
1079                       {
1080                         if (section_type != s_private)
1081                           {
1082                             section_type = s_private;
1083                             fprintfi_filtered (level + 2, stream,
1084                                                "private:\n");
1085                           }
1086                       }
1087                     else
1088                       {
1089                         if (section_type != s_public)
1090                           {
1091                             section_type = s_public;
1092                             fprintfi_filtered (level + 2, stream,
1093                                                "public:\n");
1094                           }
1095                       }
1096                   }
1097
1098                 print_spaces_filtered (level + 4, stream);
1099                 if (field_is_static (&TYPE_FIELD (type, i)))
1100                   fprintf_filtered (stream, "static ");
1101                 c_print_type (TYPE_FIELD_TYPE (type, i),
1102                               TYPE_FIELD_NAME (type, i),
1103                               stream, show - 1, level + 4,
1104                               &local_flags);
1105                 if (!field_is_static (&TYPE_FIELD (type, i))
1106                     && TYPE_FIELD_PACKED (type, i))
1107                   {
1108                     /* It is a bitfield.  This code does not attempt
1109                        to look at the bitpos and reconstruct filler,
1110                        unnamed fields.  This would lead to misleading
1111                        results if the compiler does not put out fields
1112                        for such things (I don't know what it does).  */
1113                     fprintf_filtered (stream, " : %d",
1114                                       TYPE_FIELD_BITSIZE (type, i));
1115                   }
1116                 fprintf_filtered (stream, ";\n");
1117               }
1118
1119           /* If there are both fields and methods, put a blank line
1120              between them.  Make sure to count only method that we
1121              will display; artificial methods will be hidden.  */
1122           len = TYPE_NFN_FIELDS (type);
1123           if (!flags->print_methods)
1124             len = 0;
1125           real_len = 0;
1126           for (i = 0; i < len; i++)
1127             {
1128               struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1129               int len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1130               int j;
1131
1132               for (j = 0; j < len2; j++)
1133                 if (!TYPE_FN_FIELD_ARTIFICIAL (f, j))
1134                   real_len++;
1135             }
1136           if (real_len > 0 && section_type != s_none)
1137             fprintf_filtered (stream, "\n");
1138
1139           /* C++: print out the methods.  */
1140           for (i = 0; i < len; i++)
1141             {
1142               struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1143               int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1144               const char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
1145               const char *name = type_name_no_tag (type);
1146               int is_constructor = name && strcmp (method_name,
1147                                                    name) == 0;
1148
1149               for (j = 0; j < len2; j++)
1150                 {
1151                   const char *mangled_name;
1152                   char *demangled_name;
1153                   struct cleanup *inner_cleanup;
1154                   const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1155                   int is_full_physname_constructor =
1156                     TYPE_FN_FIELD_CONSTRUCTOR (f, j)
1157                     || is_constructor_name (physname)
1158                     || is_destructor_name (physname)
1159                     || method_name[0] == '~';
1160
1161                   /* Do not print out artificial methods.  */
1162                   if (TYPE_FN_FIELD_ARTIFICIAL (f, j))
1163                     continue;
1164
1165                   inner_cleanup = make_cleanup (null_cleanup, NULL);
1166
1167                   QUIT;
1168                   if (TYPE_FN_FIELD_PROTECTED (f, j))
1169                     {
1170                       if (section_type != s_protected)
1171                         {
1172                           section_type = s_protected;
1173                           fprintfi_filtered (level + 2, stream,
1174                                              "protected:\n");
1175                         }
1176                     }
1177                   else if (TYPE_FN_FIELD_PRIVATE (f, j))
1178                     {
1179                       if (section_type != s_private)
1180                         {
1181                           section_type = s_private;
1182                           fprintfi_filtered (level + 2, stream,
1183                                              "private:\n");
1184                         }
1185                     }
1186                   else
1187                     {
1188                       if (section_type != s_public)
1189                         {
1190                           section_type = s_public;
1191                           fprintfi_filtered (level + 2, stream,
1192                                              "public:\n");
1193                         }
1194                     }
1195
1196                   print_spaces_filtered (level + 4, stream);
1197                   if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1198                     fprintf_filtered (stream, "virtual ");
1199                   else if (TYPE_FN_FIELD_STATIC_P (f, j))
1200                     fprintf_filtered (stream, "static ");
1201                   if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1202                     {
1203                       /* Keep GDB from crashing here.  */
1204                       fprintf_filtered (stream,
1205                                         _("<undefined type> %s;\n"),
1206                                         TYPE_FN_FIELD_PHYSNAME (f, j));
1207                       break;
1208                     }
1209                   else if (!is_constructor      /* Constructors don't
1210                                                    have declared
1211                                                    types.  */
1212                            && !is_full_physname_constructor  /* " " */
1213                            && !is_type_conversion_operator (type, i, j))
1214                     {
1215                       c_print_type (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1216                                     "", stream, -1, 0,
1217                                     &local_flags);
1218                       fputs_filtered (" ", stream);
1219                     }
1220                   if (TYPE_FN_FIELD_STUB (f, j))
1221                     {
1222                       char *tem;
1223
1224                       /* Build something we can demangle.  */
1225                       tem = gdb_mangle_name (type, i, j);
1226                       make_cleanup (xfree, tem);
1227                       mangled_name = tem;
1228                     }
1229                   else
1230                     mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
1231
1232                   demangled_name =
1233                     gdb_demangle (mangled_name,
1234                                   DMGL_ANSI | DMGL_PARAMS);
1235                   if (demangled_name == NULL)
1236                     {
1237                       /* In some cases (for instance with the HP
1238                          demangling), if a function has more than 10
1239                          arguments, the demangling will fail.
1240                          Let's try to reconstruct the function
1241                          signature from the symbol information.  */
1242                       if (!TYPE_FN_FIELD_STUB (f, j))
1243                         {
1244                           int staticp = TYPE_FN_FIELD_STATIC_P (f, j);
1245                           struct type *mtype = TYPE_FN_FIELD_TYPE (f, j);
1246
1247                           cp_type_print_method_args (mtype,
1248                                                      "",
1249                                                      method_name,
1250                                                      staticp,
1251                                                      stream, &local_flags);
1252                         }
1253                       else
1254                         fprintf_filtered (stream,
1255                                           _("<badly mangled name '%s'>"),
1256                                           mangled_name);
1257                     }
1258                   else
1259                     {
1260                       char *p;
1261                       char *demangled_no_class
1262                         = remove_qualifiers (demangled_name);
1263
1264                       /* Get rid of the `static' appended by the
1265                          demangler.  */
1266                       p = strstr (demangled_no_class, " static");
1267                       if (p != NULL)
1268                         {
1269                           int length = p - demangled_no_class;
1270                           char *demangled_no_static;
1271
1272                           demangled_no_static
1273                             = (char *) xmalloc (length + 1);
1274                           strncpy (demangled_no_static,
1275                                    demangled_no_class, length);
1276                           *(demangled_no_static + length) = '\0';
1277                           fputs_filtered (demangled_no_static, stream);
1278                           xfree (demangled_no_static);
1279                         }
1280                       else
1281                         fputs_filtered (demangled_no_class, stream);
1282                       xfree (demangled_name);
1283                     }
1284
1285                   do_cleanups (inner_cleanup);
1286
1287                   fprintf_filtered (stream, ";\n");
1288                 }
1289             }
1290
1291           /* Print typedefs defined in this class.  */
1292
1293           if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0 && flags->print_typedefs)
1294             {
1295               if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0)
1296                 fprintf_filtered (stream, "\n");
1297
1298                 for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); i++)
1299                   {
1300                     struct type *target = TYPE_TYPEDEF_FIELD_TYPE (type, i);
1301
1302                     /* Dereference the typedef declaration itself.  */
1303                     gdb_assert (TYPE_CODE (target) == TYPE_CODE_TYPEDEF);
1304                     target = TYPE_TARGET_TYPE (target);
1305
1306                     print_spaces_filtered (level + 4, stream);
1307                     fprintf_filtered (stream, "typedef ");
1308
1309                     /* We want to print typedefs with substitutions
1310                        from the template parameters or globally-known
1311                        typedefs but not local typedefs.  */
1312                     c_print_type (target,
1313                                   TYPE_TYPEDEF_FIELD_NAME (type, i),
1314                                   stream, show - 1, level + 4,
1315                                   &semi_local_flags);
1316                     fprintf_filtered (stream, ";\n");
1317                   }
1318               }
1319
1320             fprintfi_filtered (level, stream, "}");
1321           }
1322
1323         do_cleanups (local_cleanups);
1324       }
1325       break;
1326
1327     case TYPE_CODE_ENUM:
1328       c_type_print_modifier (type, stream, 0, 1);
1329       fprintf_filtered (stream, "enum ");
1330       if (TYPE_DECLARED_CLASS (type))
1331         fprintf_filtered (stream, "class ");
1332       /* Print the tag name if it exists.
1333          The aCC compiler emits a spurious 
1334          "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1335          tag for unnamed struct/union/enum's, which we don't
1336          want to print.  */
1337       if (TYPE_TAG_NAME (type) != NULL
1338           && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
1339         {
1340           print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
1341           if (show > 0)
1342             fputs_filtered (" ", stream);
1343         }
1344
1345       wrap_here ("    ");
1346       if (show < 0)
1347         {
1348           /* If we just printed a tag name, no need to print anything
1349              else.  */
1350           if (TYPE_TAG_NAME (type) == NULL)
1351             fprintf_filtered (stream, "{...}");
1352         }
1353       else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
1354         {
1355           LONGEST lastval = 0;
1356
1357           /* We can't handle this case perfectly, as DWARF does not
1358              tell us whether or not the underlying type was specified
1359              in the source (and other debug formats don't provide this
1360              at all).  We choose to print the underlying type, if it
1361              has a name, when in C++ on the theory that it's better to
1362              print too much than too little; but conversely not to
1363              print something egregiously outside the current
1364              language's syntax.  */
1365           if (current_language->la_language == language_cplus
1366               && TYPE_TARGET_TYPE (type) != NULL)
1367             {
1368               struct type *underlying = check_typedef (TYPE_TARGET_TYPE (type));
1369
1370               if (TYPE_NAME (underlying) != NULL)
1371                 fprintf_filtered (stream, ": %s ", TYPE_NAME (underlying));
1372             }
1373
1374           fprintf_filtered (stream, "{");
1375           len = TYPE_NFIELDS (type);
1376           for (i = 0; i < len; i++)
1377             {
1378               QUIT;
1379               if (i)
1380                 fprintf_filtered (stream, ", ");
1381               wrap_here ("    ");
1382               fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1383               if (lastval != TYPE_FIELD_ENUMVAL (type, i))
1384                 {
1385                   fprintf_filtered (stream, " = %s",
1386                                     plongest (TYPE_FIELD_ENUMVAL (type, i)));
1387                   lastval = TYPE_FIELD_ENUMVAL (type, i);
1388                 }
1389               lastval++;
1390             }
1391           fprintf_filtered (stream, "}");
1392         }
1393       break;
1394
1395     case TYPE_CODE_VOID:
1396       fprintf_filtered (stream, "void");
1397       break;
1398
1399     case TYPE_CODE_UNDEF:
1400       fprintf_filtered (stream, _("struct <unknown>"));
1401       break;
1402
1403     case TYPE_CODE_ERROR:
1404       fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
1405       break;
1406
1407     case TYPE_CODE_RANGE:
1408       /* This should not occur.  */
1409       fprintf_filtered (stream, _("<range type>"));
1410       break;
1411
1412     case TYPE_CODE_NAMESPACE:
1413       fputs_filtered ("namespace ", stream);
1414       fputs_filtered (TYPE_TAG_NAME (type), stream);
1415       break;
1416
1417     default:
1418       /* Handle types not explicitly handled by the other cases, such
1419          as fundamental types.  For these, just print whatever the
1420          type name is, as recorded in the type itself.  If there is no
1421          type name, then complain.  */
1422       if (TYPE_NAME (type) != NULL)
1423         {
1424           c_type_print_modifier (type, stream, 0, 1);
1425           print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
1426         }
1427       else
1428         {
1429           /* At least for dump_symtab, it is important that this not
1430              be an error ().  */
1431           fprintf_filtered (stream, _("<invalid type code %d>"),
1432                             TYPE_CODE (type));
1433         }
1434       break;
1435     }
1436 }