1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Start using bool.

This commit is contained in:
Bruno Haible
2002-11-19 12:55:48 +00:00
parent 4cda19576b
commit 2cd11405ed
15 changed files with 81 additions and 51 deletions

View File

@@ -1,3 +1,31 @@
2002-11-02 Bruno Haible <bruno@clisp.org>
Start using bool.
* src/bool-array.h (Bool_Array::set_bit): Change return type to bool.
* src/bool-array.icc (Bool_Array::set_bit): Likewise.
* src/gen-perf.h (Gen_Perf::affects_prev): Likewise.
* src/gen-perf.cc (Gen_Perf::affects_prev): Likewise.
* src/hash-table.h (Hash_Table::_ignore_length): Change type to bool.
(Hash_Table::Hash_Table): Change 3rd argument type to bool.
* src/hash-table.cc (Hash_Table::Hash_Table): Likewise.
* src/input.h (Input::_additional_code): Change type to bool.
* src/input.cc (Input::read_keys): Update.
* src/key-list.h (Key_List::_occurrence_sort, Key_List::_hash_sort,
Key_List::_additional_code): Change type to bool.
(Key_List::_determined): Change element type to bool.
(Key_List::already_determined): Change return type to bool.
* src/key-list.cc (Key_List::_determined): Change element type to bool.
(Key_List::set_determined): Update.
(Key_List::already_determined): Change return type to bool.
(Key_List::reorder, Key_List::sort, Key_List::Key_List): Update.
* src/options.h (Positions::sort): Change return type to bool.
(Options::operator[]): Likewise.
* src/options.icc (Positions::sort): Change return type to bool.
(Options::operator[]): Likewise.
* src/output.h (Output::Output): Change 5th argument type to bool.
(Output::_additional_code): Change type to bool.
* src/output.cc (Output::Output): Change 5th argument type to bool.
2002-10-16 Bruno Haible <bruno@clisp.org> 2002-10-16 Bruno Haible <bruno@clisp.org>
* src/*.h: Align all member names at column 24. * src/*.h: Align all member names at column 24.

View File

@@ -46,8 +46,9 @@ public:
/* Resets all bits to zero. */ /* Resets all bits to zero. */
void clear (); void clear ();
/* Sets the specified bit to one. Returns its previous value (0 or 1). */ /* Sets the specified bit to true.
int set_bit (unsigned int index); Returns its previous value (false or true). */
bool set_bit (unsigned int index);
private: private:
/* Size of array. */ /* Size of array. */

View File

@@ -38,18 +38,19 @@ Bool_Array::Bool_Array (unsigned int size)
_size, (unsigned int) (_size * sizeof (_storage_array[0]))); _size, (unsigned int) (_size * sizeof (_storage_array[0])));
} }
/* Sets the specified bit to one. Returns its previous value (0 or 1). */ /* Sets the specified bit to true.
INLINE int Returns its previous value (false or true). */
INLINE bool
Bool_Array::set_bit (unsigned int index) Bool_Array::set_bit (unsigned int index)
{ {
if (_storage_array[index] == _iteration_number) if (_storage_array[index] == _iteration_number)
/* The bit was set since the last clear() call. */ /* The bit was set since the last clear() call. */
return 1; return true;
else else
{ {
/* The last operation on this bit was clear(). Set it now. */ /* The last operation on this bit was clear(). Set it now. */
_storage_array[index] = _iteration_number; _storage_array[index] = _iteration_number;
return 0; return false;
} }
} }

View File

@@ -168,7 +168,7 @@ Gen_Perf::hash (KeywordExt *key_node)
that all legal Asso_Values are visited without repetition since that all legal Asso_Values are visited without repetition since
Option.Get_Jump was forced to be an odd value! */ Option.Get_Jump was forced to be an odd value! */
inline int inline bool
Gen_Perf::affects_prev (char c, KeywordExt *curr) Gen_Perf::affects_prev (char c, KeywordExt *curr)
{ {
int original_char = _asso_values[(unsigned char)c]; int original_char = _asso_values[(unsigned char)c];
@@ -202,7 +202,7 @@ Gen_Perf::affects_prev (char c, KeywordExt *curr)
_fewest_collisions = collisions; _fewest_collisions = collisions;
if (option[DEBUG]) if (option[DEBUG])
fprintf (stderr, "- resolved after %d iterations", total_iterations - i); fprintf (stderr, "- resolved after %d iterations", total_iterations - i);
return 0; return false;
} }
} }
} }
@@ -210,7 +210,7 @@ Gen_Perf::affects_prev (char c, KeywordExt *curr)
/* Restore original values, no more tries. */ /* Restore original values, no more tries. */
_asso_values[(unsigned char)c] = original_char; _asso_values[(unsigned char)c] = original_char;
/* If we're this far it's time to try the next character.... */ /* If we're this far it's time to try the next character.... */
return 1; return true;
} }
/* Change a character value, try least-used characters first. */ /* Change a character value, try least-used characters first. */

