]> git.saurik.com Git - bison.git/commitdiff
tests: factor.
authorAkim Demaille <akim@lrde.epita.fr>
Thu, 21 Jun 2012 16:26:44 +0000 (18:26 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Thu, 21 Jun 2012 20:54:40 +0000 (22:54 +0200)
* 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_*.

tests/actions.at
tests/glr-regression.at
tests/output.at
tests/push.at
tests/regression.at
tests/torture.at

index cfac299202a9e204042ac419df3ab6cf303602b3..5efc043df933b0371127be8c3ec3903e1c66e32c 100644 (file)
@@ -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)
 {
index 9c534631eded6e00f3c35b522527d254cf536c2b..479303df1391432c2893bc85dc6d597b4f2f244b 100644 (file)
@@ -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
index 058ae89a96051c6fe205b6a5e79e14e9d1445ab0..f7a7d8e57ed59ba2ee948b017df0c96cb9b9a1c9 100644 (file)
@@ -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
 ])
 
index 21322f0dd5f3a8572ef24e6a2b9974fbfda43e99..057807dd21bb45211c4250c3c85afa757a73b74d 100644 (file)
@@ -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
index fa93833cd0d08b3bf4378e8b54c4a5bfe79243cc..5c1ad32be86053d371b062b509e929b67e10d8f2 100644 (file)
@@ -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]))
index 313df345ed494f3c81e0c43ea1ff75a9d13201e8..a8837b2246713777c3c61da329df97ee86b40f9f 100644 (file)
@@ -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)
 {