c-typeprint.c revision 19370
1/* Support for printing C and C++ types for GDB, the GNU debugger.
2   Copyright 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996
3   Free Software Foundation, Inc.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21#include "defs.h"
22#include "obstack.h"
23#include "bfd.h"		/* Binary File Description */
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "expression.h"
27#include "value.h"
28#include "gdbcore.h"
29#include "target.h"
30#include "command.h"
31#include "gdbcmd.h"
32#include "language.h"
33#include "demangle.h"
34#include "c-lang.h"
35#include "typeprint.h"
36
37#include "gdb_string.h"
38#include <errno.h>
39#include <ctype.h>
40
41static void
42c_type_print_args PARAMS ((struct type *, GDB_FILE *));
43
44static void
45c_type_print_varspec_suffix PARAMS ((struct type *, GDB_FILE *, int, int, int));
46
47static void
48cp_type_print_derivation_info PARAMS ((GDB_FILE *, struct type *));
49
50void
51c_type_print_varspec_prefix PARAMS ((struct type *, GDB_FILE *, int, int));
52
53
54/* Print a description of a type in the format of a
55   typedef for the current language.
56   NEW is the new name for a type TYPE. */
57
58void
59c_typedef_print (type, new, stream)
60   struct type *type;
61   struct symbol *new;
62   GDB_FILE *stream;
63{
64  CHECK_TYPEDEF (type);
65   switch (current_language->la_language)
66   {
67#ifdef _LANG_c
68   case language_c:
69   case language_cplus:
70      fprintf_filtered(stream, "typedef ");
71      type_print(type,"",stream,0);
72      if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
73	 || !STREQ (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_NAME (new)))
74	fprintf_filtered(stream,  " %s", SYMBOL_SOURCE_NAME(new));
75      break;
76#endif
77#ifdef _LANG_m2
78   case language_m2:
79      fprintf_filtered(stream, "TYPE ");
80      if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
81	 !STREQ (TYPE_NAME(SYMBOL_TYPE(new)), SYMBOL_NAME(new)))
82	fprintf_filtered(stream, "%s = ", SYMBOL_SOURCE_NAME(new));
83      else
84	 fprintf_filtered(stream, "<builtin> = ");
85      type_print(type,"",stream,0);
86      break;
87#endif
88#ifdef _LANG_chill
89   case language_chill:
90      fprintf_filtered(stream, "SYNMODE ");
91      if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
92	 !STREQ (TYPE_NAME(SYMBOL_TYPE(new)), SYMBOL_NAME(new)))
93	fprintf_filtered(stream, "%s = ", SYMBOL_SOURCE_NAME(new));
94      else
95	 fprintf_filtered(stream, "<builtin> = ");
96      type_print(type,"",stream,0);
97      break;
98#endif
99   default:
100      error("Language not supported.");
101   }
102   fprintf_filtered(stream, ";\n");
103}
104
105
106/* LEVEL is the depth to indent lines by.  */
107
108void
109c_print_type (type, varstring, stream, show, level)
110     struct type *type;
111     char *varstring;
112     GDB_FILE *stream;
113     int show;
114     int level;
115{
116  register enum type_code code;
117  int demangled_args;
118
119  if (show > 0)
120    CHECK_TYPEDEF (type);
121
122  c_type_print_base (type, stream, show, level);
123  code = TYPE_CODE (type);
124  if ((varstring != NULL && *varstring != '\0')
125      ||
126      /* Need a space if going to print stars or brackets;
127	 but not if we will print just a type name.  */
128      ((show > 0 || TYPE_NAME (type) == 0)
129       &&
130       (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
131	|| code == TYPE_CODE_METHOD
132	|| code == TYPE_CODE_ARRAY
133	|| code == TYPE_CODE_MEMBER
134	|| code == TYPE_CODE_REF)))
135    fputs_filtered (" ", stream);
136  c_type_print_varspec_prefix (type, stream, show, 0);
137
138  fputs_filtered (varstring, stream);
139
140  /* For demangled function names, we have the arglist as part of the name,
141     so don't print an additional pair of ()'s */
142
143  demangled_args = strchr(varstring, '(') != NULL;
144  c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
145
146}
147
148/* Print the C++ method arguments ARGS to the file STREAM.  */
149
150void
151cp_type_print_method_args (args, prefix, varstring, staticp, stream)
152     struct type **args;
153     char *prefix;
154     char *varstring;
155     int staticp;
156     GDB_FILE *stream;
157{
158  int i;
159
160  fprintf_symbol_filtered (stream, prefix, language_cplus, DMGL_ANSI);
161  fprintf_symbol_filtered (stream, varstring, language_cplus, DMGL_ANSI);
162  fputs_filtered (" (", stream);
163  if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
164    {
165      i = !staticp;		/* skip the class variable */
166      while (1)
167	{
168	  type_print (args[i++], "", stream, 0);
169	  if (!args[i])
170	    {
171	      fprintf_filtered (stream, " ...");
172	      break;
173	    }
174	  else if (args[i]->code != TYPE_CODE_VOID)
175	    {
176	      fprintf_filtered (stream, ", ");
177	    }
178	  else break;
179	}
180    }
181  fprintf_filtered (stream, ")");
182}
183
184/* If TYPE is a derived type, then print out derivation information.
185   Print only the actual base classes of this type, not the base classes
186   of the base classes.  I.E.  for the derivation hierarchy:
187
188	class A { int a; };
189	class B : public A {int b; };
190	class C : public B {int c; };
191
192   Print the type of class C as:
193
194   	class C : public B {
195		int c;
196	}
197
198   Not as the following (like gdb used to), which is not legal C++ syntax for
199   derived types and may be confused with the multiple inheritance form:
200
201	class C : public B : public A {
202		int c;
203	}
204
205   In general, gdb should try to print the types as closely as possible to
206   the form that they appear in the source code. */
207
208static void
209cp_type_print_derivation_info (stream, type)
210     GDB_FILE *stream;
211     struct type *type;
212{
213  char *name;
214  int i;
215
216  for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
217    {
218      fputs_filtered (i == 0 ? ": " : ", ", stream);
219      fprintf_filtered (stream, "%s%s ",
220			BASETYPE_VIA_PUBLIC (type, i) ? "public" : "private",
221			BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : "");
222      name = type_name_no_tag (TYPE_BASECLASS (type, i));
223      fprintf_filtered (stream, "%s", name ? name : "(null)");
224    }
225  if (i > 0)
226    {
227      fputs_filtered (" ", stream);
228    }
229}
230
231/* Print any asterisks or open-parentheses needed before the
232   variable name (to describe its type).
233
234   On outermost call, pass 0 for PASSED_A_PTR.
235   On outermost call, SHOW > 0 means should ignore
236   any typename for TYPE and show its details.
237   SHOW is always zero on recursive calls.  */
238
239void
240c_type_print_varspec_prefix (type, stream, show, passed_a_ptr)
241     struct type *type;
242     GDB_FILE *stream;
243     int show;
244     int passed_a_ptr;
245{
246  char *name;
247  if (type == 0)
248    return;
249
250  if (TYPE_NAME (type) && show <= 0)
251    return;
252
253  QUIT;
254
255  switch (TYPE_CODE (type))
256    {
257    case TYPE_CODE_PTR:
258      c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
259      fprintf_filtered (stream, "*");
260      break;
261
262    case TYPE_CODE_MEMBER:
263      if (passed_a_ptr)
264	fprintf_filtered (stream, "(");
265      c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
266      fprintf_filtered (stream, " ");
267      name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
268      if (name)
269	fputs_filtered (name, stream);
270      else
271        c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
272      fprintf_filtered (stream, "::");
273      break;
274
275    case TYPE_CODE_METHOD:
276      if (passed_a_ptr)
277	fprintf_unfiltered (stream, "(");
278      c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
279      if (passed_a_ptr)
280	{
281	  fprintf_filtered (stream, " ");
282	  c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
283	  fprintf_filtered (stream, "::");
284	}
285      break;
286
287    case TYPE_CODE_REF:
288      c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
289      fprintf_filtered (stream, "&");
290      break;
291
292    case TYPE_CODE_FUNC:
293      c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
294      if (passed_a_ptr)
295	fprintf_filtered (stream, "(");
296      break;
297
298    case TYPE_CODE_ARRAY:
299      c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
300      if (passed_a_ptr)
301	fprintf_filtered (stream, "(");
302      break;
303
304    case TYPE_CODE_UNDEF:
305    case TYPE_CODE_STRUCT:
306    case TYPE_CODE_UNION:
307    case TYPE_CODE_ENUM:
308    case TYPE_CODE_INT:
309    case TYPE_CODE_FLT:
310    case TYPE_CODE_VOID:
311    case TYPE_CODE_ERROR:
312    case TYPE_CODE_CHAR:
313    case TYPE_CODE_BOOL:
314    case TYPE_CODE_SET:
315    case TYPE_CODE_RANGE:
316    case TYPE_CODE_STRING:
317    case TYPE_CODE_BITSTRING:
318    case TYPE_CODE_COMPLEX:
319    case TYPE_CODE_TYPEDEF:
320      /* These types need no prefix.  They are listed here so that
321	 gcc -Wall will reveal any types that haven't been handled.  */
322      break;
323    }
324}
325
326static void
327c_type_print_args (type, stream)
328     struct type *type;
329     GDB_FILE *stream;
330{
331  int i;
332  struct type **args;
333
334  fprintf_filtered (stream, "(");
335  args = TYPE_ARG_TYPES (type);
336  if (args != NULL)
337    {
338      if (args[1] == NULL)
339	{
340	  fprintf_filtered (stream, "...");
341	}
342      else
343	{
344	  for (i = 1;
345	       args[i] != NULL && args[i]->code != TYPE_CODE_VOID;
346	       i++)
347	    {
348	      c_print_type (args[i], "", stream, -1, 0);
349	      if (args[i+1] == NULL)
350		{
351		  fprintf_filtered (stream, "...");
352		}
353	      else if (args[i+1]->code != TYPE_CODE_VOID)
354		{
355		  fprintf_filtered (stream, ",");
356		  wrap_here ("    ");
357		}
358	    }
359	}
360    }
361  fprintf_filtered (stream, ")");
362}
363
364/* Print any array sizes, function arguments or close parentheses
365   needed after the variable name (to describe its type).
366   Args work like c_type_print_varspec_prefix.  */
367
368static void
369c_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
370     struct type *type;
371     GDB_FILE *stream;
372     int show;
373     int passed_a_ptr;
374     int demangled_args;
375{
376  if (type == 0)
377    return;
378
379  if (TYPE_NAME (type) && show <= 0)
380    return;
381
382  QUIT;
383
384  switch (TYPE_CODE (type))
385    {
386    case TYPE_CODE_ARRAY:
387      if (passed_a_ptr)
388	fprintf_filtered (stream, ")");
389
390      fprintf_filtered (stream, "[");
391      if (TYPE_LENGTH (type) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
392	  && TYPE_ARRAY_UPPER_BOUND_TYPE(type) != BOUND_CANNOT_BE_DETERMINED)
393	fprintf_filtered (stream, "%d",
394			  (TYPE_LENGTH (type)
395			   / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
396      fprintf_filtered (stream, "]");
397
398      c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
399      break;
400
401    case TYPE_CODE_MEMBER:
402      if (passed_a_ptr)
403	fprintf_filtered (stream, ")");
404      c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
405      break;
406
407    case TYPE_CODE_METHOD:
408      if (passed_a_ptr)
409	fprintf_filtered (stream, ")");
410      c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
411      if (passed_a_ptr)
412	{
413	  c_type_print_args (type, stream);
414	}
415      break;
416
417    case TYPE_CODE_PTR:
418    case TYPE_CODE_REF:
419      c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
420      break;
421
422    case TYPE_CODE_FUNC:
423      if (passed_a_ptr)
424	fprintf_filtered (stream, ")");
425      if (!demangled_args)
426	{ int i, len = TYPE_NFIELDS (type);
427	  fprintf_filtered (stream, "(");
428	  for (i = 0; i < len; i++)
429	    {
430	      if (i > 0)
431		{
432		  fputs_filtered (", ", stream);
433		  wrap_here ("    ");
434		}
435	      c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
436	    }
437	  fprintf_filtered (stream, ")");
438	}
439      c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
440				   passed_a_ptr, 0);
441      break;
442
443    case TYPE_CODE_UNDEF:
444    case TYPE_CODE_STRUCT:
445    case TYPE_CODE_UNION:
446    case TYPE_CODE_ENUM:
447    case TYPE_CODE_INT:
448    case TYPE_CODE_FLT:
449    case TYPE_CODE_VOID:
450    case TYPE_CODE_ERROR:
451    case TYPE_CODE_CHAR:
452    case TYPE_CODE_BOOL:
453    case TYPE_CODE_SET:
454    case TYPE_CODE_RANGE:
455    case TYPE_CODE_STRING:
456    case TYPE_CODE_BITSTRING:
457    case TYPE_CODE_COMPLEX:
458    case TYPE_CODE_TYPEDEF:
459      /* These types do not need a suffix.  They are listed so that
460	 gcc -Wall will report types that may not have been considered.  */
461      break;
462    }
463}
464
465/* Print the name of the type (or the ultimate pointer target,
466   function value or array element), or the description of a
467   structure or union.
468
469   SHOW positive means print details about the type (e.g. enum values),
470   and print structure elements passing SHOW - 1 for show.
471   SHOW negative means just print the type name or struct tag if there is one.
472   If there is no name, print something sensible but concise like
473   "struct {...}".
474   SHOW zero means just print the type name or struct tag if there is one.
475   If there is no name, print something sensible but not as concise like
476   "struct {int x; int y;}".
477
478   LEVEL is the number of spaces to indent by.
479   We increase it for some recursive calls.  */
480
481void
482c_type_print_base (type, stream, show, level)
483     struct type *type;
484     GDB_FILE *stream;
485     int show;
486     int level;
487{
488  register int i;
489  register int len;
490  register int lastval;
491  char *mangled_name;
492  char *demangled_name;
493  enum {s_none, s_public, s_private, s_protected} section_type;
494  QUIT;
495
496  wrap_here ("    ");
497  if (type == NULL)
498    {
499      fputs_filtered ("<type unknown>", stream);
500      return;
501    }
502
503  /* When SHOW is zero or less, and there is a valid type name, then always
504     just print the type name directly from the type.  */
505  /* If we have "typedef struct foo {. . .} bar;" do we want to print it
506     as "struct foo" or as "bar"?  Pick the latter, because C++ folk tend
507     to expect things like "class5 *foo" rather than "struct class5 *foo".  */
508
509  if (show <= 0
510      && TYPE_NAME (type) != NULL)
511    {
512      fputs_filtered (TYPE_NAME (type), stream);
513      return;
514    }
515
516  CHECK_TYPEDEF (type);
517
518  switch (TYPE_CODE (type))
519    {
520    case TYPE_CODE_TYPEDEF:
521    case TYPE_CODE_ARRAY:
522    case TYPE_CODE_PTR:
523    case TYPE_CODE_MEMBER:
524    case TYPE_CODE_REF:
525    case TYPE_CODE_FUNC:
526    case TYPE_CODE_METHOD:
527      c_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
528      break;
529
530    case TYPE_CODE_STRUCT:
531      if (HAVE_CPLUS_STRUCT (type))
532	{
533	  fprintf_filtered (stream, "class ");
534	}
535      else
536	{
537	  fprintf_filtered (stream, "struct ");
538	}
539      goto struct_union;
540
541    case TYPE_CODE_UNION:
542      fprintf_filtered (stream, "union ");
543
544    struct_union:
545      if (TYPE_TAG_NAME (type) != NULL)
546	{
547	  fputs_filtered (TYPE_TAG_NAME (type), stream);
548	  if (show > 0)
549	    fputs_filtered (" ", stream);
550	}
551      wrap_here ("    ");
552      if (show < 0)
553	{
554	  /* If we just printed a tag name, no need to print anything else.  */
555	  if (TYPE_TAG_NAME (type) == NULL)
556	    fprintf_filtered (stream, "{...}");
557	}
558      else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
559	{
560	  cp_type_print_derivation_info (stream, type);
561
562	  fprintf_filtered (stream, "{\n");
563	  if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
564	    {
565	      if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
566		fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
567	      else
568		fprintfi_filtered (level + 4, stream, "<no data fields>\n");
569	    }
570
571	  /* Start off with no specific section type, so we can print
572	     one for the first field we find, and use that section type
573	     thereafter until we find another type. */
574
575	  section_type = s_none;
576
577	  /* If there is a base class for this type,
578	     do not print the field that it occupies.  */
579
580	  len = TYPE_NFIELDS (type);
581	  for (i = TYPE_N_BASECLASSES (type); i < len; i++)
582	    {
583	      QUIT;
584	      /* Don't print out virtual function table.  */
585	      if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5)
586		  && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
587		continue;
588
589	      /* If this is a C++ class we can print the various C++ section
590		 labels. */
591
592	      if (HAVE_CPLUS_STRUCT (type))
593		{
594		  if (TYPE_FIELD_PROTECTED (type, i))
595		    {
596		      if (section_type != s_protected)
597			{
598			  section_type = s_protected;
599			  fprintfi_filtered (level + 2, stream,
600					     "protected:\n");
601			}
602		    }
603		  else if (TYPE_FIELD_PRIVATE (type, i))
604		    {
605		      if (section_type != s_private)
606			{
607			  section_type = s_private;
608			  fprintfi_filtered (level + 2, stream, "private:\n");
609			}
610		    }
611		  else
612		    {
613		      if (section_type != s_public)
614			{
615			  section_type = s_public;
616			  fprintfi_filtered (level + 2, stream, "public:\n");
617			}
618		    }
619		}
620
621	      print_spaces_filtered (level + 4, stream);
622	      if (TYPE_FIELD_STATIC (type, i))
623		{
624		  fprintf_filtered (stream, "static ");
625		}
626	      c_print_type (TYPE_FIELD_TYPE (type, i),
627			    TYPE_FIELD_NAME (type, i),
628			    stream, show - 1, level + 4);
629	      if (!TYPE_FIELD_STATIC (type, i)
630		  && TYPE_FIELD_PACKED (type, i))
631		{
632		  /* It is a bitfield.  This code does not attempt
633		     to look at the bitpos and reconstruct filler,
634		     unnamed fields.  This would lead to misleading
635		     results if the compiler does not put out fields
636		     for such things (I don't know what it does).  */
637		  fprintf_filtered (stream, " : %d",
638				    TYPE_FIELD_BITSIZE (type, i));
639		}
640	      fprintf_filtered (stream, ";\n");
641	    }
642
643	  /* If there are both fields and methods, put a space between. */
644	  len = TYPE_NFN_FIELDS (type);
645	  if (len && section_type != s_none)
646	     fprintf_filtered (stream, "\n");
647
648	  /* C++: print out the methods */
649
650	  for (i = 0; i < len; i++)
651	    {
652	      struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
653	      int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
654	      char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
655	      char *name = type_name_no_tag (type);
656	      int is_constructor = name && STREQ(method_name, name);
657	      for (j = 0; j < len2; j++)
658		{
659		  char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
660		  int is_full_physname_constructor =
661		    ((physname[0]=='_' && physname[1]=='_' &&
662		      (isdigit(physname[2])
663		       || physname[2]=='Q'
664		       || physname[2]=='t'))
665		     || (strncmp(physname, "__ct__", 6) == 0));
666
667		  QUIT;
668		  if (TYPE_FN_FIELD_PROTECTED (f, j))
669		    {
670		      if (section_type != s_protected)
671			{
672			  section_type = s_protected;
673			  fprintfi_filtered (level + 2, stream,
674					     "protected:\n");
675			}
676		    }
677		  else if (TYPE_FN_FIELD_PRIVATE (f, j))
678		    {
679		      if (section_type != s_private)
680			{
681			  section_type = s_private;
682			  fprintfi_filtered (level + 2, stream, "private:\n");
683			}
684		    }
685		  else
686		    {
687		      if (section_type != s_public)
688			{
689			  section_type = s_public;
690			  fprintfi_filtered (level + 2, stream, "public:\n");
691			}
692		    }
693
694		  print_spaces_filtered (level + 4, stream);
695		  if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
696		    fprintf_filtered (stream, "virtual ");
697		  else if (TYPE_FN_FIELD_STATIC_P (f, j))
698		    fprintf_filtered (stream, "static ");
699		  if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
700		    {
701		      /* Keep GDB from crashing here.  */
702		      fprintf_unfiltered (stream, "<undefined type> %s;\n",
703			       TYPE_FN_FIELD_PHYSNAME (f, j));
704		      break;
705		    }
706		  else if (!is_constructor && !is_full_physname_constructor)
707		    {
708		      type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
709				  "", stream, -1);
710		      fputs_filtered (" ", stream);
711		    }
712		  if (TYPE_FN_FIELD_STUB (f, j))
713		    {
714		      /* Build something we can demangle.  */
715		      mangled_name = gdb_mangle_name (type, i, j);
716		      demangled_name =
717			cplus_demangle (mangled_name,
718					DMGL_ANSI | DMGL_PARAMS);
719		      if (demangled_name == NULL)
720			fprintf_filtered (stream, "<badly mangled name %s>",
721					  mangled_name);
722		      else
723			{
724			  char *demangled_no_class =
725			    strchr (demangled_name, ':');
726
727			  if (demangled_no_class == NULL)
728			    demangled_no_class = demangled_name;
729			  else
730			    {
731			      if (*++demangled_no_class == ':')
732				++demangled_no_class;
733			    }
734			  fputs_filtered (demangled_no_class, stream);
735			  free (demangled_name);
736			}
737		      free (mangled_name);
738		    }
739		  else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
740		          && is_cplus_marker (TYPE_FN_FIELD_PHYSNAME (f, j)[1]))
741		    cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j) + 1,
742					       "~", method_name, 0, stream);
743		  else
744		    cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j), "",
745					       method_name,
746					       TYPE_FN_FIELD_STATIC_P (f, j),
747					       stream);
748
749		  fprintf_filtered (stream, ";\n");
750		}
751	    }
752
753	  fprintfi_filtered (level, stream, "}");
754	}
755      break;
756
757    case TYPE_CODE_ENUM:
758      fprintf_filtered (stream, "enum ");
759      if (TYPE_TAG_NAME (type) != NULL)
760	{
761	  fputs_filtered (TYPE_TAG_NAME (type), stream);
762	  if (show > 0)
763	    fputs_filtered (" ", stream);
764	}
765
766      wrap_here ("    ");
767      if (show < 0)
768	{
769	  /* If we just printed a tag name, no need to print anything else.  */
770	  if (TYPE_TAG_NAME (type) == NULL)
771	    fprintf_filtered (stream, "{...}");
772	}
773      else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
774	{
775	  fprintf_filtered (stream, "{");
776	  len = TYPE_NFIELDS (type);
777	  lastval = 0;
778	  for (i = 0; i < len; i++)
779	    {
780	      QUIT;
781	      if (i) fprintf_filtered (stream, ", ");
782	      wrap_here ("    ");
783	      fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
784	      if (lastval != TYPE_FIELD_BITPOS (type, i))
785		{
786		  fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
787		  lastval = TYPE_FIELD_BITPOS (type, i);
788		}
789	      lastval++;
790	    }
791	  fprintf_filtered (stream, "}");
792	}
793      break;
794
795    case TYPE_CODE_VOID:
796      fprintf_filtered (stream, "void");
797      break;
798
799    case TYPE_CODE_UNDEF:
800      fprintf_filtered (stream, "struct <unknown>");
801      break;
802
803    case TYPE_CODE_ERROR:
804      fprintf_filtered (stream, "<unknown type>");
805      break;
806
807    case TYPE_CODE_RANGE:
808      /* This should not occur */
809      fprintf_filtered (stream, "<range type>");
810      break;
811
812    default:
813      /* Handle types not explicitly handled by the other cases,
814	 such as fundamental types.  For these, just print whatever
815	 the type name is, as recorded in the type itself.  If there
816	 is no type name, then complain. */
817      if (TYPE_NAME (type) != NULL)
818	{
819	  fputs_filtered (TYPE_NAME (type), stream);
820	}
821      else
822	{
823	  /* At least for dump_symtab, it is important that this not be
824	     an error ().  */
825	  fprintf_filtered (stream, "<invalid type code %d>",
826			    TYPE_CODE (type));
827	}
828      break;
829    }
830}
831
832