]> andersk Git - splint.git/blobdiff - src/fileloc.c
Fixed all /*@i...@*/ tags (except 1).
[splint.git] / src / fileloc.c
index bf21ba4489eb16d01ea4f6f235d9f4006516fa00..84d9e3b969163097a6bb6de81784bb1885a98a88 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
 */
 /*
 ** fileloc.c
  *   instead of fileloc_unparseFilename().
  */
 
-# include "lclintMacros.nf"
-# include "llbasic.h"
-# include "fileIdList.h"
+# include "splintMacros.nf"
+# include "basic.h"
+# include "osd.h"
 # include "portab.h"
 
-static /*@only@*/ fileloc fileloc_createPrim (flkind p_kind, fileId p_fid, int p_line, int p_col);
+static /*@only@*/ fileloc fileloc_createPrim (flkind p_kind, fileId p_fid, int p_line, int p_col) /*@*/ ;
+
+/*
+** builtin locs are never free'd
+*/
+
+static /*@owned@*/ fileloc s_builtinLoc = fileloc_undefined;
+static /*@owned@*/ fileloc s_externalLoc = fileloc_undefined;
+
+void fileloc_destroyMod ()
+{
+  if (fileloc_isDefined (s_builtinLoc))
+    {
+      sfree (s_builtinLoc);
+      s_builtinLoc = fileloc_undefined;
+    }
+
+  if (fileloc_isDefined (s_externalLoc))
+    {
+      sfree (s_externalLoc);
+      s_externalLoc = fileloc_undefined;
+    }
+}
 
 static flkind fileId_kind (fileId s)
 {
-  cstring fname = rootFileName (s);
+  cstring fname = fileTable_rootFileName (s);
   
-  if (isLCLfile (fname))
+  if (fileLib_isLCLFile (fname))
     {
       return (FL_SPEC);
     }
-  else if (cstring_equalPrefix (fname, SYSTEM_LIBDIR))
+  else if (cstring_equalPrefix (fname, cstring_makeLiteralTemp (SYSTEM_LIBDIR)))
     {
       return (FL_STDHDR); 
     }
@@ -62,6 +84,9 @@ fileloc
 fileloc_decColumn (fileloc f, int x)
 {
   fileloc ret = fileloc_copy (f);
+
+  llassert (x >= 0);
+
   if (x > 0 && fileloc_isDefined (ret))
     {
       llassertprint (ret->column > x, ("decColumn: %d", x));
@@ -177,13 +202,14 @@ fileloc_free (/*@only@*/ fileloc f)
            }
          else
            {
-                     sfree (f);  
+             sfree (f);  
              /*@-branchstate@*/ 
            } 
        }
       else
        {
-               }
+         ; /* Don't free g_currentloc ever! */
+       }
       /*@=branchstate@*/
     }
 }
@@ -208,7 +234,7 @@ cstring fileloc_getBase (fileloc f)
 {
   llassert (fileloc_isDefined (f));
 
-  return (fileNameBase (f->fid));
+  return (fileTable_fileNameBase (f->fid));
 }
 
 bool
@@ -236,9 +262,13 @@ fileloc_compare (fileloc f1, fileloc f2)
   INTCOMPARERETURN (f1->fid, f2->fid); 
   /*@noaccess fileId@*/
 
-  INTCOMPARERETURN (f1->column, f2->column);
-  INTCOMPARERETURN (f1->lineno, f2->lineno); 
 
+  /* drl 8-11-01 fix what I think is a bug
+     lineno should more important than column number*/
+
+  INTCOMPARERETURN (f1->lineno, f2->lineno);   
+  INTCOMPARERETURN (f1->column, f2->column);
+  
   return 0;
 }
 
@@ -283,7 +313,6 @@ fileloc_notAfter (fileloc f1, fileloc f2)
   /*@noaccess fileId@*/
 }
 
-# ifndef NOLCL
 bool
 fileloc_isStandardLibrary (fileloc f)
 {
@@ -296,7 +325,14 @@ fileloc_isStandardLibrary (fileloc f)
          || cstring_equalLit (s, LLPOSIXSTRICTLIBS_NAME)
          || cstring_equalLit (s, LLPOSIXLIBS_NAME));
 }
-# endif
+
+bool
+fileloc_sameFileAndLine (fileloc f1, fileloc f2)
+{
+  return (fileloc_sameFile (f1, f2)
+         && (fileloc_isDefined (f1) && fileloc_isDefined (f2)
+             && f1->lineno == f2->lineno));
+}
 
 bool
 fileloc_sameFile (fileloc f1, fileloc f2)
