(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>
+
+ * 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>
* src/closure.c, src/conflicts.c, src/lalr.c, src/print.c,
2002-03-04 Akim Demaille <akim@epita.fr>
* src/closure.c, src/conflicts.c, src/lalr.c, src/print.c,
- 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.
02111-1307, USA. */
#include "system.h"
02111-1307, USA. */
#include "system.h"
+#include "bitset.h"
+#include "bitsetv.h"
#include "getargs.h"
#include "symtab.h"
#include "gram.h"
#include "reader.h"
#include "closure.h"
#include "derives.h"
#include "getargs.h"
#include "symtab.h"
#include "gram.h"
#include "reader.h"
#include "closure.h"
#include "derives.h"
#include "warshall.h"
/* NITEMSET is the size of the array ITEMSET. */
#include "warshall.h"
/* NITEMSET is the size of the array ITEMSET. */
static bitset ruleset;
/* internal data. See comments before set_fderives and set_firsts. */
static bitset ruleset;
/* internal data. See comments before set_fderives and set_firsts. */
-static bitset *fderives = NULL;
-static bitset *firsts = NULL;
+static bitsetv fderives = NULL;
+static bitsetv firsts = NULL;
/* Retrieve the FDERIVES/FIRSTS sets of the nonterminals numbered Var. */
#define FDERIVES(Var) fderives[(Var) - ntokens]
/* Retrieve the FDERIVES/FIRSTS sets of the nonterminals numbered Var. */
#define FDERIVES(Var) fderives[(Var) - ntokens]
- firsts = XCALLOC (bitset, nvars);
+ firsts = bitsetv_create (nvars, nvars, BITSET_FIXED);
+
for (i = ntokens; i < nsyms; i++)
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);
- }
- }
+ 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);
+ }
if (trace_flag)
print_firsts ();
if (trace_flag)
print_firsts ();
- fderives = XCALLOC (bitset, nvars);
- bitset_stats_init ();
- for (i = 0 ; i < nvars; ++i)
- fderives[i] = bitset_create (nrules + 1, BITSET_FIXED);
+ fderives = bitsetv_create (nvars, nrules + 1, BITSET_FIXED);
if (trace_flag)
print_fderives ();
if (trace_flag)
print_fderives ();
- for (i = ntokens; i < nsyms; ++i)
- bitset_free (FIRSTS (i));
- XFREE (firsts);
void
free_closure (void)
{
void
free_closure (void)
{
-
- for (i = 0 ; i < nvars; ++i)
- bitset_free (fderives[i]);
- free (fderives);
+ bitsetv_free (fderives);
static void
set_conflicts (state_t *state)
{
static void
set_conflicts (state_t *state)
{
shifts *shiftp;
if (state->consistent)
shifts *shiftp;
if (state->consistent)
check for shift-reduce conflict, and try to resolve using
precedence */
for (i = 0; i < state->nlookaheads; ++i)
check for shift-reduce conflict, and try to resolve using
precedence */
for (i = 0; i < state->nlookaheads; ++i)
- if (rules[LAruleno[state->lookaheadsp + i]].prec)
- for (j = 0; j < ntokens; ++j)
- if (bitset_test (LA[state->lookaheadsp + i], j)
- && bitset_test (lookaheadset, j))
- {
- resolve_sr_conflict (state, state->lookaheadsp + i);
- break;
- }
-
+ if (rules[LAruleno[state->lookaheadsp + i]].prec
+ && !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
+ {
+ resolve_sr_conflict (state, state->lookaheadsp + i);
+ break;
+ }
/* Loop over all rules which require lookahead in this state. Check
for conflicts not resolved above. */
for (i = 0; i < state->nlookaheads; ++i)
{
/* Loop over all rules which require lookahead in this state. Check
for conflicts not resolved above. */
for (i = 0; i < state->nlookaheads; ++i)
{
- /* FIXME: Here, I need something like `bitset_disjoint_p'. */
- for (j = 0; j < ntokens; ++j)
- if (bitset_test (LA[state->lookaheadsp + i], j)
- && bitset_test (lookaheadset, j))
- conflicts[state->number] = 1;
+ if (!bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
+ conflicts[state->number] = 1;
bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
}
bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
}
bitset_and (lookaheadset, lookaheadset, shiftset);
bitset_and (lookaheadset, lookaheadset, shiftset);
- for (i = 0; i < ntokens; i++)
- if (bitset_test (lookaheadset, i))
- src_count++;
+ src_count = bitset_count (lookaheadset);
#include "system.h"
#include "bitset.h"
#include "system.h"
#include "bitset.h"
#include "reader.h"
#include "types.h"
#include "LR0.h"
#include "reader.h"
#include "types.h"
#include "LR0.h"
state_t **states = NULL;
short *LAruleno = NULL;
state_t **states = NULL;
short *LAruleno = NULL;
size_t nLA;
static int ngotos;
size_t nLA;
static int ngotos;
/* And for the famous F variable, which name is so descriptive that a
comment is hardly needed. <grin>. */
/* And for the famous F variable, which name is so descriptive that a
comment is hardly needed. <grin>. */
-static bitset *F = NULL;
+static bitsetv F = NULL;
static short **includes;
static shorts **lookback;
static short **includes;
static shorts **lookback;
- LA = XCALLOC (bitset, nLA);
- for (i = 0; i < nLA; ++i)
- LA[i] = bitset_create (ntokens, BITSET_FIXED);
+ LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
LAruleno = XCALLOC (short, nLA);
lookback = XCALLOC (shorts *, nLA);
LAruleno = XCALLOC (short, nLA);
lookback = XCALLOC (shorts *, nLA);
- F = XCALLOC (bitset, ngotos);
- for (i = 0; i < ngotos; ++i)
- F[i] = bitset_create (ntokens, BITSET_FIXED);
+ F = bitsetv_create (ngotos, ntokens, BITSET_FIXED);
for (i = 0; i < ngotos; i++)
{
for (i = 0; i < ngotos; i++)
{
LIST_FREE (shorts, lookback[i]);
XFREE (lookback);
LIST_FREE (shorts, lookback[i]);
XFREE (lookback);
- for (i = 0; i < (unsigned) ngotos; ++i)
- bitset_free (F[i]);
- XFREE (F);
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ bitset_stats_init ();
+
lineno = 0;
getargs (argc, argv);
lineno = 0;
getargs (argc, argv);
negative short int. Used to flag ?? */
#include "system.h"
negative short int. Used to flag ?? */
#include "system.h"
#include "quotearg.h"
#include "error.h"
#include "getargs.h"
#include "quotearg.h"
#include "error.h"
#include "getargs.h"
width = XCALLOC (short, nvectors);
token_actions ();
width = XCALLOC (short, nvectors);
token_actions ();
XFREE (LAruleno);
goto_actions ();
XFREE (LAruleno);
goto_actions ();
static int nuseful_nonterminals;
int nuseless_nonterminals;
\f
static int nuseful_nonterminals;
int nuseless_nonterminals;
\f
-static int
-bits_size (bitset S)
-{
- int i, count = 0;
-
- BITSET_EXECUTE (S, 0, i, { ++count; });
- return count;
-}
-\f
/*-------------------------------------------------------------------.
| 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 |
/*-------------------------------------------------------------------.
| 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 |
in the set of useful nonterminals. */
for (r = &ritem[rules[i].rhs]; *r >= 0; r++)
in the set of useful nonterminals. */
for (r = &ritem[rules[i].rhs]; *r >= 0; r++)
- if (ISVAR (n = *r))
- if (!bitset_test (N0, n - ntokens))
- return FALSE;
+ if (ISVAR (n = *r) && !bitset_test (N0, n - ntokens))
+ return FALSE;
- nuseful_productions = bits_size (P);
+ nuseful_productions = bitset_count (P);
nuseless_productions = nrules - nuseful_productions;
nuseful_nonterminals = 0;
nuseless_productions = nrules - nuseful_productions;
nuseful_nonterminals = 0;
#include "system.h"
#include "getargs.h"
#include "system.h"
#include "getargs.h"
#include "warshall.h"
/*--------------------------------------------------------.
#include "warshall.h"
/*--------------------------------------------------------.
`--------------------------------------------------------*/
static void
`--------------------------------------------------------*/
static void
-bitmatrix_print (const char *title, bitset *matrix, size_t size)
+bitmatrix_print (const char *title, bitsetv matrix)
+ size_t size = bitset_size (matrix[0]);
/* Title. */
fprintf (stderr, "%s BEGIN\n", title);
/* Title. */
fprintf (stderr, "%s BEGIN\n", title);
`-------------------------------------------------------------------*/
static void
`-------------------------------------------------------------------*/
static void
-TC (bitset *matrix, int n)
{
int i, j;
if (trace_flag)
{
int i, j;
if (trace_flag)
- bitmatrix_print ("TC: Input", matrix, n);
+ bitmatrix_print ("TC: Input", matrix);
/* R (J, I) && R (I, K) => R (J, K).
I *must* be the outter loop. */
/* R (J, I) && R (I, K) => R (J, K).
I *must* be the outter loop. */
- for (i = 0; i < n; ++i)
- for (j = 0; j < n; ++j)
+ for (i = 0; matrix[i]; ++i)
+ for (j = 0; matrix[j]; ++j)
if (bitset_test (matrix[j], i))
bitset_or (matrix[j], matrix[j], matrix[i]);
if (trace_flag)
if (bitset_test (matrix[j], i))
bitset_or (matrix[j], matrix[j], matrix[i]);
if (trace_flag)
- bitmatrix_print ("TC: Output", matrix, n);
+ bitmatrix_print ("TC: Output", matrix);
`---------------------------------------------------------------*/
void
`---------------------------------------------------------------*/
void
-RTC (bitset *matrix, int n)
- TC (matrix, n);
- for (i = 0; i < n; ++i)
+ TC (matrix);
+ for (i = 0; matrix[i]; ++i)
bitset_set (matrix[i], i);
}
bitset_set (matrix[i], i);
}
/* 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.
#ifndef WARSHALL_H_
# define WARSHALL_H_
#ifndef WARSHALL_H_
# define WARSHALL_H_
-void RTC PARAMS ((bitset *, int));
+void RTC PARAMS ((bitsetv));
#endif /* !WARSHALL_H_ */
#endif /* !WARSHALL_H_ */