* gdbtypes.h (builtin_type_true_char): Remove.
[deliverable/binutils-gdb.git] / gdb / p-typeprint.c
index a2cfadb4d40ed1e1f26e2dea7d6b005bcd76b22c..62f4511f09e6fa2034111fc7dafbefea2a30995f 100644 (file)
@@ -1,12 +1,12 @@
 /* Support for printing Pascal types for GDB, the GNU debugger.
-   Copyright 2000
+   Copyright (C) 2000, 2001, 2002, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* This file is derived from p-typeprint.c */
 
 #include "defs.h"
-#include "obstack.h"
+#include "gdb_obstack.h"
 #include "bfd.h"               /* Binary File Description */
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "value.h"
 #include "gdbcore.h"
 #include "target.h"
-#include "command.h"
-#include "gdbcmd.h"
 #include "language.h"
-#include "demangle.h"
 #include "p-lang.h"
 #include "typeprint.h"
 
@@ -40,8 +36,6 @@
 #include <errno.h>
 #include <ctype.h>
 
-static void pascal_type_print_args (struct type *, struct ui_file *);
-
 static void pascal_type_print_varspec_suffix (struct type *, struct ui_file *, int, int, int);
 
 static void pascal_type_print_derivation_info (struct ui_file *, struct type *);
@@ -52,14 +46,10 @@ void pascal_type_print_varspec_prefix (struct type *, struct ui_file *, int, int
 /* LEVEL is the depth to indent lines by.  */
 
 void
-pascal_print_type (type, varstring, stream, show, level)
-     struct type *type;
-     char *varstring;
-     struct ui_file *stream;
-     int show;
-     int level;
+pascal_print_type (struct type *type, char *varstring, struct ui_file *stream,
+                  int show, int level)
 {
-  register enum type_code code;
+  enum type_code code;
   int demangled_args;
 
   code = TYPE_CODE (type);
@@ -67,23 +57,23 @@ pascal_print_type (type, varstring, stream, show, level)
   if (show > 0)
     CHECK_TYPEDEF (type);
 
-  if ((code == TYPE_CODE_FUNC ||
-       code == TYPE_CODE_METHOD))
+  if ((code == TYPE_CODE_FUNC
+       || code == TYPE_CODE_METHOD))
     {
       pascal_type_print_varspec_prefix (type, stream, show, 0);
     }
   /* first the name */
   fputs_filtered (varstring, stream);
 
-  if ((varstring != NULL && *varstring != '\0') &&
-      !(code == TYPE_CODE_FUNC ||
-       code == TYPE_CODE_METHOD))
+  if ((varstring != NULL && *varstring != '\0')
+      && !(code == TYPE_CODE_FUNC
+          || code == TYPE_CODE_METHOD))
     {
       fputs_filtered (" : ", stream);
     }
 
-  if (!(code == TYPE_CODE_FUNC ||
-       code == TYPE_CODE_METHOD))
+  if (!(code == TYPE_CODE_FUNC
+       || code == TYPE_CODE_METHOD))
     {
       pascal_type_print_varspec_prefix (type, stream, show, 0);
     }
@@ -97,6 +87,21 @@ pascal_print_type (type, varstring, stream, show, level)
 
 }
 
+/* Print a typedef using Pascal syntax.  TYPE is the underlying type.
+   NEW_SYMBOL is the symbol naming the type.  STREAM is the stream on
+   which to print.  */
+
+void
+pascal_print_typedef (struct type *type, struct symbol *new_symbol,
+                     struct ui_file *stream)
+{
+  CHECK_TYPEDEF (type);
+  fprintf_filtered (stream, "type ");
+  fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol));
+  type_print (type, "", stream, 0);
+  fprintf_filtered (stream, ";\n");
+}
+
 /* If TYPE is a derived type, then print out derivation information.
    Print only the actual base classes of this type, not the base classes
    of the base classes.  I.E.  for the derivation hierarchy:
@@ -122,9 +127,7 @@ pascal_print_type (type, varstring, stream, show, level)
    the form that they appear in the source code. */
 
 static void