@@ -335,7 +371,7 @@ fileloc_sameModule (fileloc f1, fileloc f2)
          cstring s1 = fileloc_getBase (f1);
          cstring s2 = fileloc_getBase (f2);
          
-         return (cstring_equal (s1, s2));
+         return (cstring_equal (s1, s2)); 
        }
     }
 }
@@ -369,6 +405,19 @@ bool fileloc_isSystemFile (fileloc f1)
   return FALSE;
 }
 
+bool fileloc_isXHFile (fileloc f1)
+{
+  if (fileloc_isDefined (f1)
+      && !fileloc_isBuiltin (f1)
+      && !fileloc_isExternal (f1))
+    {
+      DPRINTF (("Fileloc is XH: [%p] %s", f1, fileloc_unparse (f1)));
+      return (fileTable_isXHFile (context_fileTable (), f1->fid));
+    }
+  
+  return FALSE;
+}
+
 bool
 fileloc_almostSameFile (fileloc f1, fileloc f2)
 {
@@ -401,7 +450,6 @@ fileloc_almostSameFile (fileloc f1, fileloc f2)
     }
 }
 
-# ifndef NOLCL
 /*@only@*/ fileloc
 fileloc_fromTok (ltoken t) 
 {
@@ -418,7 +466,6 @@ fileloc_fromTok (ltoken t)
   
   return (fl);
 }
-# endif
 
 /*@only@*/ fileloc
 fileloc_createLib (cstring ln)
@@ -431,7 +478,7 @@ fileloc_createLib (cstring ln)
       fid = fileTable_addLibraryFile (context_fileTable (), ln);
     }
 
-  if (cstring_equalPrefix (ln, SYSTEM_LIBDIR))
+  if (cstring_equalPrefix (ln, cstring_makeLiteralTemp (SYSTEM_LIBDIR)))
     {
       fk = FL_STDLIB;
     }
@@ -453,14 +500,12 @@ fileloc fileloc_createExternal (void)
 
 fileloc fileloc_getExternal (void)
 {
-  static /*@owned@*/ fileloc res = fileloc_undefined;
-
-  if (res == fileloc_undefined) 
+  if (s_externalLoc == fileloc_undefined) 
     {
-      res = fileloc_createPrim (FL_EXTERNAL, fileId_invalid, 0, 0);
+      s_externalLoc = fileloc_createPrim (FL_EXTERNAL, fileId_invalid, 0, 0);
     }
 
-  return res;
+  return s_externalLoc;
 }
 
 fileloc fileloc_observeBuiltin ()
@@ -512,13 +557,20 @@ fileloc_makePreprocPrevious (fileloc loc)
   return (fileloc_createPrim (FL_PREPROC, fileId_invalid, 0, 0));
 }
 
+/* We pretend the result is only, because fileloc_free doesn't free it! */
 /*@only@*/ fileloc
 fileloc_createBuiltin ()
 {
-  return (fileloc_createPrim (FL_BUILTIN, fileId_invalid, 0, 0)); 
+  if (fileloc_isUndefined (s_builtinLoc))
+    {
+      s_builtinLoc = fileloc_createPrim (FL_BUILTIN, fileId_invalid, 0, 0); 
+    }
+
+  /*@-globstate@*/ /*@-retalias@*/ 
+  return s_builtinLoc;
+  /*@=globstate@*/ /*@=retalias@*/ 
 }
 
-# ifndef NOLCL
 /*@only@*/ fileloc
 fileloc_createImport (cstring fname, int lineno)
 {
@@ -531,7 +583,6 @@ fileloc_createImport (cstring fname, int lineno)
 
   return (fileloc_createPrim (FL_IMPORT, fid, lineno, 0));
 }
-# endif
 
 static /*@only@*/ fileloc
 fileloc_createPrim (flkind kind, fileId fid, int line, int col)
@@ -542,17 +593,16 @@ fileloc_createPrim (flkind kind, fileId fid, int line, int col)
   f->fid    = fid; 
   f->lineno = line;
   f->column = col;
-  
+
+  DPRINTF (("Fileloc create: [%p] %s", f, fileloc_unparse (f)));
   return (f);
 }
 
-# ifndef NOLCL
 /*@only@*/ fileloc
 fileloc_createSpec (fileId fid, int line, int col)
 {
   return (fileloc_createPrim (FL_SPEC, fid, line, col));
 }
