Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH v2 08/19] gdb: make $(YACC) and $(FLEX) generate headers
Date: Sat,  5 Sep 2026 00:23:11 -0400	[thread overview]
Message-ID: <20260905042353.1702204-9-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260905042353.1702204-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@efficios.com>

I'd like to move the hand-written support code of parsers out of the .y
files, because I find it very impractical to read and edit.  C++ tooling
also typically doesn't work for the C++ code inside .y files.

To help with this, pass -d to $(YACC), so that it also produces header
files exposing the generated parsers, allowing to call them from other
files.  I checked that the following yacc implementations support it:

 - bison
 - AIX (https://www.ibm.com/docs/en/aix/7.2.0?topic=y-yacc-command)
 - Solaris (https://docs.oracle.com/cd/E88353_01/html/E37839/yacc-1.html)
 - NetBSD (https://man.netbsd.org/yacc.1)
 - FreeBSD (https://man.freebsd.org/cgi/man.cgi?query=yacc&apropos=0&sektion=1&manpath=FreeBSD+15.1-RELEASE&arch=default&format=html)
 - OpenBSD (https://man.openbsd.org/yacc)

Also pass `--header-file` to $(FLEX) to have it generate a header
file.  This is a flex-specific option, but a previous patch in this
series (to use -P) already effectively required the use of flex.

The post-processing must be applied to the header files exactly as it is
applied to the source files (it contains declarations of things that get
renamed by that post-processing), so call the post processing script for
the headers too.

Add the generated headers to generated_files, so they are created before
anything that could include them is compiled.

Change-Id: I7153f85c69e989b5a1e4318288b85ba4b456a319
---
 gdb/.gitignore  |  9 +++++++++
 gdb/Makefile.in | 38 +++++++++++++++++++++++++-------------
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/gdb/.gitignore b/gdb/.gitignore
index c4d0f0595448..6b5600dd695e 100644
--- a/gdb/.gitignore
+++ b/gdb/.gitignore
@@ -6,15 +6,24 @@
 /xml-builtin.c
 
 /ada-exp-gen.c
+/ada-exp-gen.h
 /ada-lex-gen.c
+/ada-lex-gen.h
 /c-exp-gen.c
+/c-exp-gen.h
 /cp-name-parser-gen.c
+/cp-name-parser-gen.h
 /d-exp-gen.c
+/d-exp-gen.h
 /f-exp-gen.c
+/f-exp-gen.h
 /gdb
 /gcore
 /go-exp-gen.c
+/go-exp-gen.h
 /init.c
 /jit-reader.h
 /m2-exp-gen.c
+/m2-exp-gen.h
 /p-exp-gen.c
+/p-exp-gen.h
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index daf5cf2baee1..e6c1587f4767 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -2071,9 +2071,12 @@ YYFILES = \
 # a .o itself.
 YYOBJ = $(filter-out ada-lex-gen.o,$(patsubst %.c,%.o,$(YYFILES)))
 
+# The headers bison/byacc and flex generate alongside the files above.
+YYHFILES = $(patsubst %-gen.c,%-gen.h,$(YYFILES))
+
 # Things which need to be built when making a distribution.
 
-DISTSTUFF = $(YYFILES)
+DISTSTUFF = $(YYFILES) $(YYHFILES)
 
 
 # All generated files which can be included by another file.
@@ -2081,6 +2084,7 @@ generated_files = \
 	ada-lex-gen.c \
 	config.h \
 	jit-reader.h \
+	$(YYHFILES) \
 	$(NAT_GENERATED_FILES) \
 	$(NM_H)
 
@@ -2437,7 +2441,7 @@ local-maintainer-clean:
 	@echo "This command is intended for maintainers to use;"
 	@echo "it deletes files that may require special tools to rebuild."
 	rm -f TAGS
-	rm -f $(YYFILES)
+	rm -f $(YYFILES) $(YYHFILES)
 	rm -f nm.h config.status
 
 do-maintainer-clean:
@@ -2710,17 +2714,25 @@ YY_PREFIX_go-exp = go_yy
 YY_PREFIX_m2-exp = m2_yy
 YY_PREFIX_p-exp = pascal_yy
 
-%-gen.c: %.y $(POST_PROCESS_PARSER_OUTPUT_SH)
-	$(ECHO_YACC) $(SHELL) $(YLWRAP) $< y.tab.c $@.tmp -- \
-		$(YACC) $(YFLAGS) -p $(YY_PREFIX_$*) -t || (rm -f $@.tmp; false)
-	@$(POST_PROCESS_PARSER_OUTPUT) bison $* < $@.tmp > $@.new && \
-	  rm -f $@.tmp && \
-	  mv $@.new $@
-%-gen.c: %.l $(POST_PROCESS_PARSER_OUTPUT_SH)
-	$(ECHO_LEX) $(FLEX) -t -P $(YY_PREFIX_$*) $< > $@.tmp || (rm -f $@.tmp; false)
-	@$(POST_PROCESS_PARSER_OUTPUT) flex $* < $@.tmp > $@.new && \
-	  rm -f $@.tmp && \
-	  mv $@.new $@
+%-gen.c %-gen.h: %.y $(POST_PROCESS_PARSER_OUTPUT_SH)
+	$(ECHO_YACC) $(SHELL) $(YLWRAP) $< \
+		y.tab.c $*-gen.c.tmp \
+		y.tab.h $*-gen.h.tmp -- \
+		$(YACC) $(YFLAGS) -p $(YY_PREFIX_$*) -t -d \
+			|| (rm -f $*-gen.c.tmp $*-gen.h.tmp; false)
+	@$(POST_PROCESS_PARSER_OUTPUT) bison $* < $*-gen.c.tmp > $*-gen.c.new \
+		&& rm -f $*-gen.c.tmp && mv $*-gen.c.new $*-gen.c
+	@$(POST_PROCESS_PARSER_OUTPUT) bison $* < $*-gen.h.tmp > $*-gen.h.new \
+		&& rm -f $*-gen.h.tmp && mv $*-gen.h.new $*-gen.h
+
+%-gen.c %-gen.h: %.l $(POST_PROCESS_PARSER_OUTPUT_SH)
+	$(ECHO_LEX) $(FLEX) -t -P $(YY_PREFIX_$*) \
+		--header-file=$*-gen.h.tmp $< > $*-gen.c.tmp \
+			|| (rm -f $*-gen.c.tmp $*-gen.h.tmp; false)
+	@$(POST_PROCESS_PARSER_OUTPUT) flex $* < $*-gen.c.tmp > $*-gen.c.new \
+		&& rm -f $*-gen.c.tmp && mv $*-gen.c.new $*-gen.c
+	@$(POST_PROCESS_PARSER_OUTPUT) flex $* < $*-gen.h.tmp > $*-gen.h.new \
+		&& rm -f $*-gen.h.tmp && mv $*-gen.h.new $*-gen.h
 
 # XML rules
 
-- 
2.55.0


  parent reply	other threads:[~2026-09-05  4:26 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 ` [PATCH v2 02/19] gdb: replace parse_type macros with functions simon.marchi
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 ` simon.marchi [this message]
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-9-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.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