* data/push.c (yypstate_init): Rename to...

(yypstate_new): ... this and use b4_c_function_def.
(yypstate_delete): New.
(yypush_parse): Change parameters yynval and yynlloc to be const.
* tests/calc.at (_AT_DATA_CALC_Y): Use new yypstate_new and
yypstate_delete functions.
This commit is contained in:
Joel E. Denny
2006-12-14 02:58:11 +00:00
parent f02e2948bd
commit 9bf32be3a0
3 changed files with 35 additions and 14 deletions

View File

@@ -1,3 +1,12 @@
2006-12-13 Bob Rossi <bob@brasko.net>
* data/push.c (yypstate_init): Rename to...
(yypstate_new): ... this and use b4_c_function_def.
(yypstate_delete): New.
(yypush_parse): Change parameters yynval and yynlloc to be const.
* tests/calc.at (_AT_DATA_CALC_Y): Use new yypstate_new and
yypstate_delete functions.
2006-12-13 Joel E. Denny <jdenny@ces.clemson.edu> 2006-12-13 Joel E. Denny <jdenny@ces.clemson.edu>
* configure.ac (AC_PREREQ): Require Autoconf 2.61 because of our * configure.ac (AC_PREREQ): Require Autoconf 2.61 because of our

View File

@@ -153,7 +153,8 @@ m4_if(b4_prefix, [yy], [],
[/* Substitute the variable and function names. */ [/* Substitute the variable and function names. */
#define yyparse b4_prefix[]parse #define yyparse b4_prefix[]parse
]b4_push_if([#define yypush_parse b4_prefix[]push_parse ]b4_push_if([#define yypush_parse b4_prefix[]push_parse
#define yypstate_init b4_prefix[]pstate_init #define yypstate_new b4_prefix[]pstate_new
#define yypstate_delete b4_prefix[]pstate_delete
#define yypstate b4_prefix[]pstate])[ #define yypstate b4_prefix[]pstate])[
#define yylex b4_prefix[]lex #define yylex b4_prefix[]lex
#define yyerror b4_prefix[]error #define yyerror b4_prefix[]error
@@ -970,12 +971,13 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
]b4_push_if([ ]b4_push_if([
struct yypstate; struct yypstate;
enum { YYPUSH_MORE = 4 }; enum { YYPUSH_MORE = 4 };
]b4_c_function_decl([yypstate_init], [struct yypstate *], [[void], []])[ ]b4_c_function_decl([yypstate_new], [struct yypstate *], [[void], []])[
]b4_c_function_decl([yypstate_delete], [void], [[struct yypstate *yyps], [yyps]])[
]b4_c_function_decl([yypush_parse], [int], ]b4_c_function_decl([yypush_parse], [int],
[[struct yypstate *yyps], [yyps]], [[struct yypstate *yyps], [yyps]],
[[int yynchar], [yynchar]], [[int yynchar], [yynchar]],
[[YYSTYPE *yynlval], [yynlval]] [[YYSTYPE const *yynlval], [yynlval]]
b4_locations_if([,[[YYLTYPE *yynlloc], [yynlloc]]]))[ b4_locations_if([,[[YYLTYPE const *yynlloc], [yynlloc]]]))[
])[ ])[
]m4_divert_push([KILL])# ======================== M4 code. ]m4_divert_push([KILL])# ======================== M4 code.
@@ -1047,8 +1049,7 @@ m4_define([b4_declare_yyparse_variables],
}; };
/* Initialize the parser data structure. */ /* Initialize the parser data structure. */
struct yypstate* ]b4_c_function_def([yypstate_new], [struct yypstate *])[
yypstate_init (void)
{ {
struct yypstate *yyps = (struct yypstate *) malloc (sizeof *yyps); struct yypstate *yyps = (struct yypstate *) malloc (sizeof *yyps);
yyps->yystate = 0; yyps->yystate = 0;
@@ -1071,7 +1072,14 @@ yypstate_init (void)
]b4_locations_if([ yyps->yylsp = yyps->yyls;])[ ]b4_locations_if([ yyps->yylsp = yyps->yyls;])[
return yyps; return yyps;
}]) }
]b4_c_function_def([yypstate_delete], [void],
[[struct yypstate *yyps], [yyps]])[
{
free (yyps);
}
])
m4_divert_pop([KILL])dnl# ====================== End of M4 code. m4_divert_pop([KILL])dnl# ====================== End of M4 code.
b4_push_if([],[b4_pure_if([], b4_push_if([],[b4_pure_if([],
@@ -1085,8 +1093,9 @@ b4_push_if([b4_declare_yyparse_variables])
b4_push_if([ b4_push_if([
b4_c_function_def([yypush_parse], [int], [[struct yypstate *yyps], [yyps]], b4_c_function_def([yypush_parse], [int], [[struct yypstate *yyps], [yyps]],
[[int yynchar], [yynchar]], [[YYSTYPE *yynlval], [yynlval]] [[int yynchar], [yynchar]],
b4_locations_if([,[[YYLTYPE *yynlloc], [yynlloc]]]))],[ [[YYSTYPE const *yynlval], [yynlval]]
b4_locations_if([,[[YYLTYPE const *yynlloc], [yynlloc]]]))],[
#ifdef YYPARSE_PARAM #ifdef YYPARSE_PARAM
b4_c_function_def([yyparse], [int], [[void *YYPARSE_PARAM], [YYPARSE_PARAM]]) b4_c_function_def([yyparse], [int], [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])
#else /* ! YYPARSE_PARAM */ #else /* ! YYPARSE_PARAM */
@@ -1679,12 +1688,15 @@ typedef struct YYLTYPE
#endif #endif
]b4_push_if([struct ]b4_prefix[pstate; ]b4_push_if([struct ]b4_prefix[pstate;
]b4_c_function_decl([]b4_prefix[pstate_init], [struct ]b4_prefix[pstate *], [[void], []])[ ]b4_c_function_decl([]b4_prefix[pstate_new], [struct ]b4_prefix[pstate *],
[[void], []])[
]b4_c_function_decl([]b4_prefix[pstate_delete], [void],
[[struct ]b4_prefix[pstate *yyps],[yyps]])[
]b4_c_function_decl([]b4_prefix[push_parse], [int], ]b4_c_function_decl([]b4_prefix[push_parse], [int],
[[struct ]b4_prefix[pstate *]b4_prefix[pstate], []b4_prefix[pstate]], [[struct ]b4_prefix[pstate *]b4_prefix[pstate], []b4_prefix[pstate]],
[[int yynchar], [yynchar]], [[int yynchar], [yynchar]],
[[YYSTYPE *yynlval], [yynlval]] [[YYSTYPE const *yynlval], [yynlval]]
b4_locations_if([,[[YYLTYPE *yynlloc], [yynlloc]]]))[ b4_locations_if([,[[YYLTYPE const *yynlloc], [yynlloc]]]))[
enum { YYPUSH_MORE = 4 };])[ enum { YYPUSH_MORE = 4 };])[
]b4_pure_if([], ]b4_pure_if([],
[extern YYLTYPE b4_prefix[]lloc;]) [extern YYLTYPE b4_prefix[]lloc;])

View File

@@ -338,13 +338,13 @@ main (int argc, const char **argv)
[ yydebug = 1;])])[ [ yydebug = 1;])])[
]AT_PUSH_IF([ ]AT_PUSH_IF([
{ {
struct yypstate *pstate = yypstate_init (); struct yypstate *pstate = yypstate_new ();
YYSTYPE my_lval; YYSTYPE my_lval;
]AT_LOCATION_IF([YYLTYPE my_lloc;])[ ]AT_LOCATION_IF([YYLTYPE my_lloc;])[
do { do {
status = yypush_parse (pstate, yylex (&my_lval]AT_LOCATION_IF([[, &my_lloc]])[), &my_lval]AT_LOCATION_IF([[, &my_lloc]])[); status = yypush_parse (pstate, yylex (&my_lval]AT_LOCATION_IF([[, &my_lloc]])[), &my_lval]AT_LOCATION_IF([[, &my_lloc]])[);
} while (status == YYPUSH_MORE); } while (status == YYPUSH_MORE);
free (pstate); yypstate_delete (pstate);
}],[ }],[
status = yyparse (]AT_PARAM_IF([[&result, &count]])[);])[ status = yyparse (]AT_PARAM_IF([[&result, &count]])[);])[
fclose (input); fclose (input);