bison-patches
[Top][All Lists]
Advanced

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

Re: glr.c cleanup


From: Joel E. Denny
Subject: Re: glr.c cleanup
Date: Fri, 30 Dec 2005 20:48:16 -0500 (EST)

On Fri, 16 Dec 2005, Akim Demaille wrote:

> >>> "Joel" == Joel E Denny <address@hidden> writes:
> 
>  > I noticed b4_lpure_formals in glr.c.  It doesn't appear to be used
>  > anywhere.  Should we maintain it just for completeness?  Does
>  > someone have plans for it?
> 
> It must remain from earlier changes, feel free to remove it.

Here's some more trivial cleanup including the above.

Joel

2005-12-31  Joel E. Denny  <address@hidden>
        * data/glr.c: Reformat whitespace with tabs.
        (b4_lpure_formals): Remove this unused m4 macro.
        * tests/cxx-type.at: Reformat whitespace with tabs.
        (_AT_TEST_GLR_CXXTYPES): In union Node, rename node_info to nodeInfo
        since it's a member.  Rename type to isNterm for clarity.

Index: data/glr.c
===================================================================
RCS file: /sources/bison/bison/data/glr.c,v
retrieving revision 1.149
diff -p -u -r1.149 glr.c
--- data/glr.c  22 Dec 2005 13:01:50 -0000      1.149
+++ data/glr.c  31 Dec 2005 01:24:28 -0000
@@ -92,13 +92,6 @@ m4_define([b4_pure_formals],
 [b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals])
 
 
-# b4_lpure_formals
-# ----------------
-# Same as above, but on the look-ahead, hence yyllocp instead of yylocp.
-m4_define([b4_lpure_formals],
-[b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals])
-
-
 ## ----------------- ##
 ## Semantic Values.  ##
 ## ----------------- ##
@@ -495,7 +488,7 @@ static const ]b4_int_type_for([b4_stos])
 #ifndef YYLLOC_DEFAULT
 # define YYLLOC_DEFAULT(Current, Rhs, N)                               \
     do                                                                 \
-      if (YYID (N))                                                    \
+      if (YYID (N))                                                    \
        {                                                               \
          (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
          (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
@@ -584,8 +577,8 @@ do {                                                        
                    \
   if (yydebug)                                                             \
     {                                                                      \
       YYFPRINTF (stderr, "%s ", Title);                                        
    \
-      yy_symbol_print (stderr,                                             \
-                 Type, Value]b4_location_if([, Location])[]b4_user_args[); \
+      yy_symbol_print (stderr, Type,                                       \
+                      Value]b4_location_if([, Location])[]b4_user_args[);  \
       YYFPRINTF (stderr, "\n");                                                
    \
     }                                                                      \
 } while (YYID (0))
@@ -977,7 +970,7 @@ yydestroyGLRState (char const *yymsg, yy
        {
          YYFPRINTF (stderr, "%s unresolved ", yymsg);
          yy_symbol_print (stderr, yystos[yys->yylrState],
-                     &yys->yysemantics.yysval]b4_location_if([, 
&yys->yyloc])[]b4_user_args[);
+                          &yys->yysemantics.yysval]b4_location_if([, 
&yys->yyloc])[]b4_user_args[);
          YYFPRINTF (stderr, "\n");
        }
 #endif
@@ -1851,7 +1844,7 @@ yycompressStack (yyGLRStack* yystackp)
 
 static YYRESULTTAG
 yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
-                  size_t yyposn]b4_pure_formals[)
+                  size_t yyposn]b4_pure_formals[)
 {
   int yyaction;
   const short int* yyconflicts;
@@ -1885,7 +1878,7 @@ yyprocessOneStack (yyGLRStack* yystackp,
              YYDPRINTF ((stderr, "Reading a token: "));
              yychar = YYLEX;
              *yytokenp = YYTRANSLATE (yychar);
-             YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
+             YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
            }
          yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
 
@@ -1897,8 +1890,8 @@ yyprocessOneStack (yyGLRStack* yystackp,
                          (unsigned long int) yyk));
              YYCHK (yyglrReduce (yystackp, yynewStack,
                                  *yyconflicts, yyfalse]b4_user_args[));
-             YYCHK (yyprocessOneStack (yystackp, yynewStack,
-                                       yyposn]b4_pure_args[));
+             YYCHK (yyprocessOneStack (yystackp, yynewStack,
+                                       yyposn]b4_pure_args[));
              yyconflicts += 1;
            }
 
@@ -1912,8 +1905,8 @@ yyprocessOneStack (yyGLRStack* yystackp,
              break;
            }
          else
-           YYCHK (yyglrReduce (yystackp, yyk, -yyaction,
-                               yyfalse]b4_user_args[));
+           YYCHK (yyglrReduce (yystackp, yyk, -yyaction,
+                               yyfalse]b4_user_args[));
        }
     }
   return yyok;
@@ -2044,15 +2037,15 @@ yyrecoverSyntaxError (yyGLRStack* yystac
            yyGLRState *yys = yystackp->yytops.yystates[0];
            yyGLRStackItem yyerror_range[3];
            yyerror_range[1].yystate.yyloc = yys->yyloc;
-           yyerror_range[2].yystate.yyloc = yylloc;
+           yyerror_range[2].yystate.yyloc = yylloc;
            YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[
            yydestruct ("Error: discarding",
-                       *yytokenp, &yylval]b4_location_if([, 
&yylloc])[]b4_user_args[);
+                       *yytokenp, &yylval]b4_location_if([, 
&yylloc])[]b4_user_args[);
          }
        YYDPRINTF ((stderr, "Reading a token: "));
        yychar = YYLEX;
        *yytokenp = YYTRANSLATE (yychar);
-       YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
+       YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
        yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
        if (yyis_pact_ninf (yyj))
          return;
@@ -2091,12 +2084,12 @@ yyrecoverSyntaxError (yyGLRStack* yystac
            {
              /* Shift the error token having adjusted its location.  */
              YYLTYPE yyerrloc;]b4_location_if([[
-             yystackp->yyerror_range[2].yystate.yyloc = yylloc;
+             yystackp->yyerror_range[2].yystate.yyloc = yylloc;
              YYLLOC_DEFAULT (yyerrloc, yystackp->yyerror_range, 2);]])[
              YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
-                              &yylval, &yyerrloc);
+                              &yylval, &yyerrloc);
              yyglrShift (yystackp, 0, yytable[yyj],
-                         yys->yyposn, &yylval, &yyerrloc);
+                         yys->yyposn, &yylval, &yyerrloc);
              yys = yystackp->yytops.yystates[0];
              break;
            }
@@ -2194,8 +2187,8 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
              yyrule = yydefaultAction (yystate);
              if (yyrule == 0)
                {
-]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = 
yylloc;]])[
-                 yyreportSyntaxError (&yystack]b4_user_args[);
+]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = 
yylloc;]])[
+                 yyreportSyntaxError (&yystack]b4_user_args[);
                  goto yyuser_error;
                }
              YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
@@ -2207,25 +2200,25 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
                  YYDPRINTF ((stderr, "Reading a token: "));
                  yychar = YYLEX;
                  yytoken = YYTRANSLATE (yychar);
-                 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+                 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
                }
              yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
              if (*yyconflicts != 0)
                break;
              if (yyisShiftAction (yyaction))
                {
-                 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+                 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
                  if (yytoken != YYEOF)
                    yytoken = YYEMPTY;
                  yyposn += 1;
-                 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
+                 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
                  if (0 < yystack.yyerrState)
                    yystack.yyerrState -= 1;
                }
              else if (yyisErrorAction (yyaction))
                {
-]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = 
yylloc;]])[
-                 yyreportSyntaxError (&yystack]b4_user_args[);
+]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = 
yylloc;]])[
+                 yyreportSyntaxError (&yystack]b4_user_args[);
                  goto yyuser_error;
                }
              else
@@ -2259,7 +2252,7 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
             on yylval in the event of memory exhaustion.  */
 
          for (yys = 0; yys < yyn; yys += 1)
-           YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
+           YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
          yyremoveDeletes (&yystack);
          yyn = yystack.yytops.yysize;
 
@@ -2280,9 +2273,9 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
                              &yyconflicts);
              /* Note that yyconflicts were handled by yyprocessOneStack.  */
              YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
-             YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
+             YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
              yyglrShift (&yystack, yys, yyaction, yyposn,
-                         &yylval, &yylloc);
+                         &yylval, &yylloc);
              YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
                          (unsigned long int) yys,
                          yystack.yytops.yystates[yys]->yylrState));
@@ -2294,8 +2287,8 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
                yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
              YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
              YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
-]b4_location_if([[           yystack.yyerror_range[1].yystate.yyloc = 
yylloc;]])[
-             yyreportSyntaxError (&yystack]b4_user_args[);
+]b4_location_if([[           yystack.yyerror_range[1].yystate.yyloc = 
yylloc;]])[
+             yyreportSyntaxError (&yystack]b4_user_args[);
              goto yyuser_error;
            }
          else if (yystack.yytops.yysize == 1)
@@ -2332,7 +2325,7 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
  yyreturn:
   if (yytoken != YYEOF && yytoken != YYEMPTY)
     yydestruct ("Cleanup: discarding lookahead",
-               yytoken, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
+               yytoken, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
 
   /* If the stack is well-formed, pop the stack until it is empty,
      destroying its entries as we go.  But free the stack regardless
Index: tests/cxx-type.at
===================================================================
RCS file: /sources/bison/bison/tests/cxx-type.at,v
retrieving revision 1.29
diff -p -u -r1.29 cxx-type.at
--- tests/cxx-type.at   22 Dec 2005 00:24:40 -0000      1.29
+++ tests/cxx-type.at   31 Dec 2005 01:24:28 -0000
@@ -36,17 +36,17 @@ $1
   #include <stdio.h>
   union Node {
     struct {
-      int type;
+      int isNterm;
       int parents;
-    } node_info;
+    } nodeInfo;
     struct {
-      int type; /* 1 */
+      int isNterm; /* 1 */
       int parents;
       char const *form;
       union Node *children[3];
     } nterm;
     struct {
-      int type; /* 0 */
+      int isNterm; /* 0 */
       int parents;
       char *text;
     } term;
@@ -93,35 +93,35 @@ $1
 
 prog :
      | prog stmt   {
-                       char *output;]AT_LOCATION_IF([
+                       char *output;]AT_LOCATION_IF([
                        printf ("%d.%d-%d.%d: ",
                             @2.first_line, @2.first_column,
                             @2.last_line, @2.last_column);])[
-                       output = node_to_string (]$[2);
-                       printf ("%s\n", output);
-                       free (output);
-                       free_node (]$[2);
+                       output = node_to_string (]$[2);
+                       printf ("%s\n", output);
+                       free (output);
+                       free_node (]$[2);
                   }
      ;
 
 stmt : expr ';'  $2    { $$ = ]$[1; }
      | decl      $3
-     | error ';'       { $$ = new_nterm ("<error>", 0, 0, 0); }
+     | error ';'       { $$ = new_nterm ("<error>", 0, 0, 0); }
      | '@'             { YYACCEPT; }
      ;
 
 expr : ID
      | TYPENAME '(' expr ')'
-                       { $$ = new_nterm ("<cast>(%s,%s)", ]$[3, ]$[1, 0); }
-     | expr '+' expr   { $$ = new_nterm ("+(%s,%s)", ]$[1, ]$[3, 0); }
+                       { $$ = new_nterm ("<cast>(%s,%s)", ]$[3, ]$[1, 0); }
+     | expr '+' expr   { $$ = new_nterm ("+(%s,%s)", ]$[1, ]$[3, 0); }
      | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", ]$[1, ]$[3, 0); }
      ;
 
 decl : TYPENAME declarator ';'
-                       { $$ = new_nterm ("<declare>(%s,%s)", ]$[1, ]$[2, 0); }
+                       { $$ = new_nterm ("<declare>(%s,%s)", ]$[1, ]$[2, 0); }
      | TYPENAME declarator '=' expr ';'
-                       { $$ = new_nterm ("<init-declare>(%s,%s,%s)", ]$[1,
-                                         ]$[2, ]$[4); }
+                       { $$ = new_nterm ("<init-declare>(%s,%s,%s)", ]$[1,
+                                         ]$[2, ]$[4); }
      ;
 
 declarator : ID
@@ -200,13 +200,13 @@ yylex (LEX_PARAMETERS)
                ungetc (c, stdin);
                buffer[i++] = 0;
                tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
-               yylval = new_term (strcpy ((char *) malloc (i), buffer));
+               yylval = new_term (strcpy ((char *) malloc (i), buffer));
              }
            else
              {
                colNum += 1;
                tok = c;
-               yylval = 0;
+               yylval = 0;
              }
 #if YYLSP_NEEDED
            yylloc.last_column = colNum-1;
@@ -232,18 +232,18 @@ static Node *
 new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
 {
   Node *node = (Node *) malloc (sizeof (Node));
-  node->nterm.type = 1;
+  node->nterm.isNterm = 1;
   node->nterm.parents = 0;
   node->nterm.form = form;
   node->nterm.children[0] = child0;
   if (child0)
-    child0->node_info.parents += 1;
+    child0->nodeInfo.parents += 1;
   node->nterm.children[1] = child1;
   if (child1)
-    child1->node_info.parents += 1;
+    child1->nodeInfo.parents += 1;
   node->nterm.children[2] = child2;
   if (child2)
-    child2->node_info.parents += 1;
+    child2->nodeInfo.parents += 1;
   return node;
 }
 
