public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 09/20] Unify arch_character_type and init_character_type
Date: Mon, 13 Mar 2023 16:08:09 -0600	[thread overview]
Message-ID: <20230313-split-objfile-type-allocator-2-v1-9-69ba773ac17b@tromey.com> (raw)
In-Reply-To: <20230313-split-objfile-type-allocator-2-v1-0-69ba773ac17b@tromey.com>

This unifies arch_character_type and init_character_type by using a
type allocator.
---
 gdb/ada-lang.c    |  6 +++---
 gdb/ctfread.c     |  2 +-
 gdb/d-lang.c      |  6 +++---
 gdb/dwarf2/read.c |  8 ++++----
 gdb/gdbtypes.c    | 29 +++++------------------------
 gdb/gdbtypes.h    |  9 ++++++---
 gdb/go-lang.c     |  2 +-
 gdb/m2-lang.c     |  2 +-
 gdb/rust-lang.c   |  2 +-
 gdb/stabsread.c   |  4 ++--
 10 files changed, 27 insertions(+), 43 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index a3ceb3ae838..07995f3d47b 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13563,12 +13563,12 @@ class ada_language : public language_defn
 			    0, "long_integer"));
     add (init_integer_type (alloc, gdbarch_short_bit (gdbarch),
 			    0, "short_integer"));
-    struct type *char_type = arch_character_type (gdbarch, TARGET_CHAR_BIT,
+    struct type *char_type = init_character_type (alloc, TARGET_CHAR_BIT,
 						  1, "character");
     lai->set_string_char_type (char_type);
     add (char_type);
-    add (arch_character_type (gdbarch, 16, 1, "wide_character"));
-    add (arch_character_type (gdbarch, 32, 1, "wide_wide_character"));
+    add (init_character_type (alloc, 16, 1, "wide_character"));
+    add (init_character_type (alloc, 32, 1, "wide_wide_character"));
     add (arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
 			  "float", gdbarch_float_format (gdbarch)));
     add (arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 879fdeb74d6..3940a4f8c67 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -566,7 +566,7 @@ read_base_type (struct ctf_context *ccp, ctf_id_t tid)
       ischar = cet.cte_format & CTF_INT_CHAR;
       isbool = cet.cte_format & CTF_INT_BOOL;
       if (ischar)
-	type = init_character_type (of, TARGET_CHAR_BIT, !issigned, name);
+	type = init_character_type (alloc, TARGET_CHAR_BIT, !issigned, name);
       else if (isbool)
 	type = init_boolean_type (of, gdbarch_int_bit (gdbarch),
 				  !issigned, name);
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index af9a81d1b1b..8e5262d170a 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -262,11 +262,11 @@ build_d_types (struct gdbarch *gdbarch)
 
   /* Character types.  */
   builtin_d_type->builtin_char
-    = arch_character_type (gdbarch, 8, 1, "char");
+    = init_character_type (alloc, 8, 1, "char");
   builtin_d_type->builtin_wchar
-    = arch_character_type (gdbarch, 16, 1, "wchar");
+    = init_character_type (alloc, 16, 1, "wchar");
   builtin_d_type->builtin_dchar
-    = arch_character_type (gdbarch, 32, 1, "dchar");
+    = init_character_type (alloc, 32, 1, "dchar");
 
   return builtin_d_type;
 }
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index f3cc78ce10b..bb77f75179a 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -15270,7 +15270,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
 	if (cu->lang () == language_fortran
 	    && name
 	    && startswith (name, "character("))
-	  type = init_character_type (objfile, bits, 1, name);
+	  type = init_character_type (alloc, bits, 1, name);
 	else
 	  type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
 	break;
@@ -15279,7 +15279,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
 	    || cu->lang () == language_m2
 	    || cu->lang () == language_pascal
 	    || cu->lang () == language_fortran)
-	  type = init_character_type (objfile, bits, 0, name);
+	  type = init_character_type (alloc, bits, 0, name);
 	else
 	  type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
 	break;
@@ -15289,13 +15289,13 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
 	    || cu->lang () == language_pascal
 	    || cu->lang () == language_fortran
 	    || cu->lang () == language_rust)
-	  type = init_character_type (objfile, bits, 1, name);
+	  type = init_character_type (alloc, bits, 1, name);
 	else
 	  type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
 	break;
       case DW_ATE_UTF:
 	{
-	  type = init_character_type (objfile, bits, 1, name);
+	  type = init_character_type (alloc, bits, 1, name);
 	  return set_die_type (die, type, cu);
 	}
 	break;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index f5ddc869ebf..49f88ce6026 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3417,17 +3417,15 @@ init_integer_type (type_allocator &alloc,
   return t;
 }
 
-/* Allocate a TYPE_CODE_CHAR type structure associated with OBJFILE.
-   BIT is the type size in bits.  If UNSIGNED_P is non-zero, set
-   the type's TYPE_UNSIGNED flag.  NAME is the type name.  */
+/* See gdbtypes.h.  */
 
 struct type *
-init_character_type (struct objfile *objfile,
+init_character_type (type_allocator &alloc,
 		     int bit, int unsigned_p, const char *name)
 {
   struct type *t;
 
-  t = type_allocator (objfile).new_type (TYPE_CODE_CHAR, bit, name);
+  t = alloc.new_type (TYPE_CODE_CHAR, bit, name);
   if (unsigned_p)
     t->set_is_unsigned (true);
 
@@ -5750,23 +5748,6 @@ copy_type (const struct type *type)
 \f
 /* Helper functions to initialize architecture-specific types.  */
 
-/* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
-   BIT is the type size in bits.  If UNSIGNED_P is non-zero, set
-   the type's TYPE_UNSIGNED flag.  NAME is the type name.  */
-
-struct type *
-arch_character_type (struct gdbarch *gdbarch,
-		     int bit, int unsigned_p, const char *name)
-{
-  struct type *t;
-
-  t = type_allocator (gdbarch).new_type (TYPE_CODE_CHAR, bit, name);
-  if (unsigned_p)
-    t->set_is_unsigned (true);
-
-  return t;
-}
-
 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
    BIT is the type size in bits.  If UNSIGNED_P is non-zero, set
    the type's TYPE_UNSIGNED flag.  NAME is the type name.  */
@@ -6135,9 +6116,9 @@ create_gdbtypes_data (struct gdbarch *gdbarch)
 
   /* "True" character types.  */
   builtin_type->builtin_true_char
-    = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character");
+    = init_character_type (alloc, TARGET_CHAR_BIT, 0, "true character");
   builtin_type->builtin_true_unsigned_char
-    = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character");
+    = init_character_type (alloc, TARGET_CHAR_BIT, 1, "true character");
 
   /* Fixed-size integer types.  */
   builtin_type->builtin_int0
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 7f2da7a6572..178a8b9a663 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2300,7 +2300,12 @@ class type_allocator
 
 extern struct type *init_integer_type (type_allocator &, int, int,
 				       const char *);
-extern struct type *init_character_type (struct objfile *, int, int,
+
+/* Allocate a TYPE_CODE_CHAR type structure using ALLOC.  BIT is the
+   type size in bits.  If UNSIGNED_P is non-zero, set the type's
+   TYPE_UNSIGNED flag.  NAME is the type name.  */
+
+extern struct type *init_character_type (type_allocator &, int, int,
 					 const char *);
 extern struct type *init_boolean_type (struct objfile *, int, int,
 				       const char *);
@@ -2316,8 +2321,6 @@ extern struct type *init_fixed_point_type (struct objfile *, int, int,
 					   const char *);
 
 /* Helper functions to construct architecture-owned types.  */
-extern struct type *arch_character_type (struct gdbarch *, int, int,
-					 const char *);
 extern struct type *arch_boolean_type (struct gdbarch *, int, int,
 				       const char *);
 extern struct type *arch_float_type (struct gdbarch *, int, const char *,
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 8cdd6b124c4..6d0d43530f8 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -486,7 +486,7 @@ build_go_types (struct gdbarch *gdbarch)
   type_allocator alloc (gdbarch);
   builtin_go_type->builtin_void = builtin_type (gdbarch)->builtin_void;
   builtin_go_type->builtin_char
-    = arch_character_type (gdbarch, 8, 1, "char");
+    = init_character_type (alloc, 8, 1, "char");
   builtin_go_type->builtin_bool
     = arch_boolean_type (gdbarch, 8, 0, "bool");
   builtin_go_type->builtin_int
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 218867d408e..d2fa1a46364 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -292,7 +292,7 @@ build_m2_types (struct gdbarch *gdbarch)
     = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch), "REAL",
 		       gdbarch_float_format (gdbarch));
   builtin_m2_type->builtin_char
-    = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "CHAR");
+    = init_character_type (alloc, TARGET_CHAR_BIT, 1, "CHAR");
   builtin_m2_type->builtin_bool
     = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "BOOLEAN");
 
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 608799cc662..be0a7100f56 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1597,7 +1597,7 @@ rust_language::language_arch_info (struct gdbarch *gdbarch,
   type_allocator alloc (gdbarch);
   struct type *bool_type
     = add (arch_boolean_type (gdbarch, 8, 1, "bool"));
-  add (arch_character_type (gdbarch, 32, 1, "char"));
+  add (init_character_type (alloc, 32, 1, "char"));
   add (init_integer_type (alloc, 8, 0, "i8"));
   struct type *u8_type
     = add (init_integer_type (alloc, 8, 1, "u8"));
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 6270f48bebb..4c7b88f30cd 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -2158,7 +2158,7 @@ rs6000_builtin_type (int typenum, struct objfile *objfile)
       rettype = alloc.new_type (TYPE_CODE_ERROR, 0, "stringptr");
       break;
     case 20:
-      rettype = init_character_type (objfile, 8, 1, "character");
+      rettype = init_character_type (alloc, 8, 1, "character");
       break;
     case 21:
       rettype = init_boolean_type (objfile, 8, 1, "logical*1");
@@ -2192,7 +2192,7 @@ rs6000_builtin_type (int typenum, struct objfile *objfile)
       rettype = init_integer_type (alloc, 32, 0, "integer*4");
       break;
     case 30:
-      rettype = init_character_type (objfile, 16, 0, "wchar");
+      rettype = init_character_type (alloc, 16, 0, "wchar");
       break;
     case 31:
       rettype = init_integer_type (alloc, 64, 0, "long long");

-- 
2.39.1


  parent reply	other threads:[~2023-03-13 22:08 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-13 22:08 [PATCH 00/20] Remove objfile_type Tom Tromey
2023-03-13 22:08 ` [PATCH 01/20] Introduce type_allocator Tom Tromey
2023-03-13 22:08 ` [PATCH 02/20] Remove alloc_type_arch Tom Tromey
2023-03-13 22:08 ` [PATCH 03/20] Remove alloc_type_copy Tom Tromey
2023-03-13 22:08 ` [PATCH 04/20] Remove alloc_type Tom Tromey
2023-03-13 22:08 ` [PATCH 05/20] Reuse existing builtin types Tom Tromey
2023-03-13 22:08 ` [PATCH 06/20] Remove arch_type Tom Tromey
2023-03-13 22:08 ` [PATCH 07/20] Remove init_type Tom Tromey
2023-03-13 22:08 ` [PATCH 08/20] Unify arch_integer_type and init_integer_type Tom Tromey
2023-03-13 22:08 ` Tom Tromey [this message]
2023-03-13 22:08 ` [PATCH 10/20] Unify arch_boolean_type and init_boolean_type Tom Tromey
2023-03-13 22:08 ` [PATCH 11/20] Unify arch_float_type and init_float_type Tom Tromey
2023-03-13 22:08 ` [PATCH 12/20] Unify arch_decfloat_type and init_decfloat_type Tom Tromey
2023-03-13 22:08 ` [PATCH 13/20] Unify arch_pointer_type and init_pointer_type Tom Tromey
2023-03-13 22:08 ` [PATCH 14/20] Use type allocator for range types Tom Tromey
2023-03-14 14:41   ` Simon Marchi
2023-03-18 15:56     ` Tom Tromey
2023-03-13 22:08 ` [PATCH 15/20] Use type allocator for array types Tom Tromey
2023-03-13 22:08 ` [PATCH 16/20] Use type allocator for set types Tom Tromey
2023-03-13 22:08 ` [PATCH 17/20] Use builtin type when appropriate Tom Tromey
2023-03-13 22:08 ` [PATCH 18/20] Rename objfile_type to builtin_type Tom Tromey
2023-03-13 22:08 ` [PATCH 19/20] Add some types to struct builtin_type Tom Tromey
2023-03-13 22:08 ` [PATCH 20/20] Remove objfile_type Tom Tromey
2023-03-14 14:48 ` [PATCH 00/20] " Simon Marchi
2023-03-18 15:57   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230313-split-objfile-type-allocator-2-v1-9-69ba773ac17b@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).