]> andersk Git - splint.git/blobdiff - src/usymtab.c
Cleaned up code problems reported by make splintme.
[splint.git] / src / usymtab.c
index 245b22b236f0d9beba4906c7dc7725a4cb74effb..1f70646bd04a921e858c5e6ca1601f015c1dca00 100644 (file)
@@ -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
 */
 /*
 **                      weird C syntax.
 */
 
-# include "lclintMacros.nf"
+# include "splintMacros.nf"
 # include "basic.h"
 # include "structNames.h"
 # include "exprChecks.h"
 # include "transferChecks.h"
 
+/* Needed to install macros when loading libraries */
+
+# include "cpplib.h"
+# include "cpperror.h"
+# include "cpphash.h"
+
 /*
 ** Keep track of type definitions inside a function.
 */
@@ -99,6 +105,10 @@ static bool usymtab_isAltDefinitelyNull (sRef p_s) /*@globals utab@*/ ;
 static void refTable_free (/*@only@*/ /*@null@*/ refTable p_x, int p_nentries);
 static ctype usymtab_suFieldsType (uentryList p_f, bool p_isStruct) /*@globals globtab@*/ ;
 
+static void usymtab_freeAux (/*@only@*/ usymtab p_u)
+     /*@globals globtab, utab, filetab@*/
+     /*@modifies p_u@*/ ;
+
 extern int usymtab_getCurrentDepth (void) /*@globals utab@*/ 
 {
   return utab->lexlevel;
@@ -113,7 +123,7 @@ static /*@only@*/ cstring usymtab_unparseStackTab (usymtab p_t);
 static /*@exposed@*/ /*@dependent@*/ uentry 
   usymtab_getRefTab (/*@notnull@*/ usymtab p_u, int p_level, usymId p_index);
 
-# ifdef __LCLINT__
+# ifdef S_SPLINT_S
 /* These are not used anymore... */
 static /*@unused@*/ /*@only@*/ cstring 
   usymtab_unparseLocalAux (/*@notnull@*/ usymtab p_s);
@@ -142,7 +152,7 @@ static /*@exposed@*/ /*@dependent@*/ uentry
 static /*@exposed@*/ /*@dependent@*/ uentry 
   usymtab_lookupQuietNoAlt (usymtab p_s, cstring p_k);
 
-static void usymtab_printAllAux (usymtab p_s) /*@modifies g_msgstream@*/ ;
+static void usymtab_printAllAux (usymtab p_s) /*@modifies g_warningstream@*/ ;
 static int usymtab_getIndex (/*@notnull@*/ usymtab p_s, cstring p_k);
 static /*@exposed@*/ uentry usymtab_fetchIndex (/*@notnull@*/ usymtab p_s, int p_i);
 static /*@exposed@*/ uentry 
@@ -187,7 +197,7 @@ static void clearFunctionTypes (void)
   uentryList_clear (functypes);
 }
 
-static /*@falsenull@*/ bool usymtab_isBranch (usymtab u)
+static /*@falsewhennull@*/ bool usymtab_isBranch (usymtab u)
 {
   return (usymtab_isDefined (u) && 
          (u->kind == US_TBRANCH || u->kind == US_FBRANCH
@@ -291,7 +301,8 @@ static /*@notnull@*/ /*@special@*/ usymtab
 
   t->mustBreak = FALSE;
   t->exitCode = XK_NEVERESCAPE;
-  
+
+  DPRINTF (("Create usymtab [%p]", t));
   return t;
 }
 
@@ -333,6 +344,13 @@ usymtab_initMod (void)
   oldtab = usymtab_undefined;
 }
 
+void 
+usymtab_destroyMod (void) /*@modifies utab, globtab, filetab@*/ /*@globals killed utab@*/ 
+{
+  DPRINTF (("Destroy usymtab [%p]: %d", utab, utab->nentries));
+  usymtab_freeAux (utab);
+  utab = usymtab_undefined;
+}
 
 void
 usymtab_initGlobalMarker () /*@globals globtab@*/
@@ -357,6 +375,8 @@ usymtab_initGlobalMarker () /*@globals globtab@*/
 void
 usymtab_initBool ()
 {
+  DPRINTF (("Init bool!"));
+
   if (context_getFlag (FLG_NOLIB))
     {
       ctype boolt = ctype_bool;
@@ -375,6 +395,7 @@ usymtab_initBool ()
        (uentry_makeConstantValue (context_getFalseName (), boolt, 
                                   fileloc_getBuiltin (), FALSE, 
                                   multiVal_makeInt (0)));
+
       usymtab_supGlobalEntry 
        (uentry_makeConstantValue (context_getTrueName (), boolt, 
                                   fileloc_getBuiltin (), FALSE, 
@@ -751,8 +772,6 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st,
     }
   }
 
-  DPRINTF (("Using symtab: %s", usymtab_unparseLocalAux (st)));
-
   eindex = usymtab_getIndex (st, ename);
       
   if (eindex != NOT_FOUND)
@@ -884,7 +903,8 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st,
          if (!(st->lexlevel > fileScope || !sRef_modInFunction ()))
            {
              if (uentry_isDatatype (e) || uentry_isAnyTag (e)
-                 || uentry_isEnumConstant (e))
+                 || uentry_isEnumConstant (e)
+                 || uentry_isStatic (e)) /* bug fix from Brian St. Pierre */
                {
                  ; /* 
                     ** Not a bug.  Code like,
@@ -1011,7 +1031,6 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st,
     return (staticEntry ? USYMIDINVALID : eindex);
 }
 
-# ifndef NOLCL
 static void
 usymtab_replaceEntryAux (/*@notnull@*/ usymtab st, /*@only@*/ uentry e)
    /*@globals globtab@*/ /*@modifies st, e@*/
@@ -1040,7 +1059,6 @@ usymtab_replaceEntryAux (/*@notnull@*/ usymtab st, /*@only@*/ uentry e)
       eindex = usymtab_addEntryAux (st, e, FALSE);
     }
 }
-# endif
 
 /*@=deparrays@*/ 
 
@@ -1258,7 +1276,6 @@ usymtab_supAbstractTypeEntry (/*@only@*/ uentry e, bool dodef)
   return (uid);
 }
 
