Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Cc: simon.marchi@polymtl.ca
Subject: Re: [PATCH 04/17] gdb: move parser output post-processing to a script
Date: Fri, 4 Sep 2026 17:38:35 -0700	[thread overview]
Message-ID: <20260904173835.303e34d8@f44-mesa-1> (raw)
In-Reply-To: <20260904170338.1643894-5-simon.marchi@polymtl.ca>

On Fri,  4 Sep 2026 12:56:36 -0400
simon.marchi@polymtl.ca wrote:

> diff --git a/gdb/post-process-parser-output.sh b/gdb/post-process-parser-output.sh
> new file mode 100755
> index 000000000000..b246e63ddff1
> --- /dev/null
> +++ b/gdb/post-process-parser-output.sh
> @@ -0,0 +1,67 @@
> +#!/bin/sh
> +
> +# Copyright (C) 2026 Free Software Foundation, Inc.
> +#
> +# This file is part of GDB.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# Post-process a file produced by flex or bison/byacc, reading it from
> +# standard input and writing the result to standard output.
> +#
> +# Usage:
> +#
> +#    ./post-process-parser-output.sh GENERATOR NAME < INPUT > OUTPUT
> +#
> +# Where GENERATOR is "bison" (regardless of whether we're using the actual
> +# bison or byacc) or "flex", and NAME is the name of the parser (e.g.
> +# "cp-name-parser"), used to make the global symbols names bison produces
> +# unique.
> +
> +set -e
> +
> +generator="$1"
> +
> +# Convert e.g. "cp-name-parser" to "cp_name_parser".
> +name=$(echo "$2" | sed -e 's/-/_/g')
> +
> +common='
> +/extern.*malloc/d
> +/extern.*realloc/d
> +/extern.*free/d
> +/include.*malloc.h/d
> +s/\([^x]\)malloc/\1xmalloc/g
> +s/\([^x]\)realloc/\1xrealloc/g
> +s/\([ \t;,(]\)free\([ \t]*[&(),]\)/\1xfree\2/g
> +s/\([ \t;,(]\)free$/\1xfree/g
> +'
> +
> +case "$generator" in
> +    bison)
> +	sed -e "$common" \
> +	    -e '/^#line.*y.tab.c/d' \
> +	    -e 's/YY_NULL/YY_NULLPTR/g' \

Another (pre-existing) nit found by AI code review:

  post-process-parser-output.sh:53: s/YY_NULL/YY_NULLPTR/g also
  matches inside YY_NULLPTR, producing YY_NULLPTRPTR; harmless
  (guarded by #ifndef), faithfully carried over from the old Makefile
  sed.  Opportunity to fix with word boundaries.

> +	    -e "s/YYSTYPE/${name}_YYSTYPE/g" \
> +	    -e "s/yyalloc/${name}_yyalloc/g" \
> +	    -e "s/yysymbol_kind_t/${name}_yysymbol_kind_t/g"
> +	;;
> +    flex)
> +	sed -e "$common" \
> +	    -e 's/yy_flex_xrealloc/yyxrealloc/g'
> +	;;
> +    *)
> +	echo "$0: unknown parser generator \"$generator\"" >&2
> +	exit 1
> +	;;
> +esac
> -- 
> 2.55.0
> 


  reply	other threads:[~2026-09-05  0:39 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 ` [PATCH 03/17] gdb: suffix flex/bison output files with -gen.c simon.marchi
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 [this message]
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=20260904173835.303e34d8@f44-mesa-1 \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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