gdb/p-typeprint.c - gdb

Functions defined

Source code

  1. /* Support for printing Pascal types for GDB, the GNU debugger.
  2.    Copyright (C) 2000-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. /* This file is derived from p-typeprint.c */

  15. #include "defs.h"
  16. #include "gdb_obstack.h"
  17. #include "bfd.h"                /* Binary File Description */
  18. #include "symtab.h"
  19. #include "gdbtypes.h"
  20. #include "expression.h"
  21. #include "value.h"
  22. #include "gdbcore.h"
  23. #include "target.h"
  24. #include "language.h"
  25. #include "p-lang.h"
  26. #include "typeprint.h"
  27. #include "gdb-demangle.h"
  28. #include <ctype.h>

  29. static void pascal_type_print_varspec_suffix (struct type *, struct ui_file *,
  30.                                               int, int, int,
  31.                                               const struct type_print_options *);

  32. static void pascal_type_print_derivation_info (struct ui_file *,
  33.                                                struct type *);



  34. /* LEVEL is the depth to indent lines by.  */

  35. void
  36. pascal_print_type (struct type *type, const char *varstring,
  37.                    struct ui_file *stream, int show, int level,
  38.                    const struct type_print_options *flags)
  39. {
  40.   enum type_code code;
  41.   int demangled_args;

  42.   code = TYPE_CODE (type);

  43.   if (show > 0)
  44.     CHECK_TYPEDEF (type);

  45.   if ((code == TYPE_CODE_FUNC
  46.        || code == TYPE_CODE_METHOD))
  47.     {
  48.       pascal_type_print_varspec_prefix (type, stream, show, 0, flags);
  49.     }
  50.   /* first the name */
  51.   fputs_filtered (varstring, stream);

  52.   if ((varstring != NULL && *varstring != '\0')
  53.       && !(code == TYPE_CODE_FUNC
  54.            || code == TYPE_CODE_METHOD))
  55.     {
  56.       fputs_filtered (" : ", stream);
  57.     }

  58.   if (!(code == TYPE_CODE_FUNC
  59.         || code == TYPE_CODE_METHOD))
  60.     {
  61.       pascal_type_print_varspec_prefix (type, stream, show, 0, flags);
  62.     }

  63.   pascal_type_print_base (type, stream, show, level, flags);
  64.   /* For demangled function names, we have the arglist as part of the name,
  65.      so don't print an additional pair of ()'s.  */

  66.   demangled_args = varstring ? strchr (varstring, '(') != NULL : 0;
  67.   pascal_type_print_varspec_suffix (type, stream, show, 0, demangled_args,
  68.                                     flags);

  69. }

  70. /* Print a typedef using Pascal syntax.  TYPE is the underlying type.
  71.    NEW_SYMBOL is the symbol naming the type.  STREAM is the stream on
  72.    which to print.  */

  73. void
  74. pascal_print_typedef (struct type *type, struct symbol *new_symbol,
  75.                       struct ui_file *stream)
  76. {
  77.   CHECK_TYPEDEF (type);
  78.   fprintf_filtered (stream, "type ");
  79.   fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol));
  80.   type_print (type, "", stream, 0);
  81.   fprintf_filtered (stream, ";\n");
  82. }

  83. /* If TYPE is a derived type, then print out derivation information.
  84.    Print only the actual base classes of this type, not the base classes
  85.    of the base classes.  I.e. for the derivation hierarchy:

  86.    class A { int a; };
  87.    class B : public A {int b; };
  88.    class C : public B {int c; };

  89.    Print the type of class C as:

  90.    class C : public B {
  91.    int c;
  92.    }

  93.    Not as the following (like gdb used to), which is not legal C++ syntax for
  94.    derived types and may be confused with the multiple inheritance form:

  95.    class C : public B : public A {
  96.    int c;
  97.    }

  98.    In general, gdb should try to print the types as closely as possible to
  99.    the form that they appear in the source code.  */

  100. static void
  101. pascal_type_print_derivation_info (struct ui_file *stream, struct type *type)
  102. {
  103.   const char *name;
  104.   int i;

  105.   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
  106.     {
  107.       fputs_filtered (i == 0 ? ": " : ", ", stream);
  108.       fprintf_filtered (stream, "%s%s ",
  109.                         BASETYPE_VIA_PUBLIC (type, i) ? "public" : "private",
  110.                         BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
  111.       name = type_name_no_tag (TYPE_BASECLASS (type, i));
  112.       fprintf_filtered (stream, "%s", name ? name : "(null)");
  113.     }
  114.   if (i > 0)
  115.     {
  116.       fputs_filtered (" ", stream);
  117.     }
  118. }

  119. /* Print the Pascal method arguments ARGS to the file STREAM.  */

  120. void
  121. pascal_type_print_method_args (const char *physname, const char *methodname,
  122.                                struct ui_file *stream)
  123. {
  124.   int is_constructor = (strncmp (physname, "__ct__", 6) == 0);
  125.   int is_destructor = (strncmp (physname, "__dt__", 6) == 0);

  126.   if (is_constructor || is_destructor)
  127.     {
  128.       physname += 6;
  129.     }

  130.   fputs_filtered (methodname, stream);

  131.   if (physname && (*physname != 0))
  132.     {
  133.       fputs_filtered (" (", stream);
  134.       /* We must demangle this.  */
  135.       while (isdigit (physname[0]))
  136.         {
  137.           int len = 0;
  138.           int i, j;
  139.           char *argname;

  140.           while (isdigit (physname[len]))
  141.             {
  142.               len++;
  143.             }
  144.           i = strtol (physname, &argname, 0);
  145.           physname += len;

  146.           for (j = 0; j < i; ++j)
  147.             fputc_filtered (physname[j], stream);

  148.           physname += i;
  149.           if (physname[0] != 0)
  150.             {
  151.               fputs_filtered (", ", stream);
  152.             }
  153.         }
  154.       fputs_filtered (")", stream);
  155.     }
  156. }

  157. /* Print any asterisks or open-parentheses needed before the
  158.    variable name (to describe its type).

  159.    On outermost call, pass 0 for PASSED_A_PTR.
  160.    On outermost call, SHOW > 0 means should ignore
  161.    any typename for TYPE and show its details.
  162.    SHOW is always zero on recursive calls.  */

  163. void
  164. pascal_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
  165.                                   int show, int passed_a_ptr,
  166.                                   const struct type_print_options *flags)
  167. {
  168.   if (type == 0)
  169.     return;

  170.   if (TYPE_NAME (type) && show <= 0)
  171.     return;

  172.   QUIT;

  173.   switch (TYPE_CODE (type))
  174.     {
  175.     case TYPE_CODE_PTR:
  176.       fprintf_filtered (stream, "^");
  177.       pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1,
  178.                                         flags);
  179.       break;                        /* Pointer should be handled normally
  180.                                    in pascal.  */

  181.     case TYPE_CODE_METHOD:
  182.       if (passed_a_ptr)
  183.         fprintf_filtered (stream, "(");
  184.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
  185.         {
  186.           fprintf_filtered (stream, "function  ");
  187.         }
  188.       else
  189.         {
  190.           fprintf_filtered (stream, "procedure ");
  191.         }

  192.       if (passed_a_ptr)
  193.         {
  194.           fprintf_filtered (stream, " ");
  195.           pascal_type_print_base (TYPE_DOMAIN_TYPE (type),
  196.                                   stream, 0, passed_a_ptr, flags);
  197.           fprintf_filtered (stream, "::");
  198.         }
  199.       break;

  200.     case TYPE_CODE_REF:
  201.       pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1,
  202.                                         flags);
  203.       fprintf_filtered (stream, "&");
  204.       break;

  205.     case TYPE_CODE_FUNC:
  206.       if (passed_a_ptr)
  207.         fprintf_filtered (stream, "(");

  208.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
  209.         {
  210.           fprintf_filtered (stream, "function  ");
  211.         }
  212.       else
  213.         {
  214.           fprintf_filtered (stream, "procedure ");
  215.         }

  216.       break;

  217.     case TYPE_CODE_ARRAY:
  218.       if (passed_a_ptr)
  219.         fprintf_filtered (stream, "(");
  220.       fprintf_filtered (stream, "array ");
  221.       if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
  222.         && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
  223.         fprintf_filtered (stream, "[%s..%s] ",
  224.                           plongest (TYPE_ARRAY_LOWER_BOUND_VALUE (type)),
  225.                           plongest (TYPE_ARRAY_UPPER_BOUND_VALUE (type)));
  226.       fprintf_filtered (stream, "of ");
  227.       break;

  228.     case TYPE_CODE_UNDEF:
  229.     case TYPE_CODE_STRUCT:
  230.     case TYPE_CODE_UNION:
  231.     case TYPE_CODE_ENUM:
  232.     case TYPE_CODE_INT:
  233.     case TYPE_CODE_FLT:
  234.     case TYPE_CODE_VOID:
  235.     case TYPE_CODE_ERROR:
  236.     case TYPE_CODE_CHAR:
  237.     case TYPE_CODE_BOOL:
  238.     case TYPE_CODE_SET:
  239.     case TYPE_CODE_RANGE:
  240.     case TYPE_CODE_STRING:
  241.     case TYPE_CODE_COMPLEX:
  242.     case TYPE_CODE_TYPEDEF:
  243.       /* These types need no prefix.  They are listed here so that
  244.          gcc -Wall will reveal any types that haven't been handled.  */
  245.       break;
  246.     default:
  247.       error (_("type not handled in pascal_type_print_varspec_prefix()"));
  248.       break;
  249.     }
  250. }

  251. static void
  252. pascal_print_func_args (struct type *type, struct ui_file *stream,
  253.                         const struct type_print_options *flags)
  254. {
  255.   int i, len = TYPE_NFIELDS (type);

  256.   if (len)
  257.     {
  258.       fprintf_filtered (stream, "(");
  259.     }
  260.   for (i = 0; i < len; i++)
  261.     {
  262.       if (i > 0)
  263.         {
  264.           fputs_filtered (", ", stream);
  265.           wrap_here ("    ");
  266.         }
  267.       /*  Can we find if it is a var parameter ??
  268.          if ( TYPE_FIELD(type, i) == )
  269.          {
  270.          fprintf_filtered (stream, "var ");
  271.          } */
  272.       pascal_print_type (TYPE_FIELD_TYPE (type, i), ""        /* TYPE_FIELD_NAME
  273.                                                            seems invalid!  */
  274.                          ,stream, -1, 0, flags);
  275.     }
  276.   if (len)
  277.     {
  278.       fprintf_filtered (stream, ")");
  279.     }
  280. }

  281. /* Print any array sizes, function arguments or close parentheses
  282.    needed after the variable name (to describe its type).
  283.    Args work like pascal_type_print_varspec_prefix.  */

  284. static void
  285. pascal_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
  286.                                   int show, int passed_a_ptr,
  287.                                   int demangled_args,
  288.                                   const struct type_print_options *flags)
  289. {
  290.   if (type == 0)
  291.     return;

  292.   if (TYPE_NAME (type) && show <= 0)
  293.     return;

  294.   QUIT;

  295.   switch (TYPE_CODE (type))
  296.     {
  297.     case TYPE_CODE_ARRAY:
  298.       if (passed_a_ptr)
  299.         fprintf_filtered (stream, ")");
  300.       break;

  301.     case TYPE_CODE_METHOD:
  302.       if (passed_a_ptr)
  303.         fprintf_filtered (stream, ")");
  304.       pascal_type_print_method_args ("",
  305.                                      "",
  306.                                      stream);
  307.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
  308.         {
  309.           fprintf_filtered (stream, " : ");
  310.           pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  311.                                             stream, 0, 0, flags);
  312.           pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, 0,
  313.                                   flags);
  314.           pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
  315.                                             passed_a_ptr, 0, flags);
  316.         }
  317.       break;

  318.     case TYPE_CODE_PTR:
  319.     case TYPE_CODE_REF:
  320.       pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type),
  321.                                         stream, 0, 1, 0, flags);
  322.       break;

  323.     case TYPE_CODE_FUNC:
  324.       if (passed_a_ptr)
  325.         fprintf_filtered (stream, ")");
  326.       if (!demangled_args)
  327.         pascal_print_func_args (type, stream, flags);
  328.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
  329.         {
  330.           fprintf_filtered (stream, " : ");
  331.           pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  332.                                             stream, 0, 0, flags);
  333.           pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, 0,
  334.                                   flags);
  335.           pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
  336.                                             passed_a_ptr, 0, flags);
  337.         }
  338.       break;

  339.     case TYPE_CODE_UNDEF:
  340.     case TYPE_CODE_STRUCT:
  341.     case TYPE_CODE_UNION:
  342.     case TYPE_CODE_ENUM:
  343.     case TYPE_CODE_INT:
  344.     case TYPE_CODE_FLT:
  345.     case TYPE_CODE_VOID:
  346.     case TYPE_CODE_ERROR:
  347.     case TYPE_CODE_CHAR:
  348.     case TYPE_CODE_BOOL:
  349.     case TYPE_CODE_SET:
  350.     case TYPE_CODE_RANGE:
  351.     case TYPE_CODE_STRING:
  352.     case TYPE_CODE_COMPLEX:
  353.     case TYPE_CODE_TYPEDEF:
  354.       /* These types do not need a suffix.  They are listed so that
  355.          gcc -Wall will report types that may not have been considered.  */
  356.       break;
  357.     default:
  358.       error (_("type not handled in pascal_type_print_varspec_suffix()"));
  359.       break;
  360.     }
  361. }

  362. /* Print the name of the type (or the ultimate pointer target,
  363.    function value or array element), or the description of a
  364.    structure or union.

  365.    SHOW positive means print details about the type (e.g. enum values),
  366.    and print structure elements passing SHOW - 1 for show.
  367.    SHOW negative means just print the type name or struct tag if there is one.
  368.    If there is no name, print something sensible but concise like
  369.    "struct {...}".
  370.    SHOW zero means just print the type name or struct tag if there is one.
  371.    If there is no name, print something sensible but not as concise like
  372.    "struct {int x; int y;}".

  373.    LEVEL is the number of spaces to indent by.
  374.    We increase it for some recursive calls.  */

  375. void
  376. pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
  377.                         int level, const struct type_print_options *flags)
  378. {
  379.   int i;
  380.   int len;
  381.   LONGEST lastval;
  382.   enum
  383.     {
  384.       s_none, s_public, s_private, s_protected
  385.     }
  386.   section_type;

  387.   QUIT;
  388.   wrap_here ("    ");
  389.   if (type == NULL)
  390.     {
  391.       fputs_filtered ("<type unknown>", stream);
  392.       return;
  393.     }

  394.   /* void pointer */
  395.   if ((TYPE_CODE (type) == TYPE_CODE_PTR)
  396.       && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID))
  397.     {
  398.       fputs_filtered (TYPE_NAME (type) ? TYPE_NAME (type) : "pointer",
  399.                       stream);
  400.       return;
  401.     }
  402.   /* When SHOW is zero or less, and there is a valid type name, then always
  403.      just print the type name directly from the type.  */

  404.   if (show <= 0
  405.       && TYPE_NAME (type) != NULL)
  406.     {
  407.       fputs_filtered (TYPE_NAME (type), stream);
  408.       return;
  409.     }

  410.   CHECK_TYPEDEF (type);

  411.   switch (TYPE_CODE (type))
  412.     {
  413.     case TYPE_CODE_TYPEDEF:
  414.     case TYPE_CODE_PTR:
  415.     case TYPE_CODE_REF:
  416.       /* case TYPE_CODE_FUNC:
  417.          case TYPE_CODE_METHOD: */
  418.       pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level,
  419.                               flags);
  420.       break;

  421.     case TYPE_CODE_ARRAY:
  422.       /* pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  423.                                            stream, 0, 0);
  424.          pascal_type_print_base (TYPE_TARGET_TYPE (type),
  425.                                  stream, show, level);
  426.          pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type),
  427.                                            stream, 0, 0, 0); */
  428.       pascal_print_type (TYPE_TARGET_TYPE (type), NULL, stream, 0, 0, flags);
  429.       break;

  430.     case TYPE_CODE_FUNC:
  431.     case TYPE_CODE_METHOD:
  432.       /*
  433.          pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
  434.          only after args !!  */
  435.       break;
  436.     case TYPE_CODE_STRUCT:
  437.       if (TYPE_TAG_NAME (type) != NULL)
  438.         {
  439.           fputs_filtered (TYPE_TAG_NAME (type), stream);
  440.           fputs_filtered (" = ", stream);
  441.         }
  442.       if (HAVE_CPLUS_STRUCT (type))
  443.         {
  444.           fprintf_filtered (stream, "class ");
  445.         }
  446.       else
  447.         {
  448.           fprintf_filtered (stream, "record ");
  449.         }
  450.       goto struct_union;

  451.     case TYPE_CODE_UNION:
  452.       if (TYPE_TAG_NAME (type) != NULL)
  453.         {
  454.           fputs_filtered (TYPE_TAG_NAME (type), stream);
  455.           fputs_filtered (" = ", stream);
  456.         }
  457.       fprintf_filtered (stream, "case <?> of ");

  458.     struct_union:
  459.       wrap_here ("    ");
  460.       if (show < 0)
  461.         {
  462.           /* If we just printed a tag name, no need to print anything else.  */
  463.           if (TYPE_TAG_NAME (type) == NULL)
  464.             fprintf_filtered (stream, "{...}");
  465.         }
  466.       else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
  467.         {
  468.           pascal_type_print_derivation_info (stream, type);

  469.           fprintf_filtered (stream, "\n");
  470.           if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
  471.             {
  472.               if (TYPE_STUB (type))
  473.                 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
  474.               else
  475.                 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
  476.             }

  477.           /* Start off with no specific section type, so we can print
  478.              one for the first field we find, and use that section type
  479.              thereafter until we find another type.  */

  480.           section_type = s_none;

  481.           /* If there is a base class for this type,
  482.              do not print the field that it occupies.  */

  483.           len = TYPE_NFIELDS (type);
  484.           for (i = TYPE_N_BASECLASSES (type); i < len; i++)
  485.             {
  486.               QUIT;
  487.               /* Don't print out virtual function table.  */
  488.               if ((strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5) == 0)
  489.                   && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
  490.                 continue;

  491.               /* If this is a pascal object or class we can print the
  492.                  various section labels.  */

  493.               if (HAVE_CPLUS_STRUCT (type))
  494.                 {
  495.                   if (TYPE_FIELD_PROTECTED (type, i))
  496.                     {
  497.                       if (section_type != s_protected)
  498.                         {
  499.                           section_type = s_protected;
  500.                           fprintfi_filtered (level + 2, stream,
  501.                                              "protected\n");
  502.                         }
  503.                     }
  504.                   else if (TYPE_FIELD_PRIVATE (type, i))
  505.                     {
  506.                       if (section_type != s_private)
  507.                         {
  508.                           section_type = s_private;
  509.                           fprintfi_filtered (level + 2, stream, "private\n");
  510.                         }
  511.                     }
  512.                   else
  513.                     {
  514.                       if (section_type != s_public)
  515.                         {
  516.                           section_type = s_public;
  517.                           fprintfi_filtered (level + 2, stream, "public\n");
  518.                         }
  519.                     }
  520.                 }

  521.               print_spaces_filtered (level + 4, stream);
  522.               if (field_is_static (&TYPE_FIELD (type, i)))
  523.                 fprintf_filtered (stream, "static ");
  524.               pascal_print_type (TYPE_FIELD_TYPE (type, i),
  525.                                  TYPE_FIELD_NAME (type, i),
  526.                                  stream, show - 1, level + 4, flags);
  527.               if (!field_is_static (&TYPE_FIELD (type, i))
  528.                   && TYPE_FIELD_PACKED (type, i))
  529.                 {
  530.                   /* It is a bitfield.  This code does not attempt
  531.                      to look at the bitpos and reconstruct filler,
  532.                      unnamed fields.  This would lead to misleading
  533.                      results if the compiler does not put out fields
  534.                      for such things (I don't know what it does).  */
  535.                   fprintf_filtered (stream, " : %d",
  536.                                     TYPE_FIELD_BITSIZE (type, i));
  537.                 }
  538.               fprintf_filtered (stream, ";\n");
  539.             }

  540.           /* If there are both fields and methods, put a space between.  */
  541.           len = TYPE_NFN_FIELDS (type);
  542.           if (len && section_type != s_none)
  543.             fprintf_filtered (stream, "\n");

  544.           /* Object pascal: print out the methods.  */

  545.           for (i = 0; i < len; i++)
  546.             {
  547.               struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
  548.               int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
  549.               const char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);

  550.               /* this is GNU C++ specific
  551.                  how can we know constructor/destructor?
  552.                  It might work for GNU pascal.  */
  553.               for (j = 0; j < len2; j++)
  554.                 {
  555.                   const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);

  556.                   int is_constructor = (strncmp (physname, "__ct__", 6) == 0);
  557.                   int is_destructor = (strncmp (physname, "__dt__", 6) == 0);

  558.                   QUIT;
  559.                   if (TYPE_FN_FIELD_PROTECTED (f, j))
  560.                     {
  561.                       if (section_type != s_protected)
  562.                         {
  563.                           section_type = s_protected;
  564.                           fprintfi_filtered (level + 2, stream,
  565.                                              "protected\n");
  566.                         }
  567.                     }
  568.                   else if (TYPE_FN_FIELD_PRIVATE (f, j))
  569.                     {
  570.                       if (section_type != s_private)
  571.                         {
  572.                           section_type = s_private;
  573.                           fprintfi_filtered (level + 2, stream, "private\n");
  574.                         }
  575.                     }
  576.                   else
  577.                     {
  578.                       if (section_type != s_public)
  579.                         {
  580.                           section_type = s_public;
  581.                           fprintfi_filtered (level + 2, stream, "public\n");
  582.                         }
  583.                     }

  584.                   print_spaces_filtered (level + 4, stream);
  585.                   if (TYPE_FN_FIELD_STATIC_P (f, j))
  586.                     fprintf_filtered (stream, "static ");
  587.                   if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
  588.                     {
  589.                       /* Keep GDB from crashing here.  */
  590.                       fprintf_filtered (stream, "<undefined type> %s;\n",
  591.                                         TYPE_FN_FIELD_PHYSNAME (f, j));
  592.                       break;
  593.                     }

  594.                   if (is_constructor)
  595.                     {
  596.                       fprintf_filtered (stream, "constructor ");
  597.                     }
  598.                   else if (is_destructor)
  599.                     {
  600.                       fprintf_filtered (stream, "destructor  ");
  601.                     }
  602.                   else if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0
  603.                            && TYPE_CODE (TYPE_TARGET_TYPE (
  604.                                 TYPE_FN_FIELD_TYPE (f, j))) != TYPE_CODE_VOID)
  605.                     {
  606.                       fprintf_filtered (stream, "function  ");
  607.                     }
  608.                   else
  609.                     {
  610.                       fprintf_filtered (stream, "procedure ");
  611.                     }
  612.                   /* This does not work, no idea why !!  */

  613.                   pascal_type_print_method_args (physname,
  614.                                                  method_name,
  615.                                                  stream);

  616.                   if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0
  617.                       && TYPE_CODE (TYPE_TARGET_TYPE (
  618.                            TYPE_FN_FIELD_TYPE (f, j))) != TYPE_CODE_VOID)
  619.                     {
  620.                       fputs_filtered (" : ", stream);
  621.                       type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
  622.                                   "", stream, -1);
  623.                     }
  624.                   if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  625.                     fprintf_filtered (stream, "; virtual");

  626.                   fprintf_filtered (stream, ";\n");
  627.                 }
  628.             }
  629.           fprintfi_filtered (level, stream, "end");
  630.         }
  631.       break;

  632.     case TYPE_CODE_ENUM:
  633.       if (TYPE_TAG_NAME (type) != NULL)
  634.         {
  635.           fputs_filtered (TYPE_TAG_NAME (type), stream);
  636.           if (show > 0)
  637.             fputs_filtered (" ", stream);
  638.         }
  639.       /* enum is just defined by
  640.          type enume_name = (enum_member1,enum_member2,...)  */
  641.       fprintf_filtered (stream, " = ");
  642.       wrap_here ("    ");
  643.       if (show < 0)
  644.         {
  645.           /* If we just printed a tag name, no need to print anything else.  */
  646.           if (TYPE_TAG_NAME (type) == NULL)
  647.             fprintf_filtered (stream, "(...)");
  648.         }
  649.       else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
  650.         {
  651.           fprintf_filtered (stream, "(");
  652.           len = TYPE_NFIELDS (type);
  653.           lastval = 0;
  654.           for (i = 0; i < len; i++)
  655.             {
  656.               QUIT;
  657.               if (i)
  658.                 fprintf_filtered (stream, ", ");
  659.               wrap_here ("    ");
  660.               fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  661.               if (lastval != TYPE_FIELD_ENUMVAL (type, i))
  662.                 {
  663.                   fprintf_filtered (stream,
  664.                                     " := %s",
  665.                                     plongest (TYPE_FIELD_ENUMVAL (type, i)));
  666.                   lastval = TYPE_FIELD_ENUMVAL (type, i);
  667.                 }
  668.               lastval++;
  669.             }
  670.           fprintf_filtered (stream, ")");
  671.         }
  672.       break;

  673.     case TYPE_CODE_VOID:
  674.       fprintf_filtered (stream, "void");
  675.       break;

  676.     case TYPE_CODE_UNDEF:
  677.       fprintf_filtered (stream, "record <unknown>");
  678.       break;

  679.     case TYPE_CODE_ERROR:
  680.       fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
  681.       break;

  682.       /* this probably does not work for enums.  */
  683.     case TYPE_CODE_RANGE:
  684.       {
  685.         struct type *target = TYPE_TARGET_TYPE (type);

  686.         print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
  687.         fputs_filtered ("..", stream);
  688.         print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
  689.       }
  690.       break;

  691.     case TYPE_CODE_SET:
  692.       fputs_filtered ("set of ", stream);
  693.       pascal_print_type (TYPE_INDEX_TYPE (type), "", stream,
  694.                          show - 1, level, flags);
  695.       break;

  696.     case TYPE_CODE_STRING:
  697.       fputs_filtered ("String", stream);
  698.       break;

  699.     default:
  700.       /* Handle types not explicitly handled by the other cases,
  701.          such as fundamental types.  For these, just print whatever
  702.          the type name is, as recorded in the type itself.  If there
  703.          is no type name, then complain.  */
  704.       if (TYPE_NAME (type) != NULL)
  705.         {
  706.           fputs_filtered (TYPE_NAME (type), stream);
  707.         }
  708.       else
  709.         {
  710.           /* At least for dump_symtab, it is important that this not be
  711.              an error ().  */
  712.           fprintf_filtered (stream, "<invalid unnamed pascal type code %d>",
  713.                             TYPE_CODE (type));
  714.         }
  715.       break;
  716.     }
  717. }