-# ifndef NOLCL
 usymId
 usymtab_supExposedTypeEntry (/*@only@*/ uentry e, bool dodef)
   /*@globals globtab, filetab@*/
@@ -1282,7 +1299,6 @@ usymtab_supExposedTypeEntry (/*@only@*/ uentry e, bool dodef)
 
   return (uid);
 }
-# endif
 
 ctype
 usymtab_supForwardTypeEntry (/*@only@*/ uentry e)
@@ -1308,7 +1324,6 @@ void
   /*@modifies utab, globtab, e@*/
 {
   sRef old = uentry_getSref (e);
-
   
   if (sRef_isType (old))
     {
@@ -1590,7 +1605,7 @@ usymtab_rehash (/*@notnull@*/ usymtab s)
       cstringTable_free (s->htable);
     }
   
-  s->htable = cstringTable_create (LLHASHSIZE);
+  s->htable = cstringTable_create (LLAHSHSIZE);
 
   for (i = 0; i < s->nentries; i++)
     {
@@ -1794,6 +1809,17 @@ void usymtab_dump (FILE *fout)
   lastekind = KINVALID;
 
   fprintf(fout, ";; Library constraints\n");
+
+ /*drl July 27 added this so that libraries without
+    buffer constraints would be handled correctly.
+    I'm trying to do this without breaking older libraries.
+
+    Splint should still be able to handle libraries without this message.
+ */
+
+  
+  fprintf(fout, "start_Buffer_Constraints\n");
+
   for (i = 0; i < utab->nentries; i++)
     {
       uentry thisentry = utab->entries[i];
@@ -1836,11 +1862,9 @@ void usymtab_dump (FILE *fout)
                  
        }
     }
-    
-
-  
 }
 
+
 void usymtab_load (FILE *f)
   /*@globals utab, globtab@*/
   /*@modifies utab, *f@*/
@@ -1892,7 +1916,7 @@ void usymtab_load (FILE *f)
        {
          llfatalerror
            (cstring_makeLiteral 
-            ("Library is in obsolete format.  Use lclint +whichlib "
+            ("Library is in obsolete format.  Use splint +whichlib "
              "to see which library is being loaded."));
        }
 
@@ -1914,6 +1938,30 @@ void usymtab_load (FILE *f)
        {       
          int lastindex = utab->nentries;
          ue = usymtab_addEntryAlways (utab, ue);
+
+
+# if 0
+         if (uentry_isConstant (ue)) /*@i23! isPreProcessorMacro */
+           {
+             cstring uname = uentry_getName (ue);
+             
+             /* Also check its a macro... */
+             DPRINTF (("Installing: %s", uname));
+
+             cpphash_installMacro 
+               (mstring_copy (cstring_toCharsSafe (uname)),
+                cstring_length (uname),
+                cpplib_createDefinition (message ("%s 255", uname),
+                                         loc,
+                                         FALSE, FALSE).defn,
+                cpphash_hashCode (cstring_toCharsSafe (uname),
+                                  cstring_length (uname),
+                                  CPP_HASHSIZE));
+             
+             DPRINTF (("After install: %s", uname));
+           }
+# endif
+
          if (utab->nentries != lastindex + 1)
            {
              DPRINTF (("No add: %s", uentry_unparseFull (ue)));
@@ -1963,6 +2011,17 @@ void usymtab_load (FILE *f)
     {
       ; /* ignore ;-comments */
     }
+
+  /*drl July 27 added this so that libraries without
+    buffer constraints would be handled correctly.
+    I'm trying to do this without breaking older libraries*/
+  
+  /*check for "optional" start buffer constraints message*/
+
+  if (mstring_equalPrefix (s, "start_Buffer_Constraints")) 
+    {
+      (void) fgets (s, MAX_DUMP_LINE_LENGTH, f);
+    }
   
   while (s != NULL && *s != ';')
     {
@@ -2041,8 +2100,8 @@ usymtab_enterFile ()
     {
       if (sRef_hasDerived (uentry_getSref (ue)))
        {
-         fprintf (g_msgstream, "Derived Global: %s\n", uentry_unparse (ue));
-         fprintf (g_msgstream, "sRef: %s\n", sRef_unparseFull (ue->sref));
+         fprintf (g_warningstream, "Derived Global: %s\n", uentry_unparse (ue));
+         fprintf (g_warningstream, "sRef: %s\n", sRef_unparseFull (ue->sref));
        }
     } end_usymtab_entries ;
 
@@ -2133,7 +2192,10 @@ usymtab_handleParams (void)
                {
                  if (sRef_isStateSpecial (pref))
                    {
-                     uentry_setDefState (ue, SS_ALLOCATED);
+                     uentry_setDefState (ue, SS_SPECIAL); /* ALLOCATED); */
+                     /* evans 2002-01-01: should be unnecessary, the pre clauses
+                     **    set the state if necessary.
+                     */
                    }
                  else
                    {
@@ -2297,6 +2359,8 @@ usymtab_enterFunctionScope (uentry fcn)
 {
   usymtab t = usymtab_create (US_NORMAL, utab, TRUE);
 
+  DPRINTF (("Enter function: %s", uentry_unparse (fcn)));
+
   if (utab->lexlevel != fileScope)
     {
       if (utab->lexlevel > fileScope)
@@ -2394,6 +2458,9 @@ usymtab_enterFunctionScope (uentry fcn)
     } end_globSet_allElements;
 
   DPRINTF (("Globs after: %s", globSet_unparse (uentry_getGlobs (fcn))));
+# ifdef DEBUGSPLINT
+  usymtab_checkAllValid ();
+# endif
 }
 
 static void
@@ -2554,6 +2621,8 @@ usymtab_newCase (/*@unused@*/ exprNode pred, exprNode last)
   bool mustReturn = usymtab_mustEscape (utab);
   usymtab stab = utab;
 
+  DPRINTF (("New case!"));
+
   /*
   ** Find last case (or outer switch)
   */
@@ -2563,9 +2632,7 @@ usymtab_newCase (/*@unused@*/ exprNode pred, exprNode last)
       stab = stab->env;
       llassert (stab != GLOBAL_ENV);
     }
-
-  /* ??? */
-
+  
   while (stab->kind == US_CBRANCH)
     {
       stab = stab->env;
@@ -2875,13 +2942,17 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab,
              if (!guardSet_isGuarded (ttab->guards, el) 
                  && !sRef_isNotNull (sr))
                {
+                 DPRINTF (("Here! %s / %s",
+                           sRef_unparseFull (sr),
+                           sRef_unparseFull (el)));
                  sRef_setDerivNullState (sr, el, NS_DEFNULL);
-                               }
+               }
            }
        }
       else
        {
-               }
+         ;
+       }
       
       ue = usymtab_getRefTab (ftab, level, index);
       
@@ -2889,7 +2960,6 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab,
        {
          sRef sr = uentry_getSref (ue);
          
-         
          if (!trueGuard) /* yikes!  forgot the ! */
            {
              sRef_setDerivNullState (sr, el, NS_NOTNULL);
@@ -2901,7 +2971,7 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab,
                  && !sRef_isNotNull (sr))
                {
                  sRef_setDerivNullState (sr, el, NS_DEFNULL);
-                               }
+               }
            }
        }
       else
