Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

lcllib.c File Reference

#include "lclintMacros.nf"
#include "llbasic.h"
#include "osd.h"
#include "gram.h"
#include "lclscan.h"
#include "herald.h"
#include "lcllib.h"
#include "llmain.h"
#include "portab.h"

Go to the source code of this file.

Defines

#define NUMLIBS   17
#define NUMPOSIXLIBS   12
#define BUFLEN   128

Functions

bool lcllib_isSkipHeader (cstring sname)
void dumpState (cstring cfname)
bool loadStandardState ()
void loadState (cstring cfname)

Variables

FILE* yyin = (FILE *) 0


Define Documentation

#define BUFLEN   128
 

Definition at line 395 of file lcllib.c.

#define NUMLIBS   17
 

Definition at line 56 of file lcllib.c.

#define NUMPOSIXLIBS   12
 

Definition at line 59 of file lcllib.c.


Function Documentation

void dumpState ( cstring cfname )
 

Definition at line 232 of file lcllib.c.

Referenced by main().

00233 {
00234   FILE *f;
00235   char *fname = cstring_toCharsSafe (cfname);
00236   
00237   fname = addExtension (fname, DUMP_SUFFIX);
00238   
00239   f = fopen (fname, "w");
00240 
00241   if (context_getFlag (FLG_SHOWSCAN))
00242     {
00243       fprintf (stderr, "< Dumping to %s ", fname); 
00244     }
00245   
00246   if (f == NULL)
00247     {
00248       llgloberror (message ("Cannot open dump file for writing: %s", cfname));
00249     }
00250   else
00251     {
00252       /*
00253       ** sequence is convulted --- must call usymtab_prepareDump before
00254       **    dumping ctype table to convert type uid's
00255       */
00256 
00257       printDot ();
00258 
00259       usymtab_prepareDump ();
00260 
00261       /*
00262       ** Be careful, these lines must match loadStateFile checking.
00263       */
00264 
00265       fprintf (f, ";;LCLint Dump: %s\n", fname);
00266       fprintf (f, ";;%s\n", LCL_VERSION);
00267       fprintf (f, ";;lib:%d\n", (int) context_getLibrary ());
00268       fprintf (f, ";;ctTable\n");
00269 
00270       printDot ();
00271             ctype_dumpTable (f);
00272       printDot ();
00273 
00274       fprintf (f, ";;tistable\n");
00275       typeIdSet_dumpTable (f);
00276       printDot ();
00277 
00278             fprintf (f, ";;symTable\n");
00279       usymtab_dump (f);
00280       printDot ();
00281 
00282       fprintf (f, ";; Modules access\n");
00283       context_dumpModuleAccess (f);
00284       fprintf (f, ";;End\n");
00285       check (fclose (f) == 0);
00286     }
00287 
00288   if (context_getFlag (FLG_SHOWSCAN))
00289     {
00290       fprintf (g_msgstream, " >\n");
00291     }
00292 
00293   sfree (fname);
00294 }

bool lcllib_isSkipHeader ( cstring sname )
 

Definition at line 101 of file lcllib.c.

00102 {
00103   int i;
00104   bool posixlib = FALSE;
00105   char *libname;
00106   char *name = cstring_toCharsSafe (sname);
00107   char *matchname;
00108 
00109   llassert (cstring_isDefined (sname));
00110   name = removeExtension (name, ".h");
00111 
00112   libname = strrchr (name, CONNECTCHAR);
00113   matchname = libname;
00114 
00115   if (libname == NULL) 
00116     {
00117       libname = name;
00118     }
00119   else
00120     {
00121       libname++;
00122       /*@-branchstate@*/
00123     }
00124   /*@=branchstate@*/
00125 
00126   if (mstring_equal (libname, "varargs"))
00127     {
00128       fileloc tmp = fileloc_makePreprocPrevious (g_currentloc);
00129       
00130       voptgenerror 
00131         (FLG_USEVARARGS,
00132          message ("Include file <%s> is inconsistent with "
00133                   "ANSI library (should use <stdarg.h>)",
00134                   cstring_fromChars (libname)),
00135          tmp);
00136       
00137       fileloc_free (tmp);
00138       sfree (name);
00139       return TRUE;
00140     }
00141 
00142   if (context_getFlag (FLG_SKIPANSIHEADERS)
00143       && context_usingAnsiLibrary ())
00144     {
00145       
00146       for (i = 0; i < NUMLIBS; i++)
00147         {
00148           if (mstring_equal (libname, stdlibs[i]))
00149             {
00150               sfree (name);
00151               return TRUE;
00152             }
00153         }
00154     }
00155 
00156   for (i = 0; i < NUMPOSIXLIBS; i++)
00157     {
00158       if (strchr (posixlibs[i], CONNECTCHAR) != NULL)
00159         {
00160           char *ptr;
00161           
00162           if ((ptr = strstr (name, posixlibs[i])) != NULL) 
00163             {
00164               if (ptr[strlen (posixlibs[i])] == '\0')
00165                 {
00166                   posixlib = TRUE;
00167                   matchname = ptr;
00168                   break;
00169                 }
00170               else
00171                 {
00172                   ; /* no match */
00173                 }
00174             }
00175         }
00176       else
00177         {
00178           if (mstring_equal (libname, posixlibs[i]))
00179             {
00180               posixlib = TRUE;
00181               matchname = libname;
00182               break;
00183             }
00184           /*@-branchstate@*/ 
00185         }
00186     } /*@=branchstate@*/
00187   
00188   if (posixlib)
00189     {
00190       if (context_usingPosixLibrary ())
00191         {
00192           if (context_getFlag (FLG_SKIPPOSIXHEADERS))
00193             {
00194               sfree (name);
00195               return TRUE;
00196             }
00197         }
00198       else
00199         {       
00200           fileloc tmp = fileloc_makePreprocPrevious (g_currentloc);           
00201           
00202           voptgenerror 
00203             (FLG_WARNPOSIX,
00204              message ("Include file <%s> matches the name of a "
00205                       "POSIX library, but the POSIX library is "
00206                       "not being used.  Consider using +posixlib "
00207                       "or +posixstrictlib to select the POSIX "
00208                       "library, or -warnposix "
00209                       "to suppress this message.",
00210                       cstring_fromChars (matchname)),
00211              tmp);
00212           
00213           fileloc_free (tmp);
00214         }
00215     }
00216 
00217   sfree (name);
00218   return FALSE;
00219 }

