Add sparclite support.
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index 91908711233fad14202663cc44b30823df9e2a08..77a26bc78a4fb90a1111955fd472a616b60a0e79 100644 (file)
@@ -18,16 +18,18 @@ 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-#include <stdio.h>
 #include "defs.h"
+#include <string.h>
 #include "bfd.h"
 #include "symtab.h"
 #include "symfile.h"
+#include "objfiles.h"
 #include "gdbtypes.h"
 #include "expression.h"
 #include "language.h"
 #include "target.h"
 #include "value.h"
+#include "demangle.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
@@ -50,7 +52,7 @@ alloc_type (objfile)
       type  = (struct type *) obstack_alloc (&objfile -> type_obstack,
                                             sizeof (struct type));
     }
-  (void) memset (type, 0, sizeof (struct type));
+  (void) memset ((char *)type, 0, sizeof (struct type));
 
   /* Initialize the fields that might not be zero. */
 
@@ -61,6 +63,61 @@ alloc_type (objfile)
   return (type);
 }
 
+/* Lookup a pointer to a type TYPE.  TYPEPTR, if nonzero, points
+   to a pointer to memory where the pointer type should be stored.
+   If *TYPEPTR is zero, update it to point to the pointer type we return.
+   We allocate new memory if needed.  */
+
+struct type *
+make_pointer_type (type, typeptr)
+     struct type *type;
+     struct type **typeptr;
+{
+  register struct type *ntype;         /* New type */
+  struct objfile *objfile;
+
+  ntype = TYPE_POINTER_TYPE (type);
+
+  if (ntype) 
+    if (typeptr == 0)          
+      return ntype;    /* Don't care about alloc, and have new type.  */
+    else if (*typeptr == 0)
+      {
+       *typeptr = ntype;       /* Tracking alloc, and we have new type.  */
+       return ntype;
+      }
+
+  if (typeptr == 0 || *typeptr == 0)   /* We'll need to allocate one.  */
+    {
+      ntype = alloc_type (TYPE_OBJFILE (type));
+      if (typeptr)
+       *typeptr = ntype;
+    }
+  else                         /* We have storage, but need to reset it.  */
+    {
+      ntype = *typeptr;
+      objfile = TYPE_OBJFILE (ntype);
+      memset ((char *)ntype, 0, sizeof (struct type));
+      TYPE_OBJFILE (ntype) = objfile;
+    }
+
+  TYPE_TARGET_TYPE (ntype) = type;
+  TYPE_POINTER_TYPE (type) = ntype;
+
+  /* FIXME!  Assume the machine has only one representation for pointers!  */
+
+  TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
+  TYPE_CODE (ntype) = TYPE_CODE_PTR;
+
+  /* pointers are unsigned */
+  TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
+  
+  if (!TYPE_POINTER_TYPE (type))       /* Remember it, if don't have one.  */
+    TYPE_POINTER_TYPE (type) = ntype;
+
+  return ntype;
+}
+
 /* Given a type TYPE, return a type of pointers to that type.
    May need to construct such a type if this is the first use.  */
 
@@ -68,73 +125,130 @@ struct type *
 lookup_pointer_type (type)
      struct type *type;
 {
-  register struct type *ptype;
-
-  if ((ptype = TYPE_POINTER_TYPE (type)) == NULL)
-    {
-      /* This is the first time anyone wanted a pointer to a TYPE.  */
-      
-      ptype  = alloc_type (TYPE_OBJFILE (type));
-      TYPE_TARGET_TYPE (ptype) = type;
-      TYPE_POINTER_TYPE (type) = ptype;
-      
-      /* We assume the machine has only one representation for pointers!  */
-      /* FIXME:  This confuses host<->target data representations, and is a
-        poor assumption besides. */
-      
-      TYPE_LENGTH (ptype) = sizeof (char *);
-      TYPE_CODE (ptype) = TYPE_CODE_PTR;
-      
-    }
-  return (ptype);
+  return make_pointer_type (type, (struct type **)0);
 }
 
