mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 06:13:02 +00:00
Merge remote-tracking branch 'origin/maint'
* origin/maint: (46 commits) doc: minor style change maint: use gendocs's new -I option regen yacc.c: do not define location support when not using locations maint: be compilable with GCC 4.0 tests: address a warning from GCC 4.4 tests: don't use options that Clang does not support tests: restore the tests on -Werror regen parse-gram: update the Bison interface fix comment maint: post-release administrivia version 2.6.4 regen 2.6.4: botched 2.6.3 maint: post-release administrivia version 2.6.3 gnulib: update tests: check %no-lines NEWS: warnings with clang ... Conflicts: NEWS TODO data/c.m4 data/java.m4 doc/Makefile.am src/getargs.c src/getargs.h src/output.c src/parse-gram.c src/parse-gram.h src/parse-gram.y src/reader.h
This commit is contained in:
108
src/graphviz.c
108
src/graphviz.c
@@ -53,7 +53,10 @@ start_graph (FILE *fout)
|
||||
"digraph %s\n"
|
||||
"{\n",
|
||||
quote (grammar_file));
|
||||
fprintf (fout, "node [shape=box]\n");
|
||||
fprintf (fout,
|
||||
" node [fontname = courier, shape = box, colorscheme = paired6]\n"
|
||||
" edge [fontname = courier]\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -93,13 +96,54 @@ no_reduce_bitset_init (state const *s, bitset *no_reduce_set)
|
||||
bitset_set (*no_reduce_set, s->errs->symbols[n]->number);
|
||||
}
|
||||
|
||||
static void
|
||||
conclude_red (struct obstack *out, int source, rule_number ruleno,
|
||||
bool enabled, bool first, FILE *fout)
|
||||
{
|
||||
/* If no lookahead tokens were valid transitions, this reduction is
|
||||
actually hidden, so cancel everything. */
|
||||
if (first)
|
||||
return (void) obstack_finish0 (out);
|
||||
else
|
||||
{
|
||||
char const *ed = enabled ? "e" : "d";
|
||||
char const *color = enabled ? ruleno ? "3" : "1" : "5";
|
||||
|
||||
/* First, build the edge's head. The name of reduction nodes is "nRm",
|
||||
with n the source state and m the rule number. This is because we
|
||||
don't want all the reductions bearing a same rule number to point to
|
||||
the same state, since that is not the desired format. */
|
||||
fprintf (fout, " %1$d -> \"%1$dR%2$d%3$s\" [",
|
||||
source, ruleno, ed);
|
||||
|
||||
if (! obstack_empty_p (out))
|
||||
/* (The lookahead tokens have been added to the beginning of the
|
||||
obstack, in the caller function.) */
|
||||
fprintf (fout, "label = \"[%s]\" ", obstack_finish0 (out));
|
||||
|
||||
/* Then, the edge's tail. */
|
||||
fprintf (fout, "style = solid]\n");
|
||||
|
||||
/* Build the associated diamond representation of the target rule. */
|
||||
fprintf (fout, " \"%dR%d%s\" [style = filled, "
|
||||
"shape = diamond, fillcolor = %s, ",
|
||||
source, ruleno, ed, color);
|
||||
|
||||
if (ruleno)
|
||||
fprintf (fout, "label = \"R%d\"]\n", ruleno);
|
||||
else
|
||||
fprintf (fout, "label = \"Acc\"]\n");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
print_token (struct obstack *out, bool first, char const *tok)
|
||||
{
|
||||
char const *q = escape (tok);
|
||||
|
||||
if (! first)
|
||||
obstack_sgrow (out, ",");
|
||||
obstack_sgrow (out, ", ");
|
||||
obstack_sgrow (out, q);
|
||||
return false;
|
||||
}
|
||||
@@ -110,58 +154,56 @@ output_red (state const *s, reductions const *reds, FILE *fout)
|
||||
bitset no_reduce_set;
|
||||
int j;
|
||||
int source = s->number;
|
||||
struct obstack oout;
|
||||
|
||||
/* Two obstacks are needed: one for the enabled reductions, and one
|
||||
for the disabled reductions, because in the end we want two
|
||||
separate edges, even though in most cases only one will actually
|
||||
be printed. */
|
||||
struct obstack dout;
|
||||
struct obstack eout;
|
||||
|
||||
no_reduce_bitset_init (s, &no_reduce_set);
|
||||
obstack_init (&oout);
|
||||
obstack_init (&dout);
|
||||
obstack_init (&eout);
|
||||
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
{
|
||||
bool disabled = false;
|
||||
bool first = true;
|
||||
int ruleno = reds->rules[j]->user_number;
|
||||
bool defaulted = false;
|
||||
bool firstd = true;
|
||||
bool firste = true;
|
||||
rule_number ruleno = reds->rules[j]->user_number;
|
||||
rule *default_reduction = NULL;
|
||||
|
||||
if (yydefact[s->number] != 0)
|
||||
default_reduction = &rules[yydefact[s->number] - 1];
|
||||
|
||||
/* First, print the edges that represent each possible reduction for
|
||||
the given state. */
|
||||
obstack_printf (&oout, " %1$d -> \"%1$dR%2$d\" [label=\"",
|
||||
source, ruleno);
|
||||
/* Build the lookahead tokens lists, one for enabled transitions and one
|
||||
for disabled transistions. */
|
||||
if (default_reduction && default_reduction == reds->rules[j])
|
||||
first = print_token (&oout, true, "$default");
|
||||
else
|
||||
defaulted = true;
|
||||
if (reds->lookahead_tokens)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < ntokens; i++)
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
{
|
||||
first = print_token (&oout, first, symbols[i]->tag);
|
||||
if (bitset_test (no_reduce_set, i))
|
||||
disabled = true;
|
||||
firstd = print_token (&dout, firstd, symbols[i]->tag);
|
||||
else
|
||||
{
|
||||
if (! defaulted)
|
||||
firste = print_token (&eout, firste, symbols[i]->tag);
|
||||
bitset_set (no_reduce_set, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
obstack_sgrow (&oout, "\" style=solid]\n");
|
||||
|
||||
/* Then, print the reduction's representation. Done later since
|
||||
we need to know whether this reduction is disabled. */
|
||||
obstack_printf (&oout,
|
||||
" \"%dR%d\" "
|
||||
"[style=filled shape=diamond fillcolor=%s "
|
||||
"label=\"R%d\"]\n",
|
||||
source, ruleno,
|
||||
disabled ? "firebrick1" : "yellowgreen",
|
||||
ruleno);
|
||||
|
||||
/* If no lookahead tokens were valid transitions, this reduction is
|
||||
actually disabled, so don't print it. */
|
||||
if (first)
|
||||
(void) obstack_finish0 (&oout);
|
||||
else
|
||||
fprintf (fout, obstack_finish0 (&oout));
|
||||
/* Do the actual output. */
|
||||
conclude_red (&eout, source, ruleno, true, firste && !defaulted, fout);
|
||||
conclude_red (&dout, source, ruleno, false, firstd, fout);
|
||||
}
|
||||
obstack_free (&oout, 0);
|
||||
obstack_free (&eout, 0);
|
||||
obstack_free (&dout, 0);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -88,7 +88,7 @@ typedef struct
|
||||
|
||||
} location;
|
||||
|
||||
#define YYLTYPE location
|
||||
#define GRAM_LTYPE location
|
||||
|
||||
#define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}}
|
||||
extern location const empty_location;
|
||||
|
||||
@@ -87,15 +87,15 @@ static char const *char_name (char);
|
||||
#define YYTYPE_UINT8 uint_fast8_t
|
||||
}
|
||||
|
||||
%verbose
|
||||
%defines
|
||||
%define locations
|
||||
%define api.prefix "gram_"
|
||||
%define api.pure
|
||||
%define locations
|
||||
%define parse.error verbose
|
||||
%define parse.lac full
|
||||
%define parse.trace
|
||||
%name-prefix "gram_"
|
||||
%defines
|
||||
%expect 0
|
||||
%verbose
|
||||
|
||||
%initial-action
|
||||
{
|
||||
|
||||
@@ -40,11 +40,32 @@
|
||||
| Construct the node labels. |
|
||||
`----------------------------*/
|
||||
|
||||
/* Print the lhs of a rule in such a manner that there is no vertical
|
||||
repetition, like in *.output files. */
|
||||
|
||||
static void
|
||||
print_lhs (struct obstack *oout, rule *previous_rule, rule *r)
|
||||
{
|
||||
if (previous_rule && STREQ (previous_rule->lhs->tag, r->lhs->tag))
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < strlen (r->lhs->tag); ++i)
|
||||
obstack_1grow (oout, ' ');
|
||||
obstack_1grow (oout, '|');
|
||||
}
|
||||
else
|
||||
{
|
||||
obstack_sgrow (oout, escape (r->lhs->tag));
|
||||
obstack_1grow (oout, ':');
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_core (struct obstack *oout, state *s)
|
||||
{
|
||||
size_t i;
|
||||
item_number *sitems = s->items;
|
||||
rule *previous_rule = NULL;
|
||||
size_t i;
|
||||
size_t snritems = s->nitems;
|
||||
|
||||
/* Output all the items of a state, not only its kernel. */
|
||||
@@ -55,7 +76,8 @@ print_core (struct obstack *oout, state *s)
|
||||
snritems = nitemset;
|
||||
}
|
||||
|
||||
obstack_printf (oout, "state %d\\n", s->number);
|
||||
obstack_printf (oout, _("State %d"), s->number);
|
||||
obstack_sgrow (oout, "\\n");
|
||||
for (i = 0; i < snritems; i++)
|
||||
{
|
||||
item_number *sp;
|
||||
@@ -69,12 +91,14 @@ print_core (struct obstack *oout, state *s)
|
||||
|
||||
r = item_number_as_rule_number (*sp);
|
||||
|
||||
obstack_printf (oout, "%d: %s -> ", r, escape (rules[r].lhs->tag));
|
||||
obstack_printf (oout, "%3d ", r);
|
||||
print_lhs (oout, previous_rule, &rules[r]);
|
||||
previous_rule = &rules[r];
|
||||
|
||||
for (sp = rules[r].rhs; sp < sp1; sp++)
|
||||
obstack_printf (oout, "%s ", escape (symbols[*sp]->tag));
|
||||
|
||||
obstack_1grow (oout, '.');
|
||||
obstack_sgrow (oout, " .");
|
||||
|
||||
for (/* Nothing */; *sp >= 0; ++sp)
|
||||
obstack_printf (oout, " %s", escape (symbols[*sp]->tag));
|
||||
@@ -93,7 +117,7 @@ print_core (struct obstack *oout, state *s)
|
||||
bitset_iterator biter;
|
||||
int k;
|
||||
char const *sep = "";
|
||||
obstack_1grow (oout, '[');
|
||||
obstack_sgrow (oout, " [");
|
||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
|
||||
{
|
||||
obstack_sgrow (oout, sep);
|
||||
@@ -116,9 +140,8 @@ print_core (struct obstack *oout, state *s)
|
||||
static void
|
||||
print_actions (state const *s, FILE *fgraph)
|
||||
{
|
||||
int i;
|
||||
|
||||
transitions const *trans = s->transitions;
|
||||
int i;
|
||||
|
||||
/* Display reductions. */
|
||||
output_red (s, s->reductions, fgraph);
|
||||
|
||||
@@ -51,9 +51,9 @@ void grammar_current_rule_prec_set (symbol *precsym, location loc);
|
||||
void grammar_current_rule_dprec_set (int dprec, location loc);
|
||||
void grammar_current_rule_merge_set (uniqstr name, location loc);
|
||||
void grammar_current_rule_symbol_append (symbol *sym, location loc,
|
||||
named_ref *named_ref);
|
||||
named_ref *nref);
|
||||
void grammar_current_rule_action_append (const char *action, location loc,
|
||||
named_ref *named_ref, bool);
|
||||
named_ref *nref, bool);
|
||||
void reader (void);
|
||||
void free_merger_functions (void);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ void gram_scanner_last_string_free (void);
|
||||
extern FILE *gram_out;
|
||||
extern int gram_lineno;
|
||||
|
||||
# define GRAM_LEX_DECL int gram_lex (YYSTYPE *val, location *loc)
|
||||
# define GRAM_LEX_DECL int gram_lex (GRAM_STYPE *val, location *loc)
|
||||
GRAM_LEX_DECL;
|
||||
|
||||
#endif /* !SCAN_GRAM_H_ */
|
||||
|
||||
Reference in New Issue
Block a user