Port to GCC 2.95. First two problems reported by Michael Deutschmann in

<http://lists.gnu.org/archive/html/bug-bison/2006-09/msg00018.html>.

* src/parse-gram.y (symbol_declaration): Don't put statements
before declarations; it's not portable to C89.
* src/scan-code.l (handle_action_at): Likewise.

* src/scan-code.l: Always initialize braces_level; the old code
left it uninitialized and therefore had undefined behavior.

Don't attempt to redefine 'assert', since it runs afoul of
systems where standard headers (mistakenly) include <assert.h>.
Instead, define and use our own alternative, called 'aver'.
* src/reader.c: Don't include assert.h, since we no longer
use assert.
* src/scan-code.l: Likewise.
* src/system.h (assert): Remove, replacing with....
(aver): New function, taking a bool arg.  All uses changed.
* src/tables.c (pack_vector): Ensure that aver arg is bool,
not merely an integer.
This commit is contained in:
Paul Eggert
2006-09-15 16:34:48 +00:00
parent 3fa3725adb
commit 4f82b42a9d
13 changed files with 78 additions and 48 deletions

View File

@@ -1,3 +1,26 @@
2006-09-15 Paul Eggert <eggert@cs.ucla.edu>
Port to GCC 2.95. First two problems reported by Michael Deutschmann in
<http://lists.gnu.org/archive/html/bug-bison/2006-09/msg00018.html>.
* src/parse-gram.y (symbol_declaration): Don't put statements
before declarations; it's not portable to C89.
* src/scan-code.l (handle_action_at): Likewise.
* src/scan-code.l: Always initialize braces_level; the old code
left it uninitialized and therefore had undefined behavior.
Don't attempt to redefine 'assert', since it runs afoul of
systems where standard headers (mistakenly) include <assert.h>.
Instead, define and use our own alternative, called 'aver'.
* src/reader.c: Don't include assert.h, since we no longer
use assert.
* src/scan-code.l: Likewise.
* src/system.h (assert): Remove, replacing with....
(aver): New function, taking a bool arg. All uses changed.
* src/tables.c (pack_vector): Ensure that aver arg is bool,
not merely an integer.
2006-09-15 Bob Rossi <bob@brasko.net>
* data/Makefile.am (dist_pkgdata_DATA): Add push.c.

View File

@@ -1,7 +1,7 @@
/* Generate the nondeterministic finite state machine for Bison.
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2004, 2005 Free
Software Foundation, Inc.
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2004, 2005, 2006
Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -282,7 +282,7 @@ save_reductions (state *s)
if (r == 0)
{
/* This is "reduce 0", i.e., accept. */
assert (!final_state);
aver (!final_state);
final_state = s;
}
}

View File