@@ -3663,6 +3733,8 @@ checkGlobalReturn (uentry glob, sRef orig)
          else
            {
              ctype ct = ctype_realType (uentry_getType (glob));
+             
+             DPRINTF (("Check global destroyed: %s", uentry_unparseFull (glob)));
 
              if (ctype_isVisiblySharable (ct))
                {
@@ -3680,7 +3752,7 @@ checkGlobalReturn (uentry glob, sRef orig)
              else
                {
                  sRef_protectDerivs ();
-                 (void) checkGlobalDestroyed (sr, g_currentloc);
+                 (void) transferChecks_globalDestroyed (sr, g_currentloc);
                  sRef_clearProtectDerivs ();
                }
            }
@@ -3739,7 +3811,8 @@ checkGlobalReturn (uentry glob, sRef orig)
                }
              else
                {
-                 checkGlobReturn (glob);
+                 DPRINTF (("Check transfer: %s", uentry_unparseFull (glob)));
+                 transferChecks_globalReturn (glob);
                }
            }
        }
@@ -3753,7 +3826,7 @@ checkGlobalReturn (uentry glob, sRef orig)
 void usymtab_checkFinalScope (bool isReturn)
   /*@globals utab@*/
 {
-  bool mustFree = context_getFlag (FLG_MUSTFREE);
+  bool mustFree = context_getFlag (FLG_MUSTFREEONLY) || context_getFlag (FLG_MUSTFREEFRESH); /*@i423 remove this mustFree */
   bool mustDefine = context_getFlag (FLG_MUSTDEFINE);
   /* bool mustNotAlias = context_getFlag (FLG_MUSTNOTALIAS); */
   sRefSet checked = sRefSet_new ();
@@ -3789,7 +3862,7 @@ void usymtab_checkFinalScope (bool isReturn)
                  /*@innercontinue@*/ continue;
                }
            }
-                           
+         
          DPRINTF (("Here check final scope: %s", uentry_unparseFull (ce)));
          
          if (ctype_isFunction (uentry_getType (ce)))
@@ -3802,6 +3875,7 @@ void usymtab_checkFinalScope (bool isReturn)
              || sRef_isFileOrGlobalScope (rb))
            {
              /* Don't do the loseref check...but should check state! */
+             DPRINTF (("Skipping check 1"));
            }
          else if (sRef_isDefinitelyNull (sr)
                   || usymtab_isDefinitelyNull (sr))
@@ -3809,6 +3883,8 @@ void usymtab_checkFinalScope (bool isReturn)
              /*
              ** No state reference errors for definitely null references.
              */
+
+             DPRINTF (("Skipping check 2"));
            }
          else
            {
@@ -3828,7 +3904,7 @@ void usymtab_checkFinalScope (bool isReturn)
                if (stateValue_isError (fval)
                    || sRef_isStateUndefined (sr)) /* No errors for undefined state */
                  {
-                   ;
+                   DPRINTF (("Skipping check 3"));
                  }
                else 
                  {
@@ -3871,9 +3947,11 @@ void usymtab_checkFinalScope (bool isReturn)
              } end_valueTable_elements;
            }
 
