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