Commit 638d694d by Zack Weinberg Committed by Zack Weinberg

cppfiles.c (redundant_include_p): Provide length of token to cpp_defined.

	* cppfiles.c (redundant_include_p): Provide length of token to
	cpp_defined.
	* cpphash.c (_cpp_make_hashnode, _cpp_lookup_slot): Hash
	values are unsigned int.
	(_cpp_lookup, _cpp_lookup_slot): Do not calculate the length.
	(_cpp_lookup_slot): Do not calculate the hash, either.
	* cpphash.h: Update prototypes.
	* cpplib.c (do_define, do_undef, do_pragma_poison, do_assert):
	Hashes are unsigned int.  Calculate hash here, pass by value
	to _cpp_lookup_slot.

From-SVN: r33551
parent 3f49b842
2000-04-30 Zack Weinberg <zack@wolery.cumb.org>
* cppfiles.c (redundant_include_p): Provide length of token to
cpp_defined.
* cpphash.c (_cpp_make_hashnode, _cpp_lookup_slot): Hash
values are unsigned int.
(_cpp_lookup, _cpp_lookup_slot): Do not calculate the length.
(_cpp_lookup_slot): Do not calculate the hash, either.
* cpphash.h: Update prototypes.
* cpplib.c (do_define, do_undef, do_pragma_poison, do_assert):
Hashes are unsigned int. Calculate hash here, pass by value
to _cpp_lookup_slot.
2000-04-30 Bernd Schmidt <bernds@cygnus.co.uk> 2000-04-30 Bernd Schmidt <bernds@cygnus.co.uk>
* simplify-rtx.c (check_value_useless): Delete function. * simplify-rtx.c (check_value_useless): Delete function.
......
...@@ -132,7 +132,8 @@ redundant_include_p (pfile, ihash, ilist) ...@@ -132,7 +132,8 @@ redundant_include_p (pfile, ihash, ilist)
included again if the string is the name of a defined macro. */ included again if the string is the name of a defined macro. */
return (i->control_macro return (i->control_macro
&& (i->control_macro[0] == '\0' && (i->control_macro[0] == '\0'
|| cpp_defined (pfile, i->control_macro, -1))) || cpp_defined (pfile, i->control_macro,
strlen (i->control_macro))))
? (IHASH *)-1 : i; ? (IHASH *)-1 : i;
return 0; return 0;
......
...@@ -246,7 +246,7 @@ _cpp_make_hashnode (name, len, type, hash) ...@@ -246,7 +246,7 @@ _cpp_make_hashnode (name, len, type, hash)
const U_CHAR *name; const U_CHAR *name;
size_t len; size_t len;
enum node_type type; enum node_type type;
unsigned long hash; unsigned int hash;
{ {
HASHNODE *hp = (HASHNODE *) xmalloc (sizeof (HASHNODE)); HASHNODE *hp = (HASHNODE *) xmalloc (sizeof (HASHNODE));
U_CHAR *p = xmalloc (len + 1); U_CHAR *p = xmalloc (len + 1);
...@@ -263,11 +263,7 @@ _cpp_make_hashnode (name, len, type, hash) ...@@ -263,11 +263,7 @@ _cpp_make_hashnode (name, len, type, hash)
return hp; return hp;
} }
/* Find the hash node for name "name", which ends at the first /* Find the hash node for name "name", of length LEN. */
non-identifier char.
If LEN is >= 0, it is the length of the name.
Otherwise, compute the length now. */
HASHNODE * HASHNODE *
_cpp_lookup (pfile, name, len) _cpp_lookup (pfile, name, len)
...@@ -278,12 +274,6 @@ _cpp_lookup (pfile, name, len) ...@@ -278,12 +274,6 @@ _cpp_lookup (pfile, name, len)
const U_CHAR *bp; const U_CHAR *bp;
HASHNODE dummy; HASHNODE dummy;
if (len < 0)
{
for (bp = name; is_idchar (*bp); bp++);
len = bp - name;
}
dummy.name = name; dummy.name = name;
dummy.length = len; dummy.length = len;
dummy.hash = _cpp_calc_hash (name, len); dummy.hash = _cpp_calc_hash (name, len);
...@@ -300,30 +290,18 @@ _cpp_lookup_slot (pfile, name, len, insert, hash) ...@@ -300,30 +290,18 @@ _cpp_lookup_slot (pfile, name, len, insert, hash)
const U_CHAR *name; const U_CHAR *name;
int len; int len;
enum insert_option insert; enum insert_option insert;
unsigned long *hash; unsigned int hash;
{ {
const U_CHAR *bp; const U_CHAR *bp;
HASHNODE dummy; HASHNODE dummy;
HASHNODE **slot;
if (len < 0)
{
for (bp = name; is_idchar (*bp); bp++)
;
len = bp - name;
}
dummy.name = name; dummy.name = name;
dummy.length = len; dummy.length = len;
dummy.hash = _cpp_calc_hash (name, len); dummy.hash = hash;
slot = (HASHNODE **) htab_find_slot_with_hash (pfile->hashtab, return (HASHNODE **) htab_find_slot_with_hash (pfile->hashtab,
(void *) &dummy, (void *) &dummy,
dummy.hash, insert); dummy.hash, insert);
if (insert)
*hash = dummy.hash;
return slot;
} }
/* Init the hash table. In here so it can see the hash and eq functions. */ /* Init the hash table. In here so it can see the hash and eq functions. */
......
...@@ -103,7 +103,7 @@ struct ihash ...@@ -103,7 +103,7 @@ struct ihash
Used for include_next */ Used for include_next */
struct file_name_list *foundhere; struct file_name_list *foundhere;
unsigned long hash; /* save hash value for future reference */ unsigned int hash; /* save hash value for future reference */
const char *nshort; /* name of file as referenced in #include; const char *nshort; /* name of file as referenced in #include;
points into name[] */ points into name[] */
const U_CHAR *control_macro; /* macro, if any, preventing reinclusion - const U_CHAR *control_macro; /* macro, if any, preventing reinclusion -
...@@ -212,14 +212,14 @@ extern unsigned char _cpp_IStable[256]; ...@@ -212,14 +212,14 @@ extern unsigned char _cpp_IStable[256];
/* In cpphash.c */ /* In cpphash.c */
extern HASHNODE *_cpp_make_hashnode PARAMS ((const U_CHAR *, size_t, extern HASHNODE *_cpp_make_hashnode PARAMS ((const U_CHAR *, size_t,
enum node_type, enum node_type,
unsigned long)); unsigned int));
extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t)); extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t));
extern HASHNODE *_cpp_lookup PARAMS ((cpp_reader *, extern HASHNODE *_cpp_lookup PARAMS ((cpp_reader *,
const U_CHAR *, int)); const U_CHAR *, int));
extern HASHNODE **_cpp_lookup_slot PARAMS ((cpp_reader *, extern HASHNODE **_cpp_lookup_slot PARAMS ((cpp_reader *,
const U_CHAR *, int, const U_CHAR *, int,
enum insert_option, enum insert_option,
unsigned long *)); unsigned int));
extern void _cpp_free_definition PARAMS ((HASHNODE *)); extern void _cpp_free_definition PARAMS ((HASHNODE *));
extern int _cpp_create_definition PARAMS ((cpp_reader *, extern int _cpp_create_definition PARAMS ((cpp_reader *,
cpp_toklist *, HASHNODE *)); cpp_toklist *, HASHNODE *));
......
...@@ -339,7 +339,7 @@ do_define (pfile) ...@@ -339,7 +339,7 @@ do_define (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
HASHNODE **slot; HASHNODE **slot;
unsigned long hash; unsigned int hash;
int len; int len;
U_CHAR *sym; U_CHAR *sym;
cpp_toklist *list = &pfile->directbuf; cpp_toklist *list = &pfile->directbuf;
...@@ -371,7 +371,8 @@ do_define (pfile) ...@@ -371,7 +371,8 @@ do_define (pfile)
goto out; goto out;
} }
slot = _cpp_lookup_slot (pfile, sym, len, INSERT, &hash); hash = _cpp_calc_hash (sym, len);
slot = _cpp_lookup_slot (pfile, sym, len, INSERT, hash);
if (*slot) if (*slot)
{ {
/* Check for poisoned identifiers now. All other checks /* Check for poisoned identifiers now. All other checks
...@@ -686,6 +687,7 @@ do_undef (pfile) ...@@ -686,6 +687,7 @@ do_undef (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
int len; int len;
unsigned int hash;
HASHNODE **slot; HASHNODE **slot;
U_CHAR *name; U_CHAR *name;
long here = CPP_WRITTEN (pfile); long here = CPP_WRITTEN (pfile);
...@@ -713,7 +715,8 @@ do_undef (pfile) ...@@ -713,7 +715,8 @@ do_undef (pfile)
name = pfile->token_buffer + here; name = pfile->token_buffer + here;
CPP_SET_WRITTEN (pfile, here); CPP_SET_WRITTEN (pfile, here);
slot = _cpp_lookup_slot (pfile, name, len, NO_INSERT, 0); hash = _cpp_calc_hash (name, len);
slot = _cpp_lookup_slot (pfile, name, len, NO_INSERT, hash);
if (slot) if (slot)
{ {
HASHNODE *hp = *slot; HASHNODE *hp = *slot;
...@@ -949,7 +952,7 @@ do_pragma_poison (pfile) ...@@ -949,7 +952,7 @@ do_pragma_poison (pfile)
size_t len; size_t len;
enum cpp_ttype token; enum cpp_ttype token;
int writeit; int writeit;
unsigned long hash; unsigned int hash;
/* As a rule, don't include #pragma poison commands in output, /* As a rule, don't include #pragma poison commands in output,
unless the user asks for them. */ unless the user asks for them. */
...@@ -972,7 +975,8 @@ do_pragma_poison (pfile) ...@@ -972,7 +975,8 @@ do_pragma_poison (pfile)
p = pfile->token_buffer + written; p = pfile->token_buffer + written;
len = CPP_PWRITTEN (pfile) - p; len = CPP_PWRITTEN (pfile) - p;
slot = _cpp_lookup_slot (pfile, p, len, INSERT, &hash); hash = _cpp_calc_hash (p, len);
slot = _cpp_lookup_slot (pfile, p, len, INSERT, hash);
if (*slot) if (*slot)
{ {
HASHNODE *hp = *slot; HASHNODE *hp = *slot;
...@@ -1507,7 +1511,7 @@ do_assert (pfile) ...@@ -1507,7 +1511,7 @@ do_assert (pfile)
HASHNODE *base, *this; HASHNODE *base, *this;
HASHNODE **bslot, **tslot; HASHNODE **bslot, **tslot;
size_t blen, tlen; size_t blen, tlen;
unsigned long bhash, thash; unsigned int bhash, thash;
old_written = CPP_WRITTEN (pfile); /* remember where it starts */ old_written = CPP_WRITTEN (pfile); /* remember where it starts */
ret = _cpp_parse_assertion (pfile); ret = _cpp_parse_assertion (pfile);
...@@ -1528,14 +1532,16 @@ do_assert (pfile) ...@@ -1528,14 +1532,16 @@ do_assert (pfile)
sym = pfile->token_buffer + old_written; sym = pfile->token_buffer + old_written;
blen = (U_CHAR *) strchr (sym, '(') - sym; blen = (U_CHAR *) strchr (sym, '(') - sym;
tslot = _cpp_lookup_slot (pfile, sym, tlen, INSERT, &thash); thash = _cpp_calc_hash (sym, tlen);
tslot = _cpp_lookup_slot (pfile, sym, tlen, INSERT, thash);
if (*tslot) if (*tslot)
{ {
cpp_warning (pfile, "%s re-asserted", sym); cpp_warning (pfile, "%s re-asserted", sym);
goto error; goto error;
} }
bslot = _cpp_lookup_slot (pfile, sym, blen, INSERT, &bhash); bhash = _cpp_calc_hash (sym, blen);
bslot = _cpp_lookup_slot (pfile, sym, blen, INSERT, bhash);
if (! *bslot) if (! *bslot)
{ {
*bslot = base = _cpp_make_hashnode (sym, blen, T_ASSERT, bhash); *bslot = base = _cpp_make_hashnode (sym, blen, T_ASSERT, bhash);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment