]> andersk Git - splint.git/blobdiff - src/context.c
Removed obsolete OS/2 test makefiles.
[splint.git] / src / context.c
index 57953ff3c5d470ef36fc6c1d08be0001329f35f8..0f1906b921bdf4f761bf2dbe48ac5e86f4f5b28e 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
 */
 /*
 ** context.c
  *   or, if not set "." will be used.
  */
 
-# include "lclintMacros.nf"
-# include "llbasic.h"
+# include "splintMacros.nf"
+# include "basic.h"
 
-# ifndef NOLCL
 # include "usymtab_interface.h"
-# endif
-
 # include "exprChecks.h"
 # include "filelocStack.h"
-# include "fileIdList.h"
 # include "llmain.h"
 # include "intSet.h"
 # include "osd.h"
-# include "portab.h"
 
 extern /*@external@*/ int yydebug;
+extern /*@external@*/ int mtdebug;
 
 typedef struct
 { 
   cstring file; 
-  typeIdSet daccess 
+  typeIdSet daccess; 
 } maccesst;
 
 typedef enum { 
+  CX_ERROR,
+
   CX_GLOBAL, CX_INNER, 
-  CX_FUNCTION, CX_FCNDECL,
+  CX_FUNCTION, CX_FCNDECLARATION,
   CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO, 
-  CX_ITERDEF, CX_ITEREND,
-  CX_LCL, CX_LCLLIB
+  CX_ITERDEF, CX_ITEREND, 
+  CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
+  CX_LCL, CX_LCLLIB, CX_MT
 } kcontext;
 
-static struct _context
+static struct
 {
   int linesprocessed;
   int speclinesprocessed;
@@ -91,6 +90,7 @@ static struct _context
   bool savedFlags  BOOLBITS;
   bool justpopped  BOOLBITS;
   bool anyExports BOOLBITS;
+  bool inFunctionHeader BOOLBITS;
 
   flagcode library;
 
@@ -102,6 +102,7 @@ static struct _context
   clause inclause;
 
   int numerrors;
+  int numbugs;
 
   filelocStack locstack;
   fileTable ftab;
@@ -142,14 +143,19 @@ static struct _context
   int counters[NUMVALUEFLAGS];
 
   o_cstring strings[NUMSTRINGFLAGS];
-  sRefSetList modrecs;
+  sRefSetList modrecs; /* Keep track of file static symbols modified. */
 
-  union 
+  metaStateTable stateTable; /* User-defined state information. */
+  annotationTable annotTable; /* User-defined annotations table. */
+  union u_cont
     {
       bool glob;
       int  cdepth;
       /*@dependent@*/ /*@exposed@*/ uentry  fcn;
     } cont;
+
+  kcontext savekind;
+  union u_cont savecont;
 } gc;
 
 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
@@ -161,14 +167,16 @@ static void context_exitClauseSimp (void)  /*@modifies gc@*/ ;
 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
-static void context_setFlag (flagcode p_f, bool p_b)
+static void context_setFlag (flagcode p_f, bool p_b, fileloc p_loc)
   /*@modifies gc.flags@*/ ;
 
 static void
-  context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, bool p_isRestore)
+  context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, 
+                     bool p_isRestore, fileloc p_loc)
   /*@modifies gc.flags@*/ ;
 
-static void context_restoreFlag (flagcode p_f) /*@modifies gc.flags@*/ ;
+static void context_restoreFlag (flagcode p_f, fileloc p_loc)
+  /*@modifies gc.flags@*/ ;
 
 /*@+enumindex@*/ 
 
@@ -194,6 +202,16 @@ bool context_isPreprocessing (void)
   return gc.preprocessing;
 }
 
+bool context_loadingLibrary (void)
+{
+  return (fileloc_isLib (g_currentloc));
+}
+
+bool context_inXHFile (void)
+{
+  return (fileloc_isXHFile (g_currentloc));
+}
+
 void context_setInCommandLine (void)
 {
   llassert (!gc.incommandline);
@@ -245,13 +263,14 @@ clause topClause (clauseStack s) /*@*/
 void
 context_addMacroCache (/*@only@*/ cstring def)
 {
-    macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
+  DPRINTF (("macro cache: %s", def));
+  macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
 }
 
 void
-context_addComment (/*@only@*/ cstring def)
+context_addComment (/*@only@*/ cstring def, fileloc loc)
 {
-    macrocache_addComment (gc.mc, fileloc_copy (g_currentloc), def);
+  macrocache_addComment (gc.mc, fileloc_copy (loc), def);
 }
 
 /*
@@ -310,18 +329,22 @@ context_suppressFlagMsg (flagcode flag, fileloc fl)
       return TRUE;
     }
 
+  DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
+
   /* want same object compare here */
 
   if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
     {
+      DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
+
       return (!context_getFlag (flag)
              || context_inSuppressRegion ()
              || context_inSuppressZone (fl)
-             || (gc.inDerivedFile && context_inSuppressFlagZone (fl, flag)));
+             || (context_inSuppressFlagZone (fl, flag))); /* removed gc.inDerivedFile from this */
     }
   else
     {
-            return (context_inSuppressFlagZone (fl, flag));
+      return (context_inSuppressFlagZone (fl, flag));
     }
 }
 
@@ -365,39 +388,47 @@ context_inSuppressRegion (void)
 }
 
 void
-context_enterSuppressRegion (void)
+context_enterSuppressRegion (fileloc loc)
 {
   if (gc.insuppressregion)
     {
       gc.insuppressregion = FALSE;     /* get this msg! */
       llmsg (message
             ("%q: New ignore errors region entered while in ignore errors region",
-             fileloc_unparse (g_currentloc)));
+             fileloc_unparse (loc)));
     }
   
   gc.insuppressregion = TRUE;
-  flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (g_currentloc));
+  (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (loc));
 }
 
 static void
-context_addFlagMarker (flagcode code, ynm set)
+context_addFlagMarker (flagcode code, ynm set, fileloc loc)
 {
-  flagMarkerList_add (gc.markers,
-                     flagMarker_createLocalSet (code, set, g_currentloc));
+  (void) flagMarkerList_add (gc.markers,
+                            flagMarker_createLocalSet (code, set, loc));
 }
 
 void
-context_enterSuppressLine (int count)
+context_enterSuppressLine (int count, fileloc loc)
 {
-  fileloc nextline = fileloc_copy (g_currentloc);
+  if (context_processingMacros ())
+    {
+      return;
+    }
 
-  flagMarkerList_add (gc.markers,
-                     flagMarker_createIgnoreCount (count, g_currentloc));
+  if (flagMarkerList_add 
+      (gc.markers,
+       flagMarker_createIgnoreCount (count, loc)))
+    {
+      fileloc nextline = fileloc_copy (loc);
+      fileloc_nextLine (nextline);
+      fileloc_setColumn (nextline, 0);
 
-  fileloc_nextLine (nextline);
-  flagMarkerList_add (gc.markers,
-                     flagMarker_createIgnoreOff (nextline));
-  fileloc_free (nextline);
+      check (flagMarkerList_add (gc.markers,
+                                flagMarker_createIgnoreOff (nextline)));
+      fileloc_free (nextline);
+    }
 }
 
 void context_checkSuppressCounts (void)
@@ -415,26 +446,39 @@ void context_incLineno (void)
 }
 
 void
-context_exitSuppressRegion (void)
+context_exitSuppressRegion (fileloc loc)
 {
   if (!gc.insuppressregion)
     {
-      llerrorlit (FLG_SYNTAX, 
-                 "End ignore errors in region while not ignoring errors");
+      voptgenerror 
+       (FLG_SYNTAX, 
+        message ("End ignore errors in region while not ignoring errors"),
+        loc);
     }
+  
+  gc.insuppressregion = FALSE;
+  (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (loc));
+}
+
+void
+context_enterMTfile (void)
+{
+  gc.kind = CX_MT;
+}
 
-    gc.insuppressregion = FALSE;
-  flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (g_currentloc));
+void
+context_exitMTfile (void)
+{
+  llassert (gc.kind == CX_MT);
+  gc.kind = CX_GLOBAL;
 }
 
-# ifndef NOLCL
 void
 context_enterLCLfile (void)
 {
   gc.kind = CX_LCL;
   gc.facct = typeIdSet_emptySet ();
 }
-# endif
 
 static void
 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
@@ -491,26 +535,22 @@ insertModuleAccess (cstring fname, typeId t)
     addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
 }
 
-# ifndef NOLCL
 void
 context_exitLCLfile (void)
 {
   if (gc.kind != CX_LCLLIB)
     {
-      char *lclname =  
-       removeExtension (cstring_toCharsSafe 
-                        (fileName (currentFile ())), ".lcl"); 
-      
-      addModuleAccess (cstring_fromCharsO (removePath (lclname)), gc.facct);
+      cstring lclname =  
+       fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION);
       
-      mstring_free (lclname);
+      addModuleAccess (fileLib_removePath (lclname), gc.facct);
+      cstring_free (lclname);
     }
   
   gc.kind = CX_LCL;
   gc.kind = CX_GLOBAL;
   gc.facct = typeIdSet_emptySet ();
 }
-# endif
 
 void
 context_dumpModuleAccess (FILE *fout)
@@ -552,22 +592,22 @@ void context_setLibrary (flagcode code)
   gc.library = code;
 }
 
-/*@observer@*/ char *context_selectedLibrary ()
+/*@observer@*/ cstring context_selectedLibrary ()
 {
   switch (gc.library)
     {
     case FLG_STRICTLIB:
-      return LLSTRICTLIBS_NAME;
+      return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
     case FLG_POSIXLIB:
-      return LLPOSIXLIBS_NAME;
+      return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
     case FLG_POSIXSTRICTLIB:
-      return LLPOSIXSTRICTLIBS_NAME;
+      return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
     case FLG_UNIXLIB:
-      return LLUNIXLIBS_NAME;    
+      return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);    
     case FLG_UNIXSTRICTLIB:
-      return LLUNIXSTRICTLIBS_NAME;
+      return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
     case FLG_ANSILIB:
-      return LLSTDLIBS_NAME;
+      return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
     BADDEFAULT;
     }
 }
@@ -584,7 +624,7 @@ context_loadModuleAccess (FILE *in)
   char *os = s;
 # endif
 
-  while (fgets (s, MAX_DUMP_LINE_LENGTH, in) != NULL 
+  while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
         && *s == ';')
     {
       ;
@@ -613,7 +653,7 @@ context_loadModuleAccess (FILE *in)
       addModuleAccess (cstring_copy (cstring_fromChars (oname)), 
                       typeIdSet_undump (&s)); 
 
-      (void) fgets (s, MAX_DUMP_LINE_LENGTH, in);
+      (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
       llassert (s != lasts);
       lasts = s;
     }
@@ -631,17 +671,15 @@ typeIdSet context_fileAccessTypes (void)
 
 void
 context_resetModeFlags (void)
-{
-  
+{  
   allFlagCodes (code)
     {
       if (flagcode_isModeFlag (code))
        {
-         context_setFlag (code, FALSE);
+         context_setFlag (code, FALSE, g_currentloc);
        }
-    } end_allFlagCodes;
-
-  }
+    } end_allFlagCodes;  
+}
 
 /*
 ** resetAllFlags
@@ -665,13 +703,15 @@ conext_resetAllCounters (void)
 }
 
 void
-context_resetAllFlags (void)
+context_resetAllFlags (void) 
 {
+  DPRINTF (("******** Reset all flags"));
+
   allFlagCodes (code)
     {
       gc.flags[code] = FALSE;
 
-      if (flagcode_hasValue (code))
+      if (flagcode_hasNumber (code))
        {
          int val = 0;
          
@@ -680,24 +720,30 @@ context_resetAllFlags (void)
            {
            case FLG_LIMIT: 
              val = DEFAULT_LIMIT; break;
+           case FLG_BUGSLIMIT:
+             val = DEFAULT_BUGSLIMIT; break;
            case FLG_LINELEN: 
              val = DEFAULT_LINELEN; break;
+           case FLG_INDENTSPACES: 
+             val = DEFAULT_INDENTSPACES; break;
+           case FLG_LOCINDENTSPACES: 
+             val = DEFAULT_LOCINDENTSPACES; break;
            case FLG_EXTERNALNAMELEN:
-             val = DEFAULT_EXTERNALNAMELEN; break;
+             val = ISO99_EXTERNALNAMELEN; break;
            case FLG_INTERNALNAMELEN:
-             val = DEFAULT_INTERNALNAMELEN; break;
+             val = ISO99_INTERNALNAMELEN; break;
            case FLG_COMMENTCHAR: 
              val = (int) DEFAULT_COMMENTCHAR; break;
            case FLG_CONTROLNESTDEPTH:
-             val = (int) DEFAULT_CONTROLNESTDEPTH; break;
+             val = (int) ISO99_CONTROLNESTDEPTH; break;
            case FLG_STRINGLITERALLEN:
-             val = (int) DEFAULT_STRINGLITERALLEN; break;
+             val = (int) ISO99_STRINGLITERALLEN; break;
            case FLG_INCLUDENEST:
-             val = (int) DEFAULT_INCLUDENEST; break;
+             val = (int) ISO99_INCLUDENEST; break;
            case FLG_NUMSTRUCTFIELDS:
-             val = (int) DEFAULT_NUMSTRUCTFIELDS; break;
+             val = (int) ISO99_NUMSTRUCTFIELDS; break;
            case FLG_NUMENUMMEMBERS:
-             val = (int) DEFAULT_NUMENUMMEMBERS; break;
+             val = (int) ISO99_NUMENUMMEMBERS; break;
            case FLG_EXPECT:
            case FLG_LCLEXPECT:
              break;
@@ -706,7 +752,15 @@ context_resetAllFlags (void)
            }
          /*@=loopswitchbreak@*/          
 
