diff options
author | thegeorg <[email protected]> | 2024-06-29 11:45:54 +0300 |
---|---|---|
committer | thegeorg <[email protected]> | 2024-06-29 11:54:41 +0300 |
commit | 9158d9115725ca7f4ada745ec55eddd5747bc61e (patch) | |
tree | f262cd6d7a98bb367943a4918b6963a7800f3937 /contrib/tools/bison/lib | |
parent | 632b3cedb8e12fbbb0bcd1bdbf7ec5686725b7e9 (diff) |
Update contrib/tools/bison to 3.2.4
78e59a97f3fde03511ddb9969cd1daabbaf998bd
Diffstat (limited to 'contrib/tools/bison/lib')
42 files changed, 2016 insertions, 1912 deletions
diff --git a/contrib/tools/bison/lib/abitset.c b/contrib/tools/bison/lib/abitset.c index 830fdefcfc7..0d6b9a5d8a4 100644 --- a/contrib/tools/bison/lib/abitset.c +++ b/contrib/tools/bison/lib/abitset.c @@ -35,33 +35,28 @@ static bitset_bindex abitset_resize (bitset src, bitset_bindex size) { - /* These bitsets have a fixed size. */ - if (BITSET_SIZE_ (src) != size) - abort (); + /* These bitsets have a fixed size. */ + if (BITSET_SIZE_ (src) != size) + abort (); - return size; + return size; } /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex abitset_small_list (bitset src, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex count; - bitset_windex size; - bitset_word word; - - word = ABITSET_WORDS (src)[0]; + bitset_word word = ABITSET_WORDS (src)[0]; /* Short circuit common case. */ if (!word) return 0; - size = BITSET_SIZE_ (src); - bitno = *next; + bitset_windex size = BITSET_SIZE_ (src); + bitset_bindex bitno = *next; if (bitno >= size) return 0; @@ -70,6 +65,7 @@ abitset_small_list (bitset src, bitset_bindex *list, /* If num is 1, we could speed things up with a binary search of the word of interest. */ + bitset_bindex count; if (num >= BITSET_WORD_BITS) { for (count = 0; word; bitno++) @@ -142,36 +138,27 @@ static bitset_bindex abitset_list_reverse (bitset src, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex rbitno; - bitset_bindex count; - bitset_windex windex; - unsigned bitcnt; - bitset_bindex bitoff; + bitset_bindex rbitno = *next; bitset_word *srcp = ABITSET_WORDS (src); bitset_bindex n_bits = BITSET_SIZE_ (src); - rbitno = *next; - /* If num is 1, we could speed things up with a binary search of the word of interest. */ if (rbitno >= n_bits) return 0; - count = 0; + bitset_bindex count = 0; - bitno = n_bits - (rbitno + 1); + bitset_bindex bitno = n_bits - (rbitno + 1); - windex = bitno / BITSET_WORD_BITS; - bitcnt = bitno % BITSET_WORD_BITS; - bitoff = windex * BITSET_WORD_BITS; + bitset_windex windex = bitno / BITSET_WORD_BITS; + unsigned bitcnt = bitno % BITSET_WORD_BITS; + bitset_bindex bitoff = windex * BITSET_WORD_BITS; do { - bitset_word word; - - word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); + bitset_word word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); for (; word; bitcnt--) { if (word & BITSET_MSB) @@ -196,23 +183,20 @@ abitset_list_reverse (bitset src, bitset_bindex *list, /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex abitset_list (bitset src, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex count; bitset_windex windex; bitset_bindex bitoff; bitset_windex size = src->b.csize; bitset_word *srcp = ABITSET_WORDS (src); - bitset_word word; - bitno = *next; + bitset_bindex bitno = *next; - count = 0; + bitset_bindex count = 0; if (!bitno) { /* Many bitsets are zero, so make this common case fast. */ @@ -242,7 +226,7 @@ abitset_list (bitset src, bitset_bindex *list, on the previous call to this function. */ bitoff = windex * BITSET_WORD_BITS; - word = srcp[windex] >> bitno; + bitset_word word = srcp[windex] >> bitno; for (bitno = bitoff + bitno; word; bitno++) { if (word & 1) @@ -263,7 +247,8 @@ abitset_list (bitset src, bitset_bindex *list, for (; windex < size; windex++, bitoff += BITSET_WORD_BITS) { - if (!(word = srcp[windex])) + bitset_word word = srcp[windex]; + if (!word) continue; if ((count + BITSET_WORD_BITS) < num) @@ -302,9 +287,7 @@ abitset_list (bitset src, bitset_bindex *list, static inline void abitset_unused_clear (bitset dst) { - unsigned last_bit; - - last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; + unsigned last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; if (last_bit) ABITSET_WORDS (dst)[dst->b.csize - 1] &= ((bitset_word) 1 << last_bit) - 1; @@ -315,9 +298,7 @@ static void abitset_ones (bitset dst) { bitset_word *dstp = ABITSET_WORDS (dst); - size_t bytes; - - bytes = sizeof (bitset_word) * dst->b.csize; + size_t bytes = sizeof (bitset_word) * dst->b.csize; memset (dstp, -1, bytes); abitset_unused_clear (dst); @@ -328,9 +309,7 @@ static void abitset_zero (bitset dst) { bitset_word *dstp = ABITSET_WORDS (dst); - size_t bytes; - - bytes = sizeof (bitset_word) * dst->b.csize; + size_t bytes = sizeof (bitset_word) * dst->b.csize; memset (dstp, 0, bytes); } @@ -339,13 +318,11 @@ abitset_zero (bitset dst) static bool abitset_empty_p (bitset dst) { - bitset_windex i; bitset_word *dstp = ABITSET_WORDS (dst); - for (i = 0; i < dst->b.csize; i++) + for (bitset_windex i = 0; i < dst->b.csize; i++) if (dstp[i]) return false; - return true; } @@ -355,10 +332,9 @@ abitset_copy1 (bitset dst, bitset src) { bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); - bitset_windex size = dst->b.csize; - if (srcp == dstp) - return; + return; + bitset_windex size = dst->b.csize; memcpy (dstp, srcp, sizeof (bitset_word) * size); } @@ -366,13 +342,12 @@ abitset_copy1 (bitset dst, bitset src) static void abitset_not (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = ~(*srcp++); + for (bitset_windex i = 0; i < size; i++) + *dstp++ = ~(*srcp++); abitset_unused_clear (dst); } @@ -380,14 +355,13 @@ abitset_not (bitset dst, bitset src) static bool abitset_equal_p (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - if (*srcp++ != *dstp++) - return false; + for (bitset_windex i = 0; i < size; i++) + if (*srcp++ != *dstp++) + return false; return true; } @@ -395,14 +369,13 @@ abitset_equal_p (bitset dst, bitset src) static bool abitset_subset_p (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++, srcp++) - if (*dstp != (*srcp | *dstp)) - return false; + for (bitset_windex i = 0; i < size; i++, dstp++, srcp++) + if (*dstp != (*srcp | *dstp)) + return false; return true; } @@ -410,15 +383,13 @@ abitset_subset_p (bitset dst, bitset src) static bool abitset_disjoint_p (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - if (*srcp++ & *dstp++) - return false; - + for (bitset_windex i = 0; i < size; i++) + if (*srcp++ & *dstp++) + return false; return true; } @@ -426,31 +397,28 @@ abitset_disjoint_p (bitset dst, bitset src) static void abitset_and (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ & *src2p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ & *src2p++; } static bool abitset_and_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ & *src2p++; - if (*dstp != tmp) { changed = true; @@ -464,31 +432,28 @@ abitset_and_cmp (bitset dst, bitset src1, bitset src2) static void abitset_andn (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ & ~(*src2p++); + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ & ~(*src2p++); } static bool abitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ & ~(*src2p++); - if (*dstp != tmp) { changed = true; @@ -502,28 +467,26 @@ abitset_andn_cmp (bitset dst, bitset src1, bitset src2) static void abitset_or (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ | *src2p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ | *src2p++; } static bool abitset_or_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ | *src2p++; @@ -540,28 +503,26 @@ abitset_or_cmp (bitset dst, bitset src1, bitset src2) static void abitset_xor (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ ^ *src2p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ ^ *src2p++; } static bool abitset_xor_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ ^ *src2p++; @@ -578,22 +539,20 @@ abitset_xor_cmp (bitset dst, bitset src1, bitset src2) static void abitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & *src2p++) | *src3p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = (*src1p++ & *src2p++) | *src3p++; } static bool abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); @@ -601,10 +560,9 @@ abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & *src2p++) | *src3p++; - if (*dstp != tmp) { changed = true; @@ -618,22 +576,20 @@ abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void abitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; } static bool abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); @@ -641,10 +597,9 @@ abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++; - if (*dstp != tmp) { changed = true; @@ -658,22 +613,20 @@ abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void abitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ | *src2p++) & *src3p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = (*src1p++ | *src2p++) & *src3p++; } static bool abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); @@ -681,10 +634,9 @@ abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ | *src2p++) & *src3p++; - if (*dstp != tmp) { changed = true; @@ -699,9 +651,9 @@ static void abitset_copy (bitset dst, bitset src) { if (BITSET_COMPATIBLE_ (dst, src)) - abitset_copy1 (dst, src); + abitset_copy1 (dst, src); else - bitset_copy_ (dst, src); + bitset_copy_ (dst, src); } @@ -784,14 +736,12 @@ struct bitset_vtable abitset_vtable = { size_t abitset_bytes (bitset_bindex n_bits) { - bitset_windex size; - size_t bytes; size_t header_size = offsetof (union bitset_union, a.words); struct bitset_align_struct { char a; union bitset_union b; }; size_t bitset_alignment = offsetof (struct bitset_align_struct, b); - size = ABITSET_N_WORDS (n_bits); - bytes = header_size + size * sizeof (bitset_word); + bitset_windex size = ABITSET_N_WORDS (n_bits); + size_t bytes = header_size + size * sizeof (bitset_word); /* Align the size properly for a vector of abitset objects. */ if (header_size % bitset_alignment != 0 @@ -808,19 +758,13 @@ abitset_bytes (bitset_bindex n_bits) bitset abitset_init (bitset bset, bitset_bindex n_bits) { - bitset_windex size; - - size = ABITSET_N_WORDS (n_bits); + bitset_windex size = ABITSET_N_WORDS (n_bits); BITSET_NBITS_ (bset) = n_bits; /* Use optimized routines if bitset fits within a single word. There is probably little merit if using caching since the small bitset will always fit in the cache. */ - if (size == 1) - bset->b.vtable = &abitset_small_vtable; - else - bset->b.vtable = &abitset_vtable; - + bset->b.vtable = size == 1 ? &abitset_small_vtable : &abitset_vtable; bset->b.cindex = 0; bset->b.csize = size; bset->b.cdata = ABITSET_WORDS (bset); diff --git a/contrib/tools/bison/lib/abitset.h b/contrib/tools/bison/lib/abitset.h index 65d4842751c..821eed9d96c 100644 --- a/contrib/tools/bison/lib/abitset.h +++ b/contrib/tools/bison/lib/abitset.h @@ -23,8 +23,8 @@ #include "bitset.h" -extern size_t abitset_bytes (bitset_bindex); +size_t abitset_bytes (bitset_bindex); -extern bitset abitset_init (bitset, bitset_bindex); +bitset abitset_init (bitset, bitset_bindex); #endif diff --git a/contrib/tools/bison/lib/arg-nonnull.h b/contrib/tools/bison/lib/arg-nonnull.h new file mode 100644 index 00000000000..5f034083129 --- /dev/null +++ b/contrib/tools/bison/lib/arg-nonnull.h @@ -0,0 +1,26 @@ +/* A C macro for declaring that specific arguments must not be NULL. + Copyright (C) 2009-2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools + that the values passed as arguments n, ..., m must be non-NULL pointers. + n = 1 stands for the first argument, n = 2 for the second argument etc. */ +#ifndef _GL_ARG_NONNULL +# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 +# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) +# else +# define _GL_ARG_NONNULL(params) +# endif +#endif diff --git a/contrib/tools/bison/lib/bbitset.h b/contrib/tools/bison/lib/bbitset.h index d0e7c17c267..29502a5b1d6 100644 --- a/contrib/tools/bison/lib/bbitset.h +++ b/contrib/tools/bison/lib/bbitset.h @@ -21,12 +21,20 @@ #ifndef _BBITSET_H #define _BBITSET_H -#include "libiberty.h" - -#include <stdbool.h> #include <limits.h> +#include <stdbool.h> #include <stddef.h> +#include "xalloc.h" + +#ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) +# define __attribute__(x) +# endif +#endif + +#define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) + /* Currently we support five flavours of bitsets: BITSET_ARRAY: Array of bits (fixed size, fast for dense bitsets). Memory for bit array and bitset structure allocated @@ -281,24 +289,24 @@ if (!BITSET_COMPATIBLE_ (DST, SRC1) || !BITSET_COMPATIBLE_ (DST, SRC2) \ /* Private functions for bitset implementations. */ -extern bool bitset_toggle_ (bitset, bitset_bindex); +bool bitset_toggle_ (bitset, bitset_bindex); -extern bitset_bindex bitset_count_ (bitset); +bitset_bindex bitset_count_ (bitset); -extern bitset_bindex bitset_size_ (bitset); +bitset_bindex bitset_size_ (bitset); -extern bool bitset_copy_ (bitset, bitset); +bool bitset_copy_ (bitset, bitset); -extern void bitset_and_or_ (bitset, bitset, bitset, bitset); +void bitset_and_or_ (bitset, bitset, bitset, bitset); -extern bool bitset_and_or_cmp_ (bitset, bitset, bitset, bitset); +bool bitset_and_or_cmp_ (bitset, bitset, bitset, bitset); -extern void bitset_andn_or_ (bitset, bitset, bitset, bitset); +void bitset_andn_or_ (bitset, bitset, bitset, bitset); -extern bool bitset_andn_or_cmp_ (bitset, bitset, bitset, bitset); +bool bitset_andn_or_cmp_ (bitset, bitset, bitset, bitset); -extern void bitset_or_and_ (bitset, bitset, bitset, bitset); +void bitset_or_and_ (bitset, bitset, bitset, bitset); -extern bool bitset_or_and_cmp_ (bitset, bitset, bitset, bitset); +bool bitset_or_and_cmp_ (bitset, bitset, bitset, bitset); #endif /* _BBITSET_H */ diff --git a/contrib/tools/bison/lib/bitset.c b/contrib/tools/bison/lib/bitset.c index 97a60ef4e3c..325213777b9 100644 --- a/contrib/tools/bison/lib/bitset.c +++ b/contrib/tools/bison/lib/bitset.c @@ -24,12 +24,14 @@ #include <stdlib.h> #include <string.h> + +#include "obstack.h" + #include "abitset.h" #include "lbitset.h" #include "ebitset.h" #include "vbitset.h" #include "bitset_stats.h" -#include "obstack.h" const char * const bitset_type_names[] = BITSET_TYPE_NAMES; @@ -39,8 +41,6 @@ const char * const bitset_type_names[] = BITSET_TYPE_NAMES; size_t bitset_bytes (enum bitset_type type, bitset_bindex n_bits) { - size_t bytes; - if (bitset_stats_enabled) return bitset_stats_bytes (); @@ -50,23 +50,17 @@ bitset_bytes (enum bitset_type type, bitset_bindex n_bits) abort (); case BITSET_ARRAY: - bytes = abitset_bytes (n_bits); - break; + return abitset_bytes (n_bits); case BITSET_LIST: - bytes = lbitset_bytes (n_bits); - break; + return lbitset_bytes (n_bits); case BITSET_TABLE: - bytes = ebitset_bytes (n_bits); - break; + return ebitset_bytes (n_bits); case BITSET_VARRAY: - bytes = vbitset_bytes (n_bits); - break; + return vbitset_bytes (n_bits); } - - return bytes; } @@ -134,12 +128,9 @@ bitset_type_choose (bitset_bindex n_bits ATTRIBUTE_UNUSED, unsigned attr) bitset bitset_alloc (bitset_bindex n_bits, enum bitset_type type) { - size_t bytes; - bitset bset; - - bytes = bitset_bytes (type, n_bits); + size_t bytes = bitset_bytes (type, n_bits); - bset = xcalloc (1, bytes); + bitset bset = xcalloc (1, bytes); /* The cache is disabled until some elements are allocated. If we have variable length arrays, then we may need to allocate a dummy @@ -154,12 +145,9 @@ bitset bitset_obstack_alloc (struct obstack *bobstack, bitset_bindex n_bits, enum bitset_type type) { - size_t bytes; - bitset bset; + size_t bytes = bitset_bytes (type, n_bits); - bytes = bitset_bytes (type, n_bits); - - bset = obstack_alloc (bobstack, bytes); + bitset bset = obstack_alloc (bobstack, bytes); memset (bset, 0, bytes); return bitset_init (bset, n_bits, type); @@ -171,9 +159,7 @@ bitset_obstack_alloc (struct obstack *bobstack, bitset bitset_create (bitset_bindex n_bits, unsigned attr) { - enum bitset_type type; - - type = bitset_type_choose (n_bits, attr); + enum bitset_type type = bitset_type_choose (n_bits, attr); return bitset_alloc (n_bits, type); } @@ -200,11 +186,9 @@ bitset_obstack_free (bitset bset) enum bitset_type bitset_type_get (bitset bset) { - enum bitset_type type; - - type = BITSET_TYPE_ (bset); + enum bitset_type type = BITSET_TYPE_ (bset); if (type != BITSET_STATS) - return type; + return type; return bitset_stats_type_get (bset); } @@ -214,9 +198,7 @@ bitset_type_get (bitset bset) const char * bitset_type_name_get (bitset bset) { - enum bitset_type type; - - type = bitset_type_get (bset); + enum bitset_type type = bitset_type_get (bset); return bitset_type_names[type]; } @@ -227,9 +209,8 @@ bitset_type_name_get (bitset bset) bitset_bindex bitset_next (bitset src, bitset_bindex bitno) { - bitset_bindex val; bitset_bindex next = bitno; - + bitset_bindex val; if (!bitset_list (src, &val, 1, &next)) return BITSET_BINDEX_MAX; return val; @@ -240,7 +221,7 @@ bitset_next (bitset src, bitset_bindex bitno) extern bool bitset_compatible_p (bitset bset1, bitset bset2) { - return BITSET_COMPATIBLE_ (bset1, bset2); + return BITSET_COMPATIBLE_ (bset1, bset2); } @@ -249,9 +230,8 @@ bitset_compatible_p (bitset bset1, bitset bset2) bitset_bindex bitset_prev (bitset src, bitset_bindex bitno) { - bitset_bindex val; bitset_bindex next = bitno; - + bitset_bindex val; if (!bitset_list_reverse (src, &val, 1, &next)) return BITSET_BINDEX_MAX; return val; @@ -291,15 +271,13 @@ bitset_only_set_p (bitset src, bitset_bindex bitno) static void bitset_print (FILE *file, bitset bset, bool verbose) { - unsigned pos; - bitset_bindex i; - bitset_iterator iter; - if (verbose) fprintf (file, "n_bits = %lu, set = {", (unsigned long) bitset_size (bset)); - pos = 30; + unsigned pos = 30; + bitset_bindex i; + bitset_iterator iter; BITSET_FOR_EACH (iter, bset, i, 0) { if (pos > 70) @@ -310,7 +288,7 @@ bitset_print (FILE *file, bitset bset, bool verbose) fprintf (file, "%lu ", (unsigned long) i); pos += 1 + (i >= 10) + (i >= 100); - }; + } if (verbose) fprintf (file, "}\n"); @@ -357,7 +335,7 @@ bitset_toggle_ (bitset bset, bitset_bindex bitno) bitset_bindex bitset_size_ (bitset src) { - return BITSET_NBITS_ (src); + return BITSET_NBITS_ (src); } @@ -366,18 +344,18 @@ bitset_bindex bitset_count_ (bitset src) { bitset_bindex list[BITSET_LIST_SIZE]; - bitset_bindex next; - bitset_bindex num; - bitset_bindex count; + bitset_bindex count = 0; /* This could be greatly sped up by adding a count method for each bitset implementation that uses a direct technique (based on masks) for counting the number of bits set in a word. */ - next = 0; - for (count = 0; (num = bitset_list (src, list, BITSET_LIST_SIZE, &next)); - count += num) - continue; + { + bitset_bindex next = 0; + bitset_bindex num; + while ((num = bitset_list (src, list, BITSET_LIST_SIZE, &next))) + count += num; + } return count; } @@ -398,7 +376,7 @@ bitset_copy_ (bitset dst, bitset src) BITSET_FOR_EACH (iter, src, i, 0) { bitset_set (dst, i); - }; + } return true; } @@ -411,13 +389,11 @@ bitset_op4_cmp (bitset dst, bitset src1, bitset src2, bitset src3, enum bitset_ops op) { bool changed = false; - bool stats_enabled_save; - bitset tmp; /* Create temporary bitset. */ - stats_enabled_save = bitset_stats_enabled; + bool stats_enabled_save = bitset_stats_enabled; bitset_stats_enabled = false; - tmp = bitset_alloc (0, bitset_type_get (dst)); + bitset tmp = bitset_alloc (0, bitset_type_get (dst)); bitset_stats_enabled = stats_enabled_save; switch (op) diff --git a/contrib/tools/bison/lib/bitset.h b/contrib/tools/bison/lib/bitset.h index 48bd2300b97..f7b2cd0bfa0 100644 --- a/contrib/tools/bison/lib/bitset.h +++ b/contrib/tools/bison/lib/bitset.h @@ -24,14 +24,14 @@ /* This file is the public interface to the bitset abstract data type. Only use the functions and macros defined in this file. */ -#include "bbitset.h" -#include "obstack.h" #include <stdio.h> - #if USE_UNLOCKED_IO # include "unlocked-io.h" #endif +#include "bbitset.h" +#include "obstack.h" + /* Attributes used to select a bitset implementation. */ enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */ BITSET_VARIABLE = 2, /* Bitset size variable. */ @@ -83,7 +83,6 @@ union bitset_union struct bbitset_struct b; bitset_windex size; /* Allocated size of array. */ } v; - }; @@ -99,37 +98,37 @@ typedef struct /* Return bytes required for bitset of desired type and size. */ -extern size_t bitset_bytes (enum bitset_type, bitset_bindex); +size_t bitset_bytes (enum bitset_type, bitset_bindex); /* Initialise a bitset with desired type and size. */ -extern bitset bitset_init (bitset, bitset_bindex, enum bitset_type); +bitset bitset_init (bitset, bitset_bindex, enum bitset_type); /* Select an implementation type based on the desired bitset size and attributes. */ -extern enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs); +enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs); /* Create a bitset of desired type and size. The bitset is zeroed. */ -extern bitset bitset_alloc (bitset_bindex, enum bitset_type); +bitset bitset_alloc (bitset_bindex, enum bitset_type); /* Free bitset. */ -extern void bitset_free (bitset); +void bitset_free (bitset); /* Create a bitset of desired type and size using an obstack. The bitset is zeroed. */ -extern bitset bitset_obstack_alloc (struct obstack *bobstack, - bitset_bindex, enum bitset_type); +bitset bitset_obstack_alloc (struct obstack *bobstack, + bitset_bindex, enum bitset_type); /* Free bitset allocated on obstack. */ -extern void bitset_obstack_free (bitset); +void bitset_obstack_free (bitset); /* Create a bitset of desired size and attributes. The bitset is zeroed. */ -extern bitset bitset_create (bitset_bindex, bitset_attrs); +bitset bitset_create (bitset_bindex, bitset_attrs); /* Return bitset type. */ -extern enum bitset_type bitset_type_get (bitset); +enum bitset_type bitset_type_get (bitset); /* Return bitset type name. */ -extern const char *bitset_type_name_get (bitset); +const char *bitset_type_name_get (bitset); /* Set bit BITNO in bitset BSET. */ @@ -181,7 +180,7 @@ bitset_test (bitset bset, bitset_bindex bitno) #define bitset_size(SRC) BITSET_SIZE_ (SRC) /* Change size of bitset. */ -extern void bitset_resize (bitset, bitset_bindex); +void bitset_resize (bitset, bitset_bindex); /* Return number of bits set in bitset SRC. */ #define bitset_count(SRC) BITSET_COUNT_ (SRC) @@ -281,25 +280,25 @@ extern void bitset_resize (bitset, bitset_bindex); BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT) /* Return true if both bitsets are of the same type and size. */ -extern bool bitset_compatible_p (bitset bset1, bitset bset2); +bool bitset_compatible_p (bitset bset1, bitset bset2); /* Find next set bit from the given bit index. */ -extern bitset_bindex bitset_next (bitset, bitset_bindex); +bitset_bindex bitset_next (bitset, bitset_bindex); /* Find previous set bit from the given bit index. */ -extern bitset_bindex bitset_prev (bitset, bitset_bindex); +bitset_bindex bitset_prev (bitset, bitset_bindex); /* Find first set bit. */ -extern bitset_bindex bitset_first (bitset); +bitset_bindex bitset_first (bitset); /* Find last set bit. */ -extern bitset_bindex bitset_last (bitset); +bitset_bindex bitset_last (bitset); /* Return nonzero if this is the only set bit. */ -extern bool bitset_only_set_p (bitset, bitset_bindex); +bool bitset_only_set_p (bitset, bitset_bindex); /* Dump bitset. */ -extern void bitset_dump (FILE *, bitset); +void bitset_dump (FILE *, bitset); /* Loop over all elements of BSET, starting with MIN, setting INDEX to the index of each set bit. For example, the following will print @@ -309,9 +308,7 @@ extern void bitset_dump (FILE *, bitset); bitset_iterator iter; BITSET_FOR_EACH (iter, src, i, 0) - { - printf ("%lu ", (unsigned long) i); - }; + printf ("%lu ", (unsigned long) i); */ #define BITSET_FOR_EACH(ITER, BSET, INDEX, MIN) \ for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \ @@ -331,9 +328,7 @@ extern void bitset_dump (FILE *, bitset); bitset_iterator iter; BITSET_FOR_EACH_REVERSE (iter, src, i, 0) - { - printf ("%lu ", (unsigned long) i); - }; + printf ("%lu ", (unsigned long) i); */ #define BITSET_FOR_EACH_REVERSE(ITER, BSET, INDEX, MIN) \ for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \ @@ -368,13 +363,13 @@ extern void bitset_dump (FILE *, bitset); /* Release any memory tied up with bitsets. */ -extern void bitset_release_memory (void); +void bitset_release_memory (void); /* Enable bitset stats gathering. */ -extern void bitset_stats_enable (void); +void bitset_stats_enable (void); /* Disable bitset stats gathering. */ -extern void bitset_stats_disable (void); +void bitset_stats_disable (void); /* Read bitset stats file of accummulated stats. */ void bitset_stats_read (const char *file_name); @@ -383,12 +378,12 @@ void bitset_stats_read (const char *file_name); void bitset_stats_write (const char *file_name); /* Dump bitset stats. */ -extern void bitset_stats_dump (FILE *); +void bitset_stats_dump (FILE *); /* Function to debug bitset from debugger. */ -extern void debug_bitset (bitset); +void debug_bitset (bitset); /* Function to debug bitset stats from debugger. */ -extern void debug_bitset_stats (void); +void debug_bitset_stats (void); #endif /* _BITSET_H */ diff --git a/contrib/tools/bison/lib/bitset_stats.c b/contrib/tools/bison/lib/bitset_stats.c index dc8aae50d72..d0967348e7a 100644 --- a/contrib/tools/bison/lib/bitset_stats.c +++ b/contrib/tools/bison/lib/bitset_stats.c @@ -29,18 +29,19 @@ #include "bitset_stats.h" -#include "bbitset.h" -#include "abitset.h" -#include "ebitset.h" -#include "lbitset.h" -#include "vbitset.h" +#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdio.h> #include "gettext.h" #define _(Msgid) gettext (Msgid) +#include "abitset.h" +#include "bbitset.h" +#include "ebitset.h" +#include "lbitset.h" +#include "vbitset.h" + /* Configuration macros. */ #define BITSET_STATS_FILE "bitset.dat" #define BITSET_LOG_COUNT_BINS 10 @@ -108,18 +109,15 @@ static void bitset_percent_histogram_print (FILE *file, const char *name, const char *msg, unsigned n_bins, unsigned *bins) { - unsigned i; - unsigned total; - - total = 0; - for (i = 0; i < n_bins; i++) + unsigned total = 0; + for (unsigned i = 0; i < n_bins; i++) total += bins[i]; if (!total) return; fprintf (file, "%s %s", name, msg); - for (i = 0; i < n_bins; i++) + for (unsigned i = 0; i < n_bins; i++) fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n", i * 100.0 / n_bins, (i + 1) * 100.0 / n_bins, bins[i], @@ -132,37 +130,39 @@ static void bitset_log_histogram_print (FILE *file, const char *name, const char *msg, unsigned n_bins, unsigned *bins) { - unsigned i; - unsigned total; - unsigned max_width; - - total = 0; - for (i = 0; i < n_bins; i++) + unsigned total = 0; + for (unsigned i = 0; i < n_bins; i++) total += bins[i]; if (!total) return; /* Determine number of useful bins. */ - for (i = n_bins; i > 3 && ! bins[i - 1]; i--) - continue; - n_bins = i; + { + unsigned i; + for (i = n_bins; i > 3 && ! bins[i - 1]; i--) + continue; + n_bins = i; + } /* 2 * ceil (log10 (2) * (N - 1)) + 1. */ - max_width = 2 * (unsigned) (0.30103 * (n_bins - 1) + 0.9999) + 1; + unsigned max_width = 2 * (unsigned) (0.30103 * (n_bins - 1) + 0.9999) + 1; fprintf (file, "%s %s", name, msg); - for (i = 0; i < 2; i++) - fprintf (file, "%*d\t%8u (%5.1f%%)\n", - max_width, i, bins[i], 100.0 * bins[i] / total); - - for (; i < n_bins; i++) - fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n", - max_width - ((unsigned) (0.30103 * (i) + 0.9999) + 1), - 1UL << (i - 1), - (1UL << i) - 1, - bins[i], - (100.0 * bins[i]) / total); + { + unsigned i; + for (i = 0; i < 2; i++) + fprintf (file, "%*d\t%8u (%5.1f%%)\n", + max_width, i, bins[i], 100.0 * bins[i] / total); + + for (; i < n_bins; i++) + fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n", + max_width - ((unsigned) (0.30103 * (i) + 0.9999) + 1), + 1UL << (i - 1), + (1UL << i) - 1, + bins[i], + (100.0 * bins[i]) / total); + } } @@ -205,8 +205,6 @@ bitset_stats_print_1 (FILE *file, const char *name, static void bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED) { - int i; - if (!bitset_stats_info) return; @@ -215,7 +213,7 @@ bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED) if (bitset_stats_info->runs > 1) fprintf (file, _("Accumulated runs = %u\n"), bitset_stats_info->runs); - for (i = 0; i < BITSET_TYPE_NUM; i++) + for (int i = 0; i < BITSET_TYPE_NUM; i++) bitset_stats_print_1 (file, bitset_type_names[i], &bitset_stats_info->types[i]); } @@ -242,15 +240,13 @@ bitset_stats_disable (void) void bitset_stats_read (const char *file_name) { - FILE *file; - if (!bitset_stats_info) return; if (!file_name) file_name = BITSET_STATS_FILE; - file = fopen (file_name, "r"); + FILE *file = fopen (file_name, "r"); if (file) { if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data), @@ -272,15 +268,13 @@ bitset_stats_read (const char *file_name) void bitset_stats_write (const char *file_name) { - FILE *file; - if (!bitset_stats_info) return; if (!file_name) file_name = BITSET_STATS_FILE; - file = fopen (file_name, "w"); + FILE *file = fopen (file_name, "w"); if (file) { if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data), @@ -352,7 +346,7 @@ bitset_stats_reset (bitset dst, bitset_bindex bitno) static bool bitset_stats_toggle (bitset src, bitset_bindex bitno) { - return BITSET_TOGGLE_ (src->s.bset, bitno); + return BITSET_TOGGLE_ (src->s.bset, bitno); } @@ -378,7 +372,7 @@ bitset_stats_test (bitset src, bitset_bindex bitno) static bitset_bindex bitset_stats_resize (bitset src, bitset_bindex size) { - return BITSET_RESIZE_ (src->s.bset, size); + return BITSET_RESIZE_ (src->s.bset, size); } @@ -573,35 +567,40 @@ static bitset_bindex bitset_stats_list (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex count; - bitset_bindex tmp; - bitset_bindex size; - bitset_bindex i; - - count = BITSET_LIST_ (bset->s.bset, list, num, next); + bitset_bindex count = BITSET_LIST_ (bset->s.bset, list, num, next); BITSET_STATS_LISTS_INC (bset->s.bset); /* Log histogram of number of set bits. */ - for (i = 0, tmp = count; tmp; tmp >>= 1, i++) - continue; - if (i >= BITSET_LOG_COUNT_BINS) - i = BITSET_LOG_COUNT_BINS - 1; - BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i); + { + bitset_bindex i; + bitset_bindex tmp; + for (i = 0, tmp = count; tmp; tmp >>= 1, i++) + continue; + if (i >= BITSET_LOG_COUNT_BINS) + i = BITSET_LOG_COUNT_BINS - 1; + BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i); + } /* Log histogram of number of bits in set. */ - size = BITSET_SIZE_ (bset->s.bset); - for (i = 0, tmp = size; tmp; tmp >>= 1, i++) - continue; - if (i >= BITSET_LOG_SIZE_BINS) - i = BITSET_LOG_SIZE_BINS - 1; - BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i); + bitset_bindex size = BITSET_SIZE_ (bset->s.bset); + { + bitset_bindex i; + bitset_bindex tmp; + for (i = 0, tmp = size; tmp; tmp >>= 1, i++) + continue; + if (i >= BITSET_LOG_SIZE_BINS) + i = BITSET_LOG_SIZE_BINS - 1; + BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i); + } /* Histogram of fraction of bits set. */ - i = size ? (count * BITSET_DENSITY_BINS) / size : 0; - if (i >= BITSET_DENSITY_BINS) - i = BITSET_DENSITY_BINS - 1; - BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i); + { + bitset_bindex i = size ? (count * BITSET_DENSITY_BINS) / size : 0; + if (i >= BITSET_DENSITY_BINS) + i = BITSET_DENSITY_BINS - 1; + BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i); + } return count; } @@ -663,7 +662,7 @@ struct bitset_vtable bitset_stats_vtable = { enum bitset_type bitset_stats_type_get (bitset bset) { - return BITSET_TYPE_ (bset->s.bset); + return BITSET_TYPE_ (bset->s.bset); } @@ -677,9 +676,6 @@ bitset_stats_bytes (void) bitset bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) { - size_t bytes; - bitset sbset; - bset->b.vtable = &bitset_stats_vtable; /* Disable cache. */ @@ -697,32 +693,38 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) abort (); case BITSET_ARRAY: - bytes = abitset_bytes (n_bits); - sbset = xcalloc (1, bytes); - abitset_init (sbset, n_bits); + { + size_t bytes = abitset_bytes (n_bits); + bset->s.bset = xcalloc (1, bytes); + abitset_init (bset->s.bset, n_bits); + } break; case BITSET_LIST: - bytes = lbitset_bytes (n_bits); - sbset = xcalloc (1, bytes); - lbitset_init (sbset, n_bits); + { + size_t bytes = lbitset_bytes (n_bits); + bset->s.bset = xcalloc (1, bytes); + lbitset_init (bset->s.bset, n_bits); + } break; case BITSET_TABLE: - bytes = ebitset_bytes (n_bits); - sbset = xcalloc (1, bytes); - ebitset_init (sbset, n_bits); + { + size_t bytes = ebitset_bytes (n_bits); + bset->s.bset = xcalloc (1, bytes); + ebitset_init (bset->s.bset, n_bits); + } break; case BITSET_VARRAY: - bytes = vbitset_bytes (n_bits); - sbset = xcalloc (1, bytes); - vbitset_init (sbset, n_bits); + { + size_t bytes = vbitset_bytes (n_bits); + bset->s.bset = xcalloc (1, bytes); + vbitset_init (bset->s.bset, n_bits); + } break; } - bset->s.bset = sbset; - BITSET_STATS_ALLOCS_INC (type); return bset; diff --git a/contrib/tools/bison/lib/bitset_stats.h b/contrib/tools/bison/lib/bitset_stats.h index f1e213f9844..3a12ab36801 100644 --- a/contrib/tools/bison/lib/bitset_stats.h +++ b/contrib/tools/bison/lib/bitset_stats.h @@ -25,10 +25,10 @@ extern bool bitset_stats_enabled; -extern enum bitset_type bitset_stats_type_get (bitset); +enum bitset_type bitset_stats_type_get (bitset); -extern size_t bitset_stats_bytes (void); +size_t bitset_stats_bytes (void); -extern bitset bitset_stats_init (bitset, bitset_bindex, enum bitset_type); +bitset bitset_stats_init (bitset, bitset_bindex, enum bitset_type); #endif diff --git a/contrib/tools/bison/lib/bitsetv-print.c b/contrib/tools/bison/lib/bitsetv-print.c index 798a81acc38..d229c7d6137 100644 --- a/contrib/tools/bison/lib/bitsetv-print.c +++ b/contrib/tools/bison/lib/bitsetv-print.c @@ -29,7 +29,6 @@ void bitsetv_matrix_dump (FILE * out, const char *title, bitsetv bset) { - bitset_bindex i, j; bitset_bindex hsize = bitset_size (bset[0]); /* Title. */ @@ -37,32 +36,32 @@ bitsetv_matrix_dump (FILE * out, const char *title, bitsetv bset) /* Column numbers. */ fputs (" ", out); - for (i = 0; i < hsize; ++i) + for (bitset_bindex i = 0; i < hsize; ++i) putc (i / 10 ? '0' + i / 10 : ' ', out); putc ('\n', out); fputs (" ", out); - for (i = 0; i < hsize; ++i) + for (bitset_bindex i = 0; i < hsize; ++i) fprintf (out, "%d", (int) (i % 10)); putc ('\n', out); /* Bar. */ fputs (" .", out); - for (i = 0; i < hsize; ++i) + for (bitset_bindex i = 0; i < hsize; ++i) putc ('-', out); fputs (".\n", out); /* Contents. */ - for (i = 0; bset[i]; ++i) + for (bitset_bindex i = 0; bset[i]; ++i) { fprintf (out, "%2lu|", (unsigned long) i); - for (j = 0; j < hsize; ++j) + for (bitset_bindex j = 0; j < hsize; ++j) fputs (bitset_test (bset[i], j) ? "1" : " ", out); fputs ("|\n", out); } /* Bar. */ fputs (" `", out); - for (i = 0; i < hsize; ++i) + for (bitset_bindex i = 0; i < hsize; ++i) putc ('-', out); fputs ("'\n", out); diff --git a/contrib/tools/bison/lib/bitsetv-print.h b/contrib/tools/bison/lib/bitsetv-print.h index f1ba11829a7..b706b04a8d3 100644 --- a/contrib/tools/bison/lib/bitsetv-print.h +++ b/contrib/tools/bison/lib/bitsetv-print.h @@ -24,6 +24,6 @@ #include "bitsetv.h" /* Dump vector of bitsets as a matrix. */ -extern void bitsetv_matrix_dump (FILE *, const char *, bitsetv); +void bitsetv_matrix_dump (FILE *, const char *, bitsetv); #endif /* _BITSETV_H */ diff --git a/contrib/tools/bison/lib/bitsetv.c b/contrib/tools/bison/lib/bitsetv.c index 1d3213bf389..7077795d6df 100644 --- a/contrib/tools/bison/lib/bitsetv.c +++ b/contrib/tools/bison/lib/bitsetv.c @@ -29,23 +29,19 @@ bitset * bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits, enum bitset_type type) { - size_t vector_bytes; - size_t bytes; - bitset *bsetv; - bitset_bindex i; - /* Determine number of bytes for each set. */ - bytes = bitset_bytes (type, n_bits); + size_t bytes = bitset_bytes (type, n_bits); /* If size calculation overflows, memory is exhausted. */ if (BITSET_SIZE_MAX / (sizeof (bitset) + bytes) <= n_vecs) xalloc_die (); /* Allocate vector table at head of bitset array. */ - vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1; + size_t vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1; vector_bytes -= vector_bytes % bytes; - bsetv = xcalloc (1, vector_bytes + bytes * n_vecs); + bitset *bsetv = xcalloc (1, vector_bytes + bytes * n_vecs); + bitset_bindex i = 0; for (i = 0; i < n_vecs; i++) { bsetv[i] = (bitset) (void *) ((char *) bsetv + vector_bytes + i * bytes); @@ -64,9 +60,7 @@ bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits, bitset * bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, unsigned attr) { - enum bitset_type type; - - type = bitset_type_choose (n_bits, attr); + enum bitset_type type = bitset_type_choose (n_bits, attr); return bitsetv_alloc (n_vecs, n_bits, type); } @@ -75,10 +69,8 @@ bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, unsigned attr) void bitsetv_free (bitsetv bsetv) { - bitset_bindex i; - - for (i = 0; bsetv[i]; i++) - BITSET_FREE_ (bsetv[i]); + for (bitset_bindex i = 0; bsetv[i]; i++) + BITSET_FREE_ (bsetv[i]); free (bsetv); } @@ -87,9 +79,7 @@ bitsetv_free (bitsetv bsetv) void bitsetv_zero (bitsetv bsetv) { - bitset_bindex i; - - for (i = 0; bsetv[i]; i++) + for (bitset_bindex i = 0; bsetv[i]; i++) bitset_zero (bsetv[i]); } @@ -98,9 +88,7 @@ bitsetv_zero (bitsetv bsetv) void bitsetv_ones (bitsetv bsetv) { - bitset_bindex i; - - for (i = 0; bsetv[i]; i++) + for (bitset_bindex i = 0; bsetv[i]; i++) bitset_ones (bsetv[i]); } @@ -110,11 +98,8 @@ bitsetv_ones (bitsetv bsetv) void bitsetv_transitive_closure (bitsetv bsetv) { - bitset_bindex i; - bitset_bindex j; - - for (i = 0; bsetv[i]; i++) - for (j = 0; bsetv[j]; j++) + for (bitset_bindex i = 0; bsetv[i]; i++) + for (bitset_bindex j = 0; bsetv[j]; j++) if (bitset_test (bsetv[j], i)) bitset_or (bsetv[j], bsetv[j], bsetv[i]); } @@ -127,10 +112,8 @@ bitsetv_transitive_closure (bitsetv bsetv) void bitsetv_reflexive_transitive_closure (bitsetv bsetv) { - bitset_bindex i; - bitsetv_transitive_closure (bsetv); - for (i = 0; bsetv[i]; i++) + for (bitset_bindex i = 0; bsetv[i]; i++) bitset_set (bsetv[i], i); } @@ -141,10 +124,8 @@ void bitsetv_dump (FILE *file, char const *title, char const *subtitle, bitsetv bsetv) { - bitset_windex i; - fprintf (file, "%s\n", title); - for (i = 0; bsetv[i]; i++) + for (bitset_windex i = 0; bsetv[i]; i++) { fprintf (file, "%s %lu\n", subtitle, (unsigned long) i); bitset_dump (file, bsetv[i]); @@ -157,9 +138,7 @@ bitsetv_dump (FILE *file, char const *title, char const *subtitle, void debug_bitsetv (bitsetv bsetv) { - bitset_windex i; - - for (i = 0; bsetv[i]; i++) + for (bitset_windex i = 0; bsetv[i]; i++) { fprintf (stderr, "%lu: ", (unsigned long) i); debug_bitset (bsetv[i]); diff --git a/contrib/tools/bison/lib/bitsetv.h b/contrib/tools/bison/lib/bitsetv.h index 56e0de7dca3..60777a21e03 100644 --- a/contrib/tools/bison/lib/bitsetv.h +++ b/contrib/tools/bison/lib/bitsetv.h @@ -27,35 +27,35 @@ typedef bitset * bitsetv; /* Create a vector of N_VECS bitsets, each of N_BITS, and of type TYPE. */ -extern bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type); +bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type); /* Create a vector of N_VECS bitsets, each of N_BITS, and with attribute hints specified by ATTR. */ -extern bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned); +bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned); /* Free vector of bitsets. */ -extern void bitsetv_free (bitsetv); +void bitsetv_free (bitsetv); /* Zero vector of bitsets. */ -extern void bitsetv_zero (bitsetv); +void bitsetv_zero (bitsetv); /* Set vector of bitsets. */ -extern void bitsetv_ones (bitsetv); +void bitsetv_ones (bitsetv); /* Given a vector BSETV of N bitsets of size N, modify its contents to be the transitive closure of what was given. */ -extern void bitsetv_transitive_closure (bitsetv); +void bitsetv_transitive_closure (bitsetv); /* Given a vector BSETV of N bitsets of size N, modify its contents to be the reflexive transitive closure of what was given. This is the same as transitive closure but with all bits on the diagonal of the bit matrix set. */ -extern void bitsetv_reflexive_transitive_closure (bitsetv); +void bitsetv_reflexive_transitive_closure (bitsetv); /* Dump vector of bitsets. */ -extern void bitsetv_dump (FILE *, const char *, const char *, bitsetv); +void bitsetv_dump (FILE *, const char *, const char *, bitsetv); /* Function to debug vector of bitsets from debugger. */ -extern void debug_bitsetv (bitsetv); +void debug_bitsetv (bitsetv); #endif /* _BITSETV_H */ diff --git a/contrib/tools/bison/lib/config-linux.h b/contrib/tools/bison/lib/config-linux.h index 5322cd67cf6..7c6759f4636 100644 --- a/contrib/tools/bison/lib/config-linux.h +++ b/contrib/tools/bison/lib/config-linux.h @@ -1,111 +1,6 @@ /* lib/config.h. Generated from config.in.h by configure. */ /* lib/config.in.h. Generated from configure.ac by autoheader. */ -/* CPU and C ABI indicator */ -#ifndef __i386__ -/* #undef __i386__ */ -#endif -#ifndef __x86_64_x32__ -/* #undef __x86_64_x32__ */ -#endif -#ifndef __alpha__ -/* #undef __alpha__ */ -#endif -#ifndef __arm__ -/* #undef __arm__ */ -#endif -#ifndef __armhf__ -/* #undef __armhf__ */ -#endif -#ifndef __arm64_ilp32__ -/* #undef __arm64_ilp32__ */ -#endif -#ifndef __arm64__ -/* #undef __arm64__ */ -#endif -#ifndef __hppa__ -/* #undef __hppa__ */ -#endif -#ifndef __hppa64__ -/* #undef __hppa64__ */ -#endif -#ifndef __ia64_ilp32__ -/* #undef __ia64_ilp32__ */ -#endif -#ifndef __ia64__ -/* #undef __ia64__ */ -#endif -#ifndef __m68k__ -/* #undef __m68k__ */ -#endif -#ifndef __mips__ -/* #undef __mips__ */ -#endif -#ifndef __mipsn32__ -/* #undef __mipsn32__ */ -#endif -#ifndef __mips64__ -/* #undef __mips64__ */ -#endif -#ifndef __powerpc__ -/* #undef __powerpc__ */ -#endif -#ifndef __powerpc64__ -/* #undef __powerpc64__ */ -#endif -#ifndef __powerpc64_elfv2__ -/* #undef __powerpc64_elfv2__ */ -#endif -#ifndef __riscv32__ -/* #undef __riscv32__ */ -#endif -#ifndef __riscv64__ -/* #undef __riscv64__ */ -#endif -#ifndef __riscv32_ilp32__ -/* #undef __riscv32_ilp32__ */ -#endif -#ifndef __riscv32_ilp32f__ -/* #undef __riscv32_ilp32f__ */ -#endif -#ifndef __riscv32_ilp32d__ -/* #undef __riscv32_ilp32d__ */ -#endif -#ifndef __riscv64_ilp32__ -/* #undef __riscv64_ilp32__ */ -#endif -#ifndef __riscv64_ilp32f__ -/* #undef __riscv64_ilp32f__ */ -#endif -#ifndef __riscv64_ilp32d__ -/* #undef __riscv64_ilp32d__ */ -#endif -#ifndef __riscv64_lp64__ -/* #undef __riscv64_lp64__ */ -#endif -#ifndef __riscv64_lp64f__ -/* #undef __riscv64_lp64f__ */ -#endif -#ifndef __riscv64_lp64d__ -/* #undef __riscv64_lp64d__ */ -#endif -#ifndef __s390__ -/* #undef __s390__ */ -#endif -#ifndef __s390x__ -/* #undef __s390x__ */ -#endif -#ifndef __sh__ -/* #undef __sh__ */ -#endif -#ifndef __sparc__ -/* #undef __sparc__ */ -#endif -#ifndef __sparc64__ -/* #undef __sparc64__ */ -#endif - - /* Define if building universal (internal helper macro) */ /* #undef AC_APPLE_UNIVERSAL_BUILD */ @@ -178,6 +73,13 @@ /* Define to 1 if fopen() fails to recognize a trailing slash. */ /* #undef FOPEN_TRAILING_SLASH_BUG */ +/* Define if gettimeofday clobbers the localtime buffer. */ +/* #undef GETTIMEOFDAY_CLOBBERS_LOCALTIME */ + +/* Define this to 'void' or 'struct timezone' to match the system's + declaration of the second argument to gettimeofday. */ +#define GETTIMEOFDAY_TIMEZONE void + /* Define to a C preprocessor expression that evaluates to 1 or 0, depending whether the gnulib module close-stream shall be considered present. */ #define GNULIB_CLOSE_STREAM 1 @@ -270,6 +172,12 @@ /* Define to 1 when the gnulib module getdtablesize should be tested. */ #define GNULIB_TEST_GETDTABLESIZE 1 +/* Define to 1 when the gnulib module getrusage should be tested. */ +#define GNULIB_TEST_GETRUSAGE 1 + +/* Define to 1 when the gnulib module gettimeofday should be tested. */ +#define GNULIB_TEST_GETTIMEOFDAY 1 + /* Define to 1 when the gnulib module isnan should be tested. */ #define GNULIB_TEST_ISNAN 1 @@ -434,6 +342,9 @@ */ #define HAVE_ALLOCA_H 1 +/* Define if you have an arithmetic hrtime_t type. */ +/* #undef HAVE_ARITHMETIC_HRTIME_T */ + /* Define to 1 if you have the <bp-sym.h> header file. */ /* #undef HAVE_BP_SYM_H */ @@ -447,12 +358,19 @@ CoreFoundation framework. */ /* #undef HAVE_CFLOCALECOPYCURRENT */ +/* Define to 1 if you have the Mac OS X function + CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */ +/* #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES */ + /* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework. */ /* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */ -/* Define to 1 if the system has the type `clock_t'. */ -#define HAVE_CLOCK_T 1 +/* Define to 1 if you have the `clock_gettime' function. */ +#define HAVE_CLOCK_GETTIME 1 + +/* Define to 1 if you have the `clock_settime' function. */ +#define HAVE_CLOCK_SETTIME 1 /* Define to 1 if you have the `confstr' function. */ /* #undef HAVE_CONFSTR */ @@ -484,10 +402,6 @@ you don't. */ #define HAVE_DECL_CLEARERR_UNLOCKED 1 -/* Define to 1 if you have the declaration of `clock', and to 0 if you don't. - */ -#define HAVE_DECL_CLOCK 0 - /* Define to 1 if you have the declaration of `copysign', and to 0 if you don't. */ /* #undef HAVE_DECL_COPYSIGN */ @@ -544,9 +458,9 @@ don't. */ #define HAVE_DECL_GETDTABLESIZE 1 -/* Define to 1 if you have the declaration of `getrusage', and to 0 if you +/* Define to 1 if you have the declaration of `gethrtime', and to 0 if you don't. */ -#define HAVE_DECL_GETRUSAGE 1 +#define HAVE_DECL_GETHRTIME 0 /* Define to 1 if you have the declaration of `mbrtowc', and to 0 if you don't. */ @@ -600,14 +514,6 @@ don't. */ #define HAVE_DECL_STRNLEN 1 -/* Define to 1 if you have the declaration of `sysconf', and to 0 if you - don't. */ -#define HAVE_DECL_SYSCONF 1 - -/* Define to 1 if you have the declaration of `times', and to 0 if you don't. - */ -#define HAVE_DECL_TIMES 1 - /* Define to 1 if you have the declaration of `towlower', and to 0 if you don't. */ /* #undef HAVE_DECL_TOWLOWER */ @@ -669,9 +575,15 @@ /* Define to 1 if you have the `getprogname' function. */ /* #undef HAVE_GETPROGNAME */ +/* Define to 1 if you have the `getrusage' function. */ +#define HAVE_GETRUSAGE 1 + /* Define if the GNU gettext() function is already present or preinstalled. */ /* #undef HAVE_GETTEXT */ +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + /* Define if you have the iconv() function and it works. */ /* #undef HAVE_ICONV */ @@ -750,6 +662,9 @@ /* Define to 1 if you have the <memory.h> header file. */ #define HAVE_MEMORY_H 1 +/* Define to 1 if you have the `microuptime' function. */ +/* #undef HAVE_MICROUPTIME */ + /* Define to 1 if <limits.h> defines the MIN and MAX macros. */ /* #undef HAVE_MINMAX_IN_LIMITS_H */ @@ -763,6 +678,9 @@ concept. */ /* #undef HAVE_MSVC_INVALID_PARAMETER_HANDLER */ +/* Define to 1 if you have the `nanouptime' function. */ +/* #undef HAVE_NANOUPTIME */ + /* Define to 1 if you have the `nl_langinfo' function. */ /* #undef HAVE_NL_LANGINFO */ @@ -977,9 +895,6 @@ /* Define to 1 if you have the <sys/wait.h> header file. */ #define HAVE_SYS_WAIT_H 1 -/* Define to 1 if you have the `times' function. */ -#define HAVE_TIMES 1 - /* Define to 1 if you have the `towlower' function. */ #define HAVE_TOWLOWER 1 @@ -1040,10 +955,6 @@ /* Define to 1 if O_NOFOLLOW works. */ #define HAVE_WORKING_O_NOFOLLOW 1 -/* Define if you have the posix_spawn and posix_spawnp functions and they - work. */ -#define HAVE_WORKING_POSIX_SPAWN 1 - /* Define to 1 if the system has the type `_Bool'. */ #define HAVE__BOOL 1 @@ -1175,7 +1086,7 @@ #define PACKAGE_NAME "GNU Bison" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU Bison 3.1" +#define PACKAGE_STRING "GNU Bison 3.2.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "bison" @@ -1184,7 +1095,7 @@ #define PACKAGE_URL "http://www.gnu.org/software/bison/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.1" +#define PACKAGE_VERSION "3.2.4" /* Define if <inttypes.h> exists and defines unusable PRI* macros. */ /* #undef PRI_MACROS_BROKEN */ @@ -1208,6 +1119,9 @@ slash */ /* #undef REPLACE_FUNC_STAT_FILE */ +/* Define if gnulib uses its own posix_spawn and posix_spawnp functions. */ +/* #undef REPLACE_POSIX_SPAWN */ + /* Define if printf is overridden by a POSIX compliant gnulib implementation. */ #define REPLACE_PRINTF_POSIX 1 @@ -1222,6 +1136,15 @@ implementation. */ #define REPLACE_VFPRINTF_POSIX 1 +/* File name of the Bourne shell. */ +#if defined __CYGWIN__ +/* Omit the directory part because for 32-bit Cygwin programs in a + 64-bit Cygwin environment, the Cygwin mounts are not visible. */ +# define BOURNE_SHELL "sh" +#else +# define BOURNE_SHELL "/bin/sh" +#endif + /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 'sig_atomic_t'. */ /* #undef SIG_ATOMIC_T_SUFFIX */ @@ -1367,7 +1290,7 @@ /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.1" +#define VERSION "3.2.4" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ @@ -1418,12 +1341,15 @@ #define _NETBSD_SOURCE 1 /* The _Noreturn keyword of C11. */ -#if ! (defined _Noreturn \ - || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)) -# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ - || 0x5110 <= __SUNPRO_C) +#ifndef _Noreturn +# if 201103 <= (defined __cplusplus ? __cplusplus : 0) +# define _Noreturn [[noreturn]] +# elif (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ + || 4 < __GNUC__ + (7 <= __GNUC_MINOR__)) + /* _Noreturn works as-is. */ +# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C # define _Noreturn __attribute__ ((__noreturn__)) -# elif defined _MSC_VER && 1200 <= _MSC_VER +# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0) # define _Noreturn __declspec (noreturn) # else # define _Noreturn diff --git a/contrib/tools/bison/lib/config-win.h b/contrib/tools/bison/lib/config-win.h index cb0268bf50f..25076ea809a 100644 --- a/contrib/tools/bison/lib/config-win.h +++ b/contrib/tools/bison/lib/config-win.h @@ -1226,7 +1226,7 @@ char *strsignal (int signum); /* #undef PACKAGE_PACKAGER_VERSION */ /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU Bison 3.1" +#define PACKAGE_STRING "GNU Bison 3.2.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "m4" @@ -1235,7 +1235,7 @@ char *strsignal (int signum); #define PACKAGE_URL "http://www.gnu.org/software/m4/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.1" +#define PACKAGE_VERSION "3.2.4" /* Define if <inttypes.h> exists and defines unusable PRI* macros. */ /* #undef PRI_MACROS_BROKEN */ @@ -1398,7 +1398,7 @@ char *strsignal (int signum); /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.1" +#define VERSION "3.2.4" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ diff --git a/contrib/tools/bison/lib/configmake-linux.h b/contrib/tools/bison/lib/configmake-linux.h index bc0a0399a32..bd096ef0053 100644 --- a/contrib/tools/bison/lib/configmake-linux.h +++ b/contrib/tools/bison/lib/configmake-linux.h @@ -1,28 +1,28 @@ /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ -#define PREFIX "/var/empty/bison-3.1" -#define EXEC_PREFIX "/var/empty/bison-3.1" -#define BINDIR "/var/empty/bison-3.1/bin" -#define SBINDIR "/var/empty/bison-3.1/sbin" -#define LIBEXECDIR "/var/empty/bison-3.1/libexec" -#define DATAROOTDIR "/var/empty/bison-3.1/share" -#define DATADIR "/var/empty/bison-3.1/share" -#define SYSCONFDIR "/var/empty/bison-3.1/etc" -#define SHAREDSTATEDIR "/var/empty/bison-3.1/com" -#define LOCALSTATEDIR "/var/empty/bison-3.1/var" -#define RUNSTATEDIR "/var/empty/bison-3.1/var/run" -#define INCLUDEDIR "/var/empty/bison-3.1/include" +#define PREFIX "/var/empty/bison-3.2.4" +#define EXEC_PREFIX "/var/empty/bison-3.2.4" +#define BINDIR "/var/empty/bison-3.2.4/bin" +#define SBINDIR "/var/empty/bison-3.2.4/sbin" +#define LIBEXECDIR "/var/empty/bison-3.2.4/libexec" +#define DATAROOTDIR "/var/empty/bison-3.2.4/share" +#define DATADIR "/var/empty/bison-3.2.4/share" +#define SYSCONFDIR "/var/empty/bison-3.2.4/etc" +#define SHAREDSTATEDIR "/var/empty/bison-3.2.4/com" +#define LOCALSTATEDIR "/var/empty/bison-3.2.4/var" +#define RUNSTATEDIR "/var/empty/bison-3.2.4/var/run" +#define INCLUDEDIR "/var/empty/bison-3.2.4/include" #define OLDINCLUDEDIR "/usr/include" -#define DOCDIR "/var/empty/bison-3.1/share/doc/bison" -#define INFODIR "/var/empty/bison-3.1/share/info" -#define HTMLDIR "/var/empty/bison-3.1/share/doc/bison" -#define DVIDIR "/var/empty/bison-3.1/share/doc/bison" -#define PDFDIR "/var/empty/bison-3.1/share/doc/bison" -#define PSDIR "/var/empty/bison-3.1/share/doc/bison" -#define LIBDIR "/var/empty/bison-3.1/lib" -#define LISPDIR "/var/empty/bison-3.1/share/emacs/site-lisp" -#define LOCALEDIR "/var/empty/bison-3.1/share/locale" -#define MANDIR "/var/empty/bison-3.1/share/man" -#define PKGDATADIR "/var/empty/bison-3.1/share/bison" -#define PKGINCLUDEDIR "/var/empty/bison-3.1/include/bison" -#define PKGLIBDIR "/var/empty/bison-3.1/lib/bison" -#define PKGLIBEXECDIR "/var/empty/bison-3.1/libexec/bison" +#define DOCDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define INFODIR "/var/empty/bison-3.2.4/share/info" +#define HTMLDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define DVIDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define PDFDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define PSDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define LIBDIR "/var/empty/bison-3.2.4/lib" +#define LISPDIR "/var/empty/bison-3.2.4/share/emacs/site-lisp" +#define LOCALEDIR "/var/empty/bison-3.2.4/share/locale" +#define MANDIR "/var/empty/bison-3.2.4/share/man" +#define PKGDATADIR "/var/empty/bison-3.2.4/share/bison" +#define PKGINCLUDEDIR "/var/empty/bison-3.2.4/include/bison" +#define PKGLIBDIR "/var/empty/bison-3.2.4/lib/bison" +#define PKGLIBEXECDIR "/var/empty/bison-3.2.4/libexec/bison" diff --git a/contrib/tools/bison/lib/ebitset.c b/contrib/tools/bison/lib/ebitset.c index 06da3cc6ce3..561816b132d 100644 --- a/contrib/tools/bison/lib/ebitset.c +++ b/contrib/tools/bison/lib/ebitset.c @@ -22,10 +22,11 @@ #include "ebitset.h" -#include "obstack.h" #include <stdlib.h> #include <string.h> +#include "obstack.h" + /* This file implements expandable bitsets. These bitsets can be of arbitrary length and are more efficient than arrays of bits for large sparse sets. @@ -73,7 +74,7 @@ typedef ebitset_elt *ebitset_elts; /* Number of elements to initially allocate. */ #ifndef EBITSET_INITIAL_SIZE -#define EBITSET_INITIAL_SIZE 2 +# define EBITSET_INITIAL_SIZE 2 #endif @@ -123,19 +124,14 @@ static ebitset_elt *ebitset_free_list; /* Free list of bitset elements. */ static bitset_bindex ebitset_resize (bitset src, bitset_bindex n_bits) { - bitset_windex oldsize; - bitset_windex newsize; - if (n_bits == BITSET_NBITS_ (src)) return n_bits; - oldsize = EBITSET_SIZE (src); - newsize = EBITSET_N_ELTS (n_bits); + bitset_windex oldsize = EBITSET_SIZE (src); + bitset_windex newsize = EBITSET_N_ELTS (n_bits); if (oldsize < newsize) { - bitset_windex size; - /* The bitset needs to grow. If we already have enough memory allocated, then just zero what we need. */ if (newsize > EBITSET_ASIZE (src)) @@ -145,11 +141,7 @@ ebitset_resize (bitset src, bitset_bindex n_bits) grow the bitset 25% larger than requested to reduce number of reallocations. */ - if (oldsize == 0) - size = newsize; - else - size = newsize + newsize / 4; - + bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4; EBITSET_ELTS (src) = realloc (EBITSET_ELTS (src), size * sizeof (ebitset_elt *)); EBITSET_ASIZE (src) = size; @@ -234,9 +226,7 @@ ebitset_elt_alloc (void) static inline ebitset_elt * ebitset_elt_calloc (void) { - ebitset_elt *elt; - - elt = ebitset_elt_alloc (); + ebitset_elt *elt = ebitset_elt_alloc (); memset (EBITSET_WORDS (elt), 0, sizeof (EBITSET_WORDS (elt))); return elt; } @@ -254,12 +244,8 @@ ebitset_elt_free (ebitset_elt *elt) static inline void ebitset_elt_remove (bitset bset, bitset_windex eindex) { - ebitset_elts *elts; - ebitset_elt *elt; - - elts = EBITSET_ELTS (bset); - - elt = elts[eindex]; + ebitset_elts *elts = EBITSET_ELTS (bset); + ebitset_elt *elt = elts[eindex]; elts[eindex] = 0; ebitset_elt_free (elt); @@ -270,9 +256,7 @@ ebitset_elt_remove (bitset bset, bitset_windex eindex) static inline void ebitset_elt_add (bitset bset, ebitset_elt *elt, bitset_windex eindex) { - ebitset_elts *elts; - - elts = EBITSET_ELTS (bset); + ebitset_elts *elts = EBITSET_ELTS (bset); /* Assume that the elts entry not allocated. */ elts[eindex] = elt; } @@ -282,12 +266,9 @@ ebitset_elt_add (bitset bset, ebitset_elt *elt, bitset_windex eindex) static inline bool ebitset_elt_zero_p (ebitset_elt *elt) { - int i; - - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (int i = 0; i < EBITSET_ELT_WORDS; i++) if (EBITSET_WORDS (elt)[i]) return false; - return true; } @@ -296,24 +277,18 @@ static ebitset_elt * ebitset_elt_find (bitset bset, bitset_bindex bindex, enum ebitset_find_mode mode) { - ebitset_elt *elt; - bitset_windex size; - bitset_windex eindex; - ebitset_elts *elts; + bitset_windex eindex = bindex / EBITSET_ELT_BITS; - eindex = bindex / EBITSET_ELT_BITS; - - elts = EBITSET_ELTS (bset); - size = EBITSET_SIZE (bset); + ebitset_elts *elts = EBITSET_ELTS (bset); + bitset_windex size = EBITSET_SIZE (bset); if (eindex < size) { - if ((elt = elts[eindex])) + ebitset_elt *elt = elts[eindex]; + if (elt) { - if (EBITSET_WORDS (elt) == bset->b.cdata) - return elt; - - EBITSET_CACHE_SET (bset, eindex); + if (EBITSET_WORDS (elt) != bset->b.cdata) + EBITSET_CACHE_SET (bset, eindex); return elt; } } @@ -333,10 +308,12 @@ ebitset_elt_find (bitset bset, bitset_bindex bindex, ebitset_resize (bset, bindex); /* Create a new element. */ - elt = ebitset_elt_calloc (); - ebitset_elt_add (bset, elt, eindex); - EBITSET_CACHE_SET (bset, eindex); - return elt; + { + ebitset_elt *elt = ebitset_elt_calloc (); + ebitset_elt_add (bset, elt, eindex); + EBITSET_CACHE_SET (bset, eindex); + return elt; + } case EBITSET_SUBST: return &ebitset_zero_elts[0]; @@ -348,15 +325,12 @@ ebitset_elt_find (bitset bset, bitset_bindex bindex, static inline bitset_windex ebitset_weed (bitset bset) { - ebitset_elts *elts; - bitset_windex j; - bitset_windex count; - if (EBITSET_ZERO_P (bset)) return 0; - elts = EBITSET_ELTS (bset); - count = 0; + ebitset_elts *elts = EBITSET_ELTS (bset); + bitset_windex count = 0; + bitset_windex j; for (j = 0; j < EBITSET_SIZE (bset); j++) { ebitset_elt *elt = elts[j]; @@ -391,17 +365,13 @@ ebitset_weed (bitset bset) static inline void ebitset_zero (bitset bset) { - ebitset_elts *elts; - bitset_windex j; - if (EBITSET_ZERO_P (bset)) return; - elts = EBITSET_ELTS (bset); - for (j = 0; j < EBITSET_SIZE (bset); j++) + ebitset_elts *elts = EBITSET_ELTS (bset); + for (bitset_windex j = 0; j < EBITSET_SIZE (bset); j++) { ebitset_elt *elt = elts[j]; - if (elt) ebitset_elt_remove (bset, j); } @@ -415,10 +385,6 @@ ebitset_zero (bitset bset) static inline bool ebitset_equal_p (bitset dst, bitset src) { - ebitset_elts *selts; - ebitset_elts *delts; - bitset_windex j; - if (src == dst) return true; @@ -428,12 +394,11 @@ ebitset_equal_p (bitset dst, bitset src) if (EBITSET_SIZE (src) != EBITSET_SIZE (dst)) return false; - selts = EBITSET_ELTS (src); - delts = EBITSET_ELTS (dst); + ebitset_elts *selts = EBITSET_ELTS (src); + ebitset_elts *delts = EBITSET_ELTS (dst); - for (j = 0; j < EBITSET_SIZE (src); j++) + for (bitset_windex j = 0; j < EBITSET_SIZE (src); j++) { - unsigned i; ebitset_elt *selt = selts[j]; ebitset_elt *delt = delts[j]; @@ -442,7 +407,7 @@ ebitset_equal_p (bitset dst, bitset src) if ((selt && !delt) || (!selt && delt)) return false; - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++) if (EBITSET_WORDS (selt)[i] != EBITSET_WORDS (delt)[i]) return false; } @@ -454,10 +419,6 @@ ebitset_equal_p (bitset dst, bitset src) static inline void ebitset_copy_ (bitset dst, bitset src) { - ebitset_elts *selts; - ebitset_elts *delts; - bitset_windex j; - if (src == dst) return; @@ -466,17 +427,14 @@ ebitset_copy_ (bitset dst, bitset src) if (BITSET_NBITS_ (dst) != BITSET_NBITS_ (src)) ebitset_resize (dst, BITSET_NBITS_ (src)); - selts = EBITSET_ELTS (src); - delts = EBITSET_ELTS (dst); - for (j = 0; j < EBITSET_SIZE (src); j++) + ebitset_elts *selts = EBITSET_ELTS (src); + ebitset_elts *delts = EBITSET_ELTS (dst); + for (bitset_windex j = 0; j < EBITSET_SIZE (src); j++) { ebitset_elt *selt = selts[j]; - if (selt) { - ebitset_elt *tmp; - - tmp = ebitset_elt_alloc (); + ebitset_elt *tmp = ebitset_elt_alloc (); delts[j] = tmp; memcpy (EBITSET_WORDS (tmp), EBITSET_WORDS (selt), sizeof (EBITSET_WORDS (selt))); @@ -567,60 +525,41 @@ static bitset_bindex ebitset_list_reverse (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex n_bits; - bitset_bindex bitno; - bitset_bindex rbitno; - unsigned bcount; - bitset_bindex boffset; - bitset_windex windex; - bitset_windex eindex; - bitset_windex woffset; - bitset_bindex count; - bitset_windex size; - ebitset_elts *elts; - if (EBITSET_ZERO_P (bset)) return 0; - size = EBITSET_SIZE (bset); - n_bits = size * EBITSET_ELT_BITS; - rbitno = *next; + bitset_windex size = EBITSET_SIZE (bset); + bitset_bindex n_bits = size * EBITSET_ELT_BITS; + bitset_bindex rbitno = *next; if (rbitno >= n_bits) return 0; - elts = EBITSET_ELTS (bset); + ebitset_elts *elts = EBITSET_ELTS (bset); - bitno = n_bits - (rbitno + 1); + bitset_bindex bitno = n_bits - (rbitno + 1); - windex = bitno / BITSET_WORD_BITS; - eindex = bitno / EBITSET_ELT_BITS; - woffset = windex - eindex * EBITSET_ELT_WORDS; + bitset_windex windex = bitno / BITSET_WORD_BITS; + bitset_windex eindex = bitno / EBITSET_ELT_BITS; + bitset_windex woffset = windex - eindex * EBITSET_ELT_WORDS; /* If num is 1, we could speed things up with a binary search of the word of interest. */ - - count = 0; - bcount = bitno % BITSET_WORD_BITS; - boffset = windex * BITSET_WORD_BITS; + bitset_bindex count = 0; + unsigned bcount = bitno % BITSET_WORD_BITS; + bitset_bindex boffset = windex * BITSET_WORD_BITS; do { - ebitset_elt *elt; - bitset_word *srcp; - - elt = elts[eindex]; + ebitset_elt *elt = elts[eindex]; if (elt) { - srcp = EBITSET_WORDS (elt); + bitset_word *srcp = EBITSET_WORDS (elt); do { - bitset_word word; - - word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bcount); - - for (; word; bcount--) + for (bitset_word word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bcount); + word; bcount--) { if (word & BITSET_MSB) { @@ -656,41 +595,32 @@ static bitset_bindex ebitset_list (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_windex windex; - bitset_windex eindex; - bitset_bindex count; - bitset_windex size; - ebitset_elt *elt; - bitset_word word; - ebitset_elts *elts; - if (EBITSET_ZERO_P (bset)) return 0; - bitno = *next; - count = 0; + bitset_bindex bitno = *next; + bitset_bindex count = 0; - elts = EBITSET_ELTS (bset); - size = EBITSET_SIZE (bset); - eindex = bitno / EBITSET_ELT_BITS; + ebitset_elts *elts = EBITSET_ELTS (bset); + bitset_windex size = EBITSET_SIZE (bset); + bitset_windex eindex = bitno / EBITSET_ELT_BITS; if (bitno % EBITSET_ELT_BITS) { /* We need to start within an element. This is not very common. */ - elt = elts[eindex]; + ebitset_elt *elt = elts[eindex]; if (elt) { bitset_windex woffset; bitset_word *srcp = EBITSET_WORDS (elt); - windex = bitno / BITSET_WORD_BITS; + bitset_windex windex = bitno / BITSET_WORD_BITS; woffset = eindex * EBITSET_ELT_WORDS; for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++) { - word = srcp[windex - woffset] >> (bitno % BITSET_WORD_BITS); + bitset_word word = srcp[windex - woffset] >> (bitno % BITSET_WORD_BITS); for (; word; bitno++) { @@ -718,22 +648,21 @@ ebitset_list (bitset bset, bitset_bindex *list, for (; eindex < size; eindex++) { - int i; bitset_word *srcp; - elt = elts[eindex]; + ebitset_elt *elt = elts[eindex]; if (!elt) continue; srcp = EBITSET_WORDS (elt); - windex = eindex * EBITSET_ELT_WORDS; + bitset_windex windex = eindex * EBITSET_ELT_WORDS; if ((count + EBITSET_ELT_BITS) < num) { /* The coast is clear, plant boot! */ #if EBITSET_ELT_WORDS == 2 - word = srcp[0]; + bitset_word word = srcp[0]; if (word) { if (!(word & 0xffff)) @@ -774,7 +703,7 @@ ebitset_list (bitset bset, bitset_bindex *list, windex++; bitno = windex * BITSET_WORD_BITS; #else - for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++) + for (int i = 0; i < EBITSET_ELT_WORDS; i++, windex++) { bitno = windex * BITSET_WORD_BITS; @@ -806,11 +735,11 @@ ebitset_list (bitset bset, bitset_bindex *list, /* Tread more carefully since we need to check if array overflows. */ - for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++) + for (int i = 0; i < EBITSET_ELT_WORDS; i++, windex++) { bitno = windex * BITSET_WORD_BITS; - for (word = srcp[i]; word; bitno++) + for (bitset_word word = srcp[i]; word; bitno++) { if (word & 1) { @@ -836,31 +765,22 @@ ebitset_list (bitset bset, bitset_bindex *list, static inline void ebitset_unused_clear (bitset dst) { - unsigned last_bit; - bitset_bindex n_bits; - - n_bits = BITSET_NBITS_ (dst); - last_bit = n_bits % EBITSET_ELT_BITS; + bitset_bindex n_bits = BITSET_NBITS_ (dst); + unsigned last_bit = n_bits % EBITSET_ELT_BITS; if (last_bit) { - bitset_windex eindex; - ebitset_elts *elts; - ebitset_elt *elt; + ebitset_elts *elts = EBITSET_ELTS (dst); - elts = EBITSET_ELTS (dst); + bitset_windex eindex = n_bits / EBITSET_ELT_BITS; - eindex = n_bits / EBITSET_ELT_BITS; - - elt = elts[eindex]; + ebitset_elt *elt = elts[eindex]; if (elt) { - bitset_windex windex; - bitset_windex woffset; bitset_word *srcp = EBITSET_WORDS (elt); - windex = n_bits / BITSET_WORD_BITS; - woffset = eindex * EBITSET_ELT_WORDS; + bitset_windex windex = n_bits / BITSET_WORD_BITS; + bitset_windex woffset = eindex * EBITSET_ELT_WORDS; srcp[windex - woffset] &= ((bitset_word) 1 << last_bit) - 1; windex++; @@ -874,14 +794,11 @@ ebitset_unused_clear (bitset dst) static void ebitset_ones (bitset dst) { - bitset_windex j; - ebitset_elt *elt; - - for (j = 0; j < EBITSET_SIZE (dst); j++) + for (bitset_windex j = 0; j < EBITSET_SIZE (dst); j++) { /* Create new elements if they cannot be found. Perhaps we should just add pointers to a ones element? */ - elt = + ebitset_elt *elt = ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_CREATE); memset (EBITSET_WORDS (elt), -1, sizeof (EBITSET_WORDS (elt))); } @@ -893,14 +810,11 @@ ebitset_ones (bitset dst) static bool ebitset_empty_p (bitset dst) { - ebitset_elts *elts; - bitset_windex j; - if (EBITSET_ZERO_P (dst)) return 1; - elts = EBITSET_ELTS (dst); - for (j = 0; j < EBITSET_SIZE (dst); j++) + ebitset_elts *elts = EBITSET_ELTS (dst); + for (bitset_windex j = 0; j < EBITSET_SIZE (dst); j++) { ebitset_elt *elt = elts[j]; @@ -923,23 +837,18 @@ ebitset_empty_p (bitset dst) static void ebitset_not (bitset dst, bitset src) { - unsigned i; - ebitset_elt *selt; - ebitset_elt *delt; - bitset_windex j; - ebitset_resize (dst, BITSET_NBITS_ (src)); - for (j = 0; j < EBITSET_SIZE (src); j++) + for (bitset_windex j = 0; j < EBITSET_SIZE (src); j++) { /* Create new elements for dst if they cannot be found or substitute zero elements if src elements not found. */ - selt = + ebitset_elt *selt = ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_SUBST); - delt = + ebitset_elt *delt = ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_CREATE); - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++) EBITSET_WORDS (delt)[i] = ~EBITSET_WORDS (selt)[i]; } EBITSET_NONZERO_SET (dst); @@ -951,26 +860,16 @@ ebitset_not (bitset dst, bitset src) static bool ebitset_subset_p (bitset dst, bitset src) { - bitset_windex j; - ebitset_elts *selts; - ebitset_elts *delts; - bitset_windex ssize; - bitset_windex dsize; - - selts = EBITSET_ELTS (src); - delts = EBITSET_ELTS (dst); + ebitset_elts *selts = EBITSET_ELTS (src); + ebitset_elts *delts = EBITSET_ELTS (dst); - ssize = EBITSET_SIZE (src); - dsize = EBITSET_SIZE (dst); + bitset_windex ssize = EBITSET_SIZE (src); + bitset_windex dsize = EBITSET_SIZE (dst); - for (j = 0; j < ssize; j++) + for (bitset_windex j = 0; j < ssize; j++) { - unsigned i; - ebitset_elt *selt; - ebitset_elt *delt; - - selt = j < ssize ? selts[j] : 0; - delt = j < dsize ? delts[j] : 0; + ebitset_elt *selt = j < ssize ? selts[j] : 0; + ebitset_elt *delt = j < dsize ? delts[j] : 0; if (!selt && !delt) continue; @@ -980,7 +879,7 @@ ebitset_subset_p (bitset dst, bitset src) if (!delt) delt = &ebitset_zero_elts[0]; - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++) if (EBITSET_WORDS (delt)[i] != (EBITSET_WORDS (selt)[i] | EBITSET_WORDS (delt)[i])) return false; @@ -993,31 +892,21 @@ ebitset_subset_p (bitset dst, bitset src) static bool ebitset_disjoint_p (bitset dst, bitset src) { - bitset_windex j; - ebitset_elts *selts; - ebitset_elts *delts; - bitset_windex ssize; - bitset_windex dsize; + ebitset_elts *selts = EBITSET_ELTS (src); + ebitset_elts *delts = EBITSET_ELTS (dst); - selts = EBITSET_ELTS (src); - delts = EBITSET_ELTS (dst); + bitset_windex ssize = EBITSET_SIZE (src); + bitset_windex dsize = EBITSET_SIZE (dst); - ssize = EBITSET_SIZE (src); - dsize = EBITSET_SIZE (dst); - - for (j = 0; j < ssize; j++) + for (bitset_windex j = 0; j < ssize; j++) { - unsigned i; - ebitset_elt *selt; - ebitset_elt *delt; - - selt = j < ssize ? selts[j] : 0; - delt = j < dsize ? delts[j] : 0; + ebitset_elt *selt = j < ssize ? selts[j] : 0; + ebitset_elt *delt = j < dsize ? delts[j] : 0; if (!selt || !delt) continue; - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++) if ((EBITSET_WORDS (selt)[i] & EBITSET_WORDS (delt)[i])) return false; } @@ -1029,42 +918,27 @@ ebitset_disjoint_p (bitset dst, bitset src) static bool ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) { - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - bitset_windex size; - ebitset_elts *selts1; - ebitset_elts *selts2; - ebitset_elts *delts; - bitset_word *srcp1; - bitset_word *srcp2; - bitset_word *dstp; bool changed = false; - unsigned i; - bitset_windex j; ebitset_resize (dst, max (BITSET_NBITS_ (src1), BITSET_NBITS_ (src2))); - ssize1 = EBITSET_SIZE (src1); - ssize2 = EBITSET_SIZE (src2); - dsize = EBITSET_SIZE (dst); - size = ssize1; + bitset_windex ssize1 = EBITSET_SIZE (src1); + bitset_windex ssize2 = EBITSET_SIZE (src2); + bitset_windex dsize = EBITSET_SIZE (dst); + bitset_windex size = ssize1; if (size < ssize2) size = ssize2; - selts1 = EBITSET_ELTS (src1); - selts2 = EBITSET_ELTS (src2); - delts = EBITSET_ELTS (dst); + ebitset_elts *selts1 = EBITSET_ELTS (src1); + ebitset_elts *selts2 = EBITSET_ELTS (src2); + ebitset_elts *delts = EBITSET_ELTS (dst); + bitset_windex j = 0; for (j = 0; j < size; j++) { - ebitset_elt *selt1; - ebitset_elt *selt2; - ebitset_elt *delt; - - selt1 = j < ssize1 ? selts1[j] : 0; - selt2 = j < ssize2 ? selts2[j] : 0; - delt = j < dsize ? delts[j] : 0; + ebitset_elt *selt1 = j < ssize1 ? selts1[j] : 0; + ebitset_elt *selt2 = j < ssize2 ? selts2[j] : 0; + ebitset_elt *delt = j < dsize ? delts[j] : 0; if (!selt1 && !selt2) { @@ -1085,16 +959,16 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) else delts[j] = 0; - srcp1 = EBITSET_WORDS (selt1); - srcp2 = EBITSET_WORDS (selt2); - dstp = EBITSET_WORDS (delt); + bitset_word *srcp1 = EBITSET_WORDS (selt1); + bitset_word *srcp2 = EBITSET_WORDS (selt2); + bitset_word *dstp = EBITSET_WORDS (delt); switch (op) { default: abort (); case BITSET_OP_OR: - for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ | *srcp2++; @@ -1107,7 +981,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_AND: - for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ & *srcp2++; @@ -1120,7 +994,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_XOR: - for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ ^ *srcp2++; @@ -1133,7 +1007,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_ANDN: - for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ & ~(*srcp2++); @@ -1159,12 +1033,9 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) /* If we have elements of DST left over, free them all. */ for (; j < dsize; j++) { - ebitset_elt *delt; - changed = true; - delt = delts[j]; - + ebitset_elt *delt = delts[j]; if (delt) ebitset_elt_remove (dst, j); } @@ -1177,19 +1048,17 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) static bool ebitset_and_cmp (bitset dst, bitset src1, bitset src2) { - bool changed; - if (EBITSET_ZERO_P (src2)) { ebitset_weed (dst); - changed = EBITSET_ZERO_P (dst); + bool changed = EBITSET_ZERO_P (dst); ebitset_zero (dst); return changed; } else if (EBITSET_ZERO_P (src1)) { ebitset_weed (dst); - changed = EBITSET_ZERO_P (dst); + bool changed = EBITSET_ZERO_P (dst); ebitset_zero (dst); return changed; } @@ -1207,8 +1076,6 @@ ebitset_and (bitset dst, bitset src1, bitset src2) static bool ebitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - bool changed; - if (EBITSET_ZERO_P (src2)) { return ebitset_copy_cmp (dst, src1); @@ -1216,7 +1083,7 @@ ebitset_andn_cmp (bitset dst, bitset src1, bitset src2) else if (EBITSET_ZERO_P (src1)) { ebitset_weed (dst); - changed = EBITSET_ZERO_P (dst); + bool changed = EBITSET_ZERO_P (dst); ebitset_zero (dst); return changed; } @@ -1279,9 +1146,9 @@ static void ebitset_copy (bitset dst, bitset src) { if (BITSET_COMPATIBLE_ (dst, src)) - ebitset_copy_ (dst, src); + ebitset_copy_ (dst, src); else - bitset_copy_ (dst, src); + bitset_copy_ (dst, src); } diff --git a/contrib/tools/bison/lib/ebitset.h b/contrib/tools/bison/lib/ebitset.h index e8036cd45e5..97b9ee1522f 100644 --- a/contrib/tools/bison/lib/ebitset.h +++ b/contrib/tools/bison/lib/ebitset.h @@ -23,10 +23,10 @@ #include "bitset.h" -extern size_t ebitset_bytes (bitset_bindex); +size_t ebitset_bytes (bitset_bindex); -extern bitset ebitset_init (bitset, bitset_bindex); +bitset ebitset_init (bitset, bitset_bindex); -extern void ebitset_release_memory (void); +void ebitset_release_memory (void); #endif diff --git a/contrib/tools/bison/lib/fcntl.c b/contrib/tools/bison/lib/fcntl.c index d09e6b180c0..bdf1e5bbdae 100644 --- a/contrib/tools/bison/lib/fcntl.c +++ b/contrib/tools/bison/lib/fcntl.c @@ -27,10 +27,10 @@ #include <stdarg.h> #include <unistd.h> -#if !HAVE_FCNTL -# define rpl_fcntl fcntl +#ifdef __KLIBC__ +# define INCL_DOS +# error #include <os2.h> #endif -#undef fcntl #if defined _WIN32 && ! defined __CYGWIN__ /* Get declarations of the native Windows API functions. */ @@ -166,93 +166,18 @@ dupfd (int oldfd, int newfd, int flags) } #endif /* W32 */ +/* Forward declarations, because we '#undef fcntl' in the middle of this + compilation unit. */ +/* Our implementation of fcntl (fd, F_DUPFD, target). */ +static int rpl_fcntl_DUPFD (int fd, int target); +/* Our implementation of fcntl (fd, F_DUPFD_CLOEXEC, target). */ +static int rpl_fcntl_DUPFD_CLOEXEC (int fd, int target); #ifdef __KLIBC__ - -# define INCL_DOS -# error #include <os2.h> - -static int -klibc_fcntl (int fd, int action, /* arg */...) -{ - va_list arg_ptr; - int arg; - struct stat sbuf; - int result = -1; - - va_start (arg_ptr, action); - arg = va_arg (arg_ptr, int); - result = fcntl (fd, action, arg); - /* EPERM for F_DUPFD, ENOTSUP for others */ - if (result == -1 && (errno == EPERM || errno == ENOTSUP) - && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) - { - ULONG ulMode; - - switch (action) - { - case F_DUPFD: - /* Find available fd */ - while (fcntl (arg, F_GETFL) != -1 || errno != EBADF) - arg++; - - result = dup2 (fd, arg); - break; - - /* Using underlying APIs is right ? */ - case F_GETFD: - if (DosQueryFHState (fd, &ulMode)) - break; - - result = (ulMode & OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0; - break; - - case F_SETFD: - if (arg & ~FD_CLOEXEC) - break; - - if (DosQueryFHState (fd, &ulMode)) - break; - - if (arg & FD_CLOEXEC) - ulMode |= OPEN_FLAGS_NOINHERIT; - else - ulMode &= ~OPEN_FLAGS_NOINHERIT; - - /* Filter supported flags. */ - ulMode &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR - | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT); - - if (DosSetFHState (fd, ulMode)) - break; - - result = 0; - break; - - case F_GETFL: - result = 0; - break; - - case F_SETFL: - if (arg != 0) - break; - - result = 0; - break; - - default : - errno = EINVAL; - break; - } - } - - va_end (arg_ptr); - - return result; -} - -# define fcntl klibc_fcntl +/* Adds support for fcntl on directories. */ +static int klibc_fcntl (int fd, int action, /* arg */...); #endif + /* Perform the specified ACTION on the file descriptor FD, possibly using the argument ARG further described below. This replacement handles the following actions, and forwards all others on to the @@ -273,105 +198,30 @@ klibc_fcntl (int fd, int action, /* arg */...) return -1 and set errno. */ int -rpl_fcntl (int fd, int action, /* arg */...) +fcntl (int fd, int action, /* arg */...) +#undef fcntl +#ifdef __KLIBC__ +# define fcntl klibc_fcntl +#endif { va_list arg; int result = -1; va_start (arg, action); switch (action) { - -#if !HAVE_FCNTL case F_DUPFD: { int target = va_arg (arg, int); - result = dupfd (fd, target, 0); + result = rpl_fcntl_DUPFD (fd, target); break; } -#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR - case F_DUPFD: - { - int target = va_arg (arg, int); - /* Detect invalid target; needed for cygwin 1.5.x. */ - if (target < 0 || getdtablesize () <= target) - errno = EINVAL; - else - { - /* Haiku alpha 2 loses fd flags on original. */ - int flags = fcntl (fd, F_GETFD); - if (flags < 0) - { - result = -1; - break; - } - result = fcntl (fd, action, target); - if (0 <= result && fcntl (fd, F_SETFD, flags) == -1) - { - int saved_errno = errno; - close (result); - result = -1; - errno = saved_errno; - } -# if REPLACE_FCHDIR - if (0 <= result) - result = _gl_register_dup (fd, result); -# endif - } - break; - } /* F_DUPFD */ -#endif /* FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR */ case F_DUPFD_CLOEXEC: { int target = va_arg (arg, int); - -#if !HAVE_FCNTL - result = dupfd (fd, target, O_CLOEXEC); - break; -#else /* HAVE_FCNTL */ - /* Try the system call first, if the headers claim it exists - (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we - may be running with a glibc that has the macro but with an - older kernel that does not support it. Cache the - information on whether the system call really works, but - avoid caching failure if the corresponding F_DUPFD fails - for any reason. 0 = unknown, 1 = yes, -1 = no. */ - static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0; - if (0 <= have_dupfd_cloexec) - { - result = fcntl (fd, action, target); - if (0 <= result || errno != EINVAL) - { - have_dupfd_cloexec = 1; -# if REPLACE_FCHDIR - if (0 <= result) - result = _gl_register_dup (fd, result); -# endif - } - else - { - result = rpl_fcntl (fd, F_DUPFD, target); - if (result < 0) - break; - have_dupfd_cloexec = -1; - } - } - else - result = rpl_fcntl (fd, F_DUPFD, target); - if (0 <= result && have_dupfd_cloexec == -1) - { - int flags = fcntl (result, F_GETFD); - if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1) - { - int saved_errno = errno; - close (result); - errno = saved_errno; - result = -1; - } - } + result = rpl_fcntl_DUPFD_CLOEXEC (fd, target); break; -#endif /* HAVE_FCNTL */ - } /* F_DUPFD_CLOEXEC */ + } #if !HAVE_FCNTL case F_GETFD: @@ -405,8 +255,183 @@ rpl_fcntl (int fd, int action, /* arg */...) default: { #if HAVE_FCNTL - void *p = va_arg (arg, void *); - result = fcntl (fd, action, p); + switch (action) + { + #ifdef F_BARRIERFSYNC /* macOS */ + case F_BARRIERFSYNC: + #endif + #ifdef F_CHKCLEAN /* macOS */ + case F_CHKCLEAN: + #endif + #ifdef F_CLOSEM /* NetBSD, HP-UX */ + case F_CLOSEM: + #endif + #ifdef F_FLUSH_DATA /* macOS */ + case F_FLUSH_DATA: + #endif + #ifdef F_FREEZE_FS /* macOS */ + case F_FREEZE_FS: + #endif + #ifdef F_FULLFSYNC /* macOS */ + case F_FULLFSYNC: + #endif + #ifdef F_GETCONFINED /* macOS */ + case F_GETCONFINED: + #endif + #ifdef F_GETDEFAULTPROTLEVEL /* macOS */ + case F_GETDEFAULTPROTLEVEL: + #endif + #ifdef F_GETFD /* POSIX */ + case F_GETFD: + #endif + #ifdef F_GETFL /* POSIX */ + case F_GETFL: + #endif + #ifdef F_GETLEASE /* Linux */ + case F_GETLEASE: + #endif + #ifdef F_GETNOSIGPIPE /* macOS */ + case F_GETNOSIGPIPE: + #endif + #ifdef F_GETOWN /* POSIX */ + case F_GETOWN: + #endif + #ifdef F_GETPIPE_SZ /* Linux */ + case F_GETPIPE_SZ: + #endif + #ifdef F_GETPROTECTIONCLASS /* macOS */ + case F_GETPROTECTIONCLASS: + #endif + #ifdef F_GETPROTECTIONLEVEL /* macOS */ + case F_GETPROTECTIONLEVEL: + #endif + #ifdef F_GET_SEALS /* Linux */ + case F_GET_SEALS: + #endif + #ifdef F_GETSIG /* Linux */ + case F_GETSIG: + #endif + #ifdef F_MAXFD /* NetBSD */ + case F_MAXFD: + #endif + #ifdef F_RECYCLE /* macOS */ + case F_RECYCLE: + #endif + #ifdef F_SETFIFOENH /* HP-UX */ + case F_SETFIFOENH: + #endif + #ifdef F_THAW_FS /* macOS */ + case F_THAW_FS: + #endif + /* These actions take no argument. */ + result = fcntl (fd, action); + break; + + #ifdef F_ADD_SEALS /* Linux */ + case F_ADD_SEALS: + #endif + #ifdef F_BADFD /* Solaris */ + case F_BADFD: + #endif + #ifdef F_CHECK_OPENEVT /* macOS */ + case F_CHECK_OPENEVT: + #endif + #ifdef F_DUP2FD /* FreeBSD, AIX, Solaris */ + case F_DUP2FD: + #endif + #ifdef F_DUP2FD_CLOEXEC /* FreeBSD, Solaris */ + case F_DUP2FD_CLOEXEC: + #endif + #ifdef F_DUP2FD_CLOFORK /* Solaris */ + case F_DUP2FD_CLOFORK: + #endif + #ifdef F_DUPFD /* POSIX */ + case F_DUPFD: + #endif + #ifdef F_DUPFD_CLOEXEC /* POSIX */ + case F_DUPFD_CLOEXEC: + #endif + #ifdef F_DUPFD_CLOFORK /* Solaris */ + case F_DUPFD_CLOFORK: + #endif + #ifdef F_GETXFL /* Solaris */ + case F_GETXFL: + #endif + #ifdef F_GLOBAL_NOCACHE /* macOS */ + case F_GLOBAL_NOCACHE: + #endif + #ifdef F_MAKECOMPRESSED /* macOS */ + case F_MAKECOMPRESSED: + #endif + #ifdef F_MOVEDATAEXTENTS /* macOS */ + case F_MOVEDATAEXTENTS: + #endif + #ifdef F_NOCACHE /* macOS */ + case F_NOCACHE: + #endif + #ifdef F_NODIRECT /* macOS */ + case F_NODIRECT: + #endif + #ifdef F_NOTIFY /* Linux */ + case F_NOTIFY: + #endif + #ifdef F_OPLKACK /* IRIX */ + case F_OPLKACK: + #endif + #ifdef F_OPLKREG /* IRIX */ + case F_OPLKREG: + #endif + #ifdef F_RDAHEAD /* macOS */ + case F_RDAHEAD: + #endif + #ifdef F_SETBACKINGSTORE /* macOS */ + case F_SETBACKINGSTORE: + #endif + #ifdef F_SETCONFINED /* macOS */ + case F_SETCONFINED: + #endif + #ifdef F_SETFD /* POSIX */ + case F_SETFD: + #endif + #ifdef F_SETFL /* POSIX */ + case F_SETFL: + #endif + #ifdef F_SETLEASE /* Linux */ + case F_SETLEASE: + #endif + #ifdef F_SETNOSIGPIPE /* macOS */ + case F_SETNOSIGPIPE: + #endif + #ifdef F_SETOWN /* POSIX */ + case F_SETOWN: + #endif + #ifdef F_SETPIPE_SZ /* Linux */ + case F_SETPIPE_SZ: + #endif + #ifdef F_SETPROTECTIONCLASS /* macOS */ + case F_SETPROTECTIONCLASS: + #endif + #ifdef F_SETSIG /* Linux */ + case F_SETSIG: + #endif + #ifdef F_SINGLE_WRITER /* macOS */ + case F_SINGLE_WRITER: + #endif + /* These actions take an 'int' argument. */ + { + int x = va_arg (arg, int); + result = fcntl (fd, action, x); + } + break; + + default: + /* Other actions take a pointer argument. */ + { + void *p = va_arg (arg, void *); + result = fcntl (fd, action, p); + } + break; + } #else errno = EINVAL; #endif @@ -416,3 +441,186 @@ rpl_fcntl (int fd, int action, /* arg */...) va_end (arg); return result; } + +static int +rpl_fcntl_DUPFD (int fd, int target) +{ + int result; +#if !HAVE_FCNTL + result = dupfd (fd, target, 0); +#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR + /* Detect invalid target; needed for cygwin 1.5.x. */ + if (target < 0 || getdtablesize () <= target) + { + result = -1; + errno = EINVAL; + } + else + { + /* Haiku alpha 2 loses fd flags on original. */ + int flags = fcntl (fd, F_GETFD); + if (flags < 0) + result = -1; + else + { + result = fcntl (fd, F_DUPFD, target); + if (0 <= result && fcntl (fd, F_SETFD, flags) == -1) + { + int saved_errno = errno; + close (result); + result = -1; + errno = saved_errno; + } +# if REPLACE_FCHDIR + if (0 <= result) + result = _gl_register_dup (fd, result); +# endif + } + } +#else + result = fcntl (fd, F_DUPFD, target); +#endif + return result; +} + +static int +rpl_fcntl_DUPFD_CLOEXEC (int fd, int target) +{ + int result; +#if !HAVE_FCNTL + result = dupfd (fd, target, O_CLOEXEC); +#else /* HAVE_FCNTL */ +# if defined __HAIKU__ + /* On Haiku, the system fcntl (fd, F_DUPFD_CLOEXEC, target) sets + the FD_CLOEXEC flag on fd, not on target. Therefore avoid the + system fcntl in this case. */ +# define have_dupfd_cloexec -1 +# else + /* Try the system call first, if the headers claim it exists + (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we + may be running with a glibc that has the macro but with an + older kernel that does not support it. Cache the + information on whether the system call really works, but + avoid caching failure if the corresponding F_DUPFD fails + for any reason. 0 = unknown, 1 = yes, -1 = no. */ + static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0; + if (0 <= have_dupfd_cloexec) + { + result = fcntl (fd, F_DUPFD_CLOEXEC, target); + if (0 <= result || errno != EINVAL) + { + have_dupfd_cloexec = 1; +# if REPLACE_FCHDIR + if (0 <= result) + result = _gl_register_dup (fd, result); +# endif + } + else + { + result = rpl_fcntl_DUPFD (fd, target); + if (result >= 0) + have_dupfd_cloexec = -1; + } + } + else +# endif + result = rpl_fcntl_DUPFD (fd, target); + if (0 <= result && have_dupfd_cloexec == -1) + { + int flags = fcntl (result, F_GETFD); + if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1) + { + int saved_errno = errno; + close (result); + errno = saved_errno; + result = -1; + } + } +#endif /* HAVE_FCNTL */ + return result; +} + +#undef fcntl + +#ifdef __KLIBC__ + +static int +klibc_fcntl (int fd, int action, /* arg */...); +{ + va_list arg_ptr; + int arg; + struct stat sbuf; + int result; + + va_start (arg_ptr, action); + arg = va_arg (arg_ptr, int); + result = fcntl (fd, action, arg); + /* EPERM for F_DUPFD, ENOTSUP for others */ + if (result == -1 && (errno == EPERM || errno == ENOTSUP) + && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) + { + ULONG ulMode; + + switch (action) + { + case F_DUPFD: + /* Find available fd */ + while (fcntl (arg, F_GETFL) != -1 || errno != EBADF) + arg++; + + result = dup2 (fd, arg); + break; + + /* Using underlying APIs is right ? */ + case F_GETFD: + if (DosQueryFHState (fd, &ulMode)) + break; + + result = (ulMode & OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0; + break; + + case F_SETFD: + if (arg & ~FD_CLOEXEC) + break; + + if (DosQueryFHState (fd, &ulMode)) + break; + + if (arg & FD_CLOEXEC) + ulMode |= OPEN_FLAGS_NOINHERIT; + else + ulMode &= ~OPEN_FLAGS_NOINHERIT; + + /* Filter supported flags. */ + ulMode &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR + | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT); + + if (DosSetFHState (fd, ulMode)) + break; + + result = 0; + break; + + case F_GETFL: + result = 0; + break; + + case F_SETFL: + if (arg != 0) + break; + + result = 0; + break; + + default: + errno = EINVAL; + break; + } + } + + va_end (arg_ptr); + + return result; +} + +#endif diff --git a/contrib/tools/bison/lib/gethrxtime.c b/contrib/tools/bison/lib/gethrxtime.c new file mode 100644 index 00000000000..97e57ad577d --- /dev/null +++ b/contrib/tools/bison/lib/gethrxtime.c @@ -0,0 +1,72 @@ +/* gethrxtime -- get high resolution real time + + Copyright (C) 2005-2007, 2009-2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#include <config.h> + +#define GETHRXTIME_INLINE _GL_EXTERN_INLINE +#include "gethrxtime.h" + +#if ! (HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME) + +#include "timespec.h" + +/* Get the current time, as a count of the number of nanoseconds since + an arbitrary epoch (e.g., the system boot time). Prefer a + high-resolution clock that is not subject to resetting or + drifting. */ + +xtime_t +gethrxtime (void) +{ +# if HAVE_NANOUPTIME + { + struct timespec ts; + nanouptime (&ts); + return xtime_make (ts.tv_sec, ts.tv_nsec); + } +# else + +# if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME + { + struct timespec ts; + if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0) + return xtime_make (ts.tv_sec, ts.tv_nsec); + } +# endif + +# if HAVE_MICROUPTIME + { + struct timeval tv; + microuptime (&tv); + return xtime_make (tv.tv_sec, 1000 * tv.tv_usec); + } + +# else + /* No monotonically increasing clocks are available; fall back on a + clock that might jump backwards, since it's the best we can do. */ + { + struct timespec ts; + timespec_get(&ts, TIME_UTC); + return xtime_make (ts.tv_sec, ts.tv_nsec); + } +# endif +# endif +} + +#endif diff --git a/contrib/tools/bison/lib/gethrxtime.h b/contrib/tools/bison/lib/gethrxtime.h new file mode 100644 index 00000000000..bb781911e21 --- /dev/null +++ b/contrib/tools/bison/lib/gethrxtime.h @@ -0,0 +1,55 @@ +/* gethrxtime -- get high resolution real time + + Copyright (C) 2005, 2009-2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#ifndef GETHRXTIME_H_ +#define GETHRXTIME_H_ 1 + +#include "xtime.h" + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef GETHRXTIME_INLINE +# define GETHRXTIME_INLINE _GL_INLINE +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Get the current time, as a count of the number of nanoseconds since + an arbitrary epoch (e.g., the system boot time). Prefer a + high-resolution clock that is not subject to resetting or + drifting. */ + +#if HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME +# include <time.h> +GETHRXTIME_INLINE xtime_t gethrxtime (void) { return gethrtime (); } +# else +xtime_t gethrxtime (void); +#endif + +_GL_INLINE_HEADER_END + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/contrib/tools/bison/lib/getprogname.c b/contrib/tools/bison/lib/getprogname.c index 43f37505eab..284581da244 100644 --- a/contrib/tools/bison/lib/getprogname.c +++ b/contrib/tools/bison/lib/getprogname.c @@ -110,9 +110,73 @@ getprogname (void) first = 0; pid_t pid = getpid (); struct pst_status status; - p = (0 < pstat_getproc (&status, sizeof status, 0, pid) - ? strdup (status.pst_ucomm) - : NULL); + if (pstat_getproc (&status, sizeof status, 0, pid) > 0) + { + char *ucomm = status.pst_ucomm; + char *cmd = status.pst_cmd; + if (strlen (ucomm) < PST_UCOMMLEN - 1) + p = ucomm; + else + { + /* ucomm is truncated to length PST_UCOMMLEN - 1. + Look at cmd instead. */ + char *space = strchr (cmd, ' '); + if (space != NULL) + *space = '\0'; + p = strrchr (cmd, '/'); + if (p != NULL) + p++; + else + p = cmd; + if (strlen (p) > PST_UCOMMLEN - 1 + && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0) + /* p is less truncated than ucomm. */ + ; + else + p = ucomm; + } + p = strdup (p); + } + else + { +# if !defined __LP64__ + /* Support for 32-bit programs running in 64-bit HP-UX. + The documented way to do this is to use the same source code + as above, but in a compilation unit where '#define _PSTAT64 1' + is in effect. I prefer a single compilation unit; the struct + size and the offsets are not going to change. */ + char status64[1216]; + if (__pstat_getproc64 (status64, sizeof status64, 0, pid) > 0) + { + char *ucomm = status64 + 288; + char *cmd = status64 + 168; + if (strlen (ucomm) < PST_UCOMMLEN - 1) + p = ucomm; + else + { + /* ucomm is truncated to length PST_UCOMMLEN - 1. + Look at cmd instead. */ + char *space = strchr (cmd, ' '); + if (space != NULL) + *space = '\0'; + p = strrchr (cmd, '/'); + if (p != NULL) + p++; + else + p = cmd; + if (strlen (p) > PST_UCOMMLEN - 1 + && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0) + /* p is less truncated than ucomm. */ + ; + else + p = ucomm; + } + p = strdup (p); + } + else +# endif + p = NULL; + } if (!p) p = "?"; } diff --git a/contrib/tools/bison/lib/intprops.h b/contrib/tools/bison/lib/intprops.h index 15e470cbc6e..cdaf6586cb6 100644 --- a/contrib/tools/bison/lib/intprops.h +++ b/contrib/tools/bison/lib/intprops.h @@ -22,12 +22,13 @@ #include <limits.h> -/* Return a value with the common real type of E and V and the value of V. */ -#define _GL_INT_CONVERT(e, v) (0 * (e) + (v)) +/* Return a value with the common real type of E and V and the value of V. + Do not evaluate E. */ +#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v)) /* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00406.html>. */ -#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v)) +#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v)) /* The extra casts in the following macros work around compiler bugs, e.g., in Cray C 5.0.3.0. */ @@ -40,13 +41,14 @@ #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) /* Return 1 if the real expression E, after promotion, has a - signed or floating type. */ + signed or floating type. Do not evaluate E. */ #define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0) /* Minimum and maximum values for integer types and expressions. */ /* The width in bits of the integer type or expression T. + Do not evaluate T. Padding bits are not supported; this is checked at compile-time below. */ #define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT) @@ -58,7 +60,7 @@ : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1))) /* The maximum and minimum values for the type of the expression E, - after integer promotion. E should not have side effects. */ + after integer promotion. E is not evaluated. */ #define _GL_INT_MINIMUM(e) \ (EXPR_SIGNED (e) \ ? ~ _GL_SIGNED_INT_MAXIMUM (e) \ @@ -340,8 +342,8 @@ Arguments should be free of side effects. */ #define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ op_result_overflow (a, b, \ - _GL_INT_MINIMUM (0 * (b) + (a)), \ - _GL_INT_MAXIMUM (0 * (b) + (a))) + _GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \ + _GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b))) /* Store the low-order bits of A + B, A - B, A * B, respectively, into *R. Return 1 if the result overflows. See above for restrictions. */ diff --git a/contrib/tools/bison/lib/lbitset.c b/contrib/tools/bison/lib/lbitset.c index 2ad6957d8b4..705000929f7 100644 --- a/contrib/tools/bison/lib/lbitset.c +++ b/contrib/tools/bison/lib/lbitset.c @@ -22,12 +22,13 @@ #include "lbitset.h" -#include "obstack.h" #include <stddef.h> -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> +#include "obstack.h" + /* This file implements linked-list bitsets. These bitsets can be of arbitrary length and are more efficient than arrays of bits for large sparse sets. @@ -108,21 +109,21 @@ lbitset_elt_alloc (void) /* Let particular systems override the size of a chunk. */ #ifndef OBSTACK_CHUNK_SIZE -#define OBSTACK_CHUNK_SIZE 0 +# define OBSTACK_CHUNK_SIZE 0 #endif /* Let them override the alloc and free routines too. */ #ifndef OBSTACK_CHUNK_ALLOC -#define OBSTACK_CHUNK_ALLOC xmalloc +# define OBSTACK_CHUNK_ALLOC xmalloc #endif #ifndef OBSTACK_CHUNK_FREE -#define OBSTACK_CHUNK_FREE free +# define OBSTACK_CHUNK_FREE free #endif #if ! defined __GNUC__ || __GNUC__ < 2 -#define __alignof__(type) 0 +# define __alignof__(type) 0 #endif obstack_specify_allocation (&lbitset_obstack, OBSTACK_CHUNK_SIZE, @@ -145,9 +146,7 @@ lbitset_elt_alloc (void) static inline lbitset_elt * lbitset_elt_calloc (void) { - lbitset_elt *elt; - - elt = lbitset_elt_alloc (); + lbitset_elt *elt = lbitset_elt_alloc (); memset (elt->words, 0, sizeof (elt->words)); return elt; } @@ -210,8 +209,6 @@ lbitset_elt_unlink (bitset bset, lbitset_elt *elt) static inline void lbitset_prune (bitset bset, lbitset_elt *elt) { - lbitset_elt *next; - if (!elt) return; @@ -230,6 +227,7 @@ lbitset_prune (bitset bset, lbitset_elt *elt) bset->b.csize = 0; } + lbitset_elt *next; for (; elt; elt = next) { next = elt->next; @@ -242,12 +240,9 @@ lbitset_prune (bitset bset, lbitset_elt *elt) static inline bool lbitset_elt_zero_p (lbitset_elt *elt) { - int i; - - for (i = 0; i < LBITSET_ELT_WORDS; i++) + for (int i = 0; i < LBITSET_ELT_WORDS; i++) if (elt->words[i]) return false; - return true; } @@ -257,13 +252,8 @@ static inline void lbitset_elt_link (bitset bset, lbitset_elt *elt) { bitset_windex windex = elt->index; - lbitset_elt *ptr; - lbitset_elt *current; - if (bset->b.csize) - current = LBITSET_CURRENT (bset); - else - current = LBITSET_HEAD (bset); + lbitset_elt *current = bset->b.csize ? LBITSET_CURRENT (bset) : LBITSET_HEAD (bset); /* If this is the first and only element, add it in. */ if (LBITSET_HEAD (bset) == 0) @@ -277,6 +267,7 @@ lbitset_elt_link (bitset bset, lbitset_elt *elt) somewhere before the current element. */ else if (windex < bset->b.cindex) { + lbitset_elt *ptr; for (ptr = current; ptr->prev && ptr->prev->index > windex; ptr = ptr->prev) continue; @@ -294,6 +285,7 @@ lbitset_elt_link (bitset bset, lbitset_elt *elt) /* Otherwise, it must go somewhere after the current element. */ else { + lbitset_elt *ptr; for (ptr = current; ptr->next && ptr->next->index < windex; ptr = ptr->next) continue; @@ -319,7 +311,6 @@ static lbitset_elt * lbitset_elt_find (bitset bset, bitset_windex windex, enum lbitset_find_mode mode) { - lbitset_elt *elt; lbitset_elt *current; if (bset->b.csize) @@ -336,6 +327,7 @@ lbitset_elt_find (bitset bset, bitset_windex windex, if (current) { + lbitset_elt *elt; if (windex < bset->b.cindex) { for (elt = current; @@ -371,8 +363,7 @@ lbitset_elt_find (bitset bset, bitset_windex windex, case LBITSET_CREATE: windex -= windex % LBITSET_ELT_WORDS; - - elt = lbitset_elt_calloc (); + lbitset_elt *elt = lbitset_elt_calloc (); elt->index = windex; lbitset_elt_link (bset, elt); return elt; @@ -387,10 +378,8 @@ lbitset_elt_find (bitset bset, bitset_windex windex, static inline void lbitset_weed (bitset bset) { - lbitset_elt *elt; lbitset_elt *next; - - for (elt = LBITSET_HEAD (bset); elt; elt = next) + for (lbitset_elt *elt = LBITSET_HEAD (bset); elt; elt = next) { next = elt->next; if (lbitset_elt_zero_p (elt)) @@ -403,9 +392,7 @@ lbitset_weed (bitset bset) static void lbitset_zero (bitset bset) { - lbitset_elt *head; - - head = LBITSET_HEAD (bset); + lbitset_elt *head = LBITSET_HEAD (bset); if (!head) return; @@ -418,22 +405,20 @@ lbitset_zero (bitset bset) static inline bool lbitset_equal_p (bitset dst, bitset src) { - lbitset_elt *selt; - lbitset_elt *delt; - int j; - if (src == dst) return true; lbitset_weed (src); lbitset_weed (dst); + lbitset_elt *selt; + lbitset_elt *delt; for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst); selt && delt; selt = selt->next, delt = delt->next) { if (selt->index != delt->index) return false; - for (j = 0; j < LBITSET_ELT_WORDS; j++) + for (int j = 0; j < LBITSET_ELT_WORDS; j++) if (delt->words[j] != selt->words[j]) return false; } @@ -445,22 +430,18 @@ lbitset_equal_p (bitset dst, bitset src) static inline void lbitset_copy (bitset dst, bitset src) { - lbitset_elt *elt; - lbitset_elt *head; - lbitset_elt *prev; - lbitset_elt *tmp; - if (src == dst) return; lbitset_zero (dst); - head = LBITSET_HEAD (src); + lbitset_elt *head = LBITSET_HEAD (src); if (!head) return; - prev = 0; - for (elt = head; elt; elt = elt->next) + lbitset_elt *prev = 0; + lbitset_elt *tmp; + for (lbitset_elt *elt = head; elt; elt = elt->next) { tmp = lbitset_elt_alloc (); tmp->index = elt->index; @@ -507,10 +488,10 @@ lbitset_copy_cmp (bitset dst, bitset src) static bitset_bindex lbitset_resize (bitset src, bitset_bindex size) { - BITSET_NBITS_ (src) = size; + BITSET_NBITS_ (src) = size; - /* Need to prune any excess bits. FIXME. */ - return size; + /* Need to prune any excess bits. FIXME. */ + return size; } /* Set bit BITNO in bitset DST. */ @@ -569,29 +550,19 @@ static bitset_bindex lbitset_list_reverse (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex rbitno; - bitset_bindex bitno; - unsigned bcount; - bitset_bindex boffset; - bitset_windex windex; - bitset_bindex count; - lbitset_elt *elt; - bitset_word word; - bitset_bindex n_bits; - - elt = LBITSET_TAIL (bset); + lbitset_elt *elt = LBITSET_TAIL (bset); if (!elt) return 0; - n_bits = (elt->index + LBITSET_ELT_WORDS) * BITSET_WORD_BITS; - rbitno = *next; + bitset_bindex n_bits = (elt->index + LBITSET_ELT_WORDS) * BITSET_WORD_BITS; + bitset_bindex rbitno = *next; if (rbitno >= n_bits) return 0; - bitno = n_bits - (rbitno + 1); + bitset_bindex bitno = n_bits - (rbitno + 1); - windex = bitno / BITSET_WORD_BITS; + bitset_windex windex = bitno / BITSET_WORD_BITS; /* Skip back to starting element. */ for (; elt && elt->index > windex; elt = elt->prev) @@ -600,6 +571,7 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list, if (!elt) return 0; + unsigned bcount; if (windex >= elt->index + LBITSET_ELT_WORDS) { /* We are trying to start in no-mans land so start @@ -612,8 +584,8 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list, bcount = bitno % BITSET_WORD_BITS; } - count = 0; - boffset = windex * BITSET_WORD_BITS; + bitset_bindex count = 0; + bitset_bindex boffset = windex * BITSET_WORD_BITS; /* If num is 1, we could speed things up with a binary search of the word of interest. */ @@ -626,7 +598,7 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list, windex--, boffset -= BITSET_WORD_BITS, bcount = BITSET_WORD_BITS - 1) { - word = + bitset_word word = srcp[windex - elt->index] << (BITSET_WORD_BITS - 1 - bcount); for (; word; bcount--) @@ -658,25 +630,21 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list, /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex lbitset_list (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_windex windex; - bitset_bindex count; - lbitset_elt *elt; - lbitset_elt *head; - bitset_word word; - - head = LBITSET_HEAD (bset); + lbitset_elt *head = LBITSET_HEAD (bset); if (!head) return 0; - bitno = *next; - count = 0; + bitset_windex windex; + lbitset_elt *elt; + + bitset_bindex bitno = *next; + bitset_bindex count = 0; if (!bitno) { @@ -713,7 +681,7 @@ lbitset_list (bitset bset, bitset_bindex *list, for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++) { - word = srcp[windex - elt->index] >> (bitno % BITSET_WORD_BITS); + bitset_word word = srcp[windex - elt->index] >> (bitno % BITSET_WORD_BITS); for (; word; bitno++) { @@ -746,7 +714,6 @@ lbitset_list (bitset bset, bitset_bindex *list, while (elt) { - int i; bitset_word *srcp = elt->words; if ((count + LBITSET_ELT_BITS) < num) @@ -754,7 +721,7 @@ lbitset_list (bitset bset, bitset_bindex *list, /* The coast is clear, plant boot! */ #if LBITSET_ELT_WORDS == 2 - word = srcp[0]; + bitset_word word = srcp[0]; if (word) { if (!(word & 0xffff)) @@ -795,9 +762,9 @@ lbitset_list (bitset bset, bitset_bindex *list, windex++; bitno = windex * BITSET_WORD_BITS; #else - for (i = 0; i < LBITSET_ELT_WORDS; i++) + for (int i = 0; i < LBITSET_ELT_WORDS; i++) { - word = srcp[i]; + bitset_word word = srcp[i]; if (word) { if (!(word & 0xffff)) @@ -827,9 +794,9 @@ lbitset_list (bitset bset, bitset_bindex *list, /* Tread more carefully since we need to check if array overflows. */ - for (i = 0; i < LBITSET_ELT_WORDS; i++) + for (int i = 0; i < LBITSET_ELT_WORDS; i++) { - for (word = srcp[i]; word; bitno++) + for (bitset_word word = srcp[i]; word; bitno++) { if (word & 1) { @@ -870,12 +837,12 @@ lbitset_empty_p (bitset dst) { next = elt->next; if (!lbitset_elt_zero_p (elt)) - return 0; + return false; /* Weed as we go. */ lbitset_elt_unlink (dst, elt); } - return 1; + return true; } @@ -883,21 +850,14 @@ lbitset_empty_p (bitset dst) static inline void lbitset_unused_clear (bitset dst) { - unsigned last_bit; - bitset_bindex n_bits; - - n_bits = BITSET_SIZE_ (dst); - last_bit = n_bits % LBITSET_ELT_BITS; + bitset_bindex n_bits = BITSET_SIZE_ (dst); + unsigned last_bit = n_bits % LBITSET_ELT_BITS; if (last_bit) { - lbitset_elt *elt; - bitset_windex windex; - bitset_word *srcp; - - elt = LBITSET_TAIL (dst); - srcp = elt->words; - windex = n_bits / BITSET_WORD_BITS; + lbitset_elt *elt = LBITSET_TAIL (dst); + bitset_word *srcp = elt->words; + bitset_windex windex = n_bits / BITSET_WORD_BITS; srcp[windex - elt->index] &= ((bitset_word) 1 << last_bit) - 1; windex++; @@ -911,21 +871,18 @@ lbitset_unused_clear (bitset dst) static void lbitset_ones (bitset dst) { - bitset_windex i; - bitset_windex windex; - lbitset_elt *elt; - /* This is a decidedly unfriendly operation for a linked list - bitset! It makes a sparse bitset become dense. An alternative - is to have a flag that indicates that the bitset stores the - complement of what it indicates. */ + bitset! It makes a sparse bitset become dense. An alternative + is to have a flag that indicates that the bitset stores the + complement of what it indicates. */ - windex = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS; + bitset_windex windex + = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS; - for (i = 0; i < windex; i += LBITSET_ELT_WORDS) + for (bitset_windex i = 0; i < windex; i += LBITSET_ELT_WORDS) { /* Create new elements if they cannot be found. */ - elt = lbitset_elt_find (dst, i, LBITSET_CREATE); + lbitset_elt *elt = lbitset_elt_find (dst, i, LBITSET_CREATE); memset (elt->words, -1, sizeof (elt->words)); } @@ -936,27 +893,21 @@ lbitset_ones (bitset dst) static void lbitset_not (bitset dst, bitset src) { - lbitset_elt *selt; - lbitset_elt *delt; - bitset_windex i; - unsigned j; - bitset_windex windex; + bitset_windex windex + = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS; - windex = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS; - - for (i = 0; i < windex; i += LBITSET_ELT_WORDS) + for (bitset_windex i = 0; i < windex; i += LBITSET_ELT_WORDS) { /* Create new elements for dst if they cannot be found or substitute zero elements if src elements not found. */ - selt = lbitset_elt_find (src, i, LBITSET_SUBST); - delt = lbitset_elt_find (dst, i, LBITSET_CREATE); + lbitset_elt *selt = lbitset_elt_find (src, i, LBITSET_SUBST); + lbitset_elt *delt = lbitset_elt_find (dst, i, LBITSET_CREATE); - for (j = 0; j < LBITSET_ELT_WORDS; j++) + for (unsigned j = 0; j < LBITSET_ELT_WORDS; j++) delt->words[j] = ~selt->words[j]; } lbitset_unused_clear (dst); lbitset_weed (dst); - return; } @@ -964,11 +915,7 @@ lbitset_not (bitset dst, bitset src) static bool lbitset_subset_p (bitset dst, bitset src) { - lbitset_elt *selt; - lbitset_elt *delt; - unsigned j; - - for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst); + for (lbitset_elt *selt = LBITSET_HEAD (src), *delt = LBITSET_HEAD (dst); selt || delt; selt = selt->next, delt = delt->next) { if (!selt) @@ -989,7 +936,7 @@ lbitset_subset_p (bitset dst, bitset src) } } - for (j = 0; j < LBITSET_ELT_WORDS; j++) + for (unsigned j = 0; j < LBITSET_ELT_WORDS; j++) if (delt->words[j] != (selt->words[j] | delt->words[j])) return false; } @@ -1001,11 +948,7 @@ lbitset_subset_p (bitset dst, bitset src) static bool lbitset_disjoint_p (bitset dst, bitset src) { - lbitset_elt *selt; - lbitset_elt *delt; - unsigned j; - - for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst); + for (lbitset_elt *selt = LBITSET_HEAD (src), *delt = LBITSET_HEAD (dst); selt && delt; selt = selt->next, delt = delt->next) { if (selt->index != delt->index) @@ -1025,7 +968,7 @@ lbitset_disjoint_p (bitset dst, bitset src) continue; } - for (j = 0; j < LBITSET_ELT_WORDS; j++) + for (unsigned j = 0; j < LBITSET_ELT_WORDS; j++) if (selt->words[j] & delt->words[j]) return false; } @@ -1039,26 +982,20 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) lbitset_elt *selt1 = LBITSET_HEAD (src1); lbitset_elt *selt2 = LBITSET_HEAD (src2); lbitset_elt *delt = LBITSET_HEAD (dst); - bitset_windex windex1; - bitset_windex windex2; - bitset_windex windex; - lbitset_elt *stmp1; - lbitset_elt *stmp2; - lbitset_elt *dtmp; - bitset_word *srcp1; - bitset_word *srcp2; - bitset_word *dstp; bool changed = false; - unsigned i; LBITSET_HEAD (dst) = 0; dst->b.csize = 0; - windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX; - windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX; + bitset_windex windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX; + bitset_windex windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX; while (selt1 || selt2) { + bitset_windex windex; + lbitset_elt *stmp1; + lbitset_elt *stmp2; + /* Figure out whether we need to substitute zero elements for missing links. */ if (windex1 == windex2) @@ -1090,6 +1027,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) /* Find the appropriate element from DST. Begin by discarding elements that we've skipped. */ + lbitset_elt *dtmp; while (delt && delt->index < windex) { changed = true; @@ -1107,16 +1045,16 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) /* Do the operation, and if any bits are set, link it into the linked list. */ - srcp1 = stmp1->words; - srcp2 = stmp2->words; - dstp = dtmp->words; + bitset_word *srcp1 = stmp1->words; + bitset_word *srcp2 = stmp2->words; + bitset_word *dstp = dtmp->words; switch (op) { default: abort (); case BITSET_OP_OR: - for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ | *srcp2++; @@ -1129,7 +1067,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_AND: - for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ & *srcp2++; @@ -1142,7 +1080,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_XOR: - for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ ^ *srcp2++; @@ -1155,7 +1093,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_ANDN: - for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ & ~(*srcp2++); @@ -1196,23 +1134,23 @@ lbitset_and_cmp (bitset dst, bitset src1, bitset src2) { lbitset_elt *selt1 = LBITSET_HEAD (src1); lbitset_elt *selt2 = LBITSET_HEAD (src2); - bool changed; if (!selt2) { lbitset_weed (dst); - changed = !LBITSET_HEAD (dst); + bool changed = !LBITSET_HEAD (dst); lbitset_zero (dst); return changed; } else if (!selt1) { lbitset_weed (dst); - changed = !LBITSET_HEAD (dst); + bool changed = !LBITSET_HEAD (dst); lbitset_zero (dst); return changed; } - return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); + else + return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); } @@ -1228,7 +1166,6 @@ lbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { lbitset_elt *selt1 = LBITSET_HEAD (src1); lbitset_elt *selt2 = LBITSET_HEAD (src2); - bool changed; if (!selt2) { @@ -1237,11 +1174,12 @@ lbitset_andn_cmp (bitset dst, bitset src1, bitset src2) else if (!selt1) { lbitset_weed (dst); - changed = !LBITSET_HEAD (dst); + bool changed = !LBITSET_HEAD (dst); lbitset_zero (dst); return changed; } - return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); + else + return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); } @@ -1259,14 +1197,11 @@ lbitset_or_cmp (bitset dst, bitset src1, bitset src2) lbitset_elt *selt2 = LBITSET_HEAD (src2); if (!selt2) - { - return lbitset_copy_cmp (dst, src1); - } + return lbitset_copy_cmp (dst, src1); else if (!selt1) - { - return lbitset_copy_cmp (dst, src2); - } - return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); + return lbitset_copy_cmp (dst, src2); + else + return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); } @@ -1284,14 +1219,11 @@ lbitset_xor_cmp (bitset dst, bitset src1, bitset src2) lbitset_elt *selt2 = LBITSET_HEAD (src2); if (!selt2) - { - return lbitset_copy_cmp (dst, src1); - } + return lbitset_copy_cmp (dst, src1); else if (!selt1) - { - return lbitset_copy_cmp (dst, src2); - } - return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); + return lbitset_copy_cmp (dst, src2); + else + return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); } @@ -1375,24 +1307,18 @@ lbitset_release_memory (void) void debug_lbitset (bitset bset) { - lbitset_elt *elt; - unsigned i; - if (!bset) return; - for (elt = LBITSET_HEAD (bset); elt; elt = elt->next) + for (lbitset_elt *elt = LBITSET_HEAD (bset); elt; elt = elt->next) { fprintf (stderr, "Elt %lu\n", (unsigned long) elt->index); - for (i = 0; i < LBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++) { - unsigned j; - bitset_word word; - - word = elt->words[i]; + bitset_word word = elt->words[i]; fprintf (stderr, " Word %u:", i); - for (j = 0; j < LBITSET_WORD_BITS; j++) + for (unsigned j = 0; j < LBITSET_WORD_BITS; j++) if ((word & ((bitset_word) 1 << j))) fprintf (stderr, " %u", j); fprintf (stderr, "\n"); diff --git a/contrib/tools/bison/lib/lbitset.h b/contrib/tools/bison/lib/lbitset.h index 4aced06d659..b9d266dafb5 100644 --- a/contrib/tools/bison/lib/lbitset.h +++ b/contrib/tools/bison/lib/lbitset.h @@ -23,10 +23,10 @@ #include "bitset.h" -extern size_t lbitset_bytes (bitset_bindex); +size_t lbitset_bytes (bitset_bindex); -extern bitset lbitset_init (bitset, bitset_bindex); +bitset lbitset_init (bitset, bitset_bindex); -extern void lbitset_release_memory (void); +void lbitset_release_memory (void); #endif diff --git a/contrib/tools/bison/lib/libiberty.h b/contrib/tools/bison/lib/libiberty.h deleted file mode 100644 index 7628fc1298c..00000000000 --- a/contrib/tools/bison/lib/libiberty.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Fake libiberty.h for Bison. - - Copyright (C) 2002-2004, 2009-2015, 2018 Free Software Foundation, - Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. */ - - -/* Bison depends on libiberty's implementation of bitsets, which - requires a 'libiberty.h' file. This file provides the minimum - services. */ - -#ifndef BISON_LIBIBERTY_H_ -# define BISON_LIBIBERTY_H_ 1 - -# ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) -# define __attribute__(x) -# endif -# endif - -# define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) - -# include "xalloc.h" - -#endif /* ! BISON_LIBIBERTY_H_ */ diff --git a/contrib/tools/bison/lib/localtime-buffer.c b/contrib/tools/bison/lib/localtime-buffer.c new file mode 100644 index 00000000000..df11f4321db --- /dev/null +++ b/contrib/tools/bison/lib/localtime-buffer.c @@ -0,0 +1,58 @@ +/* Provide access to the last buffer returned by localtime() or gmtime(). + + Copyright (C) 2001-2003, 2005-2007, 2009-2018 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <https://www.gnu.org/licenses/>. */ + +/* written by Jim Meyering */ + +#include <config.h> + +/* Specification. */ +#include "localtime-buffer.h" + +#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME + +static struct tm tm_zero_buffer; +struct tm *localtime_buffer_addr = &tm_zero_buffer; + +/* This is a wrapper for localtime. + + On the first call, record the address of the static buffer that + localtime uses for its result. */ + +struct tm * +rpl_localtime (time_t const *timep) +{ + struct tm *tm = localtime (timep); + + if (localtime_buffer_addr == &tm_zero_buffer) + localtime_buffer_addr = tm; + + return tm; +} + +/* Same as above, since gmtime and localtime use the same buffer. */ +struct tm * +rpl_gmtime (time_t const *timep) +{ + struct tm *tm = gmtime (timep); + + if (localtime_buffer_addr == &tm_zero_buffer) + localtime_buffer_addr = tm; + + return tm; +} + +#endif diff --git a/contrib/tools/bison/lib/localtime-buffer.h b/contrib/tools/bison/lib/localtime-buffer.h new file mode 100644 index 00000000000..f381ff0e6de --- /dev/null +++ b/contrib/tools/bison/lib/localtime-buffer.h @@ -0,0 +1,27 @@ +/* Provide access to the last buffer returned by localtime() or gmtime(). + + Copyright (C) 2001-2003, 2005-2007, 2009-2018 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <https://www.gnu.org/licenses/>. */ + +/* written by Jim Meyering */ + +#include <time.h> + +#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME + +/* The address of the last buffer returned by localtime() or gmtime(). */ +extern struct tm *localtime_buffer_addr; + +#endif diff --git a/contrib/tools/bison/lib/path-join.c b/contrib/tools/bison/lib/path-join.c new file mode 100644 index 00000000000..73560b445d6 --- /dev/null +++ b/contrib/tools/bison/lib/path-join.c @@ -0,0 +1,37 @@ +/* Concatenate path components. + Copyright (C) 2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Akim Demaille <[email protected]>. */ + +#include <config.h> + +/* Specification. */ +#include "path-join.h" + +#include <concat-filename.h> /* xconcatenated_filename */ +#include <filename.h> /* IS_ABSOLUTE_PATH */ +#include <xalloc.h> /* xstrdup */ + +char * +xpath_join (const char *path1, const char *path2) +{ + if (!path2 || !*path2) + return xstrdup (path1); + else if (IS_ABSOLUTE_PATH (path2)) + return xstrdup (path2); + else + return xconcatenated_filename (path1, path2, NULL); +} diff --git a/contrib/tools/bison/lib/path-join.h b/contrib/tools/bison/lib/path-join.h new file mode 100644 index 00000000000..baa472a97c8 --- /dev/null +++ b/contrib/tools/bison/lib/path-join.h @@ -0,0 +1,38 @@ +/* Concatenate path components. + Copyright (C) 2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Akim Demaille <[email protected]>. */ + +#ifndef _PATH_JOIN_H +# define _PATH_JOIN_H + +# ifdef __cplusplus +extern "C" { +# endif + + +/* Concatenate two paths together. PATH2 may be null, or empty, or + absolute: do what is right. Return a freshly allocated + filename. */ +char * +xpath_join (const char *path1, const char *path2); + + +# ifdef __cplusplus +} +# endif + +#endif /* _PATH_JOIN_H */ diff --git a/contrib/tools/bison/lib/raise.c b/contrib/tools/bison/lib/raise.c index 3a29339a66a..8a93bea7f77 100644 --- a/contrib/tools/bison/lib/raise.c +++ b/contrib/tools/bison/lib/raise.c @@ -31,27 +31,9 @@ # include "msvc-inval.h" # endif -# undef raise - # if HAVE_MSVC_INVALID_PARAMETER_HANDLER -static int -raise_nothrow (int sig) -{ - int result; - - TRY_MSVC_INVAL - { - result = raise (sig); - } - CATCH_MSVC_INVAL - { - result = -1; - errno = EINVAL; - } - DONE_MSVC_INVAL; - - return result; -} +/* Forward declaration. */ +static int raise_nothrow (int sig); # else # define raise_nothrow raise # endif @@ -61,12 +43,11 @@ raise_nothrow (int sig) # include <unistd.h> -# define rpl_raise raise - #endif int -rpl_raise (int sig) +raise (int sig) +#undef raise { #if GNULIB_defined_signal_blocking && GNULIB_defined_SIGPIPE if (sig == SIGPIPE) @@ -79,3 +60,24 @@ rpl_raise (int sig) return kill (getpid (), sig); #endif } + +#if HAVE_RAISE && HAVE_MSVC_INVALID_PARAMETER_HANDLER +static int +raise_nothrow (int sig) +{ + int result; + + TRY_MSVC_INVAL + { + result = raise (sig); + } + CATCH_MSVC_INVAL + { + result = -1; + errno = EINVAL; + } + DONE_MSVC_INVAL; + + return result; +} +#endif diff --git a/contrib/tools/bison/lib/stat-time.h b/contrib/tools/bison/lib/stat-time.h index 8e787bd3b2d..69ebe85df1d 100644 --- a/contrib/tools/bison/lib/stat-time.h +++ b/contrib/tools/bison/lib/stat-time.h @@ -213,7 +213,7 @@ stat_time_normalize (int result, struct stat *st _GL_UNUSED) #if defined __sun && defined STAT_TIMESPEC if (result == 0) { - long int timespec_resolution = 1000000000; + long int timespec_hz = 1000000000; short int const ts_off[] = { offsetof (struct stat, st_atim), offsetof (struct stat, st_mtim), offsetof (struct stat, st_ctim) }; @@ -221,11 +221,11 @@ stat_time_normalize (int result, struct stat *st _GL_UNUSED) for (i = 0; i < sizeof ts_off / sizeof *ts_off; i++) { struct timespec *ts = (struct timespec *) ((char *) st + ts_off[i]); - long int q = ts->tv_nsec / timespec_resolution; - long int r = ts->tv_nsec % timespec_resolution; + long int q = ts->tv_nsec / timespec_hz; + long int r = ts->tv_nsec % timespec_hz; if (r < 0) { - r += timespec_resolution; + r += timespec_hz; q--; } ts->tv_nsec = r; diff --git a/contrib/tools/bison/lib/timespec.c b/contrib/tools/bison/lib/timespec.c new file mode 100644 index 00000000000..2b6098ed7bd --- /dev/null +++ b/contrib/tools/bison/lib/timespec.c @@ -0,0 +1,3 @@ +#include <config.h> +#define _GL_TIMESPEC_INLINE _GL_EXTERN_INLINE +#include "timespec.h" diff --git a/contrib/tools/bison/lib/timespec.h b/contrib/tools/bison/lib/timespec.h new file mode 100644 index 00000000000..cc49668f42a --- /dev/null +++ b/contrib/tools/bison/lib/timespec.h @@ -0,0 +1,136 @@ +/* timespec -- System time interface + + Copyright (C) 2000, 2002, 2004-2005, 2007, 2009-2018 Free Software + Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +#if ! defined TIMESPEC_H +#define TIMESPEC_H + +#include <time.h> + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef _GL_TIMESPEC_INLINE +# define _GL_TIMESPEC_INLINE _GL_INLINE +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include "arg-nonnull.h" +#include "verify.h" + +/* Inverse resolution of timespec timestamps (in units per second), + and log base 10 of the inverse resolution. */ + +enum { TIMESPEC_HZ = 1000000000 }; +enum { LOG10_TIMESPEC_HZ = 9 }; + +/* Obsolescent names for backward compatibility. + They are misnomers, because TIMESPEC_RESOLUTION is not a resolution. */ + +enum { TIMESPEC_RESOLUTION = TIMESPEC_HZ }; +enum { LOG10_TIMESPEC_RESOLUTION = LOG10_TIMESPEC_HZ }; + +/* Return a timespec with seconds S and nanoseconds NS. */ + +_GL_TIMESPEC_INLINE struct timespec +make_timespec (time_t s, long int ns) +{ + struct timespec r; + r.tv_sec = s; + r.tv_nsec = ns; + return r; +} + +/* Return negative, zero, positive if A < B, A == B, A > B, respectively. + + For each timestamp T, this code assumes that either: + + * T.tv_nsec is in the range 0..999999999; or + * T.tv_sec corresponds to a valid leap second on a host that supports + leap seconds, and T.tv_nsec is in the range 1000000000..1999999999; or + * T.tv_sec is the minimum time_t value and T.tv_nsec is -1; or + T.tv_sec is the maximum time_t value and T.tv_nsec is 2000000000. + This allows for special struct timespec values that are less or + greater than all possible valid timestamps. + + In all these cases, it is safe to subtract two tv_nsec values and + convert the result to integer without worrying about overflow on + any platform of interest to the GNU project, since all such + platforms have 32-bit int or wider. + + Replacing "a.tv_nsec - b.tv_nsec" with something like + "a.tv_nsec < b.tv_nsec ? -1 : a.tv_nsec > b.tv_nsec" would cause + this function to work in some cases where the above assumption is + violated, but not in all cases (e.g., a.tv_sec==1, a.tv_nsec==-2, + b.tv_sec==0, b.tv_nsec==999999999) and is arguably not worth the + extra instructions. Using a subtraction has the advantage of + detecting some invalid cases on platforms that detect integer + overflow. */ + +_GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE +timespec_cmp (struct timespec a, struct timespec b) +{ + if (a.tv_sec < b.tv_sec) + return -1; + if (a.tv_sec > b.tv_sec) + return 1; + + /* Pacify gcc -Wstrict-overflow (bleeding-edge circa 2017-10-02). See: + https://lists.gnu.org/r/bug-gnulib/2017-10/msg00006.html */ + assume (-1 <= a.tv_nsec && a.tv_nsec <= 2 * TIMESPEC_HZ); + assume (-1 <= b.tv_nsec && b.tv_nsec <= 2 * TIMESPEC_HZ); + + return a.tv_nsec - b.tv_nsec; +} + +/* Return -1, 0, 1, depending on the sign of A. A.tv_nsec must be + nonnegative. */ +_GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE +timespec_sign (struct timespec a) +{ + return a.tv_sec < 0 ? -1 : a.tv_sec || a.tv_nsec; +} + +struct timespec timespec_add (struct timespec, struct timespec) + _GL_ATTRIBUTE_CONST; +struct timespec timespec_sub (struct timespec, struct timespec) + _GL_ATTRIBUTE_CONST; +struct timespec dtotimespec (double) + _GL_ATTRIBUTE_CONST; + +/* Return an approximation to A, of type 'double'. */ +_GL_TIMESPEC_INLINE double +timespectod (struct timespec a) +{ + return a.tv_sec + a.tv_nsec / 1e9; +} + +struct timespec current_timespec (void); +void gettime (struct timespec *) _GL_ARG_NONNULL ((1)); +int settime (struct timespec const *) _GL_ARG_NONNULL ((1)); + +#ifdef __cplusplus +} +#endif + +_GL_INLINE_HEADER_END + +#endif diff --git a/contrib/tools/bison/lib/timevar.c b/contrib/tools/bison/lib/timevar.c index e780c303fca..46b8a689b45 100644 --- a/contrib/tools/bison/lib/timevar.c +++ b/contrib/tools/bison/lib/timevar.c @@ -20,121 +20,21 @@ #include <config.h> -#if IN_GCC - -#error #include "system.h" -#include "intl.h" -#include "rtl.h" - -#else - -/* This source file is taken from the GCC source code, with slight - modifications that are under control of the IN_GCC preprocessor - variable. The !IN_GCC part of this file is specific to Bison. */ - -# include "../src/system.h" -# if HAVE_SYS_TIME_H -# include <sys/time.h> -# endif -int timevar_report = 0; - -#endif - - -#ifdef HAVE_SYS_TIMES_H -# include <sys/times.h> -#endif -#ifdef HAVE_SYS_RESOURCE_H -#include <sys/resource.h> -#endif +/* Specification. */ +#include "timevar.h" -#ifndef HAVE_CLOCK_T -typedef int clock_t; -#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> -#ifndef HAVE_STRUCT_TMS -struct tms -{ - clock_t tms_utime; - clock_t tms_stime; - clock_t tms_cutime; - clock_t tms_cstime; -}; -#endif - -#if defined HAVE_DECL_GETRUSAGE && !HAVE_DECL_GETRUSAGE -extern int getrusage (int, struct rusage *); -#endif -#if defined HAVE_DECL_TIMES && !HAVE_DECL_TIMES -extern clock_t times (struct tms *); -#endif -#if defined HAVE_DECL_CLOCK && !HAVE_DECL_CLOCK -extern clock_t clock (void); -#endif - -#ifndef RUSAGE_SELF -# define RUSAGE_SELF 0 -#endif - -/* Calculation of scale factor to convert ticks to microseconds. - We mustn't use CLOCKS_PER_SEC except with clock(). */ -#if HAVE_SYSCONF && defined _SC_CLK_TCK -# define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */ -#else -# ifdef CLK_TCK -# define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */ -# else -# ifdef HZ -# define TICKS_PER_SECOND HZ /* traditional UNIX */ -# else -# define TICKS_PER_SECOND 100 /* often the correct value */ -# endif -# endif -#endif - -/* Prefer times to getrusage to clock (each gives successively less - information). */ -#ifdef HAVE_TIMES -# define USE_TIMES -# define HAVE_USER_TIME -# define HAVE_SYS_TIME -# define HAVE_WALL_TIME -#else -#ifdef HAVE_GETRUSAGE -# define USE_GETRUSAGE -# define HAVE_USER_TIME -# define HAVE_SYS_TIME -#else -#ifdef HAVE_CLOCK -# define USE_CLOCK -# define HAVE_USER_TIME -#endif -#endif -#endif - -/* libc is very likely to have snuck a call to sysconf() into one of - the underlying constants, and that can be very slow, so we have to - precompute them. Whose wonderful idea was it to make all those - _constants_ variable at run time, anyway? */ -#ifdef USE_TIMES -static float ticks_to_msec; -#define TICKS_TO_MSEC (1.0 / TICKS_PER_SECOND) -#endif - -#ifdef USE_CLOCK -static float clocks_to_msec; -#define CLOCKS_TO_MSEC (1.0 / CLOCKS_PER_SEC) -#endif - -#if IN_GCC -#include "flags.h" -#endif -#include "timevar.h" +#include "gethrxtime.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) +#include "xalloc.h" /* See timevar.h for an explanation of timing variables. */ -/* This macro evaluates to nonzero if timing variables are enabled. */ -#define TIMEVAR_ENABLE (timevar_report) +int timevar_enabled = 0; /* A timing variable. */ @@ -187,73 +87,60 @@ static struct timevar_stack_def *unused_stack_instances; element. */ static struct timevar_time_def start_time; -static void get_time (struct timevar_time_def *); -static void timevar_accumulate (struct timevar_time_def *, - struct timevar_time_def *, - struct timevar_time_def *); - -/* Fill the current times into TIME. The definition of this function - also defines any or all of the HAVE_USER_TIME, HAVE_SYS_TIME, and - HAVE_WALL_TIME macros. */ +/* Fill the current times into TIME. */ static void -get_time (now) - struct timevar_time_def *now; +set_to_current_time (struct timevar_time_def *now) { now->user = 0; now->sys = 0; now->wall = 0; - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; + /* + struct rusage self; + getrusage (RUSAGE_SELF, &self); + struct rusage chld; + getrusage (RUSAGE_CHILDREN, &chld); + + now->user = + xtime_make (self.ru_utime.tv_sec + chld.ru_utime.tv_sec, + (self.ru_utime.tv_usec + chld.ru_utime.tv_usec) * 1000); + + now->sys = + xtime_make (self.ru_stime.tv_sec + chld.ru_stime.tv_sec, + (self.ru_stime.tv_usec + chld.ru_stime.tv_usec) * 1000); + */ + now->wall = gethrxtime(); +} + +/* Return the current time. */ - { -#ifdef USE_TIMES - struct tms tms; - now->wall = times (&tms) * ticks_to_msec; -#if IN_GCC - now->user = tms.tms_utime * ticks_to_msec; - now->sys = tms.tms_stime * ticks_to_msec; -#else - now->user = (tms.tms_utime + tms.tms_cutime) * ticks_to_msec; - now->sys = (tms.tms_stime + tms.tms_cstime) * ticks_to_msec; -#endif -#endif -#ifdef USE_GETRUSAGE - struct rusage rusage; -#if IN_GCC - getrusage (RUSAGE_SELF, &rusage); -#else - getrusage (RUSAGE_CHILDREN, &rusage); -#endif - now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6; - now->sys = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6; -#endif -#ifdef USE_CLOCK - now->user = clock () * clocks_to_msec; -#endif - } +static struct timevar_time_def +get_current_time (void) +{ + struct timevar_time_def now; + set_to_current_time (&now); + return now; } /* Add the difference between STOP and START to TIMER. */ static void -timevar_accumulate (timer, start, stop) - struct timevar_time_def *timer; - struct timevar_time_def *start; - struct timevar_time_def *stop; +timevar_accumulate (struct timevar_time_def *timer, + const struct timevar_time_def *start, + const struct timevar_time_def *stop) { timer->user += stop->user - start->user; timer->sys += stop->sys - start->sys; timer->wall += stop->wall - start->wall; } -/* Initialize timing variables. */ - void -init_timevar () +timevar_init () { - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; /* Zero all elapsed times. */ @@ -264,33 +151,16 @@ init_timevar () timevars[identifier__].name = name__; #include "timevar.def" #undef DEFTIMEVAR - -#ifdef USE_TIMES - ticks_to_msec = TICKS_TO_MSEC; -#endif -#ifdef USE_CLOCK - clocks_to_msec = CLOCKS_TO_MSEC; -#endif } -/* Push TIMEVAR onto the timing stack. No further elapsed time is - attributed to the previous topmost timing variable on the stack; - subsequent elapsed time is attributed to TIMEVAR, until it is - popped or another element is pushed on top. - - TIMEVAR cannot be running as a standalone timer. */ - void -timevar_push (timevar) - timevar_id_t timevar; +timevar_push (timevar_id_t timevar) { - struct timevar_def *tv = &timevars[timevar]; - struct timevar_stack_def *context; - struct timevar_time_def now; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; + struct timevar_def *tv = &timevars[timevar]; + /* Mark this timing variable as used. */ tv->used = 1; @@ -299,7 +169,7 @@ timevar_push (timevar) abort (); /* What time is it? */ - get_time (&now); + struct timevar_time_def const now = get_current_time (); /* If the stack isn't empty, attribute the current elapsed time to the old topmost element. */ @@ -312,6 +182,7 @@ timevar_push (timevar) /* See if we have a previously-allocated stack instance. If so, take it off the list. If not, malloc a new one. */ + struct timevar_stack_def *context = NULL; if (unused_stack_instances != NULL) { context = unused_stack_instances; @@ -327,29 +198,20 @@ timevar_push (timevar) stack = context; } -/* Pop the topmost timing variable element off the timing stack. The - popped variable must be TIMEVAR. Elapsed time since the that - element was pushed on, or since it was last exposed on top of the - stack when the element above it was popped off, is credited to that - timing variable. */ - void -timevar_pop (timevar) - timevar_id_t timevar; +timevar_pop (timevar_id_t timevar) { - struct timevar_time_def now; - struct timevar_stack_def *popped = stack; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; if (&timevars[timevar] != stack->timevar) abort (); /* What time is it? */ - get_time (&now); + struct timevar_time_def const now = get_current_time (); /* Attribute the elapsed time to the element we're popping. */ + struct timevar_stack_def *popped = stack; timevar_accumulate (&popped->timevar->elapsed, &start_time, &now); /* Reset the start time; from now on, time is attributed to the @@ -365,19 +227,14 @@ timevar_pop (timevar) unused_stack_instances = popped; } -/* Start timing TIMEVAR independently of the timing stack. Elapsed - time until timevar_stop is called for the same timing variable is - attributed to TIMEVAR. */ - void -timevar_start (timevar) - timevar_id_t timevar; +timevar_start (timevar_id_t timevar) { - struct timevar_def *tv = &timevars[timevar]; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; + struct timevar_def *tv = &timevars[timevar]; + /* Mark this timing variable as used. */ tv->used = 1; @@ -387,72 +244,50 @@ timevar_start (timevar) abort (); tv->standalone = 1; - get_time (&tv->start_time); + set_to_current_time (&tv->start_time); } -/* Stop timing TIMEVAR. Time elapsed since timevar_start was called - is attributed to it. */ - void -timevar_stop (timevar) - timevar_id_t timevar; +timevar_stop (timevar_id_t timevar) { - struct timevar_def *tv = &timevars[timevar]; - struct timevar_time_def now; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; + struct timevar_def *tv = &timevars[timevar]; + /* TIMEVAR must have been started via timevar_start. */ if (!tv->standalone) abort (); - get_time (&now); + struct timevar_time_def const now = get_current_time (); timevar_accumulate (&tv->elapsed, &tv->start_time, &now); } -/* Fill the elapsed time for TIMEVAR into ELAPSED. Returns - update-to-date information even if TIMEVAR is currently running. */ - void -timevar_get (timevar, elapsed) - timevar_id_t timevar; - struct timevar_time_def *elapsed; +timevar_get (timevar_id_t timevar, + struct timevar_time_def *elapsed) { struct timevar_def *tv = &timevars[timevar]; - struct timevar_time_def now; - *elapsed = tv->elapsed; /* Is TIMEVAR currently running as a standalone timer? */ if (tv->standalone) { - get_time (&now); + struct timevar_time_def const now = get_current_time (); timevar_accumulate (elapsed, &tv->start_time, &now); } /* Or is TIMEVAR at the top of the timer stack? */ else if (stack->timevar == tv) { - get_time (&now); + struct timevar_time_def const now = get_current_time (); timevar_accumulate (elapsed, &start_time, &now); } } -/* Summarize timing variables to FP. The timing variable TV_TOTAL has - a special meaning -- it's considered to be the total elapsed time, - for normalizing the others, and is displayed last. */ - void -timevar_print (fp) - FILE *fp; +timevar_print (FILE *fp) { - /* Only print stuff if we have some sort of time information. */ -#if defined HAVE_USER_TIME || defined HAVE_SYS_TIME || defined HAVE_WALL_TIME - unsigned /* timevar_id_t */ id; - struct timevar_time_def *total = &timevars[TV_TOTAL].elapsed; - struct timevar_time_def now; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; /* Update timing information in case we're calling this from GDB. */ @@ -461,7 +296,7 @@ timevar_print (fp) fp = stderr; /* What time is it? */ - get_time (&now); + struct timevar_time_def const now = get_current_time (); /* If the stack isn't empty, attribute the current elapsed time to the old topmost element. */ @@ -472,94 +307,42 @@ timevar_print (fp) TIMEVAR. */ start_time = now; - fputs (_("\nExecution times (seconds)\n"), fp); - for (id = 0; id < (unsigned) TIMEVAR_LAST; ++id) - { - struct timevar_def *tv = &timevars[(timevar_id_t) id]; - const float tiny = 5e-3; + struct timevar_time_def const* total = &timevars[tv_total].elapsed; + fprintf (fp, "%-22s\n", + _("Execution times (seconds)")); + fprintf (fp, " %-22s %-13s %-13s %-16s\n", + "", _("CPU user"), _("CPU system"), _("wall clock")); + for (unsigned /* timevar_id_t */ id = 0; id < (unsigned) TIMEVAR_LAST; ++id) + { /* Don't print the total execution time here; that goes at the end. */ - if ((timevar_id_t) id == TV_TOTAL) + if ((timevar_id_t) id == tv_total) continue; /* Don't print timing variables that were never used. */ + struct timevar_def *tv = &timevars[(timevar_id_t) id]; if (!tv->used) continue; - /* Don't print timing variables if we're going to get a row of - zeroes. */ - if (tv->elapsed.user < tiny - && tv->elapsed.sys < tiny - && tv->elapsed.wall < tiny) + /* Percentages. */ + const int usr = total->user ? tv->elapsed.user * 100 / total->user : 0; + const int sys = total->sys ? tv->elapsed.sys * 100 / total->sys : 0; + const int wall = total->wall ? tv->elapsed.wall * 100 / total->wall : 0; + + /* Ignore insignificant lines. */ + if (!usr && !sys && !wall) continue; - /* The timing variable name. */ - fprintf (fp, " %-22s:", tv->name); - -#ifdef HAVE_USER_TIME - /* Print user-mode time for this process. */ - fprintf (fp, "%7.2f (%2.0f%%) usr", - tv->elapsed.user, - (total->user == 0 ? 0 : tv->elapsed.user / total->user) * 100); -#endif /* HAVE_USER_TIME */ - -#ifdef HAVE_SYS_TIME - /* Print system-mode time for this process. */ - fprintf (fp, "%7.2f (%2.0f%%) sys", - tv->elapsed.sys, - (total->sys == 0 ? 0 : tv->elapsed.sys / total->sys) * 100); -#endif /* HAVE_SYS_TIME */ - -#ifdef HAVE_WALL_TIME - /* Print wall clock time elapsed. */ - fprintf (fp, "%7.2f (%2.0f%%) wall", - tv->elapsed.wall, - (total->wall == 0 ? 0 : tv->elapsed.wall / total->wall) * 100); -#endif /* HAVE_WALL_TIME */ - - putc ('\n', fp); + fprintf (fp, " %-22s", tv->name); + fprintf (fp, "%8.3f (%2d%%)", tv->elapsed.user * 1e-9, usr); + fprintf (fp, "%8.3f (%2d%%)", tv->elapsed.sys * 1e-9, sys); + fprintf (fp, "%11.6f (%2d%%)\n", tv->elapsed.wall * 1e-9, wall); } /* Print total time. */ - fputs (_(" TOTAL :"), fp); -#ifdef HAVE_USER_TIME - fprintf (fp, "%7.2f ", total->user); -#endif -#ifdef HAVE_SYS_TIME - fprintf (fp, "%7.2f ", total->sys); -#endif -#ifdef HAVE_WALL_TIME - fprintf (fp, "%7.2f\n", total->wall); -#endif - -#endif /* defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME) - || defined (HAVE_WALL_TIME) */ -} - -/* Returns time (user + system) used so far by the compiler process, - in microseconds. */ - -long -get_run_time () -{ - struct timevar_time_def total_elapsed; - timevar_get (TV_TOTAL, &total_elapsed); - return total_elapsed.user + total_elapsed.sys; -} - -/* Prints a message to stderr stating that time elapsed in STR is - TOTAL (given in microseconds). */ - -void -print_time (str, total) - const char *str; - long total; -{ - long all_time = get_run_time (); - fprintf (stderr, - _("time in %s: %ld.%06ld (%ld%%)\n"), - str, total / 1000000, total % 1000000, - all_time == 0 ? 0 - : (long) (((100.0 * (double) total) / (double) all_time) + .5)); + fprintf (fp, " %-22s", timevars[tv_total].name); + fprintf (fp, "%8.3f ", total->user * 1e-9); + fprintf (fp, "%8.3f ", total->sys * 1e-9); + fprintf (fp, "%11.6f\n", total->wall * 1e-9); } diff --git a/contrib/tools/bison/lib/timevar.def b/contrib/tools/bison/lib/timevar.def index 01eaba70765..00d0cd3391b 100644 --- a/contrib/tools/bison/lib/timevar.def +++ b/contrib/tools/bison/lib/timevar.def @@ -28,35 +28,35 @@ DEFTIMEVAR (id, name) - where ID is the enumeral value used to identify the timing + where ID is the enum value used to identify the timing variable, and NAME is a character string describing its purpose. */ /* The total execution time. */ -DEFTIMEVAR (TV_TOTAL , "total time") +DEFTIMEVAR (tv_total , "total time") /* Time spent in the reader. */ -DEFTIMEVAR (TV_READER , "reader") -DEFTIMEVAR (TV_SCANNING , "scanner") -DEFTIMEVAR (TV_PARSING , "parser") +DEFTIMEVAR (tv_reader , "reader") +DEFTIMEVAR (tv_scanning , "scanner") +DEFTIMEVAR (tv_parsing , "parser") /* Time spent handling the grammar. */ -DEFTIMEVAR (TV_REDUCE , "reducing the grammar") -DEFTIMEVAR (TV_SETS , "computing the sets") -DEFTIMEVAR (TV_LR0 , "LR(0)") -DEFTIMEVAR (TV_LALR , "LALR(1)") -DEFTIMEVAR (TV_IELR_PHASE1 , "IELR(1) Phase 1") -DEFTIMEVAR (TV_IELR_PHASE2 , "IELR(1) Phase 2") -DEFTIMEVAR (TV_IELR_PHASE3 , "IELR(1) Phase 3") -DEFTIMEVAR (TV_IELR_PHASE4 , "IELR(1) Phase 4") -DEFTIMEVAR (TV_CONFLICTS , "conflicts") - -/* Time spent outputing results. */ -DEFTIMEVAR (TV_REPORT , "outputing report") -DEFTIMEVAR (TV_GRAPH , "outputing graph") -DEFTIMEVAR (TV_XML , "outputing xml") -DEFTIMEVAR (TV_ACTIONS , "parser action tables") -DEFTIMEVAR (TV_PARSER , "outputing parser") -DEFTIMEVAR (TV_M4 , "running m4") +DEFTIMEVAR (tv_reduce , "reducing the grammar") +DEFTIMEVAR (tv_sets , "computing the sets") +DEFTIMEVAR (tv_lr0 , "LR(0)") +DEFTIMEVAR (tv_lalr , "LALR(1)") +DEFTIMEVAR (tv_ielr_phase1 , "IELR(1) Phase 1") +DEFTIMEVAR (tv_ielr_phase2 , "IELR(1) Phase 2") +DEFTIMEVAR (tv_ielr_phase3 , "IELR(1) Phase 3") +DEFTIMEVAR (tv_ielr_phase4 , "IELR(1) Phase 4") +DEFTIMEVAR (tv_conflicts , "conflicts") + +/* Time spent outputting results. */ +DEFTIMEVAR (tv_report , "outputting report") +DEFTIMEVAR (tv_graph , "outputting graph") +DEFTIMEVAR (tv_xml , "outputting xml") +DEFTIMEVAR (tv_actions , "parser action tables") +DEFTIMEVAR (tv_parser , "outputting parser") +DEFTIMEVAR (tv_m4 , "running m4") /* Time spent by freeing the memory :). */ -DEFTIMEVAR (TV_FREE , "freeing") +DEFTIMEVAR (tv_free , "freeing") diff --git a/contrib/tools/bison/lib/timevar.h b/contrib/tools/bison/lib/timevar.h index 14366c9628c..cf9e0830d15 100644 --- a/contrib/tools/bison/lib/timevar.h +++ b/contrib/tools/bison/lib/timevar.h @@ -1,4 +1,4 @@ -/* Timing variables for measuring compiler performance. +/* Timing variables for measuring application performance. Copyright (C) 2000, 2002, 2004, 2009-2015, 2018 Free Software Foundation, Inc. @@ -18,11 +18,19 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef GCC_TIMEVAR_H -#define GCC_TIMEVAR_H +#ifndef _TIMEVAR_H +# define _TIMEVAR_H 1 + +# include <stdio.h> + +# include "xtime.h" + +# ifdef __cplusplus +extern "C" { +# endif /* Timing variables are used to measure elapsed time in various - portions of the compiler. Each measures elapsed user, system, and + portions of the application. Each measures elapsed user, system, and wall-clock time, as appropriate to and supported by the host system. @@ -52,14 +60,14 @@ struct timevar_time_def { /* User time in this process. */ - float user; + xtime_t user; /* System time (if applicable for this host platform) in this process. */ - float sys; + xtime_t sys; /* Wall clock time. */ - float wall; + xtime_t wall; }; /* An enumeration of timing variable identifiers. Constructed from @@ -75,18 +83,56 @@ typedef enum timevar_id_t; #undef DEFTIMEVAR -extern void init_timevar (void); -extern void timevar_push (timevar_id_t); -extern void timevar_pop (timevar_id_t); -extern void timevar_start (timevar_id_t); -extern void timevar_stop (timevar_id_t); -extern void timevar_get (timevar_id_t, struct timevar_time_def *); -extern void timevar_print (FILE *); +/* Initialize timing variables. */ + +void timevar_init (void); + +/* Push TIMEVAR onto the timing stack. No further elapsed time is + attributed to the previous topmost timing variable on the stack; + subsequent elapsed time is attributed to TIMEVAR, until it is + popped or another element is pushed on top. + + TIMEVAR cannot be running as a standalone timer. */ + +void timevar_push (timevar_id_t timevar); + +/* Pop the topmost timing variable element off the timing stack. The + popped variable must be TIMEVAR. Elapsed time since the that + element was pushed on, or since it was last exposed on top of the + stack when the element above it was popped off, is credited to that + timing variable. */ + +void timevar_pop (timevar_id_t timevar); + +/* Start timing TIMEVAR independently of the timing stack. Elapsed + time until timevar_stop is called for the same timing variable is + attributed to TIMEVAR. */ -/* Provided for backward compatibility. */ -extern long get_run_time (void); -extern void print_time (const char *, long); +void timevar_start (timevar_id_t timevar); -extern int timevar_report; +/* Stop timing TIMEVAR. Time elapsed since timevar_start was called + is attributed to it. */ + +void timevar_stop (timevar_id_t timevar); + +/* Fill the elapsed time for TIMEVAR into ELAPSED. Returns + update-to-date information even if TIMEVAR is currently running. */ + +void timevar_get (timevar_id_t timevar, struct timevar_time_def *elapsed); + +/* Summarize timing variables to FP. The timing variable TV_TOTAL has + a special meaning -- it's considered to be the total elapsed time, + for normalizing the others, and is displayed last. */ + +void timevar_print (FILE *fp); + +/* Set to to nonzero to enable timing variables. All the timevar + functions make an early exit if timevar is disabled. */ + +extern int timevar_enabled; + +# ifdef __cplusplus +} +# endif -#endif /* ! GCC_TIMEVAR_H */ +#endif /* ! _TIMEVAR_H */ diff --git a/contrib/tools/bison/lib/vasnprintf.c b/contrib/tools/bison/lib/vasnprintf.c index 3b441d03b7b..57571750a0b 100644 --- a/contrib/tools/bison/lib/vasnprintf.c +++ b/contrib/tools/bison/lib/vasnprintf.c @@ -860,7 +860,9 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes) size_t a_len = a.nlimbs; /* 0.03345 is slightly larger than log(2)/(9*log(10)). */ size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1); - char *c_ptr = (char *) malloc (xsum (c_len, extra_zeroes)); + /* We need extra_zeroes bytes for zeroes, followed by c_len bytes for the + digits of a, followed by 1 byte for the terminating NUL. */ + char *c_ptr = (char *) malloc (xsum (xsum (extra_zeroes, c_len), 1)); if (c_ptr != NULL) { char *d_ptr = c_ptr; @@ -2694,7 +2696,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, errno = EILSEQ; return NULL; } - if (precision < count) + if (precision < (unsigned int) count) break; arg_end++; characters += count; @@ -5125,7 +5127,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, { /* Verify that snprintf() has NUL-terminated its result. */ - if (count < maxlen + if ((unsigned int) count < maxlen && ((TCHAR_T *) (result + length)) [count] != '\0') abort (); /* Portability hack. */ diff --git a/contrib/tools/bison/lib/vbitset.c b/contrib/tools/bison/lib/vbitset.c index 69d1b76231a..f715f9b4f15 100644 --- a/contrib/tools/bison/lib/vbitset.c +++ b/contrib/tools/bison/lib/vbitset.c @@ -56,19 +56,14 @@ static bitset_bindex vbitset_list_reverse (bitset, bitset_bindex *, static bitset_bindex vbitset_resize (bitset src, bitset_bindex n_bits) { - bitset_windex oldsize; - bitset_windex newsize; - if (n_bits == BITSET_NBITS_ (src)) return n_bits; - oldsize = VBITSET_SIZE (src); - newsize = VBITSET_N_WORDS (n_bits); + bitset_windex oldsize = VBITSET_SIZE (src); + bitset_windex newsize = VBITSET_N_WORDS (n_bits); if (oldsize < newsize) { - bitset_windex size; - /* The bitset needs to grow. If we already have enough memory allocated, then just zero what we need. */ if (newsize > VBITSET_ASIZE (src)) @@ -78,11 +73,7 @@ vbitset_resize (bitset src, bitset_bindex n_bits) grow the bitset 25% larger than requested to reduce number of reallocations. */ - if (oldsize == 0) - size = newsize; - else - size = newsize + newsize / 4; - + bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4; VBITSET_WORDS (src) = realloc (VBITSET_WORDS (src), size * sizeof (bitset_word)); VBITSET_ASIZE (src) = size; @@ -115,9 +106,7 @@ vbitset_resize (bitset src, bitset_bindex n_bits) /* Set bit BITNO in bitset DST. */ static void -vbitset_set (dst, bitno) - bitset dst; - bitset_bindex bitno; +vbitset_set (bitset dst, bitset_bindex bitno) { bitset_windex windex = bitno / BITSET_WORD_BITS; @@ -134,9 +123,7 @@ vbitset_set (dst, bitno) /* Reset bit BITNO in bitset DST. */ static void -vbitset_reset (dst, bitno) - bitset dst ATTRIBUTE_UNUSED; - bitset_bindex bitno ATTRIBUTE_UNUSED; +vbitset_reset (bitset dst ATTRIBUTE_UNUSED, bitset_bindex bitno ATTRIBUTE_UNUSED) { /* We must be accessing outside the cache so the bit is zero anyway. */ @@ -145,13 +132,12 @@ vbitset_reset (dst, bitno) /* Test bit BITNO in bitset SRC. */ static bool -vbitset_test (src, bitno) - bitset src ATTRIBUTE_UNUSED; - bitset_bindex bitno ATTRIBUTE_UNUSED; +vbitset_test (bitset src ATTRIBUTE_UNUSED, + bitset_bindex bitno ATTRIBUTE_UNUSED) { /* We must be accessing outside the cache so the bit is zero anyway. */ - return 0; + return false; } @@ -160,22 +146,13 @@ vbitset_test (src, bitno) actual number of bits found and with *NEXT indicating where search stopped. */ static bitset_bindex -vbitset_list_reverse (src, list, num, next) - bitset src; - bitset_bindex *list; - bitset_bindex num; - bitset_bindex *next; +vbitset_list_reverse (bitset src, bitset_bindex *list, + bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex rbitno; - bitset_bindex count; - bitset_windex windex; - unsigned bitcnt; - bitset_bindex bitoff; bitset_word *srcp = VBITSET_WORDS (src); bitset_bindex n_bits = BITSET_SIZE_ (src); - rbitno = *next; + bitset_bindex rbitno = *next; /* If num is 1, we could speed things up with a binary search of the word of interest. */ @@ -183,19 +160,17 @@ vbitset_list_reverse (src, list, num, next) if (rbitno >= n_bits) return 0; - count = 0; + bitset_bindex count = 0; - bitno = n_bits - (rbitno + 1); + bitset_bindex bitno = n_bits - (rbitno + 1); - windex = bitno / BITSET_WORD_BITS; - bitcnt = bitno % BITSET_WORD_BITS; - bitoff = windex * BITSET_WORD_BITS; + bitset_windex windex = bitno / BITSET_WORD_BITS; + unsigned bitcnt = bitno % BITSET_WORD_BITS; + bitset_bindex bitoff = windex * BITSET_WORD_BITS; do { - bitset_word word; - - word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); + bitset_word word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); for (; word; bitcnt--) { if (word & BITSET_MSB) @@ -220,26 +195,21 @@ vbitset_list_reverse (src, list, num, next) /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex -vbitset_list (src, list, num, next) - bitset src; - bitset_bindex *list; - bitset_bindex num; - bitset_bindex *next; +vbitset_list (bitset src, bitset_bindex *list, + bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex count; - bitset_windex windex; - bitset_bindex bitoff; bitset_windex size = VBITSET_SIZE (src); bitset_word *srcp = VBITSET_WORDS (src); - bitset_word word; + bitset_bindex bitno = *next; + bitset_bindex count = 0; - bitno = *next; + bitset_windex windex; + bitset_bindex bitoff; + bitset_word word; - count = 0; if (!bitno) { /* Many bitsets are zero, so make this common case fast. */ @@ -327,12 +297,9 @@ vbitset_list (src, list, num, next) /* Ensure that any unused bits within the last word are clear. */ static inline void -vbitset_unused_clear (dst) - bitset dst; +vbitset_unused_clear (bitset dst) { - unsigned last_bit; - - last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; + unsigned last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; if (last_bit) VBITSET_WORDS (dst)[VBITSET_SIZE (dst) - 1] &= ((bitset_word) 1 << last_bit) - 1; @@ -343,9 +310,7 @@ static void vbitset_ones (bitset dst) { bitset_word *dstp = VBITSET_WORDS (dst); - unsigned bytes; - - bytes = sizeof (bitset_word) * VBITSET_SIZE (dst); + unsigned bytes = sizeof (bitset_word) * VBITSET_SIZE (dst); memset (dstp, -1, bytes); vbitset_unused_clear (dst); @@ -356,9 +321,7 @@ static void vbitset_zero (bitset dst) { bitset_word *dstp = VBITSET_WORDS (dst); - unsigned bytes; - - bytes = sizeof (bitset_word) * VBITSET_SIZE (dst); + unsigned bytes = sizeof (bitset_word) * VBITSET_SIZE (dst); memset (dstp, 0, bytes); } @@ -367,34 +330,27 @@ vbitset_zero (bitset dst) static bool vbitset_empty_p (bitset dst) { - unsigned i; bitset_word *dstp = VBITSET_WORDS (dst); - for (i = 0; i < VBITSET_SIZE (dst); i++) + for (unsigned i = 0; i < VBITSET_SIZE (dst); i++) if (dstp[i]) - return 0; - - return 1; + return false; + return true; } static void vbitset_copy1 (bitset dst, bitset src) { - bitset_word *srcp; - bitset_word *dstp; - bitset_windex ssize; - bitset_windex dsize; - if (src == dst) - return; + return; vbitset_resize (dst, BITSET_SIZE_ (src)); - srcp = VBITSET_WORDS (src); - dstp = VBITSET_WORDS (dst); - ssize = VBITSET_SIZE (src); - dsize = VBITSET_SIZE (dst); + bitset_word *srcp = VBITSET_WORDS (src); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex ssize = VBITSET_SIZE (src); + bitset_windex dsize = VBITSET_SIZE (dst); memcpy (dstp, srcp, sizeof (bitset_word) * ssize); @@ -406,21 +362,15 @@ vbitset_copy1 (bitset dst, bitset src) static void vbitset_not (bitset dst, bitset src) { - unsigned i; - bitset_word *srcp; - bitset_word *dstp; - bitset_windex ssize; - bitset_windex dsize; - vbitset_resize (dst, BITSET_SIZE_ (src)); - srcp = VBITSET_WORDS (src); - dstp = VBITSET_WORDS (dst); - ssize = VBITSET_SIZE (src); - dsize = VBITSET_SIZE (dst); + bitset_word *srcp = VBITSET_WORDS (src); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex ssize = VBITSET_SIZE (src); + bitset_windex dsize = VBITSET_SIZE (dst); - for (i = 0; i < ssize; i++) - *dstp++ = ~(*srcp++); + for (unsigned i = 0; i < ssize; i++) + *dstp++ = ~(*srcp++); vbitset_unused_clear (dst); memset (dstp + sizeof (bitset_word) * ssize, 0, @@ -431,96 +381,87 @@ vbitset_not (bitset dst, bitset src) static bool vbitset_equal_p (bitset dst, bitset src) { - unsigned i; bitset_word *srcp = VBITSET_WORDS (src); bitset_word *dstp = VBITSET_WORDS (dst); bitset_windex ssize = VBITSET_SIZE (src); bitset_windex dsize = VBITSET_SIZE (dst); + unsigned i; for (i = 0; i < min (ssize, dsize); i++) - if (*srcp++ != *dstp++) - return 0; + if (*srcp++ != *dstp++) + return false; if (ssize > dsize) { for (; i < ssize; i++) if (*srcp++) - return 0; + return false; } else { for (; i < dsize; i++) if (*dstp++) - return 0; + return false; } - return 1; + return true; } static bool vbitset_subset_p (bitset dst, bitset src) { - unsigned i; bitset_word *srcp = VBITSET_WORDS (src); bitset_word *dstp = VBITSET_WORDS (dst); bitset_windex ssize = VBITSET_SIZE (src); bitset_windex dsize = VBITSET_SIZE (dst); + unsigned i; for (i = 0; i < min (ssize, dsize); i++, dstp++, srcp++) - if (*dstp != (*srcp | *dstp)) - return 0; + if (*dstp != (*srcp | *dstp)) + return 0; if (ssize > dsize) { for (; i < ssize; i++) if (*srcp++) - return 0; + return false; } - return 1; + return true; } static bool vbitset_disjoint_p (bitset dst, bitset src) { - unsigned i; bitset_word *srcp = VBITSET_WORDS (src); bitset_word *dstp = VBITSET_WORDS (dst); bitset_windex ssize = VBITSET_SIZE (src); bitset_windex dsize = VBITSET_SIZE (dst); - for (i = 0; i < min (ssize, dsize); i++) - if (*srcp++ & *dstp++) - return 0; + for (unsigned i = 0; i < min (ssize, dsize); i++) + if (*srcp++ & *dstp++) + return false; - return 1; + return true; } static void vbitset_and (bitset dst, bitset src1, bitset src2) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); - for (i = 0; i < min (ssize1, ssize2); i++) - *dstp++ = *src1p++ & *src2p++; + for (unsigned i = 0; i < min (ssize1, ssize2); i++) + *dstp++ = *src1p++ & *src2p++; memset (dstp, 0, sizeof (bitset_word) * (dsize - min (ssize1, ssize2))); } @@ -529,31 +470,24 @@ vbitset_and (bitset dst, bitset src1, bitset src2) static bool vbitset_and_cmp (bitset dst, bitset src1, bitset src2) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - + bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { bitset_word tmp = *src1p++ & *src2p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -568,7 +502,7 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2) { if (*dstp != 0) { - changed = 1; + changed = true; *dstp = 0; } } @@ -582,25 +516,18 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2) static void vbitset_andn (bitset dst, bitset src1, bitset src2) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++) - *dstp++ = *src1p++ & ~(*src2p++); + *dstp++ = *src1p++ & ~(*src2p++); if (ssize2 > ssize1) { @@ -622,31 +549,24 @@ vbitset_andn (bitset dst, bitset src1, bitset src2) static bool vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - + bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { bitset_word tmp = *src1p++ & ~(*src2p++); if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -657,7 +577,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { if (*dstp != 0) { - changed = 1; + changed = true; *dstp = 0; } } @@ -672,7 +592,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -687,25 +607,18 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) static void vbitset_or (bitset dst, bitset src1, bitset src2) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++) - *dstp++ = *src1p++ | *src2p++; + *dstp++ = *src1p++ | *src2p++; if (ssize2 > ssize1) { @@ -723,31 +636,25 @@ vbitset_or (bitset dst, bitset src1, bitset src2) static bool vbitset_or_cmp (bitset dst, bitset src1, bitset src2) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; + bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { bitset_word tmp = *src1p++ | *src2p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -764,7 +671,7 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -778,25 +685,18 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2) static void vbitset_xor (bitset dst, bitset src1, bitset src2) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++) - *dstp++ = *src1p++ ^ *src2p++; + *dstp++ = *src1p++ ^ *src2p++; if (ssize2 > ssize1) { @@ -814,31 +714,24 @@ vbitset_xor (bitset dst, bitset src1, bitset src2) static bool vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - + bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { bitset_word tmp = *src1p++ ^ *src2p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -855,7 +748,7 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -872,13 +765,6 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) static void vbitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) { @@ -888,47 +774,40 @@ vbitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3) vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & *src2p++) | *src3p++; + for (unsigned i = 0; i < size; i++) + *dstp++ = (*src1p++ & *src2p++) | *src3p++; } static bool vbitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) return bitset_and_or_cmp_ (dst, src1, src2, src3); vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++, dstp++) + bool changed = false; + for (unsigned i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & *src2p++) | *src3p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -939,13 +818,6 @@ vbitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void vbitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) { @@ -955,47 +827,40 @@ vbitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; + for (unsigned i = 0; i < size; i++) + *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; } static bool vbitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) return bitset_andn_or_cmp_ (dst, src1, src2, src3); vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++, dstp++) + bool changed = false; + for (unsigned i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1006,13 +871,6 @@ vbitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void vbitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) { @@ -1022,47 +880,41 @@ vbitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3) vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ | *src2p++) & *src3p++; + for (unsigned i = 0; i < size; i++) + *dstp++ = (*src1p++ | *src2p++) & *src3p++; } static bool vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) return bitset_or_and_cmp_ (dst, src1, src2, src3); vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); + unsigned i; + bool changed = false; for (i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ | *src2p++) & *src3p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1074,9 +926,9 @@ static void vbitset_copy (bitset dst, bitset src) { if (BITSET_COMPATIBLE_ (dst, src)) - vbitset_copy1 (dst, src); + vbitset_copy1 (dst, src); else - bitset_copy_ (dst, src); + bitset_copy_ (dst, src); } @@ -1119,22 +971,17 @@ struct bitset_vtable vbitset_vtable = { size_t -vbitset_bytes (n_bits) - bitset_bindex n_bits ATTRIBUTE_UNUSED; +vbitset_bytes (bitset_bindex n_bits ATTRIBUTE_UNUSED) { return sizeof (struct vbitset_struct); } bitset -vbitset_init (bset, n_bits) - bitset bset; - bitset_bindex n_bits; +vbitset_init (bitset bset, bitset_bindex n_bits) { bset->b.vtable = &vbitset_vtable; - bset->b.cindex = 0; - VBITSET_SIZE (bset) = 0; vbitset_resize (bset, n_bits); return bset; diff --git a/contrib/tools/bison/lib/vbitset.h b/contrib/tools/bison/lib/vbitset.h index 6f7d7137d3d..23b4652b87f 100644 --- a/contrib/tools/bison/lib/vbitset.h +++ b/contrib/tools/bison/lib/vbitset.h @@ -23,8 +23,8 @@ #include "bitset.h" -extern size_t vbitset_bytes (bitset_bindex); +size_t vbitset_bytes (bitset_bindex); -extern bitset vbitset_init (bitset, bitset_bindex); +bitset vbitset_init (bitset, bitset_bindex); #endif diff --git a/contrib/tools/bison/lib/xtime.c b/contrib/tools/bison/lib/xtime.c new file mode 100644 index 00000000000..e608f69fdf2 --- /dev/null +++ b/contrib/tools/bison/lib/xtime.c @@ -0,0 +1,3 @@ +#include <config.h> +#define XTIME_INLINE _GL_EXTERN_INLINE +#include "xtime.h" diff --git a/contrib/tools/bison/lib/xtime.h b/contrib/tools/bison/lib/xtime.h new file mode 100644 index 00000000000..aabcee9e689 --- /dev/null +++ b/contrib/tools/bison/lib/xtime.h @@ -0,0 +1,105 @@ +/* xtime -- extended-resolution integer timestamps + + Copyright (C) 2005-2006, 2009-2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#ifndef XTIME_H_ +#define XTIME_H_ 1 + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef XTIME_INLINE +# define XTIME_INLINE _GL_INLINE +#endif + +/* xtime_t is a signed type used for timestamps. It is an integer + type that is a count of nanoseconds -- except for obsolescent hosts + without sufficiently-wide integers, where it is a count of + seconds. */ +#if HAVE_LONG_LONG_INT +typedef long long int xtime_t; +# define XTIME_PRECISION 1000000000 +#else +# include <limits.h> +typedef long int xtime_t; +# if LONG_MAX >> 31 >> 31 == 0 +# define XTIME_PRECISION 1 +# else +# define XTIME_PRECISION 1000000000 +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Return an extended time value that contains S seconds and NS + nanoseconds. */ +XTIME_INLINE xtime_t +xtime_make (xtime_t s, long int ns) +{ + const long int giga = 1000 * 1000 * 1000; + s += ns / giga; + ns %= giga; + if (XTIME_PRECISION == 1) + return s; + else + return XTIME_PRECISION * s + ns; +} + +/* Return the number of seconds in T, which must be nonnegative. */ +XTIME_INLINE xtime_t +xtime_nonnegative_sec (xtime_t t) +{ + return t / XTIME_PRECISION; +} + +/* Return the number of seconds in T. */ +XTIME_INLINE xtime_t +xtime_sec (xtime_t t) +{ + return (XTIME_PRECISION == 1 + ? t + : t < 0 + ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1 + : xtime_nonnegative_sec (t)); +} + +/* Return the number of nanoseconds in T, which must be nonnegative. */ +XTIME_INLINE long int +xtime_nonnegative_nsec (xtime_t t) +{ + return t % XTIME_PRECISION; +} + +/* Return the number of nanoseconds in T. */ +XTIME_INLINE long int +xtime_nsec (xtime_t t) +{ + long int ns = t % XTIME_PRECISION; + if (ns < 0) + ns += XTIME_PRECISION; + return ns; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/contrib/tools/bison/lib/ya.make b/contrib/tools/bison/lib/ya.make index 2bb7d5a261a..adda78c9fde 100644 --- a/contrib/tools/bison/lib/ya.make +++ b/contrib/tools/bison/lib/ya.make @@ -47,6 +47,7 @@ SRCS( fopen-safer.c fseterr.c get-errno.c + gethrxtime.c getprogname.c glthread/lock.c glthread/threadlib.c @@ -54,10 +55,12 @@ SRCS( hash.c lbitset.c localcharset.c + localtime-buffer.c malloca.c math.c mbrtowc.c mbswidth.c + path-join.c pipe-safer.c pipe2-safer.c pipe2.c @@ -71,6 +74,7 @@ SRCS( spawn-pipe.c stat-time.c stripslash.c + timespec.c timevar.c unistd.c uniwidth/width.c @@ -84,6 +88,7 @@ SRCS( xmemdup0.c xsize.c xstrndup.c + xtime.c ) IF (OS_DARWIN) |