struct type *
make_type_with_address_space (struct type *type, int space_flag)
{
- struct type *ntype;
int new_flags = ((TYPE_INSTANCE_FLAGS (type)
& ~(TYPE_INSTANCE_FLAG_CODE_SPACE
| TYPE_INSTANCE_FLAG_DATA_SPACE
struct type **typeptr)
{
struct type *ntype; /* New type */
- struct type *tmp_type = type; /* tmp type */
- struct objfile *objfile;
int new_flags = (TYPE_INSTANCE_FLAGS (type)
- & ~(TYPE_INSTANCE_FLAG_CONST | TYPE_INSTANCE_FLAG_VOLATILE));
+ & ~(TYPE_INSTANCE_FLAG_CONST
+ | TYPE_INSTANCE_FLAG_VOLATILE));
if (cnst)
new_flags |= TYPE_INSTANCE_FLAG_CONST;
struct type *mtype;
mtype = alloc_type_copy (to_type);
- TYPE_TARGET_TYPE (mtype) = to_type;
- TYPE_DOMAIN_TYPE (mtype) = TYPE_DOMAIN_TYPE (to_type);
- TYPE_LENGTH (mtype) = cplus_method_ptr_size (to_type);
- TYPE_CODE (mtype) = TYPE_CODE_METHODPTR;
+ smash_to_methodptr_type (mtype, to_type);
return mtype;
}
TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
}
+/* Smash TYPE to be a type of pointer to methods type TO_TYPE.
+
+ 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. */
+
+void
+smash_to_methodptr_type (struct type *type, struct type *to_type)
+{
+ smash_type (type);
+ TYPE_TARGET_TYPE (type) = to_type;
+ TYPE_DOMAIN_TYPE (type) = TYPE_DOMAIN_TYPE (to_type);
+ TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
+ TYPE_CODE (type) = TYPE_CODE_METHODPTR;
+}
+
/* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
METHOD just means `function that gets an extra "this" argument'.
if (TYPE_CODE (t) == TYPE_CODE_UNION)
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;
-
/* If we get here, it's not a union. */
error (_("This context has class, struct or enum %s, not a union."),
name);
{
return TYPE_FIELD_TYPE (type, i);
}
+ else if (!t_field_name || *t_field_name == '\0')
+ {
+ struct type *subtype = lookup_struct_elt_type (
+ TYPE_FIELD_TYPE (type, i), name, 1);
+ if (subtype != NULL)
+ return subtype;
+ }
}
/* OK, it's not in this class. Recursively check the baseclasses. */
|| (TYPE_CODE (t) == TYPE_CODE_BOOL)));
}
+/* A helper function which returns true if types A and B represent the
+ "same" class type. This is true if the types have the same main
+ type, or the same name. */
+
+int
+class_types_same_p (const struct type *a, const struct type *b)
+{
+ return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b)
+ || (TYPE_NAME (a) && TYPE_NAME (b)
+ && !strcmp (TYPE_NAME (a), TYPE_NAME (b))));
+}
+
/* Check whether BASE is an ancestor or base class or DCLASS
Return 1 if so, and 0 if not.
Note: callers may want to check for identity of the types before
CHECK_TYPEDEF (base);
CHECK_TYPEDEF (dclass);
- if (base == dclass)
- return 1;
- if (TYPE_NAME (base) && TYPE_NAME (dclass)
- && !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
+ if (class_types_same_p (base, dclass))
return 1;
for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
- if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
- return 1;
+ {
+ if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
+ return 1;
+ }
return 0;
}
+
+/* Like is_ancestor, but only returns true when BASE is a public
+ ancestor of DCLASS. */
+
+int
+is_public_ancestor (struct type *base, struct type *dclass)
+{
+ int i;
+
+ CHECK_TYPEDEF (base);
+ CHECK_TYPEDEF (dclass);
+
+ if (class_types_same_p (base, dclass))
+ return 1;
+
+ for (i = 0; i < TYPE_N_BASECLASSES (dclass); ++i)
+ {
+ if (! BASETYPE_VIA_PUBLIC (dclass, i))
+ continue;
+ if (is_public_ancestor (base, TYPE_BASECLASS (dclass, i)))
+ return 1;
+ }
+
+ return 0;
+}
+
+/* A helper function for is_unique_ancestor. */
+
+static int
+is_unique_ancestor_worker (struct type *base, struct type *dclass,
+ int *offset,
+ const bfd_byte *contents, CORE_ADDR address)
+{
+ int i, count = 0;
+
+ CHECK_TYPEDEF (base);
+ CHECK_TYPEDEF (dclass);
+
+ for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
+ {
+ struct type *iter = check_typedef (TYPE_BASECLASS (dclass, i));
+ int this_offset = baseclass_offset (dclass, i, contents, address);
+
+ if (this_offset == -1)
+ error (_("virtual baseclass botch"));
+
+ if (class_types_same_p (base, iter))
+ {
+ /* If this is the first subclass, set *OFFSET and set count
+ to 1. Otherwise, if this is at the same offset as
+ previous instances, do nothing. Otherwise, increment
+ count. */
+ if (*offset == -1)
+ {
+ *offset = this_offset;
+ count = 1;
+ }
+ else if (this_offset == *offset)
+ {
+ /* Nothing. */
+ }
+ else
+ ++count;
+ }
+ else
+ count += is_unique_ancestor_worker (base, iter, offset,
+ contents + this_offset,
+ address + this_offset);
+ }
+
+ return count;
+}
+
+/* Like is_ancestor, but only returns true if BASE is a unique base
+ class of the type of VAL. */
+
+int
+is_unique_ancestor (struct type *base, struct value *val)
+{
+ int offset = -1;
+
+ return is_unique_ancestor_worker (base, value_type (val), &offset,
+ value_contents (val),
+ value_address (val)) == 1;
+}
+
\f
case TYPE_CODE_TYPEDEF:
printf_filtered ("(TYPE_CODE_TYPEDEF)");
break;
- case TYPE_CODE_TEMPLATE:
- printf_filtered ("(TYPE_CODE_TEMPLATE)");
- break;
- case TYPE_CODE_TEMPLATE_ARG:
- printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
- break;
case TYPE_CODE_NAMESPACE:
printf_filtered ("(TYPE_CODE_NAMESPACE)");
break;
TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION
- || TYPE_CODE (type) == TYPE_CODE_TEMPLATE
|| TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
INIT_CPLUS_SPECIFIC (new_type);
}
/* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
- NAME is the type name. LENGTH is the number of flag bits. */
+ NAME is the type name. LENGTH is the size of the flag word in bytes. */
struct type *
arch_flags_type (struct gdbarch *gdbarch, char *name, int length)
{
}
/* Add new field with name NAME and type FIELD to composite type T.
- ALIGNMENT (if non-zero) specifies the minimum field alignment. */
-void
-append_composite_type_field_aligned (struct type *t, char *name,
- struct type *field, int alignment)
+ Do not set the field's position or adjust the type's length;
+ the caller should do so. Return the new field. */
+struct field *
+append_composite_type_field_raw (struct type *t, char *name,
+ struct type *field)
{
struct field *f;
TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
memset (f, 0, sizeof f[0]);
FIELD_TYPE (f[0]) = field;
FIELD_NAME (f[0]) = name;
+ return f;
+}
+
+/* Add new field with name NAME and type FIELD to composite type T.
+ ALIGNMENT (if non-zero) specifies the minimum field alignment. */
+void
+append_composite_type_field_aligned (struct type *t, char *name,
+ struct type *field, int alignment)
+{
+ struct field *f = append_composite_type_field_raw (t, name, field);
if (TYPE_CODE (t) == TYPE_CODE_UNION)
{
if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
TYPE_NOTTEXT (builtin_type->builtin_int8) = 1;
TYPE_NOTTEXT (builtin_type->builtin_uint8) = 1;
+ /* Wide character types. */
+ builtin_type->builtin_char16
+ = arch_integer_type (gdbarch, 16, 0, "char16_t");
+ builtin_type->builtin_char32
+ = arch_integer_type (gdbarch, 32, 0, "char32_t");
+
+
/* Default data/code pointer types. */
builtin_type->builtin_data_ptr
= lookup_pointer_type (builtin_type->builtin_void);