]> andersk Git - splint.git/blob - src/context.c
*** empty log message ***
[splint.git] / src / context.c
1 /*
2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 University of Virginia,
4 **         Massachusetts Institute of Technology
5 **
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
10 ** 
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ** General Public License for more details.
15 ** 
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
19 **
20 ** For information on lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
23 */
24 /*
25 ** context.c
26 */
27 /*
28  * Modified by Herbert 04/19/97:
29  * - added include for new header portab.h containing OS dependent stuff.
30  * - changed occurrances of '/' as path delimiters to macro from portab.h
31  * - changed the handling of the tmp directory -- will no longer always be
32  *   ".", if possible, environment variables "TMP" or, if not set, "TMP", 
33  *   or, if not set "." will be used.
34  */
35
36 # include "lclintMacros.nf"
37 # include "llbasic.h"
38
39 # ifndef NOLCL
40 # include "usymtab_interface.h"
41 # endif
42
43 # include "exprChecks.h"
44 # include "filelocStack.h"
45 # include "fileIdList.h"
46 # include "llmain.h"
47 # include "intSet.h"
48 # include "osd.h"
49 # include "portab.h"
50
51 extern /*@external@*/ int yydebug;
52 extern /*@external@*/ int mtdebug;
53
54 typedef struct
55
56   cstring file; 
57   typeIdSet daccess ; 
58 } maccesst;
59
60 typedef enum { 
61   CX_ERROR,
62
63   CX_GLOBAL, CX_INNER, 
64   CX_FUNCTION, CX_FCNDECLARATION,
65   CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO, 
66   CX_ITERDEF, CX_ITEREND,
67   CX_LCL, CX_LCLLIB, CX_MT
68 } kcontext;
69
70 static struct
71 {
72   int linesprocessed;
73   int speclinesprocessed;
74
75   flagMarkerList markers;
76
77   /*
78   **  used to record state where a macro must match a function name
79   **   (i.e., no params were listed in the macro definition
80   */
81
82   bool macroMissingParams BOOLBITS;
83   bool preprocessing BOOLBITS;
84   bool incommandline BOOLBITS;
85   bool insuppressregion  BOOLBITS;
86   bool inDerivedFile BOOLBITS;
87   bool instandardlib  BOOLBITS;
88   bool inimport  BOOLBITS;
89   bool inheader  BOOLBITS;
90   bool inmacrocache  BOOLBITS;
91   bool protectVars  BOOLBITS;
92   bool neednl  BOOLBITS;
93   bool showfunction  BOOLBITS;
94   bool savedFlags  BOOLBITS;
95   bool justpopped  BOOLBITS;
96   bool anyExports BOOLBITS;
97   bool inFunctionHeader BOOLBITS;
98
99   flagcode library;
100
101   ynm isNullGuarded;
102   fileloc saveloc;
103   fileloc pushloc;
104
105   clauseStack clauses; 
106   clause inclause;
107
108   int numerrors;
109
110   filelocStack locstack;
111   fileTable ftab;
112   cstring msgAnnote;
113   /*@observer@*/ sRef aliasAnnote;
114   /*@observer@*/ sRef aliasAnnoteAls;
115   messageLog  msgLog;
116
117   macrocache  mc;
118   /*@observer@*/ sRefSet mods;
119
120   /* file access types */
121   typeIdSet facct;   
122
123   /* local access types (this function) */
124   typeIdSet acct;  
125
126   /* no access types (@noaccess) */
127   typeIdSet nacct; 
128
129   /*@observer@*/ globSet globs;
130   /*@only@*/ globSet globs_used;
131   
132   int nmods;
133   int maxmods;
134   /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
135   
136   kcontext kind;
137   kcontext savekind;
138
139   ctype boolType;
140
141   bool flags[NUMFLAGS];
142   bool saveflags[NUMFLAGS];
143   bool setGlobally[NUMFLAGS];
144   bool setLocally[NUMFLAGS];
145
146   int values[NUMVALUEFLAGS];
147   int counters[NUMVALUEFLAGS];
148
149   o_cstring strings[NUMSTRINGFLAGS];
150   sRefSetList modrecs; /*@i32 ???? what is this for? */
151
152   metaStateTable stateTable; /* User-defined state information. */
153   annotationTable annotTable; /* User-defined annotations table. */
154   union 
155     {
156       bool glob;
157       int  cdepth;
158       /*@dependent@*/ /*@exposed@*/ uentry  fcn;
159     } cont;
160 } gc;
161
162 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
163 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
164 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
165 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
166    /*@modifies gc@*/ ;
167 static void context_exitClauseSimp (void)  /*@modifies gc@*/ ;
168 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
169 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
170 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
171 static void context_setFlag (flagcode p_f, bool p_b)
172   /*@modifies gc.flags@*/ ;
173
174 static void
175   context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, bool p_isRestore)
176   /*@modifies gc.flags@*/ ;
177
178 static void context_restoreFlag (flagcode p_f) /*@modifies gc.flags@*/ ;
179
180 /*@+enumindex@*/ 
181
182 cstring context_unparseFlagMarkers ()
183 {
184   return (flagMarkerList_unparse (gc.markers));
185 }
186
187 void context_setPreprocessing (void)
188 {
189   llassert (!gc.preprocessing);
190   gc.preprocessing = TRUE;
191 }
192
193 void context_clearPreprocessing (void)
194 {
195   llassert (gc.preprocessing);
196   gc.preprocessing = FALSE;
197 }
198
199 bool context_isPreprocessing (void)
200 {
201   return gc.preprocessing;
202 }
203
204 bool context_loadingLibrary (void)
205 {
206   return (fileloc_isLib (g_currentloc));
207 }
208
209 bool context_inXHFile (void)
210 {
211   return (fileloc_isXHFile (g_currentloc));
212 }
213
214 void context_setInCommandLine (void)
215 {
216   llassert (!gc.incommandline);
217   gc.incommandline = TRUE;
218 }
219
220 void context_clearInCommandLine (void)
221 {
222   llassert (gc.incommandline);
223   gc.incommandline = FALSE;
224 }
225
226 bool context_isInCommandLine (void)
227 {
228   return gc.incommandline;
229 }
230
231 static
232 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
233 {
234   gc.inclause = c;
235   clauseStack_push (gc.clauses, c);
236
237   if (clause_isConditional (c)
238       && context_getFlag (FLG_CONTROLNESTDEPTH))
239     {
240       int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
241       int depth = clauseStack_controlDepth (gc.clauses);
242       
243       if (depth == maxdepth + 1)
244         {
245           voptgenerror 
246             (FLG_CONTROLNESTDEPTH,
247              message ("Maximum control nesting depth "
248                       "(%d) exceeded",
249                       maxdepth),
250              g_currentloc);
251         }
252     }
253 }
254
255 static
256 clause topClause (clauseStack s) /*@*/
257 {
258   if (clauseStack_isEmpty (s)) return NOCLAUSE;
259   return ((clause) clauseStack_top (s));
260 }
261
262 void
263 context_addMacroCache (/*@only@*/ cstring def)
264 {
265   DPRINTF (("macro cache: %s", def));
266   macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
267 }
268
269 void
270 context_addComment (/*@only@*/ cstring def)
271 {
272   DPRINTF (("macro comment: %s", def));
273   macrocache_addComment (gc.mc, fileloc_copy (g_currentloc), def);
274 }
275
276 /*
277 ** returns TRUE is fl is in ignore region, or region where -code
278 **
279 ** the logic is fuzzy...
280 */
281
282 static bool
283 context_inSuppressFlagZone (fileloc fl, flagcode code)
284 {
285   ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
286   bool res = FALSE;
287   
288   if (ynm_isMaybe (ret))
289     {
290       /*
291       ** whas is dis?
292       */
293
294       if (gc.savedFlags)
295         {
296           res = !gc.saveflags[code];
297         }
298       else
299         {
300           res = !context_getFlag (code);
301         }
302     }
303   else
304     {
305       res = ynm_toBoolStrict (ret);
306     }
307   
308     return res;
309 }
310
311 static bool
312 context_suppressSystemMsg (fileloc fl)
313 {
314   if (context_getFlag (FLG_SYSTEMDIRERRORS))
315     {
316       return FALSE;
317     }
318   else
319     {
320       return (fileloc_isSystemFile (fl));
321     }
322 }
323
324 bool 
325 context_suppressFlagMsg (flagcode flag, fileloc fl)
326 {
327   if (context_suppressSystemMsg (fl))
328     {
329       return TRUE;
330     }
331
332   DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
333
334   /* want same object compare here */
335
336   if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
337     {
338       DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
339
340       return (!context_getFlag (flag)
341               || context_inSuppressRegion ()
342               || context_inSuppressZone (fl)
343               || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
344     }
345   else
346     {
347       return (context_inSuppressFlagZone (fl, flag));
348     }
349 }
350
351 bool 
352 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
353 {
354   
355   if (context_suppressSystemMsg (fl))
356     {
357       return TRUE;
358     }
359
360   /*@access fileloc@*/ 
361   if (fl == g_currentloc)
362     /*@noaccess fileloc@*/
363     {
364       return (context_getFlag (flag) || context_inSuppressRegion ());
365     }
366   else
367     {
368       /* for now... */
369       return (context_getFlag (flag) || context_inSuppressRegion ());
370     }
371 }
372
373 bool
374 context_inSuppressZone (fileloc fl) 
375 {
376   if (context_suppressSystemMsg (fl))
377     {
378       return TRUE;
379     }
380
381   return (flagMarkerList_inIgnore (gc.markers, fl));
382 }
383
384 bool
385 context_inSuppressRegion (void)
386 {
387   return (gc.insuppressregion);
388 }
389
390 void
391 context_enterSuppressRegion (void)
392 {
393   if (gc.insuppressregion)
394     {
395       gc.insuppressregion = FALSE;      /* get this msg! */
396       llmsg (message
397              ("%q: New ignore errors region entered while in ignore errors region",
398               fileloc_unparse (g_currentloc)));
399     }
400   
401   gc.insuppressregion = TRUE;
402   flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (g_currentloc));
403 }
404
405 static void
406 context_addFlagMarker (flagcode code, ynm set)
407 {
408   flagMarkerList_add (gc.markers,
409                       flagMarker_createLocalSet (code, set, g_currentloc));
410 }
411
412 void
413 context_enterSuppressLine (int count)
414 {
415   fileloc nextline = fileloc_copy (g_currentloc);
416
417   flagMarkerList_add (gc.markers,
418                       flagMarker_createIgnoreCount (count, g_currentloc));
419
420   fileloc_nextLine (nextline);
421   flagMarkerList_add (gc.markers,
422                       flagMarker_createIgnoreOff (nextline));
423   fileloc_free (nextline);
424 }
425
426 void context_checkSuppressCounts (void)
427 {
428   if (context_getFlag (FLG_SUPCOUNTS))
429     {
430       flagMarkerList_checkSuppressCounts (gc.markers);
431     }
432 }
433
434 void context_incLineno (void)
435 {
436   gc.linesprocessed++;
437   incLine ();
438 }
439
440 void
441 context_exitSuppressRegion (void)
442 {
443   if (!gc.insuppressregion)
444     {
445       llerrorlit (FLG_SYNTAX, 
446                   "End ignore errors in region while not ignoring errors");
447     }
448
449     gc.insuppressregion = FALSE;
450   flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (g_currentloc));
451 }
452
453 void
454 context_enterMTfile (void)
455 {
456   gc.kind = CX_MT;
457 }
458
459 void
460 context_exitMTfile (void)
461 {
462   llassert (gc.kind == CX_MT);
463   gc.kind = CX_GLOBAL;
464 }
465
466 # ifndef NOLCL
467 void
468 context_enterLCLfile (void)
469 {
470   gc.kind = CX_LCL;
471   gc.facct = typeIdSet_emptySet ();
472 }
473 # endif
474
475 static void
476 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
477 {
478   int i;
479
480   for (i = 0; i < gc.nmods; i++)
481     {
482       if (cstring_equal (gc.moduleaccess[i].file, fname))
483         {
484           gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
485           cstring_free (fname);
486           return;
487         }
488     }
489   
490   if (gc.nmods == gc.maxmods)
491     {
492       maccesst *oldmods;
493       
494       gc.maxmods = gc.maxmods + DEFAULTMAXMODS;      
495       oldmods = gc.moduleaccess;
496       
497       gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
498       
499       for (i = 0; i < gc.nmods; i++)
500         {
501           gc.moduleaccess[i] = oldmods[i];
502         }
503       
504       sfree (oldmods);
505     }
506   
507   gc.moduleaccess[gc.nmods].file = fname;
508   gc.moduleaccess[gc.nmods].daccess = mods;
509   
510   gc.nmods++;
511 }
512
513 static void
514 insertModuleAccess (cstring fname, typeId t)
515 {
516   int i;
517   
518   for (i = 0; i < gc.nmods; i++)
519     {
520       if (cstring_equal (gc.moduleaccess[i].file, fname))
521         {
522           gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
523           break;
524         }
525     }
526   
527     addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
528 }
529
530 # ifndef NOLCL
531 void
532 context_exitLCLfile (void)
533 {
534   if (gc.kind != CX_LCLLIB)
535     {
536       cstring lclname =  
537         fileLib_withoutExtension (fileName (currentFile ()), LCL_EXTENSION);
538       
539       addModuleAccess (fileLib_removePath (lclname), gc.facct);
540       cstring_free (lclname);
541     }
542   
543   gc.kind = CX_LCL;
544   gc.kind = CX_GLOBAL;
545   gc.facct = typeIdSet_emptySet ();
546 }
547 # endif
548
549 void
550 context_dumpModuleAccess (FILE *fout)
551 {
552   int i = 0;
553
554   for (i = 0; i < gc.nmods; i++)
555     {
556       cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
557
558       fprintf (fout, "%s#%s@\n", 
559                cstring_toCharsSafe (gc.moduleaccess[i].file), 
560                cstring_toCharsSafe (td));
561       
562       cstring_free (td);
563     }
564 }
565
566 bool context_usingPosixLibrary ()
567 {
568   return (gc.library == FLG_POSIXLIB 
569           || gc.library == FLG_POSIXSTRICTLIB
570           || gc.library == FLG_UNIXLIB
571           || gc.library == FLG_UNIXSTRICTLIB);
572 }
573
574 bool context_usingAnsiLibrary ()
575 {
576   return (gc.library != FLG_NOLIB);
577 }
578
579 flagcode context_getLibrary ()
580 {
581   return gc.library;
582 }
583
584 void context_setLibrary (flagcode code)
585 {
586   gc.library = code;
587 }
588
589 /*@observer@*/ cstring context_selectedLibrary ()
590 {
591   switch (gc.library)
592     {
593     case FLG_STRICTLIB:
594       return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
595     case FLG_POSIXLIB:
596       return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
597     case FLG_POSIXSTRICTLIB:
598       return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
599     case FLG_UNIXLIB:
600       return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);    
601     case FLG_UNIXSTRICTLIB:
602       return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
603     case FLG_ANSILIB:
604       return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
605     BADDEFAULT;
606     }
607 }
608   
609
610 void
611 context_loadModuleAccess (FILE *in)
612 {
613   char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
614   char *lasts = s;
615   char *name = mstring_create (MAX_NAME_LENGTH);
616   char *oname = name;
617 # ifndef NOFREE
618   char *os = s;
619 # endif
620
621   while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
622          && *s == ';')
623     {
624       ;
625     }
626
627   while (s != NULL && *s != ';' && *s != '\0')
628     {
629       name = oname;
630       
631       while (*s != '#' && *s != '\0')
632         {
633           *name++ = *s++;
634         }
635
636       *name = '\0';
637
638       if (*s != '#')
639         {
640           llcontbug (message ("context_loadModuleAccess: bad library line: %s\n", 
641                               cstring_fromChars (s)));
642           break;
643         }
644
645       s++;
646
647       addModuleAccess (cstring_copy (cstring_fromChars (oname)), 
648                        typeIdSet_undump (&s)); 
649
650       (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
651       llassert (s != lasts);
652       lasts = s;
653     }
654
655   sfree (oname);
656 # ifndef NOFREE
657   sfree (os);
658 # endif
659 }
660
661 typeIdSet context_fileAccessTypes (void)
662 {
663   return gc.facct;
664 }
665
666 void
667 context_resetModeFlags (void)
668 {
669   
670   allFlagCodes (code)
671     {
672       if (flagcode_isModeFlag (code))
673         {
674           context_setFlag (code, FALSE);
675         }
676     } end_allFlagCodes;
677
678   }
679
680 /*
681 ** resetAllFlags
682 **
683 ** Set all flags to FALSE, except for a few which are
684 ** true by default.
685 **
686 ** Set all values and strings to appropriate defaults.
687 ** Set all counters to 0.
688 */
689
690 static void
691 conext_resetAllCounters (void)
692 {
693   int i;
694
695   for (i = 0; i < NUMVALUEFLAGS; i++)
696     {
697       gc.counters[i] = 0;
698     }
699 }
700
701 void
702 context_resetAllFlags (void) 
703 {
704   allFlagCodes (code)
705     {
706       gc.flags[code] = FALSE;
707
708       if (flagcode_hasValue (code))
709         {
710           int val = 0;
711           
712           /*@-loopswitchbreak@*/
713           switch (code)
714             {
715             case FLG_LIMIT: 
716               val = DEFAULT_LIMIT; break;
717             case FLG_BUGSLIMIT:
718               val = DEFAULT_BUGSLIMIT; break;
719             case FLG_LINELEN: 
720               val = DEFAULT_LINELEN; break;
721             case FLG_INDENTSPACES: 
722               val = DEFAULT_INDENTSPACES; break;
723             case FLG_EXTERNALNAMELEN:
724               val = DEFAULT_EXTERNALNAMELEN; break;
725             case FLG_INTERNALNAMELEN:
726               val = DEFAULT_INTERNALNAMELEN; break;
727             case FLG_COMMENTCHAR: 
728               val = (int) DEFAULT_COMMENTCHAR; break;
729             case FLG_CONTROLNESTDEPTH:
730               val = (int) DEFAULT_CONTROLNESTDEPTH; break;
731             case FLG_STRINGLITERALLEN:
732               val = (int) DEFAULT_STRINGLITERALLEN; break;
733             case FLG_INCLUDENEST:
734               val = (int) DEFAULT_INCLUDENEST; break;
735             case FLG_NUMSTRUCTFIELDS:
736               val = (int) DEFAULT_NUMSTRUCTFIELDS; break;
737             case FLG_NUMENUMMEMBERS:
738               val = (int) DEFAULT_NUMENUMMEMBERS; break;
739             case FLG_EXPECT:
740             case FLG_LCLEXPECT:
741               break;
742             default:
743               llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
744             }
745           /*@=loopswitchbreak@*/          
746
747           context_setValue (code, val);
748         }
749       else if (flagcode_hasString (code))
750         {
751           cstring val = cstring_undefined;
752           
753           switch (code)
754             { /*@-loopswitchbreak@*/
755             case FLG_LARCHPATH:
756               {
757                 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
758                 
759                 if (cstring_isDefined (larchpath))
760                   {
761                     val = cstring_copy (larchpath);
762                   }
763                 else
764                   {
765                     val = cstring_makeLiteral (DEFAULT_LARCHPATH);
766                   }
767                 
768                 break;
769               }
770             case FLG_LCLIMPORTDIR:
771               {
772                 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
773                 break;
774               }
775             case FLG_TMPDIR: 
776 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
777               {
778                 char *env = osd_getEnvironmentVariable ("TMP");
779
780                 if (env == NULL)
781                   {
782                     env = osd_getEnvironmentVariable ("TEMP");
783                   }
784
785                 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
786               }
787 # else
788               val = cstring_makeLiteral (DEFAULT_TMPDIR);
789 # endif /* !defined(OS2) && !defined(MSDOS) */
790
791               break;
792             case FLG_BOOLTYPE:
793               val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
794             case FLG_BOOLFALSE:
795               val = cstring_makeLiteral ("FALSE"); break;
796             case FLG_BOOLTRUE:
797               val = cstring_makeLiteral ("TRUE"); break;
798             case FLG_MACROVARPREFIX: 
799               val = cstring_makeLiteral ("m_"); break;
800             case FLG_SYSTEMDIRS:
801               val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
802             default:
803               break;
804             } /*@=loopswitchbreak@*/
805           
806           context_setString (code, val);
807         }
808       else
809         { 
810           ; /* nothing to set */
811         }
812     } end_allFlagCodes;
813   
814   /*
815   ** These flags are true by default.
816   */
817
818   /*@i34 move this into flags.def */
819     
820   gc.flags[FLG_MODIFIES] = TRUE;
821   gc.flags[FLG_NESTCOMMENT] = TRUE;
822   gc.flags[FLG_GLOBALS] = TRUE;
823   gc.flags[FLG_FULLINITBLOCK] = TRUE;
824   gc.flags[FLG_LIKELYBOOL] = TRUE;
825   gc.flags[FLG_ZEROPTR] = TRUE;
826   gc.flags[FLG_NUMLITERAL] = TRUE;
827   gc.flags[FLG_DUPLICATEQUALS] = TRUE;
828   gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
829   gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
830   gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
831   gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
832   gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
833   gc.flags[FLG_CASTFCNPTR] = TRUE;
834   gc.flags[FLG_DOLCS] = TRUE;
835   gc.flags[FLG_USEVARARGS] = TRUE;
836   gc.flags[FLG_MAINTYPE] = TRUE;
837   gc.flags[FLG_SPECMACROS] = TRUE;
838   gc.flags[FLG_REDEF] = TRUE;
839   gc.flags[FLG_MACRONEXTLINE] = TRUE;
840
841   gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
842   gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
843
844   gc.flags[FLG_WARNUSE] = TRUE;
845   gc.flags[FLG_PREDASSIGN] = TRUE;
846   gc.flags[FLG_MODOBSERVER] = TRUE;
847   gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
848   gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
849
850   gc.flags[FLG_PARAMIMPTEMP] = TRUE;
851   gc.flags[FLG_RETIMPONLY] = TRUE;
852   gc.flags[FLG_GLOBIMPONLY] = TRUE;
853   gc.flags[FLG_STRUCTIMPONLY] = TRUE;
854   gc.flags[FLG_PREPROC] = TRUE;
855   gc.flags[FLG_NAMECHECKS] = TRUE;
856   gc.flags[FLG_FORMATCODE] = TRUE;
857   gc.flags[FLG_FORMATTYPE] = TRUE;
858   gc.flags[FLG_BADFLAG] = TRUE;
859   gc.flags[FLG_WARNFLAGS] = TRUE;
860   gc.flags[FLG_FILEEXTENSIONS] = TRUE;
861   gc.flags[FLG_WARNUNIXLIB] = TRUE;
862   gc.flags[FLG_WARNPOSIX] = TRUE;
863   gc.flags[FLG_SHOWCOL] = TRUE;
864   gc.flags[FLG_SHOWFUNC] = TRUE;
865   gc.flags[FLG_SUPCOUNTS] = TRUE;
866   gc.flags[FLG_HINTS] = TRUE;
867   gc.flags[FLG_SYNTAX] = TRUE;
868   gc.flags[FLG_TYPE] = TRUE;
869   gc.flags[FLG_INCOMPLETETYPE] = TRUE;
870   gc.flags[FLG_ABSTRACT] = TRUE;
871   gc.flags[FLG_ITER] = TRUE;
872   gc.flags[FLG_CONTROL] = TRUE;
873   gc.flags[FLG_UNRECOG] = TRUE;
874   gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
875   gc.flags[FLG_LINTCOMMENTS] = TRUE;
876   gc.flags[FLG_ACCESSCZECH] = TRUE;
877   gc.flags[FLG_ACCESSMODULE] = TRUE;
878   gc.flags[FLG_ACCESSFILE] = TRUE;
879   gc.flags[FLG_MACROVARPREFIX] = TRUE;
880
881   gc.flags[FLG_ANNOTATIONERROR] = TRUE;
882   gc.flags[FLG_COMMENTERROR] = TRUE;
883
884   /*
885   ** Changed for version 2.4.
886   */
887
888   gc.flags[FLG_GNUEXTENSIONS] = TRUE;
889
890   /*
891   ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
892   */
893
894 # ifdef WIN32
895   gc.flags[FLG_PARENFILEFORMAT] = TRUE;
896 # endif
897 }
898
899 /*
900 ** C is way-lame, and you can initialize an array to a constant except where
901 ** it is declared.  Hence, a macro is used to set the modeflags.
902 */
903
904 /*@notfunction@*/
905 # define SETFLAGS() \
906   { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
907       if (!flagcode_isModeFlag (modeflags[i])) \
908         { llbug (message ("not a mode flag: %s", \
909                           flagcode_unparse (modeflags[i]))); } \
910       else { context_setFlag (modeflags[i], TRUE); }  i++; }}
911
912 void
913 context_setMode (cstring s)
914 {
915   intSet setflags = intSet_new ();
916   
917   allFlagCodes (code)
918     {
919       if (flagcode_isModeFlag (code))
920         {
921           if (gc.setGlobally[code])
922             {
923               (void) intSet_insert (setflags, (int) code);
924             }
925         }
926     } end_allFlagCodes;
927   
928   if (!intSet_isEmpty (setflags))
929     {
930       cstring rflags = cstring_undefined;
931       int num = 0;
932
933       intSet_elements (setflags, el)
934         {
935           if (cstring_isUndefined (rflags))
936             {
937               rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
938             }
939           else
940             {
941               rflags = message ("%q, %s", rflags, 
942                                 flagcode_unparse ((flagcode) el));
943             }
944
945           num++;
946           if (num > 4 && intSet_size (setflags) > 6)
947             {
948               rflags = message ("%q, (%d others) ...", rflags, 
949                                 intSet_size (setflags) - num);
950               break;
951             }
952         } end_intSet_elements ;
953       
954       voptgenerror (FLG_WARNFLAGS,
955                     message ("Setting mode %s after setting mode flags will "
956                              "override set values of flags: %s",
957                              s, rflags),
958                     g_currentloc);
959
960       cstring_free (rflags);
961     }
962
963   intSet_free (setflags);
964
965   context_resetModeFlags ();
966
967   if (cstring_equalLit (s, "standard"))
968     {
969       flagcode modeflags[] = 
970         {
971           FLG_ENUMINT, FLG_MACROMATCHNAME,
972           FLG_MACROUNDEF, FLG_RELAXQUALS, 
973           FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
974           FLG_CHECKSTRICTGLOBALIAS,
975           FLG_CHECKEDGLOBALIAS,
976           FLG_CHECKMODGLOBALIAS,
977           FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
978           FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED, 
979           FLG_TYPEUNUSED,
980           FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
981           FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_MUTREP, 
982           FLG_NOEFFECT, FLG_IMPTYPE,
983           FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
984           FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
985           FLG_MATCHFIELDS,
986           FLG_FORMATCONST,
987           FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS, 
988           FLG_MACROSTMT, FLG_MACROPARENS, 
989           FLG_MACROFCNDECL,
990           FLG_MACROCONSTDECL,
991           FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE, 
992           FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF, 
993           FLG_FIRSTCASE,
994           FLG_NESTEDEXTERN, 
995           FLG_NUMLITERAL,
996           FLG_ZEROBOOL,
997           /* memchecks flags */
998           FLG_NULLDEREF, 
999           FLG_NULLSTATE, FLG_NULLASSIGN,
1000           FLG_NULLPASS, FLG_NULLRET,        
1001
1002           FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1003           FLG_RETSTACK,
1004
1005           /* memtrans flags */
1006           FLG_EXPOSETRANS,
1007           FLG_OBSERVERTRANS,
1008           FLG_DEPENDENTTRANS,
1009           FLG_NEWREFTRANS,
1010           FLG_ONLYTRANS,
1011           FLG_OWNEDTRANS,
1012           FLG_FRESHTRANS,
1013           FLG_SHAREDTRANS,
1014           FLG_TEMPTRANS,
1015           FLG_KEPTTRANS,
1016           FLG_REFCOUNTTRANS,
1017           FLG_STATICTRANS,
1018           FLG_UNKNOWNTRANS,
1019           FLG_KEEPTRANS,
1020           FLG_IMMEDIATETRANS,
1021
1022           FLG_EXPORTLOCAL,
1023
1024           FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1025           FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE, 
1026           FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1027           FLG_MEMIMPLICIT,
1028           FLG_BRANCHSTATE, 
1029           FLG_STATETRANSFER, FLG_STATEMERGE,
1030           FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1031           FLG_EXITARG,
1032           FLG_IMPCHECKEDSPECGLOBALS,
1033           FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1034           FLG_IFEMPTY, FLG_REALCOMPARE,
1035           FLG_BOOLOPS, FLG_PTRNEGATE,
1036           FLG_SHIFTSIGNED,
1037           FLG_BUFFEROVERFLOWHIGH,
1038           FLG_BUFFEROVERFLOW,
1039           INVALID_FLAG 
1040         } ;
1041
1042       SETFLAGS ();
1043     }
1044   else if (cstring_equalLit (s, "weak"))
1045     {
1046       flagcode modeflags[] = 
1047         { 
1048           FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1049           FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL, 
1050           FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS, 
1051           FLG_CHARUNSIGNEDCHAR,
1052           FLG_PREDBOOLOTHERS, 
1053           FLG_VARUNUSED, FLG_FUNCUNUSED, 
1054           FLG_TYPEUNUSED,
1055           FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1056           FLG_RETVALOTHER,
1057           FLG_IFEMPTY, 
1058           FLG_RETSTACK, FLG_PTRNEGATE,
1059           FLG_STATETRANSFER, FLG_STATEMERGE,
1060           FLG_LONGUNSIGNEDINTEGRAL,
1061           FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1062           FLG_NUMLITERAL,
1063           FLG_CHARINTLITERAL,
1064           FLG_ZEROBOOL,
1065           FLG_BUFFEROVERFLOWHIGH,
1066           INVALID_FLAG 
1067           } ;
1068
1069       SETFLAGS ();
1070     }
1071   else if (cstring_equalLit (s, "checks"))
1072     {
1073       flagcode modeflags[] = 
1074         { 
1075           FLG_EXPORTLOCAL, FLG_IMPTYPE,
1076           FLG_STATETRANSFER, FLG_STATEMERGE,
1077           FLG_CHECKSTRICTGLOBALIAS,
1078           FLG_CHECKEDGLOBALIAS,
1079           FLG_CHECKMODGLOBALIAS,
1080           FLG_UNCHECKEDGLOBALIAS,
1081           FLG_FORMATCONST,
1082           FLG_EXITARG, FLG_PTRNUMCOMPARE, 
1083           FLG_BOOLCOMPARE, FLG_MACROUNDEF, 
1084           FLG_MUSTMOD, FLG_ALLGLOBALS,
1085           FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1086           FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS, 
1087           FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1088           FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1089           FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1090           FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1091           FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1092           FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1093           FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1094           FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, 
1095           FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1096           FLG_MATCHFIELDS, 
1097           FLG_MACROPARAMS,
1098           FLG_MACROASSIGN,
1099           FLG_DECLPARAMMATCH,
1100           FLG_FCNDEREF,
1101           FLG_FIRSTCASE,
1102           FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS, 
1103           FLG_MACROCONSTDECL,
1104           FLG_MACROFCNDECL,
1105           FLG_MACROREDEF, 
1106           FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1107           FLG_UNREACHABLE, 
1108           FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1109           FLG_EVALORDER, FLG_USEDEF, 
1110
1111           FLG_NESTEDEXTERN, 
1112
1113           /* memchecks flags */
1114
1115           FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1116           FLG_NULLPASS, FLG_NULLRET,
1117
1118           FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,       
1119
1120           /* memtrans flags */
1121           FLG_EXPOSETRANS,
1122           FLG_OBSERVERTRANS,
1123           FLG_DEPENDENTTRANS,
1124           FLG_NEWREFTRANS,
1125           FLG_ONLYTRANS,
1126           FLG_OWNEDTRANS,
1127           FLG_FRESHTRANS,
1128           FLG_SHAREDTRANS,
1129           FLG_TEMPTRANS,
1130           FLG_KEPTTRANS,
1131           FLG_REFCOUNTTRANS,
1132           FLG_STATICTRANS,
1133           FLG_UNKNOWNTRANS,
1134           FLG_STATICINITTRANS,
1135           FLG_UNKNOWNINITTRANS,
1136           FLG_KEEPTRANS,
1137           FLG_IMMEDIATETRANS,
1138           FLG_ONLYUNQGLOBALTRANS,
1139           FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1140           FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE, 
1141           FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1142           FLG_MEMIMPLICIT,
1143           FLG_BRANCHSTATE, 
1144           FLG_NULLPOINTERARITH,
1145           FLG_SHADOW, FLG_DEPARRAYS,
1146           FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1147           FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1148           FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1149           FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1150           FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES, 
1151           FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1152           FLG_BOOLOPS, FLG_SHIFTSIGNED,
1153           FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1154           INVALID_FLAG } ;
1155
1156       SETFLAGS ();
1157     }
1158   else if (cstring_equalLit (s, "strict"))
1159     {
1160       flagcode modeflags[] = 
1161         { 
1162           FLG_CHECKSTRICTGLOBALIAS,
1163           FLG_CHECKEDGLOBALIAS,
1164           FLG_CHECKMODGLOBALIAS,
1165           FLG_UNCHECKEDGLOBALIAS,
1166           FLG_MODFILESYSTEM,
1167           FLG_MACROMATCHNAME,
1168           FLG_FORMATCONST,
1169           FLG_STATETRANSFER, FLG_STATEMERGE,
1170           FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1171           FLG_ALLGLOBALS, FLG_IMPTYPE,
1172           FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1173           FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1174           FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1175           FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG, 
1176           FLG_RETSTACK,
1177           FLG_FCNDEREF,
1178           FLG_ONLYUNQGLOBALTRANS,
1179           FLG_GLOBALSIMPMODIFIESNOTHING,
1180           FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1181           FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1182           FLG_USEALLGLOBS, FLG_RETALIAS, 
1183           FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1184           FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1185           FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1186           FLG_FUNCUNUSED,
1187           FLG_EXPORTITER, FLG_EXPORTCONST,
1188           FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1189           FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1190           FLG_VARUNUSED, 
1191           FLG_NULLPOINTERARITH, FLG_POINTERARITH, 
1192           FLG_PTRNUMCOMPARE, 
1193           FLG_BOOLCOMPARE, FLG_NOEFFECT, 
1194           FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER, 
1195           FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1196           FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF, 
1197           FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS, 
1198           FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1199           FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR, 
1200           FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS, 
1201           FLG_MACROASSIGN,
1202           FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS, 
1203           FLG_MACROFCNDECL,
1204           FLG_MACROCONSTDECL,
1205           FLG_MACROREDEF, FLG_MACROEMPTY,
1206           FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1207           FLG_UNREACHABLE, 
1208           FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1209           FLG_EVALORDER,
1210           FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1211           FLG_MODOBSERVERUNCON,
1212
1213           FLG_NESTEDEXTERN, 
1214           FLG_FIRSTCASE,
1215
1216           /* memchecks flags */
1217           FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1218           FLG_NULLPASS, FLG_NULLRET,
1219
1220           FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1221
1222           /* memtrans flags */
1223           FLG_EXPOSETRANS,
1224           FLG_OBSERVERTRANS,
1225           FLG_DEPENDENTTRANS,
1226           FLG_NEWREFTRANS,
1227           FLG_ONLYTRANS,
1228           FLG_OWNEDTRANS,
1229           FLG_FRESHTRANS,
1230           FLG_SHAREDTRANS,
1231           FLG_TEMPTRANS,
1232           FLG_KEPTTRANS,
1233           FLG_REFCOUNTTRANS,
1234           FLG_STATICTRANS,
1235           FLG_UNKNOWNTRANS,
1236           FLG_KEEPTRANS,
1237           FLG_IMMEDIATETRANS,
1238           FLG_STATICINITTRANS,
1239           FLG_UNKNOWNINITTRANS,
1240
1241           FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1242           FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE, 
1243           FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1244           FLG_MEMIMPLICIT,
1245           FLG_BRANCHSTATE, 
1246
1247           FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1248
1249           FLG_SHADOW, FLG_DEPARRAYS, 
1250           FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1251           FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1252           FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1253           FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1254           FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1255           FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1256           FLG_IMPCHECKEDSTRICTSTATICS,
1257           FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1258           FLG_IMPCHECKMODINTERNALS,
1259           FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1260           FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1261           FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1262           FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1263           FLG_CONTROLNESTDEPTH,
1264           FLG_FORBLOCK, FLG_WHILEBLOCK,
1265           FLG_FOREMPTY, FLG_WHILEEMPTY,
1266           FLG_IFEMPTY, FLG_IFBLOCK,
1267           FLG_ELSEIFCOMPLETE,
1268           FLG_REALCOMPARE, FLG_BOOLOPS,
1269           FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1270
1271           FLG_SHIFTSIGNED, FLG_BITWISEOPS,
1272           FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1273           INVALID_FLAG
1274         } ;
1275
1276       SETFLAGS ();
1277     }
1278   else
1279     {
1280       llcontbug (message ("context_setMode: bad mode: %s", s));
1281      }
1282 }
1283
1284 bool
1285 context_isSpecialFile (cstring fname)
1286 {
1287   cstring ext = fileLib_getExtension (fname);
1288   
1289   return (cstring_equalLit (ext, ".y") 
1290           || cstring_equalLit (ext, ".l")
1291           || cstring_equalLit (fname, "lex.yy.c"));
1292 }
1293
1294 bool
1295 context_isSystemDir (cstring dir)
1296 {
1297   cstring sysDirs = context_exposeString (FLG_SYSTEMDIRS);
1298   char *thisdir = cstring_toCharsSafe (sysDirs);
1299   char *nextdir = strchr (thisdir, PATH_SEPARATOR);
1300
1301   if (nextdir != NULL)
1302     {
1303       *nextdir = '\0';
1304       nextdir += 1;
1305     }
1306
1307   while (thisdir != NULL)
1308     {
1309       DPRINTF (("Test: %s / %s", dir, thisdir));
1310
1311       if (cstring_equalCanonicalPrefix (dir, thisdir))
1312         {
1313           if (nextdir != NULL)
1314             {
1315               *(nextdir - 1) = PATH_SEPARATOR;
1316             }
1317           
1318           return TRUE;
1319         }
1320
1321       if (nextdir != NULL)
1322         {
1323           *(nextdir - 1) = PATH_SEPARATOR;
1324         }
1325
1326       if (nextdir != NULL)
1327         {
1328           thisdir = nextdir;
1329           nextdir = strchr (thisdir, PATH_SEPARATOR);
1330           
1331           if (nextdir != NULL)
1332             {
1333               *nextdir = '\0';
1334               nextdir += 1;
1335             } 
1336         }
1337       else
1338         {
1339           break;
1340         }
1341     } 
1342
1343   DPRINTF (("Returns FALSE"));
1344   return FALSE;
1345 }
1346
1347 void
1348 context_addFileAccessType (typeId t)
1349 {
1350   cstring base;
1351
1352   if (context_inFunctionLike ())
1353     {
1354       gc.acct = typeIdSet_insert (gc.acct, t);
1355     }
1356   
1357   gc.facct = typeIdSet_insert (gc.facct, t);
1358   
1359   base = fileloc_getBase (g_currentloc);
1360   insertModuleAccess (base, t);
1361   DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1362             typeIdSet_unparse (gc.acct)));
1363 }
1364
1365 void
1366 context_removeFileAccessType (typeId t)
1367 {
1368   if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN 
1369       || gc.kind == CX_UNKNOWNMACRO)
1370     {
1371       gc.acct = typeIdSet_removeFresh (gc.acct, t);
1372     }
1373   
1374   gc.facct = typeIdSet_removeFresh (gc.facct, t);
1375   gc.nacct = typeIdSet_insert (gc.nacct, t);
1376 }
1377
1378 void context_enterFunctionHeader (void)
1379 {
1380   if (gc.kind != CX_GLOBAL)
1381     {
1382       llparseerror (cstring_makeLiteral
1383                     ("Likely parse error.  Function header outside global context."));
1384     }
1385   else
1386     {
1387       llassert (gc.kind == CX_GLOBAL);
1388       DPRINTF (("Enter function header!"));
1389       gc.inFunctionHeader = TRUE;
1390     }
1391 }
1392
1393 void context_exitFunctionHeader (void)
1394 {
1395   DPRINTF (("Exit function header!"));
1396   gc.inFunctionHeader = FALSE;
1397 }
1398
1399 bool context_inFunctionHeader (void)
1400 {
1401   return (gc.inFunctionHeader);
1402 }
1403
1404 void context_enterFunctionDeclaration (uentry e)
1405 {
1406   DPRINTF (("Enter function decl"));
1407   llassert (gc.savekind == CX_ERROR);
1408   gc.savekind = gc.kind;
1409   gc.kind = CX_FCNDECLARATION;
1410   gc.cont.fcn = e;
1411 }
1412
1413 void context_exitFunctionDeclaration (void)
1414 {
1415   DPRINTF (("Exit function decl"));
1416   llassert (gc.savekind != CX_ERROR);
1417   llassert (gc.kind == CX_FCNDECLARATION);
1418   gc.kind = gc.savekind;
1419   gc.cont.fcn = uentry_undefined;
1420   gc.savekind = CX_ERROR;
1421 }
1422
1423 bool context_inFunctionDeclaration (void)
1424 {
1425   return (gc.kind == CX_FCNDECLARATION);
1426 }
1427
1428
1429 void
1430 context_enterMacro (/*@observer@*/ uentry e)
1431 {
1432   context_enterFunction (e);
1433   gc.kind = CX_MACROFCN;
1434 }
1435
1436 void
1437 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1438 {
1439   llassert (uentry_isFunction (e));
1440   context_enterFunction (e);
1441   gc.kind = CX_UNKNOWNMACRO;
1442 }
1443
1444 void context_enterAndClause (exprNode e)
1445 {
1446   
1447   usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1448   pushClause (ANDCLAUSE);
1449 }
1450
1451 void context_enterOrClause (exprNode e)
1452 {
1453   usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1454   pushClause (ORCLAUSE);
1455 }
1456
1457 bool context_inDeepLoop (void)
1458 {
1459   bool inLoop = FALSE;
1460
1461   clauseStack_elements (gc.clauses, el)
1462     {
1463       if (clause_isLoop (el))
1464         {
1465           if (inLoop)
1466             {
1467               return TRUE;
1468             }
1469
1470           inLoop = TRUE;
1471         }
1472     } end_clauseStack_elements;
1473
1474   return FALSE;
1475 }
1476
1477 bool context_inDeepSwitch (void)
1478 {
1479   bool inLoop = FALSE;
1480
1481   clauseStack_elements (gc.clauses, el)
1482     {
1483       if (clause_isSwitch (el))
1484         {
1485           if (inLoop)
1486             {
1487               return TRUE;
1488             }
1489
1490           inLoop = TRUE;
1491         }
1492     } end_clauseStack_elements;
1493
1494   return FALSE;
1495 }
1496
1497 bool context_inDeepLoopSwitch (void)
1498 {
1499   bool inLoop = FALSE;
1500
1501   clauseStack_elements (gc.clauses, el)
1502     {
1503       if (clause_isBreakable (el))
1504         {
1505           if (inLoop)
1506             {
1507               return TRUE;
1508             }
1509
1510           inLoop = TRUE;
1511         }
1512     } end_clauseStack_elements;
1513
1514   return FALSE;
1515 }
1516
1517 clause context_breakClause (void)
1518 {
1519   clauseStack_elements (gc.clauses, el)
1520     {
1521       if (clause_isSwitch (el))
1522         {
1523           return el;
1524         }
1525       else if (clause_isLoop (el))
1526         {
1527           return el;
1528         }
1529       else
1530         {
1531           ;
1532         }
1533     } end_clauseStack_elements;
1534
1535   return NOCLAUSE;
1536 }
1537
1538 clause context_nextBreakClause (void)
1539 {
1540   bool hasOne = FALSE;
1541
1542   clauseStack_elements (gc.clauses, el)
1543     {
1544       if (clause_isBreakable (el))
1545         {
1546           if (hasOne)
1547             {
1548               return el;
1549             }
1550           else
1551             {
1552               hasOne = TRUE;
1553             }
1554         }
1555     } end_clauseStack_elements;
1556
1557   return NOCLAUSE;
1558 }
1559   
1560 bool context_inConditional (void)
1561 {
1562   clauseStack_elements (gc.clauses, el)
1563     {
1564       /*
1565       ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1566       ** to distinguish if from ? for this
1567       */
1568
1569       if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1570         {
1571           return TRUE;
1572         }
1573     } end_clauseStack_elements;
1574
1575   return FALSE;
1576 }
1577
1578 void context_exitAndClause (exprNode pred, exprNode tbranch)
1579 {
1580   context_setJustPopped ();
1581   
1582   llassert (gc.inclause == ANDCLAUSE);
1583   
1584   usymtab_popAndBranch (pred, tbranch);
1585   clauseStack_pop (gc.clauses);
1586   gc.inclause = topClause (gc.clauses);
1587 }
1588
1589 void context_exitOrClause (exprNode pred, exprNode tbranch)
1590 {
1591   context_setJustPopped ();
1592   
1593   llassert (gc.inclause == ORCLAUSE);
1594   
1595   usymtab_popOrBranch (pred, tbranch);
1596   clauseStack_pop (gc.clauses);
1597   gc.inclause = topClause (gc.clauses);
1598 }
1599
1600 static void context_enterCondClauseAux (clause cl)
1601      /*@modifies gc@*/
1602 {
1603   pushClause (cl);
1604 }
1605
1606 static void context_enterTrueAux (exprNode e, clause cl)
1607    /*@modifies gc@*/
1608 {
1609   usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1610   pushClause (cl);
1611 }
1612
1613 void context_enterIterClause (void)
1614 {
1615   context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1616 }
1617
1618 void context_enterDoWhileClause (void)
1619 {
1620   pushClause (DOWHILECLAUSE);
1621 }
1622
1623 void context_enterWhileClause (exprNode e)
1624 {
1625   context_enterTrueAux (e, WHILECLAUSE);
1626 }
1627
1628 void context_enterForClause (exprNode e)
1629 {
1630   context_enterTrueAux (e, FORCLAUSE);
1631 }
1632
1633 void context_enterTrueClause (exprNode e)
1634 {
1635   context_enterTrueAux (e, TRUECLAUSE);
1636 }
1637
1638 void context_enterSwitch (exprNode e)
1639 {
1640   
1641   usymtab_switchBranch (e);
1642   context_enterCondClauseAux (SWITCHCLAUSE);
1643 }
1644
1645 void context_exitSwitch (exprNode e, bool allpaths)
1646 {
1647     usymtab_exitSwitch (e, allpaths);
1648   
1649   while (clause_isCase (clauseStack_top (gc.clauses)))
1650     {
1651       clauseStack_pop (gc.clauses);
1652     }
1653   
1654   context_exitClauseSimp ();
1655 }
1656
1657 void context_enterCaseClause (exprNode e)
1658 {
1659   bool branch = FALSE;
1660  
1661   DPRINTF (("Enter case clause!"));
1662
1663   branch = usymtab_newCase (exprNode_undefined, e);
1664   
1665   if (branch)
1666     {
1667       context_enterCondClauseAux (CASECLAUSE);
1668     }
1669 }
1670
1671 static void context_enterFalseClauseAux (exprNode e, clause cl)
1672      /*@modifies gc@*/
1673 {
1674   usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1675   gc.inclause = cl;
1676   clauseStack_switchTop (gc.clauses, cl);
1677 }
1678
1679 void context_enterFalseClause (exprNode e)
1680 {
1681   
1682   context_enterFalseClauseAux (e, FALSECLAUSE);
1683 }
1684
1685 void
1686 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1687 {
1688   gc.kind = CX_MACROCONST;
1689   gc.cont.fcn = e;
1690   gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1691
1692   gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)), 
1693                                 gc.nacct);
1694
1695   
1696   usymtab_enterScope ();
1697   sRef_enterFunctionScope ();
1698
1699   gc.globs = globSet_undefined;
1700   globSet_clear (gc.globs_used);
1701   gc.mods = sRefSet_undefined;
1702 }
1703
1704 uentry context_getHeader (void)
1705 {
1706   if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1707     {
1708       llfatalbug (message ("context_getHeader: bad call: %q",
1709                            context_unparse ()));
1710     }
1711
1712   return (gc.cont.fcn);
1713 }
1714
1715 void
1716 context_setFunctionDefined (fileloc loc)
1717 {
1718   switch (gc.kind)
1719     {
1720     case CX_UNKNOWNMACRO:
1721     case CX_FUNCTION:
1722     case CX_MACROFCN:
1723       uentry_setFunctionDefined (gc.cont.fcn, loc);
1724       break;
1725     default:
1726       /* (not a bug because of parse errors) */
1727       break;
1728     }
1729 }
1730
1731 void
1732 context_enterFunction (/*@exposed@*/ uentry e)
1733 {
1734   gc.kind = CX_FUNCTION;
1735   gc.cont.fcn = e;
1736
1737   DPRINTF (("Enter function: %s", uentry_unparse (e)));
1738
1739   if (uentry_hasAccessType (e))
1740     {
1741       gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)), 
1742                                     gc.nacct);
1743     }
1744   else
1745     {
1746       gc.acct = gc.facct;
1747     }
1748
1749   DPRINTF (("Enter function: %s / %s", uentry_unparse (e), 
1750             typeIdSet_unparse (gc.acct)));
1751
1752   gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1753   
1754   gc.globs = uentry_getGlobs (e);
1755   globSet_clear (gc.globs_used);
1756   gc.mods = uentry_getMods (e);
1757
1758   usymtab_enterFunctionScope (e);
1759   sRef_enterFunctionScope ();
1760 }
1761
1762 static bool context_checkStrictGlobals (void)
1763 {
1764   return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1765 }
1766
1767 static bool context_hasGlobs (void)
1768 {
1769   if (context_inFunctionLike ())
1770     {
1771       return (uentry_hasGlobs (gc.cont.fcn));
1772     }
1773   else
1774     {
1775       return (FALSE);
1776     }
1777 }
1778
1779 static bool context_checkCheckedGlobals (void)
1780 {
1781   return (context_getFlag (FLG_GLOBALS)
1782           && (context_getFlag (FLG_GLOBUNSPEC)
1783               || context_hasGlobs ()));
1784 }
1785
1786 static bool context_checkUnknownGlobals (void)
1787 {
1788   /* should be uentry_hasGlobs ? */
1789
1790   return (context_getFlag (FLG_ALLGLOBALS)
1791           && (context_getFlag (FLG_GLOBUNSPEC)
1792               || context_hasGlobs ()));
1793 }      
1794
1795 static bool context_checkUncheckedGlobals (void)
1796 {
1797   return (FALSE);
1798 }      
1799
1800 bool 
1801 context_checkExport (uentry e)
1802 {
1803   if (!gc.anyExports) return FALSE;
1804
1805   if (uentry_isFunction (e)
1806       || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1807     {
1808       return context_maybeSet (FLG_EXPORTFCN);
1809     }
1810   else if (uentry_isExpandedMacro (e))
1811     {
1812       return context_maybeSet (FLG_EXPORTMACRO);
1813     }
1814   else if (uentry_isVariable (e))
1815     {
1816       return context_maybeSet (FLG_EXPORTVAR);
1817     }
1818   else if (uentry_isEitherConstant (e))
1819     {
1820       return context_maybeSet (FLG_EXPORTCONST);
1821     }
1822   else if (uentry_isIter (e) || uentry_isEndIter (e))
1823     {
1824       return context_maybeSet (FLG_EXPORTITER);
1825     }
1826   else if (uentry_isDatatype (e))
1827     {
1828       return context_maybeSet (FLG_EXPORTTYPE);
1829     }
1830   else
1831     {
1832       BADEXIT;
1833     }
1834 }
1835               
1836 bool
1837 context_checkGlobUse (uentry glob)
1838 {
1839   
1840   if (uentry_isCheckedStrict (glob))
1841     {
1842       return context_checkStrictGlobals ();
1843     }
1844   else if (uentry_isChecked (glob))
1845     {
1846       return context_checkCheckedGlobals ();
1847     }
1848   else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
1849     {
1850       return context_checkUnknownGlobals ();
1851     }
1852   else 
1853     {
1854       llassert (uentry_isUnchecked (glob));
1855
1856       return context_checkUncheckedGlobals ();
1857     }
1858 }
1859
1860 bool
1861 context_checkAliasGlob (uentry glob)
1862 {
1863   if (uentry_isCheckedStrict (glob))
1864     {
1865       return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
1866     }
1867   else if (uentry_isChecked (glob))
1868     {
1869       return gc.flags[FLG_CHECKEDGLOBALIAS];
1870     }
1871   else if (uentry_isCheckMod (glob))
1872     {
1873       return gc.flags[FLG_CHECKMODGLOBALIAS];
1874     }
1875   else 
1876     {
1877       llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
1878
1879       return gc.flags[FLG_UNCHECKEDGLOBALIAS];
1880     }
1881 }
1882
1883 bool context_checkInternalUse (void)
1884 {
1885   if (context_hasGlobs ())
1886     {
1887       return (gc.flags[FLG_INTERNALGLOBS]);
1888     }
1889   else
1890     {
1891       return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
1892     }
1893 }
1894
1895 bool
1896 context_checkGlobMod (sRef el)
1897 {
1898   uentry ue = sRef_getUentry (el);
1899
1900   /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
1901
1902   if (uentry_isCheckedModify (ue)
1903       || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
1904     {
1905       if (context_hasMods ())
1906         {
1907           return (gc.flags[FLG_MODGLOBS]);
1908         }
1909       else
1910         {
1911           if (uentry_isCheckedStrict (ue))
1912             {
1913               return (gc.flags[FLG_MODGLOBSUNSPEC]);
1914             }
1915           else
1916             {
1917               return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
1918             }
1919         }
1920     }
1921   else
1922     {
1923       if (context_hasMods ())
1924         {
1925           return (gc.flags[FLG_MODGLOBSUNCHECKED]);
1926         }
1927       else
1928         {
1929           return FALSE;
1930         }
1931     }
1932 }
1933
1934 void
1935 context_usedGlobal (/*@exposed@*/ sRef el)
1936 {
1937   if (!globSet_member (gc.globs_used, el))
1938     {
1939       /* 
1940       ** The first time a global is used in a function, we need
1941       ** to clear the derived sRefs, since they were set for the
1942       ** previous function.
1943       */
1944
1945       sRef_clearDerived (el);
1946       gc.globs_used = globSet_insert (gc.globs_used, el);
1947     }
1948 }
1949
1950 /*@observer@*/ sRefSet
1951 context_modList (void)
1952 {
1953   return gc.mods;
1954 }
1955
1956 bool
1957 context_globAccess (sRef s)
1958 {
1959   llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
1960   return (globSet_member (gc.globs, s));
1961 }
1962
1963 bool
1964 context_hasAccess (typeId t)
1965 {
1966   if (context_inFunctionLike ())
1967     {
1968       DPRINTF (("Access %d / %s",
1969                 t, typeIdSet_unparse (gc.acct)));
1970       return (typeIdSet_member (gc.acct, t));
1971     }
1972   else
1973     {
1974       return (context_hasFileAccess (t));
1975     }
1976 }
1977
1978 bool
1979 context_hasFileAccess (typeId t)
1980 {
1981   return (typeIdSet_member (gc.facct, t));
1982 }
1983
1984 /*@only@*/ cstring
1985 context_unparseAccess (void)
1986 {
1987   return (message ("%q / %q", typeIdSet_unparse (gc.acct),
1988                    typeIdSet_unparse (gc.facct)));
1989 }
1990
1991 /*@only@*/ cstring
1992 context_unparseClauses (void)
1993 {
1994   return (clauseStack_unparse (gc.clauses));
1995 }
1996
1997 bool
1998 context_couldHaveAccess (typeId t)
1999 {
2000   if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2001     {
2002       return (typeIdSet_member (gc.acct, t));
2003     }
2004   else
2005     {
2006       return (typeIdSet_member (gc.facct, t)); 
2007     }
2008 }
2009
2010 ctype
2011 context_getRetType (void)
2012 {
2013   ctype f = ctype_undefined;
2014
2015   if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2016     {
2017       f = uentry_getType (gc.cont.fcn);
2018     }
2019   else if (gc.kind == CX_UNKNOWNMACRO)
2020     {
2021       return ctype_unknown;
2022     }
2023   else
2024     {
2025       llcontbuglit ("context_getRetType: not in a function context");
2026       return ctype_unknown;
2027     }
2028
2029   if (!ctype_isFunction (f))
2030     {
2031       if (ctype_isKnown (f))
2032         {
2033           llbuglit ("context_getRetType: not a function");
2034         }
2035
2036       return ctype_unknown;
2037     }
2038   return (ctype_getReturnType (f));
2039 }    
2040
2041 bool
2042 context_hasMods (void)
2043 {
2044   if (context_inFunctionLike ())
2045     {
2046       return (uentry_hasMods (gc.cont.fcn));
2047     }
2048   else
2049     {
2050       return FALSE;
2051     }
2052 }
2053
2054 void
2055 context_exitAllClauses (void)
2056 {  
2057   while (!clauseStack_isEmpty (gc.clauses))
2058     {
2059       clause el = clauseStack_top (gc.clauses);
2060       gc.inclause = el;
2061
2062       if (clause_isNone (el))
2063         {
2064           usymtab_quietExitScope (g_currentloc);
2065           clauseStack_pop (gc.clauses);
2066         }
2067       else
2068         {
2069           context_exitClausePlain ();
2070         }
2071     }
2072
2073   clauseStack_clear (gc.clauses);  
2074   gc.inclause = NOCLAUSE;
2075 }
2076
2077 void
2078 context_exitAllClausesQuiet (void)
2079 {  
2080   while (!clauseStack_isEmpty (gc.clauses))
2081     {
2082       clause el = clauseStack_top (gc.clauses);
2083       gc.inclause = el;
2084
2085       usymtab_quietExitScope (g_currentloc);
2086       clauseStack_pop (gc.clauses);
2087     }
2088
2089   clauseStack_clear (gc.clauses);  
2090   gc.inclause = NOCLAUSE;
2091 }
2092
2093 static
2094 void context_exitClauseSimp (void)
2095 {
2096   
2097   context_setJustPopped ();
2098   clauseStack_pop (gc.clauses);
2099   gc.inclause = topClause (gc.clauses);
2100 }
2101
2102 static
2103 void context_exitCaseClause (void)
2104 {
2105   context_setJustPopped ();
2106   usymtab_popCaseBranch ();
2107   clauseStack_pop (gc.clauses);
2108   gc.inclause = topClause (gc.clauses);
2109 }
2110
2111 static
2112 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2113 {
2114   context_setJustPopped ();
2115   /*@i32 was makeAlt */
2116   usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2117   clauseStack_pop (gc.clauses);
2118   gc.inclause = topClause (gc.clauses);
2119 }
2120
2121 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2122 {
2123   DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2124
2125   if (gc.inclause != TRUECLAUSE)
2126     {
2127       llparseerror (cstring_makeLiteral
2128                     ("Likely parse error.  Conditional clauses are inconsistent."));
2129       return;
2130     }
2131   
2132   context_setJustPopped ();  
2133   usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2134   clauseStack_pop (gc.clauses);
2135   gc.inclause = topClause (gc.clauses);  
2136 }
2137
2138 void context_exitIterClause (exprNode body)
2139 {
2140   llassert (gc.inclause == ITERCLAUSE);
2141
2142   context_setJustPopped ();
2143
2144   if (context_getFlag (FLG_LOOPEXEC))
2145     {
2146       usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2147     }
2148   else
2149     {
2150       usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2151     }
2152
2153   clauseStack_pop (gc.clauses);
2154   gc.inclause = topClause (gc.clauses);
2155 }
2156
2157 static void context_popCase (void) {
2158   /*
2159   ** If we are exiting an outer clause, sometimes still in a switch case.
2160   **
2161   ** e.g.: 
2162   **
2163   ** switch(a)
2164   ** {
2165   **   case 1:
2166   **     while (c>3)
2167   **       {
2168   **         case 3: ++c;
2169   **       }
2170   ** }     
2171   */
2172
2173   DPRINTF (("Popping case clause: %s",
2174             clauseStack_unparse (gc.clauses)));
2175   
2176   if (gc.inclause == CASECLAUSE) {
2177     context_exitCaseClause ();
2178   }
2179 }
2180
2181 void context_exitWhileClause (exprNode pred, exprNode body)
2182 {
2183   guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2184
2185   context_popCase (); 
2186
2187   if (gc.inclause != WHILECLAUSE) {
2188     DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2189               clauseStack_unparse (gc.clauses)));
2190   }
2191
2192   llassert (gc.inclause == WHILECLAUSE);
2193
2194   context_setJustPopped ();
2195
2196   
2197   /*
2198   ** predicate must be false after while loop (unless there are breaks)
2199   */
2200
2201   if (context_getFlag (FLG_LOOPEXEC))
2202     {
2203       usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2204     }
2205   else
2206     {
2207       usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2208     }
2209
2210   
2211   usymtab_addGuards (invGuards);
2212   guardSet_free (invGuards);
2213
2214   clauseStack_pop (gc.clauses);
2215   gc.inclause = topClause (gc.clauses);  
2216 }
2217
2218 void context_exitDoWhileClause (exprNode pred)
2219 {
2220   guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2221
2222   if (gc.inclause == CASECLAUSE) {
2223     /* handle Duff's device */
2224     clauseStack_pop (gc.clauses);
2225     gc.inclause = topClause (gc.clauses);
2226   }
2227
2228   llassert (gc.inclause == DOWHILECLAUSE);
2229
2230   context_setJustPopped ();
2231
2232     
2233   usymtab_addGuards (invGuards);
2234   guardSet_free (invGuards);
2235
2236   clauseStack_pop (gc.clauses);
2237   gc.inclause = topClause (gc.clauses);  
2238 }
2239
2240 void context_exitForClause (exprNode forPred, exprNode body)
2241 {
2242   guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2243
2244   llassert (gc.inclause == FORCLAUSE);
2245   context_setJustPopped ();
2246
2247   /*
2248   ** predicate must be false after while loop (unless there are breaks)
2249   */
2250
2251   if (context_getFlag (FLG_LOOPEXEC))
2252     {
2253       usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2254     }
2255   else
2256     {
2257       usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2258     }
2259
2260   usymtab_addGuards (invGuards);
2261   guardSet_free (invGuards);
2262   clauseStack_pop (gc.clauses);
2263   gc.inclause = topClause (gc.clauses);
2264 }
2265
2266 static void context_exitClausePlain (void)
2267 {
2268   llassert (gc.inclause != NOCLAUSE);
2269   
2270   if (gc.inclause == FALSECLAUSE)
2271     {
2272       context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2273     }
2274   else
2275     {
2276       context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2277     }
2278 }
2279
2280 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2281 {
2282   context_setJustPopped ();
2283   
2284   if (gc.inclause == FALSECLAUSE)
2285     {
2286       usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2287       
2288       llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2289
2290       clauseStack_pop (gc.clauses);
2291       gc.inclause = topClause (gc.clauses);
2292     }
2293   else
2294     {
2295       context_exitTrueClause (pred, tbranch);
2296     }
2297 }
2298
2299 void
2300 context_returnFunction (void)
2301 {
2302   usymtab_checkFinalScope (TRUE);
2303 }
2304
2305 void
2306 context_exitFunction (void)
2307 {    
2308   if (!context_inFunction () && !context_inMacroConstant () 
2309       && !context_inMacroUnknown () 
2310       && !context_inIterDef () && !context_inIterEnd ())
2311     {
2312       /*
2313       ** not a bug because of parse errors
2314       */
2315     }
2316   else
2317     {
2318       if (context_inMacro () && usymtab_inFunctionScope ())
2319         {
2320           usymtab_exitScope (exprNode_undefined);
2321         }
2322       
2323       if (uentry_hasGlobs (gc.cont.fcn))
2324         {
2325           exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2326         }
2327       
2328             
2329       if (uentry_hasMods (gc.cont.fcn))
2330         {
2331           if (context_getFlag (FLG_MUSTMOD))
2332             {
2333               exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2334             }
2335         }
2336
2337       DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2338
2339       /*
2340       ** clear file static modifies
2341       */
2342       
2343       /* do this first to get unused error messages */
2344
2345       usymtab_exitScope (exprNode_undefined);
2346       sRef_exitFunctionScope ();
2347       
2348       gc.showfunction = FALSE;
2349       gc.kind = CX_GLOBAL;
2350       gc.cont.glob = TRUE;
2351       gc.acct = gc.facct; 
2352       gc.globs = globSet_new ();
2353       globSet_clear (gc.globs_used);
2354       gc.mods = sRefSet_new ();
2355     }
2356
2357   llassert (clauseStack_isEmpty (gc.clauses));
2358   llassert (gc.inclause == NOCLAUSE);
2359 }
2360
2361 void
2362 context_quietExitFunction (void)
2363 {
2364   while (gc.kind == CX_INNER)
2365     { 
2366       context_exitInnerPlain ();
2367     }
2368
2369   if (!context_inFunction () && !context_inMacroConstant () && !context_inMacroUnknown () 
2370       && !context_inIterDef () && !context_inIterEnd ())
2371     {
2372     }
2373   else
2374     {
2375       usymtab_quietExitScope (g_currentloc);
2376
2377       gc.showfunction = FALSE;
2378       gc.kind = CX_GLOBAL;
2379       gc.cont.glob = TRUE;
2380       gc.acct = gc.facct; 
2381       gc.globs = globSet_new ();
2382       globSet_clear (gc.globs_used);
2383       gc.mods = sRefSet_new ();
2384
2385       sRef_exitFunctionScope ();
2386     }
2387 }
2388
2389 /*@observer@*/ uentryList
2390 context_getParams (void)
2391 {
2392   if (context_inFunctionLike ())
2393     {
2394       return (uentry_getParams (gc.cont.fcn));
2395     }
2396   else
2397     {
2398       llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2399       return uentryList_undefined;
2400     }
2401 }
2402
2403 /*@observer@*/ globSet
2404 context_getUsedGlobs (void)
2405 {
2406   llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN 
2407             || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2408
2409   return (gc.globs_used);
2410 }
2411
2412 cstring
2413 context_moduleName ()
2414 {
2415   return (fileloc_getBase (g_currentloc));
2416 }
2417
2418 /*@observer@*/ globSet
2419 context_getGlobs (void)
2420 {
2421   llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN 
2422             || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2423
2424   return (gc.globs);
2425 }
2426
2427 void
2428 context_addBoolAccess (void)
2429 {
2430   cstring bname = context_getString (FLG_BOOLTYPE);
2431   typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2432   
2433   addModuleAccess (cstring_copy (bname), boolt);
2434
2435   /* for sys/types (perhaps, this is bogus!) */ 
2436   addModuleAccess (cstring_makeLiteral ("types"), boolt); 
2437 }
2438
2439 # if 0
2440 bool
2441 context_canAccessBool (void)
2442 {
2443   return TRUE;
2444 }
2445 # endif
2446
2447 /*
2448   static typeId boolType = typeId_invalid;
2449
2450   if (typeId_isInvalid (boolType))
2451     { 
2452       boolType = usymtab_getTypeId (context_getBoolName ());
2453     }
2454
2455   if (typeId_isInvalid (boolType)) {
2456     return FALSE;
2457   } else {
2458     return (typeIdSet_member (gc.acct, boolType));
2459   }
2460 }
2461 */
2462
2463 /* evs 2000-07-25: old version - replaced */
2464
2465 ctype
2466 context_boolImplementationType () {
2467   /* For now, this is bogus! */
2468   return ctype_int;
2469 }
2470
2471 bool
2472 context_canAccessBool (void)
2473 {
2474   static typeId boolType = typeId_invalid;
2475
2476   if (typeId_isInvalid (boolType))
2477     { 
2478       boolType = usymtab_getTypeId (context_getBoolName ());
2479     }
2480
2481   if (!typeId_isInvalid (boolType))
2482     { 
2483       return context_hasAccess (boolType);
2484     }
2485   else 
2486     {
2487       ;
2488     }
2489
2490   return FALSE; 
2491 }
2492
2493 void
2494 context_setMessageAnnote (/*@only@*/ cstring s)
2495 {
2496   llassert (cstring_isUndefined (gc.msgAnnote));
2497     gc.msgAnnote = s;
2498 }
2499
2500 bool
2501 context_hasMessageAnnote (void)
2502 {
2503   return (cstring_isDefined (gc.msgAnnote));
2504 }
2505
2506 void
2507 context_clearMessageAnnote (void)
2508 {
2509   if (cstring_isDefined (gc.msgAnnote))
2510     {
2511       cstring_free (gc.msgAnnote);
2512       gc.msgAnnote = cstring_undefined;
2513     }
2514 }
2515
2516 /*@only@*/ cstring
2517 context_getMessageAnnote (void)
2518 {
2519   cstring st = gc.msgAnnote;
2520
2521     gc.msgAnnote = cstring_undefined;
2522   return st;
2523 }
2524
2525 void
2526 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2527 {
2528     llassert (sRef_isInvalid (gc.aliasAnnote));
2529   llassert (!sRef_sameName (s, t));
2530   gc.aliasAnnote = s;
2531   gc.aliasAnnoteAls = t;
2532 }
2533
2534 bool
2535 context_hasAliasAnnote (void)
2536 {
2537   return (sRef_isValid (gc.aliasAnnote));
2538 }
2539
2540 void
2541 context_clearAliasAnnote (void)
2542 {
2543   gc.aliasAnnote = sRef_undefined;
2544 }
2545
2546 cstring
2547 context_getAliasAnnote (void)
2548 {
2549   sRef ret = gc.aliasAnnote;
2550   sRef als = gc.aliasAnnoteAls;
2551
2552   llassert (sRef_isValid (ret) && sRef_isValid (als));
2553
2554   gc.aliasAnnote = sRef_undefined;
2555   return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2556 }
2557
2558 void
2559 context_recordFileModifies (sRefSet mods)
2560 {
2561   gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2562 }
2563
2564 void
2565 context_recordFileGlobals (globSet mods)
2566 {
2567   DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2568   /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2569 }
2570
2571 void
2572 context_setCommentMarkerChar (char c)
2573 {
2574   llassert (c != '\0');
2575
2576   context_setValue (FLG_COMMENTCHAR, (int) c);
2577 }
2578
2579 char
2580 context_getCommentMarkerChar (void)
2581 {
2582   return ((char) context_getValue (FLG_COMMENTCHAR));
2583 }
2584
2585 static void
2586 context_setValue (flagcode flag, int val)
2587 {
2588   int index = flagcode_valueIndex (flag);
2589
2590   llassert (index >= 0 && index <= NUMVALUEFLAGS);
2591
2592   switch (flag)
2593     {
2594     case FLG_LINELEN:
2595       if (val <= 0)
2596         {
2597           
2598           llerror_flagWarning (message ("Value for %s must be a positive "
2599                                     "number (given %d)",
2600                                     flagcode_unparse (flag), val));
2601           return;
2602         }
2603       if (flag == FLG_LINELEN && val < MINLINELEN)
2604         {
2605           llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2606                                     flagcode_unparse (flag), 
2607                                     MINLINELEN, val));
2608           val = MINLINELEN;
2609         }
2610       break;
2611
2612     case FLG_INCLUDENEST:
2613     case FLG_CONTROLNESTDEPTH:
2614     case FLG_STRINGLITERALLEN:
2615     case FLG_NUMSTRUCTFIELDS:
2616     case FLG_NUMENUMMEMBERS:      
2617     case FLG_INDENTSPACES:
2618       if (val < 0)
2619         {
2620           
2621           llerror_flagWarning (message ("Value for %s must be a non-negative "
2622                                     "number (given %d)",
2623                                     flagcode_unparse (flag), val));
2624           return;
2625         }
2626
2627       break;
2628     default:
2629       break;
2630     }
2631     
2632   gc.values[index] = val;
2633 }
2634
2635 void
2636 context_setValueAndFlag (flagcode flag, int val)
2637 {
2638   gc.flags[flag] = TRUE;
2639   context_setValue (flag, val);
2640 }
2641
2642 int
2643 context_getValue (flagcode flag)
2644 {
2645   int index = flagcode_valueIndex (flag);
2646
2647   llassert (index >= 0 && index <= NUMVALUEFLAGS);
2648   return (gc.values[index]);
2649 }
2650
2651 int
2652 context_getCounter (flagcode flag)
2653 {
2654   int index = flagcode_valueIndex (flag);
2655
2656   llassert (index >= 0 && index <= NUMVALUEFLAGS);
2657   return (gc.counters[index]);
2658 }
2659
2660 void
2661 context_incCounter (flagcode flag)
2662 {
2663   int index = flagcode_valueIndex (flag);
2664
2665   llassert (index >= 0 && index <= NUMVALUEFLAGS);
2666   /* check limit */
2667   gc.counters[index]++;
2668 }
2669
2670 void
2671 context_decCounter (flagcode flag)
2672 {
2673   int index = flagcode_valueIndex (flag);
2674
2675   llassert (index >= 0 && index <= NUMVALUEFLAGS);
2676   gc.counters[index]--;
2677 }
2678
2679 bool context_showFunction (void)
2680 {
2681   return (gc.showfunction);
2682 }
2683
2684 void
2685 context_setString (flagcode flag, cstring val)
2686 {
2687   int index = flagcode_stringIndex (flag);
2688
2689   llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2690
2691   if (flag == FLG_SYSTEMDIRS)
2692     {
2693       llassert (cstring_isDefined (val));
2694
2695       if (cstring_firstChar (val) == '\"')
2696         {
2697           cstring oval = val;
2698           cstring tval = cstring_copy (cstring_suffix (val, 1));
2699         
2700           if (cstring_lastChar (tval) != '\"')
2701             {
2702               int n = cstring_length (tval) - 1;
2703
2704               while (isspace ((int) cstring_getChar (tval, n)))
2705                 {
2706                   n--;
2707                 }
2708
2709               if (cstring_getChar (tval, n) != '\"')
2710                 {
2711                   llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2712                 }
2713               else
2714                 {
2715                   cstring otval = tval;
2716                   tval = cstring_prefix (tval, n);
2717                   cstring_free (otval);
2718                 }
2719             }
2720           
2721           val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2722           DPRINTF (("val = %s", val));
2723           cstring_free (tval);
2724           cstring_free (oval);
2725         }
2726     }
2727
2728   if (flag == FLG_TMPDIR)
2729     {
2730       llassert (cstring_isDefined (val));
2731       
2732       if (cstring_length (val) == 0)
2733         {
2734           cstring_free (val);
2735           val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2736         }
2737       else if (cstring_lastChar (val) != CONNECTCHAR)
2738         {
2739           val = cstring_appendChar (val, CONNECTCHAR);
2740         }
2741       else
2742         {
2743           ;
2744         }
2745     }
2746
2747   if (cstring_length (val) >= 1
2748       && cstring_firstChar (val) == '"')
2749     {
2750       llerror_flagWarning (message
2751                        ("setting %s to string beginning with \".  You probably "
2752                         "don't meant to have the \"'s.",
2753                         flagcode_unparse (flag)));
2754     }
2755
2756   if (flag == FLG_BOOLTYPE)
2757     {
2758
2759     }
2760
2761   gc.strings[index] = val;
2762 }
2763
2764 static /*@exposed@*/ cstring
2765 context_exposeString (flagcode flag)
2766 {
2767   int index = flagcode_stringIndex (flag);
2768
2769   llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2770   return (gc.strings[index]);
2771 }
2772
2773 cstring
2774 context_getString (flagcode flag)
2775 {
2776   return (context_exposeString (flag));
2777 }
2778
2779 void
2780 context_resetErrors (void)
2781 {
2782   gc.numerrors = 0;
2783 }
2784
2785 void context_initMod (void)
2786    /*@globals undef gc; @*/
2787 {
2788   gc.kind = CX_GLOBAL;
2789   gc.savekind = CX_ERROR;
2790   gc.instandardlib = FALSE;
2791   gc.numerrors = 0;
2792   gc.neednl = FALSE;
2793   gc.linesprocessed = 0;
2794   gc.speclinesprocessed = 0;
2795   gc.insuppressregion = FALSE;
2796   gc.macroMissingParams = FALSE;
2797   gc.preprocessing = FALSE;
2798   gc.incommandline = FALSE;
2799   gc.mc = macrocache_create ();
2800   gc.nmods = 0;
2801   gc.maxmods = DEFAULTMAXMODS;
2802   gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2803   
2804   gc.library = FLG_ANSILIB;
2805
2806   gc.locstack = filelocStack_new ();
2807   gc.modrecs = sRefSetList_undefined;
2808   gc.anyExports = FALSE;
2809
2810   gc.ftab = fileTable_create ();
2811   gc.msgLog = messageLog_new ();
2812   gc.inimport = FALSE;
2813   gc.inDerivedFile = FALSE;
2814   gc.inheader = FALSE;
2815   gc.markers = flagMarkerList_new ();
2816   gc.cont.glob = TRUE;
2817   gc.showfunction = FALSE;
2818   gc.msgAnnote = cstring_undefined;
2819   gc.aliasAnnote = sRef_undefined;
2820   gc.aliasAnnoteAls = sRef_undefined;
2821   gc.boolType = ctype_bool;
2822   gc.mods = sRefSet_new ();
2823
2824   gc.saveloc = fileloc_undefined;
2825
2826   gc.inmacrocache = FALSE;
2827   gc.inclause = NOCLAUSE;
2828   gc.clauses = clauseStack_new ();
2829   gc.globs = globSet_new ();
2830   gc.nacct = typeIdSet_emptySet ();
2831   gc.acct = typeIdSet_emptySet ();
2832   gc.facct = typeIdSet_emptySet ();
2833   gc.savedFlags = FALSE;
2834   gc.pushloc = fileloc_undefined;
2835   gc.protectVars = FALSE;
2836   gc.justpopped = FALSE;
2837   gc.isNullGuarded = NO;
2838   gc.globs_used = globSet_undefined;
2839   
2840   allFlagCodes (code)
2841     {
2842       gc.setGlobally[code] = FALSE;
2843       gc.setLocally[code] = FALSE;
2844     } end_allFlagCodes ;
2845
2846   usymtab_initMod ();
2847
2848   context_resetAllFlags ();
2849   assertSet (gc.flags); /* Can't use global in defines */
2850   assertSet (gc.saveflags);
2851   assertSet (gc.values);
2852   assertSet (gc.strings);
2853
2854   conext_resetAllCounters ();
2855   assertSet (gc.counters);
2856
2857   context_setMode (DEFAULT_MODE);
2858
2859   gc.stateTable = metaStateTable_create ();
2860   gc.annotTable = annotationTable_create ();
2861
2862   gc.inFunctionHeader = FALSE;
2863
2864   DPRINTF (("Annotations: \n%s",
2865             cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
2866   DPRINTF (("State: \n%s",
2867             cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
2868
2869 }
2870
2871 ctype
2872 context_typeofZero (void)
2873 {
2874   ctype ct = ctype_int;
2875
2876   if (context_getFlag (FLG_ZEROPTR))
2877     {
2878       ct = ctype_makeConj (ct, ctype_voidPointer);
2879     }
2880   
2881   if (context_getFlag (FLG_ZEROBOOL)) {
2882     ct = ctype_makeConj (ct, ctype_bool); 
2883   }
2884
2885   return ct;
2886 }
2887
2888 ctype
2889 context_typeofOne (void)
2890 {
2891   ctype ct = ctype_int;
2892
2893   /* 1 is on longer a bool (was before 2.4)
2894      if (!context_getFlag (FLG_ABSTRACTBOOL))
2895      {
2896      ct = ctype_makeConj (ct, ctype_bool);
2897      }
2898      */
2899
2900   return (ct);
2901 }
2902
2903 /*@only@*/ cstring
2904 context_unparse (void)
2905 {
2906   cstring s;
2907
2908   switch (gc.kind)
2909     {
2910     case CX_LCL:
2911       s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
2912       break;
2913     case CX_LCLLIB:
2914       s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
2915       break;
2916     case CX_GLOBAL:
2917       s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
2918       break;
2919     case CX_INNER:
2920       s = message ("Inner Context:%q", fileloc_unparse (g_currentloc));
2921       break;
2922     case CX_FUNCTION:
2923       s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
2924                    uentry_unparse (gc.cont.fcn),
2925                    fileloc_unparse (g_currentloc),
2926                    typeIdSet_unparse (gc.acct),
2927                    sRefSet_unparse (gc.mods));
2928       break;
2929     case CX_MACROFCN:
2930       s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
2931       break;
2932     case CX_UNKNOWNMACRO:
2933       s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
2934       break;
2935     case CX_MACROCONST:
2936       s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
2937       break;
2938     case CX_ITERDEF:
2939       s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
2940       break;
2941     case CX_ITEREND:
2942       s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
2943       break;
2944     default:
2945       s = message ("Un-unparseable context: %d", (int) gc.kind);
2946       break;
2947     }
2948   
2949   s = message ("%q\naccess: %q", s, context_unparseAccess ());
2950   return (s);
2951 }
2952
2953 extern ctype
2954 context_currentFunctionType (void)
2955 {
2956   if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2957     {
2958             return (uentry_getType (gc.cont.fcn));
2959     }
2960   else if (gc.kind == CX_INNER)
2961     {
2962       llcontbuglit ("context_currentFunctionType: inner context");
2963       do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
2964       return (context_currentFunctionType ());
2965     }
2966   else
2967     {
2968       llcontbuglit ("context_currentFunctionType: not in function");
2969       return (ctype_undefined);
2970     }
2971 }
2972
2973 void
2974 context_enterInnerContext (void)
2975 {
2976   if (gc.kind == CX_GLOBAL)
2977     {
2978       gc.kind = CX_INNER;
2979       gc.cont.cdepth = 1;
2980     }
2981   else if (gc.kind == CX_INNER)
2982     {
2983       gc.cont.cdepth++;
2984     }
2985   else
2986     {
2987       ;
2988     }
2989
2990   
2991   usymtab_enterScope ();
2992   pushClause (NOCLAUSE);
2993 }
2994
2995 void
2996 context_exitInnerPlain (void) /*@modifies gc;@*/
2997 {
2998   context_exitInner (exprNode_undefined);
2999 }
3000
3001 void
3002 context_exitInner (exprNode exp)
3003 {
3004   
3005   llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3006                  ("inclause = %s", clause_nameTaken (gc.inclause)));
3007
3008   clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3009   gc.inclause = topClause (gc.clauses);
3010
3011   if (gc.kind == CX_INNER)
3012     {
3013       if (--gc.cont.cdepth == 0)
3014         {
3015           gc.kind = CX_GLOBAL;
3016           gc.cont.glob = TRUE;
3017         }
3018     }
3019   else 
3020     {
3021       if (gc.kind == CX_GLOBAL)
3022         {
3023           llcontbuglit ("Attempt to exit global context");
3024           return;
3025         }
3026     }
3027
3028     usymtab_exitScope (exp);
3029 }
3030
3031
3032 void
3033 context_enterStructInnerContext (void)
3034 {
3035   if (gc.kind == CX_GLOBAL)
3036     {
3037       gc.kind = CX_INNER;
3038       gc.cont.cdepth = 1;
3039     }
3040   else if (gc.kind == CX_INNER)
3041     {
3042       gc.cont.cdepth++;
3043     }
3044   else
3045     {
3046       ;
3047     }
3048
3049   usymtab_enterScope ();
3050 }
3051
3052 void
3053 context_exitStructInnerContext (void)
3054 {
3055   if (gc.kind == CX_INNER)
3056     {
3057       if (--gc.cont.cdepth == 0)
3058         {
3059           gc.kind = CX_GLOBAL;
3060           gc.cont.glob = TRUE;
3061         }
3062     }
3063   else 
3064     {
3065       if (gc.kind == CX_GLOBAL)
3066         {
3067           llcontbuglit ("Attempt to exit global context");
3068           return;
3069         }
3070     }
3071
3072   usymtab_exitScope (exprNode_undefined);
3073 }
3074
3075 void
3076 context_exitInnerSafe (void)
3077 {
3078   
3079   if (gc.kind == CX_INNER)
3080     {
3081       if (--gc.cont.cdepth == 0)
3082         {
3083           gc.cont.cdepth++;
3084         }
3085     }
3086   else if (gc.kind == CX_GLOBAL)
3087     {
3088       llcontbuglit ("Attempt to exit global context");
3089       return;
3090     }
3091   else
3092     {
3093       if (usymtab_inDeepScope ())
3094         {
3095           usymtab_exitScope (exprNode_undefined);
3096         }
3097     }
3098 }
3099
3100 static
3101 void setModuleAccess (void)
3102 {
3103   gc.facct = typeIdSet_emptySet ();
3104
3105   if (fileId_isValid (currentFile ()))
3106     {
3107       cstring baseName = fileloc_getBase (g_currentloc);
3108       
3109       if (context_getFlag (FLG_ACCESSFILE))
3110         {
3111           if (usymtab_existsType (baseName))
3112             {
3113               gc.facct = typeIdSet_insert (gc.facct, 
3114                                            usymtab_getTypeId (baseName));
3115             }
3116           else 
3117             {
3118               ;
3119             }
3120         }
3121       
3122       if (context_getFlag (FLG_ACCESSMODULE))
3123         {
3124           int i;
3125           bool hasaccess = FALSE;
3126           
3127           for (i = 0; i < gc.nmods; i++)
3128             {
3129               if (cstring_equal (baseName, gc.moduleaccess[i].file))
3130                 {
3131                   gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3132
3133                   hasaccess = TRUE;
3134                   break;
3135                 }
3136             }
3137         }
3138       
3139       gc.acct = gc.facct;
3140       gc.inheader = fileId_isHeader (currentFile ());
3141     }
3142   else
3143     {
3144       llcontbuglit ("Current file not defined\n");
3145       gc.facct = typeIdSet_emptySet ();
3146       gc.acct = gc.facct;
3147       gc.inheader = FALSE;
3148     }
3149   
3150   /* 17 Jan 1995: forgot to clear nacct */
3151   
3152   gc.nacct = typeIdSet_emptySet ();
3153 }
3154
3155 static void
3156 context_enterFileAux (void)
3157 {
3158   setModuleAccess ();
3159 }
3160
3161 void
3162 context_enterFile (void)
3163 {
3164   context_enterFileAux ();
3165   usymtab_enterFile ();
3166 }
3167
3168 void
3169 context_enterMacroFile (void)
3170 {
3171   context_enterFileAux ();
3172 }
3173
3174 bool 
3175 context_inFunction (void)
3176 {
3177   kcontext ck = gc.kind;
3178   
3179   return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3180 }
3181
3182 bool 
3183 context_inFunctionLike (void)
3184 {
3185   return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN 
3186           || gc.kind == CX_FCNDECLARATION
3187           || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3188 }
3189
3190 bool 
3191 context_inRealFunction (void)
3192 {
3193   kcontext ck = gc.kind;
3194   
3195   return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3196 }
3197   
3198 void
3199 context_processAllMacros (void)
3200 {
3201   usymtab_enterFile ();
3202
3203   gc.inmacrocache = TRUE; 
3204   macrocache_processUndefinedElements (gc.mc);
3205   cleanupMessages ();  
3206   usymtab_exitFile ();
3207
3208   gc.inmacrocache = FALSE;
3209   macrocache_finalize ();
3210 }
3211
3212 /*
3213 ** this happens once at the end of each C file
3214 **
3215 ** check each Macro that was defined in current file.c or current file.h
3216 **
3217 */
3218
3219 static void
3220 context_processMacros (void)
3221 {
3222   if (fileId_isValid (currentFile ()))
3223     {
3224       fileloc lastfl;
3225       cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileName (currentFile ())));
3226       
3227       gc.inmacrocache = TRUE;
3228
3229       DPRINTF (("Processing macros: %s", cbase));
3230       lastfl = macrocache_processFileElements (gc.mc, cbase);
3231       DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3232
3233       cstring_free (cbase);
3234       
3235       if (fileloc_isDefined (lastfl))
3236         {
3237           g_currentloc = fileloc_update (g_currentloc, lastfl);
3238           cleanupMessages ();
3239         }
3240
3241       gc.inmacrocache = FALSE;
3242     }
3243 }
3244
3245 bool
3246 context_processingMacros (void)
3247 {
3248   return (gc.inmacrocache);
3249 }
3250
3251 void
3252 context_exitCFile (void)
3253 {
3254   if (gc.kind != CX_GLOBAL)
3255     {
3256       llfatalerrorLoc
3257         (cstring_makeLiteral ("File ended outside global scope"));
3258     }
3259
3260   if (gc.insuppressregion)
3261     {
3262      /* gack...don't reverse the order of these lines! ;-> */
3263       gc.insuppressregion = FALSE;
3264       llerrorlit (FLG_SYNTAX, 
3265                   "File ended in ignore errors region, "
3266                   "possible missing /*@end*/");
3267     }
3268
3269   /* fix up parse errors */
3270
3271   while (!usymtab_inFileScope ())
3272     {
3273       usymtab_quietExitScope (g_currentloc);
3274     }
3275
3276   /*
3277   ** Clear the file-specific modifies information.
3278   */
3279   
3280   sRefSetList_elements (gc.modrecs, mods)
3281     {
3282       sRefSet_clearStatics (mods);
3283     } end_sRefSetList_elements ;
3284   
3285   sRefSetList_clear (gc.modrecs);
3286   
3287   context_processMacros ();
3288   cleanupMessages (); 
3289   
3290   usymtab_exitFile ();
3291   
3292   gc.inDerivedFile = FALSE;
3293   filelocStack_clear (gc.locstack);
3294   
3295   gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3296   
3297   gc.cont.glob = TRUE;
3298   
3299   if (gc.savedFlags)
3300     {
3301       context_restoreFlagSettings ();
3302       gc.savedFlags = FALSE;
3303     }
3304   
3305   /*
3306     DPRINTF (("After exiting file: "));
3307     usymtab_printAll ();
3308   */
3309 }
3310
3311 void
3312 context_exitMacroCache (void)
3313 {
3314   if (gc.kind != CX_GLOBAL)
3315     {
3316       if (context_inMacro ()) 
3317         /* this is okay, file could end without newline in macro */
3318         {
3319           DPRINTF (("Still in macro: %s",
3320                     context_unparse ()));
3321           context_exitFunction ();
3322         }
3323       else
3324         {
3325           llcontbug (message ("context_exitMacroCache: outside global scope: %q", 
3326                               context_unparse ()));
3327           gc.kind = CX_GLOBAL; 
3328         }
3329     }
3330
3331   /*
3332   ** no longer valid here
3333   ** if (gc.insuppressregion)
3334   **   {
3335   **     gc.insuppressregion = FALSE;
3336   **     llerror ("File ended in ignore errors region, possible missing @");
3337   **   }
3338   */
3339
3340   gc.cont.glob = TRUE;
3341 }
3342
3343 void
3344 context_saveLocation (void)
3345 {
3346   /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3347   fileloc_free (gc.saveloc);
3348   gc.saveloc = fileloc_copy (g_currentloc);
3349 }
3350
3351 fileloc
3352 context_getSaveLocation (void)
3353 {
3354   fileloc fl = gc.saveloc;
3355   gc.saveloc = fileloc_undefined;
3356   return fl;
3357 }
3358
3359 /*@observer@*/ cstring
3360 context_inFunctionName (void)
3361 {
3362   if (gc.kind == CX_FUNCTION
3363       || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO 
3364       || gc.kind == CX_MACROCONST 
3365       || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3366     {
3367       return (uentry_rawName (gc.cont.fcn));
3368     }
3369   else
3370     {
3371       llcontbuglit ("context_inFunctionName: not in function");
3372       return (cstring_undefined);
3373     }
3374 }
3375
3376 void
3377 context_userSetFlag (flagcode f, bool b)
3378 {
3379   DPRINTF (("set flag: %s", flagcode_unparse (f)));
3380
3381   if (f == FLG_NEVERINCLUDE && b)
3382     {
3383       if (gc.flags[FLG_EXPORTHEADER])
3384         {
3385           llerror_flagWarning (cstring_makeLiteral
3386                            ("setting +neverinclude after +exportheader.  "
3387                             "Turning off exportheader, since headers are not checked "
3388                             "when +neverinclude is used."));
3389
3390           gc.flags[FLG_EXPORTHEADER] = FALSE;
3391         }
3392     }
3393   else 
3394     {
3395       if (f == FLG_EXPORTHEADER && b)
3396         {
3397           if (gc.flags[FLG_NEVERINCLUDE])
3398             {
3399               llerror_flagWarning (cstring_makeLiteral
3400                                ("setting +exportheader after +neverinclude.  "
3401                                 "Not setting exportheader, since headers are not checked "
3402                                 "when +neverinclude is used."));
3403               gc.flags[FLG_EXPORTHEADER] = FALSE;
3404               return;
3405             }
3406         }
3407     }
3408   
3409   if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3410     {
3411       bool lastsetting = context_getFlag (f);
3412       
3413       if (bool_equal (lastsetting, b)
3414           && !flagcode_isSpecialFlag (f) 
3415           && !flagcode_isIdemFlag (f)
3416           && !flagcode_hasArgument (f))
3417         {
3418           llerror_flagWarning (message ("setting %s%s redundant with current value", 
3419                                     cstring_makeLiteralTemp (b ? "+" : "-"),
3420                                     flagcode_unparse (f)));
3421         }
3422     }
3423
3424   if (flagcode_isWarnUseFlag (f) && b)
3425     {
3426       if (!context_getFlag (FLG_WARNUSE))
3427         {
3428           llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3429                                     flagcode_unparse (f)));
3430           
3431         }
3432     }
3433
3434
3435   if (flagcode_isLibraryFlag (f)) 
3436     {
3437       if (gc.library != FLG_ANSILIB
3438           && gc.library != f)
3439         {
3440           llerror_flagWarning (message ("selecting library %s after library %s was "
3441                                         "selected (only one library may be used)",
3442                                         flagcode_unparse (f),
3443                                         flagcode_unparse (gc.library)));
3444         }
3445
3446       if (f == FLG_UNIXLIB)
3447         {
3448           if (context_getFlag (FLG_WARNUNIXLIB))
3449             {
3450               llerror_flagWarning (cstring_makeLiteral
3451                                    ("selecting unix library.  Unix library is "
3452                                     "ad hoc addition to POSIX library.  Recommend "
3453                                     "use +posixlib to select POSIX library instead. "
3454                                     "Use -warnunixlib to suppress this message."));
3455             }
3456         }
3457       
3458       gc.library = f;
3459     }
3460
3461   if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3462     {
3463       llerror_flagWarning (message
3464                            ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3465                             flagcode_unparse (f)));
3466     }
3467
3468   gc.setGlobally[f] = TRUE;
3469   context_setFlag (f, b);
3470 }
3471
3472 void
3473 context_fileSetFlag (flagcode f, ynm set)
3474 {
3475   if (!gc.savedFlags)
3476     {
3477       context_saveFlagSettings ();
3478     }
3479
3480   if (ynm_isOff (set))
3481     {
3482       context_setFlagAux (f, FALSE, TRUE, FALSE);
3483     }
3484   else if (ynm_isOn (set))
3485     {
3486       context_setFlagAux (f, TRUE, TRUE, FALSE);
3487       gc.setLocally[f] = TRUE;
3488     }
3489   else
3490     {
3491       context_restoreFlag (f);
3492     }
3493 }
3494
3495 static void
3496 context_restoreFlag (flagcode f)
3497 {
3498   
3499   if (!gc.savedFlags)
3500     {
3501       voptgenerror 
3502         (FLG_SYNTAX,
3503          message ("Attempt to restore flag %s when no file scope flags "
3504                   "have been set.",
3505                   flagcode_unparse (f)),
3506          g_currentloc);
3507     }
3508   else
3509     {
3510       context_addFlagMarker (f, MAYBE);
3511       context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3512     }
3513
3514   }
3515
3516 static void
3517 context_setFlag (flagcode f, bool b)
3518 {
3519   context_setFlagAux (f, b, FALSE, FALSE);
3520 }
3521
3522 void
3523 context_setFlagTemp (flagcode f, bool b)
3524 {
3525   DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3526   gc.flags[f] = b;
3527 }
3528
3529 /*@notfunction@*/
3530 # define DOSET(ff,b) \
3531    do { if (inFile) { gc.setLocally[ff] = TRUE; \
3532                       context_addFlagMarker (ff, ynm_fromBool (b)); } \
3533         DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3534         gc.flags[ff] = b; } while (FALSE)
3535
3536 static void
3537   context_setFlagAux (flagcode f, bool b, bool 
3538                       inFile, /*@unused@*/ bool isRestore)
3539 {
3540   DPRINTF (("set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3541
3542   if (f == FLG_USESTDERR) 
3543     {
3544       if (b) {
3545         g_msgstream = stderr;
3546       } else {
3547         g_msgstream = stdout;
3548       }
3549     }
3550
3551   /*
3552   ** Removed test for special flags.
3553   */
3554
3555   if (flagcode_isIdemFlag (f))
3556     {
3557       DOSET (f, TRUE);
3558     }
3559   else
3560     {
3561       DOSET (f, b);
3562     }
3563
3564   if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3565     {
3566       if (b) /* Turing higher level on, turns on all lower levels */
3567         {
3568           switch (f)
3569             {
3570             case FLG_ITS4MOSTRISKY:
3571               DOSET (FLG_ITS4VERYRISKY, b);
3572               /*@fallthrough@*/ 
3573             case FLG_ITS4VERYRISKY:
3574               DOSET (FLG_ITS4RISKY, b);
3575               /*@fallthrough@*/ 
3576             case FLG_ITS4RISKY:
3577               DOSET (FLG_ITS4MODERATERISK, b);
3578               /*@fallthrough@*/ 
3579             case FLG_ITS4MODERATERISK:
3580               DOSET (FLG_ITS4LOWRISK, b);
3581               /*@fallthrough@*/ 
3582             case FLG_ITS4LOWRISK:
3583               break;
3584               BADDEFAULT;
3585             }
3586         }
3587       else /* Turning level off, turns off all higher levels */
3588         {
3589           switch (f)
3590             {
3591             case FLG_ITS4LOWRISK:
3592               DOSET (FLG_ITS4MODERATERISK, b);
3593               /*@fallthrough@*/ 
3594             case FLG_ITS4MODERATERISK:
3595               DOSET (FLG_ITS4RISKY, b);
3596               /*@fallthrough@*/ 
3597             case FLG_ITS4RISKY:
3598               DOSET (FLG_ITS4VERYRISKY, b);
3599               /*@fallthrough@*/ 
3600             case FLG_ITS4VERYRISKY:
3601               DOSET (FLG_ITS4MOSTRISKY, b);
3602               /*@fallthrough@*/ 
3603             case FLG_ITS4MOSTRISKY:
3604               break;
3605               BADDEFAULT;
3606             }
3607         }
3608     }
3609   
3610   switch (f)
3611     {     
3612     case FLG_ALLEMPTY:
3613       DOSET (FLG_ALLEMPTY, b);
3614       DOSET (FLG_IFEMPTY, b);
3615       DOSET (FLG_WHILEEMPTY, b);
3616       DOSET (FLG_FOREMPTY, b);
3617       break;
3618     case FLG_PREDBOOL:
3619       DOSET (FLG_PREDBOOL, b);
3620       DOSET (FLG_PREDBOOLINT, b);
3621       DOSET (FLG_PREDBOOLPTR, b);
3622       DOSET (FLG_PREDBOOLOTHERS, b);
3623       break;
3624     case FLG_GLOBALIAS:
3625       DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3626       DOSET (FLG_CHECKEDGLOBALIAS, b);
3627       DOSET (FLG_CHECKMODGLOBALIAS, b);
3628       DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3629       break;
3630     case FLG_ALLBLOCK:
3631       DOSET (FLG_ALLBLOCK, b);
3632       DOSET (FLG_IFBLOCK, b);
3633       DOSET (FLG_WHILEBLOCK, b);
3634       DOSET (FLG_FORBLOCK, b);
3635       break;
3636     case FLG_GRAMMAR:
3637       if (b)
3638         {
3639           yydebug = 1;
3640           mtdebug = 1;
3641         }
3642       else
3643         {
3644           yydebug = 0;
3645           mtdebug = 0;
3646         }
3647       
3648       DOSET (FLG_GRAMMAR, b);
3649       break;
3650     case FLG_CODEIMPONLY:
3651       DOSET (FLG_CODEIMPONLY, b);
3652       DOSET (FLG_GLOBIMPONLY, b);
3653       DOSET (FLG_RETIMPONLY, b);
3654       DOSET (FLG_STRUCTIMPONLY, b);
3655       break;
3656     case FLG_SPECALLIMPONLY:
3657       DOSET (FLG_SPECALLIMPONLY, b);
3658       DOSET (FLG_SPECGLOBIMPONLY, b);
3659       DOSET (FLG_SPECRETIMPONLY, b);
3660       DOSET (FLG_SPECSTRUCTIMPONLY, b);
3661       break;
3662     case FLG_ALLIMPONLY:
3663       DOSET (FLG_ALLIMPONLY, b);
3664       DOSET (FLG_GLOBIMPONLY, b);
3665       DOSET (FLG_RETIMPONLY, b);
3666       DOSET (FLG_STRUCTIMPONLY, b);
3667       DOSET (FLG_SPECGLOBIMPONLY, b);
3668       DOSET (FLG_SPECRETIMPONLY, b);
3669       DOSET (FLG_SPECSTRUCTIMPONLY, b);
3670       break;
3671     case FLG_ANSILIMITS: 
3672       DOSET (FLG_ANSILIMITS, b);
3673       DOSET (FLG_CONTROLNESTDEPTH, b);
3674       DOSET (FLG_STRINGLITERALLEN, b);
3675       DOSET (FLG_INCLUDENEST, b);
3676       DOSET (FLG_NUMSTRUCTFIELDS, b);
3677       DOSET (FLG_NUMENUMMEMBERS, b);
3678       
3679       if (b)
3680         {
3681           context_setValue (FLG_CONTROLNESTDEPTH, DEFAULT_CONTROLNESTDEPTH);
3682           context_setValue (FLG_STRINGLITERALLEN, DEFAULT_STRINGLITERALLEN);
3683           context_setValue (FLG_INCLUDENEST, DEFAULT_INCLUDENEST);
3684           context_setValue (FLG_NUMSTRUCTFIELDS, DEFAULT_NUMSTRUCTFIELDS);
3685           context_setValue (FLG_NUMENUMMEMBERS, DEFAULT_NUMENUMMEMBERS);
3686         }
3687       break;
3688     case FLG_EXTERNALNAMELEN:
3689       DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3690       DOSET (FLG_EXTERNALNAMELEN, TRUE);
3691       break;
3692     case FLG_INTERNALNAMELEN:
3693       DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3694       DOSET (FLG_INTERNALNAMELEN, TRUE);
3695       break;
3696     case FLG_EXTERNALNAMECASEINSENSITIVE:
3697       DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3698       
3699       if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3700         {
3701           DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3702           context_setValue (FLG_EXTERNALNAMELEN, 0);
3703         }
3704       break;
3705     case FLG_INTERNALNAMECASEINSENSITIVE:
3706       DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3707       
3708       if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3709         {
3710           DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3711           context_setValue (FLG_INTERNALNAMELEN, 0);
3712         }
3713       break;
3714     case FLG_INTERNALNAMELOOKALIKE:
3715       DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3716       
3717       if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3718         {
3719           DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3720           context_setValue (FLG_INTERNALNAMELEN, 0);
3721         }
3722       break;
3723     case FLG_MODUNSPEC:
3724       DOSET (FLG_MODNOMODS, b);
3725       DOSET (FLG_MODGLOBSUNSPEC, b);
3726       DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3727       break;
3728     case FLG_EXPORTANY: 
3729       DOSET (FLG_EXPORTVAR, b);
3730       DOSET (FLG_EXPORTFCN, b);
3731       DOSET (FLG_EXPORTTYPE, b);
3732       DOSET (FLG_EXPORTMACRO, b);
3733       DOSET (FLG_EXPORTCONST, b);
3734       gc.anyExports = TRUE;
3735       break;
3736     case FLG_REPEXPOSE:
3737       DOSET (FLG_RETEXPOSE, b); 
3738       DOSET (FLG_ASSIGNEXPOSE, b); 
3739       DOSET (FLG_CASTEXPOSE, b); 
3740       break;
3741     case FLG_RETVAL:
3742       DOSET (FLG_RETVALBOOL, b);
3743       DOSET (FLG_RETVALINT, b);
3744       DOSET (FLG_RETVALOTHER, b);
3745       break;
3746     case FLG_PARTIAL:
3747       if (b)
3748         {
3749           DOSET (FLG_EXPORTLOCAL, FALSE);
3750           DOSET (FLG_DECLUNDEF, FALSE);
3751           DOSET (FLG_SPECUNDEF, FALSE);
3752           DOSET (FLG_TOPUNUSED, FALSE);
3753         }
3754       break;
3755     case FLG_DEEPBREAK:
3756       DOSET (FLG_LOOPLOOPBREAK, b);
3757       DOSET (FLG_LOOPSWITCHBREAK, b);
3758       DOSET (FLG_SWITCHLOOPBREAK, b);
3759       DOSET (FLG_SWITCHSWITCHBREAK, b);
3760       DOSET (FLG_LOOPLOOPCONTINUE, b);
3761       DOSET (FLG_DEEPBREAK, b);
3762       break;
3763     case FLG_ACCESSALL:
3764       DOSET (FLG_ACCESSMODULE, b);
3765       DOSET (FLG_ACCESSFILE, b);
3766       DOSET (FLG_ACCESSCZECH, b);
3767       break;
3768     case FLG_ALLMACROS:
3769       DOSET (FLG_ALLMACROS, b);
3770       DOSET (FLG_FCNMACROS, b);
3771       DOSET (FLG_CONSTMACROS, b);
3772       break;
3773     case FLG_CZECH:
3774       if (b) { DOSET (FLG_ACCESSCZECH, b); }
3775       DOSET (FLG_CZECHFUNCTIONS, b);
3776       DOSET (FLG_CZECHVARS, b);
3777       DOSET (FLG_CZECHCONSTANTS, b);
3778       DOSET (FLG_CZECHTYPES, b);
3779       break;
3780     case FLG_SLOVAK:
3781       if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
3782       DOSET (FLG_SLOVAKFUNCTIONS, b);
3783       DOSET (FLG_SLOVAKVARS, b);
3784       DOSET (FLG_SLOVAKCONSTANTS, b);
3785       DOSET (FLG_SLOVAKTYPES, b);
3786       break;
3787     case FLG_CZECHOSLOVAK:
3788       if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
3789       DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
3790       DOSET (FLG_CZECHOSLOVAKVARS, b);
3791       DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
3792       DOSET (FLG_CZECHOSLOVAKTYPES, b);
3793       break;
3794     case FLG_NULL:
3795       DOSET (FLG_NULLSTATE, b);
3796       DOSET (FLG_NULLDEREF, b);
3797       DOSET (FLG_NULLASSIGN, b);
3798       DOSET (FLG_NULLPASS, b);
3799       DOSET (FLG_NULLRET, b);
3800       break;
3801     case FLG_MEMCHECKS:
3802       DOSET (FLG_NULLSTATE, b);
3803       DOSET (FLG_NULLDEREF, b);
3804       DOSET (FLG_NULLASSIGN, b);
3805       DOSET (FLG_NULLPASS, b);
3806       DOSET (FLG_NULLRET, b);
3807       DOSET (FLG_COMPDEF, b);
3808       DOSET (FLG_COMPMEMPASS, b);
3809       DOSET (FLG_UNIONDEF, b);
3810       DOSET (FLG_MEMTRANS, b);
3811       DOSET (FLG_USERELEASED, b);
3812       DOSET (FLG_ALIASUNIQUE, b);
3813       DOSET (FLG_MAYALIASUNIQUE, b);
3814       DOSET (FLG_MUSTFREE, b);
3815       DOSET (FLG_MUSTDEFINE, b);
3816       DOSET (FLG_GLOBSTATE, b); 
3817       DOSET (FLG_COMPDESTROY, b);
3818       DOSET (FLG_MUSTNOTALIAS, b);
3819       DOSET (FLG_MEMIMPLICIT, b);
3820       DOSET (FLG_BRANCHSTATE, b); 
3821       /*@fallthrough@*/ /* also sets memtrans flags */
3822     case FLG_MEMTRANS:
3823       DOSET (FLG_MEMTRANS, b);
3824       DOSET (FLG_EXPOSETRANS, b);
3825       DOSET (FLG_OBSERVERTRANS, b);
3826       DOSET (FLG_DEPENDENTTRANS, b);
3827       DOSET (FLG_NEWREFTRANS, b);
3828       DOSET (FLG_ONLYTRANS, b);
3829       DOSET (FLG_OWNEDTRANS, b);
3830       DOSET (FLG_FRESHTRANS, b);
3831       DOSET (FLG_SHAREDTRANS, b);
3832       DOSET (FLG_TEMPTRANS, b);
3833       DOSET (FLG_KEPTTRANS, b);
3834       DOSET (FLG_REFCOUNTTRANS, b);
3835       DOSET (FLG_STATICTRANS, b);
3836       DOSET (FLG_UNKNOWNTRANS, b);
3837       DOSET (FLG_KEEPTRANS, b);
3838       DOSET (FLG_IMMEDIATETRANS, b);
3839       break;
3840       
3841     default:
3842       break;
3843     }
3844
3845   if (b && !gc.anyExports
3846       && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
3847           || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
3848           || f == FLG_EXPORTCONST
3849           || f == FLG_EXPORTANY))
3850     {
3851       gc.anyExports = TRUE;
3852     }
3853 }
3854
3855 bool 
3856 context_maybeSet (flagcode d)
3857 {
3858   return (gc.flags[d] || gc.setLocally[d]);
3859 }
3860
3861 bool
3862 context_getFlag (flagcode d)
3863 {
3864   return (gc.flags[d]);
3865 }
3866
3867 bool
3868 context_flagOn (flagcode f, fileloc loc)
3869 {
3870   return (!context_suppressFlagMsg (f, loc));
3871 }
3872
3873 static void context_saveFlagSettings (void)
3874 {
3875   gc.savedFlags = TRUE;
3876   llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3877   memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
3878 }
3879
3880 static void context_restoreFlagSettings (void)
3881 {
3882   llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3883   memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
3884   gc.savedFlags = FALSE;
3885 }
3886
3887 void context_setFilename (fileId fid, int lineno) 
3888    /*@globals fileloc g_currentloc;@*/
3889    /*@modifies g_currentloc@*/
3890 {
3891   if (fileId_baseEqual (currentFile (), fid))
3892     {
3893       setLine (lineno);
3894       return;
3895     }
3896   else
3897     {
3898       fileloc_setColumn (g_currentloc, 0);
3899
3900       if (fileloc_isSpecialFile (g_currentloc))
3901         {
3902           gc.inDerivedFile = TRUE;
3903         }
3904
3905       if (filelocStack_popPushFile (gc.locstack, g_currentloc))
3906         {
3907           int maxdepth = context_getValue (FLG_INCLUDENEST);
3908
3909           if (filelocStack_size (gc.locstack) > maxdepth)
3910             {
3911               int depth = filelocStack_includeDepth (gc.locstack);
3912               
3913               if (depth > maxdepth)
3914                 {
3915                   if (optgenerror 
3916                       (FLG_INCLUDENEST,
3917                        message ("Maximum include nesting depth "
3918                                 "(%d, current depth %d) exceeded",
3919                                 maxdepth,
3920                                 depth),
3921                        filelocStack_nextTop (gc.locstack)))
3922                     {
3923                       filelocStack_printIncludes (gc.locstack);
3924                     }
3925                 }
3926             }
3927         }
3928       
3929       g_currentloc = fileloc_create (fid, lineno, 1);
3930       gc.inheader = fileId_isHeader (currentFile ());
3931
3932       context_enterFileAux ();
3933     }
3934 }
3935
3936 void context_enterIterDef (/*@observer@*/ uentry le)
3937 {
3938     context_enterMacro (le);
3939   gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
3940   gc.kind = CX_ITERDEF;
3941 }
3942
3943 void context_enterIterEnd (/*@observer@*/ uentry le)
3944 {
3945     context_enterMacro (le);
3946   gc.kind = CX_ITEREND;
3947 }
3948
3949 void 
3950 context_destroyMod (void) 
3951    /*@globals killed gc@*/
3952 {
3953   setCodePoint ();
3954   ctype_destroyMod ();
3955   setCodePoint ();
3956   usymtab_free ();
3957   setCodePoint ();
3958   fileTable_free (gc.ftab);
3959   filelocStack_free (gc.locstack);
3960   setCodePoint ();
3961   gc.ftab = fileTable_undefined;
3962
3963   macrocache_free (gc.mc);
3964   sfree (gc.moduleaccess);
3965   setCodePoint ();
3966
3967   fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
3968   fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
3969
3970   setCodePoint ();
3971   sRefSetList_free (gc.modrecs);
3972   setCodePoint ();
3973   flagMarkerList_free (gc.markers); 
3974   setCodePoint ();
3975   messageLog_free (gc.msgLog);
3976   setCodePoint ();
3977   clauseStack_free (gc.clauses);
3978   setCodePoint ();
3979   
3980   cstring_free (gc.msgAnnote);
3981   globSet_free (gc.globs_used);
3982   metaStateTable_free (gc.stateTable);
3983   annotationTable_free (gc.annotTable);
3984 }
3985
3986 /*
3987 ** Flag shortcuts.
3988 */
3989
3990 bool context_msgBoolInt (void)
3991 {
3992   return gc.flags [FLG_BOOLINT];
3993 }
3994
3995 bool context_msgCharInt (void)
3996 {
3997   return gc.flags [FLG_CHARINT];
3998 }
3999
4000 bool context_msgEnumInt (void)
4001 {
4002   return gc.flags [FLG_ENUMINT];
4003 }
4004
4005 bool context_msgPointerArith (void) 
4006 {
4007   return gc.flags [FLG_POINTERARITH];
4008 }
4009
4010 bool context_msgStrictOps (void) 
4011 {
4012   return gc.flags [FLG_STRICTOPS];
4013 }
4014
4015 # ifndef NOLCL
4016 bool context_msgLh (void)           
4017 {
4018   return gc.flags [FLG_DOLH];
4019 }
4020 # endif
4021
4022 void context_pushLoc (void) 
4023 {
4024   fileloc_free (gc.pushloc);
4025   gc.pushloc = gc.saveloc;
4026   gc.saveloc = fileloc_undefined;
4027 }
4028
4029 void context_popLoc (void) 
4030 {
4031   gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4032 }
4033
4034 bool context_inGlobalScope (void)
4035 {
4036   return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4037 }
4038
4039 bool context_inInnerScope (void)
4040 {
4041   return (gc.kind == CX_INNER);
4042 }
4043
4044 void context_setProtectVars (void)
4045 {
4046   gc.protectVars = TRUE;
4047 }
4048
4049 bool context_anyErrors (void)
4050 {
4051   return (gc.numerrors > 0);
4052 }
4053
4054 void context_hasError (void)
4055 {
4056   gc.numerrors++;
4057   DPRINTF (("num errors: %d", gc.numerrors));
4058 }
4059
4060 int context_numErrors (void)
4061 {
4062   return gc.numerrors;
4063 }
4064
4065 bool context_neednl (void)
4066 {
4067   return gc.neednl;
4068 }
4069
4070 void context_setNeednl (void)
4071 {
4072   gc.neednl = TRUE;
4073 }
4074
4075 int context_getExpect (void)
4076 {
4077   return (context_getValue (FLG_EXPECT));
4078 }
4079
4080 # ifndef NOLCL
4081 int context_getLCLExpect (void)
4082 {
4083   return (context_getValue (FLG_LCLEXPECT));
4084 }
4085 # endif
4086
4087 int context_getLimit (void)
4088 {
4089   return (context_getValue (FLG_LIMIT));
4090 }
4091
4092 bool context_unlimitedMessages (void)
4093 {
4094   return (context_getLimit () < 0);
4095 }
4096
4097 void context_releaseVars (void)
4098 {
4099   llassert (gc.protectVars);
4100   gc.protectVars = FALSE;
4101 }
4102
4103 void context_sizeofReleaseVars (void)
4104 {
4105   /* If there is a nested sizeof, this might not hold:
4106      llassert (gc.protectVars);
4107      */
4108
4109   gc.protectVars = FALSE;
4110 }
4111
4112 bool context_inProtectVars (void)
4113 {
4114   return (gc.protectVars);
4115 }
4116
4117 void context_hideShowscan (void) 
4118 {
4119   gc.flags[FLG_SHOWSCAN] = FALSE;
4120 }
4121
4122 void context_unhideShowscan (void)
4123 {
4124   gc.flags[FLG_SHOWSCAN] = TRUE;
4125 }
4126
4127 bool context_inHeader (void)
4128 {
4129   return (gc.inheader);
4130 }
4131
4132 fileTable context_fileTable (void)
4133 {
4134   return gc.ftab;
4135 }
4136
4137 cstring context_tmpdir (void)
4138 {
4139   return (context_getString (FLG_TMPDIR));
4140 }
4141
4142 messageLog context_messageLog (void)
4143 {
4144   return gc.msgLog;
4145 }
4146
4147 bool context_inMacroFunction (void)
4148 {
4149   return (gc.kind == CX_MACROFCN);
4150 }
4151
4152 bool context_inMacroConstant (void)
4153 {   
4154   return (gc.kind == CX_MACROCONST);
4155 }
4156
4157 bool context_inMacroUnknown (void)
4158 {   
4159   return (gc.kind == CX_UNKNOWNMACRO);
4160 }
4161
4162 void context_setShownFunction (void)
4163 {
4164   gc.showfunction = FALSE;
4165 }
4166
4167 bool context_doDump (void)
4168 {   
4169   return cstring_isNonEmpty (context_getString (FLG_DUMP));
4170 }
4171
4172 bool context_doMerge (void)
4173 {
4174   return cstring_isNonEmpty (context_getString (FLG_MERGE));
4175 }
4176
4177 cstring context_getDump (void)
4178 {           
4179   return context_getString (FLG_DUMP);
4180 }
4181
4182 cstring context_getMerge (void)
4183 {
4184   return context_getString (FLG_MERGE);
4185 }
4186
4187 # ifndef NOLCL
4188 bool context_inLCLLib (void)
4189 {   
4190   return (gc.kind == CX_LCLLIB);
4191 }
4192
4193 bool context_inImport (void)
4194 {
4195   return (gc.inimport);
4196 }
4197
4198 void context_enterImport (void)
4199
4200   gc.inimport = TRUE;
4201 }
4202
4203 void context_leaveImport (void)
4204
4205   gc.inimport = FALSE;
4206 }
4207 # endif
4208
4209 bool context_inMacro (void) 
4210 {
4211   return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST 
4212           || gc.kind == CX_UNKNOWNMACRO
4213           || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4214 }
4215
4216 bool context_inIterDef (void)
4217 {
4218   return (gc.kind == CX_ITERDEF);
4219 }
4220
4221 bool context_inIterEnd (void)
4222 {
4223   return (gc.kind == CX_ITEREND);
4224 }
4225
4226 int context_getLinesProcessed (void)    
4227 {
4228   return (gc.linesprocessed);
4229 }
4230
4231 int context_getSpecLinesProcessed (void)    
4232 {
4233   return (gc.speclinesprocessed);
4234 }
4235
4236 # ifndef NOLCL
4237 void context_processedSpecLine (void)
4238 {
4239   gc.speclinesprocessed++;
4240 }
4241
4242 void context_resetSpecLines (void)    
4243 {
4244   gc.speclinesprocessed = 0;
4245 }
4246 # endif
4247
4248 bool context_inGlobalContext (void)
4249 {
4250   return (gc.kind == CX_GLOBAL);
4251 }
4252
4253 void context_setFileId (fileId s)
4254 {
4255   g_currentloc = fileloc_updateFileId (g_currentloc, s); 
4256 }
4257
4258 bool context_setBoolName (void)
4259 {
4260   return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4261                              DEFAULT_BOOLTYPE));
4262 }
4263
4264 cstring context_printBoolName (void)
4265 {
4266   if (context_setBoolName ()) 
4267     {
4268       return context_getBoolName ();
4269     }
4270   else
4271     {
4272       return cstring_makeLiteralTemp ("boolean");
4273     }
4274 }
4275
4276 cstring context_getBoolName (void)
4277 {
4278   return (context_getString (FLG_BOOLTYPE));
4279 }
4280
4281 cstring context_getFalseName (void)
4282 {
4283   return (context_getString (FLG_BOOLFALSE));
4284 }
4285
4286 cstring context_getTrueName (void)
4287 {
4288   return (context_getString (FLG_BOOLTRUE));
4289 }
4290
4291 cstring context_getLarchPath (void)
4292 {
4293   return (context_getString (FLG_LARCHPATH));
4294 }
4295
4296 cstring context_getLCLImportDir (void)
4297 {
4298   return (context_getString (FLG_LCLIMPORTDIR));
4299 }
4300
4301 static void context_setJustPopped (void)
4302 {
4303   gc.justpopped = TRUE;
4304 }
4305
4306 void context_clearJustPopped (void)
4307 {
4308   gc.justpopped = FALSE;
4309 }
4310
4311 bool context_justPopped (void)
4312 {
4313   return (gc.justpopped);
4314 }
4315
4316 void context_setMacroMissingParams (void)
4317 {
4318   gc.macroMissingParams = TRUE;
4319 }
4320
4321 void context_resetMacroMissingParams (void)
4322 {
4323   gc.macroMissingParams = FALSE;
4324 }
4325
4326 bool context_isMacroMissingParams (void)
4327 {
4328   return (gc.macroMissingParams);
4329 }
4330
4331 void context_showFilelocStack (void) 
4332 {
4333   filelocStack_printIncludes (gc.locstack);
4334 }
4335
4336 metaStateTable context_getMetaStateTable (void) 
4337 {
4338   return gc.stateTable;
4339 }
4340
4341 metaStateInfo context_lookupMetaStateInfo (cstring key)
4342 {
4343   return metaStateTable_lookup (gc.stateTable, key);
4344 }
4345
4346 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot) 
4347 {
4348   annotationInfo ainfo;
4349
4350   ainfo = annotationTable_lookup (gc.annotTable, annot);
4351
4352   return ainfo;
4353 }
4354
4355 void context_addAnnotation (annotationInfo ainfo)
4356 {
4357   if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4358     {
4359       voptgenerror 
4360         (FLG_SYNTAX,
4361          message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4362          annotationInfo_getLoc (ainfo));
4363
4364       annotationInfo_free (ainfo);
4365     }
4366   else
4367     {
4368       annotationTable_insert (gc.annotTable, ainfo);
4369     }
4370 }
4371
4372 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4373 {
4374   if (metaStateTable_contains (gc.stateTable, mname))
4375     {
4376       voptgenerror 
4377         (FLG_SYNTAX,
4378          message ("Duplicate metastate declaration: %s", mname),
4379          metaStateInfo_getLoc (msinfo));
4380       cstring_free (mname);
4381       metaStateInfo_free (msinfo);
4382     }
4383   else
4384     {
4385       DPRINTF (("Adding meta state: %s", mname));
4386       metaStateTable_insert (gc.stateTable, mname, msinfo); 
4387     }
4388 }
4389
4390 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4391 {
4392   if (metaStateTable_size (gc.stateTable) > 0)
4393     {
4394       valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4395       /*@i32 should use smaller value... */
4396       DPRINTF (("Value table for: %s", sRef_unparse (s)));
4397       
4398       metaStateTable_elements (gc.stateTable, msname, msi)
4399         {
4400           mtContextNode context = metaStateInfo_getContext (msi);
4401
4402           if (mtContextNode_matchesRefStrict (context, s))
4403             {
4404               DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4405               llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4406               
4407               valueTable_insert 
4408                 (res,
4409                  cstring_copy (metaStateInfo_getName (msi)),
4410                  stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s), 
4411                                             stateInfo_copy (sinfo)));
4412             }
4413           else
4414             {
4415               DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4416             }
4417         } 
4418       end_metaStateTable_elements ;
4419       
4420       stateInfo_free (sinfo);
4421       DPRINTF (("Value table: %s", valueTable_unparse (res)));
4422       return res;
4423     }
4424   else
4425     {
4426       stateInfo_free (sinfo);
4427       return valueTable_undefined;
4428     }
4429 }
4430
4431 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4432 {
4433   if (metaStateTable_size (gc.stateTable) > 0)
4434     {
4435       valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4436       /*@i32 should use smaller value... */
4437       
4438       metaStateTable_elements (gc.stateTable, msname, msi)
4439         {
4440           /*@i23 only add global...*/
4441           DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4442           llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4443           
4444           valueTable_insert (res,
4445                              cstring_copy (metaStateInfo_getName (msi)),
4446                              stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4447                                                 stateInfo_copy (sinfo)));
4448         } 
4449       end_metaStateTable_elements ;
4450       
4451       stateInfo_free (sinfo);
4452       DPRINTF (("Value table: %s", valueTable_unparse (res)));
4453       return res;
4454     }
4455   else
4456     {
4457       stateInfo_free (sinfo);
4458       return valueTable_undefined;
4459     }
4460 }
4461
4462
4463
This page took 0.405361 seconds and 5 git commands to generate.