1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #include "bfd.h" /* Binary File Description */
28 #include "expression.h"
37 #include "typeprint.h"
40 #include "gdb_string.h"
43 /* Flag indicating target was compiled by HP compiler */
44 extern int hp_som_som_object_present;
46 static void cp_type_print_method_args (struct type ** args, char *prefix,
47 char *varstring, int staticp,
48 struct ui_file *stream);
50 static void c_type_print_args (struct type *, struct ui_file *);
52 static void cp_type_print_derivation_info (struct ui_file *, struct type *);
54 void c_type_print_varspec_prefix (struct type *, struct ui_file *, int,
57 static void c_type_print_cv_qualifier (struct type *, struct ui_file *,
63 /* LEVEL is the depth to indent lines by. */
66 c_print_type (struct type *type, char *varstring, struct ui_file *stream,
69 register enum type_code code;
75 c_type_print_base (type, stream, show, level);
76 code = TYPE_CODE (type);
77 if ((varstring != NULL && *varstring != '\0')
79 /* Need a space if going to print stars or brackets;
80 but not if we will print just a type name. */
81 ((show > 0 || TYPE_NAME (type) == 0)
83 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
84 || code == TYPE_CODE_METHOD
85 || code == TYPE_CODE_ARRAY
86 || code == TYPE_CODE_MEMBER
87 || code == TYPE_CODE_REF)))
88 fputs_filtered (" ", stream);
89 c_type_print_varspec_prefix (type, stream, show, 0);
91 if (varstring != NULL)
93 fputs_filtered (varstring, stream);
95 /* For demangled function names, we have the arglist as part of the name,
96 so don't print an additional pair of ()'s */
98 demangled_args = strchr (varstring, '(') != NULL;
99 c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
103 /* If TYPE is a derived type, then print out derivation information.
104 Print only the actual base classes of this type, not the base classes
105 of the base classes. I.E. for the derivation hierarchy:
108 class B : public A {int b; };
109 class C : public B {int c; };
111 Print the type of class C as:
117 Not as the following (like gdb used to), which is not legal C++ syntax for
118 derived types and may be confused with the multiple inheritance form:
120 class C : public B : public A {
124 In general, gdb should try to print the types as closely as possible to
125 the form that they appear in the source code.
126 Note that in case of protected derivation gcc will not say 'protected'
127 but 'private'. The HP's aCC compiler emits specific information for
128 derivation via protected inheritance, so gdb can print it out */
131 cp_type_print_derivation_info (struct ui_file *stream, struct type *type)
136 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
138 fputs_filtered (i == 0 ? ": " : ", ", stream);
139 fprintf_filtered (stream, "%s%s ",
140 BASETYPE_VIA_PUBLIC (type, i) ? "public"
141 : (TYPE_FIELD_PROTECTED (type, i) ? "protected" : "private"),
142 BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
143 name = type_name_no_tag (TYPE_BASECLASS (type, i));
144 fprintf_filtered (stream, "%s", name ? name : "(null)");
148 fputs_filtered (" ", stream);
151 /* Print the C++ method arguments ARGS to the file STREAM. */
154 cp_type_print_method_args (struct type **args, char *prefix, char *varstring,
155 int staticp, struct ui_file *stream)
159 fprintf_symbol_filtered (stream, prefix, language_cplus, DMGL_ANSI);
160 fprintf_symbol_filtered (stream, varstring, language_cplus, DMGL_ANSI);
161 fputs_filtered ("(", stream);
162 if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
164 i = !staticp; /* skip the class variable */
167 type_print (args[i++], "", stream, 0);
170 fprintf_filtered (stream, " ...");
173 else if (args[i]->code != TYPE_CODE_VOID)
175 fprintf_filtered (stream, ", ");
181 else if (current_language->la_language == language_cplus)
183 fprintf_filtered (stream, "void");
186 fprintf_filtered (stream, ")");
190 /* Print any asterisks or open-parentheses needed before the
191 variable name (to describe its type).
193 On outermost call, pass 0 for PASSED_A_PTR.
194 On outermost call, SHOW > 0 means should ignore
195 any typename for TYPE and show its details.
196 SHOW is always zero on recursive calls. */
199 c_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
200 int show, int passed_a_ptr)
206 if (TYPE_NAME (type) && show <= 0)
211 switch (TYPE_CODE (type))
214 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
215 fprintf_filtered (stream, "*");
216 c_type_print_cv_qualifier (type, stream, 1, 0);
219 case TYPE_CODE_MEMBER:
221 fprintf_filtered (stream, "(");
222 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
223 fprintf_filtered (stream, " ");
224 name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
226 fputs_filtered (name, stream);
228 c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
229 fprintf_filtered (stream, "::");
232 case TYPE_CODE_METHOD:
234 fprintf_filtered (stream, "(");
235 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
238 fprintf_filtered (stream, " ");
239 c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
240 fprintf_filtered (stream, "::");
245 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
246 fprintf_filtered (stream, "&");
247 c_type_print_cv_qualifier (type, stream, 1, 0);
251 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
253 fprintf_filtered (stream, "(");
256 case TYPE_CODE_ARRAY:
257 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
259 fprintf_filtered (stream, "(");
262 case TYPE_CODE_UNDEF:
263 case TYPE_CODE_STRUCT:
264 case TYPE_CODE_UNION:
269 case TYPE_CODE_ERROR:
273 case TYPE_CODE_RANGE:
274 case TYPE_CODE_STRING:
275 case TYPE_CODE_BITSTRING:
276 case TYPE_CODE_COMPLEX:
277 case TYPE_CODE_TYPEDEF:
278 case TYPE_CODE_TEMPLATE:
279 /* These types need no prefix. They are listed here so that
280 gcc -Wall will reveal any types that haven't been handled. */
283 error ("type not handled in c_type_print_varspec_prefix()");
288 /* Print out "const" and "volatile" attributes.
289 TYPE is a pointer to the type being printed out.
290 STREAM is the output destination.
291 NEED_SPACE = 1 indicates an initial white space is needed */
294 c_type_print_cv_qualifier (struct type *type, struct ui_file *stream,
295 int need_pre_space, int need_post_space)
299 if (TYPE_CONST (type))
302 fprintf_filtered (stream, " ");
303 fprintf_filtered (stream, "const");
307 if (TYPE_VOLATILE (type))
309 if (flag || need_pre_space)
310 fprintf_filtered (stream, " ");
311 fprintf_filtered (stream, "volatile");
315 if (flag && need_post_space)
316 fprintf_filtered (stream, " ");
323 c_type_print_args (struct type *type, struct ui_file *stream)
328 fprintf_filtered (stream, "(");
329 args = TYPE_ARG_TYPES (type);
334 fprintf_filtered (stream, "...");
336 else if ((args[1]->code == TYPE_CODE_VOID) &&
337 (current_language->la_language == language_cplus))
339 fprintf_filtered (stream, "void");
344 args[i] != NULL && args[i]->code != TYPE_CODE_VOID;
347 c_print_type (args[i], "", stream, -1, 0);
348 if (args[i + 1] == NULL)
350 fprintf_filtered (stream, "...");
352 else if (args[i + 1]->code != TYPE_CODE_VOID)
354 fprintf_filtered (stream, ",");
360 else if (current_language->la_language == language_cplus)
362 fprintf_filtered (stream, "void");
365 fprintf_filtered (stream, ")");
369 /* Return true iff the j'th overloading of the i'th method of TYPE
370 is a type conversion operator, like `operator int () { ... }'.
371 When listing a class's methods, we don't print the return type of
374 is_type_conversion_operator (struct type *type, int i, int j)
376 /* I think the whole idea of recognizing type conversion operators
377 by their name is pretty terrible. But I don't think our present
378 data structure gives us any other way to tell. If you know of
379 some other way, feel free to rewrite this function. */
380 char *name = TYPE_FN_FIELDLIST_NAME (type, i);
382 if (strncmp (name, "operator", 8) != 0)
386 if (! strchr (" \t\f\n\r", *name))
389 while (strchr (" \t\f\n\r", *name))
392 if (strncmp (name, "new", 3) == 0)
394 else if (strncmp (name, "delete", 6) == 0)
399 /* Is that really the end of the name? */
400 if (('a' <= *name && *name <= 'z')
401 || ('A' <= *name && *name <= 'Z')
402 || ('0' <= *name && *name <= '9')
404 /* No, so the identifier following "operator" must be a type name,
405 and this is a type conversion operator. */
408 /* That was indeed the end of the name, so it was `operator new' or
409 `operator delete', neither of which are type conversion operators. */
414 /* Given a C++ qualified identifier QID, strip off the qualifiers,
415 yielding the unqualified name. The return value is a pointer into
418 It's a pity we don't have this information in some more structured
419 form. Even the author of this function feels that writing little
420 parsers like this everywhere is stupid. */
422 remove_qualifiers (char *qid)
424 int quoted = 0; /* zero if we're not in quotes;
425 '"' if we're in a double-quoted string;
426 '\'' if we're in a single-quoted string. */
427 int depth = 0; /* number of unclosed parens we've seen */
428 char *parenstack = (char *) alloca (strlen (qid));
430 char *last = 0; /* The character after the rightmost
431 `::' token we've seen so far. */
433 for (scan = qid; *scan; scan++)
439 else if (*scan == '\\' && *(scan + 1))
442 else if (scan[0] == ':' && scan[1] == ':')
444 /* If we're inside parenthesis (i.e., an argument list) or
445 angle brackets (i.e., a list of template arguments), then
446 we don't record the position of this :: token, since it's
447 not relevant to the top-level structure we're trying
455 else if (*scan == '"' || *scan == '\'')
457 else if (*scan == '(')
458 parenstack[depth++] = ')';
459 else if (*scan == '[')
460 parenstack[depth++] = ']';
461 /* We're going to treat <> as a pair of matching characters,
462 since we're more likely to see those in template id's than
463 real less-than characters. What a crock. */
464 else if (*scan == '<')
465 parenstack[depth++] = '>';
466 else if (*scan == ')' || *scan == ']' || *scan == '>')
468 if (depth > 0 && parenstack[depth - 1] == *scan)
472 /* We're going to do a little error recovery here. If we
473 don't find a match for *scan on the paren stack, but
474 there is something lower on the stack that does match, we
475 pop the stack to that point. */
478 for (i = depth - 1; i >= 0; i--)
479 if (parenstack[i] == *scan)
491 /* We didn't find any :: tokens at the top level, so declare the
492 whole thing an unqualified identifier. */
497 /* Print any array sizes, function arguments or close parentheses
498 needed after the variable name (to describe its type).
499 Args work like c_type_print_varspec_prefix. */
502 c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
503 int show, int passed_a_ptr, int demangled_args)
508 if (TYPE_NAME (type) && show <= 0)
513 switch (TYPE_CODE (type))
515 case TYPE_CODE_ARRAY:
517 fprintf_filtered (stream, ")");
519 fprintf_filtered (stream, "[");
520 if (TYPE_LENGTH (type) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
521 && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
522 fprintf_filtered (stream, "%d",
524 / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
525 fprintf_filtered (stream, "]");
527 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
530 case TYPE_CODE_MEMBER:
532 fprintf_filtered (stream, ")");
533 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
536 case TYPE_CODE_METHOD:
538 fprintf_filtered (stream, ")");
539 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
542 c_type_print_args (type, stream);
548 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
553 fprintf_filtered (stream, ")");
556 int i, len = TYPE_NFIELDS (type);
557 fprintf_filtered (stream, "(");
558 if ((len == 0) && (current_language->la_language == language_cplus))
560 fprintf_filtered (stream, "void");
563 for (i = 0; i < len; i++)
567 fputs_filtered (", ", stream);
570 c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
572 fprintf_filtered (stream, ")");
574 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
578 case TYPE_CODE_UNDEF:
579 case TYPE_CODE_STRUCT:
580 case TYPE_CODE_UNION:
585 case TYPE_CODE_ERROR:
589 case TYPE_CODE_RANGE:
590 case TYPE_CODE_STRING:
591 case TYPE_CODE_BITSTRING:
592 case TYPE_CODE_COMPLEX:
593 case TYPE_CODE_TYPEDEF:
594 case TYPE_CODE_TEMPLATE:
595 /* These types do not need a suffix. They are listed so that
596 gcc -Wall will report types that may not have been considered. */
599 error ("type not handled in c_type_print_varspec_suffix()");
604 /* Print the name of the type (or the ultimate pointer target,
605 function value or array element), or the description of a
608 SHOW positive means print details about the type (e.g. enum values),
609 and print structure elements passing SHOW - 1 for show.
610 SHOW negative means just print the type name or struct tag if there is one.
611 If there is no name, print something sensible but concise like
613 SHOW zero means just print the type name or struct tag if there is one.
614 If there is no name, print something sensible but not as concise like
615 "struct {int x; int y;}".
617 LEVEL is the number of spaces to indent by.
618 We increase it for some recursive calls. */
621 c_type_print_base (struct type *type, struct ui_file *stream, int show,
626 register int lastval;
628 char *demangled_name;
629 char *demangled_no_static;
632 s_none, s_public, s_private, s_protected
635 int need_access_label = 0;
643 fputs_filtered ("<type unknown>", stream);
647 /* When SHOW is zero or less, and there is a valid type name, then always
648 just print the type name directly from the type. */
649 /* If we have "typedef struct foo {. . .} bar;" do we want to print it
650 as "struct foo" or as "bar"? Pick the latter, because C++ folk tend
651 to expect things like "class5 *foo" rather than "struct class5 *foo". */
654 && TYPE_NAME (type) != NULL)
656 c_type_print_cv_qualifier (type, stream, 0, 1);
657 fputs_filtered (TYPE_NAME (type), stream);
661 CHECK_TYPEDEF (type);
663 switch (TYPE_CODE (type))
665 case TYPE_CODE_TYPEDEF:
666 case TYPE_CODE_ARRAY:
668 case TYPE_CODE_MEMBER:
671 case TYPE_CODE_METHOD:
672 c_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
675 case TYPE_CODE_STRUCT:
676 c_type_print_cv_qualifier (type, stream, 0, 1);
677 /* Note TYPE_CODE_STRUCT and TYPE_CODE_CLASS have the same value,
678 * so we use another means for distinguishing them.
680 if (HAVE_CPLUS_STRUCT (type))
682 switch (TYPE_DECLARED_TYPE (type))
684 case DECLARED_TYPE_CLASS:
685 fprintf_filtered (stream, "class ");
687 case DECLARED_TYPE_UNION:
688 fprintf_filtered (stream, "union ");
690 case DECLARED_TYPE_STRUCT:
691 fprintf_filtered (stream, "struct ");
694 /* If there is a CPLUS_STRUCT, assume class if not
695 * otherwise specified in the declared_type field.
697 fprintf_filtered (stream, "class ");
703 /* If not CPLUS_STRUCT, then assume it's a C struct */
704 fprintf_filtered (stream, "struct ");
708 case TYPE_CODE_UNION:
709 c_type_print_cv_qualifier (type, stream, 0, 1);
710 fprintf_filtered (stream, "union ");
714 /* Print the tag if it exists.
715 * The HP aCC compiler emits
716 * a spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
717 * tag for unnamed struct/union/enum's, which we don't
720 if (TYPE_TAG_NAME (type) != NULL &&
721 strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
723 fputs_filtered (TYPE_TAG_NAME (type), stream);
725 fputs_filtered (" ", stream);
730 /* If we just printed a tag name, no need to print anything else. */
731 if (TYPE_TAG_NAME (type) == NULL)
732 fprintf_filtered (stream, "{...}");
734 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
736 cp_type_print_derivation_info (stream, type);
738 fprintf_filtered (stream, "{\n");
739 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
741 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
742 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
744 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
747 /* Start off with no specific section type, so we can print
748 one for the first field we find, and use that section type
749 thereafter until we find another type. */
751 section_type = s_none;
753 /* For a class, if all members are private, there's no need
754 for a "private:" label; similarly, for a struct or union
755 masquerading as a class, if all members are public, there's
756 no need for a "public:" label. */
758 if ((TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_CLASS) ||
759 (TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_TEMPLATE))
762 len = TYPE_NFIELDS (type);
763 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
764 if (!TYPE_FIELD_PRIVATE (type, i))
766 need_access_label = 1;
770 if (!need_access_label)
772 len2 = TYPE_NFN_FIELDS (type);
773 for (j = 0; j < len2; j++)
775 len = TYPE_FN_FIELDLIST_LENGTH (type, j);
776 for (i = 0; i < len; i++)
777 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i))
779 need_access_label = 1;
782 if (need_access_label)
787 else if ((TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_STRUCT) ||
788 (TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_UNION))
791 len = TYPE_NFIELDS (type);
792 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
793 if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i))
795 need_access_label = 1;
799 if (!need_access_label)
801 len2 = TYPE_NFN_FIELDS (type);
802 for (j = 0; j < len2; j++)
805 len = TYPE_FN_FIELDLIST_LENGTH (type, j);
806 for (i = 0; i < len; i++)
807 if (TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i) ||
808 TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type, j), i))
810 need_access_label = 1;
813 if (need_access_label)
819 /* If there is a base class for this type,
820 do not print the field that it occupies. */
822 len = TYPE_NFIELDS (type);
823 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
826 /* Don't print out virtual function table. */
827 /* HP ANSI C++ case */
828 if (TYPE_HAS_VTABLE (type) && (STREQN (TYPE_FIELD_NAME (type, i), "__vfp", 5)))
830 /* Other compilers */
831 if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5)
832 && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
835 /* If this is a C++ class we can print the various C++ section
838 if (HAVE_CPLUS_STRUCT (type) && need_access_label)
840 if (TYPE_FIELD_PROTECTED (type, i))
842 if (section_type != s_protected)
844 section_type = s_protected;
845 fprintfi_filtered (level + 2, stream,
849 else if (TYPE_FIELD_PRIVATE (type, i))
851 if (section_type != s_private)
853 section_type = s_private;
854 fprintfi_filtered (level + 2, stream, "private:\n");
859 if (section_type != s_public)
861 section_type = s_public;
862 fprintfi_filtered (level + 2, stream, "public:\n");
867 print_spaces_filtered (level + 4, stream);
868 if (TYPE_FIELD_STATIC (type, i))
870 fprintf_filtered (stream, "static ");
872 c_print_type (TYPE_FIELD_TYPE (type, i),
873 TYPE_FIELD_NAME (type, i),
874 stream, show - 1, level + 4);
875 if (!TYPE_FIELD_STATIC (type, i)
876 && TYPE_FIELD_PACKED (type, i))
878 /* It is a bitfield. This code does not attempt
879 to look at the bitpos and reconstruct filler,
880 unnamed fields. This would lead to misleading
881 results if the compiler does not put out fields
882 for such things (I don't know what it does). */
883 fprintf_filtered (stream, " : %d",
884 TYPE_FIELD_BITSIZE (type, i));
886 fprintf_filtered (stream, ";\n");
889 /* If there are both fields and methods, put a space between. */
890 len = TYPE_NFN_FIELDS (type);
891 if (len && section_type != s_none)
892 fprintf_filtered (stream, "\n");
894 /* C++: print out the methods */
895 for (i = 0; i < len; i++)
897 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
898 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
899 char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
900 char *name = type_name_no_tag (type);
901 int is_constructor = name && STREQ (method_name, name);
902 for (j = 0; j < len2; j++)
904 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
905 int is_full_physname_constructor =
906 is_constructor_name (physname)
907 || is_destructor_name (physname)
908 || method_name[0] == '~';
912 if (TYPE_FN_FIELD_PROTECTED (f, j))
914 if (section_type != s_protected)
916 section_type = s_protected;
917 fprintfi_filtered (level + 2, stream,
921 else if (TYPE_FN_FIELD_PRIVATE (f, j))
923 if (section_type != s_private)
925 section_type = s_private;
926 fprintfi_filtered (level + 2, stream, "private:\n");
931 if (section_type != s_public)
933 section_type = s_public;
934 fprintfi_filtered (level + 2, stream, "public:\n");
938 print_spaces_filtered (level + 4, stream);
939 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
940 fprintf_filtered (stream, "virtual ");
941 else if (TYPE_FN_FIELD_STATIC_P (f, j))
942 fprintf_filtered (stream, "static ");
943 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
945 /* Keep GDB from crashing here. */
946 fprintf_filtered (stream, "<undefined type> %s;\n",
947 TYPE_FN_FIELD_PHYSNAME (f, j));
950 else if (!is_constructor && /* constructors don't have declared types */
951 !is_full_physname_constructor && /* " " */
952 !is_type_conversion_operator (type, i, j))
954 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
956 fputs_filtered (" ", stream);
958 if (TYPE_FN_FIELD_STUB (f, j))
959 /* Build something we can demangle. */
960 mangled_name = gdb_mangle_name (type, i, j);
962 mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
965 cplus_demangle (mangled_name,
966 DMGL_ANSI | DMGL_PARAMS);
967 if (demangled_name == NULL)
969 /* in some cases (for instance with the HP demangling),
970 if a function has more than 10 arguments,
971 the demangling will fail.
972 Let's try to reconstruct the function signature from
973 the symbol information */
974 if (!TYPE_FN_FIELD_STUB (f, j))
975 cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j), "",
977 TYPE_FN_FIELD_STATIC_P (f, j),
980 fprintf_filtered (stream, "<badly mangled name '%s'>",
986 char *demangled_no_class
987 = remove_qualifiers (demangled_name);
989 /* get rid of the `static' appended by the demangler */
990 p = strstr (demangled_no_class, " static");
993 int length = p - demangled_no_class;
994 demangled_no_static = (char *) xmalloc (length + 1);
995 strncpy (demangled_no_static, demangled_no_class, length);
996 *(demangled_no_static + length) = '\0';
997 fputs_filtered (demangled_no_static, stream);
998 xfree (demangled_no_static);
1001 fputs_filtered (demangled_no_class, stream);
1002 xfree (demangled_name);
1005 if (TYPE_FN_FIELD_STUB (f, j))
1006 xfree (mangled_name);
1008 fprintf_filtered (stream, ";\n");
1012 fprintfi_filtered (level, stream, "}");
1014 if (TYPE_LOCALTYPE_PTR (type) && show >= 0)
1015 fprintfi_filtered (level, stream, " (Local at %s:%d)\n",
1016 TYPE_LOCALTYPE_FILE (type),
1017 TYPE_LOCALTYPE_LINE (type));
1019 if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE)
1023 case TYPE_CODE_ENUM:
1024 c_type_print_cv_qualifier (type, stream, 0, 1);
1025 /* HP C supports sized enums */
1026 if (hp_som_som_object_present)
1027 switch (TYPE_LENGTH (type))
1030 fputs_filtered ("char ", stream);
1033 fputs_filtered ("short ", stream);
1038 fprintf_filtered (stream, "enum ");
1039 /* Print the tag name if it exists.
1040 The aCC compiler emits a spurious
1041 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1042 tag for unnamed struct/union/enum's, which we don't
1044 if (TYPE_TAG_NAME (type) != NULL &&
1045 strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
1047 fputs_filtered (TYPE_TAG_NAME (type), stream);
1049 fputs_filtered (" ", stream);
1055 /* If we just printed a tag name, no need to print anything else. */
1056 if (TYPE_TAG_NAME (type) == NULL)
1057 fprintf_filtered (stream, "{...}");
1059 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
1061 fprintf_filtered (stream, "{");
1062 len = TYPE_NFIELDS (type);
1064 for (i = 0; i < len; i++)
1068 fprintf_filtered (stream, ", ");
1070 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1071 if (lastval != TYPE_FIELD_BITPOS (type, i))
1073 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
1074 lastval = TYPE_FIELD_BITPOS (type, i);
1078 fprintf_filtered (stream, "}");
1082 case TYPE_CODE_VOID:
1083 fprintf_filtered (stream, "void");
1086 case TYPE_CODE_UNDEF:
1087 fprintf_filtered (stream, "struct <unknown>");
1090 case TYPE_CODE_ERROR:
1091 fprintf_filtered (stream, "<unknown type>");
1094 case TYPE_CODE_RANGE:
1095 /* This should not occur */
1096 fprintf_filtered (stream, "<range type>");
1099 case TYPE_CODE_TEMPLATE:
1100 /* Called on "ptype t" where "t" is a template.
1101 Prints the template header (with args), e.g.:
1102 template <class T1, class T2> class "
1103 and then merges with the struct/union/class code to
1104 print the rest of the definition. */
1105 c_type_print_cv_qualifier (type, stream, 0, 1);
1106 fprintf_filtered (stream, "template <");
1107 for (i = 0; i < TYPE_NTEMPLATE_ARGS (type); i++)
1109 struct template_arg templ_arg;
1110 templ_arg = TYPE_TEMPLATE_ARG (type, i);
1111 fprintf_filtered (stream, "class %s", templ_arg.name);
1112 if (i < TYPE_NTEMPLATE_ARGS (type) - 1)
1113 fprintf_filtered (stream, ", ");
1115 fprintf_filtered (stream, "> class ");
1116 /* Yuck, factor this out to a subroutine so we can call
1117 it and return to the point marked with the "goback:" label... - RT */
1120 if (TYPE_NINSTANTIATIONS (type) > 0)
1122 fprintf_filtered (stream, "\ntemplate instantiations:\n");
1123 for (i = 0; i < TYPE_NINSTANTIATIONS (type); i++)
1125 fprintf_filtered (stream, " ");
1126 c_type_print_base (TYPE_INSTANTIATION (type, i), stream, 0, level);
1127 if (i < TYPE_NINSTANTIATIONS (type) - 1)
1128 fprintf_filtered (stream, "\n");
1134 /* Handle types not explicitly handled by the other cases,
1135 such as fundamental types. For these, just print whatever
1136 the type name is, as recorded in the type itself. If there
1137 is no type name, then complain. */
1138 if (TYPE_NAME (type) != NULL)
1140 c_type_print_cv_qualifier (type, stream, 0, 1);
1141 fputs_filtered (TYPE_NAME (type), stream);
1145 /* At least for dump_symtab, it is important that this not be
1147 fprintf_filtered (stream, "<invalid type code %d>",