Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for printing C and C++ types for GDB, the GNU debugger. |
d9fcf2fb | 2 | Copyright 1986, 1988, 1989, 1991, 1993-1996, 1998-2000 |
c906108c SS |
3 | Free Software Foundation, Inc. |
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 | |
9 | the Free Software Foundation; either version 2 of the License, or | |
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 JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "obstack.h" | |
24 | #include "bfd.h" /* Binary File Description */ | |
25 | #include "symtab.h" | |
26 | #include "gdbtypes.h" | |
27 | #include "expression.h" | |
28 | #include "value.h" | |
29 | #include "gdbcore.h" | |
30 | #include "target.h" | |
31 | #include "command.h" | |
32 | #include "gdbcmd.h" | |
33 | #include "language.h" | |
34 | #include "demangle.h" | |
35 | #include "c-lang.h" | |
36 | #include "typeprint.h" | |
37 | ||
38 | #include "gdb_string.h" | |
39 | #include <errno.h> | |
40 | #include <ctype.h> | |
41 | ||
42 | /* Flag indicating target was compiled by HP compiler */ | |
43 | extern int hp_som_som_object_present; | |
44 | ||
d9fcf2fb JM |
45 | static void cp_type_print_method_args (struct type ** args, char *prefix, |
46 | char *varstring, int staticp, | |
47 | struct ui_file *stream); | |
392a587b | 48 | |
d9fcf2fb | 49 | static void c_type_print_args (struct type *, struct ui_file *); |
c906108c | 50 | |
d9fcf2fb | 51 | static void cp_type_print_derivation_info (struct ui_file *, struct type *); |
c906108c | 52 | |
d9fcf2fb JM |
53 | void c_type_print_varspec_prefix (struct type *, struct ui_file *, int, |
54 | int); | |
c906108c | 55 | |
d9fcf2fb JM |
56 | static void c_type_print_cv_qualifier (struct type *, struct ui_file *, |
57 | int, int); | |
c5aa993b | 58 | \f |
c906108c SS |
59 | |
60 | ||
c906108c SS |
61 | /* Print a description of a type in the format of a |
62 | typedef for the current language. | |
63 | NEW is the new name for a type TYPE. */ | |
64 | ||
65 | void | |
fba45db2 | 66 | c_typedef_print (struct type *type, struct symbol *new, struct ui_file *stream) |
c906108c SS |
67 | { |
68 | CHECK_TYPEDEF (type); | |
c5aa993b JM |
69 | switch (current_language->la_language) |
70 | { | |
c906108c | 71 | #ifdef _LANG_c |
c5aa993b JM |
72 | case language_c: |
73 | case language_cplus: | |
74 | fprintf_filtered (stream, "typedef "); | |
75 | type_print (type, "", stream, 0); | |
76 | if (TYPE_NAME ((SYMBOL_TYPE (new))) == 0 | |
77 | || !STREQ (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_NAME (new))) | |
78 | fprintf_filtered (stream, " %s", SYMBOL_SOURCE_NAME (new)); | |
c906108c SS |
79 | break; |
80 | #endif | |
81 | #ifdef _LANG_m2 | |
c5aa993b JM |
82 | case language_m2: |
83 | fprintf_filtered (stream, "TYPE "); | |
84 | if (!TYPE_NAME (SYMBOL_TYPE (new)) || | |
85 | !STREQ (TYPE_NAME (SYMBOL_TYPE (new)), SYMBOL_NAME (new))) | |
86 | fprintf_filtered (stream, "%s = ", SYMBOL_SOURCE_NAME (new)); | |
c906108c | 87 | else |
c5aa993b JM |
88 | fprintf_filtered (stream, "<builtin> = "); |
89 | type_print (type, "", stream, 0); | |
c906108c SS |
90 | break; |
91 | #endif | |
92 | #ifdef _LANG_chill | |
c5aa993b JM |
93 | case language_chill: |
94 | fprintf_filtered (stream, "SYNMODE "); | |
95 | if (!TYPE_NAME (SYMBOL_TYPE (new)) || | |
96 | !STREQ (TYPE_NAME (SYMBOL_TYPE (new)), SYMBOL_NAME (new))) | |
97 | fprintf_filtered (stream, "%s = ", SYMBOL_SOURCE_NAME (new)); | |
c906108c | 98 | else |
c5aa993b JM |
99 | fprintf_filtered (stream, "<builtin> = "); |
100 | type_print (type, "", stream, 0); | |
c906108c SS |
101 | break; |
102 | #endif | |
c5aa993b JM |
103 | default: |
104 | error ("Language not supported."); | |
105 | } | |
106 | fprintf_filtered (stream, ";\n"); | |
c906108c SS |
107 | } |
108 | ||
109 | ||
110 | /* LEVEL is the depth to indent lines by. */ | |
111 | ||
112 | void | |
fba45db2 KB |
113 | c_print_type (struct type *type, char *varstring, struct ui_file *stream, |
114 | int show, int level) | |
c906108c SS |
115 | { |
116 | register enum type_code code; | |
117 | int demangled_args; | |
118 | ||
119 | if (show > 0) | |
120 | CHECK_TYPEDEF (type); | |
121 | ||
122 | c_type_print_base (type, stream, show, level); | |
123 | code = TYPE_CODE (type); | |
124 | if ((varstring != NULL && *varstring != '\0') | |
125 | || | |
c5aa993b JM |
126 | /* Need a space if going to print stars or brackets; |
127 | but not if we will print just a type name. */ | |
c906108c SS |
128 | ((show > 0 || TYPE_NAME (type) == 0) |
129 | && | |
130 | (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC | |
131 | || code == TYPE_CODE_METHOD | |
132 | || code == TYPE_CODE_ARRAY | |
133 | || code == TYPE_CODE_MEMBER | |
134 | || code == TYPE_CODE_REF))) | |
135 | fputs_filtered (" ", stream); | |
136 | c_type_print_varspec_prefix (type, stream, show, 0); | |
137 | ||
138 | if (varstring != NULL) | |
139 | { | |
140 | fputs_filtered (varstring, stream); | |
141 | ||
142 | /* For demangled function names, we have the arglist as part of the name, | |
c5aa993b | 143 | so don't print an additional pair of ()'s */ |
c906108c | 144 | |
c5aa993b | 145 | demangled_args = strchr (varstring, '(') != NULL; |
c906108c SS |
146 | c_type_print_varspec_suffix (type, stream, show, 0, demangled_args); |
147 | } | |
148 | } | |
c5aa993b | 149 | |
c906108c SS |
150 | /* If TYPE is a derived type, then print out derivation information. |
151 | Print only the actual base classes of this type, not the base classes | |
152 | of the base classes. I.E. for the derivation hierarchy: | |
153 | ||
c5aa993b JM |
154 | class A { int a; }; |
155 | class B : public A {int b; }; | |
156 | class C : public B {int c; }; | |
c906108c SS |
157 | |
158 | Print the type of class C as: | |
159 | ||
c5aa993b JM |
160 | class C : public B { |
161 | int c; | |
162 | } | |
c906108c SS |
163 | |
164 | Not as the following (like gdb used to), which is not legal C++ syntax for | |
165 | derived types and may be confused with the multiple inheritance form: | |
166 | ||
c5aa993b JM |
167 | class C : public B : public A { |
168 | int c; | |
169 | } | |
c906108c SS |
170 | |
171 | In general, gdb should try to print the types as closely as possible to | |
172 | the form that they appear in the source code. | |
173 | Note that in case of protected derivation gcc will not say 'protected' | |
174 | but 'private'. The HP's aCC compiler emits specific information for | |
175 | derivation via protected inheritance, so gdb can print it out */ | |
176 | ||
177 | static void | |
fba45db2 | 178 | cp_type_print_derivation_info (struct ui_file *stream, struct type *type) |
c906108c SS |
179 | { |
180 | char *name; | |
181 | int i; | |
182 | ||
183 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) | |
184 | { | |
185 | fputs_filtered (i == 0 ? ": " : ", ", stream); | |
186 | fprintf_filtered (stream, "%s%s ", | |
c5aa993b JM |
187 | BASETYPE_VIA_PUBLIC (type, i) ? "public" |
188 | : (TYPE_FIELD_PROTECTED (type, i) ? "protected" : "private"), | |
189 | BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : ""); | |
c906108c SS |
190 | name = type_name_no_tag (TYPE_BASECLASS (type, i)); |
191 | fprintf_filtered (stream, "%s", name ? name : "(null)"); | |
192 | } | |
193 | if (i > 0) | |
194 | { | |
195 | fputs_filtered (" ", stream); | |
196 | } | |
197 | } | |
198 | /* Print the C++ method arguments ARGS to the file STREAM. */ | |
c5aa993b | 199 | |
392a587b | 200 | static void |
fba45db2 KB |
201 | cp_type_print_method_args (struct type **args, char *prefix, char *varstring, |
202 | int staticp, struct ui_file *stream) | |
c906108c SS |
203 | { |
204 | int i; | |
c5aa993b | 205 | |
c906108c SS |
206 | fprintf_symbol_filtered (stream, prefix, language_cplus, DMGL_ANSI); |
207 | fprintf_symbol_filtered (stream, varstring, language_cplus, DMGL_ANSI); | |
208 | fputs_filtered ("(", stream); | |
209 | if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID) | |
210 | { | |
c5aa993b | 211 | i = !staticp; /* skip the class variable */ |
c906108c | 212 | while (1) |
c5aa993b JM |
213 | { |
214 | type_print (args[i++], "", stream, 0); | |
215 | if (!args[i]) | |
216 | { | |
217 | fprintf_filtered (stream, " ..."); | |
218 | break; | |
219 | } | |
220 | else if (args[i]->code != TYPE_CODE_VOID) | |
221 | { | |
222 | fprintf_filtered (stream, ", "); | |
223 | } | |
224 | else | |
225 | break; | |
226 | } | |
c906108c SS |
227 | } |
228 | else if (current_language->la_language == language_cplus) | |
229 | { | |
230 | fprintf_filtered (stream, "void"); | |
231 | } | |
c5aa993b | 232 | |
c906108c SS |
233 | fprintf_filtered (stream, ")"); |
234 | } | |
235 | ||
236 | ||
237 | /* Print any asterisks or open-parentheses needed before the | |
238 | variable name (to describe its type). | |
239 | ||
240 | On outermost call, pass 0 for PASSED_A_PTR. | |
241 | On outermost call, SHOW > 0 means should ignore | |
242 | any typename for TYPE and show its details. | |
243 | SHOW is always zero on recursive calls. */ | |
244 | ||
245 | void | |
fba45db2 KB |
246 | c_type_print_varspec_prefix (struct type *type, struct ui_file *stream, |
247 | int show, int passed_a_ptr) | |
c906108c SS |
248 | { |
249 | char *name; | |
250 | if (type == 0) | |
251 | return; | |
252 | ||
253 | if (TYPE_NAME (type) && show <= 0) | |
254 | return; | |
255 | ||
256 | QUIT; | |
257 | ||
258 | switch (TYPE_CODE (type)) | |
259 | { | |
260 | case TYPE_CODE_PTR: | |
261 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
262 | fprintf_filtered (stream, "*"); | |
263 | c_type_print_cv_qualifier (type, stream, 1, 0); | |
264 | break; | |
265 | ||
266 | case TYPE_CODE_MEMBER: | |
267 | if (passed_a_ptr) | |
268 | fprintf_filtered (stream, "("); | |
269 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
270 | fprintf_filtered (stream, " "); | |
271 | name = type_name_no_tag (TYPE_DOMAIN_TYPE (type)); | |
272 | if (name) | |
273 | fputs_filtered (name, stream); | |
274 | else | |
c5aa993b | 275 | c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr); |
c906108c SS |
276 | fprintf_filtered (stream, "::"); |
277 | break; | |
278 | ||
279 | case TYPE_CODE_METHOD: | |
280 | if (passed_a_ptr) | |
281 | fprintf_filtered (stream, "("); | |
282 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
283 | if (passed_a_ptr) | |
284 | { | |
285 | fprintf_filtered (stream, " "); | |
286 | c_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr); | |
287 | fprintf_filtered (stream, "::"); | |
288 | } | |
289 | break; | |
290 | ||
291 | case TYPE_CODE_REF: | |
292 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
293 | fprintf_filtered (stream, "&"); | |
294 | c_type_print_cv_qualifier (type, stream, 1, 0); | |
295 | break; | |
296 | ||
297 | case TYPE_CODE_FUNC: | |
298 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
299 | if (passed_a_ptr) | |
300 | fprintf_filtered (stream, "("); | |
301 | break; | |
302 | ||
303 | case TYPE_CODE_ARRAY: | |
304 | c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
305 | if (passed_a_ptr) | |
306 | fprintf_filtered (stream, "("); | |
307 | break; | |
308 | ||
309 | case TYPE_CODE_UNDEF: | |
310 | case TYPE_CODE_STRUCT: | |
311 | case TYPE_CODE_UNION: | |
312 | case TYPE_CODE_ENUM: | |
313 | case TYPE_CODE_INT: | |
314 | case TYPE_CODE_FLT: | |
315 | case TYPE_CODE_VOID: | |
316 | case TYPE_CODE_ERROR: | |
317 | case TYPE_CODE_CHAR: | |
318 | case TYPE_CODE_BOOL: | |
319 | case TYPE_CODE_SET: | |
320 | case TYPE_CODE_RANGE: | |
321 | case TYPE_CODE_STRING: | |
322 | case TYPE_CODE_BITSTRING: | |
323 | case TYPE_CODE_COMPLEX: | |
324 | case TYPE_CODE_TYPEDEF: | |
c4093a6a | 325 | case TYPE_CODE_TEMPLATE: |
c906108c | 326 | /* These types need no prefix. They are listed here so that |
c5aa993b | 327 | gcc -Wall will reveal any types that haven't been handled. */ |
c906108c | 328 | break; |
c4093a6a JM |
329 | default: |
330 | error ("type not handled in c_type_print_varspec_prefix()"); | |
331 | break; | |
c906108c SS |
332 | } |
333 | } | |
334 | ||
335 | /* Print out "const" and "volatile" attributes. | |
336 | TYPE is a pointer to the type being printed out. | |
337 | STREAM is the output destination. | |
338 | NEED_SPACE = 1 indicates an initial white space is needed */ | |
339 | ||
340 | static void | |
fba45db2 KB |
341 | c_type_print_cv_qualifier (struct type *type, struct ui_file *stream, |
342 | int need_pre_space, int need_post_space) | |
c906108c SS |
343 | { |
344 | int flag = 0; | |
c5aa993b | 345 | |
c906108c SS |
346 | if (TYPE_CONST (type)) |
347 | { | |
348 | if (need_pre_space) | |
c5aa993b | 349 | fprintf_filtered (stream, " "); |
c906108c SS |
350 | fprintf_filtered (stream, "const"); |
351 | flag = 1; | |
352 | } | |
c5aa993b | 353 | |
c906108c SS |
354 | if (TYPE_VOLATILE (type)) |
355 | { | |
356 | if (flag || need_pre_space) | |
c5aa993b | 357 | fprintf_filtered (stream, " "); |
c906108c SS |
358 | fprintf_filtered (stream, "volatile"); |
359 | flag = 1; | |
360 | } | |
361 | ||
362 | if (flag && need_post_space) | |
363 | fprintf_filtered (stream, " "); | |
364 | } | |
365 | ||
366 | ||
367 | ||
368 | ||
369 | static void | |
fba45db2 | 370 | c_type_print_args (struct type *type, struct ui_file *stream) |
c906108c SS |
371 | { |
372 | int i; | |
373 | struct type **args; | |
374 | ||
375 | fprintf_filtered (stream, "("); | |
376 | args = TYPE_ARG_TYPES (type); | |
377 | if (args != NULL) | |
378 | { | |
379 | if (args[1] == NULL) | |
380 | { | |
381 | fprintf_filtered (stream, "..."); | |
382 | } | |
383 | else if ((args[1]->code == TYPE_CODE_VOID) && | |
c5aa993b JM |
384 | (current_language->la_language == language_cplus)) |
385 | { | |
386 | fprintf_filtered (stream, "void"); | |
387 | } | |
c906108c SS |
388 | else |
389 | { | |
390 | for (i = 1; | |
391 | args[i] != NULL && args[i]->code != TYPE_CODE_VOID; | |
392 | i++) | |
393 | { | |
394 | c_print_type (args[i], "", stream, -1, 0); | |
c5aa993b | 395 | if (args[i + 1] == NULL) |
c906108c SS |
396 | { |
397 | fprintf_filtered (stream, "..."); | |
398 | } | |
c5aa993b | 399 | else if (args[i + 1]->code != TYPE_CODE_VOID) |
c906108c SS |
400 | { |
401 | fprintf_filtered (stream, ","); | |
402 | wrap_here (" "); | |
403 | } | |
404 | } | |
405 | } | |
406 | } | |
407 | else if (current_language->la_language == language_cplus) | |
408 | { | |
409 | fprintf_filtered (stream, "void"); | |
410 | } | |
c5aa993b | 411 | |
c906108c SS |
412 | fprintf_filtered (stream, ")"); |
413 | } | |
414 | ||
dfcd3bfb JM |
415 | |
416 | /* Return true iff the j'th overloading of the i'th method of TYPE | |
417 | is a type conversion operator, like `operator int () { ... }'. | |
418 | When listing a class's methods, we don't print the return type of | |
419 | such operators. */ | |
420 | static int | |
421 | is_type_conversion_operator (struct type *type, int i, int j) | |
422 | { | |
423 | /* I think the whole idea of recognizing type conversion operators | |
424 | by their name is pretty terrible. But I don't think our present | |
425 | data structure gives us any other way to tell. If you know of | |
426 | some other way, feel free to rewrite this function. */ | |
427 | char *name = TYPE_FN_FIELDLIST_NAME (type, i); | |
428 | ||
429 | if (strncmp (name, "operator", 8) != 0) | |
430 | return 0; | |
431 | ||
432 | name += 8; | |
433 | if (! strchr (" \t\f\n\r", *name)) | |
434 | return 0; | |
435 | ||
436 | while (strchr (" \t\f\n\r", *name)) | |
437 | name++; | |
438 | ||
439 | if (strncmp (name, "new", 3) == 0) | |
440 | name += 3; | |
441 | else if (strncmp (name, "delete", 6) == 0) | |
442 | name += 6; | |
443 | else | |
444 | return 0; | |
445 | ||
446 | /* Is that really the end of the name? */ | |
447 | if (('a' <= *name && *name <= 'z') | |
448 | || ('A' <= *name && *name <= 'Z') | |
449 | || ('0' <= *name && *name <= '9') | |
450 | || *name == '_') | |
451 | /* No, so the identifier following "operator" must be a type name, | |
452 | and this is a type conversion operator. */ | |
453 | return 1; | |
454 | ||
455 | /* That was indeed the end of the name, so it was `operator new' or | |
456 | `operator delete', neither of which are type conversion operators. */ | |
457 | return 0; | |
458 | } | |
459 | ||
460 | ||
461 | /* Given a C++ qualified identifier QID, strip off the qualifiers, | |
462 | yielding the unqualified name. The return value is a pointer into | |
463 | the original string. | |
464 | ||
465 | It's a pity we don't have this information in some more structured | |
466 | form. Even the author of this function feels that writing little | |
467 | parsers like this everywhere is stupid. */ | |
468 | static char * | |
469 | remove_qualifiers (char *qid) | |
470 | { | |
471 | int quoted = 0; /* zero if we're not in quotes; | |
472 | '"' if we're in a double-quoted string; | |
473 | '\'' if we're in a single-quoted string. */ | |
474 | int depth = 0; /* number of unclosed parens we've seen */ | |
475 | char *parenstack = (char *) alloca (strlen (qid)); | |
476 | char *scan; | |
477 | char *last = 0; /* The character after the rightmost | |
478 | `::' token we've seen so far. */ | |
479 | ||
480 | for (scan = qid; *scan; scan++) | |
481 | { | |
482 | if (quoted) | |
483 | { | |
484 | if (*scan == quoted) | |
485 | quoted = 0; | |
486 | else if (*scan == '\\' && *(scan + 1)) | |
487 | scan++; | |
488 | } | |
489 | else if (scan[0] == ':' && scan[1] == ':') | |
490 | { | |
491 | /* If we're inside parenthesis (i.e., an argument list) or | |
492 | angle brackets (i.e., a list of template arguments), then | |
493 | we don't record the position of this :: token, since it's | |
494 | not relevant to the top-level structure we're trying | |
495 | to operate on. */ | |
496 | if (depth == 0) | |
497 | { | |
498 | last = scan + 2; | |
499 | scan++; | |
500 | } | |
501 | } | |
502 | else if (*scan == '"' || *scan == '\'') | |
503 | quoted = *scan; | |
504 | else if (*scan == '(') | |
505 | parenstack[depth++] = ')'; | |
506 | else if (*scan == '[') | |
507 | parenstack[depth++] = ']'; | |
508 | /* We're going to treat <> as a pair of matching characters, | |
509 | since we're more likely to see those in template id's than | |
510 | real less-than characters. What a crock. */ | |
511 | else if (*scan == '<') | |
512 | parenstack[depth++] = '>'; | |
513 | else if (*scan == ')' || *scan == ']' || *scan == '>') | |
514 | { | |
515 | if (depth > 0 && parenstack[depth - 1] == *scan) | |
516 | depth--; | |
517 | else | |
518 | { | |
519 | /* We're going to do a little error recovery here. If we | |
520 | don't find a match for *scan on the paren stack, but | |
521 | there is something lower on the stack that does match, we | |
522 | pop the stack to that point. */ | |
523 | int i; | |
524 | ||
525 | for (i = depth - 1; i >= 0; i--) | |
526 | if (parenstack[i] == *scan) | |
527 | { | |
528 | depth = i; | |
529 | break; | |
530 | } | |
531 | } | |
532 | } | |
533 | } | |
534 | ||
535 | if (last) | |
536 | return last; | |
537 | else | |
538 | /* We didn't find any :: tokens at the top level, so declare the | |
539 | whole thing an unqualified identifier. */ | |
540 | return qid; | |
541 | } | |
542 | ||
543 | ||
c906108c SS |
544 | /* Print any array sizes, function arguments or close parentheses |
545 | needed after the variable name (to describe its type). | |
546 | Args work like c_type_print_varspec_prefix. */ | |
547 | ||
548 | void | |
fba45db2 KB |
549 | c_type_print_varspec_suffix (struct type *type, struct ui_file *stream, |
550 | int show, int passed_a_ptr, int demangled_args) | |
c906108c SS |
551 | { |
552 | if (type == 0) | |
553 | return; | |
554 | ||
555 | if (TYPE_NAME (type) && show <= 0) | |
556 | return; | |
557 | ||
558 | QUIT; | |
559 | ||
560 | switch (TYPE_CODE (type)) | |
561 | { | |
562 | case TYPE_CODE_ARRAY: | |
563 | if (passed_a_ptr) | |
564 | fprintf_filtered (stream, ")"); | |
c5aa993b | 565 | |
c906108c SS |
566 | fprintf_filtered (stream, "["); |
567 | if (TYPE_LENGTH (type) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0 | |
c5aa993b | 568 | && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED) |
c906108c SS |
569 | fprintf_filtered (stream, "%d", |
570 | (TYPE_LENGTH (type) | |
571 | / TYPE_LENGTH (TYPE_TARGET_TYPE (type)))); | |
572 | fprintf_filtered (stream, "]"); | |
c5aa993b | 573 | |
c906108c SS |
574 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); |
575 | break; | |
576 | ||
577 | case TYPE_CODE_MEMBER: | |
578 | if (passed_a_ptr) | |
579 | fprintf_filtered (stream, ")"); | |
580 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); | |
581 | break; | |
582 | ||
583 | case TYPE_CODE_METHOD: | |
584 | if (passed_a_ptr) | |
585 | fprintf_filtered (stream, ")"); | |
586 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); | |
587 | if (passed_a_ptr) | |
588 | { | |
589 | c_type_print_args (type, stream); | |
590 | } | |
591 | break; | |
592 | ||
593 | case TYPE_CODE_PTR: | |
594 | case TYPE_CODE_REF: | |
595 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0); | |
596 | break; | |
597 | ||
598 | case TYPE_CODE_FUNC: | |
599 | if (passed_a_ptr) | |
600 | fprintf_filtered (stream, ")"); | |
601 | if (!demangled_args) | |
c5aa993b JM |
602 | { |
603 | int i, len = TYPE_NFIELDS (type); | |
c906108c | 604 | fprintf_filtered (stream, "("); |
c5aa993b JM |
605 | if ((len == 0) && (current_language->la_language == language_cplus)) |
606 | { | |
607 | fprintf_filtered (stream, "void"); | |
608 | } | |
609 | else | |
610 | for (i = 0; i < len; i++) | |
611 | { | |
612 | if (i > 0) | |
613 | { | |
614 | fputs_filtered (", ", stream); | |
615 | wrap_here (" "); | |
616 | } | |
617 | c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0); | |
618 | } | |
c906108c SS |
619 | fprintf_filtered (stream, ")"); |
620 | } | |
621 | c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, | |
622 | passed_a_ptr, 0); | |
623 | break; | |
624 | ||
625 | case TYPE_CODE_UNDEF: | |
626 | case TYPE_CODE_STRUCT: | |
627 | case TYPE_CODE_UNION: | |
628 | case TYPE_CODE_ENUM: | |
629 | case TYPE_CODE_INT: | |
630 | case TYPE_CODE_FLT: | |
631 | case TYPE_CODE_VOID: | |
632 | case TYPE_CODE_ERROR: | |
633 | case TYPE_CODE_CHAR: | |
634 | case TYPE_CODE_BOOL: | |
635 | case TYPE_CODE_SET: | |
636 | case TYPE_CODE_RANGE: | |
637 | case TYPE_CODE_STRING: | |
638 | case TYPE_CODE_BITSTRING: | |
639 | case TYPE_CODE_COMPLEX: | |
640 | case TYPE_CODE_TYPEDEF: | |
c4093a6a | 641 | case TYPE_CODE_TEMPLATE: |
c906108c | 642 | /* These types do not need a suffix. They are listed so that |
c5aa993b | 643 | gcc -Wall will report types that may not have been considered. */ |
c906108c | 644 | break; |
c4093a6a JM |
645 | default: |
646 | error ("type not handled in c_type_print_varspec_suffix()"); | |
647 | break; | |
c906108c SS |
648 | } |
649 | } | |
650 | ||
651 | /* Print the name of the type (or the ultimate pointer target, | |
652 | function value or array element), or the description of a | |
653 | structure or union. | |
654 | ||
655 | SHOW positive means print details about the type (e.g. enum values), | |
656 | and print structure elements passing SHOW - 1 for show. | |
657 | SHOW negative means just print the type name or struct tag if there is one. | |
658 | If there is no name, print something sensible but concise like | |
659 | "struct {...}". | |
660 | SHOW zero means just print the type name or struct tag if there is one. | |
661 | If there is no name, print something sensible but not as concise like | |
662 | "struct {int x; int y;}". | |
663 | ||
664 | LEVEL is the number of spaces to indent by. | |
665 | We increase it for some recursive calls. */ | |
666 | ||
667 | void | |
fba45db2 KB |
668 | c_type_print_base (struct type *type, struct ui_file *stream, int show, |
669 | int level) | |
c906108c SS |
670 | { |
671 | register int i; | |
672 | register int len; | |
673 | register int lastval; | |
674 | char *mangled_name; | |
675 | char *demangled_name; | |
676 | char *demangled_no_static; | |
c5aa993b JM |
677 | enum |
678 | { | |
679 | s_none, s_public, s_private, s_protected | |
680 | } | |
681 | section_type; | |
c906108c SS |
682 | int need_access_label = 0; |
683 | int j, len2; | |
684 | ||
685 | QUIT; | |
686 | ||
687 | wrap_here (" "); | |
688 | if (type == NULL) | |
689 | { | |
690 | fputs_filtered ("<type unknown>", stream); | |
691 | return; | |
692 | } | |
693 | ||
694 | /* When SHOW is zero or less, and there is a valid type name, then always | |
695 | just print the type name directly from the type. */ | |
696 | /* If we have "typedef struct foo {. . .} bar;" do we want to print it | |
697 | as "struct foo" or as "bar"? Pick the latter, because C++ folk tend | |
698 | to expect things like "class5 *foo" rather than "struct class5 *foo". */ | |
699 | ||
700 | if (show <= 0 | |
701 | && TYPE_NAME (type) != NULL) | |
702 | { | |
703 | c_type_print_cv_qualifier (type, stream, 0, 1); | |
704 | fputs_filtered (TYPE_NAME (type), stream); | |
705 | return; | |
706 | } | |
707 | ||
708 | CHECK_TYPEDEF (type); | |
c5aa993b | 709 | |
c906108c SS |
710 | switch (TYPE_CODE (type)) |
711 | { | |
712 | case TYPE_CODE_TYPEDEF: | |
713 | case TYPE_CODE_ARRAY: | |
714 | case TYPE_CODE_PTR: | |
715 | case TYPE_CODE_MEMBER: | |
716 | case TYPE_CODE_REF: | |
717 | case TYPE_CODE_FUNC: | |
718 | case TYPE_CODE_METHOD: | |
719 | c_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
720 | break; | |
721 | ||
722 | case TYPE_CODE_STRUCT: | |
723 | c_type_print_cv_qualifier (type, stream, 0, 1); | |
724 | /* Note TYPE_CODE_STRUCT and TYPE_CODE_CLASS have the same value, | |
725 | * so we use another means for distinguishing them. | |
726 | */ | |
c5aa993b JM |
727 | if (HAVE_CPLUS_STRUCT (type)) |
728 | { | |
729 | switch (TYPE_DECLARED_TYPE (type)) | |
730 | { | |
731 | case DECLARED_TYPE_CLASS: | |
732 | fprintf_filtered (stream, "class "); | |
733 | break; | |
734 | case DECLARED_TYPE_UNION: | |
735 | fprintf_filtered (stream, "union "); | |
736 | break; | |
737 | case DECLARED_TYPE_STRUCT: | |
738 | fprintf_filtered (stream, "struct "); | |
739 | break; | |
740 | default: | |
741 | /* If there is a CPLUS_STRUCT, assume class if not | |
742 | * otherwise specified in the declared_type field. | |
743 | */ | |
744 | fprintf_filtered (stream, "class "); | |
745 | break; | |
746 | } /* switch */ | |
747 | } | |
748 | else | |
749 | { | |
750 | /* If not CPLUS_STRUCT, then assume it's a C struct */ | |
751 | fprintf_filtered (stream, "struct "); | |
752 | } | |
c906108c SS |
753 | goto struct_union; |
754 | ||
755 | case TYPE_CODE_UNION: | |
756 | c_type_print_cv_qualifier (type, stream, 0, 1); | |
757 | fprintf_filtered (stream, "union "); | |
758 | ||
759 | struct_union: | |
760 | ||
761 | /* Print the tag if it exists. | |
762 | * The HP aCC compiler emits | |
763 | * a spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}" | |
764 | * tag for unnamed struct/union/enum's, which we don't | |
765 | * want to print. | |
766 | */ | |
767 | if (TYPE_TAG_NAME (type) != NULL && | |
c5aa993b | 768 | strncmp (TYPE_TAG_NAME (type), "{unnamed", 8)) |
c906108c SS |
769 | { |
770 | fputs_filtered (TYPE_TAG_NAME (type), stream); | |
771 | if (show > 0) | |
772 | fputs_filtered (" ", stream); | |
773 | } | |
774 | wrap_here (" "); | |
775 | if (show < 0) | |
776 | { | |
777 | /* If we just printed a tag name, no need to print anything else. */ | |
778 | if (TYPE_TAG_NAME (type) == NULL) | |
779 | fprintf_filtered (stream, "{...}"); | |
780 | } | |
781 | else if (show > 0 || TYPE_TAG_NAME (type) == NULL) | |
782 | { | |
783 | cp_type_print_derivation_info (stream, type); | |
c5aa993b | 784 | |
c906108c SS |
785 | fprintf_filtered (stream, "{\n"); |
786 | if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0)) | |
787 | { | |
788 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
789 | fprintfi_filtered (level + 4, stream, "<incomplete type>\n"); | |
790 | else | |
791 | fprintfi_filtered (level + 4, stream, "<no data fields>\n"); | |
792 | } | |
793 | ||
794 | /* Start off with no specific section type, so we can print | |
795 | one for the first field we find, and use that section type | |
796 | thereafter until we find another type. */ | |
797 | ||
798 | section_type = s_none; | |
799 | ||
c5aa993b JM |
800 | /* For a class, if all members are private, there's no need |
801 | for a "private:" label; similarly, for a struct or union | |
802 | masquerading as a class, if all members are public, there's | |
803 | no need for a "public:" label. */ | |
804 | ||
805 | if ((TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_CLASS) || | |
806 | (TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_TEMPLATE)) | |
807 | { | |
808 | QUIT; | |
809 | len = TYPE_NFIELDS (type); | |
810 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) | |
811 | if (!TYPE_FIELD_PRIVATE (type, i)) | |
812 | { | |
813 | need_access_label = 1; | |
814 | break; | |
815 | } | |
816 | QUIT; | |
817 | if (!need_access_label) | |
818 | { | |
819 | len2 = TYPE_NFN_FIELDS (type); | |
820 | for (j = 0; j < len2; j++) | |
821 | { | |
822 | len = TYPE_FN_FIELDLIST_LENGTH (type, j); | |
823 | for (i = 0; i < len; i++) | |
824 | if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i)) | |
825 | { | |
826 | need_access_label = 1; | |
827 | break; | |
828 | } | |
829 | if (need_access_label) | |
830 | break; | |
831 | } | |
832 | } | |
833 | } | |
834 | else if ((TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_STRUCT) || | |
835 | (TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_UNION)) | |
836 | { | |
837 | QUIT; | |
838 | len = TYPE_NFIELDS (type); | |
839 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) | |
840 | if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i)) | |
841 | { | |
842 | need_access_label = 1; | |
843 | break; | |
844 | } | |
845 | QUIT; | |
846 | if (!need_access_label) | |
847 | { | |
848 | len2 = TYPE_NFN_FIELDS (type); | |
849 | for (j = 0; j < len2; j++) | |
850 | { | |
851 | QUIT; | |
852 | len = TYPE_FN_FIELDLIST_LENGTH (type, j); | |
853 | for (i = 0; i < len; i++) | |
854 | if (TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i) || | |
855 | TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type, j), i)) | |
856 | { | |
857 | need_access_label = 1; | |
858 | break; | |
859 | } | |
860 | if (need_access_label) | |
861 | break; | |
862 | } | |
863 | } | |
864 | } | |
c906108c SS |
865 | |
866 | /* If there is a base class for this type, | |
867 | do not print the field that it occupies. */ | |
868 | ||
869 | len = TYPE_NFIELDS (type); | |
870 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) | |
871 | { | |
872 | QUIT; | |
873 | /* Don't print out virtual function table. */ | |
c5aa993b JM |
874 | /* HP ANSI C++ case */ |
875 | if (TYPE_HAS_VTABLE (type) && (STREQN (TYPE_FIELD_NAME (type, i), "__vfp", 5))) | |
876 | continue; | |
877 | /* Other compilers */ | |
c906108c SS |
878 | if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5) |
879 | && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5])) | |
880 | continue; | |
881 | ||
882 | /* If this is a C++ class we can print the various C++ section | |
c5aa993b | 883 | labels. */ |
c906108c SS |
884 | |
885 | if (HAVE_CPLUS_STRUCT (type) && need_access_label) | |
886 | { | |
887 | if (TYPE_FIELD_PROTECTED (type, i)) | |
888 | { | |
889 | if (section_type != s_protected) | |
890 | { | |
891 | section_type = s_protected; | |
892 | fprintfi_filtered (level + 2, stream, | |
893 | "protected:\n"); | |
894 | } | |
895 | } | |
896 | else if (TYPE_FIELD_PRIVATE (type, i)) | |
897 | { | |
898 | if (section_type != s_private) | |
899 | { | |
900 | section_type = s_private; | |
901 | fprintfi_filtered (level + 2, stream, "private:\n"); | |
902 | } | |
903 | } | |
904 | else | |
905 | { | |
906 | if (section_type != s_public) | |
907 | { | |
908 | section_type = s_public; | |
909 | fprintfi_filtered (level + 2, stream, "public:\n"); | |
910 | } | |
911 | } | |
912 | } | |
913 | ||
914 | print_spaces_filtered (level + 4, stream); | |
915 | if (TYPE_FIELD_STATIC (type, i)) | |
916 | { | |
917 | fprintf_filtered (stream, "static "); | |
918 | } | |
919 | c_print_type (TYPE_FIELD_TYPE (type, i), | |
920 | TYPE_FIELD_NAME (type, i), | |
921 | stream, show - 1, level + 4); | |
922 | if (!TYPE_FIELD_STATIC (type, i) | |
923 | && TYPE_FIELD_PACKED (type, i)) | |
924 | { | |
925 | /* It is a bitfield. This code does not attempt | |
926 | to look at the bitpos and reconstruct filler, | |
927 | unnamed fields. This would lead to misleading | |
928 | results if the compiler does not put out fields | |
929 | for such things (I don't know what it does). */ | |
930 | fprintf_filtered (stream, " : %d", | |
931 | TYPE_FIELD_BITSIZE (type, i)); | |
932 | } | |
933 | fprintf_filtered (stream, ";\n"); | |
934 | } | |
935 | ||
936 | /* If there are both fields and methods, put a space between. */ | |
937 | len = TYPE_NFN_FIELDS (type); | |
938 | if (len && section_type != s_none) | |
c5aa993b | 939 | fprintf_filtered (stream, "\n"); |
c906108c SS |
940 | |
941 | /* C++: print out the methods */ | |
942 | for (i = 0; i < len; i++) | |
943 | { | |
944 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); | |
945 | int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); | |
946 | char *method_name = TYPE_FN_FIELDLIST_NAME (type, i); | |
947 | char *name = type_name_no_tag (type); | |
c5aa993b | 948 | int is_constructor = name && STREQ (method_name, name); |
c906108c SS |
949 | for (j = 0; j < len2; j++) |
950 | { | |
951 | char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); | |
c5aa993b JM |
952 | int is_full_physname_constructor = |
953 | ((physname[0] == '_' && physname[1] == '_' | |
954 | && strchr ("0123456789Qt", physname[2])) | |
955 | || STREQN (physname, "__ct__", 6) | |
956 | || DESTRUCTOR_PREFIX_P (physname) | |
957 | || STREQN (physname, "__dt__", 6)); | |
c906108c SS |
958 | |
959 | QUIT; | |
960 | if (TYPE_FN_FIELD_PROTECTED (f, j)) | |
961 | { | |
962 | if (section_type != s_protected) | |
963 | { | |
964 | section_type = s_protected; | |
965 | fprintfi_filtered (level + 2, stream, | |
966 | "protected:\n"); | |
967 | } | |
968 | } | |
969 | else if (TYPE_FN_FIELD_PRIVATE (f, j)) | |
970 | { | |
971 | if (section_type != s_private) | |
972 | { | |
973 | section_type = s_private; | |
974 | fprintfi_filtered (level + 2, stream, "private:\n"); | |
975 | } | |
976 | } | |
977 | else | |
978 | { | |
979 | if (section_type != s_public) | |
980 | { | |
981 | section_type = s_public; | |
982 | fprintfi_filtered (level + 2, stream, "public:\n"); | |
983 | } | |
984 | } | |
985 | ||
986 | print_spaces_filtered (level + 4, stream); | |
987 | if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) | |
988 | fprintf_filtered (stream, "virtual "); | |
989 | else if (TYPE_FN_FIELD_STATIC_P (f, j)) | |
990 | fprintf_filtered (stream, "static "); | |
991 | if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0) | |
992 | { | |
993 | /* Keep GDB from crashing here. */ | |
994 | fprintf_filtered (stream, "<undefined type> %s;\n", | |
c5aa993b | 995 | TYPE_FN_FIELD_PHYSNAME (f, j)); |
c906108c SS |
996 | break; |
997 | } | |
c5aa993b JM |
998 | else if (!is_constructor && /* constructors don't have declared types */ |
999 | !is_full_physname_constructor && /* " " */ | |
dfcd3bfb | 1000 | !is_type_conversion_operator (type, i, j)) |
c906108c SS |
1001 | { |
1002 | type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), | |
1003 | "", stream, -1); | |
1004 | fputs_filtered (" ", stream); | |
1005 | } | |
1006 | if (TYPE_FN_FIELD_STUB (f, j)) | |
1007 | /* Build something we can demangle. */ | |
1008 | mangled_name = gdb_mangle_name (type, i, j); | |
1009 | else | |
1010 | mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j); | |
1011 | ||
1012 | demangled_name = | |
1013 | cplus_demangle (mangled_name, | |
1014 | DMGL_ANSI | DMGL_PARAMS); | |
1015 | if (demangled_name == NULL) | |
1016 | { | |
1017 | /* in some cases (for instance with the HP demangling), | |
c5aa993b JM |
1018 | if a function has more than 10 arguments, |
1019 | the demangling will fail. | |
1020 | Let's try to reconstruct the function signature from | |
1021 | the symbol information */ | |
c906108c SS |
1022 | if (!TYPE_FN_FIELD_STUB (f, j)) |
1023 | cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j), "", | |
1024 | method_name, | |
c5aa993b | 1025 | TYPE_FN_FIELD_STATIC_P (f, j), |
c906108c SS |
1026 | stream); |
1027 | else | |
1028 | fprintf_filtered (stream, "<badly mangled name '%s'>", | |
1029 | mangled_name); | |
1030 | } | |
1031 | else | |
1032 | { | |
1033 | char *p; | |
dfcd3bfb JM |
1034 | char *demangled_no_class |
1035 | = remove_qualifiers (demangled_name); | |
c5aa993b | 1036 | |
dfcd3bfb | 1037 | /* get rid of the `static' appended by the demangler */ |
c906108c SS |
1038 | p = strstr (demangled_no_class, " static"); |
1039 | if (p != NULL) | |
1040 | { | |
1041 | int length = p - demangled_no_class; | |
1042 | demangled_no_static = (char *) xmalloc (length + 1); | |
1043 | strncpy (demangled_no_static, demangled_no_class, length); | |
c5aa993b | 1044 | *(demangled_no_static + length) = '\0'; |
c906108c SS |
1045 | fputs_filtered (demangled_no_static, stream); |
1046 | free (demangled_no_static); | |
1047 | } | |
1048 | else | |
1049 | fputs_filtered (demangled_no_class, stream); | |
1050 | free (demangled_name); | |
1051 | } | |
1052 | ||
1053 | if (TYPE_FN_FIELD_STUB (f, j)) | |
1054 | free (mangled_name); | |
1055 | ||
1056 | fprintf_filtered (stream, ";\n"); | |
1057 | } | |
1058 | } | |
1059 | ||
c4093a6a JM |
1060 | fprintfi_filtered (level, stream, "}"); |
1061 | ||
c5aa993b JM |
1062 | if (TYPE_LOCALTYPE_PTR (type) && show >= 0) |
1063 | fprintfi_filtered (level, stream, " (Local at %s:%d)\n", | |
1064 | TYPE_LOCALTYPE_FILE (type), | |
1065 | TYPE_LOCALTYPE_LINE (type)); | |
c906108c | 1066 | } |
c5aa993b JM |
1067 | if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE) |
1068 | goto go_back; | |
c906108c SS |
1069 | break; |
1070 | ||
1071 | case TYPE_CODE_ENUM: | |
1072 | c_type_print_cv_qualifier (type, stream, 0, 1); | |
1073 | /* HP C supports sized enums */ | |
1074 | if (hp_som_som_object_present) | |
c5aa993b JM |
1075 | switch (TYPE_LENGTH (type)) |
1076 | { | |
1077 | case 1: | |
1078 | fputs_filtered ("char ", stream); | |
1079 | break; | |
1080 | case 2: | |
1081 | fputs_filtered ("short ", stream); | |
1082 | break; | |
1083 | default: | |
1084 | break; | |
1085 | } | |
1086 | fprintf_filtered (stream, "enum "); | |
c906108c SS |
1087 | /* Print the tag name if it exists. |
1088 | The aCC compiler emits a spurious | |
1089 | "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}" | |
1090 | tag for unnamed struct/union/enum's, which we don't | |
1091 | want to print. */ | |
1092 | if (TYPE_TAG_NAME (type) != NULL && | |
c5aa993b | 1093 | strncmp (TYPE_TAG_NAME (type), "{unnamed", 8)) |
c906108c SS |
1094 | { |
1095 | fputs_filtered (TYPE_TAG_NAME (type), stream); | |
1096 | if (show > 0) | |
1097 | fputs_filtered (" ", stream); | |
1098 | } | |
1099 | ||
1100 | wrap_here (" "); | |
1101 | if (show < 0) | |
1102 | { | |
1103 | /* If we just printed a tag name, no need to print anything else. */ | |
1104 | if (TYPE_TAG_NAME (type) == NULL) | |
1105 | fprintf_filtered (stream, "{...}"); | |
1106 | } | |
1107 | else if (show > 0 || TYPE_TAG_NAME (type) == NULL) | |
1108 | { | |
1109 | fprintf_filtered (stream, "{"); | |
1110 | len = TYPE_NFIELDS (type); | |
1111 | lastval = 0; | |
1112 | for (i = 0; i < len; i++) | |
1113 | { | |
1114 | QUIT; | |
c5aa993b JM |
1115 | if (i) |
1116 | fprintf_filtered (stream, ", "); | |
c906108c SS |
1117 | wrap_here (" "); |
1118 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
1119 | if (lastval != TYPE_FIELD_BITPOS (type, i)) | |
1120 | { | |
1121 | fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i)); | |
1122 | lastval = TYPE_FIELD_BITPOS (type, i); | |
1123 | } | |
1124 | lastval++; | |
1125 | } | |
1126 | fprintf_filtered (stream, "}"); | |
1127 | } | |
1128 | break; | |
1129 | ||
1130 | case TYPE_CODE_VOID: | |
1131 | fprintf_filtered (stream, "void"); | |
1132 | break; | |
1133 | ||
1134 | case TYPE_CODE_UNDEF: | |
1135 | fprintf_filtered (stream, "struct <unknown>"); | |
1136 | break; | |
1137 | ||
1138 | case TYPE_CODE_ERROR: | |
1139 | fprintf_filtered (stream, "<unknown type>"); | |
1140 | break; | |
1141 | ||
1142 | case TYPE_CODE_RANGE: | |
1143 | /* This should not occur */ | |
1144 | fprintf_filtered (stream, "<range type>"); | |
1145 | break; | |
1146 | ||
1147 | case TYPE_CODE_TEMPLATE: | |
1148 | /* Called on "ptype t" where "t" is a template. | |
1149 | Prints the template header (with args), e.g.: | |
c5aa993b | 1150 | template <class T1, class T2> class " |
c906108c SS |
1151 | and then merges with the struct/union/class code to |
1152 | print the rest of the definition. */ | |
1153 | c_type_print_cv_qualifier (type, stream, 0, 1); | |
1154 | fprintf_filtered (stream, "template <"); | |
c5aa993b JM |
1155 | for (i = 0; i < TYPE_NTEMPLATE_ARGS (type); i++) |
1156 | { | |
1157 | struct template_arg templ_arg; | |
1158 | templ_arg = TYPE_TEMPLATE_ARG (type, i); | |
1159 | fprintf_filtered (stream, "class %s", templ_arg.name); | |
1160 | if (i < TYPE_NTEMPLATE_ARGS (type) - 1) | |
1161 | fprintf_filtered (stream, ", "); | |
1162 | } | |
c906108c SS |
1163 | fprintf_filtered (stream, "> class "); |
1164 | /* Yuck, factor this out to a subroutine so we can call | |
1165 | it and return to the point marked with the "goback:" label... - RT */ | |
c5aa993b JM |
1166 | goto struct_union; |
1167 | go_back: | |
1168 | if (TYPE_NINSTANTIATIONS (type) > 0) | |
1169 | { | |
1170 | fprintf_filtered (stream, "\ntemplate instantiations:\n"); | |
1171 | for (i = 0; i < TYPE_NINSTANTIATIONS (type); i++) | |
1172 | { | |
1173 | fprintf_filtered (stream, " "); | |
1174 | c_type_print_base (TYPE_INSTANTIATION (type, i), stream, 0, level); | |
1175 | if (i < TYPE_NINSTANTIATIONS (type) - 1) | |
1176 | fprintf_filtered (stream, "\n"); | |
1177 | } | |
1178 | } | |
c906108c | 1179 | break; |
c5aa993b | 1180 | |
c906108c SS |
1181 | default: |
1182 | /* Handle types not explicitly handled by the other cases, | |
c5aa993b JM |
1183 | such as fundamental types. For these, just print whatever |
1184 | the type name is, as recorded in the type itself. If there | |
1185 | is no type name, then complain. */ | |
c906108c SS |
1186 | if (TYPE_NAME (type) != NULL) |
1187 | { | |
c5aa993b | 1188 | c_type_print_cv_qualifier (type, stream, 0, 1); |
c906108c SS |
1189 | fputs_filtered (TYPE_NAME (type), stream); |
1190 | } | |
1191 | else | |
1192 | { | |
1193 | /* At least for dump_symtab, it is important that this not be | |
1194 | an error (). */ | |
1195 | fprintf_filtered (stream, "<invalid type code %d>", | |
1196 | TYPE_CODE (type)); | |
1197 | } | |
1198 | break; | |
1199 | } | |
1200 | } |