[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02-symbols-list-t.patch
From: |
Akim Demaille |
Subject: |
02-symbols-list-t.patch |
Date: |
Mon, 17 Jun 2002 08:55:52 +0200 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* 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)
(symbol_list_prepend, symbol_list_n_type_name_get): here.
Adjust all callers.
(symbol_list_free): New.
* src/scan-gram.l (handle_dollar): Takes a location.
* tests/input.at (Invalid $n): Adjust.
Index: src/parse-gram.y
--- src/parse-gram.y Sun, 16 Jun 2002 17:41:33 +0200 akim
+++ src/parse-gram.y Sun, 16 Jun 2002 19:01:07 +0200 akim
@@ -34,6 +34,7 @@
#include "files.h"
#include "getargs.h"
#include "output.h"
+#include "symlist.h"
#include "gram.h"
#include "reader.h"
#include "conflicts.h"
@@ -88,7 +89,7 @@
%union
{
symbol_t *symbol;
- symbol_list *list;
+ symbol_list_t *list;
int integer;
char *string;
associativity assoc;
@@ -214,24 +215,24 @@ declaration:
}
| "%type" TYPE symbols.1
{
- symbol_list *list;
+ symbol_list_t *list;
for (list = $3; list; list = list->next)
symbol_type_set (list->sym, list->location, $2);
- LIST_FREE (symbol_list, $3);
+ LIST_FREE (symbol_list_t, $3);
}
;
precedence_declaration:
precedence_declarator type.opt symbols.1
{
- symbol_list *list;
+ symbol_list_t *list;
++current_prec;
for (list = $3; list; list = list->next)
{
symbol_type_set (list->sym, list->location, current_type);
symbol_precedence_set (list->sym, list->location, current_prec, $1);
}
- LIST_FREE (symbol_list, $3);
+ LIST_FREE (symbol_list_t, $3);
current_type = NULL;
}
;
Index: src/scan-gram.l
--- src/scan-gram.l Sat, 15 Jun 2002 14:24:28 +0200 akim
+++ src/scan-gram.l Sun, 16 Jun 2002 19:01:07 +0200 akim
@@ -80,7 +80,7 @@
static int braces_level = 0;
static int percent_percent_count = 0;
-static void handle_dollar PARAMS ((char *cp));
+static void handle_dollar PARAMS ((char *cp, location_t location));
static void handle_at PARAMS ((char *cp));
%}
@@ -441,7 +441,7 @@
"{" YY_OBS_GROW; braces_level++;
- "$"("<"[^>]+">")?(-?[0-9]+|"$") { handle_dollar (yytext); }
+ "$"("<"[^>]+">")?(-?[0-9]+|"$") { handle_dollar (yytext, *yylloc); }
"@"(-?[0-9]+|"$") { handle_at (yytext); }
address@hidden/\'\"\{\}\n\r]+ YY_OBS_GROW;
@@ -520,7 +520,7 @@
`------------------------------------------------------------------*/
static void
-handle_dollar (char *cp)
+handle_dollar (char *cp, location_t location)
{
const char *type_name = NULL;
@@ -529,7 +529,7 @@
stack. It is not the same as the rule->length in the case of mid
rule actions. */
int rule_length = 0;
- symbol_list *rhs;
+ symbol_list_t *rhs;
for (rhs = current_rule->next; rhs; rhs = rhs->next)
++rule_length;
@@ -548,10 +548,10 @@
if (*cp == '$')
{
if (!type_name)
- type_name = get_type_name (0, current_rule);
+ type_name = symbol_list_n_type_name_get (current_rule, location, 0);
if (!type_name && typed)
- complain (_("$$ of `%s' has no declared type"),
- current_rule->sym->tag);
+ complain_at (location, _("$$ of `%s' has no declared type"),
+ current_rule->sym->tag);
if (!type_name)
type_name = "";
obstack_fgrow1 (&string_obstack,
@@ -562,13 +562,14 @@
int n = strtol (cp, &cp, 10);
if (n > rule_length)
- complain (_("invalid value: %s%d"), "$", n);
+ complain_at (location, _("invalid value: %s%d"), "$", n);
else
{
if (!type_name && n > 0)
- type_name = get_type_name (n, current_rule);
+ type_name = symbol_list_n_type_name_get (current_rule, location,
+ n);
if (!type_name && typed)
- complain (_("$%d of `%s' has no declared type"),
+ complain_at (location, _("$%d of `%s' has no declared type"),
n, current_rule->sym->tag);
if (!type_name)
type_name = "";
@@ -598,7 +599,7 @@
stack. It is not the same as the rule->length in the case of mid
rule actions. */
int rule_length = 0;
- symbol_list *rhs;
+ symbol_list_t *rhs;
for (rhs = current_rule->next; rhs; rhs = rhs->next)
++rule_length;
Index: src/Makefile.am
--- src/Makefile.am Fri, 14 Jun 2002 23:00:02 +0200 akim
+++ src/Makefile.am Sun, 16 Jun 2002 19:01:07 +0200 akim
@@ -59,6 +59,7 @@
scan-gram.l \
scan-skel.l \
state.c state.h \
+ symlist.c symlist.h \
symtab.c symtab.h \
system.h \
types.h \
Index: src/reader.c
--- src/reader.c Sun, 16 Jun 2002 17:39:25 +0200 akim
+++ src/reader.c Sun, 16 Jun 2002 19:01:07 +0200 akim
@@ -26,6 +26,7 @@
#include "getargs.h"
#include "files.h"
#include "symtab.h"
+#include "symlist.h"
#include "options.h"
#include "gram.h"
#include "complain.h"
@@ -35,68 +36,12 @@
#include "muscle_tab.h"
int lineno;
-static symbol_list *grammar = NULL;
+static symbol_list_t *grammar = NULL;
static int start_flag = 0;
/* Nonzero if %union has been seen. */
int typed = 0;
-
-symbol_list *
-symbol_list_new (symbol_t *sym, location_t location)
-{
- symbol_list *res = XMALLOC (symbol_list, 1);
- res->next = NULL;
- res->sym = sym;
- res->location = location;
- res->action = NULL;
- res->ruleprec = NULL;
- return res;
-}
-
-symbol_list *
-symbol_list_prepend (symbol_list *list, symbol_t *symbol, location_t location)
-{
- symbol_list *res = symbol_list_new (symbol, location);
- res->next = list;
- return res;
-}
-
-/*--------------------------------------------------------------.
-| Get the data type (alternative in the union) of the value for |
-| symbol N in rule RULE. |
-`--------------------------------------------------------------*/
-
-char *
-get_type_name (int n, symbol_list *rule)
-{
- int i;
- symbol_list *rp;
-
- if (n < 0)
- {
- complain (_("invalid $ value"));
- return NULL;
- }
-
- rp = rule;
- i = 0;
-
- while (i < n)
- {
- rp = rp->next;
- if (rp == NULL || rp->sym == NULL)
- {
- complain (_("invalid $ value"));
- return NULL;
- }
- ++i;
- }
-
- return rp->sym->type_name;
-}
-
-
/*-----------------------.
| Set the start symbol. |
`-----------------------*/
@@ -183,7 +128,7 @@
}
/*-------------------------------------------------------------------.
-| Parse the input grammar into a one symbol_list structure. Each |
+| Parse the input grammar into a one symbol_list_t structure. Each |
| rule is represented by a sequence of symbols: the left hand side |
| followed by the contents of the right hand side, followed by a |
| null pointer instead of a symbol to terminate the rule. The next |
@@ -201,13 +146,13 @@
`-------------------------------------------------------------------*/
/* The (currently) last symbol of GRAMMAR. */
-symbol_list *grammar_end = NULL;
+symbol_list_t *grammar_end = NULL;
/* Append S to the GRAMMAR. */
void
grammar_symbol_append (symbol_t *symbol, location_t location)
{
- symbol_list *p = symbol_list_new (symbol, location);
+ symbol_list_t *p = symbol_list_new (symbol, location);
if (grammar_end)
grammar_end->next = p;
@@ -220,8 +165,8 @@
/* The rule currently being defined, and the previous rule.
CURRENT_RULE points to the first LHS of the current rule, while
PREVIOUS_RULE_END points to the *end* of the previous rule (NULL). */
-symbol_list *current_rule = NULL;
-symbol_list *previous_rule_end = NULL;
+symbol_list_t *current_rule = NULL;
+symbol_list_t *previous_rule_end = NULL;
/*----------------------------------------------.
@@ -323,7 +268,7 @@
action. Create the MIDRULE. */
location_t dummy_location = current_rule->action_location;
symbol_t *dummy = gensym (dummy_location);
- symbol_list *midrule = symbol_list_new (dummy, dummy_location);
+ symbol_list_t *midrule = symbol_list_new (dummy, dummy_location);
/* Make a new rule, whose body is empty, before the current one, so
that the action just read can belong to it. */
@@ -397,7 +342,7 @@
{
unsigned int itemno;
int ruleno;
- symbol_list *p;
+ symbol_list_t *p;
ritem = XCALLOC (item_number_t, nritems);
rules = XCALLOC (rule_t, nrules) - 1;
@@ -518,7 +463,7 @@
axiom: %start EOF. */
{
- symbol_list *p = symbol_list_new (axiom, empty_location);
+ symbol_list_t *p = symbol_list_new (axiom, empty_location);
p->location = grammar->location;
p->next = symbol_list_new (startsymbol, empty_location);
p->next->next = symbol_list_new (eoftoken, empty_location);
@@ -544,6 +489,6 @@
/* Convert the grammar into the format described in gram.h. */
packgram ();
- /* The grammar as a symbol_list is no longer needed. */
- LIST_FREE (symbol_list, grammar);
+ /* The grammar as a symbol_list_t is no longer needed. */
+ LIST_FREE (symbol_list_t, grammar);
}
Index: src/reader.h
--- src/reader.h Sun, 16 Jun 2002 17:39:25 +0200 akim
+++ src/reader.h Sun, 16 Jun 2002 19:01:07 +0200 akim
@@ -21,25 +21,7 @@
#ifndef READER_H_
# define READER_H_
-# include "location.h"
-
-typedef struct symbol_list
-{
- struct symbol_list *next;
- symbol_t *sym;
- location_t location;
-
- /* The action is attached to the LHS of a rule. */
- const char *action;
- location_t action_location;
-
- symbol_t *ruleprec;
-} symbol_list;
-
-symbol_list *symbol_list_new PARAMS ((symbol_t *sym, location_t location));
-symbol_list *symbol_list_prepend PARAMS ((symbol_list *list,
- symbol_t *sym, location_t location));
-
+# include "symlist.h"
# include "parse-gram.h"
typedef struct gram_control_s
@@ -66,7 +48,6 @@
location_t *loc, const char *msg);
int gram_parse (void *control);
-char *get_type_name PARAMS ((int n, symbol_list *rule));
extern int typed;
/* From reader.c. */
@@ -82,7 +63,7 @@
location_t l));
void grammar_current_rule_action_append PARAMS ((const char *action,
location_t l));
-extern symbol_list *current_rule;
+extern symbol_list_t *current_rule;
void reader PARAMS ((void));
#endif /* !READER_H_ */
Index: tests/input.at
--- tests/input.at Thu, 13 Jun 2002 18:50:44 +0200 akim
+++ tests/input.at Sun, 16 Jun 2002 19:01:27 +0200 akim
@@ -57,7 +57,7 @@ exp: { $$ = $1 ; };
]])
AT_CHECK([bison input.y], [1], [],
-[[input.y:2: invalid value: $1
+[[input.y:2.6-14: invalid value: $1
]])
AT_CLEANUP
Index: src/symlist.h
--- src/symlist.h Sun, 16 Jun 2002 19:02:50 +0200 akim
+++ src/symlist.h Sun, 16 Jun 2002 18:00:27 +0200 akim
@@ -0,0 +1,60 @@
+/* Lists of symbols for Bison
+ Copyright (C) 2002 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
+ 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.
+
+ Bison 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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef SYMLIST_H_
+# define SYMLIST_H_
+
+# include "symtab.h"
+# include "location.h"
+
+typedef struct symbol_list_s
+{
+ struct symbol_list_s *next;
+ symbol_t *sym;
+ location_t location;
+
+ /* The action is attached to the LHS of a rule. */
+ const char *action;
+ location_t action_location;
+
+ symbol_t *ruleprec;
+} symbol_list_t;
+
+
+/* Create a list containing SYMBOL at LOCATION. */
+symbol_list_t *symbol_list_new PARAMS ((symbol_t *sym, location_t location));
+
+
+/* Prepend SYMBOL at LOCATION to the LIST. */
+symbol_list_t * symbol_list_prepend PARAMS ((symbol_list_t *list,
+ symbol_t *symbol,
+ location_t location));
+
+
+/* Free the LIST, but not the symbols it contains. */
+void symbol_list_free PARAMS ((symbol_list_t *list));
+
+
+/* Get the data type (alternative in the union) of the value for
+ symbol N in rule RULE. */
+char *symbol_list_n_type_name_get PARAMS ((symbol_list_t *rule,
+ location_t location, int n));
+
+#endif /* !SYMLIST_H_ */
Index: src/symlist.c
--- src/symlist.c Sun, 16 Jun 2002 19:02:50 +0200 akim
+++ src/symlist.c Sun, 16 Jun 2002 18:00:27 +0200 akim
@@ -0,0 +1,99 @@
+/* Lists of symbols for Bison
+ Copyright (C) 2002 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
+ 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.
+
+ Bison 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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "system.h"
+#include "symlist.h"
+
+
+/*----------------------------------------------.
+| Create a list containing SYMBOL at LOCATION. |
+`----------------------------------------------*/
+
+symbol_list_t *
+symbol_list_new (symbol_t *sym, location_t location)
+{
+ symbol_list_t *res = XMALLOC (symbol_list_t, 1);
+ res->next = NULL;
+ res->sym = sym;
+ res->location = location;
+ res->action = NULL;
+ res->ruleprec = NULL;
+ return res;
+}
+
+
+/*-----------------------------------------.
+| Prepend SYMBOL at LOCATION to the LIST. |
+`-----------------------------------------*/
+
+symbol_list_t *
+symbol_list_prepend (symbol_list_t *list,
+ symbol_t *symbol, location_t location)
+{
+ symbol_list_t *res = symbol_list_new (symbol, location);
+ res->next = list;
+ return res;
+}
+
+
+/*-------------------------------------------------.
+| Free the LIST, but not the symbols it contains. |
+`-------------------------------------------------*/
+
+void
+symbol_list_free (symbol_list_t *list)
+{
+ LIST_FREE (symbol_list_t, list);
+}
+
+
+/*--------------------------------------------------------------.
+| Get the data type (alternative in the union) of the value for |
+| symbol N in rule RULE. |
+`--------------------------------------------------------------*/
+
+char *
+symbol_list_n_type_name_get (symbol_list_t *rule, location_t location, int n)
+{
+ int i;
+ symbol_list_t *rp;
+
+ if (n < 0)
+ {
+ complain_at (location, _("invalid $ value"));
+ return NULL;
+ }
+
+ rp = rule;
+ i = 0;
+
+ while (i < n)
+ {
+ rp = rp->next;
+ if (rp == NULL || rp->sym == NULL)
+ {
+ complain_at (location, _("invalid $ value"));
+ return NULL;
+ }
+ ++i;
+ }
+
+ return rp->sym->type_name;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 02-symbols-list-t.patch,
Akim Demaille <=