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