+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
#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));
}
/* 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.
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)
/* 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.
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;
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;
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;
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 *));
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.
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);
}
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
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;
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?! */
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 */
/* 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];
/* Number of bytes since the last newline. */
int deps_column;
-
-#ifdef __cplusplus
- ~cpp_reader () { cpp_cleanup (this); }
-#endif
};
#define CPP_FATAL_LIMIT 1000