* 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

@@ -1,3 +1,38 @@
2002-11-12 Akim Demaille <akim@epita.fr>
* 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.
2002-11-12 Akim Demaille <akim@epita.fr> 2002-11-12 Akim Demaille <akim@epita.fr>
* src/symtab.c (symbol_free): Remove dead deactivated code: * src/symtab.c (symbol_free): Remove dead deactivated code:

View File

@@ -117,7 +117,7 @@ warn (const char *message, ...)
va_list args; va_list args;
fflush (stdout); fflush (stdout);
fprintf (stderr, "%s: %s", infile ? infile : program_name, _("warning: ")); fprintf (stderr, "%s: %s", current_file ? current_file : program_name, _("warning: "));
va_start (args, message); va_start (args, message);
vfprintf (stderr, message, args); vfprintf (stderr, message, args);
@@ -156,7 +156,7 @@ complain (const char *message, ...)
va_list args; va_list args;
fflush (stdout); fflush (stdout);
fprintf (stderr, "%s: ", infile ? infile : program_name); fprintf (stderr, "%s: ", current_file ? current_file : program_name);
va_start (args, message); va_start (args, message);
vfprintf (stderr, message, args); vfprintf (stderr, message, args);
@@ -195,7 +195,7 @@ fatal (const char *message, ...)
va_list args; va_list args;
fflush (stdout); fflush (stdout);
fprintf (stderr, "%s: ", infile ? infile : program_name); fprintf (stderr, "%s: ", current_file ? current_file : program_name);
fputs (_("fatal error: "), stderr); fputs (_("fatal error: "), stderr);

View File

@@ -50,7 +50,7 @@ void fatal_at (location_t location, const char *format, ...)
__attribute__ ((__noreturn__, __format__ (__printf__, 2, 3))); __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3)));
/* Position in the current input file. */ /* Position in the current input file. */
extern char *infile; extern const char *current_file;
/* This variable is set each time `warn' is called. */ /* This variable is set each time `warn' is called. */
extern bool warning_issued; extern bool warning_issued;

View File

@@ -50,7 +50,8 @@ char *spec_graph_file = NULL; /* for -g. */
char *spec_defines_file = NULL; /* for --defines. */ char *spec_defines_file = NULL; /* for --defines. */
char *parser_file_name = NULL; char *parser_file_name = NULL;
char *infile = NULL; struniq_t grammar_file = NULL;
struniq_t current_file = NULL;
static char *full_base_name = NULL; static char *full_base_name = NULL;
@@ -279,7 +280,7 @@ compute_base_names (void)
{ {
/* Otherwise, the short base name is computed from the input /* Otherwise, the short base name is computed from the input
grammar: `foo/bar.yy' => `bar'. */ grammar: `foo/bar.yy' => `bar'. */
filename_split (infile, &base, &tab, &ext); filename_split (grammar_file, &base, &tab, &ext);
short_base_name = short_base_name =
xstrndup (base, xstrndup (base,
(strlen (base) - (ext ? strlen (ext) : 0))); (strlen (base) - (ext ? strlen (ext) : 0)));
@@ -291,7 +292,7 @@ compute_base_names (void)
stpcpy (stpcpy (full_base_name, short_base_name), EXT_TAB); stpcpy (stpcpy (full_base_name, short_base_name), EXT_TAB);
/* Computes the extensions from the grammar file name. */ /* Computes the extensions from the grammar file name. */
filename_split (infile, &base, &tab, &ext); filename_split (grammar_file, &base, &tab, &ext);
if (ext && !yacc_flag) if (ext && !yacc_flag)
compute_exts_from_gf (ext); compute_exts_from_gf (ext);
} }

View File

@@ -21,6 +21,8 @@
#ifndef FILES_H_ #ifndef FILES_H_
# define FILES_H_ # define FILES_H_
# include "struniq.h"
/* File name specified with -o for the output file, or 0 if no -o. */ /* File name specified with -o for the output file, or 0 if no -o. */
extern char *spec_outfile; extern char *spec_outfile;
@@ -50,7 +52,13 @@ extern FILE *finput;
extern struct obstack pre_prologue_obstack; extern struct obstack pre_prologue_obstack;
extern struct obstack post_prologue_obstack; extern struct obstack post_prologue_obstack;
extern char *infile; /* The file name as given on the command line.
Not named "input_file" because Flex uses this name for an argument,
and therefore GCC warns about a name clash. */
extern struniq_t grammar_file;
/* The current file name. Might change with %include, or with #line. */
extern struniq_t current_file;
void compute_output_file_names (void); void compute_output_file_names (void);

View File

@@ -24,6 +24,7 @@
#include "argmatch.h" #include "argmatch.h"
#include "error.h" #include "error.h"
#include "complain.h" #include "complain.h"
#include "struniq.h"
#include "getargs.h" #include "getargs.h"
#include "files.h" #include "files.h"
@@ -419,5 +420,5 @@ getargs (int argc, char *argv[])
usage (EXIT_FAILURE); usage (EXIT_FAILURE);
} }
infile = xstrdup (argv[optind]); current_file = grammar_file = struniq_new (argv[optind]);
} }

