bison-patches
[Top][All Lists]
Advanced

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

Bison uses two different 'bool' flavors


From: Paul Eggert
Subject: Bison uses two different 'bool' flavors
Date: Mon, 21 Oct 2002 21:50:12 -0700 (PDT)

Bison's lib/hash.c uses stdbool.h or an enum for bool, but Bison's
src/system.h uses an int for the same type.  This violates the C
standard, which says that you have to be consistent when defining
types of external functions in different modules.  I installed the
following patch to fix Bison to be consistent about 'bool'.

2002-10-21  Paul Eggert  <address@hidden>

        Be consistent about 'bool'; the old code used an enum in one
        module and an int in another, and this violates the C standard.
        * configure.ac (AC_HEADER_STDBOOL): Add.
        * m4/Makefile.am (EXTRA_DIST): Add stdbool.m4.
        * src/muscle_tab.c (hash_compare_muscles): (a ? FALSE : TRUE) -> (! a)
        * src/symtab.c (hash_compare_symbol_t): Likewise.
        * src/system.h (bool, false, true): Use a definition consistent
        with ../lib/hash.c.  All uses changed.
        * m4/stdbool.m4: New file, from coreutils 4.5.3.

Index: configure.ac
===================================================================
RCS file: /cvsroot/bison/bison/configure.ac,v
retrieving revision 1.16
diff -p -u -r1.16 configure.ac
--- configure.ac        21 Oct 2002 05:27:45 -0000      1.16
+++ configure.ac        22 Oct 2002 04:31:39 -0000
@@ -71,6 +71,7 @@ AC_DEFINE_UNQUOTED([M4], ["$M4"], [Defin
 # Checks for header files.
 AC_HEADER_STDC
 AC_CHECK_HEADERS([ctype.h locale.h memory.h stdlib.h string.h unistd.h])
+AC_HEADER_STDBOOL
 
 # Checks for compiler characteristics.
 AC_C_INLINE
Index: m4/Makefile.am
===================================================================
RCS file: /cvsroot/bison/bison/m4/Makefile.am,v
retrieving revision 1.21
diff -p -u -r1.21 Makefile.am
--- m4/Makefile.am      20 Oct 2002 06:30:15 -0000      1.21
+++ m4/Makefile.am      22 Oct 2002 04:31:39 -0000
@@ -2,5 +2,5 @@
 EXTRA_DIST = \
   dmalloc.m4 error.m4 \
   m4.m4 mbrtowc.m4 memcmp.m4 \
-  prereq.m4 subpipe.m4 timevar.m4 warning.m4 \
+  prereq.m4 stdbool.m4 subpipe.m4 timevar.m4 warning.m4 \
   gettext.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 progtest.m4
Index: src/conflicts.c
===================================================================
RCS file: /cvsroot/bison/bison/src/conflicts.c,v
retrieving revision 1.94
diff -p -u -r1.94 conflicts.c
--- src/conflicts.c     2 Aug 2002 08:05:01 -0000       1.94
+++ src/conflicts.c     22 Oct 2002 04:31:40 -0000
@@ -450,7 +450,7 @@ conflict_report_yacc (int src_num, int r
 void
 conflicts_output (FILE *out)
 {
-  bool printed_sth = FALSE;
+  bool printed_sth = false;
   state_number_t i;
   for (i = 0; i < nstates; i++)
     {
@@ -460,8 +460,8 @@ conflicts_output (FILE *out)
          fprintf (out, _("State %d contains "), i);
          fprintf (out, "%s.\n",
                   conflict_report (count_sr_conflicts (s),
-                                   count_rr_conflicts (s, TRUE)));
-         printed_sth = TRUE;
+                                   count_rr_conflicts (s, true)));
+         printed_sth = true;
        }
     }
   if (printed_sth)
@@ -487,7 +487,7 @@ conflicts_total_count (void)
     if (conflicts[i])
       {
        count += count_sr_conflicts (states[i]);
-       count += count_rr_conflicts (states[i], FALSE);
+       count += count_rr_conflicts (states[i], false);
       }
   return count;
 }
@@ -516,7 +516,7 @@ conflicts_print (void)
       if (conflicts[i])
        {
          src_total += count_sr_conflicts (states[i]);
-         rrc_total += count_rr_conflicts (states[i], TRUE);
+         rrc_total += count_rr_conflicts (states[i], true);
        }
   }
 