+/* Lookup a C++ `reference' to a type TYPE.  TYPEPTR, if nonzero, points
+   to a pointer to memory where the reference type should be stored.
+   If *TYPEPTR is zero, update it to point to the reference type we return.
+   We allocate new memory if needed.  */
+
+struct type *
+make_reference_type (type, typeptr)
+     struct type *type;
+     struct type **typeptr;
+{
+  register struct type *ntype;         /* New type */
+  struct objfile *objfile;
+
+  ntype = TYPE_REFERENCE_TYPE (type);
+
+  if (ntype) 
+    if (typeptr == 0)          
+      return ntype;    /* Don't care about alloc, and have new type.  */
+    else if (*typeptr == 0)
+      {
+       *typeptr = ntype;       /* Tracking alloc, and we have new type.  */
+       return ntype;
+      }
+
+  if (typeptr == 0 || *typeptr == 0)   /* We'll need to allocate one.  */
+    {
+      ntype = alloc_type (TYPE_OBJFILE (type));
+      if (typeptr)
+       *typeptr = ntype;
+    }
+  else                         /* We have storage, but need to reset it.  */
+    {
+      ntype = *typeptr;
+      objfile = TYPE_OBJFILE (ntype);
+      memset ((char *)ntype, 0, sizeof (struct type));
+      TYPE_OBJFILE (ntype) = objfile;
+    }
+
+  TYPE_TARGET_TYPE (ntype) = type;
+  TYPE_REFERENCE_TYPE (type) = ntype;
+
+  /* FIXME!  Assume the machine has only one representation for references,
+     and that it matches the (only) representation for pointers!  */
+
+  TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
+  TYPE_CODE (ntype) = TYPE_CODE_REF;
+  
+  if (!TYPE_REFERENCE_TYPE (type))     /* Remember it, if don't have one.  */
+    TYPE_REFERENCE_TYPE (type) = ntype;
+
+  return ntype;
+}
+
+/* Same as above, but caller doesn't care about memory allocation details.  */
+
 struct type *
 lookup_reference_type (type)
      struct type *type;
 {
-  register struct type *rtype;
-
-  if ((rtype = TYPE_REFERENCE_TYPE (type)) == NULL)
-    {
-      /* This is the first time anyone wanted a pointer to a TYPE.  */
-      
-      rtype  = alloc_type (TYPE_OBJFILE (type));
-      TYPE_TARGET_TYPE (rtype) = type;
-      TYPE_REFERENCE_TYPE (type) = rtype;
-      
-      /* We assume the machine has only one representation for pointers!  */
-      /* FIXME:  This confuses host<->target data representations, and is a
-        poor assumption besides. */
-      
-      TYPE_LENGTH (rtype) = sizeof (char *);
-      TYPE_CODE (rtype) = TYPE_CODE_REF;
-      
-    }
-  return (rtype);
+  return make_reference_type (type, (struct type **)0);
 }
 
-/* Given a type TYPE, return a type of functions that return that type.
-   May need to construct such a type if this is the first use.  */
+/* Lookup a function type that returns type TYPE.  TYPEPTR, if nonzero, points
+   to a pointer to memory where the function type should be stored.
+   If *TYPEPTR is zero, update it to point to the function type we return.
+   We allocate new memory if needed.  */
 
 struct type *
-lookup_function_type (type)
+make_function_type (type, typeptr)
      struct type *type;
+     struct type **typeptr;
 {
-  register struct type *ptype;
+  register struct type *ntype;         /* New type */
+  struct objfile *objfile;
+
+  ntype = TYPE_FUNCTION_TYPE (type);
 
-  if ((ptype = TYPE_FUNCTION_TYPE (type)) == NULL)
+  if (ntype) 
+    if (typeptr == 0)          
+      return ntype;    /* Don't care about alloc, and have new type.  */
+    else if (*typeptr == 0)
+      {
+       *typeptr = ntype;       /* Tracking alloc, and we have new type.  */
+       return ntype;
+      }
+
+  if (typeptr == 0 || *typeptr == 0)   /* We'll need to allocate one.  */
+    {
+      ntype = alloc_type (TYPE_OBJFILE (type));
+      if (typeptr)
+       *typeptr = ntype;
+    }
+  else                         /* We have storage, but need to reset it.  */
     {
-      /* This is the first time anyone wanted a function returning a TYPE.  */
-      
-      ptype = alloc_type (TYPE_OBJFILE (type));
-      TYPE_TARGET_TYPE (ptype) = type;
-      TYPE_FUNCTION_TYPE (type) = ptype;
-      
-      TYPE_LENGTH (ptype) = 1;
-      TYPE_CODE (ptype) = TYPE_CODE_FUNC;
+      ntype = *typeptr;
+      objfile = TYPE_OBJFILE (ntype);
+      memset ((char *)ntype, 0, sizeof (struct type));
+      TYPE_OBJFILE (ntype) = objfile;
     }
-  return (ptype);
+
+  TYPE_TARGET_TYPE (ntype) = type;
+  TYPE_FUNCTION_TYPE (type) = ntype;
+
+  TYPE_LENGTH (ntype) = 1;
+  TYPE_CODE (ntype) = TYPE_CODE_FUNC;
+  
+  if (!TYPE_FUNCTION_TYPE (type))      /* Remember it, if don't have one.  */
+    TYPE_FUNCTION_TYPE (type) = ntype;
+
+  return ntype;
+}
+
+
+/* Given a type TYPE, return a type of functions that return that type.
+   May need to construct such a type if this is the first use.  */
+
+struct type *
+lookup_function_type (type)
+     struct type *type;
+{
+  return make_function_type (type, (struct type **)0);
 }
 
 /* Implement direct support for MEMBER_TYPE in GNU C++.
@@ -234,10 +348,9 @@ create_array_type (element_type, number)
    include the offset (that's the value of the MEMBER itself), but does
    include the structure type into which it points (for some reason).
 
-   FIXME:  When "smashing" the type, we preserve the objfile that the
+   When "smashing" the type, we preserve the objfile that the
    old type pointed to, since we aren't changing where the type is actually
-   allocated.  If the two types aren't associated with the same objfile,
-   then we are in deep-s**t anyway... */
+   allocated.  */
 
 void
 smash_to_member_type (type, domain, to_type)