View File

@@ -37,7 +37,7 @@ private:
Bool_Array * _collision_detector; Bool_Array * _collision_detector;
void change (KeywordExt *prior, KeywordExt *curr); void change (KeywordExt *prior, KeywordExt *curr);
int affects_prev (char c, KeywordExt *curr); bool affects_prev (char c, KeywordExt *curr);
static int hash (KeywordExt *key_node); static int hash (KeywordExt *key_node);
static int compute_disjoint_union (const char *set_1, int size_1, const char *set_2, int size_2, char *set_3); static int compute_disjoint_union (const char *set_1, int size_1, const char *set_2, int size_2, char *set_3);
static void sort_set (char *union_set, int len); static void sort_set (char *union_set, int len);

View File

@@ -34,7 +34,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
This compromises information hiding somewhat, but greatly reduces This compromises information hiding somewhat, but greatly reduces
memory fragmentation, since we can now use alloca! */ memory fragmentation, since we can now use alloca! */
Hash_Table::Hash_Table (KeywordExt **table_ptr, int s, int ignore_len): Hash_Table::Hash_Table (KeywordExt **table_ptr, int s, bool ignore_len):
_table (table_ptr), _size (s), _collisions (0), _ignore_length (ignore_len) _table (table_ptr), _size (s), _collisions (0), _ignore_length (ignore_len)
{ {
memset ((char *) _table, 0, _size * sizeof (*_table)); memset ((char *) _table, 0, _size * sizeof (*_table));

View File

@@ -32,10 +32,10 @@ private:
KeywordExt ** _table; /* Vector of pointers to linked lists of keywords. */ KeywordExt ** _table; /* Vector of pointers to linked lists of keywords. */
int _size; /* Size of the vector. */ int _size; /* Size of the vector. */
int _collisions; /* Find out how well our double hashing is working! */ int _collisions; /* Find out how well our double hashing is working! */
int _ignore_length; bool _ignore_length;
public: public:
Hash_Table (KeywordExt **t, int s, int ignore_len); Hash_Table (KeywordExt **t, int s, bool ignore_len);
~Hash_Table (); ~Hash_Table ();
KeywordExt * insert (KeywordExt *item); KeywordExt * insert (KeywordExt *item);
}; };

View File

@@ -343,5 +343,5 @@ Input::read_keys ()
/* See if any additional C code is included at end of this file. */ /* See if any additional C code is included at end of this file. */
if (ptr) if (ptr)
_additional_code = 1; _additional_code = true;
} }

View File

@@ -45,7 +45,7 @@ public:
const char * _return_type; /* Pointer to return type for lookup function. */ const char * _return_type; /* Pointer to return type for lookup function. */
const char * _struct_tag; /* Shorthand for user-defined struct tag type. */ const char * _struct_tag; /* Shorthand for user-defined struct tag type. */
const char * _include_src; /* C source code to be included verbatim. */ const char * _include_src; /* C source code to be included verbatim. */
int _additional_code; /* True if any additional C code is included. */ bool _additional_code; /* True if any additional C code is included. */
KeywordExt_List * _head; /* Points to the head of the linked list. */ KeywordExt_List * _head; /* Points to the head of the linked list. */
}; };

View File

