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