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