+         DPRINTF (("Here 1"));
+
          if (mustFree)
            {
-             DPRINTF (("Check entry: %s", uentry_unparseFull (ce)));
+             DPRINTF (("Check mustfree entry: %s", uentry_unparseFull (ce)));
              
              if (!sRefSet_member (checked, sr) && !sRef_isFileOrGlobalScope (rb))
                {
@@ -3888,7 +3966,7 @@ void usymtab_checkFinalScope (bool isReturn)
                      
                      if (sRefSet_isEmpty (als))
                        {
-                         checkLocalDestroyed (sr, g_currentloc);
+                         transferChecks_localDestroyed (sr, g_currentloc);
                        }
                      else
                        {
@@ -3917,7 +3995,7 @@ void usymtab_checkFinalScope (bool isReturn)
                        
                        if (!isReturn)
                          {
-                           if (canLoseReference (sr, g_currentloc))
+                           if (transferChecks_canLoseReference (sr, g_currentloc))
                              {
                                DPRINTF (("Can lose!"));
                                hasError = FALSE;
@@ -3931,7 +4009,7 @@ void usymtab_checkFinalScope (bool isReturn)
                                sRef ar = sRef_getAliasInfoRef (sr);
                                
                                if (optgenerror 
-                                   (FLG_MUSTFREE,
+                                   (sRef_isFresh (ar) ? FLG_MUSTFREEFRESH : FLG_MUSTFREEONLY,
                                     message
                                     ("Last reference %q to %s storage %qnot %q before %q",
                                      sRef_unparse (sr),
@@ -3949,7 +4027,7 @@ void usymtab_checkFinalScope (bool isReturn)
                            else if (sRef_isNewRef (sr))
                              {
                                if (optgenerror
-                                   (FLG_MUSTFREE,
+                                   (sRef_isFresh (sr) ? FLG_MUSTFREEFRESH : FLG_MUSTFREEONLY,
                                     message 
                                     ("%q %q not released before %q",
                                      cstring_makeLiteral 
@@ -3967,14 +4045,14 @@ void usymtab_checkFinalScope (bool isReturn)
                              {
                                if (ctype_isRealSU (sRef_getType (sr)))
                                  {
-                                   checkStructDestroyed (sr, g_currentloc);
+                                   transferChecks_structDestroyed (sr, g_currentloc);
                                  }
                                else
                                  {
                                    DPRINTF (("Here we are: %s", sRef_unparseFull (sr)));
 
                                    if (optgenerror
-                                       (FLG_MUSTFREE,
+                                       (sRef_isFresh (sr) ? FLG_MUSTFREEFRESH : FLG_MUSTFREEONLY,
                                         message 
                                         ("%s storage %q not %q before %q",
                                          alkind_capName (sRef_getAliasKind (sr)),
@@ -3997,59 +4075,57 @@ void usymtab_checkFinalScope (bool isReturn)
                      ;
                    }
                }
-             else if (mustDefine && uentry_isOut (ce))
-               {
-                 if (!ynm_toBoolStrict (sRef_isReadable (sr)))
-                   {
-                     voptgenerror 
-                       (FLG_MUSTDEFINE,
-                        message ("Out storage %q not defined before %q",
-                                 uentry_getName (ce),
-                                 cstring_makeLiteral 
-                                 (isReturn ? "return" : "scope exit")),
-                        g_currentloc);
-                     
-                     /* uentry_showWhereDeclared (ce); */
-                   }
-               }
-             else
+           }
+
+         if (mustDefine && uentry_isOut (ce))
+           {
+             /* No error if its dead (either only or error already reported */
+             if (!sRef_isReallyDefined (sr) && !sRef_isDead (sr))
                {
-                 ; 
+                 voptgenerror 
+                   (FLG_MUSTDEFINE,
+                    message ("Out storage %q not defined before %q",
+                             uentry_getName (ce),
+                             cstring_makeLiteral 
+                             (isReturn ? "return" : "scope exit")),
+                    g_currentloc);
+
+                 DPRINTF (("sr: %s", sRef_unparseFull (sr)));
                }
+           }
+         
+         /*
+         ** also check state is okay
+         */
+         
+         if (usymtab_lexicalLevel () > functionScope
+             && uentry_isVariable (ce)
+             && (sRef_isLocalVar (sr)
+                 && (sRef_isDependent (sr) || sRef_isLocalState (sr))))
+           {
+             sRefSet ab = usymtab_aliasedBy (sr);
              
-             /*
-             ** also check state is okay
-             */
+             /* should do something more efficient here */
              
-             if (usymtab_lexicalLevel () > functionScope
-                 && uentry_isVariable (ce)
-                 && (sRef_isLocalVar (sr)
-                     && (sRef_isDependent (sr) || sRef_isLocalState (sr))))
+             if (sRefSet_isEmpty (ab))
                {
-                 sRefSet ab = usymtab_aliasedBy (sr);
-
-                 /* should do something more efficient here */
-
-                 if (sRefSet_isEmpty (ab))
-                   {
-                     /* and no local ref */
-                     DPRINTF (("Check lose ref: %s", uentry_unparseFull (ce)));
-                     checkLoseRef (ce);
-                   }
-                 else
-                   {
-                     ;
-                   }
-                 
-                 sRefSet_free (ab);
+                 /* and no local ref */
+                 DPRINTF (("Check lose ref: %s", uentry_unparseFull (ce)));
+                 transferChecks_loseReference (ce);
                }
-             else 
+             else
                {
                  ;
                }
              
-             checked = sRefSet_insert (checked, sr);
+             sRefSet_free (ab);
            }
+         else 
+           {
+             ;
+           }
+         
+         checked = sRefSet_insert (checked, sr);
        }
 
       llassert (usymtab_isDefined (stab->env));
@@ -4225,7 +4301,7 @@ void usymtab_checkFinalScope (bool isReturn)
                {
                  uentry param = usymtab_lookupQuiet (utab, uentry_rawName (arg));
                  DPRINTF (("Check param return: %s", uentry_unparseFull (param)));
-                 checkParamReturn (param);
+                 transferChecks_paramReturn (param);
                }
            }
        } end_uentryList_elements;
@@ -4270,6 +4346,8 @@ usymtab_quietExitScope (fileloc loc)
 {
   usymtab t = utab->env;
 
+  DPRINTF (("Quiet exit scope [%p]", utab));
+
   if (utab->reftable != NULL)
     {
       int i;
@@ -4296,9 +4374,14 @@ usymtab_quietExitScope (fileloc loc)
   t->mustBreak = utab->mustBreak;
   t->exitCode = utab->exitCode;
 
+  DPRINTF (("Free level [%p]", utab));
   usymtab_freeLevel (utab);
 
   utab = t;
+
+# ifdef DEBUGSPLINT
+  usymtab_checkAllValid ();
+# endif
 }
 
 /*
@@ -4326,7 +4409,7 @@ void usymtab_exitScope (exprNode expr)
   usymtab lctab = usymtab_undefined;
   bool mustReturn = exprNode_mustEscape (expr);
 
-  DPRINTF (("Exit scope"));
+  DPRINTF (("Exit scope [%p]", utab));
 
   if (utab->kind == US_CBRANCH)
     {
@@ -4345,32 +4428,34 @@ void usymtab_exitScope (exprNode expr)
     }
   
   if (utab->kind == US_TBRANCH || utab->kind == US_FBRANCH
-      || utab->kind == US_CBRANCH || utab->kind == US_SWITCH) {
-   
-    if (context_inMacro ()) {
-      /* evs 2000-07-25 */
-      /* Unparseable macro may end inside nested scope.  Deal with it. */
-      
-      llerror (FLG_SYNTAX, 
-              message ("Problem parsing macro body of %s (unbalanced scopes). "
-                       "Attempting to recover, recommend /*@notfunction@*/ before "
-                       "macro definition.", 
-                       context_inFunctionName ()));
-      
-      while (utab->kind == US_TBRANCH
-            || utab->kind == US_FBRANCH
-            || utab->kind == US_CBRANCH
-            || utab->kind == US_SWITCH) 
+      || utab->kind == US_CBRANCH || utab->kind == US_SWITCH) 
+    {
+      if (context_inMacro ()) 
        {
-         utab = utab->env;
-         llassert (utab != GLOBAL_ENV);
-       }
-    } else {
-      llcontbug (message ("exitScope: in branch: %q", usymtab_unparseStack ()));
-      /*@-branchstate@*/ 
-    } /*@=branchstate@*/
-  }
-
+         /* evs 2000-07-25 */
+         /* Unparseable macro may end inside nested scope.  Deal with it. */
+         
+         llerror (FLG_SYNTAX, 
+                  message ("Problem parsing macro body of %s (unbalanced scopes). "
+                           "Attempting to recover, recommend /*@notfunction@*/ before "
+                           "macro definition.", 
+                           context_inFunctionName ()));
+         
+         while (utab->kind == US_TBRANCH
+                || utab->kind == US_FBRANCH
+                || utab->kind == US_CBRANCH
+                || utab->kind == US_SWITCH) 
+           {
+             utab = utab->env;
+             llassert (utab != GLOBAL_ENV);
+           }
+       } else 
+         {
+           llcontbug (message ("exitScope: in branch: %q", usymtab_unparseStack ()));
+           /*@-branchstate@*/ 
+         } /*@=branchstate@*/
+    }
+  
   /*
   ** check all variables in scope were used
   */
@@ -4396,7 +4481,7 @@ void usymtab_exitScope (exprNode expr)
   ** NOTE: note for exiting paramsScope, since checkReturn should be
   ** called first.
   */
-
+  
   if (!mustReturn && (usymtab_lexicalLevel () > functionScope))
     {
       /*
@@ -4415,7 +4500,6 @@ void usymtab_exitScope (exprNode expr)
       uentryList params = context_getParams ();
       globSet    globs = context_getUsedGlobs ();
 
-                  
       uentryList_elements (params, ue)
        {
          uentry_fixupSref (ue);
@@ -4423,9 +4507,12 @@ void usymtab_exitScope (exprNode expr)
 
       clearFunctionTypes ();
 
-      
+      DPRINTF (("Fixing up globals: %s", globSet_unparse (globs)));
+
       globSet_allElements (globs, el)
        {
+         DPRINTF (("Fix: %s", sRef_unparseDebug (el)));
+
          if (sRef_isCvar (el))
            {
              uentry current;
@@ -4443,13 +4530,17 @@ void usymtab_exitScope (exprNode expr)
              
              if (uentry_isVariable (current))
                {
+                 DPRINTF (("Fixup: %s", uentry_unparse (current)));
                  uentry_fixupSref (current);
                }
              else
                {
+                 DPRINTF (("Clear: %s", uentry_getSref (current)));
                  sRef_clearDerived (uentry_getSref (current));
                }
            }
+
+         sRef_clearDerived (el); /* evans 2002-03-14 - this is the likely source of many crashes! */
        } end_globSet_allElements;
     }
   
@@ -4461,6 +4552,11 @@ void usymtab_exitScope (exprNode expr)
       /*@i@*/ utab = ctab;
     /*@-branchstate@*/ } /*@=branchstate@*/
   /*@-globstate@*/
+
+
+# ifdef DEBUGSPLINT
+  usymtab_checkAllValid ();
+# endif
 /*@i523@*/ }
 /*@=globstate@*/
 
@@ -4477,13 +4573,7 @@ uentry_directParamNo (uentry ue)
 
       if (sRef_lexLevel (sr) == functionScope)
        {
-         int index;
-
-         /*@access sRef@*/ 
-         llassert (sr->info != NULL);
-         llassert (sr->info->cvar != NULL);
-         index = sr->info->cvar->index;
-         /*@noaccess sRef@*/
+         int index = sRef_getScopeIndex (sr);
 
          if (index < uentryList_size (context_getParams ()))
            {
@@ -4815,7 +4905,15 @@ usymtab_addRefEntry (/*@notnull@*/ usymtab s, cstring k)
              uentry ue;
 
              DPRINTF (("Here: copying %s", uentry_unparse (current)));
-             ue = uentry_copy (current);
+             if (uentry_isNonLocal (current))
+               {
+                 ue = uentry_copy (current);
+               }
+             else
+               {
+                 ue = uentry_copyNoSave (current);
+               }
+
              DPRINTF (("Here: copying %s", uentry_unparse (ue)));
              usymtab_addEntryQuiet (ut, ue);
              DPRINTF (("Okay..."));
@@ -4914,6 +5012,7 @@ usymtab_lookupQuietAux (usymtab s, cstring k, bool noalt)
        }
       else
        {
+         llassert (s != NULL); /*@i523 should not need this? */
          s = s->env;
        }
     }
@@ -4976,6 +5075,7 @@ uentry usymtab_lookupGlob (cstring k)
   if (uentry_isPriv (ce))
     llfatalbug (message ("usymtab_lookup: private: %s", k));
 
+  DPRINTF (("Lookup global: %s", uentry_unparseFull (ce)));
   return ce;
 }
 
@@ -4984,7 +5084,7 @@ uentry usymtab_lookupGlob (cstring k)
   /*@globals globtab@*/
 {
   uentry ce = usymtab_lookupAux (globtab, k);
-
+  DPRINTF (("Lookup global: %s", uentry_unparseFull (ce)));
   return ce;
 }
 
@@ -4996,10 +5096,10 @@ uentry usymtab_lookupEither (cstring k)
   if (uentry_isUndefined (ce))
     llfatalerror (message ("usymtab_lookup: not found: %s", k));
 
+  DPRINTF (("Lookup either: %s", uentry_unparseFull (ce)));
   return ce;
 }
 
-# ifndef NOLCL
 ctype
 usymtab_lookupType (cstring k)
    /*@globals globtab@*/
@@ -5014,7 +5114,6 @@ usymtab_lookupType (cstring k)
   
   return (uentry_getRealType (usymtab_getTypeEntry (uid)));
 }
-# endif
 
 ctype
 usymtab_lookupAbstractType (cstring k) /*@globals globtab@*/
@@ -5149,7 +5248,6 @@ bool
   return (!(uentry_isUndefined (ce)) && !(uentry_isPriv (ce)));
 }
 
-# ifndef NOLCL
 bool
 usymtab_existsEither (cstring k)
   /*@globals utab@*/
@@ -5167,7 +5265,6 @@ bool
   
   return (uentry_isValid (ce));
 }
-# endif
 
 bool
 usymtab_existsType (cstring k)
@@ -5217,7 +5314,6 @@ usymtab_existsEnumTag (cstring k) /*@globals globtab@*/
   return (!(uentry_isUndefined (ce)) && !(uentry_isPriv (ce)));
 }
 
-# ifndef NOLCL
 bool usymtab_existsVar (cstring k)
    /*@globals utab@*/
 {
@@ -5225,7 +5321,6 @@ bool usymtab_existsVar (cstring k)
 
   return (!(uentry_isUndefined (ce)) && !(uentry_isPriv (ce)) && (uentry_isVar (ce)));
 }
-# endif
 
 /*
 ** destructors
@@ -5253,6 +5348,7 @@ usymtab_freeLevel (/*@notnull@*/ /*@only@*/ usymtab u)
 {
   int i;
 
+  DPRINTF (("Free level [%p]", u));
   aliasTable_free (u->aliases);
 
   refTable_free (u->reftable, u->nentries);
@@ -5261,7 +5357,10 @@ usymtab_freeLevel (/*@notnull@*/ /*@only@*/ usymtab u)
     {
       for (i = 0; i < u->nentries; i++)
        {
+         DPRINTF (("Free complete: %d", i));
+         DPRINTF (("Uentry: %s", uentry_unparse (u->entries[i])));
          uentry_freeComplete (u->entries[i]);
+         u->entries[i] = uentry_undefined;
        }
     }
   else
@@ -5269,6 +5368,7 @@ usymtab_freeLevel (/*@notnull@*/ /*@only@*/ usymtab u)
       for (i = 0; i < u->nentries; i++)
        {
          uentry_free (u->entries[i]);
+         u->entries[i] = uentry_undefined;
        }
     }
 
@@ -5280,11 +5380,11 @@ usymtab_freeLevel (/*@notnull@*/ /*@only@*/ usymtab u)
       && u != filetab)
     {
       llassert (!cstringTable_isDefined (u->htable));
-      sfree (u);
     }
 
