From d08290769c798befc27e9f8bbc3f1a3da12d1f08 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 24 May 2003 19:16:02 +0000 Subject: [PATCH] Switch from 'int' to 'bool' where that makes sense. --- ChangeLog | 65 ++++++++++++++++++++++++++++++++++++ lib/abitset.c | 72 ++++++++++++++++++++-------------------- lib/bbitset.h | 37 +++++++++++---------- lib/bitset.c | 42 +++++++++++------------ lib/bitset.h | 4 +-- lib/bitset_stats.c | 38 ++++++++++----------- lib/bitset_stats.h | 4 +-- lib/ebitset.c | 95 ++++++++++++++++++++++++++-------------------------- lib/lbitset.c | 97 ++++++++++++++++++++++++++---------------------------- src/conflicts.c | 4 +-- src/getargs.c | 42 ++++++++++++++--------- src/getargs.h | 16 ++++----- src/lalr.c | 10 +++--- src/muscle_tab.h | 6 ++++ src/nullable.c | 8 ++--- src/output.c | 37 +++++++++------------ src/output.h | 4 +-- src/parse-gram.y | 16 ++++----- src/print.c | 18 +++++----- src/print_graph.c | 11 ++++--- src/reader.c | 10 +++--- src/reader.h | 2 +- src/scan-gram.l | 2 +- src/state.c | 9 ++--- src/tables.c | 22 ++++++++----- 25 files changed, 376 insertions(+), 295 deletions(-) diff --git a/ChangeLog b/ChangeLog index 402f613..e6eb5d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,68 @@ +2003-05-24 Paul Eggert + + Switch from 'int' to 'bool' where that makes sense. + + * lib/abitset.c (abitset_test, abitset_empty_p, abitset_equal_p, + abitset_subset_p, abitset_disjoint_p, abitset_and_cmp, + abitset_andn_cmp, abitset_or_cmp, abitset_xor_cmp, abitset_and_or, + abitset_and_or_cmp, abitset_andn_or_cmp, abitset_or_and_cmp): + Return or accept bool, not int. All callers changed. + * lib/bbitset.h: (bitset_toggle_, bitset_copy_, bitset_and_or_cmp_, + bitset_andn_or_cmp_, bitset_or_and_cmp_): Likewise. + * lib/bitset.c (bitset_only_set_p, bitset_print, bitset_toggle_, + bitset_copy_, bitset_op4_cmp, bitset_and_or_cmp_, bitset_andn_or_cmp_, + bitset_or_and_cmp_): Likewise. + * lib/bitset.h (bitset_test, bitset_only_set_p): Likewise. + * lib/bitset_stats.c (bitset_stats_print, bitset_stats_toggle, + bitset_stats_test, bitset_stats_empty_p, bitset_stats_disjoint_p, + bitset_stats_equal_p, bitset_stats_subset_p, bitset_stats_and_cmp, + bitset_stats_andn_cmp, bitset_stats_or_cmp, bitset_stats_xor_cmp, + bitset_stats_and_or_cmp, bitset_stats_andn_or_cmp, + bitset_stats_or_and_cmp): Likewise. + * lib/ebitset.c (ebitset_elt_zero_p, ebitset_equal_p, ebitset_copy_cmp, + ebitset_test, ebitset_empty_p, ebitset_subset_p, ebitset_disjoint_p, + ebitset_op3_cmp, ebitset_and_cmp, ebitset_andn_cmp, ebitset_or_cmp, + ebitset_xor_cmp): Likewise. + * lib/lbitset.c (lbitset_elt_zero_p, lbitset_equal_p, lbitset_copy_cmp, + lbitset_test, lbitset_empty_p, lbitset_subset_p, lbitset_disjoint_p, + lbitset_op3_cmp, lbitset_and_cmp, lbitset_andn_cmp, lbitset_or_cmp, + lbitset_xor_cmp): Likewise. + * lib/bbitset.h: Include . + (struct bitset_vtable): The following members now return bool, not + int: toggle, test, empty_p, disjoint_p, equal_p, subset_p, + and_cmp, andn_cmp, or_cmp, xor_cmp, and_or_cmp, andn_or_cmp, + or_and_cmp). + * src/conflicts.c (count_rr_conflicts): Likewise. + * lib/bitset_stats.h (bitset_stats_enabled): Now bool, not int. + All uses changed. + * lib/ebitset.c (ebitset_obstack_init): Likewise. + * lib/lbitset.c (lbitset_obstack_init): Likewise. + * src/getargs.c (debug_flag, defines_flag, locations_flag, + no_lines_flag, no_parser_flag, token_table_flag, yacc_flag, + graph_flag): Likewise. + * src/getargs.h (debug_flag, defines_flag, locations_flag, + no_lines_flag, no_parser_flag, token_table_flag, yacc_flag, + graph_flag): Likewise. + * src/output.c (error_verbose): Likewise. + * src/output.h (error_verbose): Likewise. + * src/reader.c (start_flag, typed): Likewise. + * src/reader.h (typed): Likewise. + * src/getargs.c (LOCATIONS_OPTION): New constant. + (long_options, getargs): Use it. + * src/lalr.c (build_relations): Use bool, not int. + * src/nullable.c (nullable_compute): Likewise. + * src/print.c (print_reductions): Likewise. + * src/tables.c (action_row, pack_vector): Likewise. + * src/muscle_tab.h (MUSCLE_INSERT_BOOL): New macro. + * src/output.c (prepare): Use it. + * src/output.c (token_definitions_output, + symbol_destructors_output, symbol_destructors_output): Use string, + not boolean integer, to keep track of whether to output separator. + * src/print_graph.c (print_core): Likewise. + * src/state.c (state_rule_lookaheads_print): Likewise. + + * config/install-sh: Sync from automake 1.7.5. + 2003-05-14 Paul Eggert * src/parse-gram.y (rules_or_grammar_declaration): Require a diff --git a/lib/abitset.c b/lib/abitset.c index 2d5ca29..99c1c2f 100644 --- a/lib/abitset.c +++ b/lib/abitset.c @@ -1,5 +1,5 @@ /* Array bitsets. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). This program is free software; you can redistribute it and/or modify @@ -123,14 +123,14 @@ abitset_reset (bitset dst ATTRIBUTE_UNUSED, /* Test bit BITNO in bitset SRC. */ -static int +static bool abitset_test (bitset src ATTRIBUTE_UNUSED, bitset_bindex bitno ATTRIBUTE_UNUSED) { /* This should never occur for abitsets since we should always hit the cache. */ abort (); - return 0; + return false; } @@ -336,7 +336,7 @@ abitset_zero (bitset dst) } -static int +static bool abitset_empty_p (bitset dst) { bitset_windex i; @@ -344,9 +344,9 @@ abitset_empty_p (bitset dst) for (i = 0; i < dst->b.csize; i++) if (dstp[i]) - return 0; + return false; - return 1; + return true; } @@ -377,7 +377,7 @@ abitset_not (bitset dst, bitset src) } -static int +static bool abitset_equal_p (bitset dst, bitset src) { bitset_windex i; @@ -387,12 +387,12 @@ abitset_equal_p (bitset dst, bitset src) for (i = 0; i < size; i++) if (*srcp++ != *dstp++) - return 0; - return 1; + return false; + return true; } -static int +static bool abitset_subset_p (bitset dst, bitset src) { bitset_windex i; @@ -402,12 +402,12 @@ abitset_subset_p (bitset dst, bitset src) for (i = 0; i < size; i++, dstp++, srcp++) if (*dstp != (*srcp | *dstp)) - return 0; - return 1; + return false; + return true; } -static int +static bool abitset_disjoint_p (bitset dst, bitset src) { bitset_windex i; @@ -417,9 +417,9 @@ abitset_disjoint_p (bitset dst, bitset src) for (i = 0; i < size; i++) if (*srcp++ & *dstp++) - return 0; + return false; - return 1; + return true; } @@ -437,11 +437,11 @@ abitset_and (bitset dst, bitset src1, bitset src2) } -static int +static bool abitset_and_cmp (bitset dst, bitset src1, bitset src2) { bitset_windex i; - int changed = 0; + bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); @@ -453,7 +453,7 @@ abitset_and_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -475,11 +475,11 @@ abitset_andn (bitset dst, bitset src1, bitset src2) } -static int +static bool abitset_andn_cmp (bitset dst, bitset src1, bitset src2) { bitset_windex i; - int changed = 0; + bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); @@ -491,7 +491,7 @@ abitset_andn_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -513,11 +513,11 @@ abitset_or (bitset dst, bitset src1, bitset src2) } -static int +static bool abitset_or_cmp (bitset dst, bitset src1, bitset src2) { bitset_windex i; - int changed = 0; + bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); @@ -529,7 +529,7 @@ abitset_or_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -551,11 +551,11 @@ abitset_xor (bitset dst, bitset src1, bitset src2) } -static int +static bool abitset_xor_cmp (bitset dst, bitset src1, bitset src2) { bitset_windex i; - int changed = 0; + bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); @@ -567,7 +567,7 @@ abitset_xor_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -590,11 +590,11 @@ abitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3) } -static int +static bool abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { bitset_windex i; - int changed = 0; + bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); @@ -607,7 +607,7 @@ abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -630,11 +630,11 @@ abitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) } -static int +static bool abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { bitset_windex i; - int changed = 0; + bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); @@ -647,7 +647,7 @@ abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -670,11 +670,11 @@ abitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3) } -static int +static bool abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { bitset_windex i; - int changed = 0; + bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); @@ -687,7 +687,7 @@ abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } diff --git a/lib/bbitset.h b/lib/bbitset.h index e1b69e0..26539f2 100644 --- a/lib/bbitset.h +++ b/lib/bbitset.h @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "libiberty.h" +#include #include /* Currently we support three flavours of bitsets: @@ -97,36 +98,36 @@ struct bitset_vtable { void (*set) PARAMS ((bitset, bitset_bindex)); void (*reset) PARAMS ((bitset, bitset_bindex)); - int (*toggle) PARAMS ((bitset, bitset_bindex)); - int (*test) PARAMS ((bitset, bitset_bindex)); + bool (*toggle) PARAMS ((bitset, bitset_bindex)); + bool (*test) PARAMS ((bitset, bitset_bindex)); bitset_bindex (*size) PARAMS ((bitset)); bitset_bindex (*count) PARAMS ((bitset)); - int (*empty_p) PARAMS ((bitset)); + bool (*empty_p) PARAMS ((bitset)); void (*ones) PARAMS ((bitset)); void (*zero) PARAMS ((bitset)); void (*copy) PARAMS ((bitset, bitset)); - int (*disjoint_p) PARAMS ((bitset, bitset)); - int (*equal_p) PARAMS ((bitset, bitset)); + bool (*disjoint_p) PARAMS ((bitset, bitset)); + bool (*equal_p) PARAMS ((bitset, bitset)); void (*not) PARAMS ((bitset, bitset)); - int (*subset_p) PARAMS ((bitset, bitset)); + bool (*subset_p) PARAMS ((bitset, bitset)); void (*and) PARAMS ((bitset, bitset, bitset)); - int (*and_cmp) PARAMS ((bitset, bitset, bitset)); + bool (*and_cmp) PARAMS ((bitset, bitset, bitset)); void (*andn) PARAMS ((bitset, bitset, bitset)); - int (*andn_cmp) PARAMS ((bitset, bitset, bitset)); + bool (*andn_cmp) PARAMS ((bitset, bitset, bitset)); void (*or) PARAMS ((bitset, bitset, bitset)); - int (*or_cmp) PARAMS ((bitset, bitset, bitset)); + bool (*or_cmp) PARAMS ((bitset, bitset, bitset)); void (*xor) PARAMS ((bitset, bitset, bitset)); - int (*xor_cmp) PARAMS ((bitset, bitset, bitset)); + bool (*xor_cmp) PARAMS ((bitset, bitset, bitset)); void (*and_or) PARAMS ((bitset, bitset, bitset, bitset)); - int (*and_or_cmp) PARAMS ((bitset, bitset, bitset, bitset)); + bool (*and_or_cmp) PARAMS ((bitset, bitset, bitset, bitset)); void (*andn_or) PARAMS ((bitset, bitset, bitset, bitset)); - int (*andn_or_cmp) PARAMS ((bitset, bitset, bitset, bitset)); + bool (*andn_or_cmp) PARAMS ((bitset, bitset, bitset, bitset)); void (*or_and) PARAMS ((bitset, bitset, bitset, bitset)); - int (*or_and_cmp) PARAMS ((bitset, bitset, bitset, bitset)); + bool (*or_and_cmp) PARAMS ((bitset, bitset, bitset, bitset)); bitset_bindex (*list) PARAMS ((bitset, bitset_bindex *, bitset_bindex, bitset_bindex *)); @@ -259,22 +260,22 @@ if (!BITSET_COMPATIBLE_ (DST, SRC1) || !BITSET_COMPATIBLE_ (DST, SRC2) \ /* Private functions for bitset implementations. */ -extern int bitset_toggle_ PARAMS ((bitset, bitset_bindex)); +extern bool bitset_toggle_ PARAMS ((bitset, bitset_bindex)); extern bitset_bindex bitset_count_ PARAMS ((bitset)); -extern int bitset_copy_ PARAMS ((bitset, bitset)); +extern bool bitset_copy_ PARAMS ((bitset, bitset)); extern void bitset_and_or_ PARAMS ((bitset, bitset, bitset, bitset)); -extern int bitset_and_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset)); +extern bool bitset_and_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset)); extern void bitset_andn_or_ PARAMS ((bitset, bitset, bitset, bitset)); -extern int bitset_andn_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset)); +extern bool bitset_andn_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset)); extern void bitset_or_and_ PARAMS ((bitset, bitset, bitset, bitset)); -extern int bitset_or_and_cmp_ PARAMS ((bitset, bitset, bitset, bitset)); +extern bool bitset_or_and_cmp_ PARAMS ((bitset, bitset, bitset, bitset)); #endif /* _BBITSET_H */ diff --git a/lib/bitset.c b/lib/bitset.c index 82517d9..a500d47 100644 --- a/lib/bitset.c +++ b/lib/bitset.c @@ -1,5 +1,5 @@ /* General bitsets. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). This program is free software; you can redistribute it and/or modify @@ -253,22 +253,22 @@ bitset_last (bitset src) } -/* Return non-zero if BITNO in SRC is the only set bit. */ -int +/* Is BITNO in SRC the only set bit? */ +bool bitset_only_set_p (bitset src, bitset_bindex bitno) { bitset_bindex val[2]; bitset_bindex next = 0; if (bitset_list (src, val, 2, &next) != 1) - return 0; + return false; return val[0] == bitno; } /* Print contents of bitset BSET to FILE. */ static void -bitset_print (FILE *file, bitset bset, int verbose) +bitset_print (FILE *file, bitset bset, bool verbose) { unsigned int pos; bitset_bindex i; @@ -300,7 +300,7 @@ bitset_print (FILE *file, bitset bset, int verbose) void bitset_dump (FILE *file, bitset bset) { - bitset_print (file, bset, 0); + bitset_print (file, bset, false); } @@ -315,8 +315,8 @@ bitset_release_memory (void) -/* Toggle bit BITNO in bitset BSET and return non-zero if not set. */ -int +/* Toggle bit BITNO in bitset BSET and the new value of the bit. */ +bool bitset_toggle_ (bitset bset, bitset_bindex bitno) { /* This routine is for completeness. It could be optimized if @@ -324,12 +324,12 @@ bitset_toggle_ (bitset bset, bitset_bindex bitno) if (bitset_test (bset, bitno)) { bitset_reset (bset, bitno); - return 0; + return false; } else { bitset_set (bset, bitno); - return 1; + return true; } } @@ -356,10 +356,10 @@ bitset_count_ (bitset src) } -/* DST = SRC. Return non-zero if DST != SRC. +/* DST = SRC. Return true if DST != SRC. This is a fallback for the case where SRC and DST are different bitset types. */ -int +bool bitset_copy_ (bitset dst, bitset src) { bitset_bindex i; @@ -373,23 +373,23 @@ bitset_copy_ (bitset dst, bitset src) bitset_set (dst, i); }; - return 1; + return true; } /* This is a fallback for implementations that do not support four operand operations. */ -static inline int +static inline bool bitset_op4_cmp (bitset dst, bitset src1, bitset src2, bitset src3, enum bitset_ops op) { - int changed = 0; - int stats_enabled_save; + bool changed = false; + bool stats_enabled_save; bitset tmp; /* Create temporary bitset. */ stats_enabled_save = bitset_stats_enabled; - bitset_stats_enabled = 0; + bitset_stats_enabled = false; tmp = bitset_alloc (0, bitset_type_get (dst)); bitset_stats_enabled = stats_enabled_save; @@ -429,7 +429,7 @@ bitset_and_or_ (bitset dst, bitset src1, bitset src2, bitset src3) /* DST = (SRC1 & SRC2) | SRC3. Return non-zero if DST != (SRC1 & SRC2) | SRC3. */ -int +bool bitset_and_or_cmp_ (bitset dst, bitset src1, bitset src2, bitset src3) { return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_AND_OR); @@ -446,7 +446,7 @@ bitset_andn_or_ (bitset dst, bitset src1, bitset src2, bitset src3) /* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if DST != (SRC1 & ~SRC2) | SRC3. */ -int +bool bitset_andn_or_cmp_ (bitset dst, bitset src1, bitset src2, bitset src3) { return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_ANDN_OR); @@ -463,7 +463,7 @@ bitset_or_and_ (bitset dst, bitset src1, bitset src2, bitset src3) /* DST = (SRC1 | SRC2) & SRC3. Return non-zero if DST != (SRC1 | SRC2) & SRC3. */ -int +bool bitset_or_and_cmp_ (bitset dst, bitset src1, bitset src2, bitset src3) { return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_OR_AND); @@ -475,5 +475,5 @@ void debug_bitset (bitset bset) { if (bset) - bitset_print (stderr, bset, 1); + bitset_print (stderr, bset, true); } diff --git a/lib/bitset.h b/lib/bitset.h index c0e9dec..1d8940d 100644 --- a/lib/bitset.h +++ b/lib/bitset.h @@ -160,7 +160,7 @@ bitset_reset (bitset bset, bitset_bindex bitno) /* Test bit BITNO in bitset BSET. */ -static inline int +static inline bool bitset_test (bitset bset, bitset_bindex bitno) { bitset_windex windex = bitno / BITSET_WORD_BITS; @@ -290,7 +290,7 @@ extern bitset_bindex bitset_first PARAMS ((bitset)); extern bitset_bindex bitset_last PARAMS ((bitset)); /* Return nonzero if this is the only set bit. */ -extern int bitset_only_set_p PARAMS ((bitset, bitset_bindex)); +extern bool bitset_only_set_p PARAMS ((bitset, bitset_bindex)); /* Dump bitset. */ extern void bitset_dump PARAMS ((FILE *, bitset)); diff --git a/lib/bitset_stats.c b/lib/bitset_stats.c index d6c70fd..c504a61 100644 --- a/lib/bitset_stats.c +++ b/lib/bitset_stats.c @@ -100,7 +100,7 @@ struct bitset_stats_info_struct struct bitset_stats_info_struct bitset_stats_info_data; struct bitset_stats_info_struct *bitset_stats_info; -int bitset_stats_enabled = 0; +bool bitset_stats_enabled = false; /* Print a percentage histogram with message MSG to FILE. */ @@ -203,7 +203,7 @@ bitset_stats_print_1 (FILE *file, const char *name, /* Print all bitset statistics to FILE. */ static void -bitset_stats_print (FILE *file, int verbose ATTRIBUTE_UNUSED) +bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED) { int i; @@ -227,14 +227,14 @@ bitset_stats_enable (void) { if (!bitset_stats_info) bitset_stats_info = &bitset_stats_info_data; - bitset_stats_enabled = 1; + bitset_stats_enabled = true; } void bitset_stats_disable (void) { - bitset_stats_enabled = 0; + bitset_stats_enabled = false; } @@ -298,7 +298,7 @@ bitset_stats_write (const char *filename) void bitset_stats_dump (FILE *file) { - bitset_stats_print (file, 0); + bitset_stats_print (file, false); } @@ -306,7 +306,7 @@ bitset_stats_dump (FILE *file) void debug_bitset_stats (void) { - bitset_stats_print (stderr, 1); + bitset_stats_print (stderr, true); } @@ -349,14 +349,14 @@ bitset_stats_reset (bitset dst, bitset_bindex bitno) } -static int +static bool bitset_stats_toggle (bitset src, bitset_bindex bitno) { return BITSET_TOGGLE_ (src->s.bset, bitno); } -static int +static bool bitset_stats_test (bitset src, bitset_bindex bitno) { bitset bset = src->s.bset; @@ -389,7 +389,7 @@ bitset_stats_count (bitset src) } -static int +static bool bitset_stats_empty_p (bitset dst) { return BITSET_EMPTY_P_ (dst->s.bset); @@ -418,7 +418,7 @@ bitset_stats_copy (bitset dst, bitset src) } -static int +static bool bitset_stats_disjoint_p (bitset dst, bitset src) { BITSET_CHECK2_ (dst, src); @@ -426,7 +426,7 @@ bitset_stats_disjoint_p (bitset dst, bitset src) } -static int +static bool bitset_stats_equal_p (bitset dst, bitset src) { BITSET_CHECK2_ (dst, src); @@ -442,7 +442,7 @@ bitset_stats_not (bitset dst, bitset src) } -static int +static bool bitset_stats_subset_p (bitset dst, bitset src) { BITSET_CHECK2_ (dst, src); @@ -458,7 +458,7 @@ bitset_stats_and (bitset dst, bitset src1, bitset src2) } -static int +static bool bitset_stats_and_cmp (bitset dst, bitset src1, bitset src2) { BITSET_CHECK3_ (dst, src1, src2); @@ -474,7 +474,7 @@ bitset_stats_andn (bitset dst, bitset src1, bitset src2) } -static int +static bool bitset_stats_andn_cmp (bitset dst, bitset src1, bitset src2) { BITSET_CHECK3_ (dst, src1, src2); @@ -490,7 +490,7 @@ bitset_stats_or (bitset dst, bitset src1, bitset src2) } -static int +static bool bitset_stats_or_cmp (bitset dst, bitset src1, bitset src2) { BITSET_CHECK3_ (dst, src1, src2); @@ -506,7 +506,7 @@ bitset_stats_xor (bitset dst, bitset src1, bitset src2) } -static int +static bool bitset_stats_xor_cmp (bitset dst, bitset src1, bitset src2) { BITSET_CHECK3_ (dst, src1, src2); @@ -523,7 +523,7 @@ bitset_stats_and_or (bitset dst, bitset src1, bitset src2, bitset src3) } -static int +static bool bitset_stats_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { BITSET_CHECK4_ (dst, src1, src2, src3); @@ -541,7 +541,7 @@ bitset_stats_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) } -static int +static bool bitset_stats_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { BITSET_CHECK4_ (dst, src1, src2, src3); @@ -559,7 +559,7 @@ bitset_stats_or_and (bitset dst, bitset src1, bitset src2, bitset src3) } -static int +static bool bitset_stats_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { BITSET_CHECK4_ (dst, src1, src2, src3); diff --git a/lib/bitset_stats.h b/lib/bitset_stats.h index 2c4f2e4..bcf4da0 100644 --- a/lib/bitset_stats.h +++ b/lib/bitset_stats.h @@ -1,5 +1,5 @@ /* Functions to support bitset statistics. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). This program is free software; you can redistribute it and/or modify @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bbitset.h" -extern int bitset_stats_enabled; +extern bool bitset_stats_enabled; extern enum bitset_type bitset_stats_type_get PARAMS ((bitset)); diff --git a/lib/ebitset.c b/lib/ebitset.c index 11b02c8..aa8727f 100644 --- a/lib/ebitset.c +++ b/lib/ebitset.c @@ -1,5 +1,5 @@ /* Functions to support expandable bitsets. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). This program is free software; you can redistribute it and/or modify @@ -88,7 +88,7 @@ static ebitset_elt ebitset_zero_elts[1]; /* Elements of all zero bits. */ /* Obstack to allocate bitset elements from. */ static struct obstack ebitset_obstack; -static int ebitset_obstack_init = 0; +static bool ebitset_obstack_init = false; static ebitset_elt *ebitset_free_list; /* Free list of bitset elements. */ #define EBITSET_ELTS(BSET) ((BSET)->e.elts) @@ -154,7 +154,7 @@ ebitset_elt_alloc (void) { if (!ebitset_obstack_init) { - ebitset_obstack_init = 1; + ebitset_obstack_init = true; /* Let particular systems override the size of a chunk. */ @@ -242,17 +242,17 @@ ebitset_elt_add (bitset bset, ebitset_elt *elt, bitset_windex eindex) } -/* Return nonzero if all bits in an element are zero. */ -static inline int +/* Are all bits in an element zero? */ +static inline bool ebitset_elt_zero_p (ebitset_elt *elt) { int i; for (i = 0; i < EBITSET_ELT_WORDS; i++) if (EBITSET_WORDS (elt)[i]) - return 0; + return false; - return 1; + return true; } @@ -402,7 +402,7 @@ ebitset_zero (bitset bset) } -static inline int +static inline bool ebitset_equal_p (bitset dst, bitset src) { ebitset_elts *selts; @@ -410,13 +410,13 @@ ebitset_equal_p (bitset dst, bitset src) bitset_windex j; if (src == dst) - return 1; + return true; ebitset_weed (dst); ebitset_weed (src); if (EBITSET_SIZE (src) != EBITSET_SIZE (dst)) - return 0; + return false; selts = EBITSET_ELTS (src); delts = EBITSET_ELTS (dst); @@ -430,13 +430,13 @@ ebitset_equal_p (bitset dst, bitset src) if (!selt && !delt) continue; if ((selt && !delt) || (!selt && delt)) - return 0; + return false; for (i = 0; i < EBITSET_ELT_WORDS; i++) if (EBITSET_WORDS (selt)[i] != EBITSET_WORDS (delt)[i]) - return 0; + return false; } - return 1; + return true; } @@ -476,13 +476,13 @@ ebitset_copy_ (bitset dst, bitset src) } -/* Copy bits from bitset SRC to bitset DST. Return non-zero if +/* Copy bits from bitset SRC to bitset DST. Return true if bitsets different. */ -static inline int +static inline bool ebitset_copy_cmp (bitset dst, bitset src) { if (src == dst) - return 0; + return false; if (EBITSET_ZERO_P (dst)) { @@ -491,10 +491,10 @@ ebitset_copy_cmp (bitset dst, bitset src) } if (ebitset_equal_p (dst, src)) - return 0; + return false; ebitset_copy_ (dst, src); - return 1; + return true; } @@ -539,16 +539,15 @@ ebitset_reset (bitset dst, bitset_bindex bitno) /* Test bit BITNO in bitset SRC. */ -static int +static bool ebitset_test (bitset src, bitset_bindex bitno) { bitset_windex windex = bitno / BITSET_WORD_BITS; - if (!ebitset_elt_find (src, windex, EBITSET_FIND)) - return 0; - - return (src->b. - cdata[windex - src->b.cindex] >> (bitno % BITSET_WORD_BITS)) & 1; + return (ebitset_elt_find (src, windex, EBITSET_FIND) + && ((src->b.cdata[windex - src->b.cindex] + >> (bitno % BITSET_WORD_BITS)) + & 1)); } @@ -808,7 +807,7 @@ ebitset_ones (bitset dst) } -static int +static bool ebitset_empty_p (bitset dst) { return !ebitset_weed (dst); @@ -839,8 +838,8 @@ ebitset_not (bitset dst, bitset src) } -/* Return 1 if DST == DST | SRC. */ -static int +/* Is DST == DST | SRC? */ +static bool ebitset_subset_p (bitset dst, bitset src) { bitset_windex j; @@ -875,14 +874,14 @@ ebitset_subset_p (bitset dst, bitset src) for (i = 0; i < EBITSET_ELT_WORDS; i++) if (EBITSET_WORDS (delt)[i] != (EBITSET_WORDS (selt)[i] | EBITSET_WORDS (delt)[i])) - return 0; + return false; } - return 1; + return true; } -/* Return 1 if DST & SRC == 0. */ -static int +/* Is DST & SRC == 0? */ +static bool ebitset_disjoint_p (bitset dst, bitset src) { bitset_windex j; @@ -911,14 +910,14 @@ ebitset_disjoint_p (bitset dst, bitset src) for (i = 0; i < EBITSET_ELT_WORDS; i++) if ((EBITSET_WORDS (selt)[i] & EBITSET_WORDS (delt)[i])) - return 0; + return false; } - return 1; + return true; } -static int +static bool ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) { bitset_windex ssize1; @@ -931,7 +930,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) bitset_word *srcp1; bitset_word *srcp2; bitset_word *dstp; - int changed = 0; + bool changed = false; unsigned int i; bitset_windex j; @@ -963,7 +962,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) { if (delt) { - changed = 1; + changed = true; ebitset_elt_remove (dst, j); } continue; @@ -990,7 +989,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1003,7 +1002,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1016,7 +1015,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1029,7 +1028,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1054,7 +1053,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) { ebitset_elt *delt; - changed = 1; + changed = true; delt = delts[j]; @@ -1067,10 +1066,10 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) } -static int +static bool ebitset_and_cmp (bitset dst, bitset src1, bitset src2) { - int changed; + bool changed; if (EBITSET_ZERO_P (src2)) { @@ -1097,10 +1096,10 @@ ebitset_and (bitset dst, bitset src1, bitset src2) } -static int +static bool ebitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - int changed; + bool changed; if (EBITSET_ZERO_P (src2)) { @@ -1124,7 +1123,7 @@ ebitset_andn (bitset dst, bitset src1, bitset src2) } -static int +static bool ebitset_or_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) @@ -1146,7 +1145,7 @@ ebitset_or (bitset dst, bitset src1, bitset src2) } -static int +static bool ebitset_xor_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) @@ -1253,7 +1252,7 @@ ebitset_release_memory (void) ebitset_free_list = 0; if (ebitset_obstack_init) { - ebitset_obstack_init = 0; + ebitset_obstack_init = false; obstack_free (&ebitset_obstack, NULL); } } diff --git a/lib/lbitset.c b/lib/lbitset.c index d279c5e..2e5b208 100644 --- a/lib/lbitset.c +++ b/lib/lbitset.c @@ -1,5 +1,5 @@ /* Functions to support link list bitsets. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). This program is free software; you can redistribute it and/or modify @@ -71,7 +71,7 @@ static lbitset_elt lbitset_zero_elts[3]; /* Elements of all zero bits. */ /* Obstack to allocate bitset elements from. */ static struct obstack lbitset_obstack; -static int lbitset_obstack_init = 0; +static bool lbitset_obstack_init = false; static lbitset_elt *lbitset_free_list; /* Free list of bitset elements. */ extern void debug_lbitset PARAMS ((bitset)); @@ -99,7 +99,7 @@ lbitset_elt_alloc (void) { if (!lbitset_obstack_init) { - lbitset_obstack_init = 1; + lbitset_obstack_init = true; /* Let particular systems override the size of a chunk. */ @@ -236,17 +236,17 @@ lbitset_prune (bitset bset, lbitset_elt *elt) } -/* Return nonzero if all bits in an element are zero. */ -static inline int +/* Are all bits in an element zero? */ +static inline bool lbitset_elt_zero_p (lbitset_elt *elt) { int i; for (i = 0; i < LBITSET_ELT_WORDS; i++) if (elt->words[i]) - return 0; + return false; - return 1; + return true; } @@ -412,8 +412,8 @@ lbitset_zero (bitset bset) } -/* Return 1 if DST == SRC. */ -static inline int +/* Is DST == SRC? */ +static inline bool lbitset_equal_p (bitset dst, bitset src) { lbitset_elt *selt; @@ -421,7 +421,7 @@ lbitset_equal_p (bitset dst, bitset src) int j; if (src == dst) - return 1; + return true; lbitset_weed (src); lbitset_weed (dst); @@ -429,11 +429,11 @@ lbitset_equal_p (bitset dst, bitset src) selt && delt; selt = selt->next, delt = delt->next) { if (selt->index != delt->index) - return 0; + return false; for (j = 0; j < LBITSET_ELT_WORDS; j++) if (delt->words[j] != selt->words[j]) - return 0; + return false; } return !selt && !delt; } @@ -480,13 +480,13 @@ lbitset_copy (bitset dst, bitset src) } -/* Copy bits from bitset SRC to bitset DST. Return non-zero if +/* Copy bits from bitset SRC to bitset DST. Return true if bitsets different. */ -static inline int +static inline bool lbitset_copy_cmp (bitset dst, bitset src) { if (src == dst) - return 0; + return false; if (!LBITSET_HEAD (dst)) { @@ -495,10 +495,10 @@ lbitset_copy_cmp (bitset dst, bitset src) } if (lbitset_equal_p (dst, src)) - return 0; + return false; lbitset_copy (dst, src); - return 1; + return true; } @@ -547,16 +547,15 @@ lbitset_reset (bitset dst, bitset_bindex bitno) /* Test bit BITNO in bitset SRC. */ -static int +static bool lbitset_test (bitset src, bitset_bindex bitno) { bitset_windex windex = bitno / BITSET_WORD_BITS; - if (!lbitset_elt_find (src, windex, LBITSET_FIND)) - return 0; - - return (src->b.cdata[windex - src->b.cindex] - >> (bitno % BITSET_WORD_BITS)) & 1; + return (lbitset_elt_find (src, windex, LBITSET_FIND) + && ((src->b.cdata[windex - src->b.cindex] + >> (bitno % BITSET_WORD_BITS)) + & 1)); } @@ -865,13 +864,11 @@ lbitset_list (bitset bset, bitset_bindex *list, } -static int +static bool lbitset_empty_p (bitset dst) { lbitset_weed (dst); - if (LBITSET_HEAD (dst)) - return 0; - return 1; + return !LBITSET_HEAD (dst); } @@ -934,8 +931,8 @@ lbitset_not (bitset dst, bitset src) } -/* Return 1 if DST == DST | SRC. */ -static int +/* Is DST == DST | SRC? */ +static bool lbitset_subset_p (bitset dst, bitset src) { lbitset_elt *selt; @@ -965,14 +962,14 @@ lbitset_subset_p (bitset dst, bitset src) for (j = 0; j < LBITSET_ELT_WORDS; j++) if (delt->words[j] != (selt->words[j] | delt->words[j])) - return 0; + return false; } - return 1; + return true; } -/* Return 1 if DST & SRC == 0. */ -static int +/* Is DST & SRC == 0? */ +static bool lbitset_disjoint_p (bitset dst, bitset src) { lbitset_elt *selt; @@ -1001,13 +998,13 @@ lbitset_disjoint_p (bitset dst, bitset src) for (j = 0; j < LBITSET_ELT_WORDS; j++) if (selt->words[j] & delt->words[j]) - return 0; + return false; } - return 1; + return true; } -static int +static bool lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) { lbitset_elt *selt1 = LBITSET_HEAD (src1); @@ -1022,7 +1019,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) bitset_word *srcp1; bitset_word *srcp2; bitset_word *dstp; - int changed = 0; + bool changed = false; unsigned int i; LBITSET_HEAD (dst) = 0; @@ -1066,7 +1063,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) elements that we've skipped. */ while (delt && delt->index < windex) { - changed = 1; + changed = true; dtmp = delt; delt = delt->next; lbitset_elt_free (dtmp); @@ -1093,7 +1090,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1106,7 +1103,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1119,7 +1116,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1132,7 +1129,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1157,7 +1154,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) /* If we have elements of DST left over, free them all. */ if (delt) { - changed = 1; + changed = true; lbitset_prune (dst, delt); } @@ -1165,12 +1162,12 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) } -static int +static bool lbitset_and_cmp (bitset dst, bitset src1, bitset src2) { lbitset_elt *selt1 = LBITSET_HEAD (src1); lbitset_elt *selt2 = LBITSET_HEAD (src2); - int changed; + bool changed; if (!selt2) { @@ -1197,12 +1194,12 @@ lbitset_and (bitset dst, bitset src1, bitset src2) } -static int +static bool lbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { lbitset_elt *selt1 = LBITSET_HEAD (src1); lbitset_elt *selt2 = LBITSET_HEAD (src2); - int changed; + bool changed; if (!selt2) { @@ -1226,7 +1223,7 @@ lbitset_andn (bitset dst, bitset src1, bitset src2) } -static int +static bool lbitset_or_cmp (bitset dst, bitset src1, bitset src2) { lbitset_elt *selt1 = LBITSET_HEAD (src1); @@ -1251,7 +1248,7 @@ lbitset_or (bitset dst, bitset src1, bitset src2) } -static int +static bool lbitset_xor_cmp (bitset dst, bitset src1, bitset src2) { lbitset_elt *selt1 = LBITSET_HEAD (src1); @@ -1337,7 +1334,7 @@ lbitset_release_memory (void) lbitset_free_list = 0; if (lbitset_obstack_init) { - lbitset_obstack_init = 0; + lbitset_obstack_init = false; obstack_free (&lbitset_obstack, NULL); } } diff --git a/src/conflicts.c b/src/conflicts.c index fe1f6f9..44546e1 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -365,7 +365,7 @@ count_sr_conflicts (state *s) +`----------------------------------------------------------------*/ static int -count_rr_conflicts (state *s, int one_per_token) +count_rr_conflicts (state *s, bool one_per_token) { int i; reductions *reds = s->reductions; @@ -463,7 +463,7 @@ conflicts_print (void) /* Is the number of SR conflicts OK? Either EXPECTED_CONFLICTS is not set, and then we want 0 SR, or else it is specified, in which case we want equality. */ - int src_ok = 0; + bool src_ok = false; int src_total = 0; int rrc_total = 0; diff --git a/src/getargs.c b/src/getargs.c index 363e6aa..68a7016 100644 --- a/src/getargs.c +++ b/src/getargs.c @@ -43,15 +43,15 @@ #include "getargs.h" #include "uniqstr.h" -int debug_flag = 0; -int defines_flag = 0; -int locations_flag = 0; -int no_lines_flag = 0; -int no_parser_flag = 0; +bool debug_flag; +bool defines_flag; +bool locations_flag; +bool no_lines_flag; +bool no_parser_flag; int report_flag = report_none; -int token_table_flag = 0; -int yacc_flag = 0; /* for -y */ -int graph_flag = 0; +bool token_table_flag; +bool yacc_flag; /* for -y */ +bool graph_flag; int trace_flag = trace_none; bool nondeterministic_parser = false; @@ -284,6 +284,12 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ /* Shorts options. */ const char *short_options = "yvegdhr:ltknVo:b:p:S:T::"; +/* Values for long options that do not have single-letter equivalents. */ +enum +{ + LOCATIONS_OPTION = CHAR_MAX + 1 +}; + static struct option const long_options[] = { /* Operation modes. */ @@ -314,7 +320,7 @@ static struct option const long_options[] = /* Parser. */ { "debug", no_argument, 0, 't' }, - { "locations", no_argument, &locations_flag, 1 }, + { "locations", no_argument, 0, LOCATIONS_OPTION }, { "no-lines", no_argument, 0, 'l' }, { "no-parser", no_argument, 0, 'n' }, { "raw", no_argument, 0, 0 }, @@ -346,7 +352,7 @@ getargs (int argc, char *argv[]) break; case 'y': - yacc_flag = 1; + yacc_flag = true; break; case 'h': @@ -358,7 +364,7 @@ getargs (int argc, char *argv[]) case 'g': /* Here, the -g and --graph=FILE options are differentiated. */ - graph_flag = 1; + graph_flag = true; if (optarg) spec_graph_file = AS_FILE_NAME (optarg); break; @@ -377,25 +383,29 @@ getargs (int argc, char *argv[]) case 'd': /* Here, the -d and --defines options are differentiated. */ - defines_flag = 1; + defines_flag = true; if (optarg) spec_defines_file = AS_FILE_NAME (optarg); break; case 'l': - no_lines_flag = 1; + no_lines_flag = true; + break; + + case LOCATIONS_OPTION: + locations_flag = true; break; case 'k': - token_table_flag = 1; + token_table_flag = true; break; case 'n': - no_parser_flag = 1; + no_parser_flag = true; break; case 't': - debug_flag = 1; + debug_flag = true; break; case 'o': diff --git a/src/getargs.h b/src/getargs.h index af716e7..630e8ce 100644 --- a/src/getargs.h +++ b/src/getargs.h @@ -26,14 +26,14 @@ extern const char *skeleton; /* for -S */ extern const char *include; /* for -I */ -extern int debug_flag; /* for -t */ -extern int defines_flag; /* for -d */ -extern int locations_flag; -extern int no_lines_flag; /* for -l */ -extern int no_parser_flag; /* for -n */ -extern int token_table_flag; /* for -k */ -extern int graph_flag; /* for -g */ -extern int yacc_flag; /* for -y */ +extern bool debug_flag; /* for -t */ +extern bool defines_flag; /* for -d */ +extern bool locations_flag; +extern bool no_lines_flag; /* for -l */ +extern bool no_parser_flag; /* for -n */ +extern bool token_table_flag; /* for -k */ +extern bool graph_flag; /* for -g */ +extern bool yacc_flag; /* for -y */ /* GLR_PARSER is true if the input file says to use the GLR (Generalized LR) parser, and to output some additional information diff --git a/src/lalr.c b/src/lalr.c index 4e59d0a..7273805 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -1,6 +1,6 @@ /* Compute look-ahead criteria for Bison. - Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 + Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -239,7 +239,7 @@ build_relations (void) for (rulep = derives[symbol1 - ntokens]; *rulep; rulep++) { - int done; + bool done; int length = 1; item_number *rp; state *s = states[from_state[i]]; @@ -256,10 +256,10 @@ build_relations (void) add_lookback_edge (s, *rulep, i); length--; - done = 0; + done = false; while (!done) { - done = 1; + done = true; rp--; /* JF added rp>=ritem && I hope to god its right! */ if (rp >= ritem && ISVAR (*rp)) @@ -268,7 +268,7 @@ build_relations (void) edge[nedges++] = map_goto (states1[--length], item_number_as_symbol_number (*rp)); if (nullable[*rp - ntokens]) - done = 0; + done = false; } } } diff --git a/src/muscle_tab.h b/src/muscle_tab.h index 4dd9b0b..3397385 100644 --- a/src/muscle_tab.h +++ b/src/muscle_tab.h @@ -30,6 +30,12 @@ void muscle_free (void); /* An obstack dedicated to receive muscle keys and values. */ extern struct obstack muscle_obstack; +#define MUSCLE_INSERT_BOOL(Key, Value) \ +{ \ + int v = Value; \ + MUSCLE_INSERT_INT (Key, v); \ +} + #define MUSCLE_INSERT_INT(Key, Value) \ { \ obstack_fgrow1 (&muscle_obstack, "%d", Value); \ diff --git a/src/nullable.c b/src/nullable.c index cf6cfd6..9357535 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -83,10 +83,10 @@ nullable_compute (void) { /* This rule has a non empty RHS. */ item_number *rp = NULL; - int any_tokens = 0; + bool any_tokens = false; for (rp = rules_ruleno->rhs; *rp >= 0; ++rp) if (ISTOKEN (*rp)) - any_tokens = 1; + any_tokens = true; /* This rule has only nonterminals: schedule it for the second pass. */ @@ -108,7 +108,7 @@ nullable_compute (void) if (rules_ruleno->useful && ! nullable[rules_ruleno->lhs->number - ntokens]) { - nullable[rules_ruleno->lhs->number - ntokens] = 1; + nullable[rules_ruleno->lhs->number - ntokens] = true; *s2++ = rules_ruleno->lhs->number; } } @@ -121,7 +121,7 @@ nullable_compute (void) if (--rcount[r->number] == 0) if (r->useful && ! nullable[r->lhs->number - ntokens]) { - nullable[r->lhs->number - ntokens] = 1; + nullable[r->lhs->number - ntokens] = true; *s2++ = r->lhs->number; } } diff --git a/src/output.c b/src/output.c index 939775a..8acd935 100644 --- a/src/output.c +++ b/src/output.c @@ -45,7 +45,7 @@ void scan_skel (FILE *); static struct obstack format_obstack; -int error_verbose = 0; +bool error_verbose = false; @@ -341,7 +341,7 @@ static void token_definitions_output (FILE *out) { int i; - int first = 1; + char const *sep = ""; fputs ("m4_define([b4_tokens], \n[", out); for (i = 0; i < ntokens; ++i) @@ -376,9 +376,8 @@ token_definitions_output (FILE *out) continue; fprintf (out, "%s[[[%s]], [%d]]", - first ? "" : ",\n", sym->tag, number); - - first = 0; + sep, sym->tag, number); + sep = ",\n"; } fputs ("])\n\n", out); } @@ -392,7 +391,7 @@ static void symbol_destructors_output (FILE *out) { int i; - int first = 1; + char const *sep = ""; fputs ("m4_define([b4_symbol_destructors], \n[", out); for (i = 0; i < nsyms; ++i) @@ -403,8 +402,8 @@ symbol_destructors_output (FILE *out) /* Filename, lineno, Symbol-name, Symbol-number, destructor, typename. */ - fprintf (out, "%s[", - first ? "" : ",\n"); + fprintf (out, "%s[", sep); + sep = ",\n"; escaped_file_name_output (out, sym->destructor_location.start.file); fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]", sym->destructor_location.start.line, @@ -412,8 +411,6 @@ symbol_destructors_output (FILE *out) sym->number, sym->destructor, sym->type_name); - - first = 0; } fputs ("])\n\n", out); } @@ -427,7 +424,7 @@ static void symbol_printers_output (FILE *out) { int i; - int first = 1; + char const *sep = ""; fputs ("m4_define([b4_symbol_printers], \n[", out); for (i = 0; i < nsyms; ++i) @@ -438,8 +435,8 @@ symbol_printers_output (FILE *out) /* Filename, lineno, Symbol-name, Symbol-number, printer, typename. */ - fprintf (out, "%s[", - first ? "" : ",\n"); + fprintf (out, "%s[", sep); + sep = ",\n"; escaped_file_name_output (out, sym->printer_location.start.file); fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]", sym->printer_location.start.line, @@ -447,8 +444,6 @@ symbol_printers_output (FILE *out) sym->number, sym->printer, sym->type_name); - - first = 0; } fputs ("])\n\n", out); } @@ -595,12 +590,12 @@ static void prepare (void) { /* Flags. */ - MUSCLE_INSERT_INT ("debug", debug_flag); - MUSCLE_INSERT_INT ("defines_flag", defines_flag); - MUSCLE_INSERT_INT ("error_verbose", error_verbose); - MUSCLE_INSERT_INT ("locations_flag", locations_flag); - MUSCLE_INSERT_INT ("pure", pure_parser); - MUSCLE_INSERT_INT ("synclines_flag", !no_lines_flag); + MUSCLE_INSERT_BOOL ("debug", debug_flag); + MUSCLE_INSERT_BOOL ("defines_flag", defines_flag); + MUSCLE_INSERT_BOOL ("error_verbose", error_verbose); + MUSCLE_INSERT_BOOL ("locations_flag", locations_flag); + MUSCLE_INSERT_BOOL ("pure", pure_parser); + MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag); /* File names. */ MUSCLE_INSERT_STRING ("prefix", spec_name_prefix ? spec_name_prefix : "yy"); diff --git a/src/output.h b/src/output.h index ece5b2f..de69e6a 100644 --- a/src/output.h +++ b/src/output.h @@ -1,5 +1,5 @@ /* Output the generated parsing program for bison, - Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,7 +21,7 @@ #ifndef OUTPUT_H_ # define OUTPUT_H_ -extern int error_verbose; +extern bool error_verbose; /* Output the parsing tables and the parser code to FTABLE. */ void output (void); diff --git a/src/parse-gram.y b/src/parse-gram.y index 02608bb..dad4e8c 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -175,26 +175,26 @@ declarations: declaration: grammar_declaration | PROLOGUE { prologue_augment ($1, @1); } -| "%debug" { debug_flag = 1; } +| "%debug" { debug_flag = true; } | "%define" string_content string_content { muscle_insert ($2, $3); } -| "%defines" { defines_flag = 1; } -| "%error-verbose" { error_verbose = 1; } +| "%defines" { defines_flag = true; } +| "%error-verbose" { error_verbose = true; } | "%expect" INT { expected_conflicts = $2; } | "%file-prefix" "=" string_content { spec_file_prefix = $3; } | "%glr-parser" { nondeterministic_parser = true; glr_parser = true; } | "%lex-param {...}" { add_param ("lex_param", $1, @1); } -| "%locations" { locations_flag = 1; } +| "%locations" { locations_flag = true; } | "%name-prefix" "=" string_content { spec_name_prefix = $3; } -| "%no-lines" { no_lines_flag = 1; } +| "%no-lines" { no_lines_flag = true; } | "%nondeterministic-parser" { nondeterministic_parser = true; } | "%output" "=" string_content { spec_outfile = $3; } | "%parse-param {...}" { add_param ("parse_param", $1, @1); } | "%pure-parser" { pure_parser = true; } | "%skeleton" string_content { skeleton = $2; } -| "%token-table" { token_table_flag = 1; } +| "%token-table" { token_table_flag = true; } | "%verbose" { report_flag = report_states; } -| "%yacc" { yacc_flag = 1; } +| "%yacc" { yacc_flag = true; } | ";" ; @@ -207,7 +207,7 @@ grammar_declaration: } | "%union {...}" { - typed = 1; + typed = true; MUSCLE_INSERT_INT ("stype_line", @1.start.line); muscle_insert ("stype", $1); } diff --git a/src/print.c b/src/print.c index dcf7df3..4f85524 100644 --- a/src/print.c +++ b/src/print.c @@ -327,16 +327,16 @@ print_reductions (FILE *out, state *s) if (reds->lookaheads) for (i = 0; i < ntokens; i++) { - int count = bitset_test (shiftset, i); + bool count = bitset_test (shiftset, i); for (j = 0; j < reds->num; ++j) if (bitset_test (reds->lookaheads[j], i)) { - if (count == 0) + if (! count) { if (reds->rules[j] != default_rule) max_length (&width, symbols[i]->tag); - count++; + count = true; } else { @@ -356,21 +356,21 @@ print_reductions (FILE *out, state *s) if (reds->lookaheads) for (i = 0; i < ntokens; i++) { - int defaulted = 0; - int count = bitset_test (shiftset, i); + bool defaulted = false; + bool count = bitset_test (shiftset, i); for (j = 0; j < reds->num; ++j) if (bitset_test (reds->lookaheads[j], i)) { - if (count == 0) + if (! count) { if (reds->rules[j] != default_rule) print_reduction (out, width, symbols[i]->tag, reds->rules[j], true); else - defaulted = 1; - count++; + defaulted = true; + count = true; } else { @@ -378,7 +378,7 @@ print_reductions (FILE *out, state *s) print_reduction (out, width, symbols[i]->tag, default_rule, true); - defaulted = 0; + defaulted = false; print_reduction (out, width, symbols[i]->tag, reds->rules[j], false); diff --git a/src/print_graph.c b/src/print_graph.c index c92ae35..f70c143 100644 --- a/src/print_graph.c +++ b/src/print_graph.c @@ -1,6 +1,6 @@ /* Output a VCG description on generated parser, for Bison, - Copyright (C) 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -100,12 +100,13 @@ print_core (struct obstack *oout, state *s) { bitset_iterator biter; int k; - int not_first = 0; + char const *sep = ""; obstack_sgrow (oout, "["); BITSET_FOR_EACH (biter, reds->lookaheads[redno], k, 0) - obstack_fgrow2 (oout, "%s%s", - not_first++ ? ", " : "", - symbols[k]->tag); + { + obstack_fgrow2 (oout, "%s%s", sep, symbols[k]->tag); + sep = ", "; + } obstack_sgrow (oout, "]"); } } diff --git a/src/reader.c b/src/reader.c index 3f8cab8..a1baa8e 100644 --- a/src/reader.c +++ b/src/reader.c @@ -36,11 +36,11 @@ #include "symtab.h" static symbol_list *grammar = NULL; -static int start_flag = 0; +static bool start_flag = false; merger_list *merge_functions; -/* Nonzero if %union has been seen. */ -int typed = 0; +/* Has %union been seen? */ +bool typed = false; /*-----------------------. | Set the start symbol. | @@ -53,7 +53,7 @@ grammar_start_symbol_set (symbol *sym, location loc) complain_at (loc, _("multiple %s declarations"), "%start"); else { - start_flag = 1; + start_flag = true; startsymbol = sym; startsymbol_location = loc; } @@ -213,7 +213,7 @@ grammar_rule_begin (symbol *lhs, location loc) { startsymbol = lhs; startsymbol_location = loc; - start_flag = 1; + start_flag = true; } /* Start a new rule and record its lhs. */ diff --git a/src/reader.h b/src/reader.h index 56c4f5c..3176bdb 100644 --- a/src/reader.h +++ b/src/reader.h @@ -72,6 +72,6 @@ void free_merger_functions (void); extern merger_list *merge_functions; -extern int typed; +extern bool typed; #endif /* !READER_H_ */ diff --git a/src/scan-gram.l b/src/scan-gram.l index 337f9db..5a3768e 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -841,7 +841,7 @@ static inline bool handle_action_at (char *text, location loc) { char *cp = text + 1; - locations_flag = 1; + locations_flag = true; if (! current_rule) return false; diff --git a/src/state.c b/src/state.c index 730427f..e6d15f2 100644 --- a/src/state.c +++ b/src/state.c @@ -236,12 +236,13 @@ state_rule_lookaheads_print (state *s, rule *r, FILE *out) { bitset_iterator biter; int k; - int not_first = 0; + char const *sep = ""; fprintf (out, " ["); BITSET_FOR_EACH (biter, reds->lookaheads[red], k, 0) - fprintf (out, "%s%s", - not_first++ ? ", " : "", - symbols[k]->tag); + { + fprintf (out, "%s%s", sep, symbols[k]->tag); + sep = ", "; + } fprintf (out, "]"); } } diff --git a/src/tables.c b/src/tables.c index 80f47e2..2682472 100644 --- a/src/tables.c +++ b/src/tables.c @@ -243,8 +243,8 @@ action_row (state *s) transitions *trans = s->transitions; errs *errp = s->errs; /* Set to nonzero to inhibit having any default reduction. */ - int nodefault = 0; - int conflicted = 0; + bool nodefault = false; + bool conflicted = false; for (i = 0; i < ntokens; i++) actrow[i] = conflrow[i] = 0; @@ -264,7 +264,10 @@ action_row (state *s) /* and record this rule as the rule to use if that token follows. */ if (actrow[j] != 0) - conflicted = conflrow[j] = 1; + { + conflicted = true; + conflrow[j] = 1; + } actrow[j] = rule_number_as_item_number (reds->rules[i]->number); } } @@ -278,13 +281,16 @@ action_row (state *s) state *shift_state = trans->states[i]; if (actrow[sym] != 0) - conflicted = conflrow[sym] = 1; + { + conflicted = true; + conflrow[sym] = 1; + } actrow[sym] = state_number_as_int (shift_state->number); /* Do not use any default reduction if there is a shift for error */ if (sym == errtoken->number) - nodefault = 1; + nodefault = true; } /* See which tokens are an explicit error in this state (due to @@ -669,7 +675,7 @@ pack_vector (vector_number vector) for (j = lowzero - from[0]; ; j++) { int k; - int ok = 1; + bool ok = true; if (table_size <= j) abort (); @@ -681,12 +687,12 @@ pack_vector (vector_number vector) table_grow (loc); if (table[loc] != 0) - ok = 0; + ok = false; } for (k = 0; ok && k < vector; k++) if (pos[k] == j) - ok = 0; + ok = false; if (ok) { -- 2.7.4