bool loadStandardState ( )
 

Definition at line 297 of file lcllib.c.

Referenced by loadState(), and main().

00298 {
00299   char *fpath;
00300   FILE *stdlib;
00301   bool result;
00302   char *libname = addExtension (context_selectedLibrary (), DUMP_SUFFIX);
00303   
00304   
00305   if (osd_findOnLarchPath (libname, &fpath) != OSD_FILEFOUND)
00306     {
00307       lldiagmsg (message ("Cannot find %sstandard library: %s", 
00308                           cstring_makeLiteralTemp 
00309                           (context_getFlag (FLG_STRICTLIB) ? "strict " 
00310                            : (context_getFlag (FLG_UNIXLIB) ? "unix " : "")),
00311                           cstring_makeLiteralTemp (libname)));
00312       lldiagmsg (cstring_makeLiteral ("     Check LARCH_PATH environment variable."));
00313       result = FALSE;
00314     }
00315   else
00316     {
00317       stdlib = fopen (fpath, "r");
00318 
00319       if (stdlib == NULL)
00320         {
00321           lldiagmsg (message ("Cannot read standard library: %s",
00322                           cstring_fromChars (fpath)));
00323           lldiagmsg (cstring_makeLiteral ("     Check LARCH_PATH environment variable."));
00324 
00325           result = FALSE;
00326         }
00327       else
00328         {
00329           if (context_getFlag (FLG_WHICHLIB))
00330             {
00331               char *t = mstring_create (MAX_NAME_LENGTH);
00332               char *ot = t;
00333 
00334               if (fgets (t, MAX_NAME_LENGTH, stdlib) == NULL)
00335                 {
00336                   llfatalerror (cstring_makeLiteral ("Standard library format invalid"));
00337                 }
00338 
00339               if (fgets (t, MAX_NAME_LENGTH, stdlib) != NULL)
00340                 {
00341                   if (*t == ';' && *(t + 1) == ';') 
00342                     {
00343                       t += 2;
00344                     }
00345                 }
00346 
00347               if (t == NULL)
00348                 {
00349                   lldiagmsg (message ("Standard library: %s <cannot read creation information>", 
00350                                   cstring_fromChars (fpath)));
00351                 }
00352               else
00353                 {
00354                   char *tt;
00355 
00356                   tt = strrchr (t, '\n');
00357                   if (tt != NULL)
00358                     *tt = '\0';
00359 
00360                   lldiagmsg (message ("Standard library: %s", cstring_fromChars (fpath)));
00361                   lldiagmsg (message ("   (created using %s)", cstring_fromChars (t)));
00362                 }
00363 
00364               sfree (ot);
00365               
00366               check (fclose (stdlib) == 0);
00367               stdlib = fopen (fpath, "r");
00368             }
00369 
00370           llassert (stdlib != NULL);
00371 
00372           fileloc_reallyFree (g_currentloc);
00373           g_currentloc = fileloc_createLib (cstring_makeLiteralTemp (libname));
00374 
00375           if (context_getDebug (FLG_SHOWSCAN))
00376             {
00377               context_hideShowscan ();
00378               result = loadStateFile (stdlib, cstring_fromChars (fpath));
00379               context_unhideShowscan ();
00380             }
00381           else
00382             {
00383               result = loadStateFile (stdlib, cstring_fromChars (fpath));
00384             }
00385 
00386           check (fclose (stdlib) == 0);
00387         }
00388     }
00389 
00390   sfree (libname);
00391   return result;
00392 }

void loadState ( cstring cfname )
 

Definition at line 529 of file lcllib.c.

Referenced by main().

00530 {
00531   FILE *f;
00532   char *fname = cstring_toCharsSafe (cfname);
00533   cstring ofname = cstring_copy (cfname);
00534 
00535   fname = addExtension (fname, DUMP_SUFFIX);
00536 
00537   f = fopen (fname, "r");
00538 
00539   if (f == NULL)
00540     {
00541       if (context_getDebug (FLG_SHOWSCAN))
00542         fprintf (g_msgstream, " >\n");
00543 
00544       llfatalerror (message ("Cannot open dump file for loading: %s", cfname));
00545     }
00546   else
00547     {
00548       fileloc_reallyFree (g_currentloc);
00549       g_currentloc = fileloc_createLib (ofname);
00550 
00551       if (!loadStateFile (f, ofname)) 
00552         {
00553           if (!loadStandardState ()) 
00554             {
00555               ctype_initTable ();
00556             }
00557         }
00558       
00559       check (fclose (f) == 0);
00560     }
00561 
00562   cstring_free (ofname);
00563   sfree (fname);
00564 }


Variable Documentation

FILE * yyin = (FILE *) 0
 

Definition at line 265 of file lex.yy.c.


Generated at Fri Nov 3 18:57:59 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000