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