OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [gdb/] [ada-typeprint.c] - Blame information for rev 855

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 227 jeremybenn
/* Support for printing Ada types for GDB, the GNU debugger.
2
   Copyright (C) 1986, 1988, 1989, 1991, 1997, 1998, 1999, 2000, 2001, 2002,
3
   2003, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4
 
5
   This file is part of GDB.
6
 
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.
11
 
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.
16
 
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/>.  */
19
 
20
#include "defs.h"
21
#include "gdb_obstack.h"
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>
38
#include "gdb_string.h"
39
#include <errno.h>
40
 
41
static int print_record_field_types (struct type *, struct type *,
42
                                     struct ui_file *, int, int);
43
 
44
static void print_array_type (struct type *, struct ui_file *, int, int);
45
 
46
static void print_choices (struct type *, int, struct ui_file *,
47
                           struct type *);
48
 
49
static void print_range (struct type *, struct ui_file *);
50
 
51
static void print_range_bound (struct type *, char *, int *,
52
                               struct ui_file *);
53
 
54
static void
55
print_dynamic_range_bound (struct type *, const char *, int,
56
                           const char *, struct ui_file *);
57
 
58
static void print_range_type_named (char *, struct type *, struct ui_file *);
59
 
60
 
61
 
62
static char *name_buffer;
63
static int name_buffer_len;
64
 
65
/* The (decoded) Ada name of TYPE.  This value persists until the
66
   next call.  */
67
 
68
static char *
69
decoded_type_name (struct type *type)
70
{
71
  if (ada_type_name (type) == NULL)
72
    return NULL;
73
  else
74
    {
75
      char *raw_name = ada_type_name (type);
76
      char *s, *q;
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
 
85
      s = (char *) strstr (name_buffer, "___");
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
 
96
      if (!islower (s[1]))
97
        return NULL;
98
 
99
      for (s = q = name_buffer; *s != '\0'; q += 1)
100
        {
101
          if (s[0] == '_' && s[1] == '_')
102
            {
103
              *q = '.';
104
              s += 2;
105
            }
106
          else
107
            {
108
              *q = *s;
109
              s += 1;
110
            }
111
        }
112
      *q = '\0';
113
      return name_buffer;
114
    }
115
}
116
 
117
/* Print TYPE on STREAM, preferably as a range.  */
118
 
119
static void
120
print_range (struct type *type, struct ui_file *stream)
121
{
122
  switch (TYPE_CODE (type))
123
    {
124
    case TYPE_CODE_RANGE:
125
    case TYPE_CODE_ENUM:
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
      }
137
      break;
138
    default:
139
      fprintf_filtered (stream, "%.*s",
140
                        ada_name_prefix_len (TYPE_NAME (type)),
141
                        TYPE_NAME (type));
142
      break;
143
    }
144
}
145
 
146
/* Print the number or discriminant bound at BOUNDS+*N on STREAM, and
147
   set *N past the bound and its delimiter, if any.  */
148
 
149
static void
150
print_range_bound (struct type *type, char *bounds, int *n,
151
                   struct ui_file *stream)
152
{
153
  LONGEST B;
154
  if (ada_scan_number (bounds, *n, &B, n))
155
    {
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.
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,
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)
168
        type = NULL;
169
      ada_print_scalar (type, B, stream);
170
      if (bounds[*n] == '_')
171
        *n += 2;
172
    }
173
  else
174
    {
175
      int bound_len;
176
      char *bound = bounds + *n;
177
      char *pend;
178
 
179
      pend = strstr (bound, "__");
180
      if (pend == NULL)
181
        *n += bound_len = strlen (bound);
182
      else
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
193
   "___U") according to the ___XD conventions.  */
194
 
195
static void
196
print_dynamic_range_bound (struct type *type, const char *name, int name_len,
197
                           const char *suffix, struct ui_file *stream)
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
 
208
  B = get_int_var_value (name_buf, &OK);
209
  if (OK)
210
    ada_print_scalar (type, B, stream);
211
  else
212
    fprintf_filtered (stream, "?");
213
}
214
 
215
/* Print the range type named NAME.  If symbol lookup fails, fall back
216
   to ORIG_TYPE as base type.  */
