]> 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"
990ec868 38# include "mtincludes.h"
616915dd 39
40# ifndef NOLCL
41# include "usymtab_interface.h"
42# endif
43
44# include "exprChecks.h"
45# include "filelocStack.h"
46# include "fileIdList.h"
47# include "llmain.h"
48# include "intSet.h"
49# include "osd.h"
50# include "portab.h"
51
52extern /*@external@*/ int yydebug;
28bf4b0b 53extern /*@external@*/ int mtdebug;
616915dd 54
55typedef struct
56{
57 cstring file;
58 typeIdSet daccess ;
59} maccesst;
60
61typedef enum {
28bf4b0b 62 CX_ERROR,
63
616915dd 64 CX_GLOBAL, CX_INNER,
28bf4b0b 65 CX_FUNCTION, CX_FCNHEADER, CX_FCNDECLARATION,
616915dd 66 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
67 CX_ITERDEF, CX_ITEREND,
28bf4b0b 68 CX_LCL, CX_LCLLIB, CX_MT
616915dd 69} kcontext;
70
28bf4b0b 71static struct
616915dd 72{
73 int linesprocessed;
74 int speclinesprocessed;
75
76 flagMarkerList markers;
77
78 /*
79 ** used to record state where a macro must match a function name
80 ** (i.e., no params were listed in the macro definition
81 */
82
83 bool macroMissingParams BOOLBITS;
84 bool preprocessing BOOLBITS;
85 bool incommandline BOOLBITS;
86 bool insuppressregion BOOLBITS;
87 bool inDerivedFile BOOLBITS;
88 bool instandardlib BOOLBITS;
89 bool inimport BOOLBITS;
90 bool inheader BOOLBITS;
91 bool inmacrocache BOOLBITS;
92 bool protectVars BOOLBITS;
93 bool neednl BOOLBITS;
94 bool showfunction BOOLBITS;
95 bool savedFlags BOOLBITS;
96 bool justpopped BOOLBITS;
97 bool anyExports BOOLBITS;
98
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
702context_resetAllFlags (void)
703{
704 allFlagCodes (code)
705 {
706 gc.flags[code] = FALSE;
707
708 if (flagcode_hasValue (code))
709 {
710 int val = 0;
711
712 /*@-loopswitchbreak@*/
713 switch (code)
714 {
715 case FLG_LIMIT:
716 val = DEFAULT_LIMIT; break;
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);
1299 char *nextdir = strchr (thisdir, SEPCHAR);
1300
1301 if (nextdir != NULL)
1302 {
1303 *nextdir = '\0';
1304 nextdir += 1;
1305 }
1306
1307 while (thisdir != NULL)
1308 {
1309 DPRINTF (("Test: %s / %s", dir, thisdir));
1310
1311 if (cstring_equalCanonicalPrefix (dir, thisdir))
1312 {
1313 if (nextdir != NULL)
1314 {
1315 *(nextdir - 1) = SEPCHAR;
1316 }
1317
1318 return TRUE;
1319 }
1320
1321 if (nextdir != NULL)
1322 {
1323 *(nextdir - 1) = SEPCHAR;
1324 }
1325
1326 if (nextdir != NULL)
1327 {
1328 thisdir = nextdir;
1329 nextdir = strchr (thisdir, SEPCHAR);
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{
1380 llassert (gc.kind == CX_GLOBAL);
28bf4b0b 1381 DPRINTF (("Enter function decl"));
1382 gc.kind = CX_FCNHEADER;
616915dd 1383}
1384
28bf4b0b 1385void context_exitFunctionHeader (void)
616915dd 1386{
28bf4b0b 1387 DPRINTF (("Exit function decl"));
616915dd 1388 gc.kind = CX_GLOBAL;
1389}
1390
28bf4b0b 1391bool context_inFunctionHeader (void)
1392{
1393 return (gc.kind == CX_FCNHEADER);
1394}
1395
1396void context_enterFunctionDeclaration (uentry e)
1397{
1398 DPRINTF (("Enter function decl"));
1399 llassert (gc.savekind == CX_ERROR);
1400 gc.savekind = gc.kind;
1401 gc.kind = CX_FCNDECLARATION;
1402 gc.cont.fcn = e;
1403}
1404
1405void context_exitFunctionDeclaration (void)
616915dd 1406{
28bf4b0b 1407 DPRINTF (("Exit function decl"));
1408 llassert (gc.savekind != CX_ERROR);
1409 llassert (gc.kind == CX_FCNDECLARATION);
1410 gc.kind = gc.savekind;
1411 gc.cont.fcn = uentry_undefined;
1412 gc.savekind = CX_ERROR;
616915dd 1413}
1414
28bf4b0b 1415bool context_inFunctionDeclaration (void)
1416{
1417 return (gc.kind == CX_FCNDECLARATION);
1418}
1419
1420
616915dd 1421void
1422context_enterMacro (/*@observer@*/ uentry e)
1423{
1424 context_enterFunction (e);
1425 gc.kind = CX_MACROFCN;
1426}
1427
1428void
1429context_enterUnknownMacro (/*@dependent@*/ uentry e)
1430{
1431 llassert (uentry_isFunction (e));
1432 context_enterFunction (e);
1433 gc.kind = CX_UNKNOWNMACRO;
1434}
1435
1436void context_enterAndClause (exprNode e)
1437{
1438
1439 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1440 pushClause (ANDCLAUSE);
1441}
1442
1443void context_enterOrClause (exprNode e)
1444{
1445 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1446 pushClause (ORCLAUSE);
1447}
1448
1449bool context_inDeepLoop (void)
1450{
1451 bool inLoop = FALSE;
1452
1453 clauseStack_elements (gc.clauses, el)
1454 {
1455 if (clause_isLoop (el))
1456 {
1457 if (inLoop)
1458 {
1459 return TRUE;
1460 }
1461
1462 inLoop = TRUE;
1463 }
1464 } end_clauseStack_elements;
1465
1466 return FALSE;
1467}
1468
1469bool context_inDeepSwitch (void)
1470{
1471 bool inLoop = FALSE;
1472
1473 clauseStack_elements (gc.clauses, el)
1474 {
1475 if (clause_isSwitch (el))
1476 {
1477 if (inLoop)
1478 {
1479 return TRUE;
1480 }
1481
1482 inLoop = TRUE;
1483 }
1484 } end_clauseStack_elements;
1485
1486 return FALSE;
1487}
1488
1489bool context_inDeepLoopSwitch (void)
1490{
1491 bool inLoop = FALSE;
1492
1493 clauseStack_elements (gc.clauses, el)
1494 {
1495 if (clause_isBreakable (el))
1496 {
1497 if (inLoop)
1498 {
1499 return TRUE;
1500 }
1501
1502 inLoop = TRUE;
1503 }
1504 } end_clauseStack_elements;
1505
1506 return FALSE;
1507}
1508
1509clause context_breakClause (void)
1510{
1511 clauseStack_elements (gc.clauses, el)
1512 {
1513 if (clause_isSwitch (el))
1514 {
1515 return el;
1516 }
1517 else if (clause_isLoop (el))
1518 {
1519 return el;
1520 }
1521 else
1522 {
1523 ;
1524 }
1525 } end_clauseStack_elements;
1526
1527 return NOCLAUSE;
1528}
1529
1530clause context_nextBreakClause (void)
1531{
1532 bool hasOne = FALSE;
1533
1534 clauseStack_elements (gc.clauses, el)
1535 {
1536 if (clause_isBreakable (el))
1537 {
1538 if (hasOne)
1539 {
1540 return el;
1541 }
1542 else
1543 {
1544 hasOne = TRUE;
1545 }
1546 }
1547 } end_clauseStack_elements;
1548
1549 return NOCLAUSE;
1550}
1551
1552bool context_inConditional (void)
1553{
1554 clauseStack_elements (gc.clauses, el)
1555 {
1556 /*
1557 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1558 ** to distinguish if from ? for this
1559 */
1560
1561 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1562 {
1563 return TRUE;
1564 }
1565 } end_clauseStack_elements;
1566
1567 return FALSE;
1568}
1569
1570void context_exitAndClause (exprNode pred, exprNode tbranch)
1571{
1572 context_setJustPopped ();
1573
1574 llassert (gc.inclause == ANDCLAUSE);
1575
1576 usymtab_popAndBranch (pred, tbranch);
1577 clauseStack_pop (gc.clauses);
1578 gc.inclause = topClause (gc.clauses);
1579}
1580
1581void context_exitOrClause (exprNode pred, exprNode tbranch)
1582{
1583 context_setJustPopped ();
1584
1585 llassert (gc.inclause == ORCLAUSE);
1586
1587 usymtab_popOrBranch (pred, tbranch);
1588 clauseStack_pop (gc.clauses);
1589 gc.inclause = topClause (gc.clauses);
1590}
1591
1592static void context_enterCondClauseAux (clause cl)
1593 /*@modifies gc@*/
1594{
1595 pushClause (cl);
1596}
1597
1598static void context_enterTrueAux (exprNode e, clause cl)
1599 /*@modifies gc@*/
1600{
1601 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1602 pushClause (cl);
1603}
1604
1605void context_enterIterClause (void)
1606{
1607 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1608}
1609
1610void context_enterDoWhileClause (void)
1611{
1612 pushClause (DOWHILECLAUSE);
1613}
1614
1615void context_enterWhileClause (exprNode e)
1616{
1617 context_enterTrueAux (e, WHILECLAUSE);
1618}
1619
1620void context_enterForClause (exprNode e)
1621{
1622 context_enterTrueAux (e, FORCLAUSE);
1623}
1624
1625void context_enterTrueClause (exprNode e)
1626{
1627 context_enterTrueAux (e, TRUECLAUSE);
1628}
1629
1630void context_enterSwitch (exprNode e)
1631{
1632
1633 usymtab_switchBranch (e);
1634 context_enterCondClauseAux (SWITCHCLAUSE);
1635}
1636
1637void context_exitSwitch (exprNode e, bool allpaths)
1638{
1639 usymtab_exitSwitch (e, allpaths);
1640
1641 while (clause_isCase (clauseStack_top (gc.clauses)))
1642 {
1643 clauseStack_pop (gc.clauses);
1644 }
1645
1646 context_exitClauseSimp ();
1647}
1648
1649void context_enterCaseClause (exprNode e)
1650{
1651 bool branch = FALSE;
1652
1653 DPRINTF (("Enter case clause!"));
1654
1655 branch = usymtab_newCase (exprNode_undefined, e);
1656
1657 if (branch)
1658 {
1659 context_enterCondClauseAux (CASECLAUSE);
1660 }
1661}
1662
1663static void context_enterFalseClauseAux (exprNode e, clause cl)
1664 /*@modifies gc@*/
1665{
1666 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1667 gc.inclause = cl;
1668 clauseStack_switchTop (gc.clauses, cl);
1669}
1670
1671void context_enterFalseClause (exprNode e)
1672{
1673
1674 context_enterFalseClauseAux (e, FALSECLAUSE);
1675}
1676
1677void
1678context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1679{
1680 gc.kind = CX_MACROCONST;
1681 gc.cont.fcn = e;
1682 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1683
1684 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1685 gc.nacct);
1686
1687
1688 usymtab_enterScope ();
1689 sRef_enterFunctionScope ();
1690
1691 gc.globs = globSet_undefined;
1692 globSet_clear (gc.globs_used);
1693 gc.mods = sRefSet_undefined;
1694}
1695
1696uentry context_getHeader (void)
1697{
1698 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1699 {
1700 llfatalbug (message ("context_getHeader: bad call: %q",
1701 context_unparse ()));
1702 }
1703
1704 return (gc.cont.fcn);
1705}
1706
1707void
1708context_setFunctionDefined (fileloc loc)
1709{
1710 switch (gc.kind)
1711 {
1712 case CX_UNKNOWNMACRO:
1713 case CX_FUNCTION:
1714 case CX_MACROFCN:
1715 uentry_setFunctionDefined (gc.cont.fcn, loc);
1716 break;
1717 default:
1718 /* (not a bug because of parse errors) */
1719 break;
1720 }
1721}
1722
1723void
1724context_enterFunction (/*@exposed@*/ uentry e)
1725{
1726 gc.kind = CX_FUNCTION;
1727 gc.cont.fcn = e;
1728
28bf4b0b 1729 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1730
616915dd 1731 if (uentry_hasAccessType (e))
1732 {
1733 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1734 gc.nacct);
1735 }
1736 else
1737 {
1738 gc.acct = gc.facct;
1739 }
1740
1741 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1742 typeIdSet_unparse (gc.acct)));
1743
1744 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1745
1746 gc.globs = uentry_getGlobs (e);
1747 globSet_clear (gc.globs_used);
1748 gc.mods = uentry_getMods (e);
1749
1750 usymtab_enterFunctionScope (e);
1751 sRef_enterFunctionScope ();
1752}
1753
1754static bool context_checkStrictGlobals (void)
1755{
1756 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1757}
1758
1759static bool context_hasGlobs (void)
1760{
1761 if (context_inFunctionLike ())
1762 {
1763 return (uentry_hasGlobs (gc.cont.fcn));
1764 }
1765 else
1766 {
1767 return (FALSE);
1768 }
1769}
1770
1771static bool context_checkCheckedGlobals (void)
1772{
1773 return (context_getFlag (FLG_GLOBALS)
1774 && (context_getFlag (FLG_GLOBUNSPEC)
1775 || context_hasGlobs ()));
1776}
1777
1778static bool context_checkUnknownGlobals (void)
1779{
1780 /* should be uentry_hasGlobs ? */
1781
1782 return (context_getFlag (FLG_ALLGLOBALS)
1783 && (context_getFlag (FLG_GLOBUNSPEC)
1784 || context_hasGlobs ()));
1785}
1786
1787static bool context_checkUncheckedGlobals (void)
1788{
1789 return (FALSE);
1790}
1791
1792bool
1793context_checkExport (uentry e)
1794{
1795 if (!gc.anyExports) return FALSE;
1796
1797 if (uentry_isFunction (e)
1798 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1799 {
1800 return context_maybeSet (FLG_EXPORTFCN);
1801 }
1802 else if (uentry_isExpandedMacro (e))
1803 {
1804 return context_maybeSet (FLG_EXPORTMACRO);
1805 }
1806 else if (uentry_isVariable (e))
1807 {
1808 return context_maybeSet (FLG_EXPORTVAR);
1809 }
1810 else if (uentry_isEitherConstant (e))
1811 {
1812 return context_maybeSet (FLG_EXPORTCONST);
1813 }
1814 else if (uentry_isIter (e) || uentry_isEndIter (e))
1815 {
1816 return context_maybeSet (FLG_EXPORTITER);
1817 }
1818 else if (uentry_isDatatype (e))
1819 {
1820 return context_maybeSet (FLG_EXPORTTYPE);
1821 }
1822 else
1823 {
1824 BADEXIT;
1825 }
1826}
1827
1828bool
1829context_checkGlobUse (uentry glob)
1830{
1831
1832 if (uentry_isCheckedStrict (glob))
1833 {
1834 return context_checkStrictGlobals ();
1835 }
1836 else if (uentry_isChecked (glob))
1837 {
1838 return context_checkCheckedGlobals ();
1839 }
1840 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
1841 {
1842 return context_checkUnknownGlobals ();
1843 }
1844 else
1845 {
1846 llassert (uentry_isUnchecked (glob));
1847
1848 return context_checkUncheckedGlobals ();
1849 }
1850}
1851
1852bool
1853context_checkAliasGlob (uentry glob)
1854{
1855 if (uentry_isCheckedStrict (glob))
1856 {
1857 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
1858 }
1859 else if (uentry_isChecked (glob))
1860 {
1861 return gc.flags[FLG_CHECKEDGLOBALIAS];
1862 }
1863 else if (uentry_isCheckMod (glob))
1864 {
1865 return gc.flags[FLG_CHECKMODGLOBALIAS];
1866 }
1867 else
1868 {
1869 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
1870
1871 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
1872 }
1873}
1874
1875bool context_checkInternalUse (void)
1876{
1877 if (context_hasGlobs ())
1878 {
1879 return (gc.flags[FLG_INTERNALGLOBS]);
1880 }
1881 else
1882 {
1883 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
1884 }
1885}
1886
1887bool
1888context_checkGlobMod (sRef el)
1889{
1890 uentry ue = sRef_getUentry (el);
1891
28bf4b0b 1892 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
616915dd 1893
1894 if (uentry_isCheckedModify (ue)
1895 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
1896 {
1897 if (context_hasMods ())
1898 {
1899 return (gc.flags[FLG_MODGLOBS]);
1900 }
1901 else
1902 {
1903 if (uentry_isCheckedStrict (ue))
1904 {
1905 return (gc.flags[FLG_MODGLOBSUNSPEC]);
1906 }
1907 else
1908 {
1909 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
1910 }
1911 }
1912 }
1913 else
1914 {
1915 if (context_hasMods ())
1916 {
1917 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
1918 }
1919 else
1920 {
1921 return FALSE;
1922 }
1923 }
1924}
1925
1926void
28bf4b0b 1927context_usedGlobal (/*@exposed@*/ sRef el)
616915dd 1928{
1929 if (!globSet_member (gc.globs_used, el))
1930 {
1931 /*
1932 ** The first time a global is used in a function, we need
1933 ** to clear the derived sRefs, since they were set for the
1934 ** previous function.
1935 */
1936
1937 sRef_clearDerived (el);
1938 gc.globs_used = globSet_insert (gc.globs_used, el);
1939 }
1940}
1941
1942/*@observer@*/ sRefSet
1943context_modList (void)
1944{
1945 return gc.mods;
1946}
1947
1948bool
1949context_globAccess (sRef s)
1950{
28bf4b0b 1951 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
616915dd 1952 return (globSet_member (gc.globs, s));
1953}
1954
1955bool
1956context_hasAccess (typeId t)
1957{
1958 if (context_inFunctionLike ())
1959 {
28bf4b0b 1960 DPRINTF (("Access %d / %s",
1961 t, typeIdSet_unparse (gc.acct)));
616915dd 1962 return (typeIdSet_member (gc.acct, t));
1963 }
1964 else
1965 {
1966 return (context_hasFileAccess (t));
1967 }
1968}
1969
1970bool
1971context_hasFileAccess (typeId t)
1972{
1973 return (typeIdSet_member (gc.facct, t));
1974}
1975
1976/*@only@*/ cstring
1977context_unparseAccess (void)
1978{
1979 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
1980 typeIdSet_unparse (gc.facct)));
1981}
1982
1983/*@only@*/ cstring
1984context_unparseClauses (void)
1985{
1986 return (clauseStack_unparse (gc.clauses));
1987}
1988
1989bool
1990context_couldHaveAccess (typeId t)
1991{
1992 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
1993 {
1994 return (typeIdSet_member (gc.acct, t));
1995 }
1996 else
1997 {
1998 return (typeIdSet_member (gc.facct, t));
1999 }
2000}
2001
2002ctype
2003context_getRetType (void)
2004{
2005 ctype f = ctype_undefined;
2006
2007 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2008 {
2009 f = uentry_getType (gc.cont.fcn);
2010 }
2011 else if (gc.kind == CX_UNKNOWNMACRO)
2012 {
2013 return ctype_unknown;
2014 }
2015 else
2016 {
2017 llcontbuglit ("context_getRetType: not in a function context");
2018 return ctype_unknown;
2019 }
2020
2021 if (!ctype_isFunction (f))
2022 {
2023 if (ctype_isKnown (f))
2024 {
2025 llbuglit ("context_getRetType: not a function");
2026 }
2027
2028 return ctype_unknown;
2029 }
28bf4b0b 2030 return (ctype_getReturnType (f));
616915dd 2031}
2032
2033bool
2034context_hasMods (void)
2035{
2036 if (context_inFunctionLike ())
2037 {
2038 return (uentry_hasMods (gc.cont.fcn));
2039 }
2040 else
2041 {
2042 return FALSE;
2043 }
2044}
2045
2046void
2047context_exitAllClauses (void)
28bf4b0b 2048{
616915dd 2049 while (!clauseStack_isEmpty (gc.clauses))
2050 {
2051 clause el = clauseStack_top (gc.clauses);
616915dd 2052 gc.inclause = el;
2053
2054 if (clause_isNone (el))
2055 {
2056 usymtab_quietExitScope (g_currentloc);
2057 clauseStack_pop (gc.clauses);
2058 }
2059 else
2060 {
2061 context_exitClausePlain ();
2062 }
2063 }
2064
28bf4b0b 2065 clauseStack_clear (gc.clauses);
2066 gc.inclause = NOCLAUSE;
2067}
616915dd 2068
28bf4b0b 2069void
2070context_exitAllClausesQuiet (void)
2071{
2072 while (!clauseStack_isEmpty (gc.clauses))
2073 {
2074 clause el = clauseStack_top (gc.clauses);
2075 gc.inclause = el;
2076
2077 usymtab_quietExitScope (g_currentloc);
2078 clauseStack_pop (gc.clauses);
2079 }
2080
2081 clauseStack_clear (gc.clauses);
616915dd 2082 gc.inclause = NOCLAUSE;
2083}
2084
2085static
2086void context_exitClauseSimp (void)
2087{
2088
2089 context_setJustPopped ();
2090 clauseStack_pop (gc.clauses);
2091 gc.inclause = topClause (gc.clauses);
2092}
2093
2094static
2095void context_exitCaseClause (void)
2096{
2097 context_setJustPopped ();
2098 usymtab_popCaseBranch ();
2099 clauseStack_pop (gc.clauses);
2100 gc.inclause = topClause (gc.clauses);
2101}
2102
2103static
2104void context_exitClauseAux (exprNode pred, exprNode tbranch)
2105{
2106 context_setJustPopped ();
28bf4b0b 2107 /*@i32 was makeAlt */
616915dd 2108 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2109 clauseStack_pop (gc.clauses);
2110 gc.inclause = topClause (gc.clauses);
2111}
2112
2113void context_exitTrueClause (exprNode pred, exprNode tbranch)
2114{
28bf4b0b 2115 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2116
616915dd 2117 if (gc.inclause != TRUECLAUSE)
2118 {
2119 llparseerror (cstring_makeLiteral
2120 ("Likely parse error. Conditional clauses are inconsistent."));
2121 return;
2122 }
28bf4b0b 2123
2124 context_setJustPopped ();
616915dd 2125 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2126 clauseStack_pop (gc.clauses);
28bf4b0b 2127 gc.inclause = topClause (gc.clauses);
2128}
616915dd 2129
2130void context_exitIterClause (exprNode body)
2131{
2132 llassert (gc.inclause == ITERCLAUSE);
2133
2134 context_setJustPopped ();
2135
2136 if (context_getFlag (FLG_LOOPEXEC))
2137 {
2138 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2139 }
2140 else
2141 {
2142 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2143 }
2144
2145 clauseStack_pop (gc.clauses);
2146 gc.inclause = topClause (gc.clauses);
2147}
2148
2149static void context_popCase (void) {
2150 /*
2151 ** If we are exiting an outer clause, sometimes still in a switch case.
2152 **
2153 ** e.g.:
2154 **
2155 ** switch(a)
2156 ** {
2157 ** case 1:
2158 ** while (c>3)
2159 ** {
2160 ** case 3: ++c;
2161 ** }
2162 ** }
2163 */
2164
2165 DPRINTF (("Popping case clause: %s",
2166 clauseStack_unparse (gc.clauses)));
28bf4b0b 2167
616915dd 2168 if (gc.inclause == CASECLAUSE) {
2169 context_exitCaseClause ();
2170 }
2171}
2172
2173void context_exitWhileClause (exprNode pred, exprNode body)
2174{
2175 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2176
2177 context_popCase ();
2178
2179 if (gc.inclause != WHILECLAUSE) {
2180 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2181 clauseStack_unparse (gc.clauses)));
2182 }
2183
2184 llassert (gc.inclause == WHILECLAUSE);
2185
2186 context_setJustPopped ();
2187
2188
2189 /*
2190 ** predicate must be false after while loop (unless there are breaks)
2191 */
2192
2193 if (context_getFlag (FLG_LOOPEXEC))
2194 {
2195 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2196 }
2197 else
2198 {
2199 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2200 }
2201
2202
2203 usymtab_addGuards (invGuards);
2204 guardSet_free (invGuards);
2205
2206 clauseStack_pop (gc.clauses);
2207 gc.inclause = topClause (gc.clauses);
2208}
2209
2210void context_exitDoWhileClause (exprNode pred)
2211{
2212 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2213
2214 if (gc.inclause == CASECLAUSE) {
2215 /* handle Duff's device */
2216 clauseStack_pop (gc.clauses);
2217 gc.inclause = topClause (gc.clauses);
2218 }
2219
2220 llassert (gc.inclause == DOWHILECLAUSE);
2221
2222 context_setJustPopped ();
2223
2224
2225 usymtab_addGuards (invGuards);
2226 guardSet_free (invGuards);
2227
2228 clauseStack_pop (gc.clauses);
2229 gc.inclause = topClause (gc.clauses);
2230}
2231
2232void context_exitForClause (exprNode forPred, exprNode body)
2233{
2234 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2235
2236 llassert (gc.inclause == FORCLAUSE);
2237 context_setJustPopped ();
2238
2239 /*
2240 ** predicate must be false after while loop (unless there are breaks)
2241 */
2242
2243 if (context_getFlag (FLG_LOOPEXEC))
2244 {
28bf4b0b 2245 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
616915dd 2246 }
2247 else
2248 {
2249 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2250 }
2251
2252 usymtab_addGuards (invGuards);
2253 guardSet_free (invGuards);
2254 clauseStack_pop (gc.clauses);
2255 gc.inclause = topClause (gc.clauses);
2256}
2257
2258static void context_exitClausePlain (void)
2259{
2260 llassert (gc.inclause != NOCLAUSE);
2261
2262 if (gc.inclause == FALSECLAUSE)
2263 {
2264 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2265 }
2266 else
2267 {
2268 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2269 }
616915dd 2270}
2271
2272void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2273{
616915dd 2274 context_setJustPopped ();
28bf4b0b 2275
616915dd 2276 if (gc.inclause == FALSECLAUSE)
2277 {
2278 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
28bf4b0b 2279
616915dd 2280 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2281
2282 clauseStack_pop (gc.clauses);
2283 gc.inclause = topClause (gc.clauses);
2284 }
2285 else
2286 {
28bf4b0b 2287 context_exitTrueClause (pred, tbranch);
616915dd 2288 }
2289}
2290
2291void
2292context_returnFunction (void)
2293{
2294 usymtab_checkFinalScope (TRUE);
2295}
2296
2297void
2298context_exitFunction (void)
2299{
2300 if (!context_inFunction () && !context_inMacroConstant ()
2301 && !context_inMacroUnknown ()
2302 && !context_inIterDef () && !context_inIterEnd ())
2303 {
2304 /*
2305 ** not a bug because of parse errors
2306 */
2307 }
2308 else
2309 {
2310 if (context_inMacro () && usymtab_inFunctionScope ())
2311 {
2312 usymtab_exitScope (exprNode_undefined);
2313 }
2314
2315 if (uentry_hasGlobs (gc.cont.fcn))
2316 {
2317 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2318 }
2319
2320
2321 if (uentry_hasMods (gc.cont.fcn))
2322 {
2323 if (context_getFlag (FLG_MUSTMOD))
2324 {
2325 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2326 }
2327 }
2328
28bf4b0b 2329 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2330
616915dd 2331 /*
2332 ** clear file static modifies
2333 */
2334
2335 /* do this first to get unused error messages */
2336
2337 usymtab_exitScope (exprNode_undefined);
2338 sRef_exitFunctionScope ();
2339
2340 gc.showfunction = FALSE;
2341 gc.kind = CX_GLOBAL;
2342 gc.cont.glob = TRUE;
2343 gc.acct = gc.facct;
2344 gc.globs = globSet_new ();
2345 globSet_clear (gc.globs_used);
2346 gc.mods = sRefSet_new ();
2347 }
2348
2349 llassert (clauseStack_isEmpty (gc.clauses));
2350 llassert (gc.inclause == NOCLAUSE);
2351}
2352
2353void
2354context_quietExitFunction (void)
2355{
2356 while (gc.kind == CX_INNER)
2357 {
2358 context_exitInnerPlain ();
2359 }
2360
2361 if (!context_inFunction () && !context_inMacroConstant () && !context_inMacroUnknown ()
2362 && !context_inIterDef () && !context_inIterEnd ())
2363 {
2364 }
2365 else
2366 {
2367 usymtab_quietExitScope (g_currentloc);
2368
2369 gc.showfunction = FALSE;
2370 gc.kind = CX_GLOBAL;
2371 gc.cont.glob = TRUE;
2372 gc.acct = gc.facct;
2373 gc.globs = globSet_new ();
2374 globSet_clear (gc.globs_used);
2375 gc.mods = sRefSet_new ();
2376
2377 sRef_exitFunctionScope ();
2378 }
2379}
2380
2381/*@observer@*/ uentryList
2382context_getParams (void)
2383{
2384 if (context_inFunctionLike ())
2385 {
2386 return (uentry_getParams (gc.cont.fcn));
2387 }
2388 else
2389 {
2390 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2391 return uentryList_undefined;
2392 }
2393}
2394
2395/*@observer@*/ globSet
2396context_getUsedGlobs (void)
2397{
2398 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2399 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2400
2401 return (gc.globs_used);
2402}
2403
2404cstring
2405context_moduleName ()
2406{
2407 return (fileloc_getBase (g_currentloc));
2408}
2409
2410/*@observer@*/ globSet
2411context_getGlobs (void)
2412{
2413 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2414 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2415
2416 return (gc.globs);
2417}
2418
2419void
2420context_addBoolAccess (void)
2421{
2422 cstring bname = context_getString (FLG_BOOLTYPE);
2423 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2424
2425 addModuleAccess (cstring_copy (bname), boolt);
2426
2427 /* for sys/types (perhaps, this is bogus!) */
2428 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2429}
2430
2431# if 0
2432bool
2433context_canAccessBool (void)
2434{
2435 return TRUE;
2436}
2437# endif
2438
2439/*
2440 static typeId boolType = typeId_invalid;
2441
2442 if (typeId_isInvalid (boolType))
2443 {
2444 boolType = usymtab_getTypeId (context_getBoolName ());
2445 }
2446
2447 if (typeId_isInvalid (boolType)) {
2448 return FALSE;
2449 } else {
2450 return (typeIdSet_member (gc.acct, boolType));
2451 }
2452}
2453*/
2454
2455/* evs 2000-07-25: old version - replaced */
2456
2457ctype
2458context_boolImplementationType () {
2459 /* For now, this is bogus! */
2460 return ctype_int;
2461}
2462
2463bool
2464context_canAccessBool (void)
2465{
2466 static typeId boolType = typeId_invalid;
2467
2468 if (typeId_isInvalid (boolType))
2469 {
2470 boolType = usymtab_getTypeId (context_getBoolName ());
2471 }
2472
2473 if (!typeId_isInvalid (boolType))
2474 {
2475 return context_hasAccess (boolType);
2476 }
2477 else
2478 {
2479 ;
2480 }
2481
2482 return FALSE;
2483}
2484
2485void
2486context_setMessageAnnote (/*@only@*/ cstring s)
2487{
2488 llassert (cstring_isUndefined (gc.msgAnnote));
2489 gc.msgAnnote = s;
2490}
2491
2492bool
2493context_hasMessageAnnote (void)
2494{
2495 return (cstring_isDefined (gc.msgAnnote));
2496}
2497
2498void
2499context_clearMessageAnnote (void)
2500{
2501 if (cstring_isDefined (gc.msgAnnote))
2502 {
2503 cstring_free (gc.msgAnnote);
2504 gc.msgAnnote = cstring_undefined;
2505 }
2506}
2507
2508/*@only@*/ cstring
2509context_getMessageAnnote (void)
2510{
2511 cstring st = gc.msgAnnote;
2512
2513 gc.msgAnnote = cstring_undefined;
2514 return st;
2515}
2516
2517void
2518context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2519{
2520 llassert (sRef_isInvalid (gc.aliasAnnote));
2521 llassert (!sRef_sameName (s, t));
2522 gc.aliasAnnote = s;
2523 gc.aliasAnnoteAls = t;
2524}
2525
2526bool
2527context_hasAliasAnnote (void)
2528{
2529 return (sRef_isValid (gc.aliasAnnote));
2530}
2531
2532void
2533context_clearAliasAnnote (void)
2534{
2535 gc.aliasAnnote = sRef_undefined;
2536}
2537
2538cstring
2539context_getAliasAnnote (void)
2540{
2541 sRef ret = gc.aliasAnnote;
2542 sRef als = gc.aliasAnnoteAls;
2543
2544 llassert (sRef_isValid (ret) && sRef_isValid (als));
2545
2546 gc.aliasAnnote = sRef_undefined;
2547 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2548}
2549
2550void
2551context_recordFileModifies (sRefSet mods)
2552{
28bf4b0b 2553 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
616915dd 2554}
2555
2556void
2557context_recordFileGlobals (globSet mods)
2558{
28bf4b0b 2559 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2560 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
616915dd 2561}
2562
2563void
2564context_setCommentMarkerChar (char c)
2565{
2566 llassert (c != '\0');
2567
2568 context_setValue (FLG_COMMENTCHAR, (int) c);
2569}
2570
2571char
2572context_getCommentMarkerChar (void)
2573{
2574 return ((char) context_getValue (FLG_COMMENTCHAR));
2575}
2576
2577static void
2578context_setValue (flagcode flag, int val)
2579{
2580 int index = flagcode_valueIndex (flag);
2581
2582 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2583
28bf4b0b 2584 switch (flag)
616915dd 2585 {
28bf4b0b 2586 case FLG_LINELEN:
2587 if (val <= 0)
616915dd 2588 {
28bf4b0b 2589
abb1cb43 2590 llerror_flagWarning (message ("Value for %s must be a positive "
2591 "number (given %d)",
2592 flagcode_unparse (flag), val));
616915dd 2593 return;
616915dd 2594 }
28bf4b0b 2595 if (flag == FLG_LINELEN && val < MINLINELEN)
2596 {
abb1cb43 2597 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2598 flagcode_unparse (flag),
2599 MINLINELEN, val));
28bf4b0b 2600 val = MINLINELEN;
2601 }
2602 break;
616915dd 2603
28bf4b0b 2604 case FLG_INCLUDENEST:
2605 case FLG_CONTROLNESTDEPTH:
2606 case FLG_STRINGLITERALLEN:
2607 case FLG_NUMSTRUCTFIELDS:
2608 case FLG_NUMENUMMEMBERS:
2609 case FLG_INDENTSPACES:
2610 if (val < 0)
2611 {
2612
abb1cb43 2613 llerror_flagWarning (message ("Value for %s must be a non-negative "
2614 "number (given %d)",
2615 flagcode_unparse (flag), val));
28bf4b0b 2616 return;
2617 }
616915dd 2618
28bf4b0b 2619 break;
2620 default:
2621 break;
2622 }
2623
2624 gc.values[index] = val;
616915dd 2625}
2626
2627void
2628context_setValueAndFlag (flagcode flag, int val)
2629{
2630 gc.flags[flag] = TRUE;
2631 context_setValue (flag, val);
2632}
2633
2634int
2635context_getValue (flagcode flag)
2636{
2637 int index = flagcode_valueIndex (flag);
2638
2639 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2640 return (gc.values[index]);
2641}
2642
2643int
2644context_getCounter (flagcode flag)
2645{
2646 int index = flagcode_valueIndex (flag);
2647
2648 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2649 return (gc.counters[index]);
2650}
2651
2652void
2653context_incCounter (flagcode flag)
2654{
2655 int index = flagcode_valueIndex (flag);
2656
2657 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2658 /* check limit */
2659 gc.counters[index]++;
2660}
2661
2662void
2663context_decCounter (flagcode flag)
2664{
2665 int index = flagcode_valueIndex (flag);
2666
2667 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2668 gc.counters[index]--;
2669}
2670
2671bool context_showFunction (void)
2672{
2673 return (gc.showfunction);
2674}
2675
2676void
2677context_setString (flagcode flag, cstring val)
2678{
2679 int index = flagcode_stringIndex (flag);
2680
2681 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2682
2683 if (flag == FLG_SYSTEMDIRS)
2684 {
2685 llassert (cstring_isDefined (val));
2686
2687 if (cstring_firstChar (val) == '\"')
2688 {
2689 cstring oval = val;
2690 cstring tval = cstring_copy (cstring_suffix (val, 1));
2691
2692 if (cstring_lastChar (tval) != '\"')
2693 {
2694 int n = cstring_length (tval) - 1;
2695
2696 while (isspace ((int) cstring_getChar (tval, n)))
2697 {
2698 n--;
2699 }
2700
2701 if (cstring_getChar (tval, n) != '\"')
2702 {
abb1cb43 2703 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
616915dd 2704 }
2705 else
2706 {
2707 cstring otval = tval;
2708 tval = cstring_prefix (tval, n);
2709 cstring_free (otval);
2710 }
2711 }
2712
2713 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2714 DPRINTF (("val = %s", val));
2715 cstring_free (tval);
2716 cstring_free (oval);
2717 }
2718 }
2719
2720 if (flag == FLG_TMPDIR)
2721 {
2722 llassert (cstring_isDefined (val));
2723
2724 if (cstring_length (val) == 0)
2725 {
2726 cstring_free (val);
2727 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2728 }
2729 else if (cstring_lastChar (val) != CONNECTCHAR)
2730 {
2731 val = cstring_appendChar (val, CONNECTCHAR);
2732 }
2733 else
2734 {
2735 ;
2736 }
2737 }
2738
2739 if (cstring_length (val) >= 1
2740 && cstring_firstChar (val) == '"')
2741 {
abb1cb43 2742 llerror_flagWarning (message
2743 ("setting %s to string beginning with \". You probably "
2744 "don't meant to have the \"'s.",
2745 flagcode_unparse (flag)));
616915dd 2746 }
2747
2748 if (flag == FLG_BOOLTYPE)
2749 {
2750
2751 }
2752
2753 gc.strings[index] = val;
2754}
2755
2756static /*@exposed@*/ cstring
2757context_exposeString (flagcode flag)
2758{
2759 int index = flagcode_stringIndex (flag);
2760
2761 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2762 return (gc.strings[index]);
2763}
2764
2765cstring
2766context_getString (flagcode flag)
2767{
2768 return (context_exposeString (flag));
2769}
2770
2771void
2772context_resetErrors (void)
2773{
2774 gc.numerrors = 0;
2775}
2776
2777void context_initMod (void)
2778 /*@globals undef gc; @*/
2779{
2780 gc.kind = CX_GLOBAL;
28bf4b0b 2781 gc.savekind = CX_ERROR;
616915dd 2782 gc.instandardlib = FALSE;
2783 gc.numerrors = 0;
2784 gc.neednl = FALSE;
2785 gc.linesprocessed = 0;
2786 gc.speclinesprocessed = 0;
2787 gc.insuppressregion = FALSE;
2788 gc.macroMissingParams = FALSE;
2789 gc.preprocessing = FALSE;
2790 gc.incommandline = FALSE;
2791 gc.mc = macrocache_create ();
2792 gc.nmods = 0;
2793 gc.maxmods = DEFAULTMAXMODS;
28bf4b0b 2794 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2795
616915dd 2796 gc.library = FLG_ANSILIB;
2797
2798 gc.locstack = filelocStack_new ();
2799 gc.modrecs = sRefSetList_undefined;
2800 gc.anyExports = FALSE;
2801
2802 gc.ftab = fileTable_create ();
2803 gc.msgLog = messageLog_new ();
2804 gc.inimport = FALSE;
2805 gc.inDerivedFile = FALSE;
2806 gc.inheader = FALSE;
2807 gc.markers = flagMarkerList_new ();
2808 gc.cont.glob = TRUE;
2809 gc.showfunction = FALSE;
2810 gc.msgAnnote = cstring_undefined;
2811 gc.aliasAnnote = sRef_undefined;
2812 gc.aliasAnnoteAls = sRef_undefined;
2813 gc.boolType = ctype_bool;
2814 gc.mods = sRefSet_new ();
2815
2816 gc.saveloc = fileloc_undefined;
2817
2818 gc.inmacrocache = FALSE;
2819 gc.inclause = NOCLAUSE;
2820 gc.clauses = clauseStack_new ();
2821 gc.globs = globSet_new ();
2822 gc.nacct = typeIdSet_emptySet ();
2823 gc.acct = typeIdSet_emptySet ();
2824 gc.facct = typeIdSet_emptySet ();
2825 gc.savedFlags = FALSE;
2826 gc.pushloc = fileloc_undefined;
2827 gc.protectVars = FALSE;
2828 gc.justpopped = FALSE;
2829 gc.isNullGuarded = NO;
2830 gc.globs_used = globSet_undefined;
2831
2832 allFlagCodes (code)
2833 {
2834 gc.setGlobally[code] = FALSE;
2835 gc.setLocally[code] = FALSE;
2836 } end_allFlagCodes ;
2837
2838 usymtab_initMod ();
2839
2840 context_resetAllFlags ();
2841 conext_resetAllCounters ();
2842 context_setMode (DEFAULT_MODE);
28bf4b0b 2843
2844 gc.stateTable = metaStateTable_create ();
2845 gc.annotTable = annotationTable_create ();
2846
2847 DPRINTF (("Annotations: \n%s",
2848 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
2849 DPRINTF (("State: \n%s",
2850 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
2851
616915dd 2852}
2853
2854ctype
2855context_typeofZero (void)
2856{
2857 ctype ct = ctype_int;
2858
2859 if (context_getFlag (FLG_ZEROPTR))
2860 {
2861 ct = ctype_makeConj (ct, ctype_voidPointer);
2862 }
2863
2864 if (context_getFlag (FLG_ZEROBOOL)) {
2865 ct = ctype_makeConj (ct, ctype_bool);
2866 }
2867
2868 return ct;
2869}
2870
2871ctype
2872context_typeofOne (void)
2873{
2874 ctype ct = ctype_int;
2875
2876 /* 1 is on longer a bool (was before 2.4)
2877 if (!context_getFlag (FLG_ABSTRACTBOOL))
2878 {
2879 ct = ctype_makeConj (ct, ctype_bool);
2880 }
2881 */
2882
2883 return (ct);
2884}
2885
2886/*@only@*/ cstring
2887context_unparse (void)
2888{
2889 cstring s;
2890
2891 switch (gc.kind)
2892 {
2893 case CX_LCL:
2894 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
2895 break;
2896 case CX_LCLLIB:
2897 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
2898 break;
2899 case CX_GLOBAL:
2900 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
2901 break;
2902 case CX_INNER:
2903 s = message ("Inner Context:%q", fileloc_unparse (g_currentloc));
2904 break;
2905 case CX_FUNCTION:
2906 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
2907 uentry_unparse (gc.cont.fcn),
2908 fileloc_unparse (g_currentloc),
2909 typeIdSet_unparse (gc.acct),
2910 sRefSet_unparse (gc.mods));
2911 break;
2912 case CX_MACROFCN:
2913 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
2914 break;
2915 case CX_UNKNOWNMACRO:
2916 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
2917 break;
2918 case CX_MACROCONST:
2919 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
2920 break;
2921 case CX_ITERDEF:
2922 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
2923 break;
2924 case CX_ITEREND:
2925 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
2926 break;
2927 default:
2928 s = message ("Un-unparseable context: %d", (int) gc.kind);
2929 break;
2930 }
2931
2932 s = message ("%q\naccess: %q", s, context_unparseAccess ());
2933 return (s);
2934}
2935
2936extern ctype
2937context_currentFunctionType (void)
2938{
2939 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2940 {
2941 return (uentry_getType (gc.cont.fcn));
2942 }
2943 else if (gc.kind == CX_INNER)
2944 {
2945 llcontbuglit ("context_currentFunctionType: inner context");
2946 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
2947 return (context_currentFunctionType ());
2948 }
2949 else
2950 {
2951 llcontbuglit ("context_currentFunctionType: not in function");
2952 return (ctype_undefined);
2953 }
2954}
2955
2956void
2957context_enterInnerContext (void)
2958{
2959 if (gc.kind == CX_GLOBAL)
2960 {
2961 gc.kind = CX_INNER;
2962 gc.cont.cdepth = 1;
2963 }
2964 else if (gc.kind == CX_INNER)
2965 {
2966 gc.cont.cdepth++;
2967 }
2968 else
2969 {
2970 ;
2971 }
2972
2973
2974 usymtab_enterScope ();
2975 pushClause (NOCLAUSE);
2976}
2977
2978void
2979context_exitInnerPlain (void) /*@modifies gc;@*/
2980{
2981 context_exitInner (exprNode_undefined);
2982}
2983
2984void
2985context_exitInner (exprNode exp)
2986{
2987
2988 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
2989 ("inclause = %s", clause_nameTaken (gc.inclause)));
2990
2991 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
2992 gc.inclause = topClause (gc.clauses);
2993
2994 if (gc.kind == CX_INNER)
2995 {
2996 if (--gc.cont.cdepth == 0)
2997 {
2998 gc.kind = CX_GLOBAL;
2999 gc.cont.glob = TRUE;
3000 }
3001 }
3002 else
3003 {
3004 if (gc.kind == CX_GLOBAL)
3005 {
3006 llcontbuglit ("Attempt to exit global context");
3007 return;
3008 }
3009 }
3010
3011 usymtab_exitScope (exp);
3012}
3013
3014
3015void
3016context_enterStructInnerContext (void)
3017{
3018 if (gc.kind == CX_GLOBAL)
3019 {
3020 gc.kind = CX_INNER;
3021 gc.cont.cdepth = 1;
3022 }
3023 else if (gc.kind == CX_INNER)
3024 {
3025 gc.cont.cdepth++;
3026 }
3027 else
3028 {
3029 ;
3030 }
3031
3032 usymtab_enterScope ();
3033}
3034
3035void
3036context_exitStructInnerContext (void)
3037{
3038 if (gc.kind == CX_INNER)
3039 {
3040 if (--gc.cont.cdepth == 0)
3041 {
3042 gc.kind = CX_GLOBAL;
3043 gc.cont.glob = TRUE;
3044 }
3045 }
3046 else
3047 {
3048 if (gc.kind == CX_GLOBAL)
3049 {
3050 llcontbuglit ("Attempt to exit global context");
3051 return;
3052 }
3053 }
3054
3055 usymtab_exitScope (exprNode_undefined);
3056}
3057
3058void
3059context_exitInnerSafe (void)
3060{
3061
3062 if (gc.kind == CX_INNER)
3063 {
3064 if (--gc.cont.cdepth == 0)
3065 {
3066 gc.cont.cdepth++;
3067 }
3068 }
3069 else if (gc.kind == CX_GLOBAL)
3070 {
3071 llcontbuglit ("Attempt to exit global context");
3072 return;
3073 }
3074 else
3075 {
3076 if (usymtab_inDeepScope ())
3077 {
3078 usymtab_exitScope (exprNode_undefined);
3079 }
3080 }
3081}
3082
3083static
3084void setModuleAccess (void)
3085{
3086 gc.facct = typeIdSet_emptySet ();
3087
3088 if (fileId_isValid (currentFile ()))
3089 {
3090 cstring baseName = fileloc_getBase (g_currentloc);
3091
3092 if (context_getFlag (FLG_ACCESSFILE))
3093 {
3094 if (usymtab_existsType (baseName))
3095 {
3096 gc.facct = typeIdSet_insert (gc.facct,
3097 usymtab_getTypeId (baseName));
3098 }
3099 else
3100 {
3101 ;
3102 }
3103 }
3104
3105 if (context_getFlag (FLG_ACCESSMODULE))
3106 {
3107 int i;
3108 bool hasaccess = FALSE;
3109
3110 for (i = 0; i < gc.nmods; i++)
3111 {
3112 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3113 {
3114 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3115
3116 hasaccess = TRUE;
3117 break;
3118 }
3119 }
3120 }
3121
3122 gc.acct = gc.facct;
3123 gc.inheader = fileId_isHeader (currentFile ());
3124 }
3125 else
3126 {
3127 llcontbuglit ("Current file not defined\n");
3128 gc.facct = typeIdSet_emptySet ();
3129 gc.acct = gc.facct;
3130 gc.inheader = FALSE;
3131 }
3132
3133 /* 17 Jan 1995: forgot to clear nacct */
3134
3135 gc.nacct = typeIdSet_emptySet ();
3136}
3137
3138static void
3139context_enterFileAux (void)
3140{
3141 setModuleAccess ();
3142}
3143
3144void
3145context_enterFile (void)
3146{
3147 context_enterFileAux ();
3148 usymtab_enterFile ();
3149}
3150
3151void
3152context_enterMacroFile (void)
3153{
3154 context_enterFileAux ();
3155}
3156
3157bool
3158context_inFunction (void)
3159{
3160 kcontext ck = gc.kind;
3161
3162 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3163}
3164
3165bool
3166context_inFunctionLike (void)
3167{
3168 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
28bf4b0b 3169 || gc.kind == CX_FCNDECLARATION
616915dd 3170 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3171}
3172
3173bool
3174context_inRealFunction (void)
3175{
3176 kcontext ck = gc.kind;
3177
3178 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3179}
3180
3181void
3182context_processAllMacros (void)
3183{
3184 usymtab_enterFile ();
3185
3186 gc.inmacrocache = TRUE;
3187 macrocache_processUndefinedElements (gc.mc);
3188 cleanupMessages ();
3189 usymtab_exitFile ();
3190
3191 gc.inmacrocache = FALSE;
3192 macrocache_finalize ();
3193}
3194
3195/*
3196** this happens once at the end of each C file
3197**
3198** check each Macro that was defined in current file.c or current file.h
3199**
3200*/
3201
3202static void
3203context_processMacros (void)
3204{
3205 if (fileId_isValid (currentFile ()))
3206 {
3207 fileloc lastfl;
28bf4b0b 3208 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileName (currentFile ())));
616915dd 3209
3210 gc.inmacrocache = TRUE;
3211
3212 DPRINTF (("Processing macros: %s", cbase));
3213 lastfl = macrocache_processFileElements (gc.mc, cbase);
3214 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3215
3216 cstring_free (cbase);
3217
3218 if (fileloc_isDefined (lastfl))
3219 {
3220 g_currentloc = fileloc_update (g_currentloc, lastfl);
3221 cleanupMessages ();
3222 }
3223
3224 gc.inmacrocache = FALSE;
3225 }
3226}
3227
3228bool
3229context_processingMacros (void)
3230{
3231 return (gc.inmacrocache);
3232}
3233
3234void
28bf4b0b 3235context_exitCFile (void)
616915dd 3236{
3237 if (gc.kind != CX_GLOBAL)
3238 {
3239 llfatalerrorLoc
3240 (cstring_makeLiteral ("File ended outside global scope"));
3241 }
3242
3243 if (gc.insuppressregion)
3244 {
3245 /* gack...don't reverse the order of these lines! ;-> */
3246 gc.insuppressregion = FALSE;
3247 llerrorlit (FLG_SYNTAX,
3248 "File ended in ignore errors region, "
3249 "possible missing /*@end*/");
3250 }
3251
3252 /* fix up parse errors */
3253
3254 while (!usymtab_inFileScope ())
3255 {
3256 usymtab_quietExitScope (g_currentloc);
3257 }
3258
3259 /*
3260 ** Clear the file-specific modifies information.
3261 */
3262
3263 sRefSetList_elements (gc.modrecs, mods)
3264 {
3265 sRefSet_clearStatics (mods);
28bf4b0b 3266 } end_sRefSetList_elements ;
616915dd 3267
3268 sRefSetList_clear (gc.modrecs);
28bf4b0b 3269
616915dd 3270 context_processMacros ();
3271 cleanupMessages ();
28bf4b0b 3272
616915dd 3273 usymtab_exitFile ();
28bf4b0b 3274
616915dd 3275 gc.inDerivedFile = FALSE;
3276 filelocStack_clear (gc.locstack);
28bf4b0b 3277
616915dd 3278 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
28bf4b0b 3279
616915dd 3280 gc.cont.glob = TRUE;
3281
3282 if (gc.savedFlags)
3283 {
3284 context_restoreFlagSettings ();
3285 gc.savedFlags = FALSE;
3286 }
28bf4b0b 3287
3288 /*
3289 DPRINTF (("After exiting file: "));
3290 usymtab_printAll ();
3291 */
616915dd 3292}
3293
3294void
3295context_exitMacroCache (void)
3296{
3297 if (gc.kind != CX_GLOBAL)
3298 {
28bf4b0b 3299 if (context_inMacro ())
3300 /* this is okay, file could end without newline in macro */
616915dd 3301 {
28bf4b0b 3302 DPRINTF (("Still in macro: %s",
3303 context_unparse ()));
616915dd 3304 context_exitFunction ();
3305 }
3306 else
3307 {
3308 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3309 context_unparse ()));
3310 gc.kind = CX_GLOBAL;
3311 }
3312 }
3313
3314 /*
3315 ** no longer valid here
3316 ** if (gc.insuppressregion)
3317 ** {
3318 ** gc.insuppressregion = FALSE;
3319 ** llerror ("File ended in ignore errors region, possible missing @");
3320 ** }
3321 */
3322
3323 gc.cont.glob = TRUE;
3324}
3325
3326void
3327context_saveLocation (void)
3328{
3329 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3330 fileloc_free (gc.saveloc);
3331
3332
3333 gc.saveloc = fileloc_copy (g_currentloc);
3334 }
3335
3336fileloc
3337context_getSaveLocation (void)
3338{
3339 fileloc fl = gc.saveloc;
3340
3341 gc.saveloc = fileloc_undefined;
3342 return fl;
3343}
3344
3345/*@observer@*/ cstring
3346context_inFunctionName (void)
3347{
3348 if (gc.kind == CX_FUNCTION
3349 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3350 || gc.kind == CX_MACROCONST
3351 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3352 {
3353 return (uentry_rawName (gc.cont.fcn));
3354 }
3355 else
3356 {
3357 llcontbuglit ("context_inFunctionName: not in function");
3358 return (cstring_undefined);
3359 }
3360}
3361
3362void
3363context_userSetFlag (flagcode f, bool b)
3364{
28bf4b0b 3365 DPRINTF (("set flag: %s", flagcode_unparse (f)));
616915dd 3366
3367 if (f == FLG_NEVERINCLUDE && b)
3368 {
3369 if (gc.flags[FLG_EXPORTHEADER])
3370 {
abb1cb43 3371 llerror_flagWarning (cstring_makeLiteral
3372 ("setting +neverinclude after +exportheader. "
3373 "Turning off exportheader, since headers are not checked "
3374 "when +neverinclude is used."));
616915dd 3375
3376 gc.flags[FLG_EXPORTHEADER] = FALSE;
3377 }
3378 }
3379 else
3380 {
3381 if (f == FLG_EXPORTHEADER && b)
3382 {
3383 if (gc.flags[FLG_NEVERINCLUDE])
3384 {
abb1cb43 3385 llerror_flagWarning (cstring_makeLiteral
3386 ("setting +exportheader after +neverinclude. "
3387 "Not setting exportheader, since headers are not checked "
3388 "when +neverinclude is used."));
616915dd 3389 gc.flags[FLG_EXPORTHEADER] = FALSE;
3390 return;
3391 }
3392 }
3393 }
3394
3395 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3396 {
3397 bool lastsetting = context_getFlag (f);
3398
3399 if (bool_equal (lastsetting, b)
3400 && !flagcode_isSpecialFlag (f)
3401 && !flagcode_isIdemFlag (f)
3402 && !flagcode_hasArgument (f))
3403 {
abb1cb43 3404 llerror_flagWarning (message ("setting %s%s redundant with current value",
3405 cstring_makeLiteralTemp (b ? "+" : "-"),
3406 flagcode_unparse (f)));
28bf4b0b 3407 }
3408 }
3409
3410 if (flagcode_isWarnUseFlag (f) && b)
3411 {
3412 if (!context_getFlag (FLG_WARNUSE))
3413 {
abb1cb43 3414 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3415 flagcode_unparse (f)));
28bf4b0b 3416
616915dd 3417 }
3418 }
3419
28bf4b0b 3420
616915dd 3421 if (flagcode_isLibraryFlag (f))
3422 {
3423 if (gc.library != FLG_ANSILIB
3424 && gc.library != f)
3425 {
abb1cb43 3426 llerror_flagWarning (message ("selecting library %s after library %s was "
3427 "selected (only one library may be used)",
3428 flagcode_unparse (f),
3429 flagcode_unparse (gc.library)));
616915dd 3430 }
3431
3432 if (f == FLG_UNIXLIB)
3433 {
3434 if (context_getFlag (FLG_WARNUNIXLIB))
3435 {
abb1cb43 3436 llerror_flagWarning (cstring_makeLiteral
3437 ("selecting unix library. Unix library is "
3438 "ad hoc addition to POSIX library. Recommend "
3439 "use +posixlib to select POSIX library instead. "
3440 "Use -warnunixlib to suppress this message."));
616915dd 3441 }
3442 }
3443
3444 gc.library = f;
3445 }
abb1cb43 3446
3447 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3448 {
3449 llerror_flagWarning (message
3450 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3451 flagcode_unparse (f)));
3452 }
3453
616915dd 3454 gc.setGlobally[f] = TRUE;
3455 context_setFlag (f, b);
3456}
3457
3458void
3459context_fileSetFlag (flagcode f, ynm set)
3460{
3461 if (!gc.savedFlags)
3462 {
3463 context_saveFlagSettings ();
3464 }
3465
3466 if (ynm_isOff (set))
3467 {
3468 context_setFlagAux (f, FALSE, TRUE, FALSE);
3469 }
3470 else if (ynm_isOn (set))
3471 {
3472 context_setFlagAux (f, TRUE, TRUE, FALSE);
3473 gc.setLocally[f] = TRUE;
3474 }
3475 else
3476 {
3477 context_restoreFlag (f);
3478 }
3479}
3480
3481static void
3482context_restoreFlag (flagcode f)
3483{
3484
3485 if (!gc.savedFlags)
3486 {
3487 voptgenerror
3488 (FLG_SYNTAX,
3489 message ("Attempt to restore flag %s when no file scope flags "
3490 "have been set.",
3491 flagcode_unparse (f)),
3492 g_currentloc);
3493 }
3494 else
3495 {
3496 context_addFlagMarker (f, MAYBE);
3497 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3498 }
3499
3500 }
3501
28bf4b0b 3502static void
616915dd 3503context_setFlag (flagcode f, bool b)
3504{
3505 context_setFlagAux (f, b, FALSE, FALSE);
3506}
3507
3508void
3509context_setFlagTemp (flagcode f, bool b)
3510{
3511 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3512 gc.flags[f] = b;
3513}
3514
3515/*@notfunction@*/
3516# define DOSET(ff,b) \
3517 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3518 context_addFlagMarker (ff, ynm_fromBool (b)); } \
28bf4b0b 3519 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
616915dd 3520 gc.flags[ff] = b; } while (FALSE)
3521
3522static void
3523 context_setFlagAux (flagcode f, bool b, bool
3524 inFile, /*@unused@*/ bool isRestore)
3525{
3526 DPRINTF (("set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3527
3528 if (f == FLG_USESTDERR)
3529 {
3530 if (b) {
3531 g_msgstream = stderr;
3532 } else {
3533 g_msgstream = stdout;
3534 }
3535 }
3536
28bf4b0b 3537 /*
3538 ** Removed test for special flags.
3539 */
616915dd 3540
28bf4b0b 3541 if (flagcode_isIdemFlag (f))
3542 {
3543 DOSET (f, TRUE);
3544 }
3545 else
3546 {
3547 DOSET (f, b);
3548 }
616915dd 3549
28bf4b0b 3550 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3551 {
3552 if (b) /* Turing higher level on, turns on all lower levels */
3553 {
3554 switch (f)
616915dd 3555 {
28bf4b0b 3556 case FLG_ITS4MOSTRISKY:
3557 DOSET (FLG_ITS4VERYRISKY, b);
3558 /*@fallthrough@*/
3559 case FLG_ITS4VERYRISKY:
3560 DOSET (FLG_ITS4RISKY, b);
3561 /*@fallthrough@*/
3562 case FLG_ITS4RISKY:
3563 DOSET (FLG_ITS4MODERATERISK, b);
3564 /*@fallthrough@*/
3565 case FLG_ITS4MODERATERISK:
3566 DOSET (FLG_ITS4LOWRISK, b);
3567 /*@fallthrough@*/
3568 case FLG_ITS4LOWRISK:
3569 break;
3570 BADDEFAULT;
616915dd 3571 }
28bf4b0b 3572 }
3573 else /* Turning level off, turns off all higher levels */
3574 {
3575 switch (f)
616915dd 3576 {
28bf4b0b 3577 case FLG_ITS4LOWRISK:
3578 DOSET (FLG_ITS4MODERATERISK, b);
3579 /*@fallthrough@*/
3580 case FLG_ITS4MODERATERISK:
3581 DOSET (FLG_ITS4RISKY, b);
3582 /*@fallthrough@*/
3583 case FLG_ITS4RISKY:
3584 DOSET (FLG_ITS4VERYRISKY, b);
3585 /*@fallthrough@*/
3586 case FLG_ITS4VERYRISKY:
3587 DOSET (FLG_ITS4MOSTRISKY, b);
3588 /*@fallthrough@*/
3589 case FLG_ITS4MOSTRISKY:
3590 break;
3591 BADDEFAULT;
616915dd 3592 }
616915dd 3593 }
3594 }
28bf4b0b 3595
3596 switch (f)
3597 {
3598 case FLG_ALLEMPTY:
3599 DOSET (FLG_ALLEMPTY, b);
3600 DOSET (FLG_IFEMPTY, b);
3601 DOSET (FLG_WHILEEMPTY, b);
3602 DOSET (FLG_FOREMPTY, b);
3603 break;
3604 case FLG_PREDBOOL:
3605 DOSET (FLG_PREDBOOL, b);
3606 DOSET (FLG_PREDBOOLINT, b);
3607 DOSET (FLG_PREDBOOLPTR, b);
3608 DOSET (FLG_PREDBOOLOTHERS, b);
3609 break;
3610 case FLG_GLOBALIAS:
3611 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3612 DOSET (FLG_CHECKEDGLOBALIAS, b);
3613 DOSET (FLG_CHECKMODGLOBALIAS, b);
3614 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3615 break;
3616 case FLG_ALLBLOCK:
3617 DOSET (FLG_ALLBLOCK, b);
3618 DOSET (FLG_IFBLOCK, b);
3619 DOSET (FLG_WHILEBLOCK, b);
3620 DOSET (FLG_FORBLOCK, b);
3621 break;
3622 case FLG_GRAMMAR:
3623 if (b)
616915dd 3624 {
28bf4b0b 3625 yydebug = 1;
3626 mtdebug = 1;
616915dd 3627 }
3628 else
3629 {
28bf4b0b 3630 yydebug = 0;
3631 mtdebug = 0;
3632 }
3633
3634 DOSET (FLG_GRAMMAR, b);
3635 break;
3636 case FLG_CODEIMPONLY:
3637 DOSET (FLG_CODEIMPONLY, b);
3638 DOSET (FLG_GLOBIMPONLY, b);
3639 DOSET (FLG_RETIMPONLY, b);
3640 DOSET (FLG_STRUCTIMPONLY, b);
3641 break;
3642 case FLG_SPECALLIMPONLY:
3643 DOSET (FLG_SPECALLIMPONLY, b);
3644 DOSET (FLG_SPECGLOBIMPONLY, b);
3645 DOSET (FLG_SPECRETIMPONLY, b);
3646 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3647 break;
3648 case FLG_ALLIMPONLY:
3649 DOSET (FLG_ALLIMPONLY, b);
3650 DOSET (FLG_GLOBIMPONLY, b);
3651 DOSET (FLG_RETIMPONLY, b);
3652 DOSET (FLG_STRUCTIMPONLY, b);
3653 DOSET (FLG_SPECGLOBIMPONLY, b);
3654 DOSET (FLG_SPECRETIMPONLY, b);
3655 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3656 break;
3657 case FLG_ANSILIMITS:
3658 DOSET (FLG_ANSILIMITS, b);
3659 DOSET (FLG_CONTROLNESTDEPTH, b);
3660 DOSET (FLG_STRINGLITERALLEN, b);
3661 DOSET (FLG_INCLUDENEST, b);
3662 DOSET (FLG_NUMSTRUCTFIELDS, b);
3663 DOSET (FLG_NUMENUMMEMBERS, b);
3664
3665 if (b)
3666 {
3667 context_setValue (FLG_CONTROLNESTDEPTH, DEFAULT_CONTROLNESTDEPTH);
3668 context_setValue (FLG_STRINGLITERALLEN, DEFAULT_STRINGLITERALLEN);
3669 context_setValue (FLG_INCLUDENEST, DEFAULT_INCLUDENEST);
3670 context_setValue (FLG_NUMSTRUCTFIELDS, DEFAULT_NUMSTRUCTFIELDS);
3671 context_setValue (FLG_NUMENUMMEMBERS, DEFAULT_NUMENUMMEMBERS);
3672 }
3673 break;
3674 case FLG_EXTERNALNAMELEN:
3675 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3676 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3677 break;
3678 case FLG_INTERNALNAMELEN:
3679 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3680 DOSET (FLG_INTERNALNAMELEN, TRUE);
3681 break;
3682 case FLG_EXTERNALNAMECASEINSENSITIVE:
3683 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3684
3685 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3686 {
3687 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3688 context_setValue (FLG_EXTERNALNAMELEN, 0);
3689 }
3690 break;
3691 case FLG_INTERNALNAMECASEINSENSITIVE:
3692 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3693
3694 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3695 {
3696 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3697 context_setValue (FLG_INTERNALNAMELEN, 0);
3698 }
3699 break;
3700 case FLG_INTERNALNAMELOOKALIKE:
3701 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3702
3703 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3704 {
3705 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3706 context_setValue (FLG_INTERNALNAMELEN, 0);
616915dd 3707 }
28bf4b0b 3708 break;
3709 case FLG_MODUNSPEC:
3710 DOSET (FLG_MODNOMODS, b);
3711 DOSET (FLG_MODGLOBSUNSPEC, b);
3712 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3713 break;
3714 case FLG_EXPORTANY:
3715 DOSET (FLG_EXPORTVAR, b);
3716 DOSET (FLG_EXPORTFCN, b);
3717 DOSET (FLG_EXPORTTYPE, b);
3718 DOSET (FLG_EXPORTMACRO, b);
3719 DOSET (FLG_EXPORTCONST, b);
3720 gc.anyExports = TRUE;
3721 break;
3722 case FLG_REPEXPOSE:
3723 DOSET (FLG_RETEXPOSE, b);
3724 DOSET (FLG_ASSIGNEXPOSE, b);
3725 DOSET (FLG_CASTEXPOSE, b);
3726 break;
3727 case FLG_RETVAL:
3728 DOSET (FLG_RETVALBOOL, b);
3729 DOSET (FLG_RETVALINT, b);
3730 DOSET (FLG_RETVALOTHER, b);
3731 break;
3732 case FLG_PARTIAL:
3733 if (b)
3734 {
3735 DOSET (FLG_EXPORTLOCAL, FALSE);
3736 DOSET (FLG_DECLUNDEF, FALSE);
3737 DOSET (FLG_SPECUNDEF, FALSE);
3738 DOSET (FLG_TOPUNUSED, FALSE);
3739 }
3740 break;
3741 case FLG_DEEPBREAK:
3742 DOSET (FLG_LOOPLOOPBREAK, b);
3743 DOSET (FLG_LOOPSWITCHBREAK, b);
3744 DOSET (FLG_SWITCHLOOPBREAK, b);
3745 DOSET (FLG_SWITCHSWITCHBREAK, b);
3746 DOSET (FLG_LOOPLOOPCONTINUE, b);
3747 DOSET (FLG_DEEPBREAK, b);
3748 break;
3749 case FLG_ACCESSALL:
3750 DOSET (FLG_ACCESSMODULE, b);
3751 DOSET (FLG_ACCESSFILE, b);
3752 DOSET (FLG_ACCESSCZECH, b);
3753 break;
3754 case FLG_ALLMACROS:
3755 DOSET (FLG_ALLMACROS, b);
3756 DOSET (FLG_FCNMACROS, b);
3757 DOSET (FLG_CONSTMACROS, b);
3758 break;
3759 case FLG_CZECH:
3760 if (b) { DOSET (FLG_ACCESSCZECH, b); }
3761 DOSET (FLG_CZECHFUNCTIONS, b);
3762 DOSET (FLG_CZECHVARS, b);
3763 DOSET (FLG_CZECHCONSTANTS, b);
3764 DOSET (FLG_CZECHTYPES, b);
3765 break;
3766 case FLG_SLOVAK:
3767 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
3768 DOSET (FLG_SLOVAKFUNCTIONS, b);
3769 DOSET (FLG_SLOVAKVARS, b);
3770 DOSET (FLG_SLOVAKCONSTANTS, b);
3771 DOSET (FLG_SLOVAKTYPES, b);
3772 break;
3773 case FLG_CZECHOSLOVAK:
3774 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
3775 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
3776 DOSET (FLG_CZECHOSLOVAKVARS, b);
3777 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
3778 DOSET (FLG_CZECHOSLOVAKTYPES, b);
3779 break;
3780 case FLG_NULL:
3781 DOSET (FLG_NULLSTATE, b);
3782 DOSET (FLG_NULLDEREF, b);
3783 DOSET (FLG_NULLASSIGN, b);
3784 DOSET (FLG_NULLPASS, b);
3785 DOSET (FLG_NULLRET, b);
3786 break;
3787 case FLG_MEMCHECKS:
3788 DOSET (FLG_NULLSTATE, b);
3789 DOSET (FLG_NULLDEREF, b);
3790 DOSET (FLG_NULLASSIGN, b);
3791 DOSET (FLG_NULLPASS, b);
3792 DOSET (FLG_NULLRET, b);
3793 DOSET (FLG_COMPDEF, b);
3794 DOSET (FLG_COMPMEMPASS, b);
3795 DOSET (FLG_UNIONDEF, b);
3796 DOSET (FLG_MEMTRANS, b);
3797 DOSET (FLG_USERELEASED, b);
3798 DOSET (FLG_ALIASUNIQUE, b);
3799 DOSET (FLG_MAYALIASUNIQUE, b);
3800 DOSET (FLG_MUSTFREE, b);
3801 DOSET (FLG_MUSTDEFINE, b);
3802 DOSET (FLG_GLOBSTATE, b);
3803 DOSET (FLG_COMPDESTROY, b);
3804 DOSET (FLG_MUSTNOTALIAS, b);
3805 DOSET (FLG_MEMIMPLICIT, b);
3806 DOSET (FLG_BRANCHSTATE, b);
3807 /*@fallthrough@*/ /* also sets memtrans flags */
3808 case FLG_MEMTRANS:
3809 DOSET (FLG_MEMTRANS, b);
3810 DOSET (FLG_EXPOSETRANS, b);
3811 DOSET (FLG_OBSERVERTRANS, b);
3812 DOSET (FLG_DEPENDENTTRANS, b);
3813 DOSET (FLG_NEWREFTRANS, b);
3814 DOSET (FLG_ONLYTRANS, b);
3815 DOSET (FLG_OWNEDTRANS, b);
3816 DOSET (FLG_FRESHTRANS, b);
3817 DOSET (FLG_SHAREDTRANS, b);
3818 DOSET (FLG_TEMPTRANS, b);
3819 DOSET (FLG_KEPTTRANS, b);
3820 DOSET (FLG_REFCOUNTTRANS, b);
3821 DOSET (FLG_STATICTRANS, b);
3822 DOSET (FLG_UNKNOWNTRANS, b);
3823 DOSET (FLG_KEEPTRANS, b);
3824 DOSET (FLG_IMMEDIATETRANS, b);
3825 break;
3826
3827 default:
3828 break;
3829 }
3830
3831 if (b && !gc.anyExports
3832 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
3833 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
3834 || f == FLG_EXPORTCONST
3835 || f == FLG_EXPORTANY))
3836 {
3837 gc.anyExports = TRUE;
616915dd 3838 }
3839}
3840
3841bool
3842context_maybeSet (flagcode d)
3843{
3844 return (gc.flags[d] || gc.setLocally[d]);
3845}
3846
3847bool
3848context_getFlag (flagcode d)
3849{
3850 return (gc.flags[d]);
3851}
3852
28bf4b0b 3853bool
3854context_flagOn (flagcode f, fileloc loc)
3855{
3856 return (!context_suppressFlagMsg (f, loc));
3857}
3858
616915dd 3859static void context_saveFlagSettings (void)
3860{
3861 gc.savedFlags = TRUE;
3862 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3863 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
3864}
3865
3866static void context_restoreFlagSettings (void)
3867{
3868 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3869 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
3870 gc.savedFlags = FALSE;
3871}
3872
3873void context_setFilename (fileId fid, int lineno)
3874 /*@globals fileloc g_currentloc;@*/
3875 /*@modifies g_currentloc@*/
3876{
3877 if (fileId_baseEqual (currentFile (), fid))
3878 {
3879 setLine (lineno);
3880 return;
3881 }
3882 else
3883 {
3884 fileloc_setColumn (g_currentloc, 0);
3885
3886 if (fileloc_isSpecialFile (g_currentloc))
3887 {
3888 gc.inDerivedFile = TRUE;
3889 }
3890
3891 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
3892 {
3893 int maxdepth = context_getValue (FLG_INCLUDENEST);
3894
3895 if (filelocStack_size (gc.locstack) > maxdepth)
3896 {
3897 int depth = filelocStack_includeDepth (gc.locstack);
3898
3899 if (depth > maxdepth)
3900 {
3901 if (optgenerror
3902 (FLG_INCLUDENEST,
3903 message ("Maximum include nesting depth "
3904 "(%d, current depth %d) exceeded",
3905 maxdepth,
3906 depth),
3907 filelocStack_nextTop (gc.locstack)))
3908 {
3909 filelocStack_printIncludes (gc.locstack);
3910 }
3911 }
3912 }
3913 }
3914
3915 g_currentloc = fileloc_create (fid, lineno, 1);
3916 gc.inheader = fileId_isHeader (currentFile ());
3917
3918 context_enterFileAux ();
3919 }
3920}
3921
3922void context_enterIterDef (/*@observer@*/ uentry le)
3923{
3924 context_enterMacro (le);
3925 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
3926 gc.kind = CX_ITERDEF;
3927}
3928
3929void context_enterIterEnd (/*@observer@*/ uentry le)
3930{
3931 context_enterMacro (le);
3932 gc.kind = CX_ITEREND;
3933}
3934
3935void
3936context_destroyMod (void)
3937 /*@globals killed gc@*/
3938{
3939 setCodePoint ();
3940 ctype_destroyMod ();
3941 setCodePoint ();
3942 usymtab_free ();
3943 setCodePoint ();
3944 fileTable_free (gc.ftab);
3945 filelocStack_free (gc.locstack);
3946 setCodePoint ();
3947 gc.ftab = fileTable_undefined;
3948
3949 macrocache_free (gc.mc);
3950 sfree (gc.moduleaccess);
3951 setCodePoint ();
3952
3953 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
3954 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
3955
3956 setCodePoint ();
3957 sRefSetList_free (gc.modrecs);
3958 setCodePoint ();
3959 flagMarkerList_free (gc.markers);
3960 setCodePoint ();
3961 messageLog_free (gc.msgLog);
3962 setCodePoint ();
3963 clauseStack_free (gc.clauses);
3964 setCodePoint ();
3965
3966 cstring_free (gc.msgAnnote);
3967 globSet_free (gc.globs_used);
28bf4b0b 3968 metaStateTable_free (gc.stateTable);
3969 annotationTable_free (gc.annotTable);
3970}
616915dd 3971
3972/*
3973** Flag shortcuts.
3974*/
3975
3976bool context_msgBoolInt (void)
3977{
3978 return gc.flags [FLG_BOOLINT];
3979}
3980
3981bool context_msgCharInt (void)
3982{
3983 return gc.flags [FLG_CHARINT];
3984}
3985
3986bool context_msgEnumInt (void)
3987{
3988 return gc.flags [FLG_ENUMINT];
3989}
3990
3991bool context_msgPointerArith (void)
3992{
3993 return gc.flags [FLG_POINTERARITH];
3994}
3995
3996bool context_msgStrictOps (void)
3997{
3998 return gc.flags [FLG_STRICTOPS];
3999}
4000
4001# ifndef NOLCL
4002bool context_msgLh (void)
4003{
4004 return gc.flags [FLG_DOLH];
4005}
4006# endif
4007
4008void context_pushLoc (void)
4009{
4010 fileloc_free (gc.pushloc);
4011 gc.pushloc = gc.saveloc;
4012 gc.saveloc = fileloc_undefined;
4013}
4014
4015void context_popLoc (void)
4016{
4017 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4018}
4019
4020bool context_inGlobalScope (void)
4021{
4022 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4023}
4024
4025bool context_inInnerScope (void)
4026{
4027 return (gc.kind == CX_INNER);
4028}
4029
4030void context_setProtectVars (void)
4031{
4032 gc.protectVars = TRUE;
4033}
4034
4035bool context_anyErrors (void)
4036{
4037 return (gc.numerrors > 0);
4038}
4039
4040void context_hasError (void)
4041{
4042 gc.numerrors++;
4043}
4044
4045int context_numErrors (void)
4046{
4047 return gc.numerrors;
4048}
4049
4050bool context_neednl (void)
4051{
4052 return gc.neednl;
4053}
4054
4055void context_setNeednl (void)
4056{
4057 gc.neednl = TRUE;
4058}
4059
4060int context_getExpect (void)
4061{
4062 return (context_getValue (FLG_EXPECT));
4063}
4064
4065# ifndef NOLCL
4066int context_getLCLExpect (void)
4067{
4068 return (context_getValue (FLG_LCLEXPECT));
4069}
4070# endif
4071
4072int context_getLimit (void)
4073{
4074 return (context_getValue (FLG_LIMIT));
4075}
4076
4077bool context_unlimitedMessages (void)
4078{
4079 return (context_getLimit () < 0);
4080}
4081
4082void context_releaseVars (void)
4083{
4084 llassert (gc.protectVars);
4085 gc.protectVars = FALSE;
4086}
4087
4088void context_sizeofReleaseVars (void)
4089{
4090 /* If there is a nested sizeof, this might not hold:
4091 llassert (gc.protectVars);
4092 */
4093
4094 gc.protectVars = FALSE;
4095}
4096
4097bool context_inProtectVars (void)
4098{
4099 return (gc.protectVars);
4100}
4101
4102void context_hideShowscan (void)
4103{
4104 gc.flags[FLG_SHOWSCAN] = FALSE;
4105}
4106
4107void context_unhideShowscan (void)
4108{
4109 gc.flags[FLG_SHOWSCAN] = TRUE;
4110}
4111
4112bool context_inHeader (void)
4113{
4114 return (gc.inheader);
4115}
4116
4117fileTable context_fileTable (void)
4118{
4119 return gc.ftab;
4120}
4121
4122cstring context_tmpdir (void)
4123{
4124 return (context_getString (FLG_TMPDIR));
4125}
4126
4127messageLog context_messageLog (void)
4128{
4129 return gc.msgLog;
4130}
4131
4132bool context_inMacroFunction (void)
4133{
4134 return (gc.kind == CX_MACROFCN);
4135}
4136
4137bool context_inMacroConstant (void)
4138{
4139 return (gc.kind == CX_MACROCONST);
4140}
4141
4142bool context_inMacroUnknown (void)
4143{
4144 return (gc.kind == CX_UNKNOWNMACRO);
4145}
4146
4147void context_setShownFunction (void)
4148{
4149 gc.showfunction = FALSE;
4150}
4151
4152bool context_doDump (void)
4153{
4154 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4155}
4156
4157bool context_doMerge (void)
4158{
4159 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4160}
4161
4162cstring context_getDump (void)
4163{
4164 return context_getString (FLG_DUMP);
4165}
4166
4167cstring context_getMerge (void)
4168{
4169 return context_getString (FLG_MERGE);
4170}
4171
4172# ifndef NOLCL
4173bool context_inLCLLib (void)
4174{
4175 return (gc.kind == CX_LCLLIB);
4176}
4177
4178bool context_inImport (void)
4179{
4180 return (gc.inimport);
4181}
4182
4183void context_enterImport (void)
4184{
4185 gc.inimport = TRUE;
4186}
4187
4188void context_leaveImport (void)
4189{
4190 gc.inimport = FALSE;
4191}
4192# endif
4193
4194bool context_inMacro (void)
4195{
4196 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4197 || gc.kind == CX_UNKNOWNMACRO
4198 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4199}
4200
4201bool context_inIterDef (void)
4202{
4203 return (gc.kind == CX_ITERDEF);
4204}
4205
4206bool context_inIterEnd (void)
4207{
4208 return (gc.kind == CX_ITEREND);
4209}
4210
4211int context_getLinesProcessed (void)
4212{
4213 return (gc.linesprocessed);
4214}
4215
4216int context_getSpecLinesProcessed (void)
4217{
4218 return (gc.speclinesprocessed);
4219}
4220
4221# ifndef NOLCL
4222void context_processedSpecLine (void)
4223{
4224 gc.speclinesprocessed++;
4225}
4226
4227void context_resetSpecLines (void)
4228{
4229 gc.speclinesprocessed = 0;
4230}
4231# endif
4232
4233bool context_inGlobalContext (void)
4234{
4235 return (gc.kind == CX_GLOBAL);
4236}
4237
4238void context_setFileId (fileId s)
4239{
4240 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4241}
4242
4243bool context_setBoolName (void)
4244{
4245 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4246 DEFAULT_BOOLTYPE));
4247}
4248
4249cstring context_printBoolName (void)
4250{
4251 if (context_setBoolName ())
4252 {
4253 return context_getBoolName ();
4254 }
4255 else
4256 {
4257 return cstring_makeLiteralTemp ("boolean");
4258 }
4259}
4260
4261cstring context_getBoolName (void)
4262{
4263 return (context_getString (FLG_BOOLTYPE));
4264}
4265
4266cstring context_getFalseName (void)
4267{
4268 return (context_getString (FLG_BOOLFALSE));
4269}
4270
4271cstring context_getTrueName (void)
4272{
4273 return (context_getString (FLG_BOOLTRUE));
4274}
4275
4276cstring context_getLarchPath (void)
4277{
4278 return (context_getString (FLG_LARCHPATH));
4279}
4280
4281cstring context_getLCLImportDir (void)
4282{
4283 return (context_getString (FLG_LCLIMPORTDIR));
4284}
4285
4286static void context_setJustPopped (void)
4287{
4288 gc.justpopped = TRUE;
4289}
4290
4291void context_clearJustPopped (void)
4292{
4293 gc.justpopped = FALSE;
4294}
4295
4296bool context_justPopped (void)
4297{
4298 return (gc.justpopped);
4299}
4300
4301void context_setMacroMissingParams (void)
4302{
4303 gc.macroMissingParams = TRUE;
4304}
4305
4306void context_resetMacroMissingParams (void)
4307{
4308 gc.macroMissingParams = FALSE;
4309}
4310
4311bool context_isMacroMissingParams (void)
4312{
4313 return (gc.macroMissingParams);
4314}
4315
4316void context_showFilelocStack (void)
4317{
4318 filelocStack_printIncludes (gc.locstack);
4319}
4320
28bf4b0b 4321metaStateTable context_getMetaStateTable (void)
4322{
4323 return gc.stateTable;
4324}
4325
4326metaStateInfo context_lookupMetaStateInfo (cstring key)
4327{
4328 return metaStateTable_lookup (gc.stateTable, key);
4329}
4330
4331/*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4332{
4333 annotationInfo ainfo;
4334
4335 ainfo = annotationTable_lookup (gc.annotTable, annot);
4336
4337 return ainfo;
4338}
4339
4340void context_addAnnotation (annotationInfo ainfo)
4341{
4342 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4343 {
4344 voptgenerror
4345 (FLG_SYNTAX,
4346 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4347 annotationInfo_getLoc (ainfo));
4348
4349 annotationInfo_free (ainfo);
4350 }
4351 else
4352 {
4353 annotationTable_insert (gc.annotTable, ainfo);
4354 }
4355}
4356
4357void context_addMetaState (cstring mname, metaStateInfo msinfo)
4358{
4359 if (metaStateTable_contains (gc.stateTable, mname))
4360 {
4361 voptgenerror
4362 (FLG_SYNTAX,
4363 message ("Duplicate metastate declaration: %s", mname),
4364 metaStateInfo_getLoc (msinfo));
4365 cstring_free (mname);
4366 metaStateInfo_free (msinfo);
4367 }
4368 else
4369 {
990ec868 4370 DPRINTF (("Adding meta state: %s", mname));
28bf4b0b 4371 metaStateTable_insert (gc.stateTable, mname, msinfo);
4372 }
4373}
616915dd 4374
28bf4b0b 4375valueTable context_createValueTable (sRef s)
4376{
4377 if (metaStateTable_size (gc.stateTable) > 0)
4378 {
4379 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4380 /*@i32 should use smaller value... */
4381 DPRINTF (("Value table for: %s", sRef_unparse (s)));
990ec868 4382
28bf4b0b 4383 metaStateTable_elements (gc.stateTable, msname, msi)
4384 {
4385 mtContextNode context = metaStateInfo_getContext (msi);
616915dd 4386
28bf4b0b 4387 if (mtContextNode_matchesRefStrict (context, s))
4388 {
4389 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4390 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4391
990ec868 4392 valueTable_insert
4393 (res,
4394 cstring_copy (metaStateInfo_getName (msi)),
4395 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4396 stateInfo_undefined));
28bf4b0b 4397 }
4398 else
4399 {
4400 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4401 }
4402 }
4403 end_metaStateTable_elements ;
4404
4405 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4406 return res;
4407 }
4408 else
4409 {
4410 return valueTable_undefined;
4411 }
4412}
616915dd 4413
28bf4b0b 4414valueTable context_createGlobalMarkerValueTable ()
4415{
4416 if (metaStateTable_size (gc.stateTable) > 0)
4417 {
4418 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4419 /*@i32 should use smaller value... */
4420
4421 metaStateTable_elements (gc.stateTable, msname, msi)
4422 {
4423 /*@i23 only add global...*/
4424 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4425 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4426
4427 valueTable_insert (res,
4428 cstring_copy (metaStateInfo_getName (msi)),
4429 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4430 stateInfo_undefined));
4431 }
4432 end_metaStateTable_elements ;
4433
4434 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4435 return res;
4436 }
4437 else
4438 {
4439 return valueTable_undefined;
4440 }
4441}
616915dd 4442
4443
4444
This page took 0.716866 seconds and 5 git commands to generate.