From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH v2 02/19] gdb: replace parse_type macros with functions
Date: Sat, 5 Sep 2026 00:23:05 -0400 [thread overview]
Message-ID: <20260905042353.1702204-3-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260905042353.1702204-1-simon.marchi@polymtl.ca>
From: Simon Marchi <simon.marchi@polymtl.ca>
I noticed that many parsers defined the same parse_type macro, so I thought
let's move it to parser-defs.h so it can be shared. And while at it, change
it to a static inline function, as well as the other macros (the
language-specific ones).
Change-Id: I39160263f2ce63fdaddebf9f0b61ccaf94773e1d
---
gdb/ada-exp.y | 2 --
gdb/c-exp.y | 2 --
gdb/d-exp.y | 11 ++++++++---
gdb/f-exp.y | 11 ++++++++---
gdb/go-exp.y | 2 --
gdb/m2-exp.y | 11 ++++++++---
gdb/p-exp.y | 2 --
gdb/parser-defs.h | 8 ++++++++
8 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 15f64fdf01f9..7fd0e6d7c7db 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -46,8 +46,6 @@
#include "ada-exp.h"
#include "cli/cli-style.h"
-#define parse_type(ps) builtin_type (ps->gdbarch ())
-
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
etc). */
#define GDB_YY_REMAP_PREFIX ada_
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index e6a82e2aa3cc..d58bce833551 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -54,8 +54,6 @@
#include "macroexp.h"
#include "cli/cli-style.h"
-#define parse_type(ps) builtin_type (ps->gdbarch ())
-
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
etc). */
#define GDB_YY_REMAP_PREFIX c_
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 1031eb1eccac..d3263ba4fd72 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -50,9 +50,6 @@
#include "expop.h"
#include "cli/cli-style.h"
-#define parse_type(ps) builtin_type (ps->gdbarch ())
-#define parse_d_type(ps) builtin_d_type (ps->gdbarch ())
-
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
etc). */
#define GDB_YY_REMAP_PREFIX d_
@@ -74,6 +71,14 @@ static void yyerror (const char *);
static int type_aggregate_p (struct type *);
+/* Return the D type table for the architecture associated to PS. */
+
+static inline const struct builtin_d_type *
+parse_d_type (parser_state *ps)
+{
+ return builtin_d_type (ps->gdbarch ());
+}
+
using namespace expr;
%}
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 4216112c10b7..4cdfcc973923 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -52,9 +52,6 @@
#include "type-stack.h"
#include "f-exp.h"
-#define parse_type(ps) builtin_type (ps->gdbarch ())
-#define parse_f_type(ps) builtin_f_type (ps->gdbarch ())
-
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
etc). */
#define GDB_YY_REMAP_PREFIX f_
@@ -97,6 +94,14 @@ static void fortran_wrap2_kind (type *base_type);
template<typename T>
static void fortran_wrap3_kind (type *base_type);
+/* Return the Fortran type table for the architecture associated to PS. */
+
+static inline const struct builtin_f_type *
+parse_f_type (parser_state *ps)
+{
+ return builtin_f_type (ps->gdbarch ());
+}
+
using namespace expr;
%}
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index 289fd81db857..199da6dc5c37 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -61,8 +61,6 @@
#include "block.h"
#include "expop.h"
-#define parse_type(ps) builtin_type (ps->gdbarch ())
-
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
etc). */
#define GDB_YY_REMAP_PREFIX go_
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 97e833ddf6ef..0889054f1f37 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -45,9 +45,6 @@
#include "block.h"
#include "m2-exp.h"
-#define parse_type(ps) builtin_type (ps->gdbarch ())
-#define parse_m2_type(ps) builtin_m2_type (ps->gdbarch ())
-
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
etc). */
#define GDB_YY_REMAP_PREFIX m2_
@@ -69,6 +66,14 @@ static int parse_number (int);
/* The sign of the number being parsed. */
static int number_sign = 1;
+/* Return the Modula-2 type table for the architecture associated to PS. */
+
+static inline const struct builtin_m2_type *
+parse_m2_type (parser_state *ps)
+{
+ return builtin_m2_type (ps->gdbarch ());
+}
+
using namespace expr;
%}
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 1a43837ae333..70c74beae438 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -51,8 +51,6 @@
#include "block.h"
#include "expop.h"
-#define parse_type(ps) builtin_type (ps->gdbarch ())
-
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
etc). */
#define GDB_YY_REMAP_PREFIX pascal_
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index cfa9d9c111da..7e4f438e6f08 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -329,6 +329,14 @@ struct parser_state : public expr_builder
std::vector<expr::operation_up> m_operations;
};
+/* Return the type table for the architecture associated to PS. */
+
+static inline const struct builtin_type *
+parse_type (parser_state *ps)
+{
+ return builtin_type (ps->gdbarch ());
+}
+
/* A string token, either a char-string or bit-string. Char-strings are
used, for example, for the names of symbols. */
--
2.55.0
next prev parent reply other threads:[~2026-09-05 4:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 4:23 [PATCH v2 00/19] Move C++ support code out of .y files simon.marchi
2026-09-05 4:23 ` [PATCH v2 01/19] gdb/ada-exp-parser: remove name_info struct simon.marchi
2026-09-05 4:23 ` simon.marchi [this message]
2026-09-05 4:23 ` [PATCH v2 03/19] gdb: suffix flex/bison output files with -gen.c simon.marchi
2026-09-05 4:23 ` [PATCH v2 04/19] gdb: remove YY_NULL to YY_NULLPTR substitution simon.marchi
2026-09-05 4:23 ` [PATCH v2 05/19] gdb: move parser output post-processing to a script simon.marchi
2026-09-05 4:23 ` [PATCH v2 06/19] gdb: let the parser and lexer generators prefix their symbols simon.marchi
2026-09-05 4:23 ` [PATCH v2 07/19] gdb: separate cp-name-parser's symbol prefix with an underscore simon.marchi
2026-09-05 4:23 ` [PATCH v2 08/19] gdb: make $(YACC) and $(FLEX) generate headers simon.marchi
2026-09-05 4:23 ` [PATCH v2 09/19] gdb: add check for stale build generated files simon.marchi
2026-09-05 4:23 ` [PATCH v2 10/19] gdb: move cp-name-parser.y's support code to cp-name-parser.c simon.marchi
2026-09-05 4:23 ` [PATCH v2 11/19] gdb: rename LANG-exp.y to LANG-exp-parser.y simon.marchi
2026-09-05 4:23 ` [PATCH v2 12/19] gdb: move c-exp-parser.y's support code to c-exp-parser.c simon.marchi
2026-09-05 4:23 ` [PATCH v2 13/19] gdb: move ada-exp-parser.y's support code to ada-exp-parser.c simon.marchi
2026-09-08 18:28 ` Kevin Buettner
2026-09-05 4:23 ` [PATCH v2 14/19] gdb: move d-exp-parser.y's support code to d-exp-parser.c simon.marchi
2026-09-05 4:23 ` [PATCH v2 15/19] gdb: move f-exp-parser.y's support code to f-exp-parser.c simon.marchi
2026-09-05 4:23 ` [PATCH v2 16/19] gdb: move go-exp-parser.y's support code to go-exp-parser.c simon.marchi
2026-09-05 4:23 ` [PATCH v2 17/19] gdb: move m2-exp-parser.y's support code to m2-exp-parser.c simon.marchi
2026-09-05 4:23 ` [PATCH v2 18/19] gdb: move p-exp-parser.y's support code to p-exp-parser.c simon.marchi
2026-09-05 4:23 ` [PATCH v2 19/19] gdb: honor "set debug parser" in the Modula-2 and Pascal parsers 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=20260905042353.1702204-3-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--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