* src/symlist.h, src/symlist.c (symbol_list_length): New.
authorAkim Demaille <akim@epita.fr>
Mon, 17 Jun 2002 07:05:12 +0000 (07:05 +0000)
committerAkim Demaille <akim@epita.fr>
Mon, 17 Jun 2002 07:05:12 +0000 (07:05 +0000)
* src/scan-gram.l (handle_dollar, handle_at): Compute the
rule_length only when needed.
* src/output.c (actions_output, token_definitions_output): Output
the full M4 block.
* src/symtab.c: Don't access directly to the symbol tag, use
symbol_tag_get.
* src/parse-gram.y: Use symbol_list_free.

ChangeLog
src/output.c
src/parse-gram.c
src/parse-gram.y
src/scan-gram.c
src/scan-gram.l
src/symlist.c
src/symlist.h
src/symtab.c

index b93266f..3d181d2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2002-06-17  Akim Demaille  <akim@epita.fr>
 
+       * src/symlist.h, src/symlist.c (symbol_list_length): New.
+       * src/scan-gram.l (handle_dollar, handle_at): Compute the
+       rule_length only when needed.
+       * src/output.c (actions_output, token_definitions_output): Output
+       the full M4 block.
+       * src/symtab.c: Don't access directly to the symbol tag, use
+       symbol_tag_get.
+       * src/parse-gram.y: Use symbol_list_free.
+
+       
+2002-06-17  Akim Demaille  <akim@epita.fr>
+
        * src/reader.h, src/reader.c (symbol_list, symbol_list_new)
        (symbol_list_prepend, get_type_name): Move to...
        * src/symlist.h, src/symlist.c (symbol_list_t, symbol_list_new)
index 350d7ed..237e48a 100644 (file)
@@ -537,6 +537,8 @@ void
 actions_output (FILE *out)
 {
   int rule;
+
+  fputs ("m4_define([b4_actions], \n[[", out);
   for (rule = 1; rule < nrules + 1; ++rule)
     if (rules[rule].action)
       {
@@ -550,6 +552,7 @@ actions_output (FILE *out)
        fprintf (out, "    %s\n    break;\n\n",
                 rules[rule].action);
       }
+  fputs ("]])\n\n", out);
 }
 
 
@@ -562,6 +565,8 @@ token_definitions_output (FILE *out)
 {
   int i;
   int first = 1;
+
+  fputs ("m4_define([b4_tokens], \n[", out);
   for (i = 0; i < ntokens; ++i)
     {
       symbol_t *symbol = symbols[i];
@@ -597,6 +602,7 @@ token_definitions_output (FILE *out)
 
       first = 0;
     }
+  fputs ("])\n\n", out);
 }
 
 
@@ -1011,13 +1017,8 @@ output_skeleton (void)
   fputs ("m4_changecom()\n", out);
   fputs ("m4_init()\n", out);
 
-  fputs ("m4_define([b4_actions], \n[[", out);
   actions_output (out);
-  fputs ("]])\n\n", out);
-
-  fputs ("m4_define([b4_tokens], \n[", out);
   token_definitions_output (out);
-  fputs ("])\n\n", out);
 
   muscles_m4_output (out);
 
index 6a08310..001187a 100644 (file)
@@ -1319,7 +1319,7 @@ yyreduce:
       symbol_list_t *list;
       for (list = yyvsp[0].list; list; list = list->next)
        symbol_type_set (list->sym, list->location, yyvsp[-1].string);
-      LIST_FREE (symbol_list_t, yyvsp[0].list);
+      symbol_list_free (yyvsp[0].list);
     }
     break;
 
@@ -1333,7 +1333,7 @@ yyreduce:
          symbol_type_set (list->sym, list->location, current_type);
          symbol_precedence_set (list->sym, list->location, current_prec, yyvsp[-2].assoc);
        }
-      LIST_FREE (symbol_list_t, yyvsp[0].list);
+      symbol_list_free (yyvsp[0].list);
       current_type = NULL;
     }
     break;
index 46ccb54..4eaecb3 100644 (file)
@@ -218,7 +218,7 @@ symbol_declaration:
       symbol_list_t *list;
       for (list = $3; list; list = list->next)
        symbol_type_set (list->sym, list->location, $2);
-      LIST_FREE (symbol_list_t, $3);
+      symbol_list_free ($3);
     }
 ;
 
@@ -232,7 +232,7 @@ precedence_declaration:
          symbol_type_set (list->sym, list->location, current_type);
          symbol_precedence_set (list->sym, list->location, current_prec, $1);
        }
-      LIST_FREE (symbol_list_t, $3);
+      symbol_list_free ($3);
       current_type = NULL;
     }
 ;
