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