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