2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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"
46 extern /*@external@*/ int yydebug;
47 extern /*@external@*/ int mtdebug;
59 CX_FUNCTION, CX_FCNDECLARATION,
60 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
61 CX_ITERDEF, CX_ITEREND,
62 CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
63 CX_LCL, CX_LCLLIB, CX_MT
69 int speclinesprocessed;
71 flagMarkerList markers;
74 ** used to record state where a macro must match a function name
75 ** (i.e., no params were listed in the macro definition
78 bool macroMissingParams BOOLBITS;
79 bool preprocessing BOOLBITS;
80 bool incommandline BOOLBITS;
81 bool insuppressregion BOOLBITS;
82 bool inDerivedFile BOOLBITS;
83 bool instandardlib BOOLBITS;
84 bool inimport BOOLBITS;
85 bool inheader BOOLBITS;
86 bool inmacrocache BOOLBITS;
87 bool protectVars BOOLBITS;
89 bool showfunction BOOLBITS;
90 bool savedFlags BOOLBITS;
91 bool justpopped BOOLBITS;
92 bool anyExports BOOLBITS;
93 bool inFunctionHeader BOOLBITS;
106 filelocStack locstack;
109 /*@observer@*/ sRef aliasAnnote;
110 /*@observer@*/ sRef aliasAnnoteAls;
114 /*@observer@*/ sRefSet mods;
116 /* file access types */
119 /* local access types (this function) */
122 /* no access types (@noaccess) */
125 /*@observer@*/ globSet globs;
126 /*@only@*/ globSet globs_used;
130 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
136 bool flags[NUMFLAGS];
137 bool saveflags[NUMFLAGS];
138 bool setGlobally[NUMFLAGS];
139 bool setLocally[NUMFLAGS];
141 int values[NUMVALUEFLAGS];
142 int counters[NUMVALUEFLAGS];
144 o_cstring strings[NUMSTRINGFLAGS];
145 sRefSetList modrecs; /* Keep track of file static symbols modified. */
147 metaStateTable stateTable; /* User-defined state information. */
148 annotationTable annotTable; /* User-defined annotations table. */
153 /*@dependent@*/ /*@exposed@*/ uentry fcn;
157 union u_cont savecont;
160 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
161 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
162 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
163 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
165 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
166 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
167 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
168 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
169 static void context_setFlag (flagcode p_f, bool p_b, fileloc p_loc)
170 /*@modifies gc.flags@*/ ;
173 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile,
174 bool p_isRestore, fileloc p_loc)
175 /*@modifies gc.flags@*/ ;
177 static void context_restoreFlag (flagcode p_f, fileloc p_loc)
178 /*@modifies gc.flags@*/ ;
182 cstring context_unparseFlagMarkers ()
184 return (flagMarkerList_unparse (gc.markers));
187 void context_setPreprocessing (void)
189 llassert (!gc.preprocessing);
190 gc.preprocessing = TRUE;
193 void context_clearPreprocessing (void)
195 llassert (gc.preprocessing);
196 gc.preprocessing = FALSE;
199 bool context_isPreprocessing (void)
201 return gc.preprocessing;
204 bool context_loadingLibrary (void)
206 return (fileloc_isLib (g_currentloc));
209 bool context_inXHFile (void)
211 return (fileloc_isXHFile (g_currentloc));
214 void context_setInCommandLine (void)
216 llassert (!gc.incommandline);
217 gc.incommandline = TRUE;
220 void context_clearInCommandLine (void)
222 llassert (gc.incommandline);
223 gc.incommandline = FALSE;
226 bool context_isInCommandLine (void)
228 return gc.incommandline;
232 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
235 clauseStack_push (gc.clauses, c);
237 if (clause_isConditional (c)
238 && context_getFlag (FLG_CONTROLNESTDEPTH))
240 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
241 int depth = clauseStack_controlDepth (gc.clauses);
243 if (depth == maxdepth + 1)
246 (FLG_CONTROLNESTDEPTH,
247 message ("Maximum control nesting depth "
256 clause topClause (clauseStack s) /*@*/
258 if (clauseStack_isEmpty (s)) return NOCLAUSE;
259 return ((clause) clauseStack_top (s));
263 context_addMacroCache (/*@only@*/ cstring def)
265 DPRINTF (("macro cache: %s", def));
266 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
270 context_addComment (/*@only@*/ cstring def, fileloc loc)
272 macrocache_addComment (gc.mc, fileloc_copy (loc), def);
276 ** returns TRUE is fl is in ignore region, or region where -code
278 ** the logic is fuzzy...
282 context_inSuppressFlagZone (fileloc fl, flagcode code)
284 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
287 if (ynm_isMaybe (ret))
295 res = !gc.saveflags[code];
299 res = !context_getFlag (code);
304 res = ynm_toBoolStrict (ret);
311 context_suppressSystemMsg (fileloc fl)
313 if (context_getFlag (FLG_SYSTEMDIRERRORS))
319 return (fileloc_isSystemFile (fl));
324 context_suppressFlagMsg (flagcode flag, fileloc fl)
326 if (context_suppressSystemMsg (fl))
331 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
333 /* want same object compare here */
335 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
337 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
339 return (!context_getFlag (flag)
340 || context_inSuppressRegion ()
341 || context_inSuppressZone (fl)
342 || (context_inSuppressFlagZone (fl, flag))); /* removed gc.inDerivedFile from this */
346 return (context_inSuppressFlagZone (fl, flag));
351 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
354 if (context_suppressSystemMsg (fl))
360 if (fl == g_currentloc)
361 /*@noaccess fileloc@*/
363 return (context_getFlag (flag) || context_inSuppressRegion ());
368 return (context_getFlag (flag) || context_inSuppressRegion ());
373 context_inSuppressZone (fileloc fl)
375 if (context_suppressSystemMsg (fl))
380 return (flagMarkerList_inIgnore (gc.markers, fl));
384 context_inSuppressRegion (void)
386 return (gc.insuppressregion);
390 context_enterSuppressRegion (fileloc loc)
392 if (gc.insuppressregion)
394 gc.insuppressregion = FALSE; /* get this msg! */
396 ("%q: New ignore errors region entered while in ignore errors region",
397 fileloc_unparse (loc)));
400 gc.insuppressregion = TRUE;
401 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (loc));
405 context_addFlagMarker (flagcode code, ynm set, fileloc loc)
407 (void) flagMarkerList_add (gc.markers,
408 flagMarker_createLocalSet (code, set, loc));
412 context_enterSuppressLine (int count, fileloc loc)
414 if (context_processingMacros ())
419 if (flagMarkerList_add
421 flagMarker_createIgnoreCount (count, loc)))
423 fileloc nextline = fileloc_copy (loc);
424 fileloc_nextLine (nextline);
425 fileloc_setColumn (nextline, 0);
427 check (flagMarkerList_add (gc.markers,
428 flagMarker_createIgnoreOff (nextline)));
429 fileloc_free (nextline);
433 void context_checkSuppressCounts (void)
435 if (context_getFlag (FLG_SUPCOUNTS))
437 flagMarkerList_checkSuppressCounts (gc.markers);
441 void context_incLineno (void)
448 context_exitSuppressRegion (fileloc loc)
450 if (!gc.insuppressregion)
454 message ("End ignore errors in region while not ignoring errors"),
458 gc.insuppressregion = FALSE;
459 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (loc));
463 context_enterMTfile (void)
469 context_exitMTfile (void)
471 llassert (gc.kind == CX_MT);
476 context_enterLCLfile (void)
479 gc.facct = typeIdSet_emptySet ();
483 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
487 for (i = 0; i < gc.nmods; i++)
489 if (cstring_equal (gc.moduleaccess[i].file, fname))
491 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
492 cstring_free (fname);
497 if (gc.nmods == gc.maxmods)
501 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
502 oldmods = gc.moduleaccess;
504 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
506 for (i = 0; i < gc.nmods; i++)
508 gc.moduleaccess[i] = oldmods[i];
514 gc.moduleaccess[gc.nmods].file = fname;
515 gc.moduleaccess[gc.nmods].daccess = mods;
521 insertModuleAccess (cstring fname, typeId t)
525 for (i = 0; i < gc.nmods; i++)
527 if (cstring_equal (gc.moduleaccess[i].file, fname))
529 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
534 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
538 context_exitLCLfile (void)
540 if (gc.kind != CX_LCLLIB)
543 fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION);
545 addModuleAccess (fileLib_removePath (lclname), gc.facct);
546 cstring_free (lclname);
551 gc.facct = typeIdSet_emptySet ();
555 context_dumpModuleAccess (FILE *fout)
559 for (i = 0; i < gc.nmods; i++)
561 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
563 fprintf (fout, "%s#%s@\n",
564 cstring_toCharsSafe (gc.moduleaccess[i].file),
565 cstring_toCharsSafe (td));
571 bool context_usingPosixLibrary ()
573 return (gc.library == FLG_POSIXLIB
574 || gc.library == FLG_POSIXSTRICTLIB
575 || gc.library == FLG_UNIXLIB
576 || gc.library == FLG_UNIXSTRICTLIB);
579 bool context_usingAnsiLibrary ()
581 return (gc.library != FLG_NOLIB);
584 flagcode context_getLibrary ()
589 void context_setLibrary (flagcode code)
594 /*@observer@*/ cstring context_selectedLibrary ()
599 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
601 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
602 case FLG_POSIXSTRICTLIB:
603 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
605 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
606 case FLG_UNIXSTRICTLIB:
607 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
609 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
616 context_loadModuleAccess (FILE *in)
618 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
620 char *name = mstring_create (MAX_NAME_LENGTH);
626 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
632 while (s != NULL && *s != ';' && *s != '\0')
636 while (*s != '#' && *s != '\0')
645 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
646 cstring_fromChars (s)));
652 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
653 typeIdSet_undump (&s));
655 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
656 llassert (s != lasts);
666 typeIdSet context_fileAccessTypes (void)
672 context_resetModeFlags (void)
676 if (flagcode_isModeFlag (code))
678 context_setFlag (code, FALSE, g_currentloc);
686 ** Set all flags to FALSE, except for a few which are
689 ** Set all values and strings to appropriate defaults.
690 ** Set all counters to 0.
694 conext_resetAllCounters (void)
698 for (i = 0; i < NUMVALUEFLAGS; i++)
705 context_resetAllFlags (void)
707 DPRINTF (("******** Reset all flags"));
711 gc.flags[code] = FALSE;
713 if (flagcode_hasNumber (code))
717 /*@-loopswitchbreak@*/
721 val = DEFAULT_LIMIT; break;
723 val = DEFAULT_BUGSLIMIT; break;
725 val = DEFAULT_LINELEN; break;
726 case FLG_INDENTSPACES:
727 val = DEFAULT_INDENTSPACES; break;
728 case FLG_LOCINDENTSPACES:
729 val = DEFAULT_LOCINDENTSPACES; break;
730 case FLG_EXTERNALNAMELEN:
731 val = ISO99_EXTERNALNAMELEN; break;
732 case FLG_INTERNALNAMELEN:
733 val = ISO99_INTERNALNAMELEN; break;
734 case FLG_COMMENTCHAR:
735 val = (int) DEFAULT_COMMENTCHAR; break;
736 case FLG_CONTROLNESTDEPTH:
737 val = (int) ISO99_CONTROLNESTDEPTH; break;
738 case FLG_STRINGLITERALLEN:
739 val = (int) ISO99_STRINGLITERALLEN; break;
740 case FLG_INCLUDENEST:
741 val = (int) ISO99_INCLUDENEST; break;
742 case FLG_NUMSTRUCTFIELDS:
743 val = (int) ISO99_NUMSTRUCTFIELDS; break;
744 case FLG_NUMENUMMEMBERS:
745 val = (int) ISO99_NUMENUMMEMBERS; break;
750 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
752 /*@=loopswitchbreak@*/
754 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
755 context_setValue (code, val);
756 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
757 llassert (context_getValue (code) == val);
759 else if (flagcode_hasChar (code))
761 llassert (code == FLG_COMMENTCHAR);
762 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
764 else if (flagcode_hasString (code))
766 cstring val = cstring_undefined;
769 { /*@-loopswitchbreak@*/
772 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
774 if (cstring_isDefined (larchpath))
776 val = cstring_copy (larchpath);
780 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
785 case FLG_LCLIMPORTDIR:
787 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
791 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
793 char *env = osd_getEnvironmentVariable ("TMP");
797 env = osd_getEnvironmentVariable ("TEMP");
800 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
803 val = cstring_makeLiteral (DEFAULT_TMPDIR);
804 # endif /* !defined(OS2) && !defined(MSDOS) */
808 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
810 val = cstring_makeLiteral ("false"); break;
812 val = cstring_makeLiteral ("true"); break;
813 case FLG_MACROVARPREFIX:
814 val = cstring_makeLiteral ("m_"); break;
816 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
819 } /*@=loopswitchbreak@*/
821 context_setString (code, val);
825 ; /* nothing to set */
830 ** These flags are true by default.
833 /* eventually, move this into flags.def */
835 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;
843 gc.flags[FLG_NULLINIT] = TRUE;
845 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
847 gc.flags[FLG_LIKELYBOOL] = TRUE;
848 gc.flags[FLG_ZEROPTR] = TRUE;
849 gc.flags[FLG_NUMLITERAL] = TRUE;
850 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
851 gc.flags[FLG_SKIPISOHEADERS] = TRUE;
852 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
853 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
854 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
855 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
856 gc.flags[FLG_CASTFCNPTR] = TRUE;
857 gc.flags[FLG_DOLCS] = TRUE;
858 gc.flags[FLG_USEVARARGS] = TRUE;
859 gc.flags[FLG_MAINTYPE] = TRUE;
860 gc.flags[FLG_SPECMACROS] = TRUE;
861 gc.flags[FLG_REDEF] = TRUE;
862 gc.flags[FLG_MACRONEXTLINE] = TRUE;
864 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
865 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
867 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
868 gc.flags[FLG_WARNUSE] = TRUE;
869 gc.flags[FLG_PREDASSIGN] = TRUE;
870 gc.flags[FLG_MODOBSERVER] = TRUE;
871 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
872 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
874 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
875 gc.flags[FLG_RETIMPONLY] = TRUE;
876 gc.flags[FLG_GLOBIMPONLY] = TRUE;
877 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
878 gc.flags[FLG_PREPROC] = TRUE;
879 gc.flags[FLG_NAMECHECKS] = TRUE;
880 gc.flags[FLG_FORMATCODE] = TRUE;
881 gc.flags[FLG_FORMATTYPE] = TRUE;
882 gc.flags[FLG_BADFLAG] = TRUE;
883 gc.flags[FLG_WARNFLAGS] = TRUE;
884 gc.flags[FLG_WARNRC] = TRUE;
885 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
886 gc.flags[FLG_WARNUNIXLIB] = FALSE;
887 gc.flags[FLG_WARNPOSIX] = TRUE;
888 gc.flags[FLG_SHOWCOL] = TRUE;
889 gc.flags[FLG_SHOWDEEPHISTORY] = FALSE; /* TRUE; */
890 gc.flags[FLG_SHOWFUNC] = TRUE;
891 gc.flags[FLG_SUPCOUNTS] = TRUE;
892 gc.flags[FLG_HINTS] = TRUE;
893 gc.flags[FLG_SYNTAX] = TRUE;
894 gc.flags[FLG_TYPE] = TRUE;
895 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
896 gc.flags[FLG_ABSTRACT] = TRUE;
897 gc.flags[FLG_NUMABSTRACT] = TRUE;
898 gc.flags[FLG_ITERBALANCE] = TRUE;
899 gc.flags[FLG_ITERYIELD] = TRUE;
900 gc.flags[FLG_DUPLICATECASES] = TRUE;
901 gc.flags[FLG_ALWAYSEXITS] = TRUE;
902 gc.flags[FLG_EMPTYRETURN] = TRUE;
903 gc.flags[FLG_MACRORETURN] = TRUE;
904 gc.flags[FLG_UNRECOG] = TRUE;
905 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
906 gc.flags[FLG_LINTCOMMENTS] = TRUE;
907 gc.flags[FLG_ACCESSCZECH] = TRUE;
908 gc.flags[FLG_ACCESSMODULE] = TRUE;
909 gc.flags[FLG_ACCESSFILE] = TRUE;
910 gc.flags[FLG_MACROVARPREFIX] = TRUE;
912 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
913 gc.flags[FLG_COMMENTERROR] = TRUE;
916 ** Changed for version 2.4.
919 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
925 /* commenting ou until some output issues are fixed */
926 gc.flags[FLG_ORCONSTRAINT] = TRUE;
928 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
931 gc.flags[FLG_WARNSYSFILES] = TRUE;
934 ** On by default for Win32, but not Unix
938 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
939 gc.flags[FLG_CASEINSENSITIVEFILENAMES] = TRUE;
944 ** C is way-lame, and you can initialize an array to a constant except where
945 ** it is declared. Hence, a macro is used to set the modeflags.
949 # define SETFLAGS() \
950 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
951 if (!flagcode_isModeFlag (modeflags[i])) \
952 { llbug (message ("not a mode flag: %s", \
953 flagcode_unparse (modeflags[i]))); } \
954 else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }}
956 static void context_setModeAux (cstring p_s, bool p_warn) ;
959 context_setMode (cstring s)
961 context_setModeAux (s, TRUE);
965 context_setModeNoWarn (cstring s)
967 context_setModeAux (s, FALSE);
971 context_setModeAux (cstring s, bool warn)
973 intSet setflags = intSet_new ();
977 if (flagcode_isModeFlag (code))
979 if (gc.setGlobally[code])
981 (void) intSet_insert (setflags, (int) code);
986 if (!intSet_isEmpty (setflags))
988 cstring rflags = cstring_undefined;
991 intSet_elements (setflags, el)
993 if (cstring_isUndefined (rflags))
995 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
999 rflags = message ("%q, %s", rflags,
1000 flagcode_unparse ((flagcode) el));
1004 if (num > 4 && intSet_size (setflags) > 6)
1006 rflags = message ("%q, (%d others) ...", rflags,
1007 intSet_size (setflags) - num);
1010 } end_intSet_elements ;
1014 voptgenerror (FLG_WARNFLAGS,
1015 message ("Setting mode %s after setting mode flags will "
1016 "override set values of flags: %s",
1021 cstring_free (rflags);
1024 intSet_free (setflags);
1026 context_resetModeFlags ();
1028 if (cstring_equalLit (s, "standard"))
1030 flagcode modeflags[] =
1032 FLG_ENUMINT, FLG_MACROMATCHNAME,
1033 FLG_STRINGLITNOROOM,
1034 FLG_STRINGLITNOROOMFINALNULL,
1035 FLG_MACROUNDEF, FLG_RELAXQUALS,
1036 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1037 FLG_CHECKSTRICTGLOBALIAS,
1038 FLG_CHECKEDGLOBALIAS,
1039 FLG_CHECKMODGLOBALIAS,
1040 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1041 FLG_UNSIGNEDCOMPARE,
1042 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1044 FLG_ABSTRACTCOMPARE,
1045 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1046 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1047 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1048 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1049 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1052 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1053 FLG_MACROSTMT, FLG_MACROPARENS,
1056 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1057 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1062 /* memchecks flags */
1064 FLG_NULLSTATE, FLG_NULLASSIGN,
1065 FLG_NULLPASS, FLG_NULLRET,
1067 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1070 /* memtrans flags */
1086 FLG_NUMABSTRACTCAST,
1089 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1092 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1093 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1096 FLG_STATETRANSFER, FLG_STATEMERGE,
1097 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1099 FLG_IMPCHECKEDSPECGLOBALS,
1100 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1101 FLG_IFEMPTY, FLG_REALCOMPARE,
1102 FLG_BOOLOPS, FLG_PTRNEGATE,
1104 FLG_SHIFTIMPLEMENTATION,
1105 FLG_BUFFEROVERFLOWHIGH,
1112 else if (cstring_equalLit (s, "weak"))
1114 flagcode modeflags[] =
1116 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE, FLG_LONGINT, FLG_SHORTINT,
1117 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1118 FLG_CHARINDEX, FLG_NUMABSTRACTINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1119 FLG_CHARUNSIGNEDCHAR,
1122 FLG_VARUNUSED, FLG_FUNCUNUSED,
1124 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1127 FLG_BUFFEROVERFLOWHIGH,
1128 FLG_RETSTACK, FLG_PTRNEGATE,
1129 FLG_STATETRANSFER, FLG_STATEMERGE,
1130 FLG_LONGUNSIGNEDINTEGRAL,
1131 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1135 FLG_BUFFEROVERFLOWHIGH,
1136 FLG_STRINGLITNOROOM,
1137 FLG_STRINGLITNOROOMFINALNULL,
1143 else if (cstring_equalLit (s, "checks"))
1145 flagcode modeflags[] =
1147 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1148 FLG_NUMABSTRACTCAST,
1149 FLG_ABSTRACTCOMPARE,
1150 FLG_STATETRANSFER, FLG_STATEMERGE,
1151 FLG_CHECKSTRICTGLOBALIAS,
1152 FLG_CHECKEDGLOBALIAS,
1153 FLG_CHECKMODGLOBALIAS,
1154 FLG_UNCHECKEDGLOBALIAS,
1156 FLG_STRINGLITNOROOM,
1157 FLG_STRINGLITNOROOMFINALNULL,
1158 FLG_STRINGLITSMALLER,
1159 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1160 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1161 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1162 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1163 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1164 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1165 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1166 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1167 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1168 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1169 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1170 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1171 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1172 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1173 FLG_NUMABSTRACTPRINT,
1180 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1184 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1186 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1187 FLG_EVALORDER, FLG_USEDEF,
1190 /* warn use flags */
1191 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1192 FLG_BUFFEROVERFLOWHIGH,
1194 /* memchecks flags */
1196 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1197 FLG_NULLPASS, FLG_NULLRET,
1199 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1201 /* memtrans flags */
1215 FLG_STATICINITTRANS,
1216 FLG_UNKNOWNINITTRANS,
1219 FLG_ONLYUNQGLOBALTRANS,
1220 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1223 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1224 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1227 FLG_NULLPOINTERARITH,
1228 FLG_SHADOW, FLG_DEPARRAYS,
1229 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1230 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1231 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1232 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1233 FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES,
1234 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1235 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1236 FLG_SHIFTIMPLEMENTATION,
1237 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1242 else if (cstring_equalLit (s, "strict"))
1244 flagcode modeflags[] =
1246 FLG_ABSTRACTCOMPARE,
1247 FLG_CHECKSTRICTGLOBALIAS,
1248 FLG_NUMABSTRACTCAST,
1249 FLG_CHECKEDGLOBALIAS,
1250 FLG_CHECKMODGLOBALIAS,
1251 FLG_UNCHECKEDGLOBALIAS,
1255 FLG_NUMABSTRACTPRINT,
1256 FLG_STRINGLITNOROOM,
1257 FLG_STRINGLITNOROOMFINALNULL,
1258 FLG_STRINGLITSMALLER,
1259 FLG_STATETRANSFER, FLG_STATEMERGE,
1260 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1261 FLG_ALLGLOBALS, FLG_IMPTYPE,
1262 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1263 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1264 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1265 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1268 FLG_ONLYUNQGLOBALTRANS,
1269 FLG_GLOBALSIMPMODIFIESNOTHING,
1270 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1271 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1272 FLG_USEALLGLOBS, FLG_RETALIAS,
1273 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1274 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1275 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1277 FLG_EXPORTITER, FLG_EXPORTCONST,
1278 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1279 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1281 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1283 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1284 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1285 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1286 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1287 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1288 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1289 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1290 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1292 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1295 FLG_MACROREDEF, FLG_MACROEMPTY,
1296 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1298 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1300 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1301 FLG_MODOBSERVERUNCON,
1306 /* warn use flags */
1307 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1308 FLG_BUFFEROVERFLOWHIGH,
1309 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1311 /* memchecks flags */
1312 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1313 FLG_NULLPASS, FLG_NULLRET,
1315 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1317 /* memtrans flags */
1333 FLG_STATICINITTRANS,
1334 FLG_UNKNOWNINITTRANS,
1336 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1339 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1340 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1344 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1346 FLG_SHADOW, FLG_DEPARRAYS,
1347 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1348 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1349 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1350 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1351 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1352 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1353 FLG_IMPCHECKEDSTRICTSTATICS,
1354 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1355 FLG_IMPCHECKMODINTERNALS,
1356 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1357 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1358 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1359 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1360 FLG_CONTROLNESTDEPTH,
1361 FLG_FORBLOCK, FLG_WHILEBLOCK,
1362 FLG_FOREMPTY, FLG_WHILEEMPTY,
1363 FLG_IFEMPTY, FLG_IFBLOCK,
1365 FLG_REALCOMPARE, FLG_BOOLOPS,
1366 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1369 FLG_SHIFTIMPLEMENTATION,
1371 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1379 llcontbug (message ("context_setMode: bad mode: %s", s));
1384 context_isSpecialFile (cstring fname)
1386 cstring ext = fileLib_getExtension (fname);
1388 return (cstring_equalLit (ext, ".y")
1389 || cstring_equalLit (ext, ".l")
1390 || cstring_equalLit (fname, "lex.yy.c"));
1394 context_isSystemDir (cstring dir)
1396 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1397 cstring savedir = thisdir;
1398 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1400 if (cstring_isDefined (nextdir))
1402 /*@access cstring@*/
1403 *nextdir = '\0'; /* closes thisdir */
1405 /*@noaccess cstring@*/
1408 /* 2001-09-09: added thisdir[0] != '\0'
1409 ** herbert: don't compare with an empty name!
1410 ** should return false for empty directory path
1413 while (!cstring_isEmpty (thisdir))
1415 DPRINTF (("Test: %s / %s", dir, thisdir));
1417 if (osd_equalCanonicalPrefix (dir, thisdir))
1419 cstring_free (savedir);
1423 if (cstring_isDefined (nextdir))
1426 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1428 if (cstring_isDefined (nextdir))
1430 /*@access cstring@*/
1433 /*@noaccess cstring@*/
1442 DPRINTF (("Returns FALSE"));
1443 cstring_free (savedir);
1448 context_addFileAccessType (typeId t)
1452 if (context_inFunctionLike ())
1454 gc.acct = typeIdSet_insert (gc.acct, t);
1457 gc.facct = typeIdSet_insert (gc.facct, t);
1459 base = fileloc_getBase (g_currentloc);
1460 insertModuleAccess (base, t);
1461 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1462 typeIdSet_unparse (gc.acct)));
1466 context_removeFileAccessType (typeId t)
1468 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1469 || gc.kind == CX_UNKNOWNMACRO)
1471 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1474 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1475 gc.nacct = typeIdSet_insert (gc.nacct, t);
1478 void context_enterFunctionHeader (void)
1480 if (context_getFlag (FLG_GRAMMAR))
1482 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1485 if (gc.kind != CX_GLOBAL)
1487 llparseerror (cstring_makeLiteral
1488 ("Likely parse error. Function header outside global context."));
1492 llassert (gc.kind == CX_GLOBAL);
1493 DPRINTF (("Enter function header!"));
1494 gc.inFunctionHeader = TRUE;
1498 void context_exitFunctionHeader (void)
1500 if (context_getFlag (FLG_GRAMMAR))
1502 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1505 DPRINTF (("Exit function header!"));
1506 gc.inFunctionHeader = FALSE;
1509 bool context_inFunctionHeader (void)
1511 return (gc.inFunctionHeader);
1514 void context_enterFunctionDeclaration (uentry e)
1516 if (context_getFlag (FLG_GRAMMAR))
1518 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1521 DPRINTF (("Enter function decl"));
1522 llassert (gc.savekind == CX_ERROR);
1523 gc.savekind = gc.kind;
1524 gc.savecont = gc.cont;
1525 gc.kind = CX_FCNDECLARATION;
1529 void context_exitFunctionDeclaration (void)
1531 if (context_getFlag (FLG_GRAMMAR))
1533 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1536 DPRINTF (("Exit function decl"));
1537 llassert (gc.savekind != CX_ERROR);
1538 llassert (gc.kind == CX_FCNDECLARATION);
1539 gc.kind = gc.savekind;
1540 gc.cont = gc.savecont;
1542 gc.savekind = CX_ERROR;
1544 if (context_getFlag (FLG_GRAMMAR))
1546 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1550 bool context_inFunctionDeclaration (void)
1552 return (gc.kind == CX_FCNDECLARATION);
1557 context_enterMacro (/*@observer@*/ uentry e)
1559 context_enterFunction (e);
1560 gc.kind = CX_MACROFCN;
1564 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1566 llassert (uentry_isFunction (e));
1567 context_enterFunction (e);
1568 gc.kind = CX_UNKNOWNMACRO;
1571 void context_enterAndClause (exprNode e)
1574 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1575 pushClause (ANDCLAUSE);
1578 void context_enterOrClause (exprNode e)
1580 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1581 pushClause (ORCLAUSE);
1584 bool context_inDeepLoop (void)
1586 bool inLoop = FALSE;
1588 clauseStack_elements (gc.clauses, el)
1590 if (clause_isLoop (el))
1599 } end_clauseStack_elements;
1604 bool context_inDeepSwitch (void)
1606 bool inLoop = FALSE;
1608 clauseStack_elements (gc.clauses, el)
1610 if (clause_isSwitch (el))
1619 } end_clauseStack_elements;
1624 bool context_inDeepLoopSwitch (void)
1626 bool inLoop = FALSE;
1628 clauseStack_elements (gc.clauses, el)
1630 if (clause_isBreakable (el))
1639 } end_clauseStack_elements;
1644 clause context_breakClause (void)
1646 clauseStack_elements (gc.clauses, el)
1648 if (clause_isSwitch (el))
1652 else if (clause_isLoop (el))
1660 } end_clauseStack_elements;
1665 clause context_nextBreakClause (void)
1667 bool hasOne = FALSE;
1669 clauseStack_elements (gc.clauses, el)
1671 if (clause_isBreakable (el))
1682 } end_clauseStack_elements;
1687 bool context_inConditional (void)
1689 clauseStack_elements (gc.clauses, el)
1692 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1693 ** to distinguish if from ? for this
1696 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1700 } end_clauseStack_elements;
1705 void context_exitAndClause (exprNode pred, exprNode tbranch)
1707 context_setJustPopped ();
1709 llassert (gc.inclause == ANDCLAUSE);
1711 usymtab_popAndBranch (pred, tbranch);
1712 clauseStack_pop (gc.clauses);
1713 gc.inclause = topClause (gc.clauses);
1716 void context_exitOrClause (exprNode pred, exprNode tbranch)
1718 context_setJustPopped ();
1720 llassert (gc.inclause == ORCLAUSE);
1722 usymtab_popOrBranch (pred, tbranch);
1723 clauseStack_pop (gc.clauses);
1724 gc.inclause = topClause (gc.clauses);
1727 static void context_enterCondClauseAux (clause cl)
1733 static void context_enterTrueAux (exprNode e, clause cl)
1736 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1740 void context_enterIterClause (void)
1742 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1745 void context_enterDoWhileClause (void)
1747 pushClause (DOWHILECLAUSE);
1750 void context_enterWhileClause (exprNode e)
1752 context_enterTrueAux (e, WHILECLAUSE);
1755 void context_enterForClause (exprNode e)
1757 context_enterTrueAux (e, FORCLAUSE);
1760 void context_enterTrueClause (exprNode e)
1762 context_enterTrueAux (e, TRUECLAUSE);
1765 void context_enterSwitch (exprNode e)
1767 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1768 usymtab_switchBranch (e);
1769 context_enterCondClauseAux (SWITCHCLAUSE);
1772 void context_exitSwitch (exprNode e, bool allpaths)
1774 usymtab_exitSwitch (e, allpaths);
1776 while (clause_isCase (clauseStack_top (gc.clauses)))
1778 clauseStack_pop (gc.clauses);
1781 context_exitClauseSimp ();
1784 void context_enterCaseClause (exprNode e)
1786 bool branch = FALSE;
1788 DPRINTF (("Enter case clause!"));
1790 branch = usymtab_newCase (exprNode_undefined, e);
1794 context_enterCondClauseAux (CASECLAUSE);
1798 static void context_enterFalseClauseAux (exprNode e, clause cl)
1801 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1803 clauseStack_switchTop (gc.clauses, cl);
1806 void context_enterFalseClause (exprNode e)
1809 context_enterFalseClauseAux (e, FALSECLAUSE);
1813 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1815 gc.kind = CX_MACROCONST;
1817 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1819 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1823 usymtab_enterScope ();
1824 sRef_enterFunctionScope ();
1826 gc.globs = globSet_undefined;
1827 globSet_clear (gc.globs_used);
1828 gc.mods = sRefSet_undefined;
1831 uentry context_getHeader (void)
1833 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1835 llfatalbug (message ("context_getHeader: bad call: %q",
1836 context_unparse ()));
1839 return (gc.cont.fcn);
1843 context_setFunctionDefined (fileloc loc)
1847 case CX_UNKNOWNMACRO:
1850 uentry_setFunctionDefined (gc.cont.fcn, loc);
1853 /* (not a bug because of parse errors) */
1859 context_enterFunction (/*@exposed@*/ uentry e)
1861 gc.kind = CX_FUNCTION;
1864 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1866 if (uentry_hasAccessType (e))
1868 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1876 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1877 typeIdSet_unparse (gc.acct)));
1879 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1881 gc.globs = uentry_getGlobs (e);
1882 globSet_clear (gc.globs_used);
1883 gc.mods = uentry_getMods (e);
1885 usymtab_enterFunctionScope (e);
1886 sRef_enterFunctionScope ();
1889 bool context_inOldStyleScope(void)
1891 return (gc.kind == CX_OLDSTYLESCOPE);
1895 context_enterOldStyleScope (void)
1897 gc.kind = CX_OLDSTYLESCOPE;
1898 DPRINTF (("Enter old style scope!"));
1899 usymtab_enterFunctionScope (uentry_undefined);
1903 context_completeOldStyleFunction (uentry e)
1905 llassert (gc.kind == CX_OLDSTYLESCOPE);
1907 gc.kind = CX_FUNCTION;
1910 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1912 if (uentry_hasAccessType (e))
1914 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1922 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1923 typeIdSet_unparse (gc.acct)));
1925 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1927 if (!globSet_isEmpty (uentry_getGlobs (e)))
1929 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1930 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1933 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1935 gc.globs = uentry_getGlobs (e);
1936 globSet_clear (gc.globs_used);
1938 gc.mods = uentry_getMods (e);
1940 if (!sRefSet_isEmpty (gc.mods))
1942 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1943 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1946 sRef_enterFunctionScope ();
1949 static bool context_checkStrictGlobals (void)
1951 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1954 static bool context_hasGlobs (void)
1956 if (context_inFunctionLike ())
1958 return (uentry_hasGlobs (gc.cont.fcn));
1966 static bool context_checkCheckedGlobals (void)
1968 return (context_getFlag (FLG_GLOBALS)
1969 && (context_getFlag (FLG_GLOBUNSPEC)
1970 || context_hasGlobs ()));
1973 static bool context_checkUnknownGlobals (void)
1975 /* should be uentry_hasGlobs ? */
1977 return (context_getFlag (FLG_ALLGLOBALS)
1978 && (context_getFlag (FLG_GLOBUNSPEC)
1979 || context_hasGlobs ()));
1982 static bool context_checkUncheckedGlobals (void)
1988 context_checkExport (uentry e)
1990 if (!gc.anyExports) return FALSE;
1992 if (uentry_isFunction (e)
1993 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1995 return context_maybeSet (FLG_EXPORTFCN);
1997 else if (uentry_isExpandedMacro (e))
1999 return context_maybeSet (FLG_EXPORTMACRO);
2001 else if (uentry_isVariable (e))
2003 return context_maybeSet (FLG_EXPORTVAR);
2005 else if (uentry_isEitherConstant (e))
2007 return context_maybeSet (FLG_EXPORTCONST);
2009 else if (uentry_isIter (e) || uentry_isEndIter (e))
2011 return context_maybeSet (FLG_EXPORTITER);
2013 else if (uentry_isDatatype (e))
2015 return context_maybeSet (FLG_EXPORTTYPE);
2024 context_checkGlobUse (uentry glob)
2027 if (uentry_isCheckedStrict (glob))
2029 return context_checkStrictGlobals ();
2031 else if (uentry_isChecked (glob))
2033 return context_checkCheckedGlobals ();
2035 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2037 return context_checkUnknownGlobals ();
2041 llassert (uentry_isUnchecked (glob));
2043 return context_checkUncheckedGlobals ();
2048 context_checkAliasGlob (uentry glob)
2050 if (uentry_isCheckedStrict (glob))
2052 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2054 else if (uentry_isChecked (glob))
2056 return gc.flags[FLG_CHECKEDGLOBALIAS];
2058 else if (uentry_isCheckMod (glob))
2060 return gc.flags[FLG_CHECKMODGLOBALIAS];
2064 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2066 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2070 bool context_checkInternalUse (void)
2072 if (context_hasGlobs ())
2074 return (gc.flags[FLG_INTERNALGLOBS]);
2078 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2083 context_checkGlobMod (sRef el)
2085 uentry ue = sRef_getUentry (el);
2087 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2089 if (uentry_isCheckedModify (ue)
2090 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2092 if (context_hasMods ())
2094 return (gc.flags[FLG_MODGLOBS]);
2098 if (uentry_isCheckedStrict (ue))
2100 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2104 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2110 if (context_hasMods ())
2112 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2122 context_usedGlobal (/*@exposed@*/ sRef el)
2124 if (!globSet_member (gc.globs_used, el))
2127 ** The first time a global is used in a function, we need
2128 ** to clear the derived sRefs, since they were set for the
2129 ** previous function.
2132 sRef_clearDerived (el);
2133 gc.globs_used = globSet_insert (gc.globs_used, el);
2137 /*@observer@*/ sRefSet
2138 context_modList (void)
2144 context_globAccess (sRef s)
2146 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2147 return (globSet_member (gc.globs, s));
2151 context_hasAccess (typeId t)
2153 if (context_inFunctionLike ())
2155 DPRINTF (("Access %d / %s",
2156 t, typeIdSet_unparse (gc.acct)));
2157 return (typeIdSet_member (gc.acct, t));
2161 return (context_hasFileAccess (t));
2166 context_hasFileAccess (typeId t)
2168 return (typeIdSet_member (gc.facct, t));
2172 context_unparseAccess (void)
2174 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2175 typeIdSet_unparse (gc.facct)));
2179 context_unparseClauses (void)
2181 return (clauseStack_unparse (gc.clauses));
2185 context_couldHaveAccess (typeId t)
2187 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2189 return (typeIdSet_member (gc.acct, t));
2193 return (typeIdSet_member (gc.facct, t));
2198 context_getRetType (void)
2200 ctype f = ctype_undefined;
2202 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2204 f = uentry_getType (gc.cont.fcn);
2206 else if (gc.kind == CX_UNKNOWNMACRO)
2208 return ctype_unknown;
2212 llcontbuglit ("context_getRetType: not in a function context");
2213 return ctype_unknown;
2216 if (!ctype_isFunction (f))
2218 if (ctype_isKnown (f))
2220 llbuglit ("context_getRetType: not a function");
2223 return ctype_unknown;
2225 return (ctype_getReturnType (f));
2229 context_hasMods (void)
2231 if (context_inFunctionLike ())
2233 return (uentry_hasMods (gc.cont.fcn));
2242 context_exitAllClauses (void)
2244 while (!clauseStack_isEmpty (gc.clauses))
2246 clause el = clauseStack_top (gc.clauses);
2249 if (clause_isNone (el))
2251 usymtab_quietExitScope (g_currentloc);
2252 clauseStack_pop (gc.clauses);
2256 context_exitClausePlain ();
2260 clauseStack_clear (gc.clauses);
2261 gc.inclause = NOCLAUSE;
2265 context_exitAllClausesQuiet (void)
2267 while (!clauseStack_isEmpty (gc.clauses))
2269 clause el = clauseStack_top (gc.clauses);
2272 usymtab_quietExitScope (g_currentloc);
2273 clauseStack_pop (gc.clauses);
2276 clauseStack_clear (gc.clauses);
2277 gc.inclause = NOCLAUSE;
2281 void context_exitClauseSimp (void)
2284 context_setJustPopped ();
2285 clauseStack_pop (gc.clauses);
2286 gc.inclause = topClause (gc.clauses);
2290 void context_exitCaseClause (void)
2292 context_setJustPopped ();
2293 usymtab_popCaseBranch ();
2294 clauseStack_pop (gc.clauses);
2295 gc.inclause = topClause (gc.clauses);
2299 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2301 context_setJustPopped ();
2302 usymtab_popTrueBranch (pred, tbranch, gc.inclause); /* evans 2003-02-02?: was makeAlt */
2303 clauseStack_pop (gc.clauses);
2304 gc.inclause = topClause (gc.clauses);
2307 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2309 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2311 if (gc.inclause != TRUECLAUSE)
2313 llparseerror (cstring_makeLiteral
2314 ("Likely parse error. Conditional clauses are inconsistent."));
2318 context_setJustPopped ();
2319 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2320 clauseStack_pop (gc.clauses);
2321 gc.inclause = topClause (gc.clauses);
2324 void context_exitIterClause (exprNode body)
2326 llassert (gc.inclause == ITERCLAUSE);
2328 context_setJustPopped ();
2330 if (context_getFlag (FLG_ITERLOOPEXEC))
2332 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2336 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2339 clauseStack_pop (gc.clauses);
2340 gc.inclause = topClause (gc.clauses);
2343 static void context_popCase (void) {
2345 ** If we are exiting an outer clause, sometimes still in a switch case.
2359 DPRINTF (("Popping case clause: %s",
2360 clauseStack_unparse (gc.clauses)));
2362 if (gc.inclause == CASECLAUSE) {
2363 context_exitCaseClause ();
2367 void context_exitWhileClause (exprNode pred, exprNode body)
2369 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2373 if (gc.inclause != WHILECLAUSE) {
2374 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2375 clauseStack_unparse (gc.clauses)));
2378 llassert (gc.inclause == WHILECLAUSE);
2380 context_setJustPopped ();
2384 ** predicate must be false after while loop (unless there are breaks)
2387 if (context_getFlag (FLG_WHILELOOPEXEC))
2389 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2393 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2397 usymtab_addGuards (invGuards);
2398 guardSet_free (invGuards);
2400 clauseStack_pop (gc.clauses);
2401 gc.inclause = topClause (gc.clauses);
2404 void context_exitDoWhileClause (exprNode pred)
2406 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2408 if (gc.inclause == CASECLAUSE) {
2409 /* handle Duff's device */
2410 clauseStack_pop (gc.clauses);
2411 gc.inclause = topClause (gc.clauses);
2414 llassert (gc.inclause == DOWHILECLAUSE);
2416 context_setJustPopped ();
2419 usymtab_addGuards (invGuards);
2420 guardSet_free (invGuards);
2422 clauseStack_pop (gc.clauses);
2423 gc.inclause = topClause (gc.clauses);
2426 void context_exitForClause (exprNode forPred, exprNode body)
2428 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2430 llassert (gc.inclause == FORCLAUSE);
2431 context_setJustPopped ();
2433 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2436 ** Predicate must be false after for loop (unless there are breaks)
2439 if (context_getFlag (FLG_FORLOOPEXEC))
2441 DPRINTF (("Here: for loop exec"));
2442 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2446 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2447 && exprNode_loopMustExec (forPred))
2449 DPRINTF (("Here: loop must exec"));
2450 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2454 DPRINTF (("Pop true branch:"));
2455 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2459 usymtab_addGuards (invGuards);
2460 guardSet_free (invGuards);
2461 clauseStack_pop (gc.clauses);
2462 gc.inclause = topClause (gc.clauses);
2465 static void context_exitClausePlain (void)
2467 llassert (gc.inclause != NOCLAUSE);
2469 if (gc.inclause == FALSECLAUSE)
2471 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2475 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2479 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2481 context_setJustPopped ();
2483 if (gc.inclause == FALSECLAUSE)
2485 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2487 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2489 clauseStack_pop (gc.clauses);
2490 gc.inclause = topClause (gc.clauses);
2494 context_exitTrueClause (pred, tbranch);
2499 context_returnFunction (void)
2501 usymtab_checkFinalScope (TRUE);
2505 context_exitFunction (void)
2507 DPRINTF (("Exit function: %s", context_unparse ()));
2509 if (!context_inFunction () && !context_inMacroConstant ()
2510 && !context_inUnknownMacro ()
2511 && !context_inIterDef () && !context_inIterEnd ())
2514 ** not a bug because of parse errors
2521 if (context_inMacro () && usymtab_inFunctionScope ())
2523 usymtab_exitScope (exprNode_undefined);
2526 if (uentry_hasGlobs (gc.cont.fcn))
2528 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2532 if (uentry_hasMods (gc.cont.fcn))
2534 if (context_getFlag (FLG_MUSTMOD))
2536 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2540 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2543 ** clear file static modifies
2546 /* do this first to get unused error messages */
2548 usymtab_exitScope (exprNode_undefined);
2549 sRef_exitFunctionScope ();
2551 gc.showfunction = FALSE;
2552 gc.kind = CX_GLOBAL;
2553 gc.cont.glob = TRUE;
2555 gc.globs = globSet_new ();
2556 globSet_clear (gc.globs_used);
2557 gc.mods = sRefSet_new ();
2560 llassert (clauseStack_isEmpty (gc.clauses));
2561 llassert (gc.inclause == NOCLAUSE);
2562 DPRINTF (("After exit function: %s", context_unparse ()));
2566 context_quietExitFunction (void)
2568 while (gc.kind == CX_INNER)
2570 context_exitInnerPlain ();
2573 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2574 && !context_inIterDef () && !context_inIterEnd ())
2579 usymtab_quietExitScope (g_currentloc);
2581 gc.showfunction = FALSE;
2582 gc.kind = CX_GLOBAL;
2583 gc.cont.glob = TRUE;
2585 gc.globs = globSet_new ();
2586 globSet_clear (gc.globs_used);
2587 gc.mods = sRefSet_new ();
2589 sRef_exitFunctionScope ();
2593 /*@observer@*/ uentryList
2594 context_getParams (void)
2596 if (context_inFunctionLike ())
2598 return (uentry_getParams (gc.cont.fcn));
2602 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2603 return uentryList_undefined;
2607 /*@observer@*/ globSet
2608 context_getUsedGlobs (void)
2610 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2611 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2613 return (gc.globs_used);
2617 context_moduleName ()
2619 return (fileloc_getBase (g_currentloc));
2622 /*@observer@*/ globSet
2623 context_getGlobs (void)
2625 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2626 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2632 context_addBoolAccess (void)
2634 cstring bname = context_getString (FLG_BOOLTYPE);
2635 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2637 addModuleAccess (cstring_copy (bname), boolt);
2639 /* for sys/types (perhaps, this is bogus!) */
2640 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2645 context_canAccessBool (void)
2652 static typeId boolType = typeId_invalid;
2654 if (typeId_isInvalid (boolType))
2656 boolType = usymtab_getTypeId (context_getBoolName ());
2659 if (typeId_isInvalid (boolType)) {
2662 return (typeIdSet_member (gc.acct, boolType));
2667 /* evs 2000-07-25: old version - replaced */
2670 context_boolImplementationType () {
2671 /* For now, this is bogus! */
2676 context_canAccessBool (void)
2678 static typeId boolType = typeId_invalid;
2680 if (typeId_isInvalid (boolType))
2682 boolType = usymtab_getTypeId (context_getBoolName ());
2685 if (!typeId_isInvalid (boolType))
2687 return context_hasAccess (boolType);
2698 context_setMessageAnnote (/*@only@*/ cstring s)
2700 llassert (cstring_isUndefined (gc.msgAnnote));
2705 context_hasMessageAnnote (void)
2707 return (cstring_isDefined (gc.msgAnnote));
2711 context_clearMessageAnnote (void)
2713 if (cstring_isDefined (gc.msgAnnote))
2715 cstring_free (gc.msgAnnote);
2716 gc.msgAnnote = cstring_undefined;
2721 context_getMessageAnnote (void)
2723 cstring st = gc.msgAnnote;
2725 gc.msgAnnote = cstring_undefined;
2730 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2732 llassert (sRef_isInvalid (gc.aliasAnnote));
2733 llassert (!sRef_sameName (s, t));
2735 gc.aliasAnnoteAls = t;
2739 context_hasAliasAnnote (void)
2741 return (sRef_isValid (gc.aliasAnnote));
2745 context_clearAliasAnnote (void)
2747 gc.aliasAnnote = sRef_undefined;
2751 context_getAliasAnnote (void)
2753 sRef ret = gc.aliasAnnote;
2754 sRef als = gc.aliasAnnoteAls;
2756 llassert (sRef_isValid (ret) && sRef_isValid (als));
2758 gc.aliasAnnote = sRef_undefined;
2759 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2763 context_recordFileModifies (sRefSet mods)
2765 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2769 context_recordFileGlobals (globSet mods)
2771 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2772 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2776 context_setCommentMarkerChar (char c)
2778 llassert (c != '\0');
2780 context_setValue (FLG_COMMENTCHAR, (int) c);
2784 context_getCommentMarkerChar (void)
2786 return ((char) context_getValue (FLG_COMMENTCHAR));
2790 context_setValue (flagcode flag, int val)
2792 int index = flagcode_valueIndex (flag);
2794 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2802 llerror_flagWarning (message ("Value for %s must be a positive "
2803 "number (given %d)",
2804 flagcode_unparse (flag), val));
2807 if (flag == FLG_LINELEN && val < MINLINELEN)
2809 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2810 flagcode_unparse (flag),
2816 case FLG_INCLUDENEST:
2817 case FLG_CONTROLNESTDEPTH:
2818 case FLG_STRINGLITERALLEN:
2819 case FLG_NUMSTRUCTFIELDS:
2820 case FLG_NUMENUMMEMBERS:
2821 case FLG_INDENTSPACES:
2824 llerror_flagWarning (message ("Value for %s must be a non-negative "
2825 "number (given %d)",
2826 flagcode_unparse (flag), val));
2835 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2836 gc.values[index] = val;
2840 context_setValueAndFlag (flagcode flag, int val)
2842 gc.flags[flag] = TRUE;
2843 context_setValue (flag, val);
2847 context_getValue (flagcode flag)
2849 int index = flagcode_valueIndex (flag);
2851 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2852 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2853 return (gc.values[index]);
2857 context_getCounter (flagcode flag)
2859 int index = flagcode_valueIndex (flag);
2861 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2862 return (gc.counters[index]);
2866 context_incCounter (flagcode flag)
2868 int index = flagcode_valueIndex (flag);
2870 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2872 gc.counters[index]++;
2876 context_decCounter (flagcode flag)
2878 int index = flagcode_valueIndex (flag);
2880 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2881 gc.counters[index]--;
2884 bool context_showFunction (void)
2886 return (gc.showfunction);
2890 context_setString (flagcode flag, cstring val)
2892 int index = flagcode_stringIndex (flag);
2894 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2896 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2900 case FLG_MESSAGESTREAM:
2901 case FLG_WARNINGSTREAM:
2902 case FLG_ERRORSTREAM:
2904 if (cstring_isDefined (val))
2908 if (osd_fileExists (val))
2910 if (context_getFlag (FLG_STREAMOVERWRITE))
2912 llfatalerror (message
2913 ("Output stream file %s would overwrite existing file. "
2914 "Use -streamoverwrite if you want to allow this.",
2919 fstream = fopen (cstring_toCharsSafe (val), "w");
2921 if (fstream == NULL)
2923 llfatalerror (message ("Unable to open output stream file %s for writing",
2928 ** This ensures fstream will be closed on exit.
2931 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2935 case FLG_MESSAGESTREAM:
2936 g_messagestream = fstream;
2937 /*@innerbreak@*/ break;
2938 case FLG_WARNINGSTREAM:
2939 g_warningstream = fstream;
2940 /*@innerbreak@*/ break;
2941 case FLG_ERRORSTREAM:
2942 g_errorstream = fstream;
2943 /*@innerbreak@*/ break;
2946 /*@-statetransfer@*/
2947 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2950 case FLG_SYSTEMDIRS:
2952 llassert (cstring_isDefined (val));
2954 if (cstring_firstChar (val) == '\"')
2957 cstring tval = cstring_copy (cstring_suffix (val, 1));
2959 if (cstring_lastChar (tval) != '\"')
2961 int n = size_toInt (cstring_length (tval) - 1);
2963 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2968 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2971 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2975 cstring otval = tval;
2976 tval = cstring_prefix (tval, size_fromInt (n));
2977 cstring_free (otval);
2981 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2982 DPRINTF (("val = %s", val));
2983 cstring_free (tval);
2984 cstring_free (oval);
2991 llassert (cstring_isDefined (val));
2993 if (cstring_length (val) == 0)
2996 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2998 else if (cstring_lastChar (val) != CONNECTCHAR)
3000 val = cstring_appendChar (val, CONNECTCHAR);
3010 ; /* Okay not handle everything in this switch */
3013 } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */
3016 if (cstring_length (val) >= 1
3017 && cstring_firstChar (val) == '\"')
3019 llerror_flagWarning (message
3020 ("Setting %s to string beginning with \". You probably "
3021 "don't meant to have the \"'s.",
3022 flagcode_unparse (flag)));
3025 gc.strings[index] = val;
3028 static /*@exposed@*/ cstring
3029 context_exposeString (flagcode flag)
3031 int index = flagcode_stringIndex (flag);
3033 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3034 return (gc.strings[index]);
3038 context_getString (flagcode flag)
3040 return (context_exposeString (flag));
3044 context_resetErrors (void)
3049 void context_initMod (void)
3050 /*@globals undef gc; @*/
3052 gc.kind = CX_GLOBAL;
3054 gc.savekind = CX_ERROR;
3055 gc.savecont.glob = FALSE;
3057 gc.instandardlib = FALSE;
3060 gc.linesprocessed = 0;
3061 gc.speclinesprocessed = 0;
3062 gc.insuppressregion = FALSE;
3063 gc.macroMissingParams = FALSE;
3064 gc.preprocessing = FALSE;
3065 gc.incommandline = FALSE;
3066 gc.mc = macrocache_create ();
3068 gc.maxmods = DEFAULTMAXMODS;
3069 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3071 gc.library = FLG_ANSILIB;
3073 gc.locstack = filelocStack_new ();
3074 gc.modrecs = sRefSetList_undefined;
3075 gc.anyExports = FALSE;
3077 gc.ftab = fileTable_create ();
3078 gc.msgLog = messageLog_new ();
3079 gc.inimport = FALSE;
3080 gc.inDerivedFile = FALSE;
3081 gc.inheader = FALSE;
3082 gc.markers = flagMarkerList_new ();
3083 gc.cont.glob = TRUE;
3084 gc.showfunction = FALSE;
3085 gc.msgAnnote = cstring_undefined;
3086 gc.aliasAnnote = sRef_undefined;
3087 gc.aliasAnnoteAls = sRef_undefined;
3088 gc.boolType = ctype_bool;
3089 gc.mods = sRefSet_new ();
3091 gc.saveloc = fileloc_undefined;
3093 gc.inmacrocache = FALSE;
3094 gc.inclause = NOCLAUSE;
3095 gc.clauses = clauseStack_new ();
3096 gc.globs = globSet_new ();
3097 gc.nacct = typeIdSet_emptySet ();
3098 gc.acct = typeIdSet_emptySet ();
3099 gc.facct = typeIdSet_emptySet ();
3100 gc.savedFlags = FALSE;
3101 gc.pushloc = fileloc_undefined;
3102 gc.protectVars = FALSE;
3103 gc.justpopped = FALSE;
3104 gc.isNullGuarded = NO;
3105 gc.globs_used = globSet_undefined;
3109 gc.setGlobally[code] = FALSE;
3110 gc.setLocally[code] = FALSE;
3115 context_resetAllFlags ();
3117 assertSet (gc.flags); /* Can't use global in defines */
3118 assertSet (gc.saveflags);
3119 assertSet (gc.values);
3120 assertSet (gc.strings);
3122 conext_resetAllCounters ();
3123 assertSet (gc.counters);
3125 context_setMode (DEFAULT_MODE);
3127 gc.stateTable = metaStateTable_create ();
3128 gc.annotTable = annotationTable_create ();
3130 gc.inFunctionHeader = FALSE;
3132 DPRINTF (("Annotations: \n%s",
3133 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3134 DPRINTF (("State: \n%s",
3135 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3140 context_typeofZero (void)
3142 ctype ct = ctype_int;
3144 if (context_getFlag (FLG_ZEROPTR))
3146 ct = ctype_makeConj (ct, ctype_voidPointer);
3149 if (context_getFlag (FLG_ZEROBOOL)) {
3150 ct = ctype_makeConj (ct, ctype_bool);
3157 context_typeofOne (void)
3159 ctype ct = ctype_int;
3161 /* 1 is on longer a bool (was before 2.4)
3162 if (!context_getFlag (FLG_ABSTRACTBOOL))
3164 ct = ctype_makeConj (ct, ctype_bool);
3172 context_unparse (void)
3179 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3182 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3185 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3188 s = message ("Inner Context [%d] : %q",
3190 fileloc_unparse (g_currentloc));
3193 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3194 uentry_unparse (gc.cont.fcn),
3195 fileloc_unparse (g_currentloc),
3196 typeIdSet_unparse (gc.acct),
3197 sRefSet_unparse (gc.mods));
3200 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3202 case CX_UNKNOWNMACRO:
3203 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3206 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3209 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3212 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3214 case CX_FCNDECLARATION:
3215 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3218 s = message ("Un-unparseable context: %d", (int) gc.kind);
3222 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3227 context_currentFunctionType (void)
3229 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3231 return (uentry_getType (gc.cont.fcn));
3233 else if (gc.kind == CX_INNER)
3235 llcontbuglit ("context_currentFunctionType: inner context");
3236 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3237 return (context_currentFunctionType ());
3241 llcontbuglit ("context_currentFunctionType: not in function");
3242 return (ctype_undefined);
3247 context_enterInnerContext (void)
3249 if (context_getFlag (FLG_GRAMMAR))
3251 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3254 if (gc.kind == CX_GLOBAL)
3259 else if (gc.kind == CX_INNER)
3268 usymtab_enterScope ();
3269 pushClause (NOCLAUSE);
3273 context_exitInnerPlain (void) /*@modifies gc;@*/
3275 context_exitInner (exprNode_undefined);
3279 context_exitInner (exprNode exp)
3281 if (context_getFlag (FLG_GRAMMAR))
3283 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3286 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3287 ("inclause = %s", clause_nameTaken (gc.inclause)));
3289 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3290 gc.inclause = topClause (gc.clauses);
3292 if (gc.kind == CX_INNER)
3294 if (--gc.cont.cdepth == 0)
3296 gc.kind = CX_GLOBAL;
3297 gc.cont.glob = TRUE;
3302 if (gc.kind == CX_GLOBAL)
3304 llcontbuglit ("Attempt to exit global context");
3309 usymtab_exitScope (exp);
3314 context_enterStructInnerContext (void)
3316 if (context_getFlag (FLG_GRAMMAR))
3318 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3321 if (gc.kind == CX_GLOBAL)
3326 else if (gc.kind == CX_INNER)
3335 usymtab_enterScope ();
3337 if (context_getFlag (FLG_GRAMMAR))
3339 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3344 context_exitStructInnerContext (void)
3346 if (context_getFlag (FLG_GRAMMAR))
3348 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3351 if (gc.kind == CX_INNER)
3353 if (gc.cont.cdepth <= 0)
3355 llcontbuglit ("Attempt to exit inner context with no depth");
3356 gc.kind = CX_GLOBAL;
3357 gc.cont.glob = TRUE;
3363 if (gc.cont.cdepth == 0)
3365 gc.kind = CX_GLOBAL;
3366 gc.cont.glob = TRUE;
3372 if (gc.kind == CX_GLOBAL)
3374 llcontbuglit ("Attempt to exit global context");
3379 usymtab_exitScope (exprNode_undefined);
3381 if (context_getFlag (FLG_GRAMMAR))
3383 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3388 context_exitInnerSafe (void)
3390 if (context_getFlag (FLG_GRAMMAR))
3392 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3395 if (gc.kind == CX_INNER)
3397 if (--gc.cont.cdepth <= 0)
3402 else if (gc.kind == CX_GLOBAL)
3404 llcontbuglit ("Attempt to exit global context");
3409 if (usymtab_inDeepScope ())
3411 usymtab_exitScope (exprNode_undefined);
3417 void setModuleAccess (void)
3419 gc.facct = typeIdSet_emptySet ();
3421 if (fileId_isValid (currentFile ()))
3423 cstring baseName = fileloc_getBase (g_currentloc);
3425 if (context_getFlag (FLG_ACCESSFILE))
3427 if (usymtab_existsType (baseName))
3429 gc.facct = typeIdSet_insert (gc.facct,
3430 usymtab_getTypeId (baseName));
3438 if (context_getFlag (FLG_ACCESSMODULE))
3441 bool hasaccess = FALSE;
3443 for (i = 0; i < gc.nmods; i++)
3445 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3447 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3456 gc.inheader = fileId_isHeader (currentFile ());
3460 llcontbuglit ("Current file not defined\n");
3461 gc.facct = typeIdSet_emptySet ();
3463 gc.inheader = FALSE;
3466 /* 17 Jan 1995: forgot to clear nacct */
3468 gc.nacct = typeIdSet_emptySet ();
3472 context_enterFileAux (void)
3478 context_enterFile (void)
3480 context_enterFileAux ();
3481 usymtab_enterFile ();
3485 context_enterMacroFile (void)
3487 context_enterFileAux ();
3491 context_inFunction (void)
3493 kcontext ck = gc.kind;
3495 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3499 context_inFunctionLike (void)
3501 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3502 || gc.kind == CX_FCNDECLARATION
3503 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3507 context_inRealFunction (void)
3509 kcontext ck = gc.kind;
3511 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3515 context_processAllMacros (void)
3517 usymtab_enterFile ();
3519 gc.inmacrocache = TRUE;
3520 macrocache_processUndefinedElements (gc.mc);
3522 usymtab_exitFile ();
3524 gc.inmacrocache = FALSE;
3525 macrocache_finalize ();
3529 ** this happens once at the end of each C file
3531 ** check each Macro that was defined in current file.c or current file.h
3536 context_processMacros (void)
3538 if (fileId_isValid (currentFile ()))
3541 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3543 gc.inmacrocache = TRUE;
3545 DPRINTF (("Processing macros: %s", cbase));
3546 lastfl = macrocache_processFileElements (gc.mc, cbase);
3547 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3549 cstring_free (cbase);
3551 if (fileloc_isDefined (lastfl))
3553 g_currentloc = fileloc_update (g_currentloc, lastfl);
3557 gc.inmacrocache = FALSE;
3562 context_processingMacros (void)
3564 return (gc.inmacrocache);
3568 context_exitCFile (void)
3570 if (gc.kind != CX_GLOBAL)
3573 (cstring_makeLiteral ("File ended outside global scope"));
3576 if (gc.insuppressregion)
3578 /* gack...don't reverse the order of these lines! ;-> */
3579 gc.insuppressregion = FALSE;
3580 llerrorlit (FLG_SYNTAX,
3581 "File ended in ignore errors region, "
3582 "possible missing /*@end*/");
3585 /* fix up parse errors */
3587 while (!usymtab_inFileScope ())
3589 usymtab_quietExitScope (g_currentloc);
3593 ** Clear the file-specific modifies information.
3596 sRefSetList_elements (gc.modrecs, mods)
3598 sRefSet_clearStatics (mods);
3599 } end_sRefSetList_elements ;
3601 sRefSetList_clear (gc.modrecs);
3603 context_processMacros ();
3606 usymtab_exitFile ();
3608 gc.inDerivedFile = FALSE;
3609 filelocStack_clear (gc.locstack);
3611 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3613 gc.cont.glob = TRUE;
3617 context_restoreFlagSettings ();
3618 gc.savedFlags = FALSE;
3622 DPRINTF (("After exiting file: "));
3623 usymtab_printAll ();
3628 context_exitMacroCache (void)
3630 if (gc.kind != CX_GLOBAL)
3632 if (context_inMacro ())
3633 /* this is okay, file could end without newline in macro */
3635 DPRINTF (("Still in macro: %s",
3636 context_unparse ()));
3637 context_exitFunction ();
3641 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3642 context_unparse ()));
3643 gc.kind = CX_GLOBAL;
3648 ** no longer valid here
3649 ** if (gc.insuppressregion)
3651 ** gc.insuppressregion = FALSE;
3652 ** llerror ("File ended in ignore errors region, possible missing @");
3656 gc.cont.glob = TRUE;
3660 context_saveLocation (void)
3662 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3663 fileloc_free (gc.saveloc);
3664 gc.saveloc = fileloc_copy (g_currentloc);
3668 context_getSaveLocation (void)
3670 fileloc fl = gc.saveloc;
3671 gc.saveloc = fileloc_undefined;
3675 /*@observer@*/ cstring
3676 context_inFunctionName (void)
3678 if (gc.kind == CX_FUNCTION
3679 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3680 || gc.kind == CX_MACROCONST
3681 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3683 return (uentry_rawName (gc.cont.fcn));
3687 llcontbuglit ("context_inFunctionName: not in function");
3688 return (cstring_undefined);
3693 context_userSetFlag (flagcode f, bool b)
3695 DPRINTF (("set flag: %s / %s",
3696 flagcode_unparse (f),
3697 bool_unparse (context_getFlag (f))));
3699 if (f == FLG_NEVERINCLUDE && b)
3701 if (gc.flags[FLG_EXPORTHEADER])
3704 (cstring_makeLiteral
3705 ("Setting +neverinclude after +exportheader. "
3706 "Turning off exportheader, since headers are not checked "
3707 "when +neverinclude is used."));
3709 gc.flags[FLG_EXPORTHEADER] = FALSE;
3714 if (f == FLG_EXPORTHEADER && b)
3716 if (gc.flags[FLG_NEVERINCLUDE])
3719 (cstring_makeLiteral
3720 ("Setting +exportheader after +neverinclude. "
3721 "Not setting exportheader, since headers are not checked "
3722 "when +neverinclude is used."));
3723 gc.flags[FLG_EXPORTHEADER] = FALSE;
3729 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3731 bool lastsetting = context_getFlag (f);
3733 if (bool_equal (lastsetting, b)
3734 && !flagcode_isSpecialFlag (f)
3735 && !flagcode_isIdemFlag (f)
3736 && !flagcode_hasArgument (f))
3739 (message ("Setting %s%s redundant with current value",
3740 cstring_makeLiteralTemp (b ? "+" : "-"),
3741 flagcode_unparse (f)));
3745 if (flagcode_isWarnUseFlag (f) && b)
3747 if (!context_getFlag (FLG_WARNUSE))
3750 (message ("Flag +%s is canceled by -warnuse",
3751 flagcode_unparse (f)));
3756 if (flagcode_isLibraryFlag (f))
3758 if (gc.library != FLG_ANSILIB
3762 (message ("Selecting library %s after library %s was "
3763 "selected (only one library may be used)",
3764 flagcode_unparse (f),
3765 flagcode_unparse (gc.library)));
3768 if (f == FLG_UNIXLIB)
3770 if (context_getFlag (FLG_WARNUNIXLIB))
3773 (cstring_makeLiteral
3774 ("Selecting unix library. Unix library is "
3775 "based on the Single Unix Specification, Version 2. Not all "
3776 "Unix implementations are consistend with this specification. "
3777 "Use -warnunixlib to suppress this message."));
3784 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3788 ("Setting +%s will not produce warnings with -namechecks. "
3789 "Must set +namechecks also.",
3790 flagcode_unparse (f)));
3793 gc.setGlobally[f] = TRUE;
3794 context_setFlag (f, b, g_currentloc);
3798 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3802 context_saveFlagSettings ();
3805 if (ynm_isOff (set))
3807 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3809 else if (ynm_isOn (set))
3811 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3812 gc.setLocally[f] = TRUE;
3816 context_restoreFlag (f, loc);
3821 context_restoreFlag (flagcode f, fileloc loc)
3827 message ("Attempt to restore flag %s when no file scope flags "
3829 flagcode_unparse (f)),
3834 context_addFlagMarker (f, MAYBE, loc);
3835 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3841 context_setFlag (flagcode f, bool b, fileloc loc)
3843 context_setFlagAux (f, b, FALSE, FALSE, loc);
3847 context_setFlagTemp (flagcode f, bool b)
3849 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3854 # define DOSET(ff,b) \
3855 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3856 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3857 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3858 gc.flags[ff] = b; } while (FALSE)
3861 context_setFlagAux (flagcode f, bool b, bool inFile,
3862 /*@unused@*/ bool isRestore, fileloc loc)
3864 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3867 ** Removed test for special flags.
3870 if (flagcode_isIdemFlag (f))
3879 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3881 if (b) /* Turing higher level on, turns on all lower levels */
3885 case FLG_ITS4MOSTRISKY:
3886 DOSET (FLG_ITS4VERYRISKY, b);
3888 case FLG_ITS4VERYRISKY:
3889 DOSET (FLG_ITS4RISKY, b);
3892 DOSET (FLG_ITS4MODERATERISK, b);
3894 case FLG_ITS4MODERATERISK:
3895 DOSET (FLG_ITS4LOWRISK, b);
3897 case FLG_ITS4LOWRISK:
3902 else /* Turning level off, turns off all higher levels */
3906 case FLG_ITS4LOWRISK:
3907 DOSET (FLG_ITS4MODERATERISK, b);
3909 case FLG_ITS4MODERATERISK:
3910 DOSET (FLG_ITS4RISKY, b);
3913 DOSET (FLG_ITS4VERYRISKY, b);
3915 case FLG_ITS4VERYRISKY:
3916 DOSET (FLG_ITS4MOSTRISKY, b);
3918 case FLG_ITS4MOSTRISKY:
3927 case FLG_MESSAGESTREAMSTDOUT:
3928 g_messagestream = stdout;
3930 case FLG_MESSAGESTREAMSTDERR:
3931 g_messagestream = stderr;
3933 case FLG_WARNINGSTREAMSTDOUT:
3934 g_warningstream = stdout;
3936 case FLG_WARNINGSTREAMSTDERR:
3937 g_warningstream = stderr;
3939 case FLG_ERRORSTREAMSTDOUT:
3940 g_errorstream = stdout;
3942 case FLG_ERRORSTREAMSTDERR:
3943 g_errorstream = stderr;
3946 DOSET (FLG_ALLEMPTY, b);
3947 DOSET (FLG_IFEMPTY, b);
3948 DOSET (FLG_WHILEEMPTY, b);
3949 DOSET (FLG_FOREMPTY, b);
3952 DOSET (FLG_PREDBOOL, b);
3953 DOSET (FLG_PREDBOOLINT, b);
3954 DOSET (FLG_PREDBOOLPTR, b);
3955 DOSET (FLG_PREDBOOLOTHERS, b);
3958 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3959 DOSET (FLG_CHECKEDGLOBALIAS, b);
3960 DOSET (FLG_CHECKMODGLOBALIAS, b);
3961 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3964 DOSET (FLG_ALLBLOCK, b);
3965 DOSET (FLG_IFBLOCK, b);
3966 DOSET (FLG_WHILEBLOCK, b);
3967 DOSET (FLG_FORBLOCK, b);
3981 DOSET (FLG_GRAMMAR, b);
3983 case FLG_CODEIMPONLY:
3984 DOSET (FLG_CODEIMPONLY, b);
3985 DOSET (FLG_GLOBIMPONLY, b);
3986 DOSET (FLG_RETIMPONLY, b);
3987 DOSET (FLG_STRUCTIMPONLY, b);
3989 case FLG_SPECALLIMPONLY:
3990 DOSET (FLG_SPECALLIMPONLY, b);
3991 DOSET (FLG_SPECGLOBIMPONLY, b);
3992 DOSET (FLG_SPECRETIMPONLY, b);
3993 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3995 case FLG_ALLIMPONLY:
3996 DOSET (FLG_ALLIMPONLY, b);
3997 DOSET (FLG_GLOBIMPONLY, b);
3998 DOSET (FLG_RETIMPONLY, b);
3999 DOSET (FLG_STRUCTIMPONLY, b);
4000 DOSET (FLG_SPECGLOBIMPONLY, b);
4001 DOSET (FLG_SPECRETIMPONLY, b);
4002 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4004 case FLG_ANSI89LIMITS:
4005 DOSET (FLG_ANSI89LIMITS, b);
4006 DOSET (FLG_CONTROLNESTDEPTH, b);
4007 DOSET (FLG_STRINGLITERALLEN, b);
4008 DOSET (FLG_INCLUDENEST, b);
4009 DOSET (FLG_NUMSTRUCTFIELDS, b);
4010 DOSET (FLG_NUMENUMMEMBERS, b);
4014 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4015 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4016 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4017 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4018 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4019 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4020 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4023 case FLG_ISO99LIMITS:
4024 DOSET (FLG_ISO99LIMITS, b);
4025 DOSET (FLG_CONTROLNESTDEPTH, b);
4026 DOSET (FLG_STRINGLITERALLEN, b);
4027 DOSET (FLG_INCLUDENEST, b);
4028 DOSET (FLG_NUMSTRUCTFIELDS, b);
4029 DOSET (FLG_NUMENUMMEMBERS, b);
4033 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4034 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4035 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4036 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4037 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4038 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4039 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4042 case FLG_EXTERNALNAMELEN:
4043 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4044 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4046 case FLG_INTERNALNAMELEN:
4047 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4048 DOSET (FLG_INTERNALNAMELEN, TRUE);
4050 case FLG_EXTERNALNAMECASEINSENSITIVE:
4051 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4053 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4055 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4056 context_setValue (FLG_EXTERNALNAMELEN, 0);
4059 case FLG_INTERNALNAMECASEINSENSITIVE:
4060 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4062 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4064 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4065 context_setValue (FLG_INTERNALNAMELEN, 0);
4068 case FLG_INTERNALNAMELOOKALIKE:
4069 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4071 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4073 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4074 context_setValue (FLG_INTERNALNAMELEN, 0);
4078 DOSET (FLG_MODNOMODS, b);
4079 DOSET (FLG_MODGLOBSUNSPEC, b);
4080 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4083 DOSET (FLG_EXPORTVAR, b);
4084 DOSET (FLG_EXPORTFCN, b);
4085 DOSET (FLG_EXPORTTYPE, b);
4086 DOSET (FLG_EXPORTMACRO, b);
4087 DOSET (FLG_EXPORTCONST, b);
4088 gc.anyExports = TRUE;
4091 DOSET (FLG_RETEXPOSE, b);
4092 DOSET (FLG_ASSIGNEXPOSE, b);
4093 DOSET (FLG_CASTEXPOSE, b);
4096 DOSET (FLG_RETVALBOOL, b);
4097 DOSET (FLG_RETVALINT, b);
4098 DOSET (FLG_RETVALOTHER, b);
4103 DOSET (FLG_EXPORTLOCAL, FALSE);
4104 DOSET (FLG_DECLUNDEF, FALSE);
4105 DOSET (FLG_SPECUNDEF, FALSE);
4106 DOSET (FLG_TOPUNUSED, FALSE);
4110 DOSET (FLG_LOOPLOOPBREAK, b);
4111 DOSET (FLG_LOOPSWITCHBREAK, b);
4112 DOSET (FLG_SWITCHLOOPBREAK, b);
4113 DOSET (FLG_SWITCHSWITCHBREAK, b);
4114 DOSET (FLG_LOOPLOOPCONTINUE, b);
4115 DOSET (FLG_DEEPBREAK, b);
4118 DOSET (FLG_FORLOOPEXEC, b);
4119 DOSET (FLG_WHILELOOPEXEC, b);
4120 DOSET (FLG_ITERLOOPEXEC, b);
4123 DOSET (FLG_ACCESSMODULE, b);
4124 DOSET (FLG_ACCESSFILE, b);
4125 DOSET (FLG_ACCESSCZECH, b);
4128 DOSET (FLG_ALLMACROS, b);
4129 DOSET (FLG_FCNMACROS, b);
4130 DOSET (FLG_CONSTMACROS, b);
4133 DOSET (FLG_BOUNDSREAD, b);
4134 DOSET (FLG_BOUNDSWRITE, b);
4135 DOSET (FLG_LIKELYBOUNDSREAD, b);
4136 DOSET (FLG_LIKELYBOUNDSWRITE, b);
4138 case FLG_BOUNDSREAD:
4139 DOSET (FLG_LIKELYBOUNDSREAD, b);
4141 case FLG_BOUNDSWRITE:
4142 DOSET (FLG_LIKELYBOUNDSWRITE, b);
4144 case FLG_LIKELYBOUNDS:
4145 DOSET (FLG_LIKELYBOUNDSREAD, b);
4146 DOSET (FLG_LIKELYBOUNDSWRITE, b);
4150 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4151 DOSET (FLG_CZECHFUNCTIONS, b);
4152 DOSET (FLG_CZECHVARS, b);
4153 DOSET (FLG_CZECHCONSTANTS, b);
4154 DOSET (FLG_CZECHTYPES, b);
4157 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4158 DOSET (FLG_SLOVAKFUNCTIONS, b);
4159 DOSET (FLG_SLOVAKVARS, b);
4160 DOSET (FLG_SLOVAKCONSTANTS, b);
4161 DOSET (FLG_SLOVAKTYPES, b);
4163 case FLG_CZECHOSLOVAK:
4164 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4165 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4166 DOSET (FLG_CZECHOSLOVAKVARS, b);
4167 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4168 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4171 DOSET (FLG_NULLSTATE, b);
4172 DOSET (FLG_NULLDEREF, b);
4173 DOSET (FLG_NULLASSIGN, b);
4174 DOSET (FLG_NULLPASS, b);
4175 DOSET (FLG_NULLRET, b);
4178 DOSET (FLG_MUSTFREEONLY, b);
4179 DOSET (FLG_MUSTFREEFRESH, b);
4182 DOSET (FLG_NULLSTATE, b);
4183 DOSET (FLG_NULLDEREF, b);
4184 DOSET (FLG_NULLASSIGN, b);
4185 DOSET (FLG_NULLPASS, b);
4186 DOSET (FLG_NULLRET, b);
4187 DOSET (FLG_COMPDEF, b);
4188 DOSET (FLG_COMPMEMPASS, b);
4189 DOSET (FLG_UNIONDEF, b);
4190 DOSET (FLG_MEMTRANS, b);
4191 DOSET (FLG_USERELEASED, b);
4192 DOSET (FLG_ALIASUNIQUE, b);
4193 DOSET (FLG_MAYALIASUNIQUE, b);
4194 DOSET (FLG_MUSTFREEONLY, b);
4195 DOSET (FLG_MUSTFREEFRESH, b);
4196 DOSET (FLG_MUSTDEFINE, b);
4197 DOSET (FLG_GLOBSTATE, b);
4198 DOSET (FLG_COMPDESTROY, b);
4199 DOSET (FLG_MUSTNOTALIAS, b);
4200 DOSET (FLG_MEMIMPLICIT, b);
4201 DOSET (FLG_BRANCHSTATE, b);
4202 /*@fallthrough@*/ /* also sets memtrans flags */
4204 DOSET (FLG_MEMTRANS, b);
4205 DOSET (FLG_EXPOSETRANS, b);
4206 DOSET (FLG_OBSERVERTRANS, b);
4207 DOSET (FLG_DEPENDENTTRANS, b);
4208 DOSET (FLG_NEWREFTRANS, b);
4209 DOSET (FLG_ONLYTRANS, b);
4210 DOSET (FLG_OWNEDTRANS, b);
4211 DOSET (FLG_FRESHTRANS, b);
4212 DOSET (FLG_SHAREDTRANS, b);
4213 DOSET (FLG_TEMPTRANS, b);
4214 DOSET (FLG_KEPTTRANS, b);
4215 DOSET (FLG_REFCOUNTTRANS, b);
4216 DOSET (FLG_STATICTRANS, b);
4217 DOSET (FLG_UNKNOWNTRANS, b);
4218 DOSET (FLG_KEEPTRANS, b);
4219 DOSET (FLG_IMMEDIATETRANS, b);
4226 if (b && !gc.anyExports
4227 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4228 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4229 || f == FLG_EXPORTCONST
4230 || f == FLG_EXPORTANY))
4232 gc.anyExports = TRUE;
4237 context_maybeSet (flagcode d)
4239 return (gc.flags[d] || gc.setLocally[d]);
4243 context_getFlag (flagcode d)
4245 return (gc.flags[d]);
4249 context_flagOn (flagcode f, fileloc loc)
4251 return (!context_suppressFlagMsg (f, loc));
4254 static void context_saveFlagSettings (void)
4256 gc.savedFlags = TRUE;
4257 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4258 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4261 static void context_restoreFlagSettings (void)
4263 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4264 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4265 gc.savedFlags = FALSE;
4268 void context_setFilename (fileId fid, int lineno)
4269 /*@globals fileloc g_currentloc;@*/
4270 /*@modifies g_currentloc@*/
4272 if (fileId_baseEqual (currentFile (), fid))
4279 fileloc_setColumn (g_currentloc, 0);
4281 if (fileloc_isSpecialFile (g_currentloc))
4283 gc.inDerivedFile = TRUE;
4286 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4288 int maxdepth = context_getValue (FLG_INCLUDENEST);
4290 if (filelocStack_size (gc.locstack) > maxdepth)
4292 int depth = filelocStack_includeDepth (gc.locstack);
4294 if (depth > maxdepth)
4298 message ("Maximum include nesting depth "
4299 "(%d, current depth %d) exceeded",
4302 filelocStack_nextTop (gc.locstack)))
4304 filelocStack_printIncludes (gc.locstack);
4310 g_currentloc = fileloc_create (fid, lineno, 1);
4311 gc.inheader = fileId_isHeader (currentFile ());
4313 context_enterFileAux ();
4317 void context_enterIterDef (/*@observer@*/ uentry le)
4319 context_enterMacro (le);
4320 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4321 gc.kind = CX_ITERDEF;
4324 void context_enterIterEnd (/*@observer@*/ uentry le)
4326 context_enterMacro (le);
4327 gc.kind = CX_ITEREND;
4331 context_destroyMod (void)
4332 /*@globals killed gc@*/
4336 ctype_destroyMod ();
4343 fileTable_free (gc.ftab);
4344 gc.ftab = fileTable_undefined;
4346 filelocStack_free (gc.locstack);
4349 macrocache_free (gc.mc);
4351 /* evans 2002-07-12: not reported because of reldef */
4352 for (i = 0; i < gc.nmods; i++)
4354 cstring_free (gc.moduleaccess[i].file);
4357 sfree (gc.moduleaccess);
4360 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4361 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4364 sRefSetList_free (gc.modrecs);
4366 flagMarkerList_free (gc.markers);
4368 messageLog_free (gc.msgLog);
4370 clauseStack_free (gc.clauses);
4373 cstring_free (gc.msgAnnote);
4374 globSet_free (gc.globs_used);
4375 metaStateTable_free (gc.stateTable);
4376 annotationTable_free (gc.annotTable);
4383 bool context_msgBoolInt (void)
4385 return context_flagOn (FLG_BOOLINT, g_currentloc);
4388 bool context_msgCharInt (void)
4390 return context_flagOn (FLG_CHARINT, g_currentloc);
4393 bool context_msgEnumInt (void)
4395 return context_flagOn (FLG_ENUMINT, g_currentloc);
4398 bool context_msgLongInt (void)
4400 return context_flagOn (FLG_LONGINT, g_currentloc);
4403 bool context_msgShortInt (void)
4405 return context_flagOn (FLG_SHORTINT, g_currentloc);
4408 bool context_msgPointerArith (void)
4410 return context_flagOn (FLG_POINTERARITH, g_currentloc);
4413 bool context_msgStrictOps (void)
4415 return context_flagOn (FLG_STRICTOPS, g_currentloc);
4418 bool context_msgLh (void)
4420 return gc.flags [FLG_DOLH];
4423 void context_pushLoc (void)
4425 fileloc_free (gc.pushloc);
4426 gc.pushloc = gc.saveloc;
4427 gc.saveloc = fileloc_undefined;
4430 void context_popLoc (void)
4432 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4435 bool context_inGlobalScope (void)
4437 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4440 bool context_inInnerScope (void)
4442 return (gc.kind == CX_INNER);
4445 void context_setProtectVars (void)
4447 gc.protectVars = TRUE;
4450 bool context_anyErrors (void)
4452 return (gc.numerrors > 0);
4455 void context_hasError (void)
4458 DPRINTF (("num errors: %d", gc.numerrors));
4461 int context_numErrors (void)
4463 return gc.numerrors;
4466 bool context_neednl (void)
4471 void context_setNeednl (void)
4476 int context_getExpect (void)
4478 return (context_getValue (FLG_EXPECT));
4481 int context_getLCLExpect (void)
4483 return (context_getValue (FLG_LCLEXPECT));
4486 int context_getLimit (void)
4488 return (context_getValue (FLG_LIMIT));
4491 bool context_unlimitedMessages (void)
4493 return (context_getLimit () < 0);
4496 void context_releaseVars (void)
4498 llassert (gc.protectVars);
4499 gc.protectVars = FALSE;
4502 void context_sizeofReleaseVars (void)
4504 /* If there is a nested sizeof, this might not hold:
4505 llassert (gc.protectVars);
4508 gc.protectVars = FALSE;
4511 bool context_inProtectVars (void)
4513 return (gc.protectVars);
4516 void context_hideShowscan (void)
4518 gc.flags[FLG_SHOWSCAN] = FALSE;
4521 void context_unhideShowscan (void)
4523 gc.flags[FLG_SHOWSCAN] = TRUE;
4526 bool context_inHeader (void)
4528 return (gc.inheader);
4531 fileTable context_fileTable (void)
4536 cstring context_tmpdir (void)
4538 return (context_getString (FLG_TMPDIR));
4541 messageLog context_messageLog (void)
4546 bool context_inMacroFunction (void)
4548 return (gc.kind == CX_MACROFCN);
4551 bool context_inMacroConstant (void)
4553 return (gc.kind == CX_MACROCONST);
4556 bool context_inUnknownMacro (void)
4558 return (gc.kind == CX_UNKNOWNMACRO);
4561 void context_setShownFunction (void)
4563 gc.showfunction = FALSE;
4566 bool context_doDump (void)
4568 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4571 bool context_doMerge (void)
4573 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4576 cstring context_getDump (void)
4578 return context_getString (FLG_DUMP);
4581 cstring context_getMerge (void)
4583 return context_getString (FLG_MERGE);
4586 bool context_inLCLLib (void)
4588 return (gc.kind == CX_LCLLIB);
4592 /*drl add these 3/5/2003*/
4593 static bool inSizeof = FALSE;
4595 bool context_inSizeof (void)
4600 void context_enterSizeof (void)
4602 DPRINTF((message("context_enterSizeof ") ) );
4606 void context_leaveSizeof (void)
4608 DPRINTF((message("context_leaveSizeof ") ));
4611 /*end function added 3/5/2003*/
4614 bool context_inImport (void)
4616 return (gc.inimport);
4619 void context_enterImport (void)
4624 void context_leaveImport (void)
4626 gc.inimport = FALSE;
4629 bool context_inMacro (void)
4631 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4632 || gc.kind == CX_UNKNOWNMACRO
4633 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4636 bool context_inIterDef (void)
4638 return (gc.kind == CX_ITERDEF);
4641 bool context_inIterEnd (void)
4643 return (gc.kind == CX_ITEREND);
4646 int context_getLinesProcessed (void)
4648 return (gc.linesprocessed);
4651 int context_getSpecLinesProcessed (void)
4653 return (gc.speclinesprocessed);
4656 void context_processedSpecLine (void)
4658 gc.speclinesprocessed++;
4661 void context_resetSpecLines (void)
4663 gc.speclinesprocessed = 0;
4667 bool context_inGlobalContext (void)
4669 return (gc.kind == CX_GLOBAL);
4672 static void context_quietExitScopes (void)
4675 ** Try to restore the global scope (after an error).
4678 while (!usymtab_inFileScope ())
4680 usymtab_quietExitScope (g_currentloc);
4683 gc.cont.glob = TRUE;
4684 gc.kind = CX_GLOBAL;
4687 void context_checkGlobalScope (void)
4689 if (gc.kind != CX_GLOBAL)
4691 if (context_inMacro ())
4693 ; /* evans 2001-10-14: Okay to be in a macro here! */
4697 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4698 context_quietExitScopes ();
4703 void context_setFileId (fileId s)
4705 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4708 bool context_setBoolName (void)
4710 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4714 cstring context_printBoolName (void)
4716 if (context_setBoolName ())
4718 return context_getBoolName ();
4722 return cstring_makeLiteralTemp ("boolean");
4726 cstring context_getBoolName (void)
4728 return (context_getString (FLG_BOOLTYPE));
4731 cstring context_getFalseName (void)
4733 return (context_getString (FLG_BOOLFALSE));
4736 cstring context_getTrueName (void)
4738 return (context_getString (FLG_BOOLTRUE));
4741 cstring context_getLarchPath (void)
4743 return (context_getString (FLG_LARCHPATH));
4746 cstring context_getLCLImportDir (void)
4748 return (context_getString (FLG_LCLIMPORTDIR));
4751 static void context_setJustPopped (void)
4753 gc.justpopped = TRUE;
4756 void context_clearJustPopped (void)
4758 gc.justpopped = FALSE;
4761 bool context_justPopped (void)
4763 return (gc.justpopped);
4766 void context_setMacroMissingParams (void)
4768 gc.macroMissingParams = TRUE;
4771 void context_resetMacroMissingParams (void)
4773 gc.macroMissingParams = FALSE;
4776 bool context_isMacroMissingParams (void)
4778 return (gc.macroMissingParams);
4781 void context_showFilelocStack (void)
4783 filelocStack_printIncludes (gc.locstack);
4786 metaStateTable context_getMetaStateTable (void)
4788 return gc.stateTable;
4791 metaStateInfo context_lookupMetaStateInfo (cstring key)
4793 return metaStateTable_lookup (gc.stateTable, key);
4796 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4798 annotationInfo ainfo;
4800 ainfo = annotationTable_lookup (gc.annotTable, annot);
4805 void context_addAnnotation (annotationInfo ainfo)
4807 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4811 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4812 annotationInfo_getLoc (ainfo));
4814 annotationInfo_free (ainfo);
4818 annotationTable_insert (gc.annotTable, ainfo);
4822 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4824 if (metaStateTable_contains (gc.stateTable, mname))
4828 message ("Duplicate metastate declaration: %s", mname),
4829 metaStateInfo_getLoc (msinfo));
4830 cstring_free (mname);
4831 metaStateInfo_free (msinfo);
4835 DPRINTF (("Adding meta state: %s", mname));
4836 metaStateTable_insert (gc.stateTable, mname, msinfo);
4840 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4842 if (metaStateTable_size (gc.stateTable) > 0)
4844 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4845 /* should use smaller value... */
4846 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4848 metaStateTable_elements (gc.stateTable, msname, msi)
4850 mtContextNode context = metaStateInfo_getContext (msi);
4852 if (mtContextNode_matchesRefStrict (context, s))
4854 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4855 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4859 cstring_copy (metaStateInfo_getName (msi)),
4860 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4861 stateInfo_copy (sinfo)));
4865 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4868 end_metaStateTable_elements ;
4870 stateInfo_free (sinfo);
4871 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4876 stateInfo_free (sinfo);
4877 return valueTable_undefined;
4881 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4883 if (metaStateTable_size (gc.stateTable) > 0)
4885 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4886 /* should use smaller value... */
4888 metaStateTable_elements (gc.stateTable, msname, msi)
4890 /* only add global...*/
4891 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4892 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4894 valueTable_insert (res,
4895 cstring_copy (metaStateInfo_getName (msi)),
4896 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4897 stateInfo_copy (sinfo)));
4899 end_metaStateTable_elements ;
4901 stateInfo_free (sinfo);
4902 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4907 stateInfo_free (sinfo);
4908 return valueTable_undefined;
4913 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4917 static ctype lastStruct;
4919 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4925 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4931 ** Why is this stuff in context.c?
4934 /*@unused@*/ static int sInfoNum = 0;
4938 /*@unused@*/ uentry ue;
4939 /*@unused@*/ sRef s;
4943 /*@unused@*/ ctype ct;
4944 /*@unused@*/ constraintList inv;
4945 /*@unused@*/ int ngetUe;
4946 /*@unused@*/ struct getUe * t ;
4949 /* unused: static struct sInfo globalStructInfo; */
4951 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4952 stable release of splint. I coomented them out so that they won't break anything
4953 but didn't delete them because they will be fixed and included later
4960 void context_setGlobalStructInfo (ctype ct, constraintList list)
4966 f = ctype_getFields (ct);
4968 if (constraintList_isDefined(list) )
4970 globalStructInfo.ct = ct;
4971 globalStructInfo.inv = list;
4973 globalStructInfo.ngetUe = 0;
4975 /* abstraction violation fix it * /
4976 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4978 globalStructInfo.ngetUe = f->nelements;
4982 uentryList_elements(f, ue)
4984 globalStructInfo.t[i].ue = ue;
4985 globalStructInfo.t[i].s = uentry_getSref(ue);
4986 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4987 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4992 end_uentryList_elements;
5001 bool hasInvariants (ctype ct) /*@* /
5003 if ( ctype_sameName(globalStructInfo.ct, ct) )