View File

@@ -55,6 +55,8 @@ main (int argc, char *argv[])
(void) bindtextdomain (PACKAGE, LOCALEDIR); (void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE); (void) textdomain (PACKAGE);
struniqs_new ();
getargs (argc, argv); getargs (argc, argv);
time_report = trace_flag & trace_time; time_report = trace_flag & trace_time;
@@ -64,7 +66,6 @@ main (int argc, char *argv[])
if (trace_flag & trace_bitsets) if (trace_flag & trace_bitsets)
bitset_stats_enable (); bitset_stats_enable ();
struniqs_new ();
muscle_init (); muscle_init ();
/* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE /* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE
@@ -160,8 +161,6 @@ main (int argc, char *argv[])
reduce_free (); reduce_free ();
conflicts_free (); conflicts_free ();
grammar_free (); grammar_free ();
/* FIXME: We are leaking all the other file names. */
free (infile);
/* The scanner memory cannot be released right after parsing, as it /* The scanner memory cannot be released right after parsing, as it
contains things such as user actions, prologue, epilogue etc. */ contains things such as user actions, prologue, epilogue etc. */

View File

@@ -65,7 +65,7 @@ muscle_init (void)
/* Version and input file. */ /* Version and input file. */
MUSCLE_INSERT_STRING ("version", VERSION); MUSCLE_INSERT_STRING ("version", VERSION);
MUSCLE_INSERT_C_STRING ("filename", infile); MUSCLE_INSERT_C_STRING ("filename", grammar_file);
} }

View File

