#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
type = (struct type *) obstack_alloc (&objfile -> type_obstack,
sizeof (struct type));
}
- (void) memset ((char *)type, 0, sizeof (struct type));
+ memset ((char *)type, 0, sizeof (struct type));
/* Initialize the fields that might not be zero. */
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. */
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;
-
- /* FIXME, assume machine has only one representation for pointers! */
-
- TYPE_LENGTH (ptype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
- TYPE_CODE (ptype) = TYPE_CODE_PTR;
-
- /* pointers are unsigned */
- TYPE_FLAGS(ptype) |= TYPE_FLAG_UNSIGNED;
-
- }
- 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;
- if ((ptype = TYPE_FUNCTION_TYPE (type)) == NULL)
+ ntype = TYPE_FUNCTION_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. */
{
- /* 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 = alloc_type (TYPE_OBJFILE (type));
+ if (typeptr)
+ *typeptr = ntype;
}
- return (ptype);
+ 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_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++.
objfile = TYPE_OBJFILE (type);
- (void) 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;
objfile = TYPE_OBJFILE (type);
- (void) 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;
name += 5;
}
break;
+ default: /* To avoid -Wall warnings */
+ break;
}
}
return (name);
{
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;
}
}
-/* Helper function to initialize the standard scalar types. */
+/* Helper function to initialize the standard scalar types.
+
+ If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
+ of the string pointed to by name in the type_obstack for that objfile,
+ and initialize the type name to that copy. There are places (mipsread.c
+ in particular, where init_type is called with a NULL value for NAME). */
struct type *
init_type (code, length, flags, name, objfile)
TYPE_CODE (type) = code;
TYPE_LENGTH (type) = length;
TYPE_FLAGS (type) |= flags;
- TYPE_NAME (type) = name;
+ if ((name != NULL) && (objfile != NULL))
+ {
+ TYPE_NAME (type) =
+ obsavestring (name, strlen (name), &objfile -> type_obstack);
+ }
+ else
+ {
+ TYPE_NAME (type) = name;
+ }
/* C++ fancies. */
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. */
+ 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 */
struct type *
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 ((char *)objfile -> fundamental_types, 0, nbytes);
+ memset ((char *)objfile -> fundamental_types, 0, nbytes);
}
typep = objfile -> fundamental_types + typeid;
if ((type = *typep) == NULL)
type = init_type (TYPE_CODE_INT,
TARGET_SHORT_BIT / TARGET_CHAR_BIT,
TYPE_FLAG_SIGNED,
- "signed short", objfile);
+ "short", objfile); /* FIXME -fnf */
break;
case FT_UNSIGNED_SHORT:
type = init_type (TYPE_CODE_INT,
type = init_type (TYPE_CODE_INT,
TARGET_INT_BIT / TARGET_CHAR_BIT,
TYPE_FLAG_SIGNED,
- "signed int", objfile);
+ "int", objfile); /* FIXME -fnf */
break;
case FT_UNSIGNED_INTEGER:
type = init_type (TYPE_CODE_INT,
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,
type = init_type (TYPE_CODE_INT,
TARGET_LONG_BIT / TARGET_CHAR_BIT,
TYPE_FLAG_SIGNED,
- "signed long", objfile);
+ "long", objfile); /* FIXME -fnf */
break;
case FT_UNSIGNED_LONG:
type = init_type (TYPE_CODE_INT,
type = init_type (TYPE_CODE_INT,
TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
TYPE_FLAG_UNSIGNED,
- "unsigned long long",
- objfile);
+ "unsigned long long", objfile);
break;
case FT_FLOAT:
type = init_type (TYPE_CODE_FLT,
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,
type = init_type (TYPE_CODE_FLT,
TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
0,
- "long double complex",
- objfile);
+ "long double complex", objfile);
break;
}
/* Install the newly created type in the objfile's fundamental_types