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