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