-pascal_type_print_derivation_info (stream, type)
-     struct ui_file *stream;
-     struct type *type;
+pascal_type_print_derivation_info (struct ui_file *stream, struct type *type)
 {
   char *name;
   int i;
@@ -147,13 +150,11 @@ pascal_type_print_derivation_info (stream, type)
 /* Print the Pascal method arguments ARGS to the file STREAM.  */
 
 void
-pascal_type_print_method_args (physname, methodname, stream)
-     char *physname;
-     char *methodname;
-     struct ui_file *stream;
+pascal_type_print_method_args (char *physname, char *methodname,
+                              struct ui_file *stream)
 {
-  int is_constructor = STREQN (physname, "__ct__", 6);
-  int is_destructor = STREQN (physname, "__dt__", 6);
+  int is_constructor = (strncmp (physname, "__ct__", 6) == 0);
+  int is_destructor = (strncmp (physname, "__dt__", 6) == 0);
 
   if (is_constructor || is_destructor)
     {
@@ -170,11 +171,9 @@ pascal_type_print_method_args (physname, methodname, stream)
       char *argname;
       fputs_filtered (" (", stream);
       /* we must demangle this */
-      while isdigit
-       (physname[0])
+      while (isdigit (physname[0]))
        {
-         while isdigit
-           (physname[len])
+         while (isdigit (physname[len]))
            {
              len++;
            }
@@ -203,11 +202,8 @@ pascal_type_print_method_args (physname, methodname, stream)
    SHOW is always zero on recursive calls.  */
 
 void
-pascal_type_print_varspec_prefix (type, stream, show, passed_a_ptr)
-     struct type *type;
-     struct ui_file *stream;
-     int show;
-     int passed_a_ptr;
+pascal_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
+                                 int show, int passed_a_ptr)
 {
   char *name;
   if (type == 0)
@@ -225,19 +221,6 @@ pascal_type_print_varspec_prefix (type, stream, show, passed_a_ptr)
       pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
       break;                   /* pointer should be handled normally in pascal */
 
-    case TYPE_CODE_MEMBER:
-      if (passed_a_ptr)
-       fprintf_filtered (stream, "(");
-      pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
-      fprintf_filtered (stream, " ");
-      name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
-      if (name)
-       fputs_filtered (name, stream);
-      else
-       pascal_type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
-      fprintf_filtered (stream, "::");
-      break;
-
     case TYPE_CODE_METHOD:
       if (passed_a_ptr)
        fprintf_filtered (stream, "(");
@@ -282,8 +265,8 @@ pascal_type_print_varspec_prefix (type, stream, show, passed_a_ptr)
       if (passed_a_ptr)
        fprintf_filtered (stream, "(");
       fprintf_filtered (stream, "array ");
-      if (TYPE_LENGTH (type) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
-       && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
+      if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
+       && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
        fprintf_filtered (stream, "[%d..%d] ",
                          TYPE_ARRAY_LOWER_BOUND_VALUE (type),
                          TYPE_ARRAY_UPPER_BOUND_VALUE (type)
@@ -312,59 +295,11 @@ pascal_type_print_varspec_prefix (type, stream, show, passed_a_ptr)
          gcc -Wall will reveal any types that haven't been handled.  */
       break;
     default:
-      error ("type not handled in pascal_type_print_varspec_prefix()");
+      error (_("type not handled in pascal_type_print_varspec_prefix()"));
       break;
     }
 }
 
-static void
-pascal_type_print_args (type, stream)
-     struct type *type;
-     struct ui_file *stream;
-{
-  int i;
-  struct type **args;
-
-  /*  fprintf_filtered (stream, "(");
-     no () for procedures !! */
-  args = TYPE_ARG_TYPES (type);
-  if (args != NULL)
-    {
-      if ((args[1] != NULL && args[1]->code != TYPE_CODE_VOID) ||
-         (args[2] != NULL))
-       {
-         fprintf_filtered (stream, "(");
-       }
-      if (args[1] == NULL)
-       {
-         fprintf_filtered (stream, "...");
-       }
-      else
-       {
-         for (i = 1;
-              args[i] != NULL && args[i]->code != TYPE_CODE_VOID;
-              i++)
-           {
-             pascal_print_type (args[i], "", stream, -1, 0);
-             if (args[i + 1] == NULL)
-               {
-                 fprintf_filtered (stream, "...");
-               }
-             else if (args[i + 1]->code != TYPE_CODE_VOID)
-               {
-                 fprintf_filtered (stream, ",");
-                 wrap_here ("    ");
-               }
-           }
-       }
-      if ((args[1] != NULL && args[1]->code != TYPE_CODE_VOID) ||
-         (args[2] != NULL))
-       {
-         fprintf_filtered (stream, ")");
-       }
-    }
-}
-
 static void
 pascal_print_func_args (struct type *type, struct ui_file *stream)
 {
@@ -399,12 +334,9 @@ pascal_print_func_args (struct type *type, struct ui_file *stream)
    Args work like pascal_type_print_varspec_prefix.  */
 
 static void
-pascal_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
-     struct type *type;
-     struct ui_file *stream;
-     int show;
-     int passed_a_ptr;
-     int demangled_args;
+pascal_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
+                                 int show, int passed_a_ptr,
+                                 int demangled_args)
 {
   if (type == 0)
     return;
@@ -421,19 +353,12 @@ pascal_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_ar
        fprintf_filtered (stream, ")");
       break;
 
-    case TYPE_CODE_MEMBER:
-      if (passed_a_ptr)
-       fprintf_filtered (stream, ")");
-      pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
-      break;
-
     case TYPE_CODE_METHOD:
       if (passed_a_ptr)
        fprintf_filtered (stream, ")");
       pascal_type_print_method_args ("",
                                     "",
                                     stream);
-      /* pascal_type_print_args (type, stream); */
       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
        {
          fprintf_filtered (stream, " : ");
@@ -485,7 +410,7 @@ pascal_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_ar
          gcc -Wall will report types that may not have been considered.  */
       break;
     default:
-      error ("type not handled in pascal_type_print_varspec_suffix()");
+      error (_("type not handled in pascal_type_print_varspec_suffix()"));
       break;
     }
 }
@@ -507,15 +432,12 @@ pascal_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_ar
    We increase it for some recursive calls.  */
 
 void
-pascal_type_print_base (type, stream, show, level)
-     struct type *type;
-     struct ui_file *stream;
-     int show;
-     int level;
+pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
+                       int level)
 {
-  register int i;
-  register int len;
-  register int lastval;
+  int i;
+  int len;
+  int lastval;
   enum
     {
       s_none, s_public, s_private, s_protected
@@ -533,8 +455,8 @@ pascal_type_print_base (type, stream, show, level)
   /* void pointer */
   if ((TYPE_CODE (type) == TYPE_CODE_PTR) && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID))
     {
-      fprintf_filtered (stream,
-                       TYPE_NAME (type) ? TYPE_NAME (type) : "pointer");
+      fputs_filtered (TYPE_NAME (type) ? TYPE_NAME (type) : "pointer",
+                     stream);
       return;
     }
   /* When SHOW is zero or less, and there is a valid type name, then always
@@ -553,7 +475,6 @@ pascal_type_print_base (type, stream, show, level)
     {
     case TYPE_CODE_TYPEDEF:
     case TYPE_CODE_PTR:
-    case TYPE_CODE_MEMBER:
     case TYPE_CODE_REF:
       /* case TYPE_CODE_FUNC:
          case TYPE_CODE_METHOD: */
@@ -612,7 +533,7 @@ pascal_type_print_base (type, stream, show, level)
          fprintf_filtered (stream, "\n");
          if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
            {
-             if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
+             if (TYPE_STUB (type))
                fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
              else
                fprintfi_filtered (level + 4, stream, "<no data fields>\n");
@@ -632,7 +553,7 @@ pascal_type_print_base (type, stream, show, level)
            {
              QUIT;
              /* Don't print out virtual function table.  */
-             if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5)
+             if ((strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5) == 0)
                  && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
                continue;
 
@@ -669,14 +590,12 @@ pascal_type_print_base (type, stream, show, level)
                }
 
              print_spaces_filtered (level + 4, stream);
-             if (TYPE_FIELD_STATIC (type, i))
-               {
-                 fprintf_filtered (stream, "static ");
-               }
+             if (field_is_static (&TYPE_FIELD (type, i)))
+               fprintf_filtered (stream, "static ");
              pascal_print_type (TYPE_FIELD_TYPE (type, i),
                                 TYPE_FIELD_NAME (type, i),
                                 stream, show - 1, level + 4);
-             if (!TYPE_FIELD_STATIC (type, i)
+             if (!field_is_static (&TYPE_FIELD (type, i))
                  && TYPE_FIELD_PACKED (type, i))
                {
                  /* It is a bitfield.  This code does not attempt
@@ -710,8 +629,8 @@ pascal_type_print_base (type, stream, show, level)
                {
                  char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
 
-                 int is_constructor = STREQN (physname, "__ct__", 6);
-                 int is_destructor = STREQN (physname, "__dt__", 6);
+                 int is_constructor = (strncmp (physname, "__ct__", 6) == 0);
+                 int is_destructor = (strncmp (physname, "__dt__", 6) == 0);
 
                  QUIT;
                  if (TYPE_FN_FIELD_PROTECTED (f, j))
@@ -759,8 +678,9 @@ pascal_type_print_base (type, stream, show, level)
                    {
                      fprintf_filtered (stream, "destructor  ");
                    }
-                 else if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0 &&
-                          TYPE_CODE (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j))) != TYPE_CODE_VOID)
+                 else if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0
+                          && TYPE_CODE (TYPE_TARGET_TYPE (
+                               TYPE_FN_FIELD_TYPE (f, j))) != TYPE_CODE_VOID)
                    {
                      fprintf_filtered (stream, "function  ");
                    }
@@ -774,8 +694,9 @@ pascal_type_print_base (type, stream, show, level)
                                                 method_name,
                                                 stream);
 
-                 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0 &&
-                     TYPE_CODE (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j))) != TYPE_CODE_VOID)
+                 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0
+                     && TYPE_CODE (TYPE_TARGET_TYPE (
+                          TYPE_FN_FIELD_TYPE (f, j))) != TYPE_CODE_VOID)
                    {
                      fputs_filtered (" : ", stream);
                      type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
@@ -847,8 +768,6 @@ pascal_type_print_base (type, stream, show, level)
     case TYPE_CODE_RANGE:
       {
        struct type *target = TYPE_TARGET_TYPE (type);
-       if (target == NULL)
-         target = builtin_type_long;
        print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
        fputs_filtered ("..", stream);
        print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
@@ -861,6 +780,14 @@ pascal_type_print_base (type, stream, show, level)
                         show - 1, level);
       break;
 
+    case TYPE_CODE_BITSTRING:
+      fputs_filtered ("BitString", stream);
+      break;
+
+    case TYPE_CODE_STRING:
+      fputs_filtered ("String", stream);
+      break;
+
     default:
       /* Handle types not explicitly handled by the other cases,
          such as fundamental types.  For these, just print whatever
This page took 0.029573 seconds and 4 git commands to generate.