]> git.saurik.com Git - bison.git/blobdiff - tests/glr-regression.at
Regenerate.
[bison.git] / tests / glr-regression.at
index 148931559a41391705e31f6dd6a5179e139c9af3..ad8f6d864fbb3b6733b0668a61d51973f1466f24 100644 (file)
@@ -120,7 +120,7 @@ AT_DATA_GRAMMAR([glr-regr2a.y],
 /* Reported by S. Eken */
 
 %{
-  #define YYSTYPE char const *
+  #define YYSTYPE char *
 
   #include <ctype.h>
   #include <stdio.h>
@@ -138,9 +138,11 @@ command:
     's' var 't'
        { printf ("Variable: '%s'\n", $2); }
     'v' 'x' 'q'
+       { free ($2); }
   | 's' var_list 't' 'e'
-       { printf ("Varlist: '%s'\n", $2); }
+       { printf ("Varlist: '%s'\n", $2); free ($2); }
   | 's' var 't' var_printer 'x'
+       { free ($2); }
   ;
 
 var:
@@ -153,10 +155,10 @@ var_list:
     { $$ = $1; }
   | var ',' var_list
     {
-      char *s = (char *) malloc (strlen ($1) + 1 + strlen ($3) + 1);
-      strcpy (s, $1);
+      char *s = (char *) realloc ($1, strlen ($1) + 1 + strlen ($3) + 1);
       strcat (s, ",");
       strcat (s, $3);
+      free ($3);
       $$ = s;
     }
   ;
@@ -633,8 +635,6 @@ AT_CHECK([[./glr-regr7]], 2, [],
 [memory exhausted
 ])
 
-AT_XFAIL_IF(:)
-
 AT_CLEANUP
 
 
@@ -667,9 +667,9 @@ AT_DATA_GRAMMAR([glr-regr8.y],
 
 
 PortClause     : T_PORT InterfaceDeclaration T_PORT
-               { printf("%d/%d - %d/%d - %d/%d\n", 
-                        @1.first_column, @1.last_column, 
-                        @2.first_column, @2.last_column, 
+               { printf("%d/%d - %d/%d - %d/%d\n",
+                        @1.first_column, @1.last_column,
+                        @2.first_column, @2.last_column,
                         @3.first_column, @3.last_column); }
        ;
 
@@ -695,7 +695,7 @@ void yyerror(const char *msg)
 
 static int lexIndex;
 
-int yylex() 
+int yylex (void)
 {
   lexIndex += 1;
   switch (lexIndex)
@@ -714,7 +714,7 @@ int yylex()
 }
 
 int
-main (void) 
+main (void)
 {
   yyparse();
   return 0;
@@ -726,10 +726,92 @@ AT_CHECK([[bison -o glr-regr8.c glr-regr8.y]], 0, [],
 ])
 AT_COMPILE([glr-regr8])
 
-AT_CHECK([[./glr-regr8]], 0, 
+AT_CHECK([[./glr-regr8]], 0,
 [empty: 9/9
 1/9 - 9/9 - 13/17
 ],
 [])
 
 AT_CLEANUP
+
+
+## ------------------------------------------------------------------------- ##
+## No users destructors if stack 0 deleted                                   ##
+## Thanks to Joel E. Denny for this test; see                                ##
+## <http://lists.gnu.org/archive/html/bison-patches/2005-09/msg00109.html>.  ##
+## ------------------------------------------------------------------------- ##
+
+AT_SETUP([No users destructors if stack 0 deleted])
+
+AT_DATA_GRAMMAR([glr-regr9.y],
+[[
+%{
+# include <stdio.h>
+# include <stdlib.h>
+  static void yyerror (char const *);
+  static int yylex (void);
+# define YYSTACKEXPANDABLE 0
+  static int tokens = 0;
+  static int destructors = 0;
+# define USE(Var)
+%}
+
+%glr-parser
+%union { int dummy; }
+%type <dummy> 'a'
+
+%destructor {
+  destructors += 1;
+} 'a'
+
+%%
+
+start:
+    ambig0 'a'   { destructors += 2; USE ($2); }
+  | ambig1 start { destructors += 1; }
+  | ambig2 start { destructors += 1; }
+  ;
+
+ambig0: 'a' ;
+ambig1: 'a' ;
+ambig2: 'a' ;
+
+%%
+
+static int
+yylex (void)
+{
+  tokens += 1;
+  return 'a';
+}
+
+static void
+yyerror (char const *msg)
+{
+  fprintf (stderr, "%s\n", msg);
+}
+
+int
+main (void)
+{
+  int exit_status;
+  exit_status = yyparse ();
+  if (tokens != destructors)
+    {
+      fprintf (stderr, "Tokens = %d, Destructors = %d\n", tokens, destructors);
+      return 1;
+    }
+  return !exit_status;
+}
+]])
+
+AT_CHECK([[bison -o glr-regr9.c glr-regr9.y]], 0, [],
+[glr-regr9.y: conflicts: 1 reduce/reduce
+])
+AT_COMPILE([glr-regr9])
+
+AT_CHECK([[./glr-regr9]], 0, [],
+[memory exhausted
+])
+
+AT_CLEANUP