]> git.saurik.com Git - bison.git/blobdiff - src/Sbitset.h
muscle: factor the computation of variable names
[bison.git] / src / Sbitset.h
index 0d0aabf859fe53656866356264ffbbef48dee3a1..a930196ebd57ec5818f513f44e5f8936aed3b7b3 100644 (file)
@@ -1,6 +1,6 @@
 /* A simple, memory-efficient bitset implementation.
 
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009-2013 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 #ifndef SBITSET_H_
 # define SBITSET_H_
 
-typedef char *Sbitset;
+typedef unsigned char *Sbitset;
 typedef size_t Sbitset__Index;
-#define SBITSET__INDEX__CONVERSION_SPEC "zu"
+# define SBITSET__INDEX__CONVERSION_SPEC "zu"
 
-#define Sbitset__nbytes(NBITS) \
+# define Sbitset__nbytes(NBITS) \
   (((NBITS) + CHAR_BIT - 1) / CHAR_BIT)
-#define Sbitset__byteAddress(SELF, INDEX) \
+# define Sbitset__byteAddress(SELF, INDEX) \
   (((SELF) + (INDEX) / CHAR_BIT))
-#define Sbitset__bit_mask(INDEX) \
+# define Sbitset__bit_mask(INDEX) \
   (1 << (CHAR_BIT - 1 - (INDEX) % CHAR_BIT))
-#define Sbitset__last_byte_mask(NBITS) \
+# define Sbitset__last_byte_mask(NBITS) \
   (UCHAR_MAX << (CHAR_BIT - 1 - ((NBITS) - 1) % CHAR_BIT))
 
 /* nbits must not be 0.  */
@@ -39,54 +39,54 @@ Sbitset Sbitset__new_on_obstack (Sbitset__Index nbits,
                                  struct obstack *obstackp);
 void Sbitset__delete (Sbitset self);
 
-#define Sbitset__test(SELF, INDEX)                                            \
+# define Sbitset__test(SELF, INDEX)                                     \
   ((*Sbitset__byteAddress ((SELF), (INDEX)) & Sbitset__bit_mask (INDEX)) != 0)
 
 bool Sbitset__isEmpty (Sbitset self, Sbitset__Index nbits);
 
 void Sbitset__fprint(Sbitset self, Sbitset__Index nbits, FILE *file);
 
-#define Sbitset__set(SELF, INDEX)                                             \
-do {                                                                          \
-  *Sbitset__byteAddress ((SELF), (INDEX)) =                                   \
-    *Sbitset__byteAddress ((SELF), (INDEX)) | Sbitset__bit_mask (INDEX);      \
-} while(0)
+# define Sbitset__set(SELF, INDEX)                                      \
+  do {                                                                  \
+    *Sbitset__byteAddress ((SELF), (INDEX)) =                           \
+      *Sbitset__byteAddress ((SELF), (INDEX)) | Sbitset__bit_mask (INDEX); \
+  } while(0)
 
-#define Sbitset__reset(SELF, INDEX)                                           \
-do {                                                                          \
-  *Sbitset__byteAddress ((SELF), (INDEX)) =                                   \
-    *Sbitset__byteAddress ((SELF), (INDEX)) & ~Sbitset__bit_mask (INDEX);     \
-} while(0)
+# define Sbitset__reset(SELF, INDEX)                                    \
+  do {                                                                  \
+    *Sbitset__byteAddress ((SELF), (INDEX)) =                           \
+      *Sbitset__byteAddress ((SELF), (INDEX)) & ~Sbitset__bit_mask (INDEX); \
+  } while(0)
 
 /* NBITS is the size of the bitset.  More than NBITS bits might be reset.  */
-#define Sbitset__zero(SELF, NBITS)                                            \
-do {                                                                          \
-  memset (SELF, 0, Sbitset__nbytes (NBITS));                                  \
-} while(0)
+# define Sbitset__zero(SELF, NBITS)             \
+  do {                                          \
+    memset (SELF, 0, Sbitset__nbytes (NBITS));  \
+  } while(0)
 
 /* NBITS is the size of the bitset.  More than NBITS bits might be set.  */
-#define Sbitset__ones(SELF, NBITS)                                            \
-do {                                                                          \
-  memset (SELF, UCHAR_MAX, Sbitset__nbytes (NBITS));                          \
-} while(0)
+# define Sbitset__ones(SELF, NBITS)                     \
+  do {                                                  \
+    memset (SELF, UCHAR_MAX, Sbitset__nbytes (NBITS));  \
+  } while(0)
 
 /* NBITS is the size of every bitset.  More than NBITS bits might be set.  */
-#define Sbitset__or(SELF, OTHER1, OTHER2, NBITS)                              \
-do {                                                                          \
-  char *ptr_self = (SELF);                                                    \
-  char *ptr_other1 = (OTHER1);                                                \
-  char *ptr_other2 = (OTHER2);                                                \
-  char *end_self = ptr_self + Sbitset__nbytes (NBITS);                        \
-  for (; ptr_self < end_self; ++ptr_self, ++ptr_other1, ++ptr_other2)         \
-    *ptr_self = *ptr_other1 | *ptr_other2;                                    \
-} while(0)
-
-#define SBITSET__FOR_EACH(SELF, NBITS, ITER, INDEX)                           \
-  for ((ITER) = (SELF); (ITER) < (SELF) + Sbitset__nbytes (NBITS); ++(ITER))  \
-    if (*(ITER) != 0)                                                         \
-      for ((INDEX) = ((ITER)-(SELF))*CHAR_BIT;                                \
-           (INDEX) < (NBITS) && (SELF)+(INDEX)/CHAR_BIT < (ITER)+1;           \
-           ++(INDEX))                                                         \
+# define Sbitset__or(SELF, OTHER1, OTHER2, NBITS)                       \
+  do {                                                                  \
+    Sbitset ptr_self = (SELF);                                          \
+    Sbitset ptr_other1 = (OTHER1);                                      \
+    Sbitset ptr_other2 = (OTHER2);                                      \
+    Sbitset end_self = ptr_self + Sbitset__nbytes (NBITS);              \
+    for (; ptr_self < end_self; ++ptr_self, ++ptr_other1, ++ptr_other2) \
+      *ptr_self = *ptr_other1 | *ptr_other2;                            \
+  } while(0)
+
+# define SBITSET__FOR_EACH(SELF, NBITS, ITER, INDEX)                    \
+  for ((ITER) = (SELF); (ITER) < (SELF) + Sbitset__nbytes (NBITS); ++(ITER)) \
+    if (*(ITER) != 0)                                                   \
+      for ((INDEX) = ((ITER)-(SELF))*CHAR_BIT;                          \
+           (INDEX) < (NBITS) && (SELF)+(INDEX)/CHAR_BIT < (ITER)+1;     \
+           ++(INDEX))                                                   \
         if (((*ITER) & Sbitset__bit_mask (INDEX)) != 0)
 
 #endif /* !SBITSET_H_ */