]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: refactor type_stack::insert methods
authorTankut Baris Aktemur <tankutbaris.aktemur@amd.com>
Thu, 23 Jul 2026 10:04:42 +0000 (05:04 -0500)
committerTankut Baris Aktemur <tankutbaris.aktemur@amd.com>
Thu, 23 Jul 2026 10:10:06 +0000 (05:10 -0500)
Clone the 'insert_into' method of struct type_stack into two
overloads, one taking a type piece and the other taking an integer,
and use the overloads to simplify the 'insert' methods.  This is a
refactoring.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/type-stack.c
gdb/type-stack.h

index 7e790a003ec7419c3d6054e641412a9e46006fad..d19854363a2407cfd47bf1e5729d7dca0b30411a 100644 (file)
@@ -26,9 +26,6 @@
 void
 type_stack::insert (enum type_pieces tp)
 {
-  union type_stack_elt element;
-  int slot;
-
   gdb_assert (tp == tp_pointer || tp == tp_reference
              || tp == tp_rvalue_reference || tp == tp_const
              || tp == tp_volatile || tp == tp_restrict
@@ -39,12 +36,9 @@ type_stack::insert (enum type_pieces tp)
      push this on the top of the stack.  */
   if (!m_elements.empty () && (tp == tp_const || tp == tp_volatile
                               || tp == tp_restrict))
-    slot = 1;
+    insert_into (1, tp);
   else
-    slot = 0;
-
-  element.piece = tp;
-  insert_into (slot, element);
+    insert_into (0, tp);
 }
 
 /* See type-stack.h.  */
@@ -52,22 +46,15 @@ type_stack::insert (enum type_pieces tp)
 void
 type_stack::insert (struct gdbarch *gdbarch, const char *string)
 {
-  union type_stack_elt element;
-  int slot;
-
   /* If there is anything on the stack (we know it will be a
      tp_pointer), insert the address space qualifier above it.
      Otherwise, simply push this on the top of the stack.  */
-  if (!m_elements.empty ())
-    slot = 1;
-  else
-    slot = 0;
+  int slot = (!m_elements.empty ()) ? 1 : 0;
 
-  element.piece = tp_space_identifier;
-  insert_into (slot, element);
-  element.int_val
-    = address_space_name_to_type_instance_flags (gdbarch, string);
-  insert_into (slot, element);
+  insert_into (slot, tp_space_identifier);
+  insert_into (slot,
+              address_space_name_to_type_instance_flags (gdbarch,
+                                                         string));
 }
 
 /* See type-stack.h.  */
index 318ef715b2e3481fe9a659ac99e73d303e49570c..1be6d569d8e47cd1854fd3c05bb8e6a4452f6ff7 100644 (file)
@@ -238,12 +238,26 @@ public:
 private:
 
   /* A helper function for the insert methods.  This does work of
-     expanding the type stack and inserting the new element, ELEMENT,
+     expanding the type stack and inserting the new element, TP,
      into the stack at location SLOT.  */
 
-  void insert_into (int slot, union type_stack_elt element)
+  void insert_into (int slot, enum type_pieces tp)
   {
     gdb_assert (slot <= m_elements.size ());
+    union type_stack_elt element;
+    element.piece = tp;
+    m_elements.insert (m_elements.begin () + slot, element);
+  }
+
+  /* A helper function for the insert methods.  This does work of
+     expanding the type stack and inserting the new element, VAL,
+     into the stack at location SLOT.  */
+
+  void insert_into (int slot, int val)
+  {
+    gdb_assert (slot <= m_elements.size ());
+    union type_stack_elt element;
+    element.int_val = val;
     m_elements.insert (m_elements.begin () + slot, element);
   }