217
 
218
static void
219
print_range_type_named (char *name, struct type *orig_type,
220
                        struct ui_file *stream)
221
{
222
  struct type *raw_type = ada_find_any_type (name);
223
  struct type *base_type;
224
  char *subtype_info;
225
 
226
  if (raw_type == NULL)
227
    raw_type = orig_type;
228
 
229
  if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
230
    base_type = TYPE_TARGET_TYPE (raw_type);
231
  else
232
    base_type = raw_type;
233
 
234
  subtype_info = strstr (name, "___XD");
235
  if (subtype_info == NULL)
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
 
247
      if (*subtype_info == 'L')
248
        {
249
          print_range_bound (base_type, bounds_str, &n, stream);
250
          subtype_info += 1;
251
        }
252
      else
253
        print_dynamic_range_bound (base_type, name, prefix_len, "___L",
254
                                   stream);
255
 
256
      fprintf_filtered (stream, " .. ");
257
 
258
      if (*subtype_info == 'U')
259
        print_range_bound (base_type, bounds_str, &n, stream);
260
      else
261
        print_dynamic_range_bound (base_type, name, prefix_len, "___U",
262
                                   stream);
263
    }
264
}
265
 
266
/* Print enumerated type TYPE on STREAM.  */
267
 
268
static void
269
print_enum_type (struct type *type, struct ui_file *stream)
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;
281
      if (i)
282
        fprintf_filtered (stream, ", ");
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
 
295
/* Print representation of Ada fixed-point type TYPE on STREAM.  */
296
 
297
static void
298
print_fixed_point_type (struct type *type, struct ui_file *stream)
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);
308
      if (delta != small)
309
        fprintf_filtered (stream, " <'small = %g>", (double) small);
310
    }
311
}
312
 
313
/* Print simple (constrained) array type TYPE on STREAM.  LEVEL is the
314
   recursion (indentation) level, in case the element type itself has
315
   nested structure, and SHOW is the number of levels of internal
316
   structure to show (see ada_print_type).  */
317
 
318
static void
319
print_array_type (struct type *type, struct ui_file *stream, int show,
320
                  int level)
321
{
322
  int bitsize;
323
  int n_indices;
324
 
325
  if (ada_is_constrained_packed_array_type (type))
326
    type = ada_coerce_to_simple_array_type (type);
327
 
328
  bitsize = 0;
329
  fprintf_filtered (stream, "array (");
330
 
331
  if (type == NULL)
332
    {
333
      fprintf_filtered (stream, _("<undecipherable array type>"));
334
      return;
335
    }
336
 
337
  n_indices = -1;
338
  if (show < 0)
339
    fprintf_filtered (stream, "...");
340
  else
341
    {
342
      if (ada_is_simple_array_type (type))
343
        {
344
          struct type *range_desc_type =
345
            ada_find_parallel_type (type, "___XA");
346
          struct type *arr_type;
347
 
348
          bitsize = 0;
349
          if (range_desc_type == NULL)
350
            {
351
              for (arr_type = type; TYPE_CODE (arr_type) == TYPE_CODE_ARRAY;
352
                   arr_type = TYPE_TARGET_TYPE (arr_type))
353
                {
354
                  if (arr_type != type)
355
                    fprintf_filtered (stream, ", ");
356
                  print_range (TYPE_INDEX_TYPE (arr_type), stream);
357
                  if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
358
                    bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
359
                }
360
            }
361
          else
362
            {
363
              int k;
364
              n_indices = TYPE_NFIELDS (range_desc_type);
365
              for (k = 0, arr_type = type;
366
                   k < n_indices;
367
                   k += 1, arr_type = TYPE_TARGET_TYPE (arr_type))
368
                {
369
                  if (k > 0)
370
                    fprintf_filtered (stream, ", ");
371
                  print_range_type_named (TYPE_FIELD_NAME
372
                                          (range_desc_type, k),
373
                                          TYPE_INDEX_TYPE (arr_type), stream);
374
                  if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
375
                    bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
376
                }
377
            }
378
        }
379
      else
380
        {
381
          int i, i0;
382
          for (i = i0 = ada_array_arity (type); i > 0; i -= 1)
383
            fprintf_filtered (stream, "%s<>", i == i0 ? "" : ", ");
384
        }
385
    }
386
 
387
  fprintf_filtered (stream, ") of ");
388
  wrap_here ("");
389
  ada_print_type (ada_array_element_type (type, n_indices), "", stream,
390
                  show == 0 ? 0 : show - 1, level + 1);
391
  if (bitsize > 0)
392
    fprintf_filtered (stream, " <packed: %d-bit elements>", bitsize);
393
}
394
 
395
/* Print the choices encoded by field FIELD_NUM of variant-part TYPE on
396
   STREAM, assuming that VAL_TYPE (if non-NULL) is the type of the values.  */
397
 
398
static void
399
print_choices (struct type *type, int field_num, struct ui_file *stream,
400
               struct type *val_type)
401
{
402
  int have_output;
403
  int p;
404
  const char *name = TYPE_FIELD_NAME (type, field_num);
405
 
406
  have_output = 0;
407
 
408
  /* Skip over leading 'V': NOTE soon to be obsolete.  */
409
  if (name[0] == 'V')
410
    {
411
      if (!ada_scan_number (name, 1, NULL, &p))
412
        goto Huh;
413
    }
414
  else
415
    p = 0;
416
 
417
  while (1)
418
    {
419
      switch (name[p])
420
        {
421
        default:
422
          return;
423
        case 'S':
424
        case 'R':
425
        case 'O':
426
          if (have_output)
427
            fprintf_filtered (stream, " | ");
428
          have_output = 1;
429
          break;
430
        }
431
 
432
      switch (name[p])
433
        {
434
        case 'S':
435
          {
436
            LONGEST W;
437
            if (!ada_scan_number (name, p + 1, &W, &p))
438
              goto Huh;
439
            ada_print_scalar (val_type, W, stream);
440
            break;
441
          }
442
        case 'R':
443
          {
444
            LONGEST L, U;
445
            if (!ada_scan_number (name, p + 1, &L, &p)
446
                || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p))
447
              goto Huh;
448
            ada_print_scalar (val_type, L, stream);
449
            fprintf_filtered (stream, " .. ");
450
            ada_print_scalar (val_type, U, stream);
451
            break;
452
          }
453
        case 'O':
454
          fprintf_filtered (stream, "others");
455
          p += 1;
456
          break;
457
        }
458
    }
459
 
460
Huh:
461
  fprintf_filtered (stream, "??");
462
 
463
}
464
 
465
/* Assuming that field FIELD_NUM of TYPE is a VARIANTS field whose
466
   discriminant is contained in OUTER_TYPE, print its variants on STREAM.
467
   LEVEL is the recursion
468
   (indentation) level, in case any of the fields themselves have
469
   nested structure, and SHOW is the number of levels of internal structure
470
   to show (see ada_print_type).  For this purpose, fields nested in a
471
   variant part are taken to be at the same level as the fields
472
   immediately outside the variant part.  */
473
 
474
static void
475
print_variant_clauses (struct type *type, int field_num,
476
                       struct type *outer_type, struct ui_file *stream,
477
                       int show, int level)
478
{
479
  int i;
480
  struct type *var_type, *par_type;
481
  struct type *discr_type;
482
 
483
  var_type = TYPE_FIELD_TYPE (type, field_num);
484
  discr_type = ada_variant_discrim_type (var_type, outer_type);
485
 
486
  if (TYPE_CODE (var_type) == TYPE_CODE_PTR)
487
    {
488
      var_type = TYPE_TARGET_TYPE (var_type);
489
      if (var_type == NULL || TYPE_CODE (var_type) != TYPE_CODE_UNION)
490
        return;
491
    }
492
 
493
  par_type = ada_find_parallel_type (var_type, "___XVU");
494
  if (par_type != NULL)
495
    var_type = par_type;
496
 
497
  for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
498
    {
499
      fprintf_filtered (stream, "\n%*swhen ", level + 4, "");
500
      print_choices (var_type, i, stream, discr_type);
501
      fprintf_filtered (stream, " =>");
502
      if (print_record_field_types (TYPE_FIELD_TYPE (var_type, i),
503
                                    outer_type, stream, show, level + 4) <= 0)
504
        fprintf_filtered (stream, " null;");
505
    }
506
}
507
 
508
/* Assuming that field FIELD_NUM of TYPE is a variant part whose
509
   discriminants are contained in OUTER_TYPE, print a description of it
510
   on STREAM.  LEVEL is the recursion (indentation) level, in case any of
511
   the fields themselves have nested structure, and SHOW is the number of
512
   levels of internal structure to show (see ada_print_type).  For this
513
   purpose, fields nested in a variant part are taken to be at the same
514
   level as the fields immediately outside the variant part.  */
515
 
516
static void
517
print_variant_part (struct type *type, int field_num, struct type *outer_type,
518
                    struct ui_file *stream, int show, int level)
519
{
520
  fprintf_filtered (stream, "\n%*scase %s is", level + 4, "",
521
                    ada_variant_discrim_name
522
                    (TYPE_FIELD_TYPE (type, field_num)));
523
  print_variant_clauses (type, field_num, outer_type, stream, show,
524
                         level + 4);
525
  fprintf_filtered (stream, "\n%*send case;", level + 4, "");
526
}
527
 
528
/* Print a description on STREAM of the fields in record type TYPE, whose
529
   discriminants are in OUTER_TYPE.  LEVEL is the recursion (indentation)
530
   level, in case any of the fields themselves have nested structure,
531
   and SHOW is the number of levels of internal structure to show
532
   (see ada_print_type).  Does not print parent type information of TYPE.
533
   Returns 0 if no fields printed, -1 for an incomplete type, else > 0.
534
   Prints each field beginning on a new line, but does not put a new line at
535
   end.  */
536
 
537
static int
538
print_record_field_types (struct type *type, struct type *outer_type,
539
                          struct ui_file *stream, int show, int level)
540
{
541
  int len, i, flds;
542
 
543
  flds = 0;
544
  len = TYPE_NFIELDS (type);
545
 
546
  if (len == 0 && TYPE_STUB (type))
547
    return -1;
548
 
549
  for (i = 0; i < len; i += 1)
550
    {
551
      QUIT;
552
 
553
      if (ada_is_parent_field (type, i) || ada_is_ignored_field (type, i))
554
        ;
555
      else if (ada_is_wrapper_field (type, i))
556
        flds += print_record_field_types (TYPE_FIELD_TYPE (type, i), type,
557
                                          stream, show, level);
558
      else if (ada_is_variant_part (type, i))
559
        {
560
          print_variant_part (type, i, outer_type, stream, show, level);
561
          flds = 1;
562
        }
563
      else
564
        {
565
          flds += 1;
566
          fprintf_filtered (stream, "\n%*s", level + 4, "");
567
          ada_print_type (TYPE_FIELD_TYPE (type, i),
568
                          TYPE_FIELD_NAME (type, i),
569
                          stream, show - 1, level + 4);
570
          fprintf_filtered (stream, ";");
571
        }
572
    }
573
 
574
  return flds;
575
}
576
 
577
/* Print record type TYPE on STREAM.  LEVEL is the recursion (indentation)
578
   level, in case the element type itself has nested structure, and SHOW is
579
   the number of levels of internal structure to show (see ada_print_type).  */
580
 
581
static void
582
print_record_type (struct type *type0, struct ui_file *stream, int show,
583
                   int level)
584
{
585
  struct type *parent_type;
586
  struct type *type;
587
 
588
  type = ada_find_parallel_type (type0, "___XVE");
589
  if (type == NULL)
590
    type = type0;
591
 
592
  parent_type = ada_parent_type (type);
593
  if (ada_type_name (parent_type) != NULL)
594
    fprintf_filtered (stream, "new %s with record",
595
                      decoded_type_name (parent_type));
596
  else if (parent_type == NULL && ada_is_tagged_type (type, 0))
597
    fprintf_filtered (stream, "tagged record");
598
  else
599
    fprintf_filtered (stream, "record");
600
 
601
  if (show < 0)
602
    fprintf_filtered (stream, " ... end record");
603
  else
604
    {
605
      int flds;
606
 
607
      flds = 0;
608
      if (parent_type != NULL && ada_type_name (parent_type) == NULL)
609
        flds += print_record_field_types (parent_type, parent_type,
610
                                          stream, show, level);
611
      flds += print_record_field_types (type, type, stream, show, level);
612
 
613
      if (flds > 0)
614
        fprintf_filtered (stream, "\n%*send record", level, "");
615
      else if (flds < 0)
616
        fprintf_filtered (stream, _(" <incomplete type> end record"));
617
      else
618
        fprintf_filtered (stream, " null; end record");
619
    }
620
}
621
 
