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