Index: src/gram.c
===================================================================
RCS file: /cvsroot/bison/bison/src/gram.c,v
retrieving revision 1.45
diff -p -u -r1.45 gram.c
--- src/gram.c  4 Sep 2002 10:07:33 -0000       1.45
+++ src/gram.c  22 Oct 2002 04:31:40 -0000
@@ -201,7 +201,7 @@ grammar_rules_partial_print (FILE *out, 
                             rule_filter_t filter)
 {
   int r;
-  bool first = TRUE;
+  bool first = true;
   symbol_t *previous_lhs = NULL;
 
   /* rule # : LHS -> RHS */
@@ -213,7 +213,7 @@ grammar_rules_partial_print (FILE *out, 
        fprintf (out, "%s\n\n", title);
       else if (previous_lhs && previous_lhs != rules[r].lhs)
        fputc ('\n', out);
-      first = FALSE;
+      first = false;
       rule_lhs_print (&rules[r], previous_lhs, out);
       rule_rhs_print (&rules[r], out);
       previous_lhs = rules[r].lhs;
Index: src/gram.h
===================================================================
RCS file: /cvsroot/bison/bison/src/gram.h,v
retrieving revision 1.49
diff -p -u -r1.49 gram.h
--- src/gram.h  21 Oct 2002 05:30:49 -0000      1.49
+++ src/gram.h  22 Oct 2002 04:31:40 -0000
@@ -76,7 +76,7 @@
 
    RULES[R].line -- the line where R was defined.
 
-   RULES[R].useful -- TRUE iff the rule is used (i.e., FALSE if thrown
+   RULES[R].useful -- true iff the rule is used (i.e., false if thrown
    away by reduce).
 
    The right hand side is stored as symbol numbers in a portion of
Index: src/muscle_tab.c
===================================================================
RCS file: /cvsroot/bison/bison/src/muscle_tab.c,v
retrieving revision 1.24
diff -p -u -r1.24 muscle_tab.c
--- src/muscle_tab.c    20 Oct 2002 16:09:47 -0000      1.24
+++ src/muscle_tab.c    22 Oct 2002 04:31:40 -0000
@@ -38,7 +38,7 @@ hash_compare_muscles (void const *x, voi
 {
   const muscle_entry_t *m1 = x;
   const muscle_entry_t *m2 = y;
-  return strcmp (m1->key, m2->key) ? FALSE : TRUE;
+  return strcmp (m1->key, m2->key) == 0;
 }
 
 static unsigned int
Index: src/print.c
===================================================================
RCS file: /cvsroot/bison/bison/src/print.c,v
retrieving revision 1.90
diff -p -u -r1.90 print.c
--- src/print.c 13 Oct 2002 19:35:59 -0000      1.90
+++ src/print.c 22 Oct 2002 04:31:41 -0000
@@ -366,7 +366,7 @@ print_reductions (FILE *out, state_t *st
                  if (redp->rules[j] != default_rule)
                    print_reduction (out, width,
                                     symbols[i]->tag,
-                                    redp->rules[j], TRUE);
+                                    redp->rules[j], true);
                  else
                    defaulted = 1;
                  count++;
@@ -376,18 +376,18 @@ print_reductions (FILE *out, state_t *st
                  if (defaulted)
                    print_reduction (out, width,
                                     symbols[i]->tag,
-                                    default_rule, TRUE);
+                                    default_rule, true);
                  defaulted = 0;
                  print_reduction (out, width,
                                   symbols[i]->tag,
-                                  redp->rules[j], FALSE);
+                                  redp->rules[j], false);
                }
            }
       }
 
   if (default_rule)
     print_reduction (out, width,
-                    _("$default"), default_rule, TRUE);
+                    _("$default"), default_rule, true);
 }
 
 
@@ -400,11 +400,11 @@ static void
 print_actions (FILE *out, state_t *state)
 {
   /* Print shifts.  */
-  print_transitions (state, out, TRUE);
+  print_transitions (state, out, true);
   print_errs (out, state);
   print_reductions (out, state);
   /* Print gotos.  */
-  print_transitions (state, out, FALSE);
+  print_transitions (state, out, false);
 }
 
 
Index: src/reader.c
===================================================================
RCS file: /cvsroot/bison/bison/src/reader.c,v
retrieving revision 1.212
diff -p -u -r1.212 reader.c
--- src/reader.c        17 Oct 2002 17:47:33 -0000      1.212
+++ src/reader.c        22 Oct 2002 04:31:41 -0000
@@ -422,7 +422,7 @@ packgram (void)
       rules[ruleno].lhs = p->sym;
       rules[ruleno].rhs = ritem + itemno;
       rules[ruleno].location = p->location;
