Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on '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 /* Return true is an access label (i.e., "public:", "private:",
879 "protected:") needs to be printed for TYPE. */
880
881 static bool
882 need_access_label_p (struct type *type)
883 {
884 if (TYPE_DECLARED_CLASS (type))
885 {
886 QUIT;
887 for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
888 if (!TYPE_FIELD_PRIVATE (type, i))
889 return true;
890 QUIT;
891 for (int j = 0; j < TYPE_NFN_FIELDS (type); j++)
892 for (int i = 0; i < TYPE_FN_FIELDLIST_LENGTH (type, j); i++)
893 if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
894 j), i))
895 return true;
896 QUIT;
897 for (int i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); ++i)
898 if (!TYPE_TYPEDEF_FIELD_PRIVATE (type, i))
899 return true;
900 }
901 else
902 {
903 QUIT;
904 for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
905 if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i))
906 return true;
907 QUIT;
908 for (int j = 0; j < TYPE_NFN_FIELDS (type); j++)
909 {
910 QUIT;
911 for (int i = 0; i < TYPE_FN_FIELDLIST_LENGTH (type, j); i++)
912 if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type,
913 j), i)
914 || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
915 j),
916 i))
917 return true;
918 }
919 QUIT;
920 for (int i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); ++i)
921 if (TYPE_TYPEDEF_FIELD_PROTECTED (type, i)
922 || TYPE_TYPEDEF_FIELD_PRIVATE (type, i))
923 return true;
924 }
925
926 return false;
927 }
928
929 /* Helper for 'c_type_print_base' that handles structs and unions.
930 For a description of the arguments, see 'c_type_print_base'. */
931
932 static void
933 c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
934 int show, int level,
935 const struct type_print_options *flags)
936 {
937 struct type_print_options local_flags = *flags;
938 struct type_print_options semi_local_flags = *flags;
939 struct cleanup *local_cleanups = make_cleanup (null_cleanup, NULL);
940
941 local_flags.local_typedefs = NULL;
942 semi_local_flags.local_typedefs = NULL;
943
944 if (!flags->raw)
945 {
946 if (flags->local_typedefs)
947 local_flags.local_typedefs
948 = copy_typedef_hash (flags->local_typedefs);
949 else
950 local_flags.local_typedefs = create_typedef_hash ();
951
952 make_cleanup_free_typedef_hash (local_flags.local_typedefs);
953 }
954
955 c_type_print_modifier (type, stream, 0, 1);
956 if (TYPE_CODE (type) == TYPE_CODE_UNION)
957 fprintf_filtered (stream, "union ");
958 else if (TYPE_DECLARED_CLASS (type))
959 fprintf_filtered (stream, "class ");
960 else
961 fprintf_filtered (stream, "struct ");
962
963 /* Print the tag if it exists. The HP aCC compiler emits a
964 spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
965 enum}" tag for unnamed struct/union/enum's, which we don't
966 want to print. */
967 if (TYPE_TAG_NAME (type) != NULL
968 && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
969 {
970 /* When printing the tag name, we are still effectively
971 printing in the outer context, hence the use of FLAGS
972 here. */
973 print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
974 if (show > 0)
975 fputs_filtered (" ", stream);
976 }
977
978 if (show < 0)
979 {
980 /* If we just printed a tag name, no need to print anything
981 else. */
982 if (TYPE_TAG_NAME (type) == NULL)
983 fprintf_filtered (stream, "{...}");
984 }
985 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
986 {
987 struct type *basetype;
988 int vptr_fieldno;
989
990 c_type_print_template_args (&local_flags, type, stream);
991
992 /* Add in template parameters when printing derivation info. */
993 add_template_parameters (local_flags.local_typedefs, type);
994 cp_type_print_derivation_info (stream, type, &local_flags);
995
996 /* This holds just the global typedefs and the template
997 parameters. */
998 semi_local_flags.local_typedefs
999 = copy_typedef_hash (local_flags.local_typedefs);
1000 if (semi_local_flags.local_typedefs)
1001 make_cleanup_free_typedef_hash (semi_local_flags.local_typedefs);
1002
1003 /* Now add in the local typedefs. */
1004 recursively_update_typedef_hash (local_flags.local_typedefs, type);
1005
1006 fprintf_filtered (stream, "{\n");
1007 if (TYPE_NFIELDS (type) == 0 && TYPE_NFN_FIELDS (type) == 0
1008 && TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
1009 {
1010 if (TYPE_STUB (type))
1011 fprintfi_filtered (level + 4, stream,
1012 _("<incomplete type>\n"));
1013 else
1014 fprintfi_filtered (level + 4, stream,
1015 _("<no data fields>\n"));
1016 }
1017
1018 /* Start off with no specific section type, so we can print
1019 one for the first field we find, and use that section type
1020 thereafter until we find another type. */
1021
1022 enum access_specifier section_type = s_none;
1023
1024 /* For a class, if all members are private, there's no need
1025 for a "private:" label; similarly, for a struct or union
1026 masquerading as a class, if all members are public, there's
1027 no need for a "public:" label. */
1028 bool need_access_label = need_access_label_p (type);
1029
1030 /* If there is a base class for this type,
1031 do not print the field that it occupies. */
1032
1033 int len = TYPE_NFIELDS (type);
1034 vptr_fieldno = get_vptr_fieldno (type, &basetype);
1035 for (int i = TYPE_N_BASECLASSES (type); i < len; i++)
1036 {
1037 QUIT;
1038
1039 /* If we have a virtual table pointer, omit it. Even if
1040 virtual table pointers are not specifically marked in
1041 the debug info, they should be artificial. */
1042 if ((i == vptr_fieldno && type == basetype)
1043 || TYPE_FIELD_ARTIFICIAL (type, i))
1044 continue;
1045
1046 if (need_access_label)
1047 {
1048 section_type = output_access_specifier
1049 (stream, section_type, level,
1050 TYPE_FIELD_PROTECTED (type, i),
1051 TYPE_FIELD_PRIVATE (type, i));
1052 }
1053
1054 print_spaces_filtered (level + 4, stream);
1055 if (field_is_static (&TYPE_FIELD (type, i)))
1056 fprintf_filtered (stream, "static ");
1057 c_print_type (TYPE_FIELD_TYPE (type, i),
1058 TYPE_FIELD_NAME (type, i),
1059 stream, show - 1, level + 4,
1060 &local_flags);
1061 if (!field_is_static (&TYPE_FIELD (type, i))
1062 && TYPE_FIELD_PACKED (type, i))
1063 {
1064 /* It is a bitfield. This code does not attempt
1065 to look at the bitpos and reconstruct filler,
1066 unnamed fields. This would lead to misleading
1067 results if the compiler does not put out fields
1068 for such things (I don't know what it does). */
1069 fprintf_filtered (stream, " : %d",
1070 TYPE_FIELD_BITSIZE (type, i));
1071 }
1072 fprintf_filtered (stream, ";\n");
1073 }
1074
1075 /* If there are both fields and methods, put a blank line
1076 between them. Make sure to count only method that we
1077 will display; artificial methods will be hidden. */
1078 len = TYPE_NFN_FIELDS (type);
1079 if (!flags->print_methods)
1080 len = 0;
1081 int real_len = 0;
1082 for (int i = 0; i < len; i++)
1083 {
1084 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1085 int len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1086 int j;
1087
1088 for (j = 0; j < len2; j++)
1089 if (!TYPE_FN_FIELD_ARTIFICIAL (f, j))
1090 real_len++;
1091 }
1092 if (real_len > 0 && section_type != s_none)
1093 fprintf_filtered (stream, "\n");
1094
1095 /* C++: print out the methods. */
1096 for (int i = 0; i < len; i++)
1097 {
1098 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1099 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1100 const char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
1101 const char *name = type_name_no_tag (type);
1102 int is_constructor = name && strcmp (method_name,
1103 name) == 0;
1104
1105 for (j = 0; j < len2; j++)
1106 {
1107 const char *mangled_name;
1108 gdb::unique_xmalloc_ptr<char> mangled_name_holder;
1109 char *demangled_name;
1110 const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1111 int is_full_physname_constructor =
1112 TYPE_FN_FIELD_CONSTRUCTOR (f, j)
1113 || is_constructor_name (physname)
1114 || is_destructor_name (physname)
1115 || method_name[0] == '~';
1116
1117 /* Do not print out artificial methods. */
1118 if (TYPE_FN_FIELD_ARTIFICIAL (f, j))
1119 continue;
1120
1121 QUIT;
1122 section_type = output_access_specifier
1123 (stream, section_type, level,
1124 TYPE_FN_FIELD_PROTECTED (f, j),
1125 TYPE_FN_FIELD_PRIVATE (f, j));
1126
1127 print_spaces_filtered (level + 4, stream);
1128 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1129 fprintf_filtered (stream, "virtual ");
1130 else if (TYPE_FN_FIELD_STATIC_P (f, j))
1131 fprintf_filtered (stream, "static ");
1132 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1133 {
1134 /* Keep GDB from crashing here. */
1135 fprintf_filtered (stream,
1136 _("<undefined type> %s;\n"),
1137 TYPE_FN_FIELD_PHYSNAME (f, j));
1138 break;
1139 }
1140 else if (!is_constructor /* Constructors don't
1141 have declared
1142 types. */
1143 && !is_full_physname_constructor /* " " */
1144 && !is_type_conversion_operator (type, i, j))
1145 {
1146 c_print_type (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1147 "", stream, -1, 0,
1148 &local_flags);
1149 fputs_filtered (" ", stream);
1150 }
1151 if (TYPE_FN_FIELD_STUB (f, j))
1152 {
1153 /* Build something we can demangle. */
1154 mangled_name_holder.reset (gdb_mangle_name (type, i, j));
1155 mangled_name = mangled_name_holder.get ();
1156 }
1157 else
1158 mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
1159
1160 demangled_name =
1161 gdb_demangle (mangled_name,
1162 DMGL_ANSI | DMGL_PARAMS);
1163 if (demangled_name == NULL)
1164 {
1165 /* In some cases (for instance with the HP
1166 demangling), if a function has more than 10
1167 arguments, the demangling will fail.
1168 Let's try to reconstruct the function
1169 signature from the symbol information. */
1170 if (!TYPE_FN_FIELD_STUB (f, j))
1171 {
1172 int staticp = TYPE_FN_FIELD_STATIC_P (f, j);
1173 struct type *mtype = TYPE_FN_FIELD_TYPE (f, j);
1174
1175 cp_type_print_method_args (mtype,
1176 "",
1177 method_name,
1178 staticp,
1179 stream, &local_flags);
1180 }
1181 else
1182 fprintf_filtered (stream,
1183 _("<badly mangled name '%s'>"),
1184 mangled_name);
1185 }
1186 else
1187 {
1188 char *p;
1189 char *demangled_no_class
1190 = remove_qualifiers (demangled_name);
1191
1192 /* Get rid of the `static' appended by the
1193 demangler. */
1194 p = strstr (demangled_no_class, " static");
1195 if (p != NULL)
1196 {
1197 int length = p - demangled_no_class;
1198 char *demangled_no_static;
1199
1200 demangled_no_static
1201 = (char *) xmalloc (length + 1);
1202 strncpy (demangled_no_static,
1203 demangled_no_class, length);
1204 *(demangled_no_static + length) = '\0';
1205 fputs_filtered (demangled_no_static, stream);
1206 xfree (demangled_no_static);
1207 }
1208 else
1209 fputs_filtered (demangled_no_class, stream);
1210 xfree (demangled_name);
1211 }
1212
1213 fprintf_filtered (stream, ";\n");
1214 }
1215 }
1216
1217 /* Print out nested types. */
1218 if (TYPE_NESTED_TYPES_COUNT (type) != 0
1219 && semi_local_flags.print_nested_type_limit != 0)
1220 {
1221 if (semi_local_flags.print_nested_type_limit > 0)
1222 --semi_local_flags.print_nested_type_limit;
1223
1224 if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0)
1225 fprintf_filtered (stream, "\n");
1226
1227 for (int i = 0; i < TYPE_NESTED_TYPES_COUNT (type); ++i)
1228 {
1229 print_spaces_filtered (level + 4, stream);
1230 c_print_type (TYPE_NESTED_TYPES_FIELD_TYPE (type, i),
1231 "", stream, show, level + 4, &semi_local_flags);
1232 fprintf_filtered (stream, ";\n");
1233 }
1234 }
1235
1236 /* Print typedefs defined in this class. */
1237
1238 if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0 && flags->print_typedefs)
1239 {
1240 if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0
1241 || TYPE_NESTED_TYPES_COUNT (type) != 0)
1242 fprintf_filtered (stream, "\n");
1243
1244 for (int i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); i++)
1245 {
1246 struct type *target = TYPE_TYPEDEF_FIELD_TYPE (type, i);
1247
1248 /* Dereference the typedef declaration itself. */
1249 gdb_assert (TYPE_CODE (target) == TYPE_CODE_TYPEDEF);
1250 target = TYPE_TARGET_TYPE (target);
1251
1252 if (need_access_label)
1253 {
1254 section_type = output_access_specifier
1255 (stream, section_type, level,
1256 TYPE_TYPEDEF_FIELD_PROTECTED (type, i),
1257 TYPE_TYPEDEF_FIELD_PRIVATE (type, i));
1258 }
1259 print_spaces_filtered (level + 4, stream);
1260 fprintf_filtered (stream, "typedef ");
1261
1262 /* We want to print typedefs with substitutions
1263 from the template parameters or globally-known
1264 typedefs but not local typedefs. */
1265 c_print_type (target,
1266 TYPE_TYPEDEF_FIELD_NAME (type, i),
1267 stream, show - 1, level + 4,
1268 &semi_local_flags);
1269 fprintf_filtered (stream, ";\n");
1270 }
1271 }
1272
1273 fprintfi_filtered (level, stream, "}");
1274 }
1275
1276 do_cleanups (local_cleanups);
1277 }
1278
1279 /* Print the name of the type (or the ultimate pointer target,
1280 function value or array element), or the description of a structure
1281 or union.
1282
1283 SHOW positive means print details about the type (e.g. enum
1284 values), and print structure elements passing SHOW - 1 for show.
1285
1286 SHOW negative means just print the type name or struct tag if there
1287 is one. If there is no name, print something sensible but concise
1288 like "struct {...}".
1289
1290 SHOW zero means just print the type name or struct tag if there is
1291 one. If there is no name, print something sensible but not as
1292 concise like "struct {int x; int y;}".
1293
1294 LEVEL is the number of spaces to indent by.
1295 We increase it for some recursive calls. */
1296
1297 void
1298 c_type_print_base (struct type *type, struct ui_file *stream,
1299 int show, int level, const struct type_print_options *flags)
1300 {
1301 int i;
1302 int len;
1303
1304 QUIT;
1305
1306 if (type == NULL)
1307 {
1308 fputs_filtered (_("<type unknown>"), stream);
1309 return;
1310 }
1311
1312 /* When SHOW is zero or less, and there is a valid type name, then
1313 always just print the type name directly from the type. */
1314 /* If we have "typedef struct foo {. . .} bar;" do we want to print
1315 it as "struct foo" or as "bar"? Pick the latter, because C++
1316 folk tend to expect things like "class5 *foo" rather than "struct
1317 class5 *foo". */
1318
1319 if (show <= 0
1320 && TYPE_NAME (type) != NULL)
1321 {
1322 c_type_print_modifier (type, stream, 0, 1);
1323 print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
1324 return;
1325 }
1326
1327 type = check_typedef (type);
1328
1329 switch (TYPE_CODE (type))
1330 {
1331 case TYPE_CODE_TYPEDEF:
1332 /* If we get here, the typedef doesn't have a name, and we
1333 couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
1334 gdb_assert (TYPE_NAME (type) == NULL);
1335 gdb_assert (TYPE_TARGET_TYPE (type) == NULL);
1336 fprintf_filtered (stream, _("<unnamed typedef>"));
1337 break;
1338
1339 case TYPE_CODE_FUNC:
1340 case TYPE_CODE_METHOD:
1341 if (TYPE_TARGET_TYPE (type) == NULL)
1342 type_print_unknown_return_type (stream);
1343 else
1344 c_type_print_base (TYPE_TARGET_TYPE (type),
1345 stream, show, level, flags);
1346 break;
1347 case TYPE_CODE_ARRAY:
1348 case TYPE_CODE_PTR:
1349 case TYPE_CODE_MEMBERPTR:
1350 case TYPE_CODE_REF:
1351 case TYPE_CODE_RVALUE_REF:
1352 case TYPE_CODE_METHODPTR:
1353 c_type_print_base (TYPE_TARGET_TYPE (type),
1354 stream, show, level, flags);
1355 break;
1356
1357 case TYPE_CODE_STRUCT:
1358 case TYPE_CODE_UNION:
1359 c_type_print_base_struct_union (type, stream, show, level, flags);
1360 break;
1361
1362 case TYPE_CODE_ENUM:
1363 c_type_print_modifier (type, stream, 0, 1);
1364 fprintf_filtered (stream, "enum ");
1365 if (TYPE_DECLARED_CLASS (type))
1366 fprintf_filtered (stream, "class ");
1367 /* Print the tag name if it exists.
1368 The aCC compiler emits a spurious
1369 "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
1370 tag for unnamed struct/union/enum's, which we don't
1371 want to print. */
1372 if (TYPE_TAG_NAME (type) != NULL
1373 && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
1374 {
1375 print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
1376 if (show > 0)
1377 fputs_filtered (" ", stream);
1378 }
1379
1380 wrap_here (" ");
1381 if (show < 0)
1382 {
1383 /* If we just printed a tag name, no need to print anything
1384 else. */
1385 if (TYPE_TAG_NAME (type) == NULL)
1386 fprintf_filtered (stream, "{...}");
1387 }
1388 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
1389 {
1390 LONGEST lastval = 0;
1391
1392 /* We can't handle this case perfectly, as DWARF does not
1393 tell us whether or not the underlying type was specified
1394 in the source (and other debug formats don't provide this
1395 at all). We choose to print the underlying type, if it
1396 has a name, when in C++ on the theory that it's better to
1397 print too much than too little; but conversely not to
1398 print something egregiously outside the current
1399 language's syntax. */
1400 if (current_language->la_language == language_cplus
1401 && TYPE_TARGET_TYPE (type) != NULL)
1402 {
1403 struct type *underlying = check_typedef (TYPE_TARGET_TYPE (type));
1404
1405 if (TYPE_NAME (underlying) != NULL)
1406 fprintf_filtered (stream, ": %s ", TYPE_NAME (underlying));
1407 }
1408
1409 fprintf_filtered (stream, "{");
1410 len = TYPE_NFIELDS (type);
1411 for (i = 0; i < len; i++)
1412 {
1413 QUIT;
1414 if (i)
1415 fprintf_filtered (stream, ", ");
1416 wrap_here (" ");
1417 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1418 if (lastval != TYPE_FIELD_ENUMVAL (type, i))
1419 {
1420 fprintf_filtered (stream, " = %s",
1421 plongest (TYPE_FIELD_ENUMVAL (type, i)));
1422 lastval = TYPE_FIELD_ENUMVAL (type, i);
1423 }
1424 lastval++;
1425 }
1426 fprintf_filtered (stream, "}");
1427 }
1428 break;
1429
1430 case TYPE_CODE_FLAGS:
1431 {
1432 struct type_print_options local_flags = *flags;
1433
1434 local_flags.local_typedefs = NULL;
1435
1436 c_type_print_modifier (type, stream, 0, 1);
1437 fprintf_filtered (stream, "flag ");
1438 print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
1439 if (show > 0)
1440 {
1441 fputs_filtered (" ", stream);
1442 fprintf_filtered (stream, "{\n");
1443 if (TYPE_NFIELDS (type) == 0)
1444 {
1445 if (TYPE_STUB (type))
1446 fprintfi_filtered (level + 4, stream,
1447 _("<incomplete type>\n"));
1448 else
1449 fprintfi_filtered (level + 4, stream,
1450 _("<no data fields>\n"));
1451 }
1452 len = TYPE_NFIELDS (type);
1453 for (i = 0; i < len; i++)
1454 {
1455 QUIT;
1456 print_spaces_filtered (level + 4, stream);
1457 /* We pass "show" here and not "show - 1" to get enum types
1458 printed. There's no other way to see them. */
1459 c_print_type (TYPE_FIELD_TYPE (type, i),
1460 TYPE_FIELD_NAME (type, i),
1461 stream, show, level + 4,
1462 &local_flags);
1463 fprintf_filtered (stream, " @%s",
1464 plongest (TYPE_FIELD_BITPOS (type, i)));
1465 if (TYPE_FIELD_BITSIZE (type, i) > 1)
1466 {
1467 fprintf_filtered (stream, "-%s",
1468 plongest (TYPE_FIELD_BITPOS (type, i)
1469 + TYPE_FIELD_BITSIZE (type, i)
1470 - 1));
1471 }
1472 fprintf_filtered (stream, ";\n");
1473 }
1474 fprintfi_filtered (level, stream, "}");
1475 }
1476 }
1477 break;
1478
1479 case TYPE_CODE_VOID:
1480 fprintf_filtered (stream, "void");
1481 break;
1482
1483 case TYPE_CODE_UNDEF:
1484 fprintf_filtered (stream, _("struct <unknown>"));
1485 break;
1486
1487 case TYPE_CODE_ERROR:
1488 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
1489 break;
1490
1491 case TYPE_CODE_RANGE:
1492 /* This should not occur. */
1493 fprintf_filtered (stream, _("<range type>"));
1494 break;
1495
1496 case TYPE_CODE_NAMESPACE:
1497 fputs_filtered ("namespace ", stream);
1498 fputs_filtered (TYPE_TAG_NAME (type), stream);
1499 break;
1500
1501 default:
1502 /* Handle types not explicitly handled by the other cases, such
1503 as fundamental types. For these, just print whatever the
1504 type name is, as recorded in the type itself. If there is no
1505 type name, then complain. */
1506 if (TYPE_NAME (type) != NULL)
1507 {
1508 c_type_print_modifier (type, stream, 0, 1);
1509 print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
1510 }
1511 else
1512 {
1513 /* At least for dump_symtab, it is important that this not
1514 be an error (). */
1515 fprintf_filtered (stream, _("<invalid type code %d>"),
1516 TYPE_CODE (type));
1517 }
1518 break;
1519 }
1520 }
This page took 0.102917 seconds and 4 git commands to generate.