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 03/17] gdb: suffix flex/bison output files with -gen.c
Date: Fri,  4 Sep 2026 12:56:35 -0400	[thread overview]
Message-ID: <20260904170338.1643894-4-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260904170338.1643894-1-simon.marchi@polymtl.ca>

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

We already have some generated files using the -gen.c suffix.  I think
it's useful to quickly spot that a file is generated and should
generally not be modified by hand.  Change the output bison files to use
that suffix too, as well as ada-lex.c while at it.

The other reason I want to do this change is that I want to move as much
C++ code out of the .y files, into dedicated C++ files.  Logically, I
would move code out from foo-exp.y into a new file called foo-exp.c.
Naming the generated file foo-exp-gen.c instead of foo-exp.c allows me
to do this.

Until now, our own %.c: %.y and %.c: %.l pattern rules overrode make's
built-in rules of the same name.  Renaming ours to %-gen.c re-enables
the built-in ones, which is a problem for my intended use case of having
a hand-written <source>/foo-exp.c, as make would generate
<build>/foo-exp.c from <source>/foo-exp.y, thus hiding
<source>/foo-exp.c.  Cancel the built-in rules to avoid this.

Change-Id: I2a80e9e4c73c6a19b0e5a86b1eb2e28b9e9ee6bb
---
 gdb/.gitignore  | 18 ++++++++---------
 gdb/Makefile.in | 53 ++++++++++++++++++++++++++++---------------------
 gdb/ada-exp.y   |  4 ++--
 3 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/gdb/.gitignore b/gdb/.gitignore
index a68ed4e33178..c4d0f0595448 100644
--- a/gdb/.gitignore
+++ b/gdb/.gitignore
@@ -5,16 +5,16 @@
 /version.c
 /xml-builtin.c
 
-/ada-exp.c
-/ada-lex.c
-/c-exp.c
-/cp-name-parser.c
-/d-exp.c
-/f-exp.c
+/ada-exp-gen.c
+/ada-lex-gen.c
+/c-exp-gen.c
+/cp-name-parser-gen.c
+/d-exp-gen.c
+/f-exp-gen.c
 /gdb
 /gcore
-/go-exp.c
+/go-exp-gen.c
 /init.c
 /jit-reader.h
-/m2-exp.c
-/p-exp.c
+/m2-exp-gen.c
+/p-exp-gen.c
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index d1574ec2d2cb..aeafb9394d7b 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -128,8 +128,8 @@ COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $(CXXFLAGS) \
 
 YACC = @YACC@
 
-# This is used to rebuild ada-lex.c from ada-lex.l.  If the program is
-# not defined, but ada-lex.c is present, compilation will continue,
+# This is used to rebuild ada-lex-gen.c from ada-lex.l.  If the program
+# is not defined, but ada-lex-gen.c is present, compilation will continue,
 # possibly with a warning.
 FLEX = flex
 
@@ -2058,19 +2058,19 @@ REQUIRED_SUBDIRS = doc | testsuite | data-directory
 
 # Parser intermediate files.
 YYFILES = \
-	ada-exp.c \
-	ada-lex.c \
-	c-exp.c \
-	cp-name-parser.c \
-	d-exp.c \
-	f-exp.c \
-	go-exp.c \
-	m2-exp.c \
-	p-exp.c
-
-# ada-lex.c is included by another file, so it shouldn't wind up as a
-# .o itself.
-YYOBJ = $(filter-out ada-lex.o,$(patsubst %.c,%.o,$(YYFILES)))
+	ada-exp-gen.c \
+	ada-lex-gen.c \
+	c-exp-gen.c \
+	cp-name-parser-gen.c \
+	d-exp-gen.c \
+	f-exp-gen.c \
+	go-exp-gen.c \
+	m2-exp-gen.c \
+	p-exp-gen.c
+
+# ada-lex-gen.c is included by another file, so it shouldn't wind up as
+# a .o itself.
+YYOBJ = $(filter-out ada-lex-gen.o,$(patsubst %.c,%.o,$(YYFILES)))
 
 # Things which need to be built when making a distribution.
 
@@ -2079,7 +2079,7 @@ DISTSTUFF = $(YYFILES)
 
 # All generated files which can be included by another file.
 generated_files = \
-	ada-lex.c \
+	ada-lex-gen.c \
 	config.h \
 	jit-reader.h \
 	$(NAT_GENERATED_FILES) \
@@ -2339,7 +2339,7 @@ INIT_FILES_FILTER_OUT = \
 
 INIT_FILES = \
 	$(patsubst %.o,%.c, \
-	  $(patsubst %-exp.o,%-exp.y, \
+	  $(patsubst %-exp-gen.o,%-exp.y, \
 	    $(filter-out $(INIT_FILES_FILTER_OUT), $(COMMON_OBS))))
 
 init.c: stamp-init; @true
@@ -2678,15 +2678,22 @@ po/$(PACKAGE).pot: force
 #
 # YACC/LEX dependencies
 #
-# LANG-exp.c is generated in objdir from LANG-exp.y if it doesn't
-# exist in srcdir, then compiled in objdir to LANG-exp.o.  If we
-# said LANG-exp.c rather than ./c-exp.c some makes would
-# sometimes re-write it into $(srcdir)/c-exp.c.  Remove bogus
+# LANG-exp-gen.c is generated in objdir from LANG-exp.y if it doesn't
+# exist in srcdir, then compiled in objdir to LANG-exp-gen.o.  If we
+# said LANG-exp-gen.c rather than ./c-exp-gen.c some makes would
+# sometimes re-write it into $(srcdir)/c-exp-gen.c.  Remove bogus
 # decls for malloc/realloc/free which conflict with everything else.
-# Strictly speaking c-exp.c should therefore depend on
+# Strictly speaking c-exp-gen.c should therefore depend on
 # Makefile.in, but that was a pretty big annoyance.
 
+# Cancel make's built-in rules for producing a .c file from a .y or .l
+# file, to avoid them producing a <build>/foo-exp.c file from
+# <source>/foo-exp.y, when we also have a hand-written <source>/foo-exp.c
+# file.
 %.c: %.y
+%.c: %.l
+
+%-gen.c: %.y
 	$(ECHO_YACC) $(SHELL) $(YLWRAP) $< y.tab.c $@.tmp -- \
 		$(YACC) $(YFLAGS) || (rm -f $@.tmp; false)
 	@sed -e '/extern.*malloc/d' \
@@ -2705,7 +2712,7 @@ po/$(PACKAGE).pot: force
 	  < $@.tmp > $@.new && \
 	  rm -f $@.tmp && \
 	  mv $@.new $@
-%.c: %.l
+%-gen.c: %.l
 	$(ECHO_LEX) $(FLEX) -t $< > $@.tmp || (rm -f $@.tmp; false)
 	@sed -e '/extern.*malloc/d' \
 	     -e '/extern.*realloc/d' \
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 7fd0e6d7c7db..bffe94a8de9b 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1234,7 +1234,7 @@ primary	:	'*' primary		%prec '.'
 
 %%
 
-/* yylex defined in ada-lex.c: Reads one token, getting characters */
+/* yylex defined in ada-lex-gen.c: Reads one token, getting characters */
 /* through lexptr.  */
 
 /* Remap normal flex interface names (yylex) as well as gratuitously */
@@ -1254,7 +1254,7 @@ primary	:	'*' primary		%prec '.'
 /* The following kludge was found necessary to prevent conflicts between */
 /* defs.h and non-standard stdlib.h files.  */
 #define qsort __qsort__dummy
-#include "ada-lex.c"
+#include "ada-lex-gen.c"
 
 int
 ada_parse (struct parser_state *par_state)
-- 
2.55.0


  parent reply	other threads:[~2026-09-04 17:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04 16:56 [PATCH 00/17] Move C++ support code out of .y files simon.marchi
2026-09-04 16:56 ` [PATCH 01/17] gdb/ada-exp-parser: remove name_info struct simon.marchi
2026-09-04 16:56 ` [PATCH 02/17] gdb: replace parse_type macros with functions simon.marchi
2026-09-04 16:56 ` simon.marchi [this message]
2026-09-04 16:56 ` [PATCH 04/17] gdb: move parser output post-processing to a script simon.marchi
2026-09-05  0:38   ` Kevin Buettner
2026-09-05  3:59     ` Simon Marchi
2026-09-04 16:56 ` [PATCH 05/17] gdb: let the parser and lexer generators prefix their symbols simon.marchi
2026-09-04 16:56 ` [PATCH 06/17] gdb: separate cp-name-parser's symbol prefix with an underscore simon.marchi
2026-09-04 16:56 ` [PATCH 07/17] gdb: make $(YACC) and $(FLEX) generate headers simon.marchi
2026-09-04 16:56 ` [PATCH 08/17] gdb: add check for stale build generated files simon.marchi
2026-09-04 16:56 ` [PATCH 09/17] gdb: move cp-name-parser.y's support code to cp-name-parser.c simon.marchi
2026-09-04 16:56 ` [PATCH 10/17] gdb: rename LANG-exp.y to LANG-exp-parser.y simon.marchi
2026-09-04 16:56 ` [PATCH 11/17] gdb: move c-exp-parser.y's support code to c-exp-parser.c simon.marchi
2026-09-04 16:56 ` [PATCH 12/17] gdb: move ada-exp-parser.y's support code to ada-exp-parser.c simon.marchi
2026-09-05  0:16   ` Kevin Buettner
2026-09-04 16:56 ` [PATCH 13/17] gdb: move d-exp-parser.y's support code to d-exp-parser.c simon.marchi
2026-09-04 16:56 ` [PATCH 14/17] gdb: move f-exp-parser.y's support code to f-exp-parser.c simon.marchi
2026-09-04 16:56 ` [PATCH 15/17] gdb: move go-exp-parser.y's support code to go-exp-parser.c simon.marchi
2026-09-04 16:56 ` [PATCH 16/17] gdb: move m2-exp-parser.y's support code to m2-exp-parser.c simon.marchi
2026-09-05  0:30   ` Kevin Buettner
2026-09-05  4:04     ` Simon Marchi
2026-09-04 16:56 ` [PATCH 17/17] gdb: move p-exp-parser.y's support code to p-exp-parser.c simon.marchi
2026-09-05  0:29   ` Kevin Buettner
2026-09-05  0:50 ` [PATCH 00/17] Move C++ support code out of .y files Kevin Buettner

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=20260904170338.1643894-4-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