]> andersk Git - splint.git/blobdiff - src/context.c
*** empty log message ***
[splint.git] / src / context.c
index 2aba4716fd3aac40cbdefa80972d38b1343d2f63..021aeb89d60f0215f1a41c0a8558bd5d0ceabb3b 100644 (file)
@@ -61,9 +61,10 @@ typedef enum {
   CX_ERROR,
 
   CX_GLOBAL, CX_INNER, 
-  CX_FUNCTION, CX_FCNHEADER, CX_FCNDECLARATION,
+  CX_FUNCTION, CX_FCNDECLARATION,
   CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO, 
-  CX_ITERDEF, CX_ITEREND,
+  CX_ITERDEF, CX_ITEREND, 
+  CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
   CX_LCL, CX_LCLLIB, CX_MT
 } kcontext;
 
@@ -94,6 +95,7 @@ static struct
   bool savedFlags  BOOLBITS;
   bool justpopped  BOOLBITS;
   bool anyExports BOOLBITS;
+  bool inFunctionHeader BOOLBITS;
 
   flagcode library;
 
@@ -133,7 +135,6 @@ static struct
   /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
   
   kcontext kind;
-  kcontext savekind;
 
   ctype boolType;
 
@@ -150,12 +151,15 @@ static struct
 
   metaStateTable stateTable; /* User-defined state information. */
   annotationTable annotTable; /* User-defined annotations table. */
-  union 
+  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) ;
@@ -167,7 +171,7 @@ 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@*/ ;
-/*drl fix*/ static  void context_setFlag (flagcode p_f, bool p_b)
+static void context_setFlag (flagcode p_f, bool p_b)
   /*@modifies gc.flags@*/ ;
 
 static void
@@ -200,6 +204,11 @@ 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));
@@ -323,14 +332,18 @@ 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)));
+             || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
     }
   else
     {
@@ -689,7 +702,7 @@ conext_resetAllCounters (void)
 }
 
 void
