+2002-03-04 Akim Demaille <akim@epita.fr>
+
+ Use bitset operations when possible, not loops over bits.
+
+ * src/conflicts.c (set_conflicts, count_sr_conflicts): Use
+ bitset_or.
+ * src/print.c (print_reductions): Use bitset_and, bitset_andn.
+ * src/reduce.c (useless_nonterminals): Formatting changes.
+ * src/warshall.c (TC): Use bitset_or.
+
+
2002-03-04 Akim Demaille <akim@epita.fr>
* src/lalr.h, src/lalr.c (tokensetsize): Remove, unused.
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;
- for (j = 0; j < ntokens; ++j)
- if (bitset_test (LA[state->lookaheadsp + i], j))
- bitset_set (lookaheadset, j);
+ bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
}
}
static int
count_sr_conflicts (state_t *state)
{
- int i, k;
+ int i;
int src_count = 0;
shifts *shiftp = state->shifts;
bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
for (i = 0; i < state->nlookaheads; ++i)
- for (k = 0; k < ntokens; ++k)
- if (bitset_test (LA[state->lookaheadsp + i], k))
- bitset_set (lookaheadset, k);
+ bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
bitset_and (lookaheadset, lookaheadset, shiftset);
{
int default_rule = LAruleno[state->lookaheadsp];
- for (i = 0; i < ntokens; ++i)
- if (bitset_test (LA[state->lookaheadsp], i)
- && bitset_test (shiftset, i))
- bitset_set (lookaheadset, i);
- else
- bitset_reset (lookaheadset, i);
+ bitset_and (lookaheadset, LA[state->lookaheadsp], shiftset);
for (i = 0; i < ntokens; i++)
if (bitset_test (lookaheadset, i))
for (i = 0; i < state->nlookaheads; ++i)
{
int count = 0;
- int j, k;
+ int j;
- for (k = 0; k < ntokens; ++k)
- if (bitset_test (LA[state->lookaheadsp + i], k)
- && ! bitset_test (shiftset, k))
- bitset_set (lookaheadset, k);
- else
- bitset_reset (lookaheadset, k);
+ bitset_andn (lookaheadset, LA[state->lookaheadsp + i], shiftset);
for (j = 0; j < ntokens; j++)
if (bitset_test (lookaheadset, j))
int count = bitset_test (shiftset, i);
for (j = 0; j < state->nlookaheads; ++j)
- {
- if (bitset_test (LA[state->lookaheadsp + j], i))
- {
- if (count == 0)
- {
- if (state->lookaheadsp + j != default_LA)
- fprintf (out,
- _(" %-4s\treduce using rule %d (%s)\n"),
- escape (symbols[i]->tag),
- LAruleno[state->lookaheadsp + j] - 1,
- escape2 (symbols[rules[LAruleno[state->lookaheadsp + j]].lhs]->tag));
- else
- defaulted = 1;
-
- count++;
- }
- else
- {
- if (defaulted)
- fprintf (out,
- _(" %-4s\treduce using rule %d (%s)\n"),
- escape (symbols[i]->tag),
- LAruleno[default_LA] - 1,
- escape2 (symbols[rules[LAruleno[default_LA]].lhs]->tag));
- defaulted = 0;
+ if (bitset_test (LA[state->lookaheadsp + j], i))
+ {
+ if (count == 0)
+ {
+ if (state->lookaheadsp + j != default_LA)
fprintf (out,
- _(" %-4s\t[reduce using rule %d (%s)]\n"),
+ _(" %-4s\treduce using rule %d (%s)\n"),
escape (symbols[i]->tag),
LAruleno[state->lookaheadsp + j] - 1,
escape2 (symbols[rules[LAruleno[state->lookaheadsp + j]].lhs]->tag));
- }
- }
- }
+ else
+ defaulted = 1;
+
+ count++;
+ }
+ else
+ {
+ if (defaulted)
+ fprintf (out,
+ _(" %-4s\treduce using rule %d (%s)\n"),
+ escape (symbols[i]->tag),
+ LAruleno[default_LA] - 1,
+ escape2 (symbols[rules[LAruleno[default_LA]].lhs]->tag));
+ defaulted = 0;
+ fprintf (out,
+ _(" %-4s\t[reduce using rule %d (%s)]\n"),
+ escape (symbols[i]->tag),
+ LAruleno[state->lookaheadsp + j] - 1,
+ escape2 (symbols[rules[LAruleno[state->lookaheadsp + j]].lhs]->tag));
+ }
+ }
}
if (default_LA >= 0)
static void
TC (bitset *matrix, int n)
{
- int i, j, k;
+ int i, j;
if (trace_flag)
bitmatrix_print ("TC: Input", matrix, n);
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
if (bitset_test (matrix[j], i))
- for (k = 0; k < n; ++k)
- if (bitset_test (matrix[i], k))
- bitset_set (matrix[j], k);
+ bitset_or (matrix[j], matrix[j], matrix[i]);
if (trace_flag)
bitmatrix_print ("TC: Output", matrix, n);