]> andersk Git - splint.git/blobdiff - src/cpphash.c
Fixed all /*@i...@*/ tags (except 1).
[splint.git] / src / cpphash.c
index 04137ca080c7f3c1a21a63aafdc959a3a1144ee1..3716c2abb64d6485f25dddaf0d20e9531f870813 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** 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,8 +17,8 @@
 ** 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 information on splint: info@splint.org
+** To report a bug: splint-bug@splint.org
 ** For more information: http://www.splint.org
 */
 /*
@@ -51,8 +51,8 @@ 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 "llbasic.h"
+# include "splintMacros.nf"
+# include "basic.h"
 # include <string.h>
 # include "cpplib.h"
 # include "cpphash.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" <koma@focs.sei.co.jp>
              */
 
-             /*! 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
This page took 0.047898 seconds and 4 git commands to generate.