-context_resetAllFlags (void)
+context_resetAllFlags (void) 
 {
   allFlagCodes (code)
     {
@@ -819,6 +832,7 @@ context_resetAllFlags (void)
   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;
@@ -964,11 +978,12 @@ context_setMode (cstring s)
          FLG_CHECKEDGLOBALIAS,
          FLG_CHECKMODGLOBALIAS,
          FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
+         FLG_UNSIGNEDCOMPARE,
          FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED, 
          FLG_TYPEUNUSED,
          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_MISPLACEDSHAREQUAL,
          FLG_MATCHFIELDS,
@@ -1044,6 +1059,7 @@ context_setMode (cstring s)
           FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
          FLG_RETVALOTHER,
          FLG_IFEMPTY, 
+         FLG_BUFFEROVERFLOWHIGH,
          FLG_RETSTACK, FLG_PTRNEGATE,
          FLG_STATETRANSFER, FLG_STATEMERGE,
          FLG_LONGUNSIGNEDINTEGRAL,
@@ -1069,8 +1085,8 @@ context_setMode (cstring s)
          FLG_UNCHECKEDGLOBALIAS,
          FLG_FORMATCONST,
           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,
@@ -1099,6 +1115,10 @@ context_setMode (cstring s)
 
          FLG_NESTEDEXTERN, 
 
+         /* warn use flags */
+         FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
+         FLG_BUFFEROVERFLOWHIGH,
+
          /* memchecks flags */
 
          FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
@@ -1179,8 +1199,8 @@ context_setMode (cstring s)
          FLG_VARUNUSED, 
          FLG_NULLPOINTERARITH, FLG_POINTERARITH, 
          FLG_PTRNUMCOMPARE, 
-         FLG_BOOLCOMPARE, FLG_NOEFFECT, 
-         FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER, 
+         FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
+         FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER, 
          FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
          FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF, 
          FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS, 
@@ -1202,6 +1222,11 @@ 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,
@@ -1285,7 +1310,7 @@ context_isSystemDir (cstring dir)
 {
   cstring sysDirs = context_exposeString (FLG_SYSTEMDIRS);
   char *thisdir = cstring_toCharsSafe (sysDirs);
-  char *nextdir = strchr (thisdir, SEPCHAR);
+  char *nextdir = strchr (thisdir, PATH_SEPARATOR);
 
   if (nextdir != NULL)
     {
@@ -1301,7 +1326,7 @@ context_isSystemDir (cstring dir)
        {
          if (nextdir != NULL)
            {
-             *(nextdir - 1) = SEPCHAR;
+             *(nextdir - 1) = PATH_SEPARATOR;
            }
          
          return TRUE;
@@ -1309,13 +1334,13 @@ context_isSystemDir (cstring dir)
 
       if (nextdir != NULL)
        {
-         *(nextdir - 1) = SEPCHAR;
+         *(nextdir - 1) = PATH_SEPARATOR;
        }
 
       if (nextdir != NULL)
        {
          thisdir = nextdir;
-         nextdir = strchr (thisdir, SEPCHAR);
+         nextdir = strchr (thisdir, PATH_SEPARATOR);
          
          if (nextdir != NULL)
            {
@@ -1366,39 +1391,74 @@ context_removeFileAccessType (typeId t)
 
 void context_enterFunctionHeader (void)
 {
-  llassert (gc.kind == CX_GLOBAL);
-  DPRINTF (("Enter function decl"));
-  gc.kind = CX_FCNHEADER;
+  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)
 {
-  DPRINTF (("Exit function decl"));
-  gc.kind = CX_GLOBAL;
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Exit function header: %q", context_unparse ()));
+    }
+
+  DPRINTF (("Exit function header!"));
+  gc.inFunctionHeader = FALSE;
 }
 
 bool context_inFunctionHeader (void)
 {
-  return (gc.kind == CX_FCNHEADER);
+  return (gc.inFunctionHeader);
 }
 
 void context_enterFunctionDeclaration (uentry e)
 {
+  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.fcn = uentry_undefined;
+  gc.cont = gc.savecont;
+
   gc.savekind = CX_ERROR;
+
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
+    }
 }
 
 bool context_inFunctionDeclaration (void)
@@ -1740,6 +1800,61 @@ context_enterFunction (/*@exposed@*/ uentry e)
   sRef_enterFunctionScope ();
 }
 
+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));
@@ -2286,13 +2401,17 @@ context_returnFunction (void)
 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
     {
@@ -2337,6 +2456,7 @@ context_exitFunction (void)
 
   llassert (clauseStack_isEmpty (gc.clauses));
   llassert (gc.inclause == NOCLAUSE);
+  DPRINTF (("After exit function: %s", context_unparse ()));
 }
 
 void
@@ -2347,7 +2467,7 @@ context_quietExitFunction (void)
       context_exitInnerPlain ();
     }
 
-  if (!context_inFunction () && !context_inMacroConstant () && !context_inMacroUnknown () 
+  if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro () 
       && !context_inIterDef () && !context_inIterEnd ())
     {
     }
@@ -2576,21 +2696,16 @@ context_setValue (flagcode flag, int val)
       if (val <= 0)
        {
          
-         cstring warn = message ("Value for %s must be a positive "
-                                 "number (given %d)",
-                                 flagcode_unparse (flag), val);
-         
-         flagWarning (warn);
-         cstring_free (warn);
+         llerror_flagWarning (message ("Value for %s must be a positive "
+                                   "number (given %d)",
+                                   flagcode_unparse (flag), val));
          return;
        }
       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);
+         llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
+                                   flagcode_unparse (flag), 
+                                   MINLINELEN, val));
          val = MINLINELEN;
        }
       break;
@@ -2604,12 +2719,9 @@ context_setValue (flagcode flag, int val)
       if (val < 0)
        {
          
-         cstring warn = message ("Value for %s must be a non-negative "
-                                 "number (given %d)",
-                                 flagcode_unparse (flag), val);
-         
-         flagWarning (warn);
-         cstring_free (warn);
+         llerror_flagWarning (message ("Value for %s must be a non-negative "
+                                   "number (given %d)",
+                                   flagcode_unparse (flag), val));
          return;
        }
 
@@ -2697,9 +2809,7 @@ context_setString (flagcode flag, cstring val)
 
              if (cstring_getChar (tval, n) != '\"')
                {
-                 cstring msg = message ("Setting -systemdirs to string with unmatching quotes: %s", val);
-                 flagWarning (msg);
-                 cstring_free (msg);
+                 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
                }
              else
                {
@@ -2738,13 +2848,10 @@ context_setString (flagcode flag, cstring val)
   if (cstring_length (val) >= 1
       && 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)
@@ -2780,7 +2887,10 @@ 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.neednl = FALSE;
@@ -2840,12 +2950,21 @@ void context_initMod (void)
   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",
@@ -2902,7 +3021,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",
@@ -2926,6 +3047,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;
@@ -2958,6 +3082,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;
@@ -2972,7 +3101,6 @@ context_enterInnerContext (void)
       ;
     }
 
-  
   usymtab_enterScope ();
   pushClause (NOCLAUSE);
 }
@@ -2986,7 +3114,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)));
 
