[04/20] Remove alloc_type

Message ID 20230313-split-objfile-type-allocator-2-v1-4-69ba773ac17b@tromey.com
State New
Headers
Series Remove objfile_type |

Commit Message

Tom Tromey March 13, 2023, 10:08 p.m. UTC
  This removes alloc_type, replacing all uses with the new type
allocator.
---
 gdb/coffread.c    |  2 +-
 gdb/ctfread.c     |  8 ++++----
 gdb/dwarf2/read.c | 15 ++++++++-------
 gdb/gdbtypes.c    | 29 +----------------------------
 gdb/gdbtypes.h    |  3 ---
 gdb/mdebugread.c  |  2 +-
 gdb/stabsread.c   |  4 ++--
 7 files changed, 17 insertions(+), 46 deletions(-)
  

Patch

diff --git a/gdb/coffread.c b/gdb/coffread.c
index 4da3799243b..6b2ba96c997 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -354,7 +354,7 @@  coff_alloc_type (int index)
      We will fill it in later if we find out how.  */
   if (type == NULL)
     {
-      type = alloc_type (coffread_objfile);
+      type = type_allocator (coffread_objfile).new_type ();
       *type_addr = type;
     }
   return type;
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 69906c9cb2e..94597af58a9 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -629,7 +629,7 @@  read_structure_type (struct ctf_context *ccp, ctf_id_t tid)
   struct type *type;
   uint32_t kind;
 
-  type = alloc_type (of);
+  type = type_allocator (of).new_type ();
 
   const char *name = ctf_type_name_raw (fp, tid);
   if (name != nullptr && strlen (name) != 0)
@@ -688,7 +688,7 @@  read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid)
   ctf_funcinfo_t cfi;
   uint32_t argc;
 
-  type = alloc_type (of);
+  type = type_allocator (of).new_type ();
 
   type->set_code (TYPE_CODE_FUNC);
   if (ctf_func_type_info (fp, tid, &cfi) < 0)
@@ -740,7 +740,7 @@  read_enum_type (struct ctf_context *ccp, ctf_id_t tid)
   ctf_dict_t *fp = ccp->fp;
   struct type *type;
 
-  type = alloc_type (of);
+  type = type_allocator (of).new_type ();
 
   const char *name = ctf_type_name_raw (fp, tid);
   if (name != nullptr && strlen (name) != 0)
@@ -976,7 +976,7 @@  read_forward_type (struct ctf_context *ccp, ctf_id_t tid)
   struct type *type;
   uint32_t kind;
 
-  type = alloc_type (of);
+  type = type_allocator (of).new_type ();
 
   const char *name = ctf_type_name_raw (fp, tid);
   if (name != nullptr && strlen (name) != 0)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7ff090225e0..450bf73a886 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12147,7 +12147,7 @@  dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
       fnp->physname = physname ? physname : "";
     }
 
-  fnp->type = alloc_type (objfile);
+  fnp->type = type_allocator (objfile).new_type ();
   this_type = read_type_die (die, cu);
   if (this_type && this_type->code () == TYPE_CODE_FUNC)
     {
@@ -12369,7 +12369,7 @@  quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
     return;
 
   self_type = pfn_type->field (0).type ()->target_type ();
-  new_type = alloc_type (objfile);
+  new_type = type_allocator (objfile).new_type ();
   smash_to_method_type (new_type, self_type, pfn_type->target_type (),
 			pfn_type->fields (), pfn_type->num_fields (),
 			pfn_type->has_varargs ());
@@ -12608,7 +12608,7 @@  read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
       return set_die_type (die, type, cu);
     }
 
-  type = alloc_type (objfile);
+  type = type_allocator (objfile).new_type ();
   INIT_CPLUS_SPECIFIC (type);
 
   name = dwarf2_name (die, cu);
@@ -13215,7 +13215,7 @@  read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
       return set_die_type (die, type, cu);
     }
 
-  type = alloc_type (objfile);
+  type = type_allocator (objfile).new_type ();
 
   type->set_code (TYPE_CODE_ENUM);
   name = dwarf2_full_name (NULL, die, cu);
