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"
39 # include "usymtab_interface.h"
40 # include "exprChecks.h"
41 # include "filelocStack.h"
47 extern /*@external@*/ int yydebug;
48 extern /*@external@*/ int mtdebug;
60 CX_FUNCTION, CX_FCNDECLARATION,
61 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
62 CX_ITERDEF, CX_ITEREND,
63 CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
64 CX_LCL, CX_LCLLIB, CX_MT
70 int speclinesprocessed;
72 flagMarkerList markers;
75 ** used to record state where a macro must match a function name
76 ** (i.e., no params were listed in the macro definition
79 bool macroMissingParams BOOLBITS;
80 bool preprocessing BOOLBITS;
81 bool incommandline BOOLBITS;
82 bool insuppressregion BOOLBITS;
83 bool inDerivedFile BOOLBITS;
84 bool instandardlib BOOLBITS;
85 bool inimport BOOLBITS;
86 bool inheader BOOLBITS;
87 bool inmacrocache BOOLBITS;
88 bool protectVars BOOLBITS;
90 bool showfunction BOOLBITS;
91 bool savedFlags BOOLBITS;
92 bool justpopped BOOLBITS;
93 bool anyExports BOOLBITS;
94 bool inFunctionHeader BOOLBITS;
107 filelocStack locstack;
110 /*@observer@*/ sRef aliasAnnote;
111 /*@observer@*/ sRef aliasAnnoteAls;
115 /*@observer@*/ sRefSet mods;
117 /* file access types */
120 /* local access types (this function) */
123 /* no access types (@noaccess) */
126 /*@observer@*/ globSet globs;
127 /*@only@*/ globSet globs_used;
131 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
137 bool flags[NUMFLAGS];
138 bool saveflags[NUMFLAGS];
139 bool setGlobally[NUMFLAGS];
140 bool setLocally[NUMFLAGS];
142 int values[NUMVALUEFLAGS];
143 int counters[NUMVALUEFLAGS];
145 o_cstring strings[NUMSTRINGFLAGS];
146 sRefSetList modrecs; /*@i32 ???? what is this for? */
148 metaStateTable stateTable; /* User-defined state information. */
149 annotationTable annotTable; /* User-defined annotations table. */
154 /*@dependent@*/ /*@exposed@*/ uentry fcn;
158 union u_cont savecont;
161 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
162 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
163 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
164 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
166 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
167 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
168 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
169 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
170 static void context_setFlag (flagcode p_f, bool p_b, fileloc p_loc)
171 /*@modifies gc.flags@*/ ;
174 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile,
175 bool p_isRestore, fileloc p_loc)
176 /*@modifies gc.flags@*/ ;
178 static void context_restoreFlag (flagcode p_f, fileloc p_loc)
179 /*@modifies gc.flags@*/ ;
183 cstring context_unparseFlagMarkers ()
185 return (flagMarkerList_unparse (gc.markers));
188 void context_setPreprocessing (void)
190 llassert (!gc.preprocessing);
191 gc.preprocessing = TRUE;
194 void context_clearPreprocessing (void)
196 llassert (gc.preprocessing);
197 gc.preprocessing = FALSE;
200 bool context_isPreprocessing (void)
202 return gc.preprocessing;
205 bool context_loadingLibrary (void)
207 return (fileloc_isLib (g_currentloc));
210 bool context_inXHFile (void)
212 return (fileloc_isXHFile (g_currentloc));
215 void context_setInCommandLine (void)
217 llassert (!gc.incommandline);
218 gc.incommandline = TRUE;
221 void context_clearInCommandLine (void)
223 llassert (gc.incommandline);
224 gc.incommandline = FALSE;
227 bool context_isInCommandLine (void)
229 return gc.incommandline;
233 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
236 clauseStack_push (gc.clauses, c);
238 if (clause_isConditional (c)
239 && context_getFlag (FLG_CONTROLNESTDEPTH))
241 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
242 int depth = clauseStack_controlDepth (gc.clauses);
244 if (depth == maxdepth + 1)
247 (FLG_CONTROLNESTDEPTH,
248 message ("Maximum control nesting depth "
257 clause topClause (clauseStack s) /*@*/
259 if (clauseStack_isEmpty (s)) return NOCLAUSE;
260 return ((clause) clauseStack_top (s));
264 context_addMacroCache (/*@only@*/ cstring def)
266 DPRINTF (("macro cache: %s", def));
267 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
271 context_addComment (/*@only@*/ cstring def, fileloc loc)
273 macrocache_addComment (gc.mc, fileloc_copy (loc), def);
277 ** returns TRUE is fl is in ignore region, or region where -code
279 ** the logic is fuzzy...
283 context_inSuppressFlagZone (fileloc fl, flagcode code)
285 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
288 if (ynm_isMaybe (ret))
296 res = !gc.saveflags[code];
300 res = !context_getFlag (code);
305 res = ynm_toBoolStrict (ret);
312 context_suppressSystemMsg (fileloc fl)
314 if (context_getFlag (FLG_SYSTEMDIRERRORS))
320 return (fileloc_isSystemFile (fl));
325 context_suppressFlagMsg (flagcode flag, fileloc fl)
327 if (context_suppressSystemMsg (fl))
332 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
334 /* want same object compare here */
336 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
338 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
340 return (!context_getFlag (flag)
341 || context_inSuppressRegion ()
342 || context_inSuppressZone (fl)
343 || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
347 return (context_inSuppressFlagZone (fl, flag));
352 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
355 if (context_suppressSystemMsg (fl))
361 if (fl == g_currentloc)
362 /*@noaccess fileloc@*/
364 return (context_getFlag (flag) || context_inSuppressRegion ());
369 return (context_getFlag (flag) || context_inSuppressRegion ());
374 context_inSuppressZone (fileloc fl)
376 if (context_suppressSystemMsg (fl))
381 return (flagMarkerList_inIgnore (gc.markers, fl));
385 context_inSuppressRegion (void)
387 return (gc.insuppressregion);
391 context_enterSuppressRegion (fileloc loc)
393 if (gc.insuppressregion)
395 gc.insuppressregion = FALSE; /* get this msg! */
397 ("%q: New ignore errors region entered while in ignore errors region",
398 fileloc_unparse (loc)));
401 gc.insuppressregion = TRUE;
402 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (loc));
406 context_addFlagMarker (flagcode code, ynm set, fileloc loc)
408 (void) flagMarkerList_add (gc.markers,
409 flagMarker_createLocalSet (code, set, loc));
413 context_enterSuppressLine (int count, fileloc loc)
415 if (context_processingMacros ())
420 if (flagMarkerList_add
422 flagMarker_createIgnoreCount (count, loc)))
424 fileloc nextline = fileloc_copy (loc);
425 fileloc_nextLine (nextline);
426 fileloc_setColumn (nextline, 0);
428 check (flagMarkerList_add (gc.markers,
429 flagMarker_createIgnoreOff (nextline)));
430 fileloc_free (nextline);
434 void context_checkSuppressCounts (void)
436 if (context_getFlag (FLG_SUPCOUNTS))
438 flagMarkerList_checkSuppressCounts (gc.markers);
442 void context_incLineno (void)
449 context_exitSuppressRegion (fileloc loc)
451 if (!gc.insuppressregion)
455 message ("End ignore errors in region while not ignoring errors"),
459 gc.insuppressregion = FALSE;
460 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (loc));
464 context_enterMTfile (void)
470 context_exitMTfile (void)
472 llassert (gc.kind == CX_MT);
477 context_enterLCLfile (void)
480 gc.facct = typeIdSet_emptySet ();
484 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
488 for (i = 0; i < gc.nmods; i++)
490 if (cstring_equal (gc.moduleaccess[i].file, fname))
492 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
493 cstring_free (fname);
498 if (gc.nmods == gc.maxmods)
502 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
503 oldmods = gc.moduleaccess;
505 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
507 for (i = 0; i < gc.nmods; i++)
509 gc.moduleaccess[i] = oldmods[i];
515 gc.moduleaccess[gc.nmods].file = fname;
516 gc.moduleaccess[gc.nmods].daccess = mods;
522 insertModuleAccess (cstring fname, typeId t)
526 for (i = 0; i < gc.nmods; i++)
528 if (cstring_equal (gc.moduleaccess[i].file, fname))
530 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
535 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
539 context_exitLCLfile (void)
541 if (gc.kind != CX_LCLLIB)
544 fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION);
546 addModuleAccess (fileLib_removePath (lclname), gc.facct);
547 cstring_free (lclname);
552 gc.facct = typeIdSet_emptySet ();
556 context_dumpModuleAccess (FILE *fout)
560 for (i = 0; i < gc.nmods; i++)
562 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
564 fprintf (fout, "%s#%s@\n",
565 cstring_toCharsSafe (gc.moduleaccess[i].file),
566 cstring_toCharsSafe (td));
572 bool context_usingPosixLibrary ()
574 return (gc.library == FLG_POSIXLIB
575 || gc.library == FLG_POSIXSTRICTLIB
576 || gc.library == FLG_UNIXLIB
577 || gc.library == FLG_UNIXSTRICTLIB);
580 bool context_usingAnsiLibrary ()
582 return (gc.library != FLG_NOLIB);
585 flagcode context_getLibrary ()
590 void context_setLibrary (flagcode code)
595 /*@observer@*/ cstring context_selectedLibrary ()
600 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
602 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
603 case FLG_POSIXSTRICTLIB:
604 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
606 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
607 case FLG_UNIXSTRICTLIB:
608 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
610 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
617 context_loadModuleAccess (FILE *in)
619 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
621 char *name = mstring_create (MAX_NAME_LENGTH);
627 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
633 while (s != NULL && *s != ';' && *s != '\0')
637 while (*s != '#' && *s != '\0')
646 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
647 cstring_fromChars (s)));
653 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
654 typeIdSet_undump (&s));
656 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
657 llassert (s != lasts);
667 typeIdSet context_fileAccessTypes (void)
673 context_resetModeFlags (void)
677 if (flagcode_isModeFlag (code))
679 context_setFlag (code, FALSE, g_currentloc);
687 ** Set all flags to FALSE, except for a few which are
690 ** Set all values and strings to appropriate defaults.
691 ** Set all counters to 0.
695 conext_resetAllCounters (void)
699 for (i = 0; i < NUMVALUEFLAGS; i++)
706 context_resetAllFlags (void)
708 DPRINTF (("******** Reset all flags"));
712 gc.flags[code] = FALSE;
714 if (flagcode_hasNumber (code))
718 /*@-loopswitchbreak@*/
722 val = DEFAULT_LIMIT; break;
724 val = DEFAULT_BUGSLIMIT; break;
726 val = DEFAULT_LINELEN; break;
727 case FLG_INDENTSPACES:
728 val = DEFAULT_INDENTSPACES; break;
729 case FLG_EXTERNALNAMELEN:
730 val = ISO99_EXTERNALNAMELEN; break;
731 case FLG_INTERNALNAMELEN:
732 val = ISO99_INTERNALNAMELEN; break;
733 case FLG_COMMENTCHAR:
734 val = (int) DEFAULT_COMMENTCHAR; break;
735 case FLG_CONTROLNESTDEPTH:
736 val = (int) ISO99_CONTROLNESTDEPTH; break;
737 case FLG_STRINGLITERALLEN:
738 val = (int) ISO99_STRINGLITERALLEN; break;
739 case FLG_INCLUDENEST:
740 val = (int) ISO99_INCLUDENEST; break;
741 case FLG_NUMSTRUCTFIELDS:
742 val = (int) ISO99_NUMSTRUCTFIELDS; break;
743 case FLG_NUMENUMMEMBERS:
744 val = (int) ISO99_NUMENUMMEMBERS; break;
749 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
751 /*@=loopswitchbreak@*/
753 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
754 context_setValue (code, val);
755 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
756 llassert (context_getValue (code) == val);
758 else if (flagcode_hasChar (code))
760 llassert (code == FLG_COMMENTCHAR);
761 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
763 else if (flagcode_hasString (code))
765 cstring val = cstring_undefined;
768 { /*@-loopswitchbreak@*/
771 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
773 if (cstring_isDefined (larchpath))
775 val = cstring_copy (larchpath);
779 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
784 case FLG_LCLIMPORTDIR:
786 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
790 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
792 char *env = osd_getEnvironmentVariable ("TMP");
796 env = osd_getEnvironmentVariable ("TEMP");
799 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
802 val = cstring_makeLiteral (DEFAULT_TMPDIR);
803 # endif /* !defined(OS2) && !defined(MSDOS) */
807 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
809 val = cstring_makeLiteral ("FALSE"); break;
811 val = cstring_makeLiteral ("TRUE"); break;
812 case FLG_MACROVARPREFIX:
813 val = cstring_makeLiteral ("m_"); break;
815 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
818 } /*@=loopswitchbreak@*/
820 context_setString (code, val);
824 ; /* nothing to set */
829 ** These flags are true by default.
832 /*@i34 move this into flags.def */
834 gc.flags[FLG_STREAMOVERWRITE] = TRUE;
836 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
837 gc.flags[FLG_MODIFIES] = TRUE;
838 gc.flags[FLG_NESTCOMMENT] = TRUE;
839 gc.flags[FLG_GLOBALS] = TRUE;
840 gc.flags[FLG_FULLINITBLOCK] = TRUE;
841 gc.flags[FLG_INITSIZE] = TRUE;
842 gc.flags[FLG_INITALLELEMENTS] = TRUE;
844 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
846 gc.flags[FLG_LIKELYBOOL] = TRUE;
847 gc.flags[FLG_ZEROPTR] = TRUE;
848 gc.flags[FLG_NUMLITERAL] = TRUE;
849 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
850 gc.flags[FLG_SKIPISOHEADERS] = TRUE;
851 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
852 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
853 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
854 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
855 gc.flags[FLG_CASTFCNPTR] = TRUE;
856 gc.flags[FLG_DOLCS] = TRUE;
857 gc.flags[FLG_USEVARARGS] = TRUE;
858 gc.flags[FLG_MAINTYPE] = TRUE;
859 gc.flags[FLG_SPECMACROS] = TRUE;
860 gc.flags[FLG_REDEF] = TRUE;
861 gc.flags[FLG_MACRONEXTLINE] = TRUE;
863 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
864 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
866 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
867 gc.flags[FLG_WARNUSE] = TRUE;
868 gc.flags[FLG_PREDASSIGN] = TRUE;
869 gc.flags[FLG_MODOBSERVER] = TRUE;
870 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
871 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
873 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
874 gc.flags[FLG_RETIMPONLY] = TRUE;
875 gc.flags[FLG_GLOBIMPONLY] = TRUE;
876 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
877 gc.flags[FLG_PREPROC] = TRUE;
878 gc.flags[FLG_NAMECHECKS] = TRUE;
879 gc.flags[FLG_FORMATCODE] = TRUE;
880 gc.flags[FLG_FORMATTYPE] = TRUE;
881 gc.flags[FLG_BADFLAG] = TRUE;
882 gc.flags[FLG_WARNFLAGS] = TRUE;
883 gc.flags[FLG_WARNRC] = TRUE;
884 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
885 gc.flags[FLG_WARNUNIXLIB] = TRUE;
886 gc.flags[FLG_WARNPOSIX] = TRUE;
887 gc.flags[FLG_SHOWCOL] = TRUE;
888 gc.flags[FLG_SHOWFUNC] = TRUE;
889 gc.flags[FLG_SUPCOUNTS] = TRUE;
890 gc.flags[FLG_HINTS] = TRUE;
891 gc.flags[FLG_SYNTAX] = TRUE;
892 gc.flags[FLG_TYPE] = TRUE;
893 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
894 gc.flags[FLG_ABSTRACT] = TRUE;
895 gc.flags[FLG_ITERBALANCE] = TRUE;
896 gc.flags[FLG_ITERYIELD] = TRUE;
897 gc.flags[FLG_DUPLICATECASES] = TRUE;
898 gc.flags[FLG_ALWAYSEXITS] = TRUE;
899 gc.flags[FLG_EMPTYRETURN] = TRUE;
900 gc.flags[FLG_MACRORETURN] = TRUE;
901 gc.flags[FLG_UNRECOG] = TRUE;
902 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
903 gc.flags[FLG_LINTCOMMENTS] = TRUE;
904 gc.flags[FLG_ACCESSCZECH] = TRUE;
905 gc.flags[FLG_ACCESSMODULE] = TRUE;
906 gc.flags[FLG_ACCESSFILE] = TRUE;
907 gc.flags[FLG_MACROVARPREFIX] = TRUE;
909 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
910 gc.flags[FLG_COMMENTERROR] = TRUE;
913 ** Changed for version 2.4.
916 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
922 /* commenting ou until some output issues are fixed */
923 gc.flags[FLG_ORCONSTRAINT] = TRUE;
925 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
928 gc.flags[FLG_WARNSYSFILES] = TRUE;
931 ** On by default for Win32, but not Unix
935 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
936 gc.flags[FLG_CASEINSENSITIVEFILENAMES] = TRUE;
941 ** C is way-lame, and you can initialize an array to a constant except where
942 ** it is declared. Hence, a macro is used to set the modeflags.
946 # define SETFLAGS() \
947 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
948 if (!flagcode_isModeFlag (modeflags[i])) \
949 { llbug (message ("not a mode flag: %s", \
950 flagcode_unparse (modeflags[i]))); } \
951 else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }}
953 static void context_setModeAux (cstring p_s, bool p_warn) ;
956 context_setMode (cstring s)
958 context_setModeAux (s, TRUE);
962 context_setModeNoWarn (cstring s)
964 context_setModeAux (s, FALSE);
968 context_setModeAux (cstring s, bool warn)
970 intSet setflags = intSet_new ();
974 if (flagcode_isModeFlag (code))
976 if (gc.setGlobally[code])
978 (void) intSet_insert (setflags, (int) code);
983 if (!intSet_isEmpty (setflags))
985 cstring rflags = cstring_undefined;
988 intSet_elements (setflags, el)
990 if (cstring_isUndefined (rflags))
992 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
996 rflags = message ("%q, %s", rflags,
997 flagcode_unparse ((flagcode) el));
1001 if (num > 4 && intSet_size (setflags) > 6)
1003 rflags = message ("%q, (%d others) ...", rflags,
1004 intSet_size (setflags) - num);
1007 } end_intSet_elements ;
1011 voptgenerror (FLG_WARNFLAGS,
1012 message ("Setting mode %s after setting mode flags will "
1013 "override set values of flags: %s",
1018 cstring_free (rflags);
1021 intSet_free (setflags);
1023 context_resetModeFlags ();
1025 if (cstring_equalLit (s, "standard"))
1027 flagcode modeflags[] =
1029 FLG_ENUMINT, FLG_MACROMATCHNAME,
1030 FLG_STRINGLITNOROOM,
1031 FLG_STRINGLITNOROOMFINALNULL,
1032 FLG_MACROUNDEF, FLG_RELAXQUALS,
1033 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1034 FLG_CHECKSTRICTGLOBALIAS,
1035 FLG_CHECKEDGLOBALIAS,
1036 FLG_CHECKMODGLOBALIAS,
1037 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1038 FLG_UNSIGNEDCOMPARE,
1039 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1041 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1042 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1043 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1044 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1045 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1048 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1049 FLG_MACROSTMT, FLG_MACROPARENS,
1052 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1053 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1058 /* memchecks flags */
1060 FLG_NULLSTATE, FLG_NULLASSIGN,
1061 FLG_NULLPASS, FLG_NULLRET,
1063 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1066 /* memtrans flags */
1085 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1088 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1089 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1092 FLG_STATETRANSFER, FLG_STATEMERGE,
1093 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1095 FLG_IMPCHECKEDSPECGLOBALS,
1096 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1097 FLG_IFEMPTY, FLG_REALCOMPARE,
1098 FLG_BOOLOPS, FLG_PTRNEGATE,
1100 FLG_SHIFTIMPLEMENTATION,
1101 FLG_BUFFEROVERFLOWHIGH,
1108 else if (cstring_equalLit (s, "weak"))
1110 flagcode modeflags[] =
1112 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE, FLG_LONGINT, FLG_SHORTINT,
1113 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1114 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1115 FLG_CHARUNSIGNEDCHAR,
1117 FLG_VARUNUSED, FLG_FUNCUNUSED,
1119 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1122 FLG_BUFFEROVERFLOWHIGH,
1123 FLG_RETSTACK, FLG_PTRNEGATE,
1124 FLG_STATETRANSFER, FLG_STATEMERGE,
1125 FLG_LONGUNSIGNEDINTEGRAL,
1126 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1130 FLG_BUFFEROVERFLOWHIGH,
1131 FLG_STRINGLITNOROOM,
1132 FLG_STRINGLITNOROOMFINALNULL,
1138 else if (cstring_equalLit (s, "checks"))
1140 flagcode modeflags[] =
1142 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1143 FLG_STATETRANSFER, FLG_STATEMERGE,
1144 FLG_CHECKSTRICTGLOBALIAS,
1145 FLG_CHECKEDGLOBALIAS,
1146 FLG_CHECKMODGLOBALIAS,
1147 FLG_UNCHECKEDGLOBALIAS,
1149 FLG_STRINGLITNOROOM,
1150 FLG_STRINGLITNOROOMFINALNULL,
1151 FLG_STRINGLITSMALLER,
1152 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1153 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1154 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1155 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1156 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1157 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1158 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1159 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1160 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1161 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1162 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1163 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1164 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1165 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1172 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1176 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1178 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1179 FLG_EVALORDER, FLG_USEDEF,
1182 /* warn use flags */
1183 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1184 FLG_BUFFEROVERFLOWHIGH,
1186 /* memchecks flags */
1188 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1189 FLG_NULLPASS, FLG_NULLRET,
1191 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1193 /* memtrans flags */
1207 FLG_STATICINITTRANS,
1208 FLG_UNKNOWNINITTRANS,
1211 FLG_ONLYUNQGLOBALTRANS,
1212 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1215 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1216 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1219 FLG_NULLPOINTERARITH,
1220 FLG_SHADOW, FLG_DEPARRAYS,
1221 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1222 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1223 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1224 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1225 FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES,
1226 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1227 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1228 FLG_SHIFTIMPLEMENTATION,
1229 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1234 else if (cstring_equalLit (s, "strict"))
1236 flagcode modeflags[] =
1238 FLG_CHECKSTRICTGLOBALIAS,
1239 FLG_CHECKEDGLOBALIAS,
1240 FLG_CHECKMODGLOBALIAS,
1241 FLG_UNCHECKEDGLOBALIAS,
1245 FLG_STRINGLITNOROOM,
1246 FLG_STRINGLITNOROOMFINALNULL,
1247 FLG_STRINGLITSMALLER,
1248 FLG_STATETRANSFER, FLG_STATEMERGE,
1249 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1250 FLG_ALLGLOBALS, FLG_IMPTYPE,
1251 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1252 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1253 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1254 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1257 FLG_ONLYUNQGLOBALTRANS,
1258 FLG_GLOBALSIMPMODIFIESNOTHING,
1259 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1260 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1261 FLG_USEALLGLOBS, FLG_RETALIAS,
1262 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1263 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1264 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1266 FLG_EXPORTITER, FLG_EXPORTCONST,
1267 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1268 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1270 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1272 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1273 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1274 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1275 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1276 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1277 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1278 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1279 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1281 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1284 FLG_MACROREDEF, FLG_MACROEMPTY,
1285 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1287 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1289 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1290 FLG_MODOBSERVERUNCON,
1295 /* warn use flags */
1296 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1297 FLG_BUFFEROVERFLOWHIGH,
1298 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1300 /* memchecks flags */
1301 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1302 FLG_NULLPASS, FLG_NULLRET,
1304 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1306 /* memtrans flags */
1322 FLG_STATICINITTRANS,
1323 FLG_UNKNOWNINITTRANS,
1325 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1328 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1329 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1333 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1335 FLG_SHADOW, FLG_DEPARRAYS,
1336 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1337 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1338 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1339 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1340 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1341 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1342 FLG_IMPCHECKEDSTRICTSTATICS,
1343 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1344 FLG_IMPCHECKMODINTERNALS,
1345 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1346 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1347 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1348 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1349 FLG_CONTROLNESTDEPTH,
1350 FLG_FORBLOCK, FLG_WHILEBLOCK,
1351 FLG_FOREMPTY, FLG_WHILEEMPTY,
1352 FLG_IFEMPTY, FLG_IFBLOCK,
1354 FLG_REALCOMPARE, FLG_BOOLOPS,
1355 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1358 FLG_SHIFTIMPLEMENTATION,
1360 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1368 llcontbug (message ("context_setMode: bad mode: %s", s));
1373 context_isSpecialFile (cstring fname)
1375 cstring ext = fileLib_getExtension (fname);
1377 return (cstring_equalLit (ext, ".y")
1378 || cstring_equalLit (ext, ".l")
1379 || cstring_equalLit (fname, "lex.yy.c"));
1383 context_isSystemDir (cstring dir)
1385 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1386 cstring savedir = thisdir;
1387 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1389 if (cstring_isDefined (nextdir))
1391 /*@access cstring@*/
1392 *nextdir = '\0'; /* closes thisdir */
1394 /*@noaccess cstring@*/
1397 /* 2001-09-09: added thisdir[0] != '\0'
1398 ** herbert: don't compare with an empty name!
1399 ** should return false for empty directory path
1402 while (!cstring_isEmpty (thisdir))
1404 DPRINTF (("Test: %s / %s", dir, thisdir));
1406 if (osd_equalCanonicalPrefix (dir, thisdir))
1408 cstring_free (savedir);
1412 if (cstring_isDefined (nextdir))
1415 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1417 if (cstring_isDefined (nextdir))
1419 /*@access cstring@*/
1422 /*@noaccess cstring@*/
1431 DPRINTF (("Returns FALSE"));
1432 cstring_free (savedir);
1437 context_addFileAccessType (typeId t)
1441 if (context_inFunctionLike ())
1443 gc.acct = typeIdSet_insert (gc.acct, t);
1446 gc.facct = typeIdSet_insert (gc.facct, t);
1448 base = fileloc_getBase (g_currentloc);
1449 insertModuleAccess (base, t);
1450 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1451 typeIdSet_unparse (gc.acct)));
1455 context_removeFileAccessType (typeId t)
1457 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1458 || gc.kind == CX_UNKNOWNMACRO)
1460 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1463 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1464 gc.nacct = typeIdSet_insert (gc.nacct, t);
1467 void context_enterFunctionHeader (void)
1469 if (context_getFlag (FLG_GRAMMAR))
1471 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1474 if (gc.kind != CX_GLOBAL)
1476 llparseerror (cstring_makeLiteral
1477 ("Likely parse error. Function header outside global context."));
1481 llassert (gc.kind == CX_GLOBAL);
1482 DPRINTF (("Enter function header!"));
1483 gc.inFunctionHeader = TRUE;
1487 void context_exitFunctionHeader (void)
1489 if (context_getFlag (FLG_GRAMMAR))
1491 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1494 DPRINTF (("Exit function header!"));
1495 gc.inFunctionHeader = FALSE;
1498 bool context_inFunctionHeader (void)
1500 return (gc.inFunctionHeader);
1503 void context_enterFunctionDeclaration (uentry e)
1505 if (context_getFlag (FLG_GRAMMAR))
1507 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1510 DPRINTF (("Enter function decl"));
1511 llassert (gc.savekind == CX_ERROR);
1512 gc.savekind = gc.kind;
1513 gc.savecont = gc.cont;
1514 gc.kind = CX_FCNDECLARATION;
1518 void context_exitFunctionDeclaration (void)
1520 if (context_getFlag (FLG_GRAMMAR))
1522 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1525 DPRINTF (("Exit function decl"));
1526 llassert (gc.savekind != CX_ERROR);
1527 llassert (gc.kind == CX_FCNDECLARATION);
1528 gc.kind = gc.savekind;
1529 gc.cont = gc.savecont;
1531 gc.savekind = CX_ERROR;
1533 if (context_getFlag (FLG_GRAMMAR))
1535 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1539 bool context_inFunctionDeclaration (void)
1541 return (gc.kind == CX_FCNDECLARATION);
1546 context_enterMacro (/*@observer@*/ uentry e)
1548 context_enterFunction (e);
1549 gc.kind = CX_MACROFCN;
1553 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1555 llassert (uentry_isFunction (e));
1556 context_enterFunction (e);
1557 gc.kind = CX_UNKNOWNMACRO;
1560 void context_enterAndClause (exprNode e)
1563 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1564 pushClause (ANDCLAUSE);
1567 void context_enterOrClause (exprNode e)
1569 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1570 pushClause (ORCLAUSE);
1573 bool context_inDeepLoop (void)
1575 bool inLoop = FALSE;
1577 clauseStack_elements (gc.clauses, el)
1579 if (clause_isLoop (el))
1588 } end_clauseStack_elements;
1593 bool context_inDeepSwitch (void)
1595 bool inLoop = FALSE;
1597 clauseStack_elements (gc.clauses, el)
1599 if (clause_isSwitch (el))
1608 } end_clauseStack_elements;
1613 bool context_inDeepLoopSwitch (void)
1615 bool inLoop = FALSE;
1617 clauseStack_elements (gc.clauses, el)
1619 if (clause_isBreakable (el))
1628 } end_clauseStack_elements;
1633 clause context_breakClause (void)
1635 clauseStack_elements (gc.clauses, el)
1637 if (clause_isSwitch (el))
1641 else if (clause_isLoop (el))
1649 } end_clauseStack_elements;
1654 clause context_nextBreakClause (void)
1656 bool hasOne = FALSE;
1658 clauseStack_elements (gc.clauses, el)
1660 if (clause_isBreakable (el))
1671 } end_clauseStack_elements;
1676 bool context_inConditional (void)
1678 clauseStack_elements (gc.clauses, el)
1681 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1682 ** to distinguish if from ? for this
1685 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1689 } end_clauseStack_elements;
1694 void context_exitAndClause (exprNode pred, exprNode tbranch)
1696 context_setJustPopped ();
1698 llassert (gc.inclause == ANDCLAUSE);
1700 usymtab_popAndBranch (pred, tbranch);
1701 clauseStack_pop (gc.clauses);
1702 gc.inclause = topClause (gc.clauses);
1705 void context_exitOrClause (exprNode pred, exprNode tbranch)
1707 context_setJustPopped ();
1709 llassert (gc.inclause == ORCLAUSE);
1711 usymtab_popOrBranch (pred, tbranch);
1712 clauseStack_pop (gc.clauses);
1713 gc.inclause = topClause (gc.clauses);
1716 static void context_enterCondClauseAux (clause cl)
1722 static void context_enterTrueAux (exprNode e, clause cl)
1725 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1729 void context_enterIterClause (void)
1731 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1734 void context_enterDoWhileClause (void)
1736 pushClause (DOWHILECLAUSE);
1739 void context_enterWhileClause (exprNode e)
1741 context_enterTrueAux (e, WHILECLAUSE);
1744 void context_enterForClause (exprNode e)
1746 context_enterTrueAux (e, FORCLAUSE);
1749 void context_enterTrueClause (exprNode e)
1751 context_enterTrueAux (e, TRUECLAUSE);
1754 void context_enterSwitch (exprNode e)
1756 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1757 usymtab_switchBranch (e);
1758 context_enterCondClauseAux (SWITCHCLAUSE);
1761 void context_exitSwitch (exprNode e, bool allpaths)
1763 usymtab_exitSwitch (e, allpaths);
1765 while (clause_isCase (clauseStack_top (gc.clauses)))
1767 clauseStack_pop (gc.clauses);
1770 context_exitClauseSimp ();
1773 void context_enterCaseClause (exprNode e)
1775 bool branch = FALSE;
1777 DPRINTF (("Enter case clause!"));
1779 branch = usymtab_newCase (exprNode_undefined, e);
1783 context_enterCondClauseAux (CASECLAUSE);
1787 static void context_enterFalseClauseAux (exprNode e, clause cl)
1790 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1792 clauseStack_switchTop (gc.clauses, cl);
1795 void context_enterFalseClause (exprNode e)
1798 context_enterFalseClauseAux (e, FALSECLAUSE);
1802 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1804 gc.kind = CX_MACROCONST;
1806 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1808 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1812 usymtab_enterScope ();
1813 sRef_enterFunctionScope ();
1815 gc.globs = globSet_undefined;
1816 globSet_clear (gc.globs_used);
1817 gc.mods = sRefSet_undefined;
1820 uentry context_getHeader (void)
1822 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1824 llfatalbug (message ("context_getHeader: bad call: %q",
1825 context_unparse ()));
1828 return (gc.cont.fcn);
1832 context_setFunctionDefined (fileloc loc)
1836 case CX_UNKNOWNMACRO:
1839 uentry_setFunctionDefined (gc.cont.fcn, loc);
1842 /* (not a bug because of parse errors) */
1848 context_enterFunction (/*@exposed@*/ uentry e)
1850 gc.kind = CX_FUNCTION;
1853 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1855 if (uentry_hasAccessType (e))
1857 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1865 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1866 typeIdSet_unparse (gc.acct)));
1868 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1870 gc.globs = uentry_getGlobs (e);
1871 globSet_clear (gc.globs_used);
1872 gc.mods = uentry_getMods (e);
1874 usymtab_enterFunctionScope (e);
1875 sRef_enterFunctionScope ();
1878 bool context_inOldStyleScope(void)
1880 return (gc.kind == CX_OLDSTYLESCOPE);
1884 context_enterOldStyleScope (void)
1886 gc.kind = CX_OLDSTYLESCOPE;
1887 DPRINTF (("Enter old style scope!"));
1888 usymtab_enterFunctionScope (uentry_undefined);
1892 context_completeOldStyleFunction (uentry e)
1894 llassert (gc.kind == CX_OLDSTYLESCOPE);
1896 gc.kind = CX_FUNCTION;
1899 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1901 if (uentry_hasAccessType (e))
1903 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1911 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1912 typeIdSet_unparse (gc.acct)));
1914 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1916 if (!globSet_isEmpty (uentry_getGlobs (e)))
1918 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1919 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1922 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1924 gc.globs = uentry_getGlobs (e);
1925 globSet_clear (gc.globs_used);
1927 gc.mods = uentry_getMods (e);
1929 if (!sRefSet_isEmpty (gc.mods))
1931 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1932 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1935 sRef_enterFunctionScope ();
1938 static bool context_checkStrictGlobals (void)
1940 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1943 static bool context_hasGlobs (void)
1945 if (context_inFunctionLike ())
1947 return (uentry_hasGlobs (gc.cont.fcn));
1955 static bool context_checkCheckedGlobals (void)
1957 return (context_getFlag (FLG_GLOBALS)
1958 && (context_getFlag (FLG_GLOBUNSPEC)
1959 || context_hasGlobs ()));
1962 static bool context_checkUnknownGlobals (void)
1964 /* should be uentry_hasGlobs ? */
1966 return (context_getFlag (FLG_ALLGLOBALS)
1967 && (context_getFlag (FLG_GLOBUNSPEC)
1968 || context_hasGlobs ()));
1971 static bool context_checkUncheckedGlobals (void)
1977 context_checkExport (uentry e)
1979 if (!gc.anyExports) return FALSE;
1981 if (uentry_isFunction (e)
1982 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1984 return context_maybeSet (FLG_EXPORTFCN);
1986 else if (uentry_isExpandedMacro (e))
1988 return context_maybeSet (FLG_EXPORTMACRO);
1990 else if (uentry_isVariable (e))
1992 return context_maybeSet (FLG_EXPORTVAR);
1994 else if (uentry_isEitherConstant (e))
1996 return context_maybeSet (FLG_EXPORTCONST);
1998 else if (uentry_isIter (e) || uentry_isEndIter (e))
2000 return context_maybeSet (FLG_EXPORTITER);
2002 else if (uentry_isDatatype (e))
2004 return context_maybeSet (FLG_EXPORTTYPE);
2013 context_checkGlobUse (uentry glob)
2016 if (uentry_isCheckedStrict (glob))
2018 return context_checkStrictGlobals ();
2020 else if (uentry_isChecked (glob))
2022 return context_checkCheckedGlobals ();
2024 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2026 return context_checkUnknownGlobals ();
2030 llassert (uentry_isUnchecked (glob));
2032 return context_checkUncheckedGlobals ();
2037 context_checkAliasGlob (uentry glob)
2039 if (uentry_isCheckedStrict (glob))
2041 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2043 else if (uentry_isChecked (glob))
2045 return gc.flags[FLG_CHECKEDGLOBALIAS];
2047 else if (uentry_isCheckMod (glob))
2049 return gc.flags[FLG_CHECKMODGLOBALIAS];
2053 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2055 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2059 bool context_checkInternalUse (void)
2061 if (context_hasGlobs ())
2063 return (gc.flags[FLG_INTERNALGLOBS]);
2067 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2072 context_checkGlobMod (sRef el)
2074 uentry ue = sRef_getUentry (el);
2076 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2078 if (uentry_isCheckedModify (ue)
2079 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2081 if (context_hasMods ())
2083 return (gc.flags[FLG_MODGLOBS]);
2087 if (uentry_isCheckedStrict (ue))
2089 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2093 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2099 if (context_hasMods ())
2101 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2111 context_usedGlobal (/*@exposed@*/ sRef el)
2113 if (!globSet_member (gc.globs_used, el))
2116 ** The first time a global is used in a function, we need
2117 ** to clear the derived sRefs, since they were set for the
2118 ** previous function.
2121 sRef_clearDerived (el);
2122 gc.globs_used = globSet_insert (gc.globs_used, el);
2126 /*@observer@*/ sRefSet
2127 context_modList (void)
2133 context_globAccess (sRef s)
2135 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2136 return (globSet_member (gc.globs, s));
2140 context_hasAccess (typeId t)
2142 if (context_inFunctionLike ())
2144 DPRINTF (("Access %d / %s",
2145 t, typeIdSet_unparse (gc.acct)));
2146 return (typeIdSet_member (gc.acct, t));
2150 return (context_hasFileAccess (t));
2155 context_hasFileAccess (typeId t)
2157 return (typeIdSet_member (gc.facct, t));
2161 context_unparseAccess (void)
2163 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2164 typeIdSet_unparse (gc.facct)));
2168 context_unparseClauses (void)
2170 return (clauseStack_unparse (gc.clauses));
2174 context_couldHaveAccess (typeId t)
2176 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2178 return (typeIdSet_member (gc.acct, t));
2182 return (typeIdSet_member (gc.facct, t));
2187 context_getRetType (void)
2189 ctype f = ctype_undefined;
2191 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2193 f = uentry_getType (gc.cont.fcn);
2195 else if (gc.kind == CX_UNKNOWNMACRO)
2197 return ctype_unknown;
2201 llcontbuglit ("context_getRetType: not in a function context");
2202 return ctype_unknown;
2205 if (!ctype_isFunction (f))
2207 if (ctype_isKnown (f))
2209 llbuglit ("context_getRetType: not a function");
2212 return ctype_unknown;
2214 return (ctype_getReturnType (f));
2218 context_hasMods (void)
2220 if (context_inFunctionLike ())
2222 return (uentry_hasMods (gc.cont.fcn));
2231 context_exitAllClauses (void)
2233 while (!clauseStack_isEmpty (gc.clauses))
2235 clause el = clauseStack_top (gc.clauses);
2238 if (clause_isNone (el))
2240 usymtab_quietExitScope (g_currentloc);
2241 clauseStack_pop (gc.clauses);
2245 context_exitClausePlain ();
2249 clauseStack_clear (gc.clauses);
2250 gc.inclause = NOCLAUSE;
2254 context_exitAllClausesQuiet (void)
2256 while (!clauseStack_isEmpty (gc.clauses))
2258 clause el = clauseStack_top (gc.clauses);
2261 usymtab_quietExitScope (g_currentloc);
2262 clauseStack_pop (gc.clauses);
2265 clauseStack_clear (gc.clauses);
2266 gc.inclause = NOCLAUSE;
2270 void context_exitClauseSimp (void)
2273 context_setJustPopped ();
2274 clauseStack_pop (gc.clauses);
2275 gc.inclause = topClause (gc.clauses);
2279 void context_exitCaseClause (void)
2281 context_setJustPopped ();
2282 usymtab_popCaseBranch ();
2283 clauseStack_pop (gc.clauses);
2284 gc.inclause = topClause (gc.clauses);
2288 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2290 context_setJustPopped ();
2291 /*@i32 was makeAlt */
2292 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2293 clauseStack_pop (gc.clauses);
2294 gc.inclause = topClause (gc.clauses);
2297 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2299 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2301 if (gc.inclause != TRUECLAUSE)
2303 llparseerror (cstring_makeLiteral
2304 ("Likely parse error. Conditional clauses are inconsistent."));
2308 context_setJustPopped ();
2309 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2310 clauseStack_pop (gc.clauses);
2311 gc.inclause = topClause (gc.clauses);
2314 void context_exitIterClause (exprNode body)
2316 llassert (gc.inclause == ITERCLAUSE);
2318 context_setJustPopped ();
2320 if (context_getFlag (FLG_ITERLOOPEXEC))
2322 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2326 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2329 clauseStack_pop (gc.clauses);
2330 gc.inclause = topClause (gc.clauses);
2333 static void context_popCase (void) {
2335 ** If we are exiting an outer clause, sometimes still in a switch case.
2349 DPRINTF (("Popping case clause: %s",
2350 clauseStack_unparse (gc.clauses)));
2352 if (gc.inclause == CASECLAUSE) {
2353 context_exitCaseClause ();
2357 void context_exitWhileClause (exprNode pred, exprNode body)
2359 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2363 if (gc.inclause != WHILECLAUSE) {
2364 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2365 clauseStack_unparse (gc.clauses)));
2368 llassert (gc.inclause == WHILECLAUSE);
2370 context_setJustPopped ();
2374 ** predicate must be false after while loop (unless there are breaks)
2377 if (context_getFlag (FLG_WHILELOOPEXEC))
2379 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2383 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2387 usymtab_addGuards (invGuards);
2388 guardSet_free (invGuards);
2390 clauseStack_pop (gc.clauses);
2391 gc.inclause = topClause (gc.clauses);
2394 void context_exitDoWhileClause (exprNode pred)
2396 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2398 if (gc.inclause == CASECLAUSE) {
2399 /* handle Duff's device */
2400 clauseStack_pop (gc.clauses);
2401 gc.inclause = topClause (gc.clauses);
2404 llassert (gc.inclause == DOWHILECLAUSE);
2406 context_setJustPopped ();
2409 usymtab_addGuards (invGuards);
2410 guardSet_free (invGuards);
2412 clauseStack_pop (gc.clauses);
2413 gc.inclause = topClause (gc.clauses);
2416 void context_exitForClause (exprNode forPred, exprNode body)
2418 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2420 llassert (gc.inclause == FORCLAUSE);
2421 context_setJustPopped ();
2423 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2426 ** Predicate must be false after for loop (unless there are breaks)
2429 if (context_getFlag (FLG_FORLOOPEXEC))
2431 DPRINTF (("Here: for loop exec"));
2432 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2436 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2437 && exprNode_loopMustExec (forPred))
2439 DPRINTF (("Here: loop must exec"));
2440 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2444 DPRINTF (("Pop true branch:"));
2445 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2449 usymtab_addGuards (invGuards);
2450 guardSet_free (invGuards);
2451 clauseStack_pop (gc.clauses);
2452 gc.inclause = topClause (gc.clauses);
2455 static void context_exitClausePlain (void)
2457 llassert (gc.inclause != NOCLAUSE);
2459 if (gc.inclause == FALSECLAUSE)
2461 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2465 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2469 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2471 context_setJustPopped ();
2473 if (gc.inclause == FALSECLAUSE)
2475 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2477 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2479 clauseStack_pop (gc.clauses);
2480 gc.inclause = topClause (gc.clauses);
2484 context_exitTrueClause (pred, tbranch);
2489 context_returnFunction (void)
2491 usymtab_checkFinalScope (TRUE);
2495 context_exitFunction (void)
2497 DPRINTF (("Exit function: %s", context_unparse ()));
2499 if (!context_inFunction () && !context_inMacroConstant ()
2500 && !context_inUnknownMacro ()
2501 && !context_inIterDef () && !context_inIterEnd ())
2504 ** not a bug because of parse errors
2511 if (context_inMacro () && usymtab_inFunctionScope ())
2513 usymtab_exitScope (exprNode_undefined);
2516 if (uentry_hasGlobs (gc.cont.fcn))
2518 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2522 if (uentry_hasMods (gc.cont.fcn))
2524 if (context_getFlag (FLG_MUSTMOD))
2526 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2530 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2533 ** clear file static modifies
2536 /* do this first to get unused error messages */
2538 usymtab_exitScope (exprNode_undefined);
2539 sRef_exitFunctionScope ();
2541 gc.showfunction = FALSE;
2542 gc.kind = CX_GLOBAL;
2543 gc.cont.glob = TRUE;
2545 gc.globs = globSet_new ();
2546 globSet_clear (gc.globs_used);
2547 gc.mods = sRefSet_new ();
2550 llassert (clauseStack_isEmpty (gc.clauses));
2551 llassert (gc.inclause == NOCLAUSE);
2552 DPRINTF (("After exit function: %s", context_unparse ()));
2556 context_quietExitFunction (void)
2558 while (gc.kind == CX_INNER)
2560 context_exitInnerPlain ();
2563 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2564 && !context_inIterDef () && !context_inIterEnd ())
2569 usymtab_quietExitScope (g_currentloc);
2571 gc.showfunction = FALSE;
2572 gc.kind = CX_GLOBAL;
2573 gc.cont.glob = TRUE;
2575 gc.globs = globSet_new ();
2576 globSet_clear (gc.globs_used);
2577 gc.mods = sRefSet_new ();
2579 sRef_exitFunctionScope ();
2583 /*@observer@*/ uentryList
2584 context_getParams (void)
2586 if (context_inFunctionLike ())
2588 return (uentry_getParams (gc.cont.fcn));
2592 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2593 return uentryList_undefined;
2597 /*@observer@*/ globSet
2598 context_getUsedGlobs (void)
2600 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2601 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2603 return (gc.globs_used);
2607 context_moduleName ()
2609 return (fileloc_getBase (g_currentloc));
2612 /*@observer@*/ globSet
2613 context_getGlobs (void)
2615 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2616 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2622 context_addBoolAccess (void)
2624 cstring bname = context_getString (FLG_BOOLTYPE);
2625 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2627 addModuleAccess (cstring_copy (bname), boolt);
2629 /* for sys/types (perhaps, this is bogus!) */
2630 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2635 context_canAccessBool (void)
2642 static typeId boolType = typeId_invalid;
2644 if (typeId_isInvalid (boolType))
2646 boolType = usymtab_getTypeId (context_getBoolName ());
2649 if (typeId_isInvalid (boolType)) {
2652 return (typeIdSet_member (gc.acct, boolType));
2657 /* evs 2000-07-25: old version - replaced */
2660 context_boolImplementationType () {
2661 /* For now, this is bogus! */
2666 context_canAccessBool (void)
2668 static typeId boolType = typeId_invalid;
2670 if (typeId_isInvalid (boolType))
2672 boolType = usymtab_getTypeId (context_getBoolName ());
2675 if (!typeId_isInvalid (boolType))
2677 return context_hasAccess (boolType);
2688 context_setMessageAnnote (/*@only@*/ cstring s)
2690 llassert (cstring_isUndefined (gc.msgAnnote));
2695 context_hasMessageAnnote (void)
2697 return (cstring_isDefined (gc.msgAnnote));
2701 context_clearMessageAnnote (void)
2703 if (cstring_isDefined (gc.msgAnnote))
2705 cstring_free (gc.msgAnnote);
2706 gc.msgAnnote = cstring_undefined;
2711 context_getMessageAnnote (void)
2713 cstring st = gc.msgAnnote;
2715 gc.msgAnnote = cstring_undefined;
2720 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2722 llassert (sRef_isInvalid (gc.aliasAnnote));
2723 llassert (!sRef_sameName (s, t));
2725 gc.aliasAnnoteAls = t;
2729 context_hasAliasAnnote (void)
2731 return (sRef_isValid (gc.aliasAnnote));
2735 context_clearAliasAnnote (void)
2737 gc.aliasAnnote = sRef_undefined;
2741 context_getAliasAnnote (void)
2743 sRef ret = gc.aliasAnnote;
2744 sRef als = gc.aliasAnnoteAls;
2746 llassert (sRef_isValid (ret) && sRef_isValid (als));
2748 gc.aliasAnnote = sRef_undefined;
2749 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2753 context_recordFileModifies (sRefSet mods)
2755 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2759 context_recordFileGlobals (globSet mods)
2761 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2762 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2766 context_setCommentMarkerChar (char c)
2768 llassert (c != '\0');
2770 context_setValue (FLG_COMMENTCHAR, (int) c);
2774 context_getCommentMarkerChar (void)
2776 return ((char) context_getValue (FLG_COMMENTCHAR));
2780 context_setValue (flagcode flag, int val)
2782 int index = flagcode_valueIndex (flag);
2784 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2792 llerror_flagWarning (message ("Value for %s must be a positive "
2793 "number (given %d)",
2794 flagcode_unparse (flag), val));
2797 if (flag == FLG_LINELEN && val < MINLINELEN)
2799 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2800 flagcode_unparse (flag),
2806 case FLG_INCLUDENEST:
2807 case FLG_CONTROLNESTDEPTH:
2808 case FLG_STRINGLITERALLEN:
2809 case FLG_NUMSTRUCTFIELDS:
2810 case FLG_NUMENUMMEMBERS:
2811 case FLG_INDENTSPACES:
2814 llerror_flagWarning (message ("Value for %s must be a non-negative "
2815 "number (given %d)",
2816 flagcode_unparse (flag), val));
2825 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2826 gc.values[index] = val;
2830 context_setValueAndFlag (flagcode flag, int val)
2832 gc.flags[flag] = TRUE;
2833 context_setValue (flag, val);
2837 context_getValue (flagcode flag)
2839 int index = flagcode_valueIndex (flag);
2841 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2842 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2843 return (gc.values[index]);
2847 context_getCounter (flagcode flag)
2849 int index = flagcode_valueIndex (flag);
2851 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2852 return (gc.counters[index]);
2856 context_incCounter (flagcode flag)
2858 int index = flagcode_valueIndex (flag);
2860 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2862 gc.counters[index]++;
2866 context_decCounter (flagcode flag)
2868 int index = flagcode_valueIndex (flag);
2870 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2871 gc.counters[index]--;
2874 bool context_showFunction (void)
2876 return (gc.showfunction);
2880 context_setString (flagcode flag, cstring val)
2882 int index = flagcode_stringIndex (flag);
2884 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2886 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2892 usymtab_supGlobalEntry
2893 (uentry_makeConstantValue (val, ctype_bool,
2894 fileloc_getBuiltin (), TRUE,
2895 multiVal_makeInt (1)));
2898 usymtab_supGlobalEntry
2899 (uentry_makeConstantValue (val, ctype_bool,
2900 fileloc_getBuiltin (), FALSE,
2901 multiVal_makeInt (0)));
2904 case FLG_MESSAGESTREAM:
2905 case FLG_WARNINGSTREAM:
2906 case FLG_ERRORSTREAM:
2908 if (cstring_isDefined (val))
2912 if (osd_fileExists (val))
2914 if (context_getFlag (FLG_STREAMOVERWRITE))
2916 llfatalerror (message
2917 ("Output stream file %s would overwrite existing file. "
2918 "Use -streamoverwrite if you want to allow this.",
2923 fstream = fopen (cstring_toCharsSafe (val), "w");
2925 if (fstream == NULL)
2927 llfatalerror (message ("Unable to open output stream file %s for writing",
2932 ** This ensures fstream will be closed on exit.
2935 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2939 case FLG_MESSAGESTREAM:
2940 g_messagestream = fstream;
2941 /*@innerbreak@*/ break;
2942 case FLG_WARNINGSTREAM:
2943 g_warningstream = fstream;
2944 /*@innerbreak@*/ break;
2945 case FLG_ERRORSTREAM:
2946 g_errorstream = fstream;
2947 /*@innerbreak@*/ break;
2950 /*@-statetransfer@*/
2951 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2954 case FLG_SYSTEMDIRS:
2956 llassert (cstring_isDefined (val));
2958 if (cstring_firstChar (val) == '\"')
2961 cstring tval = cstring_copy (cstring_suffix (val, 1));
2963 if (cstring_lastChar (tval) != '\"')
2965 int n = cstring_length (tval) - 1;
2967 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2972 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2975 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2979 cstring otval = tval;
2980 tval = cstring_prefix (tval, size_fromInt (n));
2981 cstring_free (otval);
2985 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2986 DPRINTF (("val = %s", val));
2987 cstring_free (tval);
2988 cstring_free (oval);
2995 llassert (cstring_isDefined (val));
2997 if (cstring_length (val) == 0)
3000 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
3002 else if (cstring_lastChar (val) != CONNECTCHAR)
3004 val = cstring_appendChar (val, CONNECTCHAR);
3014 ; /* Okay not handle everything in this switch */
3016 /*@i523@*/ } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */
3018 if (cstring_length (val) >= 1
3019 && cstring_firstChar (val) == '\"')
3021 llerror_flagWarning (message
3022 ("Setting %s to string beginning with \". You probably "
3023 "don't meant to have the \"'s.",
3024 flagcode_unparse (flag)));
3027 gc.strings[index] = val;
3030 static /*@exposed@*/ cstring
3031 context_exposeString (flagcode flag)
3033 int index = flagcode_stringIndex (flag);
3035 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3036 return (gc.strings[index]);
3040 context_getString (flagcode flag)
3042 return (context_exposeString (flag));
3046 context_resetErrors (void)
3051 void context_initMod (void)
3052 /*@globals undef gc; @*/
3054 gc.kind = CX_GLOBAL;
3056 gc.savekind = CX_ERROR;
3057 gc.savecont.glob = FALSE;
3059 gc.instandardlib = FALSE;
3062 gc.linesprocessed = 0;
3063 gc.speclinesprocessed = 0;
3064 gc.insuppressregion = FALSE;
3065 gc.macroMissingParams = FALSE;
3066 gc.preprocessing = FALSE;
3067 gc.incommandline = FALSE;
3068 gc.mc = macrocache_create ();
3070 gc.maxmods = DEFAULTMAXMODS;
3071 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3073 gc.library = FLG_ANSILIB;
3075 gc.locstack = filelocStack_new ();
3076 gc.modrecs = sRefSetList_undefined;
3077 gc.anyExports = FALSE;
3079 gc.ftab = fileTable_create ();
3080 gc.msgLog = messageLog_new ();
3081 gc.inimport = FALSE;
3082 gc.inDerivedFile = FALSE;
3083 gc.inheader = FALSE;
3084 gc.markers = flagMarkerList_new ();
3085 gc.cont.glob = TRUE;
3086 gc.showfunction = FALSE;
3087 gc.msgAnnote = cstring_undefined;
3088 gc.aliasAnnote = sRef_undefined;
3089 gc.aliasAnnoteAls = sRef_undefined;
3090 gc.boolType = ctype_bool;
3091 gc.mods = sRefSet_new ();
3093 gc.saveloc = fileloc_undefined;
3095 gc.inmacrocache = FALSE;
3096 gc.inclause = NOCLAUSE;
3097 gc.clauses = clauseStack_new ();
3098 gc.globs = globSet_new ();
3099 gc.nacct = typeIdSet_emptySet ();
3100 gc.acct = typeIdSet_emptySet ();
3101 gc.facct = typeIdSet_emptySet ();
3102 gc.savedFlags = FALSE;
3103 gc.pushloc = fileloc_undefined;
3104 gc.protectVars = FALSE;
3105 gc.justpopped = FALSE;
3106 gc.isNullGuarded = NO;
3107 gc.globs_used = globSet_undefined;
3111 gc.setGlobally[code] = FALSE;
3112 gc.setLocally[code] = FALSE;
3117 context_resetAllFlags ();
3119 assertSet (gc.flags); /* Can't use global in defines */
3120 assertSet (gc.saveflags);
3121 assertSet (gc.values);
3122 assertSet (gc.strings);
3124 conext_resetAllCounters ();
3125 assertSet (gc.counters);
3127 context_setMode (DEFAULT_MODE);
3129 gc.stateTable = metaStateTable_create ();
3130 gc.annotTable = annotationTable_create ();
3132 gc.inFunctionHeader = FALSE;
3134 DPRINTF (("Annotations: \n%s",
3135 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3136 DPRINTF (("State: \n%s",
3137 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3142 context_typeofZero (void)
3144 ctype ct = ctype_int;
3146 if (context_getFlag (FLG_ZEROPTR))
3148 ct = ctype_makeConj (ct, ctype_voidPointer);
3151 if (context_getFlag (FLG_ZEROBOOL)) {
3152 ct = ctype_makeConj (ct, ctype_bool);
3159 context_typeofOne (void)
3161 ctype ct = ctype_int;
3163 /* 1 is on longer a bool (was before 2.4)
3164 if (!context_getFlag (FLG_ABSTRACTBOOL))
3166 ct = ctype_makeConj (ct, ctype_bool);
3174 context_unparse (void)
3181 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3184 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3187 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3190 s = message ("Inner Context [%d] : %q",
3192 fileloc_unparse (g_currentloc));
3195 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3196 uentry_unparse (gc.cont.fcn),
3197 fileloc_unparse (g_currentloc),
3198 typeIdSet_unparse (gc.acct),
3199 sRefSet_unparse (gc.mods));
3202 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3204 case CX_UNKNOWNMACRO:
3205 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3208 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3211 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3214 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3216 case CX_FCNDECLARATION:
3217 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3220 s = message ("Un-unparseable context: %d", (int) gc.kind);
3224 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3229 context_currentFunctionType (void)
3231 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3233 return (uentry_getType (gc.cont.fcn));
3235 else if (gc.kind == CX_INNER)
3237 llcontbuglit ("context_currentFunctionType: inner context");
3238 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3239 return (context_currentFunctionType ());
3243 llcontbuglit ("context_currentFunctionType: not in function");
3244 return (ctype_undefined);
3249 context_enterInnerContext (void)
3251 if (context_getFlag (FLG_GRAMMAR))
3253 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3256 if (gc.kind == CX_GLOBAL)
3261 else if (gc.kind == CX_INNER)
3270 usymtab_enterScope ();
3271 pushClause (NOCLAUSE);
3275 context_exitInnerPlain (void) /*@modifies gc;@*/
3277 context_exitInner (exprNode_undefined);
3281 context_exitInner (exprNode exp)
3283 if (context_getFlag (FLG_GRAMMAR))
3285 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3288 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3289 ("inclause = %s", clause_nameTaken (gc.inclause)));
3291 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3292 gc.inclause = topClause (gc.clauses);
3294 if (gc.kind == CX_INNER)
3296 if (--gc.cont.cdepth == 0)
3298 gc.kind = CX_GLOBAL;
3299 gc.cont.glob = TRUE;
3304 if (gc.kind == CX_GLOBAL)
3306 llcontbuglit ("Attempt to exit global context");
3311 usymtab_exitScope (exp);
3316 context_enterStructInnerContext (void)
3318 if (context_getFlag (FLG_GRAMMAR))
3320 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3323 if (gc.kind == CX_GLOBAL)
3328 else if (gc.kind == CX_INNER)
3337 usymtab_enterScope ();
3339 if (context_getFlag (FLG_GRAMMAR))
3341 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3346 context_exitStructInnerContext (void)
3348 if (context_getFlag (FLG_GRAMMAR))
3350 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3353 if (gc.kind == CX_INNER)
3355 if (gc.cont.cdepth <= 0)
3357 llcontbuglit ("Attempt to exit inner context with no depth");
3358 gc.kind = CX_GLOBAL;
3359 gc.cont.glob = TRUE;
3365 if (gc.cont.cdepth == 0)
3367 gc.kind = CX_GLOBAL;
3368 gc.cont.glob = TRUE;
3374 if (gc.kind == CX_GLOBAL)
3376 llcontbuglit ("Attempt to exit global context");
3381 usymtab_exitScope (exprNode_undefined);
3383 if (context_getFlag (FLG_GRAMMAR))
3385 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3390 context_exitInnerSafe (void)
3392 if (context_getFlag (FLG_GRAMMAR))
3394 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3397 if (gc.kind == CX_INNER)
3399 if (--gc.cont.cdepth <= 0)
3404 else if (gc.kind == CX_GLOBAL)
3406 llcontbuglit ("Attempt to exit global context");
3411 if (usymtab_inDeepScope ())
3413 usymtab_exitScope (exprNode_undefined);
3419 void setModuleAccess (void)
3421 gc.facct = typeIdSet_emptySet ();
3423 if (fileId_isValid (currentFile ()))
3425 cstring baseName = fileloc_getBase (g_currentloc);
3427 if (context_getFlag (FLG_ACCESSFILE))
3429 if (usymtab_existsType (baseName))
3431 gc.facct = typeIdSet_insert (gc.facct,
3432 usymtab_getTypeId (baseName));
3440 if (context_getFlag (FLG_ACCESSMODULE))
3443 bool hasaccess = FALSE;
3445 for (i = 0; i < gc.nmods; i++)
3447 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3449 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3458 gc.inheader = fileId_isHeader (currentFile ());
3462 llcontbuglit ("Current file not defined\n");
3463 gc.facct = typeIdSet_emptySet ();
3465 gc.inheader = FALSE;
3468 /* 17 Jan 1995: forgot to clear nacct */
3470 gc.nacct = typeIdSet_emptySet ();
3474 context_enterFileAux (void)
3480 context_enterFile (void)
3482 context_enterFileAux ();
3483 usymtab_enterFile ();
3487 context_enterMacroFile (void)
3489 context_enterFileAux ();
3493 context_inFunction (void)
3495 kcontext ck = gc.kind;
3497 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3501 context_inFunctionLike (void)
3503 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3504 || gc.kind == CX_FCNDECLARATION
3505 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3509 context_inRealFunction (void)
3511 kcontext ck = gc.kind;
3513 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3517 context_processAllMacros (void)
3519 usymtab_enterFile ();
3521 gc.inmacrocache = TRUE;
3522 macrocache_processUndefinedElements (gc.mc);
3524 usymtab_exitFile ();
3526 gc.inmacrocache = FALSE;
3527 macrocache_finalize ();
3531 ** this happens once at the end of each C file
3533 ** check each Macro that was defined in current file.c or current file.h
3538 context_processMacros (void)
3540 if (fileId_isValid (currentFile ()))
3543 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3545 gc.inmacrocache = TRUE;
3547 DPRINTF (("Processing macros: %s", cbase));
3548 lastfl = macrocache_processFileElements (gc.mc, cbase);
3549 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3551 cstring_free (cbase);
3553 if (fileloc_isDefined (lastfl))
3555 g_currentloc = fileloc_update (g_currentloc, lastfl);
3559 gc.inmacrocache = FALSE;
3564 context_processingMacros (void)
3566 return (gc.inmacrocache);
3570 context_exitCFile (void)
3572 if (gc.kind != CX_GLOBAL)
3575 (cstring_makeLiteral ("File ended outside global scope"));
3578 if (gc.insuppressregion)
3580 /* gack...don't reverse the order of these lines! ;-> */
3581 gc.insuppressregion = FALSE;
3582 llerrorlit (FLG_SYNTAX,
3583 "File ended in ignore errors region, "
3584 "possible missing /*@end*/");
3587 /* fix up parse errors */
3589 while (!usymtab_inFileScope ())
3591 usymtab_quietExitScope (g_currentloc);
3595 ** Clear the file-specific modifies information.
3598 sRefSetList_elements (gc.modrecs, mods)
3600 sRefSet_clearStatics (mods);
3601 } end_sRefSetList_elements ;
3603 sRefSetList_clear (gc.modrecs);
3605 context_processMacros ();
3608 usymtab_exitFile ();
3610 gc.inDerivedFile = FALSE;
3611 filelocStack_clear (gc.locstack);
3613 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3615 gc.cont.glob = TRUE;
3619 context_restoreFlagSettings ();
3620 gc.savedFlags = FALSE;
3624 DPRINTF (("After exiting file: "));
3625 usymtab_printAll ();
3630 context_exitMacroCache (void)
3632 if (gc.kind != CX_GLOBAL)
3634 if (context_inMacro ())
3635 /* this is okay, file could end without newline in macro */
3637 DPRINTF (("Still in macro: %s",
3638 context_unparse ()));
3639 context_exitFunction ();
3643 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3644 context_unparse ()));
3645 gc.kind = CX_GLOBAL;
3650 ** no longer valid here
3651 ** if (gc.insuppressregion)
3653 ** gc.insuppressregion = FALSE;
3654 ** llerror ("File ended in ignore errors region, possible missing @");
3658 gc.cont.glob = TRUE;
3662 context_saveLocation (void)
3664 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3665 fileloc_free (gc.saveloc);
3666 gc.saveloc = fileloc_copy (g_currentloc);
3670 context_getSaveLocation (void)
3672 fileloc fl = gc.saveloc;
3673 gc.saveloc = fileloc_undefined;
3677 /*@observer@*/ cstring
3678 context_inFunctionName (void)
3680 if (gc.kind == CX_FUNCTION
3681 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3682 || gc.kind == CX_MACROCONST
3683 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3685 return (uentry_rawName (gc.cont.fcn));
3689 llcontbuglit ("context_inFunctionName: not in function");
3690 return (cstring_undefined);
3695 context_userSetFlag (flagcode f, bool b)
3697 DPRINTF (("set flag: %s / %s",
3698 flagcode_unparse (f),
3699 bool_unparse (context_getFlag (f))));
3701 if (f == FLG_NEVERINCLUDE && b)
3703 if (gc.flags[FLG_EXPORTHEADER])
3706 (cstring_makeLiteral
3707 ("Setting +neverinclude after +exportheader. "
3708 "Turning off exportheader, since headers are not checked "
3709 "when +neverinclude is used."));
3711 gc.flags[FLG_EXPORTHEADER] = FALSE;
3716 if (f == FLG_EXPORTHEADER && b)
3718 if (gc.flags[FLG_NEVERINCLUDE])
3721 (cstring_makeLiteral
3722 ("Setting +exportheader after +neverinclude. "
3723 "Not setting exportheader, since headers are not checked "
3724 "when +neverinclude is used."));
3725 gc.flags[FLG_EXPORTHEADER] = FALSE;
3731 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3733 bool lastsetting = context_getFlag (f);
3735 if (bool_equal (lastsetting, b)
3736 && !flagcode_isSpecialFlag (f)
3737 && !flagcode_isIdemFlag (f)
3738 && !flagcode_hasArgument (f))
3741 (message ("Setting %s%s redundant with current value",
3742 cstring_makeLiteralTemp (b ? "+" : "-"),
3743 flagcode_unparse (f)));
3747 if (flagcode_isWarnUseFlag (f) && b)
3749 if (!context_getFlag (FLG_WARNUSE))
3752 (message ("Flag +%s is canceled by -warnuse",
3753 flagcode_unparse (f)));
3758 if (flagcode_isLibraryFlag (f))
3760 if (gc.library != FLG_ANSILIB
3764 (message ("Selecting library %s after library %s was "
3765 "selected (only one library may be used)",
3766 flagcode_unparse (f),
3767 flagcode_unparse (gc.library)));
3770 if (f == FLG_UNIXLIB)
3772 if (context_getFlag (FLG_WARNUNIXLIB))
3775 (cstring_makeLiteral
3776 ("Selecting unix library. Unix library is "
3777 "ad hoc addition to POSIX library. Recommend "
3778 "use +posixlib to select POSIX library instead. "
3779 "Use -warnunixlib to suppress this message."));
3786 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3790 ("Setting +%s will not produce warnings with -namechecks. "
3791 "Must set +namechecks also.",
3792 flagcode_unparse (f)));
3795 gc.setGlobally[f] = TRUE;
3796 context_setFlag (f, b, g_currentloc);
3800 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3804 context_saveFlagSettings ();
3807 if (ynm_isOff (set))
3809 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3811 else if (ynm_isOn (set))
3813 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3814 gc.setLocally[f] = TRUE;
3818 context_restoreFlag (f, loc);
3823 context_restoreFlag (flagcode f, fileloc loc)
3829 message ("Attempt to restore flag %s when no file scope flags "
3831 flagcode_unparse (f)),
3836 context_addFlagMarker (f, MAYBE, loc);
3837 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3843 context_setFlag (flagcode f, bool b, fileloc loc)
3845 context_setFlagAux (f, b, FALSE, FALSE, loc);
3849 context_setFlagTemp (flagcode f, bool b)
3851 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3856 # define DOSET(ff,b) \
3857 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3858 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3859 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3860 gc.flags[ff] = b; } while (FALSE)
3863 context_setFlagAux (flagcode f, bool b, bool inFile,
3864 /*@unused@*/ bool isRestore, fileloc loc)
3866 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3869 ** Removed test for special flags.
3872 if (flagcode_isIdemFlag (f))
3881 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3883 if (b) /* Turing higher level on, turns on all lower levels */
3887 case FLG_ITS4MOSTRISKY:
3888 DOSET (FLG_ITS4VERYRISKY, b);
3890 case FLG_ITS4VERYRISKY:
3891 DOSET (FLG_ITS4RISKY, b);
3894 DOSET (FLG_ITS4MODERATERISK, b);
3896 case FLG_ITS4MODERATERISK:
3897 DOSET (FLG_ITS4LOWRISK, b);
3899 case FLG_ITS4LOWRISK:
3904 else /* Turning level off, turns off all higher levels */
3908 case FLG_ITS4LOWRISK:
3909 DOSET (FLG_ITS4MODERATERISK, b);
3911 case FLG_ITS4MODERATERISK:
3912 DOSET (FLG_ITS4RISKY, b);
3915 DOSET (FLG_ITS4VERYRISKY, b);
3917 case FLG_ITS4VERYRISKY:
3918 DOSET (FLG_ITS4MOSTRISKY, b);
3920 case FLG_ITS4MOSTRISKY:
3929 case FLG_MESSAGESTREAMSTDOUT:
3930 g_messagestream = stdout;
3932 case FLG_MESSAGESTREAMSTDERR:
3933 g_messagestream = stderr;
3935 case FLG_WARNINGSTREAMSTDOUT:
3936 g_warningstream = stdout;
3938 case FLG_WARNINGSTREAMSTDERR:
3939 g_warningstream = stderr;
3941 case FLG_ERRORSTREAMSTDOUT:
3942 g_errorstream = stdout;
3944 case FLG_ERRORSTREAMSTDERR:
3945 g_errorstream = stderr;
3948 DOSET (FLG_ALLEMPTY, b);
3949 DOSET (FLG_IFEMPTY, b);
3950 DOSET (FLG_WHILEEMPTY, b);
3951 DOSET (FLG_FOREMPTY, b);
3954 DOSET (FLG_PREDBOOL, b);
3955 DOSET (FLG_PREDBOOLINT, b);
3956 DOSET (FLG_PREDBOOLPTR, b);
3957 DOSET (FLG_PREDBOOLOTHERS, b);
3960 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3961 DOSET (FLG_CHECKEDGLOBALIAS, b);
3962 DOSET (FLG_CHECKMODGLOBALIAS, b);
3963 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3966 DOSET (FLG_ALLBLOCK, b);
3967 DOSET (FLG_IFBLOCK, b);
3968 DOSET (FLG_WHILEBLOCK, b);
3969 DOSET (FLG_FORBLOCK, b);
3983 DOSET (FLG_GRAMMAR, b);
3985 case FLG_CODEIMPONLY:
3986 DOSET (FLG_CODEIMPONLY, b);
3987 DOSET (FLG_GLOBIMPONLY, b);
3988 DOSET (FLG_RETIMPONLY, b);
3989 DOSET (FLG_STRUCTIMPONLY, b);
3991 case FLG_SPECALLIMPONLY:
3992 DOSET (FLG_SPECALLIMPONLY, b);
3993 DOSET (FLG_SPECGLOBIMPONLY, b);
3994 DOSET (FLG_SPECRETIMPONLY, b);
3995 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3997 case FLG_ALLIMPONLY:
3998 DOSET (FLG_ALLIMPONLY, b);
3999 DOSET (FLG_GLOBIMPONLY, b);
4000 DOSET (FLG_RETIMPONLY, b);
4001 DOSET (FLG_STRUCTIMPONLY, b);
4002 DOSET (FLG_SPECGLOBIMPONLY, b);
4003 DOSET (FLG_SPECRETIMPONLY, b);
4004 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4006 case FLG_ANSI89LIMITS:
4007 DOSET (FLG_ANSI89LIMITS, b);
4008 DOSET (FLG_CONTROLNESTDEPTH, b);
4009 DOSET (FLG_STRINGLITERALLEN, b);
4010 DOSET (FLG_INCLUDENEST, b);
4011 DOSET (FLG_NUMSTRUCTFIELDS, b);
4012 DOSET (FLG_NUMENUMMEMBERS, b);
4016 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4017 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4018 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4019 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4020 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4021 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4022 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4025 case FLG_ISO99LIMITS:
4026 DOSET (FLG_ISO99LIMITS, b);
4027 DOSET (FLG_CONTROLNESTDEPTH, b);
4028 DOSET (FLG_STRINGLITERALLEN, b);
4029 DOSET (FLG_INCLUDENEST, b);
4030 DOSET (FLG_NUMSTRUCTFIELDS, b);
4031 DOSET (FLG_NUMENUMMEMBERS, b);
4035 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4036 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4037 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4038 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4039 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4040 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4041 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4044 case FLG_EXTERNALNAMELEN:
4045 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4046 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4048 case FLG_INTERNALNAMELEN:
4049 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4050 DOSET (FLG_INTERNALNAMELEN, TRUE);
4052 case FLG_EXTERNALNAMECASEINSENSITIVE:
4053 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4055 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4057 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4058 context_setValue (FLG_EXTERNALNAMELEN, 0);
4061 case FLG_INTERNALNAMECASEINSENSITIVE:
4062 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4064 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4066 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4067 context_setValue (FLG_INTERNALNAMELEN, 0);
4070 case FLG_INTERNALNAMELOOKALIKE:
4071 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4073 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4075 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4076 context_setValue (FLG_INTERNALNAMELEN, 0);
4080 DOSET (FLG_MODNOMODS, b);
4081 DOSET (FLG_MODGLOBSUNSPEC, b);
4082 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4085 DOSET (FLG_EXPORTVAR, b);
4086 DOSET (FLG_EXPORTFCN, b);
4087 DOSET (FLG_EXPORTTYPE, b);
4088 DOSET (FLG_EXPORTMACRO, b);
4089 DOSET (FLG_EXPORTCONST, b);
4090 gc.anyExports = TRUE;
4093 DOSET (FLG_RETEXPOSE, b);
4094 DOSET (FLG_ASSIGNEXPOSE, b);
4095 DOSET (FLG_CASTEXPOSE, b);
4098 DOSET (FLG_RETVALBOOL, b);
4099 DOSET (FLG_RETVALINT, b);
4100 DOSET (FLG_RETVALOTHER, b);
4105 DOSET (FLG_EXPORTLOCAL, FALSE);
4106 DOSET (FLG_DECLUNDEF, FALSE);
4107 DOSET (FLG_SPECUNDEF, FALSE);
4108 DOSET (FLG_TOPUNUSED, FALSE);
4112 DOSET (FLG_LOOPLOOPBREAK, b);
4113 DOSET (FLG_LOOPSWITCHBREAK, b);
4114 DOSET (FLG_SWITCHLOOPBREAK, b);
4115 DOSET (FLG_SWITCHSWITCHBREAK, b);
4116 DOSET (FLG_LOOPLOOPCONTINUE, b);
4117 DOSET (FLG_DEEPBREAK, b);
4120 DOSET (FLG_FORLOOPEXEC, b);
4121 DOSET (FLG_WHILELOOPEXEC, b);
4122 DOSET (FLG_ITERLOOPEXEC, b);
4125 DOSET (FLG_ACCESSMODULE, b);
4126 DOSET (FLG_ACCESSFILE, b);
4127 DOSET (FLG_ACCESSCZECH, b);
4130 DOSET (FLG_ALLMACROS, b);
4131 DOSET (FLG_FCNMACROS, b);
4132 DOSET (FLG_CONSTMACROS, b);
4135 DOSET (FLG_BOUNDSREAD, b);
4136 DOSET (FLG_BOUNDSWRITE, b);
4139 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4140 DOSET (FLG_CZECHFUNCTIONS, b);
4141 DOSET (FLG_CZECHVARS, b);
4142 DOSET (FLG_CZECHCONSTANTS, b);
4143 DOSET (FLG_CZECHTYPES, b);
4146 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4147 DOSET (FLG_SLOVAKFUNCTIONS, b);
4148 DOSET (FLG_SLOVAKVARS, b);
4149 DOSET (FLG_SLOVAKCONSTANTS, b);
4150 DOSET (FLG_SLOVAKTYPES, b);
4152 case FLG_CZECHOSLOVAK:
4153 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4154 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4155 DOSET (FLG_CZECHOSLOVAKVARS, b);
4156 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4157 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4160 DOSET (FLG_NULLSTATE, b);
4161 DOSET (FLG_NULLDEREF, b);
4162 DOSET (FLG_NULLASSIGN, b);
4163 DOSET (FLG_NULLPASS, b);
4164 DOSET (FLG_NULLRET, b);
4167 DOSET (FLG_MUSTFREEONLY, b);
4168 DOSET (FLG_MUSTFREEFRESH, b);
4171 DOSET (FLG_NULLSTATE, b);
4172 DOSET (FLG_NULLDEREF, b);
4173 DOSET (FLG_NULLASSIGN, b);
4174 DOSET (FLG_NULLPASS, b);
4175 DOSET (FLG_NULLRET, b);
4176 DOSET (FLG_COMPDEF, b);
4177 DOSET (FLG_COMPMEMPASS, b);
4178 DOSET (FLG_UNIONDEF, b);
4179 DOSET (FLG_MEMTRANS, b);
4180 DOSET (FLG_USERELEASED, b);
4181 DOSET (FLG_ALIASUNIQUE, b);
4182 DOSET (FLG_MAYALIASUNIQUE, b);
4183 DOSET (FLG_MUSTFREEONLY, b);
4184 DOSET (FLG_MUSTFREEFRESH, b);
4185 DOSET (FLG_MUSTDEFINE, b);
4186 DOSET (FLG_GLOBSTATE, b);
4187 DOSET (FLG_COMPDESTROY, b);
4188 DOSET (FLG_MUSTNOTALIAS, b);
4189 DOSET (FLG_MEMIMPLICIT, b);
4190 DOSET (FLG_BRANCHSTATE, b);
4191 /*@fallthrough@*/ /* also sets memtrans flags */
4193 DOSET (FLG_MEMTRANS, b);
4194 DOSET (FLG_EXPOSETRANS, b);
4195 DOSET (FLG_OBSERVERTRANS, b);
4196 DOSET (FLG_DEPENDENTTRANS, b);
4197 DOSET (FLG_NEWREFTRANS, b);
4198 DOSET (FLG_ONLYTRANS, b);
4199 DOSET (FLG_OWNEDTRANS, b);
4200 DOSET (FLG_FRESHTRANS, b);
4201 DOSET (FLG_SHAREDTRANS, b);
4202 DOSET (FLG_TEMPTRANS, b);
4203 DOSET (FLG_KEPTTRANS, b);
4204 DOSET (FLG_REFCOUNTTRANS, b);
4205 DOSET (FLG_STATICTRANS, b);
4206 DOSET (FLG_UNKNOWNTRANS, b);
4207 DOSET (FLG_KEEPTRANS, b);
4208 DOSET (FLG_IMMEDIATETRANS, b);
4215 if (b && !gc.anyExports
4216 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4217 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4218 || f == FLG_EXPORTCONST
4219 || f == FLG_EXPORTANY))
4221 gc.anyExports = TRUE;
4226 context_maybeSet (flagcode d)
4228 return (gc.flags[d] || gc.setLocally[d]);
4232 context_getFlag (flagcode d)
4234 return (gc.flags[d]);
4238 context_flagOn (flagcode f, fileloc loc)
4240 return (!context_suppressFlagMsg (f, loc));
4243 static void context_saveFlagSettings (void)
4245 gc.savedFlags = TRUE;
4246 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4247 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4250 static void context_restoreFlagSettings (void)
4252 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4253 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4254 gc.savedFlags = FALSE;
4257 void context_setFilename (fileId fid, int lineno)
4258 /*@globals fileloc g_currentloc;@*/
4259 /*@modifies g_currentloc@*/
4261 if (fileId_baseEqual (currentFile (), fid))
4268 fileloc_setColumn (g_currentloc, 0);
4270 if (fileloc_isSpecialFile (g_currentloc))
4272 gc.inDerivedFile = TRUE;
4275 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4277 int maxdepth = context_getValue (FLG_INCLUDENEST);
4279 if (filelocStack_size (gc.locstack) > maxdepth)
4281 int depth = filelocStack_includeDepth (gc.locstack);
4283 if (depth > maxdepth)
4287 message ("Maximum include nesting depth "
4288 "(%d, current depth %d) exceeded",
4291 filelocStack_nextTop (gc.locstack)))
4293 filelocStack_printIncludes (gc.locstack);
4299 g_currentloc = fileloc_create (fid, lineno, 1);
4300 gc.inheader = fileId_isHeader (currentFile ());
4302 context_enterFileAux ();
4306 void context_enterIterDef (/*@observer@*/ uentry le)
4308 context_enterMacro (le);
4309 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4310 gc.kind = CX_ITERDEF;
4313 void context_enterIterEnd (/*@observer@*/ uentry le)
4315 context_enterMacro (le);
4316 gc.kind = CX_ITEREND;
4320 context_destroyMod (void)
4321 /*@globals killed gc@*/
4325 ctype_destroyMod ();
4332 fileTable_free (gc.ftab);
4333 gc.ftab = fileTable_undefined;
4335 filelocStack_free (gc.locstack);
4338 macrocache_free (gc.mc);
4340 /* evans 2002-07-12: not reported because of reldef */
4341 for (i = 0; i < gc.nmods; i++)
4343 cstring_free (gc.moduleaccess[i].file);
4346 sfree (gc.moduleaccess);
4349 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4350 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4353 sRefSetList_free (gc.modrecs);
4355 flagMarkerList_free (gc.markers);
4357 messageLog_free (gc.msgLog);
4359 clauseStack_free (gc.clauses);
4362 cstring_free (gc.msgAnnote);
4363 globSet_free (gc.globs_used);
4364 metaStateTable_free (gc.stateTable);
4365 annotationTable_free (gc.annotTable);
4374 bool context_msgBoolInt (void)
4376 return context_flagOn (FLG_BOOLINT, g_currentloc);
4379 bool context_msgCharInt (void)
4381 return context_flagOn (FLG_CHARINT, g_currentloc);
4384 bool context_msgEnumInt (void)
4386 return context_flagOn (FLG_ENUMINT, g_currentloc);
4389 bool context_msgLongInt (void)
4391 return context_flagOn (FLG_LONGINT, g_currentloc);
4394 bool context_msgShortInt (void)
4396 return context_flagOn (FLG_SHORTINT, g_currentloc);
4399 bool context_msgPointerArith (void)
4401 return context_flagOn (FLG_POINTERARITH, g_currentloc);
4404 bool context_msgStrictOps (void)
4406 return context_flagOn (FLG_STRICTOPS, g_currentloc);
4409 bool context_msgLh (void)
4411 return gc.flags [FLG_DOLH];
4414 void context_pushLoc (void)
4416 fileloc_free (gc.pushloc);
4417 gc.pushloc = gc.saveloc;
4418 gc.saveloc = fileloc_undefined;
4421 void context_popLoc (void)
4423 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4426 bool context_inGlobalScope (void)
4428 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4431 bool context_inInnerScope (void)
4433 return (gc.kind == CX_INNER);
4436 void context_setProtectVars (void)
4438 gc.protectVars = TRUE;
4441 bool context_anyErrors (void)
4443 return (gc.numerrors > 0);
4446 void context_hasError (void)
4449 DPRINTF (("num errors: %d", gc.numerrors));
4452 int context_numErrors (void)
4454 return gc.numerrors;
4457 bool context_neednl (void)
4462 void context_setNeednl (void)
4467 int context_getExpect (void)
4469 return (context_getValue (FLG_EXPECT));
4472 int context_getLCLExpect (void)
4474 return (context_getValue (FLG_LCLEXPECT));
4477 int context_getLimit (void)
4479 return (context_getValue (FLG_LIMIT));
4482 bool context_unlimitedMessages (void)
4484 return (context_getLimit () < 0);
4487 void context_releaseVars (void)
4489 llassert (gc.protectVars);
4490 gc.protectVars = FALSE;
4493 void context_sizeofReleaseVars (void)
4495 /* If there is a nested sizeof, this might not hold:
4496 llassert (gc.protectVars);
4499 gc.protectVars = FALSE;
4502 bool context_inProtectVars (void)
4504 return (gc.protectVars);
4507 void context_hideShowscan (void)
4509 gc.flags[FLG_SHOWSCAN] = FALSE;
4512 void context_unhideShowscan (void)
4514 gc.flags[FLG_SHOWSCAN] = TRUE;
4517 bool context_inHeader (void)
4519 return (gc.inheader);
4522 fileTable context_fileTable (void)
4527 cstring context_tmpdir (void)
4529 return (context_getString (FLG_TMPDIR));
4532 messageLog context_messageLog (void)
4537 bool context_inMacroFunction (void)
4539 return (gc.kind == CX_MACROFCN);
4542 bool context_inMacroConstant (void)
4544 return (gc.kind == CX_MACROCONST);
4547 bool context_inUnknownMacro (void)
4549 return (gc.kind == CX_UNKNOWNMACRO);
4552 void context_setShownFunction (void)
4554 gc.showfunction = FALSE;
4557 bool context_doDump (void)
4559 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4562 bool context_doMerge (void)
4564 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4567 cstring context_getDump (void)
4569 return context_getString (FLG_DUMP);
4572 cstring context_getMerge (void)
4574 return context_getString (FLG_MERGE);
4577 bool context_inLCLLib (void)
4579 return (gc.kind == CX_LCLLIB);
4582 bool context_inImport (void)
4584 return (gc.inimport);
4587 void context_enterImport (void)
4592 void context_leaveImport (void)
4594 gc.inimport = FALSE;
4597 bool context_inMacro (void)
4599 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4600 || gc.kind == CX_UNKNOWNMACRO
4601 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4604 bool context_inIterDef (void)
4606 return (gc.kind == CX_ITERDEF);
4609 bool context_inIterEnd (void)
4611 return (gc.kind == CX_ITEREND);
4614 int context_getLinesProcessed (void)
4616 return (gc.linesprocessed);
4619 int context_getSpecLinesProcessed (void)
4621 return (gc.speclinesprocessed);
4624 void context_processedSpecLine (void)
4626 gc.speclinesprocessed++;
4629 void context_resetSpecLines (void)
4631 gc.speclinesprocessed = 0;
4635 bool context_inGlobalContext (void)
4637 return (gc.kind == CX_GLOBAL);
4640 static void context_quietExitScopes (void)
4643 ** Try to restore the global scope (after an error).
4646 while (!usymtab_inFileScope ())
4648 usymtab_quietExitScope (g_currentloc);
4651 gc.cont.glob = TRUE;
4652 gc.kind = CX_GLOBAL;
4655 void context_checkGlobalScope (void)
4657 if (gc.kind != CX_GLOBAL)
4659 if (context_inMacro ())
4661 ; /* evans 2001-10-14: Okay to be in a macro here! */
4665 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4666 context_quietExitScopes ();
4671 void context_setFileId (fileId s)
4673 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4676 bool context_setBoolName (void)
4678 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4682 cstring context_printBoolName (void)
4684 if (context_setBoolName ())
4686 return context_getBoolName ();
4690 return cstring_makeLiteralTemp ("boolean");
4694 cstring context_getBoolName (void)
4696 return (context_getString (FLG_BOOLTYPE));
4699 cstring context_getFalseName (void)
4701 return (context_getString (FLG_BOOLFALSE));
4704 cstring context_getTrueName (void)
4706 return (context_getString (FLG_BOOLTRUE));
4709 cstring context_getLarchPath (void)
4711 return (context_getString (FLG_LARCHPATH));
4714 cstring context_getLCLImportDir (void)
4716 return (context_getString (FLG_LCLIMPORTDIR));
4719 static void context_setJustPopped (void)
4721 gc.justpopped = TRUE;
4724 void context_clearJustPopped (void)
4726 gc.justpopped = FALSE;
4729 bool context_justPopped (void)
4731 return (gc.justpopped);
4734 void context_setMacroMissingParams (void)
4736 gc.macroMissingParams = TRUE;
4739 void context_resetMacroMissingParams (void)
4741 gc.macroMissingParams = FALSE;
4744 bool context_isMacroMissingParams (void)
4746 return (gc.macroMissingParams);
4749 void context_showFilelocStack (void)
4751 filelocStack_printIncludes (gc.locstack);
4754 metaStateTable context_getMetaStateTable (void)
4756 return gc.stateTable;
4759 metaStateInfo context_lookupMetaStateInfo (cstring key)
4761 return metaStateTable_lookup (gc.stateTable, key);
4764 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4766 annotationInfo ainfo;
4768 ainfo = annotationTable_lookup (gc.annotTable, annot);
4773 void context_addAnnotation (annotationInfo ainfo)
4775 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4779 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4780 annotationInfo_getLoc (ainfo));
4782 annotationInfo_free (ainfo);
4786 annotationTable_insert (gc.annotTable, ainfo);
4790 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4792 if (metaStateTable_contains (gc.stateTable, mname))
4796 message ("Duplicate metastate declaration: %s", mname),
4797 metaStateInfo_getLoc (msinfo));
4798 cstring_free (mname);
4799 metaStateInfo_free (msinfo);
4803 DPRINTF (("Adding meta state: %s", mname));
4804 metaStateTable_insert (gc.stateTable, mname, msinfo);
4808 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4810 if (metaStateTable_size (gc.stateTable) > 0)
4812 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4813 /*@i32 should use smaller value... */
4814 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4816 metaStateTable_elements (gc.stateTable, msname, msi)
4818 mtContextNode context = metaStateInfo_getContext (msi);
4820 if (mtContextNode_matchesRefStrict (context, s))
4822 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4823 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4827 cstring_copy (metaStateInfo_getName (msi)),
4828 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4829 stateInfo_copy (sinfo)));
4833 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4836 end_metaStateTable_elements ;
4838 stateInfo_free (sinfo);
4839 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4844 stateInfo_free (sinfo);
4845 return valueTable_undefined;
4849 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4851 if (metaStateTable_size (gc.stateTable) > 0)
4853 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4854 /*@i32 should use smaller value... */
4856 metaStateTable_elements (gc.stateTable, msname, msi)
4858 /*@i23 only add global...*/
4859 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4860 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4862 valueTable_insert (res,
4863 cstring_copy (metaStateInfo_getName (msi)),
4864 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4865 stateInfo_copy (sinfo)));
4867 end_metaStateTable_elements ;
4869 stateInfo_free (sinfo);
4870 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4875 stateInfo_free (sinfo);
4876 return valueTable_undefined;
4881 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4885 static ctype lastStruct;
4887 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4893 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4899 ** Why is this stuff in context.c?
4902 /*@unused@*/ static int sInfoNum = 0;
4906 /*@unused@*/ uentry ue;
4907 /*@unused@*/ sRef s;
4911 /*@unused@*/ ctype ct;
4912 /*@unused@*/ constraintList inv;
4913 /*@unused@*/ int ngetUe;
4914 /*@unused@*/ struct getUe * t ;
4917 /* unused: static struct sInfo globalStructInfo; */
4919 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4920 stable release of splint. I coomented them out so that they won't break anything
4921 but didn't delete them because they will be fixed and included later
4928 void context_setGlobalStructInfo(ctype ct, constraintList list)
4934 f = ctype_getFields (ct);
4936 if (constraintList_isDefined(list) )
4938 globalStructInfo.ct = ct;
4939 globalStructInfo.inv = list;
4941 globalStructInfo.ngetUe = 0;
4943 /* abstraction violation fix it * /
4944 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4946 globalStructInfo.ngetUe = f->nelements;
4950 uentryList_elements(f, ue)
4952 globalStructInfo.t[i].ue = ue;
4953 globalStructInfo.t[i].s = uentry_getSref(ue);
4954 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4955 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4960 end_uentryList_elements;
4969 bool hasInvariants (ctype ct) /*@* /
4971 if ( ctype_sameName(globalStructInfo.ct, ct) )