@@ -3017,6 +3149,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;
@@ -3032,18 +3169,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 
     {
@@ -3055,17 +3213,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)
@@ -3329,18 +3496,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;
 }
 
@@ -3370,10 +3534,10 @@ context_userSetFlag (flagcode f, bool 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;
        }
@@ -3384,10 +3548,10 @@ 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;
            }
@@ -3403,11 +3567,9 @@ 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_unparse (f));
-         flagWarning (warn);
-         cstring_free (warn);
+         llerror_flagWarning (message ("setting %s%s redundant with current value", 
+                                   cstring_makeLiteralTemp (b ? "+" : "-"),
+                                   flagcode_unparse (f)));
        }
     }
 
@@ -3415,10 +3577,8 @@ context_userSetFlag (flagcode f, bool b)
     {
       if (!context_getFlag (FLG_WARNUSE))
        {
-         cstring warn = message ("flag +%s is canceled by -warnuse",
-                                 flagcode_unparse (f));
-         flagWarning (warn);
-         cstring_free (warn);
+         llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
+                                   flagcode_unparse (f)));
          
        }
     }
@@ -3429,29 +3589,34 @@ context_userSetFlag (flagcode f, bool b)
       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_unparse (f),
-                                 flagcode_unparse (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 "
+                                   "ad hoc addition to POSIX library.  Recommend "
+                                   "use +posixlib to select POSIX library instead. "
+                                   "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);
 }
@@ -3922,14 +4087,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;
 }
 
@@ -4041,6 +4206,7 @@ bool context_anyErrors (void)
 void context_hasError (void)
 {
   gc.numerrors++;
+  DPRINTF (("num errors: %d", gc.numerrors));
 }
 
 int context_numErrors (void)
@@ -4140,7 +4306,7 @@ bool context_inMacroConstant (void)
   return (gc.kind == CX_MACROCONST);
 }
 
-bool context_inMacroUnknown (void)
+bool context_inUnknownMacro (void)
 {   
   return (gc.kind == CX_UNKNOWNMACRO);
 }
@@ -4236,6 +4402,30 @@ 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)
+    {
+      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); 
@@ -4368,18 +4558,19 @@ void context_addMetaState (cstring mname, metaStateInfo msinfo)
     }
   else
     {
+      DPRINTF (("Adding meta state: %s", mname));
       metaStateTable_insert (gc.stateTable, mname, msinfo); 
     }
 }
 
-valueTable context_createValueTable (sRef s)
+valueTable context_createValueTable (sRef s, stateInfo sinfo)
 {
   if (metaStateTable_size (gc.stateTable) > 0)
     {
       valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
       /*@i32 should use smaller value... */
       DPRINTF (("Value table for: %s", sRef_unparse (s)));
-
+      
       metaStateTable_elements (gc.stateTable, msname, msi)
        {
          mtContextNode context = metaStateInfo_getContext (msi);
@@ -4389,10 +4580,11 @@ valueTable context_createValueTable (sRef s)
              DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
              llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
              
-             valueTable_insert (res,
-                                cstring_copy (metaStateInfo_getName (msi)),
-                                stateValue_create (metaStateInfo_getDefaultValue (msi, s),
-                                                   stateInfo_undefined));
+             valueTable_insert 
+               (res,
+                cstring_copy (metaStateInfo_getName (msi)),
+                stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s), 
+                                           stateInfo_copy (sinfo)));
            }
          else
            {
@@ -4401,16 +4593,18 @@ valueTable context_createValueTable (sRef s)
        } 
       end_metaStateTable_elements ;
       
+      stateInfo_free (sinfo);
       DPRINTF (("Value table: %s", valueTable_unparse (res)));
       return res;
     }
   else
     {
+      stateInfo_free (sinfo);
       return valueTable_undefined;
     }
 }
 
-valueTable context_createGlobalMarkerValueTable ()
+valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
 {
   if (metaStateTable_size (gc.stateTable) > 0)
     {
@@ -4426,15 +4620,17 @@ valueTable context_createGlobalMarkerValueTable ()
          valueTable_insert (res,
                             cstring_copy (metaStateInfo_getName (msi)),
                             stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
-                                               stateInfo_undefined));
+                                               stateInfo_copy (sinfo)));
        } 
       end_metaStateTable_elements ;
       
+      stateInfo_free (sinfo);
       DPRINTF (("Value table: %s", valueTable_unparse (res)));
       return res;
     }
   else
     {
+      stateInfo_free (sinfo);
       return valueTable_undefined;
     }
 }
This page took 0.649915 seconds and 4 git commands to generate.