-      rules[ruleno].useful = TRUE;
+      rules[ruleno].useful = true;
       rules[ruleno].action = p->action;
       rules[ruleno].action_location = p->action_location;
       rules[ruleno].dprec = p->dprec;
Index: src/reduce.c
===================================================================
RCS file: /cvsroot/bison/bison/src/reduce.c,v
retrieving revision 1.75
diff -p -u -r1.75 reduce.c
--- src/reduce.c        2 Aug 2002 08:05:01 -0000       1.75
+++ src/reduce.c        22 Oct 2002 04:31:41 -0000
@@ -71,8 +71,8 @@ useful_production (rule_number_t r, bits
 
   for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
     if (ISVAR (*rhsp) && !bitset_test (N0, *rhsp - ntokens))
-      return FALSE;
-  return TRUE;
+      return false;
+  return true;
 }
 
 
@@ -353,14 +353,14 @@ reduce_output (FILE *out)
     }
 
   {
-    bool b = FALSE;
+    bool b = false;
     int i;
     for (i = 0; i < ntokens; i++)
       if (!bitset_test (V, i) && !bitset_test (V1, i))
        {
          if (!b)
            fprintf (out, "%s\n\n", _("Terminals which are not used"));
-         b = TRUE;
+         b = true;
          fprintf (out, "   %s\n", symbols[i]->tag);
        }
     if (b)
Index: src/state.c
===================================================================
RCS file: /cvsroot/bison/bison/src/state.c,v
retrieving revision 1.23
diff -p -u -r1.23 state.c
--- src/state.c 1 Aug 2002 18:14:30 -0000       1.23
+++ src/state.c 22 Oct 2002 04:31:41 -0000
@@ -266,13 +266,13 @@ state_compare (const state_t *s1, const 
   int i;
 
   if (s1->nitems != s2->nitems)
-    return FALSE;
+    return false;
 
   for (i = 0; i < s1->nitems; ++i)
     if (s1->items[i] != s2->items[i])
-      return FALSE;
+      return false;
 
-  return TRUE;
+  return true;
 }
 
 static unsigned int
Index: src/symtab.c
===================================================================
RCS file: /cvsroot/bison/bison/src/symtab.c,v
retrieving revision 1.47
diff -p -u -r1.47 symtab.c
--- src/symtab.c        12 Aug 2002 14:53:26 -0000      1.47
+++ src/symtab.c        22 Oct 2002 04:31:41 -0000
@@ -228,7 +228,7 @@ symbol_check_defined (symbol_t *this)
       this->number = nvars++;
     }
 
-  return TRUE;
+  return true;
 }
 
 
@@ -299,7 +299,7 @@ symbol_check_alias_consistence (symbol_t
            this->assoc = this->alias->assoc;
        }
     }
-  return TRUE;
+  return true;
 }
 
 
@@ -332,7 +332,7 @@ symbol_pack (symbol_t *this)
        }
       /* Do not do processing below for USER_NUMBER_ALIASs.  */
       if (this->user_token_number == USER_NUMBER_ALIAS)
-       return TRUE;
+       return true;
     }
   else /* this->class == token_sym */
     {
@@ -340,7 +340,7 @@ symbol_pack (symbol_t *this)
     }
 
   symbols[this->number] = this;
-  return TRUE;
+  return true;
 }
 
 
@@ -367,7 +367,7 @@ symbol_translation (symbol_t *this)
       token_translations[this->user_token_number] = this->number;
     }
 
-  return TRUE;
+  return true;
 }
 
 
@@ -383,7 +383,7 @@ static struct hash_table *symbol_table =
 static bool
 hash_compare_symbol_t (const symbol_t *m1, const symbol_t *m2)
 {
-  return strcmp (m1->tag, m2->tag) ? FALSE : TRUE;
+  return strcmp (m1->tag, m2->tag) == 0;
 }
 
 static unsigned int
