mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-14 23:03:04 +00:00
api.prefix.
* data/c.m4 (b4_api_prefix, b4_api_PREFIX): New. (b4_prefix, b4_union_name, b4_token_enums, b4_declare_yylstype): Use them. * data/glr.c, data/yacc.c, data/glr.cc, data/lalr1.cc: Use them to change the prefix of exported preprocessor symbols. * src/getargs.c (usage): Ditto. * tests/headers.at (Several parsers): New. * tests/local.at (AT_API_PREFIX): New. AT_YYSTYPE, AT_YYLTYPE): Adjust. * doc/bison.texi (Multiple Parsers): Move documentation of %name-prefix to... (Table of Symbols): here. (Multiple Parsers): Document api.prefix. (%define Summary): Point to it. Use @code for variable names. (Bison Options): -p/--name-prefix are obsoleted. * NEWS: Announce api.prefix.
This commit is contained in:
67
data/c.m4
67
data/c.m4
@@ -84,11 +84,24 @@ m4_define([b4_identification],
|
||||
## Default values. ##
|
||||
## ---------------- ##
|
||||
|
||||
# If the %union is not named, its name is YYSTYPE.
|
||||
m4_define_default([b4_union_name], [YYSTYPE])
|
||||
# b4_api_prefix, b4_api_PREFIX
|
||||
# ----------------------------
|
||||
# Corresponds to %define api.prefix
|
||||
b4_percent_define_default([[api.prefix]], [[yy]])
|
||||
m4_define([b4_api_prefix],
|
||||
[b4_percent_define_get([[api.prefix]])])
|
||||
m4_define([b4_api_PREFIX],
|
||||
[m4_toupper(b4_api_prefix)])
|
||||
|
||||
|
||||
# b4_prefix
|
||||
# ---------
|
||||
# If the %name-prefix is not given, it is api.prefix.
|
||||
m4_define_default([b4_prefix], [b4_api_prefix])
|
||||
|
||||
# If the %union is not named, its name is YYSTYPE.
|
||||
m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE])
|
||||
|
||||
# If the %name-prefix is not given, it is yy.
|
||||
m4_define_default([b4_prefix], [yy])
|
||||
|
||||
## ------------------------ ##
|
||||
## Pure/impure interfaces. ##
|
||||
@@ -232,18 +245,18 @@ m4_define([b4_token_enum],
|
||||
# Output the definition of the tokens (if there are) as enums.
|
||||
m4_define([b4_token_enums],
|
||||
[m4_if([$#$1], [1], [],
|
||||
[/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
[[/* Tokens. */
|
||||
#ifndef ]b4_api_PREFIX[TOKENTYPE
|
||||
# define ]b4_api_PREFIX[TOKENTYPE
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
know about them. */
|
||||
enum yytokentype {
|
||||
m4_map_sep([ b4_token_enum], [,
|
||||
enum ]b4_api_prefix[tokentype {
|
||||
]m4_map_sep([ b4_token_enum], [,
|
||||
],
|
||||
[$@])
|
||||
[$@])[
|
||||
};
|
||||
#endif
|
||||
])])
|
||||
]])])
|
||||
|
||||
|
||||
# b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
|
||||
@@ -533,39 +546,39 @@ b4_locations_if([, yylocationp])[]b4_user_args[);
|
||||
## -------------- ##
|
||||
|
||||
# b4_declare_yylstype
|
||||
# ------------------
|
||||
# -------------------
|
||||
# Declarations that might either go into the header (if --defines) or
|
||||
# in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc.
|
||||
m4_define([b4_declare_yylstype],
|
||||
[[#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
|
||||
]m4_ifdef([b4_stype],
|
||||
[[typedef union ]b4_union_name[
|
||||
{
|
||||
]b4_user_stype[
|
||||
} YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1]],
|
||||
} ]b4_api_PREFIX[STYPE;
|
||||
# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]],
|
||||
[m4_if(b4_tag_seen_flag, 0,
|
||||
[[typedef int YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1]])])[
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
[[typedef int ]b4_api_PREFIX[STYPE;
|
||||
# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]])])[
|
||||
# define ]b4_api_prefix[stype ]b4_api_PREFIX[STYPE /* obsolescent; will be withdrawn */
|
||||
# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
|
||||
#endif]b4_locations_if([[
|
||||
|
||||
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
|
||||
typedef struct YYLTYPE
|
||||
#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED
|
||||
typedef struct ]b4_api_PREFIX[LTYPE
|
||||
{
|
||||
int first_line;
|
||||
int first_column;
|
||||
int last_line;
|
||||
int last_column;
|
||||
} YYLTYPE;
|
||||
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYLTYPE_IS_DECLARED 1
|
||||
# define YYLTYPE_IS_TRIVIAL 1
|
||||
} ]b4_api_PREFIX[LTYPE;
|
||||
# define ]b4_api_prefix[ltype ]b4_api_PREFIX[LTYPE /* obsolescent; will be withdrawn */
|
||||
# define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1
|
||||
# define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1
|
||||
#endif]])
|
||||
|
||||
b4_pure_if([], [[extern YYSTYPE ]b4_prefix[lval;
|
||||
]b4_locations_if([[extern YYLTYPE ]b4_prefix[lloc;]])])[]dnl
|
||||
b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval;
|
||||
]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl
|
||||
])
|
||||
|
||||
# b4_declare_yydebug
|
||||
|
||||
@@ -188,6 +188,14 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
|
||||
]b4_identification
|
||||
|
||||
b4_percent_code_get([[top]])[
|
||||
]m4_if(b4_api_prefix, [yy], [],
|
||||
[[/* Substitute the type names. */
|
||||
#define YYSTYPE ]b4_api_PREFIX[STYPE
|
||||
#define YYSTYPE_IS_TRIVIAL ]b4_api_PREFIX[STYPE_IS_TRIVIAL
|
||||
#define YYSTYPE_IS_DECLARED ]b4_api_PREFIX[STYPE_IS_DECLARED]b4_locations_if([[
|
||||
#define YYLTYPE ]b4_api_PREFIX[LTYPE
|
||||
#define YYLTYPE_IS_TRIVIAL ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
|
||||
#define YYLTYPE_IS_DECLARED ]b4_api_PREFIX[LTYPE_IS_DECLARED]])])[
|
||||
]m4_if(b4_prefix, [yy], [],
|
||||
[[/* Substitute the variable and function names. */
|
||||
#define yyparse ]b4_prefix[parse
|
||||
|
||||
14
data/glr.cc
14
data/glr.cc
@@ -269,7 +269,7 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
|
||||
{
|
||||
public:
|
||||
/// Symbol semantic values.
|
||||
#ifndef YYSTYPE
|
||||
#ifndef ]b4_api_PREFIX[STYPE
|
||||
]m4_ifdef([b4_stype],
|
||||
[ union semantic_type
|
||||
{
|
||||
@@ -277,9 +277,9 @@ b4_user_stype
|
||||
};],
|
||||
[m4_if(b4_tag_seen_flag, 0,
|
||||
[[ typedef int semantic_type;]],
|
||||
[[ typedef YYSTYPE semantic_type;]])])[
|
||||
[[ typedef ]b4_api_PREFIX[STYPE semantic_type;]])])[
|
||||
#else
|
||||
typedef YYSTYPE semantic_type;
|
||||
typedef ]b4_api_PREFIX[STYPE semantic_type;
|
||||
#endif
|
||||
/// Symbol locations.
|
||||
typedef ]b4_percent_define_get([[location_type]],
|
||||
@@ -350,11 +350,11 @@ b4_user_stype
|
||||
b4_percent_define_flag_if([[global_tokens_and_yystype]],
|
||||
[b4_token_defines(b4_tokens)])
|
||||
[
|
||||
#ifndef YYSTYPE
|
||||
# define YYSTYPE ]b4_namespace_ref[::]b4_parser_class_name[::semantic_type
|
||||
#ifndef ]b4_api_PREFIX[STYPE
|
||||
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class_name[::semantic_type
|
||||
#endif
|
||||
#ifndef YYLTYPE
|
||||
# define YYLTYPE ]b4_namespace_ref[::]b4_parser_class_name[::location_type
|
||||
#ifndef ]b4_api_PREFIX[LTYPE
|
||||
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class_name[::location_type
|
||||
#endif
|
||||
|
||||
]b4_namespace_close[
|
||||
|
||||
@@ -69,7 +69,7 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
|
||||
{
|
||||
public:
|
||||
/// Symbol semantic values.
|
||||
#ifndef YYSTYPE
|
||||
#ifndef ]b4_api_PREFIX[STYPE
|
||||
]m4_ifdef([b4_stype],
|
||||
[ union semantic_type
|
||||
{
|
||||
@@ -77,9 +77,9 @@ b4_user_stype
|
||||
};],
|
||||
[m4_if(b4_tag_seen_flag, 0,
|
||||
[[ typedef int semantic_type;]],
|
||||
[[ typedef YYSTYPE semantic_type;]])])[
|
||||
[[ typedef ]b4_api_PREFIX[STYPE semantic_type;]])])[
|
||||
#else
|
||||
typedef YYSTYPE semantic_type;
|
||||
typedef ]b4_api_PREFIX[STYPE semantic_type;
|
||||
#endif
|
||||
/// Symbol locations.
|
||||
typedef ]b4_percent_define_get([[location_type]],
|
||||
@@ -262,9 +262,9 @@ b4_user_stype
|
||||
]b4_percent_define_flag_if([[global_tokens_and_yystype]],
|
||||
[b4_token_defines(b4_tokens)
|
||||
|
||||
#ifndef YYSTYPE
|
||||
#ifndef ]b4_api_PREFIX[STYPE
|
||||
/* Redirection for backward compatibility. */
|
||||
# define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
|
||||
# define ]b4_api_PREFIX[STYPE b4_namespace_ref::b4_parser_class_name::semantic_type
|
||||
#endif
|
||||
])[
|
||||
]b4_percent_code_get([[provides]])[
|
||||
@@ -597,7 +597,7 @@ m4_popdef([b4_at_dollar])])dnl
|
||||
{
|
||||
YYCDEBUG << "Reading a token: ";
|
||||
yychar = ]b4_c_function_call([yylex], [int],
|
||||
[[YYSTYPE*], [&yylval]][]dnl
|
||||
[b4_api_PREFIX[STYPE*], [&yylval]][]dnl
|
||||
b4_locations_if([, [[location*], [&yylloc]]])dnl
|
||||
m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
||||
}
|
||||
|
||||
10
data/yacc.c
10
data/yacc.c
@@ -307,7 +307,15 @@ b4_copyright([Bison implementation for Yacc-like parsers in C],
|
||||
|
||||
]b4_identification
|
||||
b4_percent_code_get([[top]])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
m4_if(b4_api_prefix, [yy], [],
|
||||
[[/* Substitute the type names. */
|
||||
#define YYSTYPE ]b4_api_PREFIX[STYPE
|
||||
#define YYSTYPE_IS_TRIVIAL ]b4_api_PREFIX[STYPE_IS_TRIVIAL
|
||||
#define YYSTYPE_IS_DECLARED ]b4_api_PREFIX[STYPE_IS_DECLARED]b4_locations_if([[
|
||||
#define YYLTYPE ]b4_api_PREFIX[LTYPE
|
||||
#define YYLTYPE_IS_TRIVIAL ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
|
||||
#define YYLTYPE_IS_DECLARED ]b4_api_PREFIX[LTYPE_IS_DECLARED]])])[
|
||||
]m4_if(b4_prefix, [yy], [],
|
||||
[[/* Substitute the variable and function names. */]b4_pull_if([[
|
||||
#define yyparse ]b4_prefix[parse]])b4_push_if([[
|
||||
#define yypush_parse ]b4_prefix[push_parse]b4_pull_if([[
|
||||
|
||||
Reference in New Issue
Block a user