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