]> git.draconx.ca Git - cdecl99.git/blobdiff - src/parse.y
libcdecl: Move another error message into the string table.
[cdecl99.git] / src / parse.y
index 14d593ef1622f57a97d0b5bbb26023a07ce0fafb..6d349f79ef1bc8537280c92066a349f0429ff20f 100644 (file)
@@ -1,7 +1,7 @@
 %code top {
 /*
  *  Parser for C declarations.
- *  Copyright © 2011-2012, 2021, 2023 Nick Bowler
+ *  Copyright © 2011-2012, 2021, 2023-2024 Nick Bowler
  *
  *  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
 #include "cdecl-internal.h"
 #include "errmsg.h"
 
-#define FAIL(msg) do { \
-       yyerror(&yylloc, NULL, NULL, msg); \
-       YYERROR; \
-} while (0)
-
 /*
  * Allocate a parse tree node via cdecl__alloc_item.
  *
@@ -120,6 +115,7 @@ static size_t yytnamerr_copy(char *dst, const char *src)
 
 %code requires {
 #include <inttypes.h>
+#include <stdbool.h>
 }
 
 %code provides {
@@ -131,7 +127,7 @@ const char *cdecl__token_name(unsigned token);
 %union {
        uintmax_t uintval;
        unsigned spectype;
-       _Bool boolval;
+       bool boolval;
        struct cdecl_declspec *declspec;
        struct cdecl_declarator *declarator;
        struct cdecl *decl;
@@ -592,8 +588,10 @@ english_array: T_VLA T_ARRAY english_vla T_OF {
 
 array_length: { $$ = 0; }
 array_length: T_UINT {
-       if (!($$ = $1))
-               FAIL(_("array length must be positive"));
+       if (!($$ = $1)) {
+               cdecl__errmsg(CDECL__EZEROARRAY);
+               YYERROR;
+       }
 }
 
 english_vla: T_IDENT | {
@@ -617,11 +615,16 @@ const char *cdecl__token_name(unsigned token)
        return yytname[YYTRANSLATE(token)];
 }
 
-static void
+/*
+ * Current versions of GCC (up to 13) want to inline this function into the
+ * parser even when optimizing for size and the results are not great, so
+ * try to prevent such inlining.
+ */
+CDECL__NOINLINE 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);
+       cdecl__err("%s", err);
 }