bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: report: clean up its format


From: Akim Demaille
Subject: Re: report: clean up its format
Date: Tue, 5 Feb 2019 07:49:17 +0100


> Le 5 févr. 2019 à 07:38, Akim Demaille <address@hidden> a écrit :
> 
> I'd appreciate comments about this change.
> 
> I'm very happy to get rid of this piece of code, with several calls to 
> sprintf.  I don't think it make the output less readable.  Actually, I do 
> think it is more readable.
> 
> commit 245143ceb03865bbcc2e9c52225198bec0913499
> Author: Akim Demaille <address@hidden>
> Date:   Sun Feb 3 14:26:37 2019 +0100
> 
>    report: clean up its format

Then this:

commit f91cabfdf01051c545d58be73550f248eb9fca06
Author: Akim Demaille <address@hidden>
Date:   Tue Feb 5 07:46:38 2019 +0100

    report: stop counting uselessly
    
    * src/print.c (print_nonterminal_symbols): Replace left_count and
    right_count with on_left and on_right.

diff --git a/src/print.c b/src/print.c
index ab63a3eb..97dd18f8 100644
--- a/src/print.c
+++ b/src/print.c
@@ -392,18 +392,16 @@ print_nonterminal_symbols (FILE *out)
   for (symbol_number i = ntokens; i < nsyms; i++)
     {
       const char *tag = symbols[i]->tag;
-      int left_count = 0, right_count = 0;
+      bool on_left = false;
+      bool on_right = false;
 
       for (rule_number r = 0; r < nrules; r++)
         {
-          if (rules[r].lhs->number == i)
-            left_count++;
-          for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; rhsp++)
-            if (item_number_as_symbol_number (*rhsp) == i)
-              {
-                right_count++;
-                break;
-              }
+          on_left |= rules[r].lhs->number == i;
+          for (item_number *rhsp = rules[r].rhs; !on_right && 0 <= *rhsp; 
++rhsp)
+            on_right |= item_number_as_symbol_number (*rhsp) == i;
+          if (on_left && on_right)
+            break;
         }
 
       int column = 4 + strlen (tag);
@@ -413,7 +411,7 @@ print_nonterminal_symbols (FILE *out)
                            symbols[i]->content->type_name);
       fprintf (out, " (%d)\n", i);
 
-      if (left_count > 0)
+      if (on_left)
         {
           fprintf (out, "%8s%s", "", _("on left:"));
           for (rule_number r = 0; r < nrules; r++)
@@ -422,11 +420,11 @@ print_nonterminal_symbols (FILE *out)
           fputc ('\n', out);
         }
 
-      if (right_count > 0)
+      if (on_right)
         {
           fprintf (out, "%8s%s", "", _("on right:"));
           for (rule_number r = 0; r < nrules; r++)
-            for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; rhsp++)
+            for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp)
               if (item_number_as_symbol_number (*rhsp) == i)
                 {
                   fprintf (out, " %d", r);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]