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_NUMABSTRACT] = TRUE;
896 gc.flags[FLG_ITERBALANCE] = TRUE;
897 gc.flags[FLG_ITERYIELD] = TRUE;
898 gc.flags[FLG_DUPLICATECASES] = TRUE;
899 gc.flags[FLG_ALWAYSEXITS] = TRUE;
900 gc.flags[FLG_EMPTYRETURN] = TRUE;
901 gc.flags[FLG_MACRORETURN] = TRUE;
902 gc.flags[FLG_UNRECOG] = TRUE;
903 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
904 gc.flags[FLG_LINTCOMMENTS] = TRUE;
905 gc.flags[FLG_ACCESSCZECH] = TRUE;
906 gc.flags[FLG_ACCESSMODULE] = TRUE;
907 gc.flags[FLG_ACCESSFILE] = TRUE;
908 gc.flags[FLG_MACROVARPREFIX] = TRUE;
910 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
911 gc.flags[FLG_COMMENTERROR] = TRUE;
914 ** Changed for version 2.4.
917 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
923 /* commenting ou until some output issues are fixed */
924 gc.flags[FLG_ORCONSTRAINT] = TRUE;
926 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
929 gc.flags[FLG_WARNSYSFILES] = TRUE;
932 ** On by default for Win32, but not Unix
936 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
937 gc.flags[FLG_CASEINSENSITIVEFILENAMES] = TRUE;
942 ** C is way-lame, and you can initialize an array to a constant except where
943 ** it is declared. Hence, a macro is used to set the modeflags.
947 # define SETFLAGS() \
948 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
949 if (!flagcode_isModeFlag (modeflags[i])) \
950 { llbug (message ("not a mode flag: %s", \
951 flagcode_unparse (modeflags[i]))); } \
952 else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }}
954 static void context_setModeAux (cstring p_s, bool p_warn) ;
957 context_setMode (cstring s)
959 context_setModeAux (s, TRUE);
963 context_setModeNoWarn (cstring s)
965 context_setModeAux (s, FALSE);
969 context_setModeAux (cstring s, bool warn)
971 intSet setflags = intSet_new ();
975 if (flagcode_isModeFlag (code))
977 if (gc.setGlobally[code])
979 (void) intSet_insert (setflags, (int) code);
984 if (!intSet_isEmpty (setflags))
986 cstring rflags = cstring_undefined;
989 intSet_elements (setflags, el)
991 if (cstring_isUndefined (rflags))
993 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
997 rflags = message ("%q, %s", rflags,
998 flagcode_unparse ((flagcode) el));
1002 if (num > 4 && intSet_size (setflags) > 6)
1004 rflags = message ("%q, (%d others) ...", rflags,
1005 intSet_size (setflags) - num);
1008 } end_intSet_elements ;
1012 voptgenerror (FLG_WARNFLAGS,
1013 message ("Setting mode %s after setting mode flags will "
1014 "override set values of flags: %s",
1019 cstring_free (rflags);
1022 intSet_free (setflags);
1024 context_resetModeFlags ();
1026 if (cstring_equalLit (s, "standard"))
1028 flagcode modeflags[] =
1030 FLG_ENUMINT, FLG_MACROMATCHNAME,
1031 FLG_STRINGLITNOROOM,
1032 FLG_STRINGLITNOROOMFINALNULL,
1033 FLG_MACROUNDEF, FLG_RELAXQUALS,
1034 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1035 FLG_CHECKSTRICTGLOBALIAS,
1036 FLG_CHECKEDGLOBALIAS,
1037 FLG_CHECKMODGLOBALIAS,
1038 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1039 FLG_UNSIGNEDCOMPARE,
1040 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1042 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1043 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1044 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1045 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1046 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1049 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1050 FLG_MACROSTMT, FLG_MACROPARENS,
1053 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1054 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1059 /* memchecks flags */
1061 FLG_NULLSTATE, FLG_NULLASSIGN,
1062 FLG_NULLPASS, FLG_NULLRET,
1064 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1067 /* memtrans flags */
1083 FLG_NUMABSTRACTCAST,
1086 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1089 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1090 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1093 FLG_STATETRANSFER, FLG_STATEMERGE,
1094 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1096 FLG_IMPCHECKEDSPECGLOBALS,
1097 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1098 FLG_IFEMPTY, FLG_REALCOMPARE,
1099 FLG_BOOLOPS, FLG_PTRNEGATE,
1101 FLG_SHIFTIMPLEMENTATION,
1102 FLG_BUFFEROVERFLOWHIGH,
1109 else if (cstring_equalLit (s, "weak"))
1111 flagcode modeflags[] =
1113 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE, FLG_LONGINT, FLG_SHORTINT,
1114 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1115 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1116 FLG_CHARUNSIGNEDCHAR,
1119 FLG_VARUNUSED, FLG_FUNCUNUSED,
1121 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1124 FLG_BUFFEROVERFLOWHIGH,
1125 FLG_RETSTACK, FLG_PTRNEGATE,
1126 FLG_STATETRANSFER, FLG_STATEMERGE,
1127 FLG_LONGUNSIGNEDINTEGRAL,
1128 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1132 FLG_BUFFEROVERFLOWHIGH,
1133 FLG_STRINGLITNOROOM,
1134 FLG_STRINGLITNOROOMFINALNULL,
1140 else if (cstring_equalLit (s, "checks"))
1142 flagcode modeflags[] =
1144 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1145 FLG_NUMABSTRACTCAST,
1146 FLG_STATETRANSFER, FLG_STATEMERGE,
1147 FLG_CHECKSTRICTGLOBALIAS,
1148 FLG_CHECKEDGLOBALIAS,
1149 FLG_CHECKMODGLOBALIAS,
1150 FLG_UNCHECKEDGLOBALIAS,
1152 FLG_STRINGLITNOROOM,
1153 FLG_STRINGLITNOROOMFINALNULL,
1154 FLG_STRINGLITSMALLER,
1155 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1156 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1157 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1158 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1159 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1160 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1161 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1162 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1163 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1164 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1165 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1166 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1167 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1168 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1175 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1179 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1181 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1182 FLG_EVALORDER, FLG_USEDEF,
1185 /* warn use flags */
1186 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1187 FLG_BUFFEROVERFLOWHIGH,
1189 /* memchecks flags */
1191 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1192 FLG_NULLPASS, FLG_NULLRET,
1194 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1196 /* memtrans flags */
1210 FLG_STATICINITTRANS,
1211 FLG_UNKNOWNINITTRANS,
1214 FLG_ONLYUNQGLOBALTRANS,
1215 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1218 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1219 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1222 FLG_NULLPOINTERARITH,
1223 FLG_SHADOW, FLG_DEPARRAYS,
1224 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1225 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1226 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1227 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1228 FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES,
1229 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1230 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1231 FLG_SHIFTIMPLEMENTATION,
1232 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1237 else if (cstring_equalLit (s, "strict"))
1239 flagcode modeflags[] =
1241 FLG_CHECKSTRICTGLOBALIAS,
1242 FLG_NUMABSTRACTCAST,
1243 FLG_CHECKEDGLOBALIAS,
1244 FLG_CHECKMODGLOBALIAS,
1245 FLG_UNCHECKEDGLOBALIAS,
1249 FLG_STRINGLITNOROOM,
1250 FLG_STRINGLITNOROOMFINALNULL,
1251 FLG_STRINGLITSMALLER,
1252 FLG_STATETRANSFER, FLG_STATEMERGE,
1253 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1254 FLG_ALLGLOBALS, FLG_IMPTYPE,
1255 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1256 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1257 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1258 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1261 FLG_ONLYUNQGLOBALTRANS,
1262 FLG_GLOBALSIMPMODIFIESNOTHING,
1263 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1264 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1265 FLG_USEALLGLOBS, FLG_RETALIAS,
1266 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1267 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1268 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1270 FLG_EXPORTITER, FLG_EXPORTCONST,
1271 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1272 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1274 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1276 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1277 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1278 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1279 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1280 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1281 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1282 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1283 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1285 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1288 FLG_MACROREDEF, FLG_MACROEMPTY,
1289 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1291 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1293 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1294 FLG_MODOBSERVERUNCON,
1299 /* warn use flags */
1300 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1301 FLG_BUFFEROVERFLOWHIGH,
1302 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1304 /* memchecks flags */
1305 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1306 FLG_NULLPASS, FLG_NULLRET,
1308 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1310 /* memtrans flags */
1326 FLG_STATICINITTRANS,
1327 FLG_UNKNOWNINITTRANS,
1329 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1332 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1333 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1337 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1339 FLG_SHADOW, FLG_DEPARRAYS,
1340 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1341 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1342 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1343 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1344 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1345 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1346 FLG_IMPCHECKEDSTRICTSTATICS,
1347 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1348 FLG_IMPCHECKMODINTERNALS,
1349 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1350 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1351 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1352 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1353 FLG_CONTROLNESTDEPTH,
1354 FLG_FORBLOCK, FLG_WHILEBLOCK,
1355 FLG_FOREMPTY, FLG_WHILEEMPTY,
1356 FLG_IFEMPTY, FLG_IFBLOCK,
1358 FLG_REALCOMPARE, FLG_BOOLOPS,
1359 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1362 FLG_SHIFTIMPLEMENTATION,
1364 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1372 llcontbug (message ("context_setMode: bad mode: %s", s));
1377 context_isSpecialFile (cstring fname)
1379 cstring ext = fileLib_getExtension (fname);
1381 return (cstring_equalLit (ext, ".y")
1382 || cstring_equalLit (ext, ".l")
1383 || cstring_equalLit (fname, "lex.yy.c"));
1387 context_isSystemDir (cstring dir)
1389 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1390 cstring savedir = thisdir;
1391 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1393 if (cstring_isDefined (nextdir))
1395 /*@access cstring@*/
1396 *nextdir = '\0'; /* closes thisdir */
1398 /*@noaccess cstring@*/
1401 /* 2001-09-09: added thisdir[0] != '\0'
1402 ** herbert: don't compare with an empty name!
1403 ** should return false for empty directory path
1406 while (!cstring_isEmpty (thisdir))
1408 DPRINTF (("Test: %s / %s", dir, thisdir));
1410 if (osd_equalCanonicalPrefix (dir, thisdir))
1412 cstring_free (savedir);
1416 if (cstring_isDefined (nextdir))
1419 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1421 if (cstring_isDefined (nextdir))
1423 /*@access cstring@*/
1426 /*@noaccess cstring@*/
1435 DPRINTF (("Returns FALSE"));
1436 cstring_free (savedir);
1441 context_addFileAccessType (typeId t)
1445 if (context_inFunctionLike ())
1447 gc.acct = typeIdSet_insert (gc.acct, t);
1450 gc.facct = typeIdSet_insert (gc.facct, t);
1452 base = fileloc_getBase (g_currentloc);
1453 insertModuleAccess (base, t);
1454 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1455 typeIdSet_unparse (gc.acct)));
1459 context_removeFileAccessType (typeId t)
1461 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1462 || gc.kind == CX_UNKNOWNMACRO)
1464 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1467 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1468 gc.nacct = typeIdSet_insert (gc.nacct, t);
1471 void context_enterFunctionHeader (void)
1473 if (context_getFlag (FLG_GRAMMAR))
1475 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1478 if (gc.kind != CX_GLOBAL)
1480 llparseerror (cstring_makeLiteral
1481 ("Likely parse error. Function header outside global context."));
1485 llassert (gc.kind == CX_GLOBAL);
1486 DPRINTF (("Enter function header!"));
1487 gc.inFunctionHeader = TRUE;
1491 void context_exitFunctionHeader (void)
1493 if (context_getFlag (FLG_GRAMMAR))
1495 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1498 DPRINTF (("Exit function header!"));
1499 gc.inFunctionHeader = FALSE;
1502 bool context_inFunctionHeader (void)
1504 return (gc.inFunctionHeader);
1507 void context_enterFunctionDeclaration (uentry e)
1509 if (context_getFlag (FLG_GRAMMAR))
1511 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1514 DPRINTF (("Enter function decl"));
1515 llassert (gc.savekind == CX_ERROR);
1516 gc.savekind = gc.kind;
1517 gc.savecont = gc.cont;
1518 gc.kind = CX_FCNDECLARATION;
1522 void context_exitFunctionDeclaration (void)
1524 if (context_getFlag (FLG_GRAMMAR))
1526 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1529 DPRINTF (("Exit function decl"));
1530 llassert (gc.savekind != CX_ERROR);
1531 llassert (gc.kind == CX_FCNDECLARATION);
1532 gc.kind = gc.savekind;
1533 gc.cont = gc.savecont;
1535 gc.savekind = CX_ERROR;
1537 if (context_getFlag (FLG_GRAMMAR))
1539 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1543 bool context_inFunctionDeclaration (void)
1545 return (gc.kind == CX_FCNDECLARATION);
1550 context_enterMacro (/*@observer@*/ uentry e)
1552 context_enterFunction (e);
1553 gc.kind = CX_MACROFCN;
1557 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1559 llassert (uentry_isFunction (e));
1560 context_enterFunction (e);
1561 gc.kind = CX_UNKNOWNMACRO;
1564 void context_enterAndClause (exprNode e)
1567 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1568 pushClause (ANDCLAUSE);
1571 void context_enterOrClause (exprNode e)
1573 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1574 pushClause (ORCLAUSE);
1577 bool context_inDeepLoop (void)
1579 bool inLoop = FALSE;
1581 clauseStack_elements (gc.clauses, el)
1583 if (clause_isLoop (el))
1592 } end_clauseStack_elements;
1597 bool context_inDeepSwitch (void)
1599 bool inLoop = FALSE;
1601 clauseStack_elements (gc.clauses, el)
1603 if (clause_isSwitch (el))
1612 } end_clauseStack_elements;
1617 bool context_inDeepLoopSwitch (void)
1619 bool inLoop = FALSE;
1621 clauseStack_elements (gc.clauses, el)
1623 if (clause_isBreakable (el))
1632 } end_clauseStack_elements;
1637 clause context_breakClause (void)
1639 clauseStack_elements (gc.clauses, el)
1641 if (clause_isSwitch (el))
1645 else if (clause_isLoop (el))
1653 } end_clauseStack_elements;
1658 clause context_nextBreakClause (void)
1660 bool hasOne = FALSE;
1662 clauseStack_elements (gc.clauses, el)
1664 if (clause_isBreakable (el))
1675 } end_clauseStack_elements;
1680 bool context_inConditional (void)
1682 clauseStack_elements (gc.clauses, el)
1685 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1686 ** to distinguish if from ? for this
1689 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1693 } end_clauseStack_elements;
1698 void context_exitAndClause (exprNode pred, exprNode tbranch)
1700 context_setJustPopped ();
1702 llassert (gc.inclause == ANDCLAUSE);
1704 usymtab_popAndBranch (pred, tbranch);
1705 clauseStack_pop (gc.clauses);
1706 gc.inclause = topClause (gc.clauses);
1709 void context_exitOrClause (exprNode pred, exprNode tbranch)
1711 context_setJustPopped ();
1713 llassert (gc.inclause == ORCLAUSE);
1715 usymtab_popOrBranch (pred, tbranch);
1716 clauseStack_pop (gc.clauses);
1717 gc.inclause = topClause (gc.clauses);
1720 static void context_enterCondClauseAux (clause cl)
1726 static void context_enterTrueAux (exprNode e, clause cl)
1729 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1733 void context_enterIterClause (void)
1735 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1738 void context_enterDoWhileClause (void)
1740 pushClause (DOWHILECLAUSE);
1743 void context_enterWhileClause (exprNode e)
1745 context_enterTrueAux (e, WHILECLAUSE);
1748 void context_enterForClause (exprNode e)
1750 context_enterTrueAux (e, FORCLAUSE);
1753 void context_enterTrueClause (exprNode e)
1755 context_enterTrueAux (e, TRUECLAUSE);
1758 void context_enterSwitch (exprNode e)
1760 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1761 usymtab_switchBranch (e);
1762 context_enterCondClauseAux (SWITCHCLAUSE);
1765 void context_exitSwitch (exprNode e, bool allpaths)
1767 usymtab_exitSwitch (e, allpaths);
1769 while (clause_isCase (clauseStack_top (gc.clauses)))
1771 clauseStack_pop (gc.clauses);
1774 context_exitClauseSimp ();
1777 void context_enterCaseClause (exprNode e)
1779 bool branch = FALSE;
1781 DPRINTF (("Enter case clause!"));
1783 branch = usymtab_newCase (exprNode_undefined, e);
1787 context_enterCondClauseAux (CASECLAUSE);
1791 static void context_enterFalseClauseAux (exprNode e, clause cl)
1794 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1796 clauseStack_switchTop (gc.clauses, cl);
1799 void context_enterFalseClause (exprNode e)
1802 context_enterFalseClauseAux (e, FALSECLAUSE);
1806 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1808 gc.kind = CX_MACROCONST;
1810 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1812 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1816 usymtab_enterScope ();
1817 sRef_enterFunctionScope ();
1819 gc.globs = globSet_undefined;
1820 globSet_clear (gc.globs_used);
1821 gc.mods = sRefSet_undefined;
1824 uentry context_getHeader (void)
1826 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1828 llfatalbug (message ("context_getHeader: bad call: %q",
1829 context_unparse ()));
1832 return (gc.cont.fcn);
1836 context_setFunctionDefined (fileloc loc)
1840 case CX_UNKNOWNMACRO:
1843 uentry_setFunctionDefined (gc.cont.fcn, loc);
1846 /* (not a bug because of parse errors) */
1852 context_enterFunction (/*@exposed@*/ uentry e)
1854 gc.kind = CX_FUNCTION;
1857 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1859 if (uentry_hasAccessType (e))
1861 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1869 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1870 typeIdSet_unparse (gc.acct)));
1872 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1874 gc.globs = uentry_getGlobs (e);
1875 globSet_clear (gc.globs_used);
1876 gc.mods = uentry_getMods (e);
1878 usymtab_enterFunctionScope (e);
1879 sRef_enterFunctionScope ();
1882 bool context_inOldStyleScope(void)
1884 return (gc.kind == CX_OLDSTYLESCOPE);
1888 context_enterOldStyleScope (void)
1890 gc.kind = CX_OLDSTYLESCOPE;
1891 DPRINTF (("Enter old style scope!"));
1892 usymtab_enterFunctionScope (uentry_undefined);
1896 context_completeOldStyleFunction (uentry e)
1898 llassert (gc.kind == CX_OLDSTYLESCOPE);
1900 gc.kind = CX_FUNCTION;
1903 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1905 if (uentry_hasAccessType (e))
1907 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1915 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1916 typeIdSet_unparse (gc.acct)));
1918 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1920 if (!globSet_isEmpty (uentry_getGlobs (e)))
1922 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1923 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1926 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1928 gc.globs = uentry_getGlobs (e);
1929 globSet_clear (gc.globs_used);
1931 gc.mods = uentry_getMods (e);
1933 if (!sRefSet_isEmpty (gc.mods))
1935 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1936 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1939 sRef_enterFunctionScope ();
1942 static bool context_checkStrictGlobals (void)
1944 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1947 static bool context_hasGlobs (void)
1949 if (context_inFunctionLike ())
1951 return (uentry_hasGlobs (gc.cont.fcn));
1959 static bool context_checkCheckedGlobals (void)
1961 return (context_getFlag (FLG_GLOBALS)
1962 && (context_getFlag (FLG_GLOBUNSPEC)
1963 || context_hasGlobs ()));
1966 static bool context_checkUnknownGlobals (void)
1968 /* should be uentry_hasGlobs ? */
1970 return (context_getFlag (FLG_ALLGLOBALS)
1971 && (context_getFlag (FLG_GLOBUNSPEC)
1972 || context_hasGlobs ()));
1975 static bool context_checkUncheckedGlobals (void)
1981 context_checkExport (uentry e)
1983 if (!gc.anyExports) return FALSE;
1985 if (uentry_isFunction (e)
1986 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1988 return context_maybeSet (FLG_EXPORTFCN);
1990 else if (uentry_isExpandedMacro (e))
1992 return context_maybeSet (FLG_EXPORTMACRO);
1994 else if (uentry_isVariable (e))
1996 return context_maybeSet (FLG_EXPORTVAR);
1998 else if (uentry_isEitherConstant (e))
2000 return context_maybeSet (FLG_EXPORTCONST);
2002 else if (uentry_isIter (e) || uentry_isEndIter (e))
2004 return context_maybeSet (FLG_EXPORTITER);
2006 else if (uentry_isDatatype (e))
2008 return context_maybeSet (FLG_EXPORTTYPE);
2017 context_checkGlobUse (uentry glob)
2020 if (uentry_isCheckedStrict (glob))
2022 return context_checkStrictGlobals ();
2024 else if (uentry_isChecked (glob))
2026 return context_checkCheckedGlobals ();
2028 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2030 return context_checkUnknownGlobals ();
2034 llassert (uentry_isUnchecked (glob));
2036 return context_checkUncheckedGlobals ();
2041 context_checkAliasGlob (uentry glob)
2043 if (uentry_isCheckedStrict (glob))
2045 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2047 else if (uentry_isChecked (glob))
2049 return gc.flags[FLG_CHECKEDGLOBALIAS];
2051 else if (uentry_isCheckMod (glob))
2053 return gc.flags[FLG_CHECKMODGLOBALIAS];
2057 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2059 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2063 bool context_checkInternalUse (void)
2065 if (context_hasGlobs ())
2067 return (gc.flags[FLG_INTERNALGLOBS]);
2071 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2076 context_checkGlobMod (sRef el)
2078 uentry ue = sRef_getUentry (el);
2080 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2082 if (uentry_isCheckedModify (ue)
2083 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2085 if (context_hasMods ())
2087 return (gc.flags[FLG_MODGLOBS]);
2091 if (uentry_isCheckedStrict (ue))
2093 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2097 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2103 if (context_hasMods ())
2105 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2115 context_usedGlobal (/*@exposed@*/ sRef el)
2117 if (!globSet_member (gc.globs_used, el))
2120 ** The first time a global is used in a function, we need
2121 ** to clear the derived sRefs, since they were set for the
2122 ** previous function.
2125 sRef_clearDerived (el);
2126 gc.globs_used = globSet_insert (gc.globs_used, el);
2130 /*@observer@*/ sRefSet
2131 context_modList (void)
2137 context_globAccess (sRef s)
2139 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2140 return (globSet_member (gc.globs, s));
2144 context_hasAccess (typeId t)
2146 if (context_inFunctionLike ())
2148 DPRINTF (("Access %d / %s",
2149 t, typeIdSet_unparse (gc.acct)));
2150 return (typeIdSet_member (gc.acct, t));
2154 return (context_hasFileAccess (t));
2159 context_hasFileAccess (typeId t)
2161 return (typeIdSet_member (gc.facct, t));
2165 context_unparseAccess (void)
2167 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2168 typeIdSet_unparse (gc.facct)));
2172 context_unparseClauses (void)
2174 return (clauseStack_unparse (gc.clauses));
2178 context_couldHaveAccess (typeId t)
2180 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2182 return (typeIdSet_member (gc.acct, t));
2186 return (typeIdSet_member (gc.facct, t));
2191 context_getRetType (void)
2193 ctype f = ctype_undefined;
2195 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2197 f = uentry_getType (gc.cont.fcn);
2199 else if (gc.kind == CX_UNKNOWNMACRO)
2201 return ctype_unknown;
2205 llcontbuglit ("context_getRetType: not in a function context");
2206 return ctype_unknown;
2209 if (!ctype_isFunction (f))
2211 if (ctype_isKnown (f))
2213 llbuglit ("context_getRetType: not a function");
2216 return ctype_unknown;
2218 return (ctype_getReturnType (f));
2222 context_hasMods (void)
2224 if (context_inFunctionLike ())
2226 return (uentry_hasMods (gc.cont.fcn));
2235 context_exitAllClauses (void)
2237 while (!clauseStack_isEmpty (gc.clauses))
2239 clause el = clauseStack_top (gc.clauses);
2242 if (clause_isNone (el))
2244 usymtab_quietExitScope (g_currentloc);
2245 clauseStack_pop (gc.clauses);
2249 context_exitClausePlain ();
2253 clauseStack_clear (gc.clauses);
2254 gc.inclause = NOCLAUSE;
2258 context_exitAllClausesQuiet (void)
2260 while (!clauseStack_isEmpty (gc.clauses))
2262 clause el = clauseStack_top (gc.clauses);
2265 usymtab_quietExitScope (g_currentloc);
2266 clauseStack_pop (gc.clauses);
2269 clauseStack_clear (gc.clauses);
2270 gc.inclause = NOCLAUSE;
2274 void context_exitClauseSimp (void)
2277 context_setJustPopped ();
2278 clauseStack_pop (gc.clauses);
2279 gc.inclause = topClause (gc.clauses);
2283 void context_exitCaseClause (void)
2285 context_setJustPopped ();
2286 usymtab_popCaseBranch ();
2287 clauseStack_pop (gc.clauses);
2288 gc.inclause = topClause (gc.clauses);
2292 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2294 context_setJustPopped ();
2295 /*@i32 was makeAlt */
2296 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2297 clauseStack_pop (gc.clauses);
2298 gc.inclause = topClause (gc.clauses);
2301 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2303 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2305 if (gc.inclause != TRUECLAUSE)
2307 llparseerror (cstring_makeLiteral
2308 ("Likely parse error. Conditional clauses are inconsistent."));
2312 context_setJustPopped ();
2313 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2314 clauseStack_pop (gc.clauses);
2315 gc.inclause = topClause (gc.clauses);
2318 void context_exitIterClause (exprNode body)
2320 llassert (gc.inclause == ITERCLAUSE);
2322 context_setJustPopped ();
2324 if (context_getFlag (FLG_ITERLOOPEXEC))
2326 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2330 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2333 clauseStack_pop (gc.clauses);
2334 gc.inclause = topClause (gc.clauses);
2337 static void context_popCase (void) {
2339 ** If we are exiting an outer clause, sometimes still in a switch case.
2353 DPRINTF (("Popping case clause: %s",
2354 clauseStack_unparse (gc.clauses)));
2356 if (gc.inclause == CASECLAUSE) {
2357 context_exitCaseClause ();
2361 void context_exitWhileClause (exprNode pred, exprNode body)
2363 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2367 if (gc.inclause != WHILECLAUSE) {
2368 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2369 clauseStack_unparse (gc.clauses)));
2372 llassert (gc.inclause == WHILECLAUSE);
2374 context_setJustPopped ();
2378 ** predicate must be false after while loop (unless there are breaks)
2381 if (context_getFlag (FLG_WHILELOOPEXEC))
2383 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2387 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2391 usymtab_addGuards (invGuards);
2392 guardSet_free (invGuards);
2394 clauseStack_pop (gc.clauses);
2395 gc.inclause = topClause (gc.clauses);
2398 void context_exitDoWhileClause (exprNode pred)
2400 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2402 if (gc.inclause == CASECLAUSE) {
2403 /* handle Duff's device */
2404 clauseStack_pop (gc.clauses);
2405 gc.inclause = topClause (gc.clauses);
2408 llassert (gc.inclause == DOWHILECLAUSE);
2410 context_setJustPopped ();
2413 usymtab_addGuards (invGuards);
2414 guardSet_free (invGuards);
2416 clauseStack_pop (gc.clauses);
2417 gc.inclause = topClause (gc.clauses);
2420 void context_exitForClause (exprNode forPred, exprNode body)
2422 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2424 llassert (gc.inclause == FORCLAUSE);
2425 context_setJustPopped ();
2427 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2430 ** Predicate must be false after for loop (unless there are breaks)
2433 if (context_getFlag (FLG_FORLOOPEXEC))
2435 DPRINTF (("Here: for loop exec"));
2436 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2440 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2441 && exprNode_loopMustExec (forPred))
2443 DPRINTF (("Here: loop must exec"));
2444 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2448 DPRINTF (("Pop true branch:"));
2449 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2453 usymtab_addGuards (invGuards);
2454 guardSet_free (invGuards);
2455 clauseStack_pop (gc.clauses);
2456 gc.inclause = topClause (gc.clauses);
2459 static void context_exitClausePlain (void)
2461 llassert (gc.inclause != NOCLAUSE);
2463 if (gc.inclause == FALSECLAUSE)
2465 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2469 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2473 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2475 context_setJustPopped ();
2477 if (gc.inclause == FALSECLAUSE)
2479 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2481 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2483 clauseStack_pop (gc.clauses);
2484 gc.inclause = topClause (gc.clauses);
2488 context_exitTrueClause (pred, tbranch);
2493 context_returnFunction (void)
2495 usymtab_checkFinalScope (TRUE);
2499 context_exitFunction (void)
2501 DPRINTF (("Exit function: %s", context_unparse ()));
2503 if (!context_inFunction () && !context_inMacroConstant ()
2504 && !context_inUnknownMacro ()
2505 && !context_inIterDef () && !context_inIterEnd ())
2508 ** not a bug because of parse errors
2515 if (context_inMacro () && usymtab_inFunctionScope ())
2517 usymtab_exitScope (exprNode_undefined);
2520 if (uentry_hasGlobs (gc.cont.fcn))
2522 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2526 if (uentry_hasMods (gc.cont.fcn))
2528 if (context_getFlag (FLG_MUSTMOD))
2530 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2534 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2537 ** clear file static modifies
2540 /* do this first to get unused error messages */
2542 usymtab_exitScope (exprNode_undefined);
2543 sRef_exitFunctionScope ();
2545 gc.showfunction = FALSE;
2546 gc.kind = CX_GLOBAL;
2547 gc.cont.glob = TRUE;
2549 gc.globs = globSet_new ();
2550 globSet_clear (gc.globs_used);
2551 gc.mods = sRefSet_new ();
2554 llassert (clauseStack_isEmpty (gc.clauses));
2555 llassert (gc.inclause == NOCLAUSE);
2556 DPRINTF (("After exit function: %s", context_unparse ()));
2560 context_quietExitFunction (void)
2562 while (gc.kind == CX_INNER)
2564 context_exitInnerPlain ();
2567 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2568 && !context_inIterDef () && !context_inIterEnd ())
2573 usymtab_quietExitScope (g_currentloc);
2575 gc.showfunction = FALSE;
2576 gc.kind = CX_GLOBAL;
2577 gc.cont.glob = TRUE;
2579 gc.globs = globSet_new ();
2580 globSet_clear (gc.globs_used);
2581 gc.mods = sRefSet_new ();
2583 sRef_exitFunctionScope ();
2587 /*@observer@*/ uentryList
2588 context_getParams (void)
2590 if (context_inFunctionLike ())
2592 return (uentry_getParams (gc.cont.fcn));
2596 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2597 return uentryList_undefined;
2601 /*@observer@*/ globSet
2602 context_getUsedGlobs (void)
2604 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2605 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2607 return (gc.globs_used);
2611 context_moduleName ()
2613 return (fileloc_getBase (g_currentloc));
2616 /*@observer@*/ globSet
2617 context_getGlobs (void)
2619 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2620 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2626 context_addBoolAccess (void)
2628 cstring bname = context_getString (FLG_BOOLTYPE);
2629 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2631 addModuleAccess (cstring_copy (bname), boolt);
2633 /* for sys/types (perhaps, this is bogus!) */
2634 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2639 context_canAccessBool (void)
2646 static typeId boolType = typeId_invalid;
2648 if (typeId_isInvalid (boolType))
2650 boolType = usymtab_getTypeId (context_getBoolName ());
2653 if (typeId_isInvalid (boolType)) {
2656 return (typeIdSet_member (gc.acct, boolType));
2661 /* evs 2000-07-25: old version - replaced */
2664 context_boolImplementationType () {
2665 /* For now, this is bogus! */
2670 context_canAccessBool (void)
2672 static typeId boolType = typeId_invalid;
2674 if (typeId_isInvalid (boolType))
2676 boolType = usymtab_getTypeId (context_getBoolName ());
2679 if (!typeId_isInvalid (boolType))
2681 return context_hasAccess (boolType);
2692 context_setMessageAnnote (/*@only@*/ cstring s)
2694 llassert (cstring_isUndefined (gc.msgAnnote));
2699 context_hasMessageAnnote (void)
2701 return (cstring_isDefined (gc.msgAnnote));
2705 context_clearMessageAnnote (void)
2707 if (cstring_isDefined (gc.msgAnnote))
2709 cstring_free (gc.msgAnnote);
2710 gc.msgAnnote = cstring_undefined;
2715 context_getMessageAnnote (void)
2717 cstring st = gc.msgAnnote;
2719 gc.msgAnnote = cstring_undefined;
2724 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2726 llassert (sRef_isInvalid (gc.aliasAnnote));
2727 llassert (!sRef_sameName (s, t));
2729 gc.aliasAnnoteAls = t;
2733 context_hasAliasAnnote (void)
2735 return (sRef_isValid (gc.aliasAnnote));
2739 context_clearAliasAnnote (void)
2741 gc.aliasAnnote = sRef_undefined;
2745 context_getAliasAnnote (void)
2747 sRef ret = gc.aliasAnnote;
2748 sRef als = gc.aliasAnnoteAls;
2750 llassert (sRef_isValid (ret) && sRef_isValid (als));
2752 gc.aliasAnnote = sRef_undefined;
2753 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2757 context_recordFileModifies (sRefSet mods)
2759 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2763 context_recordFileGlobals (globSet mods)
2765 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2766 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2770 context_setCommentMarkerChar (char c)
2772 llassert (c != '\0');
2774 context_setValue (FLG_COMMENTCHAR, (int) c);
2778 context_getCommentMarkerChar (void)
2780 return ((char) context_getValue (FLG_COMMENTCHAR));
2784 context_setValue (flagcode flag, int val)
2786 int index = flagcode_valueIndex (flag);
2788 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2796 llerror_flagWarning (message ("Value for %s must be a positive "
2797 "number (given %d)",
2798 flagcode_unparse (flag), val));
2801 if (flag == FLG_LINELEN && val < MINLINELEN)
2803 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2804 flagcode_unparse (flag),
2810 case FLG_INCLUDENEST:
2811 case FLG_CONTROLNESTDEPTH:
2812 case FLG_STRINGLITERALLEN:
2813 case FLG_NUMSTRUCTFIELDS:
2814 case FLG_NUMENUMMEMBERS:
2815 case FLG_INDENTSPACES:
2818 llerror_flagWarning (message ("Value for %s must be a non-negative "
2819 "number (given %d)",
2820 flagcode_unparse (flag), val));
2829 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2830 gc.values[index] = val;
2834 context_setValueAndFlag (flagcode flag, int val)
2836 gc.flags[flag] = TRUE;
2837 context_setValue (flag, val);
2841 context_getValue (flagcode flag)
2843 int index = flagcode_valueIndex (flag);
2845 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2846 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2847 return (gc.values[index]);
2851 context_getCounter (flagcode flag)
2853 int index = flagcode_valueIndex (flag);
2855 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2856 return (gc.counters[index]);
2860 context_incCounter (flagcode flag)
2862 int index = flagcode_valueIndex (flag);
2864 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2866 gc.counters[index]++;
2870 context_decCounter (flagcode flag)
2872 int index = flagcode_valueIndex (flag);
2874 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2875 gc.counters[index]--;
2878 bool context_showFunction (void)
2880 return (gc.showfunction);
2884 context_setString (flagcode flag, cstring val)
2886 int index = flagcode_stringIndex (flag);
2888 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2890 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2896 usymtab_supGlobalEntry
2897 (uentry_makeConstantValue (val, ctype_bool,
2898 fileloc_getBuiltin (), TRUE,
2899 multiVal_makeInt (1)));
2902 usymtab_supGlobalEntry
2903 (uentry_makeConstantValue (val, ctype_bool,
2904 fileloc_getBuiltin (), FALSE,
2905 multiVal_makeInt (0)));
2908 case FLG_MESSAGESTREAM:
2909 case FLG_WARNINGSTREAM:
2910 case FLG_ERRORSTREAM:
2912 if (cstring_isDefined (val))
2916 if (osd_fileExists (val))
2918 if (context_getFlag (FLG_STREAMOVERWRITE))
2920 llfatalerror (message
2921 ("Output stream file %s would overwrite existing file. "
2922 "Use -streamoverwrite if you want to allow this.",
2927 fstream = fopen (cstring_toCharsSafe (val), "w");
2929 if (fstream == NULL)
2931 llfatalerror (message ("Unable to open output stream file %s for writing",
2936 ** This ensures fstream will be closed on exit.
2939 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2943 case FLG_MESSAGESTREAM:
2944 g_messagestream = fstream;
2945 /*@innerbreak@*/ break;
2946 case FLG_WARNINGSTREAM:
2947 g_warningstream = fstream;
2948 /*@innerbreak@*/ break;
2949 case FLG_ERRORSTREAM:
2950 g_errorstream = fstream;
2951 /*@innerbreak@*/ break;
2954 /*@-statetransfer@*/
2955 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2958 case FLG_SYSTEMDIRS:
2960 llassert (cstring_isDefined (val));
2962 if (cstring_firstChar (val) == '\"')
2965 cstring tval = cstring_copy (cstring_suffix (val, 1));
2967 if (cstring_lastChar (tval) != '\"')
2969 int n = size_toInt (cstring_length (tval) - 1);
2971 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2976 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2979 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2983 cstring otval = tval;
2984 tval = cstring_prefix (tval, size_fromInt (n));
2985 cstring_free (otval);
2989 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2990 DPRINTF (("val = %s", val));
2991 cstring_free (tval);
2992 cstring_free (oval);
2999 llassert (cstring_isDefined (val));
3001 if (cstring_length (val) == 0)
3004 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
3006 else if (cstring_lastChar (val) != CONNECTCHAR)
3008 val = cstring_appendChar (val, CONNECTCHAR);
3018 ; /* Okay not handle everything in this switch */
3020 /*@i523@*/ } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */
3022 if (cstring_length (val) >= 1
3023 && cstring_firstChar (val) == '\"')
3025 llerror_flagWarning (message
3026 ("Setting %s to string beginning with \". You probably "
3027 "don't meant to have the \"'s.",
3028 flagcode_unparse (flag)));
3031 gc.strings[index] = val;
3034 static /*@exposed@*/ cstring
3035 context_exposeString (flagcode flag)
3037 int index = flagcode_stringIndex (flag);
3039 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3040 return (gc.strings[index]);
3044 context_getString (flagcode flag)
3046 return (context_exposeString (flag));
3050 context_resetErrors (void)
3055 void context_initMod (void)
3056 /*@globals undef gc; @*/
3058 gc.kind = CX_GLOBAL;
3060 gc.savekind = CX_ERROR;
3061 gc.savecont.glob = FALSE;
3063 gc.instandardlib = FALSE;
3066 gc.linesprocessed = 0;
3067 gc.speclinesprocessed = 0;
3068 gc.insuppressregion = FALSE;
3069 gc.macroMissingParams = FALSE;
3070 gc.preprocessing = FALSE;
3071 gc.incommandline = FALSE;
3072 gc.mc = macrocache_create ();
3074 gc.maxmods = DEFAULTMAXMODS;
3075 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3077 gc.library = FLG_ANSILIB;
3079 gc.locstack = filelocStack_new ();
3080 gc.modrecs = sRefSetList_undefined;
3081 gc.anyExports = FALSE;
3083 gc.ftab = fileTable_create ();
3084 gc.msgLog = messageLog_new ();
3085 gc.inimport = FALSE;
3086 gc.inDerivedFile = FALSE;
3087 gc.inheader = FALSE;
3088 gc.markers = flagMarkerList_new ();
3089 gc.cont.glob = TRUE;
3090 gc.showfunction = FALSE;
3091 gc.msgAnnote = cstring_undefined;
3092 gc.aliasAnnote = sRef_undefined;
3093 gc.aliasAnnoteAls = sRef_undefined;
3094 gc.boolType = ctype_bool;
3095 gc.mods = sRefSet_new ();
3097 gc.saveloc = fileloc_undefined;
3099 gc.inmacrocache = FALSE;
3100 gc.inclause = NOCLAUSE;
3101 gc.clauses = clauseStack_new ();
3102 gc.globs = globSet_new ();
3103 gc.nacct = typeIdSet_emptySet ();
3104 gc.acct = typeIdSet_emptySet ();
3105 gc.facct = typeIdSet_emptySet ();
3106 gc.savedFlags = FALSE;
3107 gc.pushloc = fileloc_undefined;
3108 gc.protectVars = FALSE;
3109 gc.justpopped = FALSE;
3110 gc.isNullGuarded = NO;
3111 gc.globs_used = globSet_undefined;
3115 gc.setGlobally[code] = FALSE;
3116 gc.setLocally[code] = FALSE;
3121 context_resetAllFlags ();
3123 assertSet (gc.flags); /* Can't use global in defines */
3124 assertSet (gc.saveflags);
3125 assertSet (gc.values);
3126 assertSet (gc.strings);
3128 conext_resetAllCounters ();
3129 assertSet (gc.counters);
3131 context_setMode (DEFAULT_MODE);
3133 gc.stateTable = metaStateTable_create ();
3134 gc.annotTable = annotationTable_create ();
3136 gc.inFunctionHeader = FALSE;
3138 DPRINTF (("Annotations: \n%s",
3139 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3140 DPRINTF (("State: \n%s",
3141 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3146 context_typeofZero (void)
3148 ctype ct = ctype_int;
3150 if (context_getFlag (FLG_ZEROPTR))
3152 ct = ctype_makeConj (ct, ctype_voidPointer);
3155 if (context_getFlag (FLG_ZEROBOOL)) {
3156 ct = ctype_makeConj (ct, ctype_bool);
3163 context_typeofOne (void)
3165 ctype ct = ctype_int;
3167 /* 1 is on longer a bool (was before 2.4)
3168 if (!context_getFlag (FLG_ABSTRACTBOOL))
3170 ct = ctype_makeConj (ct, ctype_bool);
3178 context_unparse (void)
3185 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3188 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3191 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3194 s = message ("Inner Context [%d] : %q",
3196 fileloc_unparse (g_currentloc));
3199 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3200 uentry_unparse (gc.cont.fcn),
3201 fileloc_unparse (g_currentloc),
3202 typeIdSet_unparse (gc.acct),
3203 sRefSet_unparse (gc.mods));
3206 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3208 case CX_UNKNOWNMACRO:
3209 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3212 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3215 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3218 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3220 case CX_FCNDECLARATION:
3221 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3224 s = message ("Un-unparseable context: %d", (int) gc.kind);
3228 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3233 context_currentFunctionType (void)
3235 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3237 return (uentry_getType (gc.cont.fcn));
3239 else if (gc.kind == CX_INNER)
3241 llcontbuglit ("context_currentFunctionType: inner context");
3242 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3243 return (context_currentFunctionType ());
3247 llcontbuglit ("context_currentFunctionType: not in function");
3248 return (ctype_undefined);
3253 context_enterInnerContext (void)
3255 if (context_getFlag (FLG_GRAMMAR))
3257 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3260 if (gc.kind == CX_GLOBAL)
3265 else if (gc.kind == CX_INNER)
3274 usymtab_enterScope ();
3275 pushClause (NOCLAUSE);
3279 context_exitInnerPlain (void) /*@modifies gc;@*/
3281 context_exitInner (exprNode_undefined);
3285 context_exitInner (exprNode exp)
3287 if (context_getFlag (FLG_GRAMMAR))
3289 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3292 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3293 ("inclause = %s", clause_nameTaken (gc.inclause)));
3295 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3296 gc.inclause = topClause (gc.clauses);
3298 if (gc.kind == CX_INNER)
3300 if (--gc.cont.cdepth == 0)
3302 gc.kind = CX_GLOBAL;
3303 gc.cont.glob = TRUE;
3308 if (gc.kind == CX_GLOBAL)
3310 llcontbuglit ("Attempt to exit global context");
3315 usymtab_exitScope (exp);
3320 context_enterStructInnerContext (void)
3322 if (context_getFlag (FLG_GRAMMAR))
3324 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3327 if (gc.kind == CX_GLOBAL)
3332 else if (gc.kind == CX_INNER)
3341 usymtab_enterScope ();
3343 if (context_getFlag (FLG_GRAMMAR))
3345 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3350 context_exitStructInnerContext (void)
3352 if (context_getFlag (FLG_GRAMMAR))
3354 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3357 if (gc.kind == CX_INNER)
3359 if (gc.cont.cdepth <= 0)
3361 llcontbuglit ("Attempt to exit inner context with no depth");
3362 gc.kind = CX_GLOBAL;
3363 gc.cont.glob = TRUE;
3369 if (gc.cont.cdepth == 0)
3371 gc.kind = CX_GLOBAL;
3372 gc.cont.glob = TRUE;
3378 if (gc.kind == CX_GLOBAL)
3380 llcontbuglit ("Attempt to exit global context");
3385 usymtab_exitScope (exprNode_undefined);
3387 if (context_getFlag (FLG_GRAMMAR))
3389 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3394 context_exitInnerSafe (void)
3396 if (context_getFlag (FLG_GRAMMAR))
3398 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3401 if (gc.kind == CX_INNER)
3403 if (--gc.cont.cdepth <= 0)
3408 else if (gc.kind == CX_GLOBAL)
3410 llcontbuglit ("Attempt to exit global context");
3415 if (usymtab_inDeepScope ())
3417 usymtab_exitScope (exprNode_undefined);
3423 void setModuleAccess (void)
3425 gc.facct = typeIdSet_emptySet ();
3427 if (fileId_isValid (currentFile ()))
3429 cstring baseName = fileloc_getBase (g_currentloc);
3431 if (context_getFlag (FLG_ACCESSFILE))
3433 if (usymtab_existsType (baseName))
3435 gc.facct = typeIdSet_insert (gc.facct,
3436 usymtab_getTypeId (baseName));
3444 if (context_getFlag (FLG_ACCESSMODULE))
3447 bool hasaccess = FALSE;
3449 for (i = 0; i < gc.nmods; i++)
3451 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3453 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3462 gc.inheader = fileId_isHeader (currentFile ());
3466 llcontbuglit ("Current file not defined\n");
3467 gc.facct = typeIdSet_emptySet ();
3469 gc.inheader = FALSE;
3472 /* 17 Jan 1995: forgot to clear nacct */
3474 gc.nacct = typeIdSet_emptySet ();
3478 context_enterFileAux (void)
3484 context_enterFile (void)
3486 context_enterFileAux ();
3487 usymtab_enterFile ();
3491 context_enterMacroFile (void)
3493 context_enterFileAux ();
3497 context_inFunction (void)
3499 kcontext ck = gc.kind;
3501 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3505 context_inFunctionLike (void)
3507 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3508 || gc.kind == CX_FCNDECLARATION
3509 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3513 context_inRealFunction (void)
3515 kcontext ck = gc.kind;
3517 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3521 context_processAllMacros (void)
3523 usymtab_enterFile ();
3525 gc.inmacrocache = TRUE;
3526 macrocache_processUndefinedElements (gc.mc);
3528 usymtab_exitFile ();
3530 gc.inmacrocache = FALSE;
3531 macrocache_finalize ();
3535 ** this happens once at the end of each C file
3537 ** check each Macro that was defined in current file.c or current file.h
3542 context_processMacros (void)
3544 if (fileId_isValid (currentFile ()))
3547 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3549 gc.inmacrocache = TRUE;
3551 DPRINTF (("Processing macros: %s", cbase));
3552 lastfl = macrocache_processFileElements (gc.mc, cbase);
3553 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3555 cstring_free (cbase);
3557 if (fileloc_isDefined (lastfl))
3559 g_currentloc = fileloc_update (g_currentloc, lastfl);
3563 gc.inmacrocache = FALSE;
3568 context_processingMacros (void)
3570 return (gc.inmacrocache);
3574 context_exitCFile (void)
3576 if (gc.kind != CX_GLOBAL)
3579 (cstring_makeLiteral ("File ended outside global scope"));
3582 if (gc.insuppressregion)
3584 /* gack...don't reverse the order of these lines! ;-> */
3585 gc.insuppressregion = FALSE;
3586 llerrorlit (FLG_SYNTAX,
3587 "File ended in ignore errors region, "
3588 "possible missing /*@end*/");
3591 /* fix up parse errors */
3593 while (!usymtab_inFileScope ())
3595 usymtab_quietExitScope (g_currentloc);
3599 ** Clear the file-specific modifies information.
3602 sRefSetList_elements (gc.modrecs, mods)
3604 sRefSet_clearStatics (mods);
3605 } end_sRefSetList_elements ;
3607 sRefSetList_clear (gc.modrecs);
3609 context_processMacros ();
3612 usymtab_exitFile ();
3614 gc.inDerivedFile = FALSE;
3615 filelocStack_clear (gc.locstack);
3617 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3619 gc.cont.glob = TRUE;
3623 context_restoreFlagSettings ();
3624 gc.savedFlags = FALSE;
3628 DPRINTF (("After exiting file: "));
3629 usymtab_printAll ();
3634 context_exitMacroCache (void)
3636 if (gc.kind != CX_GLOBAL)
3638 if (context_inMacro ())
3639 /* this is okay, file could end without newline in macro */
3641 DPRINTF (("Still in macro: %s",
3642 context_unparse ()));
3643 context_exitFunction ();
3647 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3648 context_unparse ()));
3649 gc.kind = CX_GLOBAL;
3654 ** no longer valid here
3655 ** if (gc.insuppressregion)
3657 ** gc.insuppressregion = FALSE;
3658 ** llerror ("File ended in ignore errors region, possible missing @");
3662 gc.cont.glob = TRUE;
3666 context_saveLocation (void)
3668 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3669 fileloc_free (gc.saveloc);
3670 gc.saveloc = fileloc_copy (g_currentloc);
3674 context_getSaveLocation (void)
3676 fileloc fl = gc.saveloc;
3677 gc.saveloc = fileloc_undefined;
3681 /*@observer@*/ cstring
3682 context_inFunctionName (void)
3684 if (gc.kind == CX_FUNCTION
3685 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3686 || gc.kind == CX_MACROCONST
3687 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3689 return (uentry_rawName (gc.cont.fcn));
3693 llcontbuglit ("context_inFunctionName: not in function");
3694 return (cstring_undefined);
3699 context_userSetFlag (flagcode f, bool b)
3701 DPRINTF (("set flag: %s / %s",
3702 flagcode_unparse (f),
3703 bool_unparse (context_getFlag (f))));
3705 if (f == FLG_NEVERINCLUDE && b)
3707 if (gc.flags[FLG_EXPORTHEADER])
3710 (cstring_makeLiteral
3711 ("Setting +neverinclude after +exportheader. "
3712 "Turning off exportheader, since headers are not checked "
3713 "when +neverinclude is used."));
3715 gc.flags[FLG_EXPORTHEADER] = FALSE;
3720 if (f == FLG_EXPORTHEADER && b)
3722 if (gc.flags[FLG_NEVERINCLUDE])
3725 (cstring_makeLiteral
3726 ("Setting +exportheader after +neverinclude. "
3727 "Not setting exportheader, since headers are not checked "
3728 "when +neverinclude is used."));
3729 gc.flags[FLG_EXPORTHEADER] = FALSE;
3735 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3737 bool lastsetting = context_getFlag (f);
3739 if (bool_equal (lastsetting, b)
3740 && !flagcode_isSpecialFlag (f)
3741 && !flagcode_isIdemFlag (f)
3742 && !flagcode_hasArgument (f))
3745 (message ("Setting %s%s redundant with current value",
3746 cstring_makeLiteralTemp (b ? "+" : "-"),
3747 flagcode_unparse (f)));
3751 if (flagcode_isWarnUseFlag (f) && b)
3753 if (!context_getFlag (FLG_WARNUSE))
3756 (message ("Flag +%s is canceled by -warnuse",
3757 flagcode_unparse (f)));
3762 if (flagcode_isLibraryFlag (f))
3764 if (gc.library != FLG_ANSILIB
3768 (message ("Selecting library %s after library %s was "
3769 "selected (only one library may be used)",
3770 flagcode_unparse (f),
3771 flagcode_unparse (gc.library)));
3774 if (f == FLG_UNIXLIB)
3776 if (context_getFlag (FLG_WARNUNIXLIB))
3779 (cstring_makeLiteral
3780 ("Selecting unix library. Unix library is "
3781 "ad hoc addition to POSIX library. Recommend "
3782 "use +posixlib to select POSIX library instead. "
3783 "Use -warnunixlib to suppress this message."));
3790 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3794 ("Setting +%s will not produce warnings with -namechecks. "
3795 "Must set +namechecks also.",
3796 flagcode_unparse (f)));
3799 gc.setGlobally[f] = TRUE;
3800 context_setFlag (f, b, g_currentloc);
3804 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3808 context_saveFlagSettings ();
3811 if (ynm_isOff (set))
3813 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3815 else if (ynm_isOn (set))
3817 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3818 gc.setLocally[f] = TRUE;
3822 context_restoreFlag (f, loc);
3827 context_restoreFlag (flagcode f, fileloc loc)
3833 message ("Attempt to restore flag %s when no file scope flags "
3835 flagcode_unparse (f)),
3840 context_addFlagMarker (f, MAYBE, loc);
3841 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3847 context_setFlag (flagcode f, bool b, fileloc loc)
3849 context_setFlagAux (f, b, FALSE, FALSE, loc);
3853 context_setFlagTemp (flagcode f, bool b)
3855 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3860 # define DOSET(ff,b) \
3861 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3862 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3863 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3864 gc.flags[ff] = b; } while (FALSE)
3867 context_setFlagAux (flagcode f, bool b, bool inFile,
3868 /*@unused@*/ bool isRestore, fileloc loc)
3870 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3873 ** Removed test for special flags.
3876 if (flagcode_isIdemFlag (f))
3885 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3887 if (b) /* Turing higher level on, turns on all lower levels */
3891 case FLG_ITS4MOSTRISKY:
3892 DOSET (FLG_ITS4VERYRISKY, b);
3894 case FLG_ITS4VERYRISKY:
3895 DOSET (FLG_ITS4RISKY, b);
3898 DOSET (FLG_ITS4MODERATERISK, b);
3900 case FLG_ITS4MODERATERISK:
3901 DOSET (FLG_ITS4LOWRISK, b);
3903 case FLG_ITS4LOWRISK:
3908 else /* Turning level off, turns off all higher levels */
3912 case FLG_ITS4LOWRISK:
3913 DOSET (FLG_ITS4MODERATERISK, b);
3915 case FLG_ITS4MODERATERISK:
3916 DOSET (FLG_ITS4RISKY, b);
3919 DOSET (FLG_ITS4VERYRISKY, b);
3921 case FLG_ITS4VERYRISKY:
3922 DOSET (FLG_ITS4MOSTRISKY, b);
3924 case FLG_ITS4MOSTRISKY:
3933 case FLG_MESSAGESTREAMSTDOUT:
3934 g_messagestream = stdout;
3936 case FLG_MESSAGESTREAMSTDERR:
3937 g_messagestream = stderr;
3939 case FLG_WARNINGSTREAMSTDOUT:
3940 g_warningstream = stdout;
3942 case FLG_WARNINGSTREAMSTDERR:
3943 g_warningstream = stderr;
3945 case FLG_ERRORSTREAMSTDOUT:
3946 g_errorstream = stdout;
3948 case FLG_ERRORSTREAMSTDERR:
3949 g_errorstream = stderr;
3952 DOSET (FLG_ALLEMPTY, b);
3953 DOSET (FLG_IFEMPTY, b);
3954 DOSET (FLG_WHILEEMPTY, b);
3955 DOSET (FLG_FOREMPTY, b);
3958 DOSET (FLG_PREDBOOL, b);
3959 DOSET (FLG_PREDBOOLINT, b);
3960 DOSET (FLG_PREDBOOLPTR, b);
3961 DOSET (FLG_PREDBOOLOTHERS, b);
3964 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3965 DOSET (FLG_CHECKEDGLOBALIAS, b);
3966 DOSET (FLG_CHECKMODGLOBALIAS, b);
3967 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3970 DOSET (FLG_ALLBLOCK, b);
3971 DOSET (FLG_IFBLOCK, b);
3972 DOSET (FLG_WHILEBLOCK, b);
3973 DOSET (FLG_FORBLOCK, b);
3987 DOSET (FLG_GRAMMAR, b);
3989 case FLG_CODEIMPONLY:
3990 DOSET (FLG_CODEIMPONLY, b);
3991 DOSET (FLG_GLOBIMPONLY, b);
3992 DOSET (FLG_RETIMPONLY, b);
3993 DOSET (FLG_STRUCTIMPONLY, b);
3995 case FLG_SPECALLIMPONLY:
3996 DOSET (FLG_SPECALLIMPONLY, b);
3997 DOSET (FLG_SPECGLOBIMPONLY, b);
3998 DOSET (FLG_SPECRETIMPONLY, b);
3999 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4001 case FLG_ALLIMPONLY:
4002 DOSET (FLG_ALLIMPONLY, b);
4003 DOSET (FLG_GLOBIMPONLY, b);
4004 DOSET (FLG_RETIMPONLY, b);
4005 DOSET (FLG_STRUCTIMPONLY, b);
4006 DOSET (FLG_SPECGLOBIMPONLY, b);
4007 DOSET (FLG_SPECRETIMPONLY, b);
4008 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4010 case FLG_ANSI89LIMITS:
4011 DOSET (FLG_ANSI89LIMITS, b);
4012 DOSET (FLG_CONTROLNESTDEPTH, b);
4013 DOSET (FLG_STRINGLITERALLEN, b);
4014 DOSET (FLG_INCLUDENEST, b);
4015 DOSET (FLG_NUMSTRUCTFIELDS, b);
4016 DOSET (FLG_NUMENUMMEMBERS, b);
4020 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4021 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4022 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4023 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4024 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4025 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4026 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4029 case FLG_ISO99LIMITS:
4030 DOSET (FLG_ISO99LIMITS, b);
4031 DOSET (FLG_CONTROLNESTDEPTH, b);
4032 DOSET (FLG_STRINGLITERALLEN, b);
4033 DOSET (FLG_INCLUDENEST, b);
4034 DOSET (FLG_NUMSTRUCTFIELDS, b);
4035 DOSET (FLG_NUMENUMMEMBERS, b);
4039 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4040 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4041 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4042 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4043 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4044 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4045 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4048 case FLG_EXTERNALNAMELEN:
4049 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4050 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4052 case FLG_INTERNALNAMELEN:
4053 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4054 DOSET (FLG_INTERNALNAMELEN, TRUE);
4056 case FLG_EXTERNALNAMECASEINSENSITIVE:
4057 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4059 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4061 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4062 context_setValue (FLG_EXTERNALNAMELEN, 0);
4065 case FLG_INTERNALNAMECASEINSENSITIVE:
4066 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4068 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4070 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4071 context_setValue (FLG_INTERNALNAMELEN, 0);
4074 case FLG_INTERNALNAMELOOKALIKE:
4075 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4077 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4079 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4080 context_setValue (FLG_INTERNALNAMELEN, 0);
4084 DOSET (FLG_MODNOMODS, b);
4085 DOSET (FLG_MODGLOBSUNSPEC, b);
4086 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4089 DOSET (FLG_EXPORTVAR, b);
4090 DOSET (FLG_EXPORTFCN, b);
4091 DOSET (FLG_EXPORTTYPE, b);
4092 DOSET (FLG_EXPORTMACRO, b);
4093 DOSET (FLG_EXPORTCONST, b);
4094 gc.anyExports = TRUE;
4097 DOSET (FLG_RETEXPOSE, b);
4098 DOSET (FLG_ASSIGNEXPOSE, b);
4099 DOSET (FLG_CASTEXPOSE, b);
4102 DOSET (FLG_RETVALBOOL, b);
4103 DOSET (FLG_RETVALINT, b);
4104 DOSET (FLG_RETVALOTHER, b);
4109 DOSET (FLG_EXPORTLOCAL, FALSE);
4110 DOSET (FLG_DECLUNDEF, FALSE);
4111 DOSET (FLG_SPECUNDEF, FALSE);
4112 DOSET (FLG_TOPUNUSED, FALSE);
4116 DOSET (FLG_LOOPLOOPBREAK, b);
4117 DOSET (FLG_LOOPSWITCHBREAK, b);
4118 DOSET (FLG_SWITCHLOOPBREAK, b);
4119 DOSET (FLG_SWITCHSWITCHBREAK, b);
4120 DOSET (FLG_LOOPLOOPCONTINUE, b);
4121 DOSET (FLG_DEEPBREAK, b);
4124 DOSET (FLG_FORLOOPEXEC, b);
4125 DOSET (FLG_WHILELOOPEXEC, b);
4126 DOSET (FLG_ITERLOOPEXEC, b);
4129 DOSET (FLG_ACCESSMODULE, b);
4130 DOSET (FLG_ACCESSFILE, b);
4131 DOSET (FLG_ACCESSCZECH, b);
4134 DOSET (FLG_ALLMACROS, b);
4135 DOSET (FLG_FCNMACROS, b);
4136 DOSET (FLG_CONSTMACROS, b);
4139 DOSET (FLG_BOUNDSREAD, b);
4140 DOSET (FLG_BOUNDSWRITE, b);
4143 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4144 DOSET (FLG_CZECHFUNCTIONS, b);
4145 DOSET (FLG_CZECHVARS, b);
4146 DOSET (FLG_CZECHCONSTANTS, b);
4147 DOSET (FLG_CZECHTYPES, b);
4150 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4151 DOSET (FLG_SLOVAKFUNCTIONS, b);
4152 DOSET (FLG_SLOVAKVARS, b);
4153 DOSET (FLG_SLOVAKCONSTANTS, b);
4154 DOSET (FLG_SLOVAKTYPES, b);
4156 case FLG_CZECHOSLOVAK:
4157 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4158 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4159 DOSET (FLG_CZECHOSLOVAKVARS, b);
4160 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4161 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4164 DOSET (FLG_NULLSTATE, b);
4165 DOSET (FLG_NULLDEREF, b);
4166 DOSET (FLG_NULLASSIGN, b);
4167 DOSET (FLG_NULLPASS, b);
4168 DOSET (FLG_NULLRET, b);
4171 DOSET (FLG_MUSTFREEONLY, b);
4172 DOSET (FLG_MUSTFREEFRESH, b);
4175 DOSET (FLG_NULLSTATE, b);
4176 DOSET (FLG_NULLDEREF, b);
4177 DOSET (FLG_NULLASSIGN, b);
4178 DOSET (FLG_NULLPASS, b);
4179 DOSET (FLG_NULLRET, b);
4180 DOSET (FLG_COMPDEF, b);
4181 DOSET (FLG_COMPMEMPASS, b);
4182 DOSET (FLG_UNIONDEF, b);
4183 DOSET (FLG_MEMTRANS, b);
4184 DOSET (FLG_USERELEASED, b);
4185 DOSET (FLG_ALIASUNIQUE, b);
4186 DOSET (FLG_MAYALIASUNIQUE, b);
4187 DOSET (FLG_MUSTFREEONLY, b);
4188 DOSET (FLG_MUSTFREEFRESH, b);
4189 DOSET (FLG_MUSTDEFINE, b);
4190 DOSET (FLG_GLOBSTATE, b);
4191 DOSET (FLG_COMPDESTROY, b);
4192 DOSET (FLG_MUSTNOTALIAS, b);
4193 DOSET (FLG_MEMIMPLICIT, b);
4194 DOSET (FLG_BRANCHSTATE, b);
4195 /*@fallthrough@*/ /* also sets memtrans flags */
4197 DOSET (FLG_MEMTRANS, b);
4198 DOSET (FLG_EXPOSETRANS, b);
4199 DOSET (FLG_OBSERVERTRANS, b);
4200 DOSET (FLG_DEPENDENTTRANS, b);
4201 DOSET (FLG_NEWREFTRANS, b);
4202 DOSET (FLG_ONLYTRANS, b);
4203 DOSET (FLG_OWNEDTRANS, b);
4204 DOSET (FLG_FRESHTRANS, b);
4205 DOSET (FLG_SHAREDTRANS, b);
4206 DOSET (FLG_TEMPTRANS, b);
4207 DOSET (FLG_KEPTTRANS, b);
4208 DOSET (FLG_REFCOUNTTRANS, b);
4209 DOSET (FLG_STATICTRANS, b);
4210 DOSET (FLG_UNKNOWNTRANS, b);
4211 DOSET (FLG_KEEPTRANS, b);
4212 DOSET (FLG_IMMEDIATETRANS, b);
4219 if (b && !gc.anyExports
4220 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4221 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4222 || f == FLG_EXPORTCONST
4223 || f == FLG_EXPORTANY))
4225 gc.anyExports = TRUE;
4230 context_maybeSet (flagcode d)
4232 return (gc.flags[d] || gc.setLocally[d]);
4236 context_getFlag (flagcode d)
4238 return (gc.flags[d]);
4242 context_flagOn (flagcode f, fileloc loc)
4244 return (!context_suppressFlagMsg (f, loc));
4247 static void context_saveFlagSettings (void)
4249 gc.savedFlags = TRUE;
4250 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4251 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4254 static void context_restoreFlagSettings (void)
4256 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4257 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4258 gc.savedFlags = FALSE;
4261 void context_setFilename (fileId fid, int lineno)
4262 /*@globals fileloc g_currentloc;@*/
4263 /*@modifies g_currentloc@*/
4265 if (fileId_baseEqual (currentFile (), fid))
4272 fileloc_setColumn (g_currentloc, 0);
4274 if (fileloc_isSpecialFile (g_currentloc))
4276 gc.inDerivedFile = TRUE;
4279 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4281 int maxdepth = context_getValue (FLG_INCLUDENEST);
4283 if (filelocStack_size (gc.locstack) > maxdepth)
4285 int depth = filelocStack_includeDepth (gc.locstack);
4287 if (depth > maxdepth)
4291 message ("Maximum include nesting depth "
4292 "(%d, current depth %d) exceeded",
4295 filelocStack_nextTop (gc.locstack)))
4297 filelocStack_printIncludes (gc.locstack);
4303 g_currentloc = fileloc_create (fid, lineno, 1);
4304 gc.inheader = fileId_isHeader (currentFile ());
4306 context_enterFileAux ();
4310 void context_enterIterDef (/*@observer@*/ uentry le)
4312 context_enterMacro (le);
4313 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4314 gc.kind = CX_ITERDEF;
4317 void context_enterIterEnd (/*@observer@*/ uentry le)
4319 context_enterMacro (le);
4320 gc.kind = CX_ITEREND;
4324 context_destroyMod (void)
4325 /*@globals killed gc@*/
4329 ctype_destroyMod ();
4336 fileTable_free (gc.ftab);
4337 gc.ftab = fileTable_undefined;
4339 filelocStack_free (gc.locstack);
4342 macrocache_free (gc.mc);
4344 /* evans 2002-07-12: not reported because of reldef */
4345 for (i = 0; i < gc.nmods; i++)
4347 cstring_free (gc.moduleaccess[i].file);
4350 sfree (gc.moduleaccess);
4353 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4354 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4357 sRefSetList_free (gc.modrecs);
4359 flagMarkerList_free (gc.markers);
4361 messageLog_free (gc.msgLog);
4363 clauseStack_free (gc.clauses);
4366 cstring_free (gc.msgAnnote);
4367 globSet_free (gc.globs_used);
4368 metaStateTable_free (gc.stateTable);
4369 annotationTable_free (gc.annotTable);
4378 bool context_msgBoolInt (void)
4380 return context_flagOn (FLG_BOOLINT, g_currentloc);
4383 bool context_msgCharInt (void)
4385 return context_flagOn (FLG_CHARINT, g_currentloc);
4388 bool context_msgEnumInt (void)
4390 return context_flagOn (FLG_ENUMINT, g_currentloc);
4393 bool context_msgLongInt (void)
4395 return context_flagOn (FLG_LONGINT, g_currentloc);
4398 bool context_msgShortInt (void)
4400 return context_flagOn (FLG_SHORTINT, g_currentloc);
4403 bool context_msgPointerArith (void)
4405 return context_flagOn (FLG_POINTERARITH, g_currentloc);
4408 bool context_msgStrictOps (void)
4410 return context_flagOn (FLG_STRICTOPS, g_currentloc);
4413 bool context_msgLh (void)
4415 return gc.flags [FLG_DOLH];
4418 void context_pushLoc (void)
4420 fileloc_free (gc.pushloc);
4421 gc.pushloc = gc.saveloc;
4422 gc.saveloc = fileloc_undefined;
4425 void context_popLoc (void)
4427 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4430 bool context_inGlobalScope (void)
4432 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4435 bool context_inInnerScope (void)
4437 return (gc.kind == CX_INNER);
4440 void context_setProtectVars (void)
4442 gc.protectVars = TRUE;
4445 bool context_anyErrors (void)
4447 return (gc.numerrors > 0);
4450 void context_hasError (void)
4453 DPRINTF (("num errors: %d", gc.numerrors));
4456 int context_numErrors (void)
4458 return gc.numerrors;
4461 bool context_neednl (void)
4466 void context_setNeednl (void)
4471 int context_getExpect (void)
4473 return (context_getValue (FLG_EXPECT));
4476 int context_getLCLExpect (void)
4478 return (context_getValue (FLG_LCLEXPECT));
4481 int context_getLimit (void)
4483 return (context_getValue (FLG_LIMIT));
4486 bool context_unlimitedMessages (void)
4488 return (context_getLimit () < 0);
4491 void context_releaseVars (void)
4493 llassert (gc.protectVars);
4494 gc.protectVars = FALSE;
4497 void context_sizeofReleaseVars (void)
4499 /* If there is a nested sizeof, this might not hold:
4500 llassert (gc.protectVars);
4503 gc.protectVars = FALSE;
4506 bool context_inProtectVars (void)
4508 return (gc.protectVars);
4511 void context_hideShowscan (void)
4513 gc.flags[FLG_SHOWSCAN] = FALSE;
4516 void context_unhideShowscan (void)
4518 gc.flags[FLG_SHOWSCAN] = TRUE;
4521 bool context_inHeader (void)
4523 return (gc.inheader);
4526 fileTable context_fileTable (void)
4531 cstring context_tmpdir (void)
4533 return (context_getString (FLG_TMPDIR));
4536 messageLog context_messageLog (void)
4541 bool context_inMacroFunction (void)
4543 return (gc.kind == CX_MACROFCN);
4546 bool context_inMacroConstant (void)
4548 return (gc.kind == CX_MACROCONST);
4551 bool context_inUnknownMacro (void)
4553 return (gc.kind == CX_UNKNOWNMACRO);
4556 void context_setShownFunction (void)
4558 gc.showfunction = FALSE;
4561 bool context_doDump (void)
4563 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4566 bool context_doMerge (void)
4568 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4571 cstring context_getDump (void)
4573 return context_getString (FLG_DUMP);
4576 cstring context_getMerge (void)
4578 return context_getString (FLG_MERGE);
4581 bool context_inLCLLib (void)
4583 return (gc.kind == CX_LCLLIB);
4586 bool context_inImport (void)
4588 return (gc.inimport);
4591 void context_enterImport (void)
4596 void context_leaveImport (void)
4598 gc.inimport = FALSE;
4601 bool context_inMacro (void)
4603 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4604 || gc.kind == CX_UNKNOWNMACRO
4605 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4608 bool context_inIterDef (void)
4610 return (gc.kind == CX_ITERDEF);
4613 bool context_inIterEnd (void)
4615 return (gc.kind == CX_ITEREND);
4618 int context_getLinesProcessed (void)
4620 return (gc.linesprocessed);
4623 int context_getSpecLinesProcessed (void)
4625 return (gc.speclinesprocessed);
4628 void context_processedSpecLine (void)
4630 gc.speclinesprocessed++;
4633 void context_resetSpecLines (void)
4635 gc.speclinesprocessed = 0;
4639 bool context_inGlobalContext (void)
4641 return (gc.kind == CX_GLOBAL);
4644 static void context_quietExitScopes (void)
4647 ** Try to restore the global scope (after an error).
4650 while (!usymtab_inFileScope ())
4652 usymtab_quietExitScope (g_currentloc);
4655 gc.cont.glob = TRUE;
4656 gc.kind = CX_GLOBAL;
4659 void context_checkGlobalScope (void)
4661 if (gc.kind != CX_GLOBAL)
4663 if (context_inMacro ())
4665 ; /* evans 2001-10-14: Okay to be in a macro here! */
4669 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4670 context_quietExitScopes ();
4675 void context_setFileId (fileId s)
4677 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4680 bool context_setBoolName (void)
4682 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4686 cstring context_printBoolName (void)
4688 if (context_setBoolName ())
4690 return context_getBoolName ();
4694 return cstring_makeLiteralTemp ("boolean");
4698 cstring context_getBoolName (void)
4700 return (context_getString (FLG_BOOLTYPE));
4703 cstring context_getFalseName (void)
4705 return (context_getString (FLG_BOOLFALSE));
4708 cstring context_getTrueName (void)
4710 return (context_getString (FLG_BOOLTRUE));
4713 cstring context_getLarchPath (void)
4715 return (context_getString (FLG_LARCHPATH));
4718 cstring context_getLCLImportDir (void)
4720 return (context_getString (FLG_LCLIMPORTDIR));
4723 static void context_setJustPopped (void)
4725 gc.justpopped = TRUE;
4728 void context_clearJustPopped (void)
4730 gc.justpopped = FALSE;
4733 bool context_justPopped (void)
4735 return (gc.justpopped);
4738 void context_setMacroMissingParams (void)
4740 gc.macroMissingParams = TRUE;
4743 void context_resetMacroMissingParams (void)
4745 gc.macroMissingParams = FALSE;
4748 bool context_isMacroMissingParams (void)
4750 return (gc.macroMissingParams);
4753 void context_showFilelocStack (void)
4755 filelocStack_printIncludes (gc.locstack);
4758 metaStateTable context_getMetaStateTable (void)
4760 return gc.stateTable;
4763 metaStateInfo context_lookupMetaStateInfo (cstring key)
4765 return metaStateTable_lookup (gc.stateTable, key);
4768 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4770 annotationInfo ainfo;
4772 ainfo = annotationTable_lookup (gc.annotTable, annot);
4777 void context_addAnnotation (annotationInfo ainfo)
4779 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4783 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4784 annotationInfo_getLoc (ainfo));
4786 annotationInfo_free (ainfo);
4790 annotationTable_insert (gc.annotTable, ainfo);
4794 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4796 if (metaStateTable_contains (gc.stateTable, mname))
4800 message ("Duplicate metastate declaration: %s", mname),
4801 metaStateInfo_getLoc (msinfo));
4802 cstring_free (mname);
4803 metaStateInfo_free (msinfo);
4807 DPRINTF (("Adding meta state: %s", mname));
4808 metaStateTable_insert (gc.stateTable, mname, msinfo);
4812 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4814 if (metaStateTable_size (gc.stateTable) > 0)
4816 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4817 /*@i32 should use smaller value... */
4818 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4820 metaStateTable_elements (gc.stateTable, msname, msi)
4822 mtContextNode context = metaStateInfo_getContext (msi);
4824 if (mtContextNode_matchesRefStrict (context, s))
4826 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4827 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4831 cstring_copy (metaStateInfo_getName (msi)),
4832 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4833 stateInfo_copy (sinfo)));
4837 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4840 end_metaStateTable_elements ;
4842 stateInfo_free (sinfo);
4843 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4848 stateInfo_free (sinfo);
4849 return valueTable_undefined;
4853 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4855 if (metaStateTable_size (gc.stateTable) > 0)
4857 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4858 /*@i32 should use smaller value... */
4860 metaStateTable_elements (gc.stateTable, msname, msi)
4862 /*@i23 only add global...*/
4863 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4864 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4866 valueTable_insert (res,
4867 cstring_copy (metaStateInfo_getName (msi)),
4868 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4869 stateInfo_copy (sinfo)));
4871 end_metaStateTable_elements ;
4873 stateInfo_free (sinfo);
4874 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4879 stateInfo_free (sinfo);
4880 return valueTable_undefined;
4885 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4889 static ctype lastStruct;
4891 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4897 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4903 ** Why is this stuff in context.c?
4906 /*@unused@*/ static int sInfoNum = 0;
4910 /*@unused@*/ uentry ue;
4911 /*@unused@*/ sRef s;
4915 /*@unused@*/ ctype ct;
4916 /*@unused@*/ constraintList inv;
4917 /*@unused@*/ int ngetUe;
4918 /*@unused@*/ struct getUe * t ;
4921 /* unused: static struct sInfo globalStructInfo; */
4923 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4924 stable release of splint. I coomented them out so that they won't break anything
4925 but didn't delete them because they will be fixed and included later
4932 void context_setGlobalStructInfo(ctype ct, constraintList list)
4938 f = ctype_getFields (ct);
4940 if (constraintList_isDefined(list) )
4942 globalStructInfo.ct = ct;
4943 globalStructInfo.inv = list;
4945 globalStructInfo.ngetUe = 0;
4947 /* abstraction violation fix it * /
4948 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4950 globalStructInfo.ngetUe = f->nelements;
4954 uentryList_elements(f, ue)
4956 globalStructInfo.t[i].ue = ue;
4957 globalStructInfo.t[i].s = uentry_getSref(ue);
4958 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4959 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4964 end_uentryList_elements;
4973 bool hasInvariants (ctype ct) /*@* /
4975 if ( ctype_sameName(globalStructInfo.ct, ct) )