bison-patches
[Top][All Lists]
Advanced

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

Re: Bison 1.30f


From: Paul Eggert
Subject: Re: Bison 1.30f
Date: Wed, 12 Dec 2001 18:47:15 -0800 (PST)

> From: Akim Demaille <address@hidden>
> Date: 12 Dec 2001 16:29:33 +0100
> 
> If you can reach an agreement, then please, Paul, install your patch
> on both branches.

OK, I installed the patch enclosed below on the bison-1_29-branch.  I
think it addresses all the issues he mentioned (at least, the ones
that can be easily addressed).  I'll do the main branch next.

> I plan to release Bison with a week, please, people, make up your
> minds quickly.

OK.  Will you generate another test version first?  1.30f didn't work
on the Awk grammar; it'd be nice to have a test version that I could
try on some real .y files before unleashing this on the world.


2001-12-12  Paul Eggert  <address@hidden>

        * src/bison.simple (YYSIZE_T, YYSTACK_ALLOC, YYSTACK_FREE):
        Do not infringe on the global user namespace when using C++.
        (YYFPRINTF, YYSTDERR): New macros, needed for the above.
        All uses of `fprintf' and `stderr' changed.

        * src/output.c (output): Do not output "#include <stdio.h>"; that
        is bison.simple's job.  stdio.h should be included only if
        necessary, to avoid infringing on the user name space when
        possible.

        * doc/bison.texinfo: Document YYFPRINTF, YYSTDERR.

--- doc/bison.texinfo.~1.37.2.11.~      Fri Nov 30 09:52:33 2001
+++ doc/bison.texinfo   Wed Dec 12 18:43:39 2001
@@ -707,6 +707,7 @@ those cases your code should respect the
 headers.  On some address@hidden hosts, @code{<alloca.h>},
 @code{<stddef.h>}, and @code{<stdlib.h>} are included as needed to
-declare memory allocators and related types.  On all hosts,
address@hidden<stdio.h>} is included if you define @code{YYDEBUG}
+declare memory allocators and related types.  In the same situation,
+C++ parsers may include @code{<cstddef>} and @code{<cstdlib>} instead.
+Other system headers may be included if you define @code{YYDEBUG}
 (@pxref{Debugging, ,Debugging Your Parser}).
 
@@ -4932,6 +4933,12 @@ you run Bison (@pxref{Invocation, ,Invok
 debugging is always possible.
 
-The trace facility uses @code{stderr}, so you must add @address@hidden
-<stdio.h>}} to the C declarations section unless it is already there.
+The trace facility outputs messages with macro calls of the form
address@hidden (YYSTDERR, @var{format}, @var{args})} where
address@hidden and @var{args} are the usual @code{printf} format and
+arguments.  If you define @code{YYDEBUG} but do not define
address@hidden, @code{<stdio.h>} is automatically included and the
+macros are defined to @code{fprintf} and @code{stderr}.  In the same
+situation, C++ parsers include @code{<cstdio.h>} instead, and use
address@hidden::fprintf} and @code{std::stderr}.
 
 Once you have compiled the program with trace facilities, the way to
@@ -5012,5 +5019,5 @@ Here @var{infile} is the grammar file na
 with @samp{.tab.c}.  Thus, the @samp{bison foo.y} filename yields
 @file{foo.tab.c}, and the @samp{bison hack/foo.y} filename yields
address@hidden/foo.tab.c}. It's is also possible, in case you are writting
address@hidden/foo.tab.c}. It's is also possible, in case you are writing
 C++ code instead of C in your grammar file, to name it @file{foo.ypp}
 or @file{foo.y++}. Then, the output files will take an extention like
Index: src/bison.simple
===================================================================
RCS file: /cvsroot/bison/bison/src/bison.simple,v
retrieving revision 1.53.2.12
diff -p -u -r1.53.2.12 bison.simple
--- src/bison.simple    4 Dec 2001 14:06:06 -0000       1.53.2.12
+++ src/bison.simple    13 Dec 2001 02:15:54 -0000
@@ -32,7 +32,7 @@
    infringing on user name space.  This should be done even for local
    variables, as they might otherwise be expanded by user macros.
    There are some unavoidable exceptions within include files to
-   define necessary C library symbols; they are noted "INFRINGES ON
+   define necessary library symbols; they are noted "INFRINGES ON
    USER NAME SPACE" below.  */
 
 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
@@ -69,11 +69,18 @@
    /* Pacify GCC's `empty if-body' warning. */
 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
 # else
-#  define YYSTACK_ALLOC malloc
-#  define YYSTACK_FREE(Ptr) free (Ptr)
-#  if defined (__STDC__) || defined (__cplusplus)
-#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-#   define YYSIZE_T size_t
+#  ifdef __cplusplus
+#   include <cstdlib> /* INFRINGES ON USER NAME SPACE */
+#   define YYSIZE_T std::size_t
+#   define YYSTACK_ALLOC std::malloc
+#   define YYSTACK_FREE std::free
+#  else
+#   ifdef __STDC__
+#    include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+#    define YYSIZE_T size_t
+#   endif
+#   define YYSTACK_ALLOC malloc
+#   define YYSTACK_FREE free
 #  endif
 # endif
 
@@ -128,9 +135,16 @@ union yyalloc
 #if ! defined (YYSIZE_T) && defined (size_t)
 # define YYSIZE_T size_t
 #endif
-#if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
-# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
-# define YYSIZE_T size_t
+#if ! defined (YYSIZE_T)
+# ifdef __cplusplus
+#  include <cstddef> /* INFRINGES ON USER NAME SPACE */
+#  define YYSIZE_T std::size_t
+# else
+#  ifdef __STDC__
+#   include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+#   define YYSIZE_T size_t
+#  endif
+# endif
 #endif
 #if ! defined (YYSIZE_T)
 # define YYSIZE_T unsigned int
@@ -206,11 +220,23 @@ while (0)
 
 /* Enable debugging if requested.  */
 #if YYDEBUG
-# include <stdio.h>
+
+# ifndef YYFPRINTF
+#  ifdef __cplusplus
+#   include <cstdio.h> /* INFRINGES ON USER NAME SPACE */
+#   define YYFPRINTF std::fprintf
+#   define YYSTDERR std::stderr
+#  else
+#   include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+#   define YYFPRINTF fprintf
+#   define YYSTDERR stderr
+#  endif
+# endif
+
 # define YYDPRINTF(Args)                       \
 do {                                           \
   if (yydebug)                                 \
-    fprintf Args;                              \
+    YYFPRINTF Args;                            \
 } while (0)
 /* Nonzero means print parse trace. [The following comment makes no
    sense to me.  Could someone clarify it?  --akim] Since this is
@@ -443,7 +469,7 @@ yyparse (YYPARSE_PARAM_ARG)
      rule. */
   int yylen;
 
-  YYDPRINTF ((stderr, "Starting parse\n"));
+  YYDPRINTF ((YYSTDERR, "Starting parse\n"));
 
   yystate = 0;
   yyerrstatus = 0;
@@ -539,14 +565,14 @@ yyparse (YYPARSE_PARAM_ARG)
       yylsp = yyls + yysize - 1;
 #endif
 
-      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+      YYDPRINTF ((YYSTDERR, "Stack size increased to %lu\n",
                  (unsigned long int) yystacksize));
 
       if (yyssp >= yyss + yystacksize - 1)
        YYABORT;
     }
 
-  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+  YYDPRINTF ((YYSTDERR, "Entering state %d\n", yystate));
 
   goto yybackup;
 
@@ -573,7 +599,7 @@ yybackup:
 
   if (yychar == YYEMPTY)
     {
-      YYDPRINTF ((stderr, "Reading a token: "));
+      YYDPRINTF ((YYSTDERR, "Reading a token: "));
       yychar = YYLEX;
     }
 
@@ -584,7 +610,7 @@ yybackup:
       yychar1 = 0;
       yychar = YYEOF;          /* Don't call YYLEX any more */
 
-      YYDPRINTF ((stderr, "Now at end of input.\n"));
+      YYDPRINTF ((YYSTDERR, "Now at end of input.\n"));
     }
   else
     {
@@ -595,13 +621,14 @@ yybackup:
        which are defined only if `YYDEBUG' is set.  */
       if (yydebug)
        {
-         fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
+         YYFPRINTF (YYSTDERR, "Next token is %d (%s",
+                    yychar, yytname[yychar1]);
          /* Give the individual parser a way to print the precise
             meaning of a token, for further debugging info.  */
 # ifdef YYPRINT
-         YYPRINT (stderr, yychar, yylval);
+         YYPRINT (YYSTDERR, yychar, yylval);
 # endif
-         fprintf (stderr, ")\n");
+         YYFPRINTF (YYSTDERR, ")\n");
        }
 #endif
     }
@@ -633,7 +660,8 @@ yybackup:
     YYACCEPT;
 
   /* Shift the lookahead token.  */
-  YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]));
+  YYDPRINTF ((YYSTDERR, "Shifting token %d (%s), ",
+             yychar, yytname[yychar1]));
 
   /* Discard the token being shifted unless it is eof.  */
   if (yychar != YYEOF)
@@ -694,13 +722,13 @@ yyreduce:
     {
       int yyi;
 
-      fprintf (stderr, "Reducing via rule %d (line %d), ",
-              yyn, yyrline[yyn]);
+      YYFPRINTF (YYSTDERR, "Reducing via rule %d (line %d), ",
+                yyn, yyrline[yyn]);
 
       /* Print the symbols being reduced, and their result.  */
       for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
-       fprintf (stderr, "%s ", yytname[yyrhs[yyi]]);
-      fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
+       YYFPRINTF (YYSTDERR, "%s ", yytname[yyrhs[yyi]]);
+      YYFPRINTF (YYSTDERR, " -> %s\n", yytname[yyr1[yyn]]);
     }
 #endif
 %% actions /* The action file replaces this line. */
@@ -716,10 +744,10 @@ yyreduce:
   if (yydebug)
     {
       short *yyssp1 = yyss - 1;
-      fprintf (stderr, "state stack now");
+      YYFPRINTF (YYSTDERR, "state stack now");
       while (yyssp1 != yyssp)
-       fprintf (stderr, " %d", *++yyssp1);
-      fprintf (stderr, "\n");
+       YYFPRINTF (YYSTDERR, " %d", *++yyssp1);
+      YYFPRINTF (YYSTDERR, "\n");
     }
 #endif
 
@@ -815,7 +843,7 @@ yyerrlab1:
       /* return failure if at end of input */
       if (yychar == YYEOF)
        YYABORT;
-      YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
+      YYDPRINTF ((YYSTDERR, "Discarding token %d (%s).\n",
                  yychar, yytname[yychar1]));
       yychar = YYEMPTY;
     }
@@ -861,10 +889,10 @@ yyerrpop:
   if (yydebug)
     {
       short *yyssp1 = yyss - 1;
-      fprintf (stderr, "Error: state stack now");
+      YYFPRINTF (YYSTDERR, "Error: state stack now");
       while (yyssp1 != yyssp)
-       fprintf (stderr, " %d", *++yyssp1);
-      fprintf (stderr, "\n");
+       YYFPRINTF (YYSTDERR, " %d", *++yyssp1);
+      YYFPRINTF (YYSTDERR, "\n");
     }
 #endif
 
@@ -894,7 +922,7 @@ yyerrhandle:
   if (yyn == YYFINAL)
     YYACCEPT;
 
-  YYDPRINTF ((stderr, "Shifting error token, "));
+  YYDPRINTF ((YYSTDERR, "Shifting error token, "));
 
   *++yyvsp = yylval;
 #if YYLSP_NEEDED
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.39.2.17
diff -p -u -r1.39.2.17 output.c
--- src/output.c        5 Dec 2001 09:24:54 -0000       1.39.2.17
+++ src/output.c        13 Dec 2001 02:15:54 -0000
@@ -1277,9 +1277,6 @@ output (void)
     obstack_fgrow1 (&table_obstack, "#include %s\n",
                    quotearg_style (c_quoting_style, attrsfile));
 
-  if (!no_parser_flag)
-    obstack_sgrow (&table_obstack, "#include <stdio.h>\n\n");
-
   LIST_FREE (core, first_state);
   output_defines ();
   output_token_translations ();



reply via email to

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