622
/* Print the unchecked union type TYPE in something resembling Ada
623
   format on STREAM.  LEVEL is the recursion (indentation) level
624
   in case the element type itself has nested structure, and SHOW is the
625
   number of levels of internal structure to show (see ada_print_type).  */
626
static void
627
print_unchecked_union_type (struct type *type, struct ui_file *stream,
628
                            int show, int level)
629
{
630
  if (show < 0)
631
    fprintf_filtered (stream, "record (?) is ... end record");
632
  else if (TYPE_NFIELDS (type) == 0)
633
    fprintf_filtered (stream, "record (?) is null; end record");
634
  else
635
    {
636
      int i;
637
 
638
      fprintf_filtered (stream, "record (?) is\n%*scase ? is", level + 4, "");
639
 
640
      for (i = 0; i < TYPE_NFIELDS (type); i += 1)
641
        {
642
          fprintf_filtered (stream, "\n%*swhen ? =>\n%*s", level + 8, "",
643
                            level + 12, "");
644
          ada_print_type (TYPE_FIELD_TYPE (type, i),
645
                          TYPE_FIELD_NAME (type, i),
646
                          stream, show - 1, level + 12);
647
          fprintf_filtered (stream, ";");
648
        }
649
 
650
      fprintf_filtered (stream, "\n%*send case;\n%*send record",
651
                        level + 4, "", level, "");
652
    }
653
}
654
 
655
 
656
 
657
/* Print function or procedure type TYPE on STREAM.  Make it a header
658
   for function or procedure NAME if NAME is not null.  */
659
 
660
static void
661
print_func_type (struct type *type, struct ui_file *stream, char *name)
662
{
663
  int i, len = TYPE_NFIELDS (type);
664
 
665
  if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
666
    fprintf_filtered (stream, "procedure");
667
  else
668
    fprintf_filtered (stream, "function");
669
 
670
  if (name != NULL && name[0] != '\0')
671
    fprintf_filtered (stream, " %s", name);
672
 
673
  if (len > 0)
674
    {
675
      fprintf_filtered (stream, " (");
676
      for (i = 0; i < len; i += 1)
677
        {
678
          if (i > 0)
679
            {
680
              fputs_filtered ("; ", stream);
681
              wrap_here ("    ");
682
            }
683
          fprintf_filtered (stream, "a%d: ", i + 1);
684
          ada_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
685
        }
686
      fprintf_filtered (stream, ")");
687
    }
688
 
689
  if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
690
    {
691
      fprintf_filtered (stream, " return ");
692
      ada_print_type (TYPE_TARGET_TYPE (type), "", stream, 0, 0);
693
    }
694
}
695
 
696
 
697
/* Print a description of a type TYPE0.
698
   Output goes to STREAM (via stdio).
699
   If VARSTRING is a non-empty string, print as an Ada variable/field
700
       declaration.
701
   SHOW+1 is the maximum number of levels of internal type structure
702
      to show (this applies to record types, enumerated types, and
703
      array types).
704
   SHOW is the number of levels of internal type structure to show
705
      when there is a type name for the SHOWth deepest level (0th is
706
      outer level).
707
   When SHOW<0, no inner structure is shown.
708
   LEVEL indicates level of recursion (for nested definitions).  */
709
 
710
void
711
ada_print_type (struct type *type0, char *varstring, struct ui_file *stream,
712
                int show, int level)
