diff options
author | Akim Demaille <akim@lrde.epita.fr> | 2012-06-21 18:26:44 +0200 |
---|---|---|
committer | Akim Demaille <akim@lrde.epita.fr> | 2012-06-21 22:54:40 +0200 |
commit | 290a8ff2c09fba654b6746caab26a1b6e1c866b1 (patch) | |
tree | d7336b4671485dfdf7622eec0a068c3c7d32c405 /tests | |
parent | 6e2d7b0974f44053d4425baf5195a84013292262 (diff) | |
download | bison-290a8ff2c09fba654b6746caab26a1b6e1c866b1.tar.gz |
tests: factor.
* tests/glr-regression.at, tests/output.at, tests/push.at,
* tests/regression.at, tests/torture.at, tests/actions.at:
Use AT_YYLEX_* and AT_YYERROR_*.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/actions.at | 8 | ||||
-rw-r--r-- | tests/glr-regression.at | 40 | ||||
-rw-r--r-- | tests/output.at | 8 | ||||
-rw-r--r-- | tests/push.at | 40 | ||||
-rw-r--r-- | tests/regression.at | 25 | ||||
-rw-r--r-- | tests/torture.at | 44 |
6 files changed, 46 insertions, 119 deletions
diff --git a/tests/actions.at b/tests/actions.at index cfac2992..5efc043d 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -150,14 +150,8 @@ two: { $$.val = 2; } ; sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ; %% - -static int -yylex (void) -{ - return 0; -} - ]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE()[ int main (void) { diff --git a/tests/glr-regression.at b/tests/glr-regression.at index 9c534631..479303df 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -35,8 +35,8 @@ AT_DATA_GRAMMAR([glr-regr1.y], #define YYSTYPE int static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1); -]AT_YYLEX_DECLARE[ ]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ %} @@ -128,8 +128,8 @@ AT_DATA_GRAMMAR([glr-regr2a.y], #include <stdio.h> #include <stdlib.h> #include <string.h> - ]AT_YYLEX_DECLARE[ ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ %} %glr-parser @@ -519,18 +519,8 @@ AT_DATA_GRAMMAR([glr-regr6.y], start: 'a' | 'a' ; %% - -static int -yylex (void) -{ - static char const input[] = "a"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - return input[toknum++]; -} - ]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE(a)[ int main (void) { @@ -657,7 +647,6 @@ AT_DATA_GRAMMAR([glr-regr8.y], #include <stdlib.h> ]AT_YYERROR_DECLARE[ ]AT_YYLEX_DECLARE[ - ]AT_YYERROR_DECLARE[ %} %token T_CONSTANT @@ -845,16 +834,8 @@ start: ; %% - ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static int called; - if (called++) - abort (); - return 0; -} +]AT_YYLEX_DEFINE()[ int main (void) @@ -1468,16 +1449,8 @@ ambiguity1: ; ambiguity2: ; %% - ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static int called; - if (called++) - abort (); - return 0; -} +]AT_YYLEX_DEFINE()[ int main (void) @@ -1675,7 +1648,7 @@ AT_DATA_GRAMMAR([glr-regr18.y], %{ #include <stdlib.h> ]AT_YYERROR_DECLARE[ - static int yylex (); + ]AT_YYLEX_DECLARE[ %} %union { @@ -1695,7 +1668,6 @@ sym3: %merge<merge> { $$ = 0; } ; %type <type3> sym3; %% - ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE()[ int diff --git a/tests/output.at b/tests/output.at index 058ae89a..f7a7d8e5 100644 --- a/tests/output.at +++ b/tests/output.at @@ -176,10 +176,11 @@ AT_CHECK_CONFLICTING_OUTPUT([foo.y], [], [-o foo.y], # AT_CHECK_OUTPUT_FILE_NAME(FILE-NAME-PREFIX, [ADDITIONAL-TESTS]) -# ----------------------------------------------------------------------------- +# --------------------------------------------------------------- m4_define([AT_CHECK_OUTPUT_FILE_NAME], [AT_SETUP([Output file name: $1]) +AT_BISON_OPTION_PUSHDEFS # Skip if platform doesn't support file name. For example, Cygwin # doesn't support file names containing ":" or "\". AT_CHECK([[touch "]AS_ESCAPE([$1[.tmp]])[" || exit 77]]) @@ -187,8 +188,8 @@ AT_CHECK([[touch "]AS_ESCAPE([$1[.tmp]])[" || exit 77]]) AT_DATA_GRAMMAR([glr.y], [[%glr-parser %code { - int yylex (void); - void yyerror (const char *); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ } %% start: {}; @@ -209,6 +210,7 @@ AT_CHECK([ls "AS_ESCAPE([$1.c])" "AS_ESCAPE([$1.h])"], [], [ignore]) AT_COMPILE_CXX([cxx.o], [-c "AS_ESCAPE([$1.c])"]) $2 +AT_BISON_OPTION_POPDEFS AT_CLEANUP ]) diff --git a/tests/push.at b/tests/push.at index 21322f0d..057807dd 100644 --- a/tests/push.at +++ b/tests/push.at @@ -24,17 +24,18 @@ AT_BANNER([[Push Parsing Tests]]) AT_SETUP([[Memory Leak for Early Deletion]]) # Requires Valgrind. - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [[ %{ #include <assert.h> #include <stdio.h> #define YYINITDEPTH 1 - void yyerror (char const *msg); +]AT_YYERROR_DECLARE[ %} -%define api.pure %define api.push-pull push +%define api.pure +%define api.push-pull push %% @@ -42,11 +43,7 @@ start: 'a' 'b' 'c' ; %% -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} +]AT_YYERROR_DEFINE[ int main (void) @@ -71,6 +68,7 @@ main (void) return 0; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o input.c input.y]]) AT_COMPILE([[input]]) @@ -85,13 +83,14 @@ AT_CLEANUP AT_SETUP([[Multiple impure instances]]) m4_pushdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK], [ +AT_BISON_OPTION_PUSHDEFS([%define api.push-pull $1]) AT_DATA_GRAMMAR([[input.y]], [[ %{ #include <assert.h> #include <stdio.h> - void yyerror (char const *msg); - int yylex (void); +]AT_YYERROR_DECLARE[ +]m4_if([$1], [[both]], [AT_YYLEX_DECLARE([])])[ %} %define api.push-pull ]$1[ @@ -101,28 +100,16 @@ AT_DATA_GRAMMAR([[input.y]], start: ; %% - -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - -int -yylex (void) -{ - return 0; -} +]AT_YYERROR_DEFINE[ +]m4_if([$1], [[both]], [AT_YYLEX_DEFINE([])])[ int main (void) { - yypstate *ps; int i; - for (i = 0; i < 2; ++i) { - ps = yypstate_new (); + yypstate *ps = yypstate_new (); assert (ps); assert (yypstate_new () == YY_NULL); ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[; @@ -140,6 +127,7 @@ main (void) AT_BISON_CHECK([[-o input.c input.y]]) AT_COMPILE([[input]]) AT_PARSER_CHECK([[./input]]) +AT_BISON_OPTION_POPDEFS ]) AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[both]]) @@ -155,12 +143,14 @@ AT_CLEANUP AT_SETUP([[Unsupported Skeletons]]) +AT_BISON_OPTION_PUSHDEFS AT_DATA([[input.y]], [[%glr-parser %define api.push-pull push %% start: ; ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[input.y]], [[1]], [], [[input.y:2.9-21: %define variable 'api.push-pull' is not used diff --git a/tests/regression.at b/tests/regression.at index fa93833c..5c1ad32b 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -462,11 +462,7 @@ AT_DATA_GRAMMAR([input.y], %% exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"; %% -void -yyerror (char const *s) -{ - fprintf (stderr, "%s\n", s); -} +]AT_YYERROR_DEFINE[ int yylex (void) @@ -901,15 +897,9 @@ member: STRING | INVALID ; %% -AT_LALR1_CC_IF( -[/* A C++ error reporting function. */ -void -yy::parser::error (const location&, const std::string& m) -{ - std::cerr << m << std::endl; -} - -int +AT_YYERROR_DEFINE[ +]AT_LALR1_CC_IF( +[int yyparse () { yy::parser parser; @@ -918,12 +908,7 @@ yyparse () #endif return parser.parse (); } -], -[static void -yyerror (const char *s) -{ - fprintf (stderr, "%s\n", s); -}]) +]) static int yylex (AT_LALR1_CC_IF([int *lval], [void])) diff --git a/tests/torture.at b/tests/torture.at index 313df345..a8837b22 100644 --- a/tests/torture.at +++ b/tests/torture.at @@ -56,7 +56,7 @@ print <<EOF; %{ #include <stdio.h> #include <stdlib.h> - +#define MAX $max ]AT_YYLEX_DECLARE[ ]AT_YYERROR_DECLARE[ %} @@ -96,14 +96,15 @@ for my $size (1 .. $max) }; print ";\n"; -print <<EOF; +print <<\EOF; %% +]AT_YYERROR_DEFINE[ static int yylex (void) { static int inner = 1; static int outer = 0; - if (outer > $max) + if (outer > MAX) return 0; else if (inner > outer) { @@ -113,13 +114,6 @@ yylex (void) } return inner++; } - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\\n", msg); -} - int main (void) { @@ -173,7 +167,7 @@ print <<EOF; %{ #include <stdio.h> #include <stdlib.h> - +#define MAX $max ]AT_YYLEX_DECLARE[ ]AT_YYERROR_DECLARE[ %} @@ -196,25 +190,20 @@ print (map { "\"$_\"" } (1 .. $max)), ";"), "\n"; -print <<EOF; +print <<\EOF; %% +]AT_YYERROR_DEFINE[ static int yylex (void) { static int counter = 1; - if (counter <= $max) + if (counter <= MAX) return counter++; - if (counter++ != $max + 1) + if (counter++ != MAX + 1) abort (); return 0; } -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\\n", msg); -} - int main (void) { @@ -282,7 +271,7 @@ print <<EOF; # include <stdio.h> # include <stdlib.h> # include <assert.h> - +# define MAX $max ]AT_YYLEX_DECLARE[ ]AT_YYERROR_DECLARE[ %} @@ -329,16 +318,17 @@ for my $count (1 .. $max) print "n$count: token { \$\$ = $count; };\n"; }; -print <<EOF; +print <<\EOF; %% +]AT_YYERROR_DEFINE[ static int yylex (void) { static int return_token = 1; static int counter = 1; - if (counter > $max) + if (counter > MAX) { - if (counter++ != $max + 1) + if (counter++ != MAX + 1) abort (); return 0; } @@ -351,12 +341,6 @@ yylex (void) return counter++; } -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\\n", msg); -} - int main (void) { |