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