[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03-symlist-length.patch
From: |
Akim Demaille |
Subject: |
03-symlist-length.patch |
Date: |
Mon, 17 Jun 2002 08:55:57 +0200 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* 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.
Index: src/parse-gram.y
--- src/parse-gram.y Sun, 16 Jun 2002 18:00:27 +0200 akim
+++ src/parse-gram.y Sun, 16 Jun 2002 19:10:36 +0200 akim
@@ -218,7 +218,7 @@ 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 @@ 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: src/scan-gram.l
--- src/scan-gram.l Sun, 16 Jun 2002 18:00:27 +0200 akim
+++ src/scan-gram.l Sun, 16 Jun 2002 19:09:52 +0200 akim
@@ -524,15 +524,6 @@
{
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 @@
}
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 @@
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 @@
}
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: src/output.c
--- src/output.c Sat, 15 Jun 2002 18:15:43 +0200 akim
+++ src/output.c Sun, 16 Jun 2002 19:05:56 +0200 akim
@@ -537,6 +537,8 @@
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 @@
fprintf (out, " %s\n break;\n\n",
rules[rule].action);
}
+ fputs ("]])\n\n", out);
}
@@ -562,6 +565,8 @@
{
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 @@
first = 0;
}
+ fputs ("])\n\n", out);
}
@@ -1011,13 +1017,8 @@
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: src/symtab.c
--- src/symtab.c Sun, 16 Jun 2002 17:39:25 +0200 akim
+++ src/symtab.c Sun, 16 Jun 2002 19:05:46 +0200 akim
@@ -108,7 +108,7 @@
{
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 @@
{
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 @@
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 @@
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 @@
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 @@
{
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 @@
{
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 @@
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 @@
/* 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 @@
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));
}
Index: src/symlist.h
--- src/symlist.h Sun, 16 Jun 2002 18:00:27 +0200 akim
+++ src/symlist.h Sun, 16 Jun 2002 19:05:32 +0200 akim
@@ -51,6 +51,8 @@
/* 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: src/symlist.c
--- src/symlist.c Sun, 16 Jun 2002 18:00:27 +0200 akim
+++ src/symlist.c Sun, 16 Jun 2002 19:05:32 +0200 akim
@@ -64,6 +64,20 @@
}
+/*--------------------.
+| 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. |
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 03-symlist-length.patch,
Akim Demaille <=