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