* lib/libiberty.h: New.

* lib: Update the bitset implementation from upstream.
* src/closure.c, src/lalr.c, src/output.c, src/print_graph.c,
* src/state.c: Use BITSET_FOR_EACH, not BITSET_EXECUTE.
* src/main.c: Adjust bitset stats calls.
This commit is contained in:
Akim Demaille
2002-07-02 13:51:27 +00:00
parent 524346a3a3
commit 613f5e1a89
22 changed files with 1009 additions and 809 deletions

View File

@@ -74,12 +74,13 @@ print_firsts (void)
fprintf (stderr, "FIRSTS\n");
for (i = ntokens; i < nsyms; i++)
{
bitset_iterator iter;
fprintf (stderr, "\t%s firsts\n", symbols[i]->tag);
BITSET_EXECUTE (FIRSTS (i), 0, j,
{
fprintf (stderr, "\t\t%s\n",
symbols[j + ntokens]->tag);
});
BITSET_FOR_EACH (iter, FIRSTS (i), j, 0)
{
fprintf (stderr, "\t\t%s\n",
symbols[j + ntokens]->tag);
}
}
fprintf (stderr, "\n\n");
}
@@ -94,15 +95,16 @@ print_fderives (void)
fprintf (stderr, "FDERIVES\n");
for (i = ntokens; i < nsyms; i++)
{
bitset_iterator iter;
fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
BITSET_EXECUTE (FDERIVES (i), 0, r,
{
item_number_t *rhsp = NULL;
fprintf (stderr, "\t\t%d:", r - 1);
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
fprintf (stderr, " %s", symbols[*rhsp]->tag);
fputc ('\n', stderr);
});
BITSET_FOR_EACH (iter, FDERIVES (i), r, 0)
{
item_number_t *rhsp = NULL;
fprintf (stderr, "\t\t%d:", r - 1);
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
fprintf (stderr, " %s", symbols[*rhsp]->tag);
fputc ('\n', stderr);
}
}
fprintf (stderr, "\n\n");
}
@@ -198,6 +200,8 @@ closure (item_number_t *core, int n)
/* A bit index over RULESET. */
rule_number_t ruleno;
bitset_iterator iter;
if (trace_flag)
print_closure ("input", core, n);
@@ -209,18 +213,18 @@ closure (item_number_t *core, int n)
nritemset = 0;
c = 0;
BITSET_EXECUTE (ruleset, 0, ruleno,
{
item_number_t itemno = rules[ruleno].rhs - ritem;
while (c < n && core[c] < itemno)
{
itemset[nritemset] = core[c];
nritemset++;
c++;
}
itemset[nritemset] = itemno;
nritemset++;
});
BITSET_FOR_EACH (iter, ruleset, ruleno, 0)
{
item_number_t itemno = rules[ruleno].rhs - ritem;
while (c < n && core[c] < itemno)
{
itemset[nritemset] = core[c];
nritemset++;
c++;
}
itemset[nritemset] = itemno;
nritemset++;
};
while (c < n)
{

View File

@@ -420,16 +420,18 @@ lookaheads_print (FILE *out)
fprintf (out, "Lookaheads: BEGIN\n");
for (i = 0; i < nstates; ++i)
{
bitset_iterator iter;
fprintf (out, "State %d: %d lookaheads\n",
i, states[i]->nlookaheads);
for (j = 0; j < states[i]->nlookaheads; ++j)
BITSET_EXECUTE (states[i]->lookaheads[j], 0, k,
BITSET_FOR_EACH (iter, states[i]->lookaheads[j], k, 0)
{
fprintf (out, " on %d (%s) -> rule %d\n",
k, symbols[k]->tag,
states[i]->lookaheads_rule[j]->number - 1);
});
};
}
fprintf (out, "Lookaheads: END\n");
}

View File

@@ -21,6 +21,7 @@
#include "system.h"
#include "bitset_stats.h"
#include "bitset.h"
#include "getargs.h"
#include "symtab.h"
@@ -50,11 +51,12 @@ main (int argc, char *argv[])
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
bitset_stats_init ();
lineno = 0;
getargs (argc, argv);
if (trace_flag)
bitset_stats_enable ();
muscle_init ();
/* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE
@@ -122,5 +124,8 @@ main (int argc, char *argv[])
alloca (0);
#endif
if (trace_flag)
bitset_stats_dump (stderr);
return complain_message_count ? EXIT_FAILURE : EXIT_SUCCESS;
}

View File

@@ -442,19 +442,20 @@ action_row (state_t *state)
if (redp->num >= 1)
{
int j;
bitset_iterator biter;
/* loop over all the rules available here which require
lookahead */
for (i = state->nlookaheads - 1; i >= 0; --i)
/* and find each token which the rule finds acceptable
to come next */
BITSET_EXECUTE (state->lookaheads[i], 0, j,
BITSET_FOR_EACH (biter, state->lookaheads[i], j, 0)
{
/* and record this rule as the rule to use if that
token follows. */
if (actrow[j] != 0)
conflicted = conflrow[j] = 1;
actrow[j] = -state->lookaheads_rule[i]->number;
});
}
}
/* Now see which tokens are allowed for shifts in this state. For

View File

@@ -90,26 +90,24 @@ print_core (struct obstack *oout, state_t *state)
&& state->nlookaheads)
{
int j, k;
bitset_iterator biter;
int nlookaheads = 0;
/* Look for lookaheads corresponding to this rule. */
for (j = 0; j < state->nlookaheads; ++j)
BITSET_EXECUTE (state->lookaheads[j], 0, k,
{
BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0)
if (state->lookaheads_rule[j]->number == rule)
nlookaheads++;
});
if (nlookaheads)
{
obstack_sgrow (oout, " [");
for (j = 0; j < state->nlookaheads; ++j)
BITSET_EXECUTE (state->lookaheads[j], 0, k,
{
BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0)
if (state->lookaheads_rule[j]->number == rule)
obstack_fgrow2 (oout, "%s%s",
symbols[k]->tag,
--nlookaheads ? ", " : "");
});
obstack_sgrow (oout, "]");
}
}

View File

@@ -195,27 +195,24 @@ void
state_rule_lookaheads_print (state_t *state, rule_t *rule, FILE *out)
{
int j, k;
bitset_iterator biter;
int nlookaheads = 0;
/* Count the number of lookaheads corresponding to this rule. */
for (j = 0; j < state->nlookaheads; ++j)
BITSET_EXECUTE (state->lookaheads[j], 0, k,
{
BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0)
if (state->lookaheads_rule[j]->number == rule->number)
nlookaheads++;
});
/* Print them if there are. */
if (nlookaheads)
{
fprintf (out, " [");
for (j = 0; j < state->nlookaheads; ++j)
BITSET_EXECUTE (state->lookaheads[j], 0, k,
{
BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0)
if (state->lookaheads_rule[j]->number == rule->number)
fprintf (out, "%s%s",
symbols[k]->tag,
--nlookaheads ? ", " : "");
});
fprintf (out, "]");
}
}