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