* src/symtab.c (symbol_free): Remove dead deactivated code:

type_name are properly removed.
Don't use XFREE to free items that cannot be NULL.
* src/struniq.h, src/struniq.c: New.
* src/main.c (main): Initialize/free struniqs.
* src/parse-gram.y (%union): Add astruniq member.
(yyprint): Adjust.
* src/scan-gram.l (<{tag}>): Return a struniq.
Free the obstack bit that used to store it.
* src/symtab.h (symbol_t): The 'type_name' member is a struniq.
This commit is contained in:
Akim Demaille
2002-11-12 07:55:55 +00:00
parent ccdb39e0a6
commit 3e6656f9ab
12 changed files with 304 additions and 103 deletions

View File

@@ -1,3 +1,16 @@
2002-11-12 Akim Demaille <akim@epita.fr>
* src/symtab.c (symbol_free): Remove dead deactivated code:
type_name are properly removed.
Don't use XFREE to free items that cannot be NULL.
* src/struniq.h, src/struniq.c: New.
* src/main.c (main): Initialize/free struniqs.
* src/parse-gram.y (%union): Add astruniq member.
(yyprint): Adjust.
* src/scan-gram.l (<{tag}>): Return a struniq.
Free the obstack bit that used to store it.
* src/symtab.h (symbol_t): The 'type_name' member is a struniq.
2002-11-11 Paul Eggert <eggert@twinsun.com> 2002-11-11 Paul Eggert <eggert@twinsun.com>
Revamp to fix many (but not all) of the C- and M4-related quoting Revamp to fix many (but not all) of the C- and M4-related quoting

View File

@@ -55,6 +55,7 @@ bison_SOURCES = \
scan-gram.l \ scan-gram.l \
scan-skel.l \ scan-skel.l \
state.c state.h \ state.c state.h \
struniq.c struniq.h \
symlist.c symlist.h \ symlist.c symlist.h \
symtab.c symtab.h \ symtab.c symtab.h \
system.h \ system.h \

View File

@@ -24,6 +24,7 @@
#include "bitset_stats.h" #include "bitset_stats.h"
#include "bitset.h" #include "bitset.h"
#include "getargs.h" #include "getargs.h"
#include "struniq.h"
#include "symtab.h" #include "symtab.h"
#include "gram.h" #include "gram.h"
#include "files.h" #include "files.h"
@@ -63,6 +64,7 @@ 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
@@ -165,6 +167,7 @@ main (int argc, char *argv[])
contains things such as user actions, prologue, epilogue etc. */ contains things such as user actions, prologue, epilogue etc. */
scanner_free (); scanner_free ();
muscle_free (); muscle_free ();
struniqs_free ();
/* If using alloca.c, flush the alloca'ed memory for the benefit of /* If using alloca.c, flush the alloca'ed memory for the benefit of
people running Bison as a library in IDEs. */ people running Bison as a library in IDEs. */
#if C_ALLOCA #if C_ALLOCA

View File

@@ -1,4 +1,4 @@
/* A Bison parser, made by GNU Bison 1.75b. */ /* A Bison parser, made from parse-gram.y, by GNU bison 1.75b. */
/* Skeleton parser for Yacc-like parsing with Bison, /* Skeleton parser for Yacc-like parsing with Bison,
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
@@ -236,9 +236,10 @@ typedef union {
int integer; int integer;
char *string; char *string;
assoc_t assoc; assoc_t assoc;
struniq_t struniq;
} yystype; } yystype;
/* Line 212 of /tmp/prefix/share/bison/yacc.c. */ /* Line 237 of /usr/local/share/bison/yacc.c. */
#line 241 "parse-gram.c" #line 243 "parse-gram.c"
# define YYSTYPE yystype # define YYSTYPE yystype
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
#endif #endif
@@ -258,8 +259,8 @@ typedef struct yyltype
/* Copy the second part of user declarations. */ /* Copy the second part of user declarations. */
/* Line 232 of /tmp/prefix/share/bison/yacc.c. */ /* Line 257 of /usr/local/share/bison/yacc.c. */
#line 262 "parse-gram.c" #line 264 "parse-gram.c"
#if ! defined (yyoverflow) || YYERROR_VERBOSE #if ! defined (yyoverflow) || YYERROR_VERBOSE
@@ -457,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, 167, 167, 180, 182, 185, 187, 188, 189, 190, 0, 168, 168, 181, 183, 186, 188, 189, 190, 191,
191, 192, 193, 194, 195, 197, 198, 199, 200, 201, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202,
203, 204, 205, 206, 207, 210, 212, 213, 217, 224, 204, 205, 206, 207, 208, 211, 213, 214, 218, 225,
223, 234, 233, 246, 245, 251, 251, 256, 265, 280, 224, 235, 234, 247, 246, 252, 252, 257, 266, 281,
282, 283, 286, 288, 293, 295, 299, 304, 309, 315, 283, 284, 287, 289, 294, 296, 300, 305, 310, 316,
321, 331, 334, 343, 345, 351, 353, 358, 365, 364, 322, 332, 335, 344, 346, 352, 354, 359, 366, 365,
369, 371, 374, 377, 379, 381, 383, 385, 389, 391, 370, 372, 375, 378, 380, 382, 384, 386, 390, 392,
394, 400, 409, 417, 422, 428, 430 395, 401, 410, 418, 423, 429, 431
}; };
#endif #endif
@@ -1215,7 +1216,7 @@ yyreduce:
switch (yyn) switch (yyn)
{ {
case 2: case 2:
#line 169 "parse-gram.y" #line 170 "parse-gram.y"
{ {
yycontrol->errcode = 0; yycontrol->errcode = 0;
epilogue_set (yyvsp[0].string, yylsp[0]); epilogue_set (yyvsp[0].string, yylsp[0]);
@@ -1223,109 +1224,109 @@ yyreduce:
break; break;
case 6: case 6:
#line 187 "parse-gram.y" #line 188 "parse-gram.y"
{ prologue_augment (yyvsp[0].string, yylsp[0]); } { prologue_augment (yyvsp[0].string, yylsp[0]); }
break; break;
case 7: case 7:
#line 188 "parse-gram.y" #line 189 "parse-gram.y"
{ debug_flag = 1; } { debug_flag = 1; }
break; break;
case 8: case 8:
#line 189 "parse-gram.y" #line 190 "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 190 "parse-gram.y" #line 191 "parse-gram.y"
{ defines_flag = 1; } { defines_flag = 1; }
break; break;
case 10: case 10:
#line 191 "parse-gram.y" #line 192 "parse-gram.y"
{ error_verbose = 1; } { error_verbose = 1; }
break; break;
case 11: case 11:
#line 192 "parse-gram.y" #line 193 "parse-gram.y"
{ expected_conflicts = yyvsp[0].integer; } { expected_conflicts = yyvsp[0].integer; }
break; break;
case 12: case 12:
#line 193 "parse-gram.y" #line 194 "parse-gram.y"
{ spec_file_prefix = yyvsp[0].string; } { spec_file_prefix = yyvsp[0].string; }
break; break;
case 13: case 13:
#line 194 "parse-gram.y" #line 195 "parse-gram.y"
{ glr_parser = 1; } { glr_parser = 1; }
break; break;
case 14: case 14:
#line 196 "parse-gram.y" #line 197 "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 197 "parse-gram.y" #line 198 "parse-gram.y"
{ locations_flag = 1; } { locations_flag = 1; }
break; break;
case 16: case 16:
#line 198 "parse-gram.y" #line 199 "parse-gram.y"
{ spec_name_prefix = yyvsp[0].string; } { spec_name_prefix = yyvsp[0].string; }
break; break;
case 17: case 17:
#line 199 "parse-gram.y" #line 200 "parse-gram.y"
{ no_lines_flag = 1; } { no_lines_flag = 1; }
break; break;
case 18: case 18:
#line 200 "parse-gram.y" #line 201 "parse-gram.y"
{ spec_outfile = yyvsp[0].string; } { spec_outfile = yyvsp[0].string; }
break; break;
case 19: case 19:
#line 202 "parse-gram.y" #line 203 "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 203 "parse-gram.y" #line 204 "parse-gram.y"
{ pure_parser = 1; } { pure_parser = 1; }
break; break;
case 21: case 21:
#line 204 "parse-gram.y" #line 205 "parse-gram.y"
{ skeleton = yyvsp[0].string; } { skeleton = yyvsp[0].string; }
break; break;
case 22: case 22:
#line 205 "parse-gram.y" #line 206 "parse-gram.y"
{ token_table_flag = 1; } { token_table_flag = 1; }
break; break;
case 23: case 23:
#line 206 "parse-gram.y" #line 207 "parse-gram.y"
{ report_flag = 1; } { report_flag = 1; }
break; break;
case 24: case 24:
#line 207 "parse-gram.y" #line 208 "parse-gram.y"
{ yacc_flag = 1; } { yacc_flag = 1; }
break; break;
case 27: case 27:
#line 214 "parse-gram.y" #line 215 "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 218 "parse-gram.y" #line 219 "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);
@@ -1334,12 +1335,12 @@ yyreduce:
break; break;
case 29: case 29:
#line 224 "parse-gram.y" #line 225 "parse-gram.y"
{ current_braced_code = destructor_braced_code; } { current_braced_code = destructor_braced_code; }
break; break;
case 30: case 30:
#line 226 "parse-gram.y" #line 227 "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)
@@ -1350,12 +1351,12 @@ yyreduce:
break; break;
case 31: case 31:
#line 234 "parse-gram.y" #line 235 "parse-gram.y"
{ current_braced_code = printer_braced_code; } { current_braced_code = printer_braced_code; }
break; break;
case 32: case 32:
#line 236 "parse-gram.y" #line 237 "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)
@@ -1366,12 +1367,12 @@ yyreduce:
break; break;
case 33: case 33:
#line 246 "parse-gram.y" #line 247 "parse-gram.y"
{ current_class = nterm_sym; } { current_class = nterm_sym; }
break; break;
case 34: case 34:
#line 247 "parse-gram.y" #line 248 "parse-gram.y"
{ {
current_class = unknown_sym; current_class = unknown_sym;
current_type = NULL; current_type = NULL;
@@ -1379,12 +1380,12 @@ yyreduce:
break; break;
case 35: case 35:
#line 251 "parse-gram.y" #line 252 "parse-gram.y"
{ current_class = token_sym; } { current_class = token_sym; }
break; break;
case 36: case 36:
#line 252 "parse-gram.y" #line 253 "parse-gram.y"
{ {
current_class = unknown_sym; current_class = unknown_sym;
current_type = NULL; current_type = NULL;
@@ -1392,7 +1393,7 @@ yyreduce:
break; break;
case 37: case 37:
#line 257 "parse-gram.y" #line 258 "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)
@@ -1402,7 +1403,7 @@ yyreduce:
break; break;
case 38: case 38:
#line 267 "parse-gram.y" #line 268 "parse-gram.y"
{ {
symbol_list_t *list; symbol_list_t *list;
++current_prec; ++current_prec;
@@ -1417,49 +1418,49 @@ yyreduce:
break; break;
case 39: case 39:
#line 281 "parse-gram.y" #line 282 "parse-gram.y"
{ yyval.assoc = left_assoc; } { yyval.assoc = left_assoc; }
break; break;
case 40: case 40:
#line 282 "parse-gram.y" #line 283 "parse-gram.y"
{ yyval.assoc = right_assoc; } { yyval.assoc = right_assoc; }
break; break;
case 41: case 41:
#line 283 "parse-gram.y" #line 284 "parse-gram.y"
{ yyval.assoc = non_assoc; } { yyval.assoc = non_assoc; }
break; break;
case 42: case 42:
#line 287 "parse-gram.y" #line 288 "parse-gram.y"
{ current_type = NULL; } { current_type = NULL; }
break; break;
case 43: case 43:
#line 288 "parse-gram.y" #line 289 "parse-gram.y"
{ current_type = yyvsp[0].string; } { current_type = yyvsp[0].string; }
break; break;
case 44: case 44:
#line 294 "parse-gram.y" #line 295 "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 295 "parse-gram.y" #line 296 "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 301 "parse-gram.y" #line 302 "parse-gram.y"
{ {
current_type = yyvsp[0].string; current_type = yyvsp[0].string;
} }
break; break;
case 47: case 47:
#line 305 "parse-gram.y" #line 306 "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]);
@@ -1467,7 +1468,7 @@ yyreduce:
break; break;
case 48: case 48:
#line 310 "parse-gram.y" #line 311 "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]);
@@ -1476,7 +1477,7 @@ yyreduce:
break; break;
case 49: case 49:
#line 316 "parse-gram.y" #line 317 "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]);
@@ -1485,7 +1486,7 @@ yyreduce:
break; break;
case 50: case 50:
#line 322 "parse-gram.y" #line 323 "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]);
@@ -1495,17 +1496,17 @@ yyreduce:
break; break;
case 51: case 51:
#line 333 "parse-gram.y" #line 334 "parse-gram.y"
{;} {;}
break; break;
case 52: case 52:
#line 335 "parse-gram.y" #line 336 "parse-gram.y"
{;} {;}
break; break;
case 56: case 56:
#line 354 "parse-gram.y" #line 355 "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"));
@@ -1513,79 +1514,79 @@ yyreduce:
break; break;
case 57: case 57:
#line 359 "parse-gram.y" #line 360 "parse-gram.y"
{ {
yyerrok; yyerrok;
} }
break; break;
case 58: case 58:
#line 365 "parse-gram.y" #line 366 "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 366 "parse-gram.y" #line 367 "parse-gram.y"
{;} {;}
break; break;
case 60: case 60:
#line 370 "parse-gram.y"
{ grammar_rule_end (yylsp[0]); }
break;
case 61:
#line 371 "parse-gram.y" #line 371 "parse-gram.y"
{ grammar_rule_end (yylsp[0]); } { grammar_rule_end (yylsp[0]); }
break; break;
case 61:
#line 372 "parse-gram.y"
{ grammar_rule_end (yylsp[0]); }
break;
case 62: case 62:
#line 376 "parse-gram.y" #line 377 "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 378 "parse-gram.y" #line 379 "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 380 "parse-gram.y" #line 381 "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 382 "parse-gram.y" #line 383 "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 384 "parse-gram.y" #line 385 "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 386 "parse-gram.y" #line 387 "parse-gram.y"
{ grammar_current_rule_merge_set (yyvsp[0].string, yylsp[0]); } { grammar_current_rule_merge_set (yyvsp[0].string, yylsp[0]); }
break; break;
case 68: case 68:
#line 390 "parse-gram.y"
{ yyval.symbol = yyvsp[0].symbol; }
break;
case 69:
#line 391 "parse-gram.y" #line 391 "parse-gram.y"
{ yyval.symbol = yyvsp[0].symbol; } { yyval.symbol = yyvsp[0].symbol; }
break; break;
case 69:
#line 392 "parse-gram.y"
{ yyval.symbol = yyvsp[0].symbol; }
break;
case 70: case 70:
#line 396 "parse-gram.y" #line 397 "parse-gram.y"
{ yyval.string = yyvsp[0].string; } { yyval.string = yyvsp[0].string; }
break; break;
case 71: case 71:
#line 402 "parse-gram.y" #line 403 "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]);
@@ -1593,7 +1594,7 @@ yyreduce:
break; break;
case 72: case 72:
#line 411 "parse-gram.y" #line 412 "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';
@@ -1601,14 +1602,14 @@ yyreduce:
break; break;
case 73: case 73:
#line 419 "parse-gram.y" #line 420 "parse-gram.y"
{ {
yyval.string = xstrdup (""); yyval.string = xstrdup ("");
} }
break; break;
case 74: case 74:
#line 423 "parse-gram.y" #line 424 "parse-gram.y"
{ {
yyval.string = yyvsp[0].string; yyval.string = yyvsp[0].string;
} }
@@ -1617,8 +1618,8 @@ yyreduce:
} }
/* Line 1031 of /tmp/prefix/share/bison/yacc.c. */ /* Line 1056 of /usr/local/share/bison/yacc.c. */
#line 1621 "parse-gram.c" #line 1623 "parse-gram.c"
yyvsp -= yylen; yyvsp -= yylen;
yyssp -= yylen; yyssp -= yylen;
@@ -1837,7 +1838,7 @@ yyreturn:
} }
#line 432 "parse-gram.y" #line 433 "parse-gram.y"
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| When debugging the parser, display tokens' locations and values. | | When debugging the parser, display tokens' locations and values. |
@@ -1863,7 +1864,7 @@ yyprint (FILE *file,
break; break;
case TYPE: case TYPE:
fprintf (file, " = <%s>", value->string); fprintf (file, " = <%s>", value->struniq);
break; break;
case BRACED_CODE: case BRACED_CODE:

View File

@@ -1,4 +1,4 @@
/* A Bison parser, made by GNU Bison 1.75b. */ /* A Bison parser, made from parse-gram.y, by GNU bison 1.75b. */
/* Skeleton parser for Yacc-like parsing with Bison, /* Skeleton parser for Yacc-like parsing with Bison,
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
@@ -23,6 +23,9 @@
This special exception was added by the Free Software Foundation This special exception was added by the Free Software Foundation
in version 1.24 of Bison. */ in version 1.24 of Bison. */
#ifndef BISON_PARSE_GRAM_H
# define BISON_PARSE_GRAM_H
/* Tokens. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
# define YYTOKENTYPE # define YYTOKENTYPE
@@ -133,11 +136,11 @@ typedef union {
int integer; int integer;
char *string; char *string;
assoc_t assoc; assoc_t assoc;
struniq_t struniq;
} yystype; } yystype;
/* Line 1293 of /tmp/prefix/share/bison/yacc.c. */ /* Line 1321 of /usr/local/share/bison/yacc.c. */
#line 138 "y.tab.h" #line 143 "y.tab.h"
# define YYSTYPE yystype # define YYSTYPE yystype
# define YYSTYPE_IS_TRIVIAL 1
#endif #endif
@@ -155,4 +158,5 @@ typedef struct yyltype
#endif /* not BISON_PARSE_GRAM_H */

View File

@@ -92,6 +92,7 @@ braced_code_t current_braced_code = action_braced_code;
int integer; int integer;
char *string; char *string;
assoc_t assoc; assoc_t assoc;
struniq_t struniq;
}; };
/* Define the tokens together with their human representation. */ /* Define the tokens together with their human representation. */
@@ -454,7 +455,7 @@ yyprint (FILE *file,
break; break;
case TYPE: case TYPE:
fprintf (file, " = <%s>", value->string); fprintf (file, " = <%s>", value->struniq);
break; break;
case BRACED_CODE: case BRACED_CODE:

View File

@@ -99,7 +99,7 @@ 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. |

View File

@@ -27,6 +27,7 @@
#include "mbswidth.h" #include "mbswidth.h"
#include "complain.h" #include "complain.h"
#include "quote.h" #include "quote.h"
#include "struniq.h"
#include "getargs.h" #include "getargs.h"
#include "gram.h" #include "gram.h"
#include "reader.h" #include "reader.h"
@@ -301,7 +302,8 @@ splice (\\[ \f\t\v]*\n)*
"<"{tag}">" { "<"{tag}">" {
obstack_grow (&string_obstack, yytext + 1, yyleng - 2); obstack_grow (&string_obstack, yytext + 1, yyleng - 2);
YY_OBS_FINISH; YY_OBS_FINISH;
yylval->string = last_string; yylval->struniq = struniq_new (last_string);
YY_OBS_FREE;
return TYPE; return TYPE;
} }

134
src/struniq.c Normal file
View File

@@ -0,0 +1,134 @@
/* Keeping a unique copy of strings.
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 "quotearg.h"
#include "hash.h"
#include "struniq.h"
/*-----------------------.
| A struniq hash table. |
`-----------------------*/
/* Initial capacity of struniq hash table. */
#define HT_INITIAL_CAPACITY 257
static struct hash_table *struniqs_table = NULL;
/*-------------------------------------.
| Create the struniq for S if needed. |
`-------------------------------------*/
const struniq_t
struniq_new (const char *s)
{
/* Keep the struniqs in a printable form. */
struniq_t res = hash_lookup (struniqs_table,
quotearg_style (escape_quoting_style, s));
if (!res)
{
/* First insertion in the hash. */
res = xstrdup (quotearg_style (escape_quoting_style, s));
hash_insert (struniqs_table, res);
}
return res;
}
/*--------------------.
| Print the struniq. |
`--------------------*/
static bool
struniq_print (const struniq_t s)
{
fprintf (stderr, "%s\n", s);
return true;
}
/*-----------------------.
| A struniq hash table. |
`-----------------------*/
static bool
hash_compare_struniq_t (const struniq_t m1, const struniq_t m2)
{
return strcmp (m1, m2) == 0;
}
static unsigned int
hash_struniq_t (const struniq_t m, unsigned int tablesize)
{
return hash_string (m, tablesize);
}
/* A function to apply to each symbol. */
typedef bool (*struniq_processor_t) (const struniq_t);
/*----------------------------.
| Create the struniqs table. |
`----------------------------*/
void
struniqs_new (void)
{
struniqs_table = hash_initialize (HT_INITIAL_CAPACITY,
NULL,
(Hash_hasher) hash_struniq_t,
(Hash_comparator) hash_compare_struniq_t,
(Hash_data_freer) free);
}
/*-------------------------------------.
| Perform a task on all the struniqs. |
`-------------------------------------*/
static void
struniqs_do (struniq_processor_t processor, void *processor_data)
{
hash_do_for_each (struniqs_table,
(Hash_processor) processor,
processor_data);
}
/*-----------------.
| Print them all. |
`-----------------*/
void
struniqs_print (void)
{
struniqs_do (struniq_print, NULL);
}
/*--------------------.
| Free the struniqs. |
`--------------------*/
void
struniqs_free (void)
{
hash_free (struniqs_table);
}

46
src/struniq.h Normal file
View File

@@ -0,0 +1,46 @@
/* Keeping a unique copy of strings.
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 STRUNIQ_H_
# define STRUNIQ_H_
/*------------------------------------------------------.
| struniq_t -- pointers to unique copies of C strings. |
`------------------------------------------------------*/
typedef char *struniq_t;
/* Return the struniq for S. */
const struniq_t struniq_new (const char *s);
/*--------------------------------------.
| Initializing, destroying, debugging. |
`--------------------------------------*/
/* Create the string table. */
void struniqs_new (void);
/* Free all the memory allocated for symbols. */
void struniqs_free (void);
/* Report them all. */
void struniqs_print (void);
#endif /* !STRUNIQ_H_ */

View File

@@ -200,13 +200,8 @@ symbol_user_token_number_set (symbol_t *symbol,
static void static void
symbol_free (symbol_t *this) symbol_free (symbol_t *this)
{ {
#if 0 free (this->tag);
/* This causes crashes because one string can appear more free (this);
than once. */
XFREE (this->type_name);
#endif
XFREE (this->tag);
XFREE (this);
} }

View File

@@ -22,6 +22,7 @@
#ifndef SYMTAB_H_ #ifndef SYMTAB_H_
# define SYMTAB_H_ # define SYMTAB_H_
# include "struniq.h"
# include "location.h" # include "location.h"
# include "assoc.h" # include "assoc.h"
@@ -52,7 +53,7 @@ struct symbol_s
location_t location; location_t location;
/* Its %type and associated printer and destructor. */ /* Its %type and associated printer and destructor. */
char *type_name; struniq_t type_name;
char *destructor; char *destructor;
location_t destructor_location; location_t destructor_location;
char *printer; char *printer;