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