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