1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2 Copyright (C) 1986-2020 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdb_obstack.h"
21 #include "bfd.h" /* Binary File Description. */
24 #include "expression.h"
31 #include "cli/cli-style.h"
32 #include "typeprint.h"
34 #include "cp-support.h"
36 /* A list of access specifiers used for printing. */
46 static void c_type_print_varspec_suffix (struct type
*, struct ui_file
*, int,
49 const struct type_print_options
*);
51 static void c_type_print_varspec_prefix (struct type
*,
55 const struct type_print_options
*,
56 struct print_offset_data
*);
58 /* Print "const", "volatile", or address space modifiers. */
59 static void c_type_print_modifier (struct type
*,
61 int, int, enum language
);
63 static void c_type_print_base_1 (struct type
*type
, struct ui_file
*stream
,
64 int show
, int level
, enum language language
,
65 const struct type_print_options
*flags
,
66 struct print_offset_data
*podata
);
69 /* A callback function for cp_canonicalize_string_full that uses
70 typedef_hash_table::find_typedef. */
73 find_typedef_for_canonicalize (struct type
*t
, void *data
)
75 return typedef_hash_table::find_typedef
76 ((const struct type_print_options
*) data
, t
);
79 /* Print NAME on STREAM. If the 'raw' field of FLAGS is not set,
80 canonicalize NAME using the local typedefs first. */
83 print_name_maybe_canonical (const char *name
,
84 const struct type_print_options
*flags
,
85 struct ui_file
*stream
)
87 gdb::unique_xmalloc_ptr
<char> s
;
90 s
= cp_canonicalize_string_full (name
,
91 find_typedef_for_canonicalize
,
94 fputs_filtered (s
!= nullptr ? s
.get () : name
, stream
);
99 /* Helper function for c_print_type. */
102 c_print_type_1 (struct type
*type
,
103 const char *varstring
,
104 struct ui_file
*stream
,
106 enum language language
,
107 const struct type_print_options
*flags
,
108 struct print_offset_data
*podata
)
113 const char *local_name
;
116 type
= check_typedef (type
);
118 local_name
= typedef_hash_table::find_typedef (flags
, type
);
119 code
= type
->code ();
120 if (local_name
!= NULL
)
122 fputs_filtered (local_name
, stream
);
123 if (varstring
!= NULL
&& *varstring
!= '\0')
124 fputs_filtered (" ", stream
);
128 c_type_print_base_1 (type
, stream
, show
, level
, language
, flags
, podata
);
129 if ((varstring
!= NULL
&& *varstring
!= '\0')
130 /* Need a space if going to print stars or brackets;
131 but not if we will print just a type name. */
132 || ((show
> 0 || type
->name () == 0)
133 && (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
134 || code
== TYPE_CODE_METHOD
135 || (code
== TYPE_CODE_ARRAY
136 && !type
->is_vector ())
137 || code
== TYPE_CODE_MEMBERPTR
138 || code
== TYPE_CODE_METHODPTR
139 || TYPE_IS_REFERENCE (type
))))
140 fputs_filtered (" ", stream
);
141 need_post_space
= (varstring
!= NULL
&& strcmp (varstring
, "") != 0);
142 c_type_print_varspec_prefix (type
, stream
, show
, 0, need_post_space
,
143 language
, flags
, podata
);
146 if (varstring
!= NULL
)
148 if (code
== TYPE_CODE_FUNC
|| code
== TYPE_CODE_METHOD
)
149 fputs_styled (varstring
, function_name_style
.style (), stream
);
151 fputs_styled (varstring
, variable_name_style
.style (), stream
);
153 /* For demangled function names, we have the arglist as part of
154 the name, so don't print an additional pair of ()'s. */
155 if (local_name
== NULL
)
157 demangled_args
= strchr (varstring
, '(') != NULL
;
158 c_type_print_varspec_suffix (type
, stream
, show
,
165 /* LEVEL is the depth to indent lines by. */
168 c_print_type (struct type
*type
,
169 const char *varstring
,
170 struct ui_file
*stream
,
172 const struct type_print_options
*flags
)
174 struct print_offset_data podata
;
176 c_print_type_1 (type
, varstring
, stream
, show
, level
,
177 current_language
->la_language
, flags
, &podata
);
184 c_print_type (struct type
*type
,
185 const char *varstring
,
186 struct ui_file
*stream
,
188 enum language language
,
189 const struct type_print_options
*flags
)
191 struct print_offset_data podata
;
193 c_print_type_1 (type
, varstring
, stream
, show
, level
, language
, flags
,
197 /* Print a typedef using C syntax. TYPE is the underlying type.
198 NEW_SYMBOL is the symbol naming the type. STREAM is the stream on
202 c_print_typedef (struct type
*type
,
203 struct symbol
*new_symbol
,
204 struct ui_file
*stream
)
206 type
= check_typedef (type
);
207 fprintf_filtered (stream
, "typedef ");
208 type_print (type
, "", stream
, -1);
209 if ((SYMBOL_TYPE (new_symbol
))->name () == 0
210 || strcmp ((SYMBOL_TYPE (new_symbol
))->name (),
211 new_symbol
->linkage_name ()) != 0
212 || SYMBOL_TYPE (new_symbol
)->code () == TYPE_CODE_TYPEDEF
)
213 fprintf_filtered (stream
, " %s", new_symbol
->print_name ());
214 fprintf_filtered (stream
, ";");
217 /* If TYPE is a derived type, then print out derivation information.
218 Print only the actual base classes of this type, not the base
219 classes of the base classes. I.e. for the derivation hierarchy:
222 class B : public A {int b; };
223 class C : public B {int c; };
225 Print the type of class C as:
231 Not as the following (like gdb used to), which is not legal C++
232 syntax for derived types and may be confused with the multiple
235 class C : public B : public A {
239 In general, gdb should try to print the types as closely as
240 possible to the form that they appear in the source code. */
243 cp_type_print_derivation_info (struct ui_file
*stream
,
245 const struct type_print_options
*flags
)
250 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
253 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
254 fprintf_filtered (stream
, "%s%s ",
255 BASETYPE_VIA_PUBLIC (type
, i
)
256 ? "public" : (TYPE_FIELD_PROTECTED (type
, i
)
257 ? "protected" : "private"),
258 BASETYPE_VIA_VIRTUAL (type
, i
) ? " virtual" : "");
259 name
= TYPE_BASECLASS (type
, i
)->name ();
261 print_name_maybe_canonical (name
, flags
, stream
);
263 fprintf_filtered (stream
, "(null)");
267 fputs_filtered (" ", stream
);
271 /* Print the C++ method arguments ARGS to the file STREAM. */
274 cp_type_print_method_args (struct type
*mtype
, const char *prefix
,
275 const char *varstring
, int staticp
,
276 struct ui_file
*stream
,
277 enum language language
,
278 const struct type_print_options
*flags
)
280 struct field
*args
= mtype
->fields ();
281 int nargs
= mtype
->num_fields ();
282 int varargs
= mtype
->has_varargs ();
285 fprintf_symbol_filtered (stream
, prefix
,
286 language_cplus
, DMGL_ANSI
);
287 fprintf_symbol_filtered (stream
, varstring
,
288 language_cplus
, DMGL_ANSI
);
289 fputs_filtered ("(", stream
);
291 /* Skip the class variable. We keep this here to accommodate older
292 compilers and debug formats which may not support artificial
299 struct field arg
= args
[i
++];
301 /* Skip any artificial arguments. */
302 if (FIELD_ARTIFICIAL (arg
))
305 c_print_type (arg
.type (), "", stream
, 0, 0, flags
);
307 if (i
== nargs
&& varargs
)
308 fprintf_filtered (stream
, ", ...");
311 fprintf_filtered (stream
, ", ");
317 fprintf_filtered (stream
, "...");
318 else if (language
== language_cplus
)
319 fprintf_filtered (stream
, "void");
321 fprintf_filtered (stream
, ")");
323 /* For non-static methods, read qualifiers from the type of
329 gdb_assert (nargs
> 0);
330 gdb_assert (args
[0].type ()->code () == TYPE_CODE_PTR
);
331 domain
= TYPE_TARGET_TYPE (args
[0].type ());
333 if (TYPE_CONST (domain
))
334 fprintf_filtered (stream
, " const");
336 if (TYPE_VOLATILE (domain
))
337 fprintf_filtered (stream
, " volatile");
339 if (TYPE_RESTRICT (domain
))
340 fprintf_filtered (stream
, (language
== language_cplus
344 if (TYPE_ATOMIC (domain
))
345 fprintf_filtered (stream
, " _Atomic");
350 /* Print any asterisks or open-parentheses needed before the
351 variable name (to describe its type).
353 On outermost call, pass 0 for PASSED_A_PTR.
354 On outermost call, SHOW > 0 means should ignore
355 any typename for TYPE and show its details.
356 SHOW is always zero on recursive calls.
358 NEED_POST_SPACE is non-zero when a space will be be needed
359 between a trailing qualifier and a field, variable, or function
363 c_type_print_varspec_prefix (struct type
*type
,
364 struct ui_file
*stream
,
365 int show
, int passed_a_ptr
,
367 enum language language
,
368 const struct type_print_options
*flags
,
369 struct print_offset_data
*podata
)
376 if (type
->name () && show
<= 0)
381 switch (type
->code ())
384 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
385 stream
, show
, 1, 1, language
, flags
,
387 fprintf_filtered (stream
, "*");
388 c_type_print_modifier (type
, stream
, 1, need_post_space
, language
);
391 case TYPE_CODE_MEMBERPTR
:
392 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
393 stream
, show
, 0, 0, language
, flags
, podata
);
394 name
= TYPE_SELF_TYPE (type
)->name ();
396 print_name_maybe_canonical (name
, flags
, stream
);
398 c_type_print_base_1 (TYPE_SELF_TYPE (type
),
399 stream
, -1, passed_a_ptr
, language
, flags
,
401 fprintf_filtered (stream
, "::*");
404 case TYPE_CODE_METHODPTR
:
405 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
406 stream
, show
, 0, 0, language
, flags
,
408 fprintf_filtered (stream
, "(");
409 name
= TYPE_SELF_TYPE (type
)->name ();
411 print_name_maybe_canonical (name
, flags
, stream
);
413 c_type_print_base_1 (TYPE_SELF_TYPE (type
),
414 stream
, -1, passed_a_ptr
, language
, flags
,
416 fprintf_filtered (stream
, "::*");
420 case TYPE_CODE_RVALUE_REF
:
421 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
422 stream
, show
, 1, 0, language
, flags
,
424 fprintf_filtered (stream
, type
->code () == TYPE_CODE_REF
? "&" : "&&");
425 c_type_print_modifier (type
, stream
, 1, need_post_space
, language
);
428 case TYPE_CODE_METHOD
:
430 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
431 stream
, show
, 0, 0, language
, flags
,
434 fprintf_filtered (stream
, "(");
437 case TYPE_CODE_ARRAY
:
438 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
439 stream
, show
, 0, 0, language
, flags
,
442 fprintf_filtered (stream
, "(");
445 case TYPE_CODE_TYPEDEF
:
446 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
),
447 stream
, show
, passed_a_ptr
, 0,
448 language
, flags
, podata
);
451 case TYPE_CODE_UNDEF
:
452 case TYPE_CODE_STRUCT
:
453 case TYPE_CODE_UNION
:
455 case TYPE_CODE_FLAGS
:
459 case TYPE_CODE_ERROR
:
463 case TYPE_CODE_RANGE
:
464 case TYPE_CODE_STRING
:
465 case TYPE_CODE_COMPLEX
:
466 case TYPE_CODE_NAMESPACE
:
467 case TYPE_CODE_DECFLOAT
:
468 case TYPE_CODE_FIXED_POINT
:
469 /* These types need no prefix. They are listed here so that
470 gcc -Wall will reveal any types that haven't been handled. */
473 error (_("type not handled in c_type_print_varspec_prefix()"));
478 /* Print out "const" and "volatile" attributes,
479 and address space id if present.
480 TYPE is a pointer to the type being printed out.
481 STREAM is the output destination.
482 NEED_PRE_SPACE = 1 indicates an initial white space is needed.
483 NEED_POST_SPACE = 1 indicates a final white space is needed. */
486 c_type_print_modifier (struct type
*type
, struct ui_file
*stream
,
487 int need_pre_space
, int need_post_space
,
488 enum language language
)
490 int did_print_modifier
= 0;
491 const char *address_space_id
;
493 /* We don't print `const' qualifiers for references --- since all
494 operators affect the thing referenced, not the reference itself,
495 every reference is `const'. */
496 if (TYPE_CONST (type
) && !TYPE_IS_REFERENCE (type
))
499 fprintf_filtered (stream
, " ");
500 fprintf_filtered (stream
, "const");
501 did_print_modifier
= 1;
504 if (TYPE_VOLATILE (type
))
506 if (did_print_modifier
|| need_pre_space
)
507 fprintf_filtered (stream
, " ");
508 fprintf_filtered (stream
, "volatile");
509 did_print_modifier
= 1;
512 if (TYPE_RESTRICT (type
))
514 if (did_print_modifier
|| need_pre_space
)
515 fprintf_filtered (stream
, " ");
516 fprintf_filtered (stream
, (language
== language_cplus
519 did_print_modifier
= 1;
522 if (TYPE_ATOMIC (type
))
524 if (did_print_modifier
|| need_pre_space
)
525 fprintf_filtered (stream
, " ");
526 fprintf_filtered (stream
, "_Atomic");
527 did_print_modifier
= 1;
531 = address_space_type_instance_flags_to_name (get_type_arch (type
),
532 type
->instance_flags ());
533 if (address_space_id
)
535 if (did_print_modifier
|| need_pre_space
)
536 fprintf_filtered (stream
, " ");
537 fprintf_filtered (stream
, "@%s", address_space_id
);
538 did_print_modifier
= 1;
541 if (did_print_modifier
&& need_post_space
)
542 fprintf_filtered (stream
, " ");
546 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
547 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
548 in non-static methods, are displayed if LINKAGE_NAME is zero. If
549 LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
550 parameter types get removed their possible const and volatile qualifiers to
551 match demangled linkage name parameters part of such function type.
552 LANGUAGE is the language in which TYPE was defined. This is a necessary
553 evil since this code is used by the C and C++. */
556 c_type_print_args (struct type
*type
, struct ui_file
*stream
,
557 int linkage_name
, enum language language
,
558 const struct type_print_options
*flags
)
563 fprintf_filtered (stream
, "(");
565 for (i
= 0; i
< type
->num_fields (); i
++)
567 struct type
*param_type
;
569 if (TYPE_FIELD_ARTIFICIAL (type
, i
) && linkage_name
)
574 fprintf_filtered (stream
, ", ");
578 param_type
= type
->field (i
).type ();
580 if (language
== language_cplus
&& linkage_name
)
582 /* C++ standard, 13.1 Overloadable declarations, point 3, item:
583 - Parameter declarations that differ only in the presence or
584 absence of const and/or volatile are equivalent.
586 And the const/volatile qualifiers are not present in the mangled
587 names as produced by GCC. */
589 param_type
= make_cv_type (0, 0, param_type
, NULL
);
592 c_print_type (param_type
, "", stream
, -1, 0, language
, flags
);
596 if (printed_any
&& type
->has_varargs ())
598 /* Print out a trailing ellipsis for varargs functions. Ignore
599 TYPE_VARARGS if the function has no named arguments; that
600 represents unprototyped (K&R style) C functions. */
601 if (printed_any
&& type
->has_varargs ())
603 fprintf_filtered (stream
, ", ");
605 fprintf_filtered (stream
, "...");
608 else if (!printed_any
609 && (type
->is_prototyped () || language
== language_cplus
))
610 fprintf_filtered (stream
, "void");
612 fprintf_filtered (stream
, ")");
615 /* Return true iff the j'th overloading of the i'th method of TYPE
616 is a type conversion operator, like `operator int () { ... }'.
617 When listing a class's methods, we don't print the return type of
621 is_type_conversion_operator (struct type
*type
, int i
, int j
)
623 /* I think the whole idea of recognizing type conversion operators
624 by their name is pretty terrible. But I don't think our present
625 data structure gives us any other way to tell. If you know of
626 some other way, feel free to rewrite this function. */
627 const char *name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
629 if (!startswith (name
, CP_OPERATOR_STR
))
633 if (! strchr (" \t\f\n\r", *name
))
636 while (strchr (" \t\f\n\r", *name
))
639 if (!('a' <= *name
&& *name
<= 'z')
640 && !('A' <= *name
&& *name
<= 'Z')
642 /* If this doesn't look like the start of an identifier, then it
643 isn't a type conversion operator. */
645 else if (startswith (name
, "new"))
647 else if (startswith (name
, "delete"))
650 /* If it doesn't look like new or delete, it's a type conversion
654 /* Is that really the end of the name? */
655 if (('a' <= *name
&& *name
<= 'z')
656 || ('A' <= *name
&& *name
<= 'Z')
657 || ('0' <= *name
&& *name
<= '9')
659 /* No, so the identifier following "operator" must be a type name,
660 and this is a type conversion operator. */
663 /* That was indeed the end of the name, so it was `operator new' or
664 `operator delete', neither of which are type conversion
669 /* Given a C++ qualified identifier QID, strip off the qualifiers,
670 yielding the unqualified name. The return value is a pointer into
673 It's a pity we don't have this information in some more structured
674 form. Even the author of this function feels that writing little
675 parsers like this everywhere is stupid. */
678 remove_qualifiers (char *qid
)
680 int quoted
= 0; /* Zero if we're not in quotes;
681 '"' if we're in a double-quoted string;
682 '\'' if we're in a single-quoted string. */
683 int depth
= 0; /* Number of unclosed parens we've seen. */
684 char *parenstack
= (char *) alloca (strlen (qid
));
686 char *last
= 0; /* The character after the rightmost
687 `::' token we've seen so far. */
689 for (scan
= qid
; *scan
; scan
++)
695 else if (*scan
== '\\' && *(scan
+ 1))
698 else if (scan
[0] == ':' && scan
[1] == ':')
700 /* If we're inside parenthesis (i.e., an argument list) or
701 angle brackets (i.e., a list of template arguments), then
702 we don't record the position of this :: token, since it's
703 not relevant to the top-level structure we're trying to
711 else if (*scan
== '"' || *scan
== '\'')
713 else if (*scan
== '(')
714 parenstack
[depth
++] = ')';
715 else if (*scan
== '[')
716 parenstack
[depth
++] = ']';
717 /* We're going to treat <> as a pair of matching characters,
718 since we're more likely to see those in template id's than
719 real less-than characters. What a crock. */
720 else if (*scan
== '<')
721 parenstack
[depth
++] = '>';
722 else if (*scan
== ')' || *scan
== ']' || *scan
== '>')
724 if (depth
> 0 && parenstack
[depth
- 1] == *scan
)
728 /* We're going to do a little error recovery here. If
729 we don't find a match for *scan on the paren stack,
730 but there is something lower on the stack that does
731 match, we pop the stack to that point. */
734 for (i
= depth
- 1; i
>= 0; i
--)
735 if (parenstack
[i
] == *scan
)
747 /* We didn't find any :: tokens at the top level, so declare the
748 whole thing an unqualified identifier. */
752 /* Print any array sizes, function arguments or close parentheses
753 needed after the variable name (to describe its type).
754 Args work like c_type_print_varspec_prefix. */
757 c_type_print_varspec_suffix (struct type
*type
,
758 struct ui_file
*stream
,
759 int show
, int passed_a_ptr
,
761 enum language language
,
762 const struct type_print_options
*flags
)
767 if (type
->name () && show
<= 0)
772 switch (type
->code ())
774 case TYPE_CODE_ARRAY
:
776 LONGEST low_bound
, high_bound
;
777 int is_vector
= type
->is_vector ();
780 fprintf_filtered (stream
, ")");
782 fprintf_filtered (stream
, (is_vector
?
783 " __attribute__ ((vector_size(" : "["));
784 /* Bounds are not yet resolved, print a bounds placeholder instead. */
785 if (type
->bounds ()->high
.kind () == PROP_LOCEXPR
786 || type
->bounds ()->high
.kind () == PROP_LOCLIST
)
787 fprintf_filtered (stream
, "variable length");
788 else if (get_array_bounds (type
, &low_bound
, &high_bound
))
789 fprintf_filtered (stream
, "%s",
790 plongest (high_bound
- low_bound
+ 1));
791 fprintf_filtered (stream
, (is_vector
? ")))" : "]"));
793 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
794 show
, 0, 0, language
, flags
);
798 case TYPE_CODE_MEMBERPTR
:
799 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
800 show
, 0, 0, language
, flags
);
803 case TYPE_CODE_METHODPTR
:
804 fprintf_filtered (stream
, ")");
805 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
806 show
, 0, 0, language
, flags
);
811 case TYPE_CODE_RVALUE_REF
:
812 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
813 show
, 1, 0, language
, flags
);
816 case TYPE_CODE_METHOD
:
819 fprintf_filtered (stream
, ")");
821 c_type_print_args (type
, stream
, 0, language
, flags
);
822 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
823 show
, passed_a_ptr
, 0, language
, flags
);
826 case TYPE_CODE_TYPEDEF
:
827 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
,
828 show
, passed_a_ptr
, 0, language
, flags
);
831 case TYPE_CODE_UNDEF
:
832 case TYPE_CODE_STRUCT
:
833 case TYPE_CODE_UNION
:
834 case TYPE_CODE_FLAGS
:
839 case TYPE_CODE_ERROR
:
843 case TYPE_CODE_RANGE
:
844 case TYPE_CODE_STRING
:
845 case TYPE_CODE_COMPLEX
:
846 case TYPE_CODE_NAMESPACE
:
847 case TYPE_CODE_DECFLOAT
:
848 case TYPE_CODE_FIXED_POINT
:
849 /* These types do not need a suffix. They are listed so that
850 gcc -Wall will report types that may not have been
854 error (_("type not handled in c_type_print_varspec_suffix()"));
859 /* A helper for c_type_print_base that displays template
860 parameters and their bindings, if needed.
862 TABLE is the local bindings table to use. If NULL, no printing is
863 done. Note that, at this point, TABLE won't have any useful
864 information in it -- but it is also used as a flag to
865 print_name_maybe_canonical to activate searching the global typedef
868 TYPE is the type whose template arguments are being displayed.
870 STREAM is the stream on which to print. */
873 c_type_print_template_args (const struct type_print_options
*flags
,
874 struct type
*type
, struct ui_file
*stream
)
881 for (i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
883 struct symbol
*sym
= TYPE_TEMPLATE_ARGUMENT (type
, i
);
885 if (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
891 fprintf_filtered (stream
, _("[with %s = "), sym
->linkage_name ());
896 fputs_filtered (", ", stream
);
898 fprintf_filtered (stream
, "%s = ", sym
->linkage_name ());
901 c_print_type (SYMBOL_TYPE (sym
), "", stream
, -1, 0, flags
);
905 fputs_filtered (_("] "), stream
);
908 /* Use 'print_spaces_filtered', but take into consideration the
909 type_print_options FLAGS in order to determine how many whitespaces
913 print_spaces_filtered_with_print_options
914 (int level
, struct ui_file
*stream
, const struct type_print_options
*flags
)
916 if (!flags
->print_offsets
)
917 print_spaces_filtered (level
, stream
);
919 print_spaces_filtered (level
+ print_offset_data::indentation
, stream
);
922 /* Output an access specifier to STREAM, if needed. LAST_ACCESS is the
923 last access specifier output (typically returned by this function). */
925 static enum access_specifier
926 output_access_specifier (struct ui_file
*stream
,
927 enum access_specifier last_access
,
928 int level
, bool is_protected
, bool is_private
,
929 const struct type_print_options
*flags
)
933 if (last_access
!= s_protected
)
935 last_access
= s_protected
;
936 print_spaces_filtered_with_print_options (level
+ 2, stream
, flags
);
937 fprintf_filtered (stream
, "protected:\n");
942 if (last_access
!= s_private
)
944 last_access
= s_private
;
945 print_spaces_filtered_with_print_options (level
+ 2, stream
, flags
);
946 fprintf_filtered (stream
, "private:\n");
951 if (last_access
!= s_public
)
953 last_access
= s_public
;
954 print_spaces_filtered_with_print_options (level
+ 2, stream
, flags
);
955 fprintf_filtered (stream
, "public:\n");
962 /* Return true if an access label (i.e., "public:", "private:",
963 "protected:") needs to be printed for TYPE. */
966 need_access_label_p (struct type
*type
)
968 if (TYPE_DECLARED_CLASS (type
))
971 for (int i
= TYPE_N_BASECLASSES (type
); i
< type
->num_fields (); i
++)
972 if (!TYPE_FIELD_PRIVATE (type
, i
))
975 for (int j
= 0; j
< TYPE_NFN_FIELDS (type
); j
++)
976 for (int i
= 0; i
< TYPE_FN_FIELDLIST_LENGTH (type
, j
); i
++)
977 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
981 for (int i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); ++i
)
982 if (!TYPE_TYPEDEF_FIELD_PRIVATE (type
, i
))
988 for (int i
= TYPE_N_BASECLASSES (type
); i
< type
->num_fields (); i
++)
989 if (TYPE_FIELD_PRIVATE (type
, i
) || TYPE_FIELD_PROTECTED (type
, i
))
992 for (int j
= 0; j
< TYPE_NFN_FIELDS (type
); j
++)
995 for (int i
= 0; i
< TYPE_FN_FIELDLIST_LENGTH (type
, j
); i
++)
996 if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type
,
998 || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type
,
1004 for (int i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); ++i
)
1005 if (TYPE_TYPEDEF_FIELD_PROTECTED (type
, i
)
1006 || TYPE_TYPEDEF_FIELD_PRIVATE (type
, i
))
1013 /* Helper function that temporarily disables FLAGS->PRINT_OFFSETS,
1014 calls 'c_print_type_1', and then reenables FLAGS->PRINT_OFFSETS if
1018 c_print_type_no_offsets (struct type
*type
,
1019 const char *varstring
,
1020 struct ui_file
*stream
,
1021 int show
, int level
,
1022 enum language language
,
1023 struct type_print_options
*flags
,
1024 struct print_offset_data
*podata
)
1026 unsigned int old_po
= flags
->print_offsets
;
1028 /* Temporarily disable print_offsets, because it would mess with
1030 flags
->print_offsets
= 0;
1031 c_print_type_1 (type
, varstring
, stream
, show
, level
, language
, flags
,
1033 flags
->print_offsets
= old_po
;
1036 /* Helper for 'c_type_print_base' that handles structs and unions.
1037 For a description of the arguments, see 'c_type_print_base'. */
1040 c_type_print_base_struct_union (struct type
*type
, struct ui_file
*stream
,
1041 int show
, int level
,
1042 enum language language
,
1043 const struct type_print_options
*flags
,
1044 struct print_offset_data
*podata
)
1046 struct type_print_options local_flags
= *flags
;
1047 local_flags
.local_typedefs
= NULL
;
1049 std::unique_ptr
<typedef_hash_table
> hash_holder
;
1052 if (flags
->local_typedefs
)
1053 local_flags
.local_typedefs
1054 = new typedef_hash_table (*flags
->local_typedefs
);
1056 local_flags
.local_typedefs
= new typedef_hash_table ();
1058 hash_holder
.reset (local_flags
.local_typedefs
);
1061 c_type_print_modifier (type
, stream
, 0, 1, language
);
1062 if (type
->code () == TYPE_CODE_UNION
)
1063 fprintf_filtered (stream
, "union ");
1064 else if (TYPE_DECLARED_CLASS (type
))
1065 fprintf_filtered (stream
, "class ");
1067 fprintf_filtered (stream
, "struct ");
1069 /* Print the tag if it exists. The HP aCC compiler emits a
1070 spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
1071 enum}" tag for unnamed struct/union/enum's, which we don't
1073 if (type
->name () != NULL
1074 && !startswith (type
->name (), "{unnamed"))
1076 /* When printing the tag name, we are still effectively
1077 printing in the outer context, hence the use of FLAGS
1079 print_name_maybe_canonical (type
->name (), flags
, stream
);
1081 fputs_filtered (" ", stream
);
1086 /* If we just printed a tag name, no need to print anything
1088 if (type
->name () == NULL
)
1089 fprintf_filtered (stream
, "{...}");
1091 else if (show
> 0 || type
->name () == NULL
)
1093 struct type
*basetype
;
1096 c_type_print_template_args (&local_flags
, type
, stream
);
1098 /* Add in template parameters when printing derivation info. */
1099 if (local_flags
.local_typedefs
!= NULL
)
1100 local_flags
.local_typedefs
->add_template_parameters (type
);
1101 cp_type_print_derivation_info (stream
, type
, &local_flags
);
1103 /* This holds just the global typedefs and the template
1105 struct type_print_options semi_local_flags
= *flags
;
1106 semi_local_flags
.local_typedefs
= NULL
;
1108 std::unique_ptr
<typedef_hash_table
> semi_holder
;
1109 if (local_flags
.local_typedefs
!= nullptr)
1111 semi_local_flags
.local_typedefs
1112 = new typedef_hash_table (*local_flags
.local_typedefs
);
1113 semi_holder
.reset (semi_local_flags
.local_typedefs
);
1115 /* Now add in the local typedefs. */
1116 local_flags
.local_typedefs
->recursively_update (type
);
1119 fprintf_filtered (stream
, "{\n");
1121 if (type
->num_fields () == 0 && TYPE_NFN_FIELDS (type
) == 0
1122 && TYPE_TYPEDEF_FIELD_COUNT (type
) == 0)
1124 if (type
->is_stub ())
1125 fprintfi_filtered (level
+ 4, stream
,
1126 _("%p[<incomplete type>%p]\n"),
1127 metadata_style
.style ().ptr (), nullptr);
1129 fprintfi_filtered (level
+ 4, stream
,
1130 _("%p[<no data fields>%p]\n"),
1131 metadata_style
.style ().ptr (), nullptr);
1134 /* Start off with no specific section type, so we can print
1135 one for the first field we find, and use that section type
1136 thereafter until we find another type. */
1138 enum access_specifier section_type
= s_none
;
1140 /* For a class, if all members are private, there's no need
1141 for a "private:" label; similarly, for a struct or union
1142 masquerading as a class, if all members are public, there's
1143 no need for a "public:" label. */
1144 bool need_access_label
= need_access_label_p (type
);
1146 /* If there is a base class for this type,
1147 do not print the field that it occupies. */
1149 int len
= type
->num_fields ();
1150 vptr_fieldno
= get_vptr_fieldno (type
, &basetype
);
1152 struct print_offset_data local_podata
;
1154 for (int i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
1158 /* If we have a virtual table pointer, omit it. Even if
1159 virtual table pointers are not specifically marked in
1160 the debug info, they should be artificial. */
1161 if ((i
== vptr_fieldno
&& type
== basetype
)
1162 || TYPE_FIELD_ARTIFICIAL (type
, i
))
1165 if (need_access_label
)
1167 section_type
= output_access_specifier
1168 (stream
, section_type
, level
,
1169 TYPE_FIELD_PROTECTED (type
, i
),
1170 TYPE_FIELD_PRIVATE (type
, i
), flags
);
1173 bool is_static
= field_is_static (&type
->field (i
));
1175 if (flags
->print_offsets
)
1176 podata
->update (type
, i
, stream
);
1178 print_spaces_filtered (level
+ 4, stream
);
1180 fprintf_filtered (stream
, "static ");
1182 int newshow
= show
- 1;
1184 if (!is_static
&& flags
->print_offsets
1185 && (type
->field (i
).type ()->code () == TYPE_CODE_STRUCT
1186 || type
->field (i
).type ()->code () == TYPE_CODE_UNION
))
1188 /* If we're printing offsets and this field's type is
1189 either a struct or an union, then we're interested in
1193 /* Make sure we carry our offset when we expand the
1195 local_podata
.offset_bitpos
1196 = podata
->offset_bitpos
+ TYPE_FIELD_BITPOS (type
, i
);
1197 /* We're entering a struct/union. Right now,
1198 PODATA->END_BITPOS points right *after* the
1199 struct/union. However, when printing the first field
1200 of this inner struct/union, the end_bitpos we're
1201 expecting is exactly at the beginning of the
1202 struct/union. Therefore, we subtract the length of
1203 the whole struct/union. */
1204 local_podata
.end_bitpos
1205 = podata
->end_bitpos
1206 - TYPE_LENGTH (type
->field (i
).type ()) * TARGET_CHAR_BIT
;
1209 c_print_type_1 (type
->field (i
).type (),
1210 TYPE_FIELD_NAME (type
, i
),
1211 stream
, newshow
, level
+ 4,
1212 language
, &local_flags
, &local_podata
);
1214 if (!is_static
&& TYPE_FIELD_PACKED (type
, i
))
1216 /* It is a bitfield. This code does not attempt
1217 to look at the bitpos and reconstruct filler,
1218 unnamed fields. This would lead to misleading
1219 results if the compiler does not put out fields
1220 for such things (I don't know what it does). */
1221 fprintf_filtered (stream
, " : %d",
1222 TYPE_FIELD_BITSIZE (type
, i
));
1224 fprintf_filtered (stream
, ";\n");
1227 /* If there are both fields and methods, put a blank line
1228 between them. Make sure to count only method that we
1229 will display; artificial methods will be hidden. */
1230 len
= TYPE_NFN_FIELDS (type
);
1231 if (!flags
->print_methods
)
1234 for (int i
= 0; i
< len
; i
++)
1236 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1237 int len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1240 for (j
= 0; j
< len2
; j
++)
1241 if (!TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
1244 if (real_len
> 0 && section_type
!= s_none
)
1245 fprintf_filtered (stream
, "\n");
1247 /* C++: print out the methods. */
1248 for (int i
= 0; i
< len
; i
++)
1250 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1251 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1252 const char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1253 const char *name
= type
->name ();
1254 int is_constructor
= name
&& strcmp (method_name
,
1257 for (j
= 0; j
< len2
; j
++)
1259 const char *mangled_name
;
1260 gdb::unique_xmalloc_ptr
<char> mangled_name_holder
;
1261 char *demangled_name
;
1262 const char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1263 int is_full_physname_constructor
=
1264 TYPE_FN_FIELD_CONSTRUCTOR (f
, j
)
1265 || is_constructor_name (physname
)
1266 || is_destructor_name (physname
)
1267 || method_name
[0] == '~';
1269 /* Do not print out artificial methods. */
1270 if (TYPE_FN_FIELD_ARTIFICIAL (f
, j
))
1274 section_type
= output_access_specifier
1275 (stream
, section_type
, level
,
1276 TYPE_FN_FIELD_PROTECTED (f
, j
),
1277 TYPE_FN_FIELD_PRIVATE (f
, j
), flags
);
1279 print_spaces_filtered_with_print_options (level
+ 4, stream
,
1281 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1282 fprintf_filtered (stream
, "virtual ");
1283 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1284 fprintf_filtered (stream
, "static ");
1285 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1287 /* Keep GDB from crashing here. */
1288 fprintf_filtered (stream
,
1289 _("%p[<undefined type>%p] %s;\n"),
1290 metadata_style
.style ().ptr (), nullptr,
1291 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1294 else if (!is_constructor
/* Constructors don't
1297 && !is_full_physname_constructor
/* " " */
1298 && !is_type_conversion_operator (type
, i
, j
))
1300 c_print_type_no_offsets
1301 (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1302 "", stream
, -1, 0, language
, &local_flags
, podata
);
1304 fputs_filtered (" ", stream
);
1306 if (TYPE_FN_FIELD_STUB (f
, j
))
1308 /* Build something we can demangle. */
1309 mangled_name_holder
.reset (gdb_mangle_name (type
, i
, j
));
1310 mangled_name
= mangled_name_holder
.get ();
1313 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1316 gdb_demangle (mangled_name
,
1317 DMGL_ANSI
| DMGL_PARAMS
);
1318 if (demangled_name
== NULL
)
1320 /* In some cases (for instance with the HP
1321 demangling), if a function has more than 10
1322 arguments, the demangling will fail.
1323 Let's try to reconstruct the function
1324 signature from the symbol information. */
1325 if (!TYPE_FN_FIELD_STUB (f
, j
))
1327 int staticp
= TYPE_FN_FIELD_STATIC_P (f
, j
);
1328 struct type
*mtype
= TYPE_FN_FIELD_TYPE (f
, j
);
1330 cp_type_print_method_args (mtype
,
1338 fprintf_styled (stream
, metadata_style
.style (),
1339 _("<badly mangled name '%s'>"),
1345 char *demangled_no_class
1346 = remove_qualifiers (demangled_name
);
1348 /* Get rid of the `static' appended by the
1350 p
= strstr (demangled_no_class
, " static");
1353 int length
= p
- demangled_no_class
;
1354 char *demangled_no_static
;
1357 = (char *) xmalloc (length
+ 1);
1358 strncpy (demangled_no_static
,
1359 demangled_no_class
, length
);
1360 *(demangled_no_static
+ length
) = '\0';
1361 fputs_filtered (demangled_no_static
, stream
);
1362 xfree (demangled_no_static
);
1365 fputs_filtered (demangled_no_class
, stream
);
1366 xfree (demangled_name
);
1369 fprintf_filtered (stream
, ";\n");
1373 /* Print out nested types. */
1374 if (TYPE_NESTED_TYPES_COUNT (type
) != 0
1375 && semi_local_flags
.print_nested_type_limit
!= 0)
1377 if (semi_local_flags
.print_nested_type_limit
> 0)
1378 --semi_local_flags
.print_nested_type_limit
;
1380 if (type
->num_fields () != 0 || TYPE_NFN_FIELDS (type
) != 0)
1381 fprintf_filtered (stream
, "\n");
1383 for (int i
= 0; i
< TYPE_NESTED_TYPES_COUNT (type
); ++i
)
1385 print_spaces_filtered_with_print_options (level
+ 4, stream
,
1387 c_print_type_no_offsets (TYPE_NESTED_TYPES_FIELD_TYPE (type
, i
),
1388 "", stream
, show
, level
+ 4,
1389 language
, &semi_local_flags
, podata
);
1390 fprintf_filtered (stream
, ";\n");
1394 /* Print typedefs defined in this class. */
1396 if (TYPE_TYPEDEF_FIELD_COUNT (type
) != 0 && flags
->print_typedefs
)
1398 if (type
->num_fields () != 0 || TYPE_NFN_FIELDS (type
) != 0
1399 || TYPE_NESTED_TYPES_COUNT (type
) != 0)
1400 fprintf_filtered (stream
, "\n");
1402 for (int i
= 0; i
< TYPE_TYPEDEF_FIELD_COUNT (type
); i
++)
1404 struct type
*target
= TYPE_TYPEDEF_FIELD_TYPE (type
, i
);
1406 /* Dereference the typedef declaration itself. */
1407 gdb_assert (target
->code () == TYPE_CODE_TYPEDEF
);
1408 target
= TYPE_TARGET_TYPE (target
);
1410 if (need_access_label
)
1412 section_type
= output_access_specifier
1413 (stream
, section_type
, level
,
1414 TYPE_TYPEDEF_FIELD_PROTECTED (type
, i
),
1415 TYPE_TYPEDEF_FIELD_PRIVATE (type
, i
), flags
);
1417 print_spaces_filtered_with_print_options (level
+ 4, stream
,
1419 fprintf_filtered (stream
, "typedef ");
1421 /* We want to print typedefs with substitutions
1422 from the template parameters or globally-known
1423 typedefs but not local typedefs. */
1424 c_print_type_no_offsets (target
,
1425 TYPE_TYPEDEF_FIELD_NAME (type
, i
),
1426 stream
, show
- 1, level
+ 4,
1427 language
, &semi_local_flags
, podata
);
1428 fprintf_filtered (stream
, ";\n");
1432 if (flags
->print_offsets
)
1435 podata
->finish (type
, level
, stream
);
1437 print_spaces_filtered (print_offset_data::indentation
, stream
);
1439 print_spaces_filtered (2, stream
);
1442 fprintfi_filtered (level
, stream
, "}");
1446 /* Print the name of the type (or the ultimate pointer target,
1447 function value or array element), or the description of a structure
1450 SHOW positive means print details about the type (e.g. enum
1451 values), and print structure elements passing SHOW - 1 for show.
1453 SHOW negative means just print the type name or struct tag if there
1454 is one. If there is no name, print something sensible but concise
1455 like "struct {...}".
1457 SHOW zero means just print the type name or struct tag if there is
1458 one. If there is no name, print something sensible but not as
1459 concise like "struct {int x; int y;}".
1461 LEVEL is the number of spaces to indent by.
1462 We increase it for some recursive calls. */
1465 c_type_print_base_1 (struct type
*type
, struct ui_file
*stream
,
1466 int show
, int level
,
1467 enum language language
,
1468 const struct type_print_options
*flags
,
1469 struct print_offset_data
*podata
)
1478 fputs_styled (_("<type unknown>"), metadata_style
.style (), stream
);
1482 /* When SHOW is zero or less, and there is a valid type name, then
1483 always just print the type name directly from the type. */
1486 && type
->name () != NULL
)
1488 c_type_print_modifier (type
, stream
, 0, 1, language
);
1490 /* If we have "typedef struct foo {. . .} bar;" do we want to
1491 print it as "struct foo" or as "bar"? Pick the latter for
1492 C++, because C++ folk tend to expect things like "class5
1493 *foo" rather than "struct class5 *foo". We rather
1494 arbitrarily choose to make language_minimal work in a C-like
1496 if (language
== language_c
|| language
== language_minimal
)
1498 if (type
->code () == TYPE_CODE_UNION
)
1499 fprintf_filtered (stream
, "union ");
1500 else if (type
->code () == TYPE_CODE_STRUCT
)
1502 if (TYPE_DECLARED_CLASS (type
))
1503 fprintf_filtered (stream
, "class ");
1505 fprintf_filtered (stream
, "struct ");
1507 else if (type
->code () == TYPE_CODE_ENUM
)
1508 fprintf_filtered (stream
, "enum ");
1511 print_name_maybe_canonical (type
->name (), flags
, stream
);
1515 type
= check_typedef (type
);
1517 switch (type
->code ())
1519 case TYPE_CODE_TYPEDEF
:
1520 /* If we get here, the typedef doesn't have a name, and we
1521 couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
1522 gdb_assert (type
->name () == NULL
);
1523 gdb_assert (TYPE_TARGET_TYPE (type
) == NULL
);
1524 fprintf_styled (stream
, metadata_style
.style (),
1525 _("<unnamed typedef>"));
1528 case TYPE_CODE_FUNC
:
1529 case TYPE_CODE_METHOD
:
1530 if (TYPE_TARGET_TYPE (type
) == NULL
)
1531 type_print_unknown_return_type (stream
);
1533 c_type_print_base_1 (TYPE_TARGET_TYPE (type
),
1534 stream
, show
, level
, language
, flags
, podata
);
1536 case TYPE_CODE_ARRAY
:
1538 case TYPE_CODE_MEMBERPTR
:
1540 case TYPE_CODE_RVALUE_REF
:
1541 case TYPE_CODE_METHODPTR
:
1542 c_type_print_base_1 (TYPE_TARGET_TYPE (type
),
1543 stream
, show
, level
, language
, flags
, podata
);
1546 case TYPE_CODE_STRUCT
:
1547 case TYPE_CODE_UNION
:
1548 c_type_print_base_struct_union (type
, stream
, show
, level
,
1549 language
, flags
, podata
);
1552 case TYPE_CODE_ENUM
:
1553 c_type_print_modifier (type
, stream
, 0, 1, language
);
1554 fprintf_filtered (stream
, "enum ");
1555 if (TYPE_DECLARED_CLASS (type
))
1556 fprintf_filtered (stream
, "class ");
1557 /* Print the tag name if it exists.
1558 The aCC compiler emits a spurious
1559 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1560 tag for unnamed struct/union/enum's, which we don't
1562 if (type
->name () != NULL
1563 && !startswith (type
->name (), "{unnamed"))
1565 print_name_maybe_canonical (type
->name (), flags
, stream
);
1567 fputs_filtered (" ", stream
);
1573 /* If we just printed a tag name, no need to print anything
1575 if (type
->name () == NULL
)
1576 fprintf_filtered (stream
, "{...}");
1578 else if (show
> 0 || type
->name () == NULL
)
1580 LONGEST lastval
= 0;
1582 /* We can't handle this case perfectly, as DWARF does not
1583 tell us whether or not the underlying type was specified
1584 in the source (and other debug formats don't provide this
1585 at all). We choose to print the underlying type, if it
1586 has a name, when in C++ on the theory that it's better to
1587 print too much than too little; but conversely not to
1588 print something egregiously outside the current
1589 language's syntax. */
1590 if (language
== language_cplus
&& TYPE_TARGET_TYPE (type
) != NULL
)
1592 struct type
*underlying
= check_typedef (TYPE_TARGET_TYPE (type
));
1594 if (underlying
->name () != NULL
)
1595 fprintf_filtered (stream
, ": %s ", underlying
->name ());
1598 fprintf_filtered (stream
, "{");
1599 len
= type
->num_fields ();
1600 for (i
= 0; i
< len
; i
++)
1604 fprintf_filtered (stream
, ", ");
1606 fputs_styled (TYPE_FIELD_NAME (type
, i
),
1607 variable_name_style
.style (), stream
);
1608 if (lastval
!= TYPE_FIELD_ENUMVAL (type
, i
))
1610 fprintf_filtered (stream
, " = %s",
1611 plongest (TYPE_FIELD_ENUMVAL (type
, i
)));
1612 lastval
= TYPE_FIELD_ENUMVAL (type
, i
);
1616 fprintf_filtered (stream
, "}");
1620 case TYPE_CODE_FLAGS
:
1622 struct type_print_options local_flags
= *flags
;
1624 local_flags
.local_typedefs
= NULL
;
1626 c_type_print_modifier (type
, stream
, 0, 1, language
);
1627 fprintf_filtered (stream
, "flag ");
1628 print_name_maybe_canonical (type
->name (), flags
, stream
);
1631 fputs_filtered (" ", stream
);
1632 fprintf_filtered (stream
, "{\n");
1633 if (type
->num_fields () == 0)
1635 if (type
->is_stub ())
1636 fprintfi_filtered (level
+ 4, stream
,
1637 _("%p[<incomplete type>%p]\n"),
1638 metadata_style
.style ().ptr (), nullptr);
1640 fprintfi_filtered (level
+ 4, stream
,
1641 _("%p[<no data fields>%p]\n"),
1642 metadata_style
.style ().ptr (), nullptr);
1644 len
= type
->num_fields ();
1645 for (i
= 0; i
< len
; i
++)
1648 print_spaces_filtered (level
+ 4, stream
);
1649 /* We pass "show" here and not "show - 1" to get enum types
1650 printed. There's no other way to see them. */
1651 c_print_type_1 (type
->field (i
).type (),
1652 TYPE_FIELD_NAME (type
, i
),
1653 stream
, show
, level
+ 4,
1654 language
, &local_flags
, podata
);
1655 fprintf_filtered (stream
, " @%s",
1656 plongest (TYPE_FIELD_BITPOS (type
, i
)));
1657 if (TYPE_FIELD_BITSIZE (type
, i
) > 1)
1659 fprintf_filtered (stream
, "-%s",
1660 plongest (TYPE_FIELD_BITPOS (type
, i
)
1661 + TYPE_FIELD_BITSIZE (type
, i
)
1664 fprintf_filtered (stream
, ";\n");
1666 fprintfi_filtered (level
, stream
, "}");
1671 case TYPE_CODE_VOID
:
1672 fprintf_filtered (stream
, "void");
1675 case TYPE_CODE_UNDEF
:
1676 fprintf_filtered (stream
, _("struct <unknown>"));
1679 case TYPE_CODE_ERROR
:
1680 fprintf_filtered (stream
, "%s", TYPE_ERROR_NAME (type
));
1683 case TYPE_CODE_RANGE
:
1684 /* This should not occur. */
1685 fprintf_styled (stream
, metadata_style
.style (), _("<range type>"));
1688 case TYPE_CODE_FIXED_POINT
:
1689 print_type_fixed_point (type
, stream
);
1692 case TYPE_CODE_NAMESPACE
:
1693 fputs_filtered ("namespace ", stream
);
1694 fputs_filtered (type
->name (), stream
);
1698 /* Handle types not explicitly handled by the other cases, such
1699 as fundamental types. For these, just print whatever the
1700 type name is, as recorded in the type itself. If there is no
1701 type name, then complain. */
1702 if (type
->name () != NULL
)
1704 c_type_print_modifier (type
, stream
, 0, 1, language
);
1705 print_name_maybe_canonical (type
->name (), flags
, stream
);
1709 /* At least for dump_symtab, it is important that this not
1711 fprintf_styled (stream
, metadata_style
.style (),
1712 _("<invalid type code %d>"), type
->code ());
1718 /* See c_type_print_base_1. */
1721 c_type_print_base (struct type
*type
, struct ui_file
*stream
,
1722 int show
, int level
,
1723 const struct type_print_options
*flags
)
1725 struct print_offset_data podata
;
1727 c_type_print_base_1 (type
, stream
, show
, level
,
1728 current_language
->la_language
, flags
, &podata
);