* src/system.h (CALLOC, MALLOC, REALLOC): Remove. All callers

changed to use xcalloc, xnmalloc, xnrealloc, respectively,
unless otherwise specified below.

* src/LR0.c (allocate_itemsets): Use xnmalloc, not xcalloc,
to allocate kernel_base, kernel_items, kernel_size, since
they needn't be initialized to 0.
(allocate_storgae): Likewise, for shiftset, redset, shift_symbol.
* src/closure.c (new_closure): Likewise, for itemset.
* src/derives.c (derives_compute): Likewise, for delts, derives, q.
* src/lalr.c (set_goto_map): Likewise, for temp_map.
(initialize_F): Likewise, for reads, edge, reads[i], includes[i].
(build_relations): Likewise for edge, states1, includes.
* src/nullable.c (nullable_compute): Likewise, for squeue, relts.
* src/reader.c (packgram): Likewise, for ritem, rules.
* src/reduce.c (nonterminals_reduce): Likewise for nontermmap.
* src/relation.c (relation_digraph): Likewise for VERTICES.
(relation_transpose): Likewise for new_R, end_R.
* src/symtab.c (symbols_token_translations_init): Likewise for
token_translations.
* src/tables.c (save_row): Likewise for froms, tos, conflict_tos.
(token_actions): Likewise for yydefact, actrow, conflrow,
conflict_list.
(save_column): Likewise for froms[symno], tos[symno].
(goto_actions): Likewise for state_count.
(pack_table): Likewise for base, pos, check.
(tables_generate): Likewise for width.

* src/LR0.c (set_states): Don't reuse kernel_size and kernel_base
for initial core.  Just have a separate core, so we needn't worry
about whether kernel_size and kernel_base are initialized.

* src/LR0.c (shift_symbol, redset, shiftset, kernel_base,
kernel_size, kernel_items): Remove unnecessary initialization.
* src/conflicts.c (conflicts): Likewise.
* src/derives.c (derives): Likewise.
* src/muscle_tablc (muscle_insert): Likewise.
* src/relation.c (relation_digraph): Likewise.
* src/tables.c (froms, tos, conflict_tos, tally, width, actrow, order,
conflrow, conflict_table, conflict_list, table, check):
Likewise.

* src/closure.c (new_closure): Arg is of type unsigned int, not int.
This is because all callers pass unsigned int.
* src/closure.h (new_closure): Likewise.

* src/lalr.c (initialize_F): Initialize reads[i] in all cases.
(build_relations): Initialize includes[i] in all cases.
* src/reader.c (packgram): Always initialize rules[ruleno].prec
and rules[ruleno].precsym.  Initialize members in order.
* src/relation.c (relation_transpose): Always initialize new_R[i]
and end_R[i].
* src/table.c (conflict_row): Initialize 0 at end of conflict_list.

* src/output.c (prepare_actions): Pass 0 instead of conflict_list[0];
conflict_list[0] was always 0, but now it isn't initialized.

* src/table.c (table_grow): When conflict_table grew, the grown
area wasn't cleared.  Fix this.
This commit is contained in:
Paul Eggert
2004-12-10 07:50:44 +00:00
parent 86a54ab102
commit da2a7671e1
16 changed files with 191 additions and 120 deletions

View File

@@ -1,3 +1,68 @@
2004-12-08 Paul Eggert <eggert@cs.ucla.edu>
* src/system.h (CALLOC, MALLOC, REALLOC): Remove. All callers
changed to use xcalloc, xnmalloc, xnrealloc, respectively,
unless otherwise specified below.
* src/LR0.c (allocate_itemsets): Use xnmalloc, not xcalloc,
to allocate kernel_base, kernel_items, kernel_size, since
they needn't be initialized to 0.
(allocate_storgae): Likewise, for shiftset, redset, shift_symbol.
* src/closure.c (new_closure): Likewise, for itemset.
* src/derives.c (derives_compute): Likewise, for delts, derives, q.
* src/lalr.c (set_goto_map): Likewise, for temp_map.
(initialize_F): Likewise, for reads, edge, reads[i], includes[i].
(build_relations): Likewise for edge, states1, includes.
* src/nullable.c (nullable_compute): Likewise, for squeue, relts.
* src/reader.c (packgram): Likewise, for ritem, rules.
* src/reduce.c (nonterminals_reduce): Likewise for nontermmap.
* src/relation.c (relation_digraph): Likewise for VERTICES.
(relation_transpose): Likewise for new_R, end_R.
* src/symtab.c (symbols_token_translations_init): Likewise for
token_translations.
* src/tables.c (save_row): Likewise for froms, tos, conflict_tos.
(token_actions): Likewise for yydefact, actrow, conflrow,
conflict_list.
(save_column): Likewise for froms[symno], tos[symno].
(goto_actions): Likewise for state_count.
(pack_table): Likewise for base, pos, check.
(tables_generate): Likewise for width.
* src/LR0.c (set_states): Don't reuse kernel_size and kernel_base
for initial core. Just have a separate core, so we needn't worry
about whether kernel_size and kernel_base are initialized.
* src/LR0.c (shift_symbol, redset, shiftset, kernel_base,
kernel_size, kernel_items): Remove unnecessary initialization.
* src/conflicts.c (conflicts): Likewise.
* src/derives.c (derives): Likewise.
* src/muscle_tablc (muscle_insert): Likewise.
* src/relation.c (relation_digraph): Likewise.
* src/tables.c (froms, tos, conflict_tos, tally, width, actrow, order,
conflrow, conflict_table, conflict_list, table, check):
Likewise.
* src/closure.c (new_closure): Arg is of type unsigned int, not int.
This is because all callers pass unsigned int.
* src/closure.h (new_closure): Likewise.
* src/lalr.c (initialize_F): Initialize reads[i] in all cases.
(build_relations): Initialize includes[i] in all cases.
* src/reader.c (packgram): Always initialize rules[ruleno].prec
and rules[ruleno].precsym. Initialize members in order.
* src/relation.c (relation_transpose): Always initialize new_R[i]
and end_R[i].
* src/table.c (conflict_row): Initialize 0 at end of conflict_list.
* src/output.c (prepare_actions): Pass 0 instead of conflict_list[0];
conflict_list[0] was always 0, but now it isn't initialized.
* src/table.c (table_grow): When conflict_table grew, the grown
area wasn't cleared. Fix this.
* lib/.cvsignore: Add strdup.c, strdup.h.
* m4/.cvsignore: Add strdup.m4.
2004-12-07 Paul Eggert <eggert@cs.ucla.edu> 2004-12-07 Paul Eggert <eggert@cs.ucla.edu>
* src/lalr.h (GOTO_NUMBER_MAXIMUM): New macro. * src/lalr.h (GOTO_NUMBER_MAXIMUM): New macro.

View File