@@ -251,7 +251,7 @@ static Node *
 new_term (char *text)
 {
   Node *node = (Node *) malloc (sizeof (Node));
-  node->term.type = 0;
+  node->term.isNterm = 0;
   node->term.parents = 0;
   node->term.text = text;
   return node;
@@ -262,11 +262,11 @@ free_node (Node *node)
 {
   if (!node)
     return;
-  node->node_info.parents -= 1;
+  node->nodeInfo.parents -= 1;
   /* Free only if 0 (last parent) or -1 (no parents).  */
-  if (node->node_info.parents > 0)
+  if (node->nodeInfo.parents > 0)
     return;
-  if (node->node_info.type == 1)
+  if (node->nodeInfo.isNterm == 1)
     {
       free_node (node->nterm.children[0]);
       free_node (node->nterm.children[1]);
@@ -289,7 +289,7 @@ node_to_string (Node *node)
       buffer = (char *) malloc (1);
       buffer[0] = 0;
     }
-  else if (node->node_info.type == 1)
+  else if (node->nodeInfo.isNterm == 1)
     {
       child0 = node_to_string (node->nterm.children[0]);
       child1 = node_to_string (node->nterm.children[1]);
@@ -409,61 +409,61 @@ m4_define([_AT_VERBOSE_GLR_STDERR],
 
 AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
 _AT_TEST_GLR_CXXTYPES([],
-                      [%dprec 1], [%dprec 2])
+                     [%dprec 1], [%dprec 2])
 AT_PARSER_CHECK([[./types test-input]], 0,
-                _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
+               _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
 AT_CLEANUP
 
 AT_SETUP([GLR: Resolve ambiguity, impure, locations])
 _AT_TEST_GLR_CXXTYPES([%locations],[%dprec 1],[%dprec 2])
 AT_PARSER_CHECK([[./types test-input]], 0,
-                _AT_RESOLVED_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR)
+               _AT_RESOLVED_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR)
 AT_CLEANUP
 
 AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
 _AT_TEST_GLR_CXXTYPES([%pure-parser],
-                      [%dprec 1], [%dprec 2])
+                     [%dprec 1], [%dprec 2])
 AT_PARSER_CHECK([[./types test-input]], 0,
-                _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
+               _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
 AT_CLEANUP
 
 AT_SETUP([GLR: Resolve ambiguity, pure, locations])
 _AT_TEST_GLR_CXXTYPES([%pure-parser %locations],
-                      [%dprec 1], [%dprec 2])
+                     [%dprec 1], [%dprec 2])
 AT_PARSER_CHECK([[./types test-input]], 0,
-                _AT_RESOLVED_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR)
+               _AT_RESOLVED_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR)
 AT_CLEANUP
 
 AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
 _AT_TEST_GLR_CXXTYPES([],
-                      [%merge <stmtMerge>], [%merge <stmtMerge>])
+                     [%merge <stmtMerge>], [%merge <stmtMerge>])
 AT_PARSER_CHECK([[./types test-input]], 0,
-                _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
+               _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
 AT_CLEANUP
 
 AT_SETUP([GLR: Merge conflicting parses, impure, locations])
 _AT_TEST_GLR_CXXTYPES([%locations],
-                      [%merge <stmtMerge>], [%merge <stmtMerge>])
+                     [%merge <stmtMerge>], [%merge <stmtMerge>])
 AT_PARSER_CHECK([[./types test-input]], 0,
-                _AT_AMBIG_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR)
+               _AT_AMBIG_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR)
 AT_CLEANUP
 
 AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
 _AT_TEST_GLR_CXXTYPES([%pure-parser],
-                      [%merge <stmtMerge>], [%merge <stmtMerge>])
+                     [%merge <stmtMerge>], [%merge <stmtMerge>])
 AT_PARSER_CHECK([[./types test-input]], 0,
-                _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
+               _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
 AT_CLEANUP
 AT_SETUP([GLR: Merge conflicting parses, pure, locations])
 _AT_TEST_GLR_CXXTYPES([%pure-parser %locations],
-                      [%merge <stmtMerge>],[%merge <stmtMerge>])
+                     [%merge <stmtMerge>],[%merge <stmtMerge>])
 AT_PARSER_CHECK([[./types test-input]], 0,
-                _AT_AMBIG_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR)
+               _AT_AMBIG_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR)
 AT_CLEANUP
 
 AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
 _AT_TEST_GLR_CXXTYPES([%error-verbose],
-                      [%merge <stmtMerge>], [%merge <stmtMerge>])
+                     [%merge <stmtMerge>], [%merge <stmtMerge>])
 AT_PARSER_CHECK([[./types test-input]], 0,
-               _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR)
+               _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR)
 AT_CLEANUP




reply via email to

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