Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tankut Baris Aktemur <tankutbaris.aktemur@amd.com>
To: <gdb-patches@sourceware.org>
Cc: <tom@tromey.com>
Subject: [PATCH v2 10/17] gdb: convert TYPE_CONST macro to type::is_const
Date: Wed, 22 Jul 2026 05:41:59 -0500	[thread overview]
Message-ID: <20260722-users-aktemur-type-instance-flags-v2-10-d60dcbc2a76f@amd.com> (raw)
In-Reply-To: <20260722-users-aktemur-type-instance-flags-v2-0-d60dcbc2a76f@amd.com>

Convert the TYPE_CONST macro to a method of the type class.  This is
a refactoring.
---
 gdb/c-typeprint.c                 |  4 ++--
 gdb/compile/compile-c-types.c     |  4 ++--
 gdb/compile/compile-cplus-types.c |  6 +++---
 gdb/ctfread.c                     |  4 ++--
 gdb/dwarf2/read.c                 |  8 ++++----
 gdb/gdbtypes.c                    | 12 +++++-------
 gdb/gdbtypes.h                    |  7 ++++++-
 gdb/m2-typeprint.c                |  2 +-
 gdb/m2-valprint.c                 |  2 +-
 gdb/opencl-lang.c                 |  2 +-
 gdb/python/py-type.c              |  4 ++--
 gdb/type-stack.c                  |  2 +-
 gdb/valops.c                      |  6 +++---
 13 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index db3bc29475f..97e547a92ef 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -311,7 +311,7 @@ cp_type_print_method_args (struct type *mtype,
       gdb_assert (args[0].type ()->code () == TYPE_CODE_PTR);
       domain = args[0].type ()->target_type ();
 
-      if (TYPE_CONST (domain))
+      if (domain->is_const ())
 	gdb_printf (stream, " const");
 
       if (TYPE_VOLATILE (domain))
@@ -449,7 +449,7 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
   /* We don't print `const' qualifiers for references --- since all
      operators affect the thing referenced, not the reference itself,
      every reference is `const'.  */
-  if (TYPE_CONST (type) && !TYPE_IS_REFERENCE (type))
+  if (type->is_const () && !TYPE_IS_REFERENCE (type))
     {
       if (need_pre_space)
 	gdb_printf (stream, " ");
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index af9dea730eb..2e5ca12a61b 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -247,7 +247,7 @@ convert_qualified (compile_c_instance *context, struct type *type)
 
   unqual_converted = context->convert_type (unqual);
 
-  if (TYPE_CONST (type))
+  if (type->is_const ())
     quals |= GCC_QUALIFIER_CONST;
   if (TYPE_VOLATILE (type))
     quals |= GCC_QUALIFIER_VOLATILE;
@@ -278,7 +278,7 @@ convert_type_basic (compile_c_instance *context, struct type *type)
 {
   /* If we are converting a qualified type, first convert the
      unqualified type and then apply the qualifiers.  */
-  if (TYPE_CONST (type) || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
+  if (type->is_const () || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
     return convert_qualified (context, type);
 
   switch (type->code ())
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index ff25fc62c8b..90ef1bda2cb 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -669,7 +669,7 @@ compile_cplus_convert_method (compile_cplus_instance *instance,
   gcc_type class_type = instance->convert_type (parent_type);
   gcc_cp_qualifiers_flags quals = 0;
 
-  if (TYPE_CONST (method_type))
+  if (method_type->is_const ())
     quals |= GCC_CP_QUALIFIER_CONST;
   if (TYPE_VOLATILE (method_type))
     quals |= GCC_CP_QUALIFIER_VOLATILE;
@@ -1066,7 +1066,7 @@ compile_cplus_convert_qualified (compile_cplus_instance *instance,
   gcc_cp_qualifiers_flags quals = (enum gcc_cp_qualifiers) 0;
   gcc_type unqual_converted = instance->convert_type (unqual);
 
-  if (TYPE_CONST (type))
+  if (type->is_const ())
     quals |= GCC_CP_QUALIFIER_CONST;
   if (TYPE_VOLATILE (type))
     quals |= GCC_CP_QUALIFIER_VOLATILE;
@@ -1126,7 +1126,7 @@ convert_type_cplus_basic (compile_cplus_instance *instance,
 {
   /* If we are converting a qualified type, first convert the
      unqualified type and then apply the qualifiers.  */
-  if (TYPE_CONST (type) || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
+  if (type->is_const () || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
     return compile_cplus_convert_qualified (instance, type);
 
   switch (type->code ())
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 5f8c54a34df..b40d3de6763 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -757,7 +757,7 @@ add_array_cv_type (struct ctf_context *ccp,
     }
 
   el_type = inner_array->target_type ();
-  cnst |= TYPE_CONST (el_type);
+  cnst |= el_type->is_const ();
   voltl |= TYPE_VOLATILE (el_type);
   inner_array->set_target_type (make_cv_type (cnst, voltl, el_type));
 
@@ -857,7 +857,7 @@ read_volatile_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
 
   if (ctf_type_kind (dict, btid) == CTF_K_ARRAY)
     return add_array_cv_type (ccp, tid, base_type, 0, 1);
-  cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type);
+  cv_type = make_cv_type (base_type->is_const (), 1, base_type);
 
   return set_tid_type (ccp, tid, cv_type);
 }
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ce4d6ca8675..067561b6e48 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5178,7 +5178,7 @@ dwarf2_compute_name (const char *name,
 		  if (type->num_fields () > 0
 		      && type->field (0).is_artificial ()
 		      && type->field (0).type ()->code () == TYPE_CODE_PTR
-		      && TYPE_CONST (type->field (0).type ()->target_type ()))
+		      && type->field (0).type ()->target_type ()->is_const ())
 		    buf.puts (" const");
 		}
 	    }
@@ -12176,7 +12176,7 @@ add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
     }
 
   el_type = inner_array->target_type ();
-  cnst |= TYPE_CONST (el_type);
+  cnst |= el_type->is_const ();
   voltl |= TYPE_VOLATILE (el_type);
   inner_array->set_target_type (make_cv_type (cnst, voltl, el_type));
 
@@ -12222,7 +12222,7 @@ read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
   if (base_type->code () == TYPE_CODE_ARRAY)
     return add_array_cv_type (die, cu, base_type, 0, 1);
 
-  cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type);
+  cv_type = make_cv_type (base_type->is_const (), 1, base_type);
   return set_die_type (die, cv_type, cu);
 }
 
@@ -12521,7 +12521,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 		 expects.  GCC marks THIS as const in method definitions,
 		 but not in the class specifications (GCC PR 43053).  */
 	      if (cu->lang () == language_cplus
-		  && !TYPE_CONST (arg_type)
+		  && !arg_type->is_const ()
 		  && ftype->field (iparams).is_artificial ())
 		{
 		  int is_this = 0;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index dd73d9e624f..74b043de9f9 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4314,7 +4314,7 @@ rank_one_type_parm_ptr (struct type *parm, struct type *arg, struct value *value
 	if (types_equal (t1, t2))
 	  {
 	    /* Make sure they are CV equal.  */
-	    if (TYPE_CONST (t1) != TYPE_CONST (t2))
+	    if (t1->is_const () != t2->is_const ())
 	      rank.subrank |= CV_CONVERSION_CONST;
 	    if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
 	      rank.subrank |= CV_CONVERSION_VOLATILE;
@@ -4700,7 +4700,7 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
 	     lvalue references.  */
 	  if (parm->code () == TYPE_CODE_RVALUE_REF)
 	    rank.subrank = REFERENCE_CONVERSION_RVALUE;
-	  else if (TYPE_CONST (parm->target_type ()))
+	  else if (parm->target_type ()->is_const ())
 	    rank.subrank = REFERENCE_CONVERSION_CONST_LVALUE;
 	  else
 	    return INCOMPATIBLE_TYPE_BADNESS;
@@ -4727,7 +4727,7 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
 	}
 
       /* Make sure they are CV equal, too.  */
-      if (TYPE_CONST (t1) != TYPE_CONST (t2))
+      if (t1->is_const () != t2->is_const ())
 	rank.subrank |= CV_CONVERSION_CONST;
       if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
 	rank.subrank |= CV_CONVERSION_VOLATILE;
@@ -5021,10 +5021,8 @@ recursive_dump_type (struct type *type, int spaces)
   gdb_printf ("%*stype_chain %s\n", spaces, "",
 	      host_address_to_string (type->chain));
   gdb_printf ("%*sinstance_flags [", spaces, "");
-  if (TYPE_CONST (type))
-    {
-      gdb_puts (" TYPE_CONST");
-    }
+  if (type->is_const ())
+    gdb_puts (" TYPE_CONST");
   if (TYPE_VOLATILE (type))
     {
       gdb_puts (" TYPE_VOLATILE");
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 176d3936661..a4fcd4d07b4 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -168,7 +168,6 @@ struct type_instance_flags
   bool is_atomic : 1;
 };
 
-#define TYPE_CONST(t) (((t)->instance_flags ()).is_const)
 #define TYPE_VOLATILE(t) (((t)->instance_flags ()).is_volatile)
 #define TYPE_RESTRICT(t) (((t)->instance_flags ()).is_restrict)
 #define TYPE_ATOMIC(t) (((t)->instance_flags ()).is_atomic)
@@ -1206,6 +1205,12 @@ struct type
     return this->m_instance_flags.is_nottext;
   }
 
+  /* Return if this type is const.  */
+  bool is_const () const
+  {
+    return this->m_instance_flags.is_const;
+  }
+
   /* Get the bounds bounds of this type.  The type must be a range type.  */
   range_bounds *bounds () const
   {
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 59616e7f2d6..30b40105405 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -244,7 +244,7 @@ static void
 m2_pointer (struct type *type, struct ui_file *stream, int show,
 	    int level, const struct type_print_options *flags)
 {
-  if (TYPE_CONST (type))
+  if (type->is_const ())
     gdb_printf (stream, "[...] : ");
   else
     gdb_printf (stream, "POINTER TO ");
diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c
index eb2be9d33a8..ee0ab9fda6a 100644
--- a/gdb/m2-valprint.c
+++ b/gdb/m2-valprint.c
@@ -356,7 +356,7 @@ m2_language::value_print_inner (struct value *val, struct ui_file *stream,
       break;
 
     case TYPE_CODE_PTR:
-      if (TYPE_CONST (type))
+      if (type->is_const ())
 	print_variable_at_address (type, valaddr, stream, recurse, options);
       else if (options->format && options->format != 's')
 	value_print_scalar_formatted (val, options, 0, stream);
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 8576f4224a2..96119785f92 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -292,7 +292,7 @@ create_value (struct gdbarch *gdbarch, struct value *val, enum noside noside,
       if (dst_type == NULL)
 	dst_type = init_vector_type (elm_type, n);
 
-      make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type), dst_type);
+      make_cv_type (type->is_const (), TYPE_VOLATILE (type), dst_type);
 
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
 	ret = value::allocate (dst_type);
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 7831e838481..5b98ec1fa7f 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -733,7 +733,7 @@ typy_volatile (PyObject *self, PyObject *args)
 
   try
     {
-      type = make_cv_type (TYPE_CONST (type), 1, type);
+      type = make_cv_type (type->is_const (), 1, type);
     }
   catch (const gdb_exception &except)
     {
@@ -894,7 +894,7 @@ typy_lookup_type (struct demangle_component *demangled,
 	      rtype = make_cv_type (1, TYPE_VOLATILE (type), type);
 	      break;
 	    case DEMANGLE_COMPONENT_VOLATILE:
-	      rtype = make_cv_type (TYPE_CONST (type), 1, type);
+	      rtype = make_cv_type (type->is_const (), 1, type);
 	      break;
 	    }
 	}
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index 476848fcad1..05c5ee6e47f 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -159,7 +159,7 @@ type_stack::follow_types (struct type *follow_type)
 				      TYPE_VOLATILE (follow_type),
 				      follow_type);
 	if (make_volatile)
-	  follow_type = make_cv_type (TYPE_CONST (follow_type),
+	  follow_type = make_cv_type (follow_type->is_const (),
 				      make_volatile,
 				      follow_type);
 	if (make_harvard_aspace != HARVARD_ASPACE_NONE)
diff --git a/gdb/valops.c b/gdb/valops.c
index 76be9c58e6a..ccb2ae21adc 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3650,7 +3650,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
 	    {
 	      for (j = 0; j < len; ++j)
 		{
-		  if (TYPE_CONST (intype) != TYPE_FN_FIELD_CONST (f, j))
+		  if (intype->is_const () != TYPE_FN_FIELD_CONST (f, j))
 		    continue;
 		  if (TYPE_VOLATILE (intype) != TYPE_FN_FIELD_VOLATILE (f, j))
 		    continue;
@@ -3873,7 +3873,7 @@ value_rtti_indirect_type (struct value *v, int *full,
     {
       /* Copy qualifiers to the referenced object.  */
       target_type = target->type ();
-      real_type = make_cv_type (TYPE_CONST (target_type),
+      real_type = make_cv_type (target_type->is_const (),
 				TYPE_VOLATILE (target_type), real_type);
       if (TYPE_IS_REFERENCE (type))
 	real_type = lookup_reference_type (real_type, type->code ());
@@ -3883,7 +3883,7 @@ value_rtti_indirect_type (struct value *v, int *full,
 	internal_error (_("Unexpected value type."));
 
       /* Copy qualifiers to the pointer/reference.  */
-      real_type = make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type),
+      real_type = make_cv_type (type->is_const (), TYPE_VOLATILE (type),
 				real_type);
     }
 

-- 
2.34.1


  parent reply	other threads:[~2026-07-22 10:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 01/17] gdb: use type instance macros to query const, volatile, restrict Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 02/17] gdb: convert address_class_type_flags_to_name to address_class_id_to_name Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 03/17] gdb: convert address_class_name_to_type_flags to address_class_name_to_id Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 04/17] gdb: convert address_class_type_flags to address_class_dwarf_to_id Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 05/17] gdb: refactor type_stack::insert methods Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 06/17] gdb: inline address_space_{name, type_instance_flags}_to_{type_instance_flags, name} Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 07/17] gdb: split make_type_with_address_space Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 08/17] gdb: convert type instance flags to bitfields Tankut Baris Aktemur
2026-07-24 19:10   ` Keith Seitz
2026-07-22 10:41 ` [PATCH v2 09/17] gdb: convert TYPE_NOTTEXT macro to type::is_nottext Tankut Baris Aktemur
2026-07-22 10:41 ` Tankut Baris Aktemur [this message]
2026-07-22 10:42 ` [PATCH v2 11/17] gdb: convert TYPE_VOLATILE macro to type::is_volatile Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 12/17] gdb: convert TYPE_CODE_SPACE macro to type::is_code_space Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 13/17] gdb: convert TYPE_DATA_SPACE macro to type::is_data_space Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 14/17] gdb: convert TYPE_RESTRICT macro to type::is_restrict Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 15/17] gdb: convert TYPE_ATOMIC macro to type::is_atomic Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 16/17] gdb: convert TYPE_ADDRESS_CLASS macro to type::address_class Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 17/17] gdb: remove unnecessary braces in recursive_dump_type Tankut Baris Aktemur
2026-07-22 15:42 ` [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields 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=20260722-users-aktemur-type-instance-flags-v2-10-d60dcbc2a76f@amd.com \
    --to=tankutbaris.aktemur@amd.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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