[binutils-gdb] gdb: refactor type_stack::insert methods
Tankut Baris Aktemur via Gdb-cvs <[email protected]> Thu, 23 Jul 2026 10:12:49 +0000 (GMT)
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc35fba975844= a6bf275ca0b4e8b8196749bd22df commit c35fba975844a6bf275ca0b4e8b8196749bd22df Author: Tankut Baris Aktemur <[email protected]> Date: Thu Jul 23 05:04:42 2026 -0500 gdb: refactor type_stack::insert methods =20 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. =20 Approved-By: Tom Tromey <[email protected]> Diff: --- gdb/type-stack.c | 27 +++++++-------------------- gdb/type-stack.h | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 22 deletions(-) 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 =3D=3D tp_pointer || tp =3D=3D tp_reference || tp =3D=3D tp_rvalue_reference || tp =3D=3D tp_const || tp =3D=3D tp_volatile || tp =3D=3D 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 =3D=3D tp_const || tp =3D=3D tp_volatile || tp =3D=3D tp_restrict)) - slot =3D 1; + insert_into (1, tp); else - slot =3D 0; - - element.piece =3D tp; - insert_into (slot, element); + insert_into (0, tp); } =20 /* 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 =3D 1; - else - slot =3D 0; + int slot =3D (!m_elements.empty ()) ? 1 : 0; =20 - element.piece =3D tp_space_identifier; - insert_into (slot, element); - element.int_val - =3D 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)); } =20 /* 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: =20 /* 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. */ =20 - void insert_into (int slot, union type_stack_elt element) + void insert_into (int slot, enum type_pieces tp) { gdb_assert (slot <=3D m_elements.size ()); + union type_stack_elt element; + element.piece =3D 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 <=3D m_elements.size ()); + union type_stack_elt element; + element.int_val =3D val; m_elements.insert (m_elements.begin () + slot, element); }