mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 01:03:04 +00:00
Because useless nonterminals are now kept alive (instead of being
`destroyed'), we now sometimes examine them, and store information related to them. Hence we need to know their number, and adjust memory allocations. * src/reduce.c, src/reduce.h (nuseless_nonterminals): No longer static. * src/LR0.c (allocate_itemsets): The memory allocated to `symbol_count' was used for two different purpose: once to count the number of occurrences of each symbol, and later reassigned to `shift_symbol', containing the symbol that can be shifted from a given state. Deobfuscate, i.e., allocate, use and free `symbol_count' here only, and... (new_itemsets): Allocate `shift_symbol' here. (allocate_itemsets): symbol_count includes useless nonterminals. Make room for them. (free_storage): Use `free', not `XFREE', for pointers that cannot be null.
This commit is contained in:
23
ChangeLog
23
ChangeLog
@@ -1,3 +1,26 @@
|
|||||||
|
2001-12-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
Because useless nonterminals are now kept alive (instead of being
|
||||||
|
`destroyed'), we now sometimes examine them, and store information
|
||||||
|
related to them. Hence we need to know their number, and adjust
|
||||||
|
memory allocations.
|
||||||
|
|
||||||
|
* src/reduce.c, src/reduce.h (nuseless_nonterminals): No longer
|
||||||
|
static.
|
||||||
|
* src/LR0.c (allocate_itemsets): The memory allocated to
|
||||||
|
`symbol_count' was used for two different purpose: once to count
|
||||||
|
the number of occurrences of each symbol, and later reassigned to
|
||||||
|
`shift_symbol', containing the symbol that can be shifted from a
|
||||||
|
given state.
|
||||||
|
Deobfuscate, i.e., allocate, use and free `symbol_count' here
|
||||||
|
only, and...
|
||||||
|
(new_itemsets): Allocate `shift_symbol' here.
|
||||||
|
(allocate_itemsets): symbol_count includes useless nonterminals.
|
||||||
|
Make room for them.
|
||||||
|
(free_storage): Use `free', not `XFREE', for pointers that cannot
|
||||||
|
be null.
|
||||||
|
|
||||||
|
|
||||||
2001-12-05 Akim Demaille <akim@epita.fr>
|
2001-12-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/nullable.c (set_nullable): Deobfuscate the handling of
|
* src/nullable.c (set_nullable): Deobfuscate the handling of
|
||||||
|
|||||||
27
src/LR0.c
27
src/LR0.c
@@ -30,7 +30,7 @@
|
|||||||
#include "complain.h"
|
#include "complain.h"
|
||||||
#include "closure.h"
|
#include "closure.h"
|
||||||
#include "LR0.h"
|
#include "LR0.h"
|
||||||
|
#include "reduce.h"
|
||||||
|
|
||||||
int nstates;
|
int nstates;
|
||||||
int final_state;
|
int final_state;
|
||||||
@@ -63,11 +63,13 @@ static void
|
|||||||
allocate_itemsets (void)
|
allocate_itemsets (void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int count;
|
|
||||||
short *symbol_count = NULL;
|
|
||||||
|
|
||||||
count = 0;
|
/* Count the number of occurrences of all the symbols in RITEMS.
|
||||||
symbol_count = XCALLOC (short, nsyms);
|
Note that useless productions (hence useless nonterminals) are
|
||||||
|
browsed too, hence we need to allocate room for _all_ the
|
||||||
|
symbols. */
|
||||||
|
int count = 0;
|
||||||
|
short *symbol_count = XCALLOC (short, nsyms + nuseless_nonterminals);
|
||||||
|
|
||||||
for (i = 0; ritem[i]; ++i)
|
for (i = 0; ritem[i]; ++i)
|
||||||
if (ritem[i] > 0)
|
if (ritem[i] > 0)
|
||||||
@@ -93,7 +95,7 @@ allocate_itemsets (void)
|
|||||||
count += symbol_count[i];
|
count += symbol_count[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
shift_symbol = symbol_count;
|
free (symbol_count);
|
||||||
kernel_size = XCALLOC (int, nsyms);
|
kernel_size = XCALLOC (int, nsyms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,13 +114,13 @@ allocate_storage (void)
|
|||||||
static void
|
static void
|
||||||
free_storage (void)
|
free_storage (void)
|
||||||
{
|
{
|
||||||
XFREE (shift_symbol);
|
free (shift_symbol);
|
||||||
XFREE (redset);
|
free (redset);
|
||||||
XFREE (shiftset);
|
free (shiftset);
|
||||||
XFREE (kernel_base);
|
free (kernel_base);
|
||||||
XFREE (kernel_size);
|
free (kernel_size);
|
||||||
XFREE (kernel_items);
|
XFREE (kernel_items);
|
||||||
XFREE (state_table);
|
free (state_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -148,6 +150,7 @@ new_itemsets (void)
|
|||||||
for (i = 0; i < nsyms; i++)
|
for (i = 0; i < nsyms; i++)
|
||||||
kernel_size[i] = 0;
|
kernel_size[i] = 0;
|
||||||
|
|
||||||
|
shift_symbol = XCALLOC (short, nsyms);
|
||||||
shiftcount = 0;
|
shiftcount = 0;
|
||||||
|
|
||||||
for (i = 0; i < itemsetsize; ++i)
|
for (i = 0; i < itemsetsize; ++i)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "gram.h"
|
#include "gram.h"
|
||||||
|
#include "reduce.h"
|
||||||
#include "nullable.h"
|
#include "nullable.h"
|
||||||
|
|
||||||
char *nullable = NULL;
|
char *nullable = NULL;
|
||||||
@@ -64,11 +65,14 @@ set_nullable (void)
|
|||||||
s1 = s2 = squeue;
|
s1 = s2 = squeue;
|
||||||
|
|
||||||
rcount = XCALLOC (short, nrules + 1);
|
rcount = XCALLOC (short, nrules + 1);
|
||||||
rsets = XCALLOC (shorts *, nvars) - ntokens;
|
|
||||||
|
/* RITEM contains all the rules, including useless productions.
|
||||||
|
Hence we must allocate room for useless nonterminals too. */
|
||||||
|
rsets = XCALLOC (shorts *, nvars + nuseless_nonterminals) - ntokens;
|
||||||
/* This is said to be more elements than we actually use.
|
/* This is said to be more elements than we actually use.
|
||||||
Supposedly nitems - nrules is enough.
|
Supposedly nitems - nrules is enough.
|
||||||
But why take the risk? */
|
But why take the risk? */
|
||||||
relts = XCALLOC (shorts, nitems + nvars + 1);
|
relts = XCALLOC (shorts, nitems + nvars + nuseless_nonterminals + 1);
|
||||||
p = relts;
|
p = relts;
|
||||||
|
|
||||||
for (r = ritem; *r; ++r)
|
for (r = ritem; *r; ++r)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ static BSet V1;
|
|||||||
static int nuseful_productions;
|
static int nuseful_productions;
|
||||||
static int nuseless_productions;
|
static int nuseless_productions;
|
||||||
static int nuseful_nonterminals;
|
static int nuseful_nonterminals;
|
||||||
static int nuseless_nonterminals;
|
int nuseless_nonterminals;
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
bits_equal (BSet L, BSet R, int n)
|
bits_equal (BSet L, BSet R, int n)
|
||||||
|
|||||||
@@ -24,4 +24,6 @@
|
|||||||
void reduce_grammar PARAMS ((void));
|
void reduce_grammar PARAMS ((void));
|
||||||
void reduce_output PARAMS ((FILE *out));
|
void reduce_output PARAMS ((FILE *out));
|
||||||
void reduce_free PARAMS ((void));
|
void reduce_free PARAMS ((void));
|
||||||
|
|
||||||
|
extern int nuseless_nonterminals;
|
||||||
#endif /* !REDUCE_H_ */
|
#endif /* !REDUCE_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user