]> andersk Git - splint.git/blobdiff - src/abstract.c
Committing after merging Evan's changes.
[splint.git] / src / abstract.c
index dc4d135088314c54ca29f444b319cb489393bd82..3e95eaea3c3e6ac6d753026b142c5f0db2e78e61 100644 (file)
@@ -1,6 +1,6 @@
 /*
-** LCLint - annotation-assisted static program checker
-** Copyright (C) 1994-2000 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
 */
 /*
 ** abstract.c
@@ -34,7 +34,7 @@
 **         Massachusetts Institute of Technology
 */
 
-# include "lclintMacros.nf"
+# include "splintMacros.nf"
 # include "llbasic.h"
 # include "lslparse.h"
 # include "llgrammar.h"        /* need simpleOp, MULOP and logicalOp in makeInfixTermNode */
@@ -102,7 +102,7 @@ resetImports (cstring current)
 
   g_currentImports = lsymbolSet_new ();        /* equal_symbol; */
   (void) lsymbolSet_insert (g_currentImports, 
-                             lsymbol_fromChars (cstring_toCharsSafe (current)));
+                             lsymbol_fromString (current));
 }
 
 void
@@ -186,7 +186,7 @@ abstract_init ()
   ti->modifiable = FALSE;
   ti->abstract = FALSE;
   ti->export = FALSE;          /* this is implicit, not exported */
-  ti->basedOn = sort_float;
+  ti->basedOn = g_sortFloat;
   symtable_enterType (g_symtab, ti);
 }
 
@@ -236,15 +236,15 @@ void LCLBuiltins (void)
 
   ti->modifiable = FALSE;
   ti->abstract = TRUE;
-  ti->basedOn = sort_bool;
-  ti->export = FALSE; /* this wasn't set (detected by lclint) */
+  ti->basedOn = g_sortBool;
+  ti->export = FALSE; /* this wasn't set (detected by Splint) */
   symtable_enterType (g_symtab, ti);
   
   /* do "constant bool FALSE = false;" */
   vi->id = ltoken_createType (simpleId, SID_VAR, lsymbol_fromChars ("FALSE"));
 
   vi->kind = VRK_CONST;
-  vi->sort = sort_bool;
+  vi->sort = g_sortBool;
   vi->export = TRUE;
 
   (void) symtable_enterVar (g_symtab, vi);
@@ -276,7 +276,7 @@ LCLBootstrap (void)
  
   s = sort_makeImmutable (ltoken_undefined, lsymbol_bool);
   range = ltoken_create (simpleId, lsymbol_bool);
-  sign = makesigNode (ltoken_undefined, ltokenList_new (), range);
+  sign = makesigNode (ltoken_undefined, ltokenList_new (),  range);
 
   nn1 = (nameNode) dmalloc (sizeof (*nn1));
   nn1->isOpId = TRUE;
@@ -487,7 +487,7 @@ interfaceNode_makePrivFcn (/*@only@*/ fcnNode x)
   privateNode e = (privateNode) dmalloc (sizeof (*e));
 
   /*
-  ** bug detected by lclint enum checking
+  ** bug detected by enum checking
   ** e->kind = XPK_FCN;
   */
 
@@ -935,7 +935,7 @@ sort_member_modulo_cstring (sort s, /*@null@*/ termNode t)
 
          sn = sort_lookup (s);
 