@@ -249,7 +362,7 @@ smash_to_member_type (type, domain, to_type)
 
   objfile = TYPE_OBJFILE (type);
 
-  (void) memset (type, 0, sizeof (struct type));
+  (void) memset ((char *)type, 0, sizeof (struct type));
   TYPE_OBJFILE (type) = objfile;
   TYPE_TARGET_TYPE (type) = to_type;
   TYPE_DOMAIN_TYPE (type) = domain;
@@ -260,10 +373,9 @@ smash_to_member_type (type, domain, to_type)
 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
    METHOD just means `function that gets an extra "this" argument'.
 
-   FIXME:  When "smashing" the type, we preserve the objfile that the
+   When "smashing" the type, we preserve the objfile that the
    old type pointed to, since we aren't changing where the type is actually
-   allocated.  If the two types aren't associated with the same objfile,
-   then we are in deep-s**t anyway... */
+   allocated.  */
 
 void
 smash_to_method_type (type, domain, to_type, args)
@@ -276,7 +388,7 @@ smash_to_method_type (type, domain, to_type, args)
 
   objfile = TYPE_OBJFILE (type);
 
-  (void) memset (type, 0, sizeof (struct type));
+  (void) memset ((char *)type, 0, sizeof (struct type));
   TYPE_OBJFILE (type) = objfile;
   TYPE_TARGET_TYPE (type) = to_type;
   TYPE_DOMAIN_TYPE (type) = domain;
@@ -317,6 +429,8 @@ type_name_no_tag (type)
                name += 5;
              }
            break;
+         default:              /* To avoid -Wall warnings */
+           break;
        }
     }
   return (name);
@@ -603,7 +717,7 @@ check_stub_type (type)
                           (struct symtab **) NULL);
       if (sym)
        {
-         memcpy (type, SYMBOL_TYPE(sym), sizeof (struct type));
+         memcpy ((char *)type, (char *)SYMBOL_TYPE(sym), sizeof (struct type));
        }
     }
 }
@@ -626,7 +740,7 @@ check_stub_method (type, i, j)
 {
   struct fn_field *f;
   char *mangled_name = gdb_mangle_name (type, i, j);
-  char *demangled_name = cplus_demangle (mangled_name, 0);
+  char *demangled_name = cplus_demangle (mangled_name, DMGL_PARAMS);
   char *argtypetext, *p;
   int depth = 0, argcount = 1;
   struct type **argtypes;
@@ -789,7 +903,7 @@ lookup_fundamental_type (objfile, typeid)
          nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
          objfile -> fundamental_types = (struct type **)
            obstack_alloc (&objfile -> type_obstack, nbytes);
-         (void) memset (objfile -> fundamental_types, 0, nbytes);
+         (void) memset ((char *)objfile -> fundamental_types, 0, nbytes);
        }
       typep = objfile -> fundamental_types + typeid;
       if ((type = *typep) == NULL)
@@ -809,141 +923,151 @@ lookup_fundamental_type (objfile, typeid)
                type = init_type (TYPE_CODE_INT,
                                  TARGET_INT_BIT / TARGET_CHAR_BIT,
                                  TYPE_FLAG_UNSIGNED,
-                                 "boolean", (struct objfile *) NULL);
+                                 "boolean", objfile);
                break;
              case FT_STRING:
                type = init_type (TYPE_CODE_PASCAL_ARRAY,
                                  TARGET_CHAR_BIT / TARGET_CHAR_BIT,
                                  0,
-                                 "string", (struct objfile *) NULL);
+                                 "string", objfile);
                break;
              case FT_CHAR:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_CHAR_BIT / TARGET_CHAR_BIT,
                                  0,
-                                 "char", (struct objfile *) NULL);
+                                 "char", objfile);
                break;
              case FT_SIGNED_CHAR:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_CHAR_BIT / TARGET_CHAR_BIT,
                                  TYPE_FLAG_SIGNED,
-                                 "signed char", (struct objfile *) NULL);
+                                 "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", (struct objfile *) NULL);
+                                 "unsigned char", objfile);
                break;
              case FT_SHORT:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_SHORT_BIT / TARGET_CHAR_BIT,
                                  0,
-                                 "short", (struct objfile *) NULL);
+                                 "short", objfile);
                break;
              case FT_SIGNED_SHORT:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_SHORT_BIT / TARGET_CHAR_BIT,
                                  TYPE_FLAG_SIGNED,
-                                 "signed short", (struct objfile *) NULL);
+                                 "signed short", objfile);
                break;
              case FT_UNSIGNED_SHORT:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_SHORT_BIT / TARGET_CHAR_BIT,
                                  TYPE_FLAG_UNSIGNED,
-                                 "unsigned short", (struct objfile *) NULL);
+                                 "unsigned short", objfile);
                break;
              case FT_INTEGER:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_INT_BIT / TARGET_CHAR_BIT,
                                  0,
-                                 "int", (struct objfile *) NULL);
+                                 "int", objfile);
                break;
              case FT_SIGNED_INTEGER:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_INT_BIT / TARGET_CHAR_BIT,
                                  TYPE_FLAG_SIGNED,
-                                 "signed int", (struct objfile *) NULL);
+                                 "signed int", objfile);
                break;
              case FT_UNSIGNED_INTEGER:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_INT_BIT / TARGET_CHAR_BIT,
                                  TYPE_FLAG_UNSIGNED,
-                                 "unsigned int", (struct objfile *) NULL);
+                                 "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", (struct objfile *) NULL);
+                                 "long", objfile);
                break;
              case FT_SIGNED_LONG:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_LONG_BIT / TARGET_CHAR_BIT,
                                  TYPE_FLAG_SIGNED,
-                                 "signed long", (struct objfile *) NULL);
+                                 "signed long", objfile);
                break;
              case FT_UNSIGNED_LONG:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_LONG_BIT / TARGET_CHAR_BIT,
                                  TYPE_FLAG_UNSIGNED,
-                                 "unsigned long", (struct objfile *) NULL);
+                                 "unsigned long", objfile);
                break;
              case FT_LONG_LONG:
                type = init_type (TYPE_CODE_INT,
                                  TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
                                  0,
-                                 "long long", (struct objfile *) NULL);
+                                 "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", (struct objfile *) NULL);
+                                 "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",
-                                 (struct objfile *) NULL);
+                                 "unsigned long long", objfile);
                break;
              case FT_FLOAT:
                type = init_type (TYPE_CODE_FLT,
                                  TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
                                  0,
-                                 "float", (struct objfile *) NULL);
+                                 "float", objfile);
                break;
              case FT_DBL_PREC_FLOAT:
                type = init_type (TYPE_CODE_FLT,
                                  TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
                                  0,
-                                 "double", (struct objfile *) NULL);
+                                 "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", (struct objfile *) NULL);
+                                 "long double", objfile);
                break;
              case FT_COMPLEX:
                type = init_type (TYPE_CODE_FLT,
                                  TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
                                  0,
-                                 "complex", (struct objfile *) NULL);
+                                 "complex", objfile);
                break;
              case FT_DBL_PREC_COMPLEX:
                type = init_type (TYPE_CODE_FLT,
                                  TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
                                  0,
-                                 "double complex", (struct objfile *) NULL);
+                                 "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",
-                                 (struct objfile *) NULL);
+                                 "long double complex", objfile);
                break;
            }
          /* Install the newly created type in the objfile's fundamental_types
This page took 0.02911 seconds and 4 git commands to generate.