+         DPRINTF (("Set value: [%s] / %d",  flagcode_unparse (code), val));
          context_setValue (code, val);
+         DPRINTF (("Set value: [%s] / %d",  flagcode_unparse (code), context_getValue (code)));
+         llassert (context_getValue (code) == val);
+       }
+      else if (flagcode_hasChar (code))
+       {
+         llassert (code == FLG_COMMENTCHAR);
+         context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
        }
       else if (flagcode_hasString (code))
        {
@@ -716,11 +770,11 @@ context_resetAllFlags (void)
            { /*@-loopswitchbreak@*/
            case FLG_LARCHPATH:
              {
-               char *larchpath = osd_getEnvironmentVariable (LARCH_PATH);
+               cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
                
-               if (larchpath != NULL)
+               if (cstring_isDefined (larchpath))
                  {
-                   val = cstring_fromCharsNew (larchpath);
+                   val = cstring_copy (larchpath);
                  }
                else
                  {
@@ -731,7 +785,7 @@ context_resetAllFlags (void)
              }
            case FLG_LCLIMPORTDIR:
              {
-               val = cstring_fromCharsNew (osd_getEnvironment (LCLIMPORTDIR, DEFAULT_LCLIMPORTDIR));
+               val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
                break;
              }
            case FLG_TMPDIR: 
@@ -754,9 +808,9 @@ context_resetAllFlags (void)
            case FLG_BOOLTYPE:
              val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
            case FLG_BOOLFALSE:
-             val = cstring_makeLiteral ("FALSE"); break;
+             val = cstring_makeLiteral ("false"); break;
            case FLG_BOOLTRUE:
-             val = cstring_makeLiteral ("TRUE"); break;
+             val = cstring_makeLiteral ("true"); break;
            case FLG_MACROVARPREFIX: 
              val = cstring_makeLiteral ("m_"); break;
            case FLG_SYSTEMDIRS:
@@ -764,7 +818,7 @@ context_resetAllFlags (void)
            default:
              break;
            } /*@=loopswitchbreak@*/
-         
+
          context_setString (code, val);
        }
       else
@@ -777,18 +831,29 @@ context_resetAllFlags (void)
   ** These flags are true by default.
   */
 
+  /* eventually, move this into flags.def */
+    
+  gc.flags[FLG_STREAMOVERWRITE] = TRUE;
+  gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
   gc.flags[FLG_MODIFIES] = TRUE;
   gc.flags[FLG_NESTCOMMENT] = TRUE;
   gc.flags[FLG_GLOBALS] = TRUE;
   gc.flags[FLG_FULLINITBLOCK] = TRUE;
+  gc.flags[FLG_INITSIZE] = TRUE;
+  gc.flags[FLG_INITALLELEMENTS] = TRUE;
+  gc.flags[FLG_NULLINIT] = TRUE;
+
+  gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
+
   gc.flags[FLG_LIKELYBOOL] = TRUE;
   gc.flags[FLG_ZEROPTR] = TRUE;
   gc.flags[FLG_NUMLITERAL] = TRUE;
   gc.flags[FLG_DUPLICATEQUALS] = TRUE;
-  gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
+  gc.flags[FLG_SKIPISOHEADERS] = TRUE;
   gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
   gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
   gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
+  gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
   gc.flags[FLG_CASTFCNPTR] = TRUE;
   gc.flags[FLG_DOLCS] = TRUE;
   gc.flags[FLG_USEVARARGS] = TRUE;
@@ -800,6 +865,8 @@ context_resetAllFlags (void)
   gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
   gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
 
+  gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
+  gc.flags[FLG_WARNUSE] = TRUE;
   gc.flags[FLG_PREDASSIGN] = TRUE;
   gc.flags[FLG_MODOBSERVER] = TRUE;
   gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
@@ -815,9 +882,12 @@ context_resetAllFlags (void)
   gc.flags[FLG_FORMATTYPE] = TRUE;
   gc.flags[FLG_BADFLAG] = TRUE;
   gc.flags[FLG_WARNFLAGS] = TRUE;
-  gc.flags[FLG_WARNUNIXLIB] = TRUE;
+  gc.flags[FLG_WARNRC] = TRUE;
+  gc.flags[FLG_FILEEXTENSIONS] = TRUE;
+  gc.flags[FLG_WARNUNIXLIB] = FALSE;
   gc.flags[FLG_WARNPOSIX] = TRUE;
   gc.flags[FLG_SHOWCOL] = TRUE;
+  gc.flags[FLG_SHOWDEEPHISTORY] = FALSE; /* TRUE; */
   gc.flags[FLG_SHOWFUNC] = TRUE;
   gc.flags[FLG_SUPCOUNTS] = TRUE;
   gc.flags[FLG_HINTS] = TRUE;
@@ -825,8 +895,13 @@ context_resetAllFlags (void)
   gc.flags[FLG_TYPE] = TRUE;
   gc.flags[FLG_INCOMPLETETYPE] = TRUE;
   gc.flags[FLG_ABSTRACT] = TRUE;
-  gc.flags[FLG_ITER] = TRUE;
-  gc.flags[FLG_CONTROL] = TRUE;
+  gc.flags[FLG_NUMABSTRACT] = TRUE;
+  gc.flags[FLG_ITERBALANCE] = TRUE;
+  gc.flags[FLG_ITERYIELD] = TRUE;
+  gc.flags[FLG_DUPLICATECASES] = TRUE;
+  gc.flags[FLG_ALWAYSEXITS] = TRUE;
+  gc.flags[FLG_EMPTYRETURN] = TRUE;
+  gc.flags[FLG_MACRORETURN] = TRUE;
   gc.flags[FLG_UNRECOG] = TRUE;
   gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
   gc.flags[FLG_LINTCOMMENTS] = TRUE;
@@ -835,6 +910,9 @@ context_resetAllFlags (void)
   gc.flags[FLG_ACCESSFILE] = TRUE;
   gc.flags[FLG_MACROVARPREFIX] = TRUE;
 
+  gc.flags[FLG_ANNOTATIONERROR] = TRUE;
+  gc.flags[FLG_COMMENTERROR] = TRUE;
+
   /*
   ** Changed for version 2.4.
   */
@@ -842,11 +920,24 @@ context_resetAllFlags (void)
   gc.flags[FLG_GNUEXTENSIONS] = TRUE;
 
   /*
-  ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
+    Changed for 3.0.0.19
+   */
+
+  /* commenting ou until some output issues are fixed */
+  gc.flags[FLG_ORCONSTRAINT] = TRUE; 
+  
+  gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
+
+  /*drl 1/18/2002*/
+  gc.flags[FLG_WARNSYSFILES] = TRUE;
+
+  /*
+  ** On by default for Win32, but not Unix
   */
 
-# ifdef WIN32
+# if defined (WIN32) || defined (OS2)
   gc.flags[FLG_PARENFILEFORMAT] = TRUE;
+  gc.flags[FLG_CASEINSENSITIVEFILENAMES] = TRUE;
 # endif
 }
 
@@ -861,10 +952,24 @@ context_resetAllFlags (void)
       if (!flagcode_isModeFlag (modeflags[i])) \
        { llbug (message ("not a mode flag: %s", \
                          flagcode_unparse (modeflags[i]))); } \
-      else { context_setFlag (modeflags[i], TRUE); }  i++; }}
+      else { context_setFlag (modeflags[i], TRUE, g_currentloc); }  i++; }}
+
+static void context_setModeAux (cstring p_s, bool p_warn) ;
 
 void
 context_setMode (cstring s)
+{
+  context_setModeAux (s, TRUE);
+}
+
+void
+context_setModeNoWarn (cstring s)
+{
+  context_setModeAux (s, FALSE);
+}
+
+void
+context_setModeAux (cstring s, bool warn)
 {
   intSet setflags = intSet_new ();
   
@@ -905,11 +1010,14 @@ context_setMode (cstring s)
            }
        } end_intSet_elements ;
       
-      voptgenerror (FLG_WARNFLAGS,
-                   message ("Setting mode %s after setting mode flags will "
-                            "override set values of flags: %s",
-                            s, rflags),
-                   g_currentloc);
+      if (warn)
+       {
+         voptgenerror (FLG_WARNFLAGS,
+                       message ("Setting mode %s after setting mode flags will "
+                                "override set values of flags: %s",
+                                s, rflags),
+                       g_currentloc);
+       }
 
       cstring_free (rflags);
     }
@@ -923,20 +1031,25 @@ context_setMode (cstring s)
       flagcode modeflags[] = 
        {
          FLG_ENUMINT, FLG_MACROMATCHNAME,
+         FLG_STRINGLITNOROOM, 
+         FLG_STRINGLITNOROOMFINALNULL,
          FLG_MACROUNDEF, FLG_RELAXQUALS, 
          FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
          FLG_CHECKSTRICTGLOBALIAS,
          FLG_CHECKEDGLOBALIAS,
          FLG_CHECKMODGLOBALIAS,
          FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
+         FLG_UNSIGNEDCOMPARE,
          FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED, 
          FLG_TYPEUNUSED,
+         FLG_ABSTRACTCOMPARE,
          FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
-         FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_MUTREP, 
-         FLG_NOEFFECT, FLG_IMPTYPE,
+         FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
+         FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE, 
          FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
-         FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, 
+         FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
          FLG_MATCHFIELDS,
+         FLG_FORMATCONST,
          FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS, 
          FLG_MACROSTMT, FLG_MACROPARENS, 
          FLG_MACROFCNDECL,
@@ -947,10 +1060,12 @@ context_setMode (cstring s)
          FLG_NESTEDEXTERN, 
          FLG_NUMLITERAL,
          FLG_ZEROBOOL,
+
          /* memchecks flags */
          FLG_NULLDEREF, 
          FLG_NULLSTATE, FLG_NULLASSIGN,
          FLG_NULLPASS, FLG_NULLRET,        
+         FLG_ALLOCMISMATCH,
 
          FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
          FLG_RETSTACK,
@@ -971,23 +1086,29 @@ context_setMode (cstring s)
          FLG_UNKNOWNTRANS,
          FLG_KEEPTRANS,
          FLG_IMMEDIATETRANS,
-
+         FLG_NUMABSTRACTCAST,
          FLG_EXPORTLOCAL,
 
          FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
-         FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE, 
+         FLG_MUSTFREEONLY, 
+         FLG_MUSTFREEFRESH,
+         FLG_MUSTDEFINE, FLG_GLOBSTATE, 
          FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
          FLG_MEMIMPLICIT,
          FLG_BRANCHSTATE, 
-
+         FLG_STATETRANSFER, FLG_STATEMERGE,
          FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
          FLG_EXITARG,
          FLG_IMPCHECKEDSPECGLOBALS,
          FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
          FLG_IFEMPTY, FLG_REALCOMPARE,
          FLG_BOOLOPS, FLG_PTRNEGATE,
-         FLG_SHIFTSIGNED,
-         INVALID_FLAG } ;
+         FLG_SHIFTNEGATIVE,      
+         FLG_SHIFTIMPLEMENTATION,
+         FLG_BUFFEROVERFLOWHIGH,
+         FLG_BUFFEROVERFLOW,
+         INVALID_FLAG 
+       } ;
 
       SETFLAGS ();
     }
