mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 12:53:03 +00:00
Be a bit more systematic about using 'abort'.
* lib/abitset.c (abitset_test): Remove ATTRIBUTE_UNUSED; not needed. * lib/bitset.c (bitset_bytes, bitset_init, bitset_op4_cmp): Put 'default: abort ();' before some other case, to satisfy older pedantic compilers. * lib/bitset_stats.c (bitset_stats_init): Likewise. * lib/ebitset.c (ebitset_elt_find, ebitset_op3_cmp): Likewise. * lib/lbitset.c (lbitset_elt_find, lbitset_op3_cmp): Likewise. * src/conflicts.c (resolve_sr_conflict): Likewise. * src/vcg.c (get_color_str, get_textmode_str, get_shape_str): (get_decision_str, get_orientation_str, get_node_alignment_str): (get_arrow_mode_str, get_crossing_type_str, get_view_str): (get_linestyle_str, get_arrowstyle_str): Likewise. * src/conflicts.c (resolve_sr_conflict): Use a default case rather than one for the one remaining enum value, to catch invalid enum values as well. * src/lalr.c (set_goto_map, map_goto): Prefer "assert (FOO);" to "if (!FOO) abort ();". * src/nullable.c (nullable_compute, token_definitions_output): Likewise. * src/reader.c (packgram, reader): Likewise. * src/state.c (transitions_to, state_new, state_reduction_find): Likewise. * src/symtab.c (symbol_user_token_number_set, symbol_make_alias): (symbol_pack): Likewise. * src/tables.c (conflict_row, pack_vector): Likewise. * src/scan-skel.l (QPUTS): Remove unnecessary parens. (BASE_QPUTS, "@output ".*\n): Remove unnecessary asserts. * src/system.h: Don't include <assert.h>. (assert): New macro.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* Find and resolve or report look-ahead conflicts for bison,
|
||||
|
||||
Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2003, 2004, 2005
|
||||
Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
@@ -216,6 +216,9 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
|
||||
|
||||
switch (symbols[i]->assoc)
|
||||
{
|
||||
default:
|
||||
abort ();
|
||||
|
||||
case right_assoc:
|
||||
log_resolution (redrule, i, right_resolution);
|
||||
flush_reduce (look_ahead_tokens, i);
|
||||
@@ -233,9 +236,6 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
|
||||
/* Record an explicit error for this token. */
|
||||
errors[nerrs++] = symbols[i];
|
||||
break;
|
||||
|
||||
case undef_assoc:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,8 +94,7 @@ set_goto_map (void)
|
||||
ngotos++;
|
||||
|
||||
/* Abort if (ngotos + 1) would overflow. */
|
||||
if (ngotos == GOTO_NUMBER_MAXIMUM)
|
||||
abort ();
|
||||
assert (ngotos != GOTO_NUMBER_MAXIMUM);
|
||||
|
||||
goto_map[TRANSITION_SYMBOL (sp, i) - ntokens]++;
|
||||
}
|
||||
@@ -154,8 +153,7 @@ map_goto (state_number s0, symbol_number sym)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (high < low)
|
||||
abort ();
|
||||
assert (low <= high);
|
||||
middle = (low + high) / 2;
|
||||
s = from_state[middle];
|
||||
if (s == s0)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Calculate which nonterminals can expand into the null string for Bison.
|
||||
|
||||
Copyright (C) 1984, 1989, 2000, 2001, 2002, 2003, 2004, 2005 Free
|
||||
Software Foundation, Inc.
|
||||
Copyright (C) 1984, 1989, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
@@ -104,8 +104,8 @@ nullable_compute (void)
|
||||
else
|
||||
{
|
||||
/* This rule has an empty RHS. */
|
||||
if (item_number_as_rule_number (rules_ruleno->rhs[0]) != ruleno)
|
||||
abort ();
|
||||
assert (item_number_as_rule_number (rules_ruleno->rhs[0])
|
||||
== ruleno);
|
||||
if (rules_ruleno->useful
|
||||
&& ! nullable[rules_ruleno->lhs->number - ntokens])
|
||||
{
|
||||
|
||||
@@ -239,8 +239,7 @@ prepare_rules (void)
|
||||
/* Merger-function index (GLR). */
|
||||
merger[r] = rules[r].merger;
|
||||
}
|
||||
if (i != nritems)
|
||||
abort ();
|
||||
assert (i == nritems);
|
||||
|
||||
muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems);
|
||||
muscle_insert_unsigned_int_table ("prhs", prhs, 0, 0, nrules);
|
||||
@@ -351,8 +350,7 @@ token_definitions_output (FILE *out)
|
||||
/* At this stage, if there are literal aliases, they are part of
|
||||
SYMBOLS, so we should not find symbols which are the aliases
|
||||
here. */
|
||||
if (number == USER_NUMBER_ALIAS)
|
||||
abort ();
|
||||
assert (number != USER_NUMBER_ALIAS);
|
||||
|
||||
/* Skip error token. */
|
||||
if (sym == errtoken)
|
||||
|
||||
@@ -469,8 +469,7 @@ packgram (void)
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
if (itemno != nritems)
|
||||
abort ();
|
||||
assert (itemno == nritems);
|
||||
|
||||
if (trace_flag & trace_sets)
|
||||
ritem_print (stderr);
|
||||
@@ -554,8 +553,7 @@ reader (void)
|
||||
grammar = p;
|
||||
}
|
||||
|
||||
if (! (nsyms <= SYMBOL_NUMBER_MAXIMUM && nsyms == ntokens + nvars))
|
||||
abort ();
|
||||
assert (nsyms <= SYMBOL_NUMBER_MAXIMUM && nsyms == ntokens + nvars);
|
||||
|
||||
xfclose (gram_in);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* Scan Bison Skeletons. -*- C -*-
|
||||
|
||||
Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
@@ -39,10 +40,10 @@
|
||||
#include "scan-skel.h"
|
||||
|
||||
#define QPUTS(String) \
|
||||
fputs (quotearg_style (c_quoting_style, (String)), yyout)
|
||||
fputs (quotearg_style (c_quoting_style, String), yyout)
|
||||
|
||||
#define BASE_QPUTS(File) \
|
||||
assert (File), QPUTS (base_name (File))
|
||||
QPUTS (base_name (File))
|
||||
|
||||
%}
|
||||
%%
|
||||
@@ -63,15 +64,9 @@
|
||||
if (*file_name == '@')
|
||||
{
|
||||
if (strcmp (file_name, "@output_header_name@") == 0)
|
||||
{
|
||||
assert (spec_defines_file);
|
||||
file_name = spec_defines_file;
|
||||
}
|
||||
file_name = spec_defines_file;
|
||||
else if (strcmp (file_name, "@output_parser_name@") == 0)
|
||||
{
|
||||
assert (parser_file_name);
|
||||
file_name = parser_file_name;
|
||||
}
|
||||
file_name = parser_file_name;
|
||||
else
|
||||
fatal ("invalid token in skeleton: %s", yytext);
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ transitions_to (transitions *shifts, symbol_number sym)
|
||||
int j;
|
||||
for (j = 0; ; j++)
|
||||
{
|
||||
if (shifts->num <= j)
|
||||
abort ();
|
||||
assert (j < shifts->num);
|
||||
if (TRANSITION_SYMBOL (shifts, j) == sym)
|
||||
return shifts->states[j];
|
||||
}
|
||||
@@ -136,8 +135,7 @@ state_new (symbol_number accessing_symbol,
|
||||
state *res;
|
||||
size_t items_size = nitems * sizeof *core;
|
||||
|
||||
if (STATE_NUMBER_MAXIMUM <= nstates)
|
||||
abort ();
|
||||
assert (nstates < STATE_NUMBER_MAXIMUM);
|
||||
|
||||
res = xmalloc (offsetof (state, items) + items_size);
|
||||
res->number = nstates++;
|
||||
@@ -214,8 +212,7 @@ state_reduction_find (state *s, rule *r)
|
||||
void
|
||||
state_errs_set (state *s, int num, symbol **tokens)
|
||||
{
|
||||
if (s->errs)
|
||||
abort ();
|
||||
assert (!s->errs);
|
||||
s->errs = errs_new (num, tokens);
|
||||
}
|
||||
|
||||
|
||||
14
src/symtab.c
14
src/symtab.c
@@ -223,8 +223,7 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
|
||||
void
|
||||
symbol_user_token_number_set (symbol *sym, int user_token_number, location loc)
|
||||
{
|
||||
if (sym->class != token_sym)
|
||||
abort ();
|
||||
assert (sym->class == token_sym);
|
||||
|
||||
if (sym->user_token_number != USER_NUMBER_UNDEFINED
|
||||
&& sym->user_token_number != user_token_number)
|
||||
@@ -295,8 +294,7 @@ symbol_make_alias (symbol *sym, symbol *symval, location loc)
|
||||
/* sym and symval combined are only one symbol. */
|
||||
nsyms--;
|
||||
ntokens--;
|
||||
if (ntokens != sym->number && ntokens != symval->number)
|
||||
abort ();
|
||||
assert (ntokens == sym->number || ntokens == symval->number);
|
||||
sym->number = symval->number =
|
||||
(symval->number < sym->number) ? symval->number : sym->number;
|
||||
symbol_type_set (symval, sym->type_name, loc);
|
||||
@@ -389,8 +387,7 @@ symbol_pack (symbol *this)
|
||||
this->number = this->alias->number = 0;
|
||||
else
|
||||
{
|
||||
if (this->alias->number == NUMBER_UNDEFINED)
|
||||
abort ();
|
||||
assert (this->alias->number != NUMBER_UNDEFINED);
|
||||
this->number = this->alias->number;
|
||||
}
|
||||
}
|
||||
@@ -399,10 +396,7 @@ symbol_pack (symbol *this)
|
||||
return true;
|
||||
}
|
||||
else /* this->class == token_sym */
|
||||
{
|
||||
if (this->number == NUMBER_UNDEFINED)
|
||||
abort ();
|
||||
}
|
||||
assert (this->number != NUMBER_UNDEFINED);
|
||||
|
||||
symbols[this->number] = this;
|
||||
return true;
|
||||
|
||||
@@ -64,8 +64,6 @@
|
||||
typedef size_t uintptr_t;
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <verify.h>
|
||||
#include <xalloc.h>
|
||||
|
||||
@@ -216,6 +214,11 @@ do { \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Assertions. <assert.h>'s assertions are too heavyweight, and can
|
||||
be disabled too easily, so implement it separately here. */
|
||||
#define assert(x) ((void) ((x) || (abort (), 0)))
|
||||
|
||||
|
||||
/*---------------------------------------------.
|
||||
| Debugging memory allocation (must be last). |
|
||||
`---------------------------------------------*/
|
||||
|
||||
15
src/tables.c
15
src/tables.c
@@ -202,16 +202,14 @@ conflict_row (state *s)
|
||||
&& (actrow[j]
|
||||
!= rule_number_as_item_number (reds->rules[i]->number)))
|
||||
{
|
||||
if (conflict_list_free <= 0)
|
||||
abort ();
|
||||
assert (0 < conflict_list_free);
|
||||
conflict_list[conflict_list_cnt] = reds->rules[i]->number + 1;
|
||||
conflict_list_cnt += 1;
|
||||
conflict_list_free -= 1;
|
||||
}
|
||||
|
||||
/* Leave a 0 at the end. */
|
||||
if (conflict_list_free <= 0)
|
||||
abort ();
|
||||
assert (0 < conflict_list_free);
|
||||
conflict_list[conflict_list_cnt] = 0;
|
||||
conflict_list_cnt += 1;
|
||||
conflict_list_free -= 1;
|
||||
@@ -675,16 +673,14 @@ pack_vector (vector_number vector)
|
||||
base_number *to = tos[i];
|
||||
unsigned int *conflict_to = conflict_tos[i];
|
||||
|
||||
if (!t)
|
||||
abort ();
|
||||
assert (t);
|
||||
|
||||
for (j = lowzero - from[0]; ; j++)
|
||||
{
|
||||
int k;
|
||||
bool ok = true;
|
||||
|
||||
if (table_size <= j)
|
||||
abort ();
|
||||
assert (j < table_size);
|
||||
|
||||
for (k = 0; ok && k < t; k++)
|
||||
{
|
||||
@@ -717,8 +713,7 @@ pack_vector (vector_number vector)
|
||||
if (loc > high)
|
||||
high = loc;
|
||||
|
||||
if (! (BASE_MINIMUM <= j && j <= BASE_MAXIMUM))
|
||||
abort ();
|
||||
assert (BASE_MINIMUM <= j && j <= BASE_MAXIMUM);
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
25
src/vcg.c
25
src/vcg.c
@@ -1,6 +1,7 @@
|
||||
/* VCG description handler for Bison.
|
||||
|
||||
Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
@@ -213,6 +214,7 @@ get_color_str (enum color color)
|
||||
{
|
||||
switch (color)
|
||||
{
|
||||
default: abort ();
|
||||
case white: return "white";
|
||||
case blue: return "blue";
|
||||
case red: return "red";
|
||||
@@ -245,7 +247,6 @@ get_color_str (enum color color)
|
||||
case orange: return "orange";
|
||||
case orchid: return "orchid";
|
||||
case black: return "black";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,10 +255,10 @@ get_textmode_str (enum textmode textmode)
|
||||
{
|
||||
switch (textmode)
|
||||
{
|
||||
default: abort ();
|
||||
case centered: return "center";
|
||||
case left_justify: return "left_justify";
|
||||
case right_justify: return "right_justify";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,11 +267,11 @@ get_shape_str (enum shape shape)
|
||||
{
|
||||
switch (shape)
|
||||
{
|
||||
default: abort ();
|
||||
case box: return "box";
|
||||
case rhomb: return "rhomb";
|
||||
case ellipse: return "ellipse";
|
||||
case triangle: return "triangle";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,9 +280,9 @@ get_decision_str (enum decision decision)
|
||||
{
|
||||
switch (decision)
|
||||
{
|
||||
default: abort ();
|
||||
case no: return "no";
|
||||
case yes: return "yes";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,11 +291,11 @@ get_orientation_str (enum orientation orientation)
|
||||
{
|
||||
switch (orientation)
|
||||
{
|
||||
default: abort ();
|
||||
case top_to_bottom: return "top_to_bottom";
|
||||
case bottom_to_top: return "bottom_to_top";
|
||||
case left_to_right: return "left_to_right";
|
||||
case right_to_left: return "right_to_left";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,10 +304,10 @@ get_node_alignment_str (enum alignment alignment)
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
default: abort ();
|
||||
case center: return "center";
|
||||
case top: return "top";
|
||||
case bottom: return "bottom";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,9 +316,9 @@ get_arrow_mode_str (enum arrow_mode arrow_mode)
|
||||
{
|
||||
switch (arrow_mode)
|
||||
{
|
||||
default: abort ();
|
||||
case fixed: return "fixed";
|
||||
case free_a: return "free";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,11 +327,11 @@ get_crossing_type_str (enum crossing_type crossing_type)
|
||||
{
|
||||
switch (crossing_type)
|
||||
{
|
||||
default: abort ();
|
||||
case bary: return "bary";
|
||||
case median: return "median";
|
||||
case barymedian: return "barymedian";
|
||||
case medianbary: return "medianbary";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,11 +342,11 @@ get_view_str (enum view view)
|
||||
so it is an error here if view == normal_view. */
|
||||
switch (view)
|
||||
{
|
||||
default: abort ();
|
||||
case cfish: return "cfish";
|
||||
case pfish: return "pfish";
|
||||
case fcfish: return "fcfish";
|
||||
case fpfish: return "fpfish";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,11 +355,11 @@ get_linestyle_str (enum linestyle linestyle)
|
||||
{
|
||||
switch (linestyle)
|
||||
{
|
||||
default: abort ();
|
||||
case continuous: return "continuous";
|
||||
case dashed: return "dashed";
|
||||
case dotted: return "dotted";
|
||||
case invisible: return "invisible";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,10 +368,10 @@ get_arrowstyle_str (enum arrowstyle arrowstyle)
|
||||
{
|
||||
switch (arrowstyle)
|
||||
{
|
||||
default: abort ();
|
||||
case solid: return "solid";
|
||||
case line: return "line";
|
||||
case none: return "none";
|
||||
default: abort (); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user