[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/21] yysymbol_type_t: always assign an enumerator
From: |
Akim Demaille |
Subject: |
[PATCH 10/21] yysymbol_type_t: always assign an enumerator |
Date: |
Wed, 1 Apr 2020 08:37:36 +0200 |
Currently we define enumerators only for symbols that have an
identifier. That rules out tokens such as '+', and nonterminals such
as foo-bar and foo.bar. As a consequence we are taking chances: the
compiler might compile yysymbol_type_t as too small an integral type
for some symbol codes.
* data/skeletons/bison.m4 (b4_symbol_sid): Forge a unique symbol
identifier for symbols that don't have an ID.
---
data/skeletons/bison.m4 | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4
index d54ea2b7..1bd30dd1 100644
--- a/data/skeletons/bison.m4
+++ b/data/skeletons/bison.m4
@@ -407,8 +407,10 @@ m4_define([_b4_symbol],
# b4_symbol_sid(NUM)
# ------------------
-# Build the symbol ID based for this symbol. Return empty
-# if that would produce an invalid symbol.
+# Build the symbol ID based for this symbol. It must always exist,
+# otherwise some symbols might not be represented in the enum, which
+# might be compiled into too small a type to contain all the symbol
+# numbers.
m4_define([b4_symbol_sid],
[m4_case([$1],
[-2], [[YYSYMBOL_YYEMPTY]],
@@ -417,8 +419,9 @@ m4_define([b4_symbol_sid],
[$accept], [[YYSYMBOL_YYACCEPT]],
[error], [[YYSYMBOL_YYERROR]],
[$undefined], [[YYSYMBOL_YYUNDEF]],
- [m4_quote(b4_symbol_if([$1], [has_id],
- [[YYSYMBOL_]]m4_quote(_b4_symbol([$1],
[id]))))])])])
+ [b4_symbol_if([$1], [has_id],
+ [[YYSYMBOL_]]m4_quote(_b4_symbol([$1],
[id])),
+
[[YYSYMBOL_$1_][]m4_bpatsubst(m4_quote(_b4_symbol([$1], [tag])),
[[^a-zA-Z_0-9]], [_])])])])])
# b4_symbol(NUM, FIELD)
--
2.26.0
- [PATCH 01/21] style: comment changes about token numbers, (continued)
- [PATCH 01/21] style: comment changes about token numbers, Akim Demaille, 2020/04/01
- [PATCH 02/21] yacc.c: introduce an enum that defines the symbol's number, Akim Demaille, 2020/04/01
- [PATCH 04/21] yacc.c: use yysymbol_type_t instead of int for yytoken, Akim Demaille, 2020/04/01
- [PATCH 03/21] regen, Akim Demaille, 2020/04/01
- [PATCH 06/21] regen, Akim Demaille, 2020/04/01
- [PATCH 05/21] yacc.c: also define a symbol number for the empty token, Akim Demaille, 2020/04/01
- [PATCH 08/21] regen, Akim Demaille, 2020/04/01
- [PATCH 07/21] yacc.c: prefer YYSYMBOL_YYERROR to YYSYMBOL_error, Akim Demaille, 2020/04/01
- [PATCH 09/21] bistromathic: use symbol numbers instead of YYTRANSLATE, Akim Demaille, 2020/04/01
- [PATCH 11/21] regen, Akim Demaille, 2020/04/01
- [PATCH 10/21] yysymbol_type_t: always assign an enumerator,
Akim Demaille <=
- [PATCH 12/21] yacc.c: revert to not using yysymbol_type_t in the yytranslate table, Akim Demaille, 2020/04/01
- [PATCH 13/21] regen, Akim Demaille, 2020/04/01
- [PATCH 14/21] yacc.c: fix more errors from make maintainer-check-g++, Akim Demaille, 2020/04/01
- [PATCH 15/21] regen, Akim Demaille, 2020/04/01
- [PATCH 16/21] glr.c: use yysymbol_type_t, YYSYMBOL_YYEOF etc., Akim Demaille, 2020/04/01
- [PATCH 18/21] regen, Akim Demaille, 2020/04/01
- [PATCH 17/21] glr.c, yacc.c: propagate yysymbol_type_t, Akim Demaille, 2020/04/01
- [PATCH 19/21] glr.c: remove the yySymbol alias, Akim Demaille, 2020/04/01
- [PATCH 21/21] c++: replace symbol_number_type with symbol_type_type, Akim Demaille, 2020/04/01
- [PATCH 20/21] c++: also use symbol_type_type, Akim Demaille, 2020/04/01