@@ -995,22 +1116,28 @@ context_setMode (cstring s)
     {
       flagcode modeflags[] = 
        { 
-         FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
+         FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE, FLG_LONGINT, FLG_SHORTINT,
          FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL, 
-         FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS, 
+         FLG_CHARINDEX, FLG_NUMABSTRACTINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS, 
          FLG_CHARUNSIGNEDCHAR,
          FLG_PREDBOOLOTHERS, 
+         FLG_NUMABSTRACTLIT,
           FLG_VARUNUSED, FLG_FUNCUNUSED, 
          FLG_TYPEUNUSED,
           FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
          FLG_RETVALOTHER,
          FLG_IFEMPTY, 
+         FLG_BUFFEROVERFLOWHIGH,
          FLG_RETSTACK, FLG_PTRNEGATE,
+         FLG_STATETRANSFER, FLG_STATEMERGE,
          FLG_LONGUNSIGNEDINTEGRAL,
          FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
          FLG_NUMLITERAL,
          FLG_CHARINTLITERAL,
          FLG_ZEROBOOL,
+         FLG_BUFFEROVERFLOWHIGH,
+         FLG_STRINGLITNOROOM,
+         FLG_STRINGLITNOROOMFINALNULL,
          INVALID_FLAG 
          } ;
 
@@ -1020,14 +1147,21 @@ context_setMode (cstring s)
     {
       flagcode modeflags[] = 
        { 
-         FLG_EXPORTLOCAL, FLG_IMPTYPE,
+         FLG_EXPORTLOCAL, FLG_IMPTYPE, 
+         FLG_NUMABSTRACTCAST,
+         FLG_ABSTRACTCOMPARE,
+         FLG_STATETRANSFER, FLG_STATEMERGE,
          FLG_CHECKSTRICTGLOBALIAS,
          FLG_CHECKEDGLOBALIAS,
          FLG_CHECKMODGLOBALIAS,
          FLG_UNCHECKEDGLOBALIAS,
+         FLG_FORMATCONST,
+         FLG_STRINGLITNOROOM,
+         FLG_STRINGLITNOROOMFINALNULL,
+         FLG_STRINGLITSMALLER,
           FLG_EXITARG, FLG_PTRNUMCOMPARE, 
-         FLG_BOOLCOMPARE, FLG_MACROUNDEF
-         FLG_MUSTMOD, FLG_ALLGLOBALS,
+         FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE
+         FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
          FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
          FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS, 
          FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
@@ -1038,6 +1172,8 @@ context_setMode (cstring s)
          FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
          FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
          FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, 
+         FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
+         FLG_NUMABSTRACTPRINT,
          FLG_MATCHFIELDS, 
          FLG_MACROPARAMS,
          FLG_MACROASSIGN,
@@ -1052,13 +1188,17 @@ context_setMode (cstring s)
          FLG_UNREACHABLE, 
          FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
          FLG_EVALORDER, FLG_USEDEF, 
-
          FLG_NESTEDEXTERN, 
 
+         /* warn use flags */
+         FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
+         FLG_BUFFEROVERFLOWHIGH,
+
          /* memchecks flags */
 
          FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
          FLG_NULLPASS, FLG_NULLRET,
+         FLG_ALLOCMISMATCH,
 
          FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,       
 
@@ -1082,7 +1222,9 @@ context_setMode (cstring s)
          FLG_IMMEDIATETRANS,
          FLG_ONLYUNQGLOBALTRANS,
          FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
-         FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE, 
+         FLG_MUSTFREEONLY,
+         FLG_MUSTFREEFRESH,
+         FLG_MUSTDEFINE, FLG_GLOBSTATE, 
          FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
          FLG_MEMIMPLICIT,
          FLG_BRANCHSTATE, 
@@ -1092,9 +1234,11 @@ context_setMode (cstring s)
          FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
          FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
           FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
-         FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES, 
+         FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES, 
          FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
-         FLG_BOOLOPS, FLG_SHIFTSIGNED,
+         FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
+         FLG_SHIFTIMPLEMENTATION,
+         FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
          INVALID_FLAG } ;
 
       SETFLAGS ();
@@ -1103,12 +1247,20 @@ context_setMode (cstring s)
     {
       flagcode modeflags[] = 
        { 
-         FLG_CHECKSTRICTGLOBALIAS,
+         FLG_ABSTRACTCOMPARE,
+         FLG_CHECKSTRICTGLOBALIAS, 
+         FLG_NUMABSTRACTCAST,
          FLG_CHECKEDGLOBALIAS,
          FLG_CHECKMODGLOBALIAS,
          FLG_UNCHECKEDGLOBALIAS,
          FLG_MODFILESYSTEM,
          FLG_MACROMATCHNAME,
+         FLG_FORMATCONST,
+         FLG_NUMABSTRACTPRINT,
+         FLG_STRINGLITNOROOM,
+         FLG_STRINGLITNOROOMFINALNULL,
+         FLG_STRINGLITSMALLER,
+         FLG_STATETRANSFER, FLG_STATEMERGE,
           FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
          FLG_ALLGLOBALS, FLG_IMPTYPE,
          FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
@@ -1132,11 +1284,12 @@ context_setMode (cstring s)
          FLG_VARUNUSED, 
          FLG_NULLPOINTERARITH, FLG_POINTERARITH, 
          FLG_PTRNUMCOMPARE, 
-         FLG_BOOLCOMPARE, FLG_NOEFFECT, 
-         FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER, 
-         FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
+         FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
+         FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER, 
+         FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
          FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF, 
          FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS, 
+         FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
          FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR, 
          FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS, 
          FLG_MACROASSIGN,
@@ -1154,12 +1307,22 @@ context_setMode (cstring s)
          FLG_NESTEDEXTERN, 
          FLG_FIRSTCASE,
 
+         /* warn use flags */
+         FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
+         FLG_BUFFEROVERFLOWHIGH,
+         FLG_BUFFEROVERFLOW, FLG_TOCTOU,
+
          /* memchecks flags */
          FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
          FLG_NULLPASS, FLG_NULLRET,
-
+         FLG_ALLOCMISMATCH,
          FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
 
+         /* memory checking flags */
+         FLG_BOUNDSREAD, FLG_BOUNDSWRITE,
+         FLG_LIKELYBOUNDSREAD, FLG_LIKELYBOUNDSWRITE,
+         FLG_CHECKPOST, 
+
          /* memtrans flags */
          FLG_EXPOSETRANS,
          FLG_OBSERVERTRANS,
@@ -1180,7 +1343,9 @@ context_setMode (cstring s)
          FLG_UNKNOWNINITTRANS,
 
          FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
-         FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE, 
+         FLG_MUSTFREEONLY,
+         FLG_MUSTFREEFRESH,
+         FLG_MUSTDEFINE, FLG_GLOBSTATE, 
          FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
          FLG_MEMIMPLICIT,
          FLG_BRANCHSTATE, 
@@ -1198,7 +1363,7 @@ context_setMode (cstring s)
          FLG_IMPCHECKEDSTRICTSPECGLOBALS,
          FLG_IMPCHECKMODINTERNALS,
          FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
-         FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
+         FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
          FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
          FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
          FLG_CONTROLNESTDEPTH,
@@ -1209,8 +1374,12 @@ context_setMode (cstring s)
          FLG_REALCOMPARE, FLG_BOOLOPS,
          FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
 
-         FLG_SHIFTSIGNED, FLG_BITWISEOPS,
-         INVALID_FLAG } ;
+         FLG_SHIFTNEGATIVE,
+         FLG_SHIFTIMPLEMENTATION,
+         FLG_BITWISEOPS,
+         FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
+         INVALID_FLAG
+       } ;
 
       SETFLAGS ();
     }
@@ -1223,54 +1392,54 @@ context_setMode (cstring s)
 bool
 context_isSpecialFile (cstring fname)
 {
-  char *ext = filenameExtension (cstring_toCharsSafe (fname));
+  cstring ext = fileLib_getExtension (fname);
   
-  return (mstring_equal (ext, ".y") 
-         || mstring_equal (ext, ".l")
+  return (cstring_equalLit (ext, ".y") 
+         || cstring_equalLit (ext, ".l")
          || cstring_equalLit (fname, "lex.yy.c"));
 }
 
 bool
 context_isSystemDir (cstring dir)
 {
-  cstring sysDirs = context_exposeString (FLG_SYSTEMDIRS);
-  char *thisdir = cstring_toCharsSafe (sysDirs);
-  char *nextdir = strchr (thisdir, SEPCHAR);
-
-  if (nextdir != NULL)
+  cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
+  cstring savedir = thisdir;
+  cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
+  
+  if (cstring_isDefined (nextdir))
     {
-      *nextdir = '\0';
+      /*@access cstring@*/
+      *nextdir = '\0'; /* closes thisdir */
       nextdir += 1;
+      /*@noaccess cstring@*/
     }
 
-  while (thisdir != NULL)
+  /* 2001-09-09: added thisdir[0] != '\0' 
+  **   herbert: don't compare with an empty name! 
+  **   should return false for empty directory path
+  */
+
+  while (!cstring_isEmpty (thisdir))
     {
       DPRINTF (("Test: %s / %s", dir, thisdir));
 
-      if (cstring_equalCanonicalPrefix (dir, thisdir))
+      if (osd_equalCanonicalPrefix (dir, thisdir))
        {
-         if (nextdir != NULL)
-           {
-             *(nextdir - 1) = SEPCHAR;
-           }
-         
+         cstring_free (savedir);
          return TRUE;
        }
 
-      if (nextdir != NULL)
-       {
-         *(nextdir - 1) = SEPCHAR;
-       }
-
-      if (nextdir != NULL)
+      if (cstring_isDefined (nextdir))
        {
          thisdir = nextdir;
-         nextdir = strchr (thisdir, SEPCHAR);
+         nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
          
-         if (nextdir != NULL)
+         if (cstring_isDefined (nextdir))
            {
+             /*@access cstring@*/
              *nextdir = '\0';
              nextdir += 1;
+             /*@noaccess cstring@*/
            } 
        }
       else
@@ -1280,6 +1449,7 @@ context_isSystemDir (cstring dir)
     } 
 
   DPRINTF (("Returns FALSE"));
+  cstring_free (savedir);
   return FALSE;
 }
 
@@ -1288,8 +1458,7 @@ context_addFileAccessType (typeId t)
 {
   cstring base;
 
-  if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN 
-      || gc.kind == CX_UNKNOWNMACRO)
+  if (context_inFunctionLike ())
     {
       gc.acct = typeIdSet_insert (gc.acct, t);
     }
@@ -1315,22 +1484,84 @@ context_removeFileAccessType (typeId t)
   gc.nacct = typeIdSet_insert (gc.nacct, t);
 }
 
-void context_enterFunctionDecl (void)
+void context_enterFunctionHeader (void)
+{
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Enter function header: %q", context_unparse ()));
+    }
+
+  if (gc.kind != CX_GLOBAL)
+    {
+      llparseerror (cstring_makeLiteral
+                   ("Likely parse error.  Function header outside global context."));
+    }
+  else
+    {
+      llassert (gc.kind == CX_GLOBAL);
+      DPRINTF (("Enter function header!"));
+      gc.inFunctionHeader = TRUE;
+    }
+}
+
+void context_exitFunctionHeader (void)
+{
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Exit function header: %q", context_unparse ()));
+    }
+
+  DPRINTF (("Exit function header!"));
+  gc.inFunctionHeader = FALSE;
+}
+
+bool context_inFunctionHeader (void)
 {
-  llassert (gc.kind == CX_GLOBAL);
-  gc.kind = CX_FCNDECL;
+  return (gc.inFunctionHeader);
 }
 
-void context_exitFunctionDecl (void)
+void context_enterFunctionDeclaration (uentry e)
 {
-  gc.kind = CX_GLOBAL;
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
+    }
+
+  DPRINTF (("Enter function decl"));
+  llassert (gc.savekind == CX_ERROR);
+  gc.savekind = gc.kind;
+  gc.savecont = gc.cont;
+  gc.kind = CX_FCNDECLARATION;
+  gc.cont.fcn = e;
+}
+
+void context_exitFunctionDeclaration (void)
+{
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
+    }
+
+  DPRINTF (("Exit function decl"));
+  llassert (gc.savekind != CX_ERROR);
+  llassert (gc.kind == CX_FCNDECLARATION);
+  gc.kind = gc.savekind;
+  gc.cont = gc.savecont;
+
+  gc.savekind = CX_ERROR;
+
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
+    }
 }
 
-bool context_inFunctionDecl (void)
+bool context_inFunctionDeclaration (void)
 {
-  return (gc.kind == CX_FCNDECL);
+  return (gc.kind == CX_FCNDECLARATION);
 }
 
