Switch from 'int' to 'bool' where that makes sense.

This commit is contained in:
Paul Eggert
2003-05-24 19:16:02 +00:00
parent 637fa3f83e
commit d08290769c
25 changed files with 376 additions and 295 deletions

View File

@@ -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;

View File

@@ -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':

View File

@@ -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

View File

@@ -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;
}
}
}

View File

@@ -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); \

View File

@@ -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;
}
}

View File

@@ -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");

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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, "]");
}
}

View File

@@ -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. */

View File

@@ -72,6 +72,6 @@ void free_merger_functions (void);
extern merger_list *merge_functions;
extern int typed;
extern bool typed;
#endif /* !READER_H_ */

View File

@@ -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;

View File

@@ -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, "]");
}
}

View File

@@ -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)
{