GDB (API)
/home/stan/gdb/src/gdb/ada-typeprint.c
Go to the documentation of this file.
00001 /* Support for printing Ada types for GDB, the GNU debugger.
00002    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00003 
00004    This file is part of GDB.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 3 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00018 
00019 #include "defs.h"
00020 #include "gdb_obstack.h"
00021 #include "bfd.h"                /* Binary File Description */
00022 #include "symtab.h"
00023 #include "gdbtypes.h"
00024 #include "expression.h"
00025 #include "value.h"
00026 #include "gdbcore.h"
00027 #include "target.h"
00028 #include "command.h"
00029 #include "gdbcmd.h"
00030 #include "language.h"
00031 #include "demangle.h"
00032 #include "c-lang.h"
00033 #include "typeprint.h"
00034 #include "ada-lang.h"
00035 
00036 #include <ctype.h>
00037 #include "gdb_string.h"
00038 #include <errno.h>
00039 
00040 static int print_selected_record_field_types (struct type *, struct type *,
00041                                               int, int,
00042                                               struct ui_file *, int, int,
00043                                               const struct type_print_options *);
00044    
00045 static int print_record_field_types (struct type *, struct type *,
00046                                      struct ui_file *, int, int,
00047                                      const struct type_print_options *);
00048 
00049 static void print_array_type (struct type *, struct ui_file *, int, int,
00050                               const struct type_print_options *);
00051 
00052 static int print_choices (struct type *, int, struct ui_file *,
00053                           struct type *);
00054 
00055 static void print_range (struct type *, struct ui_file *);
00056 
00057 static void print_range_bound (struct type *, char *, int *,
00058                                struct ui_file *);
00059 
00060 static void
00061 print_dynamic_range_bound (struct type *, const char *, int,
00062                            const char *, struct ui_file *);
00063 
00064 static void print_range_type (struct type *, struct ui_file *);
00065 
00066 
00067 
00068 static char *name_buffer;
00069 static int name_buffer_len;
00070 
00071 /* The (decoded) Ada name of TYPE.  This value persists until the
00072    next call.  */
00073 
00074 static char *
00075 decoded_type_name (struct type *type)
00076 {
00077   if (ada_type_name (type) == NULL)
00078     return NULL;
00079   else
00080     {
00081       const char *raw_name = ada_type_name (type);
00082       char *s, *q;
00083 
00084       if (name_buffer == NULL || name_buffer_len <= strlen (raw_name))
00085         {
00086           name_buffer_len = 16 + 2 * strlen (raw_name);
00087           name_buffer = xrealloc (name_buffer, name_buffer_len);
00088         }
00089       strcpy (name_buffer, raw_name);
00090 
00091       s = (char *) strstr (name_buffer, "___");
00092       if (s != NULL)
00093         *s = '\0';
00094 
00095       s = name_buffer + strlen (name_buffer) - 1;
00096       while (s > name_buffer && (s[0] != '_' || s[-1] != '_'))
00097         s -= 1;
00098 
00099       if (s == name_buffer)
00100         return name_buffer;
00101 
00102       if (!islower (s[1]))
00103         return NULL;
00104 
00105       for (s = q = name_buffer; *s != '\0'; q += 1)
00106         {
00107           if (s[0] == '_' && s[1] == '_')
00108             {
00109               *q = '.';
00110               s += 2;
00111             }
00112           else
00113             {
00114               *q = *s;
00115               s += 1;
00116             }
00117         }
00118       *q = '\0';
00119       return name_buffer;
00120     }
00121 }
00122 
00123 /* Print TYPE on STREAM, preferably as a range.  */
00124 
00125 static void
00126 print_range (struct type *type, struct ui_file *stream)
00127 {
00128   switch (TYPE_CODE (type))
00129     {
00130     case TYPE_CODE_RANGE:
00131     case TYPE_CODE_ENUM:
00132       {
00133         struct type *target_type;
00134         target_type = TYPE_TARGET_TYPE (type);
00135         if (target_type == NULL)
00136           target_type = type;
00137         ada_print_scalar (target_type, ada_discrete_type_low_bound (type),
00138                           stream);
00139         fprintf_filtered (stream, " .. ");
00140         ada_print_scalar (target_type, ada_discrete_type_high_bound (type),
00141                           stream);
00142       }
00143       break;
00144     default:
00145       fprintf_filtered (stream, "%.*s",
00146                         ada_name_prefix_len (TYPE_NAME (type)),
00147                         TYPE_NAME (type));
00148       break;
00149     }
00150 }
00151 
00152 /* Print the number or discriminant bound at BOUNDS+*N on STREAM, and
00153    set *N past the bound and its delimiter, if any.  */
00154 
00155 static void
00156 print_range_bound (struct type *type, char *bounds, int *n,
00157                    struct ui_file *stream)
00158 {
00159   LONGEST B;
00160 
00161   if (ada_scan_number (bounds, *n, &B, n))
00162     {
00163       /* STABS decodes all range types which bounds are 0 .. -1 as
00164          unsigned integers (ie. the type code is TYPE_CODE_INT, not
00165          TYPE_CODE_RANGE).  Unfortunately, ada_print_scalar() relies
00166          on the unsigned flag to determine whether the bound should
00167          be printed as a signed or an unsigned value.  This causes
00168          the upper bound of the 0 .. -1 range types to be printed as
00169          a very large unsigned number instead of -1.
00170          To workaround this stabs deficiency, we replace the TYPE by NULL
00171          to indicate default output when we detect that the bound is negative,
00172          and the type is a TYPE_CODE_INT.  The bound is negative when
00173          'm' is the last character of the number scanned in BOUNDS.  */
00174       if (bounds[*n - 1] == 'm' && TYPE_CODE (type) == TYPE_CODE_INT)
00175         type = NULL;
00176       ada_print_scalar (type, B, stream);
00177       if (bounds[*n] == '_')
00178         *n += 2;
00179     }
00180   else
00181     {
00182       int bound_len;
00183       char *bound = bounds + *n;
00184       char *pend;
00185 
00186       pend = strstr (bound, "__");
00187       if (pend == NULL)
00188         *n += bound_len = strlen (bound);
00189       else
00190         {
00191           bound_len = pend - bound;
00192           *n += bound_len + 2;
00193         }
00194       fprintf_filtered (stream, "%.*s", bound_len, bound);
00195     }
00196 }
00197 
00198 /* Assuming NAME[0 .. NAME_LEN-1] is the name of a range type, print
00199    the value (if found) of the bound indicated by SUFFIX ("___L" or
00200    "___U") according to the ___XD conventions.  */
00201 
00202 static void
00203 print_dynamic_range_bound (struct type *type, const char *name, int name_len,
00204                            const char *suffix, struct ui_file *stream)
00205 {
00206   static char *name_buf = NULL;
00207   static size_t name_buf_len = 0;
00208   LONGEST B;
00209   int OK;
00210 
00211   GROW_VECT (name_buf, name_buf_len, name_len + strlen (suffix) + 1);
00212   strncpy (name_buf, name, name_len);
00213   strcpy (name_buf + name_len, suffix);
00214 
00215   B = get_int_var_value (name_buf, &OK);
00216   if (OK)
00217     ada_print_scalar (type, B, stream);
00218   else
00219     fprintf_filtered (stream, "?");
00220 }
00221 
00222 /* Print RAW_TYPE as a range type, using any bound information
00223    following the GNAT encoding (if available).  */
00224 
00225 static void
00226 print_range_type (struct type *raw_type, struct ui_file *stream)
00227 {
00228   const char *name;
00229   struct type *base_type;
00230   const char *subtype_info;
00231 
00232   gdb_assert (raw_type != NULL);
00233   name = TYPE_NAME (raw_type);
00234   gdb_assert (name != NULL);
00235 
00236   if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
00237     base_type = TYPE_TARGET_TYPE (raw_type);
00238   else
00239     base_type = raw_type;
00240 
00241   subtype_info = strstr (name, "___XD");
00242   if (subtype_info == NULL)
00243     print_range (raw_type, stream);
00244   else
00245     {
00246       int prefix_len = subtype_info - name;
00247       char *bounds_str;
00248       int n;
00249 
00250       subtype_info += 5;
00251       bounds_str = strchr (subtype_info, '_');
00252       n = 1;
00253 
00254       if (*subtype_info == 'L')
00255         {
00256           print_range_bound (base_type, bounds_str, &n, stream);
00257           subtype_info += 1;
00258         }
00259       else
00260         print_dynamic_range_bound (base_type, name, prefix_len, "___L",
00261                                    stream);
00262 
00263       fprintf_filtered (stream, " .. ");
00264 
00265       if (*subtype_info == 'U')
00266         print_range_bound (base_type, bounds_str, &n, stream);
00267       else
00268         print_dynamic_range_bound (base_type, name, prefix_len, "___U",
00269                                    stream);
00270     }
00271 }
00272 
00273 /* Print enumerated type TYPE on STREAM.  */
00274 
00275 static void
00276 print_enum_type (struct type *type, struct ui_file *stream)
00277 {
00278   int len = TYPE_NFIELDS (type);
00279   int i;
00280   LONGEST lastval;
00281 
00282   fprintf_filtered (stream, "(");
00283   wrap_here (" ");
00284 
00285   lastval = 0;
00286   for (i = 0; i < len; i++)
00287     {
00288       QUIT;
00289       if (i)
00290         fprintf_filtered (stream, ", ");
00291       wrap_here ("    ");
00292       fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
00293       if (lastval != TYPE_FIELD_ENUMVAL (type, i))
00294         {
00295           fprintf_filtered (stream, " => %s",
00296                             plongest (TYPE_FIELD_ENUMVAL (type, i)));
00297           lastval = TYPE_FIELD_ENUMVAL (type, i);
00298         }
00299       lastval += 1;
00300     }
00301   fprintf_filtered (stream, ")");
00302 }
00303 
00304 /* Print representation of Ada fixed-point type TYPE on STREAM.  */
00305 
00306 static void
00307 print_fixed_point_type (struct type *type, struct ui_file *stream)
00308 {
00309   DOUBLEST delta = ada_delta (type);
00310   DOUBLEST small = ada_fixed_to_float (type, 1.0);
00311 
00312   if (delta < 0.0)
00313     fprintf_filtered (stream, "delta ??");
00314   else
00315     {
00316       fprintf_filtered (stream, "delta %g", (double) delta);
00317       if (delta != small)
00318         fprintf_filtered (stream, " <'small = %g>", (double) small);
00319     }
00320 }
00321 
00322 /* Print simple (constrained) array type TYPE on STREAM.  LEVEL is the
00323    recursion (indentation) level, in case the element type itself has
00324    nested structure, and SHOW is the number of levels of internal
00325    structure to show (see ada_print_type).  */
00326 
00327 static void
00328 print_array_type (struct type *type, struct ui_file *stream, int show,
00329                   int level, const struct type_print_options *flags)
00330 {
00331   int bitsize;
00332   int n_indices;
00333 
00334   if (ada_is_constrained_packed_array_type (type))
00335     type = ada_coerce_to_simple_array_type (type);
00336 
00337   bitsize = 0;
00338   fprintf_filtered (stream, "array (");
00339 
00340   if (type == NULL)
00341     {
00342       fprintf_filtered (stream, _("<undecipherable array type>"));
00343       return;
00344     }
00345 
00346   n_indices = -1;
00347   if (ada_is_simple_array_type (type))
00348     {
00349       struct type *range_desc_type;
00350       struct type *arr_type;
00351 
00352       range_desc_type = ada_find_parallel_type (type, "___XA");
00353       ada_fixup_array_indexes_type (range_desc_type);
00354 
00355       bitsize = 0;
00356       if (range_desc_type == NULL)
00357         {
00358           for (arr_type = type; TYPE_CODE (arr_type) == TYPE_CODE_ARRAY;
00359                arr_type = TYPE_TARGET_TYPE (arr_type))
00360             {
00361               if (arr_type != type)
00362                 fprintf_filtered (stream, ", ");
00363               print_range (TYPE_INDEX_TYPE (arr_type), stream);
00364               if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
00365                 bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
00366             }
00367         }
00368       else
00369         {
00370           int k;
00371 
00372           n_indices = TYPE_NFIELDS (range_desc_type);
00373           for (k = 0, arr_type = type;
00374                k < n_indices;
00375                k += 1, arr_type = TYPE_TARGET_TYPE (arr_type))
00376             {
00377               if (k > 0)
00378                 fprintf_filtered (stream, ", ");
00379               print_range_type (TYPE_FIELD_TYPE (range_desc_type, k),
00380                                 stream);
00381               if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
00382                 bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
00383             }
00384         }
00385     }
00386   else
00387     {
00388       int i, i0;
00389 
00390       for (i = i0 = ada_array_arity (type); i > 0; i -= 1)
00391         fprintf_filtered (stream, "%s<>", i == i0 ? "" : ", ");
00392     }
00393 
00394   fprintf_filtered (stream, ") of ");
00395   wrap_here ("");
00396   ada_print_type (ada_array_element_type (type, n_indices), "", stream,
00397                   show == 0 ? 0 : show - 1, level + 1, flags);
00398   if (bitsize > 0)
00399     fprintf_filtered (stream, " <packed: %d-bit elements>", bitsize);
00400 }
00401 
00402 /* Print the choices encoded by field FIELD_NUM of variant-part TYPE on
00403    STREAM, assuming that VAL_TYPE (if non-NULL) is the type of the
00404    values.  Return non-zero if the field is an encoding of
00405    discriminant values, as in a standard variant record, and 0 if the
00406    field is not so encoded (as happens with single-component variants
00407    in types annotated with pragma Unchecked_Variant).  */
00408 
00409 static int
00410 print_choices (struct type *type, int field_num, struct ui_file *stream,
00411                struct type *val_type)
00412 {
00413   int have_output;
00414   int p;
00415   const char *name = TYPE_FIELD_NAME (type, field_num);
00416 
00417   have_output = 0;
00418 
00419   /* Skip over leading 'V': NOTE soon to be obsolete.  */
00420   if (name[0] == 'V')
00421     {
00422       if (!ada_scan_number (name, 1, NULL, &p))
00423         goto Huh;
00424     }
00425   else
00426     p = 0;
00427 
00428   while (1)
00429     {
00430       switch (name[p])
00431         {
00432         default:
00433           goto Huh;
00434         case '_':
00435         case '\0':
00436           fprintf_filtered (stream, " =>");
00437           return 1;
00438         case 'S':
00439         case 'R':
00440         case 'O':
00441           if (have_output)
00442             fprintf_filtered (stream, " | ");
00443           have_output = 1;
00444           break;
00445         }
00446 
00447       switch (name[p])
00448         {
00449         case 'S':
00450           {
00451             LONGEST W;
00452 
00453             if (!ada_scan_number (name, p + 1, &W, &p))
00454               goto Huh;
00455             ada_print_scalar (val_type, W, stream);
00456             break;
00457           }
00458         case 'R':
00459           {
00460             LONGEST L, U;
00461 
00462             if (!ada_scan_number (name, p + 1, &L, &p)
00463                 || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p))
00464               goto Huh;
00465             ada_print_scalar (val_type, L, stream);
00466             fprintf_filtered (stream, " .. ");
00467             ada_print_scalar (val_type, U, stream);
00468             break;
00469           }
00470         case 'O':
00471           fprintf_filtered (stream, "others");
00472           p += 1;
00473           break;
00474         }
00475     }
00476 
00477 Huh:
00478   fprintf_filtered (stream, "?? =>");
00479   return 0;
00480 }
00481 
00482 /* Assuming that field FIELD_NUM of TYPE represents variants whose
00483    discriminant is contained in OUTER_TYPE, print its components on STREAM.
00484    LEVEL is the recursion (indentation) level, in case any of the fields
00485    themselves have nested structure, and SHOW is the number of levels of 
00486    internal structure to show (see ada_print_type).  For this purpose,
00487    fields nested in a variant part are taken to be at the same level as
00488    the fields immediately outside the variant part.  */
00489 
00490 static void
00491 print_variant_clauses (struct type *type, int field_num,
00492                        struct type *outer_type, struct ui_file *stream,
00493                        int show, int level,
00494                        const struct type_print_options *flags)
00495 {
00496   int i;
00497   struct type *var_type, *par_type;
00498   struct type *discr_type;
00499 
00500   var_type = TYPE_FIELD_TYPE (type, field_num);
00501   discr_type = ada_variant_discrim_type (var_type, outer_type);
00502 
00503   if (TYPE_CODE (var_type) == TYPE_CODE_PTR)
00504     {
00505       var_type = TYPE_TARGET_TYPE (var_type);
00506       if (var_type == NULL || TYPE_CODE (var_type) != TYPE_CODE_UNION)
00507         return;
00508     }
00509 
00510   par_type = ada_find_parallel_type (var_type, "___XVU");
00511   if (par_type != NULL)
00512     var_type = par_type;
00513 
00514   for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
00515     {
00516       fprintf_filtered (stream, "\n%*swhen ", level + 4, "");
00517       if (print_choices (var_type, i, stream, discr_type))
00518         {
00519           if (print_record_field_types (TYPE_FIELD_TYPE (var_type, i),
00520                                         outer_type, stream, show, level + 4,
00521                                         flags)
00522               <= 0)
00523             fprintf_filtered (stream, " null;");
00524         }
00525       else
00526         print_selected_record_field_types (var_type, outer_type, i, i,
00527                                            stream, show, level + 4, flags);
00528     }
00529 }
00530 
00531 /* Assuming that field FIELD_NUM of TYPE is a variant part whose
00532    discriminants are contained in OUTER_TYPE, print a description of it
00533    on STREAM.  LEVEL is the recursion (indentation) level, in case any of
00534    the fields themselves have nested structure, and SHOW is the number of
00535    levels of internal structure to show (see ada_print_type).  For this
00536    purpose, fields nested in a variant part are taken to be at the same
00537    level as the fields immediately outside the variant part.  */
00538 
00539 static void
00540 print_variant_part (struct type *type, int field_num, struct type *outer_type,
00541                     struct ui_file *stream, int show, int level,
00542                     const struct type_print_options *flags)
00543 {
00544   fprintf_filtered (stream, "\n%*scase %s is", level + 4, "",
00545                     ada_variant_discrim_name
00546                     (TYPE_FIELD_TYPE (type, field_num)));
00547   print_variant_clauses (type, field_num, outer_type, stream, show,
00548                          level + 4, flags);
00549   fprintf_filtered (stream, "\n%*send case;", level + 4, "");
00550 }
00551 
00552 /* Print a description on STREAM of the fields FLD0 through FLD1 in
00553    record or union type TYPE, whose discriminants are in OUTER_TYPE.
00554    LEVEL is the recursion (indentation) level, in case any of the
00555    fields themselves have nested structure, and SHOW is the number of
00556    levels of internal structure to show (see ada_print_type).  Does
00557    not print parent type information of TYPE.  Returns 0 if no fields
00558    printed, -1 for an incomplete type, else > 0.  Prints each field
00559    beginning on a new line, but does not put a new line at end.  */
00560 
00561 static int
00562 print_selected_record_field_types (struct type *type, struct type *outer_type,
00563                                    int fld0, int fld1,
00564                                    struct ui_file *stream, int show, int level,
00565                                    const struct type_print_options *flags)
00566 {
00567   int i, flds;
00568 
00569   flds = 0;
00570 
00571   if (fld0 > fld1 && TYPE_STUB (type))
00572     return -1;
00573 
00574   for (i = fld0; i <= fld1; i += 1)
00575     {
00576       QUIT;
00577 
00578       if (ada_is_parent_field (type, i) || ada_is_ignored_field (type, i))
00579         ;
00580       else if (ada_is_wrapper_field (type, i))
00581         flds += print_record_field_types (TYPE_FIELD_TYPE (type, i), type,
00582                                           stream, show, level, flags);
00583       else if (ada_is_variant_part (type, i))
00584         {
00585           print_variant_part (type, i, outer_type, stream, show, level, flags);
00586           flds = 1;
00587         }
00588       else
00589         {
00590           flds += 1;
00591           fprintf_filtered (stream, "\n%*s", level + 4, "");
00592           ada_print_type (TYPE_FIELD_TYPE (type, i),
00593                           TYPE_FIELD_NAME (type, i),
00594                           stream, show - 1, level + 4, flags);
00595           fprintf_filtered (stream, ";");
00596         }
00597     }
00598 
00599   return flds;
00600 }
00601 
00602 /* Print a description on STREAM of all fields of record or union type
00603    TYPE, as for print_selected_record_field_types, above.  */
00604 
00605 static int
00606 print_record_field_types (struct type *type, struct type *outer_type,
00607                           struct ui_file *stream, int show, int level,
00608                           const struct type_print_options *flags)
00609 {
00610   return print_selected_record_field_types (type, outer_type,
00611                                             0, TYPE_NFIELDS (type) - 1,
00612                                             stream, show, level, flags);
00613 }
00614    
00615 
00616 /* Print record type TYPE on STREAM.  LEVEL is the recursion (indentation)
00617    level, in case the element type itself has nested structure, and SHOW is
00618    the number of levels of internal structure to show (see ada_print_type).  */
00619 
00620 static void
00621 print_record_type (struct type *type0, struct ui_file *stream, int show,
00622                    int level, const struct type_print_options *flags)
00623 {
00624   struct type *parent_type;
00625   struct type *type;
00626 
00627   type = ada_find_parallel_type (type0, "___XVE");
00628   if (type == NULL)
00629     type = type0;
00630 
00631   parent_type = ada_parent_type (type);
00632   if (ada_type_name (parent_type) != NULL)
00633     {
00634       const char *parent_name = decoded_type_name (parent_type);
00635 
00636       /* If we fail to decode the parent type name, then use the parent
00637          type name as is.  Not pretty, but should never happen except
00638          when the debugging info is incomplete or incorrect.  This
00639          prevents a crash trying to print a NULL pointer.  */
00640       if (parent_name == NULL)
00641         parent_name = ada_type_name (parent_type);
00642       fprintf_filtered (stream, "new %s with record", parent_name);
00643     }
00644   else if (parent_type == NULL && ada_is_tagged_type (type, 0))
00645     fprintf_filtered (stream, "tagged record");
00646   else
00647     fprintf_filtered (stream, "record");
00648 
00649   if (show < 0)
00650     fprintf_filtered (stream, " ... end record");
00651   else
00652     {
00653       int flds;
00654 
00655       flds = 0;
00656       if (parent_type != NULL && ada_type_name (parent_type) == NULL)
00657         flds += print_record_field_types (parent_type, parent_type,
00658                                           stream, show, level, flags);
00659       flds += print_record_field_types (type, type, stream, show, level,
00660                                         flags);
00661 
00662       if (flds > 0)
00663         fprintf_filtered (stream, "\n%*send record", level, "");
00664       else if (flds < 0)
00665         fprintf_filtered (stream, _(" <incomplete type> end record"));
00666       else
00667         fprintf_filtered (stream, " null; end record");
00668     }
00669 }
00670 
00671 /* Print the unchecked union type TYPE in something resembling Ada
00672    format on STREAM.  LEVEL is the recursion (indentation) level
00673    in case the element type itself has nested structure, and SHOW is the
00674    number of levels of internal structure to show (see ada_print_type).  */
00675 static void
00676 print_unchecked_union_type (struct type *type, struct ui_file *stream,
00677                             int show, int level,
00678                             const struct type_print_options *flags)
00679 {
00680   if (show < 0)
00681     fprintf_filtered (stream, "record (?) is ... end record");
00682   else if (TYPE_NFIELDS (type) == 0)
00683     fprintf_filtered (stream, "record (?) is null; end record");
00684   else
00685     {
00686       int i;
00687 
00688       fprintf_filtered (stream, "record (?) is\n%*scase ? is", level + 4, "");
00689 
00690       for (i = 0; i < TYPE_NFIELDS (type); i += 1)
00691         {
00692           fprintf_filtered (stream, "\n%*swhen ? =>\n%*s", level + 8, "",
00693                             level + 12, "");
00694           ada_print_type (TYPE_FIELD_TYPE (type, i),
00695                           TYPE_FIELD_NAME (type, i),
00696                           stream, show - 1, level + 12, flags);
00697           fprintf_filtered (stream, ";");
00698         }
00699 
00700       fprintf_filtered (stream, "\n%*send case;\n%*send record",
00701                         level + 4, "", level, "");
00702     }
00703 }
00704 
00705 
00706 
00707 /* Print function or procedure type TYPE on STREAM.  Make it a header
00708    for function or procedure NAME if NAME is not null.  */
00709 
00710 static void
00711 print_func_type (struct type *type, struct ui_file *stream, const char *name,
00712                  const struct type_print_options *flags)
00713 {
00714   int i, len = TYPE_NFIELDS (type);
00715 
00716   if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
00717     fprintf_filtered (stream, "procedure");
00718   else
00719     fprintf_filtered (stream, "function");
00720 
00721   if (name != NULL && name[0] != '\0')
00722     fprintf_filtered (stream, " %s", name);
00723 
00724   if (len > 0)
00725     {
00726       fprintf_filtered (stream, " (");
00727       for (i = 0; i < len; i += 1)
00728         {
00729           if (i > 0)
00730             {
00731               fputs_filtered ("; ", stream);
00732               wrap_here ("    ");
00733             }
00734           fprintf_filtered (stream, "a%d: ", i + 1);
00735           ada_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0,
00736                           flags);
00737         }
00738       fprintf_filtered (stream, ")");
00739     }
00740 
00741   if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
00742     {
00743       fprintf_filtered (stream, " return ");
00744       ada_print_type (TYPE_TARGET_TYPE (type), "", stream, 0, 0, flags);
00745     }
00746 }
00747 
00748 
00749 /* Print a description of a type TYPE0.
00750    Output goes to STREAM (via stdio).
00751    If VARSTRING is a non-empty string, print as an Ada variable/field
00752        declaration.
00753    SHOW+1 is the maximum number of levels of internal type structure
00754       to show (this applies to record types, enumerated types, and
00755       array types).
00756    SHOW is the number of levels of internal type structure to show
00757       when there is a type name for the SHOWth deepest level (0th is
00758       outer level).
00759    When SHOW<0, no inner structure is shown.
00760    LEVEL indicates level of recursion (for nested definitions).  */
00761 
00762 void
00763 ada_print_type (struct type *type0, const char *varstring,
00764                 struct ui_file *stream, int show, int level,
00765                 const struct type_print_options *flags)
00766 {
00767   struct type *type = ada_check_typedef (ada_get_base_type (type0));
00768   char *type_name = decoded_type_name (type0);
00769   int is_var_decl = (varstring != NULL && varstring[0] != '\0');
00770 
00771   if (type == NULL)
00772     {
00773       if (is_var_decl)
00774         fprintf_filtered (stream, "%.*s: ",
00775                           ada_name_prefix_len (varstring), varstring);
00776       fprintf_filtered (stream, "<null type?>");
00777       return;
00778     }
00779 
00780   if (show > 0)
00781     type = ada_check_typedef (type);
00782 
00783   if (is_var_decl && TYPE_CODE (type) != TYPE_CODE_FUNC)
00784     fprintf_filtered (stream, "%.*s: ",
00785                       ada_name_prefix_len (varstring), varstring);
00786 
00787   if (type_name != NULL && show <= 0 && !ada_is_aligner_type (type))
00788     {
00789       fprintf_filtered (stream, "%.*s",
00790                         ada_name_prefix_len (type_name), type_name);
00791       return;
00792     }
00793 
00794   if (ada_is_aligner_type (type))
00795     ada_print_type (ada_aligned_type (type), "", stream, show, level, flags);
00796   else if (ada_is_constrained_packed_array_type (type)
00797            && TYPE_CODE (type) != TYPE_CODE_PTR)
00798     print_array_type (type, stream, show, level, flags);
00799   else
00800     switch (TYPE_CODE (type))
00801       {
00802       default:
00803         fprintf_filtered (stream, "<");
00804         c_print_type (type, "", stream, show, level, flags);
00805         fprintf_filtered (stream, ">");
00806         break;
00807       case TYPE_CODE_PTR:
00808       case TYPE_CODE_TYPEDEF:
00809         fprintf_filtered (stream, "access ");
00810         ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
00811                         flags);
00812         break;
00813       case TYPE_CODE_REF:
00814         fprintf_filtered (stream, "<ref> ");
00815         ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
00816                         flags);
00817         break;
00818       case TYPE_CODE_ARRAY:
00819         print_array_type (type, stream, show, level, flags);
00820         break;
00821       case TYPE_CODE_BOOL:
00822         fprintf_filtered (stream, "(false, true)");
00823         break;
00824       case TYPE_CODE_INT:
00825         if (ada_is_fixed_point_type (type))
00826           print_fixed_point_type (type, stream);
00827         else
00828           {
00829             const char *name = ada_type_name (type);
00830 
00831             if (!ada_is_range_type_name (name))
00832               fprintf_filtered (stream, _("<%d-byte integer>"),
00833                                 TYPE_LENGTH (type));
00834             else
00835               {
00836                 fprintf_filtered (stream, "range ");
00837                 print_range_type (type, stream);
00838               }
00839           }
00840         break;
00841       case TYPE_CODE_RANGE:
00842         if (ada_is_fixed_point_type (type))
00843           print_fixed_point_type (type, stream);
00844         else if (ada_is_modular_type (type))
00845           fprintf_filtered (stream, "mod %s", 
00846                             int_string (ada_modulus (type), 10, 0, 0, 1));
00847         else
00848           {
00849             fprintf_filtered (stream, "range ");
00850             print_range (type, stream);
00851           }
00852         break;
00853       case TYPE_CODE_FLT:
00854         fprintf_filtered (stream, _("<%d-byte float>"), TYPE_LENGTH (type));
00855         break;
00856       case TYPE_CODE_ENUM:
00857         if (show < 0)
00858           fprintf_filtered (stream, "(...)");
00859         else
00860           print_enum_type (type, stream);
00861         break;
00862       case TYPE_CODE_STRUCT:
00863         if (ada_is_array_descriptor_type (type))
00864           print_array_type (type, stream, show, level, flags);
00865         else if (ada_is_bogus_array_descriptor (type))
00866           fprintf_filtered (stream,
00867                             _("array (?) of ? (<mal-formed descriptor>)"));
00868         else
00869           print_record_type (type, stream, show, level, flags);
00870         break;
00871       case TYPE_CODE_UNION:
00872         print_unchecked_union_type (type, stream, show, level, flags);
00873         break;
00874       case TYPE_CODE_FUNC:
00875         print_func_type (type, stream, varstring, flags);
00876         break;
00877       }
00878 }
00879 
00880 /* Implement the la_print_typedef language method for Ada.  */
00881 
00882 void
00883 ada_print_typedef (struct type *type, struct symbol *new_symbol,
00884                    struct ui_file *stream)
00885 {
00886   type = ada_check_typedef (type);
00887   ada_print_type (type, "", stream, 0, 0, &type_print_raw_options);
00888   fprintf_filtered (stream, "\n");
00889 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines