bug-bison
[Top][All Lists]
Advanced

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

Re: portability fix for bison-1.75


From: Paul Eggert
Subject: Re: portability fix for bison-1.75
Date: Mon, 23 Jan 2006 00:12:59 -0800
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

I installed the following patch into Bison CVS to work around the
Bison compatibility issue with Pike 7.0.  With this patch, Pike 7.0
builds (with a lot of warnings due to some other problems -- but it
builds).  This patch should appear in Bison 2.2.

2006-01-22  Paul Eggert  <address@hidden>

        Work around a bug in Pike 7.0, and give the Pike folks a
        better way to override the usual int widths.
        * data/yacc.c (b4_int_type): Use yytype_uint8, etc., so that the
        user can override the types.
        (short): #undef, to work around a bug in Pike 7.0.
        (yytype_uint8, yytype_int8, yytype_uint16, yytype_int16): New types.
        (union yyalloc.yyss): Use yytype_int16 rather than short.
        All uses changed.
        (yysigned_char): Remove.
        * src/parse-gram.y (YYTYPE_UINT8, YYTYPE_INT8, YYTYPE_UINT16):
        (YYTYPE_INT16): New macros, to test the new facility in yacc.c.
        * tests/regression.at (Web2c Actions): Adjust to above changes.

Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.131
diff -p -u -r1.131 yacc.c
--- data/yacc.c 22 Jan 2006 07:38:49 -0000      1.131
+++ data/yacc.c 23 Jan 2006 07:53:57 -0000
@@ -71,14 +71,15 @@ m4_ifdef([b4_lex_param], b4_lex_param)))
 # b4_int_type(MIN, MAX)
 # ---------------------
 # Return the smallest int type able to handle numbers ranging from
-# MIN to MAX (included).  We overwrite the version from c.m4 which relies
-# on "signed char" which is not portable to old K&R compilers.
+# MIN to MAX (included).  Overwrite the version from c.m4, which
+# uses only C89 types, so that the user can override the shorter
+# types, and so that pre-C89 compilers are handled correctly.
 m4_define([b4_int_type],
-[m4_if(b4_ints_in($@,      [0],   [255]), [1], [unsigned char],
-       b4_ints_in($@,   [-128],   [127]), [1], [yysigned_char],
+[m4_if(b4_ints_in($@,      [0],   [255]), [1], [yytype_uint8],
+       b4_ints_in($@,   [-128],   [127]), [1], [yytype_int8],
 
-       b4_ints_in($@,      [0], [65535]), [1], [unsigned short int],
-       b4_ints_in($@, [-32768], [32767]), [1], [short int],
+       b4_ints_in($@,      [0], [65535]), [1], [yytype_uint16],
+       b4_ints_in($@, [-32768], [32767]), [1], [yytype_int16],
 
        m4_eval([0 <= $1]),                [1], [unsigned int],
 
@@ -220,6 +221,36 @@ typedef struct YYLTYPE
 /* Line __line__ of yacc.c.  */
 b4_syncline(address@hidden@], address@hidden@])[
 
+#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#elif ]b4_c_modern[
+typedef signed char yytype_int8;
+#else
+typedef short int yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
 #ifndef YYSIZE_T
 # ifdef __SIZE_TYPE__
 #  define YYSIZE_T __SIZE_TYPE__
@@ -337,7 +368,7 @@ void free (void *); /* INFRINGES ON USER
 /* A type that is properly aligned for any stack member.  */
 union yyalloc
 {
-  short int yyss;
+  yytype_int16 yyss;
   YYSTYPE yyvs;
   ]b4_location_if([  YYLTYPE yyls;
 ])dnl
@@ -350,10 +381,10 @@ union yyalloc
    N elements.  */
 ]b4_location_if(
 [# define YYSTACK_BYTES(N) \
-     ((N) * (sizeof (short int) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
+     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
       + 2 * YYSTACK_GAP_MAXIMUM)],
 [# define YYSTACK_BYTES(N) \
-     ((N) * (sizeof (short int) + sizeof (YYSTYPE))                    \
+     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
       + YYSTACK_GAP_MAXIMUM)])[
 
 /* Copy COUNT objects from FROM to TO.  The source and destination do
@@ -392,12 +423,6 @@ union yyalloc
 
 #endif
 
-#if ]b4_c_modern[
-   typedef signed char yysigned_char;
-#else
-   typedef short int yysigned_char;
-#endif
-
 /* YYFINAL -- State number of the termination state.  */
 #define YYFINAL  ]b4_final_state_number[
 /* YYLAST -- Last index in YYTABLE.  */
@@ -649,8 +674,8 @@ do {                                                        
                  \
 `------------------------------------------------------------------*/
 
 ]b4_c_function_def([yy_stack_print], [static void],
-                  [[short int *bottom], [bottom]],
-                  [[short int *top],    [top]])[
+                  [[yytype_int16 *bottom], [bottom]],
+                  [[yytype_int16 *top],    [top]])[
 {
   YYFPRINTF (stderr, "Stack now");
   for (; bottom <= top; ++bottom)
@@ -993,9 +1018,9 @@ b4_c_function_def([yyparse], [int], b4_p
      to reallocate them elsewhere.  */
 
   /* The state stack.  */
-  short int yyssa[YYINITDEPTH];
-  short int *yyss = yyssa;
-  short int *yyssp;
+  yytype_int16 yyssa[YYINITDEPTH];
+  yytype_int16 *yyss = yyssa;
+  yytype_int16 *yyssp;
 
   /* The semantic value stack.  */
   YYSTYPE yyvsa[YYINITDEPTH];
@@ -1082,7 +1107,7 @@ m4_ifdef([b4_at_dollar_used], [[  yylsp[
           these so that the &'s don't force the real ones into
           memory.  */
        YYSTYPE *yyvs1 = yyvs;
-       short int *yyss1 = yyss;
+       yytype_int16 *yyss1 = yyss;
 ]b4_location_if([      YYLTYPE *yyls1 = yyls;])[
 
        /* Each stack pointer address is followed by the size of the
@@ -1110,7 +1135,7 @@ m4_ifdef([b4_at_dollar_used], [[  yylsp[
        yystacksize = YYMAXDEPTH;
 
       {
-       short int *yyss1 = yyss;
+       yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
        if (! yyptr)
Index: src/parse-gram.y
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.y,v
retrieving revision 1.70
diff -p -u -r1.70 parse-gram.y
--- src/parse-gram.y    22 Jan 2006 08:02:47 -0000      1.70
+++ src/parse-gram.y    23 Jan 2006 07:53:57 -0000
@@ -57,6 +57,19 @@ static uniqstr current_type = 0;
 static symbol *current_lhs;
 static location current_lhs_location;
 static int current_prec = 0;
+
+#ifdef UINT_FAST8_MAX
+# define YYTYPE_UINT8 uint_fast8_t
+#endif
+#ifdef INT_FAST8_MAX
+# define YYTYPE_INT8 int_fast8_t
+#endif
+#ifdef UINT_FAST16_MAX
+# define YYTYPE_UINT16 uint_fast16_t
+#endif
+#ifdef INT_FAST16_MAX
+# define YYTYPE_INT16 int_fast16_t
+#endif
 %}
 
 %debug
Index: tests/regression.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/regression.at,v
retrieving revision 1.94
diff -p -u -r1.94 regression.at
--- tests/regression.at 25 Jul 2005 06:36:13 -0000      1.94
+++ tests/regression.at 23 Jan 2006 07:53:57 -0000
@@ -1,5 +1,7 @@
 # Bison Regressions.                               -*- Autotest -*-
-# Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+
+# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
+# Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -581,7 +583,7 @@ AT_CLEANUP
 #
 # It used to be wrong on yydefact only:
 #
-# static const short int yydefact[] =
+# static const yytype_uint8 yydefact[] =
 #  {
 # -       2,     0,     1,     0,     0,     2,     3,     2,     5,     4,
 # +       2,     0,     1,     0,     0,     0,     3,     2,     5,     4,
@@ -611,7 +613,7 @@ AT_CHECK([bison -v -o input.c input.y])
 [sed -n 's/  *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
 
 AT_CHECK([[cat tables.c]], 0,
-[[static const unsigned char yytranslate[] =
+[[static const yytype_uint8 yytranslate[] =
 {
        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
@@ -641,16 +643,16 @@ AT_CHECK([[cat tables.c]], 0,
        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
        5,     6
 };
-static const unsigned char yyprhs[] =
+static const yytype_uint8 yyprhs[] =
 {
        0,     0,     3,     5,     6,     9,    14
 };
-static const yysigned_char yyrhs[] =
+static const yytype_int8 yyrhs[] =
 {
        8,     0,    -1,     9,    -1,    -1,    10,    11,    -1,     3,
        4,     5,     8,    -1,     6,     8,    -1
 };
-static const unsigned char yyrline[] =
+static const yytype_uint8 yyrline[] =
 {
        0,     2,     2,     3,     3,     4,     5
 };
@@ -659,45 +661,45 @@ static const char *const yytname[] =
   "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
   "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
 };
-static const unsigned short int yytoknum[] =
+static const yytype_uint16 yytoknum[] =
 {
        0,   256,   257,   258,   259,   260,   261
 };
-static const unsigned char yyr1[] =
+static const yytype_uint8 yyr1[] =
 {
        0,     7,     8,     9,     9,    10,    11
 };
-static const unsigned char yyr2[] =
+static const yytype_uint8 yyr2[] =
 {
        0,     2,     1,     0,     2,     4,     2
 };
-static const unsigned char yydefact[] =
+static const yytype_uint8 yydefact[] =
 {
        3,     0,     0,     2,     0,     0,     1,     3,     4,     3,
        6,     5
 };
-static const yysigned_char yydefgoto[] =
+static const yytype_int8 yydefgoto[] =
 {
       -1,     2,     3,     4,     8
 };
-static const yysigned_char yypact[] =
+static const yytype_int8 yypact[] =
 {
       -2,    -1,     4,    -8,     0,     2,    -8,    -2,    -8,    -2,
       -8,    -8
 };
-static const yysigned_char yypgoto[] =
+static const yytype_int8 yypgoto[] =
 {
       -8,    -7,    -8,    -8,    -8
 };
-static const unsigned char yytable[] =
+static const yytype_uint8 yytable[] =
 {
       10,     1,    11,     5,     6,     0,     7,     9
 };
-static const yysigned_char yycheck[] =
+static const yytype_int8 yycheck[] =
 {
        7,     3,     9,     4,     0,    -1,     6,     5
 };
-static const unsigned char yystos[] =
+static const yytype_uint8 yystos[] =
 {
        0,     3,     8,     9,    10,     4,     0,     6,    11,     5,
        8,     8




reply via email to

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