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