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