+
 void
 context_enterMacro (/*@observer@*/ uentry e)
 {
@@ -1348,7 +1579,7 @@ context_enterUnknownMacro (/*@dependent@*/ uentry e)
 
 void context_enterAndClause (exprNode e)
 {
-  
+  DPRINTF (("enter and clause: %s", exprNode_unparse (e)));
   usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
   pushClause (ANDCLAUSE);
 }
@@ -1542,14 +1773,14 @@ void context_enterTrueClause (exprNode e)
 
 void context_enterSwitch (exprNode e)
 {
-  
+  DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
   usymtab_switchBranch (e);
   context_enterCondClauseAux (SWITCHCLAUSE);
 }
 
 void context_exitSwitch (exprNode e, bool allpaths)
 {
-    usymtab_exitSwitch (e, allpaths);
+  usymtab_exitSwitch (e, allpaths);
   
   while (clause_isCase (clauseStack_top (gc.clauses)))
     {
@@ -1639,6 +1870,8 @@ context_enterFunction (/*@exposed@*/ uentry e)
   gc.kind = CX_FUNCTION;
   gc.cont.fcn = e;
 
+  DPRINTF (("Enter function: %s", uentry_unparse (e)));
+
   if (uentry_hasAccessType (e))
     {
       gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)), 
@@ -1662,6 +1895,66 @@ context_enterFunction (/*@exposed@*/ uentry e)
   sRef_enterFunctionScope ();
 }
 
+bool context_inOldStyleScope(void)
+{
+  return (gc.kind == CX_OLDSTYLESCOPE);
+}
+
+void
+context_enterOldStyleScope (void)
+{
+  gc.kind = CX_OLDSTYLESCOPE;
+  DPRINTF (("Enter old style scope!"));
+  usymtab_enterFunctionScope (uentry_undefined);
+}
+
+void 
+context_completeOldStyleFunction (uentry e)
+{
+  llassert (gc.kind == CX_OLDSTYLESCOPE);
+
+  gc.kind = CX_FUNCTION;
+  gc.cont.fcn = e;
+  
+  DPRINTF (("Enter function: %s", uentry_unparse (e)));
+  
+  if (uentry_hasAccessType (e))
+    {
+      gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)), 
+                                   gc.nacct);
+    }
+  else
+    {
+      gc.acct = gc.facct;
+    }
+  
+  DPRINTF (("Enter function: %s / %s", uentry_unparse (e), 
+           typeIdSet_unparse (gc.acct)));
+  
+  gc.showfunction = context_getFlag (FLG_SHOWFUNC);
+  
+  if (!globSet_isEmpty (uentry_getGlobs (e))) 
+    {
+      llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
+                            fileloc_unparse (g_currentloc), uentry_unparse (e)));
+    }
+
+  gc.showfunction = context_getFlag (FLG_SHOWFUNC);
+  
+  gc.globs = uentry_getGlobs (e);
+  globSet_clear (gc.globs_used);
+
+  gc.mods = uentry_getMods (e);
+
+  if (!sRefSet_isEmpty (gc.mods))
+    {
+      llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
+                            fileloc_unparse (g_currentloc), uentry_unparse (e)));
+    }
+
+  sRef_enterFunctionScope ();
+}
+
 static bool context_checkStrictGlobals (void)
 {
   return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
@@ -1800,7 +2093,7 @@ context_checkGlobMod (sRef el)
 {
   uentry ue = sRef_getUentry (el);
 
-  /* no: llassert (sRef_isGlobal (el)); also check local statics */
+  /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
 
   if (uentry_isCheckedModify (ue)
       || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
@@ -1835,7 +2128,7 @@ context_checkGlobMod (sRef el)
 }
 
 void
-context_usedGlobal (sRef el)
+context_usedGlobal (/*@exposed@*/ sRef el)
 {
   if (!globSet_member (gc.globs_used, el))
     {
@@ -1859,7 +2152,7 @@ context_modList (void)
 bool
 context_globAccess (sRef s)
 {
-  llassert (sRef_isGlobal (s) || sRef_isKindSpecial (s));
+  llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
   return (globSet_member (gc.globs, s));
 }
 
@@ -1868,6 +2161,8 @@ context_hasAccess (typeId t)
 {
   if (context_inFunctionLike ())
     {
+      DPRINTF (("Access %d / %s",
+               t, typeIdSet_unparse (gc.acct)));
       return (typeIdSet_member (gc.acct, t));
     }
   else
@@ -1936,7 +2231,7 @@ context_getRetType (void)
 
       return ctype_unknown;
     }
-  return (ctype_returnValue (f));
+  return (ctype_getReturnType (f));
 }    
 
 bool
@@ -1954,12 +2249,10 @@ context_hasMods (void)
 
 void
 context_exitAllClauses (void)
-{
-  
+{  
   while (!clauseStack_isEmpty (gc.clauses))
     {
       clause el = clauseStack_top (gc.clauses);
-
       gc.inclause = el;
 
       if (clause_isNone (el))
@@ -1973,9 +2266,23 @@ context_exitAllClauses (void)
        }
     }
 
-  clauseStack_clear (gc.clauses);
+  clauseStack_clear (gc.clauses);  
+  gc.inclause = NOCLAUSE;
+}
+
+void
+context_exitAllClausesQuiet (void)
+{  
+  while (!clauseStack_isEmpty (gc.clauses))
+    {
+      clause el = clauseStack_top (gc.clauses);
+      gc.inclause = el;
 
-  
+      usymtab_quietExitScope (g_currentloc);
+      clauseStack_pop (gc.clauses);
+    }
+
+  clauseStack_clear (gc.clauses);  
   gc.inclause = NOCLAUSE;
 }
 
@@ -2001,28 +2308,27 @@ static
 void context_exitClauseAux (exprNode pred, exprNode tbranch)
 {
   context_setJustPopped ();
-  usymtab_popTrueBranch (pred, tbranch, gc.inclause);
+  usymtab_popTrueBranch (pred, tbranch, gc.inclause); /* evans 2003-02-02?: was makeAlt */
   clauseStack_pop (gc.clauses);
   gc.inclause = topClause (gc.clauses);
 }
 
 void context_exitTrueClause (exprNode pred, exprNode tbranch)
 {
+  DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
+
   if (gc.inclause != TRUECLAUSE)
     {
       llparseerror (cstring_makeLiteral
                    ("Likely parse error.  Conditional clauses are inconsistent."));
       return;
     }
-
-    
-  context_setJustPopped ();
-
+  
+  context_setJustPopped ();  
   usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
   clauseStack_pop (gc.clauses);
-  gc.inclause = topClause (gc.clauses);
-  
-  }
+  gc.inclause = topClause (gc.clauses);  
+}
 
 void context_exitIterClause (exprNode body)
 {
@@ -2030,7 +2336,7 @@ void context_exitIterClause (exprNode body)
 
   context_setJustPopped ();
 
-  if (context_getFlag (FLG_LOOPEXEC))
+  if (context_getFlag (FLG_ITERLOOPEXEC))
     {
       usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
     }
@@ -2061,7 +2367,7 @@ static void context_popCase (void) {
 
   DPRINTF (("Popping case clause: %s",
            clauseStack_unparse (gc.clauses)));
-
+  
   if (gc.inclause == CASECLAUSE) {
     context_exitCaseClause ();
   }
@@ -2087,7 +2393,7 @@ void context_exitWhileClause (exprNode pred, exprNode body)
   ** predicate must be false after while loop (unless there are breaks)
   */
 
-  if (context_getFlag (FLG_LOOPEXEC))
+  if (context_getFlag (FLG_WHILELOOPEXEC))
     {
       usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
     }
@@ -2133,17 +2439,30 @@ void context_exitForClause (exprNode forPred, exprNode body)
   llassert (gc.inclause == FORCLAUSE);
   context_setJustPopped ();
 
+  DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
+
   /*
-  ** predicate must be false after while loop (unless there are breaks)
+  ** Predicate must be false after for loop (unless there are breaks)
   */
 
-  if (context_getFlag (FLG_LOOPEXEC))
+  if (context_getFlag (FLG_FORLOOPEXEC))
     {
-            usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
+      DPRINTF (("Here: for loop exec"));
+      usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
     }
   else
     {
-      usymtab_popTrueBranch (forPred, body, FORCLAUSE);
+      if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
+         && exprNode_loopMustExec (forPred))
+       {
+         DPRINTF (("Here: loop must exec"));
+         usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
+       }
+      else
+       {
+         DPRINTF (("Pop true branch:"));
+         usymtab_popTrueBranch (forPred, body, FORCLAUSE);
+       }
     }
 
   usymtab_addGuards (invGuards);
@@ -2164,18 +2483,16 @@ static void context_exitClausePlain (void)
     {
       context_exitClauseAux (exprNode_undefined, exprNode_undefined);
     }
-  
 }
 
 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
 {
-    
   context_setJustPopped ();
-
+  
   if (gc.inclause == FALSECLAUSE)
     {
       usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
-
+      
       llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
 
       clauseStack_pop (gc.clauses);
@@ -2183,26 +2500,30 @@ void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
     }
   else
     {
-            context_exitTrueClause (pred, tbranch);
+      context_exitTrueClause (pred, tbranch);
     }
 }
 
 void
 context_returnFunction (void)
 {
-    usymtab_checkFinalScope (TRUE);
-  }
+  usymtab_checkFinalScope (TRUE);
+}
 
 void
 context_exitFunction (void)
 {    
+  DPRINTF (("Exit function: %s", context_unparse ()));
+
   if (!context_inFunction () && !context_inMacroConstant () 
-      && !context_inMacroUnknown () 
+      && !context_inUnknownMacro () 
       && !context_inIterDef () && !context_inIterEnd ())
     {
       /*
       ** not a bug because of parse errors
       */
+
+      BADBRANCH;
     }
   else
     {
@@ -2225,6 +2546,8 @@ context_exitFunction (void)
            }
        }
 
+      DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
+
       /*
       ** clear file static modifies
       */
@@ -2245,6 +2568,7 @@ context_exitFunction (void)
 
   llassert (clauseStack_isEmpty (gc.clauses));
   llassert (gc.inclause == NOCLAUSE);
+  DPRINTF (("After exit function: %s", context_unparse ()));
 }
 
 void
@@ -2255,7 +2579,7 @@ context_quietExitFunction (void)
       context_exitInnerPlain ();
     }
 
-  if (!context_inFunction () && !context_inMacroConstant () && !context_inMacroUnknown () 
+  if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro () 
       && !context_inIterDef () && !context_inIterEnd ())
     {
     }
@@ -2280,7 +2604,7 @@ context_getParams (void)
 {
   if (context_inFunctionLike ())
     {
-            return (uentry_getParams (gc.cont.fcn));
+      return (uentry_getParams (gc.cont.fcn));
     }
   else
     {
@@ -2447,13 +2771,14 @@ context_getAliasAnnote (void)
 void
 context_recordFileModifies (sRefSet mods)
 {
-    gc.modrecs = sRefSetList_add (gc.modrecs, mods);
+  gc.modrecs = sRefSetList_add (gc.modrecs, mods);
 }
 
 void
 context_recordFileGlobals (globSet mods)
 {
-    /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
+  DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
+  /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
 }
 
 void
@@ -2477,42 +2802,47 @@ context_setValue (flagcode flag, int val)
 
   llassert (index >= 0 && index <= NUMVALUEFLAGS);
 
-  if (val <= 0)
+  switch (flag)
     {
-      switch (flag)
+    case FLG_LINELEN:
+      if (val <= 0)
        {
-       case FLG_INCLUDENEST:
-       case FLG_CONTROLNESTDEPTH:
-       case FLG_STRINGLITERALLEN:
-       case FLG_NUMSTRUCTFIELDS:
-       case FLG_NUMENUMMEMBERS:
-       case FLG_LINELEN:
-         {
-           cstring warn = message ("Value for %s must be a positive "
-                                   "number (given %d)",
-                                   flagcode_unparse (flag), val);
-           
-           flagWarning (warn);
-           cstring_free (warn);
-           val = MINLINELEN;
-         }
+         
+         llerror_flagWarning (message ("Value for %s must be a positive "
+                                       "number (given %d)",
+                                       flagcode_unparse (flag), val));
          return;
-       default:
-         break;
        }
-    }
+      if (flag == FLG_LINELEN && val < MINLINELEN)
+       {
+         llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
+                                       flagcode_unparse (flag), 
+                                       MINLINELEN, val));
+         val = MINLINELEN;
+       }
+      break;
 
-  if (flag == FLG_LINELEN && val < MINLINELEN)
-    {
-      cstring warn = message ("Value for %s must be at least %d (given %d)",
-                             flagcode_unparse (flag), 
-                             MINLINELEN, val);
-      flagWarning (warn);
-      cstring_free (warn);
-      val = MINLINELEN;
+    case FLG_INCLUDENEST:
+    case FLG_CONTROLNESTDEPTH:
+    case FLG_STRINGLITERALLEN:
+    case FLG_NUMSTRUCTFIELDS:
+    case FLG_NUMENUMMEMBERS:      
+    case FLG_INDENTSPACES:
+      if (val < 0)
+       {
+         llerror_flagWarning (message ("Value for %s must be a non-negative "
+                                       "number (given %d)",
+                                       flagcode_unparse (flag), val));
+         return;
+       }
+
+      break;
+    default:
+      break;
     }
 
-    gc.values[index] = val;
+  DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
+  gc.values[index] = val;
 }
 
 void
@@ -2528,6 +2858,7 @@ context_getValue (flagcode flag)
   int index = flagcode_valueIndex (flag);
 
   llassert (index >= 0 && index <= NUMVALUEFLAGS);
+  DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
   return (gc.values[index]);
 }
 
@@ -2571,81 +2902,135 @@ context_setString (flagcode flag, cstring val)
 
   llassert (index >= 0 && index <= NUMSTRINGFLAGS);
 
