X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/575619af5e1f61a5f78fb3910bee424ead5fe5a6..559b30881dd694f39aaa809797e463de73ed4e34:/src/print-xml.c?ds=inline
diff --git a/src/print-xml.c b/src/print-xml.c
index 1dc0268e..7bdc36d5 100644
--- a/src/print-xml.c
+++ b/src/print-xml.c
@@ -1,23 +1,21 @@
 /* Print an xml on generated parser, for Bison,
 
-   Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009-2015 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
-   Bison is free software; you can redistribute it and/or modify
+   This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-   Bison is distributed in the hope that it will be useful,
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with Bison; see the file COPYING.  If not, write to
-   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see .  */
 
 #include 
 #include "system.h"
@@ -25,7 +23,6 @@
 #include 
 
 #include 
-#include 
 
 #include "LR0.h"
 #include "closure.h"
@@ -48,7 +45,8 @@ struct escape_buf
   char *ptr;
   size_t size;
 };
-static struct escape_buf escape_bufs[3];
+enum { num_escape_bufs = 3 };
+static struct escape_buf escape_bufs[num_escape_bufs];
 
 
 /*--------------------------------.
@@ -67,53 +65,50 @@ print_core (FILE *out, int level, state *s)
   sitems = itemset;
   snritems = nitemset;
 
-  if (!snritems) {
-    xml_puts (out, level, "");
-    return;
-  }
+  if (!snritems)
+    {
+      xml_puts (out, level, "");
+      return;
+    }
 
   xml_puts (out, level, "");
 
   for (i = 0; i < snritems; i++)
     {
       bool printed = false;
-      item_number *sp;
-      item_number *sp1;
-      rule_number r;
-
-      sp1 = sp = ritem + sitems[i];
+      item_number *sp1 = ritem + sitems[i];
+      item_number *sp = sp1;
+      rule *r;
 
-      while (*sp >= 0)
-	sp++;
+      while (0 <= *sp)
+        sp++;
 
-      r = item_number_as_rule_number (*sp);
-      sp = rules[r].rhs;
+      r = &rules[item_number_as_rule_number (*sp)];
+      sp = r->rhs;
 
       /* Display the lookahead tokens?  */
       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;
-	    }
-	}
+        {
+          reductions *reds = s->reductions;
+          int red = state_reduction_find (s, r);
+          /* Print item with lookaheads if there are. */
+          if (reds->lookahead_tokens && red != -1)
+            {
+              xml_printf (out, level + 1,
+                          "
- ",
+                          r->number, sp1 - sp);
+              state_rule_lookahead_tokens_print_xml (s, r,
+                                                     out, level + 2);
+              xml_puts (out, level + 1, "");
+              printed = true;
+            }
+        }
 
       if (!printed)
-	{
-	  xml_printf (out, level + 1,
-		      "
- ",
-		      rules[r].number,
-		      sp1 - sp);
-	}
+        xml_printf (out, level + 1,
+                    "- ",
+                    r->number,
+                    sp1 - sp);
     }
   xml_puts (out, level, "
");
 }
@@ -134,42 +129,43 @@ print_transitions (state *s, FILE *out, int level)
   for (i = 0; i < trans->num; i++)
     if (!TRANSITION_IS_DISABLED (trans, i))
       {
-	n++;
+        n++;
       }
 
   /* Nothing to report. */
