X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/ef1b427325c10362bd5880c22de310ed96dbc235..8e6f2266302c2035ef2b0ed7375cd8810b160f13:/src/print-xml.c

diff --git a/src/print-xml.c b/src/print-xml.c
index 33ececa7..1dc0268e 100644
--- a/src/print-xml.c
+++ b/src/print-xml.c
@@ -1,6 +1,6 @@
 /* Print an xml on generated parser, for Bison,
 
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -48,7 +48,7 @@ struct escape_buf
   char *ptr;
   size_t size;
 };
-static struct escape_buf escape_bufs[2];
+static struct escape_buf escape_bufs[3];
 
 
 /*--------------------------------.
@@ -244,17 +244,18 @@ print_reductions (FILE *out, int level, state *s)
 {
   transitions *trans = s->transitions;
   reductions *reds = s->reductions;
-  rule *default_rule = NULL;
+  rule *default_reduction = NULL;
   int report = false;
   int i, j;
 
-  if (reds->num == 0) {
-    xml_puts (out, level, "<reductions/>");
-    return;
-  }
+  if (reds->num == 0)
+    {
+      xml_puts (out, level, "<reductions/>");
+      return;
+    }
 
   if (yydefact[s->number] != 0)
-    default_rule = &rules[yydefact[s->number] - 1];
+    default_reduction = &rules[yydefact[s->number] - 1];
 
   bitset_zero (no_reduce_set);
   FOR_EACH_SHIFT (trans, i)
@@ -263,7 +264,7 @@ print_reductions (FILE *out, int level, state *s)
     if (s->errs->symbols[i])
       bitset_set (no_reduce_set, s->errs->symbols[i]->number);
 
-  if (default_rule)
+  if (default_reduction)
     report = true;
 
   if (reds->lookahead_tokens)
@@ -276,7 +277,7 @@ print_reductions (FILE *out, int level, state *s)
 	    {
 	      if (! count)
 		{
-		  if (reds->rules[j] != default_rule)
+		  if (reds->rules[j] != default_reduction)
 		    report = true;
 		  count = true;
 		}
@@ -307,7 +308,7 @@ print_reductions (FILE *out, int level, state *s)
 	    {
 	      if (! count)
 		{
-		  if (reds->rules[j] != default_rule)
+		  if (reds->rules[j] != default_reduction)
 		    print_reduction (out, level + 1, symbols[i]->tag,
 				     reds->rules[j], true);
 		  else
@@ -318,7 +319,7 @@ print_reductions (FILE *out, int level, state *s)
 		{
 		  if (defaulted)
 		    print_reduction (out, level + 1, symbols[i]->tag,
-				     default_rule, true);
+				     default_reduction, true);
 		  defaulted = false;
 		  print_reduction (out, level + 1, symbols[i]->tag,
 				   reds->rules[j], false);
@@ -326,9 +327,9 @@ print_reductions (FILE *out, int level, state *s)
 	    }
       }
 
-  if (default_rule)
+  if (default_reduction)
     print_reduction (out, level + 1,
-		     "$default", default_rule, true);
+		     "$default", default_reduction, true);
 
   xml_puts (out, level, "</reductions>");
 }
@@ -392,24 +393,20 @@ 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,
-		    "<terminal symbol-number=\"%d\" token-number=\"%d\""
-                    " name=\"%s\" usefulness=\"%s\">",
-		    token_translations[i], i, xml_escape (tag),
-                    reduce_token_unused_in_grammar (token_translations[i])
-                      ? "unused-in-grammar" : "useful");
-
-	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, "<rule>%d</rule>", r);
-		break;
-	      }
-	xml_puts (out, level + 2, "</terminal>");
+        int precedence = symbols[token_translations[i]]->prec;
+        assoc associativity = symbols[token_translations[i]]->assoc;
+        xml_indent (out, level + 2);
+        fprintf (out,
+                 "<terminal symbol-number=\"%d\" token-number=\"%d\""
+                 " name=\"%s\" usefulness=\"%s\"",
+                 token_translations[i], i, xml_escape (tag),
+                 reduce_token_unused_in_grammar (token_translations[i])
+                   ? "unused-in-grammar" : "useful");
+        if (precedence)
+          fprintf (out, " prec=\"%d\"", precedence);
+        if (associativity != undef_assoc)
+          fprintf (out, " assoc=\"%s\"", assoc_to_string (associativity) + 1);
+        fputs ("/>\n", out);
       }
   xml_puts (out, level + 1, "</terminals>");
 
@@ -417,69 +414,30 @@ print_grammar (FILE *out, int level)
   xml_puts (out, level + 1, "<nonterminals>");
   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,
 		  "<nonterminal symbol-number=\"%d\" name=\"%s\""
-                  " usefulness=\"%s\">",
+                  " usefulness=\"%s\"/>",
 		  i, xml_escape (tag),
                   reduce_nonterminal_useless_in_grammar (i)
                     ? "useless-in-grammar" : "useful");
-
-      if (left_count > 0)
-	{
-	  xml_puts (out, level + 3, "<left>");
-	  for (r = 0; r < nrules; r++)
-	    {
-	      if (rules[r].lhs->number == i)
-		xml_printf (out, level + 4, "<rule>%d</rule>", r);
-	    }
-	  xml_puts (out, level + 3, "</left>");
-	}
-
-      if (right_count > 0)
-	{
-	  xml_puts (out, level + 3, "<right>");
-	  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, "<rule>%d</rule>", r);
-		    break;
-		  }
-	    }
-	  xml_puts (out, level + 3, "</right>");
-	}
-
-      xml_puts (out, level + 2, "</nonterminal>");
     }
   xml_puts (out, level + 1, "</nonterminals>");
   xml_puts (out, level, "</grammar>");
 }
 
 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);
 }
@@ -487,11 +445,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);
@@ -549,8 +505,12 @@ print_xml (void)
   FILE *out = xfopen (spec_xml_file, "w");
 
   fputs ("<?xml version=\"1.0\"?>\n\n", out);
-  xml_printf (out, level, "<bison-xml-report version=\"%s\">",
-	      xml_escape (VERSION));
+  xml_printf (out, level,
+              "<bison-xml-report version=\"%s\" bug-report=\"%s\""
+              " url=\"%s\">",
+              xml_escape_n (0, VERSION),
+              xml_escape_n (1, PACKAGE_BUGREPORT),
+              xml_escape_n (2, PACKAGE_URL));
 
   fputc ('\n', out);
   xml_printf (out, level + 1, "<filename>%s</filename>",