X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/12e3584054c16ab255672c07af0ffc7bb220e8bc..798096e1deaeb13a06e62de5c73487537e220e3c:/tests/actions.at diff --git a/tests/actions.at b/tests/actions.at index 672a4dbf..602eac8c 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -1,20 +1,19 @@ # Executing Actions. -*- Autotest -*- -# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software +# Foundation, Inc. -# This program is free software; you can redistribute it and/or modify +# This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. +# along with this program. If not, see . AT_BANNER([[User Actions.]]) @@ -75,7 +74,7 @@ main (void) } ]]) -AT_CHECK([bison -d -v -o input.c input.y]) +AT_BISON_CHECK([-d -v -o input.c input.y]) AT_COMPILE([input]) AT_PARSER_CHECK([./input], 0, [[0123456789 @@ -153,7 +152,7 @@ main (void) } ]]) -AT_CHECK([bison -d -v -o input.c input.y], 0) +AT_BISON_CHECK([-d -v -o input.c input.y], 0) AT_COMPILE([input]) AT_PARSER_CHECK([./input], 0, [[15 @@ -178,7 +177,7 @@ m4_if([$1$2$3], $[1]$[2]$[3], [], # helping macros. So don't put any directly in the Bison file. AT_BISON_OPTION_PUSHDEFS([$5]) AT_DATA_GRAMMAR([[input.y]], -[[%requires { +[[%code requires { #include #include #include @@ -196,8 +195,8 @@ m4_ifval([$6], [%union { int ival; }]) -AT_LALR1_CC_IF([%define "global_tokens_and_yystype"]) -m4_ifval([$6], [[%provides {]], [[%code {]]) +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([], [static void yyerror (const char *msg);]) @@ -369,9 +368,9 @@ main (int argc, const char *argv[]) ]]) AT_LALR1_CC_IF( - [AT_CHECK([bison -o input.cc input.y]) + [AT_BISON_CHECK([-o input.cc input.y]) AT_COMPILE_CXX([input])], - [AT_CHECK([bison -o input.c input.y]) + [AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input])]) @@ -614,11 +613,11 @@ AT_DATA_GRAMMAR([[input.y]], } <*> %printer { - fprintf (yyoutput, " printer for '%c' @ %d", $$, @$.first_column); -} + fprintf (yyoutput, "<> printer for '%c' @ %d", $$, @$.first_column); +} <> %destructor { - fprintf (stdout, " destructor for '%c' @ %d.\n", $$, @$.first_column); -} + fprintf (stdout, "<> destructor for '%c' @ %d.\n", $$, @$.first_column); +} <> %printer { fprintf (yyoutput, "'b'/'c' printer for '%c' @ %d", $$, @$.first_column); @@ -664,18 +663,18 @@ main (void) } ]]) -AT_CHECK([bison -o input.c input.y]) +AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input]) AT_PARSER_CHECK([./input], 1, -[[ destructor for 'd' @ 4. +[[<> destructor for 'd' @ 4. 'b'/'c' destructor for 'c' @ 3. 'b'/'c' destructor for 'b' @ 2. - destructor for 'a' @ 1. +<> destructor for 'a' @ 1. ]], [[Starting parse Entering state 0 -Reading a token: Next token is token 'a' (1.1-1.1: printer for 'a' @ 1) -Shifting token 'a' (1.1-1.1: printer for 'a' @ 1) +Reading a token: Next token is token 'a' (1.1-1.1: <> printer for 'a' @ 1) +Shifting token 'a' (1.1-1.1: <> printer for 'a' @ 1) Entering state 1 Reading a token: Next token is token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2) Shifting token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2) @@ -683,18 +682,18 @@ Entering state 3 Reading a token: Next token is token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3) Shifting token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3) Entering state 5 -Reading a token: Next token is token 'd' (1.4-1.4: printer for 'd' @ 4) -Shifting token 'd' (1.4-1.4: printer for 'd' @ 4) +Reading a token: Next token is token 'd' (1.4-1.4: <> printer for 'd' @ 4) +Shifting token 'd' (1.4-1.4: <> printer for 'd' @ 4) Entering state 6 Reading a token: Now at end of input. syntax error, unexpected $end, expecting 'e' -Error: popping token 'd' (1.4-1.4: printer for 'd' @ 4) +Error: popping token 'd' (1.4-1.4: <> printer for 'd' @ 4) Stack now 0 1 3 5 Error: popping token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3) Stack now 0 1 3 Error: popping token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2) Stack now 0 1 -Error: popping token 'a' (1.1-1.1: printer for 'a' @ 1) +Error: popping token 'a' (1.1-1.1: <> printer for 'a' @ 1) Stack now 0 Cleanup: discarding lookahead token $end (1.5-1.5: ) Stack now 0 @@ -723,8 +722,8 @@ AT_DATA_GRAMMAR([[input.y]], %} %printer { - fprintf (yyoutput, " printer should not be called.\n"); -} + fprintf (yyoutput, "<> printer should not be called.\n"); +} <> %union { int field0; int field1; int field2; } %type start 'a' 'g' @@ -750,8 +749,8 @@ AT_DATA_GRAMMAR([[input.y]], %destructor { fprintf (stdout, "'d' destructor.\n"); } 'd' %destructor { - fprintf (yyoutput, " destructor should not be called.\n"); -} + fprintf (yyoutput, "<> destructor should not be called.\n"); +} <> %% @@ -789,7 +788,7 @@ main (void) } ]]) -AT_CHECK([bison -o input.c input.y]) +AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input]) AT_PARSER_CHECK([./input], 1, [[<*>//e destructor. @@ -851,8 +850,8 @@ AT_SETUP([Default %printer and %destructor for user-defined end token]) # ----------------------------------------------------------------------------- m4_define([_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN], [m4_if($1, 0, - [m4_pushdef([kind], [!]) m4_pushdef([not_kind], [*])], - [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [!])]) + [m4_pushdef([kind], []) m4_pushdef([not_kind], [*])], + [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])]) AT_DATA_GRAMMAR([[input]]$1[[.y]], [[%error-verbose @@ -924,7 +923,7 @@ main (void) } ]]) -AT_CHECK([bison -o input$1.c input$1.y]) +AT_BISON_CHECK([-o input$1.c input$1.y]) AT_COMPILE([input$1]) AT_PARSER_CHECK([./input$1], 0, [[<]]kind[[> for 'E' @ 1. @@ -959,7 +958,7 @@ AT_CLEANUP ## Default %printer and %destructor are not for error or $undefined. ## ## ------------------------------------------------------------------ ## -AT_SETUP([Default %printer and %destructor are not for error or \$undefined]) +AT_SETUP([Default %printer and %destructor are not for error or $undefined]) # If Bison were to apply the default %printer and %destructor to the error # token or to $undefined: @@ -983,10 +982,10 @@ AT_DATA_GRAMMAR([[input.y]], %printer { fprintf (yyoutput, "'%c'", $$); -} <*> +} <> <*> %destructor { fprintf (stderr, "DESTROY '%c'\n", $$); -} <*> +} <> <*> %% @@ -1024,7 +1023,7 @@ main (void) } ]]) -AT_CHECK([bison -o input.c input.y]) +AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input]) AT_PARSER_CHECK([./input], [1], [], [[Starting parse @@ -1069,7 +1068,7 @@ AT_CLEANUP ## Default %printer and %destructor are not for $accept. ## ## ------------------------------------------------------ ## -AT_SETUP([Default %printer and %destructor are not for \$accept]) +AT_SETUP([Default %printer and %destructor are not for $accept]) # If YYSTYPE is a union and Bison were to apply the default %printer and # %destructor to $accept: @@ -1098,11 +1097,11 @@ AT_DATA_GRAMMAR([[input.y]], %printer { char chr = $$; fprintf (yyoutput, "'%c'", chr); -} <*> +} <> <*> %destructor { char chr = $$; fprintf (stderr, "DESTROY '%c'\n", chr); -} <*> +} <> <*> %union { char chr; } %type start @@ -1135,7 +1134,7 @@ main (void) } ]]) -AT_CHECK([bison -o input.c input.y]) +AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input]) AT_CLEANUP @@ -1162,8 +1161,8 @@ AT_DATA_GRAMMAR([[input.y]], # define YY_LOCATION_PRINT(File, Loc) %} -%printer { fprintf (yyoutput, "%d", @$); } -%destructor { fprintf (stderr, "DESTROY %d\n", @$); } +%printer { fprintf (yyoutput, "%d", @$); } <> +%destructor { fprintf (stderr, "DESTROY %d\n", @$); } <> %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*> %destructor { fprintf (yyoutput, "<*> destructor should not be called"); } <*> @@ -1203,7 +1202,7 @@ main (void) } ]]) -AT_CHECK([bison -o input.c input.y], 0,, +AT_BISON_CHECK([-o input.c input.y], 0,, [[input.y:33.3-23: warning: unset value: $$ input.y:30.3-35.37: warning: unused value: $3 ]]) @@ -1246,3 +1245,62 @@ Stack now 0 ]]) AT_CLEANUP + + +## ----------------------- ## +## @$ implies %locations. ## +## ----------------------- ## + +# Bison once forgot to check for @$ in actions other than semantic actions. + +# AT_CHECK_ACTION_LOCATIONS(ACTION-DIRECTIVE) +# ------------------------------------------------------- +m4_define([AT_CHECK_ACTION_LOCATIONS], +[AT_SETUP([[@$ in ]$1[ implies %locations]]) + +AT_DATA_GRAMMAR([[input.y]], +[[%code { + #include + static int yylex (void); + static void yyerror (char const *msg); +} + +%debug + +]$1[ { + printf ("%d\n", @$.first_line); +} ]m4_if($1, [%initial-action], [], [[start]])[ + +%% + +start: ; + +%% + +static int +yylex (void) +{ + return 0; +} + +static void +yyerror (char const *msg) +{ + fprintf (stderr, "%s\n", msg); +} + +int +main (void) +{ + return yyparse (); +} +]]) + +AT_BISON_CHECK([[-o input.c input.y]]) +AT_COMPILE([[input]]) + +AT_CLEANUP]) + +AT_CHECK_ACTION_LOCATIONS([[%initial-action]]) +AT_CHECK_ACTION_LOCATIONS([[%destructor]]) +AT_CHECK_ACTION_LOCATIONS([[%printer]])