-  if (flag == FLG_SYSTEMDIRS)
+  DPRINTF (("set string: %s", flagcode_unparse (flag)));
+
+  switch (flag)
     {
-      llassert (cstring_isDefined (val));
+    case FLG_MESSAGESTREAM:
+    case FLG_WARNINGSTREAM:
+    case FLG_ERRORSTREAM:
+      {
+       if (cstring_isDefined (val))
+         {
+           FILE *fstream;
 
-      if (cstring_firstChar (val) == '\"')
-       {
-         cstring oval = val;
-         cstring tval = cstring_copy (cstring_suffix (val, 1));
-       
-         if (cstring_lastChar (tval) != '\"')
-           {
-             int n = cstring_length (tval) - 1;
+           if (osd_fileExists (val))
+             {
+               if (context_getFlag (FLG_STREAMOVERWRITE))
+                 {
+                   llfatalerror (message 
+                                 ("Output stream file %s would overwrite existing file. "
+                                  "Use -streamoverwrite if you want to allow this.", 
+                                  val));
+                 }
+             }
+           
+           fstream = fopen (cstring_toCharsSafe (val), "w");
 
-             while (isspace ((int) cstring_getChar (tval, n)))
-               {
-                 n--;
-               }
+           if (fstream == NULL)
+             {
+               llfatalerror (message ("Unable to open output stream file %s for writing", 
+                                      val));
+             }
 
-             if (cstring_getChar (tval, n) != '\"')
-               {
-                 cstring msg = message ("Setting -systemdirs to string with unmatching quotes: %s", val);
-                 flagWarning (msg);
-                 cstring_free (msg);
-               }
-             else
-               {
-                 cstring otval = tval;
-                 tval = cstring_prefix (tval, n);
-                 cstring_free (otval);
-               }
-           }
-         
-         val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
-         DPRINTF (("val = %s", val));
-         cstring_free (tval);
-         cstring_free (oval);
-       }
-    }
+           /*
+           ** This ensures fstream will be closed on exit.
+           */
 
-  if (flag == FLG_TMPDIR)
-    {
-      llassert (cstring_isDefined (val));
-      
-      if (cstring_length (val) == 0)
-       {
-         cstring_free (val);
-         val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
-       }
-      else if (cstring_lastChar (val) != CONNECTCHAR)
-       {
-         val = cstring_appendChar (val, CONNECTCHAR);
-       }
-      else
-       {
-         ;
-       }
-    }
+           fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
+           
+           switch (flag)
+             {
+             case FLG_MESSAGESTREAM:
+               g_messagestream = fstream; 
+               /*@innerbreak@*/ break;
+             case FLG_WARNINGSTREAM:
+               g_warningstream = fstream;
+               /*@innerbreak@*/ break;
+             case FLG_ERRORSTREAM:
+               g_errorstream = fstream; 
+               /*@innerbreak@*/ break;
+               BADDEFAULT;
+             }
+           /*@-statetransfer@*/
+         } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
+       break;
+      }
+    case FLG_SYSTEMDIRS:
+      {
+       llassert (cstring_isDefined (val));
+       
+       if (cstring_firstChar (val) == '\"')
+         {
+           cstring oval = val;
+           cstring tval = cstring_copy (cstring_suffix (val, 1));
+           
+           if (cstring_lastChar (tval) != '\"')
+             {
+               int n = size_toInt (cstring_length (tval) - 1);
+               
+               while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
+                 {
+                   n--;
+                 }
+               
+               if (cstring_getChar (tval, size_fromInt (n)) != '\"')
+                 {
+                   llerror_flagWarning 
+                     (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
+                 }
+               else
+                 {
+                   cstring otval = tval;
+                   tval = cstring_prefix (tval, size_fromInt (n));
+                   cstring_free (otval);
+                 }
+             }
+           
+           val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
+           DPRINTF (("val = %s", val));
+           cstring_free (tval);
+           cstring_free (oval);
+         }
+       
+       break;
+      }
+    case FLG_TMPDIR:
+      {
+       llassert (cstring_isDefined (val));
+       
+       if (cstring_length (val) == 0)
+         {
+           cstring_free (val);
+           val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
+         }
+       else if (cstring_lastChar (val) != CONNECTCHAR)
+         {
+           val = cstring_appendChar (val, CONNECTCHAR);
+         }
+       else
+         {
+           ;
+         }
+       break;
+      }
+    default:
+      {
+       ; /* Okay not handle everything in this switch */
+      }
+      /*@-branchstate@*/
+    } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */
+  /*@=branchstate@*/ 
 
   if (cstring_length (val) >= 1
-      && cstring_firstChar (val) == '"')
+      && cstring_firstChar (val) == '\"')
     {
-      cstring s = message
-                  ("setting %s to string beginning with \".  You probably "
-                   "don't meant to have the \"'s.",
-                   flagcode_unparse (flag));
-
-      flagWarning (s);
-      cstring_free (s);
+      llerror_flagWarning (message
+                          ("Setting %s to string beginning with \".  You probably "
+                           "don't meant to have the \"'s.",
+                           flagcode_unparse (flag)));
     }
-
-  if (flag == FLG_BOOLTYPE)
-    {
-
-    }
-
+  
   gc.strings[index] = val;
 }
 
@@ -2670,12 +3055,29 @@ context_resetErrors (void)
   gc.numerrors = 0;
 }
 
+void
+context_recordBug (void)
+{
+  gc.numbugs++;
+}
+
+int
+context_numBugs (void)
+{
+  return gc.numbugs;
+}
+
 void context_initMod (void)
    /*@globals undef gc; @*/
 {
   gc.kind = CX_GLOBAL;
+
+  gc.savekind = CX_ERROR;
+  gc.savecont.glob = FALSE;
+
   gc.instandardlib = FALSE;
   gc.numerrors = 0;
+  gc.numbugs = 0;
   gc.neednl = FALSE;
   gc.linesprocessed = 0;
   gc.speclinesprocessed = 0;
@@ -2686,9 +3088,8 @@ void context_initMod (void)
   gc.mc = macrocache_create ();
   gc.nmods = 0;
   gc.maxmods = DEFAULTMAXMODS;
-  gc.moduleaccess = (maccesst *) 
-    dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
-
+  gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
+  
   gc.library = FLG_ANSILIB;
 
   gc.locstack = filelocStack_new ();
@@ -2729,13 +3130,32 @@ void context_initMod (void)
     {
       gc.setGlobally[code] = FALSE;
       gc.setLocally[code] = FALSE;
-    } end_allFlagCodes ;
-
+    } 
+  end_allFlagCodes ;
+  
   usymtab_initMod ();
-
   context_resetAllFlags ();
+
+  assertSet (gc.flags); /* Can't use global in defines */
+  assertSet (gc.saveflags);
+  assertSet (gc.values);
+  assertSet (gc.strings);
+  
   conext_resetAllCounters ();
+  assertSet (gc.counters);
+
   context_setMode (DEFAULT_MODE);
+
+  gc.stateTable = metaStateTable_create ();
+  gc.annotTable = annotationTable_create ();
+
+  gc.inFunctionHeader = FALSE;
+
+  DPRINTF (("Annotations: \n%s",
+           cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
+  DPRINTF (("State: \n%s",
+           cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
+
 }
 
 ctype
@@ -2787,7 +3207,9 @@ context_unparse (void)
       s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
       break;
     case CX_INNER:
-      s = message ("Inner Context:%q", fileloc_unparse (g_currentloc));
+      s = message ("Inner Context [%d] : %q", 
+                  gc.cont.cdepth,
+                  fileloc_unparse (g_currentloc));
       break;
     case CX_FUNCTION:
       s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
@@ -2811,6 +3233,9 @@ context_unparse (void)
     case CX_ITEREND:
       s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
       break;
+    case CX_FCNDECLARATION:
+      s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
+      break;
     default:
       s = message ("Un-unparseable context: %d", (int) gc.kind);
       break;
@@ -2843,6 +3268,11 @@ context_currentFunctionType (void)
 void
 context_enterInnerContext (void)
 {
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
+    }
+
   if (gc.kind == CX_GLOBAL)
     {
       gc.kind = CX_INNER;
@@ -2857,7 +3287,6 @@ context_enterInnerContext (void)
       ;
     }
 
-  
   usymtab_enterScope ();
   pushClause (NOCLAUSE);
 }
@@ -2871,7 +3300,11 @@ context_exitInnerPlain (void) /*@modifies gc;@*/
 void
 context_exitInner (exprNode exp)
 {
-  
+   if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
+    }
   llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
                 ("inclause = %s", clause_nameTaken (gc.inclause)));
 
@@ -2902,6 +3335,11 @@ context_exitInner (exprNode exp)
 void
 context_enterStructInnerContext (void)
 {
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
+    }
+
   if (gc.kind == CX_GLOBAL)
     {
       gc.kind = CX_INNER;
@@ -2917,18 +3355,39 @@ context_enterStructInnerContext (void)
     }
 
   usymtab_enterScope ();
+
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
+    }
 }
 
 void
 context_exitStructInnerContext (void)
 {
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
+    }
+
   if (gc.kind == CX_INNER)
     {
-      if (--gc.cont.cdepth == 0)
+      if (gc.cont.cdepth <= 0)
        {
+         llcontbuglit ("Attempt to exit inner context with no depth");
          gc.kind = CX_GLOBAL;
          gc.cont.glob = TRUE;
+         gc.cont.cdepth = 0;
        }
+      else {
+       gc.cont.cdepth--;
+
+       if (gc.cont.cdepth == 0)
+         {
+           gc.kind = CX_GLOBAL;
+           gc.cont.glob = TRUE;
+         }
+      }
     }
   else 
     {
@@ -2940,17 +3399,26 @@ context_exitStructInnerContext (void)
     }
 
   usymtab_exitScope (exprNode_undefined);
+
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
+    }
 }
 
 void
 context_exitInnerSafe (void)
 {
-  
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
+    }
+
   if (gc.kind == CX_INNER)
     {
-      if (--gc.cont.cdepth == 0)
+      if (--gc.cont.cdepth <= 0)
        {
-         gc.cont.cdepth++;
+         gc.cont.cdepth = 0;
        }
     }
   else if (gc.kind == CX_GLOBAL)
@@ -3053,6 +3521,7 @@ bool
 context_inFunctionLike (void)
 {
   return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN 
+         || gc.kind == CX_FCNDECLARATION
          || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
 }
 
@@ -3091,10 +3560,7 @@ context_processMacros (void)
   if (fileId_isValid (currentFile ()))
     {
       fileloc lastfl;
-      cstring cbase = cstring_fromChars 
-       (removePathFree
-        (removeAnyExtension 
-         (cstring_toCharsSafe (fileName (currentFile ())))));
+      cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
       
       gc.inmacrocache = TRUE;
 
@@ -3121,7 +3587,7 @@ context_processingMacros (void)
 }
 
 void
-context_exitFile (void)
+context_exitCFile (void)
 {
   if (gc.kind != CX_GLOBAL)
     {
@@ -3152,20 +3618,20 @@ context_exitFile (void)
   sRefSetList_elements (gc.modrecs, mods)
     {
       sRefSet_clearStatics (mods);
-          } end_sRefSetList_elements ;
+    } end_sRefSetList_elements ;
   
   sRefSetList_clear (gc.modrecs);
-
+  
   context_processMacros ();
   cleanupMessages (); 
-
+  
   usymtab_exitFile ();
-
+  
   gc.inDerivedFile = FALSE;
   filelocStack_clear (gc.locstack);
-
+  
   gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
-
+  
   gc.cont.glob = TRUE;
   
   if (gc.savedFlags)
@@ -3173,6 +3639,11 @@ context_exitFile (void)
       context_restoreFlagSettings ();
       gc.savedFlags = FALSE;
     }
+  
+  /*
+    DPRINTF (("After exiting file: "));
+    usymtab_printAll ();
+  */
 }
 
 void
@@ -3180,8 +3651,11 @@ context_exitMacroCache (void)
 {
   if (gc.kind != CX_GLOBAL)
     {
-      if (context_inMacro ()) /* this is okay, file could end without newline in macro */
+      if (context_inMacro ()) 
+       /* this is okay, file could end without newline in macro */
        {
+         DPRINTF (("Still in macro: %s",
+                   context_unparse ()));
          context_exitFunction ();
        }
       else
@@ -3208,18 +3682,15 @@ void
 context_saveLocation (void)
 {
   /* was llassert (fileloc_isUndefined (gc.saveloc)) */
-      fileloc_free (gc.saveloc);
-    
-
+  fileloc_free (gc.saveloc);
   gc.saveloc = fileloc_copy (g_currentloc);
-  }
+}
 
 fileloc
 context_getSaveLocation (void)
 {
   fileloc fl = gc.saveloc;
-
-    gc.saveloc = fileloc_undefined;
+  gc.saveloc = fileloc_undefined;
   return fl;
 }
 
@@ -3243,16 +3714,19 @@ context_inFunctionName (void)
 void
 context_userSetFlag (flagcode f, bool b)
 {
-  DPRINTF (("set flag: %s", flagcode_name (f)));
+  DPRINTF (("set flag: %s / %s", 
+           flagcode_unparse (f),
+           bool_unparse (context_getFlag (f))));
 
   if (f == FLG_NEVERINCLUDE && b)
     {
       if (gc.flags[FLG_EXPORTHEADER])
        {
-         flagWarning (cstring_makeLiteralTemp
-                      ("setting +neverinclude after +exportheader.  "
-                       "Turning off exportheader, since headers are not checked "
-                       "when +neverinclude is used."));
+         llerror_flagWarning 
+           (cstring_makeLiteral
+            ("Setting +neverinclude after +exportheader.  "
+             "Turning off exportheader, since headers are not checked "
+             "when +neverinclude is used."));
 
          gc.flags[FLG_EXPORTHEADER] = FALSE;
        }
@@ -3263,10 +3737,11 @@ context_userSetFlag (flagcode f, bool b)
        {
          if (gc.flags[FLG_NEVERINCLUDE])
            {
-             flagWarning (cstring_makeLiteralTemp
-                          ("setting +exportheader after +neverinclude.  "
-                           "Not setting exportheader, since headers are not checked "
-                           "when +neverinclude is used."));
+             llerror_flagWarning
+               (cstring_makeLiteral
+                ("Setting +exportheader after +neverinclude.  "
+                 "Not setting exportheader, since headers are not checked "
+                 "when +neverinclude is used."));
              gc.flags[FLG_EXPORTHEADER] = FALSE;
              return;
            }
@@ -3282,48 +3757,67 @@ context_userSetFlag (flagcode f, bool b)
          && !flagcode_isIdemFlag (f)
          && !flagcode_hasArgument (f))
        {
-         cstring warn = message ("setting %s%s redundant with current value", 
-                                 cstring_makeLiteralTemp (b ? "+" : "-"),
-                                 flagcode_name (f));
-         flagWarning (warn);
-         cstring_free (warn);
+         llerror_flagWarning 
+           (message ("Setting %s%s redundant with current value", 
+                     cstring_makeLiteralTemp (b ? "+" : "-"),
+                     flagcode_unparse (f)));
+       }
+    }
+
+  if (flagcode_isWarnUseFlag (f) && b)
+    {
+      if (!context_getFlag (FLG_WARNUSE))
+       {
+         llerror_flagWarning
+           (message ("Flag +%s is canceled by -warnuse",
+                     flagcode_unparse (f)));
        }
     }
 
+
   if (flagcode_isLibraryFlag (f)) 
     {
       if (gc.library != FLG_ANSILIB
          && gc.library != f)
        {
-         cstring warn = message ("selecting library %s after library %s was "
-                                 "selected (only one library may be used)",
-                                 flagcode_name (f),
-                                 flagcode_name (gc.library));
-         flagWarning (warn);
-         cstring_free (warn);
+         llerror_flagWarning 
+           (message ("Selecting library %s after library %s was "
+                     "selected (only one library may be used)",
+                     flagcode_unparse (f),
+                     flagcode_unparse (gc.library)));
        }
-
+      
       if (f == FLG_UNIXLIB)
        {
          if (context_getFlag (FLG_WARNUNIXLIB))
            {
-             flagWarning (cstring_makeLiteralTemp 
-                          ("selecting unix library.  Unix library is "
-                           "ad hoc addition to POSIX library.  Recommend "
-                           "use +posixlib to select POSIX library instead. "
-                           "Use -warnunixlib to suppress this message."));
+             llerror_flagWarning
+               (cstring_makeLiteral
+                ("Selecting unix library.  Unix library is "
+                 "based on the Single Unix Specification, Version 2.  Not all "
+                 "Unix implementations are consistend with this specification. "
+                 "Use -warnunixlib to suppress this message."));
            }
        }
       
       gc.library = f;
     }
   
+  if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
+    {
+      llerror_flagWarning
+       (message
+        ("Setting +%s will not produce warnings with -namechecks. "
+         "Must set +namechecks also.",
+         flagcode_unparse (f)));
+    }
+  
   gc.setGlobally[f] = TRUE;
-  context_setFlag (f, b);
+  context_setFlag (f, b, g_currentloc);
 }
 
 void
-context_fileSetFlag (flagcode f, ynm set)
+context_fileSetFlag (flagcode f, ynm set, fileloc loc)
 {
   if (!gc.savedFlags)
     {
@@ -3332,23 +3826,22 @@ context_fileSetFlag (flagcode f, ynm set)
 
   if (ynm_isOff (set))
     {
-      context_setFlagAux (f, FALSE, TRUE, FALSE);
+      context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
     }
   else if (ynm_isOn (set))
     {
-      context_setFlagAux (f, TRUE, TRUE, FALSE);
+      context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
       gc.setLocally[f] = TRUE;
     }
   else
     {
-      context_restoreFlag (f);
+      context_restoreFlag (f, loc);
     }
 }
 
 static void
-context_restoreFlag (flagcode f)
+context_restoreFlag (flagcode f, fileloc loc)
 {
-  
   if (!gc.savedFlags)
     {
       voptgenerror 
@@ -3356,20 +3849,20 @@ context_restoreFlag (flagcode f)
         message ("Attempt to restore flag %s when no file scope flags "
                  "have been set.",
                  flagcode_unparse (f)),
-        g_currentloc);
+        loc);
     }
   else
     {
-      context_addFlagMarker (f, MAYBE);
-      context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
+      context_addFlagMarker (f, MAYBE, loc);
+      context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
     }
 
   }
 
 static void
