* src/struniq.h, src/struniq.c (struniq_t): Is const.

(STRUNIQ_EQ, struniq_assert, struniq_assert_p): New.
Use struniq for symbols.
* src/symtab.h (symbol_t): The tag member is a struniq.
(symbol_type_set): Adjust.
* src/symtab.c (symbol_new): Takes a struniq.
(symbol_free): Don't free the tag member.
(hash_compare_symbol_t, hash_symbol_t): Rename as...
(hash_compare_symbol, hash_symbol): these.
Use the fact that tags as struniqs.
(symbol_get): Use struniq_new.
* src/symlist.h, src/symlist.c (symbol_list_n_type_name_get):
Returns a strniq.
* src/reader.h (merger_list, grammar_currentmerge_set): The name
and type members are struniqs.
* src/reader.c (get_merge_function)
(grammar_current_rule_merge_set): Adjust.
(TYPE, current_type): Are struniq.
Use struniq for file names.
* src/files.h, src/files.c (infile): Split into...
(grammar_file, current_file): these.
* src/scan-gram.c (YY_USER_INIT, handle_syncline): Adjust.
* src/reduce.c (reduce_print): Likewise.
* src/getargs.c (getargs): Likewise.
* src/complain.h, src/complain.c: Likewise.
* src/main.c (main): Call struniqs_new early enough to use it for
file names.
Don't free the input file name.
This commit is contained in:
Akim Demaille
2002-11-12 08:05:59 +00:00
parent 3e6656f9ab
commit 95612cfa60
21 changed files with 214 additions and 145 deletions

View File

@@ -102,12 +102,11 @@ epilogue_set (const char *epilogue, location_t location)
/*-------------------------------------------------------------------.
| Return the merger index for a merging function named NAME, whose |
| arguments have type TYPE. Records the function, if new, in |
| merger_list. |
| MERGER_LIST. |
`-------------------------------------------------------------------*/
static int
get_merge_function (const char* name, const char* type,
location_t loc)
get_merge_function (struniq_t name, struniq_t type, location_t loc)
{
merger_list *syms;
merger_list head;
@@ -117,21 +116,21 @@ get_merge_function (const char* name, const char* type,
return 0;
if (type == NULL)
type = "";
type = struniq_new ("");
head.next = merge_functions;
for (syms = &head, n = 1; syms->next != NULL; syms = syms->next, n += 1)
if (strcmp (name, syms->next->name) == 0)
if (STRUNIQ_EQ (name, syms->next->name))
break;
if (syms->next == NULL)
{
syms->next = XMALLOC (merger_list, 1);
syms->next->name = xstrdup (name);
syms->next->type = xstrdup (type);
syms->next->name = struniq_new (name);
syms->next->type = struniq_new (type);
syms->next->next = NULL;
merge_functions = head.next;
}
else if (strcmp (type, syms->next->type) != 0)
else if (!STRUNIQ_EQ (type, syms->next->type))
warn_at (loc, _("result type clash on merge function %s: <%s> != <%s>"),
name, type, syms->next->type);
return n;
@@ -257,7 +256,7 @@ grammar_current_rule_check (void)
if (first_rhs)
{
const char *rhs_type = first_rhs->type_name ? first_rhs->type_name : "";
if (strcmp (lhs_type, rhs_type))
if (!STRUNIQ_EQ (lhs_type, rhs_type))
complain_at (current_rule->location,
_("type clash on default action: <%s> != <%s>"),
lhs_type, rhs_type);
@@ -358,7 +357,7 @@ grammar_current_rule_dprec_set (int dprec, location_t location)
rule. */
void
grammar_current_rule_merge_set (const char* name, location_t location)
grammar_current_rule_merge_set (struniq_t name, location_t location)
{
if (! glr_parser)
warn_at (location, _("%s affects only GLR parsers"), "%merge");
@@ -491,7 +490,7 @@ reader (void)
obstack_init (&pre_prologue_obstack);
obstack_init (&post_prologue_obstack);
finput = xfopen (infile, "r");
finput = xfopen (grammar_file, "r");
gram_in = finput;
gram__flex_debug = trace_flag & trace_scan;