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