@@ -198,7 +198,7 @@ prepare_symbols (void)
/*-------------------------------------------------------------. /*-------------------------------------------------------------.
| Prepare the muscles related to the rules: rhs, prhs, r1, r2, | | Prepare the muscles related to the rules: rhs, prhs, r1, r2, |
| rline, dprec, merger | | rline, dprec, merger. |
`-------------------------------------------------------------*/ `-------------------------------------------------------------*/
static void static void
@@ -230,9 +230,9 @@ prepare_rules (void)
rhs[i++] = -1; rhs[i++] = -1;
/* Line where rule was defined. */ /* Line where rule was defined. */
rline[r] = rules[r].location.first_line; rline[r] = rules[r].location.first_line;
/* Dynamic precedence (GLR) */ /* Dynamic precedence (GLR). */
dprec[r] = rules[r].dprec; dprec[r] = rules[r].dprec;
/* Merger-function index (GLR) */ /* Merger-function index (GLR). */
merger[r] = rules[r].merger; merger[r] = rules[r].merger;
} }
assert (i == nritems); assert (i == nritems);

View File

@@ -207,7 +207,7 @@ do { \
static void yyprint (FILE *file, int type, const yystype *value); static void yyprint (FILE *file, int type, const yystype *value);
symbol_class current_class = unknown_sym; symbol_class current_class = unknown_sym;
char *current_type = 0; struniq_t current_type = 0;
symbol_t *current_lhs; symbol_t *current_lhs;
location_t current_lhs_location; location_t current_lhs_location;
assoc_t current_assoc; assoc_t current_assoc;
@@ -458,14 +458,14 @@ static const yysigned_char yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const unsigned short yyrline[] = static const unsigned short yyrline[] =
{ {
0, 168, 168, 181, 183, 186, 188, 189, 190, 191, 0, 169, 169, 182, 184, 187, 189, 190, 191, 192,
192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 193, 194, 195, 196, 197, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 211, 213, 214, 218, 225, 205, 206, 207, 208, 209, 212, 214, 215, 219, 226,
224, 235, 234, 247, 246, 252, 252, 257, 266, 281, 225, 236, 235, 248, 247, 253, 253, 258, 267, 282,
283, 284, 287, 289, 294, 296, 300, 305, 310, 316, 284, 285, 288, 290, 295, 297, 301, 306, 311, 317,
322, 332, 335, 344, 346, 352, 354, 359, 366, 365, 323, 333, 336, 345, 347, 353, 355, 360, 367, 366,
370, 372, 375, 378, 380, 382, 384, 386, 390, 392, 371, 373, 376, 379, 381, 383, 385, 387, 391, 393,
395, 401, 410, 418, 423, 429, 431 396, 402, 411, 419, 424, 430, 432
}; };
#endif #endif
@@ -1216,7 +1216,7 @@ yyreduce:
switch (yyn) switch (yyn)
{ {
case 2: case 2:
#line 170 "parse-gram.y" #line 171 "parse-gram.y"
{ {
yycontrol->errcode = 0; yycontrol->errcode = 0;
epilogue_set (yyvsp[0].string, yylsp[0]); epilogue_set (yyvsp[0].string, yylsp[0]);
@@ -1224,109 +1224,109 @@ yyreduce:
break; break;
case 6: case 6:
#line 188 "parse-gram.y" #line 189 "parse-gram.y"
{ prologue_augment (yyvsp[0].string, yylsp[0]); } { prologue_augment (yyvsp[0].string, yylsp[0]); }
break; break;
case 7: case 7:
#line 189 "parse-gram.y" #line 190 "parse-gram.y"
{ debug_flag = 1; } { debug_flag = 1; }
break; break;
case 8: case 8:
#line 190 "parse-gram.y" #line 191 "parse-gram.y"
{ muscle_insert (yyvsp[-1].string, yyvsp[0].string); } { muscle_insert (yyvsp[-1].string, yyvsp[0].string); }
break; break;
case 9: case 9:
#line 191 "parse-gram.y" #line 192 "parse-gram.y"
{ defines_flag = 1; } { defines_flag = 1; }
break; break;
case 10: case 10:
#line 192 "parse-gram.y" #line 193 "parse-gram.y"
{ error_verbose = 1; } { error_verbose = 1; }
break; break;
case 11: case 11:
#line 193 "parse-gram.y" #line 194 "parse-gram.y"
{ expected_conflicts = yyvsp[0].integer; } { expected_conflicts = yyvsp[0].integer; }
break; break;
case 12: case 12:
#line 194 "parse-gram.y" #line 195 "parse-gram.y"
{ spec_file_prefix = yyvsp[0].string; } { spec_file_prefix = yyvsp[0].string; }
break; break;
case 13: case 13:
#line 195 "parse-gram.y" #line 196 "parse-gram.y"
{ glr_parser = 1; } { glr_parser = 1; }
break; break;
case 14: case 14:
#line 197 "parse-gram.y" #line 198 "parse-gram.y"
{ muscle_pair_list_grow ("lex_param", yyvsp[-2].string, yyvsp[0].string); } { muscle_pair_list_grow ("lex_param", yyvsp[-2].string, yyvsp[0].string); }
break; break;
case 15: case 15:
#line 198 "parse-gram.y" #line 199 "parse-gram.y"
{ locations_flag = 1; } { locations_flag = 1; }
break; break;
case 16: case 16:
#line 199 "parse-gram.y" #line 200 "parse-gram.y"
{ spec_name_prefix = yyvsp[0].string; } { spec_name_prefix = yyvsp[0].string; }
break; break;
case 17: case 17:
#line 200 "parse-gram.y" #line 201 "parse-gram.y"
{ no_lines_flag = 1; } { no_lines_flag = 1; }
break; break;
case 18: case 18:
#line 201 "parse-gram.y" #line 202 "parse-gram.y"
{ spec_outfile = yyvsp[0].string; } { spec_outfile = yyvsp[0].string; }
break; break;
case 19: case 19:
#line 203 "parse-gram.y" #line 204 "parse-gram.y"
{ muscle_pair_list_grow ("parse_param", yyvsp[-2].string, yyvsp[0].string); } { muscle_pair_list_grow ("parse_param", yyvsp[-2].string, yyvsp[0].string); }
break; break;
case 20: case 20:
#line 204 "parse-gram.y" #line 205 "parse-gram.y"
{ pure_parser = 1; } { pure_parser = 1; }
break; break;
case 21: case 21:
#line 205 "parse-gram.y" #line 206 "parse-gram.y"
{ skeleton = yyvsp[0].string; } { skeleton = yyvsp[0].string; }
break; break;
case 22: case 22:
#line 206 "parse-gram.y" #line 207 "parse-gram.y"
{ token_table_flag = 1; } { token_table_flag = 1; }
break; break;
case 23: case 23:
#line 207 "parse-gram.y" #line 208 "parse-gram.y"
{ report_flag = 1; } { report_flag = 1; }
break; break;
case 24: case 24:
#line 208 "parse-gram.y" #line 209 "parse-gram.y"
{ yacc_flag = 1; } { yacc_flag = 1; }
break; break;
case 27: case 27:
#line 215 "parse-gram.y" #line 216 "parse-gram.y"
{ {
grammar_start_symbol_set (yyvsp[0].symbol, yylsp[0]); grammar_start_symbol_set (yyvsp[0].symbol, yylsp[0]);
} }
break; break;
case 28: case 28:
#line 219 "parse-gram.y" #line 220 "parse-gram.y"
{ {
typed = 1; typed = 1;
MUSCLE_INSERT_INT ("stype_line", yylsp[0].first_line); MUSCLE_INSERT_INT ("stype_line", yylsp[0].first_line);
@@ -1335,12 +1335,12 @@ yyreduce:
break; break;
case 29: case 29:
#line 225 "parse-gram.y" #line 226 "parse-gram.y"
{ current_braced_code = destructor_braced_code; } { current_braced_code = destructor_braced_code; }
break; break;
case 30: case 30:
#line 227 "parse-gram.y" #line 228 "parse-gram.y"
{ {
symbol_list_t *list; symbol_list_t *list;
for (list = yyvsp[0].list; list; list = list->next) for (list = yyvsp[0].list; list; list = list->next)
@@ -1351,12 +1351,12 @@ yyreduce:
break; break;
case 31: case 31:
#line 235 "parse-gram.y" #line 236 "parse-gram.y"
{ current_braced_code = printer_braced_code; } { current_braced_code = printer_braced_code; }
break; break;
case 32: case 32:
#line 237 "parse-gram.y" #line 238 "parse-gram.y"
{ {
symbol_list_t *list; symbol_list_t *list;
for (list = yyvsp[0].list; list; list = list->next) for (list = yyvsp[0].list; list; list = list->next)
@@ -1367,12 +1367,12 @@ yyreduce:
break; break;
case 33: case 33:
#line 247 "parse-gram.y" #line 248 "parse-gram.y"
{ current_class = nterm_sym; } { current_class = nterm_sym; }
break; break;
case 34: case 34:
#line 248 "parse-gram.y" #line 249 "parse-gram.y"
{ {
current_class = unknown_sym; current_class = unknown_sym;
current_type = NULL; current_type = NULL;
@@ -1380,12 +1380,12 @@ yyreduce:
break; break;
case 35: case 35:
#line 252 "parse-gram.y" #line 253 "parse-gram.y"
{ current_class = token_sym; } { current_class = token_sym; }
break; break;
case 36: case 36:
#line 253 "parse-gram.y" #line 254 "parse-gram.y"
{ {
current_class = unknown_sym; current_class = unknown_sym;
current_type = NULL; current_type = NULL;
@@ -1393,17 +1393,17 @@ yyreduce:
break; break;
case 37: case 37:
#line 258 "parse-gram.y" #line 259 "parse-gram.y"
{ {
symbol_list_t *list; symbol_list_t *list;
for (list = yyvsp[0].list; list; list = list->next) for (list = yyvsp[0].list; list; list = list->next)
symbol_type_set (list->sym, yyvsp[-1].string, yylsp[-1]); symbol_type_set (list->sym, yyvsp[-1].struniq, yylsp[-1]);
symbol_list_free (yyvsp[0].list); symbol_list_free (yyvsp[0].list);
} }
break; break;
case 38: case 38:
#line 268 "parse-gram.y" #line 269 "parse-gram.y"
{ {
symbol_list_t *list; symbol_list_t *list;
++current_prec; ++current_prec;
@@ -1418,49 +1418,49 @@ yyreduce:
break; break;
case 39: case 39:
#line 282 "parse-gram.y" #line 283 "parse-gram.y"
{ yyval.assoc = left_assoc; } { yyval.assoc = left_assoc; }
break; break;
case 40: case 40:
#line 283 "parse-gram.y" #line 284 "parse-gram.y"
{ yyval.assoc = right_assoc; } { yyval.assoc = right_assoc; }
break; break;
case 41: case 41:
#line 284 "parse-gram.y" #line 285 "parse-gram.y"
{ yyval.assoc = non_assoc; } { yyval.assoc = non_assoc; }
break; break;
case 42: case 42:
#line 288 "parse-gram.y" #line 289 "parse-gram.y"
{ current_type = NULL; } { current_type = NULL; }
break; break;
case 43: case 43:
#line 289 "parse-gram.y" #line 290 "parse-gram.y"
{ current_type = yyvsp[0].string; } { current_type = yyvsp[0].struniq; }
break; break;
case 44: case 44:
#line 295 "parse-gram.y" #line 296 "parse-gram.y"
{ yyval.list = symbol_list_new (yyvsp[0].symbol, yylsp[0]); } { yyval.list = symbol_list_new (yyvsp[0].symbol, yylsp[0]); }
break; break;
case 45: case 45:
#line 296 "parse-gram.y" #line 297 "parse-gram.y"
{ yyval.list = symbol_list_prepend (yyvsp[-1].list, yyvsp[0].symbol, yylsp[0]); } { yyval.list = symbol_list_prepend (yyvsp[-1].list, yyvsp[0].symbol, yylsp[0]); }
break; break;
case 46: case 46:
#line 302 "parse-gram.y" #line 303 "parse-gram.y"
{ {
current_type = yyvsp[0].string; current_type = yyvsp[0].struniq;
} }
break; break;
case 47: case 47:
#line 306 "parse-gram.y" #line 307 "parse-gram.y"
{ {
symbol_class_set (yyvsp[0].symbol, current_class, yylsp[0]); symbol_class_set (yyvsp[0].symbol, current_class, yylsp[0]);
symbol_type_set (yyvsp[0].symbol, current_type, yylsp[0]); symbol_type_set (yyvsp[0].symbol, current_type, yylsp[0]);
@@ -1468,7 +1468,7 @@ yyreduce:
break; break;
case 48: case 48:
#line 311 "parse-gram.y" #line 312 "parse-gram.y"
{ {
symbol_class_set (yyvsp[-1].symbol, current_class, yylsp[-1]); symbol_class_set (yyvsp[-1].symbol, current_class, yylsp[-1]);
symbol_type_set (yyvsp[-1].symbol, current_type, yylsp[-1]); symbol_type_set (yyvsp[-1].symbol, current_type, yylsp[-1]);
@@ -1477,7 +1477,7 @@ yyreduce:
break; break;
case 49: case 49:
#line 317 "parse-gram.y" #line 318 "parse-gram.y"
{ {
symbol_class_set (yyvsp[-1].symbol, current_class, yylsp[-1]); symbol_class_set (yyvsp[-1].symbol, current_class, yylsp[-1]);
symbol_type_set (yyvsp[-1].symbol, current_type, yylsp[-1]); symbol_type_set (yyvsp[-1].symbol, current_type, yylsp[-1]);
@@ -1486,7 +1486,7 @@ yyreduce:
break; break;
case 50: case 50:
#line 323 "parse-gram.y" #line 324 "parse-gram.y"
{ {
symbol_class_set (yyvsp[-2].symbol, current_class, yylsp[-2]); symbol_class_set (yyvsp[-2].symbol, current_class, yylsp[-2]);
symbol_type_set (yyvsp[-2].symbol, current_type, yylsp[-2]); symbol_type_set (yyvsp[-2].symbol, current_type, yylsp[-2]);
@@ -1496,17 +1496,17 @@ yyreduce:
break; break;
case 51: case 51:
#line 334 "parse-gram.y" #line 335 "parse-gram.y"
{;} {;}
break; break;
case 52: case 52:
#line 336 "parse-gram.y" #line 337 "parse-gram.y"
{;} {;}
break; break;
case 56: case 56:
#line 355 "parse-gram.y" #line 356 "parse-gram.y"
{ {
if (yacc_flag) if (yacc_flag)
complain_at (yyloc, _("POSIX forbids declarations in the grammar")); complain_at (yyloc, _("POSIX forbids declarations in the grammar"));
@@ -1514,79 +1514,79 @@ yyreduce:
break; break;
case 57: case 57:
#line 360 "parse-gram.y" #line 361 "parse-gram.y"
{ {
yyerrok; yyerrok;
} }
break; break;
case 58: case 58:
#line 366 "parse-gram.y" #line 367 "parse-gram.y"
{ current_lhs = yyvsp[-1].symbol; current_lhs_location = yylsp[-1]; } { current_lhs = yyvsp[-1].symbol; current_lhs_location = yylsp[-1]; }
break; break;
case 59: case 59:
#line 367 "parse-gram.y" #line 368 "parse-gram.y"
{;} {;}
break; break;
case 60: case 60:
#line 371 "parse-gram.y"
{ grammar_rule_end (yylsp[0]); }
break;
case 61:
#line 372 "parse-gram.y" #line 372 "parse-gram.y"
{ grammar_rule_end (yylsp[0]); } { grammar_rule_end (yylsp[0]); }
break; break;
case 61:
#line 373 "parse-gram.y"
{ grammar_rule_end (yylsp[0]); }
break;
case 62: case 62:
#line 377 "parse-gram.y" #line 378 "parse-gram.y"
{ grammar_rule_begin (current_lhs, current_lhs_location); } { grammar_rule_begin (current_lhs, current_lhs_location); }
break; break;
case 63: case 63:
#line 379 "parse-gram.y" #line 380 "parse-gram.y"
{ grammar_current_rule_symbol_append (yyvsp[0].symbol, yylsp[0]); } { grammar_current_rule_symbol_append (yyvsp[0].symbol, yylsp[0]); }
break; break;
case 64: case 64:
#line 381 "parse-gram.y" #line 382 "parse-gram.y"
{ grammar_current_rule_action_append (yyvsp[0].string, yylsp[0]); } { grammar_current_rule_action_append (yyvsp[0].string, yylsp[0]); }
break; break;
case 65: case 65:
#line 383 "parse-gram.y" #line 384 "parse-gram.y"
{ grammar_current_rule_prec_set (yyvsp[0].symbol, yylsp[0]); } { grammar_current_rule_prec_set (yyvsp[0].symbol, yylsp[0]); }
break; break;
case 66: case 66:
#line 385 "parse-gram.y" #line 386 "parse-gram.y"
{ grammar_current_rule_dprec_set (yyvsp[0].integer, yylsp[0]); } { grammar_current_rule_dprec_set (yyvsp[0].integer, yylsp[0]); }
break; break;
case 67: case 67:
#line 387 "parse-gram.y" #line 388 "parse-gram.y"
{ grammar_current_rule_merge_set (yyvsp[0].string, yylsp[0]); } { grammar_current_rule_merge_set (yyvsp[0].struniq, yylsp[0]); }
break; break;
case 68: case 68:
#line 391 "parse-gram.y"
{ yyval.symbol = yyvsp[0].symbol; }
break;
case 69:
#line 392 "parse-gram.y" #line 392 "parse-gram.y"
{ yyval.symbol = yyvsp[0].symbol; } { yyval.symbol = yyvsp[0].symbol; }
break; break;
case 69:
#line 393 "parse-gram.y"
{ yyval.symbol = yyvsp[0].symbol; }
break;
case 70: case 70:
#line 397 "parse-gram.y" #line 398 "parse-gram.y"
{ yyval.string = yyvsp[0].string; } { yyval.string = yyvsp[0].string; }
break; break;
case 71: case 71:
#line 403 "parse-gram.y" #line 404 "parse-gram.y"
{ {
yyval.symbol = symbol_get (yyvsp[0].string, yylsp[0]); yyval.symbol = symbol_get (yyvsp[0].string, yylsp[0]);
symbol_class_set (yyval.symbol, token_sym, yylsp[0]); symbol_class_set (yyval.symbol, token_sym, yylsp[0]);
@@ -1594,7 +1594,7 @@ yyreduce:
break; break;
case 72: case 72:
#line 412 "parse-gram.y" #line 413 "parse-gram.y"
{ {
yyval.string = yyvsp[0].string + 1; yyval.string = yyvsp[0].string + 1;
yyval.string[strlen (yyval.string) - 1] = '\0'; yyval.string[strlen (yyval.string) - 1] = '\0';
@@ -1602,14 +1602,14 @@ yyreduce:
break; break;
case 73: case 73:
#line 420 "parse-gram.y" #line 421 "parse-gram.y"
{ {
yyval.string = xstrdup (""); yyval.string = xstrdup ("");
} }
break; break;
case 74: case 74:
#line 424 "parse-gram.y" #line 425 "parse-gram.y"
{ {
yyval.string = yyvsp[0].string; yyval.string = yyvsp[0].string;
} }
@@ -1838,7 +1838,7 @@ yyreturn:
} }
#line 433 "parse-gram.y" #line 434 "parse-gram.y"
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| When debugging the parser, display tokens' locations and values. | | When debugging the parser, display tokens' locations and values. |

View File

@@ -75,7 +75,7 @@ do { \
static void yyprint (FILE *file, int type, const yystype *value); static void yyprint (FILE *file, int type, const yystype *value);
symbol_class current_class = unknown_sym; symbol_class current_class = unknown_sym;
char *current_type = 0; struniq_t current_type = 0;
symbol_t *current_lhs; symbol_t *current_lhs;
location_t current_lhs_location; location_t current_lhs_location;
assoc_t current_assoc; assoc_t current_assoc;
@@ -157,8 +157,9 @@ braced_code_t current_braced_code = action_braced_code;
%token BRACED_CODE "{...}" %token BRACED_CODE "{...}"
%type <string> TYPE STRING string_content %type <string> STRING string_content
BRACED_CODE PROLOGUE EPILOGUE epilogue.opt action BRACED_CODE PROLOGUE EPILOGUE epilogue.opt action
%type <struniq> TYPE
%type <integer> INT %type <integer> INT
%type <symbol> ID symbol string_as_id %type <symbol> ID symbol string_as_id
%type <assoc> precedence_declarator %type <assoc> precedence_declarator

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

View File

@@ -27,8 +27,8 @@
typedef struct merger_list typedef struct merger_list
{ {
struct merger_list* next; struct merger_list* next;
const char* name; struniq_t name;
const char* type; struniq_t type;
} }
merger_list; merger_list;
@@ -76,7 +76,7 @@ void grammar_rule_end (location_t l);
void grammar_midrule_action (void); void grammar_midrule_action (void);
void grammar_current_rule_prec_set (symbol_t *precsym, location_t l); void grammar_current_rule_prec_set (symbol_t *precsym, location_t l);
void grammar_current_rule_dprec_set (int dprec, location_t l); void grammar_current_rule_dprec_set (int dprec, location_t l);
void grammar_current_rule_merge_set (const char* name, location_t l); void grammar_current_rule_merge_set (struniq_t name, location_t l);
void grammar_current_rule_symbol_append (symbol_t *symbol, location_t l); void grammar_current_rule_symbol_append (symbol_t *symbol, location_t l);
void grammar_current_rule_action_append (const char *action, location_t l); void grammar_current_rule_action_append (const char *action, location_t l);

View File

@@ -389,7 +389,7 @@ reduce_print (void)
nuseless_productions), nuseless_productions),
nuseless_productions); nuseless_productions);
fprintf (stderr, "%s: %s: ", infile, _("warning")); fprintf (stderr, "%s: %s: ", grammar_file, _("warning"));
if (nuseless_nonterminals > 0) if (nuseless_nonterminals > 0)
fprintf (stderr, ngettext ("%d useless nonterminal", fprintf (stderr, ngettext ("%d useless nonterminal",
@@ -449,7 +449,7 @@ reduce_grammar (void)
fprintf (stderr, "reduced %s defines %d terminals, %d nonterminals\ fprintf (stderr, "reduced %s defines %d terminals, %d nonterminals\
, and %d productions.\n", , and %d productions.\n",
infile, ntokens, nvars, nrules); grammar_file, ntokens, nvars, nrules);
} }
} }

View File

@@ -36,7 +36,7 @@
#define YY_USER_INIT \ #define YY_USER_INIT \
do { \ do { \
LOCATION_RESET (*yylloc); \ LOCATION_RESET (*yylloc); \
yylloc->file = infile; \ yylloc->file = current_file; \
/* This is only to avoid GCC warnings. */ \ /* This is only to avoid GCC warnings. */ \
if (yycontrol) {;}; \ if (yycontrol) {;}; \
} while (0) } while (0)
@@ -829,10 +829,8 @@ handle_syncline (char *args, location_t *location)
const char *file = NULL; const char *file = NULL;
file = strchr (args, '"') + 1; file = strchr (args, '"') + 1;
*strchr (file, '"') = 0; *strchr (file, '"') = 0;
/* FIXME: Leaking... Can't free, as some locations are still current_file = xstrdup (file);
pointing to the old file name. */ location->file = current_file;
infile = xstrdup (file);
location->file = infile;
location->last_line = lineno; location->last_line = lineno;
} }

View File

@@ -20,6 +20,7 @@
#include "system.h" #include "system.h"
#include "quotearg.h" #include "quotearg.h"
#include "error.h"
#include "hash.h" #include "hash.h"
#include "struniq.h" #include "struniq.h"
@@ -39,20 +40,36 @@ static struct hash_table *struniqs_table = NULL;
const struniq_t const struniq_t
struniq_new (const char *s) struniq_new (const char *s)
{ {
/* Keep the struniqs in a printable form. */ struniq_t res = hash_lookup (struniqs_table, s);
struniq_t res = hash_lookup (struniqs_table,
quotearg_style (escape_quoting_style, s));
if (!res) if (!res)
{ {
/* First insertion in the hash. */ /* First insertion in the hash. */
res = xstrdup (quotearg_style (escape_quoting_style, s)); res = xstrdup (s);
hash_insert (struniqs_table, res); hash_insert (struniqs_table, res);
} }
return res; return res;
} }
/*---------------------------------.
| Return TRUE iff S is a struniq. |
`---------------------------------*/
bool
struniq_assert_p (const char *s)
{
if (!hash_lookup (struniqs_table, s))
{
error (0, 0, "not a struniq: %s", quotearg (s));
return false;
}
else
{
return true;
}
}
/*--------------------. /*--------------------.
| Print the struniq. | | Print the struniq. |
`--------------------*/ `--------------------*/

View File

@@ -25,11 +25,14 @@
| struniq_t -- pointers to unique copies of C strings. | | struniq_t -- pointers to unique copies of C strings. |
`------------------------------------------------------*/ `------------------------------------------------------*/
typedef char *struniq_t; typedef const char *struniq_t;
/* Return the struniq for S. */ /* Return the struniq for S. */
const struniq_t struniq_new (const char *s); const struniq_t struniq_new (const char *s);
/* Two struniq have the same value iff they are the same. */
#define STRUNIQ_EQ(S1, S2) ((S1) == (S2))
/*--------------------------------------. /*--------------------------------------.
| Initializing, destroying, debugging. | | Initializing, destroying, debugging. |
`--------------------------------------*/ `--------------------------------------*/
@@ -37,6 +40,10 @@ const struniq_t struniq_new (const char *s);
/* Create the string table. */ /* Create the string table. */
void struniqs_new (void); void struniqs_new (void);
/* Die if S is not a struniq. */
#define struniq_assert(S) assert (struniq_assert_p (S));
bool struniq_assert_p (const char *s);
/* Free all the memory allocated for symbols. */ /* Free all the memory allocated for symbols. */
void struniqs_free (void); void struniqs_free (void);

View File

@@ -86,7 +86,7 @@ symbol_list_length (symbol_list_t *list)
| symbol N in rule RULE. | | symbol N in rule RULE. |
`--------------------------------------------------------------*/ `--------------------------------------------------------------*/
char * struniq_t
symbol_list_n_type_name_get (symbol_list_t *rule, location_t location, int n) symbol_list_n_type_name_get (symbol_list_t *rule, location_t location, int n)
{ {
int i; int i;

View File

@@ -56,7 +56,7 @@ unsigned int symbol_list_length (symbol_list_t *list);
/* Get the data type (alternative in the union) of the value for /* Get the data type (alternative in the union) of the value for
symbol N in rule RULE. */ symbol N in rule RULE. */
char *symbol_list_n_type_name_get (symbol_list_t *rule, struniq_t symbol_list_n_type_name_get (symbol_list_t *rule,
location_t location, int n); location_t location, int n);
#endif /* !SYMLIST_H_ */ #endif /* !SYMLIST_H_ */

View File

@@ -42,11 +42,12 @@ location_t startsymbol_location;
`---------------------------------*/ `---------------------------------*/
static symbol_t * static symbol_t *
symbol_new (const char *tag, location_t location) symbol_new (struniq_t tag, location_t location)
{ {
symbol_t *res = XMALLOC (symbol_t, 1); symbol_t *res = XMALLOC (symbol_t, 1);
res->tag = xstrdup (tag); struniq_assert (tag);
res->tag = tag;
res->location = location; res->location = location;
res->type_name = NULL; res->type_name = NULL;
@@ -72,13 +73,14 @@ symbol_new (const char *tag, location_t location)
`------------------------------------------------------------------*/ `------------------------------------------------------------------*/
void void
symbol_type_set (symbol_t *symbol, char *type_name, location_t location) symbol_type_set (symbol_t *symbol, struniq_t type_name, location_t location)
{ {
if (type_name) if (type_name)
{ {
if (symbol->type_name) if (symbol->type_name)
complain_at (location, complain_at (location,
_("type redeclaration for %s"), symbol->tag); _("type redeclaration for %s"), symbol->tag);
struniq_assert (type_name);
symbol->type_name = type_name; symbol->type_name = type_name;
} }
} }
@@ -200,7 +202,6 @@ symbol_user_token_number_set (symbol_t *symbol,
static void static void
symbol_free (symbol_t *this) symbol_free (symbol_t *this)
{ {
free (this->tag);
free (this); free (this);
} }
@@ -376,15 +377,17 @@ symbol_translation (symbol_t *this)
static struct hash_table *symbol_table = NULL; static struct hash_table *symbol_table = NULL;
static bool static bool
hash_compare_symbol_t (const symbol_t *m1, const symbol_t *m2) hash_compare_symbol (const symbol_t *m1, const symbol_t *m2)
{ {
return strcmp (m1->tag, m2->tag) == 0; /* Since tags are unique, we can compare the pointers themselves. */
return STRUNIQ_EQ (m1->tag, m2->tag);
} }
static unsigned int static unsigned int
hash_symbol_t (const symbol_t *m, unsigned int tablesize) hash_symbol (const symbol_t *m, unsigned int tablesize)
{ {
return hash_string (m->tag, tablesize); /* Since tags are unique, we can hash the pointer itself. */
return ((size_t) m->tag) % tablesize;
} }
@@ -397,8 +400,8 @@ symbols_new (void)
{ {
symbol_table = hash_initialize (HT_INITIAL_CAPACITY, symbol_table = hash_initialize (HT_INITIAL_CAPACITY,
NULL, NULL,
(Hash_hasher) hash_symbol_t, (Hash_hasher) hash_symbol,
(Hash_comparator) hash_compare_symbol_t, (Hash_comparator) hash_compare_symbol,
(Hash_data_freer) symbol_free); (Hash_data_freer) symbol_free);
} }
@@ -415,7 +418,7 @@ symbol_get (const char *key, location_t location)
symbol_t *entry; symbol_t *entry;
/* Keep the symbol in a printable form. */ /* Keep the symbol in a printable form. */
key = quotearg_style (escape_quoting_style, key); key = struniq_new (quotearg_style (escape_quoting_style, key));
*(char const **) &probe.tag = key; *(char const **) &probe.tag = key;
entry = hash_lookup (symbol_table, &probe); entry = hash_lookup (symbol_table, &probe);

View File

@@ -48,7 +48,7 @@ typedef struct symbol_s symbol_t;
struct symbol_s struct symbol_s
{ {
/* The key, name of the symbol. */ /* The key, name of the symbol. */
char *tag; struniq_t tag;
/* The location of its first occurence. */ /* The location of its first occurence. */
location_t location; location_t location;
@@ -98,7 +98,7 @@ void symbol_make_alias (symbol_t *symbol, symbol_t *symval,
/* Set the TYPE_NAME associated to SYMBOL. Does nothing if passed 0 as /* Set the TYPE_NAME associated to SYMBOL. Does nothing if passed 0 as
TYPE_NAME. */ TYPE_NAME. */
void symbol_type_set (symbol_t *symbol, void symbol_type_set (symbol_t *symbol,
char *type_name, location_t location); struniq_t type_name, location_t location);
/* Set the DESTRUCTOR associated to SYMBOL. */ /* Set the DESTRUCTOR associated to SYMBOL. */
void symbol_destructor_set (symbol_t *symbol, void symbol_destructor_set (symbol_t *symbol,