* complaints.c: New file, code moved from utils.c.
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index 764421b9458c3749a34c865cb9b4cbf1c966febb..392fec36d9bbda2a9ac0e8b20a40913de68477bb 100644 (file)
@@ -30,6 +30,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "target.h"
 #include "value.h"
 #include "demangle.h"
+#include "complaints.h"
 
 /* Alloc a new type structure and fill it with some defaults.  If
    OBJFILE is non-NULL, then allocate the space for the type structure
@@ -52,7 +53,7 @@ alloc_type (objfile)
       type  = (struct type *) obstack_alloc (&objfile -> type_obstack,
                                             sizeof (struct type));
     }
-  memset ((char *)type, 0, sizeof (struct type));
+  memset ((char *) type, 0, sizeof (struct type));
 
   /* Initialize the fields that might not be zero. */
 
@@ -97,7 +98,7 @@ make_pointer_type (type, typeptr)
     {
       ntype = *typeptr;
       objfile = TYPE_OBJFILE (ntype);
-      memset ((char *)ntype, 0, sizeof (struct type));
+      memset ((char *) ntype, 0, sizeof (struct type));
       TYPE_OBJFILE (ntype) = objfile;
     }
 
@@ -162,7 +163,7 @@ make_reference_type (type, typeptr)
     {
       ntype = *typeptr;
       objfile = TYPE_OBJFILE (ntype);
-      memset ((char *)ntype, 0, sizeof (struct type));
+      memset ((char *) ntype, 0, sizeof (struct type));
       TYPE_OBJFILE (ntype) = objfile;
     }
 
@@ -224,7 +225,7 @@ make_function_type (type, typeptr)
     {
       ntype = *typeptr;
       objfile = TYPE_OBJFILE (ntype);
-      memset ((char *)ntype, 0, sizeof (struct type));
+      memset ((char *) ntype, 0, sizeof (struct type));
       TYPE_OBJFILE (ntype) = objfile;
     }
 
@@ -290,51 +291,54 @@ allocate_stub_method (type)
   return (mtype);
 }
 
-/* Create an array type.  Elements will be of type TYPE, and there will
-   be NUM of them.
+/* Create an array type using either a blank type supplied in RESULT_TYPE,
+   or creating a new type.  Elements will be of type ELEMENT_TYPE, the
+   indices will be of type INDEX_TYPE, and will range from LOW_BOUND
+   to HIGH_BOUND, inclusive.
 
-   Eventually this should be extended to take two more arguments which
-   specify the bounds of the array and the type of the index.
-   It should also be changed to be a "lookup" function, with the
-   appropriate data structures added to the type field.
-   Then read array type should call here.  */
+   FIXME:  Maybe we should check the TYPE_CODE of RESULT_TYPE to make
+   sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
 
 struct type *
-create_array_type (element_type, number)
+create_array_type (result_type, element_type, index_type, low_bound,
+                  high_bound)
+     struct type *result_type;
      struct type *element_type;
