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