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