mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
* data/c.m4 (b4_c_ansi_args): Recognize functions with no
arguments and output `void'. (b4_c_function): Rename as... (b4_c_function_def): this. (b4_c_function_decl, b4_c_ansi_function_def) (b4_c_ansi_function_decl): New. Change the interpretation of the arguments: before `int, foo', now `int foo, foo'. * data/yacc.c (yyparse): Prototype and define thanks to these. Adjust b4_c_function_def uses. * data/glr.c (yyparse): Likewise, but ANSI only.
This commit is contained in:
14
ChangeLog
14
ChangeLog
@@ -1,3 +1,17 @@
|
||||
2002-10-20 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* data/c.m4 (b4_c_ansi_args): Recognize functions with no
|
||||
arguments and output `void'.
|
||||
(b4_c_function): Rename as...
|
||||
(b4_c_function_def): this.
|
||||
(b4_c_function_decl, b4_c_ansi_function_def)
|
||||
(b4_c_ansi_function_decl): New.
|
||||
Change the interpretation of the arguments: before `int, foo', now
|
||||
`int foo, foo'.
|
||||
* data/yacc.c (yyparse): Prototype and define thanks to these.
|
||||
Adjust b4_c_function_def uses.
|
||||
* data/glr.c (yyparse): Likewise, but ANSI only.
|
||||
|
||||
2002-10-20 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/output.c (prepare): Move the definition of `tokens_number',
|
||||
|
||||
197
data/c.m4
197
data/c.m4
@@ -82,6 +82,30 @@ m4_define([b4_int_type_for],
|
||||
[b4_int_type($1_min, $1_max)])
|
||||
|
||||
|
||||
## ------------------ ##
|
||||
## Decoding options. ##
|
||||
## ------------------ ##
|
||||
|
||||
|
||||
# b4_location_if(IF-TRUE, IF-FALSE)
|
||||
# ---------------------------------
|
||||
# Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
|
||||
m4_define([b4_location_if],
|
||||
[m4_if(b4_locations_flag, [1],
|
||||
[$1],
|
||||
[$2])])
|
||||
|
||||
|
||||
# b4_pure_if(IF-TRUE, IF-FALSE)
|
||||
# -----------------------------
|
||||
# Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
|
||||
m4_define([b4_pure_if],
|
||||
[m4_if(b4_pure, [1],
|
||||
[$1],
|
||||
[$2])])
|
||||
|
||||
|
||||
|
||||
## ------------------------- ##
|
||||
## Assigning token numbers. ##
|
||||
## ------------------------- ##
|
||||
@@ -122,12 +146,105 @@ m4_map([b4_token_define], [$@])
|
||||
])
|
||||
|
||||
|
||||
|
||||
## --------------------------------------------- ##
|
||||
## Defining C functions in both K&R and ANSI-C. ##
|
||||
## --------------------------------------------- ##
|
||||
|
||||
|
||||
# b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
|
||||
# ----------------------------------------------------------
|
||||
# Declare the function NAME.
|
||||
m4_define([b4_c_function_def],
|
||||
[#if defined (__STDC__) || defined (__cplusplus)
|
||||
b4_c_ansi_function_def($@)
|
||||
#else
|
||||
$2
|
||||
$1 (b4_c_knr_formal_names(m4_shiftn(2, $@)))
|
||||
b4_c_knr_formal_decls(m4_shiftn(2, $@))
|
||||
#endif[]dnl
|
||||
])
|
||||
|
||||
|
||||
# b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
|
||||
# ---------------------------------------------------------------
|
||||
# Declare the function NAME in ANSI.
|
||||
m4_define([b4_c_ansi_function_def],
|
||||
[$2
|
||||
$1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl
|
||||
])
|
||||
|
||||
|
||||
# b4_c_ansi_formals([DECL1, NAME1], ...)
|
||||
# --------------------------------------
|
||||
# Output the arguments ANSI-C definition.
|
||||
m4_define([b4_c_ansi_formals],
|
||||
[m4_case([$@],
|
||||
[], [void],
|
||||
[[]], [void],
|
||||
[m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
|
||||
|
||||
m4_define([b4_c_ansi_formal],
|
||||
[$1])
|
||||
|
||||
|
||||
# b4_c_knr_formal_names([DECL1, NAME1], ...)
|
||||
# ------------------------------------------
|
||||
# Output the argument names.
|
||||
m4_define([b4_c_knr_formal_names],
|
||||
[m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
|
||||
|
||||
m4_define([b4_c_knr_formal_name],
|
||||
[$2])
|
||||
|
||||
|
||||
# b4_c_knr_formal_decls([DECL1, NAME1], ...)
|
||||
# ------------------------------------------
|
||||
# Output the K&R argument declarations.
|
||||
m4_define([b4_c_knr_formal_decls],
|
||||
[m4_map_sep([b4_c_knr_formal_decl],
|
||||
[
|
||||
],
|
||||
[$@])])
|
||||
|
||||
m4_define([b4_c_knr_formal_decl],
|
||||
[ $1;])
|
||||
|
||||
|
||||
|
||||
## ------------------------------------------------------------ ##
|
||||
## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
|
||||
## ------------------------------------------------------------ ##
|
||||
|
||||
|
||||
# b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
|
||||
# -----------------------------------------------------------
|
||||
# Declare the function NAME.
|
||||
m4_define([b4_c_function_decl],
|
||||
[#if defined (__STDC__) || defined (__cplusplus)
|
||||
b4_c_ansi_function_decl($@)
|
||||
#else
|
||||
$2 $1 ();
|
||||
#endif[]dnl
|
||||
])
|
||||
|
||||
|
||||
# b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
|
||||
# ----------------------------------------------------------------
|
||||
# Declare the function NAME.
|
||||
m4_define([b4_c_ansi_function_decl],
|
||||
[$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl
|
||||
])
|
||||
|
||||
|
||||
|
||||
|
||||
## --------------------- ##
|
||||
## Calling C functions. ##
|
||||
## --------------------- ##
|
||||
|
||||
|
||||
# b4_c_function_call(NAME, RETURN-VALUE, [TYPE1, NAME1], ...)
|
||||
# b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
|
||||
# -----------------------------------------------------------
|
||||
# Call the function NAME with arguments NAME1, NAME2 etc.
|
||||
m4_define([b4_c_function_call],
|
||||
@@ -135,7 +252,7 @@ m4_define([b4_c_function_call],
|
||||
])
|
||||
|
||||
|
||||
# b4_c_args([TYPE1, NAME1], ...)
|
||||
# b4_c_args([DECL1, NAME1], ...)
|
||||
# ------------------------------
|
||||
# Output the arguments NAME1, NAME2...
|
||||
m4_define([b4_c_args],
|
||||
@@ -143,79 +260,3 @@ m4_define([b4_c_args],
|
||||
|
||||
m4_define([b4_c_arg],
|
||||
[$2])
|
||||
|
||||
|
||||
## ---------------------------------------------- ##
|
||||
## Declaring C functions in both K&R and ANSI-C. ##
|
||||
## ---------------------------------------------- ##
|
||||
|
||||
|
||||
# b4_c_function(NAME, RETURN-VALUE, [TYPE1, NAME1], ...)
|
||||
# ------------------------------------------------------
|
||||
# Declare the function NAME.
|
||||
m4_define([b4_c_function],
|
||||
[$2
|
||||
#if defined (__STDC__) || defined (__cplusplus)
|
||||
$1 (b4_c_ansi_args(m4_shiftn(2, $@)))
|
||||
#else
|
||||
$1 (b4_c_knr_arg_names(m4_shiftn(2, $@)))
|
||||
b4_c_knr_arg_decls(m4_shiftn(2, $@))
|
||||
#endif[]dnl
|
||||
])
|
||||
|
||||
|
||||
# b4_c_ansi_args([TYPE1, NAME1], ...)
|
||||
# -----------------------------------
|
||||
# Output the arguments ANSI-C definition.
|
||||
m4_define([b4_c_ansi_args],
|
||||
[m4_map_sep([b4_c_ansi_arg], [, ], [$@])])
|
||||
|
||||
m4_define([b4_c_ansi_arg],
|
||||
[$1 $2])
|
||||
|
||||
|
||||
# b4_c_knr_args([TYPE1, NAME1], ...)
|
||||
# ----------------------------------
|
||||
# Output the argument names.
|
||||
m4_define([b4_c_knr_arg_names],
|
||||
[m4_map_sep([b4_c_knr_arg_name], [, ], [$@])])
|
||||
|
||||
m4_define([b4_c_knr_arg_name],
|
||||
[$2])
|
||||
|
||||
|
||||
# b4_c_knr_args([TYPE1, NAME1], ...)
|
||||
# ----------------------------------
|
||||
# Output the K&R argument declarations.
|
||||
m4_define([b4_c_knr_arg_decls],
|
||||
[m4_map_sep([b4_c_knr_arg_decl],
|
||||
[
|
||||
],
|
||||
[$@])])
|
||||
|
||||
m4_define([b4_c_knr_arg_decl],
|
||||
[ $1 $2;])
|
||||
|
||||
|
||||
|
||||
## ------------------ ##
|
||||
## Decoding options. ##
|
||||
## ------------------ ##
|
||||
|
||||
|
||||
# b4_location_if(IF-TRUE, IF-FALSE)
|
||||
# ---------------------------------
|
||||
# Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
|
||||
m4_define([b4_location_if],
|
||||
[m4_if(b4_locations_flag, [1],
|
||||
[$1],
|
||||
[$2])])
|
||||
|
||||
|
||||
# b4_pure_if(IF-TRUE, IF-FALSE)
|
||||
# -----------------------------
|
||||
# Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
|
||||
m4_define([b4_pure_if],
|
||||
[m4_if(b4_pure, [1],
|
||||
[$1],
|
||||
[$2])])
|
||||
|
||||
37
data/glr.c
37
data/glr.c
@@ -38,7 +38,12 @@ m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[yylvalp]]][]dnl
|
||||
b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl
|
||||
m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
|
||||
|
||||
m4_define_default([b4_parse_param])
|
||||
# Yes, this is quite ugly...
|
||||
m4_define_default([b4_parse_param])
|
||||
m4_ifdef([b4_parse_param],
|
||||
[m4_define([b4_parse_param],
|
||||
b4_parse_param)])
|
||||
|
||||
|
||||
|
||||
## ----------------- ##
|
||||
@@ -377,26 +382,8 @@ static const ]b4_int_type_for([b4_check])[ yycheck[] =
|
||||
};
|
||||
|
||||
|
||||
/* The user can define YYPARSE_PARAM as the name of an argument to be passed
|
||||
into yyparse. The argument should have type void *.
|
||||
It should actually point to an object.
|
||||
Grammar actions can access the variable by casting it
|
||||
to the proper pointer type. */
|
||||
|
||||
#ifdef YYPARSE_PARAM
|
||||
# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
|
||||
#else /* !YYPARSE_PARAM */
|
||||
# define YYPARSE_PARAM_ARG void
|
||||
#endif /* !YYPARSE_PARAM */
|
||||
|
||||
/* Prevent warning if -Wstrict-prototypes. */
|
||||
#ifdef __GNUC__
|
||||
# ifdef YYPARSE_PARAM
|
||||
int yyparse (void *);
|
||||
# else
|
||||
int yyparse (void);
|
||||
# endif
|
||||
#endif
|
||||
/* Prevent warning if -Wmissing-prototypes. */
|
||||
]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
|
||||
|
||||
/* Error token number */
|
||||
#define YYTERROR 1
|
||||
@@ -1660,8 +1647,12 @@ yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int
|
||||
yyparse (YYPARSE_PARAM_ARG)
|
||||
|
||||
/*----------.
|
||||
| yyparse. |
|
||||
`----------*/
|
||||
|
||||
]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[
|
||||
{
|
||||
yySymbol yytoken;
|
||||
yyGLRStack yystack;
|
||||
|
||||
75
data/yacc.c
75
data/yacc.c
@@ -40,6 +40,12 @@ m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl
|
||||
b4_location_if([, [[YYLTYPE *], [&yylloc]]])])dnl
|
||||
m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
|
||||
|
||||
# Yes, this is quite ugly...
|
||||
m4_define_default([b4_parse_param])
|
||||
m4_ifdef([b4_parse_param],
|
||||
[m4_define([b4_parse_param],
|
||||
b4_parse_param)])
|
||||
|
||||
|
||||
## ----------------- ##
|
||||
## Semantic Values. ##
|
||||
@@ -625,12 +631,12 @@ yystpcpy (yydest, yysrc)
|
||||
| Print this symbol on YYOUT. |
|
||||
`-----------------------------*/
|
||||
|
||||
b4_c_function([yysymprint],
|
||||
[static void],
|
||||
[[FILE*], [yyout]],
|
||||
[[int], [yytype]],
|
||||
[[YYSTYPE], [yyvalue]]b4_location_if([,
|
||||
[[YYLTYPE], [yylocation]]]))
|
||||
b4_c_function_def([yysymprint],
|
||||
[static void],
|
||||
[[FILE *yyout], [yyout]],
|
||||
[[int yytype], [yytype]],
|
||||
[[YYSTYPE yyvalue], [yyvalue]]b4_location_if([,
|
||||
[[YYLTYPE yylocation], [yylocation]]]))
|
||||
{
|
||||
/* Pacify ``unused variable'' warnings. */
|
||||
(void) yyvalue;
|
||||
@@ -662,11 +668,11 @@ m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
|
||||
| Release the memory associated to this symbol. |
|
||||
`-----------------------------------------------*/
|
||||
|
||||
b4_c_function([yydestruct],
|
||||
[static void],
|
||||
[[int], [yytype]],
|
||||
[[YYSTYPE], [yyvalue]]b4_location_if([,
|
||||
[[YYLTYPE], [yylocation]]]))
|
||||
b4_c_function_def([yydestruct],
|
||||
[static void],
|
||||
[[int yytype], [yytype]],
|
||||
[[YYSTYPE yyvalue], [yyvalue]]b4_location_if([,
|
||||
[[YYLTYPE yylocation], [yylocation]]]))
|
||||
{
|
||||
/* Pacify ``unused variable'' warnings. */
|
||||
(void) yyvalue;
|
||||
@@ -683,39 +689,24 @@ m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))dnl
|
||||
|
||||
|
||||
|
||||
/* The user can define YYPARSE_PARAM as the name of an argument to be passed
|
||||
into yyparse. The argument should have type void *.
|
||||
It should actually point to an object.
|
||||
Grammar actions can access the variable by casting it
|
||||
to the proper pointer type. */
|
||||
/* Prevent warnings from -Wmissing-prototypes. */
|
||||
|
||||
#ifdef YYPARSE_PARAM
|
||||
# if defined (__STDC__) || defined (__cplusplus)
|
||||
# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
|
||||
# define YYPARSE_PARAM_DECL
|
||||
int yyparse (void *YYPARSE_PARAM);
|
||||
# else
|
||||
# define YYPARSE_PARAM_ARG YYPARSE_PARAM
|
||||
# define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
|
||||
# endif
|
||||
#else /* !YYPARSE_PARAM */
|
||||
# define YYPARSE_PARAM_ARG
|
||||
# define YYPARSE_PARAM_DECL
|
||||
#endif /* !YYPARSE_PARAM */
|
||||
|
||||
/* Prevent warning if -Wstrict-prototypes. */
|
||||
#ifdef __GNUC__
|
||||
# ifdef YYPARSE_PARAM
|
||||
int yyparse (void *);
|
||||
# else
|
||||
int yyparse (void);
|
||||
int yyparse ();
|
||||
# endif
|
||||
#else /* ! YYPARSE_PARAM */
|
||||
b4_c_function_decl([yyparse], [int], b4_parse_param)
|
||||
#endif
|
||||
|
||||
|
||||
m4_divert_push([KILL])# ======================== M4 code.
|
||||
# b4_declare_parser_variables
|
||||
# ---------------------------
|
||||
# Declare the variables that are global, or local to YYPARSE if
|
||||
# pure-parser
|
||||
# pure-parser.
|
||||
m4_define([b4_declare_parser_variables],
|
||||
[/* The lookahead symbol. */
|
||||
int yychar;
|
||||
@@ -733,9 +724,21 @@ m4_divert_pop([KILL])dnl# ====================== End of M4 code.
|
||||
b4_pure_if([],
|
||||
[b4_declare_parser_variables])
|
||||
|
||||
int
|
||||
yyparse (YYPARSE_PARAM_ARG)
|
||||
YYPARSE_PARAM_DECL
|
||||
|
||||
/*----------.
|
||||
| yyparse. |
|
||||
`----------*/
|
||||
|
||||
#ifdef YYPARSE_PARAM
|
||||
# if defined (__STDC__) || defined (__cplusplus)
|
||||
int yyparse (void *YYPARSE_PARAM)
|
||||
# else
|
||||
int yyparse (YYPARSE_PARAM)
|
||||
void *YYPARSE_PARAM;
|
||||
# endif
|
||||
#else /* ! YYPARSE_PARAM */
|
||||
b4_c_function_def([yyparse], [int], b4_parse_param)
|
||||
#endif
|
||||
{[
|
||||
]b4_pure_if([b4_declare_parser_variables])[
|
||||
register int yystate;
|
||||
|
||||
Reference in New Issue
Block a user