From: Tankut Baris Aktemur Date: Thu, 23 Jul 2026 10:04:42 +0000 (-0500) Subject: gdb: refactor type_stack::insert methods X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c35fba975844a6bf275ca0b4e8b8196749bd22df;p=thirdparty%2Fbinutils-gdb.git gdb: refactor type_stack::insert methods 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 --- diff --git a/gdb/type-stack.c b/gdb/type-stack.c index 7e790a003ec..d19854363a2 100644 --- a/gdb/type-stack.c +++ b/gdb/type-stack.c @@ -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. */ diff --git a/gdb/type-stack.h b/gdb/type-stack.h index 318ef715b2e..1be6d569d8e 100644 --- a/gdb/type-stack.h +++ b/gdb/type-stack.h @@ -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); }