@@ -32,7 +32,7 @@ static const int TABLE_MULTIPLE = 10;
/* Efficiently returns the least power of two greater than or equal to X! */ /* Efficiently returns the least power of two greater than or equal to X! */
#define POW(X) ((!X)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X))) #define POW(X) ((!X)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X)))
int Key_List::_determined[MAX_ALPHA_SIZE]; bool Key_List::_determined[MAX_ALPHA_SIZE];
/* Destructor dumps diagnostics during debugging. */ /* Destructor dumps diagnostics during debugging. */
@@ -232,15 +232,15 @@ Key_List::set_determined (KeywordExt *ptr)
const char *p = ptr->_selchars; const char *p = ptr->_selchars;
unsigned int i = ptr->_selchars_length; unsigned int i = ptr->_selchars_length;
for (; i > 0; p++, i--) for (; i > 0; p++, i--)
_determined[(unsigned char)(*p)] = 1; _determined[(unsigned char)(*p)] = true;
} }
/* Returns TRUE if PTR's key set is already completely determined. */ /* Returns TRUE if PTR's key set is already completely determined. */
inline int inline bool
Key_List::already_determined (KeywordExt *ptr) Key_List::already_determined (KeywordExt *ptr)
{ {
int is_determined = 1; bool is_determined = true;
const char *p = ptr->_selchars; const char *p = ptr->_selchars;
unsigned int i = ptr->_selchars_length; unsigned int i = ptr->_selchars_length;
@@ -267,8 +267,8 @@ Key_List::reorder ()
keyword->_occurrence = get_occurrence (keyword); keyword->_occurrence = get_occurrence (keyword);
} }
_hash_sort = 0; _hash_sort = false;
_occurrence_sort = 1; _occurrence_sort = true;
_head = merge_sort (_head); _head = merge_sort (_head);
@@ -302,8 +302,8 @@ Key_List::reorder ()
void void
Key_List::sort () Key_List::sort ()
{ {
_hash_sort = 1; _hash_sort = true;
_occurrence_sort = 0; _occurrence_sort = false;
_head = merge_sort (_head); _head = merge_sort (_head);
} }
@@ -337,7 +337,7 @@ Key_List::Key_List ()
_struct_tag = 0; _struct_tag = 0;
_head = 0; _head = 0;
_total_duplicates = 0; _total_duplicates = 0;
_additional_code = 0; _additional_code = false;
} }
/* Returns the length of entire key list. */ /* Returns the length of entire key list. */

View File

@@ -43,19 +43,19 @@ protected:
int _max_key_len; /* Maximum length of the longest keyword. */ int _max_key_len; /* Maximum length of the longest keyword. */
int _min_key_len; /* Minimum length of the shortest keyword. */ int _min_key_len; /* Minimum length of the shortest keyword. */
private: private:
int _occurrence_sort; /* True if sorting by occurrence. */ bool _occurrence_sort; /* True if sorting by occurrence. */
int _hash_sort; /* True if sorting by hash value. */ bool _hash_sort; /* True if sorting by hash value. */
protected: protected:
int _additional_code; /* True if any additional C code is included. */ bool _additional_code; /* True if any additional C code is included. */
private: private:
int _list_len; /* Length of head's Key_List, not counting duplicates. */ int _list_len; /* Length of head's Key_List, not counting duplicates. */
protected: protected:
int _total_keys; /* Total number of keys, counting duplicates. */ int _total_keys; /* Total number of keys, counting duplicates. */
int _size; /* Range of the hash table. */ int _size; /* Range of the hash table. */
private: private:
static int _determined[MAX_ALPHA_SIZE]; /* Used in function reorder, below. */ static bool _determined[MAX_ALPHA_SIZE]; /* Used in function reorder, below. */
static int get_occurrence (KeywordExt *ptr); static int get_occurrence (KeywordExt *ptr);
static int already_determined (KeywordExt *ptr); static bool already_determined (KeywordExt *ptr);
static void set_determined (KeywordExt *ptr); static void set_determined (KeywordExt *ptr);
void dump (); void dump ();
KeywordExt_List * merge (KeywordExt_List *list1, KeywordExt_List *list2); KeywordExt_List * merge (KeywordExt_List *list1, KeywordExt_List *list2);

View File

@@ -127,8 +127,8 @@ public:
void set_size (unsigned int size); void set_size (unsigned int size);
/* Sorts the array in reverse order. /* Sorts the array in reverse order.
Returns 1 if there are no duplicates, 0 otherwise. */ Returns true if there are no duplicates, false otherwise. */
int sort (); bool sort ();
private: private:
/* Number of positions, excluding the terminating PositionIterator::EOS. */ /* Number of positions, excluding the terminating PositionIterator::EOS. */
@@ -176,8 +176,8 @@ public:
/* Accessors. */ /* Accessors. */
/* Tests a given boolean option. Returns 1 if set, 0 otherwise. */ /* Tests a given boolean option. Returns true if set, false otherwise. */
int operator[] (Option_Type option) const; bool operator[] (Option_Type option) const;
/* Returns the iterations value. */ /* Returns the iterations value. */
int get_iterations () const; int get_iterations () const;

View File

@@ -68,12 +68,12 @@ Positions::set_size (unsigned int size)
} }
/* Sorts the array in reverse order. /* Sorts the array in reverse order.
Returns 1 if there are no duplicates, 0 otherwise. */ Returns true if there are no duplicates, false otherwise. */
INLINE int INLINE bool
Positions::sort () Positions::sort ()
{ {
/* Bubble sort. */ /* Bubble sort. */
int duplicate_free = 1; bool duplicate_free = true;
unsigned char *base = _positions; unsigned char *base = _positions;
unsigned int len = _size; unsigned int len = _size;
@@ -84,7 +84,7 @@ Positions::sort ()
for (j = i, tmp = base[j]; j > 0 && tmp >= base[j - 1]; j--) for (j = i, tmp = base[j]; j > 0 && tmp >= base[j - 1]; j--)
if ((base[j] = base[j - 1]) == tmp) /* oh no, a duplicate!!! */ if ((base[j] = base[j - 1]) == tmp) /* oh no, a duplicate!!! */
duplicate_free = 0; duplicate_free = false;
base[j] = tmp; base[j] = tmp;
} }
@@ -105,8 +105,8 @@ PositionIterator::next ()
return _set._positions[_index++]; return _set._positions[_index++];
} }
/* Tests a given boolean option. Returns 1 if set, 0 otherwise. */ /* Tests a given boolean option. Returns true if set, false otherwise. */
INLINE int INLINE bool
Options::operator[] (Option_Type option) const Options::operator[] (Option_Type option) const
{ {
return _option_word & option; return _option_word & option;

View File

@@ -65,16 +65,16 @@ static const char *char_to_index;
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* Constructor. */ /* Constructor. */
Output::Output (KeywordExt_List *head_, const char *array_type_, Output::Output (KeywordExt_List *head, const char *array_type,
const char *return_type_, const char *struct_tag_, const char *return_type, const char *struct_tag,
int additional_code_, const char *include_src_, bool additional_code, const char *include_src,
int total_keys_, int total_duplicates_, int max_key_len_, int total_keys, int total_duplicates, int max_key_len,
int min_key_len_, Vectors *v_) int min_key_len, Vectors *v)
: _head (head_), _array_type (array_type_), _return_type (return_type_), : _head (head), _array_type (array_type), _return_type (return_type),
_struct_tag (struct_tag_), _additional_code (additional_code_), _struct_tag (struct_tag), _additional_code (additional_code),
_include_src (include_src_), _total_keys (total_keys_), _include_src (include_src), _total_keys (total_keys),
_total_duplicates (total_duplicates_), _max_key_len (max_key_len_), _total_duplicates (total_duplicates), _max_key_len (max_key_len),
_min_key_len (min_key_len_), _v (v_) _min_key_len (min_key_len), _v (v)
{ {
} }

View File

@@ -34,7 +34,7 @@ struct Output_Compare;
class Output class Output
{ {
public: public:
Output (KeywordExt_List *head, const char *array_type, const char *return_type, const char *struct_tag, int additional_code, const char *include_src, int total_keys, int total_duplicates, int max_key_len, int min_key_len, Vectors *v); Output (KeywordExt_List *head, const char *array_type, const char *return_type, const char *struct_tag, bool additional_code, const char *include_src, int total_keys, int total_duplicates, int max_key_len, int min_key_len, Vectors *v);
void output (); void output ();
private: private:
void compute_min_max (); void compute_min_max ();
@@ -58,7 +58,7 @@ private:
/* Shorthand for user-defined struct tag type. */ /* Shorthand for user-defined struct tag type. */
const char * _struct_tag; const char * _struct_tag;
/* True if any additional C code is included. */ /* True if any additional C code is included. */
int _additional_code; bool _additional_code;
/* C source code to be included verbatim. */ /* C source code to be included verbatim. */
const char * _include_src; const char * _include_src;
/* Total number of keys, counting duplicates. */ /* Total number of keys, counting duplicates. */