-     int number;
+     struct type *index_type;
+     int low_bound;
+     int high_bound;
 {
-  struct type *result_type;
   struct type *range_type;
 
-  result_type = alloc_type (TYPE_OBJFILE (element_type));
+  /* Create a blank type if we are not given one to bash on. */
+  if (result_type == NULL)
+    {
+      result_type = alloc_type (TYPE_OBJFILE (element_type));
+    }
 
+  /* Create a range type.  */
+  range_type = alloc_type (TYPE_OBJFILE (element_type));
+  TYPE_CODE (range_type) = TYPE_CODE_RANGE;
+  TYPE_TARGET_TYPE (range_type) = index_type;
+  TYPE_LENGTH (range_type) = sizeof (int);  /* This should never be needed. */
+  TYPE_NFIELDS (range_type) = 2;
+  TYPE_FIELDS (range_type) = (struct field *)
+    TYPE_ALLOC (range_type, 2 * sizeof (struct field));
+  memset (TYPE_FIELDS (range_type), 0, 2 * sizeof (struct field));
+  TYPE_FIELD_BITPOS (range_type, 0) = low_bound;
+  TYPE_FIELD_BITPOS (range_type, 1) = high_bound;
+  TYPE_FIELD_TYPE (range_type, 0) = builtin_type_int; /* FIXME */
+  TYPE_FIELD_TYPE (range_type, 1) = builtin_type_int; /* FIXME */
+
+  /* Create the array type. */
   TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
   TYPE_TARGET_TYPE (result_type) = element_type;
-  TYPE_LENGTH (result_type) = number * TYPE_LENGTH (element_type);
+  TYPE_LENGTH (result_type) =
+    TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
   TYPE_NFIELDS (result_type) = 1;
   TYPE_FIELDS (result_type) = (struct field *)
-    obstack_alloc (&TYPE_OBJFILE (result_type) -> type_obstack,
-                  sizeof (struct field));
-
-  {
-    /* Create range type.  */
-    range_type = alloc_type (TYPE_OBJFILE (result_type));
-    TYPE_CODE (range_type) = TYPE_CODE_RANGE;
-    TYPE_TARGET_TYPE (range_type) = builtin_type_int;  /* FIXME */
-
-    /* This should never be needed.  */
-    TYPE_LENGTH (range_type) = sizeof (int);
-
-    TYPE_NFIELDS (range_type) = 2;
-    TYPE_FIELDS (range_type) = (struct field *)
-      obstack_alloc (&TYPE_OBJFILE (range_type) -> type_obstack,
-                    2 * sizeof (struct field));
-    TYPE_FIELD_BITPOS (range_type, 0) = 0; /* FIXME */
-    TYPE_FIELD_BITPOS (range_type, 1) = number-1; /* FIXME */
-    TYPE_FIELD_TYPE (range_type, 0) = builtin_type_int; /* FIXME */
-    TYPE_FIELD_TYPE (range_type, 1) = builtin_type_int; /* FIXME */
-  }
+    TYPE_ALLOC (result_type, sizeof (struct field));
+  memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
   TYPE_FIELD_TYPE (result_type, 0) = range_type;
   TYPE_VPTR_FIELDNO (result_type) = -1;
 
@@ -362,7 +366,7 @@ smash_to_member_type (type, domain, to_type)
 
   objfile = TYPE_OBJFILE (type);
 
-  memset ((char *)type, 0, sizeof (struct type));
+  memset ((char *) type, 0, sizeof (struct type));
   TYPE_OBJFILE (type) = objfile;
   TYPE_TARGET_TYPE (type) = to_type;
   TYPE_DOMAIN_TYPE (type) = domain;
@@ -388,7 +392,7 @@ smash_to_method_type (type, domain, to_type, args)
 
   objfile = TYPE_OBJFILE (type);
 
-  memset ((char *)type, 0, sizeof (struct type));
+  memset ((char *) type, 0, sizeof (struct type));
   TYPE_OBJFILE (type) = objfile;
   TYPE_TARGET_TYPE (type) = to_type;
   TYPE_DOMAIN_TYPE (type) = domain;
@@ -730,7 +734,7 @@ check_stub_type (type)
       struct symbol *sym;
       if (name == NULL)
        {
-         complain (&stub_noname_complaint, 0);
+         complain (&stub_noname_complaint);
          return;
        }
       sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, 
@@ -797,8 +801,7 @@ check_stub_method (type, i, j)
      NULL [...] or void [end of arglist].  */
 
   argtypes = (struct type **)
-    obstack_alloc (&TYPE_OBJFILE (type) -> type_obstack,
-                  (argcount+2) * sizeof (struct type *));
+    TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
   p = argtypetext;
   argtypes[0] = lookup_pointer_type (type);
   argcount = 1;
@@ -851,7 +854,7 @@ check_stub_method (type, i, j)
   TYPE_FN_FIELD_STUB (f, j) = 0;
 }
 
-const struct cplus_struct_type cplus_struct_default;
+struct cplus_struct_type cplus_struct_default;
 
 void
 allocate_cplus_struct_type (type)
@@ -860,8 +863,7 @@ allocate_cplus_struct_type (type)
   if (!HAVE_CPLUS_STRUCT (type))
     {
       TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
-       obstack_alloc (&current_objfile -> type_obstack,
-                      sizeof (struct cplus_struct_type));
+       TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
       *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default;
     }
 }
@@ -914,28 +916,24 @@ init_type (code, length, flags, name, objfile)
    define fundamental types.
 
    For the formats which don't provide fundamental types, gdb can create
