bison-patches
[Top][All Lists]
Advanced

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

bitset.h, bbitset.h patches to simplify maintenance for Bison


From: Paul Eggert
Subject: bitset.h, bbitset.h patches to simplify maintenance for Bison
Date: Tue, 12 Nov 2002 23:08:45 -0800 (PST)

When debugging some other inline-related stuff I noticed that the
bitset code produced GCC warnings when compiled with BITSET_INLINE set
to 1.  I'd rather not maintain two copies of the code, one with inline
and one without, so I removed the latter by installing the following
patch into Bison.  The inline version should work correctly on
compilers that lack 'inline', since config.h will '#define inline /*
empty */' on those hosts.

2002-11-12  Paul Eggert  <address@hidden>

        * lib/bbitset.h (BITSET_INLINE): Remove.
        * lib/bitset.h [! BITSET_INLINE]: Remove.
        (bitset_set, bitset_reset, bitset_test): Rename local vars
        to avoid shadowing warnings by GCC.

Index: lib/bbitset.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/bbitset.h,v
retrieving revision 1.9
diff -p -u -r1.9 bbitset.h
--- lib/bbitset.h       16 Oct 2002 06:16:29 -0000      1.9
+++ lib/bbitset.h       13 Nov 2002 06:59:59 -0000
@@ -42,9 +42,6 @@ extern const char * const bitset_type_na
 
 enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC};
 
-/* Non-zero to use inline functions instead of macros.  */
-#define BITSET_INLINE 0
-
 /* Data type used to store a word of bits.  */
 typedef unsigned long bitset_word;
 #define BITSET_WORD_BITS ((unsigned) (CHAR_BIT * sizeof (bitset_word)))
Index: lib/bitset.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/bitset.h,v
retrieving revision 1.10
diff -p -u -r1.10 bitset.h
--- lib/bitset.h        16 Oct 2002 06:19:22 -0000      1.10
+++ lib/bitset.h        13 Nov 2002 06:59:59 -0000
@@ -120,14 +120,13 @@ extern enum bitset_type bitset_type_get 
 /* Return bitset type name.  */
 extern const char *bitset_type_name_get PARAMS ((bitset));
 
-#if BITSET_INLINE
 
 /* Set bit BITNO in bitset BSET.  */
 static inline void
 bitset_set (bitset bset, bitset_bindex bitno)
 {
-  bitset_windex index = bitno / BITSET_WORD_BITS;
-  bitset_windex offset = index - bset->b.cindex;
+  bitset_windex windex = bitno / BITSET_WORD_BITS;
+  bitset_windex offset = windex - bset->b.cindex;
 
   if (offset < bset->b.csize)
     bset->b.cdata[offset] |= ((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
@@ -140,8 +139,8 @@ bitset_set (bitset bset, bitset_bindex b
 static inline void
 bitset_reset (bitset bset, bitset_bindex bitno)
 {
-  bitset_windex index = bitno / BITSET_WORD_BITS;
-  bitset_windex offset = index - bset->b.cindex;
+  bitset_windex windex = bitno / BITSET_WORD_BITS;
+  bitset_windex offset = windex - bset->b.cindex;
 
   if (offset < bset->b.csize)
     bset->b.cdata[offset] &= ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
@@ -154,57 +153,14 @@ bitset_reset (bitset bset, bitset_bindex
 static inline int
 bitset_test (bitset bset, bitset_bindex bitno)
 {
-  bitset_windex index = bitno / BITSET_WORD_BITS;
-  bitset_windex offset = index - bset->b.cindex;
+  bitset_windex windex = bitno / BITSET_WORD_BITS;
+  bitset_windex offset = windex - bset->b.cindex;
 
   if (offset < bset->b.csize)
     return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
   else
     return BITSET_TEST_ (bset, bitno);
 }
-#endif
-
-#if ! BITSET_INLINE
-
-/* Set bit BITNO in bitset BSET.  */
-#define bitset_set(bset, bitno)                                        \
-do                                                             \
-{                                                              \
-  bitset_bindex _bitno = (bitno);                              \
-  bitset_windex _index = _bitno / BITSET_WORD_BITS;            \
-  bitset_windex _offset = _index - (bset)->b.cindex;           \
-                                                               \
-  if (_offset < (bset)->b.csize)                                       \
-    (bset)->b.cdata[_offset] |=                                        \
-      ((bitset_word) 1 << (_bitno % BITSET_WORD_BITS));        \
-  else                                                         \
-    BITSET_SET_ ((bset), _bitno);                              \
-} while (0)
-
-
-/* Reset bit BITNO in bitset BSET.  */
-#define bitset_reset(bset, bitno)                              \
-do                                                             \
-{                                                              \
-  bitset_bindex _bitno = (bitno);                              \
-  bitset_windex _index = _bitno / BITSET_WORD_BITS;            \
-  bitset_windex _offset = _index - (bset)->b.cindex;           \
-                                                               \
-  if (_offset < (bset)->b.csize)                               \
-    (bset)->b.cdata[_offset] &=                                        \
-       ~((bitset_word) 1 << (_bitno % BITSET_WORD_BITS));      \
-  else                                                         \
-    BITSET_RESET_ ((bset), _bitno);                            \
-} while (0)
-
-
-/* Test bit BITNO in bitset BSET.  */
-#define bitset_test(bset, bitno) \
-(((((bitno) / BITSET_WORD_BITS) - (bset)->b.cindex) < (bset)->b.csize)  \
-  ? ((bset)->b.cdata[(((bitno) / BITSET_WORD_BITS) - (bset)->b.cindex)] \
-     >> ((bitno) % BITSET_WORD_BITS)) & 1 \
-  : (unsigned int) BITSET_TEST_ ((bset), (bitno)))
-#endif
 
 
 /* Toggle bit BITNO in bitset BSET and return non-zero if now set.  */




reply via email to

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