From: Akim Demaille Date: Fri, 22 Jun 2012 10:08:02 +0000 (+0200) Subject: tests: more uniformity. X-Git-Tag: v2.6~54 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/230a3db428622bb964807111b46812879b7ee726?hp=6d55954743c7243ba46680f368c76ee70b1112f8 tests: more uniformity. * tests/local.at (AT_LEX_FORMALS, AT_LEX_ARGS, AT_LEX_PRE_FORMALS) (AT_LEX_PRE_ARGS): Rename as... (AT_YYLEX_FORMALS, AT_YYLEX_ARGS, AT_YYLEX_PRE_FORMALS) (AT_YYLEX_PRE_ARGS): these, for consistency. (AT_API_PREFIX): Take %name-prefix into account. (AT_YYLEX_PROTOTYPE): New. Use it. * tests/actions.at, tests/calc.at, tests/cxx-type.at: Adjust to use them. --- diff --git a/tests/actions.at b/tests/actions.at index afba3f0b..e5a885dd 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -205,8 +205,8 @@ m4_ifval([$6], [%union }]) AT_LALR1_CC_IF([%define global_tokens_and_yystype]) m4_ifval([$6], [[%code provides {]], [[%code {]]) -AT_LALR1_CC_IF([typedef yy::location YYLTYPE;]) -[static int yylex (]AT_LEX_FORMALS[); +AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[ +]AT_YYLEX_DECLARE[ ]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE]) [} @@ -309,8 +309,8 @@ thing: /* Alias to ARGV[1]. */ const char *source = YY_NULL; -static int -yylex (]AT_LEX_FORMALS[) +static +]AT_YYLEX_PROTOTYPE[ { static unsigned int counter = 0; diff --git a/tests/calc.at b/tests/calc.at index 34d2e488..836c3a33 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -110,15 +110,15 @@ main (int argc, const char **argv) m4_pushdef([AT_CALC_LEX], [[#include -int ]AT_NAME_PREFIX[lex (]AT_LEX_FORMALS[); -static int get_char (]AT_LEX_FORMALS[); -static void unget_char (]AT_LEX_PRE_FORMALS[ int c); +]AT_YYLEX_DECLARE_EXTERN[ +static int get_char (]AT_YYLEX_FORMALS[); +static void unget_char (]AT_YYLEX_PRE_FORMALS[ int c); ]AT_LOCATION_IF([ static YYLTYPE last_yylloc; ])[ static int -get_char (]AT_LEX_FORMALS[) +get_char (]AT_YYLEX_FORMALS[) { int res = getc (input); ]AT_USE_LEX_ARGS[; @@ -136,7 +136,7 @@ get_char (]AT_LEX_FORMALS[) } static void -unget_char (]AT_LEX_PRE_FORMALS[ int c) +unget_char (]AT_YYLEX_PRE_FORMALS[ int c) { ]AT_USE_LEX_ARGS[; ]AT_LOCATION_IF([ @@ -147,26 +147,26 @@ unget_char (]AT_LEX_PRE_FORMALS[ int c) } static int -read_signed_integer (]AT_LEX_FORMALS[) +read_signed_integer (]AT_YYLEX_FORMALS[) { - int c = get_char (]AT_LEX_ARGS[); + int c = get_char (]AT_YYLEX_ARGS[); int sign = 1; int n = 0; ]AT_USE_LEX_ARGS[; if (c == '-') { - c = get_char (]AT_LEX_ARGS[); + c = get_char (]AT_YYLEX_ARGS[); sign = -1; } while (isdigit (c)) { n = 10 * n + (c - '0'); - c = get_char (]AT_LEX_ARGS[); + c = get_char (]AT_YYLEX_ARGS[); } - unget_char (]AT_LEX_PRE_ARGS[ c); + unget_char (]AT_YYLEX_PRE_ARGS[ c); return sign * n; } @@ -178,8 +178,7 @@ read_signed_integer (]AT_LEX_FORMALS[) | blanks and tabs, returns 0 for EOF. | `---------------------------------------------------------------*/ -int -]AT_NAME_PREFIX[lex (]AT_LEX_FORMALS[) +]AT_YYLEX_PROTOTYPE[ { static int init = 1; int c; @@ -201,13 +200,13 @@ int AT_LOC_FIRST_LINE = AT_LOC_LAST_LINE; ])[ } - while ((c = get_char (]AT_LEX_ARGS[)) == ' ' || c == '\t'); + while ((c = get_char (]AT_YYLEX_ARGS[)) == ' ' || c == '\t'); /* process numbers */ if (c == '.' || isdigit (c)) { - unget_char (]AT_LEX_PRE_ARGS[ c); - ]AT_VAL[.ival = read_signed_integer (]AT_LEX_ARGS[); + unget_char (]AT_YYLEX_PRE_ARGS[ c); + ]AT_VAL[.ival = read_signed_integer (]AT_YYLEX_ARGS[); return NUM; } @@ -288,14 +287,11 @@ FILE *input; static int power (int base, int exponent); ]AT_SKEL_CC_IF(, -[/* yyerror receives the location if: - - %location & %pure & %glr - - %location & %pure & %yacc & %parse-param. */ -static void yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ]) +[static void yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ]) AT_PARAM_IF([semantic_value *result, int *count, ]) const char *s );])[ -int yylex (]AT_LEX_FORMALS[); +]AT_YYLEX_DECLARE_EXTERN[ } ]AT_SKEL_CC_IF([AT_LOCATION_TYPE_IF([], [ diff --git a/tests/cxx-type.at b/tests/cxx-type.at index e6fd8a85..e172033a 100644 --- a/tests/cxx-type.at +++ b/tests/cxx-type.at @@ -135,8 +135,7 @@ main (int argc, char **argv) ]AT_YYERROR_DEFINE[ -int -yylex (]AT_LEX_FORMALS[) +]AT_YYLEX_PROTOTYPE[ { char buffer[256]; int c; diff --git a/tests/local.at b/tests/local.at index 02093938..b0e4ee1a 100644 --- a/tests/local.at +++ b/tests/local.at @@ -138,11 +138,11 @@ m4_pushdef([AT_GLR_OR_PARAM_IF], [m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])]) m4_pushdef([AT_NAME_PREFIX], [m4_bmatch([$3], [%name-prefix ".*"], - [m4_bregexp([$3], [name-prefix "\([^""]*\)"], [\1])], + [m4_bregexp([$3], [%name-prefix "\([^""]*\)"], [\1])], [yy])]) m4_pushdef([AT_API_PREFIX], -[m4_bmatch([$3], [%define api\.prefix ".*"], - [m4_bregexp([$3], [%define api\.prefix "\([^""]*\)"], [\1])], +[m4_bmatch([$3], [\(%define api\.prefix\|%name-prefix\) ".*"], + [m4_bregexp([$3], [\(%define api\.prefix\|%name-prefix\) "\([^""]*\)"], [\2])], [yy])]) # yyerror receives the location if %location & %pure & (%glr or %parse-param). m4_pushdef([AT_YYERROR_ARG_LOC_IF], @@ -165,24 +165,24 @@ m4_pushdef([AT_PURE_LEX_IF], AT_PURE_LEX_IF( [m4_pushdef([AT_LOC], [(*llocp)]) m4_pushdef([AT_VAL], [(*lvalp)]) - m4_pushdef([AT_LEX_FORMALS], + m4_pushdef([AT_YYLEX_FORMALS], [YYSTYPE *lvalp[]AT_LOCATION_IF([, YYLTYPE *llocp])]) - m4_pushdef([AT_LEX_ARGS], + m4_pushdef([AT_YYLEX_ARGS], [lvalp[]AT_LOCATION_IF([, llocp])]) m4_pushdef([AT_USE_LEX_ARGS], [(void) lvalp;AT_LOCATION_IF([(void) llocp])]) - m4_pushdef([AT_LEX_PRE_FORMALS], - [AT_LEX_FORMALS, ]) - m4_pushdef([AT_LEX_PRE_ARGS], - [AT_LEX_ARGS, ]) + m4_pushdef([AT_YYLEX_PRE_FORMALS], + [AT_YYLEX_FORMALS, ]) + m4_pushdef([AT_YYLEX_PRE_ARGS], + [AT_YYLEX_ARGS, ]) ], [m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]]) m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]]) - m4_pushdef([AT_LEX_FORMALS], [void]) - m4_pushdef([AT_LEX_ARGS], []) + m4_pushdef([AT_YYLEX_FORMALS], [void]) + m4_pushdef([AT_YYLEX_ARGS], []) m4_pushdef([AT_USE_LEX_ARGS], []) - m4_pushdef([AT_LEX_PRE_FORMALS], []) - m4_pushdef([AT_LEX_PRE_ARGS], []) + m4_pushdef([AT_YYLEX_PRE_FORMALS], []) + m4_pushdef([AT_YYLEX_PRE_ARGS], []) ]) # Handle the different types of location components. @@ -199,11 +199,11 @@ AT_SKEL_CC_IF( # AT_BISON_OPTION_POPDEFS # ----------------------- m4_define([AT_BISON_OPTION_POPDEFS], -[m4_popdef([AT_LEX_PRE_ARGS]) -m4_popdef([AT_LEX_PRE_FORMALS]) +[m4_popdef([AT_YYLEX_PRE_ARGS]) +m4_popdef([AT_YYLEX_PRE_FORMALS]) m4_popdef([AT_USE_LEX_ARGS]) -m4_popdef([AT_LEX_ARGS]) -m4_popdef([AT_LEX_FORMALS]) +m4_popdef([AT_YYLEX_ARGS]) +m4_popdef([AT_YYLEX_FORMALS]) m4_popdef([AT_VAL]) m4_popdef([AT_LOC]) m4_popdef([AT_PURE_LEX_IF]) @@ -276,12 +276,17 @@ m4_define([AT_DATA_GRAMMAR], $2]) ]) +# AT_YYLEX_PROTOTYPE # AT_YYLEX_DECLARE_EXTERN # AT_YYLEX_DECLARE # AT_YYLEX_DEFINE(INPUT-STRING, [ACTION]) # --------------------------------------- +m4_define([AT_YYLEX_PROTOTYPE], +[int AT_API_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl +]) + m4_define([AT_YYLEX_DECLARE_EXTERN], -[int AT_API_PREFIX[]lex (]AT_LEX_FORMALS[);dnl +[AT_YYLEX_PROTOTYPE;dnl ]) m4_define([AT_YYLEX_DECLARE], @@ -290,8 +295,8 @@ m4_define([AT_YYLEX_DECLARE], m4_define([AT_YYLEX_DEFINE], [[#include /* abort */ -static int -]AT_API_PREFIX[lex (]AT_LEX_FORMALS[) +static +]AT_YYLEX_PROTOTYPE[ { static char const input[] = "$1"; static size_t toknum = 0; @@ -312,9 +317,14 @@ static int # AT_YYERROR_DEFINE # ------------------------- # Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair. +m4_define([AT_YYERROR_FORMALS], +[m4_case(AT_LANG, +[c], [AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ])[const char *msg]])[]dnl +]) + m4_define([AT_YYERROR_PROTOTYPE], [m4_case(AT_LANG, -[c], [[void ]AT_API_PREFIX[error (]AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ])[const char *msg)]])[]dnl +[c], [[void ]AT_API_PREFIX[error (]AT_YYERROR_FORMALS[)]])[]dnl ]) m4_define([AT_YYERROR_DECLARE_EXTERN],