index 6b7f4dd..ca22f0d 100644 (file)
@@ -2705,15 +2705,6 @@ handle_dollar (char *cp, location_t location)
 {
   const char *type_name = NULL;
 
-  /* RULE_LENGTH is the number of values in the current rule so far,
-     which says where to find `$0' with respect to the top of the
-     stack.  It is not the same as the rule->length in the case of mid
-     rule actions.  */
-  int rule_length = 0;
-  symbol_list_t *rhs;
-  for (rhs = current_rule->next; rhs; rhs = rhs->next)
-    ++rule_length;
-
   ++cp;
 
   /* Get the type name if explicit. */
@@ -2740,6 +2731,11 @@ handle_dollar (char *cp, location_t location)
     }
   else if (isdigit (*cp) || *cp == '-')
     {
+      /* RULE_LENGTH is the number of values in the current rule so
+        far, which says where to find `$0' with respect to the top of
+        the stack.  It is not the same as the rule->length in the
+        case of mid rule actions.  */
+      int rule_length = symbol_list_length (current_rule->next);
       int n = strtol (cp, &cp, 10);
 
       if (n > rule_length)
@@ -2775,15 +2771,6 @@ handle_dollar (char *cp, location_t location)
 static void
 handle_at (char *cp)
 {
-  /* RULE_LENGTH is the number of values in the current rule so far,
-     which says where to find `$0' with respect to the top of the
-     stack.  It is not the same as the rule->length in the case of mid
-     rule actions.  */
-  int rule_length = 0;
-  symbol_list_t *rhs;
-  for (rhs = current_rule->next; rhs; rhs = rhs->next)
-    ++rule_length;
-
   locations_flag = 1;
   ++cp;
 
@@ -2793,7 +2780,13 @@ handle_at (char *cp)
     }
   else if (isdigit (*cp) || *cp == '-')
     {
+      /* RULE_LENGTH is the number of values in the current rule so
+        far, which says where to find `$0' with respect to the top of
+        the stack.  It is not the same as the rule->length in the
+        case of mid rule actions.  */
+      int rule_length = symbol_list_length (current_rule->next);
       int n = strtol (cp, &cp, 10);
+
       if (n > rule_length)
        complain (_("invalid value: %s%d"), "@", n);
       else
index 15d7543..2c80c65 100644 (file)
@@ -524,15 +524,6 @@ handle_dollar (char *cp, location_t location)
 {
   const char *type_name = NULL;
 
-  /* RULE_LENGTH is the number of values in the current rule so far,
-     which says where to find `$0' with respect to the top of the
-     stack.  It is not the same as the rule->length in the case of mid
-     rule actions.  */
-  int rule_length = 0;
-  symbol_list_t *rhs;
-  for (rhs = current_rule->next; rhs; rhs = rhs->next)
-    ++rule_length;
-
   ++cp;
 
   /* Get the type name if explicit. */
@@ -559,6 +550,11 @@ handle_dollar (char *cp, location_t location)
     }
   else if (isdigit (*cp) || *cp == '-')
     {
+      /* RULE_LENGTH is the number of values in the current rule so
+        far, which says where to find `$0' with respect to the top of
+        the stack.  It is not the same as the rule->length in the
+        case of mid rule actions.  */
+      int rule_length = symbol_list_length (current_rule->next);
       int n = strtol (cp, &cp, 10);
 
       if (n > rule_length)
@@ -594,15 +590,6 @@ handle_dollar (char *cp, location_t location)
 static void
 handle_at (char *cp)
 {
-  /* RULE_LENGTH is the number of values in the current rule so far,
-     which says where to find `$0' with respect to the top of the
-     stack.  It is not the same as the rule->length in the case of mid
-     rule actions.  */
-  int rule_length = 0;
-  symbol_list_t *rhs;
-  for (rhs = current_rule->next; rhs; rhs = rhs->next)
-    ++rule_length;
-
   locations_flag = 1;
   ++cp;
 
@@ -612,7 +599,13 @@ handle_at (char *cp)
     }
   else if (isdigit (*cp) || *cp == '-')
     {
+      /* RULE_LENGTH is the number of values in the current rule so
+        far, which says where to find `$0' with respect to the top of
+        the stack.  It is not the same as the rule->length in the
+        case of mid rule actions.  */
+      int rule_length = symbol_list_length (current_rule->next);
       int n = strtol (cp, &cp, 10);
+
       if (n > rule_length)
        complain (_("invalid value: %s%d"), "@", n);
       else
index 4ae5f01..bdb965d 100644 (file)
@@ -64,6 +64,20 @@ symbol_list_free (symbol_list_t *list)
 }
 
 
+/*--------------------.
+| Return its length.  |
+`--------------------*/
+
+unsigned int
+symbol_list_length (symbol_list_t *list)
+{
+  int res = 0;
+  for (/* Nothing. */; list; list = list->next)
+    ++res;
+  return res;
+}
+
+
 /*--------------------------------------------------------------.
 | Get the data type (alternative in the union) of the value for |
 | symbol N in rule RULE.                                        |
index b41540b..31bd2a9 100644 (file)
@@ -51,6 +51,8 @@ symbol_list_t * symbol_list_prepend PARAMS ((symbol_list_t *list,
 /* Free the LIST, but not the symbols it contains.  */
 void symbol_list_free PARAMS ((symbol_list_t *list));
 
+/* Return its length. */
+unsigned int symbol_list_length PARAMS ((symbol_list_t *list));
 
 /* Get the data type (alternative in the union) of the value for
    symbol N in rule RULE.  */
index 90f7b01..d605687 100644 (file)
@@ -108,7 +108,7 @@ symbol_type_set (symbol_t *symbol, location_t location, char *type_name)
     {
       if (symbol->type_name)
        complain_at (location,
-                    _("type redeclaration for %s"), symbol->tag);
+                    _("type redeclaration for %s"), symbol_tag_get (symbol));
       symbol->type_name = type_name;
     }
 }
@@ -127,7 +127,8 @@ symbol_precedence_set (symbol_t *symbol, location_t location,
     {
       if (symbol->prec != 0)
        complain_at (location,
-                    _("redefining precedence of %s"), symbol->tag);
+                    _("redefining precedence of %s"),
+                    symbol_tag_get (symbol));
       symbol->prec = prec;
       symbol->assoc = assoc;
     }
@@ -145,7 +146,7 @@ void
 symbol_class_set (symbol_t *symbol, symbol_class class)
 {
   if (symbol->class != unknown_sym && symbol->class != class)
-    complain (_("symbol %s redefined"), symbol->tag);
+    complain (_("symbol %s redefined"), symbol_tag_get (symbol));
 
   if (class == nterm_sym && symbol->class != nterm_sym)
     symbol->number = nvars++;
@@ -167,7 +168,8 @@ symbol_user_token_number_set (symbol_t *symbol, int user_token_number)
 
   if (symbol->user_token_number != USER_NUMBER_UNDEFINED
       && symbol->user_token_number != user_token_number)
-    complain (_("redefining user token number of %s"), symbol->tag);
+    complain (_("redefining user token number of %s"),
+             symbol_tag_get (symbol));
 
   symbol->user_token_number = user_token_number;
   /* User defined EOF token? */
@@ -212,7 +214,7 @@ symbol_check_defined (symbol_t *this)
       complain_at
        (this->location,
         _("symbol %s is used, but is not defined as a token and has no rules"),
-        this->tag);
+        symbol_tag_get (this));
       this->class = nterm_sym;
       this->number = nvars++;
     }
