From: Tankut Baris Aktemur <tankutbaris.aktemur@amd.com>
To: <gdb-patches@sourceware.org>
Cc: <tom@tromey.com>
Subject: [PATCH v2 05/17] gdb: refactor type_stack::insert methods
Date: Wed, 22 Jul 2026 05:41:54 -0500 [thread overview]
Message-ID: <20260722-users-aktemur-type-instance-flags-v2-5-d60dcbc2a76f@amd.com> (raw)
In-Reply-To: <20260722-users-aktemur-type-instance-flags-v2-0-d60dcbc2a76f@amd.com>
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.
---
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 == 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 @@ struct type_stack
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);
}
--
2.34.1
next prev parent reply other threads:[~2026-07-22 10:44 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 ` Tankut Baris Aktemur [this message]
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 ` [PATCH v2 10/17] gdb: convert TYPE_CONST macro to type::is_const Tankut Baris Aktemur
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-5-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