-context_setFlag (flagcode f, bool b)
+context_setFlag (flagcode f, bool b, fileloc loc)
 {
-  context_setFlagAux (f, b, FALSE, FALSE);
+  context_setFlagAux (f, b, FALSE, FALSE, loc);
 }
 
 void
@@ -3382,284 +3875,383 @@ context_setFlagTemp (flagcode f, bool b)
 /*@notfunction@*/
 # define DOSET(ff,b) \
    do { if (inFile) { gc.setLocally[ff] = TRUE; \
-                     context_addFlagMarker (ff, ynm_fromBool (b)); } \
-        DPRINTF (("set flag: %s / %s", flagcode_name (ff), bool_unparse (b))); \
+                     context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
+        DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
         gc.flags[ff] = b; } while (FALSE)
 
 static void
-  context_setFlagAux (flagcode f, bool b, bool 
-                     inFile, /*@unused@*/ bool isRestore)
+context_setFlagAux (flagcode f, bool b, bool inFile, 
+                   /*@unused@*/ bool isRestore, fileloc loc)
 {
-  DPRINTF (("set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
+  DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
 
-  if (f == FLG_USESTDERR) 
+  /*
+  ** Removed test for special flags.
+  */
+
+  if (flagcode_isIdemFlag (f))
     {
-      if (b) {
-       g_msgstream = stderr;
-      } else {
-       g_msgstream = stdout;
-      }
+      DOSET (f, TRUE);
     }
-
-  if (flagcode_isSpecialFlag (f))
+  else
     {
-      gc.flags[f] = b;
-
-      
-      switch (f)
-       {     
-       case FLG_ALLEMPTY:
-         DOSET (FLG_ALLEMPTY, b);
-         DOSET (FLG_IFEMPTY, b);
-         DOSET (FLG_WHILEEMPTY, b);
-         DOSET (FLG_FOREMPTY, b);
-         break;
-       case FLG_PREDBOOL:
-         DOSET (FLG_PREDBOOL, b);
-         DOSET (FLG_PREDBOOLINT, b);
-         DOSET (FLG_PREDBOOLPTR, b);
-         DOSET (FLG_PREDBOOLOTHERS, b);
-         break;
-       case FLG_GLOBALIAS:
-         DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
-         DOSET (FLG_CHECKEDGLOBALIAS, b);
-         DOSET (FLG_CHECKMODGLOBALIAS, b);
-         DOSET (FLG_UNCHECKEDGLOBALIAS, b);
-         break;
-       case FLG_ALLBLOCK:
-         DOSET (FLG_ALLBLOCK, b);
-         DOSET (FLG_IFBLOCK, b);
-         DOSET (FLG_WHILEBLOCK, b);
-         DOSET (FLG_FORBLOCK, b);
-         break;
-       case FLG_GRAMMAR:
-         if (b)
-           {
-             yydebug = 1;
-           }
-         else
-           {
-             yydebug = 0;
-           }
-         
-         DOSET (FLG_GRAMMAR, b);
-         break;
-       case FLG_CODEIMPONLY:
-         DOSET (FLG_CODEIMPONLY, b);
-         DOSET (FLG_GLOBIMPONLY, b);
-         DOSET (FLG_RETIMPONLY, b);
-         DOSET (FLG_STRUCTIMPONLY, b);
-         break;
-       case FLG_SPECALLIMPONLY:
-                 DOSET (FLG_SPECALLIMPONLY, b);
-         DOSET (FLG_SPECGLOBIMPONLY, b);
-         DOSET (FLG_SPECRETIMPONLY, b);
-         DOSET (FLG_SPECSTRUCTIMPONLY, b);
-         break;
-       case FLG_ALLIMPONLY:
-         DOSET (FLG_ALLIMPONLY, b);
-         DOSET (FLG_GLOBIMPONLY, b);
-         DOSET (FLG_RETIMPONLY, b);
-         DOSET (FLG_STRUCTIMPONLY, b);
-         DOSET (FLG_SPECGLOBIMPONLY, b);
-         DOSET (FLG_SPECRETIMPONLY, b);
-         DOSET (FLG_SPECSTRUCTIMPONLY, b);
-         break;
-       case FLG_ANSILIMITS: 
-         DOSET (FLG_ANSILIMITS, b);
-         DOSET (FLG_CONTROLNESTDEPTH, b);
-         DOSET (FLG_STRINGLITERALLEN, b);
-         DOSET (FLG_INCLUDENEST, b);
-         DOSET (FLG_NUMSTRUCTFIELDS, b);
-         DOSET (FLG_NUMENUMMEMBERS, b);
-         
-         if (b)
-           {
-             context_setValue (FLG_CONTROLNESTDEPTH, DEFAULT_CONTROLNESTDEPTH);
-             context_setValue (FLG_STRINGLITERALLEN, DEFAULT_STRINGLITERALLEN);
-             context_setValue (FLG_INCLUDENEST, DEFAULT_INCLUDENEST);
-             context_setValue (FLG_NUMSTRUCTFIELDS, DEFAULT_NUMSTRUCTFIELDS);
-             context_setValue (FLG_NUMENUMMEMBERS, DEFAULT_NUMENUMMEMBERS);
-           }
-         break;
-       case FLG_EXTERNALNAMELEN:
-         DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
-         DOSET (FLG_EXTERNALNAMELEN, TRUE);
-         break;
-       case FLG_INTERNALNAMELEN:
-         DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
-         DOSET (FLG_INTERNALNAMELEN, TRUE);
-         break;
-       case FLG_EXTERNALNAMECASEINSENSITIVE:
-         DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
-
-         if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
-           {
-             DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
-             context_setValue (FLG_EXTERNALNAMELEN, 0);
-           }
-         break;
-       case FLG_INTERNALNAMECASEINSENSITIVE:
-         DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
-
-         if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
-           {
-             DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
-             context_setValue (FLG_INTERNALNAMELEN, 0);
-           }
-         break;
-       case FLG_INTERNALNAMELOOKALIKE:
-         DOSET (FLG_INTERNALNAMELOOKALIKE, b);
+      DOSET (f, b);
+    }
 
-         if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
+  if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
+    {
+      if (b) /* Turing higher level on, turns on all lower levels */
+       {
+         switch (f)
            {
-             DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
-             context_setValue (FLG_INTERNALNAMELEN, 0);
+           case FLG_ITS4MOSTRISKY:
+             DOSET (FLG_ITS4VERYRISKY, b);
+             /*@fallthrough@*/ 
+           case FLG_ITS4VERYRISKY:
+             DOSET (FLG_ITS4RISKY, b);
+             /*@fallthrough@*/ 
+           case FLG_ITS4RISKY:
+             DOSET (FLG_ITS4MODERATERISK, b);
+             /*@fallthrough@*/ 
+           case FLG_ITS4MODERATERISK:
+             DOSET (FLG_ITS4LOWRISK, b);
+             /*@fallthrough@*/ 
+           case FLG_ITS4LOWRISK:
+             break;
+             BADDEFAULT;
            }
-         break;
-       case FLG_MODUNSPEC:
-         DOSET (FLG_MODNOMODS, b);
-         DOSET (FLG_MODGLOBSUNSPEC, b);
-         DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
-         break;
-       case FLG_EXPORTANY: 
-         DOSET (FLG_EXPORTVAR, b);
-         DOSET (FLG_EXPORTFCN, b);
-         DOSET (FLG_EXPORTTYPE, b);
-         DOSET (FLG_EXPORTMACRO, b);
-         DOSET (FLG_EXPORTCONST, b);
-         gc.anyExports = TRUE;
-         break;
-       case FLG_REPEXPOSE:
-         DOSET (FLG_RETEXPOSE, b); 
-         DOSET (FLG_ASSIGNEXPOSE, b); 
-         DOSET (FLG_CASTEXPOSE, b); 
-         break;
-       case FLG_RETVAL:
-         DOSET (FLG_RETVALBOOL, b);
-         DOSET (FLG_RETVALINT, b);
-         DOSET (FLG_RETVALOTHER, b);
-         break;
-       case FLG_PARTIAL:
-         if (b)
+       }
+      else /* Turning level off, turns off all higher levels */
+       {
+         switch (f)
            {
-             DOSET (FLG_EXPORTLOCAL, FALSE);
-             DOSET (FLG_DECLUNDEF, FALSE);
-             DOSET (FLG_SPECUNDEF, FALSE);
-             DOSET (FLG_TOPUNUSED, FALSE);
+           case FLG_ITS4LOWRISK:
+             DOSET (FLG_ITS4MODERATERISK, b);
+             /*@fallthrough@*/ 
+           case FLG_ITS4MODERATERISK:
+             DOSET (FLG_ITS4RISKY, b);
+             /*@fallthrough@*/ 
+           case FLG_ITS4RISKY:
+             DOSET (FLG_ITS4VERYRISKY, b);
+             /*@fallthrough@*/ 
+           case FLG_ITS4VERYRISKY:
+             DOSET (FLG_ITS4MOSTRISKY, b);
+             /*@fallthrough@*/ 
+           case FLG_ITS4MOSTRISKY:
+             break;
+             BADDEFAULT;
            }
-         break;
-       case FLG_DEEPBREAK:
-         DOSET (FLG_LOOPLOOPBREAK, b);
-         DOSET (FLG_LOOPSWITCHBREAK, b);
-         DOSET (FLG_SWITCHLOOPBREAK, b);
-         DOSET (FLG_SWITCHSWITCHBREAK, b);
-         DOSET (FLG_LOOPLOOPCONTINUE, b);
-         DOSET (FLG_DEEPBREAK, b);
-         break;
-       case FLG_ACCESSALL:
-         DOSET (FLG_ACCESSMODULE, b);
-         DOSET (FLG_ACCESSFILE, b);
-         DOSET (FLG_ACCESSCZECH, b);
-         break;
-       case FLG_ALLMACROS:
-         DOSET (FLG_ALLMACROS, b);
-         DOSET (FLG_FCNMACROS, b);
-         DOSET (FLG_CONSTMACROS, b);
-         break;
-       case FLG_CZECH:
-         if (b) { DOSET (FLG_ACCESSCZECH, b); }
-         DOSET (FLG_CZECHFUNCTIONS, b);
-         DOSET (FLG_CZECHVARS, b);
-         DOSET (FLG_CZECHCONSTANTS, b);
-         DOSET (FLG_CZECHTYPES, b);
-         break;
-       case FLG_SLOVAK:
-         if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
-         DOSET (FLG_SLOVAKFUNCTIONS, b);
-         DOSET (FLG_SLOVAKVARS, b);
-         DOSET (FLG_SLOVAKCONSTANTS, b);
-         DOSET (FLG_SLOVAKTYPES, b);
-         break;
-       case FLG_CZECHOSLOVAK:
-         if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
-         DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
-         DOSET (FLG_CZECHOSLOVAKVARS, b);
-         DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
-         DOSET (FLG_CZECHOSLOVAKTYPES, b);
-         break;
-       case FLG_NULL:
-         DOSET (FLG_NULLSTATE, b);
-         DOSET (FLG_NULLDEREF, b);
-         DOSET (FLG_NULLASSIGN, b);
-         DOSET (FLG_NULLPASS, b);
-         DOSET (FLG_NULLRET, b);
-         break;
-       case FLG_MEMCHECKS:
-         DOSET (FLG_NULLSTATE, b);
-         DOSET (FLG_NULLDEREF, b);
-         DOSET (FLG_NULLASSIGN, b);
-         DOSET (FLG_NULLPASS, b);
-         DOSET (FLG_NULLRET, b);
-         DOSET (FLG_COMPDEF, b);
-         DOSET (FLG_COMPMEMPASS, b);
-         DOSET (FLG_UNIONDEF, b);
-         DOSET (FLG_MEMTRANS, b);
-         DOSET (FLG_USERELEASED, b);
-         DOSET (FLG_ALIASUNIQUE, b);
-         DOSET (FLG_MAYALIASUNIQUE, b);
-         DOSET (FLG_MUSTFREE, b);
-         DOSET (FLG_MUSTDEFINE, b);
-         DOSET (FLG_GLOBSTATE, b); 
-         DOSET (FLG_COMPDESTROY, b);
-         DOSET (FLG_MUSTNOTALIAS, b);
-         DOSET (FLG_MEMIMPLICIT, b);
-         DOSET (FLG_BRANCHSTATE, b); 
-         /*@fallthrough@*/ /* also sets memtrans flags */
-       case FLG_MEMTRANS:
-         DOSET (FLG_MEMTRANS, b);
-         DOSET (FLG_EXPOSETRANS, b);
-         DOSET (FLG_OBSERVERTRANS, b);
-         DOSET (FLG_DEPENDENTTRANS, b);
-         DOSET (FLG_NEWREFTRANS, b);
-         DOSET (FLG_ONLYTRANS, b);
-         DOSET (FLG_OWNEDTRANS, b);
-         DOSET (FLG_FRESHTRANS, b);
-         DOSET (FLG_SHAREDTRANS, b);
-         DOSET (FLG_TEMPTRANS, b);
-         DOSET (FLG_KEPTTRANS, b);
-         DOSET (FLG_REFCOUNTTRANS, b);
-         DOSET (FLG_STATICTRANS, b);
-         DOSET (FLG_UNKNOWNTRANS, b);
-         DOSET (FLG_KEEPTRANS, b);
-         DOSET (FLG_IMMEDIATETRANS, b);
-         break;
-
-       default:
-         llcontbug (message ("Unhandled special flag: %s", 
-                             flagcode_unparse (f)));
-         break;
        }
     }
-  else
-    {
-      if (flagcode_isIdemFlag (f))
+  
+  switch (f)
+    {     
+    case FLG_MESSAGESTREAMSTDOUT:
+      g_messagestream = stdout;
+      break;
+    case FLG_MESSAGESTREAMSTDERR:
+      g_messagestream = stderr;
+      break;
+    case FLG_WARNINGSTREAMSTDOUT:
+      g_warningstream = stdout;
+      break;
+    case FLG_WARNINGSTREAMSTDERR:
+      g_warningstream = stderr;
+      break;
+    case FLG_ERRORSTREAMSTDOUT:
+      g_errorstream = stdout;
+      break;
+    case FLG_ERRORSTREAMSTDERR:
+      g_errorstream = stderr;
+      break;
+    case FLG_ALLEMPTY:
+      DOSET (FLG_ALLEMPTY, b);
+      DOSET (FLG_IFEMPTY, b);
+      DOSET (FLG_WHILEEMPTY, b);
+      DOSET (FLG_FOREMPTY, b);
+      break;
+    case FLG_PREDBOOL:
+      DOSET (FLG_PREDBOOL, b);
+      DOSET (FLG_PREDBOOLINT, b);
+      DOSET (FLG_PREDBOOLPTR, b);
+      DOSET (FLG_PREDBOOLOTHERS, b);
+      break;
+    case FLG_GLOBALIAS:
+      DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
+      DOSET (FLG_CHECKEDGLOBALIAS, b);
+      DOSET (FLG_CHECKMODGLOBALIAS, b);
+      DOSET (FLG_UNCHECKEDGLOBALIAS, b);
+      break;
+    case FLG_ALLBLOCK:
+      DOSET (FLG_ALLBLOCK, b);
+      DOSET (FLG_IFBLOCK, b);
+      DOSET (FLG_WHILEBLOCK, b);
+      DOSET (FLG_FORBLOCK, b);
+      break;
+    case FLG_GRAMMAR:
+      if (b)
        {
-         DOSET (f, TRUE);
+         yydebug = 1;
+         mtdebug = 1;
        }
       else
        {
-         if (b && !gc.anyExports
-             && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
-                 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
-                 || f == FLG_EXPORTCONST
-                 || f == FLG_EXPORTANY))
-           {
-             gc.anyExports = TRUE;
-           }
-
-         DOSET (f, b);
+         yydebug = 0;
+         mtdebug = 0;
+       }
+      
+      DOSET (FLG_GRAMMAR, b);
+      break;
+    case FLG_CODEIMPONLY:
+      DOSET (FLG_CODEIMPONLY, b);
+      DOSET (FLG_GLOBIMPONLY, b);
+      DOSET (FLG_RETIMPONLY, b);
+      DOSET (FLG_STRUCTIMPONLY, b);
+      break;
+    case FLG_SPECALLIMPONLY:
+      DOSET (FLG_SPECALLIMPONLY, b);
+      DOSET (FLG_SPECGLOBIMPONLY, b);
+      DOSET (FLG_SPECRETIMPONLY, b);
+      DOSET (FLG_SPECSTRUCTIMPONLY, b);
+      break;
+    case FLG_ALLIMPONLY:
+      DOSET (FLG_ALLIMPONLY, b);
+      DOSET (FLG_GLOBIMPONLY, b);
+      DOSET (FLG_RETIMPONLY, b);
+      DOSET (FLG_STRUCTIMPONLY, b);
+      DOSET (FLG_SPECGLOBIMPONLY, b);
+      DOSET (FLG_SPECRETIMPONLY, b);
+      DOSET (FLG_SPECSTRUCTIMPONLY, b);
+      break;
+    case FLG_ANSI89LIMITS: 
+      DOSET (FLG_ANSI89LIMITS, b);
+      DOSET (FLG_CONTROLNESTDEPTH, b);
+      DOSET (FLG_STRINGLITERALLEN, b);
+      DOSET (FLG_INCLUDENEST, b);
+      DOSET (FLG_NUMSTRUCTFIELDS, b);
+      DOSET (FLG_NUMENUMMEMBERS, b);
+      
+      if (b)
+       {
+         context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
+         context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
+         context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
+         context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
+         context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
+         context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
+         context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
+       }
+      break;
+    case FLG_ISO99LIMITS: 
+      DOSET (FLG_ISO99LIMITS, b);
+      DOSET (FLG_CONTROLNESTDEPTH, b);
+      DOSET (FLG_STRINGLITERALLEN, b);
+      DOSET (FLG_INCLUDENEST, b);
+      DOSET (FLG_NUMSTRUCTFIELDS, b);
+      DOSET (FLG_NUMENUMMEMBERS, b);
+      
+      if (b)
+       {
+         context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
+         context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
+         context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
+         context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
+         context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
+         context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
+         context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
+       }
+      break;
+    case FLG_EXTERNALNAMELEN:
+      DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
+      DOSET (FLG_EXTERNALNAMELEN, TRUE);
+      break;
+    case FLG_INTERNALNAMELEN:
+      DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
+      DOSET (FLG_INTERNALNAMELEN, TRUE);
+      break;
+    case FLG_EXTERNALNAMECASEINSENSITIVE:
+      DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
+      
+      if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
+       {
+         DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
+         context_setValue (FLG_EXTERNALNAMELEN, 0);
        }
+      break;
+    case FLG_INTERNALNAMECASEINSENSITIVE:
+      DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
+      
+      if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
+       {
+         DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
+         context_setValue (FLG_INTERNALNAMELEN, 0);
+       }
+      break;
+    case FLG_INTERNALNAMELOOKALIKE:
+      DOSET (FLG_INTERNALNAMELOOKALIKE, b);
+      
+      if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
+       {
+         DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
+         context_setValue (FLG_INTERNALNAMELEN, 0);
+       }
+      break;
+    case FLG_MODUNSPEC:
+      DOSET (FLG_MODNOMODS, b);
+      DOSET (FLG_MODGLOBSUNSPEC, b);
+      DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
+      break;
+    case FLG_EXPORTANY: 
+      DOSET (FLG_EXPORTVAR, b);
+      DOSET (FLG_EXPORTFCN, b);
+      DOSET (FLG_EXPORTTYPE, b);
+      DOSET (FLG_EXPORTMACRO, b);
+      DOSET (FLG_EXPORTCONST, b);
+      gc.anyExports = TRUE;
+      break;
+    case FLG_REPEXPOSE:
+      DOSET (FLG_RETEXPOSE, b); 
+      DOSET (FLG_ASSIGNEXPOSE, b); 
+      DOSET (FLG_CASTEXPOSE, b); 
+      break;
+    case FLG_RETVAL:
+      DOSET (FLG_RETVALBOOL, b);
+      DOSET (FLG_RETVALINT, b);
+      DOSET (FLG_RETVALOTHER, b);
+      break;
+    case FLG_PARTIAL:
+      if (b)
+       {
+         DOSET (FLG_EXPORTLOCAL, FALSE);
+         DOSET (FLG_DECLUNDEF, FALSE);
+         DOSET (FLG_SPECUNDEF, FALSE);
+         DOSET (FLG_TOPUNUSED, FALSE);
+       }
+      break;
+    case FLG_DEEPBREAK:
+      DOSET (FLG_LOOPLOOPBREAK, b);
+      DOSET (FLG_LOOPSWITCHBREAK, b);
+      DOSET (FLG_SWITCHLOOPBREAK, b);
+      DOSET (FLG_SWITCHSWITCHBREAK, b);
+      DOSET (FLG_LOOPLOOPCONTINUE, b);
+      DOSET (FLG_DEEPBREAK, b);
+      break;
+    case FLG_LOOPEXEC:
+      DOSET (FLG_FORLOOPEXEC, b);
+      DOSET (FLG_WHILELOOPEXEC, b);
+      DOSET (FLG_ITERLOOPEXEC, b);
+      break;
+    case FLG_ACCESSALL:
+      DOSET (FLG_ACCESSMODULE, b);
+      DOSET (FLG_ACCESSFILE, b);
+      DOSET (FLG_ACCESSCZECH, b);
+      break;
+    case FLG_ALLMACROS:
+      DOSET (FLG_ALLMACROS, b);
+      DOSET (FLG_FCNMACROS, b);
+      DOSET (FLG_CONSTMACROS, b);
+      break;      
+    case FLG_BOUNDS:
+      DOSET (FLG_BOUNDSREAD, b);
+      DOSET (FLG_BOUNDSWRITE, b);
+      DOSET (FLG_LIKELYBOUNDSREAD, b);
+      DOSET (FLG_LIKELYBOUNDSWRITE, b);
+      break;
+    case FLG_BOUNDSREAD:
+      DOSET (FLG_LIKELYBOUNDSREAD, b);
+      break;
+    case FLG_BOUNDSWRITE:
+      DOSET (FLG_LIKELYBOUNDSWRITE, b);
+      break;
+    case FLG_LIKELYBOUNDS:
+      DOSET (FLG_LIKELYBOUNDSREAD, b);
+      DOSET (FLG_LIKELYBOUNDSWRITE, b);
+      break;
+      
+    case FLG_CZECH:
+      if (b) { DOSET (FLG_ACCESSCZECH, b); }
+      DOSET (FLG_CZECHFUNCTIONS, b);
+      DOSET (FLG_CZECHVARS, b);
+      DOSET (FLG_CZECHCONSTANTS, b);
+      DOSET (FLG_CZECHTYPES, b);
+      break;
+    case FLG_SLOVAK:
+      if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
+      DOSET (FLG_SLOVAKFUNCTIONS, b);
+      DOSET (FLG_SLOVAKVARS, b);
+      DOSET (FLG_SLOVAKCONSTANTS, b);
+      DOSET (FLG_SLOVAKTYPES, b);
+      break;
+    case FLG_CZECHOSLOVAK:
+      if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
+      DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
+      DOSET (FLG_CZECHOSLOVAKVARS, b);
+      DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
+      DOSET (FLG_CZECHOSLOVAKTYPES, b);
+      break;
+    case FLG_NULL:
+      DOSET (FLG_NULLSTATE, b);
+      DOSET (FLG_NULLDEREF, b);
+      DOSET (FLG_NULLASSIGN, b);
+      DOSET (FLG_NULLPASS, b);
+      DOSET (FLG_NULLRET, b);
+      break;
+    case FLG_MUSTFREE:
+      DOSET (FLG_MUSTFREEONLY, b);
+      DOSET (FLG_MUSTFREEFRESH, b);
+      break;
+    case FLG_MEMCHECKS:
+      DOSET (FLG_NULLSTATE, b);
+      DOSET (FLG_NULLDEREF, b);
+      DOSET (FLG_NULLASSIGN, b);
+      DOSET (FLG_NULLPASS, b);
+      DOSET (FLG_NULLRET, b);
+      DOSET (FLG_COMPDEF, b);
+      DOSET (FLG_COMPMEMPASS, b);
+      DOSET (FLG_UNIONDEF, b);
+      DOSET (FLG_MEMTRANS, b);
+      DOSET (FLG_USERELEASED, b);
+      DOSET (FLG_ALIASUNIQUE, b);
+      DOSET (FLG_MAYALIASUNIQUE, b);
+      DOSET (FLG_MUSTFREEONLY, b);
+      DOSET (FLG_MUSTFREEFRESH, b);
+      DOSET (FLG_MUSTDEFINE, b);
+      DOSET (FLG_GLOBSTATE, b); 
+      DOSET (FLG_COMPDESTROY, b);
+      DOSET (FLG_MUSTNOTALIAS, b);
+      DOSET (FLG_MEMIMPLICIT, b);
+      DOSET (FLG_BRANCHSTATE, b); 
+      /*@fallthrough@*/ /* also sets memtrans flags */
+    case FLG_MEMTRANS:
+      DOSET (FLG_MEMTRANS, b);
+      DOSET (FLG_EXPOSETRANS, b);
+      DOSET (FLG_OBSERVERTRANS, b);
+      DOSET (FLG_DEPENDENTTRANS, b);
+      DOSET (FLG_NEWREFTRANS, b);
+      DOSET (FLG_ONLYTRANS, b);
+      DOSET (FLG_OWNEDTRANS, b);
+      DOSET (FLG_FRESHTRANS, b);
+      DOSET (FLG_SHAREDTRANS, b);
+      DOSET (FLG_TEMPTRANS, b);
+      DOSET (FLG_KEPTTRANS, b);
+      DOSET (FLG_REFCOUNTTRANS, b);
+      DOSET (FLG_STATICTRANS, b);
+      DOSET (FLG_UNKNOWNTRANS, b);
+      DOSET (FLG_KEEPTRANS, b);
+      DOSET (FLG_IMMEDIATETRANS, b);
+      break;
+      
+    default:
+      break;
+    }
+
+  if (b && !gc.anyExports
+      && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
+         || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
+         || f == FLG_EXPORTCONST
+         || f == FLG_EXPORTANY))
+    {
+      gc.anyExports = TRUE;
     }
 }
 
@@ -3675,6 +4267,12 @@ context_getFlag (flagcode d)
   return (gc.flags[d]);
 }
 
+bool
+context_flagOn (flagcode f, fileloc loc)
+{
+  return (!context_suppressFlagMsg (f, loc));
+}
+
 static void context_saveFlagSettings (void)
 {
   gc.savedFlags = TRUE;
@@ -3740,14 +4338,14 @@ void context_setFilename (fileId fid, int lineno)
 
 void context_enterIterDef (/*@observer@*/ uentry le)
 {
-    context_enterMacro (le);
+  context_enterMacro (le);
   gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
   gc.kind = CX_ITERDEF;
 }
 
 void context_enterIterEnd (/*@observer@*/ uentry le)
 {
-    context_enterMacro (le);
+  context_enterMacro (le);
   gc.kind = CX_ITEREND;
 }
 
@@ -3755,17 +4353,29 @@ void
 context_destroyMod (void) 
    /*@globals killed gc@*/
 {
+  int i;
   setCodePoint ();
   ctype_destroyMod ();
+  /*
   setCodePoint ();
   usymtab_free ();
   setCodePoint ();
+  */
+
   fileTable_free (gc.ftab);
+  gc.ftab = fileTable_undefined;
+
   filelocStack_free (gc.locstack);
   setCodePoint ();
-  gc.ftab = fileTable_undefined;
 
   macrocache_free (gc.mc);
+
+  /* evans 2002-07-12: not reported because of reldef */
+  for (i = 0; i < gc.nmods; i++)
+    {
+      cstring_free (gc.moduleaccess[i].file);
+    }
+
   sfree (gc.moduleaccess);
   setCodePoint ();
 
@@ -3784,43 +4394,53 @@ context_destroyMod (void)
   
   cstring_free (gc.msgAnnote);
   globSet_free (gc.globs_used);
-  }
+  metaStateTable_free (gc.stateTable);
+  annotationTable_free (gc.annotTable);
+}
 
 /*
-** Flag shortcuts.
+** Flag shortcuts
 */
 
 bool context_msgBoolInt (void)
 {
-  return gc.flags [FLG_BOOLINT];
+  return context_flagOn (FLG_BOOLINT, g_currentloc);
 }
 
 bool context_msgCharInt (void)
 {
-  return gc.flags [FLG_CHARINT];
+  return context_flagOn (FLG_CHARINT, g_currentloc);
 }
 
 bool context_msgEnumInt (void)
 {
-  return gc.flags [FLG_ENUMINT];
+  return context_flagOn (FLG_ENUMINT, g_currentloc);
+}
+
+bool context_msgLongInt (void)
+{
+  return context_flagOn (FLG_LONGINT, g_currentloc);
+}
+
+bool context_msgShortInt (void)
+{
+  return context_flagOn (FLG_SHORTINT, g_currentloc);
 }
 
 bool context_msgPointerArith (void) 
 {
-  return gc.flags [FLG_POINTERARITH];
+  return context_flagOn (FLG_POINTERARITH, g_currentloc);
 }
 
 bool context_msgStrictOps (void) 
 {
-  return gc.flags [FLG_STRICTOPS];
+  return context_flagOn (FLG_STRICTOPS, g_currentloc);
 }
 
-# ifndef NOLCL
 bool context_msgLh (void)           
 {
   return gc.flags [FLG_DOLH];
 }
-# endif
 
 void context_pushLoc (void) 
 {
@@ -3857,6 +4477,7 @@ bool context_anyErrors (void)
 void context_hasError (void)
 {
   gc.numerrors++;
+  DPRINTF (("num errors: %d", gc.numerrors));
 }
 
 int context_numErrors (void)
@@ -3879,12 +4500,10 @@ int context_getExpect (void)
   return (context_getValue (FLG_EXPECT));
 }
 
-# ifndef NOLCL
 int context_getLCLExpect (void)
 {
   return (context_getValue (FLG_LCLEXPECT));
 }
-# endif
 
 int context_getLimit (void)
 {
@@ -3956,7 +4575,7 @@ bool context_inMacroConstant (void)
   return (gc.kind == CX_MACROCONST);
 }
 
-bool context_inMacroUnknown (void)
+bool context_inUnknownMacro (void)
 {   
   return (gc.kind == CX_UNKNOWNMACRO);
 }
@@ -3986,12 +4605,34 @@ cstring context_getMerge (void)
   return context_getString (FLG_MERGE);
 }
 
