]> git.saurik.com Git - bison.git/commitdiff
c++: more YY_NULL
authorAkim Demaille <akim@lrde.epita.fr>
Sun, 1 Apr 2012 11:15:41 +0000 (13:15 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Sun, 1 Apr 2012 12:02:27 +0000 (14:02 +0200)
Caught by maintainer-check-g++.
* data/glr.c, data/lalr1.cc, data/yacc.c, tests/cxx-type.at,
* tests/glr-regression.at, tests/push.at:
When simple to do, avoid expliciting the null ptr.
Otherwise use YY_NULL.
(cherry picked from commit eeaf1dc646048e464d97f6a572b8894632e6e47a)

Conflicts:

data/glr.c
data/lalr1.cc
tests/cxx-type.at

data/yacc.c
tests/cxx-type.at
tests/glr-regression.at
tests/push.at

index 284e13de56a7eb87f18e48ba3d03969cc84273bb..19fd3011537c56b6936666cc9d63547d2283eee8 100644 (file)
@@ -1245,12 +1245,12 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
                 ]b4_lac_if([[yytype_int16 *yyesa, yytype_int16 **yyes,
                 YYSIZE_T *yyes_capacity, ]])[yytype_int16 *yyssp, int yytoken)
 {
-  YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
+  YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
   YYSIZE_T yysize = yysize0;
   YYSIZE_T yysize1;
   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
   /* Internationalized format string. */
-  const char *yyformat = 0;
+  const char *yyformat = YY_NULL;
   /* Arguments of yyformat. */
   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
   /* Number of reported tokens (one for the "unexpected", one per
@@ -1328,7 +1328,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
                     break;
                   }
                 yyarg[yycount++] = yytname[yyx];
-                yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+                yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
                 if (! (yysize <= yysize1
                        && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
                   return 2;
@@ -1417,7 +1417,7 @@ static char yypstate_allocated = 0;]])b4_pull_if([
 
 b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[
 {
-  return yypull_parse (0]m4_ifset([b4_parse_param],
+  return yypull_parse (YY_NULL]m4_ifset([b4_parse_param],
                                   [[, ]b4_c_args(b4_parse_param)])[);
 }
 
@@ -1430,7 +1430,9 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[
   int yychar;
   YYSTYPE yylval;]b4_locations_if([[
   YYLTYPE yylloc;]])])[
-  if (yyps == 0)
+  if (yyps)
+    yyps_local = yyps;
+  else
     {
       yyps_local = yypstate_new ();
       if (!yyps_local)
@@ -1441,14 +1443,12 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[
           return 2;
         }
     }
-  else
-    yyps_local = yyps;
   do {
     yychar = YYLEX;
     yystatus =
       yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])[);
   } while (yystatus == YYPUSH_MORE);
-  if (yyps == 0)
+  if (!yyps)
     yypstate_delete (yyps_local);
   return yystatus;
 }]])[
@@ -1458,10 +1458,10 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[
 {
   yypstate *yyps;]b4_pure_if([], [[
   if (yypstate_allocated)
-    return 0;]])[
+    return YY_NULL;]])[
   yyps = (yypstate *) malloc (sizeof *yyps);
   if (!yyps)
-    return 0;
+    return YY_NULL;
   yyps->yynew = 1;]b4_pure_if([], [[
   yypstate_allocated = 1;]])[
   return yyps;
index 0c2b9605358fea9a643f0ac9221639cf99717ef8..746d05a49ba7bc99eb4b635ad070cc47442716af 100644 (file)
@@ -92,35 +92,35 @@ $1
 
 prog :
      | prog stmt   {
-                       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);
-                  }
+                        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);
+                   }
      ;
 
-stmt : expr ';'  $2    { $$ = ]$[1; }
+stmt : expr ';'  $2     { $$ = ]$[1; }
      | decl      $3
-     | error ';'       { $$ = new_nterm ("<error>", 0, 0, 0); }
-     | '@'             { YYACCEPT; }
+     | error ';'        { $$ = new_nterm ("<error>", YY_NULL, YY_NULL, YY_NULL); }
+     | '@'              { YYACCEPT; }
      ;
 
 expr : ID
      | TYPENAME '(' expr ')'
-                       { $$ = 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); }
+                        { $$ = new_nterm ("<cast>(%s,%s)", ]$[3, ]$[1, YY_NULL); }
+     | expr '+' expr    { $$ = new_nterm ("+(%s,%s)", ]$[1, ]$[3, YY_NULL); }
+     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", ]$[1, ]$[3, YY_NULL); }
      ;
 
 decl : TYPENAME declarator ';'
-                       { $$ = new_nterm ("<declare>(%s,%s)", ]$[1, ]$[2, 0); }
+                        { $$ = new_nterm ("<declare>(%s,%s)", ]$[1, ]$[2, YY_NULL); }
      | 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
@@ -163,60 +163,60 @@ yylex (LEX_PARAMETERS)
   while (1)
     {
       if (feof (stdin))
-       abort ();
+        abort ();
       c = getchar ();
       switch (c)
-       {
-       case EOF:
-         return 0;
-       case '\t':
-         colNum = (colNum + 7) & ~7;
-         break;
-       case ' ': case '\f':
-         colNum += 1;
-         break;
-       case '\n':
-         lineNum += 1;
-         colNum = 0;
-         break;
-       default:
-         {
-           int tok;
+        {
+        case EOF:
+          return 0;
+        case '\t':
+          colNum = (colNum + 7) & ~7;
+          break;
+        case ' ': case '\f':
+          colNum += 1;
+          break;
+        case '\n':
+          lineNum += 1;
+          colNum = 0;
+          break;
+        default:
+          {
+            int tok;
 #if YYLSP_NEEDED
-           yylloc.first_line = yylloc.last_line = lineNum;
-           yylloc.first_column = colNum;
+            yylloc.first_line = yylloc.last_line = lineNum;
+            yylloc.first_column = colNum;
 #endif
-           if (isalpha (c))
-             {
-               i = 0;
-
-               do
-                 {
-                   buffer[i++] = c;
-                   colNum += 1;
-                   if (i == sizeof buffer - 1)
-                     abort ();
-                   c = getchar ();
-                 }
-               while (isalnum (c) || c == '_');
-
-               ungetc (c, stdin);
-               buffer[i++] = 0;
-               tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
-               yylval = new_term (strcpy ((char *) malloc (i), buffer));
-             }
-           else
-             {
-               colNum += 1;
-               tok = c;
-               yylval = 0;
-             }
+            if (isalpha (c))
+              {
+                i = 0;
+
+                do
+                  {
+                    buffer[i++] = c;
+                    colNum += 1;
+                    if (i == sizeof buffer - 1)
+                      abort ();
+                    c = getchar ();
+                  }
+                while (isalnum (c) || c == '_');
+
+                ungetc (c, stdin);
+                buffer[i++] = 0;
+                tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
+                yylval = new_term (strcpy ((char *) malloc (i), buffer));
+              }
+            else
+              {
+                colNum += 1;
+                tok = c;
+                yylval = YY_NULL;
+              }
 #if YYLSP_NEEDED
-           yylloc.last_column = colNum-1;
+            yylloc.last_column = colNum-1;
 #endif
-           return tok;
-         }
-       }
+            return tok;
+          }
+        }
     }
 }
 
@@ -298,7 +298,7 @@ node_to_string (Node *node)
       child1 = node_to_string (node->nterm.children[1]);
       child2 = node_to_string (node->nterm.children[2]);
       buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
-                               + strlen (child1) + strlen (child2) + 1);
+                                + strlen (child1) + strlen (child2) + 1);
       sprintf (buffer, node->nterm.form, child0, child1, child2);
       free (child0);
       free (child1);
@@ -314,7 +314,7 @@ m4_bmatch([$2], [stmtMerge],
 [[static YYSTYPE
 stmtMerge (YYSTYPE x0, YYSTYPE x1)
 {
-  return new_nterm ("<OR>(%s,%s)", x0, x1, 0);
+  return new_nterm ("<OR>(%s,%s)", x0, x1, YY_NULL);
 }
 ]])
 )
@@ -412,61 +412,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([%define api.pure],
-                     [%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([%define api.pure %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([%define api.pure],
-                     [%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([%define api.pure %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
index d1d0b878d4916c5b2bb616fb0c8a23849bec021b..0cbffd190e225a734ed6fb3eccdcf27169f18037 100644 (file)
@@ -298,7 +298,7 @@ static void yyerror(char const * s) {
   fprintf(stderr,"error: %s\n",s);
 }
 
-FILE *input = NULL;
+FILE *input = YY_NULL;
 
 int P[] = { P1, P2 };
 int O[] = { O1, O2 };
index adb51358aef8bad5a6d0ed21ad1d532a1ba670aa..21322f0dd5f3a8572ef24e6a2b9974fbfda43e99 100644 (file)
@@ -60,12 +60,12 @@ main (void)
   /* yypstate_delete used to leak ps->yyss if the stack was reallocated but the
      parse did not return on success, syntax error, or memory exhaustion.  */
   ps = yypstate_new ();
-  assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
+  assert (yypush_parse (ps, 'a', YY_NULL) == YYPUSH_MORE);
   yypstate_delete (ps);
 
   ps = yypstate_new ();
-  assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
-  assert (yypush_parse (ps, 'b', NULL) == YYPUSH_MORE);
+  assert (yypush_parse (ps, 'a', YY_NULL) == YYPUSH_MORE);
+  assert (yypush_parse (ps, 'b', YY_NULL) == YYPUSH_MORE);
   yypstate_delete (ps);
 
   return 0;
@@ -124,11 +124,11 @@ main (void)
     {
       ps = yypstate_new ();
       assert (ps);
-      assert (yypstate_new () == NULL);
+      assert (yypstate_new () == YY_NULL);
       ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
       yychar = 0;
       assert (yypush_parse (ps) == 0);
-      assert (yypstate_new () == NULL);
+      assert (yypstate_new () == YY_NULL);
       ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
       yypstate_delete (ps);
     }