]> andersk Git - splint.git/blobdiff - src/fileloc.c
Fixed problem with shadow parameters.
[splint.git] / src / fileloc.c
index 91bcf9e5d21e59c3f207b6e93516e4be841c19b5..0c6cb2f6c734f918764c885f51a9e9bb9f0690e3 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** Copyright (C) 1994-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
 */
 /*
  * Modified by Herbert 04/19/97:
- * - added new include file portab.h.
+ * - added new include file portab.h (now in osd.h)
  * - added new private function fileloc_filenameForCpp() to handle
  *   filenames belonging to "#line" statements for OS/2 and MSDOS. It
  *   gets called by fileloc_lineMarker() and fileloc_previousLineMarker()
  */
 
 # include "splintMacros.nf"
-# include "llbasic.h"
-# include "fileIdList.h"
+# 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)
 {
@@ -64,9 +84,11 @@ 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));
+      llassertprint (ret->column > x, ("decColumn %s: %d", fileloc_unparse (f), x));
       ret->column -= x;
     }
 
@@ -290,7 +312,6 @@ fileloc_notAfter (fileloc f1, fileloc f2)
   /*@noaccess fileId@*/
 }
 
-# ifndef NOLCL
 bool
 fileloc_isStandardLibrary (fileloc f)
 {
@@ -303,7 +324,6 @@ fileloc_isStandardLibrary (fileloc f)
          || cstring_equalLit (s, LLPOSIXSTRICTLIBS_NAME)
          || cstring_equalLit (s, LLPOSIXLIBS_NAME));
 }
-# endif
 
 bool
 fileloc_sameFileAndLine (fileloc f1, fileloc f2)
@@ -350,7 +370,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)); 
        }
     }
 }
@@ -429,7 +449,6 @@ fileloc_almostSameFile (fileloc f1, fileloc f2)
     }
 }
 
-# ifndef NOLCL
 /*@only@*/ fileloc
 fileloc_fromTok (ltoken t) 
 {
@@ -446,7 +465,6 @@ fileloc_fromTok (ltoken t)
   
   return (fl);
 }
-# endif
 
 /*@only@*/ fileloc
 fileloc_createLib (cstring ln)
@@ -481,14 +499,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 ()
@@ -540,13 +556,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)
 {
@@ -559,7 +582,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)
@@ -575,13 +597,11 @@ fileloc_createPrim (flkind kind, fileId fid, int line, int col)
   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)
 {
@@ -598,7 +618,14 @@ fileloc_filename (fileloc f)
 {
   if (fileloc_isDefined (f))
     {
-      return osd_outputPath (fileTable_rootFileName (f->fid));
+      if (fileId_isValid (f->fid))
+       {
+         return osd_outputPath (fileTable_rootFileName (f->fid));
+       }
+      else
+       {
+         return cstring_makeLiteral ("<invalid>");
+       }
     }
   else
     {
@@ -643,34 +670,50 @@ fileloc_column (fileloc f)
 /*@only@*/ cstring
 fileloc_unparse (fileloc f)
 {
+  static bool 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)
        {
        case FL_BUILTIN:
-         return (cstring_makeLiteral ("Command Line"));
+         {
+           res = cstring_makeLiteral ("Command Line");
+           break;
+         }
        case FL_IMPORT:
          if (parenFormat)
            {
-             return (message ("import file %q(%d)", fileloc_outputFilename (f), f->lineno));
+             res = message ("import file %q(%d)", fileloc_outputFilename (f), f->lineno);
            }
          else
            {
-             return (message ("import file %q:%d", fileloc_outputFilename (f), f->lineno));
+             res = message ("import file %q:%d", fileloc_outputFilename (f), f->lineno);
            }
+         break;
        case FL_PREPROC:
-         if (parenFormat)
-           {
-             return (message ("%q(%d)", fileloc_outputFilename (f), f->lineno));
-           }
-         else
-           {
-             return (message ("%q:%d", fileloc_outputFilename (f), 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:
          {
            cstring fname;
@@ -678,6 +721,12 @@ fileloc_unparse (fileloc f)
            if (f->kind == FL_LIB)
              {
                fname = message ("load file %q", fileloc_outputFilename (f));
+
+               if (!context_getFlag (FLG_SHOWLOADLOC))
+                 {
+                   res = fname;
+                   break;
+                 }
              }
            else
              {
@@ -692,84 +741,112 @@ fileloc_unparse (fileloc f)
                      {
                        if (parenFormat)
                          {
-                           return (message ("%q(%d,%d)", fname, f->lineno, f->column));
+                           res = message ("%q(%d,%d)", fname, f->lineno, f->column);
                          }
                        else
                          {
-                           return (message ("%q:%d:%d", fname, f->lineno, f->column));
+                           res = message ("%q:%d:%d", fname, f->lineno, f->column);
                          }
                      }
                    else
                      {
                        if (parenFormat)
                          {
-                           return (message ("%q(%d)", fname, f->lineno));
+                           res = message ("%q(%d)", fname, f->lineno);
                          }
                        else
                          {
-                           return (message ("%q:%d", fname, f->lineno));
+                           res = message ("%q:%d", fname, f->lineno);
                          }
                      }
                  }
-               
-               return fname;
+               else
+                 {
+                   res = fname;
+                   /*@-branchstate@*/ /* spurious warnings reporteded because of break above */
+                 }
              }
            else if (fileloc_linenoDefined (f))
              {
                if (parenFormat)
                  {
-                   return (message ("%q(%d)", fname, f->lineno));
+                   res = message ("%q(%d)", fname, f->lineno);
                  }
                else
                  {
-                   return (message ("%q:%d", fname, f->lineno));
+                   res = message ("%q:%d", fname, f->lineno);
                  }
              }
            else
              {
-               return fname;
+               res = fname;
              }
          }
        }
-    }
 
-  return (cstring_makeLiteral ("< Location unknown >"));
+       if (htmlFormat && fileloc_linenoDefined (f))
+        {
+          res = message ("<a href=\"#line%d\">%s</a>", f->lineno, res);
+        }
+    }
+  else
+    {
+      res = 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 ("%q(%d)", osd_outputPath (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 ("%q:%d", osd_outputPath (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 ("%q(%d,%d)", osd_outputPath (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 ("%q:%d:%d", osd_outputPath (fname), lineno, col));
+         return fileloc_unparseRaw (fname, lineno);
        }
     }
   else
     {
-      return fileloc_unparseRaw (fname, lineno);
+      return cstring_makeLiteral ("Command Line");
     }
 }
 
This page took 0.054546 seconds and 4 git commands to generate.