mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 02:33:03 +00:00
style: various fixes
* src/gram.c: Use consistent variable names. Prefix prefix unary operators. (grammar_dump): Use rule_rhs_length instead of duplicating it. * src/reduce.c: Avoid useless variables.
This commit is contained in:
33
src/gram.c
33
src/gram.c
@@ -86,7 +86,7 @@ size_t
|
|||||||
rule_rhs_length (rule const *r)
|
rule_rhs_length (rule const *r)
|
||||||
{
|
{
|
||||||
size_t res = 0;
|
size_t res = 0;
|
||||||
for (item_number *rhsp = r->rhs; *rhsp >= 0; ++rhsp)
|
for (item_number *rhsp = r->rhs; 0 <= *rhsp; ++rhsp)
|
||||||
++res;
|
++res;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -95,8 +95,8 @@ void
|
|||||||
rule_rhs_print (rule const *r, FILE *out)
|
rule_rhs_print (rule const *r, FILE *out)
|
||||||
{
|
{
|
||||||
if (0 <= *r->rhs)
|
if (0 <= *r->rhs)
|
||||||
for (item_number *rp = r->rhs; *rp >= 0; rp++)
|
for (item_number *rhsp = r->rhs; 0 <= *rhsp; ++rhsp)
|
||||||
fprintf (out, " %s", symbols[*rp]->tag);
|
fprintf (out, " %s", symbols[*rhsp]->tag);
|
||||||
else
|
else
|
||||||
fputs (" %empty", out);
|
fputs (" %empty", out);
|
||||||
}
|
}
|
||||||
@@ -107,9 +107,9 @@ rule_rhs_print_xml (rule const *r, FILE *out, int level)
|
|||||||
if (*r->rhs >= 0)
|
if (*r->rhs >= 0)
|
||||||
{
|
{
|
||||||
xml_puts (out, level, "<rhs>");
|
xml_puts (out, level, "<rhs>");
|
||||||
for (item_number *rp = r->rhs; *rp >= 0; rp++)
|
for (item_number *rhsp = r->rhs; 0 <= *rhsp; ++rhsp)
|
||||||
xml_printf (out, level + 1, "<symbol>%s</symbol>",
|
xml_printf (out, level + 1, "<symbol>%s</symbol>",
|
||||||
xml_escape (symbols[*rp]->tag));
|
xml_escape (symbols[*rhsp]->tag));
|
||||||
xml_puts (out, level, "</rhs>");
|
xml_puts (out, level, "</rhs>");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -138,7 +138,7 @@ ritem_longest_rhs (void)
|
|||||||
int max = 0;
|
int max = 0;
|
||||||
for (rule_number r = 0; r < nrules; ++r)
|
for (rule_number r = 0; r < nrules; ++r)
|
||||||
{
|
{
|
||||||
int length = rule_rhs_length (&rules[r]);
|
size_t length = rule_rhs_length (&rules[r]);
|
||||||
if (length > max)
|
if (length > max)
|
||||||
max = length;
|
max = length;
|
||||||
}
|
}
|
||||||
@@ -165,7 +165,7 @@ grammar_rules_partial_print (FILE *out, const char *title,
|
|||||||
first = false;
|
first = false;
|
||||||
rule_lhs_print (&rules[r], previous_lhs, out);
|
rule_lhs_print (&rules[r], previous_lhs, out);
|
||||||
rule_rhs_print (&rules[r], out);
|
rule_rhs_print (&rules[r], out);
|
||||||
fprintf (out, "\n");
|
fputc ('\n', out);
|
||||||
previous_lhs = rules[r].lhs;
|
previous_lhs = rules[r].lhs;
|
||||||
}
|
}
|
||||||
if (!first)
|
if (!first)
|
||||||
@@ -244,33 +244,30 @@ grammar_dump (FILE *out, const char *title)
|
|||||||
{
|
{
|
||||||
rule const *rule_i = &rules[i];
|
rule const *rule_i = &rules[i];
|
||||||
unsigned const rhs_itemno = rule_i->rhs - ritem;
|
unsigned const rhs_itemno = rule_i->rhs - ritem;
|
||||||
/* Find the last RHS index in ritems. */
|
unsigned length = rule_rhs_length (rule_i);
|
||||||
unsigned rhs_count = 0;
|
|
||||||
for (item_number *rp = rule_i->rhs; *rp >= 0; ++rp)
|
|
||||||
++rhs_count;
|
|
||||||
fprintf (out, "%3d (%2d, %2d, %2d, %2u-%2u) %2d ->",
|
fprintf (out, "%3d (%2d, %2d, %2d, %2u-%2u) %2d ->",
|
||||||
i,
|
i,
|
||||||
rule_i->prec ? rule_i->prec->prec : 0,
|
rule_i->prec ? rule_i->prec->prec : 0,
|
||||||
rule_i->prec ? rule_i->prec->assoc : 0,
|
rule_i->prec ? rule_i->prec->assoc : 0,
|
||||||
rule_i->useful,
|
rule_i->useful,
|
||||||
rhs_itemno,
|
rhs_itemno,
|
||||||
rhs_itemno + rhs_count - 1,
|
rhs_itemno + length - 1,
|
||||||
rule_i->lhs->number);
|
rule_i->lhs->number);
|
||||||
/* Dumped the RHS. */
|
/* Dumped the RHS. */
|
||||||
for (item_number *rp = rule_i->rhs; *rp >= 0; ++rp)
|
for (item_number *rhsp = rule_i->rhs; 0 <= *rhsp; ++rhsp)
|
||||||
fprintf (out, " %3d", *rp);
|
fprintf (out, " %3d", *rhsp);
|
||||||
fprintf (out, " [%d]\n",
|
fprintf (out, " [%d]\n",
|
||||||
item_number_as_rule_number (rule_i->rhs[rhs_count+1]));
|
item_number_as_rule_number (rule_i->rhs[length+1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf (out, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
|
|
||||||
fprintf (out, "Rules interpreted\n-----------------\n\n");
|
fprintf (out, "Rules interpreted\n-----------------\n\n");
|
||||||
for (rule_number r = 0; r < nrules + nuseless_productions; r++)
|
for (rule_number r = 0; r < nrules + nuseless_productions; ++r)
|
||||||
{
|
{
|
||||||
fprintf (out, "%-5d %s:", r, rules[r].lhs->symbol->tag);
|
fprintf (out, "%-5d %s:", r, rules[r].lhs->symbol->tag);
|
||||||
rule_rhs_print (&rules[r], out);
|
rule_rhs_print (&rules[r], out);
|
||||||
fprintf (out, "\n");
|
fputc ('\n', out);
|
||||||
}
|
}
|
||||||
fprintf (out, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
}
|
}
|
||||||
@@ -278,7 +275,7 @@ grammar_dump (FILE *out, const char *title)
|
|||||||
void
|
void
|
||||||
grammar_rules_useless_report (const char *message)
|
grammar_rules_useless_report (const char *message)
|
||||||
{
|
{
|
||||||
for (rule_number r = 0; r < nrules ; ++r)
|
for (rule_number r = 0; r < nrules; ++r)
|
||||||
/* Don't complain about rules whose LHS is useless, we already
|
/* Don't complain about rules whose LHS is useless, we already
|
||||||
complained about it. */
|
complained about it. */
|
||||||
if (!reduce_nonterminal_useless_in_grammar (rules[r].lhs)
|
if (!reduce_nonterminal_useless_in_grammar (rules[r].lhs)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <bitset/stats.h>
|
#include <bitset/stats.h>
|
||||||
#include <configmake.h>
|
#include <configmake.h>
|
||||||
#include <progname.h>
|
#include <progname.h>
|
||||||
|
#include <quote.h>
|
||||||
#include <quotearg.h>
|
#include <quotearg.h>
|
||||||
#include <relocatable.h> /* relocate2 */
|
#include <relocatable.h> /* relocate2 */
|
||||||
#include <timevar.h>
|
#include <timevar.h>
|
||||||
@@ -38,15 +39,14 @@
|
|||||||
#include "fixits.h"
|
#include "fixits.h"
|
||||||
#include "getargs.h"
|
#include "getargs.h"
|
||||||
#include "gram.h"
|
#include "gram.h"
|
||||||
#include "lalr.h"
|
|
||||||
#include "ielr.h"
|
#include "ielr.h"
|
||||||
|
#include "lalr.h"
|
||||||
#include "muscle-tab.h"
|
#include "muscle-tab.h"
|
||||||
#include "nullable.h"
|
#include "nullable.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
|
#include "print-xml.h"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
#include "print_graph.h"
|
#include "print_graph.h"
|
||||||
#include "print-xml.h"
|
|
||||||
#include <quote.h>
|
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "reduce.h"
|
#include "reduce.h"
|
||||||
#include "scan-code.h"
|
#include "scan-code.h"
|
||||||
|
|||||||
@@ -250,10 +250,7 @@ reduce_grammar_tables (void)
|
|||||||
|
|
||||||
/* Adjust NRITEMS. */
|
/* Adjust NRITEMS. */
|
||||||
for (rule_number r = nrules; r < nrules + nuseless_productions; ++r)
|
for (rule_number r = nrules; r < nrules + nuseless_productions; ++r)
|
||||||
{
|
nritems -= rule_rhs_length (&rules[r]) + 1;
|
||||||
int length = rule_rhs_length (&rules[r]);
|
|
||||||
nritems -= length + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user