X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/b072092f32623dab70e6ffe1613740542ea66748..35b9a1d988c06908076e3a6eeae55b1147879607:/src/cpphash.c?ds=sidebyside diff --git a/src/cpphash.c b/src/cpphash.c index beefb29..937af05 100644 --- a/src/cpphash.c +++ b/src/cpphash.c @@ -1,6 +1,6 @@ /* -** LCLint - annotation-assisted static program checker -** Copyright (C) 1994-2001 University of Virginia, +** Splint - annotation-assisted static program checker +** Copyright (C) 1994-2003 University of Virginia, ** Massachusetts Institute of Technology ** ** This program is free software; you can redistribute it and/or modify it @@ -17,9 +17,9 @@ ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ** MA 02111-1307, USA. ** -** For information on lclint: lclint-request@cs.virginia.edu -** To report a bug: lclint-bug@cs.virginia.edu -** For more information: http://lclint.cs.virginia.edu +** For information on splint: info@splint.org +** To report a bug: splint-bug@splint.org +** For more information: http://www.splint.org */ /* ** cpphash.c @@ -51,7 +51,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "llbasic.h" # include # include "cpplib.h" @@ -172,7 +172,7 @@ static void hashNode_delete (/*@only@*/ /*@null@*/ hashNode node) for (ap = d->pattern; ap != NULL; ap = nextap) { - struct reflist *npattern = dmalloc (sizeof (*(nd->pattern))); + struct reflist *npattern = dmalloc (sizeof (* (nd->pattern))); nextap = ap->next; @@ -182,7 +182,7 @@ static void hashNode_delete (/*@only@*/ /*@null@*/ hashNode node) /*@-branchstate@*/ } /*@=branchstate@*/ /* npattern is propagated through loop */ - last = &(npattern->next); + last = & (npattern->next); npattern->next = NULL; /* will get filled in */ npattern->stringify = d->pattern->stringify; npattern->raw_before = d->pattern->raw_before; @@ -213,7 +213,7 @@ static void hashNode_delete (/*@only@*/ /*@null@*/ hashNode node) ** From: "N.Komazaki" */ - /*! why doesn't lclint report an error for this? */ + /*! why doesn't splint report an error for this? */ nd->args.argnames = mstring_createEmpty (); } } @@ -244,7 +244,7 @@ static void hashNode_delete (/*@only@*/ /*@null@*/ hashNode node) computed a step at a time, elsewhere */ int -hashf (const char *name, int len, int hashsize) +cpphash_hashCode (const char *name, size_t len, int hashsize) { unsigned int r = 0; @@ -258,16 +258,16 @@ hashf (const char *name, int len, int hashsize) /* ** Find the most recent hash node for name name (ending with first -** non-identifier char) cppReader_installed by install +** non-identifier char) cpphash_installed by install ** -** If LEN is >= 0, it is the length of the name. +** If len is >= 0, it is the length of the name. ** Otherwise, compute the length by scanning the entire name. ** -** If HASH is >= 0, it is the precomputed hash code. +** If hash is >= 0, it is the precomputed hash code. ** Otherwise, compute the hash code. */ -/*@null@*/ hashNode cppReader_lookup (char *name, int len, int hash) +/*@null@*/ hashNode cpphash_lookup (char *name, int len, int hash) { const char *bp; hashNode bucket; @@ -284,15 +284,15 @@ hashf (const char *name, int len, int hashsize) if (hash < 0) { - hash = hashf (name, len, CPP_HASHSIZE); + hash = cpphash_hashCode (name, size_fromInt (len), CPP_HASHSIZE); } bucket = hashtab[hash]; while (bucket != NULL) { - if (bucket->length == len && - cstring_equalLen (bucket->name, cstring_fromChars (name), len)) + if (bucket->length == size_fromInt (len) && + cstring_equalLen (bucket->name, cstring_fromChars (name), size_fromInt (len))) { return bucket; } @@ -303,9 +303,9 @@ hashf (const char *name, int len, int hashsize) return NULL; } -/*@null@*/ hashNode cppReader_lookupExpand (char *name, int len, int hash) +/*@null@*/ hashNode cpphash_lookupExpand (char *name, int len, int hash, bool forceExpand) { - hashNode node = cppReader_lookup (name, len, hash); + hashNode node = cpphash_lookup (name, len, hash); DPRINTF (("Lookup expand: %s", name)); @@ -317,7 +317,7 @@ hashf (const char *name, int len, int hashsize) DPRINTF (("Check macro...")); - if (defn->noExpand) { + if (defn->noExpand && !forceExpand) { DPRINTF (("No expand!")); return NULL; } @@ -359,6 +359,10 @@ cppReader_deleteMacro (hashNode hp) /* make sure that the bucket chain header that the deleted guy was on points to the right thing afterwards. */ + + llassert (hp != NULL); + llassert (hp->bucket_hdr != NULL); + if (hp == *hp->bucket_hdr) { *hp->bucket_hdr = hp->next; } @@ -398,14 +402,14 @@ cppReader_deleteMacro (hashNode hp) If HASH is >= 0, it is the precomputed hash code. Otherwise, compute the hash code. */ -hashNode cppReader_install (char *name, int len, enum node_type type, +hashNode cpphash_install (char *name, int len, enum node_type type, int ivalue, char *value, int hash) { hashNode hp; - int i, bucket; + int bucket; char *p; - DPRINTF (("Install: %s", name)); + DPRINTF (("Install: %s / %d", name, len)); if (len < 0) { p = name; @@ -420,11 +424,9 @@ hashNode cppReader_install (char *name, int len, enum node_type type, if (hash < 0) { - hash = hashf (name, len, CPP_HASHSIZE); + hash = cpphash_hashCode (name, size_fromInt (len), CPP_HASHSIZE); } - i = sizeof (*hp) + len + 1; - hp = (hashNode) dmalloc (sizeof (*hp)); bucket = hash; hp->bucket_hdr = &hashtab[bucket]; @@ -437,11 +439,10 @@ hashNode cppReader_install (char *name, int len, enum node_type type, hp->next->prev = hp; } - hashtab[bucket] = hp; hp->type = type; - hp->length = len; + hp->length = size_fromInt (len); if (hp->type == T_CONST) { @@ -453,7 +454,7 @@ hashNode cppReader_install (char *name, int len, enum node_type type, hp->value.cpval = value; } - hp->name = cstring_clip (cstring_fromCharsNew (name), len); + hp->name = cstring_clip (cstring_fromCharsNew (name), size_fromInt (len)); DPRINTF (("Name: *%s*", hp->name)); /*@-mustfree@*/ /*@-uniondef@*/ /*@-compdef@*/ /*@-compmempass@*/ @@ -461,10 +462,11 @@ hashNode cppReader_install (char *name, int len, enum node_type type, /*@=mustfree@*/ /*@=uniondef@*/ /*@=compdef@*/ /*@=compmempass@*/ } -hashNode cppReader_installMacro (char *name, int len, +hashNode cpphash_installMacro (char *name, size_t len, struct definition *defn, int hash) { - return cppReader_install (name, len, T_MACRO, 0, (char *) defn, hash); + DPRINTF (("install macro: %s", name)); + return cpphash_install (name, size_toInt (len), T_MACRO, 0, (char *) defn, hash); } void