[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01-struniq.patch
From: |
Akim Demaille |
Subject: |
01-struniq.patch |
Date: |
Tue, 12 Nov 2002 08:44:03 +0100 |
Index: 0.3/ChangeLog
--- 0.3/ChangeLog Fri, 08 Nov 2002 16:19:16 +0100 akim (bison/d/40_ChangeLog
1.1 644)
+++ 0.3(w)/ChangeLog Fri, 08 Nov 2002 17:49:54 +0100 akim (bison/d/40_ChangeLog
1.1 644)
@@ -1,3 +1,16 @@
+2002-11-08 Akim Demaille <address@hidden>
+
+ * 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-07 Akim Demaille <address@hidden>
Let yyerror always receive the msg as last argument, so that
Index: 0.3/src/symtab.h
--- 0.3/src/symtab.h Fri, 08 Nov 2002 16:19:16 +0100 akim (bison/39_symtab.h
1.1 644)
+++ 0.3(w)/src/symtab.h Fri, 08 Nov 2002 17:16:25 +0100 akim (bison/39_symtab.h
1.1 644)
@@ -22,6 +22,7 @@
#ifndef SYMTAB_H_
# define SYMTAB_H_
+# include "struniq.h"
# include "location.h"
# include "assoc.h"
@@ -52,7 +53,7 @@
location_t location;
/* Its %type and associated printer and destructor. */
- char *type_name;
+ struniq_t type_name;
char *destructor;
location_t destructor_location;
char *printer;
Index: 0.3/src/symtab.c
--- 0.3/src/symtab.c Fri, 08 Nov 2002 16:19:16 +0100 akim (bison/40_symtab.c
1.1 644)
+++ 0.3(w)/src/symtab.c Fri, 08 Nov 2002 17:50:38 +0100 akim (bison/40_symtab.c
1.1 644)
@@ -200,13 +200,8 @@
static void
symbol_free (symbol_t *this)
{
-#if 0
- /* This causes crashes because one string can appear more
- than once. */
- XFREE (this->type_name);
-#endif
- XFREE (this->tag);
- XFREE (this);
+ free (this->tag);
+ free (this);
}
Index: 0.3/src/scan-gram.l
--- 0.3/src/scan-gram.l Fri, 08 Nov 2002 16:19:16 +0100 akim
(bison/46_scan-gram. 1.1 644)
+++ 0.3(w)/src/scan-gram.l Fri, 08 Nov 2002 17:36:52 +0100 akim
(bison/46_scan-gram. 1.1 644)
@@ -27,6 +27,7 @@
#include "mbswidth.h"
#include "complain.h"
#include "quote.h"
+#include "struniq.h"
#include "getargs.h"
#include "gram.h"
#include "reader.h"
@@ -317,7 +318,8 @@
"<"{tag}">" {
obstack_grow (&string_obstack, yytext + 1, yyleng - 2);
YY_OBS_FINISH;
- yylval->string = last_string;
+ yylval->struniq = struniq_new (last_string);
+ YY_OBS_FREE;
return TYPE;
}
Index: 0.3/src/reader.c
--- 0.3/src/reader.c Fri, 08 Nov 2002 16:19:16 +0100 akim (bison/b/0_reader.c
1.1 644)
+++ 0.3(w)/src/reader.c Fri, 08 Nov 2002 17:11:16 +0100 akim
(bison/b/0_reader.c 1.1 644)
@@ -96,7 +96,7 @@
- /*-------------------------------------------------------------------.
+/*-------------------------------------------------------------------.
| Return the merger index for a merging function named NAME, whose |
| arguments have type TYPE. Records the function, if new, in |
| merger_list. |
Index: 0.3/src/parse-gram.y
--- 0.3/src/parse-gram.y Fri, 08 Nov 2002 16:19:16 +0100 akim
(bison/b/5_parse-gram 1.1 644)
+++ 0.3(w)/src/parse-gram.y Fri, 08 Nov 2002 17:13:17 +0100 akim
(bison/b/5_parse-gram 1.1 644)
@@ -92,6 +92,7 @@
int integer;
char *string;
assoc_t assoc;
+ struniq_t struniq;
};
/* Define the tokens together with their human representation. */
@@ -460,7 +461,7 @@
break;
case TYPE:
- fprintf (file, " = <%s>", value->string);
+ fprintf (file, " = <%s>", value->struniq);
break;
case BRACED_CODE:
Index: 0.3/src/main.c
--- 0.3/src/main.c Fri, 08 Nov 2002 16:19:16 +0100 akim (bison/b/13_main.c 1.1
644)
+++ 0.3(w)/src/main.c Fri, 08 Nov 2002 17:50:24 +0100 akim (bison/b/13_main.c
1.1 644)
@@ -24,6 +24,7 @@
#include "bitset_stats.h"
#include "bitset.h"
#include "getargs.h"
+#include "struniq.h"
#include "symtab.h"
#include "gram.h"
#include "files.h"
@@ -63,6 +64,7 @@
if (trace_flag & trace_bitsets)
bitset_stats_enable ();
+ struniqs_new ();
muscle_init ();
/* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE
@@ -165,6 +167,7 @@
contains things such as user actions, prologue, epilogue etc. */
scanner_free ();
muscle_free ();
+ struniqs_free ();
/* If using alloca.c, flush the alloca'ed memory for the benefit of
people running Bison as a library in IDEs. */
#if C_ALLOCA
Index: 0.3/src/Makefile.am
--- 0.3/src/Makefile.am Fri, 08 Nov 2002 16:19:16 +0100 akim
(bison/b/39_Makefile.i 1.1 644)
+++ 0.3(w)/src/Makefile.am Fri, 08 Nov 2002 17:57:46 +0100 akim
(bison/b/39_Makefile.i 1.1 644)
@@ -180,6 +180,7 @@
scan-gram.l \
scan-skel.l \
state.c state.h \
+ struniq.c struniq.h \
symlist.c symlist.h \
symtab.c symtab.h \
system.h \
Index: 0.3/src/struniq.h
--- 0.3/src/struniq.h Fri, 08 Nov 2002 17:57:52 +0100 akim ()
+++ 0.3(w)/src/struniq.h Fri, 08 Nov 2002 17:01:58 +0100 akim
(bison/e/14_struniq.h 644)
@@ -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_ */
Index: 0.3/src/struniq.c
--- 0.3/src/struniq.c Fri, 08 Nov 2002 17:57:52 +0100 akim ()
+++ 0.3(w)/src/struniq.c Fri, 08 Nov 2002 17:26:54 +0100 akim
(bison/e/15_struniq.c 644)
@@ -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);
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 01-struniq.patch,
Akim Demaille <=