[PATCH 02/10] style: factor complex expressions

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
* src/print-xml.c, src/print.c: Introduce a variable pointing to the
current symbol.
---
 src/print-xml.c | 10 ++++++----
 src/print.c     | 15 ++++++++-------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/print-xml.c b/src/print-xml.c
index 8bb43bb3..de4bf141 100644
--- a/src/print-xml.c
+++ b/src/print-xml.c
@@ -382,9 +382,10 @@ print_grammar (FILE *out, int level)
   for (int i = 0; i < max_code + 1; i++)
     if (token_translations[i] != undeftoken->content->number)
       {
-        char const *tag = symbols[token_translations[i]]->tag;
-        int precedence = symbols[token_translations[i]]->content->prec;
-        assoc associativity = symbols[token_translations[i]]->content->assoc;
+        symbol const *sym = symbols[token_translations[i]];
+        char const *tag = sym->tag;
+        int precedence = sym->content->prec;
+        assoc associativity = sym->content->assoc;
         xml_indent (out, level + 2);
         fprintf (out,
                  "<terminal symbol-number=\"%d\" token-number=\"%d\""
@@ -404,7 +405,8 @@ print_grammar (FILE *out, int level)
   xml_puts (out, level + 1, "<nonterminals>");
   for (symbol_number i = ntokens; i < nsyms + nuseless_nonterminals; i++)
     {
-      char const *tag = symbols[i]->tag;
+      symbol const *sym = symbols[i];
+      char const *tag = sym->tag;
       xml_printf (out, level + 2,
                   "<nonterminal symbol-number=\"%d\" name=\"%s\""
                   " usefulness=\"%s\"/>",
diff --git a/src/print.c b/src/print.c
index 556bbc11..257eef25 100644
--- a/src/print.c
+++ b/src/print.c
@@ -377,11 +377,11 @@ print_terminal_symbols (FILE *out)
   for (int i = 0; i < max_code + 1; ++i)
     if (token_translations[i] != undeftoken->content->number)
       {
-        const char *tag = symbols[token_translations[i]]->tag;
+        const symbol *sym = symbols[token_translations[i]];
+        const char *tag = sym->tag;
         fprintf (out, "%4s%s", "", tag);
-        if (symbols[token_translations[i]]->content->type_name)
-          fprintf (out, " <%s>",
-                   symbols[token_translations[i]]->content->type_name);
+        if (sym->content->type_name)
+          fprintf (out, " <%s>", sym->content->type_name);
         fprintf (out, " (%d)", i);
 
         for (rule_number r = 0; r < nrules; r++)
@@ -403,7 +403,8 @@ print_nonterminal_symbols (FILE *out)
   fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear"));
   for (symbol_number i = ntokens; i < nsyms; i++)
     {
-      const char *tag = symbols[i]->tag;
+      const symbol *sym = symbols[i];
+      const char *tag = sym->tag;
       bool on_left = false;
       bool on_right = false;
 
@@ -418,9 +419,9 @@ print_nonterminal_symbols (FILE *out)
 
       int column = 4 + mbswidth (tag, 0);
       fprintf (out, "%4s%s", "", tag);
-      if (symbols[i]->content->type_name)
+      if (sym->content->type_name)
         column += fprintf (out, " <%s>",
-                           symbols[i]->content->type_name);
+                           sym->content->type_name);
       fprintf (out, " (%d)\n", i);
 
       if (on_left)
-- 
2.27.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.