Wed Nov 4 18:46:47 1998 Dave Brolley <brolley@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / c-typeprint.c
CommitLineData
a8a69e63 1/* Support for printing C and C++ types for GDB, the GNU debugger.
81afee37 2 Copyright 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996
84bdfea6 3 Free Software Foundation, Inc.
a8a69e63
FF
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
6c9638b4 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
a8a69e63
FF
20
21#include "defs.h"
22#include "obstack.h"
23#include "bfd.h" /* Binary File Description */
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "expression.h"
27#include "value.h"
28#include "gdbcore.h"
29#include "target.h"
30#include "command.h"
31#include "gdbcmd.h"
32#include "language.h"
33#include "demangle.h"
34#include "c-lang.h"
35#include "typeprint.h"
36
2b576293 37#include "gdb_string.h"
a8a69e63 38#include <errno.h>
4c664b8d 39#include <ctype.h>
a8a69e63 40
a8a69e63 41static void
199b2450 42c_type_print_args PARAMS ((struct type *, GDB_FILE *));
a8a69e63
FF
43
44static void
199b2450 45c_type_print_varspec_suffix PARAMS ((struct type *, GDB_FILE *, int, int, int));
a8a69e63
FF
46
47static void
199b2450 48cp_type_print_derivation_info PARAMS ((GDB_FILE *, struct type *));
a8a69e63
FF
49
50void
199b2450 51c_type_print_varspec_prefix PARAMS ((struct type *, GDB_FILE *, int, int));
a8a69e63 52
a8a69e63
FF
53\f
54/* Print a description of a type in the format of a
55 typedef for the current language.
56 NEW is the new name for a type TYPE. */
57
58void
59c_typedef_print (type, new, stream)
60 struct type *type;
61 struct symbol *new;
199b2450 62 GDB_FILE *stream;
a8a69e63 63{
5e548861 64 CHECK_TYPEDEF (type);
a8a69e63
FF
65 switch (current_language->la_language)
66 {
67#ifdef _LANG_c
68 case language_c:
69 case language_cplus:
70 fprintf_filtered(stream, "typedef ");
71 type_print(type,"",stream,0);
72 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
2e4964ad
FF
73 || !STREQ (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_NAME (new)))
74 fprintf_filtered(stream, " %s", SYMBOL_SOURCE_NAME(new));
a8a69e63
FF
75 break;
76#endif
77#ifdef _LANG_m2
78 case language_m2:
79 fprintf_filtered(stream, "TYPE ");
80 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
2e4964ad
FF
81 !STREQ (TYPE_NAME(SYMBOL_TYPE(new)), SYMBOL_NAME(new)))
82 fprintf_filtered(stream, "%s = ", SYMBOL_SOURCE_NAME(new));
a8a69e63
FF
83 else
84 fprintf_filtered(stream, "<builtin> = ");
85 type_print(type,"",stream,0);
86 break;
87#endif
a8a69e63
FF
88#ifdef _LANG_chill
89 case language_chill:
6a2eecac
PB
90 fprintf_filtered(stream, "SYNMODE ");
91 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
92 !STREQ (TYPE_NAME(SYMBOL_TYPE(new)), SYMBOL_NAME(new)))
93 fprintf_filtered(stream, "%s = ", SYMBOL_SOURCE_NAME(new));
94 else
95 fprintf_filtered(stream, "<builtin> = ");
96 type_print(type,"",stream,0);
97 break;
a8a69e63 98#endif
a8a69e63
FF
99 default:
100 error("Language not supported.");
101 }
102 fprintf_filtered(stream, ";\n");
103}
104
105
106/* LEVEL is the depth to indent lines by. */
107
108void
109c_print_type (type, varstring, stream, show, level)
110 struct type *type;
111 char *varstring;
199b2450 112 GDB_FILE *stream;
a8a69e63
FF
113 int show;
114 int level;
115{
116 register enum type_code code;
a8a69e63
FF
117 int demangled_args;
118
5e548861
PB
119 if (show > 0)
120 CHECK_TYPEDEF (type);
121
a8a69e63
FF
122 c_type_print_base (type, stream, show, level);
123 code = TYPE_CODE (type);
124 if ((varstring != NULL && *varstring != '\0')
125 ||
126 /* Need a space if going to print stars or brackets;
127 but not if we will print just a type name. */
128 ((show > 0 || TYPE_NAME (type) == 0)
129 &&
130 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
131 || code == TYPE_CODE_METHOD
132 || code == TYPE_CODE_ARRAY
133 || code == TYPE_CODE_MEMBER
134 || code == TYPE_CODE_REF)))
135 fputs_filtered (" ", stream);
136 c_type_print_varspec_prefix (type, stream, show, 0);
137
433732f2
SG
138 if (varstring != NULL)
139 {
140 fputs_filtered (varstring, stream);
a8a69e63 141
433732f2
SG
142 /* For demangled function names, we have the arglist as part of the name,
143 so don't print an additional pair of ()'s */
a8a69e63 144
433732f2
SG
145 demangled_args = strchr(varstring, '(') != NULL;
146 c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
147 }
a8a69e63 148}
a8a69e63
FF
149
150/* If TYPE is a derived type, then print out derivation information.
151 Print only the actual base classes of this type, not the base classes
152 of the base classes. I.E. for the derivation hierarchy:
153
154 class A { int a; };
155 class B : public A {int b; };
156 class C : public B {int c; };
157
158 Print the type of class C as:
159
160 class C : public B {
161 int c;
162 }
163
164 Not as the following (like gdb used to), which is not legal C++ syntax for
165 derived types and may be confused with the multiple inheritance form:
166
167 class C : public B : public A {
168 int c;
169 }
170
171 In general, gdb should try to print the types as closely as possible to
172 the form that they appear in the source code. */
173
174static void
175cp_type_print_derivation_info (stream, type)
199b2450 176 GDB_FILE *stream;
a8a69e63
FF
177 struct type *type;
178{
179 char *name;
180 int i;
181
182 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
183 {
184 fputs_filtered (i == 0 ? ": " : ", ", stream);
185 fprintf_filtered (stream, "%s%s ",
186 BASETYPE_VIA_PUBLIC (type, i) ? "public" : "private",
187 BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : "");
188 name = type_name_no_tag (TYPE_BASECLASS (type, i));
189 fprintf_filtered (stream, "%s", name ? name : "(null)");
190 }
191 if (i > 0)
192 {
193 fputs_filtered (" ", stream);
194 }
195}
196
197/* Print any asterisks or open-parentheses needed before the
198 variable name (to describe its type).
199
200 On outermost call, pass 0 for PASSED_A_PTR.
201 On outermost call, SHOW > 0 means should ignore
202 any typename for TYPE and show its details.
203 SHOW is always zero on recursive calls. */
204
205void
206c_type_print_varspec_prefix (type, stream, show, passed_a_ptr)
207 struct type *type;
199b2450 208 GDB_FILE *stream;
a8a69e63
FF
209 int show;
210 int passed_a_ptr;
211{
212 char *name;
213 if (type == 0)
214 return;
215
216 if (TYPE_NAME (type) && show <= 0)
217 return;
218
219 QUIT;
220
221 switch (TYPE_CODE (type))
222 {
223 case TYPE_CODE_PTR:
224 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
225 fprintf_filtered (stream, "*");
226 break;
227
228 case TYPE_CODE_MEMBER:
229 if (passed_a_ptr)
230 fprintf_filtered (stream, "(");
231 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
232 fprintf_filtered (stream, " ");
233 name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
234 if (name)
235 fputs_filtered (name, stream);
236 else
237 c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
238 fprintf_filtered (stream, "::");
239 break;
240
241 case TYPE_CODE_METHOD:
242 if (passed_a_ptr)
a46d92a7 243 fprintf_filtered (stream, "(");
a8a69e63
FF
244 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
245 if (passed_a_ptr)
246 {
247 fprintf_filtered (stream, " ");
248 c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
249 fprintf_filtered (stream, "::");
250 }
251 break;
252
253 case TYPE_CODE_REF:
254 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
255 fprintf_filtered (stream, "&");
256 break;
257
258 case TYPE_CODE_FUNC:
259 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
260 if (passed_a_ptr)
261 fprintf_filtered (stream, "(");
262 break;
263
264 case TYPE_CODE_ARRAY:
265 c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
266 if (passed_a_ptr)
267 fprintf_filtered (stream, "(");
268 break;
269
270 case TYPE_CODE_UNDEF:
271 case TYPE_CODE_STRUCT:
272 case TYPE_CODE_UNION:
273 case TYPE_CODE_ENUM:
274 case TYPE_CODE_INT:
275 case TYPE_CODE_FLT:
276 case TYPE_CODE_VOID:
277 case TYPE_CODE_ERROR:
278 case TYPE_CODE_CHAR:
279 case TYPE_CODE_BOOL:
280 case TYPE_CODE_SET:
281 case TYPE_CODE_RANGE:
c4413e2c 282 case TYPE_CODE_STRING:
72cd0384 283 case TYPE_CODE_BITSTRING:
22d7f91e 284 case TYPE_CODE_COMPLEX:
5e548861 285 case TYPE_CODE_TYPEDEF:
a8a69e63
FF
286 /* These types need no prefix. They are listed here so that
287 gcc -Wall will reveal any types that haven't been handled. */
288 break;
289 }
290}
291
292static void
293c_type_print_args (type, stream)
294 struct type *type;
199b2450 295 GDB_FILE *stream;
a8a69e63
FF
296{
297 int i;
298 struct type **args;
299
300 fprintf_filtered (stream, "(");
301 args = TYPE_ARG_TYPES (type);
302 if (args != NULL)
303 {
304 if (args[1] == NULL)
305 {
306 fprintf_filtered (stream, "...");
307 }
308 else
309 {
310 for (i = 1;
311 args[i] != NULL && args[i]->code != TYPE_CODE_VOID;
312 i++)
313 {
314 c_print_type (args[i], "", stream, -1, 0);
315 if (args[i+1] == NULL)
316 {
317 fprintf_filtered (stream, "...");
318 }
319 else if (args[i+1]->code != TYPE_CODE_VOID)
320 {
321 fprintf_filtered (stream, ",");
322 wrap_here (" ");
323 }
324 }
325 }
326 }
327 fprintf_filtered (stream, ")");
328}
329
330/* Print any array sizes, function arguments or close parentheses
331 needed after the variable name (to describe its type).
332 Args work like c_type_print_varspec_prefix. */
333
334static void
335c_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
336 struct type *type;
199b2450 337 GDB_FILE *stream;
a8a69e63
FF
338 int show;
339 int passed_a_ptr;
340 int demangled_args;
341{
342 if (type == 0)
343 return;
344
345 if (TYPE_NAME (type) && show <= 0)
346 return;
347
348 QUIT;
349
350 switch (TYPE_CODE (type))
351 {
352 case TYPE_CODE_ARRAY:
353 if (passed_a_ptr)
354 fprintf_filtered (stream, ")");
355
356 fprintf_filtered (stream, "[");
fda36387
PB
357 if (TYPE_LENGTH (type) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
358 && TYPE_ARRAY_UPPER_BOUND_TYPE(type) != BOUND_CANNOT_BE_DETERMINED)
a8a69e63
FF
359 fprintf_filtered (stream, "%d",
360 (TYPE_LENGTH (type)
361 / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
362 fprintf_filtered (stream, "]");
363
364 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
365 break;
366
367 case TYPE_CODE_MEMBER:
368 if (passed_a_ptr)
369 fprintf_filtered (stream, ")");
370 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
371 break;
372
373 case TYPE_CODE_METHOD:
374 if (passed_a_ptr)
375 fprintf_filtered (stream, ")");
376 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
377 if (passed_a_ptr)
378 {
379 c_type_print_args (type, stream);
380 }
381 break;
382
383 case TYPE_CODE_PTR:
384 case TYPE_CODE_REF:
385 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
386 break;
387
388 case TYPE_CODE_FUNC:
a8a69e63
FF
389 if (passed_a_ptr)
390 fprintf_filtered (stream, ")");
391 if (!demangled_args)
27202b6a
PB
392 { int i, len = TYPE_NFIELDS (type);
393 fprintf_filtered (stream, "(");
394 for (i = 0; i < len; i++)
395 {
396 if (i > 0)
397 {
398 fputs_filtered (", ", stream);
399 wrap_here (" ");
400 }
401 c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
402 }
403 fprintf_filtered (stream, ")");
404 }
dac317dc
JK
405 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
406 passed_a_ptr, 0);
a8a69e63
FF
407 break;
408
409 case TYPE_CODE_UNDEF:
410 case TYPE_CODE_STRUCT:
411 case TYPE_CODE_UNION:
412 case TYPE_CODE_ENUM:
413 case TYPE_CODE_INT:
414 case TYPE_CODE_FLT:
415 case TYPE_CODE_VOID:
416 case TYPE_CODE_ERROR:
417 case TYPE_CODE_CHAR:
418 case TYPE_CODE_BOOL:
419 case TYPE_CODE_SET:
420 case TYPE_CODE_RANGE:
c4413e2c 421 case TYPE_CODE_STRING:
72cd0384 422 case TYPE_CODE_BITSTRING:
22d7f91e 423 case TYPE_CODE_COMPLEX:
5e548861 424 case TYPE_CODE_TYPEDEF:
a8a69e63
FF
425 /* These types do not need a suffix. They are listed so that
426 gcc -Wall will report types that may not have been considered. */
427 break;
428 }
429}
430
431/* Print the name of the type (or the ultimate pointer target,
432 function value or array element), or the description of a
433 structure or union.
434
875fc229
JK
435 SHOW positive means print details about the type (e.g. enum values),
436 and print structure elements passing SHOW - 1 for show.
0e4ad984 437 SHOW negative means just print the type name or struct tag if there is one.
875fc229
JK
438 If there is no name, print something sensible but concise like
439 "struct {...}".
0e4ad984
JK
440 SHOW zero means just print the type name or struct tag if there is one.
441 If there is no name, print something sensible but not as concise like
442 "struct {int x; int y;}".
875fc229
JK
443
444 LEVEL is the number of spaces to indent by.
a8a69e63
FF
445 We increase it for some recursive calls. */
446
447void
448c_type_print_base (type, stream, show, level)
449 struct type *type;
199b2450 450 GDB_FILE *stream;
a8a69e63
FF
451 int show;
452 int level;
453{
a8a69e63
FF
454 register int i;
455 register int len;
456 register int lastval;
457 char *mangled_name;
458 char *demangled_name;
459 enum {s_none, s_public, s_private, s_protected} section_type;
460 QUIT;
461
462 wrap_here (" ");
463 if (type == NULL)
464 {
465 fputs_filtered ("<type unknown>", stream);
466 return;
467 }
468
469 /* When SHOW is zero or less, and there is a valid type name, then always
b2bebdb0
JK
470 just print the type name directly from the type. */
471 /* If we have "typedef struct foo {. . .} bar;" do we want to print it
472 as "struct foo" or as "bar"? Pick the latter, because C++ folk tend
473 to expect things like "class5 *foo" rather than "struct class5 *foo". */
a8a69e63 474
b2bebdb0
JK
475 if (show <= 0
476 && TYPE_NAME (type) != NULL)
a8a69e63
FF
477 {
478 fputs_filtered (TYPE_NAME (type), stream);
479 return;
480 }
481
5e548861 482 CHECK_TYPEDEF (type);
dda398c3 483
a8a69e63
FF
484 switch (TYPE_CODE (type))
485 {
5e548861 486 case TYPE_CODE_TYPEDEF:
a8a69e63
FF
487 case TYPE_CODE_ARRAY:
488 case TYPE_CODE_PTR:
489 case TYPE_CODE_MEMBER:
490 case TYPE_CODE_REF:
491 case TYPE_CODE_FUNC:
492 case TYPE_CODE_METHOD:
493 c_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
494 break;
495
496 case TYPE_CODE_STRUCT:
8789d972
JK
497 if (HAVE_CPLUS_STRUCT (type))
498 {
8789d972 499 fprintf_filtered (stream, "class ");
8789d972
JK
500 }
501 else
502 {
503 fprintf_filtered (stream, "struct ");
8789d972 504 }
a8a69e63
FF
505 goto struct_union;
506
507 case TYPE_CODE_UNION:
508 fprintf_filtered (stream, "union ");
b2bebdb0
JK
509
510 struct_union:
511 if (TYPE_TAG_NAME (type) != NULL)
8789d972 512 {
b2bebdb0
JK
513 fputs_filtered (TYPE_TAG_NAME (type), stream);
514 if (show > 0)
515 fputs_filtered (" ", stream);
8789d972 516 }
8789d972 517 wrap_here (" ");
0e4ad984 518 if (show < 0)
b2bebdb0
JK
519 {
520 /* If we just printed a tag name, no need to print anything else. */
521 if (TYPE_TAG_NAME (type) == NULL)
522 fprintf_filtered (stream, "{...}");
523 }
0e4ad984 524 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
a8a69e63 525 {
a8a69e63
FF
526 cp_type_print_derivation_info (stream, type);
527
528 fprintf_filtered (stream, "{\n");
529 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
530 {
531 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
532 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
533 else
534 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
535 }
536
537 /* Start off with no specific section type, so we can print
538 one for the first field we find, and use that section type
539 thereafter until we find another type. */
540
541 section_type = s_none;
542
543 /* If there is a base class for this type,
544 do not print the field that it occupies. */
545
546 len = TYPE_NFIELDS (type);
547 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
548 {
549 QUIT;
550 /* Don't print out virtual function table. */
81afee37
FF
551 if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5)
552 && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
a8a69e63
FF
553 continue;
554
555 /* If this is a C++ class we can print the various C++ section
556 labels. */
557
558 if (HAVE_CPLUS_STRUCT (type))
559 {
560 if (TYPE_FIELD_PROTECTED (type, i))
561 {
562 if (section_type != s_protected)
563 {
564 section_type = s_protected;
565 fprintfi_filtered (level + 2, stream,
566 "protected:\n");
567 }
568 }
569 else if (TYPE_FIELD_PRIVATE (type, i))
570 {
571 if (section_type != s_private)
572 {
573 section_type = s_private;
574 fprintfi_filtered (level + 2, stream, "private:\n");
575 }
576 }
577 else
578 {
579 if (section_type != s_public)
580 {
581 section_type = s_public;
582 fprintfi_filtered (level + 2, stream, "public:\n");
583 }
584 }
585 }
586
587 print_spaces_filtered (level + 4, stream);
588 if (TYPE_FIELD_STATIC (type, i))
589 {
590 fprintf_filtered (stream, "static ");
591 }
592 c_print_type (TYPE_FIELD_TYPE (type, i),
593 TYPE_FIELD_NAME (type, i),
594 stream, show - 1, level + 4);
595 if (!TYPE_FIELD_STATIC (type, i)
596 && TYPE_FIELD_PACKED (type, i))
597 {
598 /* It is a bitfield. This code does not attempt
599 to look at the bitpos and reconstruct filler,
600 unnamed fields. This would lead to misleading
601 results if the compiler does not put out fields
602 for such things (I don't know what it does). */
603 fprintf_filtered (stream, " : %d",
604 TYPE_FIELD_BITSIZE (type, i));
605 }
606 fprintf_filtered (stream, ";\n");
607 }
608
609 /* If there are both fields and methods, put a space between. */
610 len = TYPE_NFN_FIELDS (type);
611 if (len && section_type != s_none)
612 fprintf_filtered (stream, "\n");
613
614 /* C++: print out the methods */
615
616 for (i = 0; i < len; i++)
617 {
618 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
619 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
620 char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
b2bebdb0 621 char *name = type_name_no_tag (type);
2e4964ad 622 int is_constructor = name && STREQ(method_name, name);
a8a69e63
FF
623 for (j = 0; j < len2; j++)
624 {
4c664b8d
PS
625 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
626 int is_full_physname_constructor =
a46d92a7
PS
627 ((physname[0] == '_' && physname[1] == '_'
628 && strchr ("0123456789Qt", physname[2]))
629 || STREQN (physname, "__ct__", 6)
630 || DESTRUCTOR_PREFIX_P (physname)
631 || STREQN (physname, "__dt__", 6));
4c664b8d 632
a8a69e63
FF
633 QUIT;
634 if (TYPE_FN_FIELD_PROTECTED (f, j))
635 {
636 if (section_type != s_protected)
637 {
638 section_type = s_protected;
639 fprintfi_filtered (level + 2, stream,
640 "protected:\n");
641 }
642 }
643 else if (TYPE_FN_FIELD_PRIVATE (f, j))
644 {
645 if (section_type != s_private)
646 {
647 section_type = s_private;
648 fprintfi_filtered (level + 2, stream, "private:\n");
649 }
650 }
651 else
652 {
653 if (section_type != s_public)
654 {
655 section_type = s_public;
656 fprintfi_filtered (level + 2, stream, "public:\n");
657 }
658 }
659
660 print_spaces_filtered (level + 4, stream);
661 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
662 fprintf_filtered (stream, "virtual ");
663 else if (TYPE_FN_FIELD_STATIC_P (f, j))
664 fprintf_filtered (stream, "static ");
665 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
666 {
667 /* Keep GDB from crashing here. */
a46d92a7 668 fprintf_filtered (stream, "<undefined type> %s;\n",
a8a69e63
FF
669 TYPE_FN_FIELD_PHYSNAME (f, j));
670 break;
671 }
4c664b8d 672 else if (!is_constructor && !is_full_physname_constructor)
a8a69e63
FF
673 {
674 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
84bdfea6 675 "", stream, -1);
a8a69e63
FF
676 fputs_filtered (" ", stream);
677 }
678 if (TYPE_FN_FIELD_STUB (f, j))
a46d92a7
PS
679 /* Build something we can demangle. */
680 mangled_name = gdb_mangle_name (type, i, j);
681 else
682 mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
683
684 demangled_name =
685 cplus_demangle (mangled_name,
686 DMGL_ANSI | DMGL_PARAMS);
687 if (demangled_name == NULL)
688 fprintf_filtered (stream, "<badly mangled name '%s'>",
689 mangled_name);
690 else
a8a69e63 691 {
a46d92a7
PS
692 char *demangled_no_class =
693 strchr (demangled_name, ':');
694
695 if (demangled_no_class == NULL)
696 demangled_no_class = demangled_name;
4f9bddb4 697 else
a8a69e63 698 {
a46d92a7
PS
699 if (*++demangled_no_class == ':')
700 ++demangled_no_class;
a8a69e63 701 }
a46d92a7
PS
702 fputs_filtered (demangled_no_class, stream);
703 free (demangled_name);
a8a69e63 704 }
a46d92a7
PS
705
706 if (TYPE_FN_FIELD_STUB (f, j))
707 free (mangled_name);
a8a69e63
FF
708
709 fprintf_filtered (stream, ";\n");
710 }
711 }
712
713 fprintfi_filtered (level, stream, "}");
714 }
715 break;
716
717 case TYPE_CODE_ENUM:
718 fprintf_filtered (stream, "enum ");
b2bebdb0 719 if (TYPE_TAG_NAME (type) != NULL)
a8a69e63 720 {
b2bebdb0
JK
721 fputs_filtered (TYPE_TAG_NAME (type), stream);
722 if (show > 0)
723 fputs_filtered (" ", stream);
a8a69e63 724 }
8789d972 725
a8a69e63 726 wrap_here (" ");
0e4ad984 727 if (show < 0)
b2bebdb0
JK
728 {
729 /* If we just printed a tag name, no need to print anything else. */
730 if (TYPE_TAG_NAME (type) == NULL)
731 fprintf_filtered (stream, "{...}");
732 }
0e4ad984 733 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
a8a69e63
FF
734 {
735 fprintf_filtered (stream, "{");
736 len = TYPE_NFIELDS (type);
737 lastval = 0;
738 for (i = 0; i < len; i++)
739 {
740 QUIT;
741 if (i) fprintf_filtered (stream, ", ");
742 wrap_here (" ");
743 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
744 if (lastval != TYPE_FIELD_BITPOS (type, i))
745 {
746 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
747 lastval = TYPE_FIELD_BITPOS (type, i);
748 }
749 lastval++;
750 }
751 fprintf_filtered (stream, "}");
752 }
753 break;
754
755 case TYPE_CODE_VOID:
756 fprintf_filtered (stream, "void");
757 break;
758
759 case TYPE_CODE_UNDEF:
760 fprintf_filtered (stream, "struct <unknown>");
761 break;
762
763 case TYPE_CODE_ERROR:
764 fprintf_filtered (stream, "<unknown type>");
765 break;
766
767 case TYPE_CODE_RANGE:
768 /* This should not occur */
769 fprintf_filtered (stream, "<range type>");
770 break;
771
772 default:
773 /* Handle types not explicitly handled by the other cases,
774 such as fundamental types. For these, just print whatever
775 the type name is, as recorded in the type itself. If there
776 is no type name, then complain. */
777 if (TYPE_NAME (type) != NULL)
778 {
779 fputs_filtered (TYPE_NAME (type), stream);
780 }
781 else
782 {
fd09c963
JK
783 /* At least for dump_symtab, it is important that this not be
784 an error (). */
785 fprintf_filtered (stream, "<invalid type code %d>",
786 TYPE_CODE (type));
a8a69e63
FF
787 }
788 break;
789 }
790}
791
This page took 0.32275 seconds and 4 git commands to generate.