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