X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/dbba6a3be7dd98a7fd33353d79c088d8b66fc324..dfc8a22010ec0dbbcc361ab308e7e83ae917ef0f:/lib/bitset.h?ds=inline diff --git a/lib/bitset.h b/lib/bitset.h index c659a2ce..2e6eb8b0 100644 --- a/lib/bitset.h +++ b/lib/bitset.h @@ -1,5 +1,5 @@ /* Generic bitsets. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 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 @@ -23,7 +23,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ Only use the functions and macros defined in this file. */ #include "bbitset.h" + +/* obstack.h tries to be portable to K&R compilers, but its + __INT_TO_PTR macro generates diagnostics on compilers like Tru64 cc + that define __STDC__ to 0 when not in strict ANSI mode. The bitset + code assumes C89 or later, so it can avoid these glitches by + defining __INT_TO_PTR appropriately for C89 or later. */ +#ifndef __INT_TO_PTR +# define __INT_TO_PTR(P) ((void *) ((P) + (char *) 0)) +#endif #include "obstack.h" + #include /* Attributes used to select a bitset implementation. */ @@ -44,12 +54,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 +81,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; + }; @@ -150,7 +166,7 @@ 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 windex = bitno / BITSET_WORD_BITS; @@ -169,6 +185,9 @@ bitset_test (bitset bset, bitset_bindex bitno) /* Return size in bits of bitset SRC. */ #define bitset_size(SRC) BITSET_SIZE_ (SRC) +/* Change size of bitset. */ +extern void bitset_resize PARAMS ((bitset, bitset_bindex)); + /* Return number of bits set in bitset SRC. */ #define bitset_count(SRC) BITSET_COUNT_ (SRC) @@ -266,11 +285,13 @@ bitset_test (bitset bset, bitset_bindex bitno) #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. */ +/* Find next set bit from the given bit index. */ extern bitset_bindex bitset_next PARAMS ((bitset, bitset_bindex)); -/* Find previous set bit. */ +/* Find previous set bit from the given bit index. */ extern bitset_bindex bitset_prev PARAMS ((bitset, bitset_bindex)); /* Find first set bit. */ @@ -280,51 +301,53 @@ extern bitset_bindex bitset_first PARAMS ((bitset)); extern bitset_bindex bitset_last PARAMS ((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 PARAMS ((bitset, bitset_bindex)); /* Dump bitset. */ extern void bitset_dump PARAMS ((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, \ 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_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. */ @@ -349,7 +372,6 @@ 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));