-/*@-mustfree@*/
-} /*@=mustfree@*/
+  sfree (u); /* evans 2002-07-12: was inside if */
+  /*:!!mustfree@*/
+} /*!@=mustfree@*/
 
 static void
 usymtab_freeAux (/*@only@*/ usymtab u)
@@ -5307,6 +5407,7 @@ void usymtab_free ()
 {
   dbgfree = TRUE;
   usymtab_freeAux (utab);
+  utab = usymtab_undefined;
 }
 
 static int usymtab_lexicalLevel (void) /*@globals utab@*/
@@ -5329,7 +5430,6 @@ bool usymtab_inFunctionScope () /*@globals utab@*/
   return (utab->lexlevel == functionScope);
 }
 
-# ifndef NOLCL
 void
 usymtab_replaceEntry (uentry s)
   /*@globals utab, globtab@*/
@@ -5337,7 +5437,6 @@ usymtab_replaceEntry (uentry s)
 {
   usymtab_replaceEntryAux (utab, s);
 }
-# endif
 
 bool
 usymtab_matchForwardStruct (usymId u1, usymId u2)
@@ -5526,7 +5625,7 @@ usymtab_displayAllUses ()
 
   usymtab_entries (copy, ue)
     {
-      if (uentry_isValid (ue))
+      if (uentry_isValid (ue) && !uentry_isGlobalMarker (ue))
        {
          filelocList uses = uentry_getUses (ue);
          int size = filelocList_realSize (uses);
@@ -5618,6 +5717,7 @@ void usymtab_addMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al)
 void usymtab_addForceMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al)
   /*@modifies utab@*/
 {
+  /* evans 2002-03-3: was sRef_isMeaningful -- but we need to keep aliases for new storage also! */
   if (sRef_isMeaningful (s) 
       && sRef_isMeaningful (al)
       && !(sRef_isConst (s) || sRef_isConst (al))
@@ -5637,10 +5737,17 @@ void usymtab_addForceMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al)
     }
   else
     {
-      ;
+      DPRINTF (("Not aliasing! %s / %s", sRef_unparseFull (s), sRef_unparseFull (al)));
+      DPRINTF (("meaningful: %d %d", sRef_isMeaningful (s), sRef_isMeaningful (al)));
     }
 }
 