-# ifndef NOLCL
 bool context_inLCLLib (void)
 {   
   return (gc.kind == CX_LCLLIB);
 }
 
+
+/*drl add these 3/5/2003*/
+static bool inSizeof = FALSE;
+
+bool context_inSizeof (void)
+{
+  return (inSizeof);
+}
+
+void context_enterSizeof (void)
+{
+  DPRINTF((message("context_enterSizeof ") ) );
+  inSizeof = TRUE;
+}
+
+void context_leaveSizeof (void)
+{ 
+  DPRINTF((message("context_leaveSizeof ") ));
+  inSizeof = FALSE;
+}
+/*end function added 3/5/2003*/
+
+
 bool context_inImport (void)
 {
   return (gc.inimport);
@@ -4006,7 +4647,6 @@ void context_leaveImport (void)
 { 
   gc.inimport = FALSE;
 }
-# endif
 
 bool context_inMacro (void) 
 {
@@ -4035,7 +4675,6 @@ int context_getSpecLinesProcessed (void)
   return (gc.speclinesprocessed);
 }
 
-# ifndef NOLCL
 void context_processedSpecLine (void)
 {
   gc.speclinesprocessed++;
@@ -4044,14 +4683,45 @@ void context_processedSpecLine (void)
 void context_resetSpecLines (void)    
 {
   gc.speclinesprocessed = 0;
+
 }
-# endif
 
 bool context_inGlobalContext (void)
 {
   return (gc.kind == CX_GLOBAL);
 }
 
+static void context_quietExitScopes (void)
+{
+  /*
+  ** Try to restore the global scope (after an error).
+  */
+
+  while (!usymtab_inFileScope ())
+    {
+      usymtab_quietExitScope (g_currentloc);
+    }
+
+  gc.cont.glob = TRUE;
+  gc.kind = CX_GLOBAL;
+}
+
+void context_checkGlobalScope (void)
+{
+  if (gc.kind != CX_GLOBAL)
+    {
+      if (context_inMacro ())
+       {
+         ; /* evans 2001-10-14: Okay to be in a macro here! */ 
+       }
+      else
+       {
+         llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
+         context_quietExitScopes ();
+       }
+    }
+}
+
 void context_setFileId (fileId s)
 {
   g_currentloc = fileloc_updateFileId (g_currentloc, s); 
@@ -4135,9 +4805,168 @@ void context_showFilelocStack (void)
   filelocStack_printIncludes (gc.locstack);
 }
 
+metaStateTable context_getMetaStateTable (void) 
+{
+  return gc.stateTable;
+}
+
+metaStateInfo context_lookupMetaStateInfo (cstring key)
+{
+  return metaStateTable_lookup (gc.stateTable, key);
+}
 
+/*@null@*/ annotationInfo context_lookupAnnotation (cstring annot) 
+{
+  return annotationTable_lookup (gc.annotTable, annot);
+}
 
+void context_addAnnotation (annotationInfo info)
+{
+  if (annotationTable_contains (gc.annotTable, annotationInfo_getName (info)))
+    {
+      voptgenerror 
+       (FLG_SYNTAX,
+        message ("Duplicate annotation declaration: %s", annotationInfo_getName (info)),
+        annotationInfo_getLoc (info));
 
+      annotationInfo_free (info);
+    }
+  else
+    {
+      annotationTable_insert (gc.annotTable, info);
+    }
+}
 
+void context_addMetaState (cstring mname, metaStateInfo msinfo)
+{
+  if (metaStateTable_contains (gc.stateTable, mname))
+    {
+      voptgenerror 
+       (FLG_SYNTAX,
+        message ("Duplicate metastate declaration: %s", mname),
+        metaStateInfo_getLoc (msinfo));
+      cstring_free (mname);
+      metaStateInfo_free (msinfo);
+    }
+  else
+    {
+      DPRINTF (("Adding meta state: %s", mname));
+      metaStateTable_insert (gc.stateTable, mname, msinfo); 
+    }
+}
 
+valueTable context_createValueTable (sRef s, stateInfo info)
+{
+  if (metaStateTable_size (gc.stateTable) > 0)
+    {
+      valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
+      /* should use smaller value... */
+      DPRINTF (("Value table for: %s", sRef_unparse (s)));
+      
+      metaStateTable_elements (gc.stateTable, msname, msi)
+       {
+         mtContextNode context = metaStateInfo_getContext (msi);
+
+         if (mtContextNode_matchesRefStrict (context, s))
+           {
+             DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
+             llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
+             
+             valueTable_insert 
+               (res,
+                cstring_copy (metaStateInfo_getName (msi)),
+                stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s), 
+                                           stateInfo_copy (info)));
+           }
+         else
+           {
+             DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
+           }
+       } 
+      end_metaStateTable_elements ;
+      
+      stateInfo_free (info);
+      DPRINTF (("Value table: %s", valueTable_unparse (res)));
+      return res;
+    }
+  else
+    {
+      stateInfo_free (info);
+      return valueTable_undefined;
+    }
+}
+
+valueTable context_createGlobalMarkerValueTable (stateInfo info)
+{
+  if (metaStateTable_size (gc.stateTable) > 0)
+    {
+      valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
+      /* should use smaller value... */
+      
+      metaStateTable_elements (gc.stateTable, msname, msi)
+       {
+         /* only add global...*/
+         DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
+         llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
+         
+         valueTable_insert (res,
+                            cstring_copy (metaStateInfo_getName (msi)),
+                            stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
+                                               stateInfo_copy (info)));
+       } 
+      end_metaStateTable_elements ;
+      
+      stateInfo_free (info);
+      DPRINTF (("Value table: %s", valueTable_unparse (res)));
+      return res;
+    }
+  else
+    {
+      stateInfo_free (info);
+      return valueTable_undefined;
+    }
+}
+
+constraintList context_getImplicitFcnConstraints (uentry ue)
+{
+  constraintList ret = constraintList_makeNew ();
+  uentryList params = uentry_getParams (ue);
+
+  uentryList_elements (params, el)
+    {
+      DPRINTF (("setImplicitfcnConstraints doing: %s", uentry_unparse(el)));
+      
+      if (uentry_isElipsisMarker (el))
+       {
+         ;
+       }
+      else
+       {
+         sRef s = uentry_getSref (el);
+         
+         DPRINTF (("Trying: %s", sRef_unparse (s)));
+
+         if (ctype_isPointer (sRef_getType (s)))
+           {
+             constraint c = constraint_makeSRefWriteSafeInt (s, 0);
+             ret = constraintList_add (ret, c);
+             
+             /*drl 10/23/2002 added support for out*/
+             
+             if (!uentry_isOut(el))
+               {
+                 c = constraint_makeSRefReadSafeInt (s, 0);
+                 ret = constraintList_add (ret , c);
+               }
+           }
+         else
+           {
+             DPRINTF (("%s is NOT a pointer", sRef_unparseFull (s)));
+           }
+       }
+    } end_uentryList_elements;
+
+  DPRINTF (("Returns ==> %s", constraintList_unparse (ret)));
+  return ret;
+}
 
This page took 0.239314 seconds and 4 git commands to generate.