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