+void usymtab_addReallyForceMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al)
+  /*@modifies utab@*/
+{
+  utab->aliases = aliasTable_addMustAlias (utab->aliases, s, al); 
+}
+
 void usymtab_clearAlias (sRef s)
   /*@modifies utab, s@*/
 {
@@ -5651,7 +5758,7 @@ void usymtab_clearAlias (sRef s)
 sRefSet usymtab_allAliases (sRef s)
    /*@globals utab@*/  
 {
-  if (sRef_isMeaningful (s))
+  if (sRef_isSomewhatMeaningful (s))
     {
       sRefSet ret;
             
@@ -5669,7 +5776,7 @@ sRefSet usymtab_allAliases (sRef s)
 /*@only@*/ sRefSet usymtab_canAlias (sRef s)
      /*@globals utab@*/
 {
-  if (sRef_isMeaningful (s))
+  if (sRef_isSomewhatMeaningful (s))
     {
       sRefSet res = aliasTable_canAlias (utab->aliases, s);
       return res;
@@ -5706,7 +5813,7 @@ usymtab_printOut (void)
   int depth = 0;
   char *ind = mstring_copy ("               ");
 
-  fprintf (g_msgstream, "<<< [symbol table] >>>\n");
+  fprintf (g_warningstream, "<<< [symbol table] >>>\n");
   
   while (s != GLOBAL_ENV && s->env != GLOBAL_ENV)
     {
@@ -5717,7 +5824,7 @@ usymtab_printOut (void)
          ind[depth * 3 + 1] = '\0';
        }
      
-      fprintf (g_msgstream, "level: %d (%s)\n", s->lexlevel,
+      fprintf (g_warningstream, "level: %d (%s)\n", s->lexlevel,
               cstring_toCharsSafe (tname));
 
       cstring_free (tname);
@@ -5725,17 +5832,17 @@ usymtab_printOut (void)
       for (i = 0; i < s->nentries; i++)
        {
          cstring us = uentry_unparseFull (s->entries[i]);
-         fprintf (g_msgstream, "%s\n", cstring_toCharsSafe (us));
+         fprintf (g_warningstream, "%s\n", cstring_toCharsSafe (us));
          cstring_free (us);
        }
       
       if (s->reftable != NULL && s->nentries > 0)
        {
-         fprintf (g_msgstream, "\t<< Ref table >>\n");
+         fprintf (g_warningstream, "\t<< Ref table >>\n");
 
          for (i = 0; i < s->nentries; i++)
            {
-             fprintf (g_msgstream, "\t%s %3d: %d, %d\n", ind, i, 
+             fprintf (g_warningstream, "\t%s %3d: %d, %d\n", ind, i, 
                       s->reftable[i]->level,
                       s->reftable[i]->index);
            }
@@ -5745,7 +5852,7 @@ usymtab_printOut (void)
       depth++;
       s = s->env;
     }
-  fprintf (g_msgstream, "<<< end usymtab >>>\n");
+  fprintf (g_warningstream, "<<< end usymtab >>>\n");
   mstring_free (ind);
   return;
 }
@@ -5766,7 +5873,7 @@ usymtab_printAll (void)
 
 static void
 usymtab_printAllAux (usymtab s)
-   /*@modifies g_msgstream@*/
+   /*@modifies g_warningstream@*/
 {
   int i;
   int depth = 0;
@@ -5842,7 +5949,7 @@ usymtab_printComplete ()
          for (i = looplow; i < s->nentries; i++)
            {
              printf ("%s%3d %s\n", ind, i, 
-                     cstring_toCharsSafe (uentry_unparse (s->entries[i])));
+                     cstring_toCharsSafe (uentry_unparseFull (s->entries[i])));
            }
        }
       else
@@ -5851,7 +5958,7 @@ usymtab_printComplete ()
          for (i = 0; i < s->nentries; i++)
            {
              printf ("%s%3d %s\n", ind, i, 
-                    cstring_toCharsSafe (uentry_unparse (s->entries[i])));
+                    cstring_toCharsSafe (uentry_unparseFull (s->entries[i])));
            }
        }
       
@@ -5864,7 +5971,7 @@ usymtab_printComplete ()
   mstring_free (ind);
 }
 
-# ifdef __LCLINT__
+# ifdef S_SPLINT_S
 static /*@only@*/ cstring /*@unused@*/ 
 usymtab_unparseLocalAux (/*@notnull@*/ usymtab s)
 {
@@ -5942,9 +6049,9 @@ usymtab_printLocal (void)
 
 static bool checkDistinctExternalName (uentry e)
   /*@globals globtab@*/
-  /*@modifies *g_msgstream@*/
+  /*@modifies *g_warningstream@*/
 {
-  int checklen = context_getValue (FLG_EXTERNALNAMELEN);
+  size_t checklen = size_fromInt (context_getValue (FLG_EXTERNALNAMELEN));
   bool ignorecase = context_getFlag (FLG_EXTERNALNAMECASEINSENSITIVE);
   bool gotone = FALSE;
   bool extras = FALSE;
@@ -6019,7 +6126,7 @@ static bool checkDistinctExternalName (uentry e)
                            "in the first %d characters (%q)",
                            uentry_getName (e),
                            uentry_getName (oe),
-                           checklen,
+                           size_toInt (checklen),
                            cstring_clip (uentry_getName (e), checklen)),
                           /*@=sefparams@*/
                           uentry_whereLast (e)))
@@ -6045,7 +6152,7 @@ static bool checkDistinctExternalName (uentry e)
                            "is ignored",
                            uentry_getName (e),
                            uentry_getName (oe),
-                           checklen),
+                           size_toInt (checklen)),
                           uentry_whereLast (e)))
                        {
                          uentry_showWhereAny (oe);
@@ -6071,7 +6178,7 @@ static bool checkDistinctExternalName (uentry e)
                    "in the first %d characters (%q)",
                    uentry_getName (e),
                    uentry_getName (oe),
-                   checklen,
+                   size_toInt (checklen),
                    cstring_clip (uentry_getName (e), checklen)),
                   /*@=sefparams@*/
                   uentry_whereLast (e)))
