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