1 /* Support for printing Java types for GDB, the GNU debugger.
2 Copyright 1997 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "gdb_string.h"
30 java_type_print_derivation_info (stream, type)
36 int n_bases = TYPE_N_BASECLASSES (type);
39 for (i = 0; i < n_bases; i++)
41 int kind = BASETYPE_VIA_VIRTUAL(type, i) ? 'I' : 'E';
42 fputs_filtered (kind == prev ? ", "
43 : kind == 'I' ? " implements "
47 name = type_name_no_tag (TYPE_BASECLASS (type, i));
48 fprintf_filtered (stream, "%s", name ? name : "(null)");
52 fputs_filtered (" ", stream);
56 /* Print the name of the type (or the ultimate pointer target,
57 function value or array element), or the description of a
60 SHOW positive means print details about the type (e.g. enum values),
61 and print structure elements passing SHOW - 1 for show.
62 SHOW negative means just print the type name or struct tag if there is one.
63 If there is no name, print something sensible but concise like
65 SHOW zero means just print the type name or struct tag if there is one.
66 If there is no name, print something sensible but not as concise like
67 "struct {int x; int y;}".
69 LEVEL is the number of spaces to indent by.
70 We increase it for some recursive calls. */
73 java_type_print_base (type, stream, show, level)
88 fputs_filtered ("<type unknown>", stream);
92 /* When SHOW is zero or less, and there is a valid type name, then always
93 just print the type name directly from the type. */
96 && TYPE_NAME (type) != NULL)
98 fputs_filtered (TYPE_NAME (type), stream);
102 CHECK_TYPEDEF (type);
104 switch (TYPE_CODE (type))
106 case TYPE_CODE_STRUCT:
107 fprintf_filtered (stream, "class ");
108 if (TYPE_TAG_NAME (type) != NULL)
110 fputs_filtered (TYPE_TAG_NAME (type), stream);
112 fputs_filtered (" ", stream);
117 /* If we just printed a tag name, no need to print anything else. */
118 if (TYPE_TAG_NAME (type) == NULL)
119 fprintf_filtered (stream, "{...}");
121 else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
123 java_type_print_derivation_info (stream, type);
125 fprintf_filtered (stream, "{\n");
126 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
128 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
129 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
131 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
134 /* If there is a base class for this type,
135 do not print the field that it occupies. */
137 len = TYPE_NFIELDS (type);
138 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
141 /* Don't print out virtual function table. */
142 if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5)
143 && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
146 /* If this is a C++ class we can print the various C++ section
149 print_spaces_filtered (level + 4, stream);
150 if (HAVE_CPLUS_STRUCT (type))
152 if (TYPE_FIELD_PROTECTED (type, i))
153 fprintf_filtered (stream, "protected ");
154 else if (TYPE_FIELD_PRIVATE (type, i))
155 fprintf_filtered (stream, "private ");
157 fprintf_filtered (stream, "public ");
160 if (TYPE_FIELD_STATIC (type, i))
162 fprintf_filtered (stream, "static ");
164 java_print_type (TYPE_FIELD_TYPE (type, i),
165 TYPE_FIELD_NAME (type, i),
166 stream, show - 1, level + 4);
167 fprintf_filtered (stream, ";\n");
170 /* If there are both fields and methods, put a space between. */
171 len = TYPE_NFN_FIELDS (type);
173 fprintf_filtered (stream, "\n");
175 /* Print out the methods */
177 for (i = 0; i < len; i++)
179 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
180 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
181 char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
182 char *name = type_name_no_tag (type);
183 int is_constructor = name && STREQ(method_name, name);
184 for (j = 0; j < len2; j++)
186 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
187 int is_full_physname_constructor =
188 ((physname[0] == '_' && physname[1] == '_'
189 && strchr ("0123456789Qt", physname[2]))
190 || STREQN (physname, "__ct__", 6)
191 || DESTRUCTOR_PREFIX_P (physname)
192 || STREQN (physname, "__dt__", 6));
195 print_spaces_filtered (level + 4, stream);
196 if (TYPE_FN_FIELD_PROTECTED (f, j))
197 fprintf_filtered (stream, "protected ");
198 else if (TYPE_FN_FIELD_PRIVATE (f, j))
199 fprintf_filtered (stream, "private ");
201 fprintf_filtered (stream, "public ");
203 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
204 fprintf_filtered (stream, "virtual ");
205 else if (TYPE_FN_FIELD_STATIC_P (f, j))
206 fprintf_filtered (stream, "static ");
207 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
209 /* Keep GDB from crashing here. */
210 fprintf_filtered (stream, "<undefined type> %s;\n",
211 TYPE_FN_FIELD_PHYSNAME (f, j));
214 else if (!is_constructor && !is_full_physname_constructor)
216 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
218 fputs_filtered (" ", stream);
220 if (TYPE_FN_FIELD_STUB (f, j))
221 /* Build something we can demangle. */
222 mangled_name = gdb_mangle_name (type, i, j);
224 mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
227 cplus_demangle (mangled_name,
228 DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
229 if (demangled_name == NULL)
230 fprintf_filtered (stream, "<badly mangled name '%s'>",
234 char *demangled_no_class = demangled_name;
235 char *ptr = demangled_name;
239 if (c == 0 || c == '(')
242 demangled_no_class = ptr;
244 fputs_filtered (demangled_no_class, stream);
245 free (demangled_name);
248 if (TYPE_FN_FIELD_STUB (f, j))
251 fprintf_filtered (stream, ";\n");
255 fprintfi_filtered (level, stream, "}");
260 c_type_print_base (type, stream, show, level);
264 /* LEVEL is the depth to indent lines by. */
267 java_print_type (type, varstring, stream, show, level)
274 java_type_print_base (type, stream, show, level);
276 if (varstring != NULL && *varstring != '\0')
278 fputs_filtered (" ", stream);
279 fputs_filtered (varstring, stream);
282 /* For demangled function names, we have the arglist as part of the name,
283 so don't print an additional pair of ()'s */
285 demangled_args = strchr(varstring, '(') != NULL;
286 c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);