This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Centralize yacc interface names remapping (yyparse, yylex, yyerror, etc)
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: <gdb-patches at sourceware dot org>
- Date: Mon, 18 Apr 2016 10:10:59 -0400
- Subject: Re: [PATCH] Centralize yacc interface names remapping (yyparse, yylex, yyerror, etc)
- Authentication-results: sourceware.org; auth=none
- References: <1460766513-15104-1-git-send-email-palves at redhat dot com>
On 16-04-15 08:28 PM, Pedro Alves wrote:
> This factors out all the yy-variables remapping to a single file,
> instead of each parser having to do the same, with different prefixes.
>
> With this, a parser just needs to define the prefix they want and
> include yy-remap.h, which does the dirty job.
>
> Note this renames the c_error, ada_error, etc. functions. Writting
"Writing"
> the remapping pattern as:
>
> #define yyerror GDB_YY_REMAP(error)
>
> instead of:
>
> #define yyerror GDB_YY_REMAP(yyerror)
>
> would have avoided the renaming. However, that would be problematic
> if we have a macro 'foo' in scope, when we write:
>
> #define yyfoo GDB_YY_REMAP(foo)
>
> as that would expand 'foo'.
>
> The c_yyerror etc. naming end ups indicating that this is a yacc
> related function more clearly, so feels like a good change, anyway.
Wow, it makes look really clean! I now almost looks like it's not a hack :).
> +/* Define GDB_YY_REMAP_PREFIX to the desired remapping prefix before
> + including this file. */
What about adding an #ifndef/#error for GDB_YY_REMAP_PREFIX? The error would be
clearer than what we get otherwise if a file omits defining GDB_YY_REMAP_PREFIX:
c-lang.o:(.rodata+0x578): undefined reference to `c_yyerror'
c-lang.o:(.rodata+0x6b8): undefined reference to `c_yyerror'
c-lang.o:(.rodata+0x7f8): undefined reference to `c_yyerror'
c-lang.o:(.rodata+0x938): undefined reference to `c_yyerror'
objc-lang.o:(.rodata+0x558): undefined reference to `c_yyerror'
opencl-lang.o:(.rodata+0x5f8): more undefined references to `c_yyerror' follow
...
> +#define GDB_YY_REMAP_2(PREFIX, YYSYM) PREFIX ## YYSYM
> +#define GDB_YY_REMAP_1(PREFIX, YYSYM) GDB_YY_REMAP_2(PREFIX, YYSYM)
> +#define GDB_YY_REMAP(YYSYM) GDB_YY_REMAP_1(GDB_YY_REMAP_PREFIX, YYSYM)
> +
> +#define yymaxdepth GDB_YY_REMAP(yymaxdepth)
> +#define yyparse GDB_YY_REMAP(yyparse)
> +#define yylex GDB_YY_REMAP(yylex)
> +#define yyerror GDB_YY_REMAP(yyerror)
> +#define yylval GDB_YY_REMAP(yylval)
> +#define yychar GDB_YY_REMAP(yychar)
> +#define yydebug GDB_YY_REMAP(yydebug)
> +#define yypact GDB_YY_REMAP(yypact)
> +#define yyr1 GDB_YY_REMAP(yyr1)
> +#define yyr2 GDB_YY_REMAP(yyr2)
> +#define yydef GDB_YY_REMAP(yydef)
> +#define yychk GDB_YY_REMAP(yychk)
> +#define yypgo GDB_YY_REMAP(yypgo)
> +#define yyact GDB_YY_REMAP(yyact)
> +#define yyexca GDB_YY_REMAP(yyexca)
> +#define yyerrflag GDB_YY_REMAP(yyerrflag)
> +#define yynerrs GDB_YY_REMAP(yynerrs)
> +#define yyps GDB_YY_REMAP(yyps)
> +#define yypv GDB_YY_REMAP(yypv)
> +#define yys GDB_YY_REMAP(yys)
> +#define yy_yys GDB_YY_REMAP(yy_yys)
> +#define yystate GDB_YY_REMAP(yystate)
> +#define yytmp GDB_YY_REMAP(yytmp)
> +#define yyv GDB_YY_REMAP(yyv)
> +#define yy_yyv GDB_YY_REMAP(yy_yyv)
> +#define yyval GDB_YY_REMAP(yyval)
> +#define yylloc GDB_YY_REMAP(yylloc)
> +#define yyreds GDB_YY_REMAP(yyreds) /* With YYDEBUG defined */
> +#define yytoks GDB_YY_REMAP(yytoks) /* With YYDEBUG defined */
> +#define yyname GDB_YY_REMAP(yyname) /* With YYDEBUG defined */
> +#define yyrule GDB_YY_REMAP(yyrule) /* With YYDEBUG defined */
> +#define yylhs GDB_YY_REMAP(yylhs)
> +#define yylen GDB_YY_REMAP(yylen)
> +#define yydefred GDB_YY_REMAP(yydefred)
> +#define yydgoto GDB_YY_REMAP(yydgoto)
> +#define yysindex GDB_YY_REMAP(yysindex)
> +#define yyrindex GDB_YY_REMAP(yyrindex)
> +#define yygindex GDB_YY_REMAP(yygindex)
> +#define yytable GDB_YY_REMAP(yytable)
> +#define yycheck GDB_YY_REMAP(yycheck)
> +#define yyss GDB_YY_REMAP(yyss)
> +#define yysslim GDB_YY_REMAP(yysslim)
> +#define yyssp GDB_YY_REMAP(yyssp)
> +#define yystacksize GDB_YY_REMAP(yystacksize)
> +#define yyvs GDB_YY_REMAP(yyvs)
> +#define yyvsp GDB_YY_REMAP(yyvsp)
Mininit: I think these could be vertically aligned a bit better.
Otherwise, looks very good!