@@ -13545,7 +13545,7 @@  quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
       range_fields[i + 1].set_name (objfile->intern (name));
     }
 
-  struct type *bounds = alloc_type (objfile);
+  struct type *bounds = type_allocator (objfile).new_type ();
   bounds->set_code (TYPE_CODE_STRUCT);
 
   bounds->set_num_fields (range_fields.size ());
@@ -13573,7 +13573,7 @@  quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
       iter = iter->target_type ();
     }
 
-  struct type *result = alloc_type (objfile);
+  struct type *result = type_allocator (objfile).new_type ();
   result->set_code (TYPE_CODE_STRUCT);
 
   result->set_num_fields (2);
@@ -14255,7 +14255,8 @@  read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
     type = lookup_methodptr_type (to_type);
   else if (check_typedef (to_type)->code () == TYPE_CODE_FUNC)
     {
-      struct type *new_type = alloc_type (cu->per_objfile->objfile);
+      struct type *new_type
+	= type_allocator (cu->per_objfile->objfile).new_type ();
 
       smash_to_method_type (new_type, domain, to_type->target_type (),
 			    to_type->fields (), to_type->num_fields (),
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 6ad6aadb468..3d1d9239758 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -231,33 +231,6 @@  type_allocator::new_type ()
   return type;
 }
 
-/* Allocate a new OBJFILE-associated type structure and fill it
-   with some defaults.  Space for the type structure is allocated
-   on the objfile's objfile_obstack.  */
-
-struct type *
-alloc_type (struct objfile *objfile)
-{
-  struct type *type;
-
-  gdb_assert (objfile != NULL);
-
-  /* Alloc the structure and start off with all fields zeroed.  */
-  type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
-  TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-					  struct main_type);
-  OBJSTAT (objfile, n_types++);
-
-  type->set_owner (objfile);
-
-  /* Initialize the fields that might not be zero.  */
-
-  type->set_code (TYPE_CODE_UNDEF);
-  TYPE_CHAIN (type) = type;	/* Chain back to itself.  */
-
-  return type;
-}
-
 /* See gdbtypes.h.  */
 
 type *
@@ -3437,7 +3410,7 @@  init_type (struct objfile *objfile, enum type_code code, int bit,
 {
   struct type *type;
 
-  type = alloc_type (objfile);
+  type = type_allocator (objfile).new_type ();
   set_type_code (type, code);
   gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
   type->set_length (bit / TARGET_CHAR_BIT);
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 03f94709006..c052b74d1f3 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2186,9 +2186,6 @@  extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN];
 
 #define TYPE_ZALLOC(t,size) (memset (TYPE_ALLOC (t, size), 0, size))
 
-/* Use alloc_type to allocate a type owned by an objfile.  */
-extern struct type *alloc_type (struct objfile *);
-
 /* * This returns the target type (or NULL) of TYPE, also skipping
    past typedefs.  */
 
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 13dc7899d44..e4814b2b81e 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -4725,7 +4725,7 @@  new_type (char *name)
 {
   struct type *t;
 
-  t = alloc_type (mdebugread_objfile);
+  t = type_allocator (mdebugread_objfile).new_type ();
   t->set_name (name);
   INIT_CPLUS_SPECIFIC (t);
   return t;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index cfe245325f5..8eac7ab6261 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -346,7 +346,7 @@  dbx_alloc_type (int typenums[2], struct objfile *objfile)
 
   if (typenums[0] == -1)
     {
-      return (alloc_type (objfile));
+      return type_allocator (objfile).new_type ();
     }
 
   type_addr = dbx_lookup_type (typenums, objfile);
@@ -356,7 +356,7 @@  dbx_alloc_type (int typenums[2], struct objfile *objfile)
      We will fill it in later if we find out how.  */
   if (*type_addr == 0)
     {
-      *type_addr = alloc_type (objfile);
+      *type_addr = type_allocator (objfile).new_type ();
     }
 
   return (*type_addr);