2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
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.
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.
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.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
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.
36 # include "splintMacros.nf"
40 # include "usymtab_interface.h"
43 # include "exprChecks.h"
44 # include "filelocStack.h"
45 # include "fileIdList.h"
51 extern /*@external@*/ int yydebug;
52 extern /*@external@*/ int mtdebug;
64 CX_FUNCTION, CX_FCNDECLARATION,
65 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
66 CX_ITERDEF, CX_ITEREND,
67 CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
68 CX_LCL, CX_LCLLIB, CX_MT
74 int speclinesprocessed;
76 flagMarkerList markers;
79 ** used to record state where a macro must match a function name
80 ** (i.e., no params were listed in the macro definition
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;
94 bool showfunction BOOLBITS;
95 bool savedFlags BOOLBITS;
96 bool justpopped BOOLBITS;
97 bool anyExports BOOLBITS;
98 bool inFunctionHeader BOOLBITS;
111 filelocStack locstack;
114 /*@observer@*/ sRef aliasAnnote;
115 /*@observer@*/ sRef aliasAnnoteAls;
119 /*@observer@*/ sRefSet mods;
121 /* file access types */
124 /* local access types (this function) */
127 /* no access types (@noaccess) */
130 /*@observer@*/ globSet globs;
131 /*@only@*/ globSet globs_used;
135 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
141 bool flags[NUMFLAGS];
142 bool saveflags[NUMFLAGS];
143 bool setGlobally[NUMFLAGS];
144 bool setLocally[NUMFLAGS];
146 int values[NUMVALUEFLAGS];
147 int counters[NUMVALUEFLAGS];
149 o_cstring strings[NUMSTRINGFLAGS];
150 sRefSetList modrecs; /*@i32 ???? what is this for? */
152 metaStateTable stateTable; /* User-defined state information. */
153 annotationTable annotTable; /* User-defined annotations table. */
158 /*@dependent@*/ /*@exposed@*/ uentry fcn;
162 union u_cont savecont;
165 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
166 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
167 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
168 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
170 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
171 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
172 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
173 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
174 static void context_setFlag (flagcode p_f, bool p_b, fileloc p_loc)
175 /*@modifies gc.flags@*/ ;
178 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile,
179 bool p_isRestore, fileloc p_loc)
180 /*@modifies gc.flags@*/ ;
182 static void context_restoreFlag (flagcode p_f, fileloc p_loc)
183 /*@modifies gc.flags@*/ ;
187 cstring context_unparseFlagMarkers ()
189 return (flagMarkerList_unparse (gc.markers));
192 void context_setPreprocessing (void)
194 llassert (!gc.preprocessing);
195 gc.preprocessing = TRUE;
198 void context_clearPreprocessing (void)
200 llassert (gc.preprocessing);
201 gc.preprocessing = FALSE;
204 bool context_isPreprocessing (void)
206 return gc.preprocessing;
209 bool context_loadingLibrary (void)
211 return (fileloc_isLib (g_currentloc));
214 bool context_inXHFile (void)
216 return (fileloc_isXHFile (g_currentloc));
219 void context_setInCommandLine (void)
221 llassert (!gc.incommandline);
222 gc.incommandline = TRUE;
225 void context_clearInCommandLine (void)
227 llassert (gc.incommandline);
228 gc.incommandline = FALSE;
231 bool context_isInCommandLine (void)
233 return gc.incommandline;
237 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
240 clauseStack_push (gc.clauses, c);
242 if (clause_isConditional (c)
243 && context_getFlag (FLG_CONTROLNESTDEPTH))
245 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
246 int depth = clauseStack_controlDepth (gc.clauses);
248 if (depth == maxdepth + 1)
251 (FLG_CONTROLNESTDEPTH,
252 message ("Maximum control nesting depth "
261 clause topClause (clauseStack s) /*@*/
263 if (clauseStack_isEmpty (s)) return NOCLAUSE;
264 return ((clause) clauseStack_top (s));
268 context_addMacroCache (/*@only@*/ cstring def)
270 DPRINTF (("macro cache: %s", def));
271 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
275 context_addComment (/*@only@*/ cstring def, fileloc loc)
277 macrocache_addComment (gc.mc, fileloc_copy (loc), def);
281 ** returns TRUE is fl is in ignore region, or region where -code
283 ** the logic is fuzzy...
287 context_inSuppressFlagZone (fileloc fl, flagcode code)
289 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
292 if (ynm_isMaybe (ret))
300 res = !gc.saveflags[code];
304 res = !context_getFlag (code);
309 res = ynm_toBoolStrict (ret);
316 context_suppressSystemMsg (fileloc fl)
318 if (context_getFlag (FLG_SYSTEMDIRERRORS))
324 return (fileloc_isSystemFile (fl));
329 context_suppressFlagMsg (flagcode flag, fileloc fl)
331 if (context_suppressSystemMsg (fl))
336 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
338 /* want same object compare here */
340 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
342 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
344 return (!context_getFlag (flag)
345 || context_inSuppressRegion ()
346 || context_inSuppressZone (fl)
347 || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
351 return (context_inSuppressFlagZone (fl, flag));
356 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
359 if (context_suppressSystemMsg (fl))
365 if (fl == g_currentloc)
366 /*@noaccess fileloc@*/
368 return (context_getFlag (flag) || context_inSuppressRegion ());
373 return (context_getFlag (flag) || context_inSuppressRegion ());
378 context_inSuppressZone (fileloc fl)
380 if (context_suppressSystemMsg (fl))
385 return (flagMarkerList_inIgnore (gc.markers, fl));
389 context_inSuppressRegion (void)
391 return (gc.insuppressregion);
395 context_enterSuppressRegion (fileloc loc)
397 if (gc.insuppressregion)
399 gc.insuppressregion = FALSE; /* get this msg! */
401 ("%q: New ignore errors region entered while in ignore errors region",
402 fileloc_unparse (loc)));
405 gc.insuppressregion = TRUE;
406 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (loc));
410 context_addFlagMarker (flagcode code, ynm set, fileloc loc)
412 (void) flagMarkerList_add (gc.markers,
413 flagMarker_createLocalSet (code, set, loc));
417 context_enterSuppressLine (int count, fileloc loc)
419 if (context_processingMacros ())
424 if (flagMarkerList_add
426 flagMarker_createIgnoreCount (count, loc)))
428 fileloc nextline = fileloc_copy (loc);
429 fileloc_nextLine (nextline);
430 fileloc_setColumn (nextline, 0);
432 check (flagMarkerList_add (gc.markers,
433 flagMarker_createIgnoreOff (nextline)));
434 fileloc_free (nextline);
438 void context_checkSuppressCounts (void)
440 if (context_getFlag (FLG_SUPCOUNTS))
442 flagMarkerList_checkSuppressCounts (gc.markers);
446 void context_incLineno (void)
453 context_exitSuppressRegion (fileloc loc)
455 if (!gc.insuppressregion)
459 message ("End ignore errors in region while not ignoring errors"),
463 gc.insuppressregion = FALSE;
464 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (loc));
468 context_enterMTfile (void)
474 context_exitMTfile (void)
476 llassert (gc.kind == CX_MT);
482 context_enterLCLfile (void)
485 gc.facct = typeIdSet_emptySet ();
490 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
494 for (i = 0; i < gc.nmods; i++)
496 if (cstring_equal (gc.moduleaccess[i].file, fname))
498 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
499 cstring_free (fname);
504 if (gc.nmods == gc.maxmods)
508 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
509 oldmods = gc.moduleaccess;
511 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
513 for (i = 0; i < gc.nmods; i++)
515 gc.moduleaccess[i] = oldmods[i];
521 gc.moduleaccess[gc.nmods].file = fname;
522 gc.moduleaccess[gc.nmods].daccess = mods;
528 insertModuleAccess (cstring fname, typeId t)
532 for (i = 0; i < gc.nmods; i++)
534 if (cstring_equal (gc.moduleaccess[i].file, fname))
536 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
541 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
546 context_exitLCLfile (void)
548 if (gc.kind != CX_LCLLIB)
551 fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION);
553 addModuleAccess (fileLib_removePath (lclname), gc.facct);
554 cstring_free (lclname);
559 gc.facct = typeIdSet_emptySet ();
564 context_dumpModuleAccess (FILE *fout)
568 for (i = 0; i < gc.nmods; i++)
570 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
572 fprintf (fout, "%s#%s@\n",
573 cstring_toCharsSafe (gc.moduleaccess[i].file),
574 cstring_toCharsSafe (td));
580 bool context_usingPosixLibrary ()
582 return (gc.library == FLG_POSIXLIB
583 || gc.library == FLG_POSIXSTRICTLIB
584 || gc.library == FLG_UNIXLIB
585 || gc.library == FLG_UNIXSTRICTLIB);
588 bool context_usingAnsiLibrary ()
590 return (gc.library != FLG_NOLIB);
593 flagcode context_getLibrary ()
598 void context_setLibrary (flagcode code)
603 /*@observer@*/ cstring context_selectedLibrary ()
608 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
610 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
611 case FLG_POSIXSTRICTLIB:
612 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
614 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
615 case FLG_UNIXSTRICTLIB:
616 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
618 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
625 context_loadModuleAccess (FILE *in)
627 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
629 char *name = mstring_create (MAX_NAME_LENGTH);
635 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
641 while (s != NULL && *s != ';' && *s != '\0')
645 while (*s != '#' && *s != '\0')
654 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
655 cstring_fromChars (s)));
661 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
662 typeIdSet_undump (&s));
664 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
665 llassert (s != lasts);
675 typeIdSet context_fileAccessTypes (void)
681 context_resetModeFlags (void)
685 if (flagcode_isModeFlag (code))
687 context_setFlag (code, FALSE, g_currentloc);
695 ** Set all flags to FALSE, except for a few which are
698 ** Set all values and strings to appropriate defaults.
699 ** Set all counters to 0.
703 conext_resetAllCounters (void)
707 for (i = 0; i < NUMVALUEFLAGS; i++)
714 context_resetAllFlags (void)
716 DPRINTF (("******** Reset all flags"));
720 gc.flags[code] = FALSE;
722 if (flagcode_hasNumber (code))
726 /*@-loopswitchbreak@*/
730 val = DEFAULT_LIMIT; break;
732 val = DEFAULT_BUGSLIMIT; break;
734 val = DEFAULT_LINELEN; break;
735 case FLG_INDENTSPACES:
736 val = DEFAULT_INDENTSPACES; break;
737 case FLG_EXTERNALNAMELEN:
738 val = ISO99_EXTERNALNAMELEN; break;
739 case FLG_INTERNALNAMELEN:
740 val = ISO99_INTERNALNAMELEN; break;
741 case FLG_COMMENTCHAR:
742 val = (int) DEFAULT_COMMENTCHAR; break;
743 case FLG_CONTROLNESTDEPTH:
744 val = (int) ISO99_CONTROLNESTDEPTH; break;
745 case FLG_STRINGLITERALLEN:
746 val = (int) ISO99_STRINGLITERALLEN; break;
747 case FLG_INCLUDENEST:
748 val = (int) ISO99_INCLUDENEST; break;
749 case FLG_NUMSTRUCTFIELDS:
750 val = (int) ISO99_NUMSTRUCTFIELDS; break;
751 case FLG_NUMENUMMEMBERS:
752 val = (int) ISO99_NUMENUMMEMBERS; break;
757 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
759 /*@=loopswitchbreak@*/
761 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
762 context_setValue (code, val);
763 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
764 llassert (context_getValue (code) == val);
766 else if (flagcode_hasChar (code))
768 llassert (code == FLG_COMMENTCHAR);
769 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
771 else if (flagcode_hasString (code))
773 cstring val = cstring_undefined;
776 { /*@-loopswitchbreak@*/
779 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
781 if (cstring_isDefined (larchpath))
783 val = cstring_copy (larchpath);
787 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
792 case FLG_LCLIMPORTDIR:
794 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
798 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
800 char *env = osd_getEnvironmentVariable ("TMP");
804 env = osd_getEnvironmentVariable ("TEMP");
807 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
810 val = cstring_makeLiteral (DEFAULT_TMPDIR);
811 # endif /* !defined(OS2) && !defined(MSDOS) */
815 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
817 val = cstring_makeLiteral ("FALSE"); break;
819 val = cstring_makeLiteral ("TRUE"); break;
820 case FLG_MACROVARPREFIX:
821 val = cstring_makeLiteral ("m_"); break;
823 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
826 } /*@=loopswitchbreak@*/
828 context_setString (code, val);
832 ; /* nothing to set */
837 ** These flags are true by default.
840 /*@i34 move this into flags.def */
842 gc.flags[FLG_STREAMOVERWRITE] = TRUE;
844 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
845 gc.flags[FLG_MODIFIES] = TRUE;
846 gc.flags[FLG_NESTCOMMENT] = TRUE;
847 gc.flags[FLG_GLOBALS] = TRUE;
848 gc.flags[FLG_FULLINITBLOCK] = TRUE;
849 gc.flags[FLG_INITSIZE] = TRUE;
850 gc.flags[FLG_INITALLELEMENTS] = TRUE;
852 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
854 gc.flags[FLG_LIKELYBOOL] = TRUE;
855 gc.flags[FLG_ZEROPTR] = TRUE;
856 gc.flags[FLG_NUMLITERAL] = TRUE;
857 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
858 gc.flags[FLG_SKIPISOHEADERS] = TRUE;
859 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
860 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
861 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
862 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
863 gc.flags[FLG_CASTFCNPTR] = TRUE;
864 gc.flags[FLG_DOLCS] = TRUE;
865 gc.flags[FLG_USEVARARGS] = TRUE;
866 gc.flags[FLG_MAINTYPE] = TRUE;
867 gc.flags[FLG_SPECMACROS] = TRUE;
868 gc.flags[FLG_REDEF] = TRUE;
869 gc.flags[FLG_MACRONEXTLINE] = TRUE;
871 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
872 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
874 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
875 gc.flags[FLG_WARNUSE] = TRUE;
876 gc.flags[FLG_PREDASSIGN] = TRUE;
877 gc.flags[FLG_MODOBSERVER] = TRUE;
878 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
879 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
881 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
882 gc.flags[FLG_RETIMPONLY] = TRUE;
883 gc.flags[FLG_GLOBIMPONLY] = TRUE;
884 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
885 gc.flags[FLG_PREPROC] = TRUE;
886 gc.flags[FLG_NAMECHECKS] = TRUE;
887 gc.flags[FLG_FORMATCODE] = TRUE;
888 gc.flags[FLG_FORMATTYPE] = TRUE;
889 gc.flags[FLG_BADFLAG] = TRUE;
890 gc.flags[FLG_WARNFLAGS] = TRUE;
891 gc.flags[FLG_WARNRC] = TRUE;
892 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
893 gc.flags[FLG_WARNUNIXLIB] = TRUE;
894 gc.flags[FLG_WARNPOSIX] = TRUE;
895 gc.flags[FLG_SHOWCOL] = TRUE;
896 gc.flags[FLG_SHOWFUNC] = TRUE;
897 gc.flags[FLG_SUPCOUNTS] = TRUE;
898 gc.flags[FLG_HINTS] = TRUE;
899 gc.flags[FLG_SYNTAX] = TRUE;
900 gc.flags[FLG_TYPE] = TRUE;
901 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
902 gc.flags[FLG_ABSTRACT] = TRUE;
903 gc.flags[FLG_ITERBALANCE] = TRUE;
904 gc.flags[FLG_ITERYIELD] = TRUE;
905 gc.flags[FLG_DUPLICATECASES] = TRUE;
906 gc.flags[FLG_ALWAYSEXITS] = TRUE;
907 gc.flags[FLG_EMPTYRETURN] = TRUE;
908 gc.flags[FLG_MACRORETURN] = TRUE;
909 gc.flags[FLG_UNRECOG] = TRUE;
910 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
911 gc.flags[FLG_LINTCOMMENTS] = TRUE;
912 gc.flags[FLG_ACCESSCZECH] = TRUE;
913 gc.flags[FLG_ACCESSMODULE] = TRUE;
914 gc.flags[FLG_ACCESSFILE] = TRUE;
915 gc.flags[FLG_MACROVARPREFIX] = TRUE;
917 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
918 gc.flags[FLG_COMMENTERROR] = TRUE;
921 ** Changed for version 2.4.
924 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
930 /* commenting ou until some output issues are fixed */
931 /* gc.flags[FLG_ORCONSTRAINT] = TRUE;*/
933 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
936 gc.flags[FLG_WARNSYSFILES] = TRUE;
939 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
943 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
948 ** C is way-lame, and you can initialize an array to a constant except where
949 ** it is declared. Hence, a macro is used to set the modeflags.
953 # define SETFLAGS() \
954 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
955 if (!flagcode_isModeFlag (modeflags[i])) \
956 { llbug (message ("not a mode flag: %s", \
957 flagcode_unparse (modeflags[i]))); } \
958 else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }}
960 static void context_setModeAux (cstring p_s, bool p_warn) ;
963 context_setMode (cstring s)
965 context_setModeAux (s, TRUE);
969 context_setModeNoWarn (cstring s)
971 context_setModeAux (s, FALSE);
975 context_setModeAux (cstring s, bool warn)
977 intSet setflags = intSet_new ();
981 if (flagcode_isModeFlag (code))
983 if (gc.setGlobally[code])
985 (void) intSet_insert (setflags, (int) code);
990 if (!intSet_isEmpty (setflags))
992 cstring rflags = cstring_undefined;
995 intSet_elements (setflags, el)
997 if (cstring_isUndefined (rflags))
999 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
1003 rflags = message ("%q, %s", rflags,
1004 flagcode_unparse ((flagcode) el));
1008 if (num > 4 && intSet_size (setflags) > 6)
1010 rflags = message ("%q, (%d others) ...", rflags,
1011 intSet_size (setflags) - num);
1014 } end_intSet_elements ;
1018 voptgenerror (FLG_WARNFLAGS,
1019 message ("Setting mode %s after setting mode flags will "
1020 "override set values of flags: %s",
1025 cstring_free (rflags);
1028 intSet_free (setflags);
1030 context_resetModeFlags ();
1032 if (cstring_equalLit (s, "standard"))
1034 flagcode modeflags[] =
1036 FLG_ENUMINT, FLG_MACROMATCHNAME,
1037 FLG_STRINGLITNOROOM,
1038 FLG_MACROUNDEF, FLG_RELAXQUALS,
1039 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1040 FLG_CHECKSTRICTGLOBALIAS,
1041 FLG_CHECKEDGLOBALIAS,
1042 FLG_CHECKMODGLOBALIAS,
1043 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1044 FLG_UNSIGNEDCOMPARE,
1045 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1047 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1048 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1049 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1050 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1051 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1054 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1055 FLG_MACROSTMT, FLG_MACROPARENS,
1058 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1059 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1064 /* memchecks flags */
1066 FLG_NULLSTATE, FLG_NULLASSIGN,
1067 FLG_NULLPASS, FLG_NULLRET,
1069 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1072 /* memtrans flags */
1091 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1094 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1095 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1098 FLG_STATETRANSFER, FLG_STATEMERGE,
1099 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1101 FLG_IMPCHECKEDSPECGLOBALS,
1102 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1103 FLG_IFEMPTY, FLG_REALCOMPARE,
1104 FLG_BOOLOPS, FLG_PTRNEGATE,
1106 FLG_SHIFTIMPLEMENTATION,
1107 FLG_BUFFEROVERFLOWHIGH,
1114 else if (cstring_equalLit (s, "weak"))
1116 flagcode modeflags[] =
1118 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1119 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1120 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1121 FLG_CHARUNSIGNEDCHAR,
1123 FLG_VARUNUSED, FLG_FUNCUNUSED,
1125 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1128 FLG_BUFFEROVERFLOWHIGH,
1129 FLG_RETSTACK, FLG_PTRNEGATE,
1130 FLG_STATETRANSFER, FLG_STATEMERGE,
1131 FLG_LONGUNSIGNEDINTEGRAL,
1132 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1136 FLG_BUFFEROVERFLOWHIGH,
1142 else if (cstring_equalLit (s, "checks"))
1144 flagcode modeflags[] =
1146 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1147 FLG_STATETRANSFER, FLG_STATEMERGE,
1148 FLG_CHECKSTRICTGLOBALIAS,
1149 FLG_CHECKEDGLOBALIAS,
1150 FLG_CHECKMODGLOBALIAS,
1151 FLG_UNCHECKEDGLOBALIAS,
1153 FLG_STRINGLITNOROOM,
1154 FLG_STRINGLITNOROOMFINALNULL,
1155 FLG_STRINGLITSMALLER,
1156 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1157 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1158 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1159 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1160 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1161 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1162 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1163 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1164 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1165 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1166 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1167 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1168 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1169 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1176 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1180 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1182 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1183 FLG_EVALORDER, FLG_USEDEF,
1186 /* warn use flags */
1187 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1188 FLG_BUFFEROVERFLOWHIGH,
1190 /* memchecks flags */
1192 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1193 FLG_NULLPASS, FLG_NULLRET,
1195 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1197 /* memtrans flags */
1211 FLG_STATICINITTRANS,
1212 FLG_UNKNOWNINITTRANS,
1215 FLG_ONLYUNQGLOBALTRANS,
1216 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1219 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1220 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1223 FLG_NULLPOINTERARITH,
1224 FLG_SHADOW, FLG_DEPARRAYS,
1225 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1226 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1227 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1228 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1229 FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES,
1230 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1231 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1232 FLG_SHIFTIMPLEMENTATION,
1233 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1238 else if (cstring_equalLit (s, "strict"))
1240 flagcode modeflags[] =
1242 FLG_CHECKSTRICTGLOBALIAS,
1243 FLG_CHECKEDGLOBALIAS,
1244 FLG_CHECKMODGLOBALIAS,
1245 FLG_UNCHECKEDGLOBALIAS,
1249 FLG_STRINGLITNOROOM,
1250 FLG_STRINGLITNOROOMFINALNULL,
1251 FLG_STRINGLITSMALLER,
1252 FLG_STATETRANSFER, FLG_STATEMERGE,
1253 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1254 FLG_ALLGLOBALS, FLG_IMPTYPE,
1255 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1256 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1257 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1258 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1261 FLG_ONLYUNQGLOBALTRANS,
1262 FLG_GLOBALSIMPMODIFIESNOTHING,
1263 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1264 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1265 FLG_USEALLGLOBS, FLG_RETALIAS,
1266 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1267 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1268 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1270 FLG_EXPORTITER, FLG_EXPORTCONST,
1271 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1272 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1274 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1276 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1277 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1278 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1279 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1280 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1281 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1282 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1283 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1285 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1288 FLG_MACROREDEF, FLG_MACROEMPTY,
1289 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1291 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1293 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1294 FLG_MODOBSERVERUNCON,
1299 /* warn use flags */
1300 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1301 FLG_BUFFEROVERFLOWHIGH,
1302 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1304 /* memchecks flags */
1305 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1306 FLG_NULLPASS, FLG_NULLRET,
1308 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1310 /* memtrans flags */
1326 FLG_STATICINITTRANS,
1327 FLG_UNKNOWNINITTRANS,
1329 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1332 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1333 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1337 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1339 FLG_SHADOW, FLG_DEPARRAYS,
1340 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1341 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1342 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1343 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1344 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1345 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1346 FLG_IMPCHECKEDSTRICTSTATICS,
1347 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1348 FLG_IMPCHECKMODINTERNALS,
1349 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1350 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1351 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1352 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1353 FLG_CONTROLNESTDEPTH,
1354 FLG_FORBLOCK, FLG_WHILEBLOCK,
1355 FLG_FOREMPTY, FLG_WHILEEMPTY,
1356 FLG_IFEMPTY, FLG_IFBLOCK,
1358 FLG_REALCOMPARE, FLG_BOOLOPS,
1359 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1362 FLG_SHIFTIMPLEMENTATION,
1364 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1372 llcontbug (message ("context_setMode: bad mode: %s", s));
1377 context_isSpecialFile (cstring fname)
1379 cstring ext = fileLib_getExtension (fname);
1381 return (cstring_equalLit (ext, ".y")
1382 || cstring_equalLit (ext, ".l")
1383 || cstring_equalLit (fname, "lex.yy.c"));
1387 context_isSystemDir (cstring dir)
1389 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1390 cstring savedir = thisdir;
1391 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1393 if (cstring_isDefined (nextdir))
1395 /*@access cstring@*/
1396 *nextdir = '\0'; /* closes thisdir */
1398 /*@noaccess cstring@*/
1401 /* 2001-09-09: added thisdir[0] != '\0'
1402 ** herbert: don't compare with an empty name!
1403 ** should return false for empty directory path
1406 while (!cstring_isEmpty (thisdir))
1408 DPRINTF (("Test: %s / %s", dir, thisdir));
1410 if (osd_equalCanonicalPrefix (dir, thisdir))
1412 cstring_free (savedir);
1416 if (cstring_isDefined (nextdir))
1419 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1421 if (cstring_isDefined (nextdir))
1423 /*@access cstring@*/
1426 /*@noaccess cstring@*/
1435 DPRINTF (("Returns FALSE"));
1436 cstring_free (savedir);
1441 context_addFileAccessType (typeId t)
1445 if (context_inFunctionLike ())
1447 gc.acct = typeIdSet_insert (gc.acct, t);
1450 gc.facct = typeIdSet_insert (gc.facct, t);
1452 base = fileloc_getBase (g_currentloc);
1453 insertModuleAccess (base, t);
1454 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1455 typeIdSet_unparse (gc.acct)));
1459 context_removeFileAccessType (typeId t)
1461 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1462 || gc.kind == CX_UNKNOWNMACRO)
1464 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1467 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1468 gc.nacct = typeIdSet_insert (gc.nacct, t);
1471 void context_enterFunctionHeader (void)
1473 if (context_getFlag (FLG_GRAMMAR))
1475 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1478 if (gc.kind != CX_GLOBAL)
1480 llparseerror (cstring_makeLiteral
1481 ("Likely parse error. Function header outside global context."));
1485 llassert (gc.kind == CX_GLOBAL);
1486 DPRINTF (("Enter function header!"));
1487 gc.inFunctionHeader = TRUE;
1491 void context_exitFunctionHeader (void)
1493 if (context_getFlag (FLG_GRAMMAR))
1495 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1498 DPRINTF (("Exit function header!"));
1499 gc.inFunctionHeader = FALSE;
1502 bool context_inFunctionHeader (void)
1504 return (gc.inFunctionHeader);
1507 void context_enterFunctionDeclaration (uentry e)
1509 if (context_getFlag (FLG_GRAMMAR))
1511 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1514 DPRINTF (("Enter function decl"));
1515 llassert (gc.savekind == CX_ERROR);
1516 gc.savekind = gc.kind;
1517 gc.savecont = gc.cont;
1518 gc.kind = CX_FCNDECLARATION;
1522 void context_exitFunctionDeclaration (void)
1524 if (context_getFlag (FLG_GRAMMAR))
1526 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1529 DPRINTF (("Exit function decl"));
1530 llassert (gc.savekind != CX_ERROR);
1531 llassert (gc.kind == CX_FCNDECLARATION);
1532 gc.kind = gc.savekind;
1533 gc.cont = gc.savecont;
1535 gc.savekind = CX_ERROR;
1537 if (context_getFlag (FLG_GRAMMAR))
1539 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1543 bool context_inFunctionDeclaration (void)
1545 return (gc.kind == CX_FCNDECLARATION);
1550 context_enterMacro (/*@observer@*/ uentry e)
1552 context_enterFunction (e);
1553 gc.kind = CX_MACROFCN;
1557 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1559 llassert (uentry_isFunction (e));
1560 context_enterFunction (e);
1561 gc.kind = CX_UNKNOWNMACRO;
1564 void context_enterAndClause (exprNode e)
1567 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1568 pushClause (ANDCLAUSE);
1571 void context_enterOrClause (exprNode e)
1573 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1574 pushClause (ORCLAUSE);
1577 bool context_inDeepLoop (void)
1579 bool inLoop = FALSE;
1581 clauseStack_elements (gc.clauses, el)
1583 if (clause_isLoop (el))
1592 } end_clauseStack_elements;
1597 bool context_inDeepSwitch (void)
1599 bool inLoop = FALSE;
1601 clauseStack_elements (gc.clauses, el)
1603 if (clause_isSwitch (el))
1612 } end_clauseStack_elements;
1617 bool context_inDeepLoopSwitch (void)
1619 bool inLoop = FALSE;
1621 clauseStack_elements (gc.clauses, el)
1623 if (clause_isBreakable (el))
1632 } end_clauseStack_elements;
1637 clause context_breakClause (void)
1639 clauseStack_elements (gc.clauses, el)
1641 if (clause_isSwitch (el))
1645 else if (clause_isLoop (el))
1653 } end_clauseStack_elements;
1658 clause context_nextBreakClause (void)
1660 bool hasOne = FALSE;
1662 clauseStack_elements (gc.clauses, el)
1664 if (clause_isBreakable (el))
1675 } end_clauseStack_elements;
1680 bool context_inConditional (void)
1682 clauseStack_elements (gc.clauses, el)
1685 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1686 ** to distinguish if from ? for this
1689 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1693 } end_clauseStack_elements;
1698 void context_exitAndClause (exprNode pred, exprNode tbranch)
1700 context_setJustPopped ();
1702 llassert (gc.inclause == ANDCLAUSE);
1704 usymtab_popAndBranch (pred, tbranch);
1705 clauseStack_pop (gc.clauses);
1706 gc.inclause = topClause (gc.clauses);
1709 void context_exitOrClause (exprNode pred, exprNode tbranch)
1711 context_setJustPopped ();
1713 llassert (gc.inclause == ORCLAUSE);
1715 usymtab_popOrBranch (pred, tbranch);
1716 clauseStack_pop (gc.clauses);
1717 gc.inclause = topClause (gc.clauses);
1720 static void context_enterCondClauseAux (clause cl)
1726 static void context_enterTrueAux (exprNode e, clause cl)
1729 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1733 void context_enterIterClause (void)
1735 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1738 void context_enterDoWhileClause (void)
1740 pushClause (DOWHILECLAUSE);
1743 void context_enterWhileClause (exprNode e)
1745 context_enterTrueAux (e, WHILECLAUSE);
1748 void context_enterForClause (exprNode e)
1750 context_enterTrueAux (e, FORCLAUSE);
1753 void context_enterTrueClause (exprNode e)
1755 context_enterTrueAux (e, TRUECLAUSE);
1758 void context_enterSwitch (exprNode e)
1760 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1761 usymtab_switchBranch (e);
1762 context_enterCondClauseAux (SWITCHCLAUSE);
1765 void context_exitSwitch (exprNode e, bool allpaths)
1767 usymtab_exitSwitch (e, allpaths);
1769 while (clause_isCase (clauseStack_top (gc.clauses)))
1771 clauseStack_pop (gc.clauses);
1774 context_exitClauseSimp ();
1777 void context_enterCaseClause (exprNode e)
1779 bool branch = FALSE;
1781 DPRINTF (("Enter case clause!"));
1783 branch = usymtab_newCase (exprNode_undefined, e);
1787 context_enterCondClauseAux (CASECLAUSE);
1791 static void context_enterFalseClauseAux (exprNode e, clause cl)
1794 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1796 clauseStack_switchTop (gc.clauses, cl);
1799 void context_enterFalseClause (exprNode e)
1802 context_enterFalseClauseAux (e, FALSECLAUSE);
1806 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1808 gc.kind = CX_MACROCONST;
1810 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1812 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1816 usymtab_enterScope ();
1817 sRef_enterFunctionScope ();
1819 gc.globs = globSet_undefined;
1820 globSet_clear (gc.globs_used);
1821 gc.mods = sRefSet_undefined;
1824 uentry context_getHeader (void)
1826 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1828 llfatalbug (message ("context_getHeader: bad call: %q",
1829 context_unparse ()));
1832 return (gc.cont.fcn);
1836 context_setFunctionDefined (fileloc loc)
1840 case CX_UNKNOWNMACRO:
1843 uentry_setFunctionDefined (gc.cont.fcn, loc);
1846 /* (not a bug because of parse errors) */
1852 context_enterFunction (/*@exposed@*/ uentry e)
1854 gc.kind = CX_FUNCTION;
1857 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1859 if (uentry_hasAccessType (e))
1861 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1869 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1870 typeIdSet_unparse (gc.acct)));
1872 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1874 gc.globs = uentry_getGlobs (e);
1875 globSet_clear (gc.globs_used);
1876 gc.mods = uentry_getMods (e);
1878 usymtab_enterFunctionScope (e);
1879 sRef_enterFunctionScope ();
1882 bool context_inOldSytleScope(void)
1884 if (gc.kind == CX_OLDSTYLESCOPE)
1891 context_enterOldStyleScope (void)
1893 gc.kind = CX_OLDSTYLESCOPE;
1894 DPRINTF (("Enter old style scope!"));
1895 usymtab_enterFunctionScope (uentry_undefined);
1899 context_completeOldStyleFunction (uentry e)
1901 llassert (gc.kind == CX_OLDSTYLESCOPE);
1903 gc.kind = CX_FUNCTION;
1906 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1908 if (uentry_hasAccessType (e))
1910 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1918 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1919 typeIdSet_unparse (gc.acct)));
1921 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1923 if (!globSet_isEmpty (uentry_getGlobs (e)))
1925 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1926 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1929 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1931 gc.globs = uentry_getGlobs (e);
1932 globSet_clear (gc.globs_used);
1934 gc.mods = uentry_getMods (e);
1936 if (!sRefSet_isEmpty (gc.mods))
1938 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1939 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1942 sRef_enterFunctionScope ();
1945 static bool context_checkStrictGlobals (void)
1947 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1950 static bool context_hasGlobs (void)
1952 if (context_inFunctionLike ())
1954 return (uentry_hasGlobs (gc.cont.fcn));
1962 static bool context_checkCheckedGlobals (void)
1964 return (context_getFlag (FLG_GLOBALS)
1965 && (context_getFlag (FLG_GLOBUNSPEC)
1966 || context_hasGlobs ()));
1969 static bool context_checkUnknownGlobals (void)
1971 /* should be uentry_hasGlobs ? */
1973 return (context_getFlag (FLG_ALLGLOBALS)
1974 && (context_getFlag (FLG_GLOBUNSPEC)
1975 || context_hasGlobs ()));
1978 static bool context_checkUncheckedGlobals (void)
1984 context_checkExport (uentry e)
1986 if (!gc.anyExports) return FALSE;
1988 if (uentry_isFunction (e)
1989 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1991 return context_maybeSet (FLG_EXPORTFCN);
1993 else if (uentry_isExpandedMacro (e))
1995 return context_maybeSet (FLG_EXPORTMACRO);
1997 else if (uentry_isVariable (e))
1999 return context_maybeSet (FLG_EXPORTVAR);
2001 else if (uentry_isEitherConstant (e))
2003 return context_maybeSet (FLG_EXPORTCONST);
2005 else if (uentry_isIter (e) || uentry_isEndIter (e))
2007 return context_maybeSet (FLG_EXPORTITER);
2009 else if (uentry_isDatatype (e))
2011 return context_maybeSet (FLG_EXPORTTYPE);
2020 context_checkGlobUse (uentry glob)
2023 if (uentry_isCheckedStrict (glob))
2025 return context_checkStrictGlobals ();
2027 else if (uentry_isChecked (glob))
2029 return context_checkCheckedGlobals ();
2031 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2033 return context_checkUnknownGlobals ();
2037 llassert (uentry_isUnchecked (glob));
2039 return context_checkUncheckedGlobals ();
2044 context_checkAliasGlob (uentry glob)
2046 if (uentry_isCheckedStrict (glob))
2048 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2050 else if (uentry_isChecked (glob))
2052 return gc.flags[FLG_CHECKEDGLOBALIAS];
2054 else if (uentry_isCheckMod (glob))
2056 return gc.flags[FLG_CHECKMODGLOBALIAS];
2060 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2062 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2066 bool context_checkInternalUse (void)
2068 if (context_hasGlobs ())
2070 return (gc.flags[FLG_INTERNALGLOBS]);
2074 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2079 context_checkGlobMod (sRef el)
2081 uentry ue = sRef_getUentry (el);
2083 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2085 if (uentry_isCheckedModify (ue)
2086 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2088 if (context_hasMods ())
2090 return (gc.flags[FLG_MODGLOBS]);
2094 if (uentry_isCheckedStrict (ue))
2096 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2100 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2106 if (context_hasMods ())
2108 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2118 context_usedGlobal (/*@exposed@*/ sRef el)
2120 if (!globSet_member (gc.globs_used, el))
2123 ** The first time a global is used in a function, we need
2124 ** to clear the derived sRefs, since they were set for the
2125 ** previous function.
2128 sRef_clearDerived (el);
2129 gc.globs_used = globSet_insert (gc.globs_used, el);
2133 /*@observer@*/ sRefSet
2134 context_modList (void)
2140 context_globAccess (sRef s)
2142 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2143 return (globSet_member (gc.globs, s));
2147 context_hasAccess (typeId t)
2149 if (context_inFunctionLike ())
2151 DPRINTF (("Access %d / %s",
2152 t, typeIdSet_unparse (gc.acct)));
2153 return (typeIdSet_member (gc.acct, t));
2157 return (context_hasFileAccess (t));
2162 context_hasFileAccess (typeId t)
2164 return (typeIdSet_member (gc.facct, t));
2168 context_unparseAccess (void)
2170 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2171 typeIdSet_unparse (gc.facct)));
2175 context_unparseClauses (void)
2177 return (clauseStack_unparse (gc.clauses));
2181 context_couldHaveAccess (typeId t)
2183 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2185 return (typeIdSet_member (gc.acct, t));
2189 return (typeIdSet_member (gc.facct, t));
2194 context_getRetType (void)
2196 ctype f = ctype_undefined;
2198 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2200 f = uentry_getType (gc.cont.fcn);
2202 else if (gc.kind == CX_UNKNOWNMACRO)
2204 return ctype_unknown;
2208 llcontbuglit ("context_getRetType: not in a function context");
2209 return ctype_unknown;
2212 if (!ctype_isFunction (f))
2214 if (ctype_isKnown (f))
2216 llbuglit ("context_getRetType: not a function");
2219 return ctype_unknown;
2221 return (ctype_getReturnType (f));
2225 context_hasMods (void)
2227 if (context_inFunctionLike ())
2229 return (uentry_hasMods (gc.cont.fcn));
2238 context_exitAllClauses (void)
2240 while (!clauseStack_isEmpty (gc.clauses))
2242 clause el = clauseStack_top (gc.clauses);
2245 if (clause_isNone (el))
2247 usymtab_quietExitScope (g_currentloc);
2248 clauseStack_pop (gc.clauses);
2252 context_exitClausePlain ();
2256 clauseStack_clear (gc.clauses);
2257 gc.inclause = NOCLAUSE;
2261 context_exitAllClausesQuiet (void)
2263 while (!clauseStack_isEmpty (gc.clauses))
2265 clause el = clauseStack_top (gc.clauses);
2268 usymtab_quietExitScope (g_currentloc);
2269 clauseStack_pop (gc.clauses);
2272 clauseStack_clear (gc.clauses);
2273 gc.inclause = NOCLAUSE;
2277 void context_exitClauseSimp (void)
2280 context_setJustPopped ();
2281 clauseStack_pop (gc.clauses);
2282 gc.inclause = topClause (gc.clauses);
2286 void context_exitCaseClause (void)
2288 context_setJustPopped ();
2289 usymtab_popCaseBranch ();
2290 clauseStack_pop (gc.clauses);
2291 gc.inclause = topClause (gc.clauses);
2295 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2297 context_setJustPopped ();
2298 /*@i32 was makeAlt */
2299 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2300 clauseStack_pop (gc.clauses);
2301 gc.inclause = topClause (gc.clauses);
2304 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2306 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2308 if (gc.inclause != TRUECLAUSE)
2310 llparseerror (cstring_makeLiteral
2311 ("Likely parse error. Conditional clauses are inconsistent."));
2315 context_setJustPopped ();
2316 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2317 clauseStack_pop (gc.clauses);
2318 gc.inclause = topClause (gc.clauses);
2321 void context_exitIterClause (exprNode body)
2323 llassert (gc.inclause == ITERCLAUSE);
2325 context_setJustPopped ();
2327 if (context_getFlag (FLG_ITERLOOPEXEC))
2329 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2333 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2336 clauseStack_pop (gc.clauses);
2337 gc.inclause = topClause (gc.clauses);
2340 static void context_popCase (void) {
2342 ** If we are exiting an outer clause, sometimes still in a switch case.
2356 DPRINTF (("Popping case clause: %s",
2357 clauseStack_unparse (gc.clauses)));
2359 if (gc.inclause == CASECLAUSE) {
2360 context_exitCaseClause ();
2364 void context_exitWhileClause (exprNode pred, exprNode body)
2366 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2370 if (gc.inclause != WHILECLAUSE) {
2371 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2372 clauseStack_unparse (gc.clauses)));
2375 llassert (gc.inclause == WHILECLAUSE);
2377 context_setJustPopped ();
2381 ** predicate must be false after while loop (unless there are breaks)
2384 if (context_getFlag (FLG_WHILELOOPEXEC))
2386 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2390 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2394 usymtab_addGuards (invGuards);
2395 guardSet_free (invGuards);
2397 clauseStack_pop (gc.clauses);
2398 gc.inclause = topClause (gc.clauses);
2401 void context_exitDoWhileClause (exprNode pred)
2403 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2405 if (gc.inclause == CASECLAUSE) {
2406 /* handle Duff's device */
2407 clauseStack_pop (gc.clauses);
2408 gc.inclause = topClause (gc.clauses);
2411 llassert (gc.inclause == DOWHILECLAUSE);
2413 context_setJustPopped ();
2416 usymtab_addGuards (invGuards);
2417 guardSet_free (invGuards);
2419 clauseStack_pop (gc.clauses);
2420 gc.inclause = topClause (gc.clauses);
2423 void context_exitForClause (exprNode forPred, exprNode body)
2425 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2427 llassert (gc.inclause == FORCLAUSE);
2428 context_setJustPopped ();
2430 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2433 ** Predicate must be false after for loop (unless there are breaks)
2436 if (context_getFlag (FLG_FORLOOPEXEC))
2438 DPRINTF (("Here: for loop exec"));
2439 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2443 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2444 && exprNode_loopMustExec (forPred))
2446 DPRINTF (("Here: loop must exec"));
2447 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2451 DPRINTF (("Pop true branch:"));
2452 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2456 usymtab_addGuards (invGuards);
2457 guardSet_free (invGuards);
2458 clauseStack_pop (gc.clauses);
2459 gc.inclause = topClause (gc.clauses);
2462 static void context_exitClausePlain (void)
2464 llassert (gc.inclause != NOCLAUSE);
2466 if (gc.inclause == FALSECLAUSE)
2468 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2472 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2476 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2478 context_setJustPopped ();
2480 if (gc.inclause == FALSECLAUSE)
2482 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2484 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2486 clauseStack_pop (gc.clauses);
2487 gc.inclause = topClause (gc.clauses);
2491 context_exitTrueClause (pred, tbranch);
2496 context_returnFunction (void)
2498 usymtab_checkFinalScope (TRUE);
2502 context_exitFunction (void)
2504 DPRINTF (("Exit function: %s", context_unparse ()));
2506 if (!context_inFunction () && !context_inMacroConstant ()
2507 && !context_inUnknownMacro ()
2508 && !context_inIterDef () && !context_inIterEnd ())
2511 ** not a bug because of parse errors
2518 if (context_inMacro () && usymtab_inFunctionScope ())
2520 usymtab_exitScope (exprNode_undefined);
2523 if (uentry_hasGlobs (gc.cont.fcn))
2525 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2529 if (uentry_hasMods (gc.cont.fcn))
2531 if (context_getFlag (FLG_MUSTMOD))
2533 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2537 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2540 ** clear file static modifies
2543 /* do this first to get unused error messages */
2545 usymtab_exitScope (exprNode_undefined);
2546 sRef_exitFunctionScope ();
2548 gc.showfunction = FALSE;
2549 gc.kind = CX_GLOBAL;
2550 gc.cont.glob = TRUE;
2552 gc.globs = globSet_new ();
2553 globSet_clear (gc.globs_used);
2554 gc.mods = sRefSet_new ();
2557 llassert (clauseStack_isEmpty (gc.clauses));
2558 llassert (gc.inclause == NOCLAUSE);
2559 DPRINTF (("After exit function: %s", context_unparse ()));
2563 context_quietExitFunction (void)
2565 while (gc.kind == CX_INNER)
2567 context_exitInnerPlain ();
2570 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2571 && !context_inIterDef () && !context_inIterEnd ())
2576 usymtab_quietExitScope (g_currentloc);
2578 gc.showfunction = FALSE;
2579 gc.kind = CX_GLOBAL;
2580 gc.cont.glob = TRUE;
2582 gc.globs = globSet_new ();
2583 globSet_clear (gc.globs_used);
2584 gc.mods = sRefSet_new ();
2586 sRef_exitFunctionScope ();
2590 /*@observer@*/ uentryList
2591 context_getParams (void)
2593 if (context_inFunctionLike ())
2595 return (uentry_getParams (gc.cont.fcn));
2599 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2600 return uentryList_undefined;
2604 /*@observer@*/ globSet
2605 context_getUsedGlobs (void)
2607 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2608 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2610 return (gc.globs_used);
2614 context_moduleName ()
2616 return (fileloc_getBase (g_currentloc));
2619 /*@observer@*/ globSet
2620 context_getGlobs (void)
2622 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2623 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2629 context_addBoolAccess (void)
2631 cstring bname = context_getString (FLG_BOOLTYPE);
2632 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2634 addModuleAccess (cstring_copy (bname), boolt);
2636 /* for sys/types (perhaps, this is bogus!) */
2637 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2642 context_canAccessBool (void)
2649 static typeId boolType = typeId_invalid;
2651 if (typeId_isInvalid (boolType))
2653 boolType = usymtab_getTypeId (context_getBoolName ());
2656 if (typeId_isInvalid (boolType)) {
2659 return (typeIdSet_member (gc.acct, boolType));
2664 /* evs 2000-07-25: old version - replaced */
2667 context_boolImplementationType () {
2668 /* For now, this is bogus! */
2673 context_canAccessBool (void)
2675 static typeId boolType = typeId_invalid;
2677 if (typeId_isInvalid (boolType))
2679 boolType = usymtab_getTypeId (context_getBoolName ());
2682 if (!typeId_isInvalid (boolType))
2684 return context_hasAccess (boolType);
2695 context_setMessageAnnote (/*@only@*/ cstring s)
2697 llassert (cstring_isUndefined (gc.msgAnnote));
2702 context_hasMessageAnnote (void)
2704 return (cstring_isDefined (gc.msgAnnote));
2708 context_clearMessageAnnote (void)
2710 if (cstring_isDefined (gc.msgAnnote))
2712 cstring_free (gc.msgAnnote);
2713 gc.msgAnnote = cstring_undefined;
2718 context_getMessageAnnote (void)
2720 cstring st = gc.msgAnnote;
2722 gc.msgAnnote = cstring_undefined;
2727 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2729 llassert (sRef_isInvalid (gc.aliasAnnote));
2730 llassert (!sRef_sameName (s, t));
2732 gc.aliasAnnoteAls = t;
2736 context_hasAliasAnnote (void)
2738 return (sRef_isValid (gc.aliasAnnote));
2742 context_clearAliasAnnote (void)
2744 gc.aliasAnnote = sRef_undefined;
2748 context_getAliasAnnote (void)
2750 sRef ret = gc.aliasAnnote;
2751 sRef als = gc.aliasAnnoteAls;
2753 llassert (sRef_isValid (ret) && sRef_isValid (als));
2755 gc.aliasAnnote = sRef_undefined;
2756 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2760 context_recordFileModifies (sRefSet mods)
2762 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2766 context_recordFileGlobals (globSet mods)
2768 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2769 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2773 context_setCommentMarkerChar (char c)
2775 llassert (c != '\0');
2777 context_setValue (FLG_COMMENTCHAR, (int) c);
2781 context_getCommentMarkerChar (void)
2783 return ((char) context_getValue (FLG_COMMENTCHAR));
2787 context_setValue (flagcode flag, int val)
2789 int index = flagcode_valueIndex (flag);
2791 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2799 llerror_flagWarning (message ("Value for %s must be a positive "
2800 "number (given %d)",
2801 flagcode_unparse (flag), val));
2804 if (flag == FLG_LINELEN && val < MINLINELEN)
2806 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2807 flagcode_unparse (flag),
2813 case FLG_INCLUDENEST:
2814 case FLG_CONTROLNESTDEPTH:
2815 case FLG_STRINGLITERALLEN:
2816 case FLG_NUMSTRUCTFIELDS:
2817 case FLG_NUMENUMMEMBERS:
2818 case FLG_INDENTSPACES:
2821 llerror_flagWarning (message ("Value for %s must be a non-negative "
2822 "number (given %d)",
2823 flagcode_unparse (flag), val));
2832 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2833 gc.values[index] = val;
2837 context_setValueAndFlag (flagcode flag, int val)
2839 gc.flags[flag] = TRUE;
2840 context_setValue (flag, val);
2844 context_getValue (flagcode flag)
2846 int index = flagcode_valueIndex (flag);
2848 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2849 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2850 return (gc.values[index]);
2854 context_getCounter (flagcode flag)
2856 int index = flagcode_valueIndex (flag);
2858 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2859 return (gc.counters[index]);
2863 context_incCounter (flagcode flag)
2865 int index = flagcode_valueIndex (flag);
2867 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2869 gc.counters[index]++;
2873 context_decCounter (flagcode flag)
2875 int index = flagcode_valueIndex (flag);
2877 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2878 gc.counters[index]--;
2881 bool context_showFunction (void)
2883 return (gc.showfunction);
2887 context_setString (flagcode flag, cstring val)
2889 int index = flagcode_stringIndex (flag);
2891 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2893 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2897 case FLG_MESSAGESTREAM:
2898 case FLG_WARNINGSTREAM:
2899 case FLG_ERRORSTREAM:
2901 if (cstring_isDefined (val))
2905 if (osd_fileExists (val))
2907 if (context_getFlag (FLG_STREAMOVERWRITE))
2909 llfatalerror (message
2910 ("Output stream file %s would overwrite existing file. "
2911 "Use -streamoverwrite if you want to allow this.",
2916 fstream = fopen (cstring_toCharsSafe (val), "w");
2918 if (fstream == NULL)
2920 llfatalerror (message ("Unable to open output stream file %s for writing",
2925 ** This ensures fstream will be closed on exit.
2928 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2932 case FLG_MESSAGESTREAM:
2933 g_messagestream = fstream;
2934 /*@innerbreak@*/ break;
2935 case FLG_WARNINGSTREAM:
2936 g_warningstream = fstream;
2937 /*@innerbreak@*/ break;
2938 case FLG_ERRORSTREAM:
2939 g_errorstream = fstream;
2940 /*@innerbreak@*/ break;
2943 /*@-statetransfer@*/
2944 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2947 case FLG_SYSTEMDIRS:
2949 llassert (cstring_isDefined (val));
2951 if (cstring_firstChar (val) == '\"')
2954 cstring tval = cstring_copy (cstring_suffix (val, 1));
2956 if (cstring_lastChar (tval) != '\"')
2958 int n = cstring_length (tval) - 1;
2960 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2965 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2968 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2972 cstring otval = tval;
2973 tval = cstring_prefix (tval, size_fromInt (n));
2974 cstring_free (otval);
2978 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2979 DPRINTF (("val = %s", val));
2980 cstring_free (tval);
2981 cstring_free (oval);
2988 llassert (cstring_isDefined (val));
2990 if (cstring_length (val) == 0)
2993 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2995 else if (cstring_lastChar (val) != CONNECTCHAR)
2997 val = cstring_appendChar (val, CONNECTCHAR);
3007 ; /* Okay not handle everything in this switch */
3011 if (cstring_length (val) >= 1
3012 && cstring_firstChar (val) == '\"')
3014 llerror_flagWarning (message
3015 ("setting %s to string beginning with \". You probably "
3016 "don't meant to have the \"'s.",
3017 flagcode_unparse (flag)));
3020 gc.strings[index] = val;
3023 static /*@exposed@*/ cstring
3024 context_exposeString (flagcode flag)
3026 int index = flagcode_stringIndex (flag);
3028 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3029 return (gc.strings[index]);
3033 context_getString (flagcode flag)
3035 return (context_exposeString (flag));
3039 context_resetErrors (void)
3044 void context_initMod (void)
3045 /*@globals undef gc; @*/
3047 gc.kind = CX_GLOBAL;
3049 gc.savekind = CX_ERROR;
3050 gc.savecont.glob = FALSE;
3052 gc.instandardlib = FALSE;
3055 gc.linesprocessed = 0;
3056 gc.speclinesprocessed = 0;
3057 gc.insuppressregion = FALSE;
3058 gc.macroMissingParams = FALSE;
3059 gc.preprocessing = FALSE;
3060 gc.incommandline = FALSE;
3061 gc.mc = macrocache_create ();
3063 gc.maxmods = DEFAULTMAXMODS;
3064 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3066 gc.library = FLG_ANSILIB;
3068 gc.locstack = filelocStack_new ();
3069 gc.modrecs = sRefSetList_undefined;
3070 gc.anyExports = FALSE;
3072 gc.ftab = fileTable_create ();
3073 gc.msgLog = messageLog_new ();
3074 gc.inimport = FALSE;
3075 gc.inDerivedFile = FALSE;
3076 gc.inheader = FALSE;
3077 gc.markers = flagMarkerList_new ();
3078 gc.cont.glob = TRUE;
3079 gc.showfunction = FALSE;
3080 gc.msgAnnote = cstring_undefined;
3081 gc.aliasAnnote = sRef_undefined;
3082 gc.aliasAnnoteAls = sRef_undefined;
3083 gc.boolType = ctype_bool;
3084 gc.mods = sRefSet_new ();
3086 gc.saveloc = fileloc_undefined;
3088 gc.inmacrocache = FALSE;
3089 gc.inclause = NOCLAUSE;
3090 gc.clauses = clauseStack_new ();
3091 gc.globs = globSet_new ();
3092 gc.nacct = typeIdSet_emptySet ();
3093 gc.acct = typeIdSet_emptySet ();
3094 gc.facct = typeIdSet_emptySet ();
3095 gc.savedFlags = FALSE;
3096 gc.pushloc = fileloc_undefined;
3097 gc.protectVars = FALSE;
3098 gc.justpopped = FALSE;
3099 gc.isNullGuarded = NO;
3100 gc.globs_used = globSet_undefined;
3104 gc.setGlobally[code] = FALSE;
3105 gc.setLocally[code] = FALSE;
3111 context_resetAllFlags ();
3113 assertSet (gc.flags); /* Can't use global in defines */
3114 assertSet (gc.saveflags);
3115 assertSet (gc.values);
3116 assertSet (gc.strings);
3118 conext_resetAllCounters ();
3119 assertSet (gc.counters);
3121 context_setMode (DEFAULT_MODE);
3123 gc.stateTable = metaStateTable_create ();
3124 gc.annotTable = annotationTable_create ();
3126 gc.inFunctionHeader = FALSE;
3128 DPRINTF (("Annotations: \n%s",
3129 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3130 DPRINTF (("State: \n%s",
3131 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3136 context_typeofZero (void)
3138 ctype ct = ctype_int;
3140 if (context_getFlag (FLG_ZEROPTR))
3142 ct = ctype_makeConj (ct, ctype_voidPointer);
3145 if (context_getFlag (FLG_ZEROBOOL)) {
3146 ct = ctype_makeConj (ct, ctype_bool);
3153 context_typeofOne (void)
3155 ctype ct = ctype_int;
3157 /* 1 is on longer a bool (was before 2.4)
3158 if (!context_getFlag (FLG_ABSTRACTBOOL))
3160 ct = ctype_makeConj (ct, ctype_bool);
3168 context_unparse (void)
3175 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3178 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3181 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3184 s = message ("Inner Context [%d] : %q",
3186 fileloc_unparse (g_currentloc));
3189 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3190 uentry_unparse (gc.cont.fcn),
3191 fileloc_unparse (g_currentloc),
3192 typeIdSet_unparse (gc.acct),
3193 sRefSet_unparse (gc.mods));
3196 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3198 case CX_UNKNOWNMACRO:
3199 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3202 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3205 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3208 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3210 case CX_FCNDECLARATION:
3211 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3214 s = message ("Un-unparseable context: %d", (int) gc.kind);
3218 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3223 context_currentFunctionType (void)
3225 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3227 return (uentry_getType (gc.cont.fcn));
3229 else if (gc.kind == CX_INNER)
3231 llcontbuglit ("context_currentFunctionType: inner context");
3232 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3233 return (context_currentFunctionType ());
3237 llcontbuglit ("context_currentFunctionType: not in function");
3238 return (ctype_undefined);
3243 context_enterInnerContext (void)
3245 if (context_getFlag (FLG_GRAMMAR))
3247 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3250 if (gc.kind == CX_GLOBAL)
3255 else if (gc.kind == CX_INNER)
3264 usymtab_enterScope ();
3265 pushClause (NOCLAUSE);
3269 context_exitInnerPlain (void) /*@modifies gc;@*/
3271 context_exitInner (exprNode_undefined);
3275 context_exitInner (exprNode exp)
3277 if (context_getFlag (FLG_GRAMMAR))
3279 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3282 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3283 ("inclause = %s", clause_nameTaken (gc.inclause)));
3285 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3286 gc.inclause = topClause (gc.clauses);
3288 if (gc.kind == CX_INNER)
3290 if (--gc.cont.cdepth == 0)
3292 gc.kind = CX_GLOBAL;
3293 gc.cont.glob = TRUE;
3298 if (gc.kind == CX_GLOBAL)
3300 llcontbuglit ("Attempt to exit global context");
3305 usymtab_exitScope (exp);
3310 context_enterStructInnerContext (void)
3312 if (context_getFlag (FLG_GRAMMAR))
3314 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3317 if (gc.kind == CX_GLOBAL)
3322 else if (gc.kind == CX_INNER)
3331 usymtab_enterScope ();
3333 if (context_getFlag (FLG_GRAMMAR))
3335 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3340 context_exitStructInnerContext (void)
3342 if (context_getFlag (FLG_GRAMMAR))
3344 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3347 if (gc.kind == CX_INNER)
3349 if (gc.cont.cdepth <= 0)
3351 llcontbuglit ("Attempt to exit inner context with no depth");
3352 gc.kind = CX_GLOBAL;
3353 gc.cont.glob = TRUE;
3359 if (gc.cont.cdepth == 0)
3361 gc.kind = CX_GLOBAL;
3362 gc.cont.glob = TRUE;
3368 if (gc.kind == CX_GLOBAL)
3370 llcontbuglit ("Attempt to exit global context");
3375 usymtab_exitScope (exprNode_undefined);
3377 if (context_getFlag (FLG_GRAMMAR))
3379 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3384 context_exitInnerSafe (void)
3386 if (context_getFlag (FLG_GRAMMAR))
3388 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3391 if (gc.kind == CX_INNER)
3393 if (--gc.cont.cdepth <= 0)
3398 else if (gc.kind == CX_GLOBAL)
3400 llcontbuglit ("Attempt to exit global context");
3405 if (usymtab_inDeepScope ())
3407 usymtab_exitScope (exprNode_undefined);
3413 void setModuleAccess (void)
3415 gc.facct = typeIdSet_emptySet ();
3417 if (fileId_isValid (currentFile ()))
3419 cstring baseName = fileloc_getBase (g_currentloc);
3421 if (context_getFlag (FLG_ACCESSFILE))
3423 if (usymtab_existsType (baseName))
3425 gc.facct = typeIdSet_insert (gc.facct,
3426 usymtab_getTypeId (baseName));
3434 if (context_getFlag (FLG_ACCESSMODULE))
3437 bool hasaccess = FALSE;
3439 for (i = 0; i < gc.nmods; i++)
3441 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3443 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3452 gc.inheader = fileId_isHeader (currentFile ());
3456 llcontbuglit ("Current file not defined\n");
3457 gc.facct = typeIdSet_emptySet ();
3459 gc.inheader = FALSE;
3462 /* 17 Jan 1995: forgot to clear nacct */
3464 gc.nacct = typeIdSet_emptySet ();
3468 context_enterFileAux (void)
3474 context_enterFile (void)
3476 context_enterFileAux ();
3477 usymtab_enterFile ();
3481 context_enterMacroFile (void)
3483 context_enterFileAux ();
3487 context_inFunction (void)
3489 kcontext ck = gc.kind;
3491 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3495 context_inFunctionLike (void)
3497 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3498 || gc.kind == CX_FCNDECLARATION
3499 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3503 context_inRealFunction (void)
3505 kcontext ck = gc.kind;
3507 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3511 context_processAllMacros (void)
3513 usymtab_enterFile ();
3515 gc.inmacrocache = TRUE;
3516 macrocache_processUndefinedElements (gc.mc);
3518 usymtab_exitFile ();
3520 gc.inmacrocache = FALSE;
3521 macrocache_finalize ();
3525 ** this happens once at the end of each C file
3527 ** check each Macro that was defined in current file.c or current file.h
3532 context_processMacros (void)
3534 if (fileId_isValid (currentFile ()))
3537 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3539 gc.inmacrocache = TRUE;
3541 DPRINTF (("Processing macros: %s", cbase));
3542 lastfl = macrocache_processFileElements (gc.mc, cbase);
3543 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3545 cstring_free (cbase);
3547 if (fileloc_isDefined (lastfl))
3549 g_currentloc = fileloc_update (g_currentloc, lastfl);
3553 gc.inmacrocache = FALSE;
3558 context_processingMacros (void)
3560 return (gc.inmacrocache);
3564 context_exitCFile (void)
3566 if (gc.kind != CX_GLOBAL)
3569 (cstring_makeLiteral ("File ended outside global scope"));
3572 if (gc.insuppressregion)
3574 /* gack...don't reverse the order of these lines! ;-> */
3575 gc.insuppressregion = FALSE;
3576 llerrorlit (FLG_SYNTAX,
3577 "File ended in ignore errors region, "
3578 "possible missing /*@end*/");
3581 /* fix up parse errors */
3583 while (!usymtab_inFileScope ())
3585 usymtab_quietExitScope (g_currentloc);
3589 ** Clear the file-specific modifies information.
3592 sRefSetList_elements (gc.modrecs, mods)
3594 sRefSet_clearStatics (mods);
3595 } end_sRefSetList_elements ;
3597 sRefSetList_clear (gc.modrecs);
3599 context_processMacros ();
3602 usymtab_exitFile ();
3604 gc.inDerivedFile = FALSE;
3605 filelocStack_clear (gc.locstack);
3607 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3609 gc.cont.glob = TRUE;
3613 context_restoreFlagSettings ();
3614 gc.savedFlags = FALSE;
3618 DPRINTF (("After exiting file: "));
3619 usymtab_printAll ();
3624 context_exitMacroCache (void)
3626 if (gc.kind != CX_GLOBAL)
3628 if (context_inMacro ())
3629 /* this is okay, file could end without newline in macro */
3631 DPRINTF (("Still in macro: %s",
3632 context_unparse ()));
3633 context_exitFunction ();
3637 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3638 context_unparse ()));
3639 gc.kind = CX_GLOBAL;
3644 ** no longer valid here
3645 ** if (gc.insuppressregion)
3647 ** gc.insuppressregion = FALSE;
3648 ** llerror ("File ended in ignore errors region, possible missing @");
3652 gc.cont.glob = TRUE;
3656 context_saveLocation (void)
3658 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3659 fileloc_free (gc.saveloc);
3660 gc.saveloc = fileloc_copy (g_currentloc);
3664 context_getSaveLocation (void)
3666 fileloc fl = gc.saveloc;
3667 gc.saveloc = fileloc_undefined;
3671 /*@observer@*/ cstring
3672 context_inFunctionName (void)
3674 if (gc.kind == CX_FUNCTION
3675 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3676 || gc.kind == CX_MACROCONST
3677 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3679 return (uentry_rawName (gc.cont.fcn));
3683 llcontbuglit ("context_inFunctionName: not in function");
3684 return (cstring_undefined);
3689 context_userSetFlag (flagcode f, bool b)
3691 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3693 if (f == FLG_NEVERINCLUDE && b)
3695 if (gc.flags[FLG_EXPORTHEADER])
3698 (cstring_makeLiteral
3699 ("setting +neverinclude after +exportheader. "
3700 "Turning off exportheader, since headers are not checked "
3701 "when +neverinclude is used."));
3703 gc.flags[FLG_EXPORTHEADER] = FALSE;
3708 if (f == FLG_EXPORTHEADER && b)
3710 if (gc.flags[FLG_NEVERINCLUDE])
3713 (cstring_makeLiteral
3714 ("setting +exportheader after +neverinclude. "
3715 "Not setting exportheader, since headers are not checked "
3716 "when +neverinclude is used."));
3717 gc.flags[FLG_EXPORTHEADER] = FALSE;
3723 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3725 bool lastsetting = context_getFlag (f);
3727 if (bool_equal (lastsetting, b)
3728 && !flagcode_isSpecialFlag (f)
3729 && !flagcode_isIdemFlag (f)
3730 && !flagcode_hasArgument (f))
3733 (message ("setting %s%s redundant with current value",
3734 cstring_makeLiteralTemp (b ? "+" : "-"),
3735 flagcode_unparse (f)));
3739 if (flagcode_isWarnUseFlag (f) && b)
3741 if (!context_getFlag (FLG_WARNUSE))
3744 (message ("flag +%s is canceled by -warnuse",
3745 flagcode_unparse (f)));
3750 if (flagcode_isLibraryFlag (f))
3752 if (gc.library != FLG_ANSILIB
3756 (message ("selecting library %s after library %s was "
3757 "selected (only one library may be used)",
3758 flagcode_unparse (f),
3759 flagcode_unparse (gc.library)));
3762 if (f == FLG_UNIXLIB)
3764 if (context_getFlag (FLG_WARNUNIXLIB))
3767 (cstring_makeLiteral
3768 ("selecting unix library. Unix library is "
3769 "ad hoc addition to POSIX library. Recommend "
3770 "use +posixlib to select POSIX library instead. "
3771 "Use -warnunixlib to suppress this message."));
3778 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3782 ("setting +%s will not produce warnings with -namechecks. "
3783 "Must set +namechecks also.",
3784 flagcode_unparse (f)));
3787 gc.setGlobally[f] = TRUE;
3788 context_setFlag (f, b, g_currentloc);
3792 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3796 context_saveFlagSettings ();
3799 if (ynm_isOff (set))
3801 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3803 else if (ynm_isOn (set))
3805 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3806 gc.setLocally[f] = TRUE;
3810 context_restoreFlag (f, loc);
3815 context_restoreFlag (flagcode f, fileloc loc)
3821 message ("Attempt to restore flag %s when no file scope flags "
3823 flagcode_unparse (f)),
3828 context_addFlagMarker (f, MAYBE, loc);
3829 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3835 context_setFlag (flagcode f, bool b, fileloc loc)
3837 context_setFlagAux (f, b, FALSE, FALSE, loc);
3841 context_setFlagTemp (flagcode f, bool b)
3843 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3848 # define DOSET(ff,b) \
3849 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3850 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3851 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3852 gc.flags[ff] = b; } while (FALSE)
3855 context_setFlagAux (flagcode f, bool b, bool inFile,
3856 /*@unused@*/ bool isRestore, fileloc loc)
3858 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3861 ** Removed test for special flags.
3864 if (flagcode_isIdemFlag (f))
3873 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3875 if (b) /* Turing higher level on, turns on all lower levels */
3879 case FLG_ITS4MOSTRISKY:
3880 DOSET (FLG_ITS4VERYRISKY, b);
3882 case FLG_ITS4VERYRISKY:
3883 DOSET (FLG_ITS4RISKY, b);
3886 DOSET (FLG_ITS4MODERATERISK, b);
3888 case FLG_ITS4MODERATERISK:
3889 DOSET (FLG_ITS4LOWRISK, b);
3891 case FLG_ITS4LOWRISK:
3896 else /* Turning level off, turns off all higher levels */
3900 case FLG_ITS4LOWRISK:
3901 DOSET (FLG_ITS4MODERATERISK, b);
3903 case FLG_ITS4MODERATERISK:
3904 DOSET (FLG_ITS4RISKY, b);
3907 DOSET (FLG_ITS4VERYRISKY, b);
3909 case FLG_ITS4VERYRISKY:
3910 DOSET (FLG_ITS4MOSTRISKY, b);
3912 case FLG_ITS4MOSTRISKY:
3921 case FLG_MESSAGESTREAMSTDOUT:
3922 g_messagestream = stdout;
3924 case FLG_MESSAGESTREAMSTDERR:
3925 g_messagestream = stderr;
3927 case FLG_WARNINGSTREAMSTDOUT:
3928 g_warningstream = stdout;
3930 case FLG_WARNINGSTREAMSTDERR:
3931 g_warningstream = stderr;
3933 case FLG_ERRORSTREAMSTDOUT:
3934 g_errorstream = stdout;
3936 case FLG_ERRORSTREAMSTDERR:
3937 g_errorstream = stderr;
3940 DOSET (FLG_ALLEMPTY, b);
3941 DOSET (FLG_IFEMPTY, b);
3942 DOSET (FLG_WHILEEMPTY, b);
3943 DOSET (FLG_FOREMPTY, b);
3946 DOSET (FLG_PREDBOOL, b);
3947 DOSET (FLG_PREDBOOLINT, b);
3948 DOSET (FLG_PREDBOOLPTR, b);
3949 DOSET (FLG_PREDBOOLOTHERS, b);
3952 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3953 DOSET (FLG_CHECKEDGLOBALIAS, b);
3954 DOSET (FLG_CHECKMODGLOBALIAS, b);
3955 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3958 DOSET (FLG_ALLBLOCK, b);
3959 DOSET (FLG_IFBLOCK, b);
3960 DOSET (FLG_WHILEBLOCK, b);
3961 DOSET (FLG_FORBLOCK, b);
3975 DOSET (FLG_GRAMMAR, b);
3977 case FLG_CODEIMPONLY:
3978 DOSET (FLG_CODEIMPONLY, b);
3979 DOSET (FLG_GLOBIMPONLY, b);
3980 DOSET (FLG_RETIMPONLY, b);
3981 DOSET (FLG_STRUCTIMPONLY, b);
3983 case FLG_SPECALLIMPONLY:
3984 DOSET (FLG_SPECALLIMPONLY, b);
3985 DOSET (FLG_SPECGLOBIMPONLY, b);
3986 DOSET (FLG_SPECRETIMPONLY, b);
3987 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3989 case FLG_ALLIMPONLY:
3990 DOSET (FLG_ALLIMPONLY, b);
3991 DOSET (FLG_GLOBIMPONLY, b);
3992 DOSET (FLG_RETIMPONLY, b);
3993 DOSET (FLG_STRUCTIMPONLY, b);
3994 DOSET (FLG_SPECGLOBIMPONLY, b);
3995 DOSET (FLG_SPECRETIMPONLY, b);
3996 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3998 case FLG_ANSI89LIMITS:
3999 DOSET (FLG_ANSI89LIMITS, b);
4000 DOSET (FLG_CONTROLNESTDEPTH, b);
4001 DOSET (FLG_STRINGLITERALLEN, b);
4002 DOSET (FLG_INCLUDENEST, b);
4003 DOSET (FLG_NUMSTRUCTFIELDS, b);
4004 DOSET (FLG_NUMENUMMEMBERS, b);
4008 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4009 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4010 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4011 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4012 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4013 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4014 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4017 case FLG_ISO99LIMITS:
4018 DOSET (FLG_ISO99LIMITS, b);
4019 DOSET (FLG_CONTROLNESTDEPTH, b);
4020 DOSET (FLG_STRINGLITERALLEN, b);
4021 DOSET (FLG_INCLUDENEST, b);
4022 DOSET (FLG_NUMSTRUCTFIELDS, b);
4023 DOSET (FLG_NUMENUMMEMBERS, b);
4027 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4028 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4029 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4030 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4031 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4032 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4033 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4036 case FLG_EXTERNALNAMELEN:
4037 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4038 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4040 case FLG_INTERNALNAMELEN:
4041 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4042 DOSET (FLG_INTERNALNAMELEN, TRUE);
4044 case FLG_EXTERNALNAMECASEINSENSITIVE:
4045 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4047 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4049 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4050 context_setValue (FLG_EXTERNALNAMELEN, 0);
4053 case FLG_INTERNALNAMECASEINSENSITIVE:
4054 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4056 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4058 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4059 context_setValue (FLG_INTERNALNAMELEN, 0);
4062 case FLG_INTERNALNAMELOOKALIKE:
4063 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4065 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4067 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4068 context_setValue (FLG_INTERNALNAMELEN, 0);
4072 DOSET (FLG_MODNOMODS, b);
4073 DOSET (FLG_MODGLOBSUNSPEC, b);
4074 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4077 DOSET (FLG_EXPORTVAR, b);
4078 DOSET (FLG_EXPORTFCN, b);
4079 DOSET (FLG_EXPORTTYPE, b);
4080 DOSET (FLG_EXPORTMACRO, b);
4081 DOSET (FLG_EXPORTCONST, b);
4082 gc.anyExports = TRUE;
4085 DOSET (FLG_RETEXPOSE, b);
4086 DOSET (FLG_ASSIGNEXPOSE, b);
4087 DOSET (FLG_CASTEXPOSE, b);
4090 DOSET (FLG_RETVALBOOL, b);
4091 DOSET (FLG_RETVALINT, b);
4092 DOSET (FLG_RETVALOTHER, b);
4097 DOSET (FLG_EXPORTLOCAL, FALSE);
4098 DOSET (FLG_DECLUNDEF, FALSE);
4099 DOSET (FLG_SPECUNDEF, FALSE);
4100 DOSET (FLG_TOPUNUSED, FALSE);
4104 DOSET (FLG_LOOPLOOPBREAK, b);
4105 DOSET (FLG_LOOPSWITCHBREAK, b);
4106 DOSET (FLG_SWITCHLOOPBREAK, b);
4107 DOSET (FLG_SWITCHSWITCHBREAK, b);
4108 DOSET (FLG_LOOPLOOPCONTINUE, b);
4109 DOSET (FLG_DEEPBREAK, b);
4112 DOSET (FLG_FORLOOPEXEC, b);
4113 DOSET (FLG_WHILELOOPEXEC, b);
4114 DOSET (FLG_ITERLOOPEXEC, b);
4117 DOSET (FLG_ACCESSMODULE, b);
4118 DOSET (FLG_ACCESSFILE, b);
4119 DOSET (FLG_ACCESSCZECH, b);
4122 DOSET (FLG_ALLMACROS, b);
4123 DOSET (FLG_FCNMACROS, b);
4124 DOSET (FLG_CONSTMACROS, b);
4127 DOSET (FLG_BOUNDSREAD, b);
4128 DOSET (FLG_BOUNDSWRITE, b);
4131 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4132 DOSET (FLG_CZECHFUNCTIONS, b);
4133 DOSET (FLG_CZECHVARS, b);
4134 DOSET (FLG_CZECHCONSTANTS, b);
4135 DOSET (FLG_CZECHTYPES, b);
4138 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4139 DOSET (FLG_SLOVAKFUNCTIONS, b);
4140 DOSET (FLG_SLOVAKVARS, b);
4141 DOSET (FLG_SLOVAKCONSTANTS, b);
4142 DOSET (FLG_SLOVAKTYPES, b);
4144 case FLG_CZECHOSLOVAK:
4145 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4146 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4147 DOSET (FLG_CZECHOSLOVAKVARS, b);
4148 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4149 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4152 DOSET (FLG_NULLSTATE, b);
4153 DOSET (FLG_NULLDEREF, b);
4154 DOSET (FLG_NULLASSIGN, b);
4155 DOSET (FLG_NULLPASS, b);
4156 DOSET (FLG_NULLRET, b);
4159 DOSET (FLG_MUSTFREEONLY, b);
4160 DOSET (FLG_MUSTFREEFRESH, b);
4163 DOSET (FLG_NULLSTATE, b);
4164 DOSET (FLG_NULLDEREF, b);
4165 DOSET (FLG_NULLASSIGN, b);
4166 DOSET (FLG_NULLPASS, b);
4167 DOSET (FLG_NULLRET, b);
4168 DOSET (FLG_COMPDEF, b);
4169 DOSET (FLG_COMPMEMPASS, b);
4170 DOSET (FLG_UNIONDEF, b);
4171 DOSET (FLG_MEMTRANS, b);
4172 DOSET (FLG_USERELEASED, b);
4173 DOSET (FLG_ALIASUNIQUE, b);
4174 DOSET (FLG_MAYALIASUNIQUE, b);
4175 DOSET (FLG_MUSTFREEONLY, b);
4176 DOSET (FLG_MUSTFREEFRESH, b);
4177 DOSET (FLG_MUSTDEFINE, b);
4178 DOSET (FLG_GLOBSTATE, b);
4179 DOSET (FLG_COMPDESTROY, b);
4180 DOSET (FLG_MUSTNOTALIAS, b);
4181 DOSET (FLG_MEMIMPLICIT, b);
4182 DOSET (FLG_BRANCHSTATE, b);
4183 /*@fallthrough@*/ /* also sets memtrans flags */
4185 DOSET (FLG_MEMTRANS, b);
4186 DOSET (FLG_EXPOSETRANS, b);
4187 DOSET (FLG_OBSERVERTRANS, b);
4188 DOSET (FLG_DEPENDENTTRANS, b);
4189 DOSET (FLG_NEWREFTRANS, b);
4190 DOSET (FLG_ONLYTRANS, b);
4191 DOSET (FLG_OWNEDTRANS, b);
4192 DOSET (FLG_FRESHTRANS, b);
4193 DOSET (FLG_SHAREDTRANS, b);
4194 DOSET (FLG_TEMPTRANS, b);
4195 DOSET (FLG_KEPTTRANS, b);
4196 DOSET (FLG_REFCOUNTTRANS, b);
4197 DOSET (FLG_STATICTRANS, b);
4198 DOSET (FLG_UNKNOWNTRANS, b);
4199 DOSET (FLG_KEEPTRANS, b);
4200 DOSET (FLG_IMMEDIATETRANS, b);
4207 if (b && !gc.anyExports
4208 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4209 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4210 || f == FLG_EXPORTCONST
4211 || f == FLG_EXPORTANY))
4213 gc.anyExports = TRUE;
4218 context_maybeSet (flagcode d)
4220 return (gc.flags[d] || gc.setLocally[d]);
4224 context_getFlag (flagcode d)
4226 return (gc.flags[d]);
4230 context_flagOn (flagcode f, fileloc loc)
4232 return (!context_suppressFlagMsg (f, loc));
4235 static void context_saveFlagSettings (void)
4237 gc.savedFlags = TRUE;
4238 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4239 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4242 static void context_restoreFlagSettings (void)
4244 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4245 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4246 gc.savedFlags = FALSE;
4249 void context_setFilename (fileId fid, int lineno)
4250 /*@globals fileloc g_currentloc;@*/
4251 /*@modifies g_currentloc@*/
4253 if (fileId_baseEqual (currentFile (), fid))
4260 fileloc_setColumn (g_currentloc, 0);
4262 if (fileloc_isSpecialFile (g_currentloc))
4264 gc.inDerivedFile = TRUE;
4267 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4269 int maxdepth = context_getValue (FLG_INCLUDENEST);
4271 if (filelocStack_size (gc.locstack) > maxdepth)
4273 int depth = filelocStack_includeDepth (gc.locstack);
4275 if (depth > maxdepth)
4279 message ("Maximum include nesting depth "
4280 "(%d, current depth %d) exceeded",
4283 filelocStack_nextTop (gc.locstack)))
4285 filelocStack_printIncludes (gc.locstack);
4291 g_currentloc = fileloc_create (fid, lineno, 1);
4292 gc.inheader = fileId_isHeader (currentFile ());
4294 context_enterFileAux ();
4298 void context_enterIterDef (/*@observer@*/ uentry le)
4300 context_enterMacro (le);
4301 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4302 gc.kind = CX_ITERDEF;
4305 void context_enterIterEnd (/*@observer@*/ uentry le)
4307 context_enterMacro (le);
4308 gc.kind = CX_ITEREND;
4312 context_destroyMod (void)
4313 /*@globals killed gc@*/
4316 ctype_destroyMod ();
4320 fileTable_free (gc.ftab);
4321 filelocStack_free (gc.locstack);
4323 gc.ftab = fileTable_undefined;
4325 macrocache_free (gc.mc);
4326 sfree (gc.moduleaccess);
4329 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4330 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4333 sRefSetList_free (gc.modrecs);
4335 flagMarkerList_free (gc.markers);
4337 messageLog_free (gc.msgLog);
4339 clauseStack_free (gc.clauses);
4342 cstring_free (gc.msgAnnote);
4343 globSet_free (gc.globs_used);
4344 metaStateTable_free (gc.stateTable);
4345 annotationTable_free (gc.annotTable);
4352 bool context_msgBoolInt (void)
4354 return gc.flags [FLG_BOOLINT];
4357 bool context_msgCharInt (void)
4359 return gc.flags [FLG_CHARINT];
4362 bool context_msgEnumInt (void)
4364 return gc.flags [FLG_ENUMINT];
4367 bool context_msgPointerArith (void)
4369 return gc.flags [FLG_POINTERARITH];
4372 bool context_msgStrictOps (void)
4374 return gc.flags [FLG_STRICTOPS];
4378 bool context_msgLh (void)
4380 return gc.flags [FLG_DOLH];
4384 void context_pushLoc (void)
4386 fileloc_free (gc.pushloc);
4387 gc.pushloc = gc.saveloc;
4388 gc.saveloc = fileloc_undefined;
4391 void context_popLoc (void)
4393 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4396 bool context_inGlobalScope (void)
4398 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4401 bool context_inInnerScope (void)
4403 return (gc.kind == CX_INNER);
4406 void context_setProtectVars (void)
4408 gc.protectVars = TRUE;
4411 bool context_anyErrors (void)
4413 return (gc.numerrors > 0);
4416 void context_hasError (void)
4419 DPRINTF (("num errors: %d", gc.numerrors));
4422 int context_numErrors (void)
4424 return gc.numerrors;
4427 bool context_neednl (void)
4432 void context_setNeednl (void)
4437 int context_getExpect (void)
4439 return (context_getValue (FLG_EXPECT));
4443 int context_getLCLExpect (void)
4445 return (context_getValue (FLG_LCLEXPECT));
4449 int context_getLimit (void)
4451 return (context_getValue (FLG_LIMIT));
4454 bool context_unlimitedMessages (void)
4456 return (context_getLimit () < 0);
4459 void context_releaseVars (void)
4461 llassert (gc.protectVars);
4462 gc.protectVars = FALSE;
4465 void context_sizeofReleaseVars (void)
4467 /* If there is a nested sizeof, this might not hold:
4468 llassert (gc.protectVars);
4471 gc.protectVars = FALSE;
4474 bool context_inProtectVars (void)
4476 return (gc.protectVars);
4479 void context_hideShowscan (void)
4481 gc.flags[FLG_SHOWSCAN] = FALSE;
4484 void context_unhideShowscan (void)
4486 gc.flags[FLG_SHOWSCAN] = TRUE;
4489 bool context_inHeader (void)
4491 return (gc.inheader);
4494 fileTable context_fileTable (void)
4499 cstring context_tmpdir (void)
4501 return (context_getString (FLG_TMPDIR));
4504 messageLog context_messageLog (void)
4509 bool context_inMacroFunction (void)
4511 return (gc.kind == CX_MACROFCN);
4514 bool context_inMacroConstant (void)
4516 return (gc.kind == CX_MACROCONST);
4519 bool context_inUnknownMacro (void)
4521 return (gc.kind == CX_UNKNOWNMACRO);
4524 void context_setShownFunction (void)
4526 gc.showfunction = FALSE;
4529 bool context_doDump (void)
4531 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4534 bool context_doMerge (void)
4536 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4539 cstring context_getDump (void)
4541 return context_getString (FLG_DUMP);
4544 cstring context_getMerge (void)
4546 return context_getString (FLG_MERGE);
4550 bool context_inLCLLib (void)
4552 return (gc.kind == CX_LCLLIB);
4555 bool context_inImport (void)
4557 return (gc.inimport);
4560 void context_enterImport (void)
4565 void context_leaveImport (void)
4567 gc.inimport = FALSE;
4571 bool context_inMacro (void)
4573 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4574 || gc.kind == CX_UNKNOWNMACRO
4575 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4578 bool context_inIterDef (void)
4580 return (gc.kind == CX_ITERDEF);
4583 bool context_inIterEnd (void)
4585 return (gc.kind == CX_ITEREND);
4588 int context_getLinesProcessed (void)
4590 return (gc.linesprocessed);
4593 int context_getSpecLinesProcessed (void)
4595 return (gc.speclinesprocessed);
4599 void context_processedSpecLine (void)
4601 gc.speclinesprocessed++;
4604 void context_resetSpecLines (void)
4606 gc.speclinesprocessed = 0;
4610 bool context_inGlobalContext (void)
4612 return (gc.kind == CX_GLOBAL);
4615 static void context_quietExitScopes (void)
4618 ** Try to restore the global scope (after an error).
4621 while (!usymtab_inFileScope ())
4623 usymtab_quietExitScope (g_currentloc);
4626 gc.cont.glob = TRUE;
4627 gc.kind = CX_GLOBAL;
4630 void context_checkGlobalScope (void)
4632 if (gc.kind != CX_GLOBAL)
4634 if (context_inMacro ())
4636 ; /* evans 2001-10-14: Okay to be in a macro here! */
4640 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4641 context_quietExitScopes ();
4646 void context_setFileId (fileId s)
4648 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4651 bool context_setBoolName (void)
4653 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4657 cstring context_printBoolName (void)
4659 if (context_setBoolName ())
4661 return context_getBoolName ();
4665 return cstring_makeLiteralTemp ("boolean");
4669 cstring context_getBoolName (void)
4671 return (context_getString (FLG_BOOLTYPE));
4674 cstring context_getFalseName (void)
4676 return (context_getString (FLG_BOOLFALSE));
4679 cstring context_getTrueName (void)
4681 return (context_getString (FLG_BOOLTRUE));
4684 cstring context_getLarchPath (void)
4686 return (context_getString (FLG_LARCHPATH));
4689 cstring context_getLCLImportDir (void)
4691 return (context_getString (FLG_LCLIMPORTDIR));
4694 static void context_setJustPopped (void)
4696 gc.justpopped = TRUE;
4699 void context_clearJustPopped (void)
4701 gc.justpopped = FALSE;
4704 bool context_justPopped (void)
4706 return (gc.justpopped);
4709 void context_setMacroMissingParams (void)
4711 gc.macroMissingParams = TRUE;
4714 void context_resetMacroMissingParams (void)
4716 gc.macroMissingParams = FALSE;
4719 bool context_isMacroMissingParams (void)
4721 return (gc.macroMissingParams);
4724 void context_showFilelocStack (void)
4726 filelocStack_printIncludes (gc.locstack);
4729 metaStateTable context_getMetaStateTable (void)
4731 return gc.stateTable;
4734 metaStateInfo context_lookupMetaStateInfo (cstring key)
4736 return metaStateTable_lookup (gc.stateTable, key);
4739 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4741 annotationInfo ainfo;
4743 ainfo = annotationTable_lookup (gc.annotTable, annot);
4748 void context_addAnnotation (annotationInfo ainfo)
4750 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4754 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4755 annotationInfo_getLoc (ainfo));
4757 annotationInfo_free (ainfo);
4761 annotationTable_insert (gc.annotTable, ainfo);
4765 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4767 if (metaStateTable_contains (gc.stateTable, mname))
4771 message ("Duplicate metastate declaration: %s", mname),
4772 metaStateInfo_getLoc (msinfo));
4773 cstring_free (mname);
4774 metaStateInfo_free (msinfo);
4778 DPRINTF (("Adding meta state: %s", mname));
4779 metaStateTable_insert (gc.stateTable, mname, msinfo);
4783 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4785 if (metaStateTable_size (gc.stateTable) > 0)
4787 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4788 /*@i32 should use smaller value... */
4789 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4791 metaStateTable_elements (gc.stateTable, msname, msi)
4793 mtContextNode context = metaStateInfo_getContext (msi);
4795 if (mtContextNode_matchesRefStrict (context, s))
4797 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4798 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4802 cstring_copy (metaStateInfo_getName (msi)),
4803 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4804 stateInfo_copy (sinfo)));
4808 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4811 end_metaStateTable_elements ;
4813 stateInfo_free (sinfo);
4814 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4819 stateInfo_free (sinfo);
4820 return valueTable_undefined;
4824 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4826 if (metaStateTable_size (gc.stateTable) > 0)
4828 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4829 /*@i32 should use smaller value... */
4831 metaStateTable_elements (gc.stateTable, msname, msi)
4833 /*@i23 only add global...*/
4834 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4835 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4837 valueTable_insert (res,
4838 cstring_copy (metaStateInfo_getName (msi)),
4839 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4840 stateInfo_copy (sinfo)));
4842 end_metaStateTable_elements ;
4844 stateInfo_free (sinfo);
4845 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4850 stateInfo_free (sinfo);
4851 return valueTable_undefined;
4856 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4860 static ctype lastStruct;
4862 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4868 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4874 /*@unused@*/ static int sInfoNum = 0;
4878 /*@unused@*/ uentry ue;
4879 /*@unused@*/ sRef s;
4883 /*@unused@*/ ctype ct;
4884 /*@unused@*/ constraintList inv;
4885 /*@unused@*/ int ngetUe;
4886 /*@unused@*/ struct getUe * t ;
4890 static struct sInfo globalStructInfo;
4893 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4894 stable release of splint. I coomented them out so that they won't break anything
4895 but didn't delete them because they will be fixed and included later
4899 void setGlobalStructInfo(ctype ct, constraintList list)
4904 f = ctype_getFields (ct);
4906 if (constraintList_isDefined(list) )
4908 globalStructInfo.ct = ct;
4909 globalStructInfo.inv = list;
4911 globalStructInfo.ngetUe = 0;
4913 / *abstraction violation fix it * /
4914 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4916 globalStructInfo.ngetUe = f->nelements;
4920 uentryList_elements(f, ue)
4922 globalStructInfo.t[i].ue = ue;
4923 globalStructInfo.t[i].s = uentry_getSref(ue);
4924 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4925 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4930 end_uentryList_elements;
4936 bool hasInvariants (ctype ct) /*@*/
4938 if ( ctype_sameName(globalStructInfo.ct, ct) )