@@ -231,10 +233,10 @@ symbol_make_alias (symbol_t *symbol, symbol_t *symval)
 {
   if (symval->alias)
     warn (_("symbol `%s' used more than once as a literal string"),
-         symval->tag);
+         symbol_tag_get (symval));
   else if (symbol->alias)
     warn (_("symbol `%s' given more than one literal string"),
-         symbol->tag);
+         symbol_tag_get (symbol));
   else
     {
       symval->class = token_sym;
@@ -267,7 +269,7 @@ symbol_check_alias_consistence (symbol_t *this)
        {
          if (this->prec != 0 && this->alias->prec != 0)
            complain (_("conflicting precedences for %s and %s"),
-                     this->tag, this->alias->tag);
+                     symbol_tag_get (this), symbol_tag_get (this->alias));
          if (this->prec != 0)
            this->alias->prec = this->prec;
          else
@@ -282,7 +284,7 @@ symbol_check_alias_consistence (symbol_t *this)
          if (this->assoc != right_assoc
              && this->alias->assoc != right_assoc)
            complain (_("conflicting associativities for %s and %s"),
-                     this->tag, this->alias->tag);
+                     symbol_tag_get (this), symbol_tag_get (this->alias));
          if (this->assoc != 0)
            this->alias->assoc = this->assoc;
          else
@@ -350,8 +352,8 @@ symbol_translation (symbol_t *this)
       /* A token which translation has already been set? */
       if (token_translations[this->user_token_number] != undeftoken->number)
        complain (_("tokens %s and %s both assigned number %d"),
-                 symbols[token_translations[this->user_token_number]]->tag,
-                 this->tag, this->user_token_number);
+                 symbol_tag_get (symbols[token_translations[this->user_token_number]]),
+                 symbol_tag_get (this), this->user_token_number);
 
       token_translations[this->user_token_number] = this->number;
     }
@@ -529,8 +531,10 @@ symbols_pack (void)
 
   if (startsymbol->class == unknown_sym)
     fatal_at (startsymbol_location,
-             _("the start symbol %s is undefined"), startsymbol->tag);
+             _("the start symbol %s is undefined"),
+             symbol_tag_get (startsymbol));
   else if (startsymbol->class == token_sym)
     fatal_at (startsymbol_location,
-             _("the start symbol %s is a token"), startsymbol->tag);
+             _("the start symbol %s is a token"),
+             symbol_tag_get (startsymbol));
 }