/* Floatformat pairs. */
+const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
+ &floatformat_ieee_half_big,
+ &floatformat_ieee_half_little
+};
const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
&floatformat_ieee_single_big,
&floatformat_ieee_single_little
address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
{
int type_flags;
+
/* Check for known address space delimiters. */
if (!strcmp (space_identifier, "code"))
return TYPE_INSTANCE_FLAG_CODE_SPACE;
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 *index_type = builtin_type (gdbarch)->builtin_int;
struct type *range_type
= create_range_type (NULL, index_type, low_bound, high_bound);
+
return create_array_type (NULL, element_type, range_type);
}
int low_bound, int high_bound)
{
struct type *result_type;
+
result_type = lookup_array_range_type (string_char_type,
low_bound, high_bound);
TYPE_CODE (result_type) = TYPE_CODE_STRING;
if (!TYPE_STUB (domain_type))
{
LONGEST low_bound, high_bound, bit_length;
+
if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
low_bound = high_bound = 0;
bit_length = high_bound - low_bound + 1;
elt_type = TYPE_TARGET_TYPE (inner_array);
if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
{
- flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_FLAG_NOTTEXT;
+ flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT;
elt_type = make_qualified_type (elt_type, flags, NULL);
TYPE_TARGET_TYPE (inner_array) = elt_type;
}
init_vector_type (struct type *elt_type, int n)
{
struct type *array_type;
+
array_type = lookup_array_range_type (elt_type, 0, n - 1);
make_vector_type (array_type);
return array_type;
struct type *
lookup_typename (const struct language_defn *language,
struct gdbarch *gdbarch, char *name,
- struct block *block, int noerr)
+ const struct block *block, int noerr)
{
struct symbol *sym;
struct type *tmp;
struct symbol *sym;
char *nam = (char *)
alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
+
strcpy (nam, name);
strcat (nam, "<");
strcat (nam, TYPE_NAME (type));
lookup_struct_elt_type (struct type *type, char *name, int noerr)
{
int i;
+ char *typename;
for (;;)
{
if (TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION)
{
- target_terminal_ours ();
- gdb_flush (gdb_stdout);
- fprintf_unfiltered (gdb_stderr, "Type ");
- type_print (type, "", gdb_stderr, -1);
- error (_(" is not a structure or union type."));
+ typename = type_to_string (type);
+ make_cleanup (xfree, typename);
+ error (_("Type %s is not a structure or union type."), typename);
}
#if 0
{
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. */
return NULL;
}
- target_terminal_ours ();
- gdb_flush (gdb_stdout);
- fprintf_unfiltered (gdb_stderr, "Type ");
- type_print (type, "", gdb_stderr, -1);
- fprintf_unfiltered (gdb_stderr, " has no component named ");
- fputs_filtered (name, gdb_stderr);
- error (("."));
- return (struct type *) -1; /* For lint */
+ typename = type_to_string (type);
+ make_cleanup (xfree, typename);
+ error (_("Type %s has no component named %s."), typename, name);
}
/* Lookup the vptr basetype/fieldno values for TYPE.
complaint (&symfile_complaints, _("stub type has NULL name"));
}
-/* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
+/* Find the real type of TYPE. This function returns the real type,
+ after removing all layers of typedefs, and completing opaque or stub
+ types. Completion changes the TYPE argument, but stripping of
+ typedefs does not.
+
+ Instance flags (e.g. const/volatile) are preserved as typedefs are
+ stripped. If necessary a new qualified form of the underlying type
+ is created.
+
+ NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
+ not been computed and we're either in the middle of reading symbols, or
+ there was no name for the typedef in the debug info.
+
+ If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
+ the target type.
If this is a stubbed struct (i.e. declared as struct foo *), see if
we can find a full definition in some other file. If so, copy this
(but not any code) that if we don't find a full definition, we'd
set a flag so we don't spend time in the future checking the same
type. That would be a mistake, though--we might load in more
- symbols which contain a full definition for the type.
-
- This used to be coded as a macro, but I don't think it is called
- often enough to merit such treatment.
-
- Find the real type of TYPE. This function returns the real type,
- after removing all layers of typedefs and completing opaque or stub
- types. Completion changes the TYPE argument, but stripping of
- typedefs does not.
-
- If TYPE is a TYPE_CODE_TYPEDEF, its length is (also) set to the length of
- the target type instead of zero. However, in the case of TYPE_CODE_TYPEDEF
- check_typedef can still return different type than the original TYPE
- pointer. */
+ symbols which contain a full definition for the type. */
struct type *
check_typedef (struct type *type)
{
struct type *orig_type = type;
- int is_const, is_volatile;
+ /* While we're removing typedefs, we don't want to lose qualifiers.
+ E.g., const/volatile. */
+ int instance_flags = TYPE_INSTANCE_FLAGS (type);
gdb_assert (type);
/* It is dangerous to call lookup_symbol if we are currently
reading a symtab. Infinite recursion is one danger. */
if (currently_reading_symtab)
- return type;
+ return make_qualified_type (type, instance_flags, NULL);
name = type_name_no_tag (type);
/* FIXME: shouldn't we separately check the TYPE_NAME and
if (name == NULL)
{
stub_noname_complaint ();
- return type;
+ return make_qualified_type (type, instance_flags, NULL);
}
sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
if (sym)
TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type));
}
type = TYPE_TARGET_TYPE (type);
- }
- is_const = TYPE_CONST (type);
- is_volatile = TYPE_VOLATILE (type);
+ /* Preserve the instance flags as we traverse down the typedef chain.
+
+ Handling address spaces/classes is nasty, what do we do if there's a
+ conflict?
+ E.g., what if an outer typedef marks the type as class_1 and an inner
+ typedef marks the type as class_2?
+ This is the wrong place to do such error checking. We leave it to
+ the code that created the typedef in the first place to flag the
+ error. We just pick the outer address space (akin to letting the
+ outer cast in a chain of casting win), instead of assuming
+ "it can't happen". */
+ {
+ const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE
+ | TYPE_INSTANCE_FLAG_DATA_SPACE);
+ const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
+ int new_instance_flags = TYPE_INSTANCE_FLAGS (type);
+
+ /* Treat code vs data spaces and address classes separately. */
+ if ((instance_flags & ALL_SPACES) != 0)
+ new_instance_flags &= ~ALL_SPACES;
+ if ((instance_flags & ALL_CLASSES) != 0)
+ new_instance_flags &= ~ALL_CLASSES;
+
+ instance_flags |= new_instance_flags;
+ }
+ }
/* If this is a struct/class/union with no fields, then check
whether a full definition exists somewhere else. This is for
{
char *name = type_name_no_tag (type);
struct type *newtype;
+
if (name == NULL)
{
stub_noname_complaint ();
- return type;
+ return make_qualified_type (type, instance_flags, NULL);
}
newtype = lookup_transparent_type (name);
move over any other types NEWTYPE refers to, which could
be an unbounded amount of stuff. */
if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
- make_cv_type (is_const, is_volatile, newtype, &type);
+ type = make_qualified_type (newtype,
+ TYPE_INSTANCE_FLAGS (type),
+ type);
else
type = newtype;
}
as appropriate? (this code was written before TYPE_NAME and
TYPE_TAG_NAME were separate). */
struct symbol *sym;
+
if (name == NULL)
{
stub_noname_complaint ();
- return type;
+ return make_qualified_type (type, instance_flags, NULL);
}
sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
if (sym)
{
/* Same as above for opaque types, we can replace the stub
- with the complete type only if they are int the same
+ with the complete type only if they are in the same
objfile. */
if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
- make_cv_type (is_const, is_volatile,
- SYMBOL_TYPE (sym), &type);
+ type = make_qualified_type (SYMBOL_TYPE (sym),
+ TYPE_INSTANCE_FLAGS (type),
+ type);
else
type = SYMBOL_TYPE (sym);
}
if (high_bound < low_bound)
len = 0;
- else {
- /* For now, we conservatively take the array length to be 0
- if its length exceeds UINT_MAX. The code below assumes
- that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
- which is technically not guaranteed by C, but is usually true
- (because it would be true if x were unsigned with its
- high-order bit on). It uses the fact that
- high_bound-low_bound is always representable in
- ULONGEST and that if high_bound-low_bound+1 overflows,
- it overflows to 0. We must change these tests if we
- decide to increase the representation of TYPE_LENGTH
- from unsigned int to ULONGEST. */
- ULONGEST ulow = low_bound, uhigh = high_bound;
- ULONGEST tlen = TYPE_LENGTH (target_type);
-
- len = tlen * (uhigh - ulow + 1);
- if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh
- || len > UINT_MAX)
- len = 0;
- }
+ else
+ {
+ /* For now, we conservatively take the array length to be 0
+ if its length exceeds UINT_MAX. The code below assumes
+ that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
+ which is technically not guaranteed by C, but is usually true
+ (because it would be true if x were unsigned with its
+ high-order bit on). It uses the fact that
+ high_bound-low_bound is always representable in
+ ULONGEST and that if high_bound-low_bound+1 overflows,
+ it overflows to 0. We must change these tests if we
+ decide to increase the representation of TYPE_LENGTH
+ from unsigned int to ULONGEST. */
+ ULONGEST ulow = low_bound, uhigh = high_bound;
+ ULONGEST tlen = TYPE_LENGTH (target_type);
+
+ len = tlen * (uhigh - ulow + 1);
+ if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh
+ || len > UINT_MAX)
+ len = 0;
+ }
TYPE_LENGTH (type) = len;
TYPE_TARGET_STUB (type) = 0;
}
TYPE_TARGET_STUB (type) = 0;
}
}
+
+ type = make_qualified_type (type, instance_flags, NULL);
+
/* Cache TYPE_LENGTH for future use. */
TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
+
return type;
}
}
}
-const struct cplus_struct_type cplus_struct_default;
+/* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
+const struct cplus_struct_type cplus_struct_default = { };
void
allocate_cplus_struct_type (struct type *type)
TYPE_VECTOR (type) = 1;
if (flags & TYPE_FLAG_STUB_SUPPORTED)
TYPE_STUB_SUPPORTED (type) = 1;
- if (flags & TYPE_FLAG_NOTTEXT)
- TYPE_NOTTEXT (type) = 1;
if (flags & TYPE_FLAG_FIXED_INSTANCE)
TYPE_FIXED_INSTANCE (type) = 1;
&& !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
- calling this function -- identical types are considered to satisfy
- the ancestor relationship even if they're identical. */
+/* Check whether BASE is an ancestor or base class of DCLASS
+ Return 1 if so, and 0 if not. If PUBLIC is 1 then only public
+ ancestors are considered, and the function returns 1 only if
+ BASE is a public ancestor of DCLASS. */
-int
-is_ancestor (struct type *base, struct type *dclass)
+static int
+do_is_ancestor (struct type *base, struct type *dclass, int public)
{
int i;
for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
{
- if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
+ if (public && ! BASETYPE_VIA_PUBLIC (dclass, i))
+ continue;
+
+ if (do_is_ancestor (base, TYPE_BASECLASS (dclass, i), public))
return 1;
}
return 0;
}
+/* Check whether BASE is an ancestor or base class or DCLASS
+ Return 1 if so, and 0 if not.
+ Note: If BASE and DCLASS are of the same type, this function
+ will return 1. So for some class A, is_ancestor (A, A) will
+ return 1. */
+
+int
+is_ancestor (struct type *base, struct type *dclass)
+{
+ return do_is_ancestor (base, dclass, 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;
+ return do_is_ancestor (base, dclass, 1);
}
/* A helper function for is_unique_ancestor. */
return 1;
}
+/* Compares type A to type B returns 1 if the represent the same type
+ 0 otherwise. */
+
+static int
+types_equal (struct type *a, struct type *b)
+{
+ /* Identical type pointers. */
+ /* However, this still doesn't catch all cases of same type for b
+ and a. The reason is that builtin types are different from
+ the same ones constructed from the object. */
+ if (a == b)
+ return 1;
+
+ /* Resolve typedefs */
+ if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF)
+ a = check_typedef (a);
+ if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF)
+ b = check_typedef (b);
+
+ /* If after resolving typedefs a and b are not of the same type
+ code then they are not equal. */
+ if (TYPE_CODE (a) != TYPE_CODE (b))
+ return 0;
+
+ /* If a and b are both pointers types or both reference types then
+ they are equal of the same type iff the objects they refer to are
+ of the same type. */
+ if (TYPE_CODE (a) == TYPE_CODE_PTR
+ || TYPE_CODE (a) == TYPE_CODE_REF)
+ return types_equal (TYPE_TARGET_TYPE (a),
+ TYPE_TARGET_TYPE (b));
+
+ /*
+ Well, damnit, if the names are exactly the same, I'll say they
+ are exactly the same. This happens when we generate method
+ stubs. The types won't point to the same address, but they
+ really are the same.
+ */
+
+ if (TYPE_NAME (a) && TYPE_NAME (b)
+ && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0)
+ return 1;
+
+ /* Check if identical after resolving typedefs. */
+ if (a == b)
+ return 1;
+
+ return 0;
+}
+
/* Compare one type (PARM) for compatibility with another (ARG).
* PARM is intended to be the parameter type of a function; and
* ARG is the supplied argument's type. This function tests if
int
rank_one_type (struct type *parm, struct type *arg)
{
- /* Identical type pointers. */
- /* However, this still doesn't catch all cases of same type for arg
- and param. The reason is that builtin types are different from
- the same ones constructed from the object. */
- if (parm == arg)
+
+ if (types_equal (parm, arg))
return 0;
/* Resolve typedefs */
if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
arg = check_typedef (arg);
- /*
- Well, damnit, if the names are exactly the same, I'll say they
- are exactly the same. This happens when we generate method
- stubs. The types won't point to the same address, but they
- really are the same.
- */
-
- if (TYPE_NAME (parm) && TYPE_NAME (arg)
- && !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
- return 0;
-
- /* Check if identical after resolving typedefs. */
- if (parm == arg)
- return 0;
-
/* See through references, since we can almost make non-references
references. */
if (TYPE_CODE (arg) == TYPE_CODE_REF)
switch (TYPE_CODE (arg))
{
case TYPE_CODE_PTR:
- if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID
- && TYPE_CODE (TYPE_TARGET_TYPE (arg)) != TYPE_CODE_VOID)
+
+ /* Allowed pointer conversions are:
+ (a) pointer to void-pointer conversion. */
+ if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
return VOID_PTR_CONVERSION_BADNESS;
- else
- return rank_one_type (TYPE_TARGET_TYPE (parm),
- TYPE_TARGET_TYPE (arg));
+
+ /* (b) pointer to ancestor-pointer conversion. */
+ if (is_ancestor (TYPE_TARGET_TYPE (parm),
+ TYPE_TARGET_TYPE (arg)))
+ return BASE_PTR_CONVERSION_BADNESS;
+
+ return INCOMPATIBLE_TYPE_BADNESS;
case TYPE_CODE_ARRAY:
- return rank_one_type (TYPE_TARGET_TYPE (parm),
- TYPE_TARGET_TYPE (arg));
+ if (types_equal (TYPE_TARGET_TYPE (parm),
+ TYPE_TARGET_TYPE (arg)))
+ return 0;
+ return INCOMPATIBLE_TYPE_BADNESS;
case TYPE_CODE_FUNC:
return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
case TYPE_CODE_INT:
case TYPE_CODE_CHAR:
case TYPE_CODE_RANGE:
case TYPE_CODE_BOOL:
- return POINTER_CONVERSION_BADNESS;
default:
return INCOMPATIBLE_TYPE_BADNESS;
}
case TYPE_CODE_RANGE:
case TYPE_CODE_ENUM:
case TYPE_CODE_FLT:
+ return INCOMPATIBLE_TYPE_BADNESS;
case TYPE_CODE_PTR:
- return BOOLEAN_CONVERSION_BADNESS;
+ return BOOL_PTR_CONVERSION_BADNESS;
case TYPE_CODE_BOOL:
return 0;
default:
to the address of the enclosing struct. It would be nice to
have a dedicated flag that would be set for static fields when
the type is being created. But in practice, checking the field
- loc_kind should give us an accurate answer (at least as long as
- we assume that DWARF block locations are not going to be used
- for static fields). FIXME? */
+ loc_kind should give us an accurate answer. */
return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
|| FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
}
type_pair_hash (const void *item)
{
const struct type_pair *pair = item;
+
return htab_hash_pointer (pair->old);
}
type_pair_eq (const void *item_lhs, const void *item_rhs)
{
const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
+
return lhs->old == rhs->old;
}
char *name, struct type *target_type)
{
struct type *t;
+
t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
2 * TYPE_LENGTH (target_type), name);
TYPE_TARGET_TYPE (t) = target_type;
arch_composite_type (struct gdbarch *gdbarch, char *name, enum type_code code)
{
struct type *t;
+
gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
t = arch_type (gdbarch, code, 0, NULL);
TYPE_TAG_NAME (t) = name;
}
/* 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;
TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
sizeof (struct field) * TYPE_NFIELDS (t));
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))
if (alignment)
{
int left = FIELD_BITPOS (f[0]) % (alignment * TARGET_CHAR_BIT);
+
if (left)
{
FIELD_BITPOS (f[0]) += left;
= arch_integer_type (gdbarch, 128, 0, "int128_t");
builtin_type->builtin_uint128
= arch_integer_type (gdbarch, 128, 1, "uint128_t");
- TYPE_NOTTEXT (builtin_type->builtin_int8) = 1;
- TYPE_NOTTEXT (builtin_type->builtin_uint8) = 1;
+ TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |=
+ TYPE_INSTANCE_FLAG_NOTTEXT;
+ TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |=
+ TYPE_INSTANCE_FLAG_NOTTEXT;
+
+ /* 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