713
{
714
  struct type *type = ada_check_typedef (ada_get_base_type (type0));
715
  char *type_name = decoded_type_name (type0);
716
  int is_var_decl = (varstring != NULL && varstring[0] != '\0');
717
 
718
  if (type == NULL)
719
    {
720
      if (is_var_decl)
721
        fprintf_filtered (stream, "%.*s: ",
722
                          ada_name_prefix_len (varstring), varstring);
723
      fprintf_filtered (stream, "<null type?>");
724
      return;
725
    }
726
 
727
  if (show > 0)
728
    type = ada_check_typedef (type);
729
 
730
  if (is_var_decl && TYPE_CODE (type) != TYPE_CODE_FUNC)
731
    fprintf_filtered (stream, "%.*s: ",
732
                      ada_name_prefix_len (varstring), varstring);
733
 
734
  if (type_name != NULL && show <= 0)
735
    {
736
      fprintf_filtered (stream, "%.*s",
737
                        ada_name_prefix_len (type_name), type_name);
738
      return;
739
    }
740
 
741
  if (ada_is_aligner_type (type))
742
    ada_print_type (ada_aligned_type (type), "", stream, show, level);
743
  else if (ada_is_constrained_packed_array_type (type))
744
    {
745
      if (TYPE_CODE (type) == TYPE_CODE_PTR)
746
        {
747
          fprintf_filtered (stream, "access ");
748
          print_array_type (TYPE_TARGET_TYPE (type), stream, show, level);
749
        }
750
      else
751
        {
752
          print_array_type (type, stream, show, level);
753
        }
754
    }
755
  else
756
    switch (TYPE_CODE (type))
757
      {
758
      default:
759
        fprintf_filtered (stream, "<");
760
        c_print_type (type, "", stream, show, level);
761
        fprintf_filtered (stream, ">");
762
        break;
763
      case TYPE_CODE_PTR:
764
        fprintf_filtered (stream, "access ");
765
        ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level);
766
        break;
767
      case TYPE_CODE_REF:
768
        fprintf_filtered (stream, "<ref> ");
769
        ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level);
770
        break;
771
      case TYPE_CODE_ARRAY:
772
        print_array_type (type, stream, show, level);
773
        break;
774
      case TYPE_CODE_BOOL:
775
        fprintf_filtered (stream, "(false, true)");
776
        break;
777
      case TYPE_CODE_INT:
778
        if (ada_is_fixed_point_type (type))
779
          print_fixed_point_type (type, stream);
780
        else
781
          {
782
            char *name = ada_type_name (type);
783
            if (!ada_is_range_type_name (name))
784
              fprintf_filtered (stream, _("<%d-byte integer>"),
785
                                TYPE_LENGTH (type));
786
            else
787
              {
788
                fprintf_filtered (stream, "range ");
789
                print_range_type_named (name, type, stream);
790
              }
791
          }
792
        break;
793
      case TYPE_CODE_RANGE:
794
        if (ada_is_fixed_point_type (type))
795
          print_fixed_point_type (type, stream);
796
        else if (ada_is_modular_type (type))
797
          fprintf_filtered (stream, "mod %s",
798
                            int_string (ada_modulus (type), 10, 0, 0, 1));
799
        else
800
          {
801
            fprintf_filtered (stream, "range ");
802
            print_range (type, stream);
803
          }
804
        break;
805
      case TYPE_CODE_FLT:
806
        fprintf_filtered (stream, _("<%d-byte float>"), TYPE_LENGTH (type));
807
        break;
808
      case TYPE_CODE_ENUM:
809
        if (show < 0)
810
          fprintf_filtered (stream, "(...)");
811
        else
812
          print_enum_type (type, stream);
813
        break;
814
      case TYPE_CODE_STRUCT:
815
        if (ada_is_array_descriptor_type (type))
816
          print_array_type (type, stream, show, level);
817
        else if (ada_is_bogus_array_descriptor (type))
818
          fprintf_filtered (stream,
819
                            _("array (?) of ? (<mal-formed descriptor>)"));
820
        else
821
          print_record_type (type, stream, show, level);
822
        break;
823
      case TYPE_CODE_UNION:
824
        print_unchecked_union_type (type, stream, show, level);
825
        break;
826
      case TYPE_CODE_FUNC:
827
        print_func_type (type, stream, varstring);
828
        break;
829
      }
830
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.