3 * Defines the basic structures of an ANTLR3 bitset. this is a C version of the
\r
4 * cut down Bitset class provided with the java version of antlr 3.
\r
8 #ifndef _ANTLR3_BITSET_H
\r
9 #define _ANTLR3_BITSET_H
\r
11 // [The "BSD licence"]
\r
12 // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
\r
13 // http://www.temporal-wave.com
\r
14 // http://www.linkedin.com/in/jimidle
\r
16 // All rights reserved.
\r
18 // Redistribution and use in source and binary forms, with or without
\r
19 // modification, are permitted provided that the following conditions
\r
21 // 1. Redistributions of source code must retain the above copyright
\r
22 // notice, this list of conditions and the following disclaimer.
\r
23 // 2. Redistributions in binary form must reproduce the above copyright
\r
24 // notice, this list of conditions and the following disclaimer in the
\r
25 // documentation and/or other materials provided with the distribution.
\r
26 // 3. The name of the author may not be used to endorse or promote products
\r
27 // derived from this software without specific prior written permission.
\r
29 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
\r
30 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
\r
31 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
\r
32 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
33 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
\r
34 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
35 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
36 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
37 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
38 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
40 #include <antlr3defs.h>
\r
41 #include <antlr3collections.h>
\r
43 /** How many bits in the elements
\r
45 #define ANTLR3_BITSET_BITS 64
\r
47 /** How many bits in a nible of bits
\r
49 #define ANTLR3_BITSET_NIBBLE 4
\r
51 /** log2 of ANTLR3_BITSET_BITS 2^ANTLR3_BITSET_LOG_BITS = ANTLR3_BITSET_BITS
\r
53 #define ANTLR3_BITSET_LOG_BITS 6
\r
55 /** We will often need to do a mod operator (i mod nbits).
\r
56 * For powers of two, this mod operation is the
\r
58 * - (i & (nbits-1)).
\r
60 * Since mod is relatively slow, we use an easily
\r
61 * precomputed mod mask to do the mod instead.
\r
63 #define ANTLR3_BITSET_MOD_MASK ANTLR3_BITSET_BITS - 1
\r
69 typedef struct ANTLR3_BITSET_LIST_struct
\r
71 /// Pointer to the allocated array of bits for this bit set, which
\r
72 /// is an array of 64 bit elements (of the architecture). If we find a
\r
73 /// machine/C compiler that does not know anything about 64 bit values
\r
74 /// then it should be easy enough to produce a 32 bit (or less) version
\r
75 /// of the bitset code. Note that the pointer here may be static if laid down
\r
76 /// by the code generation, and it must be copied if it is to be manipulated
\r
77 /// to perform followset calculations.
\r
79 pANTLR3_BITWORD bits;
\r
81 /// Length of the current bit set in ANTLR3_UINT64 units.
\r
83 ANTLR3_UINT32 length;
\r
87 typedef struct ANTLR3_BITSET_struct
\r
89 /// The actual bits themselves
\r
91 ANTLR3_BITSET_LIST blist;
\r
93 pANTLR3_BITSET (*clone) (struct ANTLR3_BITSET_struct * inSet);
\r
94 pANTLR3_BITSET (*bor) (struct ANTLR3_BITSET_struct * bitset1, struct ANTLR3_BITSET_struct * bitset2);
\r
95 void (*borInPlace) (struct ANTLR3_BITSET_struct * bitset, struct ANTLR3_BITSET_struct * bitset2);
\r
96 ANTLR3_UINT32 (*size) (struct ANTLR3_BITSET_struct * bitset);
\r
97 void (*add) (struct ANTLR3_BITSET_struct * bitset, ANTLR3_INT32 bit);
\r
98 void (*grow) (struct ANTLR3_BITSET_struct * bitset, ANTLR3_INT32 newSize);
\r
99 ANTLR3_BOOLEAN (*equals) (struct ANTLR3_BITSET_struct * bitset1, struct ANTLR3_BITSET_struct * bitset2);
\r
100 ANTLR3_BOOLEAN (*isMember) (struct ANTLR3_BITSET_struct * bitset, ANTLR3_UINT32 bit);
\r
101 ANTLR3_UINT32 (*numBits) (struct ANTLR3_BITSET_struct * bitset);
\r
102 void (*remove) (struct ANTLR3_BITSET_struct * bitset, ANTLR3_UINT32 bit);
\r
103 ANTLR3_BOOLEAN (*isNilNode) (struct ANTLR3_BITSET_struct * bitset);
\r
104 pANTLR3_INT32 (*toIntList) (struct ANTLR3_BITSET_struct * bitset);
\r
106 void (*free) (struct ANTLR3_BITSET_struct * bitset);
\r