1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1998, 1999
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, Boston, MA 02111-1307, USA. */
23 #include "bfd.h" /* Binary File Description */
26 #include "expression.h"
35 #include "typeprint.h"
37 #include "gdb_string.h"
41 /* Flag indicating target was compiled by HP compiler */
42 extern int hp_som_som_object_present
;
44 static void cp_type_print_method_args
PARAMS ((struct type
**args
, char *prefix
, char *varstring
, int staticp
, GDB_FILE
*stream
));
47 c_type_print_args
PARAMS ((struct type
*, GDB_FILE
*));
50 cp_type_print_derivation_info
PARAMS ((GDB_FILE
*, struct type
*));
53 c_type_print_varspec_prefix
PARAMS ((struct type
*, GDB_FILE
*, int, int));
56 c_type_print_cv_qualifier
PARAMS ((struct type
*, GDB_FILE
*, int, int));
60 /* Print a description of a type in the format of a
61 typedef for the current language.
62 NEW is the new name for a type TYPE. */
65 c_typedef_print (type
, new, stream
)
71 switch (current_language
->la_language
)
76 fprintf_filtered(stream
, "typedef ");
77 type_print(type
,"",stream
,0);
78 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
79 || !STREQ (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_NAME (new)))
80 fprintf_filtered(stream
, " %s", SYMBOL_SOURCE_NAME(new));
85 fprintf_filtered(stream
, "TYPE ");
86 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
87 !STREQ (TYPE_NAME(SYMBOL_TYPE(new)), SYMBOL_NAME(new)))
88 fprintf_filtered(stream
, "%s = ", SYMBOL_SOURCE_NAME(new));
90 fprintf_filtered(stream
, "<builtin> = ");
91 type_print(type
,"",stream
,0);
96 fprintf_filtered(stream
, "SYNMODE ");
97 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
98 !STREQ (TYPE_NAME(SYMBOL_TYPE(new)), SYMBOL_NAME(new)))
99 fprintf_filtered(stream
, "%s = ", SYMBOL_SOURCE_NAME(new));
101 fprintf_filtered(stream
, "<builtin> = ");
102 type_print(type
,"",stream
,0);
106 error("Language not supported.");
108 fprintf_filtered(stream
, ";\n");
112 /* LEVEL is the depth to indent lines by. */
115 c_print_type (type
, varstring
, stream
, show
, level
)
122 register enum type_code code
;
126 CHECK_TYPEDEF (type
);
128 c_type_print_base (type
, stream
, show
, level
);
129 code
= TYPE_CODE (type
);
130 if ((varstring
!= NULL
&& *varstring
!= '\0')
132 /* Need a space if going to print stars or brackets;
133 but not if we will print just a type name. */
134 ((show
> 0 || TYPE_NAME (type
) == 0)
136 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
137 || code
== TYPE_CODE_METHOD
138 || code
== TYPE_CODE_ARRAY
139 || code
== TYPE_CODE_MEMBER
140 || code
== TYPE_CODE_REF
)))
141 fputs_filtered (" ", stream
);
142 c_type_print_varspec_prefix (type
, stream
, show
, 0);
144 if (varstring
!= NULL
)
146 fputs_filtered (varstring
, stream
);
148 /* For demangled function names, we have the arglist as part of the name,
149 so don't print an additional pair of ()'s */
151 demangled_args
= strchr(varstring
, '(') != NULL
;
152 c_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);
156 /* If TYPE is a derived type, then print out derivation information.
157 Print only the actual base classes of this type, not the base classes
158 of the base classes. I.E. for the derivation hierarchy:
161 class B : public A {int b; };
162 class C : public B {int c; };
164 Print the type of class C as:
170 Not as the following (like gdb used to), which is not legal C++ syntax for
171 derived types and may be confused with the multiple inheritance form:
173 class C : public B : public A {
177 In general, gdb should try to print the types as closely as possible to
178 the form that they appear in the source code.
179 Note that in case of protected derivation gcc will not say 'protected'
180 but 'private'. The HP's aCC compiler emits specific information for
181 derivation via protected inheritance, so gdb can print it out */
184 cp_type_print_derivation_info (stream
, type
)
191 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
193 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
194 fprintf_filtered (stream
, "%s%s ",
195 BASETYPE_VIA_PUBLIC (type
, i
) ? "public"
196 : (TYPE_FIELD_PROTECTED (type
, i
) ? "protected" : "private"),
197 BASETYPE_VIA_VIRTUAL(type
, i
) ? " virtual" : "");
198 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
199 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
203 fputs_filtered (" ", stream
);
206 /* Print the C++ method arguments ARGS to the file STREAM. */
209 cp_type_print_method_args (args
, prefix
, varstring
, staticp
, stream
)
218 fprintf_symbol_filtered (stream
, prefix
, language_cplus
, DMGL_ANSI
);
219 fprintf_symbol_filtered (stream
, varstring
, language_cplus
, DMGL_ANSI
);
220 fputs_filtered ("(", stream
);
221 if (args
&& args
[!staticp
] && args
[!staticp
]->code
!= TYPE_CODE_VOID
)
223 i
= !staticp
; /* skip the class variable */
226 type_print (args
[i
++], "", stream
, 0);
229 fprintf_filtered (stream
, " ...");
232 else if (args
[i
]->code
!= TYPE_CODE_VOID
)
234 fprintf_filtered (stream
, ", ");
239 else if (current_language
->la_language
== language_cplus
)
241 fprintf_filtered (stream
, "void");
244 fprintf_filtered (stream
, ")");
248 /* Print any asterisks or open-parentheses needed before the
249 variable name (to describe its type).
251 On outermost call, pass 0 for PASSED_A_PTR.
252 On outermost call, SHOW > 0 means should ignore
253 any typename for TYPE and show its details.
254 SHOW is always zero on recursive calls. */
257 c_type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
267 if (TYPE_NAME (type
) && show
<= 0)
272 switch (TYPE_CODE (type
))
275 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
276 fprintf_filtered (stream
, "*");
277 c_type_print_cv_qualifier (type
, stream
, 1, 0);
280 case TYPE_CODE_MEMBER
:
282 fprintf_filtered (stream
, "(");
283 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
284 fprintf_filtered (stream
, " ");
285 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
287 fputs_filtered (name
, stream
);
289 c_type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
290 fprintf_filtered (stream
, "::");
293 case TYPE_CODE_METHOD
:
295 fprintf_filtered (stream
, "(");
296 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
299 fprintf_filtered (stream
, " ");
300 c_type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
301 fprintf_filtered (stream
, "::");
306 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
307 fprintf_filtered (stream
, "&");
308 c_type_print_cv_qualifier (type
, stream
, 1, 0);
312 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
314 fprintf_filtered (stream
, "(");
317 case TYPE_CODE_ARRAY
:
318 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
320 fprintf_filtered (stream
, "(");
323 case TYPE_CODE_UNDEF
:
324 case TYPE_CODE_STRUCT
:
325 case TYPE_CODE_UNION
:
330 case TYPE_CODE_ERROR
:
334 case TYPE_CODE_RANGE
:
335 case TYPE_CODE_STRING
:
336 case TYPE_CODE_BITSTRING
:
337 case TYPE_CODE_COMPLEX
:
338 case TYPE_CODE_TYPEDEF
:
339 /* These types need no prefix. They are listed here so that
340 gcc -Wall will reveal any types that haven't been handled. */
345 /* Print out "const" and "volatile" attributes.
346 TYPE is a pointer to the type being printed out.
347 STREAM is the output destination.
348 NEED_SPACE = 1 indicates an initial white space is needed */
351 c_type_print_cv_qualifier (type
, stream
, need_pre_space
, need_post_space
)
359 if (TYPE_CONST (type
))
362 fprintf_filtered (stream
, " ");
363 fprintf_filtered (stream
, "const");
367 if (TYPE_VOLATILE (type
))
369 if (flag
|| need_pre_space
)
370 fprintf_filtered (stream
, " ");
371 fprintf_filtered (stream
, "volatile");
375 if (flag
&& need_post_space
)
376 fprintf_filtered (stream
, " ");
383 c_type_print_args (type
, stream
)
390 fprintf_filtered (stream
, "(");
391 args
= TYPE_ARG_TYPES (type
);
396 fprintf_filtered (stream
, "...");
398 else if ((args
[1]->code
== TYPE_CODE_VOID
) &&
399 (current_language
->la_language
== language_cplus
))
401 fprintf_filtered (stream
, "void");
406 args
[i
] != NULL
&& args
[i
]->code
!= TYPE_CODE_VOID
;
409 c_print_type (args
[i
], "", stream
, -1, 0);
410 if (args
[i
+1] == NULL
)
412 fprintf_filtered (stream
, "...");
414 else if (args
[i
+1]->code
!= TYPE_CODE_VOID
)
416 fprintf_filtered (stream
, ",");
422 else if (current_language
->la_language
== language_cplus
)
424 fprintf_filtered (stream
, "void");
427 fprintf_filtered (stream
, ")");
430 /* Print any array sizes, function arguments or close parentheses
431 needed after the variable name (to describe its type).
432 Args work like c_type_print_varspec_prefix. */
435 c_type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
, demangled_args
)
445 if (TYPE_NAME (type
) && show
<= 0)
450 switch (TYPE_CODE (type
))
452 case TYPE_CODE_ARRAY
:
454 fprintf_filtered (stream
, ")");
456 fprintf_filtered (stream
, "[");
457 if (TYPE_LENGTH (type
) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0
458 && TYPE_ARRAY_UPPER_BOUND_TYPE(type
) != BOUND_CANNOT_BE_DETERMINED
)
459 fprintf_filtered (stream
, "%d",
461 / TYPE_LENGTH (TYPE_TARGET_TYPE (type
))));
462 fprintf_filtered (stream
, "]");
464 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
467 case TYPE_CODE_MEMBER
:
469 fprintf_filtered (stream
, ")");
470 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
473 case TYPE_CODE_METHOD
:
475 fprintf_filtered (stream
, ")");
476 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
479 c_type_print_args (type
, stream
);
485 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0);
490 fprintf_filtered (stream
, ")");
492 { int i
, len
= TYPE_NFIELDS (type
);
493 fprintf_filtered (stream
, "(");
494 if ((len
== 0) && (current_language
->la_language
== language_cplus
))
496 fprintf_filtered (stream
, "void");
499 for (i
= 0; i
< len
; i
++)
503 fputs_filtered (", ", stream
);
506 c_print_type (TYPE_FIELD_TYPE (type
, i
), "", stream
, -1, 0);
508 fprintf_filtered (stream
, ")");
510 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
514 case TYPE_CODE_UNDEF
:
515 case TYPE_CODE_STRUCT
:
516 case TYPE_CODE_UNION
:
521 case TYPE_CODE_ERROR
:
525 case TYPE_CODE_RANGE
:
526 case TYPE_CODE_STRING
:
527 case TYPE_CODE_BITSTRING
:
528 case TYPE_CODE_COMPLEX
:
529 case TYPE_CODE_TYPEDEF
:
530 /* These types do not need a suffix. They are listed so that
531 gcc -Wall will report types that may not have been considered. */
536 /* Print the name of the type (or the ultimate pointer target,
537 function value or array element), or the description of a
540 SHOW positive means print details about the type (e.g. enum values),
541 and print structure elements passing SHOW - 1 for show.
542 SHOW negative means just print the type name or struct tag if there is one.
543 If there is no name, print something sensible but concise like
545 SHOW zero means just print the type name or struct tag if there is one.
546 If there is no name, print something sensible but not as concise like
547 "struct {int x; int y;}".
549 LEVEL is the number of spaces to indent by.
550 We increase it for some recursive calls. */
553 c_type_print_base (type
, stream
, show
, level
)
561 register int lastval
;
563 char *demangled_name
;
564 char *demangled_no_static
;
565 enum {s_none
, s_public
, s_private
, s_protected
} section_type
;
566 int need_access_label
= 0;
574 fputs_filtered ("<type unknown>", stream
);
578 /* When SHOW is zero or less, and there is a valid type name, then always
579 just print the type name directly from the type. */
580 /* If we have "typedef struct foo {. . .} bar;" do we want to print it
581 as "struct foo" or as "bar"? Pick the latter, because C++ folk tend
582 to expect things like "class5 *foo" rather than "struct class5 *foo". */
585 && TYPE_NAME (type
) != NULL
)
587 c_type_print_cv_qualifier (type
, stream
, 0, 1);
588 fputs_filtered (TYPE_NAME (type
), stream
);
592 CHECK_TYPEDEF (type
);
594 switch (TYPE_CODE (type
))
596 case TYPE_CODE_TYPEDEF
:
597 case TYPE_CODE_ARRAY
:
599 case TYPE_CODE_MEMBER
:
602 case TYPE_CODE_METHOD
:
603 c_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
606 case TYPE_CODE_STRUCT
:
607 c_type_print_cv_qualifier (type
, stream
, 0, 1);
608 /* Note TYPE_CODE_STRUCT and TYPE_CODE_CLASS have the same value,
609 * so we use another means for distinguishing them.
611 if (HAVE_CPLUS_STRUCT (type
)) {
612 switch (TYPE_DECLARED_TYPE(type
)) {
613 case DECLARED_TYPE_CLASS
:
614 fprintf_filtered (stream
, "class ");
616 case DECLARED_TYPE_UNION
:
617 fprintf_filtered (stream
, "union ");
619 case DECLARED_TYPE_STRUCT
:
620 fprintf_filtered (stream
, "struct ");
623 /* If there is a CPLUS_STRUCT, assume class if not
624 * otherwise specified in the declared_type field.
626 fprintf_filtered (stream
, "class ");
630 /* If not CPLUS_STRUCT, then assume it's a C struct */
631 fprintf_filtered (stream
, "struct ");
635 case TYPE_CODE_UNION
:
636 c_type_print_cv_qualifier (type
, stream
, 0, 1);
637 fprintf_filtered (stream
, "union ");
641 /* Print the tag if it exists.
642 * The HP aCC compiler emits
643 * a spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
644 * tag for unnamed struct/union/enum's, which we don't
647 if (TYPE_TAG_NAME (type
) != NULL
&&
648 strncmp(TYPE_TAG_NAME(type
), "{unnamed", 8))
650 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
652 fputs_filtered (" ", stream
);
657 /* If we just printed a tag name, no need to print anything else. */
658 if (TYPE_TAG_NAME (type
) == NULL
)
659 fprintf_filtered (stream
, "{...}");
661 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
663 cp_type_print_derivation_info (stream
, type
);
665 fprintf_filtered (stream
, "{\n");
666 if ((TYPE_NFIELDS (type
) == 0) && (TYPE_NFN_FIELDS (type
) == 0))
668 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
669 fprintfi_filtered (level
+ 4, stream
, "<incomplete type>\n");
671 fprintfi_filtered (level
+ 4, stream
, "<no data fields>\n");
674 /* Start off with no specific section type, so we can print
675 one for the first field we find, and use that section type
676 thereafter until we find another type. */
678 section_type
= s_none
;
680 /* For a class, if all members are private, there's no need
681 for a "private:" label; similarly, for a struct or union
682 masquerading as a class, if all members are public, there's
683 no need for a "public:" label. */
685 if ((TYPE_DECLARED_TYPE (type
) == DECLARED_TYPE_CLASS
) ||
686 (TYPE_DECLARED_TYPE (type
) == DECLARED_TYPE_TEMPLATE
))
689 len
= TYPE_NFIELDS (type
);
690 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
691 if (!TYPE_FIELD_PRIVATE (type
, i
))
693 need_access_label
= 1;
697 if (!need_access_label
)
699 len2
= TYPE_NFN_FIELDS (type
);
700 for (j
= 0; j
< len2
; j
++)
702 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
703 for (i
= 0; i
< len
; i
++)
704 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
, j
), i
))
706 need_access_label
= 1;
709 if (need_access_label
)
714 else if ((TYPE_DECLARED_TYPE (type
) == DECLARED_TYPE_STRUCT
) ||
715 (TYPE_DECLARED_TYPE (type
) == DECLARED_TYPE_UNION
))
718 len
= TYPE_NFIELDS (type
);
719 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
720 if (TYPE_FIELD_PRIVATE (type
, i
) || TYPE_FIELD_PROTECTED (type
, i
))
722 need_access_label
= 1;
726 if (!need_access_label
)
728 len2
= TYPE_NFN_FIELDS (type
);
729 for (j
= 0; j
< len2
; j
++)
732 len
= TYPE_FN_FIELDLIST_LENGTH (type
, j
);
733 for (i
= 0; i
< len
; i
++)
734 if (TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
, j
), i
) ||
735 TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type
, j
), i
))
737 need_access_label
= 1;
740 if (need_access_label
)
746 /* If there is a base class for this type,
747 do not print the field that it occupies. */
749 len
= TYPE_NFIELDS (type
);
750 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
753 /* Don't print out virtual function table. */
754 /* HP ANSI C++ case */
755 if (TYPE_HAS_VTABLE(type
) && (STREQN (TYPE_FIELD_NAME (type
, i
), "__vfp", 5)))
757 /* Other compilers */
758 /* pai:: FIXME : check for has_vtable < 0 */
759 if (STREQN (TYPE_FIELD_NAME (type
, i
), "_vptr", 5)
760 && is_cplus_marker ((TYPE_FIELD_NAME (type
, i
))[5]))
763 /* If this is a C++ class we can print the various C++ section
766 if (HAVE_CPLUS_STRUCT (type
) && need_access_label
)
768 if (TYPE_FIELD_PROTECTED (type
, i
))
770 if (section_type
!= s_protected
)
772 section_type
= s_protected
;
773 fprintfi_filtered (level
+ 2, stream
,
777 else if (TYPE_FIELD_PRIVATE (type
, i
))
779 if (section_type
!= s_private
)
781 section_type
= s_private
;
782 fprintfi_filtered (level
+ 2, stream
, "private:\n");
787 if (section_type
!= s_public
)
789 section_type
= s_public
;
790 fprintfi_filtered (level
+ 2, stream
, "public:\n");
795 print_spaces_filtered (level
+ 4, stream
);
796 if (TYPE_FIELD_STATIC (type
, i
))
798 fprintf_filtered (stream
, "static ");
800 c_print_type (TYPE_FIELD_TYPE (type
, i
),
801 TYPE_FIELD_NAME (type
, i
),
802 stream
, show
- 1, level
+ 4);
803 if (!TYPE_FIELD_STATIC (type
, i
)
804 && TYPE_FIELD_PACKED (type
, i
))
806 /* It is a bitfield. This code does not attempt
807 to look at the bitpos and reconstruct filler,
808 unnamed fields. This would lead to misleading
809 results if the compiler does not put out fields
810 for such things (I don't know what it does). */
811 fprintf_filtered (stream
, " : %d",
812 TYPE_FIELD_BITSIZE (type
, i
));
814 fprintf_filtered (stream
, ";\n");
817 /* If there are both fields and methods, put a space between. */
818 len
= TYPE_NFN_FIELDS (type
);
819 if (len
&& section_type
!= s_none
)
820 fprintf_filtered (stream
, "\n");
822 /* C++: print out the methods */
823 for (i
= 0; i
< len
; i
++)
825 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
826 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
827 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
828 char *name
= type_name_no_tag (type
);
829 int is_constructor
= name
&& STREQ(method_name
, name
);
830 for (j
= 0; j
< len2
; j
++)
832 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
833 int is_full_physname_constructor
=
834 ((physname
[0] == '_' && physname
[1] == '_'
835 && strchr ("0123456789Qt", physname
[2]))
836 || STREQN (physname
, "__ct__", 6)
837 || DESTRUCTOR_PREFIX_P (physname
)
838 || STREQN (physname
, "__dt__", 6));
841 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
843 if (section_type
!= s_protected
)
845 section_type
= s_protected
;
846 fprintfi_filtered (level
+ 2, stream
,
850 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
852 if (section_type
!= s_private
)
854 section_type
= s_private
;
855 fprintfi_filtered (level
+ 2, stream
, "private:\n");
860 if (section_type
!= s_public
)
862 section_type
= s_public
;
863 fprintfi_filtered (level
+ 2, stream
, "public:\n");
867 print_spaces_filtered (level
+ 4, stream
);
868 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
869 fprintf_filtered (stream
, "virtual ");
870 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
871 fprintf_filtered (stream
, "static ");
872 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
874 /* Keep GDB from crashing here. */
875 fprintf_filtered (stream
, "<undefined type> %s;\n",
876 TYPE_FN_FIELD_PHYSNAME (f
, j
));
879 else if (!is_constructor
&& /* constructors don't have declared types */
880 !is_full_physname_constructor
&& /* " " */
881 !strstr (method_name
, "operator ")) /* Not a type conversion operator */
882 /* (note space -- other operators don't have it) */
884 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
886 fputs_filtered (" ", stream
);
888 if (TYPE_FN_FIELD_STUB (f
, j
))
889 /* Build something we can demangle. */
890 mangled_name
= gdb_mangle_name (type
, i
, j
);
892 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
895 cplus_demangle (mangled_name
,
896 DMGL_ANSI
| DMGL_PARAMS
);
897 if (demangled_name
== NULL
)
899 /* in some cases (for instance with the HP demangling),
900 if a function has more than 10 arguments,
901 the demangling will fail.
902 Let's try to reconstruct the function signature from
903 the symbol information */
904 if (!TYPE_FN_FIELD_STUB (f
, j
))
905 cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f
, j
), "",
907 TYPE_FN_FIELD_STATIC_P (f
, j
),
910 fprintf_filtered (stream
, "<badly mangled name '%s'>",
916 char *demangled_no_class
= demangled_name
;
918 while ((p
= strchr (demangled_no_class
, ':')))
920 demangled_no_class
= p
;
921 if (*++demangled_no_class
== ':')
922 ++demangled_no_class
;
924 /* get rid of the static word appended by the demangler */
925 p
= strstr (demangled_no_class
, " static");
928 int length
= p
- demangled_no_class
;
929 demangled_no_static
= (char *) xmalloc (length
+ 1);
930 strncpy (demangled_no_static
, demangled_no_class
, length
);
931 *(demangled_no_static
+ length
) = '\0';
932 fputs_filtered (demangled_no_static
, stream
);
933 free (demangled_no_static
);
936 fputs_filtered (demangled_no_class
, stream
);
937 free (demangled_name
);
940 if (TYPE_FN_FIELD_STUB (f
, j
))
943 fprintf_filtered (stream
, ";\n");
947 if (TYPE_LOCALTYPE_PTR (type
) && show
>= 0)
948 fprintfi_filtered (level
, stream
, " (Local at %s:%d)\n",
949 TYPE_LOCALTYPE_FILE (type
),
950 TYPE_LOCALTYPE_LINE (type
));
952 fprintfi_filtered (level
, stream
, "}");
954 if (TYPE_CODE(type
) == TYPE_CODE_TEMPLATE
)
959 c_type_print_cv_qualifier (type
, stream
, 0, 1);
960 /* HP C supports sized enums */
961 if (hp_som_som_object_present
)
962 switch (TYPE_LENGTH (type
))
965 fputs_filtered ("char ", stream
);
968 fputs_filtered ("short ", stream
);
973 fprintf_filtered (stream
, "enum ");
974 /* Print the tag name if it exists.
975 The aCC compiler emits a spurious
976 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
977 tag for unnamed struct/union/enum's, which we don't
979 if (TYPE_TAG_NAME (type
) != NULL
&&
980 strncmp(TYPE_TAG_NAME(type
), "{unnamed", 8))
982 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
984 fputs_filtered (" ", stream
);
990 /* If we just printed a tag name, no need to print anything else. */
991 if (TYPE_TAG_NAME (type
) == NULL
)
992 fprintf_filtered (stream
, "{...}");
994 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
996 fprintf_filtered (stream
, "{");
997 len
= TYPE_NFIELDS (type
);
999 for (i
= 0; i
< len
; i
++)
1002 if (i
) fprintf_filtered (stream
, ", ");
1004 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1005 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1007 fprintf_filtered (stream
, " = %d", TYPE_FIELD_BITPOS (type
, i
));
1008 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1012 fprintf_filtered (stream
, "}");
1016 case TYPE_CODE_VOID
:
1017 fprintf_filtered (stream
, "void");
1020 case TYPE_CODE_UNDEF
:
1021 fprintf_filtered (stream
, "struct <unknown>");
1024 case TYPE_CODE_ERROR
:
1025 fprintf_filtered (stream
, "<unknown type>");
1028 case TYPE_CODE_RANGE
:
1029 /* This should not occur */
1030 fprintf_filtered (stream
, "<range type>");
1033 case TYPE_CODE_TEMPLATE
:
1034 /* Called on "ptype t" where "t" is a template.
1035 Prints the template header (with args), e.g.:
1036 template <class T1, class T2> class "
1037 and then merges with the struct/union/class code to
1038 print the rest of the definition. */
1039 c_type_print_cv_qualifier (type
, stream
, 0, 1);
1040 fprintf_filtered (stream
, "template <");
1041 for (i
= 0; i
< TYPE_NTEMPLATE_ARGS(type
); i
++) {
1042 struct template_arg templ_arg
;
1043 templ_arg
= TYPE_TEMPLATE_ARG(type
, i
);
1044 fprintf_filtered (stream
, "class %s", templ_arg
.name
);
1045 if (i
< TYPE_NTEMPLATE_ARGS(type
)-1)
1046 fprintf_filtered (stream
, ", ");
1048 fprintf_filtered (stream
, "> class ");
1049 /* Yuck, factor this out to a subroutine so we can call
1050 it and return to the point marked with the "goback:" label... - RT */
1053 if (TYPE_NINSTANTIATIONS(type
) > 0) {
1054 fprintf_filtered (stream
, "\ntemplate instantiations:\n");
1055 for (i
= 0; i
< TYPE_NINSTANTIATIONS(type
); i
++) {
1056 fprintf_filtered(stream
, " ");
1057 c_type_print_base (TYPE_INSTANTIATION(type
, i
), stream
, 0, level
);
1058 if (i
< TYPE_NINSTANTIATIONS(type
)-1) fprintf_filtered(stream
, "\n");
1064 /* Handle types not explicitly handled by the other cases,
1065 such as fundamental types. For these, just print whatever
1066 the type name is, as recorded in the type itself. If there
1067 is no type name, then complain. */
1068 if (TYPE_NAME (type
) != NULL
)
1070 c_type_print_cv_qualifier (type
, stream
, 0, 1);
1071 fputs_filtered (TYPE_NAME (type
), stream
);
1075 /* At least for dump_symtab, it is important that this not be
1077 fprintf_filtered (stream
, "<invalid type code %d>",