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