@@ -94,7 +94,7 @@ set_goto_map (void)
ngotos++;
/* Abort if (ngotos + 1) would overflow. */
assert (ngotos != GOTO_NUMBER_MAXIMUM);
aver (ngotos != GOTO_NUMBER_MAXIMUM);
goto_map[TRANSITION_SYMBOL (sp, i) - ntokens]++;
}
@@ -153,7 +153,7 @@ map_goto (state_number s0, symbol_number sym)
for (;;)
{
assert (low <= high);
aver (low <= high);
middle = (low + high) / 2;
s = from_state[middle];
if (s == s0)

View File

@@ -104,8 +104,8 @@ nullable_compute (void)
else
{
/* This rule has an empty RHS. */
assert (item_number_as_rule_number (rules_ruleno->rhs[0])
== ruleno);
aver (item_number_as_rule_number (rules_ruleno->rhs[0])
== ruleno);
if (rules_ruleno->useful
&& ! nullable[rules_ruleno->lhs->number - ntokens])
{

View File

@@ -235,7 +235,7 @@ prepare_rules (void)
/* Merger-function index (GLR). */
merger[r] = rules[r].merger;
}
assert (i == nritems);
aver (i == nritems);
muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems);
muscle_insert_unsigned_int_table ("prhs", prhs, 0, 0, nrules);
@@ -342,7 +342,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. */
assert (number != USER_NUMBER_ALIAS);
aver (number != USER_NUMBER_ALIAS);
/* Skip error token. */
if (sym == errtoken)

View File

@@ -345,8 +345,8 @@ symbol_declaration:
}
| "%type" TYPE symbols.1
{
tag_seen = true;
symbol_list *list;
tag_seen = true;
for (list = $3; list; list = list->next)
symbol_type_set (list->content.sym, $2, @2);
symbol_list_free ($3);

View File

@@ -22,7 +22,6 @@
#include <config.h>
#include "system.h"
#include <assert.h>
#include <quotearg.h>
@@ -148,7 +147,7 @@ record_merge_function_type (int merger, uniqstr type, location declaration_loc)
merge_function != NULL && merger_find != merger;
merge_function = merge_function->next)
merger_find += 1;
assert (merge_function != NULL && merger_find == merger);
aver (merge_function != NULL && merger_find == merger);
if (merge_function->type != NULL && !UNIQSTR_EQ (merge_function->type, type))
{
complain_at (declaration_loc,
@@ -515,15 +514,15 @@ packgram (void)
}
/* An item ends by the rule number (negated). */
ritem[itemno++] = rule_number_as_item_number (ruleno);
assert (itemno < ITEM_NUMBER_MAX);
aver (itemno < ITEM_NUMBER_MAX);
++ruleno;
assert (ruleno < RULE_NUMBER_MAX);
aver (ruleno < RULE_NUMBER_MAX);
if (p)
p = p->next;
}
assert (itemno == nritems);
aver (itemno == nritems);
if (trace_flag & trace_sets)
ritem_print (stderr);
@@ -614,7 +613,7 @@ check_and_convert_grammar (void)
node = node->next)
;
}
assert (node != NULL);
aver (node != NULL);
grammar_start_symbol_set (node->content.sym,
node->content.sym->location);
}
@@ -635,7 +634,7 @@ check_and_convert_grammar (void)
grammar = p;
}
assert (nsyms <= SYMBOL_NUMBER_MAXIMUM && nsyms == ntokens + nvars);
aver (nsyms <= SYMBOL_NUMBER_MAXIMUM && nsyms == ntokens + nvars);
/* Assign the symbols their symbol numbers. Write #defines for the
token symbols into FDEFINES if requested. */

View File

@@ -35,7 +35,6 @@
#include "complain.h"
#include "reader.h"
#include "getargs.h"
#include <assert.h>
#include <get-errno.h>
#include <quote.h>
@@ -79,14 +78,14 @@ splice (\\[ \f\t\v]*\n)*
%{
/* Nesting level of the current code in braces. */
int braces_level IF_LINT (= 0);
int braces_level = 0;
/* This scanner is special: it is invoked only once, henceforth
is expected to return only once. This initialization is
therefore done once per action to translate. */
assert (sc_context == SC_SYMBOL_ACTION
|| sc_context == SC_RULE_ACTION
|| sc_context == INITIAL);
aver (sc_context == SC_SYMBOL_ACTION
|| sc_context == SC_RULE_ACTION
|| sc_context == INITIAL);
BEGIN sc_context;
%}
@@ -339,13 +338,12 @@ static void
handle_action_at (symbol_list *rule, char *text, location at_loc)
{
char *cp = text + 1;
locations_flag = true;
int effective_rule_length;
int effective_rule_length =
(rule->midrule_parent_rule
? rule->midrule_parent_rhs_index - 1
: symbol_list_length (rule->next));
if (rule->midrule_parent_rule)
effective_rule_length = rule->midrule_parent_rhs_index - 1;
else
effective_rule_length = symbol_list_length (rule->next);
locations_flag = true;
if (*cp == '$')
obstack_sgrow (&obstack_for_string, "]b4_lhs_location[");

View File

@@ -61,7 +61,7 @@ transitions_to (transitions *shifts, symbol_number sym)
int j;
for (j = 0; ; j++)
{
assert (j < shifts->num);
aver (j < shifts->num);
if (TRANSITION_SYMBOL (shifts, j) == sym)
return shifts->states[j];
}
@@ -135,7 +135,7 @@ state_new (symbol_number accessing_symbol,
state *res;
size_t items_size = nitems * sizeof *core;
assert (nstates < STATE_NUMBER_MAXIMUM);
aver (nstates < STATE_NUMBER_MAXIMUM);
res = xmalloc (offsetof (state, items) + items_size);
res->number = nstates++;
@@ -176,7 +176,7 @@ state_free (state *s)
void
state_transitions_set (state *s, int num, state **trans)
{
assert (!s->transitions);
aver (!s->transitions);
s->transitions = transitions_new (num, trans);
}
@@ -188,7 +188,7 @@ state_transitions_set (state *s, int num, state **trans)
void
state_reductions_set (state *s, int num, rule **reds)
{
assert (!s->reductions);
aver (!s->reductions);
s->reductions = reductions_new (num, reds);
}
@@ -212,7 +212,7 @@ state_reduction_find (state *s, rule *r)
void
state_errs_set (state *s, int num, symbol **tokens)
{
assert (!s->errs);
aver (!s->errs);
s->errs = errs_new (num, tokens);
}

View File

@@ -185,7 +185,7 @@ symbol_list_n_type_name_get (symbol_list *l, location loc, int n)
complain_at (loc, _("invalid $ value: $%d"), n);
return NULL;
}
assert (l->content_type == SYMLIST_SYMBOL);
aver (l->content_type == SYMLIST_SYMBOL);
return l->content.sym->type_name;
}

View File

@@ -383,7 +383,7 @@ symbol_user_token_number_set (symbol *sym, int user_token_number, location loc)
{
int *user_token_numberp;
assert (sym->class == token_sym);
aver (sym->class == token_sym);
if (sym->user_token_number != USER_NUMBER_ALIAS)
user_token_numberp = &sym->user_token_number;
@@ -546,7 +546,7 @@ symbol_pack (symbol *this)
this->number = this->alias->number = 0;
else
{
assert (this->alias->number != NUMBER_UNDEFINED);
aver (this->alias->number != NUMBER_UNDEFINED);
this->number = this->alias->number;
}
}
@@ -555,7 +555,7 @@ symbol_pack (symbol *this)
return true;
}
else /* this->class == token_sym */
assert (this->number != NUMBER_UNDEFINED);
aver (this->number != NUMBER_UNDEFINED);
symbols[this->number] = this;
return true;

View File

@@ -136,6 +136,21 @@ typedef size_t uintptr_t;
#include <stdbool.h>
/*-------------.
| Assertions. |
`-------------*/
/* <assert.h>'s assertions are too heavyweight, and can be disabled
too easily, so use aver rather than assert. */
static inline void
aver (bool assertion)
{
if (! assertion)
abort ();
}
/*-----------.
| Obstacks. |
`-----------*/
@@ -210,11 +225,6 @@ 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). |
`---------------------------------------------*/

View File

@@ -1,7 +1,7 @@
/* Output the generated parsing program for Bison.
Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003, 2004,
2005 Free Software Foundation, Inc.
2005, 2006 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -202,14 +202,14 @@ conflict_row (state *s)
&& (actrow[j]
!= rule_number_as_item_number (reds->rules[i]->number)))
{
assert (0 < conflict_list_free);
aver (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. */
assert (0 < conflict_list_free);
aver (0 < conflict_list_free);
conflict_list[conflict_list_cnt] = 0;
conflict_list_cnt += 1;
conflict_list_free -= 1;
@@ -673,14 +673,14 @@ pack_vector (vector_number vector)
base_number *to = tos[i];
unsigned int *conflict_to = conflict_tos[i];
assert (t);
aver (t != 0);
for (j = lowzero - from[0]; ; j++)
{
int k;
bool ok = true;
assert (j < table_size);
aver (j < table_size);
for (k = 0; ok && k < t; k++)
{
@@ -713,7 +713,7 @@ pack_vector (vector_number vector)
if (loc > high)
high = loc;
assert (BASE_MINIMUM <= j && j <= BASE_MAXIMUM);
aver (BASE_MINIMUM <= j && j <= BASE_MAXIMUM);
return j;
}
}