bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Test yydestructor and locations


From: Akim Demaille
Subject: Test yydestructor and locations
Date: 19 Jun 2002 14:03:28 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * tests/actions.at (Destructors): Augment to test locations.
        * data/bison.simple (yydestructor): Pass it the current location
        if locations are enabled.
        Prototype only when __STDC__ or C++.
        Change the argument names to move into the yy name space: there is
        user code here.

Index: data/bison.simple
===================================================================
RCS file: /cvsroot/bison/bison/data/bison.simple,v
retrieving revision 1.40
diff -u -u -r1.40 bison.simple
--- data/bison.simple 19 Jun 2002 10:00:24 -0000 1.40
+++ data/bison.simple 19 Jun 2002 12:02:45 -0000
@@ -667,7 +667,11 @@
 int yyparse (void);
 # endif
 #endif
-static void yydestructor (int symbol_type, YYSTYPE symbol_value);
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void yydestructor (int yytype,
+                         YYSTYPE yyvalue[]b4_location_if([, YYLTYPE 
yylocation]));
+#endif
 
 m4_divert_push([KILL])# ======================== M4 code.
 # b4_declare_parser_variables
@@ -1126,7 +1130,7 @@
                    }
                }
 #endif
-             yydestructor (yystos[*yyssp], *yyvsp);
+             yydestructor (yystos[*yyssp], *yyvsp]b4_location_if([, *yylsp])[);
              YYPOPSTACK;
            }
          YYABORT;
@@ -1134,7 +1138,7 @@
 
       YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
                  yychar, yytname[yychar1]));
-      yydestructor (yychar1, yylval);
+      yydestructor (yychar1, yylval]b4_location_if([, yylloc])[);
       yychar = YYEMPTY;
     }
 
@@ -1181,7 +1185,7 @@
        }
 #endif
 
-      yydestructor (yystos[yystate], *yyvsp);
+      yydestructor (yystos[yystate], *yyvsp]b4_location_if([, *yylsp])[);
       yyvsp--;
       yystate = *--yyssp;
 ]b4_location_if([      yylsp--;])[
@@ -1251,24 +1255,27 @@
 # b4_symbol_destructor(SYMBOL-NUMBER, DESTRUCTOR, TYPE-NAME)
 # ----------------------------------------------------------
 m4_define([b4_symbol_destructor],
-[m4_pushdef([b4_dollar_dollar], [symbol_value.$6])dnl
+[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
+m4_pushdef([b4_at_dollar], [yylocation])dnl
       case $4: /* $3 */
 #line $2 "$1"
         $5;
 #line __oline__ "__ofile__"
         break;
+m4_popdef([b4_at_dollar])dnl
 m4_popdef([b4_dollar_dollar])])
 
 m4_divert_pop([KILL])dnl# End of M4 code.
 static void
-yydestructor (int symbol_type, YYSTYPE symbol_value)
+yydestructor (int yytype,
+             YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]))
 {
-  switch (symbol_type)
+  switch (yytype)
     {
 m4_map([b4_symbol_destructor], m4_defn([b4_symbol_destructors]))dnl
       default:
         YYDPRINTF ((stderr, "yydestructor: unknown symbol type: %d (%s)\n",
-                   symbol_type, yytname[[symbol_type]]));
+                   yytype, yytname[[yytype]]));
         break;
     }
 }
Index: tests/actions.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/actions.at,v
retrieving revision 1.7
diff -u -u -r1.7 actions.at
--- tests/actions.at 18 Jun 2002 09:12:58 -0000 1.7
+++ tests/actions.at 19 Jun 2002 12:02:45 -0000
@@ -177,10 +177,10 @@
   int ival;
 }
 %type <ival> 'x' thing line input
-%destructor { printf ("Freeing input %d\n", $$); } input
-%destructor { printf ("Freeing line %d\n", $$); } line
-%destructor { printf ("Freeing thing %d\n", $$); } thing
-%destructor { printf ("Freeing 'x' %d\n", $$); } 'x'
+%destructor { printf ("Freeing input %d from %d\n", $$, @$.first_line); } input
+%destructor { printf ("Freeing line %d from %d\n", $$, @$.first_line); } line
+%destructor { printf ("Freeing thing %d from %d\n", $$, @$.first_line); } thing
+%destructor { printf ("Freeing 'x' %d from %d\n", $$, @$.first_line); } 'x'
 
 %{
 static int yylex (void);
@@ -256,6 +256,8 @@
     {
        yylval.ival = counter;
        printf ("sending: '%c'(%d)\n", input[counter], counter);
+       /* As in BASIC, line numbers go from 10 to 10.  */
+       yylloc.first_line = 10 * counter;
        return input[counter++];
     }
   else
@@ -268,7 +270,7 @@
 static void
 yyerror (const char *msg)
 {
-  fprintf (stdout, "%s\n", msg);
+  fprintf (stdout, "%d: %s\n", yylloc.first_line, msg);
 }
 
 static void
@@ -291,7 +293,7 @@
 }
 ]])
 
-AT_CHECK([bison input.y -d -v -o input.c])
+AT_CHECK([bison input.y --location -d -v -o input.c])
 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
 AT_CHECK([./input], 1,
 [[sending: 'x'(0)
@@ -301,15 +303,15 @@
 sending: 'x'(2)
 thing(2): 'x'(2)
 sending: 'x'(3)
-parse error, unexpected 'x', expecting ';'
-Freeing thing 2
-Freeing thing 1
-Freeing thing 0
-Freeing 'x' 3
+30: parse error, unexpected 'x', expecting ';'
+Freeing thing 2 from 20
+Freeing thing 1 from 10
+Freeing thing 0 from 0
+Freeing 'x' 3 from 30
 sending: 'x'(4)
-Freeing 'x' 4
+Freeing 'x' 4 from 40
 sending: 'x'(5)
-Freeing 'x' 5
+Freeing 'x' 5 from 50
 sending: ';'(6)
 line(-1): error ';'
 sending: 'x'(7)
@@ -323,11 +325,11 @@
 sending: ';'(11)
 line(10): thing(10) ';'
 sending: 'y'(12)
-parse error, unexpected $undefined., expecting $ or error or 'x'
+120: parse error, unexpected $undefined., expecting $ or error or 'x'
 sending: EOF
-Freeing line 10
-Freeing line 7
-Freeing line -1
+Freeing line 10 from 100
+Freeing line 7 from 70
+Freeing line -1 from 50
 Parsing FAILED.
 ]])
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]