Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 1/7] gdb: convert QUAL_* macros into an enum_flags
Date: Thu,  1 Oct 2026 16:29:59 -0400	[thread overview]
Message-ID: <20261001203105.1379971-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20261001203105.1379971-1-simon.marchi@efficios.com>

Replace the QUAL_CONST / QUAL_RESTRICT / QUAL_VOLATILE macros with an
enum plus an enum flags_type.  Use it where applicable.

Note that the value stored on the parser's union is the raw enum, not
the enum_flags type.  enum_flags has a user-provided default constructor
(to initialize it to 0), which would make the generated YYSTYPE union's
default constructor deleted.  The d_qualify helper function accepts the
enum_flags type though.

Change-Id: Ib146f6db66c849ac2f0ee575a98bff7b90d5e17c
---
 gdb/cp-name-parser.c |  4 ++--
 gdb/cp-name-parser.h | 21 ++++++++++++++-------
 gdb/cp-name-parser.y | 11 ++++++-----
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/gdb/cp-name-parser.c b/gdb/cp-name-parser.c
index d04ed3594878..569d102213c8 100644
--- a/gdb/cp-name-parser.c
+++ b/gdb/cp-name-parser.c
@@ -110,8 +110,8 @@ cpname_state::make_name (const char *name, int len)
    may already be qualified; duplicate qualifiers are not created.  */
 
 struct demangle_component *
-cpname_state::d_qualify (struct demangle_component *lhs, int qualifiers,
-			 int is_method)
+cpname_state::d_qualify (struct demangle_component *lhs,
+			 qual_flags qualifiers, int is_method)
 {
   struct demangle_component **inner_p;
   enum demangle_component_type type;
diff --git a/gdb/cp-name-parser.h b/gdb/cp-name-parser.h
index 31b2227227fc..7585379f5be2 100644
--- a/gdb/cp-name-parser.h
+++ b/gdb/cp-name-parser.h
@@ -21,16 +21,11 @@
 #define GDB_CP_NAME_PARSER_H
 
 #include "demangle.h"
+#include "gdbsupport/enum-flags.h"
 
 union cp_name_parser_YYSTYPE;
 struct demangle_parse_info;
 
-/* Flags passed to cpname_state::d_qualify.  */
-
-#define QUAL_CONST 1
-#define QUAL_RESTRICT 2
-#define QUAL_VOLATILE 4
-
 /* Flags passed to cpname_state::d_int_type.  */
 
 #define INT_CHAR	(1 << 0)
@@ -46,6 +41,18 @@ struct demangle_parse_info;
 
 namespace cp_name_parser {
 
+/* Type qualifiers, passed to cpname_state::d_qualify.  */
+
+enum qual_flag
+{
+  QUAL_NONE = 0,
+  QUAL_CONST = 1,
+  QUAL_RESTRICT = 2,
+  QUAL_VOLATILE = 4,
+};
+
+DEF_ENUM_FLAGS_TYPE (enum qual_flag, qual_flags);
+
 /* State of an ongoing parse.  */
 
 struct cpname_state
@@ -100,7 +107,7 @@ struct cpname_state
   struct demangle_component *make_name (const char *name, int len);
 
   struct demangle_component *d_qualify (struct demangle_component *lhs,
-					int qualifiers, int is_method);
+					qual_flags qualifiers, int is_method);
 
   struct demangle_component *d_int_type (int flags);
 
diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index 57247f459fab..b41ca6b30a20 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -60,6 +60,7 @@
       int fold_flag;
     } abstract;
     int lval;
+    cp_name_parser::qual_flag qual;
     const char *opname;
   }
 
@@ -84,7 +85,7 @@
 
 %type <nested1> nested_name
 
-%type <lval> qualifier qualifiers qualifiers_opt
+%type <qual> qualifier qualifiers qualifiers_opt
 
 %type <lval> int_part int_seq
 
@@ -518,16 +519,16 @@ function_arglist:	'(' function_args ')' qualifiers_opt %prec NAME
 
 /* Should do something about DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL */
 qualifiers_opt	:	/* epsilon */
-			{ $$ = 0; }
+			{ $$ = cp_name_parser::QUAL_NONE; }
 		|	qualifiers
 		;
 
 qualifier	:	RESTRICT
-			{ $$ = QUAL_RESTRICT; }
+			{ $$ = cp_name_parser::QUAL_RESTRICT; }
 		|	VOLATILE_KEYWORD
-			{ $$ = QUAL_VOLATILE; }
+			{ $$ = cp_name_parser::QUAL_VOLATILE; }
 		|	CONST_KEYWORD
-			{ $$ = QUAL_CONST; }
+			{ $$ = cp_name_parser::QUAL_CONST; }
 		;
 
 qualifiers	:	qualifier
-- 
2.55.0


  reply	other threads:[~2026-10-01 20:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 20:29 [PATCH 0/7] Leftovers from parsers cleanup Simon Marchi
2026-10-01 20:29 ` Simon Marchi [this message]
2026-10-01 20:30 ` [PATCH 2/7] gdb: convert INT_* macros into an enum_flags Simon Marchi
2026-10-01 20:30 ` [PATCH 3/7] gdb: convert d_left and d_right macros into functions Simon Marchi
2026-10-01 20:30 ` [PATCH 4/7] gdb: replace cp-name-parser.c macros with lambdas Simon Marchi
2026-10-01 20:30 ` [PATCH 5/7] gdb: use std::string for f-exp-parser.c's tempbuf Simon Marchi
2026-10-01 20:30 ` [PATCH 6/7] gdb: remove qsort kludge from ada-exp-parser.y Simon Marchi
2026-10-01 20:30 ` [PATCH 7/7] gdb: make COMPLETE_CHAR a constexpr Simon Marchi
2026-10-14 12:54 ` [PATCH 0/7] Leftovers from parsers cleanup Tom Tromey
2026-10-14 13:13   ` Simon Marchi

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=20261001203105.1379971-2-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /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