if (objfile == NULL)
{
- type = xmalloc (sizeof (struct type));
- memset (type, 0, sizeof (struct type));
- TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
+ type = XZALLOC (struct type);
+ TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
}
else
{
- type = obstack_alloc (&objfile->objfile_obstack,
- sizeof (struct type));
- memset (type, 0, sizeof (struct type));
- TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
- sizeof (struct main_type));
+ type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
+ TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
+ struct main_type);
OBJSTAT (objfile, n_types++);
}
- memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
/* Initialize the fields that might not be zero. */
TYPE_VPTR_FIELDNO (type) = -1;
TYPE_CHAIN (type) = type; /* Chain back to itself. */
- return (type);
+ return type;
}
/* Alloc a new type instance structure, fill it with some defaults,
/* Allocate the structure. */
if (TYPE_OBJFILE (oldtype) == NULL)
- {
- type = xmalloc (sizeof (struct type));
- memset (type, 0, sizeof (struct type));
- }
+ type = XZALLOC (struct type);
else
- {
- type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
- sizeof (struct type));
- memset (type, 0, sizeof (struct type));
- }
+ type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
+ struct type);
+
TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
- return (type);
+ return type;
}
/* Clear all remnants of the previous type at TYPE, in preparation for
/* 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. */
+ function type we return. We allocate new memory from OBJFILE if needed; use
+ NULL for permanent types. */
struct type *
-make_function_type (struct type *type, struct type **typeptr)
+make_function_type (struct type *type, struct type **typeptr,
+ struct objfile *objfile)
{
struct type *ntype; /* New type */
- struct objfile *objfile;
if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
{
- ntype = alloc_type (TYPE_OBJFILE (type));
+ ntype = alloc_type (objfile);
if (typeptr)
*typeptr = ntype;
}
else /* We have storage, but need to reset it. */
{
ntype = *typeptr;
- objfile = TYPE_OBJFILE (ntype);
smash_type (ntype);
TYPE_OBJFILE (ntype) = objfile;
}
struct type *
lookup_function_type (struct type *type)
{
- return make_function_type (type, (struct type **) 0);
+ return make_function_type (type, (struct type **) 0, TYPE_OBJFILE (type));
}
/* Identify address space identifier by name --
mtype = alloc_type (TYPE_OBJFILE (type));
smash_to_memberptr_type (mtype, domain, type);
- return (mtype);
+ return mtype;
}
/* Return a pointer-to-method type, for a method of type TO_TYPE. */
TYPE_OBJFILE (type));
TYPE_TARGET_TYPE (mtype) = type;
/* _DOMAIN_TYPE (mtype) = unknown yet */
- return (mtype);
+ return mtype;
}
/* Create a range type using either a blank type supplied in
int low_bound, int high_bound)
{
if (result_type == NULL)
- {
- result_type = alloc_type (TYPE_OBJFILE (index_type));
- }
+ result_type = alloc_type (TYPE_OBJFILE (index_type));
TYPE_CODE (result_type) = TYPE_CODE_RANGE;
TYPE_TARGET_TYPE (result_type) = index_type;
if (TYPE_STUB (index_type))
else
TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
TYPE_NFIELDS (result_type) = 2;
- TYPE_FIELDS (result_type) = TYPE_ALLOC (result_type,
- TYPE_NFIELDS (result_type)
- * sizeof (struct field));
- memset (TYPE_FIELDS (result_type), 0,
- TYPE_NFIELDS (result_type) * sizeof (struct field));
+ TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
+ TYPE_NFIELDS (result_type)
+ * sizeof (struct field));
TYPE_LOW_BOUND (result_type) = low_bound;
TYPE_HIGH_BOUND (result_type) = high_bound;
TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
TYPE_NFIELDS (result_type) = 1;
TYPE_FIELDS (result_type) =
- (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
- memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
+ (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
TYPE_INDEX_TYPE (result_type) = range_type;
TYPE_VPTR_FIELDNO (result_type) = -1;
if (TYPE_LENGTH (result_type) == 0)
TYPE_TARGET_STUB (result_type) = 1;
- return (result_type);
+ return result_type;
}
/* Create a string type using either a blank type supplied in
string_char_type,
range_type);
TYPE_CODE (result_type) = TYPE_CODE_STRING;
- return (result_type);
+ return result_type;
}
struct type *
}
TYPE_CODE (result_type) = TYPE_CODE_SET;
TYPE_NFIELDS (result_type) = 1;
- TYPE_FIELDS (result_type) = (struct field *)
- TYPE_ALLOC (result_type, 1 * sizeof (struct field));
- memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
+ TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
if (!TYPE_STUB (domain_type))
{
}
TYPE_FIELD_TYPE (result_type, 0) = domain_type;
- return (result_type);
+ return result_type;
}
void
type = init_type (TYPE_CODE_FLAGS, length,
TYPE_FLAG_UNSIGNED, name, NULL);
TYPE_NFIELDS (type) = nfields;
- TYPE_FIELDS (type) = TYPE_ALLOC (type,
- nfields * sizeof (struct field));
- memset (TYPE_FIELDS (type), 0, nfields * sizeof (struct field));
+ TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
return type;
}
name);
if (tmp)
{
- return (tmp);
+ return tmp;
}
else if (!tmp && noerr)
{
- return (NULL);
+ return NULL;
}
else
{
t = SYMBOL_TYPE (sym);
if (TYPE_CODE (t) == TYPE_CODE_UNION)
- return (t);
+ return t;
/* C++ unions may come out with TYPE_CODE_CLASS, but we look at
* a further "declared_type" field to discover it is really a union.
*/
if (HAVE_CPLUS_STRUCT (t))
if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
- return (t);
+ return t;
/* If we get here, it's not a union. */
error (_("This context has class, struct or enum %s, not a union."),
{
INIT_CPLUS_SPECIFIC (type);
}
- return (type);
+ return type;
}
/* Helper function. Create an empty composite type. */
/* Helper function. Append a field to a composite type. */
void
-append_composite_type_field (struct type *t, char *name,
- struct type *field)
+append_composite_type_field_aligned (struct type *t, char *name,
+ struct type *field, int alignment)
{
struct field *f;
TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
{
TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
if (TYPE_NFIELDS (t) > 1)
- FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
- + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
- * TARGET_CHAR_BIT));
+ {
+ FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
+ + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
+ * TARGET_CHAR_BIT));
+
+ if (alignment)
+ {
+ int left = FIELD_BITPOS (f[0]) % (alignment * TARGET_CHAR_BIT);
+ if (left)
+ {
+ FIELD_BITPOS (f[0]) += left;
+ TYPE_LENGTH (t) += left / TARGET_CHAR_BIT;
+ }
+ }
+ }
}
}
+void
+append_composite_type_field (struct type *t, char *name,
+ struct type *field)
+{
+ append_composite_type_field_aligned (t, name, field, 0);
+}
+
int
can_dereference (struct type *t)
{
int i, nfields;
nfields = TYPE_NFIELDS (type);
- TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
- memset (TYPE_FIELDS (new_type), 0, sizeof (struct field) * nfields);
+ TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
for (i = 0; i < nfields; i++)
{
TYPE_FIELD_ARTIFICIAL (new_type, i) =