@@ -6103,11 +6210,11 @@ static bool checkDistinctExternalName (uentry e)
 
 static bool checkDistinctInternalName (uentry e)
   /*@globals utab@*/
-  /*@modifies *g_msgstream@*/
+  /*@modifies *g_warningstream@*/
 {
   usymtab ttab = utab;
   cstring name = uentry_rawName (e);
-  int numchars = context_getValue (FLG_INTERNALNAMELEN);
+  size_t numchars = size_fromInt (context_getValue (FLG_INTERNALNAMELEN));
   bool caseinsensitive = context_getFlag (FLG_INTERNALNAMECASEINSENSITIVE);
   bool lookalike = context_getFlag (FLG_INTERNALNAMELOOKALIKE);
 
@@ -6147,7 +6254,7 @@ static bool checkDistinctInternalName (uentry e)
                        "in the first %d characters (%q)",
                        uentry_getName (e),
                        uentry_getName (oe),
-                       numchars,
+                       size_toInt (numchars),
                        cstring_clip (uentry_getName (e), numchars)),
                       /*@=sefparams@*/
                       uentry_whereLast (e)))
@@ -6160,8 +6267,7 @@ static bool checkDistinctInternalName (uentry e)
              /*@switchbreak@*/
              break;
            case CGE_CASE:
