Use unique_xmalloc_ptr in c_type_print_base
[deliverable/binutils-gdb.git] / gdb / c-typeprint.c
1 /* Support for printing C and C++ types for GDB, the GNU debugger.
2 Copyright (C) 1986-2017 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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/>. */
18
19 #include "defs.h"
20 #include "gdb_obstack.h"
21 #include "bfd.h" /* Binary File Description. */
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "expression.h"
25 #include "value.h"
26 #include "gdbcore.h"
27 #include "target.h"
28 #include "language.h"
29 #include "demangle.h"
30 #include "c-lang.h"
31 #include "typeprint.h"
32 #include "cp-abi.h"
33 #include "cp-support.h"
34
35 /* A list of access specifiers used for printing. */
36
37 enum access_specifier
38 {
39 s_none,
40 s_public,
41 s_private,
42 s_protected
43 };
44
45 static void c_type_print_varspec_prefix (struct type *,
46 struct ui_file *,
47 int, int, int,
48 const struct type_print_options *);
49
50 /* Print "const", "volatile", or address space modifiers. */
51 static void c_type_print_modifier (struct type *,
52 struct ui_file *,
53 int, int);
54 \f
55
56 /* A callback function for cp_canonicalize_string_full that uses
57 find_typedef_in_hash. */
58
59 static const char *
60 find_typedef_for_canonicalize (struct type *t, void *data)
61 {
62 return find_typedef_in_hash ((const struct type_print_options *) data, t);
63 }
64
65 /* Print NAME on STREAM. If the 'raw' field of FLAGS is not set,
66 canonicalize NAME using the local typedefs first. */
67
68 static void
69 print_name_maybe_canonical (const char *name,
70 const struct type_print_options *flags,
71 struct ui_file *stream)
72 {
73 std::string s;
74
75 if (!flags->raw)
76 s = cp_canonicalize_string_full (name,
77 find_typedef_for_canonicalize,
78 (void *) flags);
79
80 fputs_filtered (!s.empty () ? s.c_str () : name, stream);
81 }
82
83 \f
84
85 /* LEVEL is the depth to indent lines by. */
86
87 void
88 c_print_type (struct type *type,
89 const char *varstring,
90 struct ui_file *stream,
91 int show, int level,
92 const struct type_print_options *flags)
93 {
94 enum type_code code;
95 int demangled_args;
96 int need_post_space;
97 const char *local_name;
98
99 if (show > 0)
100 type = check_typedef (type);
101
102 local_name = find_typedef_in_hash (flags, type);
103 if (local_name != NULL)
104 {
105 fputs_filtered (local_name, stream);
106 if (varstring != NULL && *varstring != '\0')
107 fputs_filtered (" ", stream);
108 }
109 else
110 {
111 c_type_print_base (type, stream, show, level, flags);
112 code = TYPE_CODE (type);
113 if ((varstring != NULL && *varstring != '\0')
114 /* Need a space if going to print stars or brackets;
115 but not if we will print just a type name. */
116 || ((show > 0 || TYPE_NAME (type) == 0)
117 && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
118 || code == TYPE_CODE_METHOD
119 || (code == TYPE_CODE_ARRAY
120 && !TYPE_VECTOR (type))
121 || code == TYPE_CODE_MEMBERPTR
122 || code == TYPE_CODE_METHODPTR
123 || TYPE_IS_REFERENCE (type))))
124 fputs_filtered (" ", stream);
125 need_post_space = (varstring != NULL && strcmp (varstring, "") != 0);
126 c_type_print_varspec_prefix (type, stream, show, 0, need_post_space,
127 flags);
128 }
129
130 if (varstring != NULL)
131 {
132 fputs_filtered (varstring, stream);
133
134 /* For demangled function names, we have the arglist as part of
135 the name, so don't print an additional pair of ()'s. */
136 if (local_name == NULL)
137 {
138 demangled_args = strchr (varstring, '(') != NULL;
139 c_type_print_varspec_suffix (type, stream, show,
140 0, demangled_args,
141 flags);
142 }
143 }
144 }
145
146 /* Print a typedef using C syntax. TYPE is the underlying type.
147 NEW_SYMBOL is the symbol naming the type. STREAM is the stream on
148 which to print. */
149
150 void
151 c_print_typedef (struct type *type,
152 struct symbol *new_symbol,
153 struct ui_file *stream)
154 {
155 type = check_typedef (type);
156 fprintf_filtered (stream, "typedef ");
157 type_print (type, "", stream, 0);
158 if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0
159 || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))),
160 SYMBOL_LINKAGE_NAME (new_symbol)) != 0
161 || TYPE_CODE (SYMBOL_TYPE (new_symbol)) == TYPE_CODE_TYPEDEF)
162 fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol));
163 fprintf_filtered (stream, ";\n");
164 }
165
166 /* If TYPE is a derived type, then print out derivation information.
167 Print only the actual base classes of this type, not the base
168 classes of the base classes. I.e. for the derivation hierarchy:
169
170 class A { int a; };
171 class B : public A {int b; };
172 class C : public B {int c; };
173
174 Print the type of class C as:
175
176 class C : public B {
177 int c;
178 }
179
180 Not as the following (like gdb used to), which is not legal C++
181 syntax for derived types and may be confused with the multiple
182 inheritance form:
183
184 class C : public B : public A {
185 int c;
186 }
187
188 In general, gdb should try to print the types as closely as
189 possible to the form that they appear in the source code. */
190
191 static void
192 cp_type_print_derivation_info (struct ui_file *stream,
193 struct type *type,
194 const struct type_print_options *flags)
195 {
196 const char *name;
197 int i;
198
199 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
200 {
201 wrap_here (" ");
202 fputs_filtered (i == 0 ? ": " : ", ", stream);
203 fprintf_filtered (stream, "%s%s ",
204 BASETYPE_VIA_PUBLIC (type, i)
205 ? "public" : (TYPE_FIELD_PROTECTED (type, i)
206 ? "protected" : "private"),
207 BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
208 name = type_name_no_tag (TYPE_BASECLASS (type, i));
209 if (name)
210 print_name_maybe_canonical (name, flags, stream);
211 else
212 fprintf_filtered (stream, "(null)");
213 }
214 if (i > 0)
215 {
216 fputs_filtered (" ", stream);
217 }
218 }
219
220 /* Print the C++ method arguments ARGS to the file STREAM. */
221
222 static void
223 cp_type_print_method_args (struct type *mtype, const char *prefix,
224 const char *varstring, int staticp,
225 struct ui_file *stream,
226 const struct type_print_options *flags)
227 {
228 struct field *args = TYPE_FIELDS (mtype);
229 int nargs = TYPE_NFIELDS (mtype);
230 int varargs = TYPE_VARARGS (mtype);
231 int i;
232
233 fprintf_symbol_filtered (stream, prefix,
234 language_cplus, DMGL_ANSI);
235 fprintf_symbol_filtered (stream, varstring,
236 language_cplus, DMGL_ANSI);
237 fputs_filtered ("(", stream);
238
239 /* Skip the class variable. We keep this here to accommodate older
240 compilers and debug formats which may not support artificial
241 parameters. */
242 i = staticp ? 0 : 1;
243 if (nargs > i)
244 {
245 while (i < nargs)
246 {
247 struct field arg = args[i++];
248
249 /* Skip any artificial arguments. */
250 if (FIELD_ARTIFICIAL (arg))
251 continue;
252
253 c_print_type (arg.type, "", stream, 0, 0, flags);
254
255 if (i == nargs && varargs)
256 fprintf_filtered (stream, ", ...");
257 else if (i < nargs)
258 {
259 fprintf_filtered (stream, ", ");
260 wrap_here (" ");
261 }
262 }
263 }
264 else if (varargs)
265 fprintf_filtered (stream, "...");
266 else if (current_language->la_language == language_cplus)
267 fprintf_filtered (stream, "void");
268
269 fprintf_filtered (stream, ")");
270
271 /* For non-static methods, read qualifiers from the type of
272 THIS. */
273 if (!staticp)
274 {
275 struct type *domain;
276
277 gdb_assert (nargs > 0);
278 gdb_assert (TYPE_CODE (args[0].type) == TYPE_CODE_PTR);
279 domain = TYPE_TARGET_TYPE (args[0].type);
280
281 if (TYPE_CONST (domain))
282 fprintf_filtered (stream, " const");
283
284 if (TYPE_VOLATILE (domain))
285 fprintf_filtered (stream, " volatile");
286
287 if (TYPE_RESTRICT (domain))
288 fprintf_filtered (stream, " restrict");
289
290 if (TYPE_ATOMIC (domain))
291 fprintf_filtered (stream, " _Atomic");
292 }
293 }
294
295
296 /* Print any asterisks or open-parentheses needed before the
297 variable name (to describe its type).
298
299 On outermost call, pass 0 for PASSED_A_PTR.
300 On outermost call, SHOW > 0 means should ignore
301 any typename for TYPE and show its details.
302 SHOW is always zero on recursive calls.
303
304 NEED_POST_SPACE is non-zero when a space will be be needed
305 between a trailing qualifier and a field, variable, or function
306 name. */
307
308 static void
309 c_type_print_varspec_prefix (struct type *type,
310 struct ui_file *stream,
311 int show, int passed_a_ptr,
312 int need_post_space,
313 const struct type_print_options *flags)
314 {
315 const char *name;
316
317 if (type == 0)
318 return;
319
320 if (TYPE_NAME (type) && show <= 0)
321 return;
322
323 QUIT;
324
325 switch (TYPE_CODE (type))
326 {
327 case TYPE_CODE_PTR:
328 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
329 stream, show, 1, 1, flags);
330 fprintf_filtered (stream, "*");
331 c_type_print_modifier (type, stream, 1, need_post_space);
332 break;
333
334 case TYPE_CODE_MEMBERPTR:
335 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
336 stream, show, 0, 0, flags);
337 name = type_name_no_tag (TYPE_SELF_TYPE (type));
338 if (name)
339 print_name_maybe_canonical (name, flags, stream);
340 else
341 c_type_print_base (TYPE_SELF_TYPE (type),
342 stream, -1, passed_a_ptr, flags);
343 fprintf_filtered (stream, "::*");
344 break;
345
346 case TYPE_CODE_METHODPTR:
347 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
348 stream, show, 0, 0, flags);
349 fprintf_filtered (stream, "(");
350 name = type_name_no_tag (TYPE_SELF_TYPE (type));
351 if (name)
352 print_name_maybe_canonical (name, flags, stream);
353 else
354 c_type_print_base (TYPE_SELF_TYPE (type),
355 stream, -1, passed_a_ptr, flags);
356 fprintf_filtered (stream, "::*");
357 break;
358
359 case TYPE_CODE_REF:
360 case TYPE_CODE_RVALUE_REF:
361 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
362 stream, show, 1, 0, flags);
363 fprintf_filtered (stream, TYPE_CODE(type) == TYPE_CODE_REF ? "&" : "&&");
364 c_type_print_modifier (type, stream, 1, need_post_space);
365 break;
366
367 case TYPE_CODE_METHOD:
368 case TYPE_CODE_FUNC:
369 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
370 stream, show, 0, 0, flags);
371 if (passed_a_ptr)
372 fprintf_filtered (stream, "(");
373 break;
374
375 case TYPE_CODE_ARRAY:
376 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
377 stream, show, 0, 0, flags);
378 if (passed_a_ptr)
379 fprintf_filtered (stream, "(");
380 break;
381
382 case TYPE_CODE_TYPEDEF:
383 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
384 stream, show, passed_a_ptr, 0, flags);
385 break;
386
387 case TYPE_CODE_UNDEF:
388 case TYPE_CODE_STRUCT:
389 case TYPE_CODE_UNION:
390 case TYPE_CODE_ENUM:
391 case TYPE_CODE_FLAGS:
392 case TYPE_CODE_INT:
393 case TYPE_CODE_FLT:
394 case TYPE_CODE_VOID:
395 case TYPE_CODE_ERROR:
396 case TYPE_CODE_CHAR:
397 case TYPE_CODE_BOOL:
398 case TYPE_CODE_SET:
399 case TYPE_CODE_RANGE:
400 case TYPE_CODE_STRING:
401 case TYPE_CODE_COMPLEX:
402 case TYPE_CODE_NAMESPACE:
403 case TYPE_CODE_DECFLOAT:
404 /* These types need no prefix. They are listed here so that
405 gcc -Wall will reveal any types that haven't been handled. */
406 break;
407 default:
408 error (_("type not handled in c_type_print_varspec_prefix()"));
409 break;
410 }
411 }
412
413 /* Print out "const" and "volatile" attributes,
414 and address space id if present.
415 TYPE is a pointer to the type being printed out.
416 STREAM is the output destination.
417 NEED_PRE_SPACE = 1 indicates an initial white space is needed.
418 NEED_POST_SPACE = 1 indicates a final white space is needed. */
419
420 static void
421 c_type_print_modifier (struct type *type, struct ui_file *stream,
422 int need_pre_space, int need_post_space)
423 {
424 int did_print_modifier = 0;
425 const char *address_space_id;
426
427 /* We don't print `const' qualifiers for references --- since all
428 operators affect the thing referenced, not the reference itself,
429 every reference is `const'. */
430 if (TYPE_CONST (type) && !TYPE_IS_REFERENCE (type))
431 {
432 if (need_pre_space)
433 fprintf_filtered (stream, " ");
434 fprintf_filtered (stream, "const");
435 did_print_modifier = 1;
436 }
437
438 if (TYPE_VOLATILE (type))
439 {
440 if (did_print_modifier || need_pre_space)
441 fprintf_filtered (stream, " ");
442 fprintf_filtered (stream, "volatile");
443 did_print_modifier = 1;
444 }
445
446 if (TYPE_RESTRICT (type))
447 {
448 if (did_print_modifier || need_pre_space)
449 fprintf_filtered (stream, " ");
450 fprintf_filtered (stream, "restrict");
451 did_print_modifier = 1;
452 }
453
454 if (TYPE_ATOMIC (type))
455 {
456 if (did_print_modifier || need_pre_space)
457 fprintf_filtered (stream, " ");
458 fprintf_filtered (stream, "_Atomic");
459 did_print_modifier = 1;
460 }
461
462 address_space_id = address_space_int_to_name (get_type_arch (type),
463 TYPE_INSTANCE_FLAGS (type));
464 if (address_space_id)
465 {
466 if (did_print_modifier || need_pre_space)
467 fprintf_filtered (stream, " ");
468 fprintf_filtered (stream, "@%s", address_space_id);
469 did_print_modifier = 1;
470 }
471
472 if (did_print_modifier && need_post_space)
473 fprintf_filtered (stream, " ");
474 }
475
476
477 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
478 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
479 in non-static methods, are displayed if LINKAGE_NAME is zero. If
480 LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
481 parameter types get removed their possible const and volatile qualifiers to
482 match demangled linkage name parameters part of such function type.
483 LANGUAGE is the language in which TYPE was defined. This is a necessary
484 evil since this code is used by the C and C++. */
485
486 void
487 c_type_print_args (struct type *type, struct ui_file *stream,
488 int linkage_name, enum language language,
489 const struct type_print_options *flags)
490 {
491 int i;
492 int printed_any = 0;
493
494 fprintf_filtered (stream, "(");
495
496 for (i = 0; i < TYPE_NFIELDS (type); i++)
497 {
498 struct type *param_type;
499
500 if (TYPE_FIELD_ARTIFICIAL (type, i) && linkage_name)
501 continue;
502
503 if (printed_any)
504 {
505 fprintf_filtered (stream, ", ");
506 wrap_here (" ");
507 }
508
509 param_type = TYPE_FIELD_TYPE (type, i);
510
511 if (language == language_cplus && linkage_name)
512 {
513 /* C++ standard, 13.1 Overloadable declarations, point 3, item:
514 - Parameter declarations that differ only in the presence or
515 absence of const and/or volatile are equivalent.
516
517 And the const/volatile qualifiers are not present in the mangled
518 names as produced by GCC. */
519
520 param_type = make_cv_type (0, 0, param_type, NULL);
521 }
522
523 c_print_type (param_type, "", stream, -1, 0, flags);
524 printed_any = 1;
525 }
526
527 if (printed_any && TYPE_VARARGS (type))
528 {
529 /* Print out a trailing ellipsis for varargs functions. Ignore
530 TYPE_VARARGS if the function has no named arguments; that
531 represents unprototyped (K&R style) C functions. */
532 if (printed_any && TYPE_VARARGS (type))
533 {
534 fprintf_filtered (stream, ", ");
535 wrap_here (" ");
536 fprintf_filtered (stream, "...");
537 }
538 }
539 else if (!printed_any
540 && (TYPE_PROTOTYPED (type) || language == language_cplus))
541 fprintf_filtered (stream, "void");
542
543 fprintf_filtered (stream, ")");
544 }
545
546 /* Return true iff the j'th overloading of the i'th method of TYPE
547 is a type conversion operator, like `operator int () { ... }'.
548 When listing a class's methods, we don't print the return type of
549 such operators. */
550
551 static int
552 is_type_conversion_operator (struct type *type, int i, int j)
553 {
554 /* I think the whole idea of recognizing type conversion operators
555 by their name is pretty terrible. But I don't think our present
556 data structure gives us any other way to tell. If you know of
557 some other way, feel free to rewrite this function. */
558 const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
559
560 if (!startswith (name, CP_OPERATOR_STR))
561 return 0;
562
563 name += 8;
564 if (! strchr (" \t\f\n\r", *name))
565 return 0;
566
567 while (strchr (" \t\f\n\r", *name))
568 name++;
569
570 if (!('a' <= *name && *name <= 'z')
571 && !('A' <= *name && *name <= 'Z')
572 && *name != '_')
573 /* If this doesn't look like the start of an identifier, then it
574 isn't a type conversion operator. */
575 return 0;
576 else if (startswith (name, "new"))
577 name += 3;
578 else if (startswith (name, "delete"))
579 name += 6;
580 else
581 /* If it doesn't look like new or delete, it's a type conversion
582 operator. */
583 return 1;
584
585 /* Is that really the end of the name? */
586 if (('a' <= *name && *name <= 'z')
587 || ('A' <= *name && *name <= 'Z')
588 || ('0' <= *name && *name <= '9')
589 || *name == '_')
590 /* No, so the identifier following "operator" must be a type name,
591 and this is a type conversion operator. */
592 return 1;
593
594 /* That was indeed the end of the name, so it was `operator new' or
595 `operator delete', neither of which are type conversion
596 operators. */
597 return 0;
598 }
599
600 /* Given a C++ qualified identifier QID, strip off the qualifiers,
601 yielding the unqualified name. The return value is a pointer into
602 the original string.
603
604 It's a pity we don't have this information in some more structured
605 form. Even the author of this function feels that writing little
606 parsers like this everywhere is stupid. */
607
608 static char *
609 remove_qualifiers (char *qid)
610 {
611 int quoted = 0; /* Zero if we're not in quotes;
612 '"' if we're in a double-quoted string;
613 '\'' if we're in a single-quoted string. */
614 int depth = 0; /* Number of unclosed parens we've seen. */
615 char *parenstack = (char *) alloca (strlen (qid));
616 char *scan;
617 char *last = 0; /* The character after the rightmost
618 `::' token we've seen so far. */
619
620 for (scan = qid; *scan; scan++)
621 {
622 if (quoted)
623 {
624 if (*scan == quoted)
625 quoted = 0;
626 else if (*scan == '\\' && *(scan + 1))
627 scan++;
628 }
629 else if (scan[0] == ':' && scan[1] == ':')
630 {
631 /* If we're inside parenthesis (i.e., an argument list) or
632 angle brackets (i.e., a list of template arguments), then
633 we don't record the position of this :: token, since it's
634 not relevant to the top-level structure we're trying to
635 operate on. */
636 if (depth == 0)
637 {
638 last = scan + 2;
639 scan++;
640 }
641 }
642 else if (*scan == '"' || *scan == '\'')
643 quoted = *scan;
644 else if (*scan == '(')
645 parenstack[depth++] = ')';
646 else if (*scan == '[')
647 parenstack[depth++] = ']';
648 /* We're going to treat <> as a pair of matching characters,
649 since we're more likely to see those in template id's than
650 real less-than characters. What a crock. */
651 else if (*scan == '<')
652 parenstack[depth++] = '>';
653 else if (*scan == ')' || *scan == ']' || *scan == '>')
654 {
655 if (depth > 0 && parenstack[depth - 1] == *scan)
656 depth--;
657 else
658 {
659 /* We're going to do a little error recovery here. If
660 we don't find a match for *scan on the paren stack,
661 but there is something lower on the stack that does
662 match, we pop the stack to that point. */
663 int i;
664
665 for (i = depth - 1; i >= 0; i--)
666 if (parenstack[i] == *scan)
667 {
668 depth = i;
669 break;
670 }
671 }
672 }
673 }
674
675 if (last)
676 return last;
677 else
678 /* We didn't find any :: tokens at the top level, so declare the
679 whole thing an unqualified identifier. */
680 return qid;
681 }
682
683 /* Print any array sizes, function arguments or close parentheses
684 needed after the variable name (to describe its type).
685 Args work like c_type_print_varspec_prefix. */
686
687 void
688 c_type_print_varspec_suffix (struct type *type,
689 struct ui_file *stream,
690 int show, int passed_a_ptr,
691 int demangled_args,
692 const struct type_print_options *flags)
693 {
694 if (type == 0)
695 return;
696
697 if (TYPE_NAME (type) && show <= 0)
698 return;
699
700 QUIT;
701
702 switch (TYPE_CODE (type))
703 {
704 case TYPE_CODE_ARRAY:
705 {
706 LONGEST low_bound, high_bound;
707 int is_vector = TYPE_VECTOR (type);
708
709 if (passed_a_ptr)
710 fprintf_filtered (stream, ")");
711
712 fprintf_filtered (stream, (is_vector ?
713 " __attribute__ ((vector_size(" : "["));
714 /* Bounds are not yet resolved, print a bounds placeholder instead. */
715 if (TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCEXPR
716 || TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCLIST)
717 fprintf_filtered (stream, "variable length");
718 else if (get_array_bounds (type, &low_bound, &high_bound))
719 fprintf_filtered (stream, "%s",
720 plongest (high_bound - low_bound + 1));
721 fprintf_filtered (stream, (is_vector ? ")))" : "]"));
722
723 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
724 show, 0, 0, flags);
725 }
726 break;
727
728 case TYPE_CODE_MEMBERPTR:
729 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
730 show, 0, 0, flags);
731 break;
732
733 case TYPE_CODE_METHODPTR:
734 fprintf_filtered (stream, ")");
735 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
736 show, 0, 0, flags);
737 break;
738
739 case TYPE_CODE_PTR:
740 case TYPE_CODE_REF:
741 case TYPE_CODE_RVALUE_REF:
742 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
743 show, 1, 0, flags);
744 break;
745
746 case TYPE_CODE_METHOD:
747 case TYPE_CODE_FUNC:
748 if (passed_a_ptr)
749 fprintf_filtered (stream, ")");
750 if (!demangled_args)
751 c_type_print_args (type, stream, 0, current_language->la_language,
752 flags);
753 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
754 show, passed_a_ptr, 0, flags);
755 break;
756
757 case TYPE_CODE_TYPEDEF:
758 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
759 show, passed_a_ptr, 0, flags);
760 break;
761
762 case TYPE_CODE_UNDEF:
763 case TYPE_CODE_STRUCT:
764 case TYPE_CODE_UNION:
765 case TYPE_CODE_FLAGS:
766 case TYPE_CODE_ENUM:
767 case TYPE_CODE_INT:
768 case TYPE_CODE_FLT:
769 case TYPE_CODE_VOID:
770 case TYPE_CODE_ERROR:
771 case TYPE_CODE_CHAR:
772 case TYPE_CODE_BOOL:
773 case TYPE_CODE_SET:
774 case TYPE_CODE_RANGE:
775 case TYPE_CODE_STRING:
776 case TYPE_CODE_COMPLEX:
777 case TYPE_CODE_NAMESPACE:
778 case TYPE_CODE_DECFLOAT:
779 /* These types do not need a suffix. They are listed so that
780 gcc -Wall will report types that may not have been
781 considered. */
782 break;
783 default:
784 error (_("type not handled in c_type_print_varspec_suffix()"));
785 break;
786 }
787 }
788
789 /* A helper for c_type_print_base that displays template
790 parameters and their bindings, if needed.
791
792 TABLE is the local bindings table to use. If NULL, no printing is
793 done. Note that, at this point, TABLE won't have any useful
794 information in it -- but it is also used as a flag to
795 print_name_maybe_canonical to activate searching the global typedef
796 table.
797
798 TYPE is the type whose template arguments are being displayed.
799
800 STREAM is the stream on which to print. */
801
802 static void
803 c_type_print_template_args (const struct type_print_options *flags,
804 struct type *type, struct ui_file *stream)
805 {
806 int first = 1, i;
807
808 if (flags->raw)
809 return;
810
811 for (i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
812 {
813 struct symbol *sym = TYPE_TEMPLATE_ARGUMENT (type, i);
814
815 if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
816 continue;
817
818 if (first)
819 {
820 wrap_here (" ");
821 fprintf_filtered (stream, _("[with %s = "),
822 SYMBOL_LINKAGE_NAME (sym));
823 first = 0;
824 }
825 else
826 {
827 fputs_filtered (", ", stream);
828 wrap_here (" ");
829 fprintf_filtered (stream, "%s = ", SYMBOL_LINKAGE_NAME (sym));
830 }
831
832 c_print_type (SYMBOL_TYPE (sym), "", stream, -1, 0, flags);
833 }
834
835 if (!first)
836 fputs_filtered (_("] "), stream);
837 }
838
839 /* Output an access specifier to STREAM, if needed. LAST_ACCESS is the
840 last access specifier output (typically returned by this function). */
841
842 static enum access_specifier
843 output_access_specifier (struct ui_file *stream,
844 enum access_specifier last_access,
845 int level, bool is_protected, bool is_private)
846 {
847 if (is_protected)
848 {
849 if (last_access != s_protected)
850 {
851 last_access = s_protected;
852 fprintfi_filtered (level + 2, stream,
853 "protected:\n");
854 }
855 }
856 else if (is_private)
857 {
858 if (last_access != s_private)
859 {
860 last_access = s_private;
861 fprintfi_filtered (level + 2, stream,
862 "private:\n");
863 }
864 }
865 else
866 {
867 if (last_access != s_public)
868 {
869 last_access = s_public;
870 fprintfi_filtered (level + 2, stream,
871 "public:\n");
872 }
873 }
874
875 return last_access;
876 }
877
878 /* Print the name of the type (or the ultimate pointer target,
879 function value or array element), or the description of a structure
880 or union.
881
882 SHOW positive means print details about the type (e.g. enum
883 values), and print structure elements passing SHOW - 1 for show.
884
885 SHOW negative means just print the type name or struct tag if there
886 is one. If there is no name, print something sensible but concise
887 like "struct {...}".
888
889 SHOW zero means just print the type name or struct tag if there is
890 one. If there is no name, print something sensible but not as
891 concise like "struct {int x; int y;}".
892
893 LEVEL is the number of spaces to indent by.
894 We increase it for some recursive calls. */
895
896 void
897 c_type_print_base (struct type *type, struct ui_file *stream,
898 int show, int level, const struct type_print_options *flags)
899 {
900 int i;
901 int len, real_len;
902 enum access_specifier section_type;
903 int need_access_label = 0;
904 int j, len2;
905
906 QUIT;
907
908 if (type == NULL)
909 {
910 fputs_filtered (_("<type unknown>"), stream);
911 return;
912 }
913
914 /* When SHOW is zero or less, and there is a valid type name, then
915 always just print the type name directly from the type. */
916 /* If we have "typedef struct foo {. . .} bar;" do we want to print
917 it as "struct foo" or as "bar"? Pick the latter, because C++
918 folk tend to expect things like "class5 *foo" rather than "struct
919 class5 *foo". */
920
921 if (show <= 0
922 && TYPE_NAME (type) != NULL)
923 {
924 c_type_print_modifier (type, stream, 0, 1);
925 print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
926 return;
927 }
928
929 type = check_typedef (type);
930
931 switch (TYPE_CODE (type))
932 {
933 case TYPE_CODE_TYPEDEF:
934 /* If we get here, the typedef doesn't have a name, and we
935 couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
936 gdb_assert (TYPE_NAME (type) == NULL);
937 gdb_assert (TYPE_TARGET_TYPE (type) == NULL);
938 fprintf_filtered (stream, _("<unnamed typedef>"));
939 break;
940
941 case TYPE_CODE_FUNC:
942 case TYPE_CODE_METHOD:
943 if (TYPE_TARGET_TYPE (type) == NULL)
944 type_print_unknown_return_type (stream);
945 else
946 c_type_print_base (TYPE_TARGET_TYPE (type),
947 stream, show, level, flags);
948 break;
949 case TYPE_CODE_ARRAY:
950 case TYPE_CODE_PTR:
951 case TYPE_CODE_MEMBERPTR:
952 case TYPE_CODE_REF:
953 case TYPE_CODE_RVALUE_REF:
954 case TYPE_CODE_METHODPTR:
955 c_type_print_base (TYPE_TARGET_TYPE (type),
956 stream, show, level, flags);
957 break;
958
959 case TYPE_CODE_STRUCT:
960 case TYPE_CODE_UNION:
961 {
962 struct type_print_options local_flags = *flags;
963 struct type_print_options semi_local_flags = *flags;
964 struct cleanup *local_cleanups = make_cleanup (null_cleanup, NULL);
965
966 local_flags.local_typedefs = NULL;
967 semi_local_flags.local_typedefs = NULL;
968
969 if (!flags->raw)
970 {
971 if (flags->local_typedefs)
972 local_flags.local_typedefs
973 = copy_typedef_hash (flags->local_typedefs);
974 else
975 local_flags.local_typedefs = create_typedef_hash ();
976
977 make_cleanup_free_typedef_hash (local_flags.local_typedefs);
978 }
979
980 c_type_print_modifier (type, stream, 0, 1);
981 if (TYPE_CODE (type) == TYPE_CODE_UNION)
982 fprintf_filtered (stream, "union ");
983 else if (TYPE_DECLARED_CLASS (type))
984 fprintf_filtered (stream, "class ");
985 else
986 fprintf_filtered (stream, "struct ");
987
988 /* Print the tag if it exists. The HP aCC compiler emits a
989 spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
990 enum}" tag for unnamed struct/union/enum's, which we don't
991 want to print. */
992 if (TYPE_TAG_NAME (type) != NULL
993 && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
994 {
995 /* When printing the tag name, we are still effectively
996 printing in the outer context, hence the use of FLAGS
997 here. */
998 print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
999 if (show > 0)
1000 fputs_filtered (" ", stream);
1001 }
1002
1003 if (show < 0)
1004 {
1005 /* If we just printed a tag name, no need to print anything
1006 else. */
1007 if (TYPE_TAG_NAME (type) == NULL)
1008 fprintf_filtered (stream, "{...}");
1009 }
1010 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
1011 {
1012 struct type *basetype;
1013 int vptr_fieldno;
1014
1015 c_type_print_template_args (&local_flags, type, stream);
1016
1017 /* Add in template parameters when printing derivation info. */
1018 add_template_parameters (local_flags.local_typedefs, type);
1019 cp_type_print_derivation_info (stream, type, &local_flags);
1020
1021 /* This holds just the global typedefs and the template
1022 parameters. */
1023 semi_local_flags.local_typedefs
1024 = copy_typedef_hash (local_flags.local_typedefs);
1025 if (semi_local_flags.local_typedefs)
1026 make_cleanup_free_typedef_hash (semi_local_flags.local_typedefs);
1027
1028 /* Now add in the local typedefs. */
1029 recursively_update_typedef_hash (local_flags.local_typedefs, type);
1030
1031 fprintf_filtered (stream, "{\n");
1032 if (TYPE_NFIELDS (type) == 0 && TYPE_NFN_FIELDS (type) == 0
1033 && TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
1034 {
1035 if (TYPE_STUB (type))
1036 fprintfi_filtered (level + 4, stream,
1037 _("<incomplete type>\n"));
1038 else
1039 fprintfi_filtered (level + 4, stream,
1040 _("<no data fields>\n"));
1041 }
1042
1043 /* Start off with no specific section type, so we can print
1044 one for the first field we find, and use that section type
1045 thereafter until we find another type. */
1046
1047 section_type = s_none;
1048
1049 /* For a class, if all members are private, there's no need
1050 for a "private:" label; similarly, for a struct or union
1051 masquerading as a class, if all members are public, there's
1052 no need for a "public:" label. */
1053
1054 if (TYPE_DECLARED_CLASS (type))
1055 {
1056 QUIT;
1057 len = TYPE_NFIELDS (type);
1058 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1059 if (!TYPE_FIELD_PRIVATE (type, i))
1060 {
1061 need_access_label = 1;
1062 break;
1063 }
1064 QUIT;
1065 if (!need_access_label)
1066 {
1067 len2 = TYPE_NFN_FIELDS (type);
1068 for (j = 0; j < len2; j++)
1069 {
1070 len = TYPE_FN_FIELDLIST_LENGTH (type, j);
1071 for (i = 0; i < len; i++)
1072 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
1073 j), i))
1074 {
1075 need_access_label = 1;
1076 break;
1077 }
1078 if (need_access_label)
1079 break;
1080 }
1081 }
1082 QUIT;
1083 if (!need_access_label)
1084 {
1085 for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); ++i)
1086 {
1087 if (!TYPE_TYPEDEF_FIELD_PRIVATE (type, i))
1088 {
1089 need_access_label = 1;
1090 break;
1091 }
1092 }
1093 }
1094 }
1095 else
1096 {
1097 QUIT;
1098 len = TYPE_NFIELDS (type);
1099 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1100 if (TYPE_FIELD_PRIVATE (type, i)
1101 || TYPE_FIELD_PROTECTED (type, i))
1102 {
1103 need_access_label = 1;
1104 break;
1105 }
1106 QUIT;
1107 if (!need_access_label)
1108 {
1109 len2 = TYPE_NFN_FIELDS (type);
1110 for (j = 0; j < len2; j++)
1111 {
1112 QUIT;
1113 len = TYPE_FN_FIELDLIST_LENGTH (type, j);
1114 for (i = 0; i < len; i++)
1115 if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type,
1116 j), i)
1117 || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
1118 j),
1119 i))
1120 {
1121 need_access_label = 1;
1122 break;
1123 }
1124 if (need_access_label)
1125 break;
1126 }
1127 }
1128 QUIT;
1129 if (!need_access_label)
1130 {
1131 for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); ++i)
1132 {
1133 if (TYPE_TYPEDEF_FIELD_PROTECTED (type, i)
1134 || TYPE_TYPEDEF_FIELD_PRIVATE (type, i))
1135 {
1136 need_access_label = 1;
1137 break;
1138 }
1139 }
1140 }
1141 }
1142
1143 /* If there is a base class for this type,
1144 do not print the field that it occupies. */
1145
1146 len = TYPE_NFIELDS (type);
1147 vptr_fieldno = get_vptr_fieldno (type, &basetype);
1148 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1149 {
1150 QUIT;
1151
1152 /* If we have a virtual table pointer, omit it. Even if
1153 virtual table pointers are not specifically marked in
1154 the debug info, they should be artificial. */
1155 if ((i == vptr_fieldno && type == basetype)
1156 || TYPE_FIELD_ARTIFICIAL (type, i))
1157 continue;
1158
1159 if (need_access_label)
1160 {
1161 section_type = output_access_specifier
1162 (stream, section_type, level,
1163 TYPE_FIELD_PROTECTED (type, i),
1164 TYPE_FIELD_PRIVATE (type, i));
1165 }
1166
1167 print_spaces_filtered (level + 4, stream);
1168 if (field_is_static (&TYPE_FIELD (type, i)))
1169 fprintf_filtered (stream, "static ");
1170 c_print_type (TYPE_FIELD_TYPE (type, i),
1171 TYPE_FIELD_NAME (type, i),
1172 stream, show - 1, level + 4,
1173 &local_flags);
1174 if (!field_is_static (&TYPE_FIELD (type, i))
1175 && TYPE_FIELD_PACKED (type, i))
1176 {
1177 /* It is a bitfield. This code does not attempt
1178 to look at the bitpos and reconstruct filler,
1179 unnamed fields. This would lead to misleading
1180 results if the compiler does not put out fields
1181 for such things (I don't know what it does). */
1182 fprintf_filtered (stream, " : %d",
1183 TYPE_FIELD_BITSIZE (type, i));
1184 }
1185 fprintf_filtered (stream, ";\n");
1186 }
1187
1188 /* If there are both fields and methods, put a blank line
1189 between them. Make sure to count only method that we
1190 will display; artificial methods will be hidden. */
1191 len = TYPE_NFN_FIELDS (type);
1192 if (!flags->print_methods)
1193 len = 0;
1194 real_len = 0;
1195 for (i = 0; i < len; i++)
1196 {
1197 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1198 int len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1199 int j;
1200
1201 for (j = 0; j < len2; j++)
1202 if (!TYPE_FN_FIELD_ARTIFICIAL (f, j))
1203 real_len++;
1204 }
1205 if (real_len > 0 && section_type != s_none)
1206 fprintf_filtered (stream, "\n");
1207
1208 /* C++: print out the methods. */
1209 for (i = 0; i < len; i++)
1210 {
1211 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1212 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1213 const char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
1214 const char *name = type_name_no_tag (type);
1215 int is_constructor = name && strcmp (method_name,
1216 name) == 0;
1217
1218 for (j = 0; j < len2; j++)
1219 {
1220 const char *mangled_name;
1221 gdb::unique_xmalloc_ptr<char> mangled_name_holder;
1222 char *demangled_name;
1223 const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1224 int is_full_physname_constructor =
1225 TYPE_FN_FIELD_CONSTRUCTOR (f, j)
1226 || is_constructor_name (physname)
1227 || is_destructor_name (physname)
1228 || method_name[0] == '~';
1229
1230 /* Do not print out artificial methods. */
1231 if (TYPE_FN_FIELD_ARTIFICIAL (f, j))
1232 continue;
1233
1234 QUIT;
1235 section_type = output_access_specifier
1236 (stream, section_type, level,
1237 TYPE_FN_FIELD_PROTECTED (f, j),
1238 TYPE_FN_FIELD_PRIVATE (f, j));
1239
1240 print_spaces_filtered (level + 4, stream);
1241 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1242 fprintf_filtered (stream, "virtual ");
1243 else if (TYPE_FN_FIELD_STATIC_P (f, j))
1244 fprintf_filtered (stream, "static ");
1245 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1246 {
1247 /* Keep GDB from crashing here. */
1248 fprintf_filtered (stream,
1249 _("<undefined type> %s;\n"),
1250 TYPE_FN_FIELD_PHYSNAME (f, j));
1251 break;
1252 }
1253 else if (!is_constructor /* Constructors don't
1254 have declared
1255 types. */
1256 && !is_full_physname_constructor /* " " */
1257 && !is_type_conversion_operator (type, i, j))
1258 {
1259 c_print_type (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1260 "", stream, -1, 0,
1261 &local_flags);
1262 fputs_filtered (" ", stream);
1263 }
1264 if (TYPE_FN_FIELD_STUB (f, j))
1265 {
1266 /* Build something we can demangle. */
1267 mangled_name_holder.reset (gdb_mangle_name (type, i, j));
1268 mangled_name = mangled_name_holder.get ();
1269 }
1270 else
1271 mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
1272
1273 demangled_name =
1274 gdb_demangle (mangled_name,
1275 DMGL_ANSI | DMGL_PARAMS);
1276 if (demangled_name == NULL)
1277 {
1278 /* In some cases (for instance with the HP
1279 demangling), if a function has more than 10
1280 arguments, the demangling will fail.
1281 Let's try to reconstruct the function
1282 signature from the symbol information. */
1283 if (!TYPE_FN_FIELD_STUB (f, j))
1284 {
1285 int staticp = TYPE_FN_FIELD_STATIC_P (f, j);
1286 struct type *mtype = TYPE_FN_FIELD_TYPE (f, j);
1287
1288 cp_type_print_method_args (mtype,
1289 "",
1290 method_name,
1291 staticp,
1292 stream, &local_flags);
1293 }
1294 else
1295 fprintf_filtered (stream,
1296 _("<badly mangled name '%s'>"),
1297 mangled_name);
1298 }
1299 else
1300 {
1301 char *p;
1302 char *demangled_no_class
1303 = remove_qualifiers (demangled_name);
1304
1305 /* Get rid of the `static' appended by the
1306 demangler. */
1307 p = strstr (demangled_no_class, " static");
1308 if (p != NULL)
1309 {
1310 int length = p - demangled_no_class;
1311 char *demangled_no_static;
1312
1313 demangled_no_static
1314 = (char *) xmalloc (length + 1);
1315 strncpy (demangled_no_static,
1316 demangled_no_class, length);
1317 *(demangled_no_static + length) = '\0';
1318 fputs_filtered (demangled_no_static, stream);
1319 xfree (demangled_no_static);
1320 }
1321 else
1322 fputs_filtered (demangled_no_class, stream);
1323 xfree (demangled_name);
1324 }
1325
1326 fprintf_filtered (stream, ";\n");
1327 }
1328 }
1329
1330 /* Print typedefs defined in this class. */
1331
1332 if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0 && flags->print_typedefs)
1333 {
1334 if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0)
1335 fprintf_filtered (stream, "\n");
1336
1337 for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); i++)
1338 {
1339 struct type *target = TYPE_TYPEDEF_FIELD_TYPE (type, i);
1340
1341 /* Dereference the typedef declaration itself. */
1342 gdb_assert (TYPE_CODE (target) == TYPE_CODE_TYPEDEF);
1343 target = TYPE_TARGET_TYPE (target);
1344
1345 if (need_access_label)
1346 {
1347 section_type = output_access_specifier
1348 (stream, section_type, level,
1349 TYPE_TYPEDEF_FIELD_PROTECTED (type, i),
1350 TYPE_TYPEDEF_FIELD_PRIVATE (type, i));
1351 }
1352 print_spaces_filtered (level + 4, stream);
1353 fprintf_filtered (stream, "typedef ");
1354
1355 /* We want to print typedefs with substitutions
1356 from the template parameters or globally-known
1357 typedefs but not local typedefs. */
1358 c_print_type (target,
1359 TYPE_TYPEDEF_FIELD_NAME (type, i),
1360 stream, show - 1, level + 4,
1361 &semi_local_flags);
1362 fprintf_filtered (stream, ";\n");
1363 }
1364 }
1365
1366 fprintfi_filtered (level, stream, "}");
1367 }
1368
1369 do_cleanups (local_cleanups);
1370 }
1371 break;
1372
1373 case TYPE_CODE_ENUM:
1374 c_type_print_modifier (type, stream, 0, 1);
1375 fprintf_filtered (stream, "enum ");
1376 if (TYPE_DECLARED_CLASS (type))
1377 fprintf_filtered (stream, "class ");
1378 /* Print the tag name if it exists.
1379 The aCC compiler emits a spurious
1380 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1381 tag for unnamed struct/union/enum's, which we don't
1382 want to print. */
1383 if (TYPE_TAG_NAME (type) != NULL
1384 && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
1385 {
1386 print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
1387 if (show > 0)
1388 fputs_filtered (" ", stream);
1389 }
1390
1391 wrap_here (" ");
1392 if (show < 0)
1393 {
1394 /* If we just printed a tag name, no need to print anything
1395 else. */
1396 if (TYPE_TAG_NAME (type) == NULL)
1397 fprintf_filtered (stream, "{...}");
1398 }
1399 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
1400 {
1401 LONGEST lastval = 0;
1402
1403 /* We can't handle this case perfectly, as DWARF does not
1404 tell us whether or not the underlying type was specified
1405 in the source (and other debug formats don't provide this
1406 at all). We choose to print the underlying type, if it
1407 has a name, when in C++ on the theory that it's better to
1408 print too much than too little; but conversely not to
1409 print something egregiously outside the current
1410 language's syntax. */
1411 if (current_language->la_language == language_cplus
1412 && TYPE_TARGET_TYPE (type) != NULL)
1413 {
1414 struct type *underlying = check_typedef (TYPE_TARGET_TYPE (type));
1415
1416 if (TYPE_NAME (underlying) != NULL)
1417 fprintf_filtered (stream, ": %s ", TYPE_NAME (underlying));
1418 }
1419
1420 fprintf_filtered (stream, "{");
1421 len = TYPE_NFIELDS (type);
1422 for (i = 0; i < len; i++)
1423 {
1424 QUIT;
1425 if (i)
1426 fprintf_filtered (stream, ", ");
1427 wrap_here (" ");
1428 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1429 if (lastval != TYPE_FIELD_ENUMVAL (type, i))
1430 {
1431 fprintf_filtered (stream, " = %s",
1432 plongest (TYPE_FIELD_ENUMVAL (type, i)));
1433 lastval = TYPE_FIELD_ENUMVAL (type, i);
1434 }
1435 lastval++;
1436 }
1437 fprintf_filtered (stream, "}");
1438 }
1439 break;
1440
1441 case TYPE_CODE_FLAGS:
1442 {
1443 struct type_print_options local_flags = *flags;
1444
1445 local_flags.local_typedefs = NULL;
1446
1447 c_type_print_modifier (type, stream, 0, 1);
1448 fprintf_filtered (stream, "flag ");
1449 print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
1450 if (show > 0)
1451 {
1452 fputs_filtered (" ", stream);
1453 fprintf_filtered (stream, "{\n");
1454 if (TYPE_NFIELDS (type) == 0)
1455 {
1456 if (TYPE_STUB (type))
1457 fprintfi_filtered (level + 4, stream,
1458 _("<incomplete type>\n"));
1459 else
1460 fprintfi_filtered (level + 4, stream,
1461 _("<no data fields>\n"));
1462 }
1463 len = TYPE_NFIELDS (type);
1464 for (i = 0; i < len; i++)
1465 {
1466 QUIT;
1467 print_spaces_filtered (level + 4, stream);
1468 /* We pass "show" here and not "show - 1" to get enum types
1469 printed. There's no other way to see them. */
1470 c_print_type (TYPE_FIELD_TYPE (type, i),
1471 TYPE_FIELD_NAME (type, i),
1472 stream, show, level + 4,
1473 &local_flags);
1474 fprintf_filtered (stream, " @%s",
1475 plongest (TYPE_FIELD_BITPOS (type, i)));
1476 if (TYPE_FIELD_BITSIZE (type, i) > 1)
1477 {
1478 fprintf_filtered (stream, "-%s",
1479 plongest (TYPE_FIELD_BITPOS (type, i)
1480 + TYPE_FIELD_BITSIZE (type, i)
1481 - 1));
1482 }
1483 fprintf_filtered (stream, ";\n");
1484 }
1485 fprintfi_filtered (level, stream, "}");
1486 }
1487 }
1488 break;
1489
1490 case TYPE_CODE_VOID:
1491 fprintf_filtered (stream, "void");
1492 break;
1493
1494 case TYPE_CODE_UNDEF:
1495 fprintf_filtered (stream, _("struct <unknown>"));
1496 break;
1497
1498 case TYPE_CODE_ERROR:
1499 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
1500 break;
1501
1502 case TYPE_CODE_RANGE:
1503 /* This should not occur. */
1504 fprintf_filtered (stream, _("<range type>"));
1505 break;
1506
1507 case TYPE_CODE_NAMESPACE:
1508 fputs_filtered ("namespace ", stream);
1509 fputs_filtered (TYPE_TAG_NAME (type), stream);
1510 break;
1511
1512 default:
1513 /* Handle types not explicitly handled by the other cases, such
1514 as fundamental types. For these, just print whatever the
1515 type name is, as recorded in the type itself. If there is no
1516 type name, then complain. */
1517 if (TYPE_NAME (type) != NULL)
1518 {
1519 c_type_print_modifier (type, stream, 0, 1);
1520 print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
1521 }
1522 else
1523 {
1524 /* At least for dump_symtab, it is important that this not
1525 be an error (). */
1526 fprintf_filtered (stream, _("<invalid type code %d>"),
1527 TYPE_CODE (type));
1528 }
1529 break;
1530 }
1531 }
This page took 0.059922 seconds and 5 git commands to generate.