]> 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)) */
6970c11b 3347 fileloc_free (gc.saveloc);
616915dd 3348 gc.saveloc = fileloc_copy (g_currentloc);
6970c11b 3349}
616915dd 3350
3351fileloc
3352context_getSaveLocation (void)
3353{
3354 fileloc fl = gc.saveloc;
6970c11b 3355 gc.saveloc = fileloc_undefined;
616915dd 3356 return fl;
3357}
3358
3359/*@observer@*/ cstring
3360context_inFunctionName (void)
3361{
3362 if (gc.kind == CX_FUNCTION
3363 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3364 || gc.kind == CX_MACROCONST
3365 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3366 {
3367 return (uentry_rawName (gc.cont.fcn));
3368 }
3369 else
3370 {
3371 llcontbuglit ("context_inFunctionName: not in function");
3372 return (cstring_undefined);
3373 }
3374}
3375
3376void
3377context_userSetFlag (flagcode f, bool b)
3378{
28bf4b0b 3379 DPRINTF (("set flag: %s", flagcode_unparse (f)));
616915dd 3380
3381 if (f == FLG_NEVERINCLUDE && b)
3382 {
3383 if (gc.flags[FLG_EXPORTHEADER])
3384 {
abb1cb43 3385 llerror_flagWarning (cstring_makeLiteral
3386 ("setting +neverinclude after +exportheader. "
3387 "Turning off exportheader, since headers are not checked "
3388 "when +neverinclude is used."));
616915dd 3389
3390 gc.flags[FLG_EXPORTHEADER] = FALSE;
3391 }
3392 }
3393 else
3394 {
3395 if (f == FLG_EXPORTHEADER && b)
3396 {
3397 if (gc.flags[FLG_NEVERINCLUDE])
3398 {
abb1cb43 3399 llerror_flagWarning (cstring_makeLiteral
3400 ("setting +exportheader after +neverinclude. "
3401 "Not setting exportheader, since headers are not checked "
3402 "when +neverinclude is used."));
616915dd 3403 gc.flags[FLG_EXPORTHEADER] = FALSE;
3404 return;
3405 }
3406 }
3407 }
3408
3409 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3410 {
3411 bool lastsetting = context_getFlag (f);
3412
3413 if (bool_equal (lastsetting, b)
3414 && !flagcode_isSpecialFlag (f)
3415 && !flagcode_isIdemFlag (f)
3416 && !flagcode_hasArgument (f))
3417 {
abb1cb43 3418 llerror_flagWarning (message ("setting %s%s redundant with current value",
3419 cstring_makeLiteralTemp (b ? "+" : "-"),
3420 flagcode_unparse (f)));
28bf4b0b 3421 }
3422 }
3423
3424 if (flagcode_isWarnUseFlag (f) && b)
3425 {
3426 if (!context_getFlag (FLG_WARNUSE))
3427 {
abb1cb43 3428 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3429 flagcode_unparse (f)));
28bf4b0b 3430
616915dd 3431 }
3432 }
3433
28bf4b0b 3434
616915dd 3435 if (flagcode_isLibraryFlag (f))
3436 {
3437 if (gc.library != FLG_ANSILIB
3438 && gc.library != f)
3439 {
abb1cb43 3440 llerror_flagWarning (message ("selecting library %s after library %s was "
3441 "selected (only one library may be used)",
3442 flagcode_unparse (f),
3443 flagcode_unparse (gc.library)));
616915dd 3444 }
3445
3446 if (f == FLG_UNIXLIB)
3447 {
3448 if (context_getFlag (FLG_WARNUNIXLIB))
3449 {
abb1cb43 3450 llerror_flagWarning (cstring_makeLiteral
3451 ("selecting unix library. Unix library is "
3452 "ad hoc addition to POSIX library. Recommend "
3453 "use +posixlib to select POSIX library instead. "
3454 "Use -warnunixlib to suppress this message."));
616915dd 3455 }
3456 }
3457
3458 gc.library = f;
3459 }
abb1cb43 3460
3461 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3462 {
3463 llerror_flagWarning (message
3464 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3465 flagcode_unparse (f)));
3466 }
3467
616915dd 3468 gc.setGlobally[f] = TRUE;
3469 context_setFlag (f, b);
3470}
3471
3472void
3473context_fileSetFlag (flagcode f, ynm set)
3474{
3475 if (!gc.savedFlags)
3476 {
3477 context_saveFlagSettings ();
3478 }
3479
3480 if (ynm_isOff (set))
3481 {
3482 context_setFlagAux (f, FALSE, TRUE, FALSE);
3483 }
3484 else if (ynm_isOn (set))
3485 {
3486 context_setFlagAux (f, TRUE, TRUE, FALSE);
3487 gc.setLocally[f] = TRUE;
3488 }
3489 else
3490 {
3491 context_restoreFlag (f);
3492 }
3493}
3494
3495static void
3496context_restoreFlag (flagcode f)
3497{
3498
3499 if (!gc.savedFlags)
3500 {
3501 voptgenerror
3502 (FLG_SYNTAX,
3503 message ("Attempt to restore flag %s when no file scope flags "
3504 "have been set.",
3505 flagcode_unparse (f)),
3506 g_currentloc);
3507 }
3508 else
3509 {
3510 context_addFlagMarker (f, MAYBE);
3511 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3512 }
3513
3514 }
3515
28bf4b0b 3516static void
616915dd 3517context_setFlag (flagcode f, bool b)
3518{
3519 context_setFlagAux (f, b, FALSE, FALSE);
3520}
3521
3522void
3523context_setFlagTemp (flagcode f, bool b)
3524{
3525 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3526 gc.flags[f] = b;
3527}
3528
3529/*@notfunction@*/
3530# define DOSET(ff,b) \
3531 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3532 context_addFlagMarker (ff, ynm_fromBool (b)); } \
28bf4b0b 3533 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
616915dd 3534 gc.flags[ff] = b; } while (FALSE)
3535
3536static void
3537 context_setFlagAux (flagcode f, bool b, bool
3538 inFile, /*@unused@*/ bool isRestore)
3539{
3540 DPRINTF (("set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3541
3542 if (f == FLG_USESTDERR)
3543 {
3544 if (b) {
3545 g_msgstream = stderr;
3546 } else {
3547 g_msgstream = stdout;
3548 }
3549 }
3550
28bf4b0b 3551 /*
3552 ** Removed test for special flags.
3553 */
616915dd 3554
28bf4b0b 3555 if (flagcode_isIdemFlag (f))
3556 {
3557 DOSET (f, TRUE);
3558 }
3559 else
3560 {
3561 DOSET (f, b);
3562 }
616915dd 3563
28bf4b0b 3564 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3565 {
3566 if (b) /* Turing higher level on, turns on all lower levels */
3567 {
3568 switch (f)
616915dd 3569 {
28bf4b0b 3570 case FLG_ITS4MOSTRISKY:
3571 DOSET (FLG_ITS4VERYRISKY, b);
3572 /*@fallthrough@*/
3573 case FLG_ITS4VERYRISKY:
3574 DOSET (FLG_ITS4RISKY, b);
3575 /*@fallthrough@*/
3576 case FLG_ITS4RISKY:
3577 DOSET (FLG_ITS4MODERATERISK, b);
3578 /*@fallthrough@*/
3579 case FLG_ITS4MODERATERISK:
3580 DOSET (FLG_ITS4LOWRISK, b);
3581 /*@fallthrough@*/
3582 case FLG_ITS4LOWRISK:
3583 break;
3584 BADDEFAULT;
616915dd 3585 }
28bf4b0b 3586 }
3587 else /* Turning level off, turns off all higher levels */
3588 {
3589 switch (f)
616915dd 3590 {
28bf4b0b 3591 case FLG_ITS4LOWRISK:
3592 DOSET (FLG_ITS4MODERATERISK, b);
3593 /*@fallthrough@*/
3594 case FLG_ITS4MODERATERISK:
3595 DOSET (FLG_ITS4RISKY, b);
3596 /*@fallthrough@*/
3597 case FLG_ITS4RISKY:
3598 DOSET (FLG_ITS4VERYRISKY, b);
3599 /*@fallthrough@*/
3600 case FLG_ITS4VERYRISKY:
3601 DOSET (FLG_ITS4MOSTRISKY, b);
3602 /*@fallthrough@*/
3603 case FLG_ITS4MOSTRISKY:
3604 break;
3605 BADDEFAULT;
616915dd 3606 }
616915dd 3607 }
3608 }
28bf4b0b 3609
3610 switch (f)
3611 {
3612 case FLG_ALLEMPTY:
3613 DOSET (FLG_ALLEMPTY, b);
3614 DOSET (FLG_IFEMPTY, b);
3615 DOSET (FLG_WHILEEMPTY, b);
3616 DOSET (FLG_FOREMPTY, b);
3617 break;
3618 case FLG_PREDBOOL:
3619 DOSET (FLG_PREDBOOL, b);
3620 DOSET (FLG_PREDBOOLINT, b);
3621 DOSET (FLG_PREDBOOLPTR, b);
3622 DOSET (FLG_PREDBOOLOTHERS, b);
3623 break;
3624 case FLG_GLOBALIAS:
3625 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3626 DOSET (FLG_CHECKEDGLOBALIAS, b);
3627 DOSET (FLG_CHECKMODGLOBALIAS, b);
3628 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3629 break;
3630 case FLG_ALLBLOCK:
3631 DOSET (FLG_ALLBLOCK, b);
3632 DOSET (FLG_IFBLOCK, b);
3633 DOSET (FLG_WHILEBLOCK, b);
3634 DOSET (FLG_FORBLOCK, b);
3635 break;
3636 case FLG_GRAMMAR:
3637 if (b)
616915dd 3638 {
28bf4b0b 3639 yydebug = 1;
3640 mtdebug = 1;
616915dd 3641 }
3642 else
3643 {
28bf4b0b 3644 yydebug = 0;
3645 mtdebug = 0;
3646 }
3647
3648 DOSET (FLG_GRAMMAR, b);
3649 break;
3650 case FLG_CODEIMPONLY:
3651 DOSET (FLG_CODEIMPONLY, b);
3652 DOSET (FLG_GLOBIMPONLY, b);
3653 DOSET (FLG_RETIMPONLY, b);
3654 DOSET (FLG_STRUCTIMPONLY, b);
3655 break;
3656 case FLG_SPECALLIMPONLY:
3657 DOSET (FLG_SPECALLIMPONLY, b);
3658 DOSET (FLG_SPECGLOBIMPONLY, b);
3659 DOSET (FLG_SPECRETIMPONLY, b);
3660 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3661 break;
3662 case FLG_ALLIMPONLY:
3663 DOSET (FLG_ALLIMPONLY, b);
3664 DOSET (FLG_GLOBIMPONLY, b);
3665 DOSET (FLG_RETIMPONLY, b);
3666 DOSET (FLG_STRUCTIMPONLY, b);
3667 DOSET (FLG_SPECGLOBIMPONLY, b);
3668 DOSET (FLG_SPECRETIMPONLY, b);
3669 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3670 break;
3671 case FLG_ANSILIMITS:
3672 DOSET (FLG_ANSILIMITS, b);
3673 DOSET (FLG_CONTROLNESTDEPTH, b);
3674 DOSET (FLG_STRINGLITERALLEN, b);
3675 DOSET (FLG_INCLUDENEST, b);
3676 DOSET (FLG_NUMSTRUCTFIELDS, b);
3677 DOSET (FLG_NUMENUMMEMBERS, b);
3678
3679 if (b)
3680 {
3681 context_setValue (FLG_CONTROLNESTDEPTH, DEFAULT_CONTROLNESTDEPTH);
3682 context_setValue (FLG_STRINGLITERALLEN, DEFAULT_STRINGLITERALLEN);
3683 context_setValue (FLG_INCLUDENEST, DEFAULT_INCLUDENEST);
3684 context_setValue (FLG_NUMSTRUCTFIELDS, DEFAULT_NUMSTRUCTFIELDS);
3685 context_setValue (FLG_NUMENUMMEMBERS, DEFAULT_NUMENUMMEMBERS);
3686 }
3687 break;
3688 case FLG_EXTERNALNAMELEN:
3689 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3690 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3691 break;
3692 case FLG_INTERNALNAMELEN:
3693 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3694 DOSET (FLG_INTERNALNAMELEN, TRUE);
3695 break;
3696 case FLG_EXTERNALNAMECASEINSENSITIVE:
3697 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3698
3699 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3700 {
3701 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3702 context_setValue (FLG_EXTERNALNAMELEN, 0);
3703 }
3704 break;
3705 case FLG_INTERNALNAMECASEINSENSITIVE:
3706 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3707
3708 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3709 {
3710 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3711 context_setValue (FLG_INTERNALNAMELEN, 0);
3712 }
3713 break;
3714 case FLG_INTERNALNAMELOOKALIKE:
3715 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3716
3717 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3718 {
3719 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3720 context_setValue (FLG_INTERNALNAMELEN, 0);
616915dd 3721 }
28bf4b0b 3722 break;
3723 case FLG_MODUNSPEC:
3724 DOSET (FLG_MODNOMODS, b);
3725 DOSET (FLG_MODGLOBSUNSPEC, b);
3726 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3727 break;
3728 case FLG_EXPORTANY:
3729 DOSET (FLG_EXPORTVAR, b);
3730 DOSET (FLG_EXPORTFCN, b);
3731 DOSET (FLG_EXPORTTYPE, b);
3732 DOSET (FLG_EXPORTMACRO, b);
3733 DOSET (FLG_EXPORTCONST, b);
3734 gc.anyExports = TRUE;
3735 break;
3736 case FLG_REPEXPOSE:
3737 DOSET (FLG_RETEXPOSE, b);
3738 DOSET (FLG_ASSIGNEXPOSE, b);
3739 DOSET (FLG_CASTEXPOSE, b);
3740 break;
3741 case FLG_RETVAL:
3742 DOSET (FLG_RETVALBOOL, b);
3743 DOSET (FLG_RETVALINT, b);
3744 DOSET (FLG_RETVALOTHER, b);
3745 break;
3746 case FLG_PARTIAL:
3747 if (b)
3748 {
3749 DOSET (FLG_EXPORTLOCAL, FALSE);
3750 DOSET (FLG_DECLUNDEF, FALSE);
3751 DOSET (FLG_SPECUNDEF, FALSE);
3752 DOSET (FLG_TOPUNUSED, FALSE);
3753 }
3754 break;
3755 case FLG_DEEPBREAK:
3756 DOSET (FLG_LOOPLOOPBREAK, b);
3757 DOSET (FLG_LOOPSWITCHBREAK, b);
3758 DOSET (FLG_SWITCHLOOPBREAK, b);
3759 DOSET (FLG_SWITCHSWITCHBREAK, b);
3760 DOSET (FLG_LOOPLOOPCONTINUE, b);
3761 DOSET (FLG_DEEPBREAK, b);
3762 break;
3763 case FLG_ACCESSALL:
3764 DOSET (FLG_ACCESSMODULE, b);
3765 DOSET (FLG_ACCESSFILE, b);
3766 DOSET (FLG_ACCESSCZECH, b);
3767 break;
3768 case FLG_ALLMACROS:
3769 DOSET (FLG_ALLMACROS, b);
3770 DOSET (FLG_FCNMACROS, b);
3771 DOSET (FLG_CONSTMACROS, b);
3772 break;
3773 case FLG_CZECH:
3774 if (b) { DOSET (FLG_ACCESSCZECH, b); }
3775 DOSET (FLG_CZECHFUNCTIONS, b);
3776 DOSET (FLG_CZECHVARS, b);
3777 DOSET (FLG_CZECHCONSTANTS, b);
3778 DOSET (FLG_CZECHTYPES, b);
3779 break;
3780 case FLG_SLOVAK:
3781 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
3782 DOSET (FLG_SLOVAKFUNCTIONS, b);
3783 DOSET (FLG_SLOVAKVARS, b);
3784 DOSET (FLG_SLOVAKCONSTANTS, b);
3785 DOSET (FLG_SLOVAKTYPES, b);
3786 break;
3787 case FLG_CZECHOSLOVAK:
3788 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
3789 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
3790 DOSET (FLG_CZECHOSLOVAKVARS, b);
3791 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
3792 DOSET (FLG_CZECHOSLOVAKTYPES, b);
3793 break;
3794 case FLG_NULL:
3795 DOSET (FLG_NULLSTATE, b);
3796 DOSET (FLG_NULLDEREF, b);
3797 DOSET (FLG_NULLASSIGN, b);
3798 DOSET (FLG_NULLPASS, b);
3799 DOSET (FLG_NULLRET, b);
3800 break;
3801 case FLG_MEMCHECKS:
3802 DOSET (FLG_NULLSTATE, b);
3803 DOSET (FLG_NULLDEREF, b);
3804 DOSET (FLG_NULLASSIGN, b);
3805 DOSET (FLG_NULLPASS, b);
3806 DOSET (FLG_NULLRET, b);
3807 DOSET (FLG_COMPDEF, b);
3808 DOSET (FLG_COMPMEMPASS, b);
3809 DOSET (FLG_UNIONDEF, b);
3810 DOSET (FLG_MEMTRANS, b);
3811 DOSET (FLG_USERELEASED, b);
3812 DOSET (FLG_ALIASUNIQUE, b);
3813 DOSET (FLG_MAYALIASUNIQUE, b);
3814 DOSET (FLG_MUSTFREE, b);
3815 DOSET (FLG_MUSTDEFINE, b);
3816 DOSET (FLG_GLOBSTATE, b);
3817 DOSET (FLG_COMPDESTROY, b);
3818 DOSET (FLG_MUSTNOTALIAS, b);
3819 DOSET (FLG_MEMIMPLICIT, b);
3820 DOSET (FLG_BRANCHSTATE, b);
3821 /*@fallthrough@*/ /* also sets memtrans flags */
3822 case FLG_MEMTRANS:
3823 DOSET (FLG_MEMTRANS, b);
3824 DOSET (FLG_EXPOSETRANS, b);
3825 DOSET (FLG_OBSERVERTRANS, b);
3826 DOSET (FLG_DEPENDENTTRANS, b);
3827 DOSET (FLG_NEWREFTRANS, b);
3828 DOSET (FLG_ONLYTRANS, b);
3829 DOSET (FLG_OWNEDTRANS, b);
3830 DOSET (FLG_FRESHTRANS, b);
3831 DOSET (FLG_SHAREDTRANS, b);
3832 DOSET (FLG_TEMPTRANS, b);
3833 DOSET (FLG_KEPTTRANS, b);
3834 DOSET (FLG_REFCOUNTTRANS, b);
3835 DOSET (FLG_STATICTRANS, b);
3836 DOSET (FLG_UNKNOWNTRANS, b);
3837 DOSET (FLG_KEEPTRANS, b);
3838 DOSET (FLG_IMMEDIATETRANS, b);
3839 break;
3840
3841 default:
3842 break;
3843 }
3844
3845 if (b && !gc.anyExports
3846 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
3847 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
3848 || f == FLG_EXPORTCONST
3849 || f == FLG_EXPORTANY))
3850 {
3851 gc.anyExports = TRUE;
616915dd 3852 }
3853}
3854
3855bool
3856context_maybeSet (flagcode d)
3857{
3858 return (gc.flags[d] || gc.setLocally[d]);
3859}
3860
3861bool
3862context_getFlag (flagcode d)
3863{
3864 return (gc.flags[d]);
3865}
3866
28bf4b0b 3867bool
3868context_flagOn (flagcode f, fileloc loc)
3869{
3870 return (!context_suppressFlagMsg (f, loc));
3871}
3872
616915dd 3873static void context_saveFlagSettings (void)
3874{
3875 gc.savedFlags = TRUE;
3876 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3877 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
3878}
3879
3880static void context_restoreFlagSettings (void)
3881{
3882 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3883 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
3884 gc.savedFlags = FALSE;
3885}
3886
3887void context_setFilename (fileId fid, int lineno)
3888 /*@globals fileloc g_currentloc;@*/
3889 /*@modifies g_currentloc@*/
3890{
3891 if (fileId_baseEqual (currentFile (), fid))
3892 {
3893 setLine (lineno);
3894 return;
3895 }
3896 else
3897 {
3898 fileloc_setColumn (g_currentloc, 0);
3899
3900 if (fileloc_isSpecialFile (g_currentloc))
3901 {
3902 gc.inDerivedFile = TRUE;
3903 }
3904
3905 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
3906 {
3907 int maxdepth = context_getValue (FLG_INCLUDENEST);
3908
3909 if (filelocStack_size (gc.locstack) > maxdepth)
3910 {
3911 int depth = filelocStack_includeDepth (gc.locstack);
3912
3913 if (depth > maxdepth)
3914 {
3915 if (optgenerror
3916 (FLG_INCLUDENEST,
3917 message ("Maximum include nesting depth "
3918 "(%d, current depth %d) exceeded",
3919 maxdepth,
3920 depth),
3921 filelocStack_nextTop (gc.locstack)))
3922 {
3923 filelocStack_printIncludes (gc.locstack);
3924 }
3925 }
3926 }
3927 }
3928
3929 g_currentloc = fileloc_create (fid, lineno, 1);
3930 gc.inheader = fileId_isHeader (currentFile ());
3931
3932 context_enterFileAux ();
3933 }
3934}
3935
3936void context_enterIterDef (/*@observer@*/ uentry le)
3937{
3938 context_enterMacro (le);
3939 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
3940 gc.kind = CX_ITERDEF;
3941}
3942
3943void context_enterIterEnd (/*@observer@*/ uentry le)
3944{
3945 context_enterMacro (le);
3946 gc.kind = CX_ITEREND;
3947}
3948
3949void
3950context_destroyMod (void)
3951 /*@globals killed gc@*/
3952{
3953 setCodePoint ();
3954 ctype_destroyMod ();
3955 setCodePoint ();
3956 usymtab_free ();
3957 setCodePoint ();
3958 fileTable_free (gc.ftab);
3959 filelocStack_free (gc.locstack);
3960 setCodePoint ();
3961 gc.ftab = fileTable_undefined;
3962
3963 macrocache_free (gc.mc);
3964 sfree (gc.moduleaccess);
3965 setCodePoint ();
3966
3967 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
3968 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
3969
3970 setCodePoint ();
3971 sRefSetList_free (gc.modrecs);
3972 setCodePoint ();
3973 flagMarkerList_free (gc.markers);
3974 setCodePoint ();
3975 messageLog_free (gc.msgLog);
3976 setCodePoint ();
3977 clauseStack_free (gc.clauses);
3978 setCodePoint ();
3979
3980 cstring_free (gc.msgAnnote);
3981 globSet_free (gc.globs_used);
28bf4b0b 3982 metaStateTable_free (gc.stateTable);
3983 annotationTable_free (gc.annotTable);
3984}
616915dd 3985
3986/*
3987** Flag shortcuts.
3988*/
3989
3990bool context_msgBoolInt (void)
3991{
3992 return gc.flags [FLG_BOOLINT];
3993}
3994
3995bool context_msgCharInt (void)
3996{
3997 return gc.flags [FLG_CHARINT];
3998}
3999
4000bool context_msgEnumInt (void)
4001{
4002 return gc.flags [FLG_ENUMINT];
4003}
4004
4005bool context_msgPointerArith (void)
4006{
4007 return gc.flags [FLG_POINTERARITH];
4008}
4009
4010bool context_msgStrictOps (void)
4011{
4012 return gc.flags [FLG_STRICTOPS];
4013}
4014
4015# ifndef NOLCL
4016bool context_msgLh (void)
4017{
4018 return gc.flags [FLG_DOLH];
4019}
4020# endif
4021
4022void context_pushLoc (void)
4023{
4024 fileloc_free (gc.pushloc);
4025 gc.pushloc = gc.saveloc;
4026 gc.saveloc = fileloc_undefined;
4027}
4028
4029void context_popLoc (void)
4030{
4031 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4032}
4033
4034bool context_inGlobalScope (void)
4035{
4036 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4037}
4038
4039bool context_inInnerScope (void)
4040{
4041 return (gc.kind == CX_INNER);
4042}
4043
4044void context_setProtectVars (void)
4045{
4046 gc.protectVars = TRUE;
4047}
4048
4049bool context_anyErrors (void)
4050{
4051 return (gc.numerrors > 0);
4052}
4053
4054void context_hasError (void)
4055{
4056 gc.numerrors++;
ccf0a4a8 4057 DPRINTF (("num errors: %d", gc.numerrors));
616915dd 4058}
4059
4060int context_numErrors (void)
4061{
4062 return gc.numerrors;
4063}
4064
4065bool context_neednl (void)
4066{
4067 return gc.neednl;
4068}
4069
4070void context_setNeednl (void)
4071{
4072 gc.neednl = TRUE;
4073}
4074
4075int context_getExpect (void)
4076{
4077 return (context_getValue (FLG_EXPECT));
4078}
4079
4080# ifndef NOLCL
4081int context_getLCLExpect (void)
4082{
4083 return (context_getValue (FLG_LCLEXPECT));
4084}
4085# endif
4086
4087int context_getLimit (void)
4088{
4089 return (context_getValue (FLG_LIMIT));
4090}
4091
4092bool context_unlimitedMessages (void)
4093{
4094 return (context_getLimit () < 0);
4095}
4096
4097void context_releaseVars (void)
4098{
4099 llassert (gc.protectVars);
4100 gc.protectVars = FALSE;
4101}
4102
4103void context_sizeofReleaseVars (void)
4104{
4105 /* If there is a nested sizeof, this might not hold:
4106 llassert (gc.protectVars);
4107 */
4108
4109 gc.protectVars = FALSE;
4110}
4111
4112bool context_inProtectVars (void)
4113{
4114 return (gc.protectVars);
4115}
4116
4117void context_hideShowscan (void)
4118{
4119 gc.flags[FLG_SHOWSCAN] = FALSE;
4120}
4121
4122void context_unhideShowscan (void)
4123{
4124 gc.flags[FLG_SHOWSCAN] = TRUE;
4125}
4126
4127bool context_inHeader (void)
4128{
4129 return (gc.inheader);
4130}
4131
4132fileTable context_fileTable (void)
4133{
4134 return gc.ftab;
4135}
4136
4137cstring context_tmpdir (void)
4138{
4139 return (context_getString (FLG_TMPDIR));
4140}
4141
4142messageLog context_messageLog (void)
4143{
4144 return gc.msgLog;
4145}
4146
4147bool context_inMacroFunction (void)
4148{
4149 return (gc.kind == CX_MACROFCN);
4150}
4151
4152bool context_inMacroConstant (void)
4153{
4154 return (gc.kind == CX_MACROCONST);
4155}
4156
4157bool context_inMacroUnknown (void)
4158{
4159 return (gc.kind == CX_UNKNOWNMACRO);
4160}
4161
4162void context_setShownFunction (void)
4163{
4164 gc.showfunction = FALSE;
4165}
4166
4167bool context_doDump (void)
4168{
4169 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4170}
4171
4172bool context_doMerge (void)
4173{
4174 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4175}
4176
4177cstring context_getDump (void)
4178{
4179 return context_getString (FLG_DUMP);
4180}
4181
4182cstring context_getMerge (void)
4183{
4184 return context_getString (FLG_MERGE);
4185}
4186
4187# ifndef NOLCL
4188bool context_inLCLLib (void)
4189{
4190 return (gc.kind == CX_LCLLIB);
4191}
4192
4193bool context_inImport (void)
4194{
4195 return (gc.inimport);
4196}
4197
4198void context_enterImport (void)
4199{
4200 gc.inimport = TRUE;
4201}
4202
4203void context_leaveImport (void)
4204{
4205 gc.inimport = FALSE;
4206}
4207# endif
4208
4209bool context_inMacro (void)
4210{
4211 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4212 || gc.kind == CX_UNKNOWNMACRO
4213 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4214}
4215
4216bool context_inIterDef (void)
4217{
4218 return (gc.kind == CX_ITERDEF);
4219}
4220
4221bool context_inIterEnd (void)
4222{
4223 return (gc.kind == CX_ITEREND);
4224}
4225
4226int context_getLinesProcessed (void)
4227{
4228 return (gc.linesprocessed);
4229}
4230
4231int context_getSpecLinesProcessed (void)
4232{
4233 return (gc.speclinesprocessed);
4234}
4235
4236# ifndef NOLCL
4237void context_processedSpecLine (void)
4238{
4239 gc.speclinesprocessed++;
4240}
4241
4242void context_resetSpecLines (void)
4243{
4244 gc.speclinesprocessed = 0;
4245}
4246# endif
4247
4248bool context_inGlobalContext (void)
4249{
4250 return (gc.kind == CX_GLOBAL);
4251}
4252
4253void context_setFileId (fileId s)
4254{
4255 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4256}
4257
4258bool context_setBoolName (void)
4259{
4260 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4261 DEFAULT_BOOLTYPE));
4262}
4263
4264cstring context_printBoolName (void)
4265{
4266 if (context_setBoolName ())
4267 {
4268 return context_getBoolName ();
4269 }
4270 else
4271 {
4272 return cstring_makeLiteralTemp ("boolean");
4273 }
4274}
4275
4276cstring context_getBoolName (void)
4277{
4278 return (context_getString (FLG_BOOLTYPE));
4279}
4280
4281cstring context_getFalseName (void)
4282{
4283 return (context_getString (FLG_BOOLFALSE));
4284}
4285
4286cstring context_getTrueName (void)
4287{
4288 return (context_getString (FLG_BOOLTRUE));
4289}
4290
4291cstring context_getLarchPath (void)
4292{
4293 return (context_getString (FLG_LARCHPATH));
4294}
4295
4296cstring context_getLCLImportDir (void)
4297{
4298 return (context_getString (FLG_LCLIMPORTDIR));
4299}
4300
4301static void context_setJustPopped (void)
4302{
4303 gc.justpopped = TRUE;
4304}
4305
4306void context_clearJustPopped (void)
4307{
4308 gc.justpopped = FALSE;
4309}
4310
4311bool context_justPopped (void)
4312{
4313 return (gc.justpopped);
4314}
4315
4316void context_setMacroMissingParams (void)
4317{
4318 gc.macroMissingParams = TRUE;
4319}
4320
4321void context_resetMacroMissingParams (void)
4322{
4323 gc.macroMissingParams = FALSE;
4324}
4325
4326bool context_isMacroMissingParams (void)
4327{
4328 return (gc.macroMissingParams);
4329}
4330
4331void context_showFilelocStack (void)
4332{
4333 filelocStack_printIncludes (gc.locstack);
4334}
4335
28bf4b0b 4336metaStateTable context_getMetaStateTable (void)
4337{
4338 return gc.stateTable;
4339}
4340
4341metaStateInfo context_lookupMetaStateInfo (cstring key)
4342{
4343 return metaStateTable_lookup (gc.stateTable, key);
4344}
4345
4346/*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4347{
4348 annotationInfo ainfo;
4349
4350 ainfo = annotationTable_lookup (gc.annotTable, annot);
4351
4352 return ainfo;
4353}
4354
4355void context_addAnnotation (annotationInfo ainfo)
4356{
4357 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4358 {
4359 voptgenerror
4360 (FLG_SYNTAX,
4361 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4362 annotationInfo_getLoc (ainfo));
4363
4364 annotationInfo_free (ainfo);
4365 }
4366 else
4367 {
4368 annotationTable_insert (gc.annotTable, ainfo);
4369 }
4370}
4371
4372void context_addMetaState (cstring mname, metaStateInfo msinfo)
4373{
4374 if (metaStateTable_contains (gc.stateTable, mname))
4375 {
4376 voptgenerror
4377 (FLG_SYNTAX,
4378 message ("Duplicate metastate declaration: %s", mname),
4379 metaStateInfo_getLoc (msinfo));
4380 cstring_free (mname);
4381 metaStateInfo_free (msinfo);
4382 }
4383 else
4384 {
990ec868 4385 DPRINTF (("Adding meta state: %s", mname));
28bf4b0b 4386 metaStateTable_insert (gc.stateTable, mname, msinfo);
4387 }
4388}
616915dd 4389
6970c11b 4390valueTable context_createValueTable (sRef s, stateInfo sinfo)
28bf4b0b 4391{
4392 if (metaStateTable_size (gc.stateTable) > 0)
4393 {
4394 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4395 /*@i32 should use smaller value... */
4396 DPRINTF (("Value table for: %s", sRef_unparse (s)));
990ec868 4397
28bf4b0b 4398 metaStateTable_elements (gc.stateTable, msname, msi)
4399 {
4400 mtContextNode context = metaStateInfo_getContext (msi);
616915dd 4401
28bf4b0b 4402 if (mtContextNode_matchesRefStrict (context, s))
4403 {
4404 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4405 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4406
990ec868 4407 valueTable_insert
4408 (res,
4409 cstring_copy (metaStateInfo_getName (msi)),
6970c11b 4410 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4411 stateInfo_copy (sinfo)));
28bf4b0b 4412 }
4413 else
4414 {
4415 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4416 }
4417 }
4418 end_metaStateTable_elements ;
4419
6970c11b 4420 stateInfo_free (sinfo);
28bf4b0b 4421 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4422 return res;
4423 }
4424 else
4425 {
6970c11b 4426 stateInfo_free (sinfo);
28bf4b0b 4427 return valueTable_undefined;
4428 }
4429}
616915dd 4430
6970c11b 4431valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
28bf4b0b 4432{
4433 if (metaStateTable_size (gc.stateTable) > 0)
4434 {
4435 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4436 /*@i32 should use smaller value... */
4437
4438 metaStateTable_elements (gc.stateTable, msname, msi)
4439 {
4440 /*@i23 only add global...*/
4441 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4442 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4443
4444 valueTable_insert (res,
4445 cstring_copy (metaStateInfo_getName (msi)),
4446 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
6970c11b 4447 stateInfo_copy (sinfo)));
28bf4b0b 4448 }
4449 end_metaStateTable_elements ;
4450
6970c11b 4451 stateInfo_free (sinfo);
28bf4b0b 4452 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4453 return res;
4454 }
4455 else
4456 {
6970c11b 4457 stateInfo_free (sinfo);
28bf4b0b 4458 return valueTable_undefined;
4459 }
4460}
616915dd 4461
4462
4463
This page took 0.69757 seconds and 5 git commands to generate.