From 4f82b42a9d5ce6f0baa70714f25346ba9303be73 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Sep 2006 16:34:48 +0000 Subject: [PATCH] Port to GCC 2.95. First two problems reported by Michael Deutschmann in . * 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 . 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. --- ChangeLog | 23 +++++++++++++++++++++++ src/LR0.c | 6 +++--- src/lalr.c | 4 ++-- src/nullable.c | 4 ++-- src/output.c | 4 ++-- src/parse-gram.y | 2 +- src/reader.c | 13 ++++++------- src/scan-code.l | 20 +++++++++----------- src/state.c | 10 +++++----- src/symlist.c | 2 +- src/symtab.c | 6 +++--- src/system.h | 20 +++++++++++++++----- src/tables.c | 12 ++++++------ 13 files changed, 78 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index a68c8506..ab7be133 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2006-09-15 Paul Eggert + + Port to GCC 2.95. First two problems reported by Michael Deutschmann in + . + + * 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 . + 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 * data/Makefile.am (dist_pkgdata_DATA): Add push.c. diff --git a/src/LR0.c b/src/LR0.c index 259b8912..945d41f8 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -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; } } diff --git a/src/lalr.c b/src/lalr.c index e7f51455..f2bfa967 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -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) diff --git a/src/nullable.c b/src/nullable.c index 83a90e95..5bde4047 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -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]) { diff --git a/src/output.c b/src/output.c index c6eb02f7..ae8bf136 100644 --- a/src/output.c +++ b/src/output.c @@ -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) diff --git a/src/parse-gram.y b/src/parse-gram.y index 956ddd36..e9ec6366 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -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); diff --git a/src/reader.c b/src/reader.c index 4cc6f7b1..e48afaf0 100644 --- a/src/reader.c +++ b/src/reader.c @@ -22,7 +22,6 @@ #include #include "system.h" -#include #include @@ -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. */ diff --git a/src/scan-code.l b/src/scan-code.l index 6e2634ec..d41c6e46 100644 --- a/src/scan-code.l +++ b/src/scan-code.l @@ -35,7 +35,6 @@ #include "complain.h" #include "reader.h" #include "getargs.h" -#include #include #include @@ -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["); diff --git a/src/state.c b/src/state.c index 86fa1f49..280a2f41 100644 --- a/src/state.c +++ b/src/state.c @@ -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); } diff --git a/src/symlist.c b/src/symlist.c index d91c3fca..b97c2ecb 100644 --- a/src/symlist.c +++ b/src/symlist.c @@ -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; } diff --git a/src/symtab.c b/src/symtab.c index 4470f3a1..59dd2a0f 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -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; diff --git a/src/system.h b/src/system.h index 241a40d7..8c086616 100644 --- a/src/system.h +++ b/src/system.h @@ -136,6 +136,21 @@ typedef size_t uintptr_t; #include + +/*-------------. +| Assertions. | +`-------------*/ + +/* '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. '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). | `---------------------------------------------*/ diff --git a/src/tables.c b/src/tables.c index 000d027c..dc82cd03 100644 --- a/src/tables.c +++ b/src/tables.c @@ -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; } } -- 2.45.2