-         if (sn.kind == SRT_PTR)
+         if (sn->kind == SRT_PTR)
            {
              char *lit = lsymbol_toChars (ltoken_getText (t->literal));
              
@@ -980,7 +980,7 @@ sort_member_modulo_cstring (sort s, /*@null@*/ termNode t)
        {
          errtok = termNode_errorToken (term);
          
-         /*      errorShowPoint (tsource_thisLine (lclsource), ltoken_getCol (errtok)); */
+         /*      errorShowPoint (inputStream_thisLine (lclsource), ltoken_getCol (errtok)); */
          /*      sprintf (ERRMSG, "expect `%s' type but given term has `%s' type",
                  sort_unparse (s), sort_unparse (termsort)); */
          
@@ -1078,7 +1078,7 @@ importNode_makeBracketed (/*@only@*/ ltoken t)
 
 static cstring extractQuote (/*@only@*/ cstring s)
 {
-  int len = cstring_length (s);
+  size_t len = cstring_length (s);
   char *sc = cstring_toCharsSafe (s);
   cstring t;
 
@@ -1097,7 +1097,7 @@ importNode_makeQuoted (/*@only@*/ ltoken t)
 
   imp->kind = IMPQUOTE;
 
-  ltoken_setRawText (t, lsymbol_fromChars (cstring_toCharsSafe (q)));
+  ltoken_setRawText (t, lsymbol_fromString (q));
 
   imp->val = t;  
 
@@ -1250,7 +1250,7 @@ makeReplaceNameNode (ltoken t, typeNameNode tn, nameNode nn)
   r->isCType = FALSE;
   r->typename = tn;
   r->content.renamesortname.name = nn;
-  r->content.renamesortname.signature = (sigNode)NULL;
+  r->content.renamesortname.signature = (sigNode) NULL;
   
   return (r);
 }
@@ -1365,7 +1365,7 @@ nameNode_unparse (/*@null@*/ nameNode n)
 makesigNode (ltoken t, /*@only@*/ ltokenList domain, ltoken range)
 {
   sigNode s = (sigNode) dmalloc (sizeof (*s));
-  unsigned int key;
+  unsigned long int key;
 
   /*
   ** Assign a hash key here to speed up lookup of operators.
@@ -1383,7 +1383,7 @@ makesigNode (ltoken t, /*@only@*/ ltokenList domain, ltoken range)
     } end_ltokenList_elements;
   
   s->key = key;
-    return (s);
+  return (s);
 }
 
 cstring sigNode_unparse (/*@null@*/ sigNode n)
@@ -1413,10 +1413,9 @@ sigNode_unparseText (/*@null@*/ sigNode n)
   return cstring_undefined;
 }
 
-static unsigned int
-  opFormNode2key (opFormNode op, opFormKind k)
+static unsigned long opFormNode2key (opFormNode op, opFormKind k)
 {
-  unsigned int key;
+  unsigned long int key;
 
   switch (k)
     {
@@ -1474,7 +1473,7 @@ makeOpFormNode (ltoken t, opFormKind k, opFormUnion u,
                ltoken close)
 {
   opFormNode n = (opFormNode) dmalloc (sizeof (*n));
-  unsigned int key = 0;
+  unsigned long int key = 0;
 
   /*
   ** Assign a hash key here to speed up lookup of operators.
@@ -1483,7 +1482,6 @@ makeOpFormNode (ltoken t, opFormKind k, opFormUnion u,
   n->tok = t;
   n->close = close;
   n->kind = k;
-
   
   switch (k)
     {
@@ -1536,7 +1534,7 @@ makeOpFormNode (ltoken t, opFormKind k, opFormUnion u,
       }
     }
   n->key = key;
-    return (n);
+  return (n);
 }
 
 static cstring printMiddle (int j)
@@ -1674,7 +1672,7 @@ makeLclTypeSpecNodeConj (/*@null@*/ lclTypeSpecNode a, /*@null@*/ lclTypeSpecNod
   lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
 
   n->kind = LTS_CONJ;
-  n->pointers = 0;
+  n->pointers = pointers_undefined;
   n->quals = qualList_new ();
   n->content.conj = (lclconj) dmalloc (sizeof (*n->content.conj));
   n->content.conj->a = a;
@@ -1689,7 +1687,7 @@ makeLclTypeSpecNodeType (/*@null@*/ CTypesNode x)
   lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
 
   n->kind = LTS_TYPE;
-  n->pointers = 0;
+  n->pointers = pointers_undefined;
   n->content.type = x;
   n->quals = qualList_new ();
   return (n);
@@ -1701,7 +1699,7 @@ makeLclTypeSpecNodeSU (/*@null@*/ strOrUnionNode x)
   lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
 
   n->kind = LTS_STRUCTUNION;
-  n->pointers = 0;
+  n->pointers = pointers_undefined;
   n->content.structorunion = x;
   n->quals = qualList_new ();
   return (n);
@@ -1714,7 +1712,7 @@ makeLclTypeSpecNodeEnum (/*@null@*/ enumSpecNode x)
 
   n->quals = qualList_new ();
   n->kind = LTS_ENUM;
-  n->pointers = 0;
+  n->pointers = pointers_undefined;
   n->content.enumspec = x;
   return (n);
 }
@@ -2895,10 +2893,10 @@ static /*@observer@*/ paramNodeList
   fcnNode_fromDeclarator (/*@only@*/ /*@null@*/ lclTypeSpecNode t, 
                          /*@only@*/ declaratorNode d)
 {
-  return (makeFcnNode (QU_UNKNOWN, t, d,
-                      varDeclarationNodeList_new (),
-                      varDeclarationNodeList_new (),
-                      letDeclNodeList_new (),
+  return (makeFcnNode (qual_createUnknown (),  t, d,
+                      varDeclarationNodeList_new (), 
+                      varDeclarationNodeList_new (), 
+                      letDeclNodeList_new (), 
                       (lclPredicateNode) 0,
                       (lclPredicateNode) 0,
                       (modifyNode) 0,
@@ -2949,15 +2947,14 @@ makeFcnNode (qual specQual,
             /*@null@*/ lclPredicateNode claims)
 {
   fcnNode x = (fcnNode) dmalloc (sizeof (*x));
-  
+
   if (d->type != (typeExpr)0 && (d->type)->kind != TEXPR_FCN)
     {
       lclerror (d->id, cstring_makeLiteral 
                ("Attempt to specify function without parameter list"));
       d->type = makeFunctionNode (d->type, paramNodeList_new ());
     }
-  
-  
+    
   x->special = specQual;
   x->typespec = t;
   x->declarator = d;
@@ -3236,7 +3233,7 @@ paramNode_checkQualifiers (lclTypeSpecNode t, typeExpr d)
 
   llassert (lclTypeSpecNode_isDefined (t));
 
-  if (t->pointers == 0 
+  if (pointers_isUndefined (t->pointers)
       && (d != (typeExpr)0 && d->kind != TEXPR_PTR) && d->kind != TEXPR_ARRAY)
     {
       if (t->kind == LTS_TYPE)
@@ -3247,8 +3244,8 @@ paramNode_checkQualifiers (lclTypeSpecNode t, typeExpr d)
 
          sn = sort_quietLookup (sort_getUnderlying ((t->content.type)->sort));
 
-         if (sn.kind == SRT_PTR || sn.kind == SRT_ARRAY 
-             || sn.kind == SRT_HOF || sn.kind == SRT_NONE)
+         if (sn->kind == SRT_PTR || sn->kind == SRT_ARRAY 
+             || sn->kind == SRT_HOF || sn->kind == SRT_NONE)
            {
              isPointer = TRUE;
            }
@@ -3268,8 +3265,8 @@ paramNode_checkQualifiers (lclTypeSpecNode t, typeExpr d)
          llassert (t->content.type != NULL);
          sn = sort_quietLookup (sort_getUnderlying ((t->content.type)->sort));
 
-         if (sn.kind == SRT_PTR || sn.kind == SRT_ARRAY
-             || sn.kind == SRT_HOF || sn.kind == SRT_NONE)
+         if (sn->kind == SRT_PTR || sn->kind == SRT_ARRAY
+             || sn->kind == SRT_HOF || sn->kind == SRT_NONE)
            {
              isUser = TRUE;
            }
@@ -3414,23 +3411,23 @@ lclTypeSpecNode_unparseAltComments (/*@null@*/ lclTypeSpecNode typespec) /*@*/
                    return (message ("%q%s", s, ltoken_unparse (n->opttagid)));
                  }
 
-               s = message ("%q%s {\n\2\1", s, ltoken_unparse (n->opttagid));
+               s = message ("%q%s {\n\t", s, ltoken_unparse (n->opttagid));
              }
            else
              {
-               s = message ("%q{\n\2\1", s);
+               s = message ("%q{\n\t", s);
              }
 
            decls = n->structdecls;
 
            stDeclNodeList_elements (decls, f)
            {
-             s = message ("%q%q\1%q;\n\1", s, 
+             s = message ("%q%q %q;\n\t", s, 
                           lclTypeSpecNode_unparseAltComments (f->lcltypespec),
                          declaratorNodeList_unparse (f->declarators));
            } end_stDeclNodeList_elements;
 
-           return (message ("%q\3}", s));
+           return (message ("%q }", s));
          }
        case LTS_CONJ:
          {
@@ -3521,23 +3518,23 @@ cstring lclTypeSpecNode_unparseComments (/*@null@*/ lclTypeSpecNode typespec)
                    return (message ("%q%s", s, ltoken_unparse (n->opttagid)));
                  }
 
-               s = message ("%q%s {\n\2\1", s, ltoken_unparse (n->opttagid));
+               s = message ("%q%s {\n\t", s, ltoken_unparse (n->opttagid));
              }
            else
              {
-               s = message ("%q{\n\2\1", s);
+               s = message ("%q{\n\t", s);
              }
 
            decls = n->structdecls;
 
            stDeclNodeList_elements (decls, f)
            {
-             s = message ("%q%q\1%q;\n\1", s, 
+             s = message ("%q%q %q;\n\t", s, 
                           lclTypeSpecNode_unparseComments (f->lcltypespec),
                          declaratorNodeList_unparse (f->declarators));
            } end_stDeclNodeList_elements;
 
-           return (message ("%q\3}", s));
+           return (message ("%q }", s));
          }
        case LTS_CONJ:
          {
@@ -3665,7 +3662,7 @@ makeInfixTermNode (termNode x, ltoken op, termNode y)
   t->kind = TRM_APPLICATION;
   t->sort = sort_makeNoSort ();
   t->given = t->sort;
-  t->possibleSorts = sortSet_new ();   /* sort_equal */
+  t->possibleSorts = sortSet_new (); /* sort_equal */
   t->possibleOps = lslOpSet_new ();
   return (t);
 }
@@ -3691,7 +3688,7 @@ makeQuantifiedTermNode (quantifierNodeList qn, ltoken open,
   termNode n = (termNode) dmalloc (sizeof (*n));
   quantifiedTermNode q = (quantifiedTermNode) dmalloc (sizeof (*q));
 
-  n->name = NULL; /*> missing this --- detected by lclint <*/
+  n->name = NULL; /*> missing this --- detected by splint <*/
   n->error_reported = FALSE;
   n->wrapped = 0;
   n->error_reported = FALSE;
@@ -3704,7 +3701,7 @@ makeQuantifiedTermNode (quantifierNodeList qn, ltoken open,
   termNodeList_free (t->args);
   t->args = termNodeList_new ();
 
-  sort = sort_bool;
+  sort = g_sortBool;
   n->sort = sort;
   (void) sortSet_insert (n->possibleSorts, sort);
 
@@ -4191,7 +4188,7 @@ makeLiteralTermNode (ltoken tok, sort s)
   /* look up signatures for this operator too */
   
   range = ltoken_create (simpleId, sort_getLsymbol (s));
-  sign = makesigNode (ltoken_undefined, ltokenList_new (), 
+  sign = makesigNode (ltoken_undefined, ltokenList_new (),  
                            ltoken_copy (range));
   
   if (opInfo_exists (oi) && (oi->name->isOpId) 
@@ -4226,7 +4223,7 @@ makeLiteralTermNode (ltoken tok, sort s)
      needed anyway.  */
   /*  symtable_enterOp (g_symtab, nn, sign); */
 
-  if (s == sort_int)
+  if (s == g_sortInt)
     {
       sigNode osign;
       lslOp opn = (lslOp) dmalloc (sizeof (*opn));
@@ -4234,7 +4231,7 @@ makeLiteralTermNode (ltoken tok, sort s)
       /* if it is a C int, we should overload it as double too because
         C allows you to say "x > 2". */
       
-      (void) sortSet_insert (n->possibleSorts, sort_double);
+      (void) sortSet_insert (n->possibleSorts, g_sortDouble);
       
       ltoken_setText (range, lsymbol_fromChars ("double"));
       osign = makesigNode (ltoken_undefined, ltokenList_new (), range);
@@ -4264,7 +4261,7 @@ makeUnchangedTermNode1 (ltoken op, /*@unused@*/ ltoken all)
   t->error_reported = FALSE;
   t->wrapped = 0;
   t->kind = TRM_UNCHANGEDALL;
-  t->sort = sort_bool;
+  t->sort = g_sortBool;
   t->literal = op;
   t->given = sort_makeNoSort ();
   t->name = NULL; /*< missing this >*/
@@ -4289,7 +4286,7 @@ makeUnchangedTermNode2 (ltoken op, storeRefNodeList x)
   t->error_reported = FALSE;
   t->wrapped = 0;
   t->kind = TRM_UNCHANGEDOTHERS;
-  t->sort = sort_bool;
+  t->sort = g_sortBool;
   t->literal = op;
   t->unchanged = x;
   t->given = sort_makeNoSort ();
@@ -4341,7 +4338,7 @@ makeUnchangedTermNode2 (ltoken op, storeRefNodeList x)
   t->error_reported = FALSE;
   t->wrapped = 0;
   t->kind = TRM_SIZEOF;
-  t->sort = sort_int;
+  t->sort = g_sortInt;
   t->literal = op;
   t->sizeofField = type;
   t->given = sort_makeNoSort ();
@@ -4500,7 +4497,7 @@ printTermNode2 (/*@null@*/ opFormNode op, termNodeList args, sort sort)
              }
 
            s = message ("%q%s", s, sortText);
-           break; /*** <<<--- bug detected by LCLint ***/
+           break; 
          }
        case OPF_MMIDDLE:
          {
@@ -5094,10 +5091,10 @@ makeTypeSpecifier (ltoken typedefname)
   
   if (typeInfo_exists (ti))
     {
-     /* must we be concern about whether this type is exported by module?
-        No.  Because all typedef's are exported.  No hiding supported. */
-     /* Later, may want to keep types around too */
-     /* 3/2/93, use underlying sort */
+      /* must we be concern about whether this type is exported by module?
+        No.  Because all typedef's are exported.  No hiding supported. */
+      /* Later, may want to keep types around too */
+      /* 3/2/93, use underlying sort */
       newnode->sort = sort_getUnderlying (ti->basedOn);
     }
   else
@@ -5105,7 +5102,7 @@ makeTypeSpecifier (ltoken typedefname)
       lclerror (typedefname, message ("Unrecognized type: %s", 
                                      ltoken_getRawString (typedefname)));
       /* evs --- Don't know how to get this message */
-
+      
       newnode->sort = sort_makeNoSort ();
     }
   
@@ -5180,12 +5177,10 @@ lclTypeSpecNode2sort (lclTypeSpecNode type)
          return sort_makePtrN (type->content.type->sort, type->pointers);
        case LTS_STRUCTUNION:
          llassert (type->content.structorunion != NULL);
-         return sort_makePtrN (type->content.structorunion->sort,
-                               type->pointers);
+         return sort_makePtrN (type->content.structorunion->sort, type->pointers);
        case LTS_ENUM:
          llassert (type->content.enumspec != NULL);
-         return sort_makePtrN (type->content.enumspec->sort, 
-                               type->pointers);
+         return sort_makePtrN (type->content.enumspec->sort, type->pointers);
        case LTS_CONJ:
          return (lclTypeSpecNode2sort (type->content.conj->a));
        }
@@ -5360,7 +5355,7 @@ enteringFcnScope (lclTypeSpecNode t, declaratorNode d, globalList g)
   fctInfo fi    = (fctInfo) dmalloc (sizeof (*fi));
   signNode sign = (signNode) dmalloc (sizeof (*sign));
   sortList domain = sortList_new ();
-  unsigned int key;
+  unsigned long int key;
 
   paramPairs = extractParams (d->type);
   returnSort = extractReturnSort (t, d);
@@ -5682,7 +5677,12 @@ static /*@null@*/ opFormNode opFormNode_copy (/*@null@*/ opFormNode op)
 
 void opFormNode_free (/*@null@*/ opFormNode op)
 {
-  sfree (op);
+  if (op != NULL)
+    {
+      ltoken_free (op->tok);
+      ltoken_free (op->close);
+      sfree (op);
+    }
 }
 
 void nameNode_free (nameNode n)
@@ -5802,7 +5802,7 @@ nameNode nameNode_copySafe (nameNode n)
     }
   else
     {
-      /* error should be detected by lclint: forgot to copy opform! */
+      /* error should be detected by splint: forgot to copy opform! */
       return (makeNameNodeForm (opFormNode_copy (n->content.opform)));
     }
 }
@@ -5814,7 +5814,14 @@ bool initDeclNode_isRedeclaration (initDeclNode d)
 
 void termNode_free (/*@only@*/ /*@null@*/ termNode t)
 {
-  sfree (t);
+  if (t != NULL) 
+    {
+      sortSet_free (t->possibleSorts);
+      lslOpSet_free (t->possibleOps);
+      nameNode_free (t->name);
+      termNodeList_free (t->args);
+      sfree (t);
+    }
 }
 
 /*@only@*/ termNode termNode_copySafe (termNode t)
@@ -5876,7 +5883,11 @@ void termNode_free (/*@only@*/ /*@null@*/ termNode t)
 
 void importNode_free (/*@only@*/ /*@null@*/ importNode x)
 {
-  sfree (x);
+  if (x != NULL) 
+    {
+      ltoken_free (x->val);
+      sfree (x);
+    }
 }
 
 void initDeclNode_free (/*@only@*/ /*@null@*/ initDeclNode x)
@@ -5902,7 +5913,11 @@ void letDeclNode_free (/*@only@*/ /*@null@*/ letDeclNode x)
 
 void pairNode_free (/*@only@*/ /*@null@*/ pairNode x)
 {
-  sfree (x);
+  if (x != NULL) 
+    {
+      ltoken_free (x->tok);
+      sfree (x);
+    }
 }
 
 /*@null@*/ paramNode paramNode_copy (/*@null@*/ paramNode p)
@@ -6179,6 +6194,8 @@ cstring interfaceNode_unparse (interfaceNode x)
     {
       return (cstring_makeLiteral ("<interface node undefined>"));
     }
+
+  BADBRANCHRET (cstring_undefined);
 }
 
 void interfaceNode_free (/*@null@*/ /*@only@*/ interfaceNode x)
This page took 0.072653 seconds and 4 git commands to generate.