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 (struct type
*type
, struct symbol
*new, struct ui_file
*stream
)
69 switch (current_language
->la_language
)
74 fprintf_filtered (stream
, "typedef ");
75 type_print (type
, "", stream
, 0);
76 if (TYPE_NAME ((SYMBOL_TYPE (new))) == 0
77 || !STREQ (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_NAME (new)))
78 fprintf_filtered (stream
, " %s", SYMBOL_SOURCE_NAME (new));
83 fprintf_filtered (stream
, "TYPE ");
84 if (!TYPE_NAME (SYMBOL_TYPE (new)) ||
85 !STREQ (TYPE_NAME (SYMBOL_TYPE (new)), SYMBOL_NAME (new)))
86 fprintf_filtered (stream
, "%s = ", SYMBOL_SOURCE_NAME (new));
88 fprintf_filtered (stream
, "<builtin> = ");
89 type_print (type
, "", stream
, 0);
94 fprintf_filtered (stream
, "SYNMODE ");
95 if (!TYPE_NAME (SYMBOL_TYPE (new)) ||
96 !STREQ (TYPE_NAME (SYMBOL_TYPE (new)), SYMBOL_NAME (new)))
97 fprintf_filtered (stream
, "%s = ", SYMBOL_SOURCE_NAME (new));
99 fprintf_filtered (stream
, "<builtin> = ");
100 type_print (type
, "", stream
, 0);
104 error ("Language not supported.");
106 fprintf_filtered (stream
, ";\n");
110 /* LEVEL is the depth to indent lines by. */
113 c_print_type (struct type
*type
, char *varstring
, struct ui_file
*stream
,
116 register enum type_code code
;
120 CHECK_TYPEDEF (type
);
122 c_type_print_base (type
, stream
, show
, level
);
123 code
= TYPE_CODE (type
);
124 if ((varstring
!= NULL
&& *varstring
!= '\0')
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)
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);
138 if (varstring
!= NULL
)
140 fputs_filtered (varstring
, stream
);
142 /* For demangled function names, we have the arglist as part of the name,
143 so don't print an additional pair of ()'s */
145 demangled_args
= strchr (varstring
, '(') != NULL
;
146 c_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);
150 /* If TYPE is a derived type, then print out derivation information.
151 Print only the actual base classes of this type, not the base classes
152 of the base classes. I.E. for the derivation hierarchy:
155 class B : public A {int b; };
156 class C : public B {int c; };
158 Print the type of class C as:
164 Not as the following (like gdb used to), which is not legal C++ syntax for
165 derived types and may be confused with the multiple inheritance form:
167 class C : public B : public A {
171 In general, gdb should try to print the types as closely as possible to
172 the form that they appear in the source code.
173 Note that in case of protected derivation gcc will not say 'protected'
174 but 'private'. The HP's aCC compiler emits specific information for
175 derivation via protected inheritance, so gdb can print it out */
178 cp_type_print_derivation_info (struct ui_file
*stream
, struct type
*type
)
183 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
185 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
186 fprintf_filtered (stream
, "%s%s ",
187 BASETYPE_VIA_PUBLIC (type
, i
) ? "public"
188 : (TYPE_FIELD_PROTECTED (type
, i
) ? "protected" : "private"),
189 BASETYPE_VIA_VIRTUAL (type
, i
) ? " virtual" : "");
190 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
191 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
195 fputs_filtered (" ", stream
);
198 /* Print the C++ method arguments ARGS to the file STREAM. */
201 cp_type_print_method_args (struct type
**args
, char *prefix
, char *varstring
,
202 int staticp
, struct ui_file
*stream
)
206 fprintf_symbol_filtered (stream
, prefix
, language_cplus
, DMGL_ANSI
);
207 fprintf_symbol_filtered (stream
, varstring
, language_cplus
, DMGL_ANSI
);
208 fputs_filtered ("(", stream
);
209 if (args
&& args
[!staticp
] && args
[!staticp
]->code
!= TYPE_CODE_VOID
)
211 i
= !staticp
; /* skip the class variable */
214 type_print (args
[i
++], "", stream
, 0);
217 fprintf_filtered (stream
, " ...");
220 else if (args
[i
]->code
!= TYPE_CODE_VOID
)
222 fprintf_filtered (stream
, ", ");
228 else if (current_language
->la_language
== language_cplus
)
230 fprintf_filtered (stream
, "void");
233 fprintf_filtered (stream
, ")");
237 /* Print any asterisks or open-parentheses needed before the
238 variable name (to describe its type).
240 On outermost call, pass 0 for PASSED_A_PTR.
241 On outermost call, SHOW > 0 means should ignore
242 any typename for TYPE and show its details.
243 SHOW is always zero on recursive calls. */
246 c_type_print_varspec_prefix (struct type
*type
, struct ui_file
*stream
,
247 int show
, int passed_a_ptr
)
253 if (TYPE_NAME (type
) && show
<= 0)
258 switch (TYPE_CODE (type
))
261 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
262 fprintf_filtered (stream
, "*");
263 c_type_print_cv_qualifier (type
, stream
, 1, 0);
266 case TYPE_CODE_MEMBER
:
268 fprintf_filtered (stream
, "(");
269 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
270 fprintf_filtered (stream
, " ");
271 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
273 fputs_filtered (name
, stream
);
275 c_type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
276 fprintf_filtered (stream
, "::");
279 case TYPE_CODE_METHOD
:
281 fprintf_filtered (stream
, "(");
282 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
285 fprintf_filtered (stream
, " ");
286 c_type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
287 fprintf_filtered (stream
, "::");
292 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
293 fprintf_filtered (stream
, "&");
294 c_type_print_cv_qualifier (type
, stream
, 1, 0);
298 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
300 fprintf_filtered (stream
, "(");
303 case TYPE_CODE_ARRAY
:
304 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
306 fprintf_filtered (stream
, "(");
309 case TYPE_CODE_UNDEF
:
310 case TYPE_CODE_STRUCT
:
311 case TYPE_CODE_UNION
:
316 case TYPE_CODE_ERROR
:
320 case TYPE_CODE_RANGE
:
321 case TYPE_CODE_STRING
:
322 case TYPE_CODE_BITSTRING
:
323 case TYPE_CODE_COMPLEX
:
324 case TYPE_CODE_TYPEDEF
:
325 case TYPE_CODE_TEMPLATE
:
326 /* These types need no prefix. They are listed here so that
327 gcc -Wall will reveal any types that haven't been handled. */
330 error ("type not handled in c_type_print_varspec_prefix()");
335 /* Print out "const" and "volatile" attributes.
336 TYPE is a pointer to the type being printed out.
337 STREAM is the output destination.
338 NEED_SPACE = 1 indicates an initial white space is needed */
341 c_type_print_cv_qualifier (struct type
*type
, struct ui_file
*stream
,
342 int need_pre_space
, int need_post_space
)
346 if (TYPE_CONST (type
))
349 fprintf_filtered (stream
, " ");
350 fprintf_filtered (stream
, "const");
354 if (TYPE_VOLATILE (type
))
356 if (flag
|| need_pre_space
)
357 fprintf_filtered (stream
, " ");
358 fprintf_filtered (stream
, "volatile");
362 if (flag
&& need_post_space
)
363 fprintf_filtered (stream
, " ");
370 c_type_print_args (struct type
*type
, struct ui_file
*stream
)
375 fprintf_filtered (stream
, "(");
376 args
= TYPE_ARG_TYPES (type
);
381 fprintf_filtered (stream
, "...");
383 else if ((args
[1]->code
== TYPE_CODE_VOID
) &&
384 (current_language
->la_language
== language_cplus
))
386 fprintf_filtered (stream
, "void");
391 args
[i
] != NULL
&& args
[i
]->code
!= TYPE_CODE_VOID
;
394 c_print_type (args
[i
], "", stream
, -1, 0);
395 if (args
[i
+ 1] == NULL
)
397 fprintf_filtered (stream
, "...");
399 else if (args
[i
+ 1]->code
!= TYPE_CODE_VOID
)
401 fprintf_filtered (stream
, ",");
407 else if (current_language
->la_language
== language_cplus
)
409 fprintf_filtered (stream
, "void");
412 fprintf_filtered (stream
, ")");
416 /* Return true iff the j'th overloading of the i'th method of TYPE
417 is a type conversion operator, like `operator int () { ... }'.
418 When listing a class's methods, we don't print the return type of
421 is_type_conversion_operator (struct type
*type
, int i
, int j
)
423 /* I think the whole idea of recognizing type conversion operators
424 by their name is pretty terrible. But I don't think our present
425 data structure gives us any other way to tell. If you know of
426 some other way, feel free to rewrite this function. */
427 char *name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
429 if (strncmp (name
, "operator", 8) != 0)
433 if (! strchr (" \t\f\n\r", *name
))
436 while (strchr (" \t\f\n\r", *name
))
439 if (strncmp (name
, "new", 3) == 0)
441 else if (strncmp (name
, "delete", 6) == 0)
446 /* Is that really the end of the name? */
447 if (('a' <= *name
&& *name
<= 'z')
448 || ('A' <= *name
&& *name
<= 'Z')
449 || ('0' <= *name
&& *name
<= '9')
451 /* No, so the identifier following "operator" must be a type name,
452 and this is a type conversion operator. */
455 /* That was indeed the end of the name, so it was `operator new' or
456 `operator delete', neither of which are type conversion operators. */
461 /* Given a C++ qualified identifier QID, strip off the qualifiers,
462 yielding the unqualified name. The return value is a pointer into
465 It's a pity we don't have this information in some more structured
466 form. Even the author of this function feels that writing little
467 parsers like this everywhere is stupid. */
469 remove_qualifiers (char *qid
)
471 int quoted
= 0; /* zero if we're not in quotes;
472 '"' if we're in a double-quoted string;
473 '\'' if we're in a single-quoted string. */
474 int depth
= 0; /* number of unclosed parens we've seen */
475 char *parenstack
= (char *) alloca (strlen (qid
));
477 char *last
= 0; /* The character after the rightmost
478 `::' token we've seen so far. */
480 for (scan
= qid
; *scan
; scan
++)
486 else if (*scan
== '\\' && *(scan
+ 1))
489 else if (scan
[0] == ':' && scan
[1] == ':')
491 /* If we're inside parenthesis (i.e., an argument list) or
492 angle brackets (i.e., a list of template arguments), then
493 we don't record the position of this :: token, since it's
494 not relevant to the top-level structure we're trying
502 else if (*scan
== '"' || *scan
== '\'')
504 else if (*scan
== '(')
505 parenstack
[depth
++] = ')';
506 else if (*scan
== '[')
507 parenstack
[depth
++] = ']';
508 /* We're going to treat <> as a pair of matching characters,
509 since we're more likely to see those in template id's than
510 real less-than characters. What a crock. */
511 else if (*scan
== '<')
512 parenstack
[depth
++] = '>';
513 else if (*scan
== ')' || *scan
== ']' || *scan
== '>')
515 if (depth
> 0 && parenstack
[depth
- 1] == *scan
)
519 /* We're going to do a little error recovery here. If we
520 don't find a match for *scan on the paren stack, but
521 there is something lower on the stack that does match, we
522 pop the stack to that point. */
525 for (i
= depth
- 1; i
>= 0; i
--)
526 if (parenstack
[i
] == *scan
)
538 /* We didn't find any :: tokens at the top level, so declare the
539 whole thing an unqualified identifier. */
544 /* Print any array sizes, function arguments or close parentheses
545 needed after the variable name (to describe its type).
546 Args work like c_type_print_varspec_prefix. */
549 c_type_print_varspec_suffix (struct type
*type
, struct ui_file
*stream
,
550 int show
, int passed_a_ptr
, int demangled_args
)
555 if (TYPE_NAME (type
) && show
<= 0)
560 switch (TYPE_CODE (type
))
562 case TYPE_CODE_ARRAY
:
564 fprintf_filtered (stream
, ")");
566 fprintf_filtered (stream
, "[");
567 if (TYPE_LENGTH (type
) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0
568 && TYPE_ARRAY_UPPER_BOUND_TYPE (type
) != BOUND_CANNOT_BE_DETERMINED
)
569 fprintf_filtered (stream
, "%d",
571 / TYPE_LENGTH (TYPE_TARGET_TYPE (type
))));
572 fprintf_filtered (stream
, "]");
574 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
577 case TYPE_CODE_MEMBER
:
579 fprintf_filtered (stream
, ")");
580 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
583 case TYPE_CODE_METHOD
:
585 fprintf_filtered (stream
, ")");
586 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
589 c_type_print_args (type
, stream
);
595 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0);
600 fprintf_filtered (stream
, ")");
603 int i
, len
= TYPE_NFIELDS (type
);
604 fprintf_filtered (stream
, "(");
605 if ((len
== 0) && (current_language
->la_language
== language_cplus
))
607 fprintf_filtered (stream
, "void");
610 for (i
= 0; i
< len
; i
++)
614 fputs_filtered (", ", stream
);
617 c_print_type (TYPE_FIELD_TYPE (type
, i
), "", stream
, -1, 0);
619 fprintf_filtered (stream
, ")");
621 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
625 case TYPE_CODE_UNDEF
:
626 case TYPE_CODE_STRUCT
:
627 case TYPE_CODE_UNION
:
632 case TYPE_CODE_ERROR
:
636 case TYPE_CODE_RANGE
:
637 case TYPE_CODE_STRING
:
638 case TYPE_CODE_BITSTRING
:
639 case TYPE_CODE_COMPLEX
:
640 case TYPE_CODE_TYPEDEF
:
641 case TYPE_CODE_TEMPLATE
:
642 /* These types do not need a suffix. They are listed so that
643 gcc -Wall will report types that may not have been considered. */
646 error ("type not handled in c_type_print_varspec_suffix()");
651 /* Print the name of the type (or the ultimate pointer target,
652 function value or array element), or the description of a
655 SHOW positive means print details about the type (e.g. enum values),
656 and print structure elements passing SHOW - 1 for show.
657 SHOW negative means just print the type name or struct tag if there is one.
658 If there is no name, print something sensible but concise like
660 SHOW zero means just print the type name or struct tag if there is one.
661 If there is no name, print something sensible but not as concise like
662 "struct {int x; int y;}".
664 LEVEL is the number of spaces to indent by.
665 We increase it for some recursive calls. */
668 c_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
673 register int lastval
;
675 char *demangled_name
;
676 char *demangled_no_static
;
679 s_none
, s_public
, s_private
, s_protected
682 int need_access_label
= 0;
690 fputs_filtered ("<type unknown>", stream
);
694 /* When SHOW is zero or less, and there is a valid type name, then always
695 just print the type name directly from the type. */
696 /* If we have "typedef struct foo {. . .} bar;" do we want to print it
697 as "struct foo" or as "bar"? Pick the latter, because C++ folk tend
698 to expect things like "class5 *foo" rather than "struct class5 *foo". */
701 && TYPE_NAME (type
) != NULL
)
703 c_type_print_cv_qualifier (type
, stream
, 0, 1);
704 fputs_filtered (TYPE_NAME (type
), stream
);
708 CHECK_TYPEDEF (type
);
710 switch (TYPE_CODE (type
))
712 case TYPE_CODE_TYPEDEF
:
713 case TYPE_CODE_ARRAY
:
715 case TYPE_CODE_MEMBER
:
718 case TYPE_CODE_METHOD
:
719 c_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
722 case TYPE_CODE_STRUCT
:
723 c_type_print_cv_qualifier (type
, stream
, 0, 1);
724 /* Note TYPE_CODE_STRUCT and TYPE_CODE_CLASS have the same value,
725 * so we use another means for distinguishing them.
727 if (HAVE_CPLUS_STRUCT (type
))
729 switch (TYPE_DECLARED_TYPE (type
))
731 case DECLARED_TYPE_CLASS
:
732 fprintf_filtered (stream
, "class ");
734 case DECLARED_TYPE_UNION
:
735 fprintf_filtered (stream
, "union ");
737 case DECLARED_TYPE_STRUCT
:
738 fprintf_filtered (stream
, "struct ");
741 /* If there is a CPLUS_STRUCT, assume class if not
742 * otherwise specified in the declared_type field.
744 fprintf_filtered (stream
, "class ");
750 /* If not CPLUS_STRUCT, then assume it's a C struct */
751 fprintf_filtered (stream
, "struct ");
755 case TYPE_CODE_UNION
:
756 c_type_print_cv_qualifier (type
, stream
, 0, 1);
757 fprintf_filtered (stream
, "union ");
761 /* Print the tag if it exists.
762 * The HP aCC compiler emits
763 * a spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
764 * tag for unnamed struct/union/enum's, which we don't
767 if (TYPE_TAG_NAME (type
) != NULL
&&
768 strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
770 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
772 fputs_filtered (" ", stream
);
777 /* If we just printed a tag name, no need to print anything else. */
778 if (TYPE_TAG_NAME (type
) == NULL
)
779 fprintf_filtered (stream
, "{...}");
781 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
783 cp_type_print_derivation_info (stream
, type
);
785 fprintf_filtered (stream
, "{\n");
786 if ((TYPE_NFIELDS (type
) == 0) && (TYPE_NFN_FIELDS (type
) == 0))
788 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
789 fprintfi_filtered (level
+ 4, stream
, "<incomplete type>\n");
791 fprintfi_filtered (level
+ 4, stream
, "<no data fields>\n");
794 /* Start off with no specific section type, so we can print
795 one for the first field we find, and use that section type
796 thereafter until we find another type. */
798 section_type
= s_none
;
800 /* For a class, if all members are private, there's no need
801 for a "private:" label; similarly, for a struct or union
802 masquerading as a class, if all members are public, there's
803 no need for a "public:" label. */
805 if ((TYPE_DECLARED_TYPE (type
) == DECLARED_TYPE_CLASS
) ||
806 (TYPE_DECLARED_TYPE (type
) == DECLARED_TYPE_TEMPLATE
))
809 len
= TYPE_NFIELDS (type
);
810 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
811 if (!TYPE_FIELD_PRIVATE (type
, i
))
813 need_access_label
= 1;
817 if (!need_access_label
)
819 len2
= TYPE_NFN_FIELDS (type
);
820 for (j
= 0; j
< len2
; j
++)
822 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
823 for (i
= 0; i
< len
; i
++)
824 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
, j
), i
))
826 need_access_label
= 1;
829 if (need_access_label
)
834 else if ((TYPE_DECLARED_TYPE (type
) == DECLARED_TYPE_STRUCT
) ||
835 (TYPE_DECLARED_TYPE (type
) == DECLARED_TYPE_UNION
))
838 len
= TYPE_NFIELDS (type
);
839 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
840 if (TYPE_FIELD_PRIVATE (type
, i
) || TYPE_FIELD_PROTECTED (type
, i
))
842 need_access_label
= 1;
846 if (!need_access_label
)
848 len2
= TYPE_NFN_FIELDS (type
);
849 for (j
= 0; j
< len2
; j
++)
852 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
853 for (i
= 0; i
< len
; i
++)
854 if (TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
, j
), i
) ||
855 TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type
, j
), i
))
857 need_access_label
= 1;
860 if (need_access_label
)
866 /* If there is a base class for this type,
867 do not print the field that it occupies. */
869 len
= TYPE_NFIELDS (type
);
870 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
873 /* Don't print out virtual function table. */
874 /* HP ANSI C++ case */
875 if (TYPE_HAS_VTABLE (type
) && (STREQN (TYPE_FIELD_NAME (type
, i
), "__vfp", 5)))
877 /* Other compilers */
878 if (STREQN (TYPE_FIELD_NAME (type
, i
), "_vptr", 5)
879 && is_cplus_marker ((TYPE_FIELD_NAME (type
, i
))[5]))
882 /* If this is a C++ class we can print the various C++ section
885 if (HAVE_CPLUS_STRUCT (type
) && need_access_label
)
887 if (TYPE_FIELD_PROTECTED (type
, i
))
889 if (section_type
!= s_protected
)
891 section_type
= s_protected
;
892 fprintfi_filtered (level
+ 2, stream
,
896 else if (TYPE_FIELD_PRIVATE (type
, i
))
898 if (section_type
!= s_private
)
900 section_type
= s_private
;
901 fprintfi_filtered (level
+ 2, stream
, "private:\n");
906 if (section_type
!= s_public
)
908 section_type
= s_public
;
909 fprintfi_filtered (level
+ 2, stream
, "public:\n");
914 print_spaces_filtered (level
+ 4, stream
);
915 if (TYPE_FIELD_STATIC (type
, i
))
917 fprintf_filtered (stream
, "static ");
919 c_print_type (TYPE_FIELD_TYPE (type
, i
),
920 TYPE_FIELD_NAME (type
, i
),
921 stream
, show
- 1, level
+ 4);
922 if (!TYPE_FIELD_STATIC (type
, i
)
923 && TYPE_FIELD_PACKED (type
, i
))
925 /* It is a bitfield. This code does not attempt
926 to look at the bitpos and reconstruct filler,
927 unnamed fields. This would lead to misleading
928 results if the compiler does not put out fields
929 for such things (I don't know what it does). */
930 fprintf_filtered (stream
, " : %d",
931 TYPE_FIELD_BITSIZE (type
, i
));
933 fprintf_filtered (stream
, ";\n");
936 /* If there are both fields and methods, put a space between. */
937 len
= TYPE_NFN_FIELDS (type
);
938 if (len
&& section_type
!= s_none
)
939 fprintf_filtered (stream
, "\n");
941 /* C++: print out the methods */
942 for (i
= 0; i
< len
; i
++)
944 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
945 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
946 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
947 char *name
= type_name_no_tag (type
);
948 int is_constructor
= name
&& STREQ (method_name
, name
);
949 for (j
= 0; j
< len2
; j
++)
951 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
952 int is_full_physname_constructor
=
953 ((physname
[0] == '_' && physname
[1] == '_'
954 && strchr ("0123456789Qt", physname
[2]))
955 || STREQN (physname
, "__ct__", 6)
956 || DESTRUCTOR_PREFIX_P (physname
)
957 || STREQN (physname
, "__dt__", 6));
960 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
962 if (section_type
!= s_protected
)
964 section_type
= s_protected
;
965 fprintfi_filtered (level
+ 2, stream
,
969 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
971 if (section_type
!= s_private
)
973 section_type
= s_private
;
974 fprintfi_filtered (level
+ 2, stream
, "private:\n");
979 if (section_type
!= s_public
)
981 section_type
= s_public
;
982 fprintfi_filtered (level
+ 2, stream
, "public:\n");
986 print_spaces_filtered (level
+ 4, stream
);
987 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
988 fprintf_filtered (stream
, "virtual ");
989 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
990 fprintf_filtered (stream
, "static ");
991 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
993 /* Keep GDB from crashing here. */
994 fprintf_filtered (stream
, "<undefined type> %s;\n",
995 TYPE_FN_FIELD_PHYSNAME (f
, j
));
998 else if (!is_constructor
&& /* constructors don't have declared types */
999 !is_full_physname_constructor
&& /* " " */
1000 !is_type_conversion_operator (type
, i
, j
))
1002 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1004 fputs_filtered (" ", stream
);
1006 if (TYPE_FN_FIELD_STUB (f
, j
))
1007 /* Build something we can demangle. */
1008 mangled_name
= gdb_mangle_name (type
, i
, j
);
1010 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1013 cplus_demangle (mangled_name
,
1014 DMGL_ANSI
| DMGL_PARAMS
);
1015 if (demangled_name
== NULL
)
1017 /* in some cases (for instance with the HP demangling),
1018 if a function has more than 10 arguments,
1019 the demangling will fail.
1020 Let's try to reconstruct the function signature from
1021 the symbol information */
1022 if (!TYPE_FN_FIELD_STUB (f
, j
))
1023 cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f
, j
), "",
1025 TYPE_FN_FIELD_STATIC_P (f
, j
),
1028 fprintf_filtered (stream
, "<badly mangled name '%s'>",
1034 char *demangled_no_class
1035 = remove_qualifiers (demangled_name
);
1037 /* get rid of the `static' appended by the demangler */
1038 p
= strstr (demangled_no_class
, " static");
1041 int length
= p
- demangled_no_class
;
1042 demangled_no_static
= (char *) xmalloc (length
+ 1);
1043 strncpy (demangled_no_static
, demangled_no_class
, length
);
1044 *(demangled_no_static
+ length
) = '\0';
1045 fputs_filtered (demangled_no_static
, stream
);
1046 free (demangled_no_static
);
1049 fputs_filtered (demangled_no_class
, stream
);
1050 free (demangled_name
);
1053 if (TYPE_FN_FIELD_STUB (f
, j
))
1054 free (mangled_name
);
1056 fprintf_filtered (stream
, ";\n");
1060 fprintfi_filtered (level
, stream
, "}");
1062 if (TYPE_LOCALTYPE_PTR (type
) && show
>= 0)
1063 fprintfi_filtered (level
, stream
, " (Local at %s:%d)\n",
1064 TYPE_LOCALTYPE_FILE (type
),
1065 TYPE_LOCALTYPE_LINE (type
));
1067 if (TYPE_CODE (type
) == TYPE_CODE_TEMPLATE
)
1071 case TYPE_CODE_ENUM
:
1072 c_type_print_cv_qualifier (type
, stream
, 0, 1);
1073 /* HP C supports sized enums */
1074 if (hp_som_som_object_present
)
1075 switch (TYPE_LENGTH (type
))
1078 fputs_filtered ("char ", stream
);
1081 fputs_filtered ("short ", stream
);
1086 fprintf_filtered (stream
, "enum ");
1087 /* Print the tag name if it exists.
1088 The aCC compiler emits a spurious
1089 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1090 tag for unnamed struct/union/enum's, which we don't
1092 if (TYPE_TAG_NAME (type
) != NULL
&&
1093 strncmp (TYPE_TAG_NAME (type
), "{unnamed", 8))
1095 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
1097 fputs_filtered (" ", stream
);
1103 /* If we just printed a tag name, no need to print anything else. */
1104 if (TYPE_TAG_NAME (type
) == NULL
)
1105 fprintf_filtered (stream
, "{...}");
1107 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
1109 fprintf_filtered (stream
, "{");
1110 len
= TYPE_NFIELDS (type
);
1112 for (i
= 0; i
< len
; i
++)
1116 fprintf_filtered (stream
, ", ");
1118 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1119 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1121 fprintf_filtered (stream
, " = %d", TYPE_FIELD_BITPOS (type
, i
));
1122 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1126 fprintf_filtered (stream
, "}");
1130 case TYPE_CODE_VOID
:
1131 fprintf_filtered (stream
, "void");
1134 case TYPE_CODE_UNDEF
:
1135 fprintf_filtered (stream
, "struct <unknown>");
1138 case TYPE_CODE_ERROR
:
1139 fprintf_filtered (stream
, "<unknown type>");
1142 case TYPE_CODE_RANGE
:
1143 /* This should not occur */
1144 fprintf_filtered (stream
, "<range type>");
1147 case TYPE_CODE_TEMPLATE
:
1148 /* Called on "ptype t" where "t" is a template.
1149 Prints the template header (with args), e.g.:
1150 template <class T1, class T2> class "
1151 and then merges with the struct/union/class code to
1152 print the rest of the definition. */
1153 c_type_print_cv_qualifier (type
, stream
, 0, 1);
1154 fprintf_filtered (stream
, "template <");
1155 for (i
= 0; i
< TYPE_NTEMPLATE_ARGS (type
); i
++)
1157 struct template_arg templ_arg
;
1158 templ_arg
= TYPE_TEMPLATE_ARG (type
, i
);
1159 fprintf_filtered (stream
, "class %s", templ_arg
.name
);
1160 if (i
< TYPE_NTEMPLATE_ARGS (type
) - 1)
1161 fprintf_filtered (stream
, ", ");
1163 fprintf_filtered (stream
, "> class ");
1164 /* Yuck, factor this out to a subroutine so we can call
1165 it and return to the point marked with the "goback:" label... - RT */
1168 if (TYPE_NINSTANTIATIONS (type
) > 0)
1170 fprintf_filtered (stream
, "\ntemplate instantiations:\n");
1171 for (i
= 0; i
< TYPE_NINSTANTIATIONS (type
); i
++)
1173 fprintf_filtered (stream
, " ");
1174 c_type_print_base (TYPE_INSTANTIATION (type
, i
), stream
, 0, level
);
1175 if (i
< TYPE_NINSTANTIATIONS (type
) - 1)
1176 fprintf_filtered (stream
, "\n");
1182 /* Handle types not explicitly handled by the other cases,
1183 such as fundamental types. For these, just print whatever
1184 the type name is, as recorded in the type itself. If there
1185 is no type name, then complain. */
1186 if (TYPE_NAME (type
) != NULL
)
1188 c_type_print_cv_qualifier (type
, stream
, 0, 1);
1189 fputs_filtered (TYPE_NAME (type
), stream
);
1193 /* At least for dump_symtab, it is important that this not be
1195 fprintf_filtered (stream
, "<invalid type code %d>",