1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1993-1996, 1998-2000
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program 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 of the License, or
10 (at your option) any later version.
12 This program 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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "bfd.h" /* Binary File Description */
27 #include "expression.h"
36 #include "typeprint.h"
38 #include "gdb_string.h"
42 /* Flag indicating target was compiled by HP compiler */
43 extern int hp_som_som_object_present;
45 static void cp_type_print_method_args (struct type ** args, char *prefix,
46 char *varstring, int staticp,
47 struct ui_file *stream);
49 static void c_type_print_args (struct type *, struct ui_file *);
51 static void cp_type_print_derivation_info (struct ui_file *, struct type *);
53 void c_type_print_varspec_prefix (struct type *, struct ui_file *, int,
56 static void c_type_print_cv_qualifier (struct type *, struct ui_file *,
61 /* Print a description of a type in the format of a
62 typedef for the current language.
63 NEW is the new name for a type TYPE. */
66 c_typedef_print (type, new, stream)
69 struct ui_file *stream;
72 switch (current_language->la_language)
77 fprintf_filtered (stream, "typedef ");
78 type_print (type, "", stream, 0);
79 if (TYPE_NAME ((SYMBOL_TYPE (new))) == 0
80 || !STREQ (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_NAME (new)))
81 fprintf_filtered (stream, " %s", SYMBOL_SOURCE_NAME (new));
86 fprintf_filtered (stream, "TYPE ");
87 if (!TYPE_NAME (SYMBOL_TYPE (new)) ||
88 !STREQ (TYPE_NAME (SYMBOL_TYPE (new)), SYMBOL_NAME (new)))
89 fprintf_filtered (stream, "%s = ", SYMBOL_SOURCE_NAME (new));
91 fprintf_filtered (stream, "<builtin> = ");
92 type_print (type, "", stream, 0);
97 fprintf_filtered (stream, "SYNMODE ");
98 if (!TYPE_NAME (SYMBOL_TYPE (new)) ||
99 !STREQ (TYPE_NAME (SYMBOL_TYPE (new)), SYMBOL_NAME (new)))
100 fprintf_filtered (stream, "%s = ", SYMBOL_SOURCE_NAME (new));
102 fprintf_filtered (stream, "<builtin> = ");
103 type_print (type, "", stream, 0);
107 error ("Language not supported.");
109 fprintf_filtered (stream, ";\n");
113 /* LEVEL is the depth to indent lines by. */
116 c_print_type (type, varstring, stream, show, level)
119 struct ui_file *stream;
123 register enum type_code code;
127 CHECK_TYPEDEF (type);
129 c_type_print_base (type, stream, show, level);
130 code = TYPE_CODE (type);
131 if ((varstring != NULL && *varstring != '\0')
133 /* Need a space if going to print stars or brackets;
134 but not if we will print just a type name. */
135 ((show > 0 || TYPE_NAME (type) == 0)
137 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
138 || code == TYPE_CODE_METHOD
139 || code == TYPE_CODE_ARRAY
140 || code == TYPE_CODE_MEMBER
141 || code == TYPE_CODE_REF)))
142 fputs_filtered (" ", stream);
143 c_type_print_varspec_prefix (type, stream, show, 0);
145 if (varstring != NULL)
147 fputs_filtered (varstring, stream);
149 /* For demangled function names, we have the arglist as part of the name,
150 so don't print an additional pair of ()'s */
152 demangled_args = strchr (varstring, '(') != NULL;
153 c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
157 /* If TYPE is a derived type, then print out derivation information.
158 Print only the actual base classes of this type, not the base classes
159 of the base classes. I.E. for the derivation hierarchy:
162 class B : public A {int b; };
163 class C : public B {int c; };
165 Print the type of class C as:
171 Not as the following (like gdb used to), which is not legal C++ syntax for
172 derived types and may be confused with the multiple inheritance form:
174 class C : public B : public A {
178 In general, gdb should try to print the types as closely as possible to
179 the form that they appear in the source code.
180 Note that in case of protected derivation gcc will not say 'protected'
181 but 'private'. The HP's aCC compiler emits specific information for
182 derivation via protected inheritance, so gdb can print it out */
185 cp_type_print_derivation_info (stream, type)
186 struct ui_file *stream;
192 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
194 fputs_filtered (i == 0 ? ": " : ", ", stream);
195 fprintf_filtered (stream, "%s%s ",
196 BASETYPE_VIA_PUBLIC (type, i) ? "public"
197 : (TYPE_FIELD_PROTECTED (type, i) ? "protected" : "private"),
198 BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
199 name = type_name_no_tag (TYPE_BASECLASS (type, i));
200 fprintf_filtered (stream, "%s", name ? name : "(null)");
204 fputs_filtered (" ", stream);
207 /* Print the C++ method arguments ARGS to the file STREAM. */
210 cp_type_print_method_args (args, prefix, varstring, staticp, stream)
215 struct ui_file *stream;
219 fprintf_symbol_filtered (stream, prefix, language_cplus, DMGL_ANSI);
220 fprintf_symbol_filtered (stream, varstring, language_cplus, DMGL_ANSI);
221 fputs_filtered ("(", stream);
222 if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
224 i = !staticp; /* skip the class variable */
227 type_print (args[i++], "", stream, 0);
230 fprintf_filtered (stream, " ...");
233 else if (args[i]->code != TYPE_CODE_VOID)
235 fprintf_filtered (stream, ", ");
241 else if (current_language->la_language == language_cplus)
243 fprintf_filtered (stream, "void");
246 fprintf_filtered (stream, ")");
250 /* Print any asterisks or open-parentheses needed before the
251 variable name (to describe its type).
253 On outermost call, pass 0 for PASSED_A_PTR.
254 On outermost call, SHOW > 0 means should ignore
255 any typename for TYPE and show its details.
256 SHOW is always zero on recursive calls. */
259 c_type_print_varspec_prefix (type, stream, show, passed_a_ptr)
261 struct ui_file *stream;
269 if (TYPE_NAME (type) && show <= 0)
274 switch (TYPE_CODE (type))
277 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
278 fprintf_filtered (stream, "*");
279 c_type_print_cv_qualifier (type, stream, 1, 0);
282 case TYPE_CODE_MEMBER:
284 fprintf_filtered (stream, "(");
285 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
286 fprintf_filtered (stream, " ");
287 name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
289 fputs_filtered (name, stream);
291 c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
292 fprintf_filtered (stream, "::");
295 case TYPE_CODE_METHOD:
297 fprintf_filtered (stream, "(");
298 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
301 fprintf_filtered (stream, " ");
302 c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
303 fprintf_filtered (stream, "::");
308 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
309 fprintf_filtered (stream, "&");
310 c_type_print_cv_qualifier (type, stream, 1, 0);
314 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
316 fprintf_filtered (stream, "(");
319 case TYPE_CODE_ARRAY:
320 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
322 fprintf_filtered (stream, "(");
325 case TYPE_CODE_UNDEF:
326 case TYPE_CODE_STRUCT:
327 case TYPE_CODE_UNION:
332 case TYPE_CODE_ERROR:
336 case TYPE_CODE_RANGE:
337 case TYPE_CODE_STRING:
338 case TYPE_CODE_BITSTRING:
339 case TYPE_CODE_COMPLEX:
340 case TYPE_CODE_TYPEDEF:
341 case TYPE_CODE_TEMPLATE:
342 /* These types need no prefix. They are listed here so that
343 gcc -Wall will reveal any types that haven't been handled. */
346 error ("type not handled in c_type_print_varspec_prefix()");
351 /* Print out "const" and "volatile" attributes.
352 TYPE is a pointer to the type being printed out.
353 STREAM is the output destination.
354 NEED_SPACE = 1 indicates an initial white space is needed */
357 c_type_print_cv_qualifier (type, stream, need_pre_space, need_post_space)
359 struct ui_file *stream;
365 if (TYPE_CONST (type))
368 fprintf_filtered (stream, " ");
369 fprintf_filtered (stream, "const");
373 if (TYPE_VOLATILE (type))
375 if (flag || need_pre_space)
376 fprintf_filtered (stream, " ");
377 fprintf_filtered (stream, "volatile");
381 if (flag && need_post_space)
382 fprintf_filtered (stream, " ");
389 c_type_print_args (type, stream)
391 struct ui_file *stream;
396 fprintf_filtered (stream, "(");
397 args = TYPE_ARG_TYPES (type);
402 fprintf_filtered (stream, "...");
404 else if ((args[1]->code == TYPE_CODE_VOID) &&
405 (current_language->la_language == language_cplus))
407 fprintf_filtered (stream, "void");
412 args[i] != NULL && args[i]->code != TYPE_CODE_VOID;
415 c_print_type (args[i], "", stream, -1, 0);
416 if (args[i + 1] == NULL)
418 fprintf_filtered (stream, "...");
420 else if (args[i + 1]->code != TYPE_CODE_VOID)
422 fprintf_filtered (stream, ",");
428 else if (current_language->la_language == language_cplus)
430 fprintf_filtered (stream, "void");
433 fprintf_filtered (stream, ")");
437 /* Return true iff the j'th overloading of the i'th method of TYPE
438 is a type conversion operator, like `operator int () { ... }'.
439 When listing a class's methods, we don't print the return type of
442 is_type_conversion_operator (struct type *type, int i, int j)
444 /* I think the whole idea of recognizing type conversion operators
445 by their name is pretty terrible. But I don't think our present
446 data structure gives us any other way to tell. If you know of
447 some other way, feel free to rewrite this function. */
448 char *name = TYPE_FN_FIELDLIST_NAME (type, i);
450 if (strncmp (name, "operator", 8) != 0)
454 if (! strchr (" \t\f\n\r", *name))
457 while (strchr (" \t\f\n\r", *name))
460 if (strncmp (name, "new", 3) == 0)
462 else if (strncmp (name, "delete", 6) == 0)
467 /* Is that really the end of the name? */
468 if (('a' <= *name && *name <= 'z')
469 || ('A' <= *name && *name <= 'Z')
470 || ('0' <= *name && *name <= '9')
472 /* No, so the identifier following "operator" must be a type name,
473 and this is a type conversion operator. */
476 /* That was indeed the end of the name, so it was `operator new' or
477 `operator delete', neither of which are type conversion operators. */
482 /* Given a C++ qualified identifier QID, strip off the qualifiers,
483 yielding the unqualified name. The return value is a pointer into
486 It's a pity we don't have this information in some more structured
487 form. Even the author of this function feels that writing little
488 parsers like this everywhere is stupid. */
490 remove_qualifiers (char *qid)
492 int quoted = 0; /* zero if we're not in quotes;
493 '"' if we're in a double-quoted string;
494 '\'' if we're in a single-quoted string. */
495 int depth = 0; /* number of unclosed parens we've seen */
496 char *parenstack = (char *) alloca (strlen (qid));
498 char *last = 0; /* The character after the rightmost
499 `::' token we've seen so far. */
501 for (scan = qid; *scan; scan++)
507 else if (*scan == '\\' && *(scan + 1))
510 else if (scan[0] == ':' && scan[1] == ':')
512 /* If we're inside parenthesis (i.e., an argument list) or
513 angle brackets (i.e., a list of template arguments), then
514 we don't record the position of this :: token, since it's
515 not relevant to the top-level structure we're trying
523 else if (*scan == '"' || *scan == '\'')
525 else if (*scan == '(')
526 parenstack[depth++] = ')';
527 else if (*scan == '[')
528 parenstack[depth++] = ']';
529 /* We're going to treat <> as a pair of matching characters,
530 since we're more likely to see those in template id's than
531 real less-than characters. What a crock. */
532 else if (*scan == '<')
533 parenstack[depth++] = '>';
534 else if (*scan == ')' || *scan == ']' || *scan == '>')
536 if (depth > 0 && parenstack[depth - 1] == *scan)
540 /* We're going to do a little error recovery here. If we
541 don't find a match for *scan on the paren stack, but
542 there is something lower on the stack that does match, we
543 pop the stack to that point. */
546 for (i = depth - 1; i >= 0; i--)
547 if (parenstack[i] == *scan)
559 /* We didn't find any :: tokens at the top level, so declare the
560 whole thing an unqualified identifier. */
565 /* Print any array sizes, function arguments or close parentheses
566 needed after the variable name (to describe its type).
567 Args work like c_type_print_varspec_prefix. */
570 c_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
572 struct ui_file *stream;
580 if (TYPE_NAME (type) && show <= 0)
585 switch (TYPE_CODE (type))
587 case TYPE_CODE_ARRAY:
589 fprintf_filtered (stream, ")");
591 fprintf_filtered (stream, "[");
592 if (TYPE_LENGTH (type) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
593 && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
594 fprintf_filtered (stream, "%d",
596 / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
597 fprintf_filtered (stream, "]");
599 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
602 case TYPE_CODE_MEMBER:
604 fprintf_filtered (stream, ")");
605 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
608 case TYPE_CODE_METHOD:
610 fprintf_filtered (stream, ")");
611 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
614 c_type_print_args (type, stream);
620 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
625 fprintf_filtered (stream, ")");
628 int i, len = TYPE_NFIELDS (type);
629 fprintf_filtered (stream, "(");
630 if ((len == 0) && (current_language->la_language == language_cplus))
632 fprintf_filtered (stream, "void");
635 for (i = 0; i < len; i++)
639 fputs_filtered (", ", stream);
642 c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
644 fprintf_filtered (stream, ")");
646 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
650 case TYPE_CODE_UNDEF:
651 case TYPE_CODE_STRUCT:
652 case TYPE_CODE_UNION:
657 case TYPE_CODE_ERROR:
661 case TYPE_CODE_RANGE:
662 case TYPE_CODE_STRING:
663 case TYPE_CODE_BITSTRING:
664 case TYPE_CODE_COMPLEX:
665 case TYPE_CODE_TYPEDEF:
666 case TYPE_CODE_TEMPLATE:
667 /* These types do not need a suffix. They are listed so that
668 gcc -Wall will report types that may not have been considered. */
671 error ("type not handled in c_type_print_varspec_suffix()");
676 /* Print the name of the type (or the ultimate pointer target,
677 function value or array element), or the description of a
680 SHOW positive means print details about the type (e.g. enum values),
681 and print structure elements passing SHOW - 1 for show.
682 SHOW negative means just print the type name or struct tag if there is one.
683 If there is no name, print something sensible but concise like
685 SHOW zero means just print the type name or struct tag if there is one.
686 If there is no name, print something sensible but not as concise like
687 "struct {int x; int y;}".
689 LEVEL is the number of spaces to indent by.
690 We increase it for some recursive calls. */
693 c_type_print_base (type, stream, show, level)
695 struct ui_file *stream;
701 register int lastval;
703 char *demangled_name;
704 char *demangled_no_static;
707 s_none, s_public, s_private, s_protected
710 int need_access_label = 0;
718 fputs_filtered ("<type unknown>", stream);
722 /* When SHOW is zero or less, and there is a valid type name, then always
723 just print the type name directly from the type. */
724 /* If we have "typedef struct foo {. . .} bar;" do we want to print it
725 as "struct foo" or as "bar"? Pick the latter, because C++ folk tend
726 to expect things like "class5 *foo" rather than "struct class5 *foo". */
729 && TYPE_NAME (type) != NULL)
731 c_type_print_cv_qualifier (type, stream, 0, 1);
732 fputs_filtered (TYPE_NAME (type), stream);
736 CHECK_TYPEDEF (type);
738 switch (TYPE_CODE (type))
740 case TYPE_CODE_TYPEDEF:
741 case TYPE_CODE_ARRAY:
743 case TYPE_CODE_MEMBER:
746 case TYPE_CODE_METHOD:
747 c_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
750 case TYPE_CODE_STRUCT:
751 c_type_print_cv_qualifier (type, stream, 0, 1);
752 /* Note TYPE_CODE_STRUCT and TYPE_CODE_CLASS have the same value,
753 * so we use another means for distinguishing them.
755 if (HAVE_CPLUS_STRUCT (type))
757 switch (TYPE_DECLARED_TYPE (type))
759 case DECLARED_TYPE_CLASS:
760 fprintf_filtered (stream, "class ");
762 case DECLARED_TYPE_UNION:
763 fprintf_filtered (stream, "union ");
765 case DECLARED_TYPE_STRUCT:
766 fprintf_filtered (stream, "struct ");
769 /* If there is a CPLUS_STRUCT, assume class if not
770 * otherwise specified in the declared_type field.
772 fprintf_filtered (stream, "class ");
778 /* If not CPLUS_STRUCT, then assume it's a C struct */
779 fprintf_filtered (stream, "struct ");
783 case TYPE_CODE_UNION:
784 c_type_print_cv_qualifier (type, stream, 0, 1);
785 fprintf_filtered (stream, "union ");
789 /* Print the tag if it exists.
790 * The HP aCC compiler emits
791 * a spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
792 * tag for unnamed struct/union/enum's, which we don't
795 if (TYPE_TAG_NAME (type) != NULL &&
796 strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
798 fputs_filtered (TYPE_TAG_NAME (type), stream);
800 fputs_filtered (" ", stream);
805 /* If we just printed a tag name, no need to print anything else. */
806 if (TYPE_TAG_NAME (type) == NULL)
807 fprintf_filtered (stream, "{...}");
809 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
811 cp_type_print_derivation_info (stream, type);
813 fprintf_filtered (stream, "{\n");
814 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
816 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
817 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
819 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
822 /* Start off with no specific section type, so we can print
823 one for the first field we find, and use that section type
824 thereafter until we find another type. */
826 section_type = s_none;
828 /* For a class, if all members are private, there's no need
829 for a "private:" label; similarly, for a struct or union
830 masquerading as a class, if all members are public, there's
831 no need for a "public:" label. */
833 if ((TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_CLASS) ||
834 (TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_TEMPLATE))
837 len = TYPE_NFIELDS (type);
838 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
839 if (!TYPE_FIELD_PRIVATE (type, i))
841 need_access_label = 1;
845 if (!need_access_label)
847 len2 = TYPE_NFN_FIELDS (type);
848 for (j = 0; j < len2; j++)
850 len = TYPE_FN_FIELDLIST_LENGTH (type, j);
851 for (i = 0; i < len; i++)
852 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i))
854 need_access_label = 1;
857 if (need_access_label)
862 else if ((TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_STRUCT) ||
863 (TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_UNION))
866 len = TYPE_NFIELDS (type);
867 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
868 if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i))
870 need_access_label = 1;
874 if (!need_access_label)
876 len2 = TYPE_NFN_FIELDS (type);
877 for (j = 0; j < len2; j++)
880 len = TYPE_FN_FIELDLIST_LENGTH (type, j);
881 for (i = 0; i < len; i++)
882 if (TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i) ||
883 TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type, j), i))
885 need_access_label = 1;
888 if (need_access_label)
894 /* If there is a base class for this type,
895 do not print the field that it occupies. */
897 len = TYPE_NFIELDS (type);
898 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
901 /* Don't print out virtual function table. */
902 /* HP ANSI C++ case */
903 if (TYPE_HAS_VTABLE (type) && (STREQN (TYPE_FIELD_NAME (type, i), "__vfp", 5)))
905 /* Other compilers */
906 if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5)
907 && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
910 /* If this is a C++ class we can print the various C++ section
913 if (HAVE_CPLUS_STRUCT (type) && need_access_label)
915 if (TYPE_FIELD_PROTECTED (type, i))
917 if (section_type != s_protected)
919 section_type = s_protected;
920 fprintfi_filtered (level + 2, stream,
924 else if (TYPE_FIELD_PRIVATE (type, i))
926 if (section_type != s_private)
928 section_type = s_private;
929 fprintfi_filtered (level + 2, stream, "private:\n");
934 if (section_type != s_public)
936 section_type = s_public;
937 fprintfi_filtered (level + 2, stream, "public:\n");
942 print_spaces_filtered (level + 4, stream);
943 if (TYPE_FIELD_STATIC (type, i))
945 fprintf_filtered (stream, "static ");
947 c_print_type (TYPE_FIELD_TYPE (type, i),
948 TYPE_FIELD_NAME (type, i),
949 stream, show - 1, level + 4);
950 if (!TYPE_FIELD_STATIC (type, i)
951 && TYPE_FIELD_PACKED (type, i))
953 /* It is a bitfield. This code does not attempt
954 to look at the bitpos and reconstruct filler,
955 unnamed fields. This would lead to misleading
956 results if the compiler does not put out fields
957 for such things (I don't know what it does). */
958 fprintf_filtered (stream, " : %d",
959 TYPE_FIELD_BITSIZE (type, i));
961 fprintf_filtered (stream, ";\n");
964 /* If there are both fields and methods, put a space between. */
965 len = TYPE_NFN_FIELDS (type);
966 if (len && section_type != s_none)
967 fprintf_filtered (stream, "\n");
969 /* C++: print out the methods */
970 for (i = 0; i < len; i++)
972 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
973 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
974 char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
975 char *name = type_name_no_tag (type);
976 int is_constructor = name && STREQ (method_name, name);
977 for (j = 0; j < len2; j++)
979 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
980 int is_full_physname_constructor =
981 ((physname[0] == '_' && physname[1] == '_'
982 && strchr ("0123456789Qt", physname[2]))
983 || STREQN (physname, "__ct__", 6)
984 || DESTRUCTOR_PREFIX_P (physname)
985 || STREQN (physname, "__dt__", 6));
988 if (TYPE_FN_FIELD_PROTECTED (f, j))
990 if (section_type != s_protected)
992 section_type = s_protected;
993 fprintfi_filtered (level + 2, stream,
997 else if (TYPE_FN_FIELD_PRIVATE (f, j))
999 if (section_type != s_private)
1001 section_type = s_private;
1002 fprintfi_filtered (level + 2, stream, "private:\n");
1007 if (section_type != s_public)
1009 section_type = s_public;
1010 fprintfi_filtered (level + 2, stream, "public:\n");
1014 print_spaces_filtered (level + 4, stream);
1015 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1016 fprintf_filtered (stream, "virtual ");
1017 else if (TYPE_FN_FIELD_STATIC_P (f, j))
1018 fprintf_filtered (stream, "static ");
1019 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1021 /* Keep GDB from crashing here. */
1022 fprintf_filtered (stream, "<undefined type> %s;\n",
1023 TYPE_FN_FIELD_PHYSNAME (f, j));
1026 else if (!is_constructor && /* constructors don't have declared types */
1027 !is_full_physname_constructor && /* " " */
1028 !is_type_conversion_operator (type, i, j))
1030 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1032 fputs_filtered (" ", stream);
1034 if (TYPE_FN_FIELD_STUB (f, j))
1035 /* Build something we can demangle. */
1036 mangled_name = gdb_mangle_name (type, i, j);
1038 mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
1041 cplus_demangle (mangled_name,
1042 DMGL_ANSI | DMGL_PARAMS);
1043 if (demangled_name == NULL)
1045 /* in some cases (for instance with the HP demangling),
1046 if a function has more than 10 arguments,
1047 the demangling will fail.
1048 Let's try to reconstruct the function signature from
1049 the symbol information */
1050 if (!TYPE_FN_FIELD_STUB (f, j))
1051 cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j), "",
1053 TYPE_FN_FIELD_STATIC_P (f, j),
1056 fprintf_filtered (stream, "<badly mangled name '%s'>",
1062 char *demangled_no_class
1063 = remove_qualifiers (demangled_name);
1065 /* get rid of the `static' appended by the demangler */
1066 p = strstr (demangled_no_class, " static");
1069 int length = p - demangled_no_class;
1070 demangled_no_static = (char *) xmalloc (length + 1);
1071 strncpy (demangled_no_static, demangled_no_class, length);
1072 *(demangled_no_static + length) = '\0';
1073 fputs_filtered (demangled_no_static, stream);
1074 free (demangled_no_static);
1077 fputs_filtered (demangled_no_class, stream);
1078 free (demangled_name);
1081 if (TYPE_FN_FIELD_STUB (f, j))
1082 free (mangled_name);
1084 fprintf_filtered (stream, ";\n");
1088 fprintfi_filtered (level, stream, "}");
1090 if (TYPE_LOCALTYPE_PTR (type) && show >= 0)
1091 fprintfi_filtered (level, stream, " (Local at %s:%d)\n",
1092 TYPE_LOCALTYPE_FILE (type),
1093 TYPE_LOCALTYPE_LINE (type));
1095 if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE)
1099 case TYPE_CODE_ENUM:
1100 c_type_print_cv_qualifier (type, stream, 0, 1);
1101 /* HP C supports sized enums */
1102 if (hp_som_som_object_present)
1103 switch (TYPE_LENGTH (type))
1106 fputs_filtered ("char ", stream);
1109 fputs_filtered ("short ", stream);
1114 fprintf_filtered (stream, "enum ");
1115 /* Print the tag name if it exists.
1116 The aCC compiler emits a spurious
1117 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1118 tag for unnamed struct/union/enum's, which we don't
1120 if (TYPE_TAG_NAME (type) != NULL &&
1121 strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
1123 fputs_filtered (TYPE_TAG_NAME (type), stream);
1125 fputs_filtered (" ", stream);
1131 /* If we just printed a tag name, no need to print anything else. */
1132 if (TYPE_TAG_NAME (type) == NULL)
1133 fprintf_filtered (stream, "{...}");
1135 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
1137 fprintf_filtered (stream, "{");
1138 len = TYPE_NFIELDS (type);
1140 for (i = 0; i < len; i++)
1144 fprintf_filtered (stream, ", ");
1146 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1147 if (lastval != TYPE_FIELD_BITPOS (type, i))
1149 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
1150 lastval = TYPE_FIELD_BITPOS (type, i);
1154 fprintf_filtered (stream, "}");
1158 case TYPE_CODE_VOID:
1159 fprintf_filtered (stream, "void");
1162 case TYPE_CODE_UNDEF:
1163 fprintf_filtered (stream, "struct <unknown>");
1166 case TYPE_CODE_ERROR:
1167 fprintf_filtered (stream, "<unknown type>");
1170 case TYPE_CODE_RANGE:
1171 /* This should not occur */
1172 fprintf_filtered (stream, "<range type>");
1175 case TYPE_CODE_TEMPLATE:
1176 /* Called on "ptype t" where "t" is a template.
1177 Prints the template header (with args), e.g.:
1178 template <class T1, class T2> class "
1179 and then merges with the struct/union/class code to
1180 print the rest of the definition. */
1181 c_type_print_cv_qualifier (type, stream, 0, 1);
1182 fprintf_filtered (stream, "template <");
1183 for (i = 0; i < TYPE_NTEMPLATE_ARGS (type); i++)
1185 struct template_arg templ_arg;
1186 templ_arg = TYPE_TEMPLATE_ARG (type, i);
1187 fprintf_filtered (stream, "class %s", templ_arg.name);
1188 if (i < TYPE_NTEMPLATE_ARGS (type) - 1)
1189 fprintf_filtered (stream, ", ");
1191 fprintf_filtered (stream, "> class ");
1192 /* Yuck, factor this out to a subroutine so we can call
1193 it and return to the point marked with the "goback:" label... - RT */
1196 if (TYPE_NINSTANTIATIONS (type) > 0)
1198 fprintf_filtered (stream, "\ntemplate instantiations:\n");
1199 for (i = 0; i < TYPE_NINSTANTIATIONS (type); i++)
1201 fprintf_filtered (stream, " ");
1202 c_type_print_base (TYPE_INSTANTIATION (type, i), stream, 0, level);
1203 if (i < TYPE_NINSTANTIATIONS (type) - 1)
1204 fprintf_filtered (stream, "\n");
1210 /* Handle types not explicitly handled by the other cases,
1211 such as fundamental types. For these, just print whatever
1212 the type name is, as recorded in the type itself. If there
1213 is no type name, then complain. */
1214 if (TYPE_NAME (type) != NULL)
1216 c_type_print_cv_qualifier (type, stream, 0, 1);
1217 fputs_filtered (TYPE_NAME (type), stream);
1221 /* At least for dump_symtab, it is important that this not be
1223 fprintf_filtered (stream, "<invalid type code %d>",