@@ -501,7 +501,7 @@ symbols_check_defined (void)
 static void
 symbols_token_translations_init (void)
 {
-  int num_256_available_p = TRUE;
+  bool num_256_available_p = true;
   int i;
 
   /* Find the highest user token number, and whether 256, the POSIX
@@ -515,7 +515,7 @@ symbols_token_translations_init (void)
          if (this->user_token_number > max_user_token_number)
            max_user_token_number = this->user_token_number;
          if (this->user_token_number == 256)
-           num_256_available_p = FALSE;
+           num_256_available_p = false;
        }
     }
 
Index: src/symtab.h
===================================================================
RCS file: /cvsroot/bison/bison/src/symtab.h,v
retrieving revision 1.46
diff -p -u -r1.46 symtab.h
--- src/symtab.h        21 Oct 2002 05:30:50 -0000      1.46
+++ src/symtab.h        22 Oct 2002 04:31:41 -0000
@@ -143,8 +143,8 @@ void symbols_new (void);
 /* A function to apply to each symbol. */
 typedef bool (*symbol_processor) (symbol_t *);
 
-/* Apply PROCESSOR to all the symbols.  PROCESSOR must return TRUE: on
-   FALSE, the processing stops.  */
+/* Apply PROCESSOR to all the symbols.  PROCESSOR must return true: on
+   false, the processing stops.  */
 void symbols_do (symbol_processor processor, void *processor_data);
 
 /* Free all the memory allocated for symbols.  */
Index: src/system.h
===================================================================
RCS file: /cvsroot/bison/bison/src/system.h,v
retrieving revision 1.50
diff -p -u -r1.50 system.h
--- src/system.h        21 Oct 2002 05:29:07 -0000      1.50
+++ src/system.h        22 Oct 2002 04:31:41 -0000
@@ -181,11 +181,11 @@ void *memrchr (const void *s, int c, siz
 | Booleans.  |
 `-----------*/
 
-#ifndef TRUE
-# define TRUE  (1)
-# define FALSE (0)
+#if HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+typedef enum {false = 0, true = 1} bool;
 #endif
-typedef int bool;
 
 
 /*-----------.
Index: src/tables.c
===================================================================
RCS file: /cvsroot/bison/bison/src/tables.c,v
retrieving revision 1.9
diff -p -u -r1.9 tables.c
--- src/tables.c        20 Oct 2002 11:18:14 -0000      1.9
+++ src/tables.c        22 Oct 2002 04:31:42 -0000
@@ -418,7 +418,7 @@ token_actions (void)
   /* Find the rules which are reduced.  */
   if (!glr_parser)
     for (r = 0; r < nrules; ++r)
-      rules[r].useful = FALSE;
+      rules[r].useful = false;
 
   for (i = 0; i < nstates; ++i)
     {
@@ -433,9 +433,9 @@ token_actions (void)
        {
          for (j = 0; j < ntokens; ++j)
            if (actrow[j] < 0 && actrow[j] != ACTION_MIN)
-             rules[item_number_as_rule_number (actrow[j])].useful = TRUE;
+             rules[item_number_as_rule_number (actrow[j])].useful = true;
          if (yydefact[i])
-           rules[yydefact[i] - 1].useful = TRUE;
+           rules[yydefact[i] - 1].useful = true;
        }
     }
 
--- /dev/null   2002-10-22 04:31:21.000000000 +0000
+++ m4/stdbool.m4       2002-06-22 08:27:18.000000000 +0000
@@ -0,0 +1,62 @@
+# Check for stdbool.h that conforms to C99.
+
+# Copyright (C) 2002 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+AC_DEFUN([AC_HEADER_STDBOOL],
+  [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
+     [ac_cv_header_stdbool_h],
+     [AC_TRY_COMPILE(
+       [
+         #include <stdbool.h>
+         #ifndef bool
+          "error: bool is not defined"
+         #endif
+         #ifndef false
+          "error: false is not defined"
+         #endif
+         #if false
+          "error: false is not 0"
+         #endif
+         #ifndef true
+          "error: false is not defined"
+         #endif
+         #if true != 1
+          "error: true is not 1"
+         #endif
+         #ifndef __bool_true_false_are_defined
+          "error: __bool_true_false_are_defined is not defined"
+         #endif
+
+         struct s { _Bool s: 1; _Bool t; } s;
+
+         char a[true == 1 ? 1 : -1];
+         char b[false == 0 ? 1 : -1];
+         char c[__bool_true_false_are_defined == 1 ? 1 : -1];
+         char d[(bool) -0.5 == true ? 1 : -1];
+         bool e = &s;
+         char f[(_Bool) -0.0 == false ? 1 : -1];
+         char g[true];
+         char h[sizeof (_Bool)];
+         char i[sizeof s.t];
+       ],
+       [ return !a + !b + !c + !d + !e + !f + !g + !h + !i; ],
+       [ac_cv_header_stdbool_h=yes],
+       [ac_cv_header_stdbool_h=no])])
+   if test $ac_cv_header_stdbool_h = yes; then
+     AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
+   fi])




reply via email to

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