Commit | Line | Data |
---|---|---|
14f9c5c9 | 1 | /* Support for printing Ada types for GDB, the GNU debugger. |
4c4b4cd2 PH |
2 | Copyright 1986, 1988, 1989, 1991, 1997, 1998, 1999, 2000, |
3 | 2001, 2002, 2003, 2004 Free Software Foundation, Inc. | |
14f9c5c9 AS |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | #include "defs.h" | |
04ea0df1 | 22 | #include "gdb_obstack.h" |
14f9c5c9 AS |
23 | #include "bfd.h" /* Binary File Description */ |
24 | #include "symtab.h" | |
25 | #include "gdbtypes.h" | |
26 | #include "expression.h" | |
27 | #include "value.h" | |
28 | #include "gdbcore.h" | |
29 | #include "target.h" | |
30 | #include "command.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "language.h" | |
33 | #include "demangle.h" | |
34 | #include "c-lang.h" | |
35 | #include "typeprint.h" | |
36 | #include "ada-lang.h" | |
37 | ||
38 | #include <ctype.h> | |
0c30c098 | 39 | #include "gdb_string.h" |
14f9c5c9 AS |
40 | #include <errno.h> |
41 | ||
d2e4a39e | 42 | static int print_record_field_types (struct type *, struct type *, |
14f9c5c9 AS |
43 | struct ui_file *, int, int); |
44 | ||
d2e4a39e | 45 | static void print_array_type (struct type *, struct ui_file *, int, int); |
14f9c5c9 | 46 | |
d2e4a39e AS |
47 | static void print_choices (struct type *, int, struct ui_file *, |
48 | struct type *); | |
14f9c5c9 | 49 | |
d2e4a39e | 50 | static void print_range (struct type *, struct ui_file *); |
14f9c5c9 | 51 | |
d2e4a39e AS |
52 | static void print_range_bound (struct type *, char *, int *, |
53 | struct ui_file *); | |
14f9c5c9 | 54 | |
d2e4a39e AS |
55 | static void |
56 | print_dynamic_range_bound (struct type *, const char *, int, | |
57 | const char *, struct ui_file *); | |
14f9c5c9 | 58 | |
d2e4a39e | 59 | static void print_range_type_named (char *, struct ui_file *); |
14f9c5c9 AS |
60 | \f |
61 | ||
d2e4a39e AS |
62 | |
63 | static char *name_buffer; | |
14f9c5c9 AS |
64 | static int name_buffer_len; |
65 | ||
4c4b4cd2 PH |
66 | /* The (decoded) Ada name of TYPE. This value persists until the |
67 | next call. */ | |
14f9c5c9 | 68 | |
d2e4a39e | 69 | static char * |
4c4b4cd2 | 70 | decoded_type_name (struct type *type) |
14f9c5c9 AS |
71 | { |
72 | if (ada_type_name (type) == NULL) | |
73 | return NULL; | |
d2e4a39e | 74 | else |
14f9c5c9 | 75 | { |
d2e4a39e AS |
76 | char *raw_name = ada_type_name (type); |
77 | char *s, *q; | |
14f9c5c9 AS |
78 | |
79 | if (name_buffer == NULL || name_buffer_len <= strlen (raw_name)) | |
80 | { | |
81 | name_buffer_len = 16 + 2 * strlen (raw_name); | |
82 | name_buffer = xrealloc (name_buffer, name_buffer_len); | |
83 | } | |
84 | strcpy (name_buffer, raw_name); | |
85 | ||
d2e4a39e | 86 | s = (char *) strstr (name_buffer, "___"); |
14f9c5c9 AS |
87 | if (s != NULL) |
88 | *s = '\0'; | |
89 | ||
90 | s = name_buffer + strlen (name_buffer) - 1; | |
91 | while (s > name_buffer && (s[0] != '_' || s[-1] != '_')) | |
92 | s -= 1; | |
93 | ||
94 | if (s == name_buffer) | |
95 | return name_buffer; | |
96 | ||
d2e4a39e | 97 | if (!islower (s[1])) |
14f9c5c9 AS |
98 | return NULL; |
99 | ||
100 | for (s = q = name_buffer; *s != '\0'; q += 1) | |
101 | { | |
102 | if (s[0] == '_' && s[1] == '_') | |
103 | { | |
d2e4a39e AS |
104 | *q = '.'; |
105 | s += 2; | |
14f9c5c9 AS |
106 | } |
107 | else | |
108 | { | |
d2e4a39e AS |
109 | *q = *s; |
110 | s += 1; | |
14f9c5c9 AS |
111 | } |
112 | } | |
113 | *q = '\0'; | |
114 | return name_buffer; | |
115 | } | |
116 | } | |
117 | ||
118 | ||
4c4b4cd2 | 119 | /* Print a description of a type in the format of a |
14f9c5c9 | 120 | typedef for the current language. |
4c4b4cd2 | 121 | NEW is the new name for a type TYPE. */ |
14f9c5c9 AS |
122 | |
123 | void | |
d2e4a39e AS |
124 | ada_typedef_print (struct type *type, struct symbol *new, |
125 | struct ui_file *stream) | |
14f9c5c9 | 126 | { |
323e0a4a | 127 | /* XXX: type_sprint */ |
0b48a291 | 128 | fprintf_filtered (stream, "type %.*s is ", |
de5ad195 DC |
129 | ada_name_prefix_len (SYMBOL_PRINT_NAME (new)), |
130 | SYMBOL_PRINT_NAME (new)); | |
14f9c5c9 AS |
131 | type_print (type, "", stream, 1); |
132 | } | |
133 | ||
4c4b4cd2 | 134 | /* Print range type TYPE on STREAM. */ |
14f9c5c9 AS |
135 | |
136 | static void | |
d2e4a39e | 137 | print_range (struct type *type, struct ui_file *stream) |
14f9c5c9 | 138 | { |
d2e4a39e | 139 | struct type *target_type; |
14f9c5c9 AS |
140 | target_type = TYPE_TARGET_TYPE (type); |
141 | if (target_type == NULL) | |
142 | target_type = type; | |
143 | ||
d2e4a39e | 144 | switch (TYPE_CODE (target_type)) |
14f9c5c9 AS |
145 | { |
146 | case TYPE_CODE_RANGE: | |
147 | case TYPE_CODE_INT: | |
148 | case TYPE_CODE_BOOL: | |
149 | case TYPE_CODE_CHAR: | |
150 | case TYPE_CODE_ENUM: | |
151 | break; | |
152 | default: | |
72d5681a | 153 | target_type = builtin_type_int; |
14f9c5c9 AS |
154 | break; |
155 | } | |
156 | ||
157 | if (TYPE_NFIELDS (type) < 2) | |
158 | { | |
4c4b4cd2 | 159 | /* A range needs at least 2 bounds to be printed. If there are less |
14f9c5c9 | 160 | than 2, just print the type name instead of the range itself. |
4c4b4cd2 | 161 | This check handles cases such as characters, for example. |
14f9c5c9 AS |
162 | |
163 | Note that if the name is not defined, then we don't print anything. | |
164 | */ | |
165 | fprintf_filtered (stream, "%.*s", | |
d2e4a39e AS |
166 | ada_name_prefix_len (TYPE_NAME (type)), |
167 | TYPE_NAME (type)); | |
14f9c5c9 AS |
168 | } |
169 | else | |
170 | { | |
171 | /* We extract the range type bounds respectively from the first element | |
172 | and the last element of the type->fields array */ | |
173 | const LONGEST lower_bound = (LONGEST) TYPE_LOW_BOUND (type); | |
174 | const LONGEST upper_bound = | |
d2e4a39e | 175 | (LONGEST) TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1); |
14f9c5c9 AS |
176 | |
177 | ada_print_scalar (target_type, lower_bound, stream); | |
178 | fprintf_filtered (stream, " .. "); | |
179 | ada_print_scalar (target_type, upper_bound, stream); | |
180 | } | |
181 | } | |
182 | ||
183 | /* Print the number or discriminant bound at BOUNDS+*N on STREAM, and | |
4c4b4cd2 | 184 | set *N past the bound and its delimiter, if any. */ |
14f9c5c9 AS |
185 | |
186 | static void | |
d2e4a39e AS |
187 | print_range_bound (struct type *type, char *bounds, int *n, |
188 | struct ui_file *stream) | |
14f9c5c9 AS |
189 | { |
190 | LONGEST B; | |
191 | if (ada_scan_number (bounds, *n, &B, n)) | |
192 | { | |
4c4b4cd2 PH |
193 | /* STABS decodes all range types which bounds are 0 .. -1 as |
194 | unsigned integers (ie. the type code is TYPE_CODE_INT, not | |
195 | TYPE_CODE_RANGE). Unfortunately, ada_print_scalar() relies | |
196 | on the unsigned flag to determine whether the bound should | |
197 | be printed as a signed or an unsigned value. This causes | |
198 | the upper bound of the 0 .. -1 range types to be printed as | |
199 | a very large unsigned number instead of -1. | |
200 | To workaround this stabs deficiency, we replace the TYPE by | |
201 | builtin_type_long when we detect that the bound is negative, | |
202 | and the type is a TYPE_CODE_INT. The bound is negative when | |
203 | 'm' is the last character of the number scanned in BOUNDS. */ | |
204 | if (bounds[*n - 1] == 'm' && TYPE_CODE (type) == TYPE_CODE_INT) | |
205 | type = builtin_type_long; | |
14f9c5c9 AS |
206 | ada_print_scalar (type, B, stream); |
207 | if (bounds[*n] == '_') | |
208 | *n += 2; | |
209 | } | |
210 | else | |
211 | { | |
212 | int bound_len; | |
d2e4a39e AS |
213 | char *bound = bounds + *n; |
214 | char *pend; | |
14f9c5c9 AS |
215 | |
216 | pend = strstr (bound, "__"); | |
217 | if (pend == NULL) | |
218 | *n += bound_len = strlen (bound); | |
d2e4a39e | 219 | else |
14f9c5c9 AS |
220 | { |
221 | bound_len = pend - bound; | |
222 | *n += bound_len + 2; | |
223 | } | |
224 | fprintf_filtered (stream, "%.*s", bound_len, bound); | |
225 | } | |
226 | } | |
227 | ||
228 | /* Assuming NAME[0 .. NAME_LEN-1] is the name of a range type, print | |
229 | the value (if found) of the bound indicated by SUFFIX ("___L" or | |
4c4b4cd2 | 230 | "___U") according to the ___XD conventions. */ |
14f9c5c9 AS |
231 | |
232 | static void | |
d2e4a39e AS |
233 | print_dynamic_range_bound (struct type *type, const char *name, int name_len, |
234 | const char *suffix, struct ui_file *stream) | |
14f9c5c9 AS |
235 | { |
236 | static char *name_buf = NULL; | |
237 | static size_t name_buf_len = 0; | |
238 | LONGEST B; | |
239 | int OK; | |
240 | ||
241 | GROW_VECT (name_buf, name_buf_len, name_len + strlen (suffix) + 1); | |
242 | strncpy (name_buf, name, name_len); | |
243 | strcpy (name_buf + name_len, suffix); | |
244 | ||
4c4b4cd2 | 245 | B = get_int_var_value (name_buf, &OK); |
14f9c5c9 AS |
246 | if (OK) |
247 | ada_print_scalar (type, B, stream); | |
248 | else | |
249 | fprintf_filtered (stream, "?"); | |
250 | } | |
251 | ||
4c4b4cd2 | 252 | /* Print the range type named NAME. */ |
14f9c5c9 AS |
253 | |
254 | static void | |
d2e4a39e | 255 | print_range_type_named (char *name, struct ui_file *stream) |
14f9c5c9 AS |
256 | { |
257 | struct type *raw_type = ada_find_any_type (name); | |
258 | struct type *base_type; | |
d2e4a39e | 259 | char *subtype_info; |
14f9c5c9 AS |
260 | |
261 | if (raw_type == NULL) | |
262 | base_type = builtin_type_int; | |
263 | else if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE) | |
264 | base_type = TYPE_TARGET_TYPE (raw_type); | |
265 | else | |
266 | base_type = raw_type; | |
267 | ||
268 | subtype_info = strstr (name, "___XD"); | |
269 | if (subtype_info == NULL && raw_type == NULL) | |
270 | fprintf_filtered (stream, "? .. ?"); | |
271 | else if (subtype_info == NULL) | |
272 | print_range (raw_type, stream); | |
273 | else | |
274 | { | |
275 | int prefix_len = subtype_info - name; | |
276 | char *bounds_str; | |
277 | int n; | |
278 | ||
279 | subtype_info += 5; | |
280 | bounds_str = strchr (subtype_info, '_'); | |
281 | n = 1; | |
282 | ||
d2e4a39e | 283 | if (*subtype_info == 'L') |
14f9c5c9 | 284 | { |
4c4b4cd2 | 285 | print_range_bound (base_type, bounds_str, &n, stream); |
14f9c5c9 AS |
286 | subtype_info += 1; |
287 | } | |
288 | else | |
4c4b4cd2 | 289 | print_dynamic_range_bound (base_type, name, prefix_len, "___L", |
d2e4a39e | 290 | stream); |
14f9c5c9 AS |
291 | |
292 | fprintf_filtered (stream, " .. "); | |
293 | ||
d2e4a39e | 294 | if (*subtype_info == 'U') |
4c4b4cd2 | 295 | print_range_bound (base_type, bounds_str, &n, stream); |
14f9c5c9 | 296 | else |
4c4b4cd2 | 297 | print_dynamic_range_bound (base_type, name, prefix_len, "___U", |
d2e4a39e | 298 | stream); |
14f9c5c9 | 299 | } |
d2e4a39e | 300 | } |
14f9c5c9 | 301 | |
4c4b4cd2 | 302 | /* Print enumerated type TYPE on STREAM. */ |
14f9c5c9 AS |
303 | |
304 | static void | |
ebf56fd3 | 305 | print_enum_type (struct type *type, struct ui_file *stream) |
14f9c5c9 AS |
306 | { |
307 | int len = TYPE_NFIELDS (type); | |
308 | int i, lastval; | |
309 | ||
310 | fprintf_filtered (stream, "("); | |
311 | wrap_here (" "); | |
312 | ||
313 | lastval = 0; | |
314 | for (i = 0; i < len; i++) | |
315 | { | |
316 | QUIT; | |
d2e4a39e AS |
317 | if (i) |
318 | fprintf_filtered (stream, ", "); | |
14f9c5c9 AS |
319 | wrap_here (" "); |
320 | fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream); | |
321 | if (lastval != TYPE_FIELD_BITPOS (type, i)) | |
322 | { | |
323 | fprintf_filtered (stream, " => %d", TYPE_FIELD_BITPOS (type, i)); | |
324 | lastval = TYPE_FIELD_BITPOS (type, i); | |
325 | } | |
326 | lastval += 1; | |
327 | } | |
328 | fprintf_filtered (stream, ")"); | |
329 | } | |
330 | ||
4c4b4cd2 | 331 | /* Print representation of Ada fixed-point type TYPE on STREAM. */ |
14f9c5c9 AS |
332 | |
333 | static void | |
ebf56fd3 | 334 | print_fixed_point_type (struct type *type, struct ui_file *stream) |
14f9c5c9 AS |
335 | { |
336 | DOUBLEST delta = ada_delta (type); | |
337 | DOUBLEST small = ada_fixed_to_float (type, 1.0); | |
338 | ||
339 | if (delta < 0.0) | |
340 | fprintf_filtered (stream, "delta ??"); | |
341 | else | |
342 | { | |
343 | fprintf_filtered (stream, "delta %g", (double) delta); | |
d2e4a39e | 344 | if (delta != small) |
14f9c5c9 AS |
345 | fprintf_filtered (stream, " <'small = %g>", (double) small); |
346 | } | |
347 | } | |
348 | ||
4c4b4cd2 | 349 | /* Print representation of special VAX floating-point type TYPE on STREAM. */ |
14f9c5c9 AS |
350 | |
351 | static void | |
ebf56fd3 | 352 | print_vax_floating_point_type (struct type *type, struct ui_file *stream) |
14f9c5c9 AS |
353 | { |
354 | fprintf_filtered (stream, "<float format %c>", | |
355 | ada_vax_float_type_suffix (type)); | |
356 | } | |
357 | ||
4c4b4cd2 PH |
358 | /* Print simple (constrained) array type TYPE on STREAM. LEVEL is the |
359 | recursion (indentation) level, in case the element type itself has | |
14f9c5c9 | 360 | nested structure, and SHOW is the number of levels of internal |
4c4b4cd2 | 361 | structure to show (see ada_print_type). */ |
14f9c5c9 AS |
362 | |
363 | static void | |
d2e4a39e AS |
364 | print_array_type (struct type *type, struct ui_file *stream, int show, |
365 | int level) | |
14f9c5c9 AS |
366 | { |
367 | int bitsize; | |
368 | int n_indices; | |
369 | ||
370 | bitsize = 0; | |
371 | fprintf_filtered (stream, "array ("); | |
372 | ||
373 | n_indices = -1; | |
d2e4a39e | 374 | if (show < 0) |
14f9c5c9 AS |
375 | fprintf_filtered (stream, "..."); |
376 | else | |
377 | { | |
378 | if (ada_is_packed_array_type (type)) | |
379 | type = ada_coerce_to_simple_array_type (type); | |
4c4b4cd2 PH |
380 | if (type == NULL) |
381 | { | |
382 | fprintf_filtered (stream, "<undecipherable array type>"); | |
383 | return; | |
384 | } | |
385 | if (ada_is_simple_array_type (type)) | |
14f9c5c9 | 386 | { |
d2e4a39e | 387 | struct type *range_desc_type = |
14f9c5c9 | 388 | ada_find_parallel_type (type, "___XA"); |
d2e4a39e | 389 | struct type *arr_type; |
14f9c5c9 AS |
390 | |
391 | bitsize = 0; | |
392 | if (range_desc_type == NULL) | |
393 | { | |
394 | for (arr_type = type; TYPE_CODE (arr_type) == TYPE_CODE_ARRAY; | |
395 | arr_type = TYPE_TARGET_TYPE (arr_type)) | |
396 | { | |
397 | if (arr_type != type) | |
398 | fprintf_filtered (stream, ", "); | |
399 | print_range (TYPE_INDEX_TYPE (arr_type), stream); | |
400 | if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0) | |
401 | bitsize = TYPE_FIELD_BITSIZE (arr_type, 0); | |
402 | } | |
403 | } | |
d2e4a39e | 404 | else |
14f9c5c9 AS |
405 | { |
406 | int k; | |
d2e4a39e AS |
407 | n_indices = TYPE_NFIELDS (range_desc_type); |
408 | for (k = 0, arr_type = type; | |
14f9c5c9 AS |
409 | k < n_indices; |
410 | k += 1, arr_type = TYPE_TARGET_TYPE (arr_type)) | |
411 | { | |
412 | if (k > 0) | |
413 | fprintf_filtered (stream, ", "); | |
d2e4a39e AS |
414 | print_range_type_named (TYPE_FIELD_NAME |
415 | (range_desc_type, k), stream); | |
14f9c5c9 AS |
416 | if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0) |
417 | bitsize = TYPE_FIELD_BITSIZE (arr_type, 0); | |
d2e4a39e | 418 | } |
14f9c5c9 AS |
419 | } |
420 | } | |
d2e4a39e | 421 | else |
14f9c5c9 AS |
422 | { |
423 | int i, i0; | |
424 | for (i = i0 = ada_array_arity (type); i > 0; i -= 1) | |
425 | fprintf_filtered (stream, "%s<>", i == i0 ? "" : ", "); | |
426 | } | |
427 | } | |
428 | ||
429 | fprintf_filtered (stream, ") of "); | |
430 | wrap_here (""); | |
d2e4a39e AS |
431 | ada_print_type (ada_array_element_type (type, n_indices), "", stream, |
432 | show == 0 ? 0 : show - 1, level + 1); | |
14f9c5c9 AS |
433 | if (bitsize > 0) |
434 | fprintf_filtered (stream, " <packed: %d-bit elements>", bitsize); | |
435 | } | |
436 | ||
437 | /* Print the choices encoded by field FIELD_NUM of variant-part TYPE on | |
4c4b4cd2 | 438 | STREAM, assuming the VAL_TYPE is the type of the values. */ |
14f9c5c9 AS |
439 | |
440 | static void | |
d2e4a39e AS |
441 | print_choices (struct type *type, int field_num, struct ui_file *stream, |
442 | struct type *val_type) | |
14f9c5c9 AS |
443 | { |
444 | int have_output; | |
445 | int p; | |
d2e4a39e | 446 | const char *name = TYPE_FIELD_NAME (type, field_num); |
14f9c5c9 AS |
447 | |
448 | have_output = 0; | |
449 | ||
4c4b4cd2 | 450 | /* Skip over leading 'V': NOTE soon to be obsolete. */ |
14f9c5c9 AS |
451 | if (name[0] == 'V') |
452 | { | |
d2e4a39e | 453 | if (!ada_scan_number (name, 1, NULL, &p)) |
14f9c5c9 AS |
454 | goto Huh; |
455 | } | |
456 | else | |
457 | p = 0; | |
458 | ||
459 | while (1) | |
460 | { | |
d2e4a39e | 461 | switch (name[p]) |
14f9c5c9 AS |
462 | { |
463 | default: | |
464 | return; | |
465 | case 'S': | |
466 | case 'R': | |
467 | case 'O': | |
d2e4a39e | 468 | if (have_output) |
14f9c5c9 AS |
469 | fprintf_filtered (stream, " | "); |
470 | have_output = 1; | |
471 | break; | |
472 | } | |
473 | ||
d2e4a39e | 474 | switch (name[p]) |
14f9c5c9 AS |
475 | { |
476 | case 'S': | |
477 | { | |
478 | LONGEST W; | |
d2e4a39e | 479 | if (!ada_scan_number (name, p + 1, &W, &p)) |
14f9c5c9 AS |
480 | goto Huh; |
481 | ada_print_scalar (val_type, W, stream); | |
482 | break; | |
483 | } | |
484 | case 'R': | |
485 | { | |
486 | LONGEST L, U; | |
d2e4a39e AS |
487 | if (!ada_scan_number (name, p + 1, &L, &p) |
488 | || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p)) | |
14f9c5c9 AS |
489 | goto Huh; |
490 | ada_print_scalar (val_type, L, stream); | |
491 | fprintf_filtered (stream, " .. "); | |
492 | ada_print_scalar (val_type, U, stream); | |
493 | break; | |
494 | } | |
495 | case 'O': | |
496 | fprintf_filtered (stream, "others"); | |
497 | p += 1; | |
498 | break; | |
499 | } | |
500 | } | |
501 | ||
502 | Huh: | |
503 | fprintf_filtered (stream, "??"); | |
504 | ||
505 | } | |
506 | ||
4c4b4cd2 PH |
507 | /* Assuming that field FIELD_NUM of TYPE is a VARIANTS field whose |
508 | discriminant is contained in OUTER_TYPE, print its variants on STREAM. | |
14f9c5c9 AS |
509 | LEVEL is the recursion |
510 | (indentation) level, in case any of the fields themselves have | |
511 | nested structure, and SHOW is the number of levels of internal structure | |
4c4b4cd2 | 512 | to show (see ada_print_type). For this purpose, fields nested in a |
14f9c5c9 | 513 | variant part are taken to be at the same level as the fields |
4c4b4cd2 | 514 | immediately outside the variant part. */ |
14f9c5c9 AS |
515 | |
516 | static void | |
ebf56fd3 AS |
517 | print_variant_clauses (struct type *type, int field_num, |
518 | struct type *outer_type, struct ui_file *stream, | |
519 | int show, int level) | |
14f9c5c9 AS |
520 | { |
521 | int i; | |
4c4b4cd2 | 522 | struct type *var_type, *par_type; |
14f9c5c9 AS |
523 | struct type *discr_type; |
524 | ||
525 | var_type = TYPE_FIELD_TYPE (type, field_num); | |
526 | discr_type = ada_variant_discrim_type (var_type, outer_type); | |
527 | ||
528 | if (TYPE_CODE (var_type) == TYPE_CODE_PTR) | |
529 | { | |
530 | var_type = TYPE_TARGET_TYPE (var_type); | |
4c4b4cd2 PH |
531 | if (var_type == NULL || TYPE_CODE (var_type) != TYPE_CODE_UNION) |
532 | return; | |
14f9c5c9 AS |
533 | } |
534 | ||
4c4b4cd2 PH |
535 | par_type = ada_find_parallel_type (var_type, "___XVU"); |
536 | if (par_type != NULL) | |
537 | var_type = par_type; | |
538 | ||
d2e4a39e | 539 | for (i = 0; i < TYPE_NFIELDS (var_type); i += 1) |
14f9c5c9 AS |
540 | { |
541 | fprintf_filtered (stream, "\n%*swhen ", level + 4, ""); | |
542 | print_choices (var_type, i, stream, discr_type); | |
543 | fprintf_filtered (stream, " =>"); | |
d2e4a39e AS |
544 | if (print_record_field_types (TYPE_FIELD_TYPE (var_type, i), |
545 | outer_type, stream, show, level + 4) <= 0) | |
14f9c5c9 AS |
546 | fprintf_filtered (stream, " null;"); |
547 | } | |
548 | } | |
549 | ||
4c4b4cd2 | 550 | /* Assuming that field FIELD_NUM of TYPE is a variant part whose |
14f9c5c9 | 551 | discriminants are contained in OUTER_TYPE, print a description of it |
4c4b4cd2 PH |
552 | on STREAM. LEVEL is the recursion (indentation) level, in case any of |
553 | the fields themselves have nested structure, and SHOW is the number of | |
554 | levels of internal structure to show (see ada_print_type). For this | |
555 | purpose, fields nested in a variant part are taken to be at the same | |
556 | level as the fields immediately outside the variant part. */ | |
14f9c5c9 AS |
557 | |
558 | static void | |
ebf56fd3 AS |
559 | print_variant_part (struct type *type, int field_num, struct type *outer_type, |
560 | struct ui_file *stream, int show, int level) | |
14f9c5c9 AS |
561 | { |
562 | fprintf_filtered (stream, "\n%*scase %s is", level + 4, "", | |
d2e4a39e AS |
563 | ada_variant_discrim_name |
564 | (TYPE_FIELD_TYPE (type, field_num))); | |
565 | print_variant_clauses (type, field_num, outer_type, stream, show, | |
566 | level + 4); | |
14f9c5c9 AS |
567 | fprintf_filtered (stream, "\n%*send case;", level + 4, ""); |
568 | } | |
569 | ||
4c4b4cd2 PH |
570 | /* Print a description on STREAM of the fields in record type TYPE, whose |
571 | discriminants are in OUTER_TYPE. LEVEL is the recursion (indentation) | |
572 | level, in case any of the fields themselves have nested structure, | |
573 | and SHOW is the number of levels of internal structure to show | |
574 | (see ada_print_type). Does not print parent type information of TYPE. | |
575 | Returns 0 if no fields printed, -1 for an incomplete type, else > 0. | |
14f9c5c9 | 576 | Prints each field beginning on a new line, but does not put a new line at |
4c4b4cd2 | 577 | end. */ |
14f9c5c9 AS |
578 | |
579 | static int | |
ebf56fd3 AS |
580 | print_record_field_types (struct type *type, struct type *outer_type, |
581 | struct ui_file *stream, int show, int level) | |
14f9c5c9 AS |
582 | { |
583 | int len, i, flds; | |
584 | ||
585 | flds = 0; | |
586 | len = TYPE_NFIELDS (type); | |
587 | ||
588 | if (len == 0 && (TYPE_FLAGS (type) & TYPE_FLAG_STUB) != 0) | |
589 | return -1; | |
590 | ||
591 | for (i = 0; i < len; i += 1) | |
592 | { | |
593 | QUIT; | |
594 | ||
d2e4a39e | 595 | if (ada_is_parent_field (type, i) || ada_is_ignored_field (type, i)) |
14f9c5c9 AS |
596 | ; |
597 | else if (ada_is_wrapper_field (type, i)) | |
598 | flds += print_record_field_types (TYPE_FIELD_TYPE (type, i), type, | |
599 | stream, show, level); | |
d2e4a39e | 600 | else if (ada_is_variant_part (type, i)) |
14f9c5c9 AS |
601 | { |
602 | print_variant_part (type, i, outer_type, stream, show, level); | |
603 | flds = 1; | |
604 | } | |
605 | else | |
606 | { | |
607 | flds += 1; | |
608 | fprintf_filtered (stream, "\n%*s", level + 4, ""); | |
609 | ada_print_type (TYPE_FIELD_TYPE (type, i), | |
610 | TYPE_FIELD_NAME (type, i), | |
611 | stream, show - 1, level + 4); | |
612 | fprintf_filtered (stream, ";"); | |
613 | } | |
614 | } | |
615 | ||
616 | return flds; | |
617 | } | |
618 | ||
4c4b4cd2 PH |
619 | /* Print record type TYPE on STREAM. LEVEL is the recursion (indentation) |
620 | level, in case the element type itself has nested structure, and SHOW is | |
621 | the number of levels of internal structure to show (see ada_print_type). */ | |
14f9c5c9 AS |
622 | |
623 | static void | |
d2e4a39e AS |
624 | print_record_type (struct type *type0, struct ui_file *stream, int show, |
625 | int level) | |
14f9c5c9 | 626 | { |
d2e4a39e AS |
627 | struct type *parent_type; |
628 | struct type *type; | |
629 | ||
4c4b4cd2 PH |
630 | type = ada_find_parallel_type (type0, "___XVE"); |
631 | if (type == NULL) | |
632 | type = type0; | |
14f9c5c9 AS |
633 | |
634 | parent_type = ada_parent_type (type); | |
d2e4a39e | 635 | if (ada_type_name (parent_type) != NULL) |
0b48a291 | 636 | fprintf_filtered (stream, "new %s with record", |
4c4b4cd2 PH |
637 | decoded_type_name (parent_type)); |
638 | else if (parent_type == NULL && ada_is_tagged_type (type, 0)) | |
0b48a291 PH |
639 | fprintf_filtered (stream, "tagged record"); |
640 | else | |
641 | fprintf_filtered (stream, "record"); | |
14f9c5c9 AS |
642 | |
643 | if (show < 0) | |
0b48a291 | 644 | fprintf_filtered (stream, " ... end record"); |
14f9c5c9 AS |
645 | else |
646 | { | |
647 | int flds; | |
648 | ||
649 | flds = 0; | |
650 | if (parent_type != NULL && ada_type_name (parent_type) == NULL) | |
d2e4a39e | 651 | flds += print_record_field_types (parent_type, parent_type, |
14f9c5c9 AS |
652 | stream, show, level); |
653 | flds += print_record_field_types (type, type, stream, show, level); | |
d2e4a39e | 654 | |
14f9c5c9 | 655 | if (flds > 0) |
0b48a291 | 656 | fprintf_filtered (stream, "\n%*send record", level, ""); |
d2e4a39e | 657 | else if (flds < 0) |
323e0a4a | 658 | fprintf_filtered (stream, _(" <incomplete type> end record")); |
d2e4a39e | 659 | else |
0b48a291 | 660 | fprintf_filtered (stream, " null; end record"); |
14f9c5c9 AS |
661 | } |
662 | } | |
663 | ||
664 | /* Print the unchecked union type TYPE in something resembling Ada | |
4c4b4cd2 | 665 | format on STREAM. LEVEL is the recursion (indentation) level |
14f9c5c9 | 666 | in case the element type itself has nested structure, and SHOW is the |
4c4b4cd2 | 667 | number of levels of internal structure to show (see ada_print_type). */ |
14f9c5c9 | 668 | static void |
d2e4a39e | 669 | print_unchecked_union_type (struct type *type, struct ui_file *stream, |
14f9c5c9 AS |
670 | int show, int level) |
671 | { | |
14f9c5c9 | 672 | if (show < 0) |
0b48a291 | 673 | fprintf_filtered (stream, "record (?) is ... end record"); |
d2e4a39e | 674 | else if (TYPE_NFIELDS (type) == 0) |
0b48a291 | 675 | fprintf_filtered (stream, "record (?) is null; end record"); |
14f9c5c9 AS |
676 | else |
677 | { | |
678 | int i; | |
679 | ||
0b48a291 | 680 | fprintf_filtered (stream, "record (?) is\n%*scase ? is", level + 4, ""); |
14f9c5c9 | 681 | |
d2e4a39e | 682 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) |
14f9c5c9 | 683 | { |
0b48a291 | 684 | fprintf_filtered (stream, "\n%*swhen ? =>\n%*s", level + 8, "", |
d2e4a39e | 685 | level + 12, ""); |
14f9c5c9 AS |
686 | ada_print_type (TYPE_FIELD_TYPE (type, i), |
687 | TYPE_FIELD_NAME (type, i), | |
688 | stream, show - 1, level + 12); | |
689 | fprintf_filtered (stream, ";"); | |
690 | } | |
691 | ||
0b48a291 | 692 | fprintf_filtered (stream, "\n%*send case;\n%*send record", |
d2e4a39e | 693 | level + 4, "", level, ""); |
14f9c5c9 AS |
694 | } |
695 | } | |
d2e4a39e | 696 | |
14f9c5c9 AS |
697 | |
698 | ||
699 | /* Print function or procedure type TYPE on STREAM. Make it a header | |
4c4b4cd2 | 700 | for function or procedure NAME if NAME is not null. */ |
14f9c5c9 AS |
701 | |
702 | static void | |
d2e4a39e | 703 | print_func_type (struct type *type, struct ui_file *stream, char *name) |
14f9c5c9 AS |
704 | { |
705 | int i, len = TYPE_NFIELDS (type); | |
706 | ||
707 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID) | |
708 | fprintf_filtered (stream, "procedure"); | |
709 | else | |
710 | fprintf_filtered (stream, "function"); | |
711 | ||
d2e4a39e | 712 | if (name != NULL && name[0] != '\0') |
14f9c5c9 AS |
713 | fprintf_filtered (stream, " %s", name); |
714 | ||
d2e4a39e | 715 | if (len > 0) |
14f9c5c9 AS |
716 | { |
717 | fprintf_filtered (stream, " ("); | |
718 | for (i = 0; i < len; i += 1) | |
719 | { | |
720 | if (i > 0) | |
721 | { | |
722 | fputs_filtered ("; ", stream); | |
723 | wrap_here (" "); | |
724 | } | |
d2e4a39e | 725 | fprintf_filtered (stream, "a%d: ", i + 1); |
14f9c5c9 AS |
726 | ada_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0); |
727 | } | |
728 | fprintf_filtered (stream, ")"); | |
d2e4a39e | 729 | } |
14f9c5c9 AS |
730 | |
731 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID) | |
732 | { | |
733 | fprintf_filtered (stream, " return "); | |
734 | ada_print_type (TYPE_TARGET_TYPE (type), "", stream, 0, 0); | |
735 | } | |
736 | } | |
737 | ||
738 | ||
739 | /* Print a description of a type TYPE0. | |
740 | Output goes to STREAM (via stdio). | |
741 | If VARSTRING is a non-empty string, print as an Ada variable/field | |
742 | declaration. | |
4c4b4cd2 | 743 | SHOW+1 is the maximum number of levels of internal type structure |
14f9c5c9 AS |
744 | to show (this applies to record types, enumerated types, and |
745 | array types). | |
746 | SHOW is the number of levels of internal type structure to show | |
4c4b4cd2 | 747 | when there is a type name for the SHOWth deepest level (0th is |
14f9c5c9 AS |
748 | outer level). |
749 | When SHOW<0, no inner structure is shown. | |
4c4b4cd2 | 750 | LEVEL indicates level of recursion (for nested definitions). */ |
14f9c5c9 AS |
751 | |
752 | void | |
d2e4a39e | 753 | ada_print_type (struct type *type0, char *varstring, struct ui_file *stream, |
ebf56fd3 | 754 | int show, int level) |
14f9c5c9 | 755 | { |
61ee279c | 756 | struct type *type = ada_check_typedef (ada_get_base_type (type0)); |
4c4b4cd2 | 757 | char *type_name = decoded_type_name (type); |
14f9c5c9 AS |
758 | int is_var_decl = (varstring != NULL && varstring[0] != '\0'); |
759 | ||
760 | if (type == NULL) | |
761 | { | |
762 | if (is_var_decl) | |
763 | fprintf_filtered (stream, "%.*s: ", | |
d2e4a39e | 764 | ada_name_prefix_len (varstring), varstring); |
14f9c5c9 AS |
765 | fprintf_filtered (stream, "<null type?>"); |
766 | return; | |
767 | } | |
768 | ||
769 | if (show > 0) | |
61ee279c | 770 | type = ada_check_typedef (type); |
14f9c5c9 AS |
771 | |
772 | if (is_var_decl && TYPE_CODE (type) != TYPE_CODE_FUNC) | |
d2e4a39e AS |
773 | fprintf_filtered (stream, "%.*s: ", |
774 | ada_name_prefix_len (varstring), varstring); | |
14f9c5c9 AS |
775 | |
776 | if (type_name != NULL && show <= 0) | |
777 | { | |
d2e4a39e | 778 | fprintf_filtered (stream, "%.*s", |
14f9c5c9 AS |
779 | ada_name_prefix_len (type_name), type_name); |
780 | return; | |
781 | } | |
782 | ||
783 | if (ada_is_aligner_type (type)) | |
784 | ada_print_type (ada_aligned_type (type), "", stream, show, level); | |
785 | else if (ada_is_packed_array_type (type)) | |
786 | print_array_type (type, stream, show, level); | |
787 | else | |
d2e4a39e AS |
788 | switch (TYPE_CODE (type)) |
789 | { | |
790 | default: | |
791 | fprintf_filtered (stream, "<"); | |
792 | c_print_type (type, "", stream, show, level); | |
793 | fprintf_filtered (stream, ">"); | |
794 | break; | |
795 | case TYPE_CODE_PTR: | |
796 | fprintf_filtered (stream, "access "); | |
797 | ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level); | |
798 | break; | |
799 | case TYPE_CODE_REF: | |
800 | fprintf_filtered (stream, "<ref> "); | |
801 | ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level); | |
802 | break; | |
803 | case TYPE_CODE_ARRAY: | |
14f9c5c9 | 804 | print_array_type (type, stream, show, level); |
d2e4a39e AS |
805 | break; |
806 | case TYPE_CODE_INT: | |
807 | if (ada_is_fixed_point_type (type)) | |
808 | print_fixed_point_type (type, stream); | |
809 | else if (ada_is_vax_floating_type (type)) | |
810 | print_vax_floating_point_type (type, stream); | |
811 | else | |
812 | { | |
813 | char *name = ada_type_name (type); | |
814 | if (!ada_is_range_type_name (name)) | |
815 | fprintf_filtered (stream, "<%d-byte integer>", | |
816 | TYPE_LENGTH (type)); | |
817 | else | |
818 | { | |
819 | fprintf_filtered (stream, "range "); | |
820 | print_range_type_named (name, stream); | |
821 | } | |
822 | } | |
823 | break; | |
824 | case TYPE_CODE_RANGE: | |
825 | if (ada_is_fixed_point_type (type)) | |
826 | print_fixed_point_type (type, stream); | |
827 | else if (ada_is_vax_floating_type (type)) | |
828 | print_vax_floating_point_type (type, stream); | |
829 | else if (ada_is_modular_type (type)) | |
830 | fprintf_filtered (stream, "mod %ld", (long) ada_modulus (type)); | |
831 | else | |
832 | { | |
833 | fprintf_filtered (stream, "range "); | |
834 | print_range (type, stream); | |
835 | } | |
836 | break; | |
837 | case TYPE_CODE_FLT: | |
838 | fprintf_filtered (stream, "<%d-byte float>", TYPE_LENGTH (type)); | |
839 | break; | |
840 | case TYPE_CODE_ENUM: | |
841 | if (show < 0) | |
842 | fprintf_filtered (stream, "(...)"); | |
843 | else | |
844 | print_enum_type (type, stream); | |
845 | break; | |
846 | case TYPE_CODE_STRUCT: | |
4c4b4cd2 | 847 | if (ada_is_array_descriptor_type (type)) |
d2e4a39e AS |
848 | print_array_type (type, stream, show, level); |
849 | else if (ada_is_bogus_array_descriptor (type)) | |
850 | fprintf_filtered (stream, | |
851 | "array (?) of ? (<mal-formed descriptor>)"); | |
852 | else | |
853 | print_record_type (type, stream, show, level); | |
854 | break; | |
855 | case TYPE_CODE_UNION: | |
856 | print_unchecked_union_type (type, stream, show, level); | |
857 | break; | |
858 | case TYPE_CODE_FUNC: | |
859 | print_func_type (type, stream, varstring); | |
860 | break; | |
861 | } | |
14f9c5c9 | 862 | } |