ยปCore Development>Code coverage>Parser/bitset.c

Python code coverage for Parser/bitset.c

#countcontent
1n/a
2n/a/* Bitset primitives used by the parser generator */
3n/a
4n/a#include "pgenheaders.h"
5n/a#include "bitset.h"
6n/a
7n/abitset
8n/anewbitset(int nbits)
9n/a{
10n/a int nbytes = NBYTES(nbits);
11n/a bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) * nbytes);
12n/a
13n/a if (ss == NULL)
14n/a Py_FatalError("no mem for bitset");
15n/a
16n/a ss += nbytes;
17n/a while (--nbytes >= 0)
18n/a *--ss = 0;
19n/a return ss;
20n/a}
21n/a
22n/avoid
23n/adelbitset(bitset ss)
24n/a{
25n/a PyObject_FREE(ss);
26n/a}
27n/a
28n/aint
29n/aaddbit(bitset ss, int ibit)
30n/a{
31n/a int ibyte = BIT2BYTE(ibit);
32n/a BYTE mask = BIT2MASK(ibit);
33n/a
34n/a if (ss[ibyte] & mask)
35n/a return 0; /* Bit already set */
36n/a ss[ibyte] |= mask;
37n/a return 1;
38n/a}
39n/a
40n/a#if 0 /* Now a macro */
41n/aint
42n/atestbit(bitset ss, int ibit)
43n/a{
44n/a return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0;
45n/a}
46n/a#endif
47n/a
48n/aint
49n/asamebitset(bitset ss1, bitset ss2, int nbits)
50n/a{
51n/a int i;
52n/a
53n/a for (i = NBYTES(nbits); --i >= 0; )
54n/a if (*ss1++ != *ss2++)
55n/a return 0;
56n/a return 1;
57n/a}
58n/a
59n/avoid
60n/amergebitset(bitset ss1, bitset ss2, int nbits)
61n/a{
62n/a int i;
63n/a
64n/a for (i = NBYTES(nbits); --i >= 0; )
65n/a *ss1++ |= *ss2++;
66n/a}