-  if (!n) {
-    xml_puts (out, level, "");
-    return;
-  }
+  if (!n)
+    {
+      xml_puts (out, level, "");
+      return;
+    }
 
   /* Report lookahead tokens and shifts.  */
   xml_puts (out, level, "");
 
   for (i = 0; i < trans->num; i++)
     if (!TRANSITION_IS_DISABLED (trans, i)
-	&& TRANSITION_IS_SHIFT (trans, i))
+        && TRANSITION_IS_SHIFT (trans, i))
       {
-	symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
-	char const *tag = sym->tag;
-	state *s1 = trans->states[i];
+        symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
+        char const *tag = sym->tag;
+        state *s1 = trans->states[i];
 
-	xml_printf (out, level + 1,
-		    "",
-		    xml_escape (tag), s1->number);
+        xml_printf (out, level + 1,
+                    "",
+                    xml_escape (tag), s1->number);
       }
 
   for (i = 0; i < trans->num; i++)
     if (!TRANSITION_IS_DISABLED (trans, i)
-	&& !TRANSITION_IS_SHIFT (trans, i))
+        && !TRANSITION_IS_SHIFT (trans, i))
       {
-	symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
-	char const *tag = sym->tag;
-	state *s1 = trans->states[i];
+        symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
+        char const *tag = sym->tag;
+        state *s1 = trans->states[i];
 
-	xml_printf (out, level + 1,
-		    "",
-		    xml_escape (tag), s1->number);
+        xml_printf (out, level + 1,
+                    "",
+                    xml_escape (tag), s1->number);
       }
 
   xml_puts (out, level, "");
@@ -192,46 +188,47 @@ print_errs (FILE *out, int level, state *s)
       count = true;
 
   /* Nothing to report. */
-  if (!count) {
-    xml_puts (out, level, "");
-    return;
-  }
+  if (!count)
+    {
+      xml_puts (out, level, "");
+      return;
+    }
 
   /* Report lookahead tokens and errors.  */
   xml_puts (out, level, "");
   for (i = 0; i < errp->num; ++i)
     if (errp->symbols[i])
       {
-	char const *tag = errp->symbols[i]->tag;
-	xml_printf (out, level + 1,
-		    "nonassociative",
-		    xml_escape (tag));
+        char const *tag = errp->symbols[i]->tag;
+        xml_printf (out, level + 1,
+                    "nonassociative",
+                    xml_escape (tag));
       }
   xml_puts (out, level, "");
 }
 
 
 /*-------------------------------------------------------------------------.
-| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be `default').  |
+| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default').  |
 | If not ENABLED, the rule is masked by a shift or a reduce (S/R and       |
 | R/R conflicts).                                                          |
 `-------------------------------------------------------------------------*/
 
 static void
 print_reduction (FILE *out, int level, char const *lookahead_token,
-		 rule *r, bool enabled)
+                 rule *r, bool enabled)
 {
   if (r->number)
     xml_printf (out, level,
-		"",
-		xml_escape (lookahead_token),
-		r->number,
-		enabled ? "true" : "false");
+                "",
+                xml_escape (lookahead_token),
+                r->number,
+                enabled ? "true" : "false");
   else
     xml_printf (out, level,
-		"",
-		xml_escape (lookahead_token),
-		enabled ? "true" : "false");
+                "",
+                xml_escape (lookahead_token),
+                enabled ? "true" : "false");
 }
 
 
@@ -270,29 +267,30 @@ print_reductions (FILE *out, int level, state *s)
   if (reds->lookahead_tokens)
     for (i = 0; i < ntokens; i++)
       {
-	bool count = bitset_test (no_reduce_set, i);
-
-	for (j = 0; j < reds->num; ++j)
-	  if (bitset_test (reds->lookahead_tokens[j], i))
-	    {
-	      if (! count)
-		{
-		  if (reds->rules[j] != default_reduction)
-		    report = true;
-		  count = true;
-		}
-	      else
-		{
-		  report = true;
-		}
-	    }
+        bool count = bitset_test (no_reduce_set, i);
+
+        for (j = 0; j < reds->num; ++j)
+          if (bitset_test (reds->lookahead_tokens[j], i))
+            {
+              if (! count)
+                {
+                  if (reds->rules[j] != default_reduction)
+                    report = true;
+                  count = true;
+                }
+              else
+                {
+                  report = true;
+                }
+            }
       }
 
   /* Nothing to report. */
-  if (!report) {
-    xml_puts (out, level, "");
-    return;
-  }
+  if (!report)
+    {
+      xml_puts (out, level, "");
+      return;
+    }
 
   xml_puts (out, level, "");
 