-   such types, using defaults reasonable for the current target machine.
-
-   FIXME:  Some compilers distinguish explicitly signed integral types
-   (signed short, signed int, signed long) from "regular" integral types
-   (short, int, long) in the debugging information.  There is some dis-
-   agreement as to how useful this feature is.  In particular, gcc does
-   not support this.  Also, only some debugging formats allow the
-   distinction to be passed on to a debugger.  For now, we always just
-   use "short", "int", or "long" as the type name, for both the implicit
-   and explicitly signed types.  This also makes life easier for the
-   gdb test suite since we don't have to account for the differences
-   in output depending upon what the compiler and debugging format
-   support.  We will probably have to re-examine the issue when gdb
-   starts taking it's fundamental type information directly from the
-   debugging information supplied by the compiler.  fnf@cygnus.com */
+   such types, using defaults reasonable for the current language and
+   the current target machine.
+
+   NOTE:  This routine is obsolescent.  Each debugging format reader
+   should manage it's own fundamental types, either creating them from
+   suitable defaults or reading them from the debugging information,
+   whichever is appropriate.  The DWARF reader has already been
+   fixed to do this.  Once the other readers are fixed, this routine
+   will go away.  Also note that fundamental types should be managed
+   on a compilation unit basis in a multi-language environment, not
+   on a linkage unit basis as is done here. */
+
 
 struct type *
 lookup_fundamental_type (objfile, typeid)
      struct objfile *objfile;
      int typeid;
 {
-  register struct type *type = NULL;
   register struct type **typep;
   register int nbytes;
 
@@ -943,187 +941,28 @@ lookup_fundamental_type (objfile, typeid)
     {
       error ("internal error - invalid fundamental type id %d", typeid);
     }
-  else
+
+  /* If this is the first time we need a fundamental type for this objfile
+     then we need to initialize the vector of type pointers. */
+  
+  if (objfile -> fundamental_types == NULL)
     {
-      /* If this is the first time we */
-      if (objfile -> fundamental_types == NULL)
-       {
-         nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
-         objfile -> fundamental_types = (struct type **)
-           obstack_alloc (&objfile -> type_obstack, nbytes);
-         memset ((char *)objfile -> fundamental_types, 0, nbytes);
-       }
-      typep = objfile -> fundamental_types + typeid;
-      if ((type = *typep) == NULL)
-       {
-         switch (typeid)
-           {
-             default:
-               error ("internal error: unhandled type id %d", typeid);
-               break;
-             case FT_VOID:
-               type = init_type (TYPE_CODE_VOID,
-                                 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "void", objfile);
-               break;
-             case FT_BOOLEAN:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_INT_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_UNSIGNED,
-                                 "boolean", objfile);
-               break;
-             case FT_STRING:
-               type = init_type (TYPE_CODE_PASCAL_ARRAY,
-                                 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "string", objfile);
-               break;
-             case FT_CHAR:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "char", objfile);
-               break;
-             case FT_SIGNED_CHAR:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_SIGNED,
-                                 "signed char", objfile);
-               break;
-             case FT_UNSIGNED_CHAR:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_UNSIGNED,
-                                 "unsigned char", objfile);
-               break;
-             case FT_SHORT:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "short", objfile);
-               break;
-             case FT_SIGNED_SHORT:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_SIGNED,
-                                 "short", objfile);    /* FIXME -fnf */
-               break;
-             case FT_UNSIGNED_SHORT:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_UNSIGNED,
-                                 "unsigned short", objfile);
-               break;
-             case FT_INTEGER:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_INT_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "int", objfile);
-               break;
-             case FT_SIGNED_INTEGER:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_INT_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_SIGNED,
-                                 "int", objfile);      /* FIXME -fnf */
-               break;
-             case FT_UNSIGNED_INTEGER:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_INT_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_UNSIGNED,
-                                 "unsigned int", objfile);
-               break;
-             case FT_FIXED_DECIMAL:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_INT_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "fixed decimal", objfile);
-               break;
-             case FT_LONG:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_LONG_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "long", objfile);
-               break;
-             case FT_SIGNED_LONG:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_LONG_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_SIGNED,
-                                 "long", objfile);     /* FIXME -fnf */
-               break;
-             case FT_UNSIGNED_LONG:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_LONG_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_UNSIGNED,
-                                 "unsigned long", objfile);
-               break;
-             case FT_LONG_LONG:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "long long", objfile);
-               break;
-             case FT_SIGNED_LONG_LONG:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_SIGNED,
-                                 "signed long long", objfile);
-               break;
-             case FT_UNSIGNED_LONG_LONG:
-               type = init_type (TYPE_CODE_INT,
-                                 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
-                                 TYPE_FLAG_UNSIGNED,
-                                 "unsigned long long", objfile);
-               break;
-             case FT_FLOAT:
-               type = init_type (TYPE_CODE_FLT,
-                                 TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "float", objfile);
-               break;
-             case FT_DBL_PREC_FLOAT:
-               type = init_type (TYPE_CODE_FLT,
-                                 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "double", objfile);
-               break;
-             case FT_FLOAT_DECIMAL:
-               type = init_type (TYPE_CODE_FLT,
-                                 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "floating decimal", objfile);
-               break;
-             case FT_EXT_PREC_FLOAT:
-               type = init_type (TYPE_CODE_FLT,
-                                 TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "long double", objfile);
-               break;
-             case FT_COMPLEX:
-               type = init_type (TYPE_CODE_FLT,
-                                 TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "complex", objfile);
-               break;
-             case FT_DBL_PREC_COMPLEX:
-               type = init_type (TYPE_CODE_FLT,
-                                 TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "double complex", objfile);
-               break;
-             case FT_EXT_PREC_COMPLEX:
-               type = init_type (TYPE_CODE_FLT,
-                                 TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
-                                 0,
-                                 "long double complex", objfile);
-               break;
-           }
-         /* Install the newly created type in the objfile's fundamental_types
-            vector. */
-         *typep = type;
-       }
+      nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
+      objfile -> fundamental_types = (struct type **)
+       obstack_alloc (&objfile -> type_obstack, nbytes);
+      memset ((char *) objfile -> fundamental_types, 0, nbytes);
     }
-  return (type);
+
+  /* Look for this particular type in the fundamental type vector.  If one is
+     not found, create and install one appropriate for the current language. */
+
+  typep = objfile -> fundamental_types + typeid;
+  if (*typep == NULL)
+    {
+      *typep = create_fundamental_type (objfile, typeid);
+    }
+
+  return (*typep);
 }
 
 #if MAINTENANCE_CMDS
This page took 0.027843 seconds and 4 git commands to generate.