]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3bitset.h
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / include / antlr3bitset.h
1 /**\r
2  * \file\r
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
5  * \r
6  * \r
7  */\r
8 #ifndef _ANTLR3_BITSET_H\r
9 #define _ANTLR3_BITSET_H\r
10 \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
15 //\r
16 // All rights reserved.\r
17 //\r
18 // Redistribution and use in source and binary forms, with or without\r
19 // modification, are permitted provided that the following conditions\r
20 // are met:\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
28 //\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
39 \r
40 #include    <antlr3defs.h>\r
41 #include    <antlr3collections.h>\r
42 \r
43 /** How many bits in the elements\r
44  */\r
45 #define ANTLR3_BITSET_BITS      64\r
46 \r
47 /** How many bits in a nible of bits\r
48  */\r
49 #define ANTLR3_BITSET_NIBBLE    4\r
50 \r
51 /** log2 of ANTLR3_BITSET_BITS 2^ANTLR3_BITSET_LOG_BITS = ANTLR3_BITSET_BITS\r
52  */\r
53 #define ANTLR3_BITSET_LOG_BITS  6\r
54 \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
57  *  same as:\r
58  *   - (i & (nbits-1)).  \r
59  *\r
60  * Since mod is relatively slow, we use an easily\r
61  * precomputed mod mask to do the mod instead.\r
62  */\r
63 #define ANTLR3_BITSET_MOD_MASK  ANTLR3_BITSET_BITS - 1\r
64 \r
65 #ifdef __cplusplus\r
66 extern "C" {\r
67 #endif\r
68 \r
69 typedef struct ANTLR3_BITSET_LIST_struct\r
70 {\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
78     ///\r
79     pANTLR3_BITWORD   bits;\r
80 \r
81     /// Length of the current bit set in ANTLR3_UINT64 units.\r
82     ///\r
83     ANTLR3_UINT32    length;\r
84 }\r
85         ANTLR3_BITSET_LIST;\r
86 \r
87 typedef struct ANTLR3_BITSET_struct\r
88 {\r
89         /// The actual bits themselves\r
90         ///\r
91         ANTLR3_BITSET_LIST                              blist;\r
92 \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
105 \r
106     void                                                        (*free)                 (struct ANTLR3_BITSET_struct  * bitset);\r
107 \r
108 \r
109 }\r
110     ANTLR3_BITSET;\r
111 \r
112 #ifdef __cplusplus\r
113 }\r
114 #endif\r
115 \r
116 \r
117 \r
118 #endif\r
119 \r