]> andersk Git - splint.git/blobdiff - src/flagMarkerList.c
noexpand always false.
[splint.git] / src / flagMarkerList.c
index cd3fe675891698acd8e1cb3012f35a155f0b430c..7b557cf392c0cf4dd2786e9bd223781677812184 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
 */
 /*
 ** flagMarkerList.c
 ** invariant: flagMarker's are listed in order
 */
 
-# include "lclintMacros.nf"
+# include "splintMacros.nf"
 # include "basic.h"
 
+static int flagMarkerList_lastBeforeLoc (flagMarkerList p_s, fileloc p_loc) /*@*/ ;
+
+static bool
+flagMarkerList_contains (flagMarkerList p_s, flagMarker p_fm) /*@*/ ;
+
 flagMarkerList
   flagMarkerList_new ()
 {
@@ -67,48 +72,59 @@ flagMarkerList_grow (flagMarkerList s)
   s->elements = newelements;
 }
 
-void flagMarkerList_add (flagMarkerList s, flagMarker fm)
+bool flagMarkerList_add (flagMarkerList s, flagMarker fm)
 {
   int i = s->nelements - 1;
+  int lastloc;
+
+  DPRINTF (("Add: %s", flagMarker_unparse (fm)));
+
+  if (flagMarkerList_contains (s, fm))
+    {
+      flagMarker_free (fm);
+      DPRINTF (("List contains: %s", flagMarkerList_unparse (s)));
+      return FALSE;
+    }
 
-  
   if (i > 0)
     {
       flagMarker last = s->elements[i];
 
-      
       if (flagMarker_isIgnoreCount (last))
        {
          if (!flagMarker_isIgnoreOff (fm))
            {
              if (flagMarker_isLocalSet (fm))
                {
-                 llforceerror 
-                   (FLG_WARNFLAGS,
-                    cstring_makeLiteral ("Cannot set flag inside ignore "
-                                         "count region."),
-                    flagMarker_getLoc (fm));
-                 llgenindentmsg 
-                   (cstring_makeLiteral ("Ignore count region starts"),
-                    flagMarker_getLoc (last));
-
+                 if (llforceerror 
+                     (FLG_WARNFLAGS,
+                      cstring_makeLiteral ("Cannot set flag inside ignore "
+                                           "count region."),
+                      flagMarker_getLoc (fm)))
+                   {
+                     llgenindentmsg 
+                       (cstring_makeLiteral ("Ignore count region starts"),
+                        flagMarker_getLoc (last));
+                   }
                }
              else 
                {
                  if (flagMarker_isIgnoreOn (fm)) 
                    {
-                     llforceerror 
-                       (FLG_WARNFLAGS,
-                        cstring_makeLiteral ("Cannot nest ignore regions."),
-                        flagMarker_getLoc (fm));
-                     llgenindentmsg 
-                       (cstring_makeLiteral ("Previous ignore region starts"),
-                        flagMarker_getLoc (last));
+                     if (llforceerror 
+                         (FLG_WARNFLAGS,
+                          cstring_makeLiteral ("Cannot nest ignore regions."),
+                          flagMarker_getLoc (fm)))
+                       {
+                         llgenindentmsg 
+                           (cstring_makeLiteral ("Previous ignore region starts"),
+                            flagMarker_getLoc (last));
+                       }
                    }
                }
 
              flagMarker_free (fm);
-             return;
+             return FALSE;
            }
        }
       else 
@@ -116,72 +132,61 @@ void flagMarkerList_add (flagMarkerList s, flagMarker fm)
          if (flagMarker_isIgnoreOff (last))
            {
              flagMarker nlast = s->elements [i - 1];
-             
+
              if (flagMarker_isIgnoreCount (nlast))
                {
-                 if (fileloc_sameFile (flagMarker_getLoc (fm),
-                                       flagMarker_getLoc (last))
-                     && fileloc_notAfter (flagMarker_getLoc (fm), 
-                                          flagMarker_getLoc (last)))
+                 if (fileloc_sameFileAndLine (flagMarker_getLoc (fm),
+                                              flagMarker_getLoc (nlast)))
                    {
                      if (flagMarker_isLocalSet (fm))
                        {
-                         llforceerror 
-                           (FLG_WARNFLAGS,
-                            cstring_makeLiteral ("Cannot set flag inside ignore "
-                                                 "count region."),
-                            flagMarker_getLoc (fm));
-                         llgenindentmsg 
-                           (cstring_makeLiteral ("Ignore count region starts"),
-                            flagMarker_getLoc (nlast));
-                         
+                         if (llforceerror 
+                             (FLG_WARNFLAGS,
+                              cstring_makeLiteral
+                              ("Cannot set flag inside ignore "
+                               "count region."),
+                              flagMarker_getLoc (fm))) 
+                           {
+                             llgenindentmsg 
+                               (cstring_makeLiteral 
+                                ("Ignore count region starts"),
+                                flagMarker_getLoc (nlast));
+                             DPRINTF (("Last: %s / %s",
+                                       fileloc_unparse (flagMarker_getLoc (last)),
+                                       fileloc_unparse (flagMarker_getLoc (fm))));
+                             
+                           }
                        }
                      else 
                        {
                          if (flagMarker_isIgnoreOn (fm)) 
                            {
-                             llforceerror 
-                               (FLG_WARNFLAGS,
-                                cstring_makeLiteral ("Cannot nest ignore regions."),
-                                flagMarker_getLoc (fm));
-                             llgenindentmsg 
-                               (cstring_makeLiteral ("Previous ignore region starts"),
-                                flagMarker_getLoc (nlast));
+                             if (llforceerror 
+                                 (FLG_WARNFLAGS,
+                                  cstring_makeLiteral ("Cannot nest ignore regions."),
+                                  flagMarker_getLoc (fm))) 
+                               {
+                                 llgenindentmsg 
+                                   (cstring_makeLiteral ("Previous ignore region starts"),
+                                    flagMarker_getLoc (nlast));
+                               }
                            }
                        }
                      
                      flagMarker_free (fm);
-                     return;
+                     return FALSE;
                    }
                }
            }
        }
     }
 
-  
-  /*
-  ** all this code is necessary to check the invariant is preserved
-  */
-
-  while (i > 0
-        && !flagMarker_sameFile (s->elements[i],
-                                 flagMarker_getLoc (fm))) 
-    {
-      i--;
-    }
 
   /*
-  ** reprocessing header file, okay to be out of order
+  ** Need to insert this flag in the right place (after the last before loc flag)
   */
 
-  if (i >= 0 && !fileloc_isHeader (flagMarker_getLoc (fm)))
-    {
-                  
-      /*
-      llassert (!flagMarker_beforeMarker (s->elements[i], 
-                                         flagMarker_getLoc (fm)));
-                                         */
-    }
+  lastloc = flagMarkerList_lastBeforeLoc (s, flagMarker_getLoc (fm));
 
   if (s->nspace <= 0)
     {
@@ -189,9 +194,31 @@ void flagMarkerList_add (flagMarkerList s, flagMarker fm)
     }
   
   s->nspace--;
-  s->elements[s->nelements] = fm;
+
+  if (lastloc == -1)
+    {
+      /* Add it to the end of the list */
+      s->elements[s->nelements] = fm;
+    }
+  else
+    {
+      DPRINTF (("Inserting: %s in %s", 
+               flagMarker_unparse (fm),
+               flagMarkerList_unparse (s)));
+
+      /* Insert it at location lastloc + 1, push other flags down */
+      for (i = s->nelements; i > lastloc + 1; i--)
+       {
+         s->elements [i] = s->elements [i - 1];
+       }
+
+      s->elements [lastloc + 1] = fm;
+
+    }
+
   s->nelements++;
-  }
+  return TRUE;
+}
 
 void flagMarkerList_checkSuppressCounts (flagMarkerList s)
 {
@@ -200,12 +227,14 @@ void flagMarkerList_checkSuppressCounts (flagMarkerList s)
   fileloc loc = fileloc_undefined;
   bool inCount = FALSE;
   int i;
-
   
   for (i = 0; i < s->nelements; i++)
     {
       flagMarker current = s->elements[i];
-
+      DPRINTF (("flagMarker: %s / %s",
+               flagMarker_unparse (current),
+               bool_unparse (inCount)));
+      
       if (flagMarker_isIgnoreCount (current))
        {
          llassert (!inCount);
@@ -213,7 +242,7 @@ void flagMarkerList_checkSuppressCounts (flagMarkerList s)
          nexpected = flagMarker_getCount (current);
          loc = flagMarker_getLoc (current);
          nsuppressed = 0;
-               }
+       }
       else if (flagMarker_isIgnoreOff (current))
        {
          if (inCount)
@@ -223,10 +252,11 @@ void flagMarkerList_checkSuppressCounts (flagMarkerList s)
 
              if (nexpected > 0 && nexpected != nsuppressed)
                {
-                 llforceerror 
+                 /* Must use forceerror to prevent self-suppression! */
+                 llforceerror
                    (FLG_SUPCOUNTS,
                     message 
-                    ("Line expects to suppress %d error%p, found %d error%p",
+                    ("Line expects to suppress %d error%&, found %d error%&",
                      nexpected, nsuppressed),
                     loc);
                }
@@ -310,23 +340,6 @@ flagMarkerList_free (flagMarkerList s)
   sfree (s);
 }
 
-/*
-** returns YES iff
-**    > in ignore region (there is an ignore ON marker not followed by OFF)
-**    > code is OFF (-)
-**
-** returns NO iff
-**    > not in ignore region
-**    > code is ON (+)
-**
-** returns MAYBE iff
-**    > not in ignore region
-**    > code is unset or =
-**
-** requires: invariant for flagMarkerList:
-**    flagMarker's are sorted by line and col
-*/
-
 static int
 flagMarkerList_lastBeforeLoc (flagMarkerList s, fileloc loc)
 {
@@ -341,17 +354,45 @@ flagMarkerList_lastBeforeLoc (flagMarkerList s, fileloc loc)
        {
          return i;
        }
-/*
-      if (flagMarker_sameFile (current, loc) 
-         && (!flagMarker_beforeMarker (current, loc)))
+    }
+
+  return -1;
+}
+
+static bool
+flagMarkerList_contains (flagMarkerList s, flagMarker fm)
+{
+  int i;
+
+  for (i = s->nelements - 1; i >= 0; i--) 
+    {
+      flagMarker current = s->elements[i];
+      
+      if (flagMarker_equal (current, fm))
        {
-         return i;
+         return TRUE;
        }
-*/
     }
 
-  return -1;
+  return FALSE;
 }
+
+/*
+** returns YES iff
+**    > in ignore region (there is an ignore ON marker not followed by OFF)
+**    > code is OFF (-)
+**
+** returns NO iff
+**    > not in ignore region
+**    > code is ON (+)
+**
+** returns MAYBE iff
+**    > not in ignore region
+**    > code is unset or =
+**
+** requires: invariant for flagMarkerList:
+**    flagMarker's are sorted by line and col
+*/
          
 ynm
 flagMarkerList_suppressError (flagMarkerList s, flagcode code, fileloc loc)
@@ -373,10 +414,10 @@ flagMarkerList_suppressError (flagMarkerList s, flagcode code, fileloc loc)
     {
       i = flagMarkerList_lastBeforeLoc (s, loc);
     }
-
   
   if (i < 0)
     {
+      DPRINTF (("RETURNING!"));
       return MAYBE;
     }
   
@@ -387,10 +428,12 @@ flagMarkerList_suppressError (flagMarkerList s, flagcode code, fileloc loc)
   for (; i >= 0; i--) 
     {
       flagMarker current = s->elements[i];
-
       
+      DPRINTF (("Check current: %s", flagMarker_unparse (current)));
+
       if (!islib && !flagMarker_sameFile (current, loc))
        {
+         DPRINTF (("Not same file: %s", fileloc_unparse (loc)));
          break;
        }
 
@@ -434,7 +477,7 @@ flagMarkerList_suppressError (flagMarkerList s, flagcode code, fileloc loc)
                    }
                  else
                    {
-                                     flagOff = TRUE;
+                     flagOff = TRUE;
                      flagSet = MAYBE;
                    }
                  
@@ -470,7 +513,7 @@ flagMarkerList_suppressError (flagMarkerList s, flagcode code, fileloc loc)
                    }
                  else
                    {
-                                     nameChecksOff = TRUE;
+                     nameChecksOff = TRUE;
                      flagSet = MAYBE;
                    }
                  
This page took 0.563619 seconds and 4 git commands to generate.