X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/34cdeddfa54df8c85b20bf013a0b82053a5148f2..41930e7ad89f9a889b1c00fbd2842dded01ada1a:/src/print-xml.c
diff --git a/src/print-xml.c b/src/print-xml.c
index 81f4d803..cb6707da 100644
--- a/src/print-xml.c
+++ b/src/print-xml.c
@@ -51,35 +51,6 @@ struct escape_buf
static struct escape_buf escape_bufs[2];
-/*----------------------------.
-| Print rules never reduced. |
-`-----------------------------*/
-
-static void
-print_rules_never_reduced (FILE *out, int level)
-{
- rule_number r;
- bool count = false;
-
- for (r = 0; r < nrules + nuseless_productions; r++)
- {
- if (rule_never_reduced_p (&rules[r]))
- {
- count = true;
- break;
- }
- }
-
- if (count) {
- xml_puts (out, level, "");
- grammar_rules_partial_print_xml (out, level - 1,
- false, rule_never_reduced_p);
- xml_puts (out, level, "");
- }
- else
- xml_puts (out, level, "");
-}
-
/*--------------------------------.
| Report information on a state. |
`--------------------------------*/
@@ -92,12 +63,9 @@ print_core (FILE *out, int level, state *s)
size_t snritems = s->nitems;
/* Output all the items of a state, not only its kernel. */
- if (report_flag & report_itemsets)
- {
- closure (sitems, snritems);
- sitems = itemset;
- snritems = nitemset;
- }
+ closure (sitems, snritems);
+ sitems = itemset;
+ snritems = nitemset;
if (!snritems) {
xml_puts (out, level, "");
@@ -108,6 +76,7 @@ print_core (FILE *out, int level, state *s)
for (i = 0; i < snritems; i++)
{
+ bool printed = false;
item_number *sp;
item_number *sp1;
rule_number r;
@@ -118,30 +87,33 @@ print_core (FILE *out, int level, state *s)
sp++;
r = item_number_as_rule_number (*sp);
-
- xml_printf (out, level + 1, "",
- rules[r].number);
-
- rule_lhs_print_xml (&rules[r], out, level + 2);
-
- xml_puts (out, level + 2, "");
- for (sp = rules[r].rhs; sp < sp1; sp++)
- xml_printf (out, level + 3, "%s",
- symbol_class_get_string (symbols[*sp]),
- xml_escape (symbols[*sp]->tag));
- xml_puts (out, level + 3, "");
- for (/* Nothing */; *sp >= 0; ++sp)
- xml_printf (out, level + 3, "%s",
- symbol_class_get_string (symbols[*sp]),
- xml_escape (symbols[*sp]->tag));
-
- xml_puts (out, level + 2, "");
+ sp = rules[r].rhs;
/* Display the lookahead tokens? */
- if (report_flag & report_lookahead_tokens)
- state_rule_lookahead_tokens_print_xml (s, &rules[r], out, level + 2);
+ if (item_number_is_rule_number (*sp1))
+ {
+ reductions *reds = s->reductions;
+ int red = state_reduction_find (s, &rules[r]);
+ /* Print item with lookaheads if there are. */
+ if (reds->lookahead_tokens && red != -1)
+ {
+ xml_printf (out, level + 1,
+ "- ",
+ rules[r].number, sp1 - sp);
+ state_rule_lookahead_tokens_print_xml (s, &rules[r],
+ out, level + 2);
+ xml_puts (out, level + 1, "
");
+ printed = true;
+ }
+ }
- xml_puts (out, level + 1, "");
+ if (!printed)
+ {
+ xml_printf (out, level + 1,
+ "- ",
+ rules[r].number,
+ sp1 - sp);
+ }
}
xml_puts (out, level, "");
}
@@ -389,7 +361,7 @@ print_state (FILE *out, int level, state *s)
xml_printf (out, level, "", s->number);
print_core (out, level + 1, s);
print_actions (out, level + 1, s);
- if ((report_flag & report_solved_conflicts) && s->solved_conflicts_xml)
+ if (s->solved_conflicts_xml)
{
xml_puts (out, level + 1, "");
fputs (s->solved_conflicts_xml, out);
@@ -420,88 +392,51 @@ print_grammar (FILE *out, int level)
if (token_translations[i] != undeftoken->number)
{
char const *tag = symbols[token_translations[i]]->tag;
- rule_number r;
- item_number *rhsp;
-
- xml_printf (out, level + 2,
- "",
- i, xml_escape (tag));
-
- for (r = 0; r < nrules; r++)
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == token_translations[i])
- {
- xml_printf (out, level + 3, "%d", r);
- break;
- }
- xml_puts (out, level + 2, "");
+ int precedence = symbols[token_translations[i]]->prec;
+ assoc associativity = symbols[token_translations[i]]->assoc;
+ xml_indent (out, level + 2);
+ fprintf (out,
+ "\n", out);
}
xml_puts (out, level + 1, "");
/* Nonterminals */
xml_puts (out, level + 1, "");
- for (i = ntokens; i < nsyms; i++)
+ for (i = ntokens; i < nsyms + nuseless_nonterminals; i++)
{
- int left_count = 0, right_count = 0;
- rule_number r;
char const *tag = symbols[i]->tag;
-
- for (r = 0; r < nrules; r++)
- {
- item_number *rhsp;
- if (rules[r].lhs->number == i)
- left_count++;
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == i)
- {
- right_count++;
- break;
- }
- }
-
xml_printf (out, level + 2,
- "",
- i, xml_escape (tag));
-
- if (left_count > 0)
- {
- xml_puts (out, level + 3, "");
- for (r = 0; r < nrules; r++)
- {
- if (rules[r].lhs->number == i)
- xml_printf (out, level + 4, "%d", r);
- }
- xml_puts (out, level + 3, "");
- }
-
- if (right_count > 0)
- {
- xml_puts (out, level + 3, "");
- for (r = 0; r < nrules; r++)
- {
- item_number *rhsp;
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == i)
- {
- xml_printf (out, level + 4, "%d", r);
- break;
- }
- }
- xml_puts (out, level + 3, "");
- }
-
- xml_puts (out, level + 2, "");
+ "",
+ i, xml_escape (tag),
+ reduce_nonterminal_useless_in_grammar (i)
+ ? "useless-in-grammar" : "useful");
}
xml_puts (out, level + 1, "");
xml_puts (out, level, "");
}
void
-xml_puts (FILE *out, int level, char const *s)
+xml_indent (FILE *out, int level)
{
int i;
for (i = 0; i < level; i++)
fputs (" ", out);
+}
+
+void
+xml_puts (FILE *out, int level, char const *s)
+{
+ xml_indent (out, level);
fputs (s, out);
fputc ('\n', out);
}
@@ -509,11 +444,9 @@ xml_puts (FILE *out, int level, char const *s)
void
xml_printf (FILE *out, int level, char const *fmt, ...)
{
- int i;
va_list arglist;
- for (i = 0; i < level; i++)
- fputs (" ", out);
+ xml_indent (out, level);
va_start (arglist, fmt);
vfprintf (out, fmt, arglist);
@@ -578,20 +511,10 @@ print_xml (void)
xml_printf (out, level + 1, "%s",
xml_escape (grammar_file));
- /* print reductions */
- reduce_xml (out, level + 1);
-
- /* print rules never reduced */
- print_rules_never_reduced (out, level + 1);
-
- /* print conflicts */
- conflicts_output_xml (out, level + 1);
-
/* print grammar */
print_grammar (out, level + 1);
- if (report_flag & report_itemsets)
- new_closure (nritems);
+ new_closure (nritems);
no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
/* print automaton */
@@ -602,8 +525,7 @@ print_xml (void)
xml_puts (out, level + 1, "");
bitset_free (no_reduce_set);
- if (report_flag & report_itemsets)
- free_closure ();
+ free_closure ();
xml_puts (out, 0, "");