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
))
107 java_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
110 case TYPE_CODE_STRUCT
:
111 if (TYPE_TAG_NAME (type
) != NULL
&& TYPE_TAG_NAME (type
)[0] == '[')
113 char *name
= java_demangle_type_signature (TYPE_TAG_NAME (type
));
114 fputs (name
, stream
);
119 fprintf_filtered (stream
, "class ");
120 if (TYPE_TAG_NAME (type
) != NULL
)
122 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
124 fputs_filtered (" ", stream
);
129 /* If we just printed a tag name, no need to print anything else. */
130 if (TYPE_TAG_NAME (type
) == NULL
)
131 fprintf_filtered (stream
, "{...}");
133 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
135 java_type_print_derivation_info (stream
, type
);
137 fprintf_filtered (stream
, "{\n");
138 if ((TYPE_NFIELDS (type
) == 0) && (TYPE_NFN_FIELDS (type
) == 0))
140 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
141 fprintfi_filtered (level
+ 4, stream
, "<incomplete type>\n");
143 fprintfi_filtered (level
+ 4, stream
, "<no data fields>\n");
146 /* If there is a base class for this type,
147 do not print the field that it occupies. */
149 len
= TYPE_NFIELDS (type
);
150 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
153 /* Don't print out virtual function table. */
154 if (STREQN (TYPE_FIELD_NAME (type
, i
), "_vptr", 5)
155 && is_cplus_marker ((TYPE_FIELD_NAME (type
, i
))[5]))
158 /* Don't print the dummy field "class". */
159 if (STREQN (TYPE_FIELD_NAME (type
, i
), "class", 5))
162 print_spaces_filtered (level
+ 4, stream
);
163 if (HAVE_CPLUS_STRUCT (type
))
165 if (TYPE_FIELD_PROTECTED (type
, i
))
166 fprintf_filtered (stream
, "protected ");
167 else if (TYPE_FIELD_PRIVATE (type
, i
))
168 fprintf_filtered (stream
, "private ");
170 fprintf_filtered (stream
, "public ");
173 if (TYPE_FIELD_STATIC (type
, i
))
175 fprintf_filtered (stream
, "static ");
177 java_print_type (TYPE_FIELD_TYPE (type
, i
),
178 TYPE_FIELD_NAME (type
, i
),
179 stream
, show
- 1, level
+ 4);
180 fprintf_filtered (stream
, ";\n");
183 /* If there are both fields and methods, put a space between. */
184 len
= TYPE_NFN_FIELDS (type
);
186 fprintf_filtered (stream
, "\n");
188 /* Print out the methods */
190 for (i
= 0; i
< len
; i
++)
192 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
193 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
194 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
195 char *name
= type_name_no_tag (type
);
196 int is_constructor
= name
&& STREQ(method_name
, name
);
197 for (j
= 0; j
< len2
; j
++)
199 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
200 int is_full_physname_constructor
=
201 ((physname
[0] == '_' && physname
[1] == '_'
202 && strchr ("0123456789Qt", physname
[2]))
203 || STREQN (physname
, "__ct__", 6)
204 || DESTRUCTOR_PREFIX_P (physname
)
205 || STREQN (physname
, "__dt__", 6));
208 print_spaces_filtered (level
+ 4, stream
);
209 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
210 fprintf_filtered (stream
, "protected ");
211 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
212 fprintf_filtered (stream
, "private ");
214 fprintf_filtered (stream
, "public ");
216 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
217 fprintf_filtered (stream
, "virtual ");
218 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
219 fprintf_filtered (stream
, "static ");
220 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
222 /* Keep GDB from crashing here. */
223 fprintf_filtered (stream
, "<undefined type> %s;\n",
224 TYPE_FN_FIELD_PHYSNAME (f
, j
));
227 else if (!is_constructor
&& !is_full_physname_constructor
)
229 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
231 fputs_filtered (" ", stream
);
233 if (TYPE_FN_FIELD_STUB (f
, j
))
234 /* Build something we can demangle. */
235 mangled_name
= gdb_mangle_name (type
, i
, j
);
237 mangled_name
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
240 cplus_demangle (mangled_name
,
241 DMGL_ANSI
| DMGL_PARAMS
| DMGL_JAVA
);
242 if (demangled_name
== NULL
)
243 fprintf_filtered (stream
, "<badly mangled name '%s'>",
247 char *demangled_no_class
= demangled_name
;
248 char *ptr
= demangled_name
;
252 if (c
== 0 || c
== '(')
255 demangled_no_class
= ptr
;
257 fputs_filtered (demangled_no_class
, stream
);
258 free (demangled_name
);
261 if (TYPE_FN_FIELD_STUB (f
, j
))
264 fprintf_filtered (stream
, ";\n");
268 fprintfi_filtered (level
, stream
, "}");
273 c_type_print_base (type
, stream
, show
, level
);
277 /* LEVEL is the depth to indent lines by. */
280 java_print_type (type
, varstring
, stream
, show
, level
)
287 java_type_print_base (type
, stream
, show
, level
);
289 if (varstring
!= NULL
&& *varstring
!= '\0')
291 fputs_filtered (" ", stream
);
292 fputs_filtered (varstring
, stream
);
295 /* For demangled function names, we have the arglist as part of the name,
296 so don't print an additional pair of ()'s */
298 demangled_args
= strchr(varstring
, '(') != NULL
;
299 c_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);