X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/04af9e52679a9c9c983078bad2643d22023b4999..a005a9c4dc5588fc017a1cb1d19c1560e0e68943:/lib/bitset.h
diff --git a/lib/bitset.h b/lib/bitset.h
index 06427c38..3e52940c 100644
--- a/lib/bitset.h
+++ b/lib/bitset.h
@@ -1,20 +1,19 @@
/* Generic bitsets.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-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 of the License, or
-(at your option) any later version.
+ 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 3 of the License, 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.
+ 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. */
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
#ifndef _BITSET_H
#define _BITSET_H
@@ -26,6 +25,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "obstack.h"
#include
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
/* Attributes used to select a bitset implementation. */
enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */
BITSET_VARIABLE = 2, /* Bitset size variable. */
@@ -44,12 +47,11 @@ union bitset_union
{
/* This must be the first member of every other structure that is a
member of this union. */
- struct bbitset_struct b;
+ struct bbitset_struct b; /* Base bitset data. */
struct abitset_struct
{
struct bbitset_struct b;
- bitset_bindex n_bits; /* Number of bits. */
bitset_word words[1]; /* The array of bits. */
} a;
@@ -72,6 +74,13 @@ union bitset_union
struct bbitset_struct b;
bitset bset;
} s;
+
+ struct vbitset_struct
+ {
+ struct bbitset_struct b;
+ bitset_windex size; /* Allocated size of array. */
+ } v;
+
};
@@ -87,47 +96,45 @@ typedef struct
/* Return bytes required for bitset of desired type and size. */
-extern size_t bitset_bytes PARAMS ((enum bitset_type, bitset_bindex));
+extern size_t bitset_bytes (enum bitset_type, bitset_bindex);
/* Initialise a bitset with desired type and size. */
-extern bitset bitset_init PARAMS ((bitset, bitset_bindex, enum bitset_type));
+extern bitset bitset_init (bitset, bitset_bindex, enum bitset_type);
/* Select an implementation type based on the desired bitset size
and attributes. */
-extern enum bitset_type bitset_type_choose PARAMS ((bitset_bindex,
- bitset_attrs));
+extern enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs);
/* Create a bitset of desired type and size. The bitset is zeroed. */
-extern bitset bitset_alloc PARAMS ((bitset_bindex, enum bitset_type));
+extern bitset bitset_alloc (bitset_bindex, enum bitset_type);
/* Free bitset. */
-extern void bitset_free PARAMS ((bitset));
+extern void bitset_free (bitset);
/* Create a bitset of desired type and size using an obstack. The
bitset is zeroed. */
-extern bitset bitset_obstack_alloc PARAMS ((struct obstack *bobstack,
- bitset_bindex, enum bitset_type));
+extern bitset bitset_obstack_alloc (struct obstack *bobstack,
+ bitset_bindex, enum bitset_type);
/* Free bitset allocated on obstack. */
-extern void bitset_obstack_free PARAMS ((bitset));
+extern void bitset_obstack_free (bitset);
/* Create a bitset of desired size and attributes. The bitset is zeroed. */
-extern bitset bitset_create PARAMS ((bitset_bindex, bitset_attrs));
+extern bitset bitset_create (bitset_bindex, bitset_attrs);
/* Return bitset type. */
-extern enum bitset_type bitset_type_get PARAMS ((bitset));
+extern enum bitset_type bitset_type_get (bitset);
/* Return bitset type name. */
-extern const char *bitset_type_name_get PARAMS ((bitset));
+extern const char *bitset_type_name_get (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 +147,8 @@ bitset_set (bitset bset, bitset_bindex bitno)
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));
@@ -151,60 +158,17 @@ bitset_reset (bitset bset, bitset_bindex bitno)
/* Test bit BITNO in bitset BSET. */
-static inline int
+static inline bool
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. */
@@ -213,6 +177,9 @@ do \
/* Return size in bits of bitset SRC. */
#define bitset_size(SRC) BITSET_SIZE_ (SRC)
+/* Change size of bitset. */
+extern void bitset_resize (bitset, bitset_bindex);
+
/* Return number of bits set in bitset SRC. */
#define bitset_count(SRC) BITSET_COUNT_ (SRC)
@@ -310,65 +277,69 @@ do \
#define bitset_list_reverse(BSET, LIST, NUM, NEXT) \
BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT)
+/* Return true if both bitsets are of the same type and size. */
+extern bool bitset_compatible_p (bitset bset1, bitset bset2);
-/* Find next set bit. */
-extern bitset_bindex bitset_next PARAMS ((bitset, bitset_bindex));
+/* Find next set bit from the given bit index. */
+extern bitset_bindex bitset_next (bitset, bitset_bindex);
-/* Find previous set bit. */
-extern bitset_bindex bitset_prev PARAMS ((bitset, bitset_bindex));
+/* Find previous set bit from the given bit index. */
+extern bitset_bindex bitset_prev (bitset, bitset_bindex);
/* Find first set bit. */
-extern bitset_bindex bitset_first PARAMS ((bitset));
+extern bitset_bindex bitset_first (bitset);
/* Find last set bit. */
-extern bitset_bindex bitset_last PARAMS ((bitset));
+extern bitset_bindex bitset_last (bitset);
/* Return nonzero if this is the only set bit. */
-extern int bitset_only_set_p PARAMS ((bitset, bitset_bindex));
+extern bool bitset_only_set_p (bitset, bitset_bindex);
/* Dump bitset. */
-extern void bitset_dump PARAMS ((FILE *, bitset));
+extern void bitset_dump (FILE *, bitset);
-/* Loop over all elements of BSET, starting with MIN, setting BIT
+/* Loop over all elements of BSET, starting with MIN, setting INDEX
to the index of each set bit. For example, the following will print
the bits set in a bitset:
bitset_bindex i;
bitset_iterator iter;
- bitset_zero (dst);
BITSET_FOR_EACH (iter, src, i, 0)
{
- printf ("%ld ", i);
+ printf ("%lu ", (unsigned long int) i);
};
*/
-#define BITSET_FOR_EACH(ITER, BSET, BIT, MIN) \
+#define BITSET_FOR_EACH(ITER, BSET, INDEX, MIN) \
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
- (ITER.num == BITSET_LIST_SIZE) \
- && (ITER.num = bitset_list (BSET, ITER.list, \
+ (ITER.num == BITSET_LIST_SIZE) \
+ && (ITER.num = bitset_list (BSET, ITER.list, \
BITSET_LIST_SIZE, &ITER.next));) \
- for (ITER.i = 0; (BIT) = ITER.list[ITER.i], ITER.i < ITER.num; ITER.i++)
+ for (ITER.i = 0; \
+ ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1); \
+ ITER.i++)
/* Loop over all elements of BSET, in reverse order starting with
- MIN, setting BIT to the index of each set bit. For example, the
+ MIN, setting INDEX to the index of each set bit. For example, the
following will print the bits set in a bitset in reverse order:
bitset_bindex i;
bitset_iterator iter;
- bitset_zero (dst);
BITSET_FOR_EACH_REVERSE (iter, src, i, 0)
{
- printf ("%ld ", i);
+ printf ("%lu ", (unsigned long int) i);
};
*/
-#define BITSET_FOR_EACH_REVERSE(ITER, BSET, BIT, MIN) \
+#define BITSET_FOR_EACH_REVERSE(ITER, BSET, INDEX, MIN) \
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
- (ITER.num == BITSET_LIST_SIZE) \
+ (ITER.num == BITSET_LIST_SIZE) \
&& (ITER.num = bitset_list_reverse (BSET, ITER.list, \
- BITSET_LIST_SIZE, &ITER.next));) \
- for (ITER.i = 0; (BIT) = ITER.list[ITER.i], ITER.i < ITER.num; ITER.i++)
+ BITSET_LIST_SIZE, &ITER.next));) \
+ for (ITER.i = 0; \
+ ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1); \
+ ITER.i++)
/* Define set operations in terms of logical operations. */
@@ -393,30 +364,28 @@ extern void bitset_dump PARAMS ((FILE *, bitset));
bitset_andn_or_cmp (DST, SRC1, SRC2, SRC3)
-
/* Release any memory tied up with bitsets. */
-extern void bitset_release_memory PARAMS ((void));
+extern void bitset_release_memory (void);
/* Enable bitset stats gathering. */
-extern void bitset_stats_enable PARAMS ((void));
+extern void bitset_stats_enable (void);
/* Disable bitset stats gathering. */
-extern void bitset_stats_disable PARAMS ((void));
+extern void bitset_stats_disable (void);
/* Read bitset stats file of accummulated stats. */
-void bitset_stats_read PARAMS ((const char *filename));
+void bitset_stats_read (const char *file_name);
/* Write bitset stats file of accummulated stats. */
-void bitset_stats_write PARAMS ((const char *filename));
+void bitset_stats_write (const char *file_name);
/* Dump bitset stats. */
-extern void bitset_stats_dump PARAMS ((FILE *));
+extern void bitset_stats_dump (FILE *);
/* Function to debug bitset from debugger. */
-extern void debug_bitset PARAMS ((bitset));
+extern void debug_bitset (bitset);
/* Function to debug bitset stats from debugger. */
-extern void debug_bitset_stats PARAMS ((void));
+extern void debug_bitset_stats (void);
#endif /* _BITSET_H */
-