@@ -300,36 +298,36 @@ print_reductions (FILE *out, int level, state *s)
   if (reds->lookahead_tokens)
     for (i = 0; i < ntokens; i++)
       {
-	bool defaulted = false;
-	bool count = bitset_test (no_reduce_set, i);
-
-	for (j = 0; j < reds->num; ++j)
-	  if (bitset_test (reds->lookahead_tokens[j], i))
-	    {
-	      if (! count)
-		{
-		  if (reds->rules[j] != default_reduction)
-		    print_reduction (out, level + 1, symbols[i]->tag,
-				     reds->rules[j], true);
-		  else
-		    defaulted = true;
-		  count = true;
-		}
-	      else
-		{
-		  if (defaulted)
-		    print_reduction (out, level + 1, symbols[i]->tag,
-				     default_reduction, true);
-		  defaulted = false;
-		  print_reduction (out, level + 1, symbols[i]->tag,
-				   reds->rules[j], false);
-		}
-	    }
+        bool defaulted = false;
+        bool count = bitset_test (no_reduce_set, i);
+
+        for (j = 0; j < reds->num; ++j)
+          if (bitset_test (reds->lookahead_tokens[j], i))
+            {
+              if (! count)
+                {
+                  if (reds->rules[j] != default_reduction)
+                    print_reduction (out, level + 1, symbols[i]->tag,
+                                     reds->rules[j], true);
+                  else
+                    defaulted = true;
+                  count = true;
+                }
+              else
+                {
+                  if (defaulted)
+                    print_reduction (out, level + 1, symbols[i]->tag,
+                                     default_reduction, true);
+                  defaulted = false;
+                  print_reduction (out, level + 1, symbols[i]->tag,
+                                   reds->rules[j], false);
+                }
+            }
       }
 
   if (default_reduction)
     print_reduction (out, level + 1,
-		     "$default", default_reduction, true);
+                     "$default", default_reduction, true);
 
   xml_puts (out, level, "");
 }
@@ -392,7 +390,7 @@ print_grammar (FILE *out, int level)
   for (i = 0; i < max_user_token_number + 1; i++)
     if (token_translations[i] != undeftoken->number)
       {
-	char const *tag = symbols[token_translations[i]]->tag;
+        char const *tag = symbols[token_translations[i]]->tag;
         int precedence = symbols[token_translations[i]]->prec;
         assoc associativity = symbols[token_translations[i]]->assoc;
         xml_indent (out, level + 2);
@@ -416,9 +414,9 @@ print_grammar (FILE *out, int level)
     {
       char const *tag = symbols[i]->tag;
       xml_printf (out, level + 2,
-		  "",
-		  i, xml_escape (tag),
+                  i, xml_escape (tag),
                   reduce_nonterminal_useless_in_grammar (i)
                     ? "useless-in-grammar" : "useful");
     }
@@ -499,7 +497,6 @@ xml_escape (char const *str)
 void
 print_xml (void)
 {
-  state_number i;
   int level = 0;
 
   FILE *out = xfopen (spec_xml_file, "w");
@@ -514,7 +511,7 @@ print_xml (void)
 
   fputc ('\n', out);
   xml_printf (out, level + 1, "%s",
-	      xml_escape (grammar_file));
+              xml_escape (grammar_file));
 
   /* print grammar */
   print_grammar (out, level + 1);
@@ -525,8 +522,11 @@ print_xml (void)
   /* print automaton */
   fputc ('\n', out);
   xml_puts (out, level + 1, "");
-  for (i = 0; i < nstates; i++)
-    print_state (out, level + 2, states[i]);
+  {
+    state_number i;
+    for (i = 0; i < nstates; i++)
+      print_state (out, level + 2, states[i]);
+  }
   xml_puts (out, level + 1, "");
 
   bitset_free (no_reduce_set);
@@ -534,8 +534,11 @@ print_xml (void)
 
   xml_puts (out, 0, "");
 
-  free (escape_bufs[0].ptr);
-  free (escape_bufs[1].ptr);
+  {
+    int i;
+    for (i = 0; i < num_escape_bufs; ++i)
+      free (escape_bufs[i].ptr);
+  }
 
   xfclose (out);
 }