+2021-01-22 Simon Marchi <simon.marchi@efficios.com>
+
+ * gdbtypes.h (TYPE_OBJFILE_OWNED): Adjust.
+ (TYPE_OWNER): Remove.
+ (TYPE_OBJFILE): Adjust.
+ (struct main_type) <flag_objfile_owned>: Rename to...
+ <m_flag_objfile_owned>: ... this.
+ <owner>: Rename to...
+ <m_owner>: ... this.
+ (struct type) <is_objfile_owned, set_owner, objfile, arch>: New
+ methods.
+ (TYPE_ALLOC): Adjust.
+ * gdbtypes.c (alloc_type): Adjust.
+ (alloc_type_arch): Adjust.
+ (alloc_type_copy): Adjust.
+ (get_type_arch): Adjust.
+ (smash_type): Adjust.
+ (lookup_array_range_type): Adjust.
+ (recursive_dump_type): Adjust.
+ (copy_type_recursive): Adjust.
+ * compile/compile-c-types.c (convert_func): Adjust.
+ (convert_type_basic): Adjust.
+ * compile/compile-cplus-types.c (compile_cplus_convert_func):
+ Adjust.
+ * language.c
+ (language_arch_info::type_and_symbol::alloc_type_symbol):
+ Adjust.
+
2021-01-21 Luis Machado <luis.machado@linaro.org>
* coffread.c (enter_linenos): Passing string to complaint.
if (target_type == NULL)
{
if (TYPE_OBJFILE_OWNED (type))
- target_type = objfile_type (TYPE_OWNER (type).objfile)->builtin_int;
+ target_type = objfile_type (type->objfile ())->builtin_int;
else
- target_type = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int;
+ target_type = builtin_type (type->arch ())->builtin_int;
warning (_("function has unknown return type; assuming int"));
}
built-in parser used to do, but at least warn. */
struct type *fallback;
if (TYPE_OBJFILE_OWNED (type))
- fallback = objfile_type (TYPE_OWNER (type).objfile)->builtin_int;
+ fallback = objfile_type (type->objfile ())->builtin_int;
else
- fallback = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int;
+ fallback = builtin_type (type->arch ())->builtin_int;
warning (_("variable has unknown type; assuming int"));
return convert_int (context, fallback);
}
if (target_type == nullptr)
{
if (TYPE_OBJFILE_OWNED (type))
- target_type = objfile_type (TYPE_OWNER (type).objfile)->builtin_int;
+ target_type = objfile_type (type->objfile ())->builtin_int;
else
- target_type = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int;
+ target_type = builtin_type (type->arch ())->builtin_int;
warning (_("function has unknown return type; assuming int"));
}
struct main_type);
OBJSTAT (objfile, n_types++);
- TYPE_OBJFILE_OWNED (type) = 1;
- TYPE_OWNER (type).objfile = objfile;
+ type->set_owner (objfile);
/* Initialize the fields that might not be zero. */
type = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct type);
TYPE_MAIN_TYPE (type) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct main_type);
- TYPE_OBJFILE_OWNED (type) = 0;
- TYPE_OWNER (type).gdbarch = gdbarch;
+ type->set_owner (gdbarch);
/* Initialize the fields that might not be zero. */
alloc_type_copy (const struct type *type)
{
if (TYPE_OBJFILE_OWNED (type))
- return alloc_type (TYPE_OWNER (type).objfile);
+ return alloc_type (type->objfile ());
else
- return alloc_type_arch (TYPE_OWNER (type).gdbarch);
+ return alloc_type_arch (type->arch ());
}
/* If TYPE is gdbarch-associated, return that architecture.
struct gdbarch *arch;
if (TYPE_OBJFILE_OWNED (type))
- arch = TYPE_OWNER (type).objfile->arch ();
+ arch = type->objfile ()->arch ();
else
- arch = TYPE_OWNER (type).gdbarch;
+ arch = type->arch ();
/* The ARCH can be NULL if TYPE is associated with neither an objfile nor
a gdbarch, however, this is very rare, and even then, in most cases
static void
smash_type (struct type *type)
{
- int objfile_owned = TYPE_OBJFILE_OWNED (type);
- union type_owner owner = TYPE_OWNER (type);
+ bool objfile_owned = type->is_objfile_owned ();
+ objfile *objfile = type->objfile ();
+ gdbarch *arch = type->arch ();
memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
/* Restore owner information. */
- TYPE_OBJFILE_OWNED (type) = objfile_owned;
- TYPE_OWNER (type) = owner;
+ if (objfile_owned)
+ type->set_owner (objfile);
+ else
+ type->set_owner (arch);
/* For now, delete the rings. */
TYPE_CHAIN (type) = type;
struct type *range_type;
if (TYPE_OBJFILE_OWNED (element_type))
- index_type = objfile_type (TYPE_OWNER (element_type).objfile)->builtin_int;
+ index_type = objfile_type (element_type->objfile ())->builtin_int;
else
- index_type = builtin_type (get_type_arch (element_type))->builtin_int;
+ index_type = builtin_type (element_type->arch ())->builtin_int;
+
range_type = create_static_range_type (NULL, index_type,
low_bound, high_bound);
if (TYPE_OBJFILE_OWNED (type))
{
printf_filtered ("%*sobjfile ", spaces, "");
- gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout);
+ gdb_print_host_address (type->objfile (), gdb_stdout);
}
else
{
printf_filtered ("%*sgdbarch ", spaces, "");
- gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout);
+ gdb_print_host_address (type->arch (), gdb_stdout);
}
printf_filtered ("\n");
printf_filtered ("%*starget_type ", spaces, "");
/* Copy the common fields of types. For the main type, we simply
copy the entire thing and then update specific fields as needed. */
*TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
- TYPE_OBJFILE_OWNED (new_type) = 0;
- TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
+
+ new_type->set_owner (type->arch ());
if (type->name ())
new_type->set_name (xstrdup (type->name ()));
the objfile retrieved as TYPE_OBJFILE. Otherwise, the type is
owned by an architecture; TYPE_OBJFILE is NULL in this case. */
-#define TYPE_OBJFILE_OWNED(t) (TYPE_MAIN_TYPE (t)->flag_objfile_owned)
-#define TYPE_OWNER(t) TYPE_MAIN_TYPE(t)->owner
-#define TYPE_OBJFILE(t) (TYPE_OBJFILE_OWNED(t)? TYPE_OWNER(t).objfile : NULL)
+#define TYPE_OBJFILE_OWNED(t) ((t)->is_objfile_owned ())
+#define TYPE_OBJFILE(t) ((t)->objfile ())
/* * True if this type was declared using the "class" keyword. This is
only valid for C++ structure and enum types. If false, a structure
unsigned int m_flag_stub_supported : 1;
unsigned int m_flag_gnu_ifunc : 1;
unsigned int m_flag_fixed_instance : 1;
- unsigned int flag_objfile_owned : 1;
+ unsigned int m_flag_objfile_owned : 1;
unsigned int m_flag_endianity_not_default : 1;
/* * True if this type was declared with "class" rather than
this is somewhat ugly, but without major overhaul of the internal
type system, it can't be avoided for now. */
- union type_owner owner;
+ union type_owner m_owner;
/* * For a pointer type, describes the type of object pointed to.
- For an array type, describes the type of the elements.
/* * Remove dynamic property of kind KIND from this type, if it exists. */
void remove_dyn_prop (dynamic_prop_node_kind kind);
+ /* Return true if this type is owned by an objfile. Return false if it is
+ owned by an architecture. */
+ bool is_objfile_owned () const
+ {
+ return this->main_type->m_flag_objfile_owned;
+ }
+
+ /* Set the owner of the type to be OBJFILE. */
+ void set_owner (objfile *objfile)
+ {
+ this->main_type->m_owner.objfile = objfile;
+ this->main_type->m_flag_objfile_owned = true;
+ }
+
+ /* Set the owner of the type to be ARCH. */
+ void set_owner (gdbarch *arch)
+ {
+ this->main_type->m_owner.gdbarch = arch;
+ this->main_type->m_flag_objfile_owned = false;
+ }
+
+ /* Return the objfile owner of this type.
+
+ Return nullptr if this type is not objfile-owned. */
+ struct objfile *objfile () const
+ {
+ if (!this->is_objfile_owned ())
+ return nullptr;
+
+ return this->main_type->m_owner.objfile;
+ }
+
+ /* Return the gdbarch owner of this type.
+
+ Return nullptr if this type is not gdbarch-owned. */
+ gdbarch *arch () const
+ {
+ if (this->is_objfile_owned ())
+ return nullptr;
+
+ return this->main_type->m_owner.gdbarch;
+ }
+
/* * Return true if this is an integer type whose logical (bit) size
differs from its storage size; false otherwise. Always return
false for non-integer (i.e., non-TYPE_SPECIFIC_INT) types. */
#define TYPE_ALLOC(t,size) \
(obstack_alloc ((TYPE_OBJFILE_OWNED (t) \
- ? &TYPE_OBJFILE (t)->objfile_obstack \
- : gdbarch_obstack (TYPE_OWNER (t).gdbarch)), \
+ ? &((t)->objfile ()->objfile_obstack) \
+ : gdbarch_obstack ((t)->arch ())), \
size))
struct symbol *symbol;
struct gdbarch *gdbarch;
gdb_assert (!TYPE_OBJFILE_OWNED (type));
- gdbarch = TYPE_OWNER (type).gdbarch;
+ gdbarch = type->arch ();
symbol = new (gdbarch_obstack (gdbarch)) struct symbol ();
symbol->m_name = type->name ();
symbol->set_language (lang, nullptr);