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