2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 * Modified by Herbert 04/19/97:
29 * - added include for new header portab.h containing OS dependent stuff.
30 * - changed occurrances of '/' as path delimiters to macro from portab.h
31 * - changed the handling of the tmp directory -- will no longer always be
32 * ".", if possible, environment variables "TMP" or, if not set, "TMP",
33 * or, if not set "." will be used.
36 # include "splintMacros.nf"
40 # include "usymtab_interface.h"
43 # include "exprChecks.h"
44 # include "filelocStack.h"
45 # include "fileIdList.h"
51 extern /*@external@*/ int yydebug;
52 extern /*@external@*/ int mtdebug;
64 CX_FUNCTION, CX_FCNDECLARATION,
65 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
66 CX_ITERDEF, CX_ITEREND,
67 CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
68 CX_LCL, CX_LCLLIB, CX_MT
74 int speclinesprocessed;
76 flagMarkerList markers;
79 ** used to record state where a macro must match a function name
80 ** (i.e., no params were listed in the macro definition
83 bool macroMissingParams BOOLBITS;
84 bool preprocessing BOOLBITS;
85 bool incommandline BOOLBITS;
86 bool insuppressregion BOOLBITS;
87 bool inDerivedFile BOOLBITS;
88 bool instandardlib BOOLBITS;
89 bool inimport BOOLBITS;
90 bool inheader BOOLBITS;
91 bool inmacrocache BOOLBITS;
92 bool protectVars BOOLBITS;
94 bool showfunction BOOLBITS;
95 bool savedFlags BOOLBITS;
96 bool justpopped BOOLBITS;
97 bool anyExports BOOLBITS;
98 bool inFunctionHeader BOOLBITS;
111 filelocStack locstack;
114 /*@observer@*/ sRef aliasAnnote;
115 /*@observer@*/ sRef aliasAnnoteAls;
119 /*@observer@*/ sRefSet mods;
121 /* file access types */
124 /* local access types (this function) */
127 /* no access types (@noaccess) */
130 /*@observer@*/ globSet globs;
131 /*@only@*/ globSet globs_used;
135 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
141 bool flags[NUMFLAGS];
142 bool saveflags[NUMFLAGS];
143 bool setGlobally[NUMFLAGS];
144 bool setLocally[NUMFLAGS];
146 int values[NUMVALUEFLAGS];
147 int counters[NUMVALUEFLAGS];
149 o_cstring strings[NUMSTRINGFLAGS];
150 sRefSetList modrecs; /*@i32 ???? what is this for? */
152 metaStateTable stateTable; /* User-defined state information. */
153 annotationTable annotTable; /* User-defined annotations table. */
158 /*@dependent@*/ /*@exposed@*/ uentry fcn;
162 union u_cont savecont;
165 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
166 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
167 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
168 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
170 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
171 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
172 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
173 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
174 static void context_setFlag (flagcode p_f, bool p_b, fileloc p_loc)
175 /*@modifies gc.flags@*/ ;
178 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile,
179 bool p_isRestore, fileloc p_loc)
180 /*@modifies gc.flags@*/ ;
182 static void context_restoreFlag (flagcode p_f, fileloc p_loc)
183 /*@modifies gc.flags@*/ ;
187 cstring context_unparseFlagMarkers ()
189 return (flagMarkerList_unparse (gc.markers));
192 void context_setPreprocessing (void)
194 llassert (!gc.preprocessing);
195 gc.preprocessing = TRUE;
198 void context_clearPreprocessing (void)
200 llassert (gc.preprocessing);
201 gc.preprocessing = FALSE;
204 bool context_isPreprocessing (void)
206 return gc.preprocessing;
209 bool context_loadingLibrary (void)
211 return (fileloc_isLib (g_currentloc));
214 bool context_inXHFile (void)
216 return (fileloc_isXHFile (g_currentloc));
219 void context_setInCommandLine (void)
221 llassert (!gc.incommandline);
222 gc.incommandline = TRUE;
225 void context_clearInCommandLine (void)
227 llassert (gc.incommandline);
228 gc.incommandline = FALSE;
231 bool context_isInCommandLine (void)
233 return gc.incommandline;
237 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
240 clauseStack_push (gc.clauses, c);
242 if (clause_isConditional (c)
243 && context_getFlag (FLG_CONTROLNESTDEPTH))
245 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
246 int depth = clauseStack_controlDepth (gc.clauses);
248 if (depth == maxdepth + 1)
251 (FLG_CONTROLNESTDEPTH,
252 message ("Maximum control nesting depth "
261 clause topClause (clauseStack s) /*@*/
263 if (clauseStack_isEmpty (s)) return NOCLAUSE;
264 return ((clause) clauseStack_top (s));
268 context_addMacroCache (/*@only@*/ cstring def)
270 DPRINTF (("macro cache: %s", def));
271 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
275 context_addComment (/*@only@*/ cstring def, fileloc loc)
277 macrocache_addComment (gc.mc, fileloc_copy (loc), def);
281 ** returns TRUE is fl is in ignore region, or region where -code
283 ** the logic is fuzzy...
287 context_inSuppressFlagZone (fileloc fl, flagcode code)
289 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
292 if (ynm_isMaybe (ret))
300 res = !gc.saveflags[code];
304 res = !context_getFlag (code);
309 res = ynm_toBoolStrict (ret);
316 context_suppressSystemMsg (fileloc fl)
318 if (context_getFlag (FLG_SYSTEMDIRERRORS))
324 return (fileloc_isSystemFile (fl));
329 context_suppressFlagMsg (flagcode flag, fileloc fl)
331 if (context_suppressSystemMsg (fl))
336 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
338 /* want same object compare here */
340 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
342 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
344 return (!context_getFlag (flag)
345 || context_inSuppressRegion ()
346 || context_inSuppressZone (fl)
347 || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
351 return (context_inSuppressFlagZone (fl, flag));
356 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
359 if (context_suppressSystemMsg (fl))
365 if (fl == g_currentloc)
366 /*@noaccess fileloc@*/
368 return (context_getFlag (flag) || context_inSuppressRegion ());
373 return (context_getFlag (flag) || context_inSuppressRegion ());
378 context_inSuppressZone (fileloc fl)
380 if (context_suppressSystemMsg (fl))
385 return (flagMarkerList_inIgnore (gc.markers, fl));
389 context_inSuppressRegion (void)
391 return (gc.insuppressregion);
395 context_enterSuppressRegion (fileloc loc)
397 if (gc.insuppressregion)
399 gc.insuppressregion = FALSE; /* get this msg! */
401 ("%q: New ignore errors region entered while in ignore errors region",
402 fileloc_unparse (loc)));
405 gc.insuppressregion = TRUE;
406 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (loc));
410 context_addFlagMarker (flagcode code, ynm set, fileloc loc)
412 (void) flagMarkerList_add (gc.markers,
413 flagMarker_createLocalSet (code, set, loc));
417 context_enterSuppressLine (int count, fileloc loc)
419 if (context_processingMacros ())
424 if (flagMarkerList_add
426 flagMarker_createIgnoreCount (count, loc)))
428 fileloc nextline = fileloc_copy (loc);
429 fileloc_nextLine (nextline);
430 fileloc_setColumn (nextline, 0);
432 check (flagMarkerList_add (gc.markers,
433 flagMarker_createIgnoreOff (nextline)));
434 fileloc_free (nextline);
438 void context_checkSuppressCounts (void)
440 if (context_getFlag (FLG_SUPCOUNTS))
442 flagMarkerList_checkSuppressCounts (gc.markers);
446 void context_incLineno (void)
453 context_exitSuppressRegion (fileloc loc)
455 if (!gc.insuppressregion)
459 message ("End ignore errors in region while not ignoring errors"),
463 gc.insuppressregion = FALSE;
464 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (loc));
468 context_enterMTfile (void)
474 context_exitMTfile (void)
476 llassert (gc.kind == CX_MT);
482 context_enterLCLfile (void)
485 gc.facct = typeIdSet_emptySet ();
490 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
494 for (i = 0; i < gc.nmods; i++)
496 if (cstring_equal (gc.moduleaccess[i].file, fname))
498 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
499 cstring_free (fname);
504 if (gc.nmods == gc.maxmods)
508 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
509 oldmods = gc.moduleaccess;
511 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
513 for (i = 0; i < gc.nmods; i++)
515 gc.moduleaccess[i] = oldmods[i];
521 gc.moduleaccess[gc.nmods].file = fname;
522 gc.moduleaccess[gc.nmods].daccess = mods;
528 insertModuleAccess (cstring fname, typeId t)
532 for (i = 0; i < gc.nmods; i++)
534 if (cstring_equal (gc.moduleaccess[i].file, fname))
536 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
541 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
546 context_exitLCLfile (void)
548 if (gc.kind != CX_LCLLIB)
551 fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION);
553 addModuleAccess (fileLib_removePath (lclname), gc.facct);
554 cstring_free (lclname);
559 gc.facct = typeIdSet_emptySet ();
564 context_dumpModuleAccess (FILE *fout)
568 for (i = 0; i < gc.nmods; i++)
570 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
572 fprintf (fout, "%s#%s@\n",
573 cstring_toCharsSafe (gc.moduleaccess[i].file),
574 cstring_toCharsSafe (td));
580 bool context_usingPosixLibrary ()
582 return (gc.library == FLG_POSIXLIB
583 || gc.library == FLG_POSIXSTRICTLIB
584 || gc.library == FLG_UNIXLIB
585 || gc.library == FLG_UNIXSTRICTLIB);
588 bool context_usingAnsiLibrary ()
590 return (gc.library != FLG_NOLIB);
593 flagcode context_getLibrary ()
598 void context_setLibrary (flagcode code)
603 /*@observer@*/ cstring context_selectedLibrary ()
608 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
610 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
611 case FLG_POSIXSTRICTLIB:
612 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
614 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
615 case FLG_UNIXSTRICTLIB:
616 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
618 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
625 context_loadModuleAccess (FILE *in)
627 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
629 char *name = mstring_create (MAX_NAME_LENGTH);
635 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
641 while (s != NULL && *s != ';' && *s != '\0')
645 while (*s != '#' && *s != '\0')
654 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
655 cstring_fromChars (s)));
661 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
662 typeIdSet_undump (&s));
664 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
665 llassert (s != lasts);
675 typeIdSet context_fileAccessTypes (void)
681 context_resetModeFlags (void)
685 if (flagcode_isModeFlag (code))
687 context_setFlag (code, FALSE, g_currentloc);
695 ** Set all flags to FALSE, except for a few which are
698 ** Set all values and strings to appropriate defaults.
699 ** Set all counters to 0.
703 conext_resetAllCounters (void)
707 for (i = 0; i < NUMVALUEFLAGS; i++)
714 context_resetAllFlags (void)
716 DPRINTF (("******** Reset all flags"));
720 gc.flags[code] = FALSE;
722 if (flagcode_hasNumber (code))
726 /*@-loopswitchbreak@*/
730 val = DEFAULT_LIMIT; break;
732 val = DEFAULT_BUGSLIMIT; break;
734 val = DEFAULT_LINELEN; break;
735 case FLG_INDENTSPACES:
736 val = DEFAULT_INDENTSPACES; break;
737 case FLG_EXTERNALNAMELEN:
738 val = ISO99_EXTERNALNAMELEN; break;
739 case FLG_INTERNALNAMELEN:
740 val = ISO99_INTERNALNAMELEN; break;
741 case FLG_COMMENTCHAR:
742 val = (int) DEFAULT_COMMENTCHAR; break;
743 case FLG_CONTROLNESTDEPTH:
744 val = (int) ISO99_CONTROLNESTDEPTH; break;
745 case FLG_STRINGLITERALLEN:
746 val = (int) ISO99_STRINGLITERALLEN; break;
747 case FLG_INCLUDENEST:
748 val = (int) ISO99_INCLUDENEST; break;
749 case FLG_NUMSTRUCTFIELDS:
750 val = (int) ISO99_NUMSTRUCTFIELDS; break;
751 case FLG_NUMENUMMEMBERS:
752 val = (int) ISO99_NUMENUMMEMBERS; break;
757 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
759 /*@=loopswitchbreak@*/
761 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
762 context_setValue (code, val);
763 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
764 llassert (context_getValue (code) == val);
766 else if (flagcode_hasChar (code))
768 llassert (code == FLG_COMMENTCHAR);
769 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
771 else if (flagcode_hasString (code))
773 cstring val = cstring_undefined;
776 { /*@-loopswitchbreak@*/
779 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
781 if (cstring_isDefined (larchpath))
783 val = cstring_copy (larchpath);
787 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
792 case FLG_LCLIMPORTDIR:
794 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
798 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
800 char *env = osd_getEnvironmentVariable ("TMP");
804 env = osd_getEnvironmentVariable ("TEMP");
807 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
810 val = cstring_makeLiteral (DEFAULT_TMPDIR);
811 # endif /* !defined(OS2) && !defined(MSDOS) */
815 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
817 val = cstring_makeLiteral ("FALSE"); break;
819 val = cstring_makeLiteral ("TRUE"); break;
820 case FLG_MACROVARPREFIX:
821 val = cstring_makeLiteral ("m_"); break;
823 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
826 } /*@=loopswitchbreak@*/
828 context_setString (code, val);
832 ; /* nothing to set */
837 ** These flags are true by default.
840 /*@i34 move this into flags.def */
842 gc.flags[FLG_STREAMOVERWRITE] = TRUE;
844 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
845 gc.flags[FLG_MODIFIES] = TRUE;
846 gc.flags[FLG_NESTCOMMENT] = TRUE;
847 gc.flags[FLG_GLOBALS] = TRUE;
848 gc.flags[FLG_FULLINITBLOCK] = TRUE;
849 gc.flags[FLG_INITSIZE] = TRUE;
850 gc.flags[FLG_INITALLELEMENTS] = TRUE;
852 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
854 gc.flags[FLG_LIKELYBOOL] = TRUE;
855 gc.flags[FLG_ZEROPTR] = TRUE;
856 gc.flags[FLG_NUMLITERAL] = TRUE;
857 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
858 gc.flags[FLG_SKIPISOHEADERS] = TRUE;
859 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
860 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
861 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
862 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
863 gc.flags[FLG_CASTFCNPTR] = TRUE;
864 gc.flags[FLG_DOLCS] = TRUE;
865 gc.flags[FLG_USEVARARGS] = TRUE;
866 gc.flags[FLG_MAINTYPE] = TRUE;
867 gc.flags[FLG_SPECMACROS] = TRUE;
868 gc.flags[FLG_REDEF] = TRUE;
869 gc.flags[FLG_MACRONEXTLINE] = TRUE;
871 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
872 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
874 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
875 gc.flags[FLG_WARNUSE] = TRUE;
876 gc.flags[FLG_PREDASSIGN] = TRUE;
877 gc.flags[FLG_MODOBSERVER] = TRUE;
878 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
879 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
881 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
882 gc.flags[FLG_RETIMPONLY] = TRUE;
883 gc.flags[FLG_GLOBIMPONLY] = TRUE;
884 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
885 gc.flags[FLG_PREPROC] = TRUE;
886 gc.flags[FLG_NAMECHECKS] = TRUE;
887 gc.flags[FLG_FORMATCODE] = TRUE;
888 gc.flags[FLG_FORMATTYPE] = TRUE;
889 gc.flags[FLG_BADFLAG] = TRUE;
890 gc.flags[FLG_WARNFLAGS] = TRUE;
891 gc.flags[FLG_WARNRC] = TRUE;
892 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
893 gc.flags[FLG_WARNUNIXLIB] = TRUE;
894 gc.flags[FLG_WARNPOSIX] = TRUE;
895 gc.flags[FLG_SHOWCOL] = TRUE;
896 gc.flags[FLG_SHOWFUNC] = TRUE;
897 gc.flags[FLG_SUPCOUNTS] = TRUE;
898 gc.flags[FLG_HINTS] = TRUE;
899 gc.flags[FLG_SYNTAX] = TRUE;
900 gc.flags[FLG_TYPE] = TRUE;
901 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
902 gc.flags[FLG_ABSTRACT] = TRUE;
903 gc.flags[FLG_ITERBALANCE] = TRUE;
904 gc.flags[FLG_ITERYIELD] = TRUE;
905 gc.flags[FLG_DUPLICATECASES] = TRUE;
906 gc.flags[FLG_ALWAYSEXITS] = TRUE;
907 gc.flags[FLG_EMPTYRETURN] = TRUE;
908 gc.flags[FLG_MACRORETURN] = TRUE;
909 gc.flags[FLG_UNRECOG] = TRUE;
910 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
911 gc.flags[FLG_LINTCOMMENTS] = TRUE;
912 gc.flags[FLG_ACCESSCZECH] = TRUE;
913 gc.flags[FLG_ACCESSMODULE] = TRUE;
914 gc.flags[FLG_ACCESSFILE] = TRUE;
915 gc.flags[FLG_MACROVARPREFIX] = TRUE;
917 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
918 gc.flags[FLG_COMMENTERROR] = TRUE;
921 ** Changed for version 2.4.
924 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
930 /* commenting ou until some output issues are fixed */
931 /* gc.flags[FLG_ORCONSTRAINT] = TRUE;*/
933 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
936 gc.flags[FLG_WARNSYSFILES] = TRUE;
939 ** On by default for Win32, but not Unix
943 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
944 gc.flags[FLG_CASEINSENSITIVEFILENAMES] = TRUE;
949 ** C is way-lame, and you can initialize an array to a constant except where
950 ** it is declared. Hence, a macro is used to set the modeflags.
954 # define SETFLAGS() \
955 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
956 if (!flagcode_isModeFlag (modeflags[i])) \
957 { llbug (message ("not a mode flag: %s", \
958 flagcode_unparse (modeflags[i]))); } \
959 else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }}
961 static void context_setModeAux (cstring p_s, bool p_warn) ;
964 context_setMode (cstring s)
966 context_setModeAux (s, TRUE);
970 context_setModeNoWarn (cstring s)
972 context_setModeAux (s, FALSE);
976 context_setModeAux (cstring s, bool warn)
978 intSet setflags = intSet_new ();
982 if (flagcode_isModeFlag (code))
984 if (gc.setGlobally[code])
986 (void) intSet_insert (setflags, (int) code);
991 if (!intSet_isEmpty (setflags))
993 cstring rflags = cstring_undefined;
996 intSet_elements (setflags, el)
998 if (cstring_isUndefined (rflags))
1000 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
1004 rflags = message ("%q, %s", rflags,
1005 flagcode_unparse ((flagcode) el));
1009 if (num > 4 && intSet_size (setflags) > 6)
1011 rflags = message ("%q, (%d others) ...", rflags,
1012 intSet_size (setflags) - num);
1015 } end_intSet_elements ;
1019 voptgenerror (FLG_WARNFLAGS,
1020 message ("Setting mode %s after setting mode flags will "
1021 "override set values of flags: %s",
1026 cstring_free (rflags);
1029 intSet_free (setflags);
1031 context_resetModeFlags ();
1033 if (cstring_equalLit (s, "standard"))
1035 flagcode modeflags[] =
1037 FLG_ENUMINT, FLG_MACROMATCHNAME,
1038 FLG_STRINGLITNOROOM,
1039 FLG_STRINGLITNOROOMFINALNULL,
1040 FLG_MACROUNDEF, FLG_RELAXQUALS,
1041 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1042 FLG_CHECKSTRICTGLOBALIAS,
1043 FLG_CHECKEDGLOBALIAS,
1044 FLG_CHECKMODGLOBALIAS,
1045 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1046 FLG_UNSIGNEDCOMPARE,
1047 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1049 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1050 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1051 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1052 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1053 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1056 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1057 FLG_MACROSTMT, FLG_MACROPARENS,
1060 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1061 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1066 /* memchecks flags */
1068 FLG_NULLSTATE, FLG_NULLASSIGN,
1069 FLG_NULLPASS, FLG_NULLRET,
1071 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1074 /* memtrans flags */
1093 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1096 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1097 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1100 FLG_STATETRANSFER, FLG_STATEMERGE,
1101 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1103 FLG_IMPCHECKEDSPECGLOBALS,
1104 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1105 FLG_IFEMPTY, FLG_REALCOMPARE,
1106 FLG_BOOLOPS, FLG_PTRNEGATE,
1108 FLG_SHIFTIMPLEMENTATION,
1109 FLG_BUFFEROVERFLOWHIGH,
1116 else if (cstring_equalLit (s, "weak"))
1118 flagcode modeflags[] =
1120 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1121 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1122 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1123 FLG_CHARUNSIGNEDCHAR,
1125 FLG_VARUNUSED, FLG_FUNCUNUSED,
1127 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1130 FLG_BUFFEROVERFLOWHIGH,
1131 FLG_RETSTACK, FLG_PTRNEGATE,
1132 FLG_STATETRANSFER, FLG_STATEMERGE,
1133 FLG_LONGUNSIGNEDINTEGRAL,
1134 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1138 FLG_BUFFEROVERFLOWHIGH,
1139 FLG_STRINGLITNOROOM,
1140 FLG_STRINGLITNOROOMFINALNULL,
1146 else if (cstring_equalLit (s, "checks"))
1148 flagcode modeflags[] =
1150 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1151 FLG_STATETRANSFER, FLG_STATEMERGE,
1152 FLG_CHECKSTRICTGLOBALIAS,
1153 FLG_CHECKEDGLOBALIAS,
1154 FLG_CHECKMODGLOBALIAS,
1155 FLG_UNCHECKEDGLOBALIAS,
1157 FLG_STRINGLITNOROOM,
1158 FLG_STRINGLITNOROOMFINALNULL,
1159 FLG_STRINGLITSMALLER,
1160 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1161 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1162 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1163 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1164 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1165 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1166 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1167 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1168 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1169 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1170 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1171 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1172 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1173 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
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_CHECKSTRICTGLOBALIAS,
1247 FLG_CHECKEDGLOBALIAS,
1248 FLG_CHECKMODGLOBALIAS,
1249 FLG_UNCHECKEDGLOBALIAS,
1253 FLG_STRINGLITNOROOM,
1254 FLG_STRINGLITNOROOMFINALNULL,
1255 FLG_STRINGLITSMALLER,
1256 FLG_STATETRANSFER, FLG_STATEMERGE,
1257 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1258 FLG_ALLGLOBALS, FLG_IMPTYPE,
1259 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1260 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1261 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1262 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1265 FLG_ONLYUNQGLOBALTRANS,
1266 FLG_GLOBALSIMPMODIFIESNOTHING,
1267 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1268 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1269 FLG_USEALLGLOBS, FLG_RETALIAS,
1270 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1271 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1272 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1274 FLG_EXPORTITER, FLG_EXPORTCONST,
1275 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1276 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1278 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1280 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1281 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1282 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1283 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1284 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1285 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1286 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1287 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1289 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1292 FLG_MACROREDEF, FLG_MACROEMPTY,
1293 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1295 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1297 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1298 FLG_MODOBSERVERUNCON,
1303 /* warn use flags */
1304 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1305 FLG_BUFFEROVERFLOWHIGH,
1306 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1308 /* memchecks flags */
1309 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1310 FLG_NULLPASS, FLG_NULLRET,
1312 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1314 /* memtrans flags */
1330 FLG_STATICINITTRANS,
1331 FLG_UNKNOWNINITTRANS,
1333 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1336 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1337 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1341 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1343 FLG_SHADOW, FLG_DEPARRAYS,
1344 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1345 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1346 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1347 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1348 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1349 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1350 FLG_IMPCHECKEDSTRICTSTATICS,
1351 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1352 FLG_IMPCHECKMODINTERNALS,
1353 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1354 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1355 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1356 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1357 FLG_CONTROLNESTDEPTH,
1358 FLG_FORBLOCK, FLG_WHILEBLOCK,
1359 FLG_FOREMPTY, FLG_WHILEEMPTY,
1360 FLG_IFEMPTY, FLG_IFBLOCK,
1362 FLG_REALCOMPARE, FLG_BOOLOPS,
1363 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1366 FLG_SHIFTIMPLEMENTATION,
1368 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1376 llcontbug (message ("context_setMode: bad mode: %s", s));
1381 context_isSpecialFile (cstring fname)
1383 cstring ext = fileLib_getExtension (fname);
1385 return (cstring_equalLit (ext, ".y")
1386 || cstring_equalLit (ext, ".l")
1387 || cstring_equalLit (fname, "lex.yy.c"));
1391 context_isSystemDir (cstring dir)
1393 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1394 cstring savedir = thisdir;
1395 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1397 if (cstring_isDefined (nextdir))
1399 /*@access cstring@*/
1400 *nextdir = '\0'; /* closes thisdir */
1402 /*@noaccess cstring@*/
1405 /* 2001-09-09: added thisdir[0] != '\0'
1406 ** herbert: don't compare with an empty name!
1407 ** should return false for empty directory path
1410 while (!cstring_isEmpty (thisdir))
1412 DPRINTF (("Test: %s / %s", dir, thisdir));
1414 if (osd_equalCanonicalPrefix (dir, thisdir))
1416 cstring_free (savedir);
1420 if (cstring_isDefined (nextdir))
1423 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1425 if (cstring_isDefined (nextdir))
1427 /*@access cstring@*/
1430 /*@noaccess cstring@*/
1439 DPRINTF (("Returns FALSE"));
1440 cstring_free (savedir);
1445 context_addFileAccessType (typeId t)
1449 if (context_inFunctionLike ())
1451 gc.acct = typeIdSet_insert (gc.acct, t);
1454 gc.facct = typeIdSet_insert (gc.facct, t);
1456 base = fileloc_getBase (g_currentloc);
1457 insertModuleAccess (base, t);
1458 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1459 typeIdSet_unparse (gc.acct)));
1463 context_removeFileAccessType (typeId t)
1465 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1466 || gc.kind == CX_UNKNOWNMACRO)
1468 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1471 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1472 gc.nacct = typeIdSet_insert (gc.nacct, t);
1475 void context_enterFunctionHeader (void)
1477 if (context_getFlag (FLG_GRAMMAR))
1479 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1482 if (gc.kind != CX_GLOBAL)
1484 llparseerror (cstring_makeLiteral
1485 ("Likely parse error. Function header outside global context."));
1489 llassert (gc.kind == CX_GLOBAL);
1490 DPRINTF (("Enter function header!"));
1491 gc.inFunctionHeader = TRUE;
1495 void context_exitFunctionHeader (void)
1497 if (context_getFlag (FLG_GRAMMAR))
1499 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1502 DPRINTF (("Exit function header!"));
1503 gc.inFunctionHeader = FALSE;
1506 bool context_inFunctionHeader (void)
1508 return (gc.inFunctionHeader);
1511 void context_enterFunctionDeclaration (uentry e)
1513 if (context_getFlag (FLG_GRAMMAR))
1515 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1518 DPRINTF (("Enter function decl"));
1519 llassert (gc.savekind == CX_ERROR);
1520 gc.savekind = gc.kind;
1521 gc.savecont = gc.cont;
1522 gc.kind = CX_FCNDECLARATION;
1526 void context_exitFunctionDeclaration (void)
1528 if (context_getFlag (FLG_GRAMMAR))
1530 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1533 DPRINTF (("Exit function decl"));
1534 llassert (gc.savekind != CX_ERROR);
1535 llassert (gc.kind == CX_FCNDECLARATION);
1536 gc.kind = gc.savekind;
1537 gc.cont = gc.savecont;
1539 gc.savekind = CX_ERROR;
1541 if (context_getFlag (FLG_GRAMMAR))
1543 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1547 bool context_inFunctionDeclaration (void)
1549 return (gc.kind == CX_FCNDECLARATION);
1554 context_enterMacro (/*@observer@*/ uentry e)
1556 context_enterFunction (e);
1557 gc.kind = CX_MACROFCN;
1561 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1563 llassert (uentry_isFunction (e));
1564 context_enterFunction (e);
1565 gc.kind = CX_UNKNOWNMACRO;
1568 void context_enterAndClause (exprNode e)
1571 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1572 pushClause (ANDCLAUSE);
1575 void context_enterOrClause (exprNode e)
1577 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1578 pushClause (ORCLAUSE);
1581 bool context_inDeepLoop (void)
1583 bool inLoop = FALSE;
1585 clauseStack_elements (gc.clauses, el)
1587 if (clause_isLoop (el))
1596 } end_clauseStack_elements;
1601 bool context_inDeepSwitch (void)
1603 bool inLoop = FALSE;
1605 clauseStack_elements (gc.clauses, el)
1607 if (clause_isSwitch (el))
1616 } end_clauseStack_elements;
1621 bool context_inDeepLoopSwitch (void)
1623 bool inLoop = FALSE;
1625 clauseStack_elements (gc.clauses, el)
1627 if (clause_isBreakable (el))
1636 } end_clauseStack_elements;
1641 clause context_breakClause (void)
1643 clauseStack_elements (gc.clauses, el)
1645 if (clause_isSwitch (el))
1649 else if (clause_isLoop (el))
1657 } end_clauseStack_elements;
1662 clause context_nextBreakClause (void)
1664 bool hasOne = FALSE;
1666 clauseStack_elements (gc.clauses, el)
1668 if (clause_isBreakable (el))
1679 } end_clauseStack_elements;
1684 bool context_inConditional (void)
1686 clauseStack_elements (gc.clauses, el)
1689 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1690 ** to distinguish if from ? for this
1693 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1697 } end_clauseStack_elements;
1702 void context_exitAndClause (exprNode pred, exprNode tbranch)
1704 context_setJustPopped ();
1706 llassert (gc.inclause == ANDCLAUSE);
1708 usymtab_popAndBranch (pred, tbranch);
1709 clauseStack_pop (gc.clauses);
1710 gc.inclause = topClause (gc.clauses);
1713 void context_exitOrClause (exprNode pred, exprNode tbranch)
1715 context_setJustPopped ();
1717 llassert (gc.inclause == ORCLAUSE);
1719 usymtab_popOrBranch (pred, tbranch);
1720 clauseStack_pop (gc.clauses);
1721 gc.inclause = topClause (gc.clauses);
1724 static void context_enterCondClauseAux (clause cl)
1730 static void context_enterTrueAux (exprNode e, clause cl)
1733 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1737 void context_enterIterClause (void)
1739 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1742 void context_enterDoWhileClause (void)
1744 pushClause (DOWHILECLAUSE);
1747 void context_enterWhileClause (exprNode e)
1749 context_enterTrueAux (e, WHILECLAUSE);
1752 void context_enterForClause (exprNode e)
1754 context_enterTrueAux (e, FORCLAUSE);
1757 void context_enterTrueClause (exprNode e)
1759 context_enterTrueAux (e, TRUECLAUSE);
1762 void context_enterSwitch (exprNode e)
1764 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1765 usymtab_switchBranch (e);
1766 context_enterCondClauseAux (SWITCHCLAUSE);
1769 void context_exitSwitch (exprNode e, bool allpaths)
1771 usymtab_exitSwitch (e, allpaths);
1773 while (clause_isCase (clauseStack_top (gc.clauses)))
1775 clauseStack_pop (gc.clauses);
1778 context_exitClauseSimp ();
1781 void context_enterCaseClause (exprNode e)
1783 bool branch = FALSE;
1785 DPRINTF (("Enter case clause!"));
1787 branch = usymtab_newCase (exprNode_undefined, e);
1791 context_enterCondClauseAux (CASECLAUSE);
1795 static void context_enterFalseClauseAux (exprNode e, clause cl)
1798 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1800 clauseStack_switchTop (gc.clauses, cl);
1803 void context_enterFalseClause (exprNode e)
1806 context_enterFalseClauseAux (e, FALSECLAUSE);
1810 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1812 gc.kind = CX_MACROCONST;
1814 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1816 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1820 usymtab_enterScope ();
1821 sRef_enterFunctionScope ();
1823 gc.globs = globSet_undefined;
1824 globSet_clear (gc.globs_used);
1825 gc.mods = sRefSet_undefined;
1828 uentry context_getHeader (void)
1830 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1832 llfatalbug (message ("context_getHeader: bad call: %q",
1833 context_unparse ()));
1836 return (gc.cont.fcn);
1840 context_setFunctionDefined (fileloc loc)
1844 case CX_UNKNOWNMACRO:
1847 uentry_setFunctionDefined (gc.cont.fcn, loc);
1850 /* (not a bug because of parse errors) */
1856 context_enterFunction (/*@exposed@*/ uentry e)
1858 gc.kind = CX_FUNCTION;
1861 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1863 if (uentry_hasAccessType (e))
1865 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1873 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1874 typeIdSet_unparse (gc.acct)));
1876 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1878 gc.globs = uentry_getGlobs (e);
1879 globSet_clear (gc.globs_used);
1880 gc.mods = uentry_getMods (e);
1882 usymtab_enterFunctionScope (e);
1883 sRef_enterFunctionScope ();
1886 bool context_inOldSytleScope(void)
1888 if (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 /*@i32 was makeAlt */
2303 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2304 clauseStack_pop (gc.clauses);
2305 gc.inclause = topClause (gc.clauses);
2308 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2310 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2312 if (gc.inclause != TRUECLAUSE)
2314 llparseerror (cstring_makeLiteral
2315 ("Likely parse error. Conditional clauses are inconsistent."));
2319 context_setJustPopped ();
2320 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2321 clauseStack_pop (gc.clauses);
2322 gc.inclause = topClause (gc.clauses);
2325 void context_exitIterClause (exprNode body)
2327 llassert (gc.inclause == ITERCLAUSE);
2329 context_setJustPopped ();
2331 if (context_getFlag (FLG_ITERLOOPEXEC))
2333 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2337 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2340 clauseStack_pop (gc.clauses);
2341 gc.inclause = topClause (gc.clauses);
2344 static void context_popCase (void) {
2346 ** If we are exiting an outer clause, sometimes still in a switch case.
2360 DPRINTF (("Popping case clause: %s",
2361 clauseStack_unparse (gc.clauses)));
2363 if (gc.inclause == CASECLAUSE) {
2364 context_exitCaseClause ();
2368 void context_exitWhileClause (exprNode pred, exprNode body)
2370 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2374 if (gc.inclause != WHILECLAUSE) {
2375 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2376 clauseStack_unparse (gc.clauses)));
2379 llassert (gc.inclause == WHILECLAUSE);
2381 context_setJustPopped ();
2385 ** predicate must be false after while loop (unless there are breaks)
2388 if (context_getFlag (FLG_WHILELOOPEXEC))
2390 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2394 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2398 usymtab_addGuards (invGuards);
2399 guardSet_free (invGuards);
2401 clauseStack_pop (gc.clauses);
2402 gc.inclause = topClause (gc.clauses);
2405 void context_exitDoWhileClause (exprNode pred)
2407 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2409 if (gc.inclause == CASECLAUSE) {
2410 /* handle Duff's device */
2411 clauseStack_pop (gc.clauses);
2412 gc.inclause = topClause (gc.clauses);
2415 llassert (gc.inclause == DOWHILECLAUSE);
2417 context_setJustPopped ();
2420 usymtab_addGuards (invGuards);
2421 guardSet_free (invGuards);
2423 clauseStack_pop (gc.clauses);
2424 gc.inclause = topClause (gc.clauses);
2427 void context_exitForClause (exprNode forPred, exprNode body)
2429 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2431 llassert (gc.inclause == FORCLAUSE);
2432 context_setJustPopped ();
2434 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2437 ** Predicate must be false after for loop (unless there are breaks)
2440 if (context_getFlag (FLG_FORLOOPEXEC))
2442 DPRINTF (("Here: for loop exec"));
2443 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2447 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2448 && exprNode_loopMustExec (forPred))
2450 DPRINTF (("Here: loop must exec"));
2451 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2455 DPRINTF (("Pop true branch:"));
2456 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2460 usymtab_addGuards (invGuards);
2461 guardSet_free (invGuards);
2462 clauseStack_pop (gc.clauses);
2463 gc.inclause = topClause (gc.clauses);
2466 static void context_exitClausePlain (void)
2468 llassert (gc.inclause != NOCLAUSE);
2470 if (gc.inclause == FALSECLAUSE)
2472 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2476 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2480 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2482 context_setJustPopped ();
2484 if (gc.inclause == FALSECLAUSE)
2486 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2488 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2490 clauseStack_pop (gc.clauses);
2491 gc.inclause = topClause (gc.clauses);
2495 context_exitTrueClause (pred, tbranch);
2500 context_returnFunction (void)
2502 usymtab_checkFinalScope (TRUE);
2506 context_exitFunction (void)
2508 DPRINTF (("Exit function: %s", context_unparse ()));
2510 if (!context_inFunction () && !context_inMacroConstant ()
2511 && !context_inUnknownMacro ()
2512 && !context_inIterDef () && !context_inIterEnd ())
2515 ** not a bug because of parse errors
2522 if (context_inMacro () && usymtab_inFunctionScope ())
2524 usymtab_exitScope (exprNode_undefined);
2527 if (uentry_hasGlobs (gc.cont.fcn))
2529 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2533 if (uentry_hasMods (gc.cont.fcn))
2535 if (context_getFlag (FLG_MUSTMOD))
2537 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2541 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2544 ** clear file static modifies
2547 /* do this first to get unused error messages */
2549 usymtab_exitScope (exprNode_undefined);
2550 sRef_exitFunctionScope ();
2552 gc.showfunction = FALSE;
2553 gc.kind = CX_GLOBAL;
2554 gc.cont.glob = TRUE;
2556 gc.globs = globSet_new ();
2557 globSet_clear (gc.globs_used);
2558 gc.mods = sRefSet_new ();
2561 llassert (clauseStack_isEmpty (gc.clauses));
2562 llassert (gc.inclause == NOCLAUSE);
2563 DPRINTF (("After exit function: %s", context_unparse ()));
2567 context_quietExitFunction (void)
2569 while (gc.kind == CX_INNER)
2571 context_exitInnerPlain ();
2574 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2575 && !context_inIterDef () && !context_inIterEnd ())
2580 usymtab_quietExitScope (g_currentloc);
2582 gc.showfunction = FALSE;
2583 gc.kind = CX_GLOBAL;
2584 gc.cont.glob = TRUE;
2586 gc.globs = globSet_new ();
2587 globSet_clear (gc.globs_used);
2588 gc.mods = sRefSet_new ();
2590 sRef_exitFunctionScope ();
2594 /*@observer@*/ uentryList
2595 context_getParams (void)
2597 if (context_inFunctionLike ())
2599 return (uentry_getParams (gc.cont.fcn));
2603 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2604 return uentryList_undefined;
2608 /*@observer@*/ globSet
2609 context_getUsedGlobs (void)
2611 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2612 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2614 return (gc.globs_used);
2618 context_moduleName ()
2620 return (fileloc_getBase (g_currentloc));
2623 /*@observer@*/ globSet
2624 context_getGlobs (void)
2626 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2627 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2633 context_addBoolAccess (void)
2635 cstring bname = context_getString (FLG_BOOLTYPE);
2636 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2638 addModuleAccess (cstring_copy (bname), boolt);
2640 /* for sys/types (perhaps, this is bogus!) */
2641 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2646 context_canAccessBool (void)
2653 static typeId boolType = typeId_invalid;
2655 if (typeId_isInvalid (boolType))
2657 boolType = usymtab_getTypeId (context_getBoolName ());
2660 if (typeId_isInvalid (boolType)) {
2663 return (typeIdSet_member (gc.acct, boolType));
2668 /* evs 2000-07-25: old version - replaced */
2671 context_boolImplementationType () {
2672 /* For now, this is bogus! */
2677 context_canAccessBool (void)
2679 static typeId boolType = typeId_invalid;
2681 if (typeId_isInvalid (boolType))
2683 boolType = usymtab_getTypeId (context_getBoolName ());
2686 if (!typeId_isInvalid (boolType))
2688 return context_hasAccess (boolType);
2699 context_setMessageAnnote (/*@only@*/ cstring s)
2701 llassert (cstring_isUndefined (gc.msgAnnote));
2706 context_hasMessageAnnote (void)
2708 return (cstring_isDefined (gc.msgAnnote));
2712 context_clearMessageAnnote (void)
2714 if (cstring_isDefined (gc.msgAnnote))
2716 cstring_free (gc.msgAnnote);
2717 gc.msgAnnote = cstring_undefined;
2722 context_getMessageAnnote (void)
2724 cstring st = gc.msgAnnote;
2726 gc.msgAnnote = cstring_undefined;
2731 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2733 llassert (sRef_isInvalid (gc.aliasAnnote));
2734 llassert (!sRef_sameName (s, t));
2736 gc.aliasAnnoteAls = t;
2740 context_hasAliasAnnote (void)
2742 return (sRef_isValid (gc.aliasAnnote));
2746 context_clearAliasAnnote (void)
2748 gc.aliasAnnote = sRef_undefined;
2752 context_getAliasAnnote (void)
2754 sRef ret = gc.aliasAnnote;
2755 sRef als = gc.aliasAnnoteAls;
2757 llassert (sRef_isValid (ret) && sRef_isValid (als));
2759 gc.aliasAnnote = sRef_undefined;
2760 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2764 context_recordFileModifies (sRefSet mods)
2766 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2770 context_recordFileGlobals (globSet mods)
2772 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2773 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2777 context_setCommentMarkerChar (char c)
2779 llassert (c != '\0');
2781 context_setValue (FLG_COMMENTCHAR, (int) c);
2785 context_getCommentMarkerChar (void)
2787 return ((char) context_getValue (FLG_COMMENTCHAR));
2791 context_setValue (flagcode flag, int val)
2793 int index = flagcode_valueIndex (flag);
2795 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2803 llerror_flagWarning (message ("Value for %s must be a positive "
2804 "number (given %d)",
2805 flagcode_unparse (flag), val));
2808 if (flag == FLG_LINELEN && val < MINLINELEN)
2810 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2811 flagcode_unparse (flag),
2817 case FLG_INCLUDENEST:
2818 case FLG_CONTROLNESTDEPTH:
2819 case FLG_STRINGLITERALLEN:
2820 case FLG_NUMSTRUCTFIELDS:
2821 case FLG_NUMENUMMEMBERS:
2822 case FLG_INDENTSPACES:
2825 llerror_flagWarning (message ("Value for %s must be a non-negative "
2826 "number (given %d)",
2827 flagcode_unparse (flag), val));
2836 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2837 gc.values[index] = val;
2841 context_setValueAndFlag (flagcode flag, int val)
2843 gc.flags[flag] = TRUE;
2844 context_setValue (flag, val);
2848 context_getValue (flagcode flag)
2850 int index = flagcode_valueIndex (flag);
2852 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2853 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2854 return (gc.values[index]);
2858 context_getCounter (flagcode flag)
2860 int index = flagcode_valueIndex (flag);
2862 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2863 return (gc.counters[index]);
2867 context_incCounter (flagcode flag)
2869 int index = flagcode_valueIndex (flag);
2871 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2873 gc.counters[index]++;
2877 context_decCounter (flagcode flag)
2879 int index = flagcode_valueIndex (flag);
2881 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2882 gc.counters[index]--;
2885 bool context_showFunction (void)
2887 return (gc.showfunction);
2891 context_setString (flagcode flag, cstring val)
2893 int index = flagcode_stringIndex (flag);
2895 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2897 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2903 usymtab_supGlobalEntry
2904 (uentry_makeConstantValue (val, ctype_bool,
2905 fileloc_getBuiltin (), TRUE,
2906 multiVal_makeInt (1)));
2909 usymtab_supGlobalEntry
2910 (uentry_makeConstantValue (val, ctype_bool,
2911 fileloc_getBuiltin (), FALSE,
2912 multiVal_makeInt (0)));
2915 case FLG_MESSAGESTREAM:
2916 case FLG_WARNINGSTREAM:
2917 case FLG_ERRORSTREAM:
2919 if (cstring_isDefined (val))
2923 if (osd_fileExists (val))
2925 if (context_getFlag (FLG_STREAMOVERWRITE))
2927 llfatalerror (message
2928 ("Output stream file %s would overwrite existing file. "
2929 "Use -streamoverwrite if you want to allow this.",
2934 fstream = fopen (cstring_toCharsSafe (val), "w");
2936 if (fstream == NULL)
2938 llfatalerror (message ("Unable to open output stream file %s for writing",
2943 ** This ensures fstream will be closed on exit.
2946 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2950 case FLG_MESSAGESTREAM:
2951 g_messagestream = fstream;
2952 /*@innerbreak@*/ break;
2953 case FLG_WARNINGSTREAM:
2954 g_warningstream = fstream;
2955 /*@innerbreak@*/ break;
2956 case FLG_ERRORSTREAM:
2957 g_errorstream = fstream;
2958 /*@innerbreak@*/ break;
2961 /*@-statetransfer@*/
2962 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2965 case FLG_SYSTEMDIRS:
2967 llassert (cstring_isDefined (val));
2969 if (cstring_firstChar (val) == '\"')
2972 cstring tval = cstring_copy (cstring_suffix (val, 1));
2974 if (cstring_lastChar (tval) != '\"')
2976 int n = cstring_length (tval) - 1;
2978 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2983 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2986 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2990 cstring otval = tval;
2991 tval = cstring_prefix (tval, size_fromInt (n));
2992 cstring_free (otval);
2996 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2997 DPRINTF (("val = %s", val));
2998 cstring_free (tval);
2999 cstring_free (oval);
3006 llassert (cstring_isDefined (val));
3008 if (cstring_length (val) == 0)
3011 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
3013 else if (cstring_lastChar (val) != CONNECTCHAR)
3015 val = cstring_appendChar (val, CONNECTCHAR);
3025 ; /* Okay not handle everything in this switch */
3027 } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */
3029 if (cstring_length (val) >= 1
3030 && cstring_firstChar (val) == '\"')
3032 llerror_flagWarning (message
3033 ("setting %s to string beginning with \". You probably "
3034 "don't meant to have the \"'s.",
3035 flagcode_unparse (flag)));
3038 gc.strings[index] = val;
3041 static /*@exposed@*/ cstring
3042 context_exposeString (flagcode flag)
3044 int index = flagcode_stringIndex (flag);
3046 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3047 return (gc.strings[index]);
3051 context_getString (flagcode flag)
3053 return (context_exposeString (flag));
3057 context_resetErrors (void)
3062 void context_initMod (void)
3063 /*@globals undef gc; @*/
3065 gc.kind = CX_GLOBAL;
3067 gc.savekind = CX_ERROR;
3068 gc.savecont.glob = FALSE;
3070 gc.instandardlib = FALSE;
3073 gc.linesprocessed = 0;
3074 gc.speclinesprocessed = 0;
3075 gc.insuppressregion = FALSE;
3076 gc.macroMissingParams = FALSE;
3077 gc.preprocessing = FALSE;
3078 gc.incommandline = FALSE;
3079 gc.mc = macrocache_create ();
3081 gc.maxmods = DEFAULTMAXMODS;
3082 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3084 gc.library = FLG_ANSILIB;
3086 gc.locstack = filelocStack_new ();
3087 gc.modrecs = sRefSetList_undefined;
3088 gc.anyExports = FALSE;
3090 gc.ftab = fileTable_create ();
3091 gc.msgLog = messageLog_new ();
3092 gc.inimport = FALSE;
3093 gc.inDerivedFile = FALSE;
3094 gc.inheader = FALSE;
3095 gc.markers = flagMarkerList_new ();
3096 gc.cont.glob = TRUE;
3097 gc.showfunction = FALSE;
3098 gc.msgAnnote = cstring_undefined;
3099 gc.aliasAnnote = sRef_undefined;
3100 gc.aliasAnnoteAls = sRef_undefined;
3101 gc.boolType = ctype_bool;
3102 gc.mods = sRefSet_new ();
3104 gc.saveloc = fileloc_undefined;
3106 gc.inmacrocache = FALSE;
3107 gc.inclause = NOCLAUSE;
3108 gc.clauses = clauseStack_new ();
3109 gc.globs = globSet_new ();
3110 gc.nacct = typeIdSet_emptySet ();
3111 gc.acct = typeIdSet_emptySet ();
3112 gc.facct = typeIdSet_emptySet ();
3113 gc.savedFlags = FALSE;
3114 gc.pushloc = fileloc_undefined;
3115 gc.protectVars = FALSE;
3116 gc.justpopped = FALSE;
3117 gc.isNullGuarded = NO;
3118 gc.globs_used = globSet_undefined;
3122 gc.setGlobally[code] = FALSE;
3123 gc.setLocally[code] = FALSE;
3128 context_resetAllFlags ();
3130 assertSet (gc.flags); /* Can't use global in defines */
3131 assertSet (gc.saveflags);
3132 assertSet (gc.values);
3133 assertSet (gc.strings);
3135 conext_resetAllCounters ();
3136 assertSet (gc.counters);
3138 context_setMode (DEFAULT_MODE);
3140 gc.stateTable = metaStateTable_create ();
3141 gc.annotTable = annotationTable_create ();
3143 gc.inFunctionHeader = FALSE;
3145 DPRINTF (("Annotations: \n%s",
3146 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3147 DPRINTF (("State: \n%s",
3148 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3153 context_typeofZero (void)
3155 ctype ct = ctype_int;
3157 if (context_getFlag (FLG_ZEROPTR))
3159 ct = ctype_makeConj (ct, ctype_voidPointer);
3162 if (context_getFlag (FLG_ZEROBOOL)) {
3163 ct = ctype_makeConj (ct, ctype_bool);
3170 context_typeofOne (void)
3172 ctype ct = ctype_int;
3174 /* 1 is on longer a bool (was before 2.4)
3175 if (!context_getFlag (FLG_ABSTRACTBOOL))
3177 ct = ctype_makeConj (ct, ctype_bool);
3185 context_unparse (void)
3192 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3195 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3198 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3201 s = message ("Inner Context [%d] : %q",
3203 fileloc_unparse (g_currentloc));
3206 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3207 uentry_unparse (gc.cont.fcn),
3208 fileloc_unparse (g_currentloc),
3209 typeIdSet_unparse (gc.acct),
3210 sRefSet_unparse (gc.mods));
3213 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3215 case CX_UNKNOWNMACRO:
3216 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3219 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3222 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3225 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3227 case CX_FCNDECLARATION:
3228 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3231 s = message ("Un-unparseable context: %d", (int) gc.kind);
3235 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3240 context_currentFunctionType (void)
3242 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3244 return (uentry_getType (gc.cont.fcn));
3246 else if (gc.kind == CX_INNER)
3248 llcontbuglit ("context_currentFunctionType: inner context");
3249 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3250 return (context_currentFunctionType ());
3254 llcontbuglit ("context_currentFunctionType: not in function");
3255 return (ctype_undefined);
3260 context_enterInnerContext (void)
3262 if (context_getFlag (FLG_GRAMMAR))
3264 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3267 if (gc.kind == CX_GLOBAL)
3272 else if (gc.kind == CX_INNER)
3281 usymtab_enterScope ();
3282 pushClause (NOCLAUSE);
3286 context_exitInnerPlain (void) /*@modifies gc;@*/
3288 context_exitInner (exprNode_undefined);
3292 context_exitInner (exprNode exp)
3294 if (context_getFlag (FLG_GRAMMAR))
3296 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3299 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3300 ("inclause = %s", clause_nameTaken (gc.inclause)));
3302 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3303 gc.inclause = topClause (gc.clauses);
3305 if (gc.kind == CX_INNER)
3307 if (--gc.cont.cdepth == 0)
3309 gc.kind = CX_GLOBAL;
3310 gc.cont.glob = TRUE;
3315 if (gc.kind == CX_GLOBAL)
3317 llcontbuglit ("Attempt to exit global context");
3322 usymtab_exitScope (exp);
3327 context_enterStructInnerContext (void)
3329 if (context_getFlag (FLG_GRAMMAR))
3331 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3334 if (gc.kind == CX_GLOBAL)
3339 else if (gc.kind == CX_INNER)
3348 usymtab_enterScope ();
3350 if (context_getFlag (FLG_GRAMMAR))
3352 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3357 context_exitStructInnerContext (void)
3359 if (context_getFlag (FLG_GRAMMAR))
3361 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3364 if (gc.kind == CX_INNER)
3366 if (gc.cont.cdepth <= 0)
3368 llcontbuglit ("Attempt to exit inner context with no depth");
3369 gc.kind = CX_GLOBAL;
3370 gc.cont.glob = TRUE;
3376 if (gc.cont.cdepth == 0)
3378 gc.kind = CX_GLOBAL;
3379 gc.cont.glob = TRUE;
3385 if (gc.kind == CX_GLOBAL)
3387 llcontbuglit ("Attempt to exit global context");
3392 usymtab_exitScope (exprNode_undefined);
3394 if (context_getFlag (FLG_GRAMMAR))
3396 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3401 context_exitInnerSafe (void)
3403 if (context_getFlag (FLG_GRAMMAR))
3405 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3408 if (gc.kind == CX_INNER)
3410 if (--gc.cont.cdepth <= 0)
3415 else if (gc.kind == CX_GLOBAL)
3417 llcontbuglit ("Attempt to exit global context");
3422 if (usymtab_inDeepScope ())
3424 usymtab_exitScope (exprNode_undefined);
3430 void setModuleAccess (void)
3432 gc.facct = typeIdSet_emptySet ();
3434 if (fileId_isValid (currentFile ()))
3436 cstring baseName = fileloc_getBase (g_currentloc);
3438 if (context_getFlag (FLG_ACCESSFILE))
3440 if (usymtab_existsType (baseName))
3442 gc.facct = typeIdSet_insert (gc.facct,
3443 usymtab_getTypeId (baseName));
3451 if (context_getFlag (FLG_ACCESSMODULE))
3454 bool hasaccess = FALSE;
3456 for (i = 0; i < gc.nmods; i++)
3458 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3460 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3469 gc.inheader = fileId_isHeader (currentFile ());
3473 llcontbuglit ("Current file not defined\n");
3474 gc.facct = typeIdSet_emptySet ();
3476 gc.inheader = FALSE;
3479 /* 17 Jan 1995: forgot to clear nacct */
3481 gc.nacct = typeIdSet_emptySet ();
3485 context_enterFileAux (void)
3491 context_enterFile (void)
3493 context_enterFileAux ();
3494 usymtab_enterFile ();
3498 context_enterMacroFile (void)
3500 context_enterFileAux ();
3504 context_inFunction (void)
3506 kcontext ck = gc.kind;
3508 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3512 context_inFunctionLike (void)
3514 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3515 || gc.kind == CX_FCNDECLARATION
3516 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3520 context_inRealFunction (void)
3522 kcontext ck = gc.kind;
3524 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3528 context_processAllMacros (void)
3530 usymtab_enterFile ();
3532 gc.inmacrocache = TRUE;
3533 macrocache_processUndefinedElements (gc.mc);
3535 usymtab_exitFile ();
3537 gc.inmacrocache = FALSE;
3538 macrocache_finalize ();
3542 ** this happens once at the end of each C file
3544 ** check each Macro that was defined in current file.c or current file.h
3549 context_processMacros (void)
3551 if (fileId_isValid (currentFile ()))
3554 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3556 gc.inmacrocache = TRUE;
3558 DPRINTF (("Processing macros: %s", cbase));
3559 lastfl = macrocache_processFileElements (gc.mc, cbase);
3560 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3562 cstring_free (cbase);
3564 if (fileloc_isDefined (lastfl))
3566 g_currentloc = fileloc_update (g_currentloc, lastfl);
3570 gc.inmacrocache = FALSE;
3575 context_processingMacros (void)
3577 return (gc.inmacrocache);
3581 context_exitCFile (void)
3583 if (gc.kind != CX_GLOBAL)
3586 (cstring_makeLiteral ("File ended outside global scope"));
3589 if (gc.insuppressregion)
3591 /* gack...don't reverse the order of these lines! ;-> */
3592 gc.insuppressregion = FALSE;
3593 llerrorlit (FLG_SYNTAX,
3594 "File ended in ignore errors region, "
3595 "possible missing /*@end*/");
3598 /* fix up parse errors */
3600 while (!usymtab_inFileScope ())
3602 usymtab_quietExitScope (g_currentloc);
3606 ** Clear the file-specific modifies information.
3609 sRefSetList_elements (gc.modrecs, mods)
3611 sRefSet_clearStatics (mods);
3612 } end_sRefSetList_elements ;
3614 sRefSetList_clear (gc.modrecs);
3616 context_processMacros ();
3619 usymtab_exitFile ();
3621 gc.inDerivedFile = FALSE;
3622 filelocStack_clear (gc.locstack);
3624 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3626 gc.cont.glob = TRUE;
3630 context_restoreFlagSettings ();
3631 gc.savedFlags = FALSE;
3635 DPRINTF (("After exiting file: "));
3636 usymtab_printAll ();
3641 context_exitMacroCache (void)
3643 if (gc.kind != CX_GLOBAL)
3645 if (context_inMacro ())
3646 /* this is okay, file could end without newline in macro */
3648 DPRINTF (("Still in macro: %s",
3649 context_unparse ()));
3650 context_exitFunction ();
3654 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3655 context_unparse ()));
3656 gc.kind = CX_GLOBAL;
3661 ** no longer valid here
3662 ** if (gc.insuppressregion)
3664 ** gc.insuppressregion = FALSE;
3665 ** llerror ("File ended in ignore errors region, possible missing @");
3669 gc.cont.glob = TRUE;
3673 context_saveLocation (void)
3675 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3676 fileloc_free (gc.saveloc);
3677 gc.saveloc = fileloc_copy (g_currentloc);
3681 context_getSaveLocation (void)
3683 fileloc fl = gc.saveloc;
3684 gc.saveloc = fileloc_undefined;
3688 /*@observer@*/ cstring
3689 context_inFunctionName (void)
3691 if (gc.kind == CX_FUNCTION
3692 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3693 || gc.kind == CX_MACROCONST
3694 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3696 return (uentry_rawName (gc.cont.fcn));
3700 llcontbuglit ("context_inFunctionName: not in function");
3701 return (cstring_undefined);
3706 context_userSetFlag (flagcode f, bool b)
3708 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3710 if (f == FLG_NEVERINCLUDE && b)
3712 if (gc.flags[FLG_EXPORTHEADER])
3715 (cstring_makeLiteral
3716 ("setting +neverinclude after +exportheader. "
3717 "Turning off exportheader, since headers are not checked "
3718 "when +neverinclude is used."));
3720 gc.flags[FLG_EXPORTHEADER] = FALSE;
3725 if (f == FLG_EXPORTHEADER && b)
3727 if (gc.flags[FLG_NEVERINCLUDE])
3730 (cstring_makeLiteral
3731 ("setting +exportheader after +neverinclude. "
3732 "Not setting exportheader, since headers are not checked "
3733 "when +neverinclude is used."));
3734 gc.flags[FLG_EXPORTHEADER] = FALSE;
3740 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3742 bool lastsetting = context_getFlag (f);
3744 if (bool_equal (lastsetting, b)
3745 && !flagcode_isSpecialFlag (f)
3746 && !flagcode_isIdemFlag (f)
3747 && !flagcode_hasArgument (f))
3750 (message ("setting %s%s redundant with current value",
3751 cstring_makeLiteralTemp (b ? "+" : "-"),
3752 flagcode_unparse (f)));
3756 if (flagcode_isWarnUseFlag (f) && b)
3758 if (!context_getFlag (FLG_WARNUSE))
3761 (message ("flag +%s is canceled by -warnuse",
3762 flagcode_unparse (f)));
3767 if (flagcode_isLibraryFlag (f))
3769 if (gc.library != FLG_ANSILIB
3773 (message ("selecting library %s after library %s was "
3774 "selected (only one library may be used)",
3775 flagcode_unparse (f),
3776 flagcode_unparse (gc.library)));
3779 if (f == FLG_UNIXLIB)
3781 if (context_getFlag (FLG_WARNUNIXLIB))
3784 (cstring_makeLiteral
3785 ("selecting unix library. Unix library is "
3786 "ad hoc addition to POSIX library. Recommend "
3787 "use +posixlib to select POSIX library instead. "
3788 "Use -warnunixlib to suppress this message."));
3795 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3799 ("setting +%s will not produce warnings with -namechecks. "
3800 "Must set +namechecks also.",
3801 flagcode_unparse (f)));
3804 gc.setGlobally[f] = TRUE;
3805 context_setFlag (f, b, g_currentloc);
3809 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3813 context_saveFlagSettings ();
3816 if (ynm_isOff (set))
3818 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3820 else if (ynm_isOn (set))
3822 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3823 gc.setLocally[f] = TRUE;
3827 context_restoreFlag (f, loc);
3832 context_restoreFlag (flagcode f, fileloc loc)
3838 message ("Attempt to restore flag %s when no file scope flags "
3840 flagcode_unparse (f)),
3845 context_addFlagMarker (f, MAYBE, loc);
3846 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3852 context_setFlag (flagcode f, bool b, fileloc loc)
3854 context_setFlagAux (f, b, FALSE, FALSE, loc);
3858 context_setFlagTemp (flagcode f, bool b)
3860 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3865 # define DOSET(ff,b) \
3866 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3867 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3868 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3869 gc.flags[ff] = b; } while (FALSE)
3872 context_setFlagAux (flagcode f, bool b, bool inFile,
3873 /*@unused@*/ bool isRestore, fileloc loc)
3875 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3878 ** Removed test for special flags.
3881 if (flagcode_isIdemFlag (f))
3890 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3892 if (b) /* Turing higher level on, turns on all lower levels */
3896 case FLG_ITS4MOSTRISKY:
3897 DOSET (FLG_ITS4VERYRISKY, b);
3899 case FLG_ITS4VERYRISKY:
3900 DOSET (FLG_ITS4RISKY, b);
3903 DOSET (FLG_ITS4MODERATERISK, b);
3905 case FLG_ITS4MODERATERISK:
3906 DOSET (FLG_ITS4LOWRISK, b);
3908 case FLG_ITS4LOWRISK:
3913 else /* Turning level off, turns off all higher levels */
3917 case FLG_ITS4LOWRISK:
3918 DOSET (FLG_ITS4MODERATERISK, b);
3920 case FLG_ITS4MODERATERISK:
3921 DOSET (FLG_ITS4RISKY, b);
3924 DOSET (FLG_ITS4VERYRISKY, b);
3926 case FLG_ITS4VERYRISKY:
3927 DOSET (FLG_ITS4MOSTRISKY, b);
3929 case FLG_ITS4MOSTRISKY:
3938 case FLG_MESSAGESTREAMSTDOUT:
3939 g_messagestream = stdout;
3941 case FLG_MESSAGESTREAMSTDERR:
3942 g_messagestream = stderr;
3944 case FLG_WARNINGSTREAMSTDOUT:
3945 g_warningstream = stdout;
3947 case FLG_WARNINGSTREAMSTDERR:
3948 g_warningstream = stderr;
3950 case FLG_ERRORSTREAMSTDOUT:
3951 g_errorstream = stdout;
3953 case FLG_ERRORSTREAMSTDERR:
3954 g_errorstream = stderr;
3957 DOSET (FLG_ALLEMPTY, b);
3958 DOSET (FLG_IFEMPTY, b);
3959 DOSET (FLG_WHILEEMPTY, b);
3960 DOSET (FLG_FOREMPTY, b);
3963 DOSET (FLG_PREDBOOL, b);
3964 DOSET (FLG_PREDBOOLINT, b);
3965 DOSET (FLG_PREDBOOLPTR, b);
3966 DOSET (FLG_PREDBOOLOTHERS, b);
3969 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3970 DOSET (FLG_CHECKEDGLOBALIAS, b);
3971 DOSET (FLG_CHECKMODGLOBALIAS, b);
3972 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3975 DOSET (FLG_ALLBLOCK, b);
3976 DOSET (FLG_IFBLOCK, b);
3977 DOSET (FLG_WHILEBLOCK, b);
3978 DOSET (FLG_FORBLOCK, b);
3992 DOSET (FLG_GRAMMAR, b);
3994 case FLG_CODEIMPONLY:
3995 DOSET (FLG_CODEIMPONLY, b);
3996 DOSET (FLG_GLOBIMPONLY, b);
3997 DOSET (FLG_RETIMPONLY, b);
3998 DOSET (FLG_STRUCTIMPONLY, b);
4000 case FLG_SPECALLIMPONLY:
4001 DOSET (FLG_SPECALLIMPONLY, b);
4002 DOSET (FLG_SPECGLOBIMPONLY, b);
4003 DOSET (FLG_SPECRETIMPONLY, b);
4004 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4006 case FLG_ALLIMPONLY:
4007 DOSET (FLG_ALLIMPONLY, b);
4008 DOSET (FLG_GLOBIMPONLY, b);
4009 DOSET (FLG_RETIMPONLY, b);
4010 DOSET (FLG_STRUCTIMPONLY, b);
4011 DOSET (FLG_SPECGLOBIMPONLY, b);
4012 DOSET (FLG_SPECRETIMPONLY, b);
4013 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4015 case FLG_ANSI89LIMITS:
4016 DOSET (FLG_ANSI89LIMITS, b);
4017 DOSET (FLG_CONTROLNESTDEPTH, b);
4018 DOSET (FLG_STRINGLITERALLEN, b);
4019 DOSET (FLG_INCLUDENEST, b);
4020 DOSET (FLG_NUMSTRUCTFIELDS, b);
4021 DOSET (FLG_NUMENUMMEMBERS, b);
4025 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4026 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4027 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4028 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4029 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4030 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4031 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4034 case FLG_ISO99LIMITS:
4035 DOSET (FLG_ISO99LIMITS, b);
4036 DOSET (FLG_CONTROLNESTDEPTH, b);
4037 DOSET (FLG_STRINGLITERALLEN, b);
4038 DOSET (FLG_INCLUDENEST, b);
4039 DOSET (FLG_NUMSTRUCTFIELDS, b);
4040 DOSET (FLG_NUMENUMMEMBERS, b);
4044 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4045 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4046 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4047 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4048 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4049 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4050 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4053 case FLG_EXTERNALNAMELEN:
4054 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4055 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4057 case FLG_INTERNALNAMELEN:
4058 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4059 DOSET (FLG_INTERNALNAMELEN, TRUE);
4061 case FLG_EXTERNALNAMECASEINSENSITIVE:
4062 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4064 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4066 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4067 context_setValue (FLG_EXTERNALNAMELEN, 0);
4070 case FLG_INTERNALNAMECASEINSENSITIVE:
4071 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4073 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4075 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4076 context_setValue (FLG_INTERNALNAMELEN, 0);
4079 case FLG_INTERNALNAMELOOKALIKE:
4080 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4082 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4084 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4085 context_setValue (FLG_INTERNALNAMELEN, 0);
4089 DOSET (FLG_MODNOMODS, b);
4090 DOSET (FLG_MODGLOBSUNSPEC, b);
4091 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4094 DOSET (FLG_EXPORTVAR, b);
4095 DOSET (FLG_EXPORTFCN, b);
4096 DOSET (FLG_EXPORTTYPE, b);
4097 DOSET (FLG_EXPORTMACRO, b);
4098 DOSET (FLG_EXPORTCONST, b);
4099 gc.anyExports = TRUE;
4102 DOSET (FLG_RETEXPOSE, b);
4103 DOSET (FLG_ASSIGNEXPOSE, b);
4104 DOSET (FLG_CASTEXPOSE, b);
4107 DOSET (FLG_RETVALBOOL, b);
4108 DOSET (FLG_RETVALINT, b);
4109 DOSET (FLG_RETVALOTHER, b);
4114 DOSET (FLG_EXPORTLOCAL, FALSE);
4115 DOSET (FLG_DECLUNDEF, FALSE);
4116 DOSET (FLG_SPECUNDEF, FALSE);
4117 DOSET (FLG_TOPUNUSED, FALSE);
4121 DOSET (FLG_LOOPLOOPBREAK, b);
4122 DOSET (FLG_LOOPSWITCHBREAK, b);
4123 DOSET (FLG_SWITCHLOOPBREAK, b);
4124 DOSET (FLG_SWITCHSWITCHBREAK, b);
4125 DOSET (FLG_LOOPLOOPCONTINUE, b);
4126 DOSET (FLG_DEEPBREAK, b);
4129 DOSET (FLG_FORLOOPEXEC, b);
4130 DOSET (FLG_WHILELOOPEXEC, b);
4131 DOSET (FLG_ITERLOOPEXEC, b);
4134 DOSET (FLG_ACCESSMODULE, b);
4135 DOSET (FLG_ACCESSFILE, b);
4136 DOSET (FLG_ACCESSCZECH, b);
4139 DOSET (FLG_ALLMACROS, b);
4140 DOSET (FLG_FCNMACROS, b);
4141 DOSET (FLG_CONSTMACROS, b);
4144 DOSET (FLG_BOUNDSREAD, b);
4145 DOSET (FLG_BOUNDSWRITE, b);
4148 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4149 DOSET (FLG_CZECHFUNCTIONS, b);
4150 DOSET (FLG_CZECHVARS, b);
4151 DOSET (FLG_CZECHCONSTANTS, b);
4152 DOSET (FLG_CZECHTYPES, b);
4155 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4156 DOSET (FLG_SLOVAKFUNCTIONS, b);
4157 DOSET (FLG_SLOVAKVARS, b);
4158 DOSET (FLG_SLOVAKCONSTANTS, b);
4159 DOSET (FLG_SLOVAKTYPES, b);
4161 case FLG_CZECHOSLOVAK:
4162 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4163 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4164 DOSET (FLG_CZECHOSLOVAKVARS, b);
4165 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4166 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4169 DOSET (FLG_NULLSTATE, b);
4170 DOSET (FLG_NULLDEREF, b);
4171 DOSET (FLG_NULLASSIGN, b);
4172 DOSET (FLG_NULLPASS, b);
4173 DOSET (FLG_NULLRET, b);
4176 DOSET (FLG_MUSTFREEONLY, b);
4177 DOSET (FLG_MUSTFREEFRESH, b);
4180 DOSET (FLG_NULLSTATE, b);
4181 DOSET (FLG_NULLDEREF, b);
4182 DOSET (FLG_NULLASSIGN, b);
4183 DOSET (FLG_NULLPASS, b);
4184 DOSET (FLG_NULLRET, b);
4185 DOSET (FLG_COMPDEF, b);
4186 DOSET (FLG_COMPMEMPASS, b);
4187 DOSET (FLG_UNIONDEF, b);
4188 DOSET (FLG_MEMTRANS, b);
4189 DOSET (FLG_USERELEASED, b);
4190 DOSET (FLG_ALIASUNIQUE, b);
4191 DOSET (FLG_MAYALIASUNIQUE, b);
4192 DOSET (FLG_MUSTFREEONLY, b);
4193 DOSET (FLG_MUSTFREEFRESH, b);
4194 DOSET (FLG_MUSTDEFINE, b);
4195 DOSET (FLG_GLOBSTATE, b);
4196 DOSET (FLG_COMPDESTROY, b);
4197 DOSET (FLG_MUSTNOTALIAS, b);
4198 DOSET (FLG_MEMIMPLICIT, b);
4199 DOSET (FLG_BRANCHSTATE, b);
4200 /*@fallthrough@*/ /* also sets memtrans flags */
4202 DOSET (FLG_MEMTRANS, b);
4203 DOSET (FLG_EXPOSETRANS, b);
4204 DOSET (FLG_OBSERVERTRANS, b);
4205 DOSET (FLG_DEPENDENTTRANS, b);
4206 DOSET (FLG_NEWREFTRANS, b);
4207 DOSET (FLG_ONLYTRANS, b);
4208 DOSET (FLG_OWNEDTRANS, b);
4209 DOSET (FLG_FRESHTRANS, b);
4210 DOSET (FLG_SHAREDTRANS, b);
4211 DOSET (FLG_TEMPTRANS, b);
4212 DOSET (FLG_KEPTTRANS, b);
4213 DOSET (FLG_REFCOUNTTRANS, b);
4214 DOSET (FLG_STATICTRANS, b);
4215 DOSET (FLG_UNKNOWNTRANS, b);
4216 DOSET (FLG_KEEPTRANS, b);
4217 DOSET (FLG_IMMEDIATETRANS, b);
4224 if (b && !gc.anyExports
4225 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4226 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4227 || f == FLG_EXPORTCONST
4228 || f == FLG_EXPORTANY))
4230 gc.anyExports = TRUE;
4235 context_maybeSet (flagcode d)
4237 return (gc.flags[d] || gc.setLocally[d]);
4241 context_getFlag (flagcode d)
4243 return (gc.flags[d]);
4247 context_flagOn (flagcode f, fileloc loc)
4249 return (!context_suppressFlagMsg (f, loc));
4252 static void context_saveFlagSettings (void)
4254 gc.savedFlags = TRUE;
4255 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4256 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4259 static void context_restoreFlagSettings (void)
4261 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4262 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4263 gc.savedFlags = FALSE;
4266 void context_setFilename (fileId fid, int lineno)
4267 /*@globals fileloc g_currentloc;@*/
4268 /*@modifies g_currentloc@*/
4270 if (fileId_baseEqual (currentFile (), fid))
4277 fileloc_setColumn (g_currentloc, 0);
4279 if (fileloc_isSpecialFile (g_currentloc))
4281 gc.inDerivedFile = TRUE;
4284 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4286 int maxdepth = context_getValue (FLG_INCLUDENEST);
4288 if (filelocStack_size (gc.locstack) > maxdepth)
4290 int depth = filelocStack_includeDepth (gc.locstack);
4292 if (depth > maxdepth)
4296 message ("Maximum include nesting depth "
4297 "(%d, current depth %d) exceeded",
4300 filelocStack_nextTop (gc.locstack)))
4302 filelocStack_printIncludes (gc.locstack);
4308 g_currentloc = fileloc_create (fid, lineno, 1);
4309 gc.inheader = fileId_isHeader (currentFile ());
4311 context_enterFileAux ();
4315 void context_enterIterDef (/*@observer@*/ uentry le)
4317 context_enterMacro (le);
4318 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4319 gc.kind = CX_ITERDEF;
4322 void context_enterIterEnd (/*@observer@*/ uentry le)
4324 context_enterMacro (le);
4325 gc.kind = CX_ITEREND;
4329 context_destroyMod (void)
4330 /*@globals killed gc@*/
4333 ctype_destroyMod ();
4337 fileTable_free (gc.ftab);
4338 filelocStack_free (gc.locstack);
4340 gc.ftab = fileTable_undefined;
4342 macrocache_free (gc.mc);
4343 sfree (gc.moduleaccess);
4346 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4347 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4350 sRefSetList_free (gc.modrecs);
4352 flagMarkerList_free (gc.markers);
4354 messageLog_free (gc.msgLog);
4356 clauseStack_free (gc.clauses);
4359 cstring_free (gc.msgAnnote);
4360 globSet_free (gc.globs_used);
4361 metaStateTable_free (gc.stateTable);
4362 annotationTable_free (gc.annotTable);
4369 bool context_msgBoolInt (void)
4371 return gc.flags [FLG_BOOLINT];
4374 bool context_msgCharInt (void)
4376 return gc.flags [FLG_CHARINT];
4379 bool context_msgEnumInt (void)
4381 return gc.flags [FLG_ENUMINT];
4384 bool context_msgPointerArith (void)
4386 return gc.flags [FLG_POINTERARITH];
4389 bool context_msgStrictOps (void)
4391 return gc.flags [FLG_STRICTOPS];
4395 bool context_msgLh (void)
4397 return gc.flags [FLG_DOLH];
4401 void context_pushLoc (void)
4403 fileloc_free (gc.pushloc);
4404 gc.pushloc = gc.saveloc;
4405 gc.saveloc = fileloc_undefined;
4408 void context_popLoc (void)
4410 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4413 bool context_inGlobalScope (void)
4415 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4418 bool context_inInnerScope (void)
4420 return (gc.kind == CX_INNER);
4423 void context_setProtectVars (void)
4425 gc.protectVars = TRUE;
4428 bool context_anyErrors (void)
4430 return (gc.numerrors > 0);
4433 void context_hasError (void)
4436 DPRINTF (("num errors: %d", gc.numerrors));
4439 int context_numErrors (void)
4441 return gc.numerrors;
4444 bool context_neednl (void)
4449 void context_setNeednl (void)
4454 int context_getExpect (void)
4456 return (context_getValue (FLG_EXPECT));
4460 int context_getLCLExpect (void)
4462 return (context_getValue (FLG_LCLEXPECT));
4466 int context_getLimit (void)
4468 return (context_getValue (FLG_LIMIT));
4471 bool context_unlimitedMessages (void)
4473 return (context_getLimit () < 0);
4476 void context_releaseVars (void)
4478 llassert (gc.protectVars);
4479 gc.protectVars = FALSE;
4482 void context_sizeofReleaseVars (void)
4484 /* If there is a nested sizeof, this might not hold:
4485 llassert (gc.protectVars);
4488 gc.protectVars = FALSE;
4491 bool context_inProtectVars (void)
4493 return (gc.protectVars);
4496 void context_hideShowscan (void)
4498 gc.flags[FLG_SHOWSCAN] = FALSE;
4501 void context_unhideShowscan (void)
4503 gc.flags[FLG_SHOWSCAN] = TRUE;
4506 bool context_inHeader (void)
4508 return (gc.inheader);
4511 fileTable context_fileTable (void)
4516 cstring context_tmpdir (void)
4518 return (context_getString (FLG_TMPDIR));
4521 messageLog context_messageLog (void)
4526 bool context_inMacroFunction (void)
4528 return (gc.kind == CX_MACROFCN);
4531 bool context_inMacroConstant (void)
4533 return (gc.kind == CX_MACROCONST);
4536 bool context_inUnknownMacro (void)
4538 return (gc.kind == CX_UNKNOWNMACRO);
4541 void context_setShownFunction (void)
4543 gc.showfunction = FALSE;
4546 bool context_doDump (void)
4548 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4551 bool context_doMerge (void)
4553 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4556 cstring context_getDump (void)
4558 return context_getString (FLG_DUMP);
4561 cstring context_getMerge (void)
4563 return context_getString (FLG_MERGE);
4567 bool context_inLCLLib (void)
4569 return (gc.kind == CX_LCLLIB);
4572 bool context_inImport (void)
4574 return (gc.inimport);
4577 void context_enterImport (void)
4582 void context_leaveImport (void)
4584 gc.inimport = FALSE;
4588 bool context_inMacro (void)
4590 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4591 || gc.kind == CX_UNKNOWNMACRO
4592 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4595 bool context_inIterDef (void)
4597 return (gc.kind == CX_ITERDEF);
4600 bool context_inIterEnd (void)
4602 return (gc.kind == CX_ITEREND);
4605 int context_getLinesProcessed (void)
4607 return (gc.linesprocessed);
4610 int context_getSpecLinesProcessed (void)
4612 return (gc.speclinesprocessed);
4616 void context_processedSpecLine (void)
4618 gc.speclinesprocessed++;
4621 void context_resetSpecLines (void)
4623 gc.speclinesprocessed = 0;
4627 bool context_inGlobalContext (void)
4629 return (gc.kind == CX_GLOBAL);
4632 static void context_quietExitScopes (void)
4635 ** Try to restore the global scope (after an error).
4638 while (!usymtab_inFileScope ())
4640 usymtab_quietExitScope (g_currentloc);
4643 gc.cont.glob = TRUE;
4644 gc.kind = CX_GLOBAL;
4647 void context_checkGlobalScope (void)
4649 if (gc.kind != CX_GLOBAL)
4651 if (context_inMacro ())
4653 ; /* evans 2001-10-14: Okay to be in a macro here! */
4657 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4658 context_quietExitScopes ();
4663 void context_setFileId (fileId s)
4665 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4668 bool context_setBoolName (void)
4670 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4674 cstring context_printBoolName (void)
4676 if (context_setBoolName ())
4678 return context_getBoolName ();
4682 return cstring_makeLiteralTemp ("boolean");
4686 cstring context_getBoolName (void)
4688 return (context_getString (FLG_BOOLTYPE));
4691 cstring context_getFalseName (void)
4693 return (context_getString (FLG_BOOLFALSE));
4696 cstring context_getTrueName (void)
4698 return (context_getString (FLG_BOOLTRUE));
4701 cstring context_getLarchPath (void)
4703 return (context_getString (FLG_LARCHPATH));
4706 cstring context_getLCLImportDir (void)
4708 return (context_getString (FLG_LCLIMPORTDIR));
4711 static void context_setJustPopped (void)
4713 gc.justpopped = TRUE;
4716 void context_clearJustPopped (void)
4718 gc.justpopped = FALSE;
4721 bool context_justPopped (void)
4723 return (gc.justpopped);
4726 void context_setMacroMissingParams (void)
4728 gc.macroMissingParams = TRUE;
4731 void context_resetMacroMissingParams (void)
4733 gc.macroMissingParams = FALSE;
4736 bool context_isMacroMissingParams (void)
4738 return (gc.macroMissingParams);
4741 void context_showFilelocStack (void)
4743 filelocStack_printIncludes (gc.locstack);
4746 metaStateTable context_getMetaStateTable (void)
4748 return gc.stateTable;
4751 metaStateInfo context_lookupMetaStateInfo (cstring key)
4753 return metaStateTable_lookup (gc.stateTable, key);
4756 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4758 annotationInfo ainfo;
4760 ainfo = annotationTable_lookup (gc.annotTable, annot);
4765 void context_addAnnotation (annotationInfo ainfo)
4767 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4771 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4772 annotationInfo_getLoc (ainfo));
4774 annotationInfo_free (ainfo);
4778 annotationTable_insert (gc.annotTable, ainfo);
4782 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4784 if (metaStateTable_contains (gc.stateTable, mname))
4788 message ("Duplicate metastate declaration: %s", mname),
4789 metaStateInfo_getLoc (msinfo));
4790 cstring_free (mname);
4791 metaStateInfo_free (msinfo);
4795 DPRINTF (("Adding meta state: %s", mname));
4796 metaStateTable_insert (gc.stateTable, mname, msinfo);
4800 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4802 if (metaStateTable_size (gc.stateTable) > 0)
4804 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4805 /*@i32 should use smaller value... */
4806 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4808 metaStateTable_elements (gc.stateTable, msname, msi)
4810 mtContextNode context = metaStateInfo_getContext (msi);
4812 if (mtContextNode_matchesRefStrict (context, s))
4814 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4815 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4819 cstring_copy (metaStateInfo_getName (msi)),
4820 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4821 stateInfo_copy (sinfo)));
4825 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4828 end_metaStateTable_elements ;
4830 stateInfo_free (sinfo);
4831 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4836 stateInfo_free (sinfo);
4837 return valueTable_undefined;
4841 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4843 if (metaStateTable_size (gc.stateTable) > 0)
4845 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4846 /*@i32 should use smaller value... */
4848 metaStateTable_elements (gc.stateTable, msname, msi)
4850 /*@i23 only add global...*/
4851 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4852 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4854 valueTable_insert (res,
4855 cstring_copy (metaStateInfo_getName (msi)),
4856 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4857 stateInfo_copy (sinfo)));
4859 end_metaStateTable_elements ;
4861 stateInfo_free (sinfo);
4862 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4867 stateInfo_free (sinfo);
4868 return valueTable_undefined;
4873 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4877 static ctype lastStruct;
4879 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4885 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4891 /*@unused@*/ static int sInfoNum = 0;
4895 /*@unused@*/ uentry ue;
4896 /*@unused@*/ sRef s;
4900 /*@unused@*/ ctype ct;
4901 /*@unused@*/ constraintList inv;
4902 /*@unused@*/ int ngetUe;
4903 /*@unused@*/ struct getUe * t ;
4907 static struct sInfo globalStructInfo;
4910 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4911 stable release of splint. I coomented them out so that they won't break anything
4912 but didn't delete them because they will be fixed and included later
4916 void setGlobalStructInfo(ctype ct, constraintList list)
4921 f = ctype_getFields (ct);
4923 if (constraintList_isDefined(list) )
4925 globalStructInfo.ct = ct;
4926 globalStructInfo.inv = list;
4928 globalStructInfo.ngetUe = 0;
4930 / *abstraction violation fix it * /
4931 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4933 globalStructInfo.ngetUe = f->nelements;
4937 uentryList_elements(f, ue)
4939 globalStructInfo.t[i].ue = ue;
4940 globalStructInfo.t[i].s = uentry_getSref(ue);
4941 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4942 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4947 end_uentryList_elements;
4953 bool hasInvariants (ctype ct) /*@*/
4955 if ( ctype_sameName(globalStructInfo.ct, ct) )