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