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,
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_inOldSytleScope(void)
1880 if (gc.kind == CX_OLDSTYLESCOPE)
1887 context_enterOldStyleScope (void)
1889 gc.kind = CX_OLDSTYLESCOPE;
1890 DPRINTF (("Enter old style scope!"));
1891 usymtab_enterFunctionScope (uentry_undefined);
1895 context_completeOldStyleFunction (uentry e)
1897 llassert (gc.kind == CX_OLDSTYLESCOPE);
1899 gc.kind = CX_FUNCTION;
1902 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1904 if (uentry_hasAccessType (e))
1906 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1914 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1915 typeIdSet_unparse (gc.acct)));
1917 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1919 if (!globSet_isEmpty (uentry_getGlobs (e)))
1921 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1922 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1925 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1927 gc.globs = uentry_getGlobs (e);
1928 globSet_clear (gc.globs_used);
1930 gc.mods = uentry_getMods (e);
1932 if (!sRefSet_isEmpty (gc.mods))
1934 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1935 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1938 sRef_enterFunctionScope ();
1941 static bool context_checkStrictGlobals (void)
1943 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1946 static bool context_hasGlobs (void)
1948 if (context_inFunctionLike ())
1950 return (uentry_hasGlobs (gc.cont.fcn));
1958 static bool context_checkCheckedGlobals (void)
1960 return (context_getFlag (FLG_GLOBALS)
1961 && (context_getFlag (FLG_GLOBUNSPEC)
1962 || context_hasGlobs ()));
1965 static bool context_checkUnknownGlobals (void)
1967 /* should be uentry_hasGlobs ? */
1969 return (context_getFlag (FLG_ALLGLOBALS)
1970 && (context_getFlag (FLG_GLOBUNSPEC)
1971 || context_hasGlobs ()));
1974 static bool context_checkUncheckedGlobals (void)
1980 context_checkExport (uentry e)
1982 if (!gc.anyExports) return FALSE;
1984 if (uentry_isFunction (e)
1985 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1987 return context_maybeSet (FLG_EXPORTFCN);
1989 else if (uentry_isExpandedMacro (e))
1991 return context_maybeSet (FLG_EXPORTMACRO);
1993 else if (uentry_isVariable (e))
1995 return context_maybeSet (FLG_EXPORTVAR);
1997 else if (uentry_isEitherConstant (e))
1999 return context_maybeSet (FLG_EXPORTCONST);
2001 else if (uentry_isIter (e) || uentry_isEndIter (e))
2003 return context_maybeSet (FLG_EXPORTITER);
2005 else if (uentry_isDatatype (e))
2007 return context_maybeSet (FLG_EXPORTTYPE);
2016 context_checkGlobUse (uentry glob)
2019 if (uentry_isCheckedStrict (glob))
2021 return context_checkStrictGlobals ();
2023 else if (uentry_isChecked (glob))
2025 return context_checkCheckedGlobals ();
2027 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2029 return context_checkUnknownGlobals ();
2033 llassert (uentry_isUnchecked (glob));
2035 return context_checkUncheckedGlobals ();
2040 context_checkAliasGlob (uentry glob)
2042 if (uentry_isCheckedStrict (glob))
2044 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2046 else if (uentry_isChecked (glob))
2048 return gc.flags[FLG_CHECKEDGLOBALIAS];
2050 else if (uentry_isCheckMod (glob))
2052 return gc.flags[FLG_CHECKMODGLOBALIAS];
2056 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2058 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2062 bool context_checkInternalUse (void)
2064 if (context_hasGlobs ())
2066 return (gc.flags[FLG_INTERNALGLOBS]);
2070 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2075 context_checkGlobMod (sRef el)
2077 uentry ue = sRef_getUentry (el);
2079 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2081 if (uentry_isCheckedModify (ue)
2082 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2084 if (context_hasMods ())
2086 return (gc.flags[FLG_MODGLOBS]);
2090 if (uentry_isCheckedStrict (ue))
2092 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2096 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2102 if (context_hasMods ())
2104 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2114 context_usedGlobal (/*@exposed@*/ sRef el)
2116 if (!globSet_member (gc.globs_used, el))
2119 ** The first time a global is used in a function, we need
2120 ** to clear the derived sRefs, since they were set for the
2121 ** previous function.
2124 sRef_clearDerived (el);
2125 gc.globs_used = globSet_insert (gc.globs_used, el);
2129 /*@observer@*/ sRefSet
2130 context_modList (void)
2136 context_globAccess (sRef s)
2138 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2139 return (globSet_member (gc.globs, s));
2143 context_hasAccess (typeId t)
2145 if (context_inFunctionLike ())
2147 DPRINTF (("Access %d / %s",
2148 t, typeIdSet_unparse (gc.acct)));
2149 return (typeIdSet_member (gc.acct, t));
2153 return (context_hasFileAccess (t));
2158 context_hasFileAccess (typeId t)
2160 return (typeIdSet_member (gc.facct, t));
2164 context_unparseAccess (void)
2166 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2167 typeIdSet_unparse (gc.facct)));
2171 context_unparseClauses (void)
2173 return (clauseStack_unparse (gc.clauses));
2177 context_couldHaveAccess (typeId t)
2179 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2181 return (typeIdSet_member (gc.acct, t));
2185 return (typeIdSet_member (gc.facct, t));
2190 context_getRetType (void)
2192 ctype f = ctype_undefined;
2194 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2196 f = uentry_getType (gc.cont.fcn);
2198 else if (gc.kind == CX_UNKNOWNMACRO)
2200 return ctype_unknown;
2204 llcontbuglit ("context_getRetType: not in a function context");
2205 return ctype_unknown;
2208 if (!ctype_isFunction (f))
2210 if (ctype_isKnown (f))
2212 llbuglit ("context_getRetType: not a function");
2215 return ctype_unknown;
2217 return (ctype_getReturnType (f));
2221 context_hasMods (void)
2223 if (context_inFunctionLike ())
2225 return (uentry_hasMods (gc.cont.fcn));
2234 context_exitAllClauses (void)
2236 while (!clauseStack_isEmpty (gc.clauses))
2238 clause el = clauseStack_top (gc.clauses);
2241 if (clause_isNone (el))
2243 usymtab_quietExitScope (g_currentloc);
2244 clauseStack_pop (gc.clauses);
2248 context_exitClausePlain ();
2252 clauseStack_clear (gc.clauses);
2253 gc.inclause = NOCLAUSE;
2257 context_exitAllClausesQuiet (void)
2259 while (!clauseStack_isEmpty (gc.clauses))
2261 clause el = clauseStack_top (gc.clauses);
2264 usymtab_quietExitScope (g_currentloc);
2265 clauseStack_pop (gc.clauses);
2268 clauseStack_clear (gc.clauses);
2269 gc.inclause = NOCLAUSE;
2273 void context_exitClauseSimp (void)
2276 context_setJustPopped ();
2277 clauseStack_pop (gc.clauses);
2278 gc.inclause = topClause (gc.clauses);
2282 void context_exitCaseClause (void)
2284 context_setJustPopped ();
2285 usymtab_popCaseBranch ();
2286 clauseStack_pop (gc.clauses);
2287 gc.inclause = topClause (gc.clauses);
2291 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2293 context_setJustPopped ();
2294 /*@i32 was makeAlt */
2295 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2296 clauseStack_pop (gc.clauses);
2297 gc.inclause = topClause (gc.clauses);
2300 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2302 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2304 if (gc.inclause != TRUECLAUSE)
2306 llparseerror (cstring_makeLiteral
2307 ("Likely parse error. Conditional clauses are inconsistent."));
2311 context_setJustPopped ();
2312 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2313 clauseStack_pop (gc.clauses);
2314 gc.inclause = topClause (gc.clauses);
2317 void context_exitIterClause (exprNode body)
2319 llassert (gc.inclause == ITERCLAUSE);
2321 context_setJustPopped ();
2323 if (context_getFlag (FLG_ITERLOOPEXEC))
2325 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2329 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2332 clauseStack_pop (gc.clauses);
2333 gc.inclause = topClause (gc.clauses);
2336 static void context_popCase (void) {
2338 ** If we are exiting an outer clause, sometimes still in a switch case.
2352 DPRINTF (("Popping case clause: %s",
2353 clauseStack_unparse (gc.clauses)));
2355 if (gc.inclause == CASECLAUSE) {
2356 context_exitCaseClause ();
2360 void context_exitWhileClause (exprNode pred, exprNode body)
2362 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2366 if (gc.inclause != WHILECLAUSE) {
2367 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2368 clauseStack_unparse (gc.clauses)));
2371 llassert (gc.inclause == WHILECLAUSE);
2373 context_setJustPopped ();
2377 ** predicate must be false after while loop (unless there are breaks)
2380 if (context_getFlag (FLG_WHILELOOPEXEC))
2382 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2386 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2390 usymtab_addGuards (invGuards);
2391 guardSet_free (invGuards);
2393 clauseStack_pop (gc.clauses);
2394 gc.inclause = topClause (gc.clauses);
2397 void context_exitDoWhileClause (exprNode pred)
2399 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2401 if (gc.inclause == CASECLAUSE) {
2402 /* handle Duff's device */
2403 clauseStack_pop (gc.clauses);
2404 gc.inclause = topClause (gc.clauses);
2407 llassert (gc.inclause == DOWHILECLAUSE);
2409 context_setJustPopped ();
2412 usymtab_addGuards (invGuards);
2413 guardSet_free (invGuards);
2415 clauseStack_pop (gc.clauses);
2416 gc.inclause = topClause (gc.clauses);
2419 void context_exitForClause (exprNode forPred, exprNode body)
2421 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2423 llassert (gc.inclause == FORCLAUSE);
2424 context_setJustPopped ();
2426 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2429 ** Predicate must be false after for loop (unless there are breaks)
2432 if (context_getFlag (FLG_FORLOOPEXEC))
2434 DPRINTF (("Here: for loop exec"));
2435 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2439 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2440 && exprNode_loopMustExec (forPred))
2442 DPRINTF (("Here: loop must exec"));
2443 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2447 DPRINTF (("Pop true branch:"));
2448 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2452 usymtab_addGuards (invGuards);
2453 guardSet_free (invGuards);
2454 clauseStack_pop (gc.clauses);
2455 gc.inclause = topClause (gc.clauses);
2458 static void context_exitClausePlain (void)
2460 llassert (gc.inclause != NOCLAUSE);
2462 if (gc.inclause == FALSECLAUSE)
2464 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2468 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2472 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2474 context_setJustPopped ();
2476 if (gc.inclause == FALSECLAUSE)
2478 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2480 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2482 clauseStack_pop (gc.clauses);
2483 gc.inclause = topClause (gc.clauses);
2487 context_exitTrueClause (pred, tbranch);
2492 context_returnFunction (void)
2494 usymtab_checkFinalScope (TRUE);
2498 context_exitFunction (void)
2500 DPRINTF (("Exit function: %s", context_unparse ()));
2502 if (!context_inFunction () && !context_inMacroConstant ()
2503 && !context_inUnknownMacro ()
2504 && !context_inIterDef () && !context_inIterEnd ())
2507 ** not a bug because of parse errors
2514 if (context_inMacro () && usymtab_inFunctionScope ())
2516 usymtab_exitScope (exprNode_undefined);
2519 if (uentry_hasGlobs (gc.cont.fcn))
2521 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2525 if (uentry_hasMods (gc.cont.fcn))
2527 if (context_getFlag (FLG_MUSTMOD))
2529 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2533 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2536 ** clear file static modifies
2539 /* do this first to get unused error messages */
2541 usymtab_exitScope (exprNode_undefined);
2542 sRef_exitFunctionScope ();
2544 gc.showfunction = FALSE;
2545 gc.kind = CX_GLOBAL;
2546 gc.cont.glob = TRUE;
2548 gc.globs = globSet_new ();
2549 globSet_clear (gc.globs_used);
2550 gc.mods = sRefSet_new ();
2553 llassert (clauseStack_isEmpty (gc.clauses));
2554 llassert (gc.inclause == NOCLAUSE);
2555 DPRINTF (("After exit function: %s", context_unparse ()));
2559 context_quietExitFunction (void)
2561 while (gc.kind == CX_INNER)
2563 context_exitInnerPlain ();
2566 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2567 && !context_inIterDef () && !context_inIterEnd ())
2572 usymtab_quietExitScope (g_currentloc);
2574 gc.showfunction = FALSE;
2575 gc.kind = CX_GLOBAL;
2576 gc.cont.glob = TRUE;
2578 gc.globs = globSet_new ();
2579 globSet_clear (gc.globs_used);
2580 gc.mods = sRefSet_new ();
2582 sRef_exitFunctionScope ();
2586 /*@observer@*/ uentryList
2587 context_getParams (void)
2589 if (context_inFunctionLike ())
2591 return (uentry_getParams (gc.cont.fcn));
2595 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2596 return uentryList_undefined;
2600 /*@observer@*/ globSet
2601 context_getUsedGlobs (void)
2603 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2604 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2606 return (gc.globs_used);
2610 context_moduleName ()
2612 return (fileloc_getBase (g_currentloc));
2615 /*@observer@*/ globSet
2616 context_getGlobs (void)
2618 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2619 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2625 context_addBoolAccess (void)
2627 cstring bname = context_getString (FLG_BOOLTYPE);
2628 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2630 addModuleAccess (cstring_copy (bname), boolt);
2632 /* for sys/types (perhaps, this is bogus!) */
2633 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2638 context_canAccessBool (void)
2645 static typeId boolType = typeId_invalid;
2647 if (typeId_isInvalid (boolType))
2649 boolType = usymtab_getTypeId (context_getBoolName ());
2652 if (typeId_isInvalid (boolType)) {
2655 return (typeIdSet_member (gc.acct, boolType));
2660 /* evs 2000-07-25: old version - replaced */
2663 context_boolImplementationType () {
2664 /* For now, this is bogus! */
2669 context_canAccessBool (void)
2671 static typeId boolType = typeId_invalid;
2673 if (typeId_isInvalid (boolType))
2675 boolType = usymtab_getTypeId (context_getBoolName ());
2678 if (!typeId_isInvalid (boolType))
2680 return context_hasAccess (boolType);
2691 context_setMessageAnnote (/*@only@*/ cstring s)
2693 llassert (cstring_isUndefined (gc.msgAnnote));
2698 context_hasMessageAnnote (void)
2700 return (cstring_isDefined (gc.msgAnnote));
2704 context_clearMessageAnnote (void)
2706 if (cstring_isDefined (gc.msgAnnote))
2708 cstring_free (gc.msgAnnote);
2709 gc.msgAnnote = cstring_undefined;
2714 context_getMessageAnnote (void)
2716 cstring st = gc.msgAnnote;
2718 gc.msgAnnote = cstring_undefined;
2723 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2725 llassert (sRef_isInvalid (gc.aliasAnnote));
2726 llassert (!sRef_sameName (s, t));
2728 gc.aliasAnnoteAls = t;
2732 context_hasAliasAnnote (void)
2734 return (sRef_isValid (gc.aliasAnnote));
2738 context_clearAliasAnnote (void)
2740 gc.aliasAnnote = sRef_undefined;
2744 context_getAliasAnnote (void)
2746 sRef ret = gc.aliasAnnote;
2747 sRef als = gc.aliasAnnoteAls;
2749 llassert (sRef_isValid (ret) && sRef_isValid (als));
2751 gc.aliasAnnote = sRef_undefined;
2752 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2756 context_recordFileModifies (sRefSet mods)
2758 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2762 context_recordFileGlobals (globSet mods)
2764 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2765 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2769 context_setCommentMarkerChar (char c)
2771 llassert (c != '\0');
2773 context_setValue (FLG_COMMENTCHAR, (int) c);
2777 context_getCommentMarkerChar (void)
2779 return ((char) context_getValue (FLG_COMMENTCHAR));
2783 context_setValue (flagcode flag, int val)
2785 int index = flagcode_valueIndex (flag);
2787 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2795 llerror_flagWarning (message ("Value for %s must be a positive "
2796 "number (given %d)",
2797 flagcode_unparse (flag), val));
2800 if (flag == FLG_LINELEN && val < MINLINELEN)
2802 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2803 flagcode_unparse (flag),
2809 case FLG_INCLUDENEST:
2810 case FLG_CONTROLNESTDEPTH:
2811 case FLG_STRINGLITERALLEN:
2812 case FLG_NUMSTRUCTFIELDS:
2813 case FLG_NUMENUMMEMBERS:
2814 case FLG_INDENTSPACES:
2817 llerror_flagWarning (message ("Value for %s must be a non-negative "
2818 "number (given %d)",
2819 flagcode_unparse (flag), val));
2828 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2829 gc.values[index] = val;
2833 context_setValueAndFlag (flagcode flag, int val)
2835 gc.flags[flag] = TRUE;
2836 context_setValue (flag, val);
2840 context_getValue (flagcode flag)
2842 int index = flagcode_valueIndex (flag);
2844 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2845 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2846 return (gc.values[index]);
2850 context_getCounter (flagcode flag)
2852 int index = flagcode_valueIndex (flag);
2854 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2855 return (gc.counters[index]);
2859 context_incCounter (flagcode flag)
2861 int index = flagcode_valueIndex (flag);
2863 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2865 gc.counters[index]++;
2869 context_decCounter (flagcode flag)
2871 int index = flagcode_valueIndex (flag);
2873 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2874 gc.counters[index]--;
2877 bool context_showFunction (void)
2879 return (gc.showfunction);
2883 context_setString (flagcode flag, cstring val)
2885 int index = flagcode_stringIndex (flag);
2887 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2889 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2895 usymtab_supGlobalEntry
2896 (uentry_makeConstantValue (val, ctype_bool,
2897 fileloc_getBuiltin (), TRUE,
2898 multiVal_makeInt (1)));
2901 usymtab_supGlobalEntry
2902 (uentry_makeConstantValue (val, ctype_bool,
2903 fileloc_getBuiltin (), FALSE,
2904 multiVal_makeInt (0)));
2907 case FLG_MESSAGESTREAM:
2908 case FLG_WARNINGSTREAM:
2909 case FLG_ERRORSTREAM:
2911 if (cstring_isDefined (val))
2915 if (osd_fileExists (val))
2917 if (context_getFlag (FLG_STREAMOVERWRITE))
2919 llfatalerror (message
2920 ("Output stream file %s would overwrite existing file. "
2921 "Use -streamoverwrite if you want to allow this.",
2926 fstream = fopen (cstring_toCharsSafe (val), "w");
2928 if (fstream == NULL)
2930 llfatalerror (message ("Unable to open output stream file %s for writing",
2935 ** This ensures fstream will be closed on exit.
2938 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2942 case FLG_MESSAGESTREAM:
2943 g_messagestream = fstream;
2944 /*@innerbreak@*/ break;
2945 case FLG_WARNINGSTREAM:
2946 g_warningstream = fstream;
2947 /*@innerbreak@*/ break;
2948 case FLG_ERRORSTREAM:
2949 g_errorstream = fstream;
2950 /*@innerbreak@*/ break;
2953 /*@-statetransfer@*/
2954 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2957 case FLG_SYSTEMDIRS:
2959 llassert (cstring_isDefined (val));
2961 if (cstring_firstChar (val) == '\"')
2964 cstring tval = cstring_copy (cstring_suffix (val, 1));
2966 if (cstring_lastChar (tval) != '\"')
2968 int n = cstring_length (tval) - 1;
2970 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2975 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2978 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2982 cstring otval = tval;
2983 tval = cstring_prefix (tval, size_fromInt (n));
2984 cstring_free (otval);
2988 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2989 DPRINTF (("val = %s", val));
2990 cstring_free (tval);
2991 cstring_free (oval);
2998 llassert (cstring_isDefined (val));
3000 if (cstring_length (val) == 0)
3003 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
3005 else if (cstring_lastChar (val) != CONNECTCHAR)
3007 val = cstring_appendChar (val, CONNECTCHAR);
3017 ; /* Okay not handle everything in this switch */
3019 /*@i523@*/ } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */
3021 if (cstring_length (val) >= 1
3022 && cstring_firstChar (val) == '\"')
3024 llerror_flagWarning (message
3025 ("Setting %s to string beginning with \". You probably "
3026 "don't meant to have the \"'s.",
3027 flagcode_unparse (flag)));
3030 gc.strings[index] = val;
3033 static /*@exposed@*/ cstring
3034 context_exposeString (flagcode flag)
3036 int index = flagcode_stringIndex (flag);
3038 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3039 return (gc.strings[index]);
3043 context_getString (flagcode flag)
3045 return (context_exposeString (flag));
3049 context_resetErrors (void)
3054 void context_initMod (void)
3055 /*@globals undef gc; @*/
3057 gc.kind = CX_GLOBAL;
3059 gc.savekind = CX_ERROR;
3060 gc.savecont.glob = FALSE;
3062 gc.instandardlib = FALSE;
3065 gc.linesprocessed = 0;
3066 gc.speclinesprocessed = 0;
3067 gc.insuppressregion = FALSE;
3068 gc.macroMissingParams = FALSE;
3069 gc.preprocessing = FALSE;
3070 gc.incommandline = FALSE;
3071 gc.mc = macrocache_create ();
3073 gc.maxmods = DEFAULTMAXMODS;
3074 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3076 gc.library = FLG_ANSILIB;
3078 gc.locstack = filelocStack_new ();
3079 gc.modrecs = sRefSetList_undefined;
3080 gc.anyExports = FALSE;
3082 gc.ftab = fileTable_create ();
3083 gc.msgLog = messageLog_new ();
3084 gc.inimport = FALSE;
3085 gc.inDerivedFile = FALSE;
3086 gc.inheader = FALSE;
3087 gc.markers = flagMarkerList_new ();
3088 gc.cont.glob = TRUE;
3089 gc.showfunction = FALSE;
3090 gc.msgAnnote = cstring_undefined;
3091 gc.aliasAnnote = sRef_undefined;
3092 gc.aliasAnnoteAls = sRef_undefined;
3093 gc.boolType = ctype_bool;
3094 gc.mods = sRefSet_new ();
3096 gc.saveloc = fileloc_undefined;
3098 gc.inmacrocache = FALSE;
3099 gc.inclause = NOCLAUSE;
3100 gc.clauses = clauseStack_new ();
3101 gc.globs = globSet_new ();
3102 gc.nacct = typeIdSet_emptySet ();
3103 gc.acct = typeIdSet_emptySet ();
3104 gc.facct = typeIdSet_emptySet ();
3105 gc.savedFlags = FALSE;
3106 gc.pushloc = fileloc_undefined;
3107 gc.protectVars = FALSE;
3108 gc.justpopped = FALSE;
3109 gc.isNullGuarded = NO;
3110 gc.globs_used = globSet_undefined;
3114 gc.setGlobally[code] = FALSE;
3115 gc.setLocally[code] = FALSE;
3120 context_resetAllFlags ();
3122 assertSet (gc.flags); /* Can't use global in defines */
3123 assertSet (gc.saveflags);
3124 assertSet (gc.values);
3125 assertSet (gc.strings);
3127 conext_resetAllCounters ();
3128 assertSet (gc.counters);
3130 context_setMode (DEFAULT_MODE);
3132 gc.stateTable = metaStateTable_create ();
3133 gc.annotTable = annotationTable_create ();
3135 gc.inFunctionHeader = FALSE;
3137 DPRINTF (("Annotations: \n%s",
3138 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3139 DPRINTF (("State: \n%s",
3140 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3145 context_typeofZero (void)
3147 ctype ct = ctype_int;
3149 if (context_getFlag (FLG_ZEROPTR))
3151 ct = ctype_makeConj (ct, ctype_voidPointer);
3154 if (context_getFlag (FLG_ZEROBOOL)) {
3155 ct = ctype_makeConj (ct, ctype_bool);
3162 context_typeofOne (void)
3164 ctype ct = ctype_int;
3166 /* 1 is on longer a bool (was before 2.4)
3167 if (!context_getFlag (FLG_ABSTRACTBOOL))
3169 ct = ctype_makeConj (ct, ctype_bool);
3177 context_unparse (void)
3184 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3187 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3190 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3193 s = message ("Inner Context [%d] : %q",
3195 fileloc_unparse (g_currentloc));
3198 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3199 uentry_unparse (gc.cont.fcn),
3200 fileloc_unparse (g_currentloc),
3201 typeIdSet_unparse (gc.acct),
3202 sRefSet_unparse (gc.mods));
3205 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3207 case CX_UNKNOWNMACRO:
3208 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3211 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3214 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3217 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3219 case CX_FCNDECLARATION:
3220 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3223 s = message ("Un-unparseable context: %d", (int) gc.kind);
3227 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3232 context_currentFunctionType (void)
3234 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3236 return (uentry_getType (gc.cont.fcn));
3238 else if (gc.kind == CX_INNER)
3240 llcontbuglit ("context_currentFunctionType: inner context");
3241 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3242 return (context_currentFunctionType ());
3246 llcontbuglit ("context_currentFunctionType: not in function");
3247 return (ctype_undefined);
3252 context_enterInnerContext (void)
3254 if (context_getFlag (FLG_GRAMMAR))
3256 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3259 if (gc.kind == CX_GLOBAL)
3264 else if (gc.kind == CX_INNER)
3273 usymtab_enterScope ();
3274 pushClause (NOCLAUSE);
3278 context_exitInnerPlain (void) /*@modifies gc;@*/
3280 context_exitInner (exprNode_undefined);
3284 context_exitInner (exprNode exp)
3286 if (context_getFlag (FLG_GRAMMAR))
3288 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3291 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3292 ("inclause = %s", clause_nameTaken (gc.inclause)));
3294 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3295 gc.inclause = topClause (gc.clauses);
3297 if (gc.kind == CX_INNER)
3299 if (--gc.cont.cdepth == 0)
3301 gc.kind = CX_GLOBAL;
3302 gc.cont.glob = TRUE;
3307 if (gc.kind == CX_GLOBAL)
3309 llcontbuglit ("Attempt to exit global context");
3314 usymtab_exitScope (exp);
3319 context_enterStructInnerContext (void)
3321 if (context_getFlag (FLG_GRAMMAR))
3323 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3326 if (gc.kind == CX_GLOBAL)
3331 else if (gc.kind == CX_INNER)
3340 usymtab_enterScope ();
3342 if (context_getFlag (FLG_GRAMMAR))
3344 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3349 context_exitStructInnerContext (void)
3351 if (context_getFlag (FLG_GRAMMAR))
3353 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3356 if (gc.kind == CX_INNER)
3358 if (gc.cont.cdepth <= 0)
3360 llcontbuglit ("Attempt to exit inner context with no depth");
3361 gc.kind = CX_GLOBAL;
3362 gc.cont.glob = TRUE;
3368 if (gc.cont.cdepth == 0)
3370 gc.kind = CX_GLOBAL;
3371 gc.cont.glob = TRUE;
3377 if (gc.kind == CX_GLOBAL)
3379 llcontbuglit ("Attempt to exit global context");
3384 usymtab_exitScope (exprNode_undefined);
3386 if (context_getFlag (FLG_GRAMMAR))
3388 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3393 context_exitInnerSafe (void)
3395 if (context_getFlag (FLG_GRAMMAR))
3397 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3400 if (gc.kind == CX_INNER)
3402 if (--gc.cont.cdepth <= 0)
3407 else if (gc.kind == CX_GLOBAL)
3409 llcontbuglit ("Attempt to exit global context");
3414 if (usymtab_inDeepScope ())
3416 usymtab_exitScope (exprNode_undefined);
3422 void setModuleAccess (void)
3424 gc.facct = typeIdSet_emptySet ();
3426 if (fileId_isValid (currentFile ()))
3428 cstring baseName = fileloc_getBase (g_currentloc);
3430 if (context_getFlag (FLG_ACCESSFILE))
3432 if (usymtab_existsType (baseName))
3434 gc.facct = typeIdSet_insert (gc.facct,
3435 usymtab_getTypeId (baseName));
3443 if (context_getFlag (FLG_ACCESSMODULE))
3446 bool hasaccess = FALSE;
3448 for (i = 0; i < gc.nmods; i++)
3450 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3452 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3461 gc.inheader = fileId_isHeader (currentFile ());
3465 llcontbuglit ("Current file not defined\n");
3466 gc.facct = typeIdSet_emptySet ();
3468 gc.inheader = FALSE;
3471 /* 17 Jan 1995: forgot to clear nacct */
3473 gc.nacct = typeIdSet_emptySet ();
3477 context_enterFileAux (void)
3483 context_enterFile (void)
3485 context_enterFileAux ();
3486 usymtab_enterFile ();
3490 context_enterMacroFile (void)
3492 context_enterFileAux ();
3496 context_inFunction (void)
3498 kcontext ck = gc.kind;
3500 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3504 context_inFunctionLike (void)
3506 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3507 || gc.kind == CX_FCNDECLARATION
3508 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3512 context_inRealFunction (void)
3514 kcontext ck = gc.kind;
3516 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3520 context_processAllMacros (void)
3522 usymtab_enterFile ();
3524 gc.inmacrocache = TRUE;
3525 macrocache_processUndefinedElements (gc.mc);
3527 usymtab_exitFile ();
3529 gc.inmacrocache = FALSE;
3530 macrocache_finalize ();
3534 ** this happens once at the end of each C file
3536 ** check each Macro that was defined in current file.c or current file.h
3541 context_processMacros (void)
3543 if (fileId_isValid (currentFile ()))
3546 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3548 gc.inmacrocache = TRUE;
3550 DPRINTF (("Processing macros: %s", cbase));
3551 lastfl = macrocache_processFileElements (gc.mc, cbase);
3552 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3554 cstring_free (cbase);
3556 if (fileloc_isDefined (lastfl))
3558 g_currentloc = fileloc_update (g_currentloc, lastfl);
3562 gc.inmacrocache = FALSE;
3567 context_processingMacros (void)
3569 return (gc.inmacrocache);
3573 context_exitCFile (void)
3575 if (gc.kind != CX_GLOBAL)
3578 (cstring_makeLiteral ("File ended outside global scope"));
3581 if (gc.insuppressregion)
3583 /* gack...don't reverse the order of these lines! ;-> */
3584 gc.insuppressregion = FALSE;
3585 llerrorlit (FLG_SYNTAX,
3586 "File ended in ignore errors region, "
3587 "possible missing /*@end*/");
3590 /* fix up parse errors */
3592 while (!usymtab_inFileScope ())
3594 usymtab_quietExitScope (g_currentloc);
3598 ** Clear the file-specific modifies information.
3601 sRefSetList_elements (gc.modrecs, mods)
3603 sRefSet_clearStatics (mods);
3604 } end_sRefSetList_elements ;
3606 sRefSetList_clear (gc.modrecs);
3608 context_processMacros ();
3611 usymtab_exitFile ();
3613 gc.inDerivedFile = FALSE;
3614 filelocStack_clear (gc.locstack);
3616 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3618 gc.cont.glob = TRUE;
3622 context_restoreFlagSettings ();
3623 gc.savedFlags = FALSE;
3627 DPRINTF (("After exiting file: "));
3628 usymtab_printAll ();
3633 context_exitMacroCache (void)
3635 if (gc.kind != CX_GLOBAL)
3637 if (context_inMacro ())
3638 /* this is okay, file could end without newline in macro */
3640 DPRINTF (("Still in macro: %s",
3641 context_unparse ()));
3642 context_exitFunction ();
3646 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3647 context_unparse ()));
3648 gc.kind = CX_GLOBAL;
3653 ** no longer valid here
3654 ** if (gc.insuppressregion)
3656 ** gc.insuppressregion = FALSE;
3657 ** llerror ("File ended in ignore errors region, possible missing @");
3661 gc.cont.glob = TRUE;
3665 context_saveLocation (void)
3667 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3668 fileloc_free (gc.saveloc);
3669 gc.saveloc = fileloc_copy (g_currentloc);
3673 context_getSaveLocation (void)
3675 fileloc fl = gc.saveloc;
3676 gc.saveloc = fileloc_undefined;
3680 /*@observer@*/ cstring
3681 context_inFunctionName (void)
3683 if (gc.kind == CX_FUNCTION
3684 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3685 || gc.kind == CX_MACROCONST
3686 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3688 return (uentry_rawName (gc.cont.fcn));
3692 llcontbuglit ("context_inFunctionName: not in function");
3693 return (cstring_undefined);
3698 context_userSetFlag (flagcode f, bool b)
3700 DPRINTF (("set flag: %s / %s",
3701 flagcode_unparse (f),
3702 bool_unparse (context_getFlag (f))));
3704 if (f == FLG_NEVERINCLUDE && b)
3706 if (gc.flags[FLG_EXPORTHEADER])
3709 (cstring_makeLiteral
3710 ("Setting +neverinclude after +exportheader. "
3711 "Turning off exportheader, since headers are not checked "
3712 "when +neverinclude is used."));
3714 gc.flags[FLG_EXPORTHEADER] = FALSE;
3719 if (f == FLG_EXPORTHEADER && b)
3721 if (gc.flags[FLG_NEVERINCLUDE])
3724 (cstring_makeLiteral
3725 ("Setting +exportheader after +neverinclude. "
3726 "Not setting exportheader, since headers are not checked "
3727 "when +neverinclude is used."));
3728 gc.flags[FLG_EXPORTHEADER] = FALSE;
3734 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3736 bool lastsetting = context_getFlag (f);
3738 if (bool_equal (lastsetting, b)
3739 && !flagcode_isSpecialFlag (f)
3740 && !flagcode_isIdemFlag (f)
3741 && !flagcode_hasArgument (f))
3744 (message ("Setting %s%s redundant with current value",
3745 cstring_makeLiteralTemp (b ? "+" : "-"),
3746 flagcode_unparse (f)));
3750 if (flagcode_isWarnUseFlag (f) && b)
3752 if (!context_getFlag (FLG_WARNUSE))
3755 (message ("Flag +%s is canceled by -warnuse",
3756 flagcode_unparse (f)));
3761 if (flagcode_isLibraryFlag (f))
3763 if (gc.library != FLG_ANSILIB
3767 (message ("Selecting library %s after library %s was "
3768 "selected (only one library may be used)",
3769 flagcode_unparse (f),
3770 flagcode_unparse (gc.library)));
3773 if (f == FLG_UNIXLIB)
3775 if (context_getFlag (FLG_WARNUNIXLIB))
3778 (cstring_makeLiteral
3779 ("Selecting unix library. Unix library is "
3780 "ad hoc addition to POSIX library. Recommend "
3781 "use +posixlib to select POSIX library instead. "
3782 "Use -warnunixlib to suppress this message."));
3789 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3793 ("Setting +%s will not produce warnings with -namechecks. "
3794 "Must set +namechecks also.",
3795 flagcode_unparse (f)));
3798 gc.setGlobally[f] = TRUE;
3799 context_setFlag (f, b, g_currentloc);
3803 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3807 context_saveFlagSettings ();
3810 if (ynm_isOff (set))
3812 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3814 else if (ynm_isOn (set))
3816 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3817 gc.setLocally[f] = TRUE;
3821 context_restoreFlag (f, loc);
3826 context_restoreFlag (flagcode f, fileloc loc)
3832 message ("Attempt to restore flag %s when no file scope flags "
3834 flagcode_unparse (f)),
3839 context_addFlagMarker (f, MAYBE, loc);
3840 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3846 context_setFlag (flagcode f, bool b, fileloc loc)
3848 context_setFlagAux (f, b, FALSE, FALSE, loc);
3852 context_setFlagTemp (flagcode f, bool b)
3854 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3859 # define DOSET(ff,b) \
3860 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3861 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3862 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3863 gc.flags[ff] = b; } while (FALSE)
3866 context_setFlagAux (flagcode f, bool b, bool inFile,
3867 /*@unused@*/ bool isRestore, fileloc loc)
3869 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3872 ** Removed test for special flags.
3875 if (flagcode_isIdemFlag (f))
3884 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3886 if (b) /* Turing higher level on, turns on all lower levels */
3890 case FLG_ITS4MOSTRISKY:
3891 DOSET (FLG_ITS4VERYRISKY, b);
3893 case FLG_ITS4VERYRISKY:
3894 DOSET (FLG_ITS4RISKY, b);
3897 DOSET (FLG_ITS4MODERATERISK, b);
3899 case FLG_ITS4MODERATERISK:
3900 DOSET (FLG_ITS4LOWRISK, b);
3902 case FLG_ITS4LOWRISK:
3907 else /* Turning level off, turns off all higher levels */
3911 case FLG_ITS4LOWRISK:
3912 DOSET (FLG_ITS4MODERATERISK, b);
3914 case FLG_ITS4MODERATERISK:
3915 DOSET (FLG_ITS4RISKY, b);
3918 DOSET (FLG_ITS4VERYRISKY, b);
3920 case FLG_ITS4VERYRISKY:
3921 DOSET (FLG_ITS4MOSTRISKY, b);
3923 case FLG_ITS4MOSTRISKY:
3932 case FLG_MESSAGESTREAMSTDOUT:
3933 g_messagestream = stdout;
3935 case FLG_MESSAGESTREAMSTDERR:
3936 g_messagestream = stderr;
3938 case FLG_WARNINGSTREAMSTDOUT:
3939 g_warningstream = stdout;
3941 case FLG_WARNINGSTREAMSTDERR:
3942 g_warningstream = stderr;
3944 case FLG_ERRORSTREAMSTDOUT:
3945 g_errorstream = stdout;
3947 case FLG_ERRORSTREAMSTDERR:
3948 g_errorstream = stderr;
3951 DOSET (FLG_ALLEMPTY, b);
3952 DOSET (FLG_IFEMPTY, b);
3953 DOSET (FLG_WHILEEMPTY, b);
3954 DOSET (FLG_FOREMPTY, b);
3957 DOSET (FLG_PREDBOOL, b);
3958 DOSET (FLG_PREDBOOLINT, b);
3959 DOSET (FLG_PREDBOOLPTR, b);
3960 DOSET (FLG_PREDBOOLOTHERS, b);
3963 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3964 DOSET (FLG_CHECKEDGLOBALIAS, b);
3965 DOSET (FLG_CHECKMODGLOBALIAS, b);
3966 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3969 DOSET (FLG_ALLBLOCK, b);
3970 DOSET (FLG_IFBLOCK, b);
3971 DOSET (FLG_WHILEBLOCK, b);
3972 DOSET (FLG_FORBLOCK, b);
3986 DOSET (FLG_GRAMMAR, b);
3988 case FLG_CODEIMPONLY:
3989 DOSET (FLG_CODEIMPONLY, b);
3990 DOSET (FLG_GLOBIMPONLY, b);
3991 DOSET (FLG_RETIMPONLY, b);
3992 DOSET (FLG_STRUCTIMPONLY, b);
3994 case FLG_SPECALLIMPONLY:
3995 DOSET (FLG_SPECALLIMPONLY, b);
3996 DOSET (FLG_SPECGLOBIMPONLY, b);
3997 DOSET (FLG_SPECRETIMPONLY, b);
3998 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4000 case FLG_ALLIMPONLY:
4001 DOSET (FLG_ALLIMPONLY, b);
4002 DOSET (FLG_GLOBIMPONLY, b);
4003 DOSET (FLG_RETIMPONLY, b);
4004 DOSET (FLG_STRUCTIMPONLY, b);
4005 DOSET (FLG_SPECGLOBIMPONLY, b);
4006 DOSET (FLG_SPECRETIMPONLY, b);
4007 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4009 case FLG_ANSI89LIMITS:
4010 DOSET (FLG_ANSI89LIMITS, b);
4011 DOSET (FLG_CONTROLNESTDEPTH, b);
4012 DOSET (FLG_STRINGLITERALLEN, b);
4013 DOSET (FLG_INCLUDENEST, b);
4014 DOSET (FLG_NUMSTRUCTFIELDS, b);
4015 DOSET (FLG_NUMENUMMEMBERS, b);
4019 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4020 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4021 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4022 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4023 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4024 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4025 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4028 case FLG_ISO99LIMITS:
4029 DOSET (FLG_ISO99LIMITS, b);
4030 DOSET (FLG_CONTROLNESTDEPTH, b);
4031 DOSET (FLG_STRINGLITERALLEN, b);
4032 DOSET (FLG_INCLUDENEST, b);
4033 DOSET (FLG_NUMSTRUCTFIELDS, b);
4034 DOSET (FLG_NUMENUMMEMBERS, b);
4038 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4039 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4040 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4041 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4042 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4043 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4044 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4047 case FLG_EXTERNALNAMELEN:
4048 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4049 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4051 case FLG_INTERNALNAMELEN:
4052 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4053 DOSET (FLG_INTERNALNAMELEN, TRUE);
4055 case FLG_EXTERNALNAMECASEINSENSITIVE:
4056 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4058 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4060 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4061 context_setValue (FLG_EXTERNALNAMELEN, 0);
4064 case FLG_INTERNALNAMECASEINSENSITIVE:
4065 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4067 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4069 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4070 context_setValue (FLG_INTERNALNAMELEN, 0);
4073 case FLG_INTERNALNAMELOOKALIKE:
4074 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4076 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4078 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4079 context_setValue (FLG_INTERNALNAMELEN, 0);
4083 DOSET (FLG_MODNOMODS, b);
4084 DOSET (FLG_MODGLOBSUNSPEC, b);
4085 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4088 DOSET (FLG_EXPORTVAR, b);
4089 DOSET (FLG_EXPORTFCN, b);
4090 DOSET (FLG_EXPORTTYPE, b);
4091 DOSET (FLG_EXPORTMACRO, b);
4092 DOSET (FLG_EXPORTCONST, b);
4093 gc.anyExports = TRUE;
4096 DOSET (FLG_RETEXPOSE, b);
4097 DOSET (FLG_ASSIGNEXPOSE, b);
4098 DOSET (FLG_CASTEXPOSE, b);
4101 DOSET (FLG_RETVALBOOL, b);
4102 DOSET (FLG_RETVALINT, b);
4103 DOSET (FLG_RETVALOTHER, b);
4108 DOSET (FLG_EXPORTLOCAL, FALSE);
4109 DOSET (FLG_DECLUNDEF, FALSE);
4110 DOSET (FLG_SPECUNDEF, FALSE);
4111 DOSET (FLG_TOPUNUSED, FALSE);
4115 DOSET (FLG_LOOPLOOPBREAK, b);
4116 DOSET (FLG_LOOPSWITCHBREAK, b);
4117 DOSET (FLG_SWITCHLOOPBREAK, b);
4118 DOSET (FLG_SWITCHSWITCHBREAK, b);
4119 DOSET (FLG_LOOPLOOPCONTINUE, b);
4120 DOSET (FLG_DEEPBREAK, b);
4123 DOSET (FLG_FORLOOPEXEC, b);
4124 DOSET (FLG_WHILELOOPEXEC, b);
4125 DOSET (FLG_ITERLOOPEXEC, b);
4128 DOSET (FLG_ACCESSMODULE, b);
4129 DOSET (FLG_ACCESSFILE, b);
4130 DOSET (FLG_ACCESSCZECH, b);
4133 DOSET (FLG_ALLMACROS, b);
4134 DOSET (FLG_FCNMACROS, b);
4135 DOSET (FLG_CONSTMACROS, b);
4138 DOSET (FLG_BOUNDSREAD, b);
4139 DOSET (FLG_BOUNDSWRITE, b);
4142 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4143 DOSET (FLG_CZECHFUNCTIONS, b);
4144 DOSET (FLG_CZECHVARS, b);
4145 DOSET (FLG_CZECHCONSTANTS, b);
4146 DOSET (FLG_CZECHTYPES, b);
4149 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4150 DOSET (FLG_SLOVAKFUNCTIONS, b);
4151 DOSET (FLG_SLOVAKVARS, b);
4152 DOSET (FLG_SLOVAKCONSTANTS, b);
4153 DOSET (FLG_SLOVAKTYPES, b);
4155 case FLG_CZECHOSLOVAK:
4156 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4157 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4158 DOSET (FLG_CZECHOSLOVAKVARS, b);
4159 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4160 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4163 DOSET (FLG_NULLSTATE, b);
4164 DOSET (FLG_NULLDEREF, b);
4165 DOSET (FLG_NULLASSIGN, b);
4166 DOSET (FLG_NULLPASS, b);
4167 DOSET (FLG_NULLRET, b);
4170 DOSET (FLG_MUSTFREEONLY, b);
4171 DOSET (FLG_MUSTFREEFRESH, b);
4174 DOSET (FLG_NULLSTATE, b);
4175 DOSET (FLG_NULLDEREF, b);
4176 DOSET (FLG_NULLASSIGN, b);
4177 DOSET (FLG_NULLPASS, b);
4178 DOSET (FLG_NULLRET, b);
4179 DOSET (FLG_COMPDEF, b);
4180 DOSET (FLG_COMPMEMPASS, b);
4181 DOSET (FLG_UNIONDEF, b);
4182 DOSET (FLG_MEMTRANS, b);
4183 DOSET (FLG_USERELEASED, b);
4184 DOSET (FLG_ALIASUNIQUE, b);
4185 DOSET (FLG_MAYALIASUNIQUE, b);
4186 DOSET (FLG_MUSTFREEONLY, b);
4187 DOSET (FLG_MUSTFREEFRESH, b);
4188 DOSET (FLG_MUSTDEFINE, b);
4189 DOSET (FLG_GLOBSTATE, b);
4190 DOSET (FLG_COMPDESTROY, b);
4191 DOSET (FLG_MUSTNOTALIAS, b);
4192 DOSET (FLG_MEMIMPLICIT, b);
4193 DOSET (FLG_BRANCHSTATE, b);
4194 /*@fallthrough@*/ /* also sets memtrans flags */
4196 DOSET (FLG_MEMTRANS, b);
4197 DOSET (FLG_EXPOSETRANS, b);
4198 DOSET (FLG_OBSERVERTRANS, b);
4199 DOSET (FLG_DEPENDENTTRANS, b);
4200 DOSET (FLG_NEWREFTRANS, b);
4201 DOSET (FLG_ONLYTRANS, b);
4202 DOSET (FLG_OWNEDTRANS, b);
4203 DOSET (FLG_FRESHTRANS, b);
4204 DOSET (FLG_SHAREDTRANS, b);
4205 DOSET (FLG_TEMPTRANS, b);
4206 DOSET (FLG_KEPTTRANS, b);
4207 DOSET (FLG_REFCOUNTTRANS, b);
4208 DOSET (FLG_STATICTRANS, b);
4209 DOSET (FLG_UNKNOWNTRANS, b);
4210 DOSET (FLG_KEEPTRANS, b);
4211 DOSET (FLG_IMMEDIATETRANS, b);
4218 if (b && !gc.anyExports
4219 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4220 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4221 || f == FLG_EXPORTCONST
4222 || f == FLG_EXPORTANY))
4224 gc.anyExports = TRUE;
4229 context_maybeSet (flagcode d)
4231 return (gc.flags[d] || gc.setLocally[d]);
4235 context_getFlag (flagcode d)
4237 return (gc.flags[d]);
4241 context_flagOn (flagcode f, fileloc loc)
4243 return (!context_suppressFlagMsg (f, loc));
4246 static void context_saveFlagSettings (void)
4248 gc.savedFlags = TRUE;
4249 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4250 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4253 static void context_restoreFlagSettings (void)
4255 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4256 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4257 gc.savedFlags = FALSE;
4260 void context_setFilename (fileId fid, int lineno)
4261 /*@globals fileloc g_currentloc;@*/
4262 /*@modifies g_currentloc@*/
4264 if (fileId_baseEqual (currentFile (), fid))
4271 fileloc_setColumn (g_currentloc, 0);
4273 if (fileloc_isSpecialFile (g_currentloc))
4275 gc.inDerivedFile = TRUE;
4278 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4280 int maxdepth = context_getValue (FLG_INCLUDENEST);
4282 if (filelocStack_size (gc.locstack) > maxdepth)
4284 int depth = filelocStack_includeDepth (gc.locstack);
4286 if (depth > maxdepth)
4290 message ("Maximum include nesting depth "
4291 "(%d, current depth %d) exceeded",
4294 filelocStack_nextTop (gc.locstack)))
4296 filelocStack_printIncludes (gc.locstack);
4302 g_currentloc = fileloc_create (fid, lineno, 1);
4303 gc.inheader = fileId_isHeader (currentFile ());
4305 context_enterFileAux ();
4309 void context_enterIterDef (/*@observer@*/ uentry le)
4311 context_enterMacro (le);
4312 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4313 gc.kind = CX_ITERDEF;
4316 void context_enterIterEnd (/*@observer@*/ uentry le)
4318 context_enterMacro (le);
4319 gc.kind = CX_ITEREND;
4323 context_destroyMod (void)
4324 /*@globals killed gc@*/
4328 ctype_destroyMod ();
4335 fileTable_free (gc.ftab);
4336 gc.ftab = fileTable_undefined;
4338 filelocStack_free (gc.locstack);
4341 macrocache_free (gc.mc);
4343 /* evans 2002-07-12: not reported because of reldef */
4344 for (i = 0; i < gc.nmods; i++)
4346 cstring_free (gc.moduleaccess[i].file);
4349 sfree (gc.moduleaccess);
4352 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4353 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4356 sRefSetList_free (gc.modrecs);
4358 flagMarkerList_free (gc.markers);
4360 messageLog_free (gc.msgLog);
4362 clauseStack_free (gc.clauses);
4365 cstring_free (gc.msgAnnote);
4366 globSet_free (gc.globs_used);
4367 metaStateTable_free (gc.stateTable);
4368 annotationTable_free (gc.annotTable);
4377 bool context_msgBoolInt (void)
4379 return gc.flags [FLG_BOOLINT];
4382 bool context_msgCharInt (void)
4384 return gc.flags [FLG_CHARINT];
4387 bool context_msgEnumInt (void)
4389 return gc.flags [FLG_ENUMINT];
4392 bool context_msgPointerArith (void)
4394 return gc.flags [FLG_POINTERARITH];
4397 bool context_msgStrictOps (void)
4399 return gc.flags [FLG_STRICTOPS];
4402 bool context_msgLh (void)
4404 return gc.flags [FLG_DOLH];
4407 void context_pushLoc (void)
4409 fileloc_free (gc.pushloc);
4410 gc.pushloc = gc.saveloc;
4411 gc.saveloc = fileloc_undefined;
4414 void context_popLoc (void)
4416 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4419 bool context_inGlobalScope (void)
4421 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4424 bool context_inInnerScope (void)
4426 return (gc.kind == CX_INNER);
4429 void context_setProtectVars (void)
4431 gc.protectVars = TRUE;
4434 bool context_anyErrors (void)
4436 return (gc.numerrors > 0);
4439 void context_hasError (void)
4442 DPRINTF (("num errors: %d", gc.numerrors));
4445 int context_numErrors (void)
4447 return gc.numerrors;
4450 bool context_neednl (void)
4455 void context_setNeednl (void)
4460 int context_getExpect (void)
4462 return (context_getValue (FLG_EXPECT));
4465 int context_getLCLExpect (void)
4467 return (context_getValue (FLG_LCLEXPECT));
4470 int context_getLimit (void)
4472 return (context_getValue (FLG_LIMIT));
4475 bool context_unlimitedMessages (void)
4477 return (context_getLimit () < 0);
4480 void context_releaseVars (void)
4482 llassert (gc.protectVars);
4483 gc.protectVars = FALSE;
4486 void context_sizeofReleaseVars (void)
4488 /* If there is a nested sizeof, this might not hold:
4489 llassert (gc.protectVars);
4492 gc.protectVars = FALSE;
4495 bool context_inProtectVars (void)
4497 return (gc.protectVars);
4500 void context_hideShowscan (void)
4502 gc.flags[FLG_SHOWSCAN] = FALSE;
4505 void context_unhideShowscan (void)
4507 gc.flags[FLG_SHOWSCAN] = TRUE;
4510 bool context_inHeader (void)
4512 return (gc.inheader);
4515 fileTable context_fileTable (void)
4520 cstring context_tmpdir (void)
4522 return (context_getString (FLG_TMPDIR));
4525 messageLog context_messageLog (void)
4530 bool context_inMacroFunction (void)
4532 return (gc.kind == CX_MACROFCN);
4535 bool context_inMacroConstant (void)
4537 return (gc.kind == CX_MACROCONST);
4540 bool context_inUnknownMacro (void)
4542 return (gc.kind == CX_UNKNOWNMACRO);
4545 void context_setShownFunction (void)
4547 gc.showfunction = FALSE;
4550 bool context_doDump (void)
4552 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4555 bool context_doMerge (void)
4557 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4560 cstring context_getDump (void)
4562 return context_getString (FLG_DUMP);
4565 cstring context_getMerge (void)
4567 return context_getString (FLG_MERGE);
4570 bool context_inLCLLib (void)
4572 return (gc.kind == CX_LCLLIB);
4575 bool context_inImport (void)
4577 return (gc.inimport);
4580 void context_enterImport (void)
4585 void context_leaveImport (void)
4587 gc.inimport = FALSE;
4590 bool context_inMacro (void)
4592 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4593 || gc.kind == CX_UNKNOWNMACRO
4594 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4597 bool context_inIterDef (void)
4599 return (gc.kind == CX_ITERDEF);
4602 bool context_inIterEnd (void)
4604 return (gc.kind == CX_ITEREND);
4607 int context_getLinesProcessed (void)
4609 return (gc.linesprocessed);
4612 int context_getSpecLinesProcessed (void)
4614 return (gc.speclinesprocessed);
4617 void context_processedSpecLine (void)
4619 gc.speclinesprocessed++;
4622 void context_resetSpecLines (void)
4624 gc.speclinesprocessed = 0;
4628 bool context_inGlobalContext (void)
4630 return (gc.kind == CX_GLOBAL);
4633 static void context_quietExitScopes (void)
4636 ** Try to restore the global scope (after an error).
4639 while (!usymtab_inFileScope ())
4641 usymtab_quietExitScope (g_currentloc);
4644 gc.cont.glob = TRUE;
4645 gc.kind = CX_GLOBAL;
4648 void context_checkGlobalScope (void)
4650 if (gc.kind != CX_GLOBAL)
4652 if (context_inMacro ())
4654 ; /* evans 2001-10-14: Okay to be in a macro here! */
4658 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4659 context_quietExitScopes ();
4664 void context_setFileId (fileId s)
4666 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4669 bool context_setBoolName (void)
4671 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4675 cstring context_printBoolName (void)
4677 if (context_setBoolName ())
4679 return context_getBoolName ();
4683 return cstring_makeLiteralTemp ("boolean");
4687 cstring context_getBoolName (void)
4689 return (context_getString (FLG_BOOLTYPE));
4692 cstring context_getFalseName (void)
4694 return (context_getString (FLG_BOOLFALSE));
4697 cstring context_getTrueName (void)
4699 return (context_getString (FLG_BOOLTRUE));
4702 cstring context_getLarchPath (void)
4704 return (context_getString (FLG_LARCHPATH));
4707 cstring context_getLCLImportDir (void)
4709 return (context_getString (FLG_LCLIMPORTDIR));
4712 static void context_setJustPopped (void)
4714 gc.justpopped = TRUE;
4717 void context_clearJustPopped (void)
4719 gc.justpopped = FALSE;
4722 bool context_justPopped (void)
4724 return (gc.justpopped);
4727 void context_setMacroMissingParams (void)
4729 gc.macroMissingParams = TRUE;
4732 void context_resetMacroMissingParams (void)
4734 gc.macroMissingParams = FALSE;
4737 bool context_isMacroMissingParams (void)
4739 return (gc.macroMissingParams);
4742 void context_showFilelocStack (void)
4744 filelocStack_printIncludes (gc.locstack);
4747 metaStateTable context_getMetaStateTable (void)
4749 return gc.stateTable;
4752 metaStateInfo context_lookupMetaStateInfo (cstring key)
4754 return metaStateTable_lookup (gc.stateTable, key);
4757 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4759 annotationInfo ainfo;
4761 ainfo = annotationTable_lookup (gc.annotTable, annot);
4766 void context_addAnnotation (annotationInfo ainfo)
4768 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4772 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4773 annotationInfo_getLoc (ainfo));
4775 annotationInfo_free (ainfo);
4779 annotationTable_insert (gc.annotTable, ainfo);
4783 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4785 if (metaStateTable_contains (gc.stateTable, mname))
4789 message ("Duplicate metastate declaration: %s", mname),
4790 metaStateInfo_getLoc (msinfo));
4791 cstring_free (mname);
4792 metaStateInfo_free (msinfo);
4796 DPRINTF (("Adding meta state: %s", mname));
4797 metaStateTable_insert (gc.stateTable, mname, msinfo);
4801 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4803 if (metaStateTable_size (gc.stateTable) > 0)
4805 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4806 /*@i32 should use smaller value... */
4807 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4809 metaStateTable_elements (gc.stateTable, msname, msi)
4811 mtContextNode context = metaStateInfo_getContext (msi);
4813 if (mtContextNode_matchesRefStrict (context, s))
4815 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4816 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4820 cstring_copy (metaStateInfo_getName (msi)),
4821 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4822 stateInfo_copy (sinfo)));
4826 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4829 end_metaStateTable_elements ;
4831 stateInfo_free (sinfo);
4832 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4837 stateInfo_free (sinfo);
4838 return valueTable_undefined;
4842 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4844 if (metaStateTable_size (gc.stateTable) > 0)
4846 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4847 /*@i32 should use smaller value... */
4849 metaStateTable_elements (gc.stateTable, msname, msi)
4851 /*@i23 only add global...*/
4852 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4853 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4855 valueTable_insert (res,
4856 cstring_copy (metaStateInfo_getName (msi)),
4857 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4858 stateInfo_copy (sinfo)));
4860 end_metaStateTable_elements ;
4862 stateInfo_free (sinfo);
4863 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4868 stateInfo_free (sinfo);
4869 return valueTable_undefined;
4874 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4878 static ctype lastStruct;
4880 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4886 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4892 ** Why is this stuff in context.c?
4895 /*@unused@*/ static int sInfoNum = 0;
4899 /*@unused@*/ uentry ue;
4900 /*@unused@*/ sRef s;
4904 /*@unused@*/ ctype ct;
4905 /*@unused@*/ constraintList inv;
4906 /*@unused@*/ int ngetUe;
4907 /*@unused@*/ struct getUe * t ;
4911 static struct sInfo globalStructInfo;
4914 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4915 stable release of splint. I coomented them out so that they won't break anything
4916 but didn't delete them because they will be fixed and included later
4923 void setGlobalStructInfo(ctype ct, constraintList list)
4929 f = ctype_getFields (ct);
4931 if (constraintList_isDefined(list) )
4933 globalStructInfo.ct = ct;
4934 globalStructInfo.inv = list;
4936 globalStructInfo.ngetUe = 0;
4938 /* abstraction violation fix it * /
4939 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4941 globalStructInfo.ngetUe = f->nelements;
4945 uentryList_elements(f, ue)
4947 globalStructInfo.t[i].ue = ue;
4948 globalStructInfo.t[i].s = uentry_getSref(ue);
4949 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4950 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4955 end_uentryList_elements;
4964 bool hasInvariants (ctype ct) /*@* /
4966 if ( ctype_sameName(globalStructInfo.ct, ct) )