@@ -1,6 +1,7 @@
/* Closures for Bison /* Closures for Bison
Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004 Free Software
Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -180,9 +181,9 @@ set_fderives (void)
void void
new_closure (int n) new_closure (unsigned int n)
{ {
CALLOC (itemset, n); itemset = xnmalloc (n, sizeof *itemset);
ruleset = bitset_create (nrules, BITSET_FIXED); ruleset = bitset_create (nrules, BITSET_FIXED);

View File

@@ -29,7 +29,7 @@
data so that closure can be called. n is the number of elements to data so that closure can be called. n is the number of elements to
allocate for itemset. */ allocate for itemset. */
void new_closure (int n); void new_closure (unsigned int n);
/* Given the kernel (aka core) of a state (a vector of item numbers /* Given the kernel (aka core) of a state (a vector of item numbers

View File

@@ -38,7 +38,7 @@
/* -1 stands for not specified. */ /* -1 stands for not specified. */
int expected_sr_conflicts = -1; int expected_sr_conflicts = -1;
int expected_rr_conflicts = -1; int expected_rr_conflicts = -1;
static char *conflicts = NULL; static char *conflicts;
struct obstack solved_conflicts_obstack; struct obstack solved_conflicts_obstack;
static bitset shift_set; static bitset shift_set;
@@ -305,9 +305,9 @@ conflicts_solve (void)
{ {
state_number i; state_number i;
/* List of look-ahead tokens on which we explicitly raise a syntax error. */ /* List of look-ahead tokens on which we explicitly raise a syntax error. */
symbol **errors = MALLOC (errors, ntokens + 1); symbol **errors = xnmalloc (ntokens + 1, sizeof *errors);
CALLOC (conflicts, nstates); conflicts = xcalloc (nstates, sizeof *conflicts);
shift_set = bitset_create (ntokens, BITSET_FIXED); shift_set = bitset_create (ntokens, BITSET_FIXED);
look_ahead_set = bitset_create (ntokens, BITSET_FIXED); look_ahead_set = bitset_create (ntokens, BITSET_FIXED);
obstack_init (&solved_conflicts_obstack); obstack_init (&solved_conflicts_obstack);

View File

@@ -37,7 +37,7 @@ typedef struct rule_list
rule *value; rule *value;
} rule_list; } rule_list;
rule ***derives = NULL; rule ***derives;
static void static void
print_derives (void) print_derives (void)
@@ -70,12 +70,12 @@ derives_compute (void)
/* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules
whose LHS is NTERM. */ whose LHS is NTERM. */
rule_list **dset = CALLOC (dset, nvars); rule_list **dset = xcalloc (nvars, sizeof *dset);
/* DELTS[RULE] -- There are NRULES rule number to attach to nterms. /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
Instead of performing NRULES allocations for each, have an array Instead of performing NRULES allocations for each, have an array
indexed by rule numbers. */ indexed by rule numbers. */
rule_list *delts = CALLOC (delts, nrules); rule_list *delts = xnmalloc (nrules, sizeof *delts);
for (r = nrules - 1; r >= 0; --r) for (r = nrules - 1; r >= 0; --r)
{ {
@@ -90,8 +90,8 @@ derives_compute (void)
/* DSET contains what we need under the form of a linked list. Make /* DSET contains what we need under the form of a linked list. Make
it a single array. */ it a single array. */
CALLOC (derives, nvars); derives = xnmalloc (nvars, sizeof *derives);
CALLOC (q, nvars + nrules); q = xnmalloc (nvars + nrules, sizeof *q);
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {

View File

@@ -80,8 +80,8 @@ set_goto_map (void)
state_number s; state_number s;
goto_number *temp_map; goto_number *temp_map;
CALLOC (goto_map, nvars + 1); goto_map = xcalloc (nvars + 1, sizeof *goto_map);
CALLOC (temp_map, nvars + 1); temp_map = xnmalloc (nvars + 1, sizeof *temp_map);
ngotos = 0; ngotos = 0;
for (s = 0; s < nstates; ++s) for (s = 0; s < nstates; ++s)
@@ -116,8 +116,8 @@ set_goto_map (void)
temp_map[nsyms - ntokens] = ngotos; temp_map[nsyms - ntokens] = ngotos;
} }
CALLOC (from_state, ngotos); from_state = xcalloc (ngotos, sizeof *from_state);
CALLOC (to_state, ngotos); to_state = xcalloc (ngotos, sizeof *to_state);
for (s = 0; s < nstates; ++s) for (s = 0; s < nstates; ++s)
{ {
@@ -170,8 +170,8 @@ map_goto (state_number s0, symbol_number sym)
static void static void
initialize_F (void) initialize_F (void)
{ {
goto_number **reads = CALLOC (reads, ngotos); goto_number **reads = xnmalloc (ngotos, sizeof *reads);
goto_number *edge = CALLOC (edge, ngotos + 1); goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge);
goto_number nedges = 0; goto_number nedges = 0;
goto_number i; goto_number i;
@@ -194,10 +194,12 @@ initialize_F (void)
edge[nedges++] = map_goto (stateno, sym); edge[nedges++] = map_goto (stateno, sym);
} }
if (nedges) if (nedges == 0)
reads[i] = NULL;
else
{ {
CALLOC (reads[i], nedges + 1); reads[i] = xnmalloc (nedges + 1, sizeof reads[i][0]);
memcpy (reads[i], edge, nedges * sizeof (edge[0])); memcpy (reads[i], edge, nedges * sizeof edge[0]);
reads[i][nedges] = END_NODE; reads[i][nedges] = END_NODE;
nedges = 0; nedges = 0;
} }
@@ -217,7 +219,7 @@ static void
add_lookback_edge (state *s, rule *r, goto_number gotono) add_lookback_edge (state *s, rule *r, goto_number gotono)
{ {
int ri = state_reduction_find (s, r); int ri = state_reduction_find (s, r);
goto_list *sp = MALLOC (sp, 1); goto_list *sp = xmalloc (sizeof *sp);
sp->next = lookback[(s->reductions->look_ahead_tokens - LA) + ri]; sp->next = lookback[(s->reductions->look_ahead_tokens - LA) + ri];
sp->value = gotono; sp->value = gotono;
lookback[(s->reductions->look_ahead_tokens - LA) + ri] = sp; lookback[(s->reductions->look_ahead_tokens - LA) + ri] = sp;
@@ -228,11 +230,11 @@ add_lookback_edge (state *s, rule *r, goto_number gotono)
static void static void
build_relations (void) build_relations (void)
{ {
goto_number *edge = CALLOC (edge, ngotos + 1); goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge);
state_number *states1 = CALLOC (states1, ritem_longest_rhs () + 1); state_number *states1 = xnmalloc (ritem_longest_rhs () + 1, sizeof *states1);
goto_number i; goto_number i;
CALLOC (includes, ngotos); includes = xnmalloc (ngotos, sizeof *includes);
for (i = 0; i < ngotos; i++) for (i = 0; i < ngotos; i++)
{ {
@@ -276,10 +278,12 @@ build_relations (void)
} }
} }
if (nedges) if (nedges == 0)
includes[i] = NULL;
else
{ {
int j; int j;
CALLOC (includes[i], nedges + 1); includes[i] = xnmalloc (nedges + 1, sizeof includes[i][0]);
for (j = 0; j < nedges; j++) for (j = 0; j < nedges; j++)
includes[i][j] = edge[j]; includes[i][j] = edge[j];
includes[i][nedges] = END_NODE; includes[i][nedges] = END_NODE;
@@ -381,7 +385,7 @@ initialize_LA (void)
nLA = 1; nLA = 1;
pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
CALLOC (lookback, nLA); lookback = xcalloc (nLA, sizeof *lookback);
/* Initialize the members LOOK_AHEAD_TOKENS for each state whose reductions /* Initialize the members LOOK_AHEAD_TOKENS for each state whose reductions
require look-ahead tokens. */ require look-ahead tokens. */

View File

@@ -99,7 +99,7 @@ void
muscle_insert (const char *key, char *value) muscle_insert (const char *key, char *value)
{ {
muscle_entry probe; muscle_entry probe;
muscle_entry *entry = NULL; muscle_entry *entry;
probe.key = key; probe.key = key;
entry = hash_lookup (muscle_table, &probe); entry = hash_lookup (muscle_table, &probe);
@@ -107,7 +107,7 @@ muscle_insert (const char *key, char *value)
if (!entry) if (!entry)
{ {
/* First insertion in the hash. */ /* First insertion in the hash. */
MALLOC (entry, 1); entry = xmalloc (sizeof *entry);
entry->key = key; entry->key = key;
hash_insert (muscle_table, entry); hash_insert (muscle_table, entry);
} }
@@ -133,7 +133,7 @@ muscle_grow (const char *key, const char *val, const char *separator)
if (!entry) if (!entry)
{ {
/* First insertion in the hash. */ /* First insertion in the hash. */
MALLOC (entry, 1); entry = xmalloc (sizeof *entry);
entry->key = key; entry->key = key;
hash_insert (muscle_table, entry); hash_insert (muscle_table, entry);
entry->value = xstrdup (val); entry->value = xstrdup (val);

View File

@@ -61,16 +61,16 @@ nullable_compute (void)
symbol_number *s2; symbol_number *s2;
rule_list *p; rule_list *p;
symbol_number *squeue = CALLOC (squeue, nvars); symbol_number *squeue = xnmalloc (nvars, sizeof *squeue);
short int *rcount = CALLOC (rcount, nrules); short int *rcount = xcalloc (nrules, sizeof *rcount);
/* RITEM contains all the rules, including useless productions. /* RITEM contains all the rules, including useless productions.
Hence we must allocate room for useless nonterminals too. */ Hence we must allocate room for useless nonterminals too. */
rule_list **rsets = CALLOC (rsets, nvars); rule_list **rsets = xcalloc (nvars, sizeof *rsets);
/* This is said to be more elements than we actually use. /* This is said to be more elements than we actually use.
Supposedly NRITEMS - NRULES is enough. But why take the risk? */ Supposedly NRITEMS - NRULES is enough. But why take the risk? */
rule_list *relts = CALLOC (relts, nritems + nvars + 1); rule_list *relts = xnmalloc (nritems + nvars + 1, sizeof *relts);
CALLOC (nullable, nvars); nullable = xcalloc (nvars, sizeof *nullable);
s1 = s2 = squeue; s1 = s2 = squeue;
p = relts; p = relts;

View File

@@ -192,7 +192,7 @@ prepare_symbols (void)
/* Output YYTOKNUM. */ /* Output YYTOKNUM. */
{ {
int i; int i;
int *values = MALLOC (values, ntokens); int *values = xnmalloc (ntokens, sizeof *values);
for (i = 0; i < ntokens; ++i) for (i = 0; i < ntokens; ++i)
values[i] = symbols[i]->user_token_number; values[i] = symbols[i]->user_token_number;
muscle_insert_int_table ("toknum", values, muscle_insert_int_table ("toknum", values,
@@ -212,13 +212,13 @@ prepare_rules (void)
{ {
rule_number r; rule_number r;
unsigned int i = 0; unsigned int i = 0;
item_number *rhs = MALLOC (rhs, nritems); item_number *rhs = xnmalloc (nritems, sizeof *rhs);
unsigned int *prhs = MALLOC (prhs, nrules); unsigned int *prhs = xnmalloc (nrules, sizeof *prhs);
unsigned int *rline = MALLOC (rline, nrules); unsigned int *rline = xnmalloc (nrules, sizeof *rline);
symbol_number *r1 = MALLOC (r1, nrules); symbol_number *r1 = xnmalloc (nrules, sizeof *r1);
unsigned int *r2 = MALLOC (r2, nrules); unsigned int *r2 = xnmalloc (nrules, sizeof *r2);
short int *dprec = MALLOC (dprec, nrules); short int *dprec = xnmalloc (nrules, sizeof *dprec);
short int *merger = MALLOC (merger, nrules); short int *merger = xnmalloc (nrules, sizeof *merger);
for (r = 0; r < nrules; ++r) for (r = 0; r < nrules; ++r)
{ {
@@ -272,7 +272,7 @@ static void
prepare_states (void) prepare_states (void)
{ {
state_number i; state_number i;
symbol_number *values = MALLOC (values, nstates); symbol_number *values = xnmalloc (nstates, sizeof *values);
for (i = 0; i < nstates; ++i) for (i = 0; i < nstates; ++i)
values[i] = states[i]->accessing_symbol; values[i] = states[i]->accessing_symbol;
muscle_insert_symbol_number_table ("stos", values, muscle_insert_symbol_number_table ("stos", values,
@@ -498,7 +498,7 @@ prepare_actions (void)
muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table, muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table,
conflict_table[0], 1, high + 1); conflict_table[0], 1, high + 1);
muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list, muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list,
conflict_list[0], 1, conflict_list_cnt); 0, 1, conflict_list_cnt);
} }

View File

@@ -108,7 +108,7 @@ get_merge_function (uniqstr name, uniqstr type, location loc)
break; break;
if (syms->next == NULL) if (syms->next == NULL)
{ {
MALLOC (syms->next, 1); syms->next = xmalloc (sizeof syms->next[0]);
syms->next->name = uniqstr_new (name); syms->next->name = uniqstr_new (name);
syms->next->type = uniqstr_new (type); syms->next->type = uniqstr_new (type);
syms->next->next = NULL; syms->next->next = NULL;
@@ -387,8 +387,8 @@ packgram (void)
rule_number ruleno = 0; rule_number ruleno = 0;
symbol_list *p = grammar; symbol_list *p = grammar;
CALLOC (ritem, nritems); ritem = xnmalloc (nritems, sizeof *ritem);
CALLOC (rules, nrules); rules = xnmalloc (nrules, sizeof *rules);
while (p) while (p)
{ {
@@ -397,12 +397,14 @@ packgram (void)
rules[ruleno].number = ruleno; rules[ruleno].number = ruleno;
rules[ruleno].lhs = p->sym; rules[ruleno].lhs = p->sym;
rules[ruleno].rhs = ritem + itemno; rules[ruleno].rhs = ritem + itemno;
rules[ruleno].prec = NULL;
rules[ruleno].dprec = p->dprec;
rules[ruleno].merger = p->merger;
rules[ruleno].precsym = NULL;
rules[ruleno].location = p->location; rules[ruleno].location = p->location;
rules[ruleno].useful = true; rules[ruleno].useful = true;
rules[ruleno].action = p->action; rules[ruleno].action = p->action;
rules[ruleno].action_location = p->action_location; rules[ruleno].action_location = p->action_location;
rules[ruleno].dprec = p->dprec;
rules[ruleno].merger = p->merger;
p = p->next; p = p->next;
while (p && p->sym) while (p && p->sym)

View File

@@ -247,7 +247,7 @@ reduce_grammar_tables (void)
{ {
int useful = 0; int useful = 0;
int useless = nrules - nuseless_productions; int useless = nrules - nuseless_productions;
rule *rules_sorted = MALLOC (rules_sorted, nrules); rule *rules_sorted = xnmalloc (nrules, sizeof *rules_sorted);
rule_number r; rule_number r;
for (r = 0; r < nrules; ++r) for (r = 0; r < nrules; ++r)
rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r]; rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r];
@@ -291,7 +291,7 @@ nonterminals_reduce (void)
/* Map the nonterminals to their new index: useful first, useless /* Map the nonterminals to their new index: useful first, useless
afterwards. Kept for later report. */ afterwards. Kept for later report. */
symbol_number *nontermmap = CALLOC (nontermmap, nvars); symbol_number *nontermmap = xnmalloc (nvars, sizeof *nontermmap);
n = ntokens; n = ntokens;
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
if (bitset_test (V, i)) if (bitset_test (V, i))
@@ -307,7 +307,7 @@ nonterminals_reduce (void)
/* Shuffle elements of tables indexed by symbol number. */ /* Shuffle elements of tables indexed by symbol number. */
{ {
symbol **symbols_sorted = MALLOC (symbols_sorted, nvars); symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted);
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
symbols[i]->number = nontermmap[i - ntokens]; symbols[i]->number = nontermmap[i - ntokens];

View File

@@ -98,16 +98,13 @@ relation_digraph (relation r, size_t size, bitsetv *function)
unsigned int i; unsigned int i;
infinity = size + 2; infinity = size + 2;
CALLOC (INDEX, size + 1); INDEX = xcalloc (size + 1, sizeof *INDEX);
CALLOC (VERTICES, size + 1); VERTICES = xnmalloc (size + 1, sizeof *VERTICES);
top = 0; top = 0;
R = r; R = r;
F = *function; F = *function;
for (i = 0; i < size; i++)
INDEX[i] = 0;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
if (INDEX[i] == 0 && R[i]) if (INDEX[i] == 0 && R[i])
traverse (i); traverse (i);
@@ -127,11 +124,11 @@ void
relation_transpose (relation *R_arg, int n) relation_transpose (relation *R_arg, int n)
{ {
/* The result. */ /* The result. */
relation new_R = CALLOC (new_R, n); relation new_R = xnmalloc (n, sizeof *new_R);
/* END_R[I] -- next entry of NEW_R[I]. */ /* END_R[I] -- next entry of NEW_R[I]. */
relation end_R = CALLOC (end_R, n); relation end_R = xnmalloc (n, sizeof *end_R);
/* NEDGES[I] -- total size of NEW_R[I]. */ /* NEDGES[I] -- total size of NEW_R[I]. */
int *nedges = CALLOC (nedges, n); int *nedges = xcalloc (n, sizeof *nedges);
int i, j; int i, j;
if (trace_flag & trace_sets) if (trace_flag & trace_sets)
@@ -148,13 +145,16 @@ relation_transpose (relation *R_arg, int n)
/* Allocate. */ /* Allocate. */
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
if (nedges[i] > 0) {
{ relation_node *sp = NULL;
relation_node *sp = CALLOC (sp, nedges[i] + 1); if (nedges[i] > 0)
sp[nedges[i]] = END_NODE; {
new_R[i] = sp; sp = xnmalloc (nedges[i] + 1, sizeof *sp);
end_R[i] = sp; sp[nedges[i]] = END_NODE;
} }
new_R[i] = sp;
end_R[i] = sp;
}
/* Store. */ /* Store. */
for (i = 0; i < n; i++) for (i = 0; i < n; i++)

View File

@@ -32,7 +32,7 @@
symbol_list * symbol_list *
symbol_list_new (symbol *sym, location loc) symbol_list_new (symbol *sym, location loc)
{ {
symbol_list *res = MALLOC (res, 1); symbol_list *res = xmalloc (sizeof *res);
res->next = NULL; res->next = NULL;
res->sym = sym; res->sym = sym;
res->location = loc; res->location = loc;

View File

@@ -48,7 +48,7 @@ location startsymbol_location;
static symbol * static symbol *
symbol_new (uniqstr tag, location loc) symbol_new (uniqstr tag, location loc)
{ {
symbol *res = MALLOC (res, 1); symbol *res = xmalloc (sizeof *res);
uniqstr_assert (tag); uniqstr_assert (tag);
res->tag = tag; res->tag = tag;
@@ -587,7 +587,8 @@ symbols_token_translations_init (void)
max_user_token_number = this->user_token_number; max_user_token_number = this->user_token_number;
} }
CALLOC (token_translations, max_user_token_number + 1); token_translations = xnmalloc (max_user_token_number + 1,
sizeof *token_translations);
/* Initialize all entries for literal tokens to 2, the internal /* Initialize all entries for literal tokens to 2, the internal
token number for $undefined, which represents all invalid inputs. token number for $undefined, which represents all invalid inputs.
@@ -606,7 +607,7 @@ symbols_token_translations_init (void)
void void
symbols_pack (void) symbols_pack (void)
{ {
CALLOC (symbols, nsyms); symbols = xcalloc (nsyms, sizeof *symbols);
symbols_do (symbol_check_alias_consistency_processor, NULL); symbols_do (symbol_check_alias_consistency_processor, NULL);
symbols_do (symbol_pack_processor, NULL); symbols_do (symbol_pack_processor, NULL);

View File

@@ -81,11 +81,11 @@ int nvectors;
#define BASE_MAXIMUM INT_MAX #define BASE_MAXIMUM INT_MAX
#define BASE_MINIMUM INT_MIN #define BASE_MINIMUM INT_MIN
static base_number **froms = NULL; static base_number **froms;
static base_number **tos = NULL; static base_number **tos;
static unsigned int **conflict_tos = NULL; static unsigned int **conflict_tos;
static short int *tally = NULL; static short int *tally;
static base_number *width = NULL; static base_number *width;
/* For a given state, N = ACTROW[SYMBOL]: /* For a given state, N = ACTROW[SYMBOL]:
@@ -97,12 +97,12 @@ static base_number *width = NULL;
typedef short int action_number; typedef short int action_number;
#define ACTION_NUMBER_MINIMUM SHRT_MIN #define ACTION_NUMBER_MINIMUM SHRT_MIN
static action_number *actrow = NULL; static action_number *actrow;
/* FROMS and TOS are reordered to be compressed. ORDER[VECTOR] is the /* FROMS and TOS are reordered to be compressed. ORDER[VECTOR] is the
new vector number of VECTOR. We skip `empty' vectors (i.e., new vector number of VECTOR. We skip `empty' vectors (i.e.,
TALLY[VECTOR] = 0), and call these `entries'. */ TALLY[VECTOR] = 0), and call these `entries'. */
static vector_number *order = NULL; static vector_number *order;
static int nentries; static int nentries;
base_number *base = NULL; base_number *base = NULL;
@@ -112,9 +112,9 @@ base_number *base = NULL;
base_number base_ninf = 0; base_number base_ninf = 0;
static base_number *pos = NULL; static base_number *pos = NULL;
static unsigned int *conflrow = NULL; static unsigned int *conflrow;
unsigned int *conflict_table = NULL; unsigned int *conflict_table;
unsigned int *conflict_list = NULL; unsigned int *conflict_list;
int conflict_list_cnt; int conflict_list_cnt;
static int conflict_list_free; static int conflict_list_free;
@@ -122,8 +122,8 @@ static int conflict_list_free;
with more or less the original hard-coded value (which was with more or less the original hard-coded value (which was
SHRT_MAX). */ SHRT_MAX). */
static int table_size = 32768; static int table_size = 32768;
base_number *table = NULL; base_number *table;
base_number *check = NULL; base_number *check;
/* The value used in TABLE to denote explicit syntax errors /* The value used in TABLE to denote explicit syntax errors
(%nonassoc), a negative infinite. First defaults to ACTION_NUMBER_MININUM, (%nonassoc), a negative infinite. First defaults to ACTION_NUMBER_MININUM,
but in order to keep small tables, renumbered as TABLE_ERROR, which but in order to keep small tables, renumbered as TABLE_ERROR, which
@@ -153,13 +153,15 @@ table_grow (int desired)
fprintf (stderr, "growing table and check from: %d to %d\n", fprintf (stderr, "growing table and check from: %d to %d\n",
old_size, table_size); old_size, table_size);
REALLOC (table, table_size); table = xnrealloc (table, table_size, sizeof *table);
REALLOC (check, table_size); conflict_table = xnrealloc (conflict_table, table_size,
REALLOC (conflict_table, table_size); sizeof *conflict_table);
check = xnrealloc (check, table_size, sizeof *check);
for (/* Nothing. */; old_size < table_size; ++old_size) for (/* Nothing. */; old_size < table_size; ++old_size)
{ {
table[old_size] = 0; table[old_size] = 0;
conflict_table[old_size] = 0;
check[old_size] = -1; check[old_size] = -1;
} }
} }
@@ -208,6 +210,7 @@ conflict_row (state *s)
/* Leave a 0 at the end. */ /* Leave a 0 at the end. */
if (conflict_list_free <= 0) if (conflict_list_free <= 0)
abort (); abort ();
conflict_list[conflict_list_cnt] = 0;
conflict_list_cnt += 1; conflict_list_cnt += 1;
conflict_list_free -= 1; conflict_list_free -= 1;
} }
@@ -373,7 +376,7 @@ save_row (state_number s)
base_number *sp; base_number *sp;
base_number *sp1; base_number *sp1;
base_number *sp2; base_number *sp2;
unsigned int *sp3 IF_LINT (= NULL); unsigned int *sp3;
/* Number of non default actions in S. */ /* Number of non default actions in S. */
count = 0; count = 0;
@@ -385,9 +388,10 @@ save_row (state_number s)
return; return;
/* Allocate non defaulted actions. */ /* Allocate non defaulted actions. */
froms[s] = sp = CALLOC (sp1, count); froms[s] = sp = sp1 = xnmalloc (count, sizeof *sp1);
tos[s] = CALLOC (sp2, count); tos[s] = sp2 = xnmalloc (count, sizeof *sp2);
conflict_tos[s] = nondeterministic_parser ? CALLOC (sp3, count) : NULL; conflict_tos[s] = sp3 =
nondeterministic_parser ? xnmalloc (count, sizeof *sp3) : NULL;
/* Store non defaulted actions. */ /* Store non defaulted actions. */
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
@@ -421,12 +425,12 @@ token_actions (void)
int nconflict = nondeterministic_parser ? conflicts_total_count () : 0; int nconflict = nondeterministic_parser ? conflicts_total_count () : 0;
CALLOC (yydefact, nstates); yydefact = xnmalloc (nstates, sizeof *yydefact);
CALLOC (actrow, ntokens); actrow = xnmalloc (ntokens, sizeof *actrow);
CALLOC (conflrow, ntokens); conflrow = xnmalloc (ntokens, sizeof *conflrow);
CALLOC (conflict_list, 1 + 2 * nconflict); conflict_list = xnmalloc (1 + 2 * nconflict, sizeof *conflict_list);
conflict_list_free = 2 * nconflict; conflict_list_free = 2 * nconflict;
conflict_list_cnt = 1; conflict_list_cnt = 1;
@@ -491,8 +495,8 @@ save_column (symbol_number sym, state_number default_state)
return; return;
/* Allocate room for non defaulted gotos. */ /* Allocate room for non defaulted gotos. */
froms[symno] = sp = CALLOC (sp1, count); froms[symno] = sp = sp1 = xnmalloc (count, sizeof *sp1);
tos[symno] = CALLOC (sp2, count); tos[symno] = sp2 = xnmalloc (count, sizeof *sp2);
/* Store the state numbers of the non defaulted gotos. */ /* Store the state numbers of the non defaulted gotos. */
for (i = begin; i < end; i++) for (i = begin; i < end; i++)
@@ -554,8 +558,8 @@ static void
goto_actions (void) goto_actions (void)
{ {
symbol_number i; symbol_number i;
short int *state_count = CALLOC (state_count, nstates); short int *state_count = xnmalloc (nstates, sizeof *state_count);
MALLOC (yydefgoto, nvars); yydefgoto = xnmalloc (nvars, sizeof *yydefgoto);
/* For a given nterm I, STATE_COUNT[S] is the number of times there /* For a given nterm I, STATE_COUNT[S] is the number of times there
is a GOTO to S on I. */ is a GOTO to S on I. */
@@ -751,11 +755,11 @@ pack_table (void)
{ {
int i; int i;
CALLOC (base, nvectors); base = xnmalloc (nvectors, sizeof *base);
CALLOC (pos, nentries); pos = xnmalloc (nentries, sizeof *pos);
CALLOC (table, table_size); table = xcalloc (table_size, sizeof *table);
CALLOC (conflict_table, table_size); conflict_table = xcalloc (table_size, sizeof *conflict_table);
CALLOC (check, table_size); check = xnmalloc (table_size, sizeof *check);
lowzero = 0; lowzero = 0;
high = 0; high = 0;
@@ -810,11 +814,11 @@ tables_generate (void)
nvectors = state_number_as_int (nstates) + nvars; nvectors = state_number_as_int (nstates) + nvars;
CALLOC (froms, nvectors); froms = xcalloc (nvectors, sizeof *froms);
CALLOC (tos, nvectors); tos = xcalloc (nvectors, sizeof *tos);
CALLOC (conflict_tos, nvectors); conflict_tos = xcalloc (nvectors, sizeof *conflict_tos);
CALLOC (tally, nvectors); tally = xcalloc (nvectors, sizeof *tally);
CALLOC (width, nvectors); width = xnmalloc (nvectors, sizeof *width);
token_actions (); token_actions ();
@@ -823,7 +827,7 @@ tables_generate (void)
free (from_state); free (from_state);
free (to_state); free (to_state);
CALLOC (order, nvectors); order = xcalloc (nvectors, sizeof *order);
sort_actions (); sort_actions ();
pack_table (); pack_table ();
free (order); free (order);

View File

@@ -418,9 +418,7 @@ add_edge (graph *g, edge *e)
void void
add_classname (graph *g, int val, const char *name) add_classname (graph *g, int val, const char *name)
{ {
struct classname *classname; struct classname *classname = xmalloc (sizeof *classname);
MALLOC (classname, 1);
classname->no = val; classname->no = val;
classname->name = name; classname->name = name;
classname->next = g->classname; classname->next = g->classname;
@@ -430,9 +428,7 @@ add_classname (graph *g, int val, const char *name)
void void
add_infoname (graph *g, int integer, const char *str) add_infoname (graph *g, int integer, const char *str)
{ {
struct infoname *infoname; struct infoname *infoname = xmalloc (sizeof *infoname);
MALLOC (infoname, 1);
infoname->integer = integer; infoname->integer = integer;
infoname->chars = str; infoname->chars = str;
infoname->next = g->infoname; infoname->next = g->infoname;
@@ -444,9 +440,7 @@ void
add_colorentry (graph *g, int color_idx, int red_cp, add_colorentry (graph *g, int color_idx, int red_cp,
int green_cp, int blue_cp) int green_cp, int blue_cp)
{ {
struct colorentry *ce; struct colorentry *ce = xmalloc (sizeof *ce);
MALLOC (ce, 1);
ce->color_index = color_idx; ce->color_index = color_idx;
ce->red_cp = red_cp; ce->red_cp = red_cp;
ce->green_cp = green_cp; ce->green_cp = green_cp;