aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorZack Weinberg <zack@rabi.columbia.edu>1999-02-25 14:24:40 +0000
committerZack Weinberg <zack@gcc.gnu.org>1999-02-25 14:24:40 +0000
commit122ae89b144a0eaf31107f871f26ead27df8daad (patch)
tree6a70d45559c3b1a18fd0998b7705e78d86303259 /gcc
parent9ab70a9bd7c8ee4fcf2f074459525e981ed1ca2e (diff)
downloadgcc-122ae89b144a0eaf31107f871f26ead27df8daad.zip
gcc-122ae89b144a0eaf31107f871f26ead27df8daad.tar.gz
gcc-122ae89b144a0eaf31107f871f26ead27df8daad.tar.bz2
cpphash.c (install): Rename to cpp_install, add cpp_reader* first argument.
1999-02-25 17:14 -0500 Zack Weinberg <zack@rabi.columbia.edu> * cpphash.c (install): Rename to cpp_install, add cpp_reader* first argument. All callers changed. (hashtab): Removed. (cpp_lookup, cpp_install): Change all refs to hashtab to pfile->hashtab. (cpp_hash_cleanup): Removed. * cpphash.h: Adjust prototypes. * cpplib.h (struct cpp_reader): Add hashtab pointer. * cppinit.c (cpp_reader_init): Also allocate space for the hashtab. (cpp_cleanup): Delete all macros and free the hashtab. From-SVN: r25441
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog14
-rw-r--r--gcc/cpphash.c29
-rw-r--r--gcc/cpphash.h10
-rw-r--r--gcc/cppinit.c39
-rw-r--r--gcc/cpplib.c10
-rw-r--r--gcc/cpplib.h8
6 files changed, 58 insertions, 52 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 83e85e3..4c618ae 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,17 @@
+1999-02-25 17:14 -0500 Zack Weinberg <zack@rabi.columbia.edu>
+
+ * cpphash.c (install): Rename to cpp_install, add cpp_reader*
+ first argument. All callers changed.
+ (hashtab): Removed.
+ (cpp_lookup, cpp_install): Change all refs to hashtab to
+ pfile->hashtab.
+ (cpp_hash_cleanup): Removed.
+ * cpphash.h: Adjust prototypes.
+ * cpplib.h (struct cpp_reader): Add hashtab pointer.
+ * cppinit.c (cpp_reader_init): Also allocate space for the
+ hashtab.
+ (cpp_cleanup): Delete all macros and free the hashtab.
+
Thu Feb 25 21:52:54 1999 J"orn Rennecke <amylaar@cygnus.co.uk>
* sh.h (PASS_IN_REG_P): For TARGET_HITACHI, don't pass structures
diff --git a/gcc/cpphash.c b/gcc/cpphash.c
index a9061a9..0f95d8a 100644
--- a/gcc/cpphash.c
+++ b/gcc/cpphash.c
@@ -27,8 +27,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cpplib.h"
#include "cpphash.h"
-static HASHNODE *hashtab[HASHSIZE];
-
static int comp_def_part PARAMS ((int, U_CHAR *, int, U_CHAR *,
int, int));
static int change_newlines PARAMS ((U_CHAR *, int));
@@ -104,7 +102,7 @@ hashf (name, len, hashsize)
}
/* Find the most recent hash node for name "name" (ending with first
- non-identifier char) installed by install
+ non-identifier char) installed by cpp_install
If LEN is >= 0, it is the length of the name.
Otherwise, compute the length by scanning the entire name.
@@ -131,7 +129,7 @@ cpp_lookup (pfile, name, len, hash)
if (hash < 0)
hash = hashf (name, len, HASHSIZE);
- bucket = hashtab[hash];
+ bucket = pfile->hashtab[hash];
while (bucket)
{
if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
@@ -191,7 +189,7 @@ delete_macro (hp)
/* Install a name in the main hash table, even if it is already there.
Name stops with first non alphanumeric, except leading '#'.
Caller must check against redefinition if that is desired.
- delete_macro () removes things installed by install () in fifo order.
+ delete_macro () removes things installed by cpp_install () in fifo order.
this is important because of the `defined' special symbol used
in #if, and also if pushdef/popdef directives are ever implemented.
@@ -202,7 +200,8 @@ delete_macro (hp)
Otherwise, compute the hash code. */
HASHNODE *
-install (name, len, type, value, hash)
+cpp_install (pfile, name, len, type, value, hash)
+ cpp_reader *pfile;
U_CHAR *name;
int len;
enum node_type type;
@@ -227,9 +226,9 @@ install (name, len, type, value, hash)
i = sizeof (HASHNODE) + len + 1;
hp = (HASHNODE *) xmalloc (i);
bucket = hash;
- hp->bucket_hdr = &hashtab[bucket];
- hp->next = hashtab[bucket];
- hashtab[bucket] = hp;
+ hp->bucket_hdr = &pfile->hashtab[bucket];
+ hp->next = pfile->hashtab[bucket];
+ pfile->hashtab[bucket] = hp;
hp->prev = NULL;
if (hp->next != NULL)
hp->next->prev = hp;
@@ -242,18 +241,6 @@ install (name, len, type, value, hash)
return hp;
}
-void
-cpp_hash_cleanup (pfile)
- cpp_reader *pfile ATTRIBUTE_UNUSED;
-{
- register int i;
- for (i = HASHSIZE; --i >= 0;)
- {
- while (hashtab[i])
- delete_macro (hashtab[i]);
- }
-}
-
static int
macro_cleanup (pbuf, pfile)
cpp_buffer *pbuf;
diff --git a/gcc/cpphash.h b/gcc/cpphash.h
index 7f7f7d6..d304f1a 100644
--- a/gcc/cpphash.h
+++ b/gcc/cpphash.h
@@ -45,18 +45,16 @@ typedef struct hashnode HASHNODE;
the hashf () function. Hashf () only exists for the sake of
politeness, for use when speed isn't so important. */
-#define HASHSIZE 1403
#define HASHSTEP(old, c) ((old << 2) + c)
#define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */
-extern HASHNODE *install PARAMS ((U_CHAR *, int, enum node_type,
- const char *, int));
-extern int hashf PARAMS ((const U_CHAR *, int, int));
-extern void delete_macro PARAMS ((HASHNODE *));
+extern HASHNODE *cpp_install PARAMS ((cpp_reader *, U_CHAR *, int,
+ enum node_type, const char *, int));
+extern int hashf PARAMS ((const U_CHAR *, int, int));
+extern void delete_macro PARAMS ((HASHNODE *));
extern MACRODEF create_definition PARAMS ((U_CHAR *, U_CHAR *,
cpp_reader *, int));
extern int compare_defs PARAMS ((cpp_reader *, DEFINITION *,
DEFINITION *));
extern void macroexpand PARAMS ((cpp_reader *, HASHNODE *));
-extern void cpp_hash_cleanup PARAMS ((cpp_reader *));
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index d410199..551d922 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -452,6 +452,8 @@ cpp_reader_init (pfile)
pfile->token_buffer_size = 200;
pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
CPP_SET_WRITTEN (pfile, 0);
+
+ pfile->hashtab = (HASHNODE **) xcalloc (HASHSIZE, sizeof (HASHNODE *));
}
/* Free resources used by PFILE.
@@ -500,7 +502,12 @@ cpp_cleanup (pfile)
pfile->all_include_files[i] = 0;
}
- cpp_hash_cleanup (pfile);
+ for (i = HASHSIZE; --i >= 0;)
+ {
+ while (pfile->hashtab[i])
+ delete_macro (pfile->hashtab[i]);
+ }
+ free (pfile->hashtab);
}
@@ -510,31 +517,31 @@ initialize_builtins (pfile)
cpp_reader *pfile;
{
#define NAME(str) (U_CHAR *)str, sizeof str - 1
- install (NAME("__TIME__"), T_TIME, 0, -1);
- install (NAME("__DATE__"), T_DATE, 0, -1);
- install (NAME("__FILE__"), T_FILE, 0, -1);
- install (NAME("__BASE_FILE__"), T_BASE_FILE, 0, -1);
- install (NAME("__LINE__"), T_SPECLINE, 0, -1);
- install (NAME("__INCLUDE_LEVEL__"), T_INCLUDE_LEVEL, 0, -1);
- install (NAME("__VERSION__"), T_VERSION, 0, -1);
+ cpp_install (pfile, NAME("__TIME__"), T_TIME, 0, -1);
+ cpp_install (pfile, NAME("__DATE__"), T_DATE, 0, -1);
+ cpp_install (pfile, NAME("__FILE__"), T_FILE, 0, -1);
+ cpp_install (pfile, NAME("__BASE_FILE__"), T_BASE_FILE, 0, -1);
+ cpp_install (pfile, NAME("__LINE__"), T_SPECLINE, 0, -1);
+ cpp_install (pfile, NAME("__INCLUDE_LEVEL__"), T_INCLUDE_LEVEL, 0, -1);
+ cpp_install (pfile, NAME("__VERSION__"), T_VERSION, 0, -1);
#ifndef NO_BUILTIN_SIZE_TYPE
- install (NAME("__SIZE_TYPE__"), T_CONST, SIZE_TYPE, -1);
+ cpp_install (pfile, NAME("__SIZE_TYPE__"), T_CONST, SIZE_TYPE, -1);
#endif
#ifndef NO_BUILTIN_PTRDIFF_TYPE
- install (NAME("__PTRDIFF_TYPE__ "), T_CONST, PTRDIFF_TYPE, -1);
+ cpp_install (pfile, NAME("__PTRDIFF_TYPE__ "), T_CONST, PTRDIFF_TYPE, -1);
#endif
- install (NAME("__WCHAR_TYPE__"), T_CONST, WCHAR_TYPE, -1);
- install (NAME("__USER_LABEL_PREFIX__"), T_CONST, user_label_prefix, -1);
- install (NAME("__REGISTER_PREFIX__"), T_CONST, REGISTER_PREFIX, -1);
+ cpp_install (pfile, NAME("__WCHAR_TYPE__"), T_CONST, WCHAR_TYPE, -1);
+ cpp_install (pfile, NAME("__USER_LABEL_PREFIX__"), T_CONST, user_label_prefix, -1);
+ cpp_install (pfile, NAME("__REGISTER_PREFIX__"), T_CONST, REGISTER_PREFIX, -1);
if (!CPP_TRADITIONAL (pfile))
{
- install (NAME("__STDC__"), T_STDC, 0, -1);
+ cpp_install (pfile, NAME("__STDC__"), T_STDC, 0, -1);
#if 0
if (CPP_OPTIONS (pfile)->c9x)
- install (NAME("__STDC_VERSION__"),T_CONST, "199909L", -1);
+ cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199909L", -1);
else
#endif
- install (NAME("__STDC_VERSION__"),T_CONST, "199409L", -1);
+ cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199409L", -1);
}
#undef NAME
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index d7499dd..26536e9 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -657,8 +657,8 @@ do_define (pfile, keyword)
that for this new definition now. */
if (CPP_OPTIONS (pfile)->debug_output && keyword)
pass_thru_directive (macro, end, pfile, keyword);
- install (mdef.symnam, mdef.symlen, T_MACRO,
- (char *) mdef.defn, hashcode);
+ cpp_install (pfile, mdef.symnam, mdef.symlen, T_MACRO,
+ (char *) mdef.defn, hashcode);
}
return 0;
@@ -2845,7 +2845,7 @@ do_assert (pfile, keyword)
base = cpp_lookup (pfile, sym, baselen, -1);
if (! base)
- base = install (sym, baselen, T_ASSERT, 0, -1);
+ base = cpp_install (pfile, sym, baselen, T_ASSERT, 0, -1);
else if (base->type != T_ASSERT)
{
/* Token clash - but with what?! */
@@ -2854,8 +2854,8 @@ do_assert (pfile, keyword)
goto error;
}
- this = install (sym, thislen, T_ASSERT,
- (char *)base->value.aschain, -1);
+ this = cpp_install (pfile, sym, thislen, T_ASSERT,
+ (char *)base->value.aschain, -1);
base->value.aschain = this;
pfile->limit = sym; /* Pop */
diff --git a/gcc/cpplib.h b/gcc/cpplib.h
index a943939..9ce1463 100644
--- a/gcc/cpplib.h
+++ b/gcc/cpplib.h
@@ -181,6 +181,10 @@ struct cpp_reader
/* Current depth of buffer stack. */
int buffer_stack_depth;
+ /* Hash table of macros and assertions. See cpphash.c */
+#define HASHSIZE 1403
+ struct hashnode **hashtab;
+
/* Hash table of other included files. See cppfiles.c */
#define ALL_INCLUDE_HASHSIZE 71
struct include_hash *all_include_files[ALL_INCLUDE_HASHSIZE];
@@ -245,10 +249,6 @@ struct cpp_reader
/* Number of bytes since the last newline. */
int deps_column;
-
-#ifdef __cplusplus
- ~cpp_reader () { cpp_cleanup (this); }
-#endif
};
#define CPP_FATAL_LIMIT 1000