15796c8dcSSimon Schubert /* Support for printing C and C++ types for GDB, the GNU debugger.
2*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc.
35796c8dcSSimon Schubert
45796c8dcSSimon Schubert This file is part of GDB.
55796c8dcSSimon Schubert
65796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
75796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
85796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
95796c8dcSSimon Schubert (at your option) any later version.
105796c8dcSSimon Schubert
115796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
125796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
135796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
145796c8dcSSimon Schubert GNU General Public License for more details.
155796c8dcSSimon Schubert
165796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
175796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
185796c8dcSSimon Schubert
195796c8dcSSimon Schubert #include "defs.h"
205796c8dcSSimon Schubert #include "gdb_obstack.h"
21c50c785cSJohn Marino #include "bfd.h" /* Binary File Description. */
225796c8dcSSimon Schubert #include "symtab.h"
235796c8dcSSimon Schubert #include "gdbtypes.h"
245796c8dcSSimon Schubert #include "expression.h"
255796c8dcSSimon Schubert #include "value.h"
265796c8dcSSimon Schubert #include "gdbcore.h"
275796c8dcSSimon Schubert #include "target.h"
285796c8dcSSimon Schubert #include "language.h"
295796c8dcSSimon Schubert #include "demangle.h"
305796c8dcSSimon Schubert #include "c-lang.h"
315796c8dcSSimon Schubert #include "typeprint.h"
325796c8dcSSimon Schubert #include "cp-abi.h"
33cf7f2e2dSJohn Marino #include "jv-lang.h"
345796c8dcSSimon Schubert #include "gdb_string.h"
355796c8dcSSimon Schubert #include <errno.h>
36*ef5ccd6cSJohn Marino #include "cp-support.h"
375796c8dcSSimon Schubert
38c50c785cSJohn Marino static void c_type_print_varspec_prefix (struct type *,
39c50c785cSJohn Marino struct ui_file *,
40*ef5ccd6cSJohn Marino int, int, int,
41*ef5ccd6cSJohn Marino const struct type_print_options *);
425796c8dcSSimon Schubert
435796c8dcSSimon Schubert /* Print "const", "volatile", or address space modifiers. */
44c50c785cSJohn Marino static void c_type_print_modifier (struct type *,
45c50c785cSJohn Marino struct ui_file *,
465796c8dcSSimon Schubert int, int);
475796c8dcSSimon Schubert
48*ef5ccd6cSJohn Marino
49*ef5ccd6cSJohn Marino /* A callback function for cp_canonicalize_string_full that uses
50*ef5ccd6cSJohn Marino find_typedef_in_hash. */
51*ef5ccd6cSJohn Marino
52*ef5ccd6cSJohn Marino static const char *
find_typedef_for_canonicalize(struct type * t,void * data)53*ef5ccd6cSJohn Marino find_typedef_for_canonicalize (struct type *t, void *data)
54*ef5ccd6cSJohn Marino {
55*ef5ccd6cSJohn Marino return find_typedef_in_hash (data, t);
56*ef5ccd6cSJohn Marino }
57*ef5ccd6cSJohn Marino
58*ef5ccd6cSJohn Marino /* Print NAME on STREAM. If the 'raw' field of FLAGS is not set,
59*ef5ccd6cSJohn Marino canonicalize NAME using the local typedefs first. */
60*ef5ccd6cSJohn Marino
61*ef5ccd6cSJohn Marino static void
print_name_maybe_canonical(const char * name,const struct type_print_options * flags,struct ui_file * stream)62*ef5ccd6cSJohn Marino print_name_maybe_canonical (const char *name,
63*ef5ccd6cSJohn Marino const struct type_print_options *flags,
64*ef5ccd6cSJohn Marino struct ui_file *stream)
65*ef5ccd6cSJohn Marino {
66*ef5ccd6cSJohn Marino char *s = NULL;
67*ef5ccd6cSJohn Marino
68*ef5ccd6cSJohn Marino if (!flags->raw)
69*ef5ccd6cSJohn Marino s = cp_canonicalize_string_full (name,
70*ef5ccd6cSJohn Marino find_typedef_for_canonicalize,
71*ef5ccd6cSJohn Marino (void *) flags);
72*ef5ccd6cSJohn Marino
73*ef5ccd6cSJohn Marino fputs_filtered (s ? s : name, stream);
74*ef5ccd6cSJohn Marino xfree (s);
75*ef5ccd6cSJohn Marino }
76*ef5ccd6cSJohn Marino
77*ef5ccd6cSJohn Marino
78*ef5ccd6cSJohn Marino
795796c8dcSSimon Schubert /* LEVEL is the depth to indent lines by. */
805796c8dcSSimon Schubert
815796c8dcSSimon Schubert void
c_print_type(struct type * type,const char * varstring,struct ui_file * stream,int show,int level,const struct type_print_options * flags)82c50c785cSJohn Marino c_print_type (struct type *type,
83c50c785cSJohn Marino const char *varstring,
84c50c785cSJohn Marino struct ui_file *stream,
85*ef5ccd6cSJohn Marino int show, int level,
86*ef5ccd6cSJohn Marino const struct type_print_options *flags)
875796c8dcSSimon Schubert {
885796c8dcSSimon Schubert enum type_code code;
895796c8dcSSimon Schubert int demangled_args;
905796c8dcSSimon Schubert int need_post_space;
91*ef5ccd6cSJohn Marino const char *local_name;
925796c8dcSSimon Schubert
935796c8dcSSimon Schubert if (show > 0)
945796c8dcSSimon Schubert CHECK_TYPEDEF (type);
955796c8dcSSimon Schubert
96*ef5ccd6cSJohn Marino local_name = find_typedef_in_hash (flags, type);
97*ef5ccd6cSJohn Marino if (local_name != NULL)
98*ef5ccd6cSJohn Marino {
99*ef5ccd6cSJohn Marino fputs_filtered (local_name, stream);
100*ef5ccd6cSJohn Marino if (varstring != NULL && *varstring != '\0')
101*ef5ccd6cSJohn Marino fputs_filtered (" ", stream);
102*ef5ccd6cSJohn Marino }
103*ef5ccd6cSJohn Marino else
104*ef5ccd6cSJohn Marino {
105*ef5ccd6cSJohn Marino c_type_print_base (type, stream, show, level, flags);
1065796c8dcSSimon Schubert code = TYPE_CODE (type);
1075796c8dcSSimon Schubert if ((varstring != NULL && *varstring != '\0')
1085796c8dcSSimon Schubert /* Need a space if going to print stars or brackets;
1095796c8dcSSimon Schubert but not if we will print just a type name. */
110cf7f2e2dSJohn Marino || ((show > 0 || TYPE_NAME (type) == 0)
111cf7f2e2dSJohn Marino && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
1125796c8dcSSimon Schubert || code == TYPE_CODE_METHOD
113*ef5ccd6cSJohn Marino || (code == TYPE_CODE_ARRAY
114*ef5ccd6cSJohn Marino && !TYPE_VECTOR (type))
1155796c8dcSSimon Schubert || code == TYPE_CODE_MEMBERPTR
1165796c8dcSSimon Schubert || code == TYPE_CODE_METHODPTR
1175796c8dcSSimon Schubert || code == TYPE_CODE_REF)))
1185796c8dcSSimon Schubert fputs_filtered (" ", stream);
1195796c8dcSSimon Schubert need_post_space = (varstring != NULL && strcmp (varstring, "") != 0);
120*ef5ccd6cSJohn Marino c_type_print_varspec_prefix (type, stream, show, 0, need_post_space,
121*ef5ccd6cSJohn Marino flags);
122*ef5ccd6cSJohn Marino }
1235796c8dcSSimon Schubert
1245796c8dcSSimon Schubert if (varstring != NULL)
1255796c8dcSSimon Schubert {
1265796c8dcSSimon Schubert fputs_filtered (varstring, stream);
1275796c8dcSSimon Schubert
128c50c785cSJohn Marino /* For demangled function names, we have the arglist as part of
129c50c785cSJohn Marino the name, so don't print an additional pair of ()'s. */
130*ef5ccd6cSJohn Marino if (local_name == NULL)
131*ef5ccd6cSJohn Marino {
1325796c8dcSSimon Schubert demangled_args = strchr (varstring, '(') != NULL;
133c50c785cSJohn Marino c_type_print_varspec_suffix (type, stream, show,
134*ef5ccd6cSJohn Marino 0, demangled_args,
135*ef5ccd6cSJohn Marino flags);
136*ef5ccd6cSJohn Marino }
1375796c8dcSSimon Schubert }
1385796c8dcSSimon Schubert }
1395796c8dcSSimon Schubert
1405796c8dcSSimon Schubert /* Print a typedef using C syntax. TYPE is the underlying type.
1415796c8dcSSimon Schubert NEW_SYMBOL is the symbol naming the type. STREAM is the stream on
1425796c8dcSSimon Schubert which to print. */
1435796c8dcSSimon Schubert
1445796c8dcSSimon Schubert void
c_print_typedef(struct type * type,struct symbol * new_symbol,struct ui_file * stream)145c50c785cSJohn Marino c_print_typedef (struct type *type,
146c50c785cSJohn Marino struct symbol *new_symbol,
1475796c8dcSSimon Schubert struct ui_file *stream)
1485796c8dcSSimon Schubert {
1495796c8dcSSimon Schubert CHECK_TYPEDEF (type);
1505796c8dcSSimon Schubert fprintf_filtered (stream, "typedef ");
1515796c8dcSSimon Schubert type_print (type, "", stream, 0);
1525796c8dcSSimon Schubert if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0
1535796c8dcSSimon Schubert || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))),
154cf7f2e2dSJohn Marino SYMBOL_LINKAGE_NAME (new_symbol)) != 0
155cf7f2e2dSJohn Marino || TYPE_CODE (SYMBOL_TYPE (new_symbol)) == TYPE_CODE_TYPEDEF)
1565796c8dcSSimon Schubert fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol));
1575796c8dcSSimon Schubert fprintf_filtered (stream, ";\n");
1585796c8dcSSimon Schubert }
1595796c8dcSSimon Schubert
1605796c8dcSSimon Schubert /* If TYPE is a derived type, then print out derivation information.
161c50c785cSJohn Marino Print only the actual base classes of this type, not the base
162c50c785cSJohn Marino classes of the base classes. I.e. for the derivation hierarchy:
1635796c8dcSSimon Schubert
1645796c8dcSSimon Schubert class A { int a; };
1655796c8dcSSimon Schubert class B : public A {int b; };
1665796c8dcSSimon Schubert class C : public B {int c; };
1675796c8dcSSimon Schubert
1685796c8dcSSimon Schubert Print the type of class C as:
1695796c8dcSSimon Schubert
1705796c8dcSSimon Schubert class C : public B {
1715796c8dcSSimon Schubert int c;
1725796c8dcSSimon Schubert }
1735796c8dcSSimon Schubert
174c50c785cSJohn Marino Not as the following (like gdb used to), which is not legal C++
175c50c785cSJohn Marino syntax for derived types and may be confused with the multiple
176c50c785cSJohn Marino inheritance form:
1775796c8dcSSimon Schubert
1785796c8dcSSimon Schubert class C : public B : public A {
1795796c8dcSSimon Schubert int c;
1805796c8dcSSimon Schubert }
1815796c8dcSSimon Schubert
182c50c785cSJohn Marino In general, gdb should try to print the types as closely as
183*ef5ccd6cSJohn Marino possible to the form that they appear in the source code. */
1845796c8dcSSimon Schubert
1855796c8dcSSimon Schubert static void
cp_type_print_derivation_info(struct ui_file * stream,struct type * type,const struct type_print_options * flags)186c50c785cSJohn Marino cp_type_print_derivation_info (struct ui_file *stream,
187*ef5ccd6cSJohn Marino struct type *type,
188*ef5ccd6cSJohn Marino const struct type_print_options *flags)
1895796c8dcSSimon Schubert {
190*ef5ccd6cSJohn Marino const char *name;
1915796c8dcSSimon Schubert int i;
1925796c8dcSSimon Schubert
1935796c8dcSSimon Schubert for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1945796c8dcSSimon Schubert {
195*ef5ccd6cSJohn Marino wrap_here (" ");
1965796c8dcSSimon Schubert fputs_filtered (i == 0 ? ": " : ", ", stream);
1975796c8dcSSimon Schubert fprintf_filtered (stream, "%s%s ",
198c50c785cSJohn Marino BASETYPE_VIA_PUBLIC (type, i)
199c50c785cSJohn Marino ? "public" : (TYPE_FIELD_PROTECTED (type, i)
200c50c785cSJohn Marino ? "protected" : "private"),
2015796c8dcSSimon Schubert BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
2025796c8dcSSimon Schubert name = type_name_no_tag (TYPE_BASECLASS (type, i));
203*ef5ccd6cSJohn Marino if (name)
204*ef5ccd6cSJohn Marino print_name_maybe_canonical (name, flags, stream);
205*ef5ccd6cSJohn Marino else
206*ef5ccd6cSJohn Marino fprintf_filtered (stream, "(null)");
2075796c8dcSSimon Schubert }
2085796c8dcSSimon Schubert if (i > 0)
2095796c8dcSSimon Schubert {
2105796c8dcSSimon Schubert fputs_filtered (" ", stream);
2115796c8dcSSimon Schubert }
2125796c8dcSSimon Schubert }
2135796c8dcSSimon Schubert
2145796c8dcSSimon Schubert /* Print the C++ method arguments ARGS to the file STREAM. */
2155796c8dcSSimon Schubert
2165796c8dcSSimon Schubert static void
cp_type_print_method_args(struct type * mtype,const char * prefix,const char * varstring,int staticp,struct ui_file * stream,const struct type_print_options * flags)217*ef5ccd6cSJohn Marino cp_type_print_method_args (struct type *mtype, const char *prefix,
218*ef5ccd6cSJohn Marino const char *varstring, int staticp,
219*ef5ccd6cSJohn Marino struct ui_file *stream,
220*ef5ccd6cSJohn Marino const struct type_print_options *flags)
2215796c8dcSSimon Schubert {
2225796c8dcSSimon Schubert struct field *args = TYPE_FIELDS (mtype);
2235796c8dcSSimon Schubert int nargs = TYPE_NFIELDS (mtype);
2245796c8dcSSimon Schubert int varargs = TYPE_VARARGS (mtype);
2255796c8dcSSimon Schubert int i;
2265796c8dcSSimon Schubert
227c50c785cSJohn Marino fprintf_symbol_filtered (stream, prefix,
228c50c785cSJohn Marino language_cplus, DMGL_ANSI);
229c50c785cSJohn Marino fprintf_symbol_filtered (stream, varstring,
230c50c785cSJohn Marino language_cplus, DMGL_ANSI);
2315796c8dcSSimon Schubert fputs_filtered ("(", stream);
2325796c8dcSSimon Schubert
2335796c8dcSSimon Schubert /* Skip the class variable. */
2345796c8dcSSimon Schubert i = staticp ? 0 : 1;
2355796c8dcSSimon Schubert if (nargs > i)
2365796c8dcSSimon Schubert {
2375796c8dcSSimon Schubert while (i < nargs)
2385796c8dcSSimon Schubert {
239*ef5ccd6cSJohn Marino c_print_type (args[i++].type, "", stream, 0, 0, flags);
2405796c8dcSSimon Schubert
2415796c8dcSSimon Schubert if (i == nargs && varargs)
2425796c8dcSSimon Schubert fprintf_filtered (stream, ", ...");
2435796c8dcSSimon Schubert else if (i < nargs)
244*ef5ccd6cSJohn Marino {
2455796c8dcSSimon Schubert fprintf_filtered (stream, ", ");
246*ef5ccd6cSJohn Marino wrap_here (" ");
247*ef5ccd6cSJohn Marino }
2485796c8dcSSimon Schubert }
2495796c8dcSSimon Schubert }
2505796c8dcSSimon Schubert else if (varargs)
2515796c8dcSSimon Schubert fprintf_filtered (stream, "...");
2525796c8dcSSimon Schubert else if (current_language->la_language == language_cplus)
2535796c8dcSSimon Schubert fprintf_filtered (stream, "void");
2545796c8dcSSimon Schubert
2555796c8dcSSimon Schubert fprintf_filtered (stream, ")");
256cf7f2e2dSJohn Marino
257cf7f2e2dSJohn Marino /* For non-static methods, read qualifiers from the type of
258cf7f2e2dSJohn Marino THIS. */
259cf7f2e2dSJohn Marino if (!staticp)
260cf7f2e2dSJohn Marino {
261cf7f2e2dSJohn Marino struct type *domain;
262cf7f2e2dSJohn Marino
263cf7f2e2dSJohn Marino gdb_assert (nargs > 0);
264cf7f2e2dSJohn Marino gdb_assert (TYPE_CODE (args[0].type) == TYPE_CODE_PTR);
265cf7f2e2dSJohn Marino domain = TYPE_TARGET_TYPE (args[0].type);
266cf7f2e2dSJohn Marino
267cf7f2e2dSJohn Marino if (TYPE_CONST (domain))
268cf7f2e2dSJohn Marino fprintf_filtered (stream, " const");
269cf7f2e2dSJohn Marino
270cf7f2e2dSJohn Marino if (TYPE_VOLATILE (domain))
271cf7f2e2dSJohn Marino fprintf_filtered (stream, " volatile");
272*ef5ccd6cSJohn Marino
273*ef5ccd6cSJohn Marino if (TYPE_RESTRICT (domain))
274*ef5ccd6cSJohn Marino fprintf_filtered (stream, " restrict");
275cf7f2e2dSJohn Marino }
2765796c8dcSSimon Schubert }
2775796c8dcSSimon Schubert
2785796c8dcSSimon Schubert
2795796c8dcSSimon Schubert /* Print any asterisks or open-parentheses needed before the
2805796c8dcSSimon Schubert variable name (to describe its type).
2815796c8dcSSimon Schubert
2825796c8dcSSimon Schubert On outermost call, pass 0 for PASSED_A_PTR.
2835796c8dcSSimon Schubert On outermost call, SHOW > 0 means should ignore
2845796c8dcSSimon Schubert any typename for TYPE and show its details.
2855796c8dcSSimon Schubert SHOW is always zero on recursive calls.
2865796c8dcSSimon Schubert
2875796c8dcSSimon Schubert NEED_POST_SPACE is non-zero when a space will be be needed
2885796c8dcSSimon Schubert between a trailing qualifier and a field, variable, or function
2895796c8dcSSimon Schubert name. */
2905796c8dcSSimon Schubert
291c50c785cSJohn Marino static void
c_type_print_varspec_prefix(struct type * type,struct ui_file * stream,int show,int passed_a_ptr,int need_post_space,const struct type_print_options * flags)292c50c785cSJohn Marino c_type_print_varspec_prefix (struct type *type,
293c50c785cSJohn Marino struct ui_file *stream,
294c50c785cSJohn Marino int show, int passed_a_ptr,
295*ef5ccd6cSJohn Marino int need_post_space,
296*ef5ccd6cSJohn Marino const struct type_print_options *flags)
2975796c8dcSSimon Schubert {
298*ef5ccd6cSJohn Marino const char *name;
299cf7f2e2dSJohn Marino
3005796c8dcSSimon Schubert if (type == 0)
3015796c8dcSSimon Schubert return;
3025796c8dcSSimon Schubert
3035796c8dcSSimon Schubert if (TYPE_NAME (type) && show <= 0)
3045796c8dcSSimon Schubert return;
3055796c8dcSSimon Schubert
3065796c8dcSSimon Schubert QUIT;
3075796c8dcSSimon Schubert
3085796c8dcSSimon Schubert switch (TYPE_CODE (type))
3095796c8dcSSimon Schubert {
3105796c8dcSSimon Schubert case TYPE_CODE_PTR:
311c50c785cSJohn Marino c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
312*ef5ccd6cSJohn Marino stream, show, 1, 1, flags);
3135796c8dcSSimon Schubert fprintf_filtered (stream, "*");
3145796c8dcSSimon Schubert c_type_print_modifier (type, stream, 1, need_post_space);
3155796c8dcSSimon Schubert break;
3165796c8dcSSimon Schubert
3175796c8dcSSimon Schubert case TYPE_CODE_MEMBERPTR:
318c50c785cSJohn Marino c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
319*ef5ccd6cSJohn Marino stream, show, 0, 0, flags);
3205796c8dcSSimon Schubert name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
3215796c8dcSSimon Schubert if (name)
322*ef5ccd6cSJohn Marino print_name_maybe_canonical (name, flags, stream);
3235796c8dcSSimon Schubert else
324c50c785cSJohn Marino c_type_print_base (TYPE_DOMAIN_TYPE (type),
325*ef5ccd6cSJohn Marino stream, -1, passed_a_ptr, flags);
3265796c8dcSSimon Schubert fprintf_filtered (stream, "::*");
3275796c8dcSSimon Schubert break;
3285796c8dcSSimon Schubert
3295796c8dcSSimon Schubert case TYPE_CODE_METHODPTR:
330c50c785cSJohn Marino c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
331*ef5ccd6cSJohn Marino stream, show, 0, 0, flags);
3325796c8dcSSimon Schubert fprintf_filtered (stream, "(");
3335796c8dcSSimon Schubert name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
3345796c8dcSSimon Schubert if (name)
335*ef5ccd6cSJohn Marino print_name_maybe_canonical (name, flags, stream);
3365796c8dcSSimon Schubert else
337c50c785cSJohn Marino c_type_print_base (TYPE_DOMAIN_TYPE (type),
338*ef5ccd6cSJohn Marino stream, -1, passed_a_ptr, flags);
3395796c8dcSSimon Schubert fprintf_filtered (stream, "::*");
3405796c8dcSSimon Schubert break;
3415796c8dcSSimon Schubert
3425796c8dcSSimon Schubert case TYPE_CODE_REF:
343c50c785cSJohn Marino c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
344*ef5ccd6cSJohn Marino stream, show, 1, 0, flags);
3455796c8dcSSimon Schubert fprintf_filtered (stream, "&");
3465796c8dcSSimon Schubert c_type_print_modifier (type, stream, 1, need_post_space);
3475796c8dcSSimon Schubert break;
3485796c8dcSSimon Schubert
3495796c8dcSSimon Schubert case TYPE_CODE_METHOD:
3505796c8dcSSimon Schubert case TYPE_CODE_FUNC:
351c50c785cSJohn Marino c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
352*ef5ccd6cSJohn Marino stream, show, 0, 0, flags);
3535796c8dcSSimon Schubert if (passed_a_ptr)
3545796c8dcSSimon Schubert fprintf_filtered (stream, "(");
3555796c8dcSSimon Schubert break;
3565796c8dcSSimon Schubert
3575796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
358c50c785cSJohn Marino c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
359*ef5ccd6cSJohn Marino stream, show, 0, 0, flags);
3605796c8dcSSimon Schubert if (passed_a_ptr)
3615796c8dcSSimon Schubert fprintf_filtered (stream, "(");
3625796c8dcSSimon Schubert break;
3635796c8dcSSimon Schubert
3645796c8dcSSimon Schubert case TYPE_CODE_TYPEDEF:
365c50c785cSJohn Marino c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
366*ef5ccd6cSJohn Marino stream, show, passed_a_ptr, 0, flags);
3675796c8dcSSimon Schubert break;
3685796c8dcSSimon Schubert
3695796c8dcSSimon Schubert case TYPE_CODE_UNDEF:
3705796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
3715796c8dcSSimon Schubert case TYPE_CODE_UNION:
3725796c8dcSSimon Schubert case TYPE_CODE_ENUM:
3735796c8dcSSimon Schubert case TYPE_CODE_INT:
3745796c8dcSSimon Schubert case TYPE_CODE_FLT:
3755796c8dcSSimon Schubert case TYPE_CODE_VOID:
3765796c8dcSSimon Schubert case TYPE_CODE_ERROR:
3775796c8dcSSimon Schubert case TYPE_CODE_CHAR:
3785796c8dcSSimon Schubert case TYPE_CODE_BOOL:
3795796c8dcSSimon Schubert case TYPE_CODE_SET:
3805796c8dcSSimon Schubert case TYPE_CODE_RANGE:
3815796c8dcSSimon Schubert case TYPE_CODE_STRING:
3825796c8dcSSimon Schubert case TYPE_CODE_COMPLEX:
3835796c8dcSSimon Schubert case TYPE_CODE_NAMESPACE:
3845796c8dcSSimon Schubert case TYPE_CODE_DECFLOAT:
3855796c8dcSSimon Schubert /* These types need no prefix. They are listed here so that
3865796c8dcSSimon Schubert gcc -Wall will reveal any types that haven't been handled. */
3875796c8dcSSimon Schubert break;
3885796c8dcSSimon Schubert default:
3895796c8dcSSimon Schubert error (_("type not handled in c_type_print_varspec_prefix()"));
3905796c8dcSSimon Schubert break;
3915796c8dcSSimon Schubert }
3925796c8dcSSimon Schubert }
3935796c8dcSSimon Schubert
394c50c785cSJohn Marino /* Print out "const" and "volatile" attributes,
395c50c785cSJohn Marino and address space id if present.
3965796c8dcSSimon Schubert TYPE is a pointer to the type being printed out.
3975796c8dcSSimon Schubert STREAM is the output destination.
398c50c785cSJohn Marino NEED_PRE_SPACE = 1 indicates an initial white space is needed.
399c50c785cSJohn Marino NEED_POST_SPACE = 1 indicates a final white space is needed. */
4005796c8dcSSimon Schubert
4015796c8dcSSimon Schubert static void
c_type_print_modifier(struct type * type,struct ui_file * stream,int need_pre_space,int need_post_space)4025796c8dcSSimon Schubert c_type_print_modifier (struct type *type, struct ui_file *stream,
4035796c8dcSSimon Schubert int need_pre_space, int need_post_space)
4045796c8dcSSimon Schubert {
4055796c8dcSSimon Schubert int did_print_modifier = 0;
4065796c8dcSSimon Schubert const char *address_space_id;
4075796c8dcSSimon Schubert
4085796c8dcSSimon Schubert /* We don't print `const' qualifiers for references --- since all
4095796c8dcSSimon Schubert operators affect the thing referenced, not the reference itself,
4105796c8dcSSimon Schubert every reference is `const'. */
4115796c8dcSSimon Schubert if (TYPE_CONST (type)
4125796c8dcSSimon Schubert && TYPE_CODE (type) != TYPE_CODE_REF)
4135796c8dcSSimon Schubert {
4145796c8dcSSimon Schubert if (need_pre_space)
4155796c8dcSSimon Schubert fprintf_filtered (stream, " ");
4165796c8dcSSimon Schubert fprintf_filtered (stream, "const");
4175796c8dcSSimon Schubert did_print_modifier = 1;
4185796c8dcSSimon Schubert }
4195796c8dcSSimon Schubert
4205796c8dcSSimon Schubert if (TYPE_VOLATILE (type))
4215796c8dcSSimon Schubert {
4225796c8dcSSimon Schubert if (did_print_modifier || need_pre_space)
4235796c8dcSSimon Schubert fprintf_filtered (stream, " ");
4245796c8dcSSimon Schubert fprintf_filtered (stream, "volatile");
4255796c8dcSSimon Schubert did_print_modifier = 1;
4265796c8dcSSimon Schubert }
4275796c8dcSSimon Schubert
428*ef5ccd6cSJohn Marino if (TYPE_RESTRICT (type))
429*ef5ccd6cSJohn Marino {
430*ef5ccd6cSJohn Marino if (did_print_modifier || need_pre_space)
431*ef5ccd6cSJohn Marino fprintf_filtered (stream, " ");
432*ef5ccd6cSJohn Marino fprintf_filtered (stream, "restrict");
433*ef5ccd6cSJohn Marino did_print_modifier = 1;
434*ef5ccd6cSJohn Marino }
435*ef5ccd6cSJohn Marino
4365796c8dcSSimon Schubert address_space_id = address_space_int_to_name (get_type_arch (type),
4375796c8dcSSimon Schubert TYPE_INSTANCE_FLAGS (type));
4385796c8dcSSimon Schubert if (address_space_id)
4395796c8dcSSimon Schubert {
4405796c8dcSSimon Schubert if (did_print_modifier || need_pre_space)
4415796c8dcSSimon Schubert fprintf_filtered (stream, " ");
4425796c8dcSSimon Schubert fprintf_filtered (stream, "@%s", address_space_id);
4435796c8dcSSimon Schubert did_print_modifier = 1;
4445796c8dcSSimon Schubert }
4455796c8dcSSimon Schubert
4465796c8dcSSimon Schubert if (did_print_modifier && need_post_space)
4475796c8dcSSimon Schubert fprintf_filtered (stream, " ");
4485796c8dcSSimon Schubert }
4495796c8dcSSimon Schubert
4505796c8dcSSimon Schubert
4515796c8dcSSimon Schubert /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
4525796c8dcSSimon Schubert or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
453c50c785cSJohn Marino in non-static methods, are displayed if LINKAGE_NAME is zero. If
454c50c785cSJohn Marino LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
455c50c785cSJohn Marino parameter types get removed their possible const and volatile qualifiers to
456c50c785cSJohn Marino match demangled linkage name parameters part of such function type.
457c50c785cSJohn Marino LANGUAGE is the language in which TYPE was defined. This is a necessary
458c50c785cSJohn Marino evil since this code is used by the C, C++, and Java backends. */
4595796c8dcSSimon Schubert
460cf7f2e2dSJohn Marino void
c_type_print_args(struct type * type,struct ui_file * stream,int linkage_name,enum language language,const struct type_print_options * flags)461cf7f2e2dSJohn Marino c_type_print_args (struct type *type, struct ui_file *stream,
462*ef5ccd6cSJohn Marino int linkage_name, enum language language,
463*ef5ccd6cSJohn Marino const struct type_print_options *flags)
4645796c8dcSSimon Schubert {
465*ef5ccd6cSJohn Marino int i;
4665796c8dcSSimon Schubert int printed_any = 0;
4675796c8dcSSimon Schubert
4685796c8dcSSimon Schubert fprintf_filtered (stream, "(");
4695796c8dcSSimon Schubert
4705796c8dcSSimon Schubert for (i = 0; i < TYPE_NFIELDS (type); i++)
4715796c8dcSSimon Schubert {
472c50c785cSJohn Marino struct type *param_type;
473c50c785cSJohn Marino
474c50c785cSJohn Marino if (TYPE_FIELD_ARTIFICIAL (type, i) && linkage_name)
475cf7f2e2dSJohn Marino continue;
476cf7f2e2dSJohn Marino
4775796c8dcSSimon Schubert if (printed_any)
4785796c8dcSSimon Schubert {
4795796c8dcSSimon Schubert fprintf_filtered (stream, ", ");
4805796c8dcSSimon Schubert wrap_here (" ");
4815796c8dcSSimon Schubert }
4825796c8dcSSimon Schubert
483c50c785cSJohn Marino param_type = TYPE_FIELD_TYPE (type, i);
484c50c785cSJohn Marino
485c50c785cSJohn Marino if (language == language_cplus && linkage_name)
486c50c785cSJohn Marino {
487c50c785cSJohn Marino /* C++ standard, 13.1 Overloadable declarations, point 3, item:
488c50c785cSJohn Marino - Parameter declarations that differ only in the presence or
489c50c785cSJohn Marino absence of const and/or volatile are equivalent.
490c50c785cSJohn Marino
491c50c785cSJohn Marino And the const/volatile qualifiers are not present in the mangled
492c50c785cSJohn Marino names as produced by GCC. */
493c50c785cSJohn Marino
494c50c785cSJohn Marino param_type = make_cv_type (0, 0, param_type, NULL);
495c50c785cSJohn Marino }
496c50c785cSJohn Marino
497cf7f2e2dSJohn Marino if (language == language_java)
498*ef5ccd6cSJohn Marino java_print_type (param_type, "", stream, -1, 0, flags);
499cf7f2e2dSJohn Marino else
500*ef5ccd6cSJohn Marino c_print_type (param_type, "", stream, -1, 0, flags);
5015796c8dcSSimon Schubert printed_any = 1;
5025796c8dcSSimon Schubert }
5035796c8dcSSimon Schubert
5045796c8dcSSimon Schubert if (printed_any && TYPE_VARARGS (type))
5055796c8dcSSimon Schubert {
5065796c8dcSSimon Schubert /* Print out a trailing ellipsis for varargs functions. Ignore
5075796c8dcSSimon Schubert TYPE_VARARGS if the function has no named arguments; that
5085796c8dcSSimon Schubert represents unprototyped (K&R style) C functions. */
5095796c8dcSSimon Schubert if (printed_any && TYPE_VARARGS (type))
5105796c8dcSSimon Schubert {
5115796c8dcSSimon Schubert fprintf_filtered (stream, ", ");
5125796c8dcSSimon Schubert wrap_here (" ");
5135796c8dcSSimon Schubert fprintf_filtered (stream, "...");
5145796c8dcSSimon Schubert }
5155796c8dcSSimon Schubert }
5165796c8dcSSimon Schubert else if (!printed_any
517cf7f2e2dSJohn Marino && ((TYPE_PROTOTYPED (type) && language != language_java)
518cf7f2e2dSJohn Marino || language == language_cplus))
5195796c8dcSSimon Schubert fprintf_filtered (stream, "void");
5205796c8dcSSimon Schubert
5215796c8dcSSimon Schubert fprintf_filtered (stream, ")");
5225796c8dcSSimon Schubert }
5235796c8dcSSimon Schubert
5245796c8dcSSimon Schubert /* Return true iff the j'th overloading of the i'th method of TYPE
5255796c8dcSSimon Schubert is a type conversion operator, like `operator int () { ... }'.
5265796c8dcSSimon Schubert When listing a class's methods, we don't print the return type of
5275796c8dcSSimon Schubert such operators. */
528c50c785cSJohn Marino
5295796c8dcSSimon Schubert static int
is_type_conversion_operator(struct type * type,int i,int j)5305796c8dcSSimon Schubert is_type_conversion_operator (struct type *type, int i, int j)
5315796c8dcSSimon Schubert {
5325796c8dcSSimon Schubert /* I think the whole idea of recognizing type conversion operators
5335796c8dcSSimon Schubert by their name is pretty terrible. But I don't think our present
5345796c8dcSSimon Schubert data structure gives us any other way to tell. If you know of
5355796c8dcSSimon Schubert some other way, feel free to rewrite this function. */
536*ef5ccd6cSJohn Marino const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
5375796c8dcSSimon Schubert
5385796c8dcSSimon Schubert if (strncmp (name, "operator", 8) != 0)
5395796c8dcSSimon Schubert return 0;
5405796c8dcSSimon Schubert
5415796c8dcSSimon Schubert name += 8;
5425796c8dcSSimon Schubert if (! strchr (" \t\f\n\r", *name))
5435796c8dcSSimon Schubert return 0;
5445796c8dcSSimon Schubert
5455796c8dcSSimon Schubert while (strchr (" \t\f\n\r", *name))
5465796c8dcSSimon Schubert name++;
5475796c8dcSSimon Schubert
5485796c8dcSSimon Schubert if (!('a' <= *name && *name <= 'z')
5495796c8dcSSimon Schubert && !('A' <= *name && *name <= 'Z')
5505796c8dcSSimon Schubert && *name != '_')
5515796c8dcSSimon Schubert /* If this doesn't look like the start of an identifier, then it
5525796c8dcSSimon Schubert isn't a type conversion operator. */
5535796c8dcSSimon Schubert return 0;
5545796c8dcSSimon Schubert else if (strncmp (name, "new", 3) == 0)
5555796c8dcSSimon Schubert name += 3;
5565796c8dcSSimon Schubert else if (strncmp (name, "delete", 6) == 0)
5575796c8dcSSimon Schubert name += 6;
5585796c8dcSSimon Schubert else
5595796c8dcSSimon Schubert /* If it doesn't look like new or delete, it's a type conversion
5605796c8dcSSimon Schubert operator. */
5615796c8dcSSimon Schubert return 1;
5625796c8dcSSimon Schubert
5635796c8dcSSimon Schubert /* Is that really the end of the name? */
5645796c8dcSSimon Schubert if (('a' <= *name && *name <= 'z')
5655796c8dcSSimon Schubert || ('A' <= *name && *name <= 'Z')
5665796c8dcSSimon Schubert || ('0' <= *name && *name <= '9')
5675796c8dcSSimon Schubert || *name == '_')
5685796c8dcSSimon Schubert /* No, so the identifier following "operator" must be a type name,
5695796c8dcSSimon Schubert and this is a type conversion operator. */
5705796c8dcSSimon Schubert return 1;
5715796c8dcSSimon Schubert
5725796c8dcSSimon Schubert /* That was indeed the end of the name, so it was `operator new' or
573c50c785cSJohn Marino `operator delete', neither of which are type conversion
574c50c785cSJohn Marino operators. */
5755796c8dcSSimon Schubert return 0;
5765796c8dcSSimon Schubert }
5775796c8dcSSimon Schubert
5785796c8dcSSimon Schubert /* Given a C++ qualified identifier QID, strip off the qualifiers,
5795796c8dcSSimon Schubert yielding the unqualified name. The return value is a pointer into
5805796c8dcSSimon Schubert the original string.
5815796c8dcSSimon Schubert
5825796c8dcSSimon Schubert It's a pity we don't have this information in some more structured
5835796c8dcSSimon Schubert form. Even the author of this function feels that writing little
5845796c8dcSSimon Schubert parsers like this everywhere is stupid. */
585c50c785cSJohn Marino
5865796c8dcSSimon Schubert static char *
remove_qualifiers(char * qid)5875796c8dcSSimon Schubert remove_qualifiers (char *qid)
5885796c8dcSSimon Schubert {
589c50c785cSJohn Marino int quoted = 0; /* Zero if we're not in quotes;
5905796c8dcSSimon Schubert '"' if we're in a double-quoted string;
5915796c8dcSSimon Schubert '\'' if we're in a single-quoted string. */
592c50c785cSJohn Marino int depth = 0; /* Number of unclosed parens we've seen. */
5935796c8dcSSimon Schubert char *parenstack = (char *) alloca (strlen (qid));
5945796c8dcSSimon Schubert char *scan;
5955796c8dcSSimon Schubert char *last = 0; /* The character after the rightmost
5965796c8dcSSimon Schubert `::' token we've seen so far. */
5975796c8dcSSimon Schubert
5985796c8dcSSimon Schubert for (scan = qid; *scan; scan++)
5995796c8dcSSimon Schubert {
6005796c8dcSSimon Schubert if (quoted)
6015796c8dcSSimon Schubert {
6025796c8dcSSimon Schubert if (*scan == quoted)
6035796c8dcSSimon Schubert quoted = 0;
6045796c8dcSSimon Schubert else if (*scan == '\\' && *(scan + 1))
6055796c8dcSSimon Schubert scan++;
6065796c8dcSSimon Schubert }
6075796c8dcSSimon Schubert else if (scan[0] == ':' && scan[1] == ':')
6085796c8dcSSimon Schubert {
6095796c8dcSSimon Schubert /* If we're inside parenthesis (i.e., an argument list) or
6105796c8dcSSimon Schubert angle brackets (i.e., a list of template arguments), then
6115796c8dcSSimon Schubert we don't record the position of this :: token, since it's
612c50c785cSJohn Marino not relevant to the top-level structure we're trying to
613c50c785cSJohn Marino operate on. */
6145796c8dcSSimon Schubert if (depth == 0)
6155796c8dcSSimon Schubert {
6165796c8dcSSimon Schubert last = scan + 2;
6175796c8dcSSimon Schubert scan++;
6185796c8dcSSimon Schubert }
6195796c8dcSSimon Schubert }
6205796c8dcSSimon Schubert else if (*scan == '"' || *scan == '\'')
6215796c8dcSSimon Schubert quoted = *scan;
6225796c8dcSSimon Schubert else if (*scan == '(')
6235796c8dcSSimon Schubert parenstack[depth++] = ')';
6245796c8dcSSimon Schubert else if (*scan == '[')
6255796c8dcSSimon Schubert parenstack[depth++] = ']';
6265796c8dcSSimon Schubert /* We're going to treat <> as a pair of matching characters,
6275796c8dcSSimon Schubert since we're more likely to see those in template id's than
6285796c8dcSSimon Schubert real less-than characters. What a crock. */
6295796c8dcSSimon Schubert else if (*scan == '<')
6305796c8dcSSimon Schubert parenstack[depth++] = '>';
6315796c8dcSSimon Schubert else if (*scan == ')' || *scan == ']' || *scan == '>')
6325796c8dcSSimon Schubert {
6335796c8dcSSimon Schubert if (depth > 0 && parenstack[depth - 1] == *scan)
6345796c8dcSSimon Schubert depth--;
6355796c8dcSSimon Schubert else
6365796c8dcSSimon Schubert {
637c50c785cSJohn Marino /* We're going to do a little error recovery here. If
638c50c785cSJohn Marino we don't find a match for *scan on the paren stack,
639c50c785cSJohn Marino but there is something lower on the stack that does
640c50c785cSJohn Marino match, we pop the stack to that point. */
6415796c8dcSSimon Schubert int i;
6425796c8dcSSimon Schubert
6435796c8dcSSimon Schubert for (i = depth - 1; i >= 0; i--)
6445796c8dcSSimon Schubert if (parenstack[i] == *scan)
6455796c8dcSSimon Schubert {
6465796c8dcSSimon Schubert depth = i;
6475796c8dcSSimon Schubert break;
6485796c8dcSSimon Schubert }
6495796c8dcSSimon Schubert }
6505796c8dcSSimon Schubert }
6515796c8dcSSimon Schubert }
6525796c8dcSSimon Schubert
6535796c8dcSSimon Schubert if (last)
6545796c8dcSSimon Schubert return last;
6555796c8dcSSimon Schubert else
6565796c8dcSSimon Schubert /* We didn't find any :: tokens at the top level, so declare the
6575796c8dcSSimon Schubert whole thing an unqualified identifier. */
6585796c8dcSSimon Schubert return qid;
6595796c8dcSSimon Schubert }
6605796c8dcSSimon Schubert
6615796c8dcSSimon Schubert /* Print any array sizes, function arguments or close parentheses
6625796c8dcSSimon Schubert needed after the variable name (to describe its type).
6635796c8dcSSimon Schubert Args work like c_type_print_varspec_prefix. */
6645796c8dcSSimon Schubert
6655796c8dcSSimon Schubert void
c_type_print_varspec_suffix(struct type * type,struct ui_file * stream,int show,int passed_a_ptr,int demangled_args,const struct type_print_options * flags)666c50c785cSJohn Marino c_type_print_varspec_suffix (struct type *type,
667c50c785cSJohn Marino struct ui_file *stream,
668c50c785cSJohn Marino int show, int passed_a_ptr,
669*ef5ccd6cSJohn Marino int demangled_args,
670*ef5ccd6cSJohn Marino const struct type_print_options *flags)
6715796c8dcSSimon Schubert {
6725796c8dcSSimon Schubert if (type == 0)
6735796c8dcSSimon Schubert return;
6745796c8dcSSimon Schubert
6755796c8dcSSimon Schubert if (TYPE_NAME (type) && show <= 0)
6765796c8dcSSimon Schubert return;
6775796c8dcSSimon Schubert
6785796c8dcSSimon Schubert QUIT;
6795796c8dcSSimon Schubert
6805796c8dcSSimon Schubert switch (TYPE_CODE (type))
6815796c8dcSSimon Schubert {
6825796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
683c50c785cSJohn Marino {
684c50c785cSJohn Marino LONGEST low_bound, high_bound;
685*ef5ccd6cSJohn Marino int is_vector = TYPE_VECTOR (type);
686c50c785cSJohn Marino
6875796c8dcSSimon Schubert if (passed_a_ptr)
6885796c8dcSSimon Schubert fprintf_filtered (stream, ")");
6895796c8dcSSimon Schubert
690*ef5ccd6cSJohn Marino fprintf_filtered (stream, (is_vector ?
691*ef5ccd6cSJohn Marino " __attribute__ ((vector_size(" : "["));
692c50c785cSJohn Marino if (get_array_bounds (type, &low_bound, &high_bound))
693*ef5ccd6cSJohn Marino fprintf_filtered (stream, "%s",
694*ef5ccd6cSJohn Marino plongest (high_bound - low_bound + 1));
695*ef5ccd6cSJohn Marino fprintf_filtered (stream, (is_vector ? ")))" : "]"));
6965796c8dcSSimon Schubert
697c50c785cSJohn Marino c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
698*ef5ccd6cSJohn Marino show, 0, 0, flags);
699c50c785cSJohn Marino }
7005796c8dcSSimon Schubert break;
7015796c8dcSSimon Schubert
7025796c8dcSSimon Schubert case TYPE_CODE_MEMBERPTR:
703c50c785cSJohn Marino c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
704*ef5ccd6cSJohn Marino show, 0, 0, flags);
7055796c8dcSSimon Schubert break;
7065796c8dcSSimon Schubert
7075796c8dcSSimon Schubert case TYPE_CODE_METHODPTR:
7085796c8dcSSimon Schubert fprintf_filtered (stream, ")");
709c50c785cSJohn Marino c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
710*ef5ccd6cSJohn Marino show, 0, 0, flags);
7115796c8dcSSimon Schubert break;
7125796c8dcSSimon Schubert
7135796c8dcSSimon Schubert case TYPE_CODE_PTR:
7145796c8dcSSimon Schubert case TYPE_CODE_REF:
715c50c785cSJohn Marino c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
716*ef5ccd6cSJohn Marino show, 1, 0, flags);
7175796c8dcSSimon Schubert break;
7185796c8dcSSimon Schubert
7195796c8dcSSimon Schubert case TYPE_CODE_METHOD:
7205796c8dcSSimon Schubert case TYPE_CODE_FUNC:
7215796c8dcSSimon Schubert if (passed_a_ptr)
7225796c8dcSSimon Schubert fprintf_filtered (stream, ")");
7235796c8dcSSimon Schubert if (!demangled_args)
724*ef5ccd6cSJohn Marino c_type_print_args (type, stream, 0, current_language->la_language,
725*ef5ccd6cSJohn Marino flags);
726c50c785cSJohn Marino c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
727*ef5ccd6cSJohn Marino show, passed_a_ptr, 0, flags);
7285796c8dcSSimon Schubert break;
7295796c8dcSSimon Schubert
7305796c8dcSSimon Schubert case TYPE_CODE_TYPEDEF:
731c50c785cSJohn Marino c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
732*ef5ccd6cSJohn Marino show, passed_a_ptr, 0, flags);
7335796c8dcSSimon Schubert break;
7345796c8dcSSimon Schubert
7355796c8dcSSimon Schubert case TYPE_CODE_UNDEF:
7365796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
7375796c8dcSSimon Schubert case TYPE_CODE_UNION:
7385796c8dcSSimon Schubert case TYPE_CODE_ENUM:
7395796c8dcSSimon Schubert case TYPE_CODE_INT:
7405796c8dcSSimon Schubert case TYPE_CODE_FLT:
7415796c8dcSSimon Schubert case TYPE_CODE_VOID:
7425796c8dcSSimon Schubert case TYPE_CODE_ERROR:
7435796c8dcSSimon Schubert case TYPE_CODE_CHAR:
7445796c8dcSSimon Schubert case TYPE_CODE_BOOL:
7455796c8dcSSimon Schubert case TYPE_CODE_SET:
7465796c8dcSSimon Schubert case TYPE_CODE_RANGE:
7475796c8dcSSimon Schubert case TYPE_CODE_STRING:
7485796c8dcSSimon Schubert case TYPE_CODE_COMPLEX:
7495796c8dcSSimon Schubert case TYPE_CODE_NAMESPACE:
7505796c8dcSSimon Schubert case TYPE_CODE_DECFLOAT:
7515796c8dcSSimon Schubert /* These types do not need a suffix. They are listed so that
752c50c785cSJohn Marino gcc -Wall will report types that may not have been
753c50c785cSJohn Marino considered. */
7545796c8dcSSimon Schubert break;
7555796c8dcSSimon Schubert default:
7565796c8dcSSimon Schubert error (_("type not handled in c_type_print_varspec_suffix()"));
7575796c8dcSSimon Schubert break;
7585796c8dcSSimon Schubert }
7595796c8dcSSimon Schubert }
7605796c8dcSSimon Schubert
761*ef5ccd6cSJohn Marino /* A helper for c_type_print_base that displays template
762*ef5ccd6cSJohn Marino parameters and their bindings, if needed.
763*ef5ccd6cSJohn Marino
764*ef5ccd6cSJohn Marino TABLE is the local bindings table to use. If NULL, no printing is
765*ef5ccd6cSJohn Marino done. Note that, at this point, TABLE won't have any useful
766*ef5ccd6cSJohn Marino information in it -- but it is also used as a flag to
767*ef5ccd6cSJohn Marino print_name_maybe_canonical to activate searching the global typedef
768*ef5ccd6cSJohn Marino table.
769*ef5ccd6cSJohn Marino
770*ef5ccd6cSJohn Marino TYPE is the type whose template arguments are being displayed.
771*ef5ccd6cSJohn Marino
772*ef5ccd6cSJohn Marino STREAM is the stream on which to print. */
773*ef5ccd6cSJohn Marino
774*ef5ccd6cSJohn Marino static void
c_type_print_template_args(const struct type_print_options * flags,struct type * type,struct ui_file * stream)775*ef5ccd6cSJohn Marino c_type_print_template_args (const struct type_print_options *flags,
776*ef5ccd6cSJohn Marino struct type *type, struct ui_file *stream)
777*ef5ccd6cSJohn Marino {
778*ef5ccd6cSJohn Marino int first = 1, i;
779*ef5ccd6cSJohn Marino
780*ef5ccd6cSJohn Marino if (flags->raw)
781*ef5ccd6cSJohn Marino return;
782*ef5ccd6cSJohn Marino
783*ef5ccd6cSJohn Marino for (i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
784*ef5ccd6cSJohn Marino {
785*ef5ccd6cSJohn Marino struct symbol *sym = TYPE_TEMPLATE_ARGUMENT (type, i);
786*ef5ccd6cSJohn Marino
787*ef5ccd6cSJohn Marino if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
788*ef5ccd6cSJohn Marino continue;
789*ef5ccd6cSJohn Marino
790*ef5ccd6cSJohn Marino if (first)
791*ef5ccd6cSJohn Marino {
792*ef5ccd6cSJohn Marino wrap_here (" ");
793*ef5ccd6cSJohn Marino fprintf_filtered (stream, _("[with %s = "),
794*ef5ccd6cSJohn Marino SYMBOL_LINKAGE_NAME (sym));
795*ef5ccd6cSJohn Marino first = 0;
796*ef5ccd6cSJohn Marino }
797*ef5ccd6cSJohn Marino else
798*ef5ccd6cSJohn Marino {
799*ef5ccd6cSJohn Marino fputs_filtered (", ", stream);
800*ef5ccd6cSJohn Marino wrap_here (" ");
801*ef5ccd6cSJohn Marino fprintf_filtered (stream, "%s = ", SYMBOL_LINKAGE_NAME (sym));
802*ef5ccd6cSJohn Marino }
803*ef5ccd6cSJohn Marino
804*ef5ccd6cSJohn Marino c_print_type (SYMBOL_TYPE (sym), "", stream, -1, 0, flags);
805*ef5ccd6cSJohn Marino }
806*ef5ccd6cSJohn Marino
807*ef5ccd6cSJohn Marino if (!first)
808*ef5ccd6cSJohn Marino fputs_filtered (_("] "), stream);
809*ef5ccd6cSJohn Marino }
810*ef5ccd6cSJohn Marino
8115796c8dcSSimon Schubert /* Print the name of the type (or the ultimate pointer target,
812c50c785cSJohn Marino function value or array element), or the description of a structure
813c50c785cSJohn Marino or union.
8145796c8dcSSimon Schubert
815c50c785cSJohn Marino SHOW positive means print details about the type (e.g. enum
816c50c785cSJohn Marino values), and print structure elements passing SHOW - 1 for show.
817c50c785cSJohn Marino
818c50c785cSJohn Marino SHOW negative means just print the type name or struct tag if there
819c50c785cSJohn Marino is one. If there is no name, print something sensible but concise
820c50c785cSJohn Marino like "struct {...}".
821c50c785cSJohn Marino
822c50c785cSJohn Marino SHOW zero means just print the type name or struct tag if there is
823c50c785cSJohn Marino one. If there is no name, print something sensible but not as
824c50c785cSJohn Marino concise like "struct {int x; int y;}".
8255796c8dcSSimon Schubert
8265796c8dcSSimon Schubert LEVEL is the number of spaces to indent by.
8275796c8dcSSimon Schubert We increase it for some recursive calls. */
8285796c8dcSSimon Schubert
8295796c8dcSSimon Schubert void
c_type_print_base(struct type * type,struct ui_file * stream,int show,int level,const struct type_print_options * flags)830c50c785cSJohn Marino c_type_print_base (struct type *type, struct ui_file *stream,
831*ef5ccd6cSJohn Marino int show, int level, const struct type_print_options *flags)
8325796c8dcSSimon Schubert {
8335796c8dcSSimon Schubert int i;
8345796c8dcSSimon Schubert int len, real_len;
8355796c8dcSSimon Schubert enum
8365796c8dcSSimon Schubert {
8375796c8dcSSimon Schubert s_none, s_public, s_private, s_protected
8385796c8dcSSimon Schubert }
8395796c8dcSSimon Schubert section_type;
8405796c8dcSSimon Schubert int need_access_label = 0;
8415796c8dcSSimon Schubert int j, len2;
8425796c8dcSSimon Schubert
8435796c8dcSSimon Schubert QUIT;
8445796c8dcSSimon Schubert
8455796c8dcSSimon Schubert if (type == NULL)
8465796c8dcSSimon Schubert {
8475796c8dcSSimon Schubert fputs_filtered (_("<type unknown>"), stream);
8485796c8dcSSimon Schubert return;
8495796c8dcSSimon Schubert }
8505796c8dcSSimon Schubert
851c50c785cSJohn Marino /* When SHOW is zero or less, and there is a valid type name, then
852c50c785cSJohn Marino always just print the type name directly from the type. */
853c50c785cSJohn Marino /* If we have "typedef struct foo {. . .} bar;" do we want to print
854c50c785cSJohn Marino it as "struct foo" or as "bar"? Pick the latter, because C++
855c50c785cSJohn Marino folk tend to expect things like "class5 *foo" rather than "struct
856c50c785cSJohn Marino class5 *foo". */
8575796c8dcSSimon Schubert
8585796c8dcSSimon Schubert if (show <= 0
8595796c8dcSSimon Schubert && TYPE_NAME (type) != NULL)
8605796c8dcSSimon Schubert {
8615796c8dcSSimon Schubert c_type_print_modifier (type, stream, 0, 1);
862*ef5ccd6cSJohn Marino print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
8635796c8dcSSimon Schubert return;
8645796c8dcSSimon Schubert }
8655796c8dcSSimon Schubert
8665796c8dcSSimon Schubert CHECK_TYPEDEF (type);
8675796c8dcSSimon Schubert
8685796c8dcSSimon Schubert switch (TYPE_CODE (type))
8695796c8dcSSimon Schubert {
8705796c8dcSSimon Schubert case TYPE_CODE_TYPEDEF:
871c50c785cSJohn Marino /* If we get here, the typedef doesn't have a name, and we
872c50c785cSJohn Marino couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
873c50c785cSJohn Marino gdb_assert (TYPE_NAME (type) == NULL);
874c50c785cSJohn Marino gdb_assert (TYPE_TARGET_TYPE (type) == NULL);
875c50c785cSJohn Marino fprintf_filtered (stream, _("<unnamed typedef>"));
876c50c785cSJohn Marino break;
877c50c785cSJohn Marino
8785796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
8795796c8dcSSimon Schubert case TYPE_CODE_PTR:
8805796c8dcSSimon Schubert case TYPE_CODE_MEMBERPTR:
8815796c8dcSSimon Schubert case TYPE_CODE_REF:
8825796c8dcSSimon Schubert case TYPE_CODE_FUNC:
8835796c8dcSSimon Schubert case TYPE_CODE_METHOD:
8845796c8dcSSimon Schubert case TYPE_CODE_METHODPTR:
885c50c785cSJohn Marino c_type_print_base (TYPE_TARGET_TYPE (type),
886*ef5ccd6cSJohn Marino stream, show, level, flags);
8875796c8dcSSimon Schubert break;
8885796c8dcSSimon Schubert
8895796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
890*ef5ccd6cSJohn Marino case TYPE_CODE_UNION:
891*ef5ccd6cSJohn Marino {
892*ef5ccd6cSJohn Marino struct type_print_options local_flags = *flags;
893*ef5ccd6cSJohn Marino struct type_print_options semi_local_flags = *flags;
894*ef5ccd6cSJohn Marino struct cleanup *local_cleanups = make_cleanup (null_cleanup, NULL);
895*ef5ccd6cSJohn Marino
896*ef5ccd6cSJohn Marino local_flags.local_typedefs = NULL;
897*ef5ccd6cSJohn Marino semi_local_flags.local_typedefs = NULL;
898*ef5ccd6cSJohn Marino
899*ef5ccd6cSJohn Marino if (!flags->raw)
900*ef5ccd6cSJohn Marino {
901*ef5ccd6cSJohn Marino if (flags->local_typedefs)
902*ef5ccd6cSJohn Marino local_flags.local_typedefs
903*ef5ccd6cSJohn Marino = copy_typedef_hash (flags->local_typedefs);
904*ef5ccd6cSJohn Marino else
905*ef5ccd6cSJohn Marino local_flags.local_typedefs = create_typedef_hash ();
906*ef5ccd6cSJohn Marino
907*ef5ccd6cSJohn Marino make_cleanup_free_typedef_hash (local_flags.local_typedefs);
908*ef5ccd6cSJohn Marino }
909*ef5ccd6cSJohn Marino
9105796c8dcSSimon Schubert c_type_print_modifier (type, stream, 0, 1);
911*ef5ccd6cSJohn Marino if (TYPE_CODE (type) == TYPE_CODE_UNION)
912*ef5ccd6cSJohn Marino fprintf_filtered (stream, "union ");
913*ef5ccd6cSJohn Marino else if (TYPE_DECLARED_CLASS (type))
9145796c8dcSSimon Schubert fprintf_filtered (stream, "class ");
9155796c8dcSSimon Schubert else
9165796c8dcSSimon Schubert fprintf_filtered (stream, "struct ");
9175796c8dcSSimon Schubert
918c50c785cSJohn Marino /* Print the tag if it exists. The HP aCC compiler emits a
919c50c785cSJohn Marino spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
920c50c785cSJohn Marino enum}" tag for unnamed struct/union/enum's, which we don't
921c50c785cSJohn Marino want to print. */
922cf7f2e2dSJohn Marino if (TYPE_TAG_NAME (type) != NULL
923cf7f2e2dSJohn Marino && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
9245796c8dcSSimon Schubert {
925*ef5ccd6cSJohn Marino /* When printing the tag name, we are still effectively
926*ef5ccd6cSJohn Marino printing in the outer context, hence the use of FLAGS
927*ef5ccd6cSJohn Marino here. */
928*ef5ccd6cSJohn Marino print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
9295796c8dcSSimon Schubert if (show > 0)
9305796c8dcSSimon Schubert fputs_filtered (" ", stream);
9315796c8dcSSimon Schubert }
932*ef5ccd6cSJohn Marino
9335796c8dcSSimon Schubert if (show < 0)
9345796c8dcSSimon Schubert {
935c50c785cSJohn Marino /* If we just printed a tag name, no need to print anything
936c50c785cSJohn Marino else. */
9375796c8dcSSimon Schubert if (TYPE_TAG_NAME (type) == NULL)
9385796c8dcSSimon Schubert fprintf_filtered (stream, "{...}");
9395796c8dcSSimon Schubert }
9405796c8dcSSimon Schubert else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
9415796c8dcSSimon Schubert {
942cf7f2e2dSJohn Marino struct type *basetype;
943cf7f2e2dSJohn Marino int vptr_fieldno;
944cf7f2e2dSJohn Marino
945*ef5ccd6cSJohn Marino c_type_print_template_args (&local_flags, type, stream);
946*ef5ccd6cSJohn Marino
947*ef5ccd6cSJohn Marino /* Add in template parameters when printing derivation info. */
948*ef5ccd6cSJohn Marino add_template_parameters (local_flags.local_typedefs, type);
949*ef5ccd6cSJohn Marino cp_type_print_derivation_info (stream, type, &local_flags);
950*ef5ccd6cSJohn Marino
951*ef5ccd6cSJohn Marino /* This holds just the global typedefs and the template
952*ef5ccd6cSJohn Marino parameters. */
953*ef5ccd6cSJohn Marino semi_local_flags.local_typedefs
954*ef5ccd6cSJohn Marino = copy_typedef_hash (local_flags.local_typedefs);
955*ef5ccd6cSJohn Marino if (semi_local_flags.local_typedefs)
956*ef5ccd6cSJohn Marino make_cleanup_free_typedef_hash (semi_local_flags.local_typedefs);
957*ef5ccd6cSJohn Marino
958*ef5ccd6cSJohn Marino /* Now add in the local typedefs. */
959*ef5ccd6cSJohn Marino recursively_update_typedef_hash (local_flags.local_typedefs, type);
9605796c8dcSSimon Schubert
9615796c8dcSSimon Schubert fprintf_filtered (stream, "{\n");
962cf7f2e2dSJohn Marino if (TYPE_NFIELDS (type) == 0 && TYPE_NFN_FIELDS (type) == 0
963cf7f2e2dSJohn Marino && TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
9645796c8dcSSimon Schubert {
9655796c8dcSSimon Schubert if (TYPE_STUB (type))
966c50c785cSJohn Marino fprintfi_filtered (level + 4, stream,
967c50c785cSJohn Marino _("<incomplete type>\n"));
9685796c8dcSSimon Schubert else
969c50c785cSJohn Marino fprintfi_filtered (level + 4, stream,
970c50c785cSJohn Marino _("<no data fields>\n"));
9715796c8dcSSimon Schubert }
9725796c8dcSSimon Schubert
9735796c8dcSSimon Schubert /* Start off with no specific section type, so we can print
9745796c8dcSSimon Schubert one for the first field we find, and use that section type
9755796c8dcSSimon Schubert thereafter until we find another type. */
9765796c8dcSSimon Schubert
9775796c8dcSSimon Schubert section_type = s_none;
9785796c8dcSSimon Schubert
9795796c8dcSSimon Schubert /* For a class, if all members are private, there's no need
9805796c8dcSSimon Schubert for a "private:" label; similarly, for a struct or union
9815796c8dcSSimon Schubert masquerading as a class, if all members are public, there's
9825796c8dcSSimon Schubert no need for a "public:" label. */
9835796c8dcSSimon Schubert
984cf7f2e2dSJohn Marino if (TYPE_DECLARED_CLASS (type))
9855796c8dcSSimon Schubert {
9865796c8dcSSimon Schubert QUIT;
9875796c8dcSSimon Schubert len = TYPE_NFIELDS (type);
9885796c8dcSSimon Schubert for (i = TYPE_N_BASECLASSES (type); i < len; i++)
9895796c8dcSSimon Schubert if (!TYPE_FIELD_PRIVATE (type, i))
9905796c8dcSSimon Schubert {
9915796c8dcSSimon Schubert need_access_label = 1;
9925796c8dcSSimon Schubert break;
9935796c8dcSSimon Schubert }
9945796c8dcSSimon Schubert QUIT;
9955796c8dcSSimon Schubert if (!need_access_label)
9965796c8dcSSimon Schubert {
9975796c8dcSSimon Schubert len2 = TYPE_NFN_FIELDS (type);
9985796c8dcSSimon Schubert for (j = 0; j < len2; j++)
9995796c8dcSSimon Schubert {
10005796c8dcSSimon Schubert len = TYPE_FN_FIELDLIST_LENGTH (type, j);
10015796c8dcSSimon Schubert for (i = 0; i < len; i++)
1002c50c785cSJohn Marino if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
1003c50c785cSJohn Marino j), i))
10045796c8dcSSimon Schubert {
10055796c8dcSSimon Schubert need_access_label = 1;
10065796c8dcSSimon Schubert break;
10075796c8dcSSimon Schubert }
10085796c8dcSSimon Schubert if (need_access_label)
10095796c8dcSSimon Schubert break;
10105796c8dcSSimon Schubert }
10115796c8dcSSimon Schubert }
10125796c8dcSSimon Schubert }
1013cf7f2e2dSJohn Marino else
10145796c8dcSSimon Schubert {
10155796c8dcSSimon Schubert QUIT;
10165796c8dcSSimon Schubert len = TYPE_NFIELDS (type);
10175796c8dcSSimon Schubert for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1018c50c785cSJohn Marino if (TYPE_FIELD_PRIVATE (type, i)
1019c50c785cSJohn Marino || TYPE_FIELD_PROTECTED (type, i))
10205796c8dcSSimon Schubert {
10215796c8dcSSimon Schubert need_access_label = 1;
10225796c8dcSSimon Schubert break;
10235796c8dcSSimon Schubert }
10245796c8dcSSimon Schubert QUIT;
10255796c8dcSSimon Schubert if (!need_access_label)
10265796c8dcSSimon Schubert {
10275796c8dcSSimon Schubert len2 = TYPE_NFN_FIELDS (type);
10285796c8dcSSimon Schubert for (j = 0; j < len2; j++)
10295796c8dcSSimon Schubert {
10305796c8dcSSimon Schubert QUIT;
10315796c8dcSSimon Schubert len = TYPE_FN_FIELDLIST_LENGTH (type, j);
10325796c8dcSSimon Schubert for (i = 0; i < len; i++)
1033c50c785cSJohn Marino if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type,
1034c50c785cSJohn Marino j), i)
1035c50c785cSJohn Marino || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
1036c50c785cSJohn Marino j),
1037c50c785cSJohn Marino i))
10385796c8dcSSimon Schubert {
10395796c8dcSSimon Schubert need_access_label = 1;
10405796c8dcSSimon Schubert break;
10415796c8dcSSimon Schubert }
10425796c8dcSSimon Schubert if (need_access_label)
10435796c8dcSSimon Schubert break;
10445796c8dcSSimon Schubert }
10455796c8dcSSimon Schubert }
10465796c8dcSSimon Schubert }
10475796c8dcSSimon Schubert
10485796c8dcSSimon Schubert /* If there is a base class for this type,
10495796c8dcSSimon Schubert do not print the field that it occupies. */
10505796c8dcSSimon Schubert
10515796c8dcSSimon Schubert len = TYPE_NFIELDS (type);
1052cf7f2e2dSJohn Marino vptr_fieldno = get_vptr_fieldno (type, &basetype);
10535796c8dcSSimon Schubert for (i = TYPE_N_BASECLASSES (type); i < len; i++)
10545796c8dcSSimon Schubert {
10555796c8dcSSimon Schubert QUIT;
1056cf7f2e2dSJohn Marino
1057cf7f2e2dSJohn Marino /* If we have a virtual table pointer, omit it. Even if
1058cf7f2e2dSJohn Marino virtual table pointers are not specifically marked in
1059cf7f2e2dSJohn Marino the debug info, they should be artificial. */
1060cf7f2e2dSJohn Marino if ((i == vptr_fieldno && type == basetype)
1061cf7f2e2dSJohn Marino || TYPE_FIELD_ARTIFICIAL (type, i))
10625796c8dcSSimon Schubert continue;
10635796c8dcSSimon Schubert
1064cf7f2e2dSJohn Marino if (need_access_label)
10655796c8dcSSimon Schubert {
10665796c8dcSSimon Schubert if (TYPE_FIELD_PROTECTED (type, i))
10675796c8dcSSimon Schubert {
10685796c8dcSSimon Schubert if (section_type != s_protected)
10695796c8dcSSimon Schubert {
10705796c8dcSSimon Schubert section_type = s_protected;
10715796c8dcSSimon Schubert fprintfi_filtered (level + 2, stream,
10725796c8dcSSimon Schubert "protected:\n");
10735796c8dcSSimon Schubert }
10745796c8dcSSimon Schubert }
10755796c8dcSSimon Schubert else if (TYPE_FIELD_PRIVATE (type, i))
10765796c8dcSSimon Schubert {
10775796c8dcSSimon Schubert if (section_type != s_private)
10785796c8dcSSimon Schubert {
10795796c8dcSSimon Schubert section_type = s_private;
1080c50c785cSJohn Marino fprintfi_filtered (level + 2, stream,
1081c50c785cSJohn Marino "private:\n");
10825796c8dcSSimon Schubert }
10835796c8dcSSimon Schubert }
10845796c8dcSSimon Schubert else
10855796c8dcSSimon Schubert {
10865796c8dcSSimon Schubert if (section_type != s_public)
10875796c8dcSSimon Schubert {
10885796c8dcSSimon Schubert section_type = s_public;
1089c50c785cSJohn Marino fprintfi_filtered (level + 2, stream,
1090c50c785cSJohn Marino "public:\n");
10915796c8dcSSimon Schubert }
10925796c8dcSSimon Schubert }
10935796c8dcSSimon Schubert }
10945796c8dcSSimon Schubert
10955796c8dcSSimon Schubert print_spaces_filtered (level + 4, stream);
10965796c8dcSSimon Schubert if (field_is_static (&TYPE_FIELD (type, i)))
10975796c8dcSSimon Schubert fprintf_filtered (stream, "static ");
10985796c8dcSSimon Schubert c_print_type (TYPE_FIELD_TYPE (type, i),
10995796c8dcSSimon Schubert TYPE_FIELD_NAME (type, i),
1100*ef5ccd6cSJohn Marino stream, show - 1, level + 4,
1101*ef5ccd6cSJohn Marino &local_flags);
11025796c8dcSSimon Schubert if (!field_is_static (&TYPE_FIELD (type, i))
11035796c8dcSSimon Schubert && TYPE_FIELD_PACKED (type, i))
11045796c8dcSSimon Schubert {
11055796c8dcSSimon Schubert /* It is a bitfield. This code does not attempt
11065796c8dcSSimon Schubert to look at the bitpos and reconstruct filler,
11075796c8dcSSimon Schubert unnamed fields. This would lead to misleading
11085796c8dcSSimon Schubert results if the compiler does not put out fields
11095796c8dcSSimon Schubert for such things (I don't know what it does). */
11105796c8dcSSimon Schubert fprintf_filtered (stream, " : %d",
11115796c8dcSSimon Schubert TYPE_FIELD_BITSIZE (type, i));
11125796c8dcSSimon Schubert }
11135796c8dcSSimon Schubert fprintf_filtered (stream, ";\n");
11145796c8dcSSimon Schubert }
11155796c8dcSSimon Schubert
11165796c8dcSSimon Schubert /* If there are both fields and methods, put a blank line
1117c50c785cSJohn Marino between them. Make sure to count only method that we
1118c50c785cSJohn Marino will display; artificial methods will be hidden. */
11195796c8dcSSimon Schubert len = TYPE_NFN_FIELDS (type);
1120*ef5ccd6cSJohn Marino if (!flags->print_methods)
1121*ef5ccd6cSJohn Marino len = 0;
11225796c8dcSSimon Schubert real_len = 0;
11235796c8dcSSimon Schubert for (i = 0; i < len; i++)
11245796c8dcSSimon Schubert {
11255796c8dcSSimon Schubert struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
11265796c8dcSSimon Schubert int len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
11275796c8dcSSimon Schubert int j;
1128cf7f2e2dSJohn Marino
11295796c8dcSSimon Schubert for (j = 0; j < len2; j++)
11305796c8dcSSimon Schubert if (!TYPE_FN_FIELD_ARTIFICIAL (f, j))
11315796c8dcSSimon Schubert real_len++;
11325796c8dcSSimon Schubert }
11335796c8dcSSimon Schubert if (real_len > 0 && section_type != s_none)
11345796c8dcSSimon Schubert fprintf_filtered (stream, "\n");
11355796c8dcSSimon Schubert
1136c50c785cSJohn Marino /* C++: print out the methods. */
11375796c8dcSSimon Schubert for (i = 0; i < len; i++)
11385796c8dcSSimon Schubert {
11395796c8dcSSimon Schubert struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
11405796c8dcSSimon Schubert int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1141*ef5ccd6cSJohn Marino const char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
1142*ef5ccd6cSJohn Marino const char *name = type_name_no_tag (type);
1143c50c785cSJohn Marino int is_constructor = name && strcmp (method_name,
1144c50c785cSJohn Marino name) == 0;
1145cf7f2e2dSJohn Marino
11465796c8dcSSimon Schubert for (j = 0; j < len2; j++)
11475796c8dcSSimon Schubert {
1148a45ae5f8SJohn Marino const char *mangled_name;
1149a45ae5f8SJohn Marino char *demangled_name;
1150a45ae5f8SJohn Marino struct cleanup *inner_cleanup;
1151a45ae5f8SJohn Marino const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
11525796c8dcSSimon Schubert int is_full_physname_constructor =
1153*ef5ccd6cSJohn Marino TYPE_FN_FIELD_CONSTRUCTOR (f, j)
1154*ef5ccd6cSJohn Marino || is_constructor_name (physname)
11555796c8dcSSimon Schubert || is_destructor_name (physname)
11565796c8dcSSimon Schubert || method_name[0] == '~';
11575796c8dcSSimon Schubert
11585796c8dcSSimon Schubert /* Do not print out artificial methods. */
11595796c8dcSSimon Schubert if (TYPE_FN_FIELD_ARTIFICIAL (f, j))
11605796c8dcSSimon Schubert continue;
11615796c8dcSSimon Schubert
1162a45ae5f8SJohn Marino inner_cleanup = make_cleanup (null_cleanup, NULL);
1163a45ae5f8SJohn Marino
11645796c8dcSSimon Schubert QUIT;
11655796c8dcSSimon Schubert if (TYPE_FN_FIELD_PROTECTED (f, j))
11665796c8dcSSimon Schubert {
11675796c8dcSSimon Schubert if (section_type != s_protected)
11685796c8dcSSimon Schubert {
11695796c8dcSSimon Schubert section_type = s_protected;
11705796c8dcSSimon Schubert fprintfi_filtered (level + 2, stream,
11715796c8dcSSimon Schubert "protected:\n");
11725796c8dcSSimon Schubert }
11735796c8dcSSimon Schubert }
11745796c8dcSSimon Schubert else if (TYPE_FN_FIELD_PRIVATE (f, j))
11755796c8dcSSimon Schubert {
11765796c8dcSSimon Schubert if (section_type != s_private)
11775796c8dcSSimon Schubert {
11785796c8dcSSimon Schubert section_type = s_private;
1179c50c785cSJohn Marino fprintfi_filtered (level + 2, stream,
1180c50c785cSJohn Marino "private:\n");
11815796c8dcSSimon Schubert }
11825796c8dcSSimon Schubert }
11835796c8dcSSimon Schubert else
11845796c8dcSSimon Schubert {
11855796c8dcSSimon Schubert if (section_type != s_public)
11865796c8dcSSimon Schubert {
11875796c8dcSSimon Schubert section_type = s_public;
1188c50c785cSJohn Marino fprintfi_filtered (level + 2, stream,
1189c50c785cSJohn Marino "public:\n");
11905796c8dcSSimon Schubert }
11915796c8dcSSimon Schubert }
11925796c8dcSSimon Schubert
11935796c8dcSSimon Schubert print_spaces_filtered (level + 4, stream);
11945796c8dcSSimon Schubert if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
11955796c8dcSSimon Schubert fprintf_filtered (stream, "virtual ");
11965796c8dcSSimon Schubert else if (TYPE_FN_FIELD_STATIC_P (f, j))
11975796c8dcSSimon Schubert fprintf_filtered (stream, "static ");
11985796c8dcSSimon Schubert if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
11995796c8dcSSimon Schubert {
12005796c8dcSSimon Schubert /* Keep GDB from crashing here. */
1201c50c785cSJohn Marino fprintf_filtered (stream,
1202c50c785cSJohn Marino _("<undefined type> %s;\n"),
12035796c8dcSSimon Schubert TYPE_FN_FIELD_PHYSNAME (f, j));
12045796c8dcSSimon Schubert break;
12055796c8dcSSimon Schubert }
1206c50c785cSJohn Marino else if (!is_constructor /* Constructors don't
1207c50c785cSJohn Marino have declared
1208c50c785cSJohn Marino types. */
1209cf7f2e2dSJohn Marino && !is_full_physname_constructor /* " " */
1210cf7f2e2dSJohn Marino && !is_type_conversion_operator (type, i, j))
12115796c8dcSSimon Schubert {
1212*ef5ccd6cSJohn Marino c_print_type (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1213*ef5ccd6cSJohn Marino "", stream, -1, 0,
1214*ef5ccd6cSJohn Marino &local_flags);
12155796c8dcSSimon Schubert fputs_filtered (" ", stream);
12165796c8dcSSimon Schubert }
12175796c8dcSSimon Schubert if (TYPE_FN_FIELD_STUB (f, j))
1218a45ae5f8SJohn Marino {
1219a45ae5f8SJohn Marino char *tem;
1220a45ae5f8SJohn Marino
12215796c8dcSSimon Schubert /* Build something we can demangle. */
1222a45ae5f8SJohn Marino tem = gdb_mangle_name (type, i, j);
1223a45ae5f8SJohn Marino make_cleanup (xfree, tem);
1224a45ae5f8SJohn Marino mangled_name = tem;
1225a45ae5f8SJohn Marino }
12265796c8dcSSimon Schubert else
12275796c8dcSSimon Schubert mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
12285796c8dcSSimon Schubert
12295796c8dcSSimon Schubert demangled_name =
12305796c8dcSSimon Schubert cplus_demangle (mangled_name,
12315796c8dcSSimon Schubert DMGL_ANSI | DMGL_PARAMS);
12325796c8dcSSimon Schubert if (demangled_name == NULL)
12335796c8dcSSimon Schubert {
1234c50c785cSJohn Marino /* In some cases (for instance with the HP
1235c50c785cSJohn Marino demangling), if a function has more than 10
1236c50c785cSJohn Marino arguments, the demangling will fail.
1237c50c785cSJohn Marino Let's try to reconstruct the function
1238c50c785cSJohn Marino signature from the symbol information. */
12395796c8dcSSimon Schubert if (!TYPE_FN_FIELD_STUB (f, j))
12405796c8dcSSimon Schubert {
12415796c8dcSSimon Schubert int staticp = TYPE_FN_FIELD_STATIC_P (f, j);
12425796c8dcSSimon Schubert struct type *mtype = TYPE_FN_FIELD_TYPE (f, j);
1243cf7f2e2dSJohn Marino
12445796c8dcSSimon Schubert cp_type_print_method_args (mtype,
12455796c8dcSSimon Schubert "",
12465796c8dcSSimon Schubert method_name,
12475796c8dcSSimon Schubert staticp,
1248*ef5ccd6cSJohn Marino stream, &local_flags);
12495796c8dcSSimon Schubert }
12505796c8dcSSimon Schubert else
1251c50c785cSJohn Marino fprintf_filtered (stream,
1252c50c785cSJohn Marino _("<badly mangled name '%s'>"),
12535796c8dcSSimon Schubert mangled_name);
12545796c8dcSSimon Schubert }
12555796c8dcSSimon Schubert else
12565796c8dcSSimon Schubert {
12575796c8dcSSimon Schubert char *p;
12585796c8dcSSimon Schubert char *demangled_no_class
12595796c8dcSSimon Schubert = remove_qualifiers (demangled_name);
12605796c8dcSSimon Schubert
1261c50c785cSJohn Marino /* Get rid of the `static' appended by the
1262c50c785cSJohn Marino demangler. */
12635796c8dcSSimon Schubert p = strstr (demangled_no_class, " static");
12645796c8dcSSimon Schubert if (p != NULL)
12655796c8dcSSimon Schubert {
12665796c8dcSSimon Schubert int length = p - demangled_no_class;
1267a45ae5f8SJohn Marino char *demangled_no_static;
1268cf7f2e2dSJohn Marino
1269c50c785cSJohn Marino demangled_no_static
1270c50c785cSJohn Marino = (char *) xmalloc (length + 1);
1271c50c785cSJohn Marino strncpy (demangled_no_static,
1272c50c785cSJohn Marino demangled_no_class, length);
12735796c8dcSSimon Schubert *(demangled_no_static + length) = '\0';
12745796c8dcSSimon Schubert fputs_filtered (demangled_no_static, stream);
12755796c8dcSSimon Schubert xfree (demangled_no_static);
12765796c8dcSSimon Schubert }
12775796c8dcSSimon Schubert else
12785796c8dcSSimon Schubert fputs_filtered (demangled_no_class, stream);
12795796c8dcSSimon Schubert xfree (demangled_name);
12805796c8dcSSimon Schubert }
12815796c8dcSSimon Schubert
1282a45ae5f8SJohn Marino do_cleanups (inner_cleanup);
12835796c8dcSSimon Schubert
12845796c8dcSSimon Schubert fprintf_filtered (stream, ";\n");
12855796c8dcSSimon Schubert }
12865796c8dcSSimon Schubert }
12875796c8dcSSimon Schubert
1288cf7f2e2dSJohn Marino /* Print typedefs defined in this class. */
1289cf7f2e2dSJohn Marino
1290*ef5ccd6cSJohn Marino if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0 && flags->print_typedefs)
1291cf7f2e2dSJohn Marino {
1292cf7f2e2dSJohn Marino if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0)
1293cf7f2e2dSJohn Marino fprintf_filtered (stream, "\n");
1294cf7f2e2dSJohn Marino
1295cf7f2e2dSJohn Marino for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); i++)
1296cf7f2e2dSJohn Marino {
1297cf7f2e2dSJohn Marino struct type *target = TYPE_TYPEDEF_FIELD_TYPE (type, i);
1298cf7f2e2dSJohn Marino
1299cf7f2e2dSJohn Marino /* Dereference the typedef declaration itself. */
1300cf7f2e2dSJohn Marino gdb_assert (TYPE_CODE (target) == TYPE_CODE_TYPEDEF);
1301cf7f2e2dSJohn Marino target = TYPE_TARGET_TYPE (target);
1302cf7f2e2dSJohn Marino
1303cf7f2e2dSJohn Marino print_spaces_filtered (level + 4, stream);
1304cf7f2e2dSJohn Marino fprintf_filtered (stream, "typedef ");
1305*ef5ccd6cSJohn Marino
1306*ef5ccd6cSJohn Marino /* We want to print typedefs with substitutions
1307*ef5ccd6cSJohn Marino from the template parameters or globally-known
1308*ef5ccd6cSJohn Marino typedefs but not local typedefs. */
1309*ef5ccd6cSJohn Marino c_print_type (target,
1310*ef5ccd6cSJohn Marino TYPE_TYPEDEF_FIELD_NAME (type, i),
1311*ef5ccd6cSJohn Marino stream, show - 1, level + 4,
1312*ef5ccd6cSJohn Marino &semi_local_flags);
1313cf7f2e2dSJohn Marino fprintf_filtered (stream, ";\n");
1314cf7f2e2dSJohn Marino }
1315cf7f2e2dSJohn Marino }
1316cf7f2e2dSJohn Marino
13175796c8dcSSimon Schubert fprintfi_filtered (level, stream, "}");
1318*ef5ccd6cSJohn Marino }
13195796c8dcSSimon Schubert
1320*ef5ccd6cSJohn Marino do_cleanups (local_cleanups);
13215796c8dcSSimon Schubert }
13225796c8dcSSimon Schubert break;
13235796c8dcSSimon Schubert
13245796c8dcSSimon Schubert case TYPE_CODE_ENUM:
13255796c8dcSSimon Schubert c_type_print_modifier (type, stream, 0, 1);
13265796c8dcSSimon Schubert fprintf_filtered (stream, "enum ");
13275796c8dcSSimon Schubert /* Print the tag name if it exists.
13285796c8dcSSimon Schubert The aCC compiler emits a spurious
13295796c8dcSSimon Schubert "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
13305796c8dcSSimon Schubert tag for unnamed struct/union/enum's, which we don't
13315796c8dcSSimon Schubert want to print. */
1332cf7f2e2dSJohn Marino if (TYPE_TAG_NAME (type) != NULL
1333cf7f2e2dSJohn Marino && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
13345796c8dcSSimon Schubert {
1335*ef5ccd6cSJohn Marino print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
13365796c8dcSSimon Schubert if (show > 0)
13375796c8dcSSimon Schubert fputs_filtered (" ", stream);
13385796c8dcSSimon Schubert }
13395796c8dcSSimon Schubert
13405796c8dcSSimon Schubert wrap_here (" ");
13415796c8dcSSimon Schubert if (show < 0)
13425796c8dcSSimon Schubert {
1343c50c785cSJohn Marino /* If we just printed a tag name, no need to print anything
1344c50c785cSJohn Marino else. */
13455796c8dcSSimon Schubert if (TYPE_TAG_NAME (type) == NULL)
13465796c8dcSSimon Schubert fprintf_filtered (stream, "{...}");
13475796c8dcSSimon Schubert }
13485796c8dcSSimon Schubert else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
13495796c8dcSSimon Schubert {
1350*ef5ccd6cSJohn Marino LONGEST lastval = 0;
1351*ef5ccd6cSJohn Marino
13525796c8dcSSimon Schubert fprintf_filtered (stream, "{");
13535796c8dcSSimon Schubert len = TYPE_NFIELDS (type);
13545796c8dcSSimon Schubert for (i = 0; i < len; i++)
13555796c8dcSSimon Schubert {
13565796c8dcSSimon Schubert QUIT;
13575796c8dcSSimon Schubert if (i)
13585796c8dcSSimon Schubert fprintf_filtered (stream, ", ");
13595796c8dcSSimon Schubert wrap_here (" ");
13605796c8dcSSimon Schubert fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1361*ef5ccd6cSJohn Marino if (lastval != TYPE_FIELD_ENUMVAL (type, i))
13625796c8dcSSimon Schubert {
1363*ef5ccd6cSJohn Marino fprintf_filtered (stream, " = %s",
1364*ef5ccd6cSJohn Marino plongest (TYPE_FIELD_ENUMVAL (type, i)));
1365*ef5ccd6cSJohn Marino lastval = TYPE_FIELD_ENUMVAL (type, i);
13665796c8dcSSimon Schubert }
13675796c8dcSSimon Schubert lastval++;
13685796c8dcSSimon Schubert }
13695796c8dcSSimon Schubert fprintf_filtered (stream, "}");
13705796c8dcSSimon Schubert }
13715796c8dcSSimon Schubert break;
13725796c8dcSSimon Schubert
13735796c8dcSSimon Schubert case TYPE_CODE_VOID:
13745796c8dcSSimon Schubert fprintf_filtered (stream, "void");
13755796c8dcSSimon Schubert break;
13765796c8dcSSimon Schubert
13775796c8dcSSimon Schubert case TYPE_CODE_UNDEF:
13785796c8dcSSimon Schubert fprintf_filtered (stream, _("struct <unknown>"));
13795796c8dcSSimon Schubert break;
13805796c8dcSSimon Schubert
13815796c8dcSSimon Schubert case TYPE_CODE_ERROR:
1382cf7f2e2dSJohn Marino fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
13835796c8dcSSimon Schubert break;
13845796c8dcSSimon Schubert
13855796c8dcSSimon Schubert case TYPE_CODE_RANGE:
1386c50c785cSJohn Marino /* This should not occur. */
13875796c8dcSSimon Schubert fprintf_filtered (stream, _("<range type>"));
13885796c8dcSSimon Schubert break;
13895796c8dcSSimon Schubert
13905796c8dcSSimon Schubert case TYPE_CODE_NAMESPACE:
13915796c8dcSSimon Schubert fputs_filtered ("namespace ", stream);
13925796c8dcSSimon Schubert fputs_filtered (TYPE_TAG_NAME (type), stream);
13935796c8dcSSimon Schubert break;
13945796c8dcSSimon Schubert
13955796c8dcSSimon Schubert default:
1396c50c785cSJohn Marino /* Handle types not explicitly handled by the other cases, such
1397c50c785cSJohn Marino as fundamental types. For these, just print whatever the
1398c50c785cSJohn Marino type name is, as recorded in the type itself. If there is no
1399c50c785cSJohn Marino type name, then complain. */
14005796c8dcSSimon Schubert if (TYPE_NAME (type) != NULL)
14015796c8dcSSimon Schubert {
14025796c8dcSSimon Schubert c_type_print_modifier (type, stream, 0, 1);
1403*ef5ccd6cSJohn Marino print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
14045796c8dcSSimon Schubert }
14055796c8dcSSimon Schubert else
14065796c8dcSSimon Schubert {
1407c50c785cSJohn Marino /* At least for dump_symtab, it is important that this not
1408c50c785cSJohn Marino be an error (). */
14095796c8dcSSimon Schubert fprintf_filtered (stream, _("<invalid type code %d>"),
14105796c8dcSSimon Schubert TYPE_CODE (type));
14115796c8dcSSimon Schubert }
14125796c8dcSSimon Schubert break;
14135796c8dcSSimon Schubert }
14145796c8dcSSimon Schubert }
1415