* src/conflicts.c (set_conflicts): Use bitset_disjoint_p.

(count_sr_conflicts): Use bitset_count.
* src/reduce.c (inaccessable_symbols): Ditto.
(bits_size): Remove.
* src/warshall.h, src/warshall.c: Convert to bitsetv.
This commit is contained in:
Akim Demaille
2002-03-04 13:58:05 +00:00
parent f0250de62e
commit 914feea9d0
9 changed files with 62 additions and 84 deletions

View File

@@ -1,3 +1,11 @@
2002-03-04 Akim Demaille <akim@epita.fr>
* src/conflicts.c (set_conflicts): Use bitset_disjoint_p.
(count_sr_conflicts): Use bitset_count.
* src/reduce.c (inaccessable_symbols): Ditto.
(bits_size): Remove.
* src/warshall.h, src/warshall.c: Convert to bitsetv.
2002-03-04 Akim Demaille <akim@epita.fr> 2002-03-04 Akim Demaille <akim@epita.fr>
* src/closure.c, src/conflicts.c, src/lalr.c, src/print.c, * src/closure.c, src/conflicts.c, src/lalr.c, src/print.c,

View File

@@ -1,5 +1,5 @@
/* Subroutines for bison /* Subroutines for bison
Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -19,13 +19,14 @@
02111-1307, USA. */ 02111-1307, USA. */
#include "system.h" #include "system.h"
#include "bitset.h"
#include "bitsetv.h"
#include "getargs.h" #include "getargs.h"
#include "symtab.h" #include "symtab.h"
#include "gram.h" #include "gram.h"
#include "reader.h" #include "reader.h"
#include "closure.h" #include "closure.h"
#include "derives.h" #include "derives.h"
#include "bitset.h"
#include "warshall.h" #include "warshall.h"
/* NITEMSET is the size of the array ITEMSET. */ /* NITEMSET is the size of the array ITEMSET. */
@@ -35,8 +36,8 @@ int nitemset;
static bitset ruleset; static bitset ruleset;
/* internal data. See comments before set_fderives and set_firsts. */ /* internal data. See comments before set_fderives and set_firsts. */
static bitset *fderives = NULL; static bitsetv fderives = NULL;
static bitset *firsts = NULL; static bitsetv firsts = NULL;
/* Retrieve the FDERIVES/FIRSTS sets of the nonterminals numbered Var. */ /* Retrieve the FDERIVES/FIRSTS sets of the nonterminals numbered Var. */
#define FDERIVES(Var) fderives[(Var) - ntokens] #define FDERIVES(Var) fderives[(Var) - ntokens]
@@ -120,19 +121,17 @@ set_firsts (void)
{ {
int i, j; int i, j;
firsts = XCALLOC (bitset, nvars); firsts = bitsetv_create (nvars, nvars, BITSET_FIXED);
for (i = ntokens; i < nsyms; i++)
{
FIRSTS (i) = bitset_create (nvars, BITSET_FIXED);
for (j = 0; derives[i][j] >= 0; ++j)
{
int symbol = ritem[rules[derives[i][j]].rhs];
if (ISVAR (symbol))
bitset_set (FIRSTS (i), symbol - ntokens);
}
}
RTC (firsts, nvars); for (i = ntokens; i < nsyms; i++)
for (j = 0; derives[i][j] >= 0; ++j)
{
int symbol = ritem[rules[derives[i][j]].rhs];
if (ISVAR (symbol))
bitset_set (FIRSTS (i), symbol - ntokens);
}
RTC (firsts);
if (trace_flag) if (trace_flag)
print_firsts (); print_firsts ();
@@ -153,10 +152,7 @@ set_fderives (void)
{ {
int i, j, k; int i, j, k;
fderives = XCALLOC (bitset, nvars); fderives = bitsetv_create (nvars, nrules + 1, BITSET_FIXED);
bitset_stats_init ();
for (i = 0 ; i < nvars; ++i)
fderives[i] = bitset_create (nrules + 1, BITSET_FIXED);
set_firsts (); set_firsts ();
@@ -169,9 +165,7 @@ set_fderives (void)
if (trace_flag) if (trace_flag)
print_fderives (); print_fderives ();
for (i = ntokens; i < nsyms; ++i) bitsetv_free (firsts);
bitset_free (FIRSTS (i));
XFREE (firsts);
} }
@@ -246,12 +240,7 @@ closure (short *core, int n)
void void
free_closure (void) free_closure (void)
{ {
int i;
XFREE (itemset); XFREE (itemset);
bitset_free (ruleset); bitset_free (ruleset);
bitsetv_free (fderives);
for (i = 0 ; i < nvars; ++i)
bitset_free (fderives[i]);
free (fderives);
} }

View File

@@ -155,7 +155,7 @@ resolve_sr_conflict (state_t *state, int lookahead)
static void static void
set_conflicts (state_t *state) set_conflicts (state_t *state)
{ {
int i, j; int i;
shifts *shiftp; shifts *shiftp;
if (state->consistent) if (state->consistent)
@@ -172,25 +172,19 @@ set_conflicts (state_t *state)
check for shift-reduce conflict, and try to resolve using check for shift-reduce conflict, and try to resolve using
precedence */ precedence */
for (i = 0; i < state->nlookaheads; ++i) for (i = 0; i < state->nlookaheads; ++i)
if (rules[LAruleno[state->lookaheadsp + i]].prec) if (rules[LAruleno[state->lookaheadsp + i]].prec
for (j = 0; j < ntokens; ++j) && !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
if (bitset_test (LA[state->lookaheadsp + i], j) {
&& bitset_test (lookaheadset, j)) resolve_sr_conflict (state, state->lookaheadsp + i);
{ break;
resolve_sr_conflict (state, state->lookaheadsp + i); }
break;
}
/* Loop over all rules which require lookahead in this state. Check /* Loop over all rules which require lookahead in this state. Check
for conflicts not resolved above. */ for conflicts not resolved above. */
for (i = 0; i < state->nlookaheads; ++i) for (i = 0; i < state->nlookaheads; ++i)
{ {
/* FIXME: Here, I need something like `bitset_disjoint_p'. */ if (!bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
for (j = 0; j < ntokens; ++j) conflicts[state->number] = 1;
if (bitset_test (LA[state->lookaheadsp + i], j)
&& bitset_test (lookaheadset, j))
conflicts[state->number] = 1;
bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]); bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
} }
@@ -236,9 +230,7 @@ count_sr_conflicts (state_t *state)
bitset_and (lookaheadset, lookaheadset, shiftset); bitset_and (lookaheadset, lookaheadset, shiftset);
for (i = 0; i < ntokens; i++) src_count = bitset_count (lookaheadset);
if (bitset_test (lookaheadset, i))
src_count++;
return src_count; return src_count;
} }

View File

@@ -25,6 +25,7 @@
#include "system.h" #include "system.h"
#include "bitset.h" #include "bitset.h"
#include "bitsetv.h"
#include "reader.h" #include "reader.h"
#include "types.h" #include "types.h"
#include "LR0.h" #include "LR0.h"
@@ -40,7 +41,7 @@
state_t **states = NULL; state_t **states = NULL;
short *LAruleno = NULL; short *LAruleno = NULL;
bitset *LA = NULL; bitsetv LA = NULL;
size_t nLA; size_t nLA;
static int ngotos; static int ngotos;
@@ -50,7 +51,7 @@ short *to_state = NULL;
/* And for the famous F variable, which name is so descriptive that a /* And for the famous F variable, which name is so descriptive that a
comment is hardly needed. <grin>. */ comment is hardly needed. <grin>. */
static bitset *F = NULL; static bitsetv F = NULL;
static short **includes; static short **includes;
static shorts **lookback; static shorts **lookback;
@@ -139,9 +140,7 @@ initialize_LA (void)
if (!nLA) if (!nLA)
nLA = 1; nLA = 1;
LA = XCALLOC (bitset, nLA); LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
for (i = 0; i < nLA; ++i)
LA[i] = bitset_create (ntokens, BITSET_FIXED);
LAruleno = XCALLOC (short, nLA); LAruleno = XCALLOC (short, nLA);
lookback = XCALLOC (shorts *, nLA); lookback = XCALLOC (shorts *, nLA);
@@ -253,9 +252,7 @@ initialize_F (void)
int i; int i;
F = XCALLOC (bitset, ngotos); F = bitsetv_create (ngotos, ntokens, BITSET_FIXED);
for (i = 0; i < ngotos; ++i)
F[i] = bitset_create (ntokens, BITSET_FIXED);
for (i = 0; i < ngotos; i++) for (i = 0; i < ngotos; i++)
{ {
@@ -500,9 +497,7 @@ compute_lookaheads (void)
LIST_FREE (shorts, lookback[i]); LIST_FREE (shorts, lookback[i]);
XFREE (lookback); XFREE (lookback);
for (i = 0; i < (unsigned) ngotos; ++i) bitsetv_free (F);
bitset_free (F[i]);
XFREE (F);
} }

View File

@@ -50,6 +50,8 @@ main (int argc, char *argv[])
bindtextdomain (PACKAGE, LOCALEDIR); bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE); textdomain (PACKAGE);
bitset_stats_init ();
lineno = 0; lineno = 0;
getargs (argc, argv); getargs (argc, argv);

View File

@@ -89,6 +89,7 @@
negative short int. Used to flag ?? */ negative short int. Used to flag ?? */
#include "system.h" #include "system.h"
#include "bitsetv.h"
#include "quotearg.h" #include "quotearg.h"
#include "error.h" #include "error.h"
#include "getargs.h" #include "getargs.h"
@@ -922,7 +923,7 @@ output_actions (void)
width = XCALLOC (short, nvectors); width = XCALLOC (short, nvectors);
token_actions (); token_actions ();
XFREE (LA); bitsetv_free (LA);
XFREE (LAruleno); XFREE (LAruleno);
goto_actions (); goto_actions ();

View File

@@ -57,15 +57,6 @@ static int nuseless_productions;
static int nuseful_nonterminals; static int nuseful_nonterminals;
int nuseless_nonterminals; int nuseless_nonterminals;
static int
bits_size (bitset S)
{
int i, count = 0;
BITSET_EXECUTE (S, 0, i, { ++count; });
return count;
}
/*-------------------------------------------------------------------. /*-------------------------------------------------------------------.
| Another way to do this would be with a set for each production and | | Another way to do this would be with a set for each production and |
| then do subset tests against N0, but even for the C grammar the | | then do subset tests against N0, but even for the C grammar the |
@@ -82,9 +73,8 @@ useful_production (int i, bitset N0)
in the set of useful nonterminals. */ in the set of useful nonterminals. */
for (r = &ritem[rules[i].rhs]; *r >= 0; r++) for (r = &ritem[rules[i].rhs]; *r >= 0; r++)
if (ISVAR (n = *r)) if (ISVAR (n = *r) && !bitset_test (N0, n - ntokens))
if (!bitset_test (N0, n - ntokens)) return FALSE;
return FALSE;
return TRUE; return TRUE;
} }
@@ -215,7 +205,7 @@ inaccessable_symbols (void)
bitset_free (P); bitset_free (P);
P = Pp; P = Pp;
nuseful_productions = bits_size (P); nuseful_productions = bitset_count (P);
nuseless_productions = nrules - nuseful_productions; nuseless_productions = nrules - nuseful_productions;
nuseful_nonterminals = 0; nuseful_nonterminals = 0;

View File

@@ -21,7 +21,7 @@
#include "system.h" #include "system.h"
#include "getargs.h" #include "getargs.h"
#include "bitset.h" #include "bitsetv.h"
#include "warshall.h" #include "warshall.h"
/*--------------------------------------------------------. /*--------------------------------------------------------.
@@ -29,9 +29,10 @@
`--------------------------------------------------------*/ `--------------------------------------------------------*/
static void static void
bitmatrix_print (const char *title, bitset *matrix, size_t size) bitmatrix_print (const char *title, bitsetv matrix)
{ {
size_t i, j; size_t i, j;
size_t size = bitset_size (matrix[0]);
/* Title. */ /* Title. */
fprintf (stderr, "%s BEGIN\n", title); fprintf (stderr, "%s BEGIN\n", title);
@@ -77,23 +78,23 @@ bitmatrix_print (const char *title, bitset *matrix, size_t size)
`-------------------------------------------------------------------*/ `-------------------------------------------------------------------*/
static void static void
TC (bitset *matrix, int n) TC (bitsetv matrix)
{ {
int i, j; int i, j;
if (trace_flag) if (trace_flag)
bitmatrix_print ("TC: Input", matrix, n); bitmatrix_print ("TC: Input", matrix);
/* R (J, I) && R (I, K) => R (J, K). /* R (J, I) && R (I, K) => R (J, K).
I *must* be the outter loop. */ I *must* be the outter loop. */
for (i = 0; i < n; ++i) for (i = 0; matrix[i]; ++i)
for (j = 0; j < n; ++j) for (j = 0; matrix[j]; ++j)
if (bitset_test (matrix[j], i)) if (bitset_test (matrix[j], i))
bitset_or (matrix[j], matrix[j], matrix[i]); bitset_or (matrix[j], matrix[j], matrix[i]);
if (trace_flag) if (trace_flag)
bitmatrix_print ("TC: Output", matrix, n); bitmatrix_print ("TC: Output", matrix);
} }
@@ -103,11 +104,11 @@ TC (bitset *matrix, int n)
`---------------------------------------------------------------*/ `---------------------------------------------------------------*/
void void
RTC (bitset *matrix, int n) RTC (bitsetv matrix)
{ {
int i; int i;
TC (matrix, n); TC (matrix);
for (i = 0; i < n; ++i) for (i = 0; matrix[i]; ++i)
bitset_set (matrix[i], i); bitset_set (matrix[i], i);
} }

View File

@@ -1,5 +1,5 @@
/* Generate transitive closure of a matrix, /* Generate transitive closure of a matrix,
Copyright 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -21,5 +21,5 @@
#ifndef WARSHALL_H_ #ifndef WARSHALL_H_
# define WARSHALL_H_ # define WARSHALL_H_
void RTC PARAMS ((bitset *, int)); void RTC PARAMS ((bitsetv));
#endif /* !WARSHALL_H_ */ #endif /* !WARSHALL_H_ */