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