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