[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bitset portability patches to better conform to Standard C
From: |
Paul Eggert |
Subject: |
bitset portability patches to better conform to Standard C |
Date: |
Thu, 10 Oct 2002 00:59:34 -0700 (PDT) |
Bison builds with many GCC warnings enabled, and the bitset code
caused several warnings to be generated. I investigated this, and
found some places where the bitset code does not conform to the C
standard. I installed the following patch to fix the
incompatibilities, and to pacify GCC.
For Bison I'd like to replace the old-style function declarations with
function prototypes, and assume C89. Any objection? This will
simplify the code in several places, and will remove some of the hacks
added below (like enum_bitset_type).
The current code won't compile with K&R C anyway as it already has
some prototypes, and K&R C is no longer a goal for the Bison
internals. If you're thinking of using this code in GCC and GCC still
requires K&R, I suppose we could make it K&R-able with ansi2knr; if
not, I'd prefer to simply assume C89.
2002-10-10 Paul Eggert <address@hidden>
Portability fixes for bitsets; this also avoids several GCC
warnings.
* lib/abitset.c: Include <stddef.h>, for offsetof.
* lib/lbitset.c: Likewise.
* lib/abitset.c (abitset_bytes): Return a size that is aligned
properly for vectors of objects. Do not assume that adding a
header size to a multiple of a word size yields a value that is
properly aligned for the whole union.
* lib/bitsetv.c (bitsetv_alloc): Likewise.
* lib/bitset_stats.c (bitset_stats_bytes): Adjust to new,
unique names for structures.
* lib/ebitset.c (ebitset_bytes): Likewise.
* lib/lbitset.c (lbitset_bytes): Likewise.
* lib/abitset.c (abitset_ones, abitset_zero, abitset_empty_p,
abitset_copy1, abitset_not, abitset_equal_p, abitset_subset_p,
abitset_disjoint_p, abitset_and, abitset_and_cmp, abitset_andn,
abitset_andn_cmp, abitset_or, abitset_or_cmp, abitset_xor,
abitset_xor_cmp, abitset_and_or, abitset_and_or_cmp,
abitset_andn_or, abitset_andn_or_cmp, abitset_or_and,
abitset_or_and_cmp, abitset_copy): Supply prototype decls,
to improve the type-checking that GCC can do.
* lib/bitset.c (bitset_op4_cmp): Likewise.
* lib/bitset_stats.c (bitset_stats_count,
bitset_stats_empty_p, bitset_stats_ones, bitset_stats_zero,
bitset_stats_copy, bitset_stats_disjoint_p,
bitset_stats_equal_p, bitset_stats_not, bitset_stats_subset_p,
bitset_stats_and, bitset_stats_and_cmp, bitset_stats_andn,
bitset_stats_andn_cmp, bitset_stats_or, bitset_stats_or_cmp,
bitset_stats_xor, bitset_stats_xor_cmp, bitset_stats_and_or,
bitset_stats_and_or_cmp, bitset_stats_andn_or,
bitset_stats_andn_or_cmp, bitset_stats_or_and,
bitset_stats_or_and_cmp): Likewise.
* lib/lbitset.c (lbitset_and, lbitset_and_cmp, lbitset_andn,
lbitset_andn_cmp, lbitset_or, lbitset_or_cmp, lbitset_xor,
lbitset_xor_cmp, lbitset_empty_p, lbitset_ones, lbitset_not,
lbitset_subset_p, lbitset_disjoint_p, debug_lbitset): Likewise.
* lib/abitset.h: Include bitset.h, not bbitset.h.
* lib/ebitset.h: Likewise.
* lib/lbitset.h: Likewise.
* lib/bbitset.h: (enum_bitset_ops, enum_bitset_type): New types.
All instances of parameters of type enum bitset_opts are now of
type enum_bitset_opts, to conform to the C Standard, and similarly
for enum_bitset_type.
* lib/ebitset.c (enum_ebitset_find_mode): Likewise.
* lib/lbitset.c (enum_lbitset_find_mode): Likewise.
Do not use "struct bitset_struct" to mean different things in
different modules. Not only is this confusing, it violates
the C Standard, which requires that structure types in different
modules must be compatible if one is to be passed to the other.
* lib/bbitset.h (bitset): Now points to a union, not to a struct.
All instances of "struct bitset_struct *" replaced with "bitset".
* lib/bitset.h (struct bitset_struct): Remove, replacing with....
(union bitset_union, struct abitset_struct, struct ebitset_struct,
struct lbitset_struct, struct bitset_stats_struct): New types.
All uses of struct bitset_struct changed to union bitset_union,
etc.
* lib/abitset.c (struct abitset_struct, abitset,
struct bitset_struct): Remove.
* lib/bitset_stats.c (struct bitset_stats_struct, bitset_stats,
struct bitset_struct): Remove.
* lib/ebitset.c (struct ebitset_struct, ebitset, struct
bitset_struct): Remove.
* lib/lbitset.c (struct lbitset_struct, lbitset, bitset_struct):
Likewise.
Do not call a function of type T using a call that assumes the
function is of a different type U. Standard C requires that a
function must be called with a type that is compatible with its
definition.
* lib/bbitset.h (bitset_and_or_, bitset_andn_or_, bitset_or_and_):
New decls.
* lib/bitset.c (bitset_and_or_, bitset_andn_or_, bitset_or_and_):
New functions.
* lib/ebitset.c (PFV): Remove.
* lib/lbitset.c (PFV): Likewise.
* lib/ebitset.c (ebitset_and, ebitset_andn, ebitset_or,
ebitset_xor, ebitset_copy, ebitset_ones, ebitset_empty_p): New
decls.
(ebitset_and, ebitset_andn, ebitset_or, ebitset_xor): New functions.
(ebitset_vtable): Use them.
* lib/lbitset.c (lbitset_and, lbitset_andn, lbitset_or,
lbitset_xor): New functions.
(lbitset_vtable): Use them.
* lib/bitset.h (bitset_next, bitset_prev, bitset_only_set_p):
Declare.
* lib/bitsetv.c (bitsetv_alloc): Add a cast to (void *) to avoid a
GCC warning.
* lib/lbitset.c (LBITSET_CURRENT1): Likewise.
Use offsetof, for simplicity.
Index: lib/abitset.c
===================================================================
RCS file: /cvsroot/bison/bison/lib/abitset.c,v
retrieving revision 1.4
diff -p -u -r1.4 abitset.c
--- lib/abitset.c 2 Oct 2002 07:41:04 -0000 1.4
+++ lib/abitset.c 10 Oct 2002 06:25:56 -0000
@@ -22,27 +22,37 @@
#endif
#include "abitset.h"
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
/* This file implements fixed size bitsets stored as an array
of words. Any unused bits in the last word must be zero. */
-typedef struct abitset_struct
-{
- bitset_bindex n_bits; /* Number of bits. */
- bitset_word words[1]; /* The array of bits. */
-}
-*abitset;
-
-
-struct bitset_struct
-{
- struct bbitset_struct b;
- struct abitset_struct a;
-};
-
static void abitset_unused_clear PARAMS ((bitset));
+static void abitset_ones PARAMS ((bitset));
+static void abitset_zero PARAMS ((bitset));
+static int abitset_empty_p PARAMS ((bitset));
+static void abitset_copy1 PARAMS ((bitset, bitset));
+static void abitset_not PARAMS ((bitset, bitset));
+static int abitset_equal_p PARAMS ((bitset, bitset));
+static int abitset_subset_p PARAMS ((bitset, bitset));
+static int abitset_disjoint_p PARAMS ((bitset, bitset));
+static void abitset_and PARAMS ((bitset, bitset, bitset));
+static int abitset_and_cmp PARAMS ((bitset, bitset, bitset));
+static void abitset_andn PARAMS ((bitset, bitset, bitset));
+static int abitset_andn_cmp PARAMS ((bitset, bitset, bitset));
+static void abitset_or PARAMS ((bitset, bitset, bitset));
+static int abitset_or_cmp PARAMS ((bitset, bitset, bitset));
+static void abitset_xor PARAMS ((bitset, bitset, bitset));
+static int abitset_xor_cmp PARAMS ((bitset, bitset, bitset));
+static void abitset_and_or PARAMS ((bitset, bitset, bitset, bitset));
+static int abitset_and_or_cmp PARAMS ((bitset, bitset, bitset, bitset));
+static void abitset_andn_or PARAMS ((bitset, bitset, bitset, bitset));
+static int abitset_andn_or_cmp PARAMS ((bitset, bitset, bitset, bitset));
+static void abitset_or_and PARAMS ((bitset, bitset, bitset, bitset));
+static int abitset_or_and_cmp PARAMS ((bitset, bitset, bitset, bitset));
+static void abitset_copy PARAMS ((bitset, bitset));
static bitset_bindex abitset_small_list PARAMS ((bitset, bitset_bindex *,
bitset_bindex,
@@ -799,7 +809,7 @@ abitset_or_and_cmp (dst, src1, src2, src
}
-void
+static void
abitset_copy (dst, src)
bitset dst;
bitset src;
@@ -891,10 +901,22 @@ abitset_bytes (n_bits)
{
bitset_windex size;
size_t bytes;
+ size_t header_size = offsetof (struct abitset_struct, words);
+ struct abitset_align_struct { char a; struct abitset_struct b; };
+ size_t abitset_alignment = offsetof (struct abitset_align_struct, b);
size = ABITSET_N_WORDS (n_bits);
- bytes = size * sizeof (bitset_word);
- return sizeof (struct bitset_struct) + bytes - sizeof (bitset_word);
+ bytes = header_size + size * sizeof (bitset_word);
+
+ /* Align the size properly for objects of type struct abitset_struct. */
+ if (header_size % abitset_alignment != 0
+ || sizeof (bitset_word) % abitset_alignment != 0)
+ {
+ bytes += abitset_alignment - 1;
+ bytes -= bytes % abitset_alignment;
+ }
+
+ return bytes;
}
Index: lib/abitset.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/abitset.h,v
retrieving revision 1.2
diff -p -u -r1.2 abitset.h
--- lib/abitset.h 2 Oct 2002 07:42:26 -0000 1.2
+++ lib/abitset.h 10 Oct 2002 06:25:56 -0000
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suit
#ifndef _ABITSET_H
#define _ABITSET_H
-#include "bbitset.h"
+#include "bitset.h"
extern size_t abitset_bytes PARAMS ((bitset_bindex));
Index: lib/bbitset.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/bbitset.h,v
retrieving revision 1.7
diff -p -u -r1.7 bbitset.h
--- lib/bbitset.h 5 Oct 2002 05:02:30 -0000 1.7
+++ lib/bbitset.h 10 Oct 2002 06:25:56 -0000
@@ -25,6 +25,15 @@ Foundation, Inc., 59 Temple Place - Suit
#include <limits.h>
#endif
+/* Use the following types for function parameters where the
+ corresponding enum would be the correct type if we could use
+ prototyped function definitions. Standard C says that one cannot
+ portably use an enum as a parameter of an old-style function
+ definition that is also declared with a prototype. */
+
+typedef int enum_bitset_ops;
+typedef int enum_bitset_type;
+
/* Currently we support three flavours of bitsets:
BITSET_ARRAY: Array of bits (fixed size, fast for dense bitsets).
BITSET_LIST: Linked list of array of bits (variable size, least storage
@@ -94,65 +103,51 @@ struct bbitset_struct
};
-typedef struct bitset_struct *bitset;
+typedef union bitset_union *bitset;
/* The contents of this structure should be considered private. */
struct bitset_vtable
{
- void (*set) PARAMS ((struct bitset_struct *, bitset_bindex));
- void (*reset) PARAMS ((struct bitset_struct *, bitset_bindex));
- int (*toggle) PARAMS ((struct bitset_struct *, bitset_bindex));
- int (*test) PARAMS ((struct bitset_struct *, bitset_bindex));
- bitset_bindex (*size) PARAMS ((struct bitset_struct *));
- bitset_bindex (*count) PARAMS ((struct bitset_struct *));
-
- int (*empty_p) PARAMS ((struct bitset_struct *));
- void (*ones) PARAMS ((struct bitset_struct *));
- void (*zero) PARAMS ((struct bitset_struct *));
-
- void (*copy) PARAMS ((struct bitset_struct *, struct bitset_struct *));
- int (*disjoint_p) PARAMS ((struct bitset_struct *, struct bitset_struct *));
- int (*equal_p) PARAMS ((struct bitset_struct *, struct bitset_struct *));
- void (*not) PARAMS ((struct bitset_struct *, struct bitset_struct *));
- int (*subset_p) PARAMS ((struct bitset_struct *, struct bitset_struct *));
-
- void (*and) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- int (*and_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- void (*andn) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- int (*andn_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- void (*or) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- int (*or_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- void (*xor) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- int (*xor_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
-
- void (*and_or) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- int (*and_or_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- void (*andn_or) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- int (*andn_or_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- void (*or_and) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- int (*or_and_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
+ void (*set) PARAMS ((bitset, bitset_bindex));
+ void (*reset) PARAMS ((bitset, bitset_bindex));
+ int (*toggle) PARAMS ((bitset, bitset_bindex));
+ int (*test) PARAMS ((bitset, bitset_bindex));
+ bitset_bindex (*size) PARAMS ((bitset));
+ bitset_bindex (*count) PARAMS ((bitset));
+
+ int (*empty_p) PARAMS ((bitset));
+ void (*ones) PARAMS ((bitset));
+ void (*zero) PARAMS ((bitset));
+
+ void (*copy) PARAMS ((bitset, bitset));
+ int (*disjoint_p) PARAMS ((bitset, bitset));
+ int (*equal_p) PARAMS ((bitset, bitset));
+ void (*not) PARAMS ((bitset, bitset));
+ int (*subset_p) PARAMS ((bitset, bitset));
+
+ void (*and) PARAMS ((bitset, bitset, bitset));
+ int (*and_cmp) PARAMS ((bitset, bitset, bitset));
+ void (*andn) PARAMS ((bitset, bitset, bitset));
+ int (*andn_cmp) PARAMS ((bitset, bitset, bitset));
+ void (*or) PARAMS ((bitset, bitset, bitset));
+ int (*or_cmp) PARAMS ((bitset, bitset, bitset));
+ void (*xor) PARAMS ((bitset, bitset, bitset));
+ int (*xor_cmp) PARAMS ((bitset, bitset, bitset));
+
+ void (*and_or) PARAMS ((bitset, bitset, bitset, bitset));
+ int (*and_or_cmp) PARAMS ((bitset, bitset, bitset, bitset));
+ void (*andn_or) PARAMS ((bitset, bitset, bitset, bitset));
+ int (*andn_or_cmp) PARAMS ((bitset, bitset, bitset, bitset));
+ void (*or_and) PARAMS ((bitset, bitset, bitset, bitset));
+ int (*or_and_cmp) PARAMS ((bitset, bitset, bitset, bitset));
- bitset_bindex (*list) PARAMS ((struct bitset_struct *, bitset_bindex *,
+ bitset_bindex (*list) PARAMS ((bitset, bitset_bindex *,
bitset_bindex, bitset_bindex *));
- bitset_bindex (*list_reverse) PARAMS ((struct bitset_struct *,
+ bitset_bindex (*list_reverse) PARAMS ((bitset,
bitset_bindex *, bitset_bindex,
bitset_bindex *));
- void (*free) PARAMS ((struct bitset_struct *));
+ void (*free) PARAMS ((bitset));
enum bitset_type type;
};
@@ -284,9 +279,15 @@ extern bitset_bindex bitset_count_ PARAM
extern int bitset_copy_ PARAMS ((bitset, bitset));
+extern void bitset_and_or_ PARAMS ((bitset, bitset, bitset, bitset));
+
extern int bitset_and_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset));
+extern void bitset_andn_or_ PARAMS ((bitset, bitset, bitset, bitset));
+
extern int bitset_andn_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset));
+
+extern void bitset_or_and_ PARAMS ((bitset, bitset, bitset, bitset));
extern int bitset_or_and_cmp_ PARAMS ((bitset, bitset, bitset, bitset));
Index: lib/bitset.c
===================================================================
RCS file: /cvsroot/bison/bison/lib/bitset.c,v
retrieving revision 1.6
diff -p -u -r1.6 bitset.c
--- lib/bitset.c 2 Oct 2002 07:45:37 -0000 1.6
+++ lib/bitset.c 10 Oct 2002 06:25:56 -0000
@@ -31,13 +31,14 @@
const char * const bitset_type_names[] = BITSET_TYPE_NAMES;
static void bitset_print PARAMS ((FILE *, bitset, int));
+static int bitset_op4_cmp PARAMS ((bitset, bitset, bitset, bitset, int));
/* Return number of bytes required to create a N_BIT bitset
of TYPE. The bitset may grow to require more bytes than this. */
size_t
bitset_bytes (type, n_bits)
- enum bitset_type type;
+ enum_bitset_type type;
bitset_bindex n_bits;
{
size_t bytes;
@@ -72,7 +73,7 @@ bitset
bitset_init (bset, n_bits, type)
bitset bset;
bitset_bindex n_bits;
- enum bitset_type type;
+ enum_bitset_type type;
{
if (bitset_stats_enabled)
return bitset_stats_init (bset, n_bits, type);
@@ -130,7 +131,7 @@ bitset_type_choose (n_bits, attr)
bitset
bitset_alloc (n_bits, type)
bitset_bindex n_bits;
- enum bitset_type type;
+ enum_bitset_type type;
{
size_t bytes;
bitset bset;
@@ -152,7 +153,7 @@ bitset
bitset_obstack_alloc (bobstack, n_bits, type)
struct obstack *bobstack;
bitset_bindex n_bits;
- enum bitset_type type;
+ enum_bitset_type type;
{
size_t bytes;
bitset bset;
@@ -422,7 +423,7 @@ bitset_op4_cmp (dst, src1, src2, src3, o
bitset src1;
bitset src2;
bitset src3;
- enum bitset_ops op;
+ enum_bitset_ops op;
{
int changed = 0;
int stats_enabled_save;
@@ -460,6 +461,18 @@ bitset_op4_cmp (dst, src1, src2, src3, o
}
+/* DST = (SRC1 & SRC2) | SRC3. */
+void
+bitset_and_or_ (dst, src1, src2, src3)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+ bitset src3;
+{
+ bitset_and_or_cmp_ (dst, src1, src2, src3);
+}
+
+
/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
DST != (SRC1 & SRC2) | SRC3. */
int
@@ -473,6 +486,18 @@ bitset_and_or_cmp_ (dst, src1, src2, src
}
+/* DST = (SRC1 & ~SRC2) | SRC3. */
+void
+bitset_andn_or_ (dst, src1, src2, src3)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+ bitset src3;
+{
+ bitset_andn_or_cmp_ (dst, src1, src2, src3);
+}
+
+
/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
DST != (SRC1 & ~SRC2) | SRC3. */
int
@@ -483,6 +508,18 @@ bitset_andn_or_cmp_ (dst, src1, src2, sr
bitset src3;
{
return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_ANDN_OR);
+}
+
+
+/* DST = (SRC1 | SRC2) & SRC3. */
+void
+bitset_or_and_ (dst, src1, src2, src3)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+ bitset src3;
+{
+ bitset_or_and_cmp_ (dst, src1, src2, src3);
}
Index: lib/bitset.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/bitset.h,v
retrieving revision 1.8
diff -p -u -r1.8 bitset.h
--- lib/bitset.h 7 Oct 2002 05:43:35 -0000 1.8
+++ lib/bitset.h 10 Oct 2002 06:25:56 -0000
@@ -36,12 +36,42 @@ enum bitset_attr {BITSET_FIXED = 1, /
typedef unsigned int bitset_attrs;
-/* The contents of the structure should be considered to be private.
- While I would like to make this structure opaque, it needs to be
- visible for the inline bit set/test functions. */
-struct bitset_struct
+/* The contents of the union should be considered to be private.
+ While I would like to make this union opaque, it needs to be
+ visible for the inline bit set/test functions, and for delegation
+ to the proper implementation. */
+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 abitset_struct
+ {
+ struct bbitset_struct b;
+ bitset_bindex n_bits; /* Number of bits. */
+ bitset_word words[1]; /* The array of bits. */
+ } a;
+
+ struct ebitset_struct
+ {
+ struct bbitset_struct b;
+ bitset_windex size; /* Number of elements. */
+ struct ebitset_elt_struct **elts; /* Expanding array of ptrs to elts. */
+ } e;
+
+ struct lbitset_struct
+ {
+ struct bbitset_struct b;
+ struct lbitset_elt_struct *head; /* First element in linked list. */
+ struct lbitset_elt_struct *tail; /* Last element in linked list. */
+ } l;
+
+ struct bitset_stats_struct
+ {
+ struct bbitset_struct b;
+ bitset bset;
+ } s;
};
@@ -57,10 +87,10 @@ 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 PARAMS ((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 PARAMS ((bitset, bitset_bindex, enum_bitset_type));
/* Select an implementation type based on the desired bitset size
and attributes. */
@@ -68,7 +98,7 @@ extern enum bitset_type bitset_type_choo
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 PARAMS ((bitset_bindex, enum_bitset_type));
/* Free bitset. */
extern void bitset_free PARAMS ((bitset));
@@ -76,7 +106,7 @@ extern void bitset_free PARAMS ((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));
+ bitset_bindex, enum_bitset_type));
/* Free bitset allocated on obstack. */
extern void bitset_obstack_free PARAMS ((bitset));
@@ -287,11 +317,20 @@ do
\
BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT)
+/* Find next set bit. */
+extern bitset_bindex bitset_next PARAMS ((bitset, bitset_bindex));
+
+/* Find previous set bit. */
+extern bitset_bindex bitset_prev PARAMS ((bitset, bitset_bindex));
+
/* Find first set bit. */
extern bitset_bindex bitset_first PARAMS ((bitset));
/* Find last set bit. */
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));
/* Dump bitset. */
extern void bitset_dump PARAMS ((FILE *, bitset));
Index: lib/bitset_stats.c
===================================================================
RCS file: /cvsroot/bison/bison/lib/bitset_stats.c,v
retrieving revision 1.4
diff -p -u -r1.4 bitset_stats.c
--- lib/bitset_stats.c 2 Oct 2002 07:49:35 -0000 1.4
+++ lib/bitset_stats.c 10 Oct 2002 06:25:56 -0000
@@ -75,19 +75,6 @@
bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_density[(I)]++
-typedef struct bitset_stats_struct
-{
- bitset bset;
-} *bitset_stats;
-
-
-struct bitset_struct
-{
- struct bbitset_struct b;
- struct bitset_stats_struct s;
-};
-
-
struct bitset_type_info_struct
{
unsigned int allocs;
@@ -121,6 +108,29 @@ static void bitset_stats_reset PARAMS ((
static int bitset_stats_toggle PARAMS ((bitset, bitset_bindex));
static int bitset_stats_test PARAMS ((bitset, bitset_bindex));
static bitset_bindex bitset_stats_size PARAMS ((bitset));
+static bitset_bindex bitset_stats_count PARAMS ((bitset));
+static int bitset_stats_empty_p PARAMS ((bitset));
+static void bitset_stats_ones PARAMS ((bitset));
+static void bitset_stats_zero PARAMS ((bitset));
+static void bitset_stats_copy PARAMS ((bitset, bitset));
+static int bitset_stats_disjoint_p PARAMS ((bitset, bitset));
+static int bitset_stats_equal_p PARAMS ((bitset, bitset));
+static void bitset_stats_not PARAMS ((bitset, bitset));
+static int bitset_stats_subset_p PARAMS ((bitset, bitset));
+static void bitset_stats_and PARAMS ((bitset, bitset, bitset));
+static int bitset_stats_and_cmp PARAMS ((bitset, bitset, bitset));
+static void bitset_stats_andn PARAMS ((bitset, bitset, bitset));
+static int bitset_stats_andn_cmp PARAMS ((bitset, bitset, bitset));
+static void bitset_stats_or PARAMS ((bitset, bitset, bitset));
+static int bitset_stats_or_cmp PARAMS ((bitset, bitset, bitset));
+static void bitset_stats_xor PARAMS ((bitset, bitset, bitset));
+static int bitset_stats_xor_cmp PARAMS ((bitset, bitset, bitset));
+static void bitset_stats_and_or PARAMS ((bitset, bitset, bitset, bitset));
+static int bitset_stats_and_or_cmp PARAMS ((bitset, bitset, bitset, bitset));
+static void bitset_stats_andn_or PARAMS ((bitset, bitset, bitset, bitset));
+static int bitset_stats_andn_or_cmp PARAMS ((bitset, bitset, bitset, bitset));
+static void bitset_stats_or_and PARAMS ((bitset, bitset, bitset, bitset));
+static int bitset_stats_or_and_cmp PARAMS ((bitset, bitset, bitset, bitset));
static bitset_bindex bitset_stats_list PARAMS ((bitset, bitset_bindex *,
bitset_bindex,
bitset_bindex *));
@@ -799,7 +809,7 @@ bitset_stats_type_get (bset)
size_t
bitset_stats_bytes (void)
{
- return sizeof (struct bitset_struct);
+ return sizeof (struct bitset_stats_struct);
}
@@ -807,7 +817,7 @@ bitset
bitset_stats_init (bset, n_bits, type)
bitset bset;
bitset_bindex n_bits;
- enum bitset_type type;
+ enum_bitset_type type;
{
size_t bytes;
bitset sbset;
Index: lib/bitset_stats.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/bitset_stats.h,v
retrieving revision 1.2
diff -p -u -r1.2 bitset_stats.h
--- lib/bitset_stats.h 2 Oct 2002 07:50:39 -0000 1.2
+++ lib/bitset_stats.h 10 Oct 2002 06:25:56 -0000
@@ -28,6 +28,6 @@ extern enum bitset_type bitset_stats_typ
extern size_t bitset_stats_bytes PARAMS ((void));
extern bitset bitset_stats_init PARAMS ((bitset, bitset_bindex,
- enum bitset_type));
+ enum_bitset_type));
#endif
Index: lib/bitsetv.c
===================================================================
RCS file: /cvsroot/bison/bison/lib/bitsetv.c,v
retrieving revision 1.6
diff -p -u -r1.6 bitsetv.c
--- lib/bitsetv.c 2 Oct 2002 07:54:52 -0000 1.6
+++ lib/bitsetv.c 10 Oct 2002 06:25:56 -0000
@@ -32,7 +32,7 @@ bitset *
bitsetv_alloc (n_vecs, n_bits, type)
bitset_bindex n_vecs;
bitset_bindex n_bits;
- enum bitset_type type;
+ enum_bitset_type type;
{
size_t vector_bytes;
size_t bytes;
@@ -47,12 +47,13 @@ bitsetv_alloc (n_vecs, n_bits, type)
xalloc_die ();
/* Allocate vector table at head of bitset array. */
- vector_bytes = (n_vecs + 1) * sizeof (bitset);
+ vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1;
+ vector_bytes -= vector_bytes % bytes;
bsetv = (bitset *) xcalloc (1, vector_bytes + bytes * n_vecs);
for (i = 0; i < n_vecs; i++)
{
- bsetv[i] = (bitset) ((char *) bsetv + vector_bytes + i * bytes);
+ bsetv[i] = (bitset) (void *) ((char *) bsetv + vector_bytes + i * bytes);
bitset_init (bsetv[i], n_bits, type);
}
@@ -94,7 +95,7 @@ bitsetv_free (bsetv)
/* Zero a vector of bitsets. */
void
bitsetv_zero (bsetv)
- struct bitset_struct **bsetv;
+ bitsetv bsetv;
{
bitset_bindex i;
Index: lib/bitsetv.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/bitsetv.h,v
retrieving revision 1.4
diff -p -u -r1.4 bitsetv.h
--- lib/bitsetv.h 2 Oct 2002 07:55:44 -0000 1.4
+++ lib/bitsetv.h 10 Oct 2002 06:25:56 -0000
@@ -26,7 +26,7 @@ typedef bitset * bitsetv;
/* Create a vector of N_VECS bitsets, each of N_BITS, and of
type TYPE. */
extern bitsetv bitsetv_alloc PARAMS ((bitset_bindex, bitset_bindex,
- enum bitset_type));
+ enum_bitset_type));
/* Create a vector of N_VECS bitsets, each of N_BITS, and with
attribute hints specified by ATTR. */
Index: lib/ebitset.c
===================================================================
RCS file: /cvsroot/bison/bison/lib/ebitset.c,v
retrieving revision 1.8
diff -p -u -r1.8 ebitset.c
--- lib/ebitset.c 5 Oct 2002 05:02:30 -0000 1.8
+++ lib/ebitset.c 10 Oct 2002 06:25:57 -0000
@@ -68,17 +68,6 @@ ebitset_elt;
typedef ebitset_elt *ebitset_elts;
-/* Head of ebitset linked list. */
-typedef struct ebitset_struct
-{
- bitset_windex size; /* Number of elements. */
- ebitset_elts *elts; /* Expanding array of pointers to elements. */
-}
-*ebitset;
-
-
-typedef void(*PFV)();
-
/* Number of elements to initially allocate. */
@@ -92,14 +81,9 @@ typedef void(*PFV)();
#define EBITSET_GROW_SIZE 4
#endif
-struct bitset_struct
-{
- struct bbitset_struct b;
- struct ebitset_struct e;
-};
-
enum ebitset_find_mode
{ EBITSET_FIND, EBITSET_CREATE, EBITSET_SUBST };
+typedef int enum_ebitset_find_mode;
static ebitset_elt ebitset_zero_elts[1]; /* Elements of all zero bits. */
@@ -115,7 +99,7 @@ static void ebitset_elt_add PARAMS ((bit
static void ebitset_elt_remove PARAMS ((bitset, bitset_windex));
static void ebitset_elt_free PARAMS ((ebitset_elt *));
static ebitset_elt *ebitset_elt_find PARAMS ((bitset, bitset_windex,
- enum ebitset_find_mode));
+ enum_ebitset_find_mode));
static ebitset_elt *ebitset_elt_last PARAMS ((bitset));
static int ebitset_elt_zero_p PARAMS ((ebitset_elt *));
@@ -131,15 +115,23 @@ static int ebitset_disjoint_p PARAMS ((b
static int ebitset_equal_p PARAMS ((bitset, bitset));
static void ebitset_not PARAMS ((bitset, bitset));
static int ebitset_subset_p PARAMS ((bitset, bitset));
-static int ebitset_op3_cmp PARAMS ((bitset, bitset, bitset, enum bitset_ops));
+static int ebitset_op3_cmp PARAMS ((bitset, bitset, bitset, enum_bitset_ops));
+static void ebitset_and PARAMS ((bitset, bitset, bitset));
static int ebitset_and_cmp PARAMS ((bitset, bitset, bitset));
+static void ebitset_andn PARAMS ((bitset, bitset, bitset));
static int ebitset_andn_cmp PARAMS ((bitset, bitset, bitset));
+static void ebitset_or PARAMS ((bitset, bitset, bitset));
static int ebitset_or_cmp PARAMS ((bitset, bitset, bitset));
+static void ebitset_xor PARAMS ((bitset, bitset, bitset));
static int ebitset_xor_cmp PARAMS ((bitset, bitset, bitset));
+static void ebitset_copy PARAMS ((bitset, bitset));
static bitset_bindex ebitset_list PARAMS ((bitset, bitset_bindex *,
bitset_bindex, bitset_bindex *));
static bitset_bindex ebitset_list_reverse
PARAMS ((bitset, bitset_bindex *, bitset_bindex, bitset_bindex *));
+static void ebitset_ones PARAMS ((bitset));
+static int ebitset_empty_p PARAMS ((bitset));
+static void ebitset_copy PARAMS ((bitset, bitset));
static void ebitset_free PARAMS ((bitset));
#define EBITSET_ELTS(BSET) ((BSET)->e.elts)
@@ -320,7 +312,7 @@ static ebitset_elt *
ebitset_elt_find (bset, windex, mode)
bitset bset;
bitset_windex windex;
- enum ebitset_find_mode mode;
+ enum_ebitset_find_mode mode;
{
ebitset_elt *elt;
bitset_windex size;
@@ -1016,7 +1008,7 @@ ebitset_op3_cmp (dst, src1, src2, op)
bitset dst;
bitset src1;
bitset src2;
- enum bitset_ops op;
+ enum_bitset_ops op;
{
bitset_windex ssize1;
bitset_windex ssize2;
@@ -1164,6 +1156,16 @@ ebitset_op3_cmp (dst, src1, src2, op)
}
+static void
+ebitset_and (dst, src1, src2)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+{
+ ebitset_and_cmp (dst, src1, src2);
+}
+
+
static int
ebitset_and_cmp (dst, src1, src2)
bitset dst;
@@ -1190,6 +1192,16 @@ ebitset_and_cmp (dst, src1, src2)
}
+static void
+ebitset_andn (dst, src1, src2)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+{
+ ebitset_andn_cmp (dst, src1, src2);
+}
+
+
static int
ebitset_andn_cmp (dst, src1, src2)
bitset dst;
@@ -1213,6 +1225,16 @@ ebitset_andn_cmp (dst, src1, src2)
}
+static void
+ebitset_or (dst, src1, src2)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+{
+ ebitset_or_cmp (dst, src1, src2);
+}
+
+
static int
ebitset_or_cmp (dst, src1, src2)
bitset dst;
@@ -1231,6 +1253,16 @@ ebitset_or_cmp (dst, src1, src2)
}
+static void
+ebitset_xor (dst, src1, src2)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+{
+ ebitset_xor_cmp (dst, src1, src2);
+}
+
+
static int
ebitset_xor_cmp (dst, src1, src2)
bitset dst;
@@ -1277,19 +1309,19 @@ struct bitset_vtable ebitset_vtable = {
ebitset_equal_p,
ebitset_not,
ebitset_subset_p,
- (PFV) ebitset_and_cmp,
+ ebitset_and,
ebitset_and_cmp,
- (PFV) ebitset_andn_cmp,
+ ebitset_andn,
ebitset_andn_cmp,
- (PFV) ebitset_or_cmp,
+ ebitset_or,
ebitset_or_cmp,
- (PFV) ebitset_xor_cmp,
+ ebitset_xor,
ebitset_xor_cmp,
- (PFV) bitset_and_or_cmp_,
+ bitset_and_or_,
bitset_and_or_cmp_,
- (PFV) bitset_andn_or_cmp_,
+ bitset_andn_or_,
bitset_andn_or_cmp_,
- (PFV) bitset_or_and_cmp_,
+ bitset_or_and_,
bitset_or_and_cmp_,
ebitset_list,
ebitset_list_reverse,
@@ -1303,7 +1335,7 @@ size_t
ebitset_bytes (n_bits)
bitset_bindex n_bits ATTRIBUTE_UNUSED;
{
- return sizeof (struct bitset_struct);
+ return sizeof (struct ebitset_struct);
}
Index: lib/ebitset.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/ebitset.h,v
retrieving revision 1.4
diff -p -u -r1.4 ebitset.h
--- lib/ebitset.h 2 Oct 2002 07:58:11 -0000 1.4
+++ lib/ebitset.h 10 Oct 2002 06:25:57 -0000
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suit
#ifndef _EBITSET_H
#define _EBITSET_H
-#include "bbitset.h"
+#include "bitset.h"
extern size_t ebitset_bytes PARAMS ((bitset_bindex));
Index: lib/lbitset.c
===================================================================
RCS file: /cvsroot/bison/bison/lib/lbitset.c,v
retrieving revision 1.8
diff -p -u -r1.8 lbitset.c
--- lib/lbitset.c 7 Oct 2002 05:41:35 -0000 1.8
+++ lib/lbitset.c 10 Oct 2002 06:25:57 -0000
@@ -23,6 +23,7 @@
#include "lbitset.h"
#include "obstack.h"
+#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
@@ -63,27 +64,9 @@ typedef struct lbitset_elt_struct
lbitset_elt;
-/* Head of lbitset linked list. */
-typedef struct lbitset_struct
-{
- lbitset_elt *head; /* First element in linked list. */
- lbitset_elt *tail; /* Last element in linked list. */
-}
-*lbitset;
-
-
-struct bitset_struct
-{
- struct bbitset_struct b;
- struct lbitset_struct l;
-};
-
-
-typedef void(*PFV)();
-
-
enum lbitset_find_mode
{ LBITSET_FIND, LBITSET_CREATE, LBITSET_SUBST };
+typedef int enum_lbitset_find_mode;
static lbitset_elt lbitset_zero_elts[3]; /* Elements of all zero bits. */
@@ -98,7 +81,7 @@ static void lbitset_elt_link PARAMS ((bi
static void lbitset_elt_unlink PARAMS ((bitset, lbitset_elt *));
static void lbitset_elt_free PARAMS ((lbitset_elt *));
static lbitset_elt *lbitset_elt_find PARAMS ((bitset, bitset_windex,
- enum lbitset_find_mode));
+ enum_lbitset_find_mode));
static int lbitset_elt_zero_p PARAMS ((lbitset_elt *));
static void lbitset_prune PARAMS ((bitset, lbitset_elt *));
@@ -111,15 +94,29 @@ static void lbitset_set PARAMS ((bitset,
static void lbitset_reset PARAMS ((bitset, bitset_bindex));
static int lbitset_test PARAMS ((bitset, bitset_bindex));
static bitset_bindex lbitset_size PARAMS ((bitset));
-static int lbitset_op3_cmp PARAMS ((bitset, bitset, bitset, enum bitset_ops));
+static int lbitset_op3_cmp PARAMS ((bitset, bitset, bitset, enum_bitset_ops));
+static void lbitset_and PARAMS ((bitset, bitset, bitset));
+static int lbitset_and_cmp PARAMS ((bitset, bitset, bitset));
+static void lbitset_andn PARAMS ((bitset, bitset, bitset));
+static int lbitset_andn_cmp PARAMS ((bitset, bitset, bitset));
+static void lbitset_or PARAMS ((bitset, bitset, bitset));
+static int lbitset_or_cmp PARAMS ((bitset, bitset, bitset));
+static void lbitset_xor PARAMS ((bitset, bitset, bitset));
+static int lbitset_xor_cmp PARAMS ((bitset, bitset, bitset));
static bitset_bindex lbitset_list PARAMS ((bitset, bitset_bindex *,
bitset_bindex, bitset_bindex *));
static bitset_bindex lbitset_list_reverse
PARAMS ((bitset, bitset_bindex *, bitset_bindex, bitset_bindex *));
+static int lbitset_empty_p PARAMS ((bitset));
+static void lbitset_ones PARAMS ((bitset));
+static void lbitset_not PARAMS ((bitset, bitset));
+static int lbitset_subset_p PARAMS ((bitset, bitset));
+static int lbitset_disjoint_p PARAMS ((bitset, bitset));
static void lbitset_free PARAMS ((bitset));
+extern void debug_lbitset PARAMS ((bitset));
-
-#define LBITSET_CURRENT1(X) (lbitset_elt *)((char *)(X) + ((char
*)&(((lbitset_elt *)(X))->next) - (char *)&(((lbitset_elt *)(X))->words)))
+#define LBITSET_CURRENT1(X) \
+ ((lbitset_elt *) (void *) ((char *) (X) - offsetof (lbitset_elt, words)))
#define LBITSET_CURRENT(X) LBITSET_CURRENT1((X)->b.cdata)
@@ -367,7 +364,7 @@ static lbitset_elt *
lbitset_elt_find (bset, windex, mode)
bitset bset;
bitset_windex windex;
- enum lbitset_find_mode mode;
+ enum_lbitset_find_mode mode;
{
lbitset_elt *elt;
lbitset_elt *current;
@@ -1094,7 +1091,7 @@ lbitset_op3_cmp (dst, src1, src2, op)
bitset dst;
bitset src1;
bitset src2;
- enum bitset_ops op;
+ enum_bitset_ops op;
{
lbitset_elt *selt1 = LBITSET_HEAD (src1);
lbitset_elt *selt2 = LBITSET_HEAD (src2);
@@ -1251,6 +1248,16 @@ lbitset_op3_cmp (dst, src1, src2, op)
}
+static void
+lbitset_and (dst, src1, src2)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+{
+ lbitset_and_cmp (dst, src1, src2);
+}
+
+
static int
lbitset_and_cmp (dst, src1, src2)
bitset dst;
@@ -1279,6 +1286,16 @@ lbitset_and_cmp (dst, src1, src2)
}
+static void
+lbitset_andn (dst, src1, src2)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+{
+ lbitset_andn_cmp (dst, src1, src2);
+}
+
+
static int
lbitset_andn_cmp (dst, src1, src2)
bitset dst;
@@ -1304,6 +1321,16 @@ lbitset_andn_cmp (dst, src1, src2)
}
+static void
+lbitset_or (dst, src1, src2)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+{
+ lbitset_or_cmp (dst, src1, src2);
+}
+
+
static int
lbitset_or_cmp (dst, src1, src2)
bitset dst;
@@ -1325,6 +1352,16 @@ lbitset_or_cmp (dst, src1, src2)
}
+static void
+lbitset_xor (dst, src1, src2)
+ bitset dst;
+ bitset src1;
+ bitset src2;
+{
+ lbitset_xor_cmp (dst, src1, src2);
+}
+
+
static int
lbitset_xor_cmp (dst, src1, src2)
bitset dst;
@@ -1363,19 +1400,19 @@ struct bitset_vtable lbitset_vtable = {
lbitset_equal_p,
lbitset_not,
lbitset_subset_p,
- (PFV) lbitset_and_cmp,
+ lbitset_and,
lbitset_and_cmp,
- (PFV) lbitset_andn_cmp,
+ lbitset_andn,
lbitset_andn_cmp,
- (PFV) lbitset_or_cmp,
+ lbitset_or,
lbitset_or_cmp,
- (PFV) lbitset_xor_cmp,
+ lbitset_xor,
lbitset_xor_cmp,
- (PFV) bitset_and_or_cmp_,
+ bitset_and_or_,
bitset_and_or_cmp_,
- (PFV) bitset_andn_or_cmp_,
+ bitset_andn_or_,
bitset_andn_or_cmp_,
- (PFV) bitset_or_and_cmp_,
+ bitset_or_and_,
bitset_or_and_cmp_,
lbitset_list,
lbitset_list_reverse,
@@ -1389,7 +1426,7 @@ size_t
lbitset_bytes (n_bits)
bitset_bindex n_bits ATTRIBUTE_UNUSED;
{
- return sizeof (struct bitset_struct);
+ return sizeof (struct lbitset_struct);
}
Index: lib/lbitset.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/lbitset.h,v
retrieving revision 1.4
diff -p -u -r1.4 lbitset.h
--- lib/lbitset.h 2 Oct 2002 08:02:06 -0000 1.4
+++ lib/lbitset.h 10 Oct 2002 06:25:57 -0000
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suit
#ifndef _LBITSET_H
#define _LBITSET_H
-#include "bbitset.h"
+#include "bitset.h"
extern size_t lbitset_bytes PARAMS ((bitset_bindex));
- bitset portability patches to better conform to Standard C,
Paul Eggert <=