From: Nick Bowler Date: Tue, 18 Jul 2023 02:33:03 +0000 (-0400) Subject: libcdecl: Avoid redundant string literal in yyerror. X-Git-Tag: v1.3~113 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/1d1912971e771773fa8041bddd100065bfb752be libcdecl: Avoid redundant string literal in yyerror. The T_LEX_ERROR string literal in yyerror won't be merged with the now-duplicate string in the token name table; use the appropriate indirection to shave off some bytes. --- diff --git a/src/parse.y b/src/parse.y index b77cfbb..abfccd2 100644 --- a/src/parse.y +++ b/src/parse.y @@ -76,6 +76,7 @@ const char *cdecl__token_name(unsigned token); } %{ +static void yyerror(YYLTYPE *, yyscan_t, struct cdecl **, const char *); static void free_decl(struct cdecl *); static void free_declspec(struct cdecl_declspec *x) @@ -141,15 +142,6 @@ void cdecl__free(struct cdecl *decl) { free_decl(decl); } - -static void -yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err) -{ - if (strstr(err, "T_LEX_ERROR")) - return; - - cdecl__err(CDECL_ENOPARSE, "%s", err); -} %} %destructor { free($$); } @@ -614,3 +606,12 @@ const char *cdecl__token_name(unsigned token) { return yytname[YYTRANSLATE(token)]; } + +static void +yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err) +{ + if (strstr(err, yytname[YYTRANSLATE(T_LEX_ERROR)])) + return; + + cdecl__err(CDECL_ENOPARSE, "%s", err); +}