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