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