]> andersk Git - splint.git/blobdiff - src/exprNode.c
Fixed parsing problem with multiple inclusions of alt typedefs.
[splint.git] / src / exprNode.c
index dc2104f6bd94bf04117cf78d49e849ca7eaf895e..648c062a76d94418863225241f1c263b7bf22bd5 100644 (file)
@@ -29,6 +29,7 @@
 # include "splintMacros.nf"
 # include "basic.h"
 # include "cgrammar.h"
+# include "cscanner.h"
 # include "cgrammar_tokens.h"
 
 # include "exprChecks.h"
@@ -218,13 +219,14 @@ exprNode_destroyMod (void)
 {
   if (initMod)
     {
-      uentry_free (regArg);
-      uentry_free (outArg);
-      uentry_free (outStringArg);
+      /* evans 2002-07-12: changed uentry_free to uentry_freeComplete */
+      uentry_freeComplete (regArg);
+      uentry_freeComplete (outArg);
+      uentry_freeComplete (outStringArg);
       
       exprNode_free (s_mustExitNode);
       initMod = FALSE;
-    /*@-branchstate@*/ 
+      /*@-branchstate@*/ 
     } 
   /*@=branchstate@*/
 }
@@ -1033,7 +1035,7 @@ exprNode_fromIdentifier (/*@observer@*/ uentry c)
 
   if (context_justPopped ()) /* watch out! c could be dead */
     { 
-      uentry ce = usymtab_lookupSafe (LastIdentifier ());
+      uentry ce = usymtab_lookupSafe (cscanner_observeLastIdentifier ());
 
       if (uentry_isValid (ce)) 
         {
@@ -1049,16 +1051,15 @@ exprNode_fromIdentifier (/*@observer@*/ uentry c)
   return ret;
 }
 
-
 static void exprNode_checkStringLiteralLength (ctype t1, exprNode e2)
 {
   multiVal mval = exprNode_getValue (e2);
   cstring slit;
-  int len;
+  size_t len;
 
   if (ctype_isFixedArray (t1))
     {
-      int nelements = long_toInt (ctype_getArraySize (t1));
+      size_t nelements = ctype_getArraySize (t1);
       
       llassert (multiVal_isString (mval));
       slit = multiVal_forceString (mval);
@@ -3778,7 +3779,7 @@ functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
       /* f->typ is already set to the return type */
 
       DPRINTF (("Function: %s", uentry_unparseFull (le)));
-      ret->sref = uentry_returnedRef (le, args);
+      ret->sref = uentry_returnedRef (le, args, exprNode_loc (f));
       DPRINTF (("Returned: %s / %s",
                uentry_unparseFull (le),
                sRef_unparseFull (ret->sref)));
@@ -3896,6 +3897,7 @@ functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
   reflectEnsuresClause (ret, le, f, args);
   setCodePoint ();
 
+  DPRINTF (("Here: %s", sRef_unparseFull (ret->sref)));
   return (ret);
 }
 
@@ -4990,11 +4992,14 @@ exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
 
   ret->sref = sRef_copy (e->sref);
   
+  DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
+
   if (!sRef_isConst (e->sref))
     {
       usymtab_addForceMustAlias (ret->sref, e->sref);
     }
   
+  DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
   sRef_setTypeFull (ret->sref, c);
   DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
 
@@ -5008,7 +5013,18 @@ exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
 
   if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
     {
-      ;
+      /* evans 2002-07-19: added this warning */
+      DPRINTF (("Checking: %s / %s", exprNode_unparse (ret), sRef_unparseFull (ret->sref)));
+      if (sRef_isFresh (ret->sref))
+       {
+         voptgenerror 
+           (FLG_MUSTFREEFRESH,
+            message ("New fresh storage %q(type %s) cast to void (not released): %s",
+                     sRef_unparseOpt (ret->sref),
+                     ctype_unparse (exprNode_getType (ret)),
+                     exprNode_unparse (ret)),
+            exprNode_loc (ret));
+       }
     }
   else if (ctype_isRealAP (c)) /* casting to array or pointer */
     {
@@ -8207,7 +8223,7 @@ static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
 
          if (ctype_isFixedArray (t1))
            {
-             int nelements = long_toInt (ctype_getArraySize (t1));
+             size_t nelements = ctype_getArraySize (t1);
              
              DPRINTF (("Checked array: %s / %d",
                        ctype_unparse (t1), nelements));
@@ -8218,10 +8234,11 @@ static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
                }
              else
                {
-                 if (exprNodeList_size (vals) != nelements) 
+                 if (exprNodeList_size (vals) != size_toInt (nelements))
                    {
                      hasError = optgenerror 
-                       (exprNodeList_size (vals) > nelements ? FLG_INITSIZE : FLG_INITALLELEMENTS,
+                       (exprNodeList_size (vals) > size_toInt (nelements) 
+                        ? FLG_INITSIZE : FLG_INITALLELEMENTS,
                         message ("Initializer block for "
                                  "%s has %d element%&, but declared as %s: %q",
                                  exprNode_unparse (el),
@@ -8584,7 +8601,7 @@ exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
        {
          sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
        }
-# if 0
+
       if (exprNode_isStringLiteral (e)
          && (ctype_isArray (ct))
          && (ctype_isChar (ctype_realType (ctype_baseArrayPtr (ct)))))
@@ -8593,61 +8610,24 @@ exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
          ** If t is a char [], the literal is copied.
          */
 
-         cstring slit;
+         exprNode_checkStringLiteralLength (ct, e);
+         sRef_setDefState (ret->sref, SS_DEFINED, e->loc);
+         ret->val = multiVal_copy (e->val);
 
+         sRef_setNullTerminatedState (ret->sref);
+         
          if (multiVal_isDefined (e->val))
            {
-             slit = multiVal_forceString (e->val);
-           }
-         else
-           {
-             slit = cstring_undefined;
+             cstring slit = multiVal_forceString (e->val);
+             sRef_setLen (ret->sref, cstring_length (slit) + 1);
            }
 
-         sRef_setDefState (ret->sref, SS_DEFINED, e->loc);
-         ret->val = multiVal_copy (e->val);
-
-         if (cstring_isDefined (slit))
+         if (ctype_isFixedArray (ct))
            {
-             if (ctype_isFixedArray (ct))
-               {
-                 long int alength = ctype_getArraySize (ct);
-                 
-                 if (alength < cstring_length (slit) + 1)
-                   {
-                     voptgenerror
-                       (FLG_LITERALOVERSIZE,
-                        ("Array initialized to string literal bigger than allocated size (literal is %d chars long (plus one for nul terminator), array size is %d): %s", 
-                         cstring_length (slit),
-                         alength,
-                         exprNode_unparse (e)),
-                        e->loc);
-                   }
-                 else if (alength > cstring_length (slit))
-                   {
-                     voptgenerror
-                       (FLG_LITERALUNDERSIZE,
-                        ("Array initialized to string literal smaller than allocated size (literal is %d chars long (plus one for nul terminator), array size is %d), could waste storage: %s", 
-                         cstring_length (slit),
-                         alength,
-                         exprNode_unparse (e)),
-                        e->loc);
-                   }
-                 else
-                   {
-                     ;
-                   }
-               }
-             else
-               {                 
-                 sRef_setNullTerminatedState (ret->sref);
-                 sRef_setSize (ret->sref, cstring_length (slit) + 1);
-                 sRef_setLen (ret->sref, cstring_length (slit) + 1);
-               }
+             sRef_setSize (ret->sref, size_toInt (ctype_getArraySize (ct)));
            }
        }
       else
-# endif
        {
          doAssign (ret, e, TRUE);
        }
This page took 0.04056 seconds and 4 git commands to generate.