-             if (numchars == 0 
-                 || (cstring_length (name) <= numchars))
+             if (numchars == 0 || (cstring_length (name) <= numchars))
                {
                  if (optgenerror 
                      (FLG_DISTINCTINTERNALNAMES,
@@ -6186,7 +6292,7 @@ static bool checkDistinctInternalName (uentry e)
                        "in the first %d characters without case sensitivity",
                        uentry_getName (e),
                        uentry_getName (oe),
-                       numchars),
+                       size_toInt (numchars)),
                       uentry_whereLast (e)))
                    {
                      uentry_showWhereAny (oe);
@@ -6223,7 +6329,7 @@ static bool checkDistinctInternalName (uentry e)
                        "in the first %d characters except by lookalike characters",
                        uentry_getName (e),
                        uentry_getName (oe),
-                       numchars),
+                       size_toInt (numchars)),
                       uentry_whereLast (e)))
                    {
                      uentry_showWhereAny (oe);
@@ -6278,3 +6384,36 @@ void usymtab_checkDistinctName (uentry e, int scope)
   return uentry_getSref (ue);
 }
 
+
+# ifdef DEBUGSPLINT
+/*
+** For debugging only
+*/
+
+void
+usymtab_checkAllValid () /*@globals utab@*/ 
+{
+  usymtab tab = utab;
+
+  while (tab != GLOBAL_ENV)
+    {
+      int i;
+
+      for (i = 0; i < utab->nentries; i++)
+       {
+         uentry e = utab->entries[i];
+         
+         uentry_checkValid (e);
+       }
+
+      aliasTable_checkValid (tab->aliases);
+      tab = tab->env;
+    }
+}
+# endif
+
+
+
+
+
+
This page took 0.092329 seconds and 4 git commands to generate.