1 /* Support for printing Java types for GDB, the GNU debugger.
2 Copyright 1997-2000 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,
19 Boston, MA 02111-1307, USA. */
28 #include "gdb_string.h"
29 #include "typeprint.h"
34 static void java_type_print_base (struct type
* type
,
35 struct ui_file
*stream
, int show
,
39 java_type_print_derivation_info (struct ui_file
*stream
, struct type
*type
)
46 n_bases
= TYPE_N_BASECLASSES (type
);
48 for (i
= 0, prev
= 0; i
< n_bases
; i
++)
52 kind
= BASETYPE_VIA_VIRTUAL (type
, i
) ? 'I' : 'E';
54 fputs_filtered (kind
== prev
? ", "
55 : kind
== 'I' ? " implements "
59 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
61 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
65 fputs_filtered (" ", stream
);
68 /* Print the name of the type (or the ultimate pointer target,
69 function value or array element), or the description of a
72 SHOW positive means print details about the type (e.g. enum values),
73 and print structure elements passing SHOW - 1 for show.
74 SHOW negative means just print the type name or struct tag if there is one.
75 If there is no name, print something sensible but concise like
77 SHOW zero means just print the type name or struct tag if there is one.
78 If there is no name, print something sensible but not as concise like
79 "struct {int x; int y;}".
81 LEVEL is the number of spaces to indent by.
82 We increase it for some recursive calls. */
85 java_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
98 fputs_filtered ("<type unknown>", stream
);
102 /* When SHOW is zero or less, and there is a valid type name, then always
103 just print the type name directly from the type. */
106 && TYPE_NAME (type
) != NULL
)
108 fputs_filtered (TYPE_NAME (type
), stream
);
112 CHECK_TYPEDEF (type
);
114 switch (TYPE_CODE (type
))
117 java_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
120 case TYPE_CODE_STRUCT
:
121 if (TYPE_TAG_NAME (type
) != NULL
&& TYPE_TAG_NAME (type
)[0] == '[')
123 char *name
= java_demangle_type_signature (TYPE_TAG_NAME (type
));
124 fputs_filtered (name
, stream
);
130 fprintf_filtered (stream
, "class ");
132 if (TYPE_TAG_NAME (type
) != NULL
)
134 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
136 fputs_filtered (" ", stream
);
143 /* If we just printed a tag name, no need to print anything else. */
144 if (TYPE_TAG_NAME (type
) == NULL
)
145 fprintf_filtered (stream
, "{...}");
147 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
149 java_type_print_derivation_info (stream
, type
);
151 fprintf_filtered (stream
, "{\n");
152 if ((TYPE_NFIELDS (type
) == 0) && (TYPE_NFN_FIELDS (type
) == 0))
154 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
155 fprintfi_filtered (level
+ 4, stream
, "<incomplete type>\n");
157 fprintfi_filtered (level
+ 4, stream
, "<no data fields>\n");
160 /* If there is a base class for this type,
161 do not print the field that it occupies. */
163 len
= TYPE_NFIELDS (type
);
164 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
167 /* Don't print out virtual function table. */
168 if (STREQN (TYPE_FIELD_NAME (type
, i
), "_vptr", 5)
169 && is_cplus_marker ((TYPE_FIELD_NAME (type
, i
))[5]))
172 /* Don't print the dummy field "class". */
173 if (STREQN (TYPE_FIELD_NAME (type
, i
), "class", 5))
176 print_spaces_filtered (level
+ 4, stream
);
178 if (HAVE_CPLUS_STRUCT (type
))
180 if (TYPE_FIELD_PROTECTED (type
, i
))
181 fprintf_filtered (stream
, "protected ");
182 else if (TYPE_FIELD_PRIVATE (type
, i
))
183 fprintf_filtered (stream
, "private ");
185 fprintf_filtered (stream
, "public ");
188 if (TYPE_FIELD_STATIC (type
, i
))
189 fprintf_filtered (stream
, "static ");
191 java_print_type (TYPE_FIELD_TYPE (type
, i
),
192 TYPE_FIELD_NAME (type
, i
),
193 stream
, show
- 1, level
+ 4);
195 fprintf_filtered (stream
, ";\n");
198 /* If there are both fields and methods, put a space between. */
199 len
= TYPE_NFN_FIELDS (type
);
201 fprintf_filtered (stream
, "\n");
203 /* Print out the methods */
205 for (i
= 0; i
< len
; i
++)
214 f
= TYPE_FN_FIELDLIST1 (type
, i
);
215 n_overloads
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
216 method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
217 name
= type_name_no_tag (type
);
218 is_constructor
= name
&& STREQ (method_name
, name
);
220 for (j
= 0; j
< n_overloads
; j
++)
223 int is_full_physname_constructor
;
225 physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
227 is_full_physname_constructor
=
228 ((physname
[0] == '_' && physname
[1] == '_'
229 && strchr ("0123456789Qt", physname
[2]))
230 || STREQN (physname
, "__ct__", 6)
231 || DESTRUCTOR_PREFIX_P (physname
)
232 || STREQN (physname
, "__dt__", 6));
236 print_spaces_filtered (level
+ 4, stream
);
238 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
239 fprintf_filtered (stream
, "protected ");
240 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
241 fprintf_filtered (stream
, "private ");
242 else if (TYPE_FN_FIELD_PUBLIC (f
, j
))
243 fprintf_filtered (stream
, "public ");
245 if (TYPE_FN_FIELD_ABSTRACT (f
, j
))
246 fprintf_filtered (stream
, "abstract ");
247 if (TYPE_FN_FIELD_STATIC (f
, j
))
248 fprintf_filtered (stream
, "static ");
249 if (TYPE_FN_FIELD_FINAL (f
, j
))
250 fprintf_filtered (stream
, "final ");
251 if (TYPE_FN_FIELD_SYNCHRONIZED (f
, j
))
252 fprintf_filtered (stream
, "synchronized ");
253 if (TYPE_FN_FIELD_NATIVE (f
, j
))
254 fprintf_filtered (stream
, "native ");
256 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
258 /* Keep GDB from crashing here. */
259 fprintf_filtered (stream
, "<undefined type> %s;\n",
260 TYPE_FN_FIELD_PHYSNAME (f
, j
));
263 else if (!is_constructor
&& !is_full_physname_constructor
)
265 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
267 fputs_filtered (" ", stream
);
270 if (TYPE_FN_FIELD_STUB (f
, j
))
271 /* Build something we can demangle. */
272 mangled_name
= gdb_mangle_name (type
, i
, j
);
274 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
277 cplus_demangle (mangled_name
,
278 DMGL_ANSI
| DMGL_PARAMS
| DMGL_JAVA
);
280 if (demangled_name
== NULL
)
281 demangled_name
= xstrdup (mangled_name
);
284 char *demangled_no_class
;
287 ptr
= demangled_no_class
= demangled_name
;
295 if (c
== 0 || c
== '(')
298 demangled_no_class
= ptr
;
301 fputs_filtered (demangled_no_class
, stream
);
302 free (demangled_name
);
305 if (TYPE_FN_FIELD_STUB (f
, j
))
308 fprintf_filtered (stream
, ";\n");
312 fprintfi_filtered (level
, stream
, "}");
317 c_type_print_base (type
, stream
, show
, level
);
321 /* LEVEL is the depth to indent lines by. */
323 extern void c_type_print_varspec_suffix (struct type
*, struct ui_file
*,
327 java_print_type (struct type
*type
, char *varstring
, struct ui_file
*stream
,
332 java_type_print_base (type
, stream
, show
, level
);
334 if (varstring
!= NULL
&& *varstring
!= '\0')
336 fputs_filtered (" ", stream
);
337 fputs_filtered (varstring
, stream
);
340 /* For demangled function names, we have the arglist as part of the name,
341 so don't print an additional pair of ()'s */
343 demangled_args
= strchr (varstring
, '(') != NULL
;
344 c_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);