[binutils-gdb] gdb: convert TYPE_CODE_SPACE macro to type::is_code_space

Tankut Baris Aktemur via Gdb-cvs <[email protected]> Thu, 23 Jul 2026 10:13:25 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dff546adf577b=
9c8a2c1bebc2dc50521894c44c6f

commit ff546adf577b9c8a2c1bebc2dc50521894c44c6f
Author: Tankut Baris Aktemur <[email protected]>
Date:   Thu Jul 23 05:04:43 2026 -0500

    gdb: convert TYPE_CODE_SPACE macro to type::is_code_space
   =20
    Convert the TYPE_CODE_SPACE macro to a method of the type class.  This
    is a refactoring.
   =20
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 gdb/avr-tdep.c    | 2 +-
 gdb/c-typeprint.c | 2 +-
 gdb/gdbtypes.c    | 6 ++----
 gdb/gdbtypes.h    | 9 ++++++---
 gdb/iq2000-tdep.c | 2 +-
 gdb/rl78-tdep.c   | 2 +-
 6 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 2191ada4c2e..26b786c68b7 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -345,7 +345,7 @@ avr_pointer_to_address (struct gdbarch *gdbarch,
   /* Is it a code address?  */
   else if (type->target_type ()->code () =3D=3D TYPE_CODE_FUNC
 	   || type->target_type ()->code () =3D=3D TYPE_CODE_METHOD
-	   || TYPE_CODE_SPACE (type->target_type ()))
+	   || type->target_type ()->is_code_space ())
     {
       /* A code pointer is word (16 bits) addressed so we shift it up
 	 by 1 bit to convert it to an address.  */
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index fb8b228ea38..a8927e0ac43 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -485,7 +485,7 @@ c_type_print_modifier (struct type *type, struct ui_fil=
e *stream,
=20
   address_space_id =3D nullptr;
=20
-  if (TYPE_CODE_SPACE (type))
+  if (type->is_code_space ())
     address_space_id =3D "code";
   else if (TYPE_DATA_SPACE (type))
     address_space_id =3D "data";
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 1019f02e2e1..465af4790fd 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5025,10 +5025,8 @@ recursive_dump_type (struct type *type, int spaces)
     gdb_puts (" TYPE_CONST");
   if (type->is_volatile ())
     gdb_puts (" TYPE_VOLATILE");
-  if (TYPE_CODE_SPACE (type))
-    {
-      gdb_puts (" TYPE_CODE_SPACE");
-    }
+  if (type->is_code_space ())
+    gdb_puts (" TYPE_CODE_SPACE");
   if (TYPE_DATA_SPACE (type))
     {
       gdb_puts (" TYPE_DATA_SPACE");
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 6a8bc425d45..d9988312e1b 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -189,9 +189,6 @@ struct type_instance_flags
   (((t)->dyn_prop (DYN_PROP_BYTE_SIZE) !=3D nullptr)	\
    || ((t)->dyn_prop (DYN_PROP_BIT_SIZE) !=3D nullptr))
=20
-#define TYPE_CODE_SPACE(t) \
-  (((t)->instance_flags ()).harvard_aspace =3D=3D HARVARD_ASPACE_CODE)
-
 #define TYPE_DATA_SPACE(t) \
   (((t)->instance_flags ()).harvard_aspace =3D=3D HARVARD_ASPACE_DATA)
=20
@@ -1216,6 +1213,12 @@ struct type
     return this->m_instance_flags.is_volatile;
   }
=20
+  /* Return if this type is in the code space.  */
+  bool is_code_space () const
+  {
+    return this->m_instance_flags.harvard_aspace =3D=3D HARVARD_ASPACE_COD=
E;
+  }
+
   /* Get the bounds bounds of this type.  The type must be a range type.  =
*/
   range_bounds *bounds () const
   {
diff --git a/gdb/iq2000-tdep.c b/gdb/iq2000-tdep.c
index 32e3750aca4..783e1720a02 100644
--- a/gdb/iq2000-tdep.c
+++ b/gdb/iq2000-tdep.c
@@ -95,7 +95,7 @@ iq2000_pointer_to_address (struct gdbarch *gdbarch,
=20
   if (target =3D=3D TYPE_CODE_FUNC
       || target =3D=3D TYPE_CODE_METHOD
-      || TYPE_CODE_SPACE (type->target_type ()))
+      || type->target_type ()->is_code_space ())
     addr =3D insn_addr_from_ptr (addr);
=20
   return addr;
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 0de2fceb795..4204ce5c8cb 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -1052,7 +1052,7 @@ rl78_pointer_to_address (struct gdbarch *gdbarch,
   /* Is it a code address?  */
   if (type->target_type ()->code () =3D=3D TYPE_CODE_FUNC
       || type->target_type ()->code () =3D=3D TYPE_CODE_METHOD
-      || TYPE_CODE_SPACE (type->target_type ())
+      || type->target_type ()->is_code_space ()
       || type->length () =3D=3D 4)
     return rl78_make_instruction_address (addr);
   else