-# endif
 
 fileloc fileloc_create (fileId fid, int line, int col)
 {
@@ -562,8 +612,26 @@ fileloc fileloc_create (fileId fid, int line, int col)
 /*@observer@*/ cstring
 fileloc_filename (fileloc f)
 {
-  return (fileloc_isDefined (f)
-         ? rootFileName (f->fid) : cstring_makeLiteralTemp ("<unknown>"));
+  return (fileloc_isDefined (f) ? fileTable_rootFileName (f->fid) : cstring_makeLiteralTemp ("<unknown>"));
+}
+
+/*@only@*/ cstring fileloc_outputFilename (fileloc f)
+{
+  if (fileloc_isDefined (f))
+    {
+      if (fileId_isValid (f->fid))
+       {
+         return osd_outputPath (fileTable_rootFileName (f->fid));
+       }
+      else
+       {
+         return cstring_makeLiteral ("<invalid>");
+       }
+    }
+  else
+    {
+      return cstring_makeLiteral ("<unknown>");
+    }
 }
 
 cstring
@@ -574,15 +642,15 @@ fileloc_unparseFilename (fileloc f)
       switch (f->kind)
        {
        case FL_LIB:
-         return (message ("load file %s", fileloc_filename (f)));
+         return (message ("load file %q", fileloc_outputFilename (f)));
        case FL_BUILTIN:
          return (cstring_makeLiteral ("# builtin #"));
        case FL_IMPORT:
-         return (message ("import file %s", fileloc_filename (f)));
+         return (message ("import file %q", fileloc_outputFilename (f)));
        case FL_EXTERNAL:
          return (cstring_makeLiteral ("<external>"));
        default: 
-         return (cstring_copy (fileloc_filename (f)));
+         return (fileloc_outputFilename (f));
        }
     }
   return cstring_undefined;
@@ -603,125 +671,183 @@ fileloc_column (fileloc f)
 /*@only@*/ cstring
 fileloc_unparse (fileloc f)
 {
+  static in_funparse = FALSE;
   bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); 
+  bool htmlFormat = context_getFlag (FLG_HTMLFILEFORMAT);
+  cstring res = cstring_undefined;
+
+  /* watch out for recursive calls when debugging... */
+  llassert (!in_funparse);
+  in_funparse = TRUE;
 
   if (fileloc_isDefined (f))
     {
-      switch (f->kind)
+       switch (f->kind)
        {
-       case FL_LIB:
-         return (message ("load file %s", rootFileName (f->fid)));
        case FL_BUILTIN:
-         return (cstring_makeLiteral ("Command Line"));
+         {
+           res = cstring_makeLiteral ("Command Line");
+           break;
+         }
        case FL_IMPORT:
          if (parenFormat)
            {
-             return (message ("import file %s(%d)", rootFileName (f->fid), f->lineno));
+             res = message ("import file %q(%d)", fileloc_outputFilename (f), f->lineno);
            }
          else
            {
-             return (message ("import file %s:%d", rootFileName (f->fid), f->lineno));
+             res = message ("import file %q:%d", fileloc_outputFilename (f), f->lineno);
            }
+         break;
        case FL_PREPROC:
-         if (parenFormat)
-           {
-             return (message ("%s(%d)", rootFileName (f->fid), f->lineno));
-           }
-         else
-           {
-             return (message ("%s:%d", rootFileName (f->fid), f->lineno));
-           }
+         {
+           if (parenFormat)
+             {
+               res = message ("%q(%d)", fileloc_outputFilename (f), f->lineno);
+             }
+           else
+             {
+               res = message ("%q:%d", fileloc_outputFilename (f), f->lineno);
+             }
+           
+           break;
+         }
        case FL_EXTERNAL:
-         return (cstring_makeLiteral ("<external>"));
+         res = cstring_makeLiteral ("<external>");
+         break;
        default:
-         if (context_getFlag (FLG_SHOWCOL))
-           {
-             if (fileloc_linenoDefined (f))
-               {
-                 if (fileloc_columnDefined (f))
-                   {
-                     if (parenFormat)
-                       {
-                         return (message ("%s(%d,%d)", 
-                                          rootFileName (f->fid),
-                                          f->lineno, f->column));
-                       }
-                     else
-                       {
-                         return (message ("%s:%d:%d", 
-                                          rootFileName (f->fid),
-                                          f->lineno, f->column));
-                       }
-                   }
-                 else
-                   {
-                     if (parenFormat)
-                       {
-                         return (message ("%s(%d)", rootFileName (f->fid), f->lineno));
-                       }
-                     else
-                       {
-                         return (message ("%s:%d", rootFileName (f->fid), f->lineno));
-                       }
-                   }
-               }
-             return (cstring_copy (rootFileName (f->fid)));
-           }
-         else if (fileloc_linenoDefined (f))
-           {
-             if (parenFormat)
-               {
-                 return (message ("%s(%d)",
-                                  rootFileName (f->fid), f->lineno));
-               }
-             else
-               {
-                 return (message ("%s:%d", rootFileName (f->fid), f->lineno));
-               }
-           }
-         else
-           {
-             return (cstring_copy (rootFileName (f->fid)));
-           }
+         {
+           cstring fname;
+           
+           if (f->kind == FL_LIB)
+             {
+               fname = message ("load file %q", fileloc_outputFilename (f));
+
+               if (!context_getFlag (FLG_SHOWLOADLOC))
+                 {
+                   res = fname;
+                   break;
+                 }
+             }
+           else
+             {
+               fname = fileloc_outputFilename (f);
+             }
+
+           if (context_getFlag (FLG_SHOWCOL))
+             {
+               if (fileloc_linenoDefined (f))
+                 {
+                   if (fileloc_columnDefined (f))
+                     {
+                       if (parenFormat)
+                         {
+                           res = message ("%q(%d,%d)", fname, f->lineno, f->column);
+                         }
+                       else
+                         {
+                           res = message ("%q:%d:%d", fname, f->lineno, f->column);
+                         }
+                     }
+                   else
+                     {
+                       if (parenFormat)
+                         {
+                           res = message ("%q(%d)", fname, f->lineno);
+                         }
+                       else
+                         {
+                           res = message ("%q:%d", fname, f->lineno);
+                         }
+                     }
+                 }
+               else
+                 {
+                   res = fname;
+                   /*@-branchstate@*/ /* spurious warnings reporteded because of break above */
+                 }
+             }
+           else if (fileloc_linenoDefined (f))
+             {
+               if (parenFormat)
+                 {
+                   res = message ("%q(%d)", fname, f->lineno);
+                 }
+               else
+                 {
+                   res = message ("%q:%d", fname, f->lineno);
+                 }
+             }
+           else
+             {
+               res = fname;
+             }
+         }
        }
+
+       if (htmlFormat && fileloc_linenoDefined (f))
+        {
+          res = message ("<a href=\"#line%d\">%s</a>", f->lineno, res);
+        }
+    }
+  else
+    {
+      res = cstring_makeLiteral ("< Location unknown >");
     }
-  return (cstring_makeLiteral ("< Location unknown >"));
+  /*@=branchstate@*/ /* this is a spurious warning because of the break */
+  
+  in_funparse = FALSE;
+  return res;
 }
 
 /*@only@*/ cstring
 fileloc_unparseRaw (cstring fname, int lineno)
 {
-  bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); 
-
-  if (parenFormat)
+  if (!cstring_isEmpty (fname))
     {
-      return (message ("%s(%d)", fname, lineno));
+      bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); 
+      
+      if (parenFormat)
+       {
+         return (message ("%q(%d)", osd_outputPath (fname), lineno));
+       }
+      else
+       {
+         return (message ("%q:%d", osd_outputPath (fname), lineno));
+       }
     }
   else
     {
-      return (message ("%s:%d", fname, lineno));
+      return cstring_makeLiteral ("Command Line");
     }
 }
 
 /*@only@*/ cstring
 fileloc_unparseRawCol (cstring fname, int lineno, int col)
 {
-  if (context_getFlag (FLG_SHOWCOL)) 
+  if (!cstring_isEmpty (fname))
     {
-      bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); 
-      
-      if (parenFormat)
+      if (context_getFlag (FLG_SHOWCOL)) 
        {
-         return (message ("%s(%d,%d)", fname, lineno, col));
+         bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); 
+         
+         if (parenFormat)
+           {
+             return (message ("%q(%d,%d)", osd_outputPath (fname), lineno, col));
+           }
+         else
+           {
+             return (message ("%q:%d:%d", osd_outputPath (fname), lineno, col));
+           }
        }
       else
        {
-         return (message ("%s:%d:%d", fname, lineno, col));
+         return fileloc_unparseRaw (fname, lineno);
        }
     }
   else
     {
-      return fileloc_unparseRaw (fname, lineno);
+      return cstring_makeLiteral ("Command Line");
     }
 }
 
@@ -757,11 +883,6 @@ bool fileloc_isRealSpec (fileloc f)
   return (fileloc_isDefined (f) && (f->kind == FL_SPEC));
 }
 
-bool fileloc_isRealLib (fileloc f)
-{
-  return (fileloc_isDefined (f) && f->kind == FL_LIB);
-}
-
 bool fileloc_isLib (fileloc f)
 {
   return (fileloc_isDefined (f) 
This page took 0.135366 seconds and 4 git commands to generate.