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 (to support MS/VC++ error message format).
943 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
948 ** C is way-lame, and you can initialize an array to a constant except where
949 ** it is declared. Hence, a macro is used to set the modeflags.
953 # define SETFLAGS() \
954 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
955 if (!flagcode_isModeFlag (modeflags[i])) \
956 { llbug (message ("not a mode flag: %s", \
957 flagcode_unparse (modeflags[i]))); } \
958 else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }}
960 static void context_setModeAux (cstring p_s, bool p_warn) ;
963 context_setMode (cstring s)
965 context_setModeAux (s, TRUE);
969 context_setModeNoWarn (cstring s)
971 context_setModeAux (s, FALSE);
975 context_setModeAux (cstring s, bool warn)
977 intSet setflags = intSet_new ();
981 if (flagcode_isModeFlag (code))
983 if (gc.setGlobally[code])
985 (void) intSet_insert (setflags, (int) code);
990 if (!intSet_isEmpty (setflags))
992 cstring rflags = cstring_undefined;
995 intSet_elements (setflags, el)
997 if (cstring_isUndefined (rflags))
999 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
1003 rflags = message ("%q, %s", rflags,
1004 flagcode_unparse ((flagcode) el));
1008 if (num > 4 && intSet_size (setflags) > 6)
1010 rflags = message ("%q, (%d others) ...", rflags,
1011 intSet_size (setflags) - num);
1014 } end_intSet_elements ;
1018 voptgenerror (FLG_WARNFLAGS,
1019 message ("Setting mode %s after setting mode flags will "
1020 "override set values of flags: %s",
1025 cstring_free (rflags);
1028 intSet_free (setflags);
1030 context_resetModeFlags ();
1032 if (cstring_equalLit (s, "standard"))
1034 flagcode modeflags[] =
1036 FLG_ENUMINT, FLG_MACROMATCHNAME,
1037 FLG_STRINGLITNOROOM,
1038 FLG_STRINGLITNOROOMFINALNULL,
1039 FLG_MACROUNDEF, FLG_RELAXQUALS,
1040 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1041 FLG_CHECKSTRICTGLOBALIAS,
1042 FLG_CHECKEDGLOBALIAS,
1043 FLG_CHECKMODGLOBALIAS,
1044 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1045 FLG_UNSIGNEDCOMPARE,
1046 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1048 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1049 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1050 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1051 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1052 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1055 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1056 FLG_MACROSTMT, FLG_MACROPARENS,
1059 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1060 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1065 /* memchecks flags */
1067 FLG_NULLSTATE, FLG_NULLASSIGN,
1068 FLG_NULLPASS, FLG_NULLRET,
1070 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1073 /* memtrans flags */
1092 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1095 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1096 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1099 FLG_STATETRANSFER, FLG_STATEMERGE,
1100 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1102 FLG_IMPCHECKEDSPECGLOBALS,
1103 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1104 FLG_IFEMPTY, FLG_REALCOMPARE,
1105 FLG_BOOLOPS, FLG_PTRNEGATE,
1107 FLG_SHIFTIMPLEMENTATION,
1108 FLG_BUFFEROVERFLOWHIGH,
1115 else if (cstring_equalLit (s, "weak"))
1117 flagcode modeflags[] =
1119 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1120 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1121 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1122 FLG_CHARUNSIGNEDCHAR,
1124 FLG_VARUNUSED, FLG_FUNCUNUSED,
1126 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1129 FLG_BUFFEROVERFLOWHIGH,
1130 FLG_RETSTACK, FLG_PTRNEGATE,
1131 FLG_STATETRANSFER, FLG_STATEMERGE,
1132 FLG_LONGUNSIGNEDINTEGRAL,
1133 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1137 FLG_BUFFEROVERFLOWHIGH,
1138 FLG_STRINGLITNOROOM,
1139 FLG_STRINGLITNOROOMFINALNULL,
1145 else if (cstring_equalLit (s, "checks"))
1147 flagcode modeflags[] =
1149 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1150 FLG_STATETRANSFER, FLG_STATEMERGE,
1151 FLG_CHECKSTRICTGLOBALIAS,
1152 FLG_CHECKEDGLOBALIAS,
1153 FLG_CHECKMODGLOBALIAS,
1154 FLG_UNCHECKEDGLOBALIAS,
1156 FLG_STRINGLITNOROOM,
1157 FLG_STRINGLITNOROOMFINALNULL,
1158 FLG_STRINGLITSMALLER,
1159 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1160 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1161 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1162 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1163 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1164 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1165 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1166 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1167 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1168 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1169 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1170 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1171 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1172 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1179 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1183 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1185 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1186 FLG_EVALORDER, FLG_USEDEF,
1189 /* warn use flags */
1190 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1191 FLG_BUFFEROVERFLOWHIGH,
1193 /* memchecks flags */
1195 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1196 FLG_NULLPASS, FLG_NULLRET,
1198 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1200 /* memtrans flags */
1214 FLG_STATICINITTRANS,
1215 FLG_UNKNOWNINITTRANS,
1218 FLG_ONLYUNQGLOBALTRANS,
1219 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1222 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1223 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1226 FLG_NULLPOINTERARITH,
1227 FLG_SHADOW, FLG_DEPARRAYS,
1228 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1229 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1230 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1231 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1232 FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES,
1233 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1234 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1235 FLG_SHIFTIMPLEMENTATION,
1236 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1241 else if (cstring_equalLit (s, "strict"))
1243 flagcode modeflags[] =
1245 FLG_CHECKSTRICTGLOBALIAS,
1246 FLG_CHECKEDGLOBALIAS,
1247 FLG_CHECKMODGLOBALIAS,
1248 FLG_UNCHECKEDGLOBALIAS,
1252 FLG_STRINGLITNOROOM,
1253 FLG_STRINGLITNOROOMFINALNULL,
1254 FLG_STRINGLITSMALLER,
1255 FLG_STATETRANSFER, FLG_STATEMERGE,
1256 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1257 FLG_ALLGLOBALS, FLG_IMPTYPE,
1258 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1259 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1260 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1261 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1264 FLG_ONLYUNQGLOBALTRANS,
1265 FLG_GLOBALSIMPMODIFIESNOTHING,
1266 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1267 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1268 FLG_USEALLGLOBS, FLG_RETALIAS,
1269 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1270 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1271 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1273 FLG_EXPORTITER, FLG_EXPORTCONST,
1274 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1275 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1277 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1279 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1280 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1281 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1282 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1283 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1284 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1285 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1286 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1288 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1291 FLG_MACROREDEF, FLG_MACROEMPTY,
1292 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1294 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1296 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1297 FLG_MODOBSERVERUNCON,
1302 /* warn use flags */
1303 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1304 FLG_BUFFEROVERFLOWHIGH,
1305 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1307 /* memchecks flags */
1308 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1309 FLG_NULLPASS, FLG_NULLRET,
1311 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1313 /* memtrans flags */
1329 FLG_STATICINITTRANS,
1330 FLG_UNKNOWNINITTRANS,
1332 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1335 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1336 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1340 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1342 FLG_SHADOW, FLG_DEPARRAYS,
1343 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1344 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1345 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1346 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1347 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1348 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1349 FLG_IMPCHECKEDSTRICTSTATICS,
1350 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1351 FLG_IMPCHECKMODINTERNALS,
1352 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1353 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1354 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1355 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1356 FLG_CONTROLNESTDEPTH,
1357 FLG_FORBLOCK, FLG_WHILEBLOCK,
1358 FLG_FOREMPTY, FLG_WHILEEMPTY,
1359 FLG_IFEMPTY, FLG_IFBLOCK,
1361 FLG_REALCOMPARE, FLG_BOOLOPS,
1362 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1365 FLG_SHIFTIMPLEMENTATION,
1367 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1375 llcontbug (message ("context_setMode: bad mode: %s", s));
1380 context_isSpecialFile (cstring fname)
1382 cstring ext = fileLib_getExtension (fname);
1384 return (cstring_equalLit (ext, ".y")
1385 || cstring_equalLit (ext, ".l")
1386 || cstring_equalLit (fname, "lex.yy.c"));
1390 context_isSystemDir (cstring dir)
1392 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1393 cstring savedir = thisdir;
1394 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1396 if (cstring_isDefined (nextdir))
1398 /*@access cstring@*/
1399 *nextdir = '\0'; /* closes thisdir */
1401 /*@noaccess cstring@*/
1404 /* 2001-09-09: added thisdir[0] != '\0'
1405 ** herbert: don't compare with an empty name!
1406 ** should return false for empty directory path
1409 while (!cstring_isEmpty (thisdir))
1411 DPRINTF (("Test: %s / %s", dir, thisdir));
1413 if (osd_equalCanonicalPrefix (dir, thisdir))
1415 cstring_free (savedir);
1419 if (cstring_isDefined (nextdir))
1422 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1424 if (cstring_isDefined (nextdir))
1426 /*@access cstring@*/
1429 /*@noaccess cstring@*/
1438 DPRINTF (("Returns FALSE"));
1439 cstring_free (savedir);
1444 context_addFileAccessType (typeId t)
1448 if (context_inFunctionLike ())
1450 gc.acct = typeIdSet_insert (gc.acct, t);
1453 gc.facct = typeIdSet_insert (gc.facct, t);
1455 base = fileloc_getBase (g_currentloc);
1456 insertModuleAccess (base, t);
1457 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1458 typeIdSet_unparse (gc.acct)));
1462 context_removeFileAccessType (typeId t)
1464 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1465 || gc.kind == CX_UNKNOWNMACRO)
1467 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1470 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1471 gc.nacct = typeIdSet_insert (gc.nacct, t);
1474 void context_enterFunctionHeader (void)
1476 if (context_getFlag (FLG_GRAMMAR))
1478 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1481 if (gc.kind != CX_GLOBAL)
1483 llparseerror (cstring_makeLiteral
1484 ("Likely parse error. Function header outside global context."));
1488 llassert (gc.kind == CX_GLOBAL);
1489 DPRINTF (("Enter function header!"));
1490 gc.inFunctionHeader = TRUE;
1494 void context_exitFunctionHeader (void)
1496 if (context_getFlag (FLG_GRAMMAR))
1498 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1501 DPRINTF (("Exit function header!"));
1502 gc.inFunctionHeader = FALSE;
1505 bool context_inFunctionHeader (void)
1507 return (gc.inFunctionHeader);
1510 void context_enterFunctionDeclaration (uentry e)
1512 if (context_getFlag (FLG_GRAMMAR))
1514 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1517 DPRINTF (("Enter function decl"));
1518 llassert (gc.savekind == CX_ERROR);
1519 gc.savekind = gc.kind;
1520 gc.savecont = gc.cont;
1521 gc.kind = CX_FCNDECLARATION;
1525 void context_exitFunctionDeclaration (void)
1527 if (context_getFlag (FLG_GRAMMAR))
1529 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1532 DPRINTF (("Exit function decl"));
1533 llassert (gc.savekind != CX_ERROR);
1534 llassert (gc.kind == CX_FCNDECLARATION);
1535 gc.kind = gc.savekind;
1536 gc.cont = gc.savecont;
1538 gc.savekind = CX_ERROR;
1540 if (context_getFlag (FLG_GRAMMAR))
1542 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1546 bool context_inFunctionDeclaration (void)
1548 return (gc.kind == CX_FCNDECLARATION);
1553 context_enterMacro (/*@observer@*/ uentry e)
1555 context_enterFunction (e);
1556 gc.kind = CX_MACROFCN;
1560 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1562 llassert (uentry_isFunction (e));
1563 context_enterFunction (e);
1564 gc.kind = CX_UNKNOWNMACRO;
1567 void context_enterAndClause (exprNode e)
1570 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1571 pushClause (ANDCLAUSE);
1574 void context_enterOrClause (exprNode e)
1576 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1577 pushClause (ORCLAUSE);
1580 bool context_inDeepLoop (void)
1582 bool inLoop = FALSE;
1584 clauseStack_elements (gc.clauses, el)
1586 if (clause_isLoop (el))
1595 } end_clauseStack_elements;
1600 bool context_inDeepSwitch (void)
1602 bool inLoop = FALSE;
1604 clauseStack_elements (gc.clauses, el)
1606 if (clause_isSwitch (el))
1615 } end_clauseStack_elements;
1620 bool context_inDeepLoopSwitch (void)
1622 bool inLoop = FALSE;
1624 clauseStack_elements (gc.clauses, el)
1626 if (clause_isBreakable (el))
1635 } end_clauseStack_elements;
1640 clause context_breakClause (void)
1642 clauseStack_elements (gc.clauses, el)
1644 if (clause_isSwitch (el))
1648 else if (clause_isLoop (el))
1656 } end_clauseStack_elements;
1661 clause context_nextBreakClause (void)
1663 bool hasOne = FALSE;
1665 clauseStack_elements (gc.clauses, el)
1667 if (clause_isBreakable (el))
1678 } end_clauseStack_elements;
1683 bool context_inConditional (void)
1685 clauseStack_elements (gc.clauses, el)
1688 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1689 ** to distinguish if from ? for this
1692 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1696 } end_clauseStack_elements;
1701 void context_exitAndClause (exprNode pred, exprNode tbranch)
1703 context_setJustPopped ();
1705 llassert (gc.inclause == ANDCLAUSE);
1707 usymtab_popAndBranch (pred, tbranch);
1708 clauseStack_pop (gc.clauses);
1709 gc.inclause = topClause (gc.clauses);
1712 void context_exitOrClause (exprNode pred, exprNode tbranch)
1714 context_setJustPopped ();
1716 llassert (gc.inclause == ORCLAUSE);
1718 usymtab_popOrBranch (pred, tbranch);
1719 clauseStack_pop (gc.clauses);
1720 gc.inclause = topClause (gc.clauses);
1723 static void context_enterCondClauseAux (clause cl)
1729 static void context_enterTrueAux (exprNode e, clause cl)
1732 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1736 void context_enterIterClause (void)
1738 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1741 void context_enterDoWhileClause (void)
1743 pushClause (DOWHILECLAUSE);
1746 void context_enterWhileClause (exprNode e)
1748 context_enterTrueAux (e, WHILECLAUSE);
1751 void context_enterForClause (exprNode e)
1753 context_enterTrueAux (e, FORCLAUSE);
1756 void context_enterTrueClause (exprNode e)
1758 context_enterTrueAux (e, TRUECLAUSE);
1761 void context_enterSwitch (exprNode e)
1763 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1764 usymtab_switchBranch (e);
1765 context_enterCondClauseAux (SWITCHCLAUSE);
1768 void context_exitSwitch (exprNode e, bool allpaths)
1770 usymtab_exitSwitch (e, allpaths);
1772 while (clause_isCase (clauseStack_top (gc.clauses)))
1774 clauseStack_pop (gc.clauses);
1777 context_exitClauseSimp ();
1780 void context_enterCaseClause (exprNode e)
1782 bool branch = FALSE;
1784 DPRINTF (("Enter case clause!"));
1786 branch = usymtab_newCase (exprNode_undefined, e);
1790 context_enterCondClauseAux (CASECLAUSE);
1794 static void context_enterFalseClauseAux (exprNode e, clause cl)
1797 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1799 clauseStack_switchTop (gc.clauses, cl);
1802 void context_enterFalseClause (exprNode e)
1805 context_enterFalseClauseAux (e, FALSECLAUSE);
1809 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1811 gc.kind = CX_MACROCONST;
1813 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1815 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1819 usymtab_enterScope ();
1820 sRef_enterFunctionScope ();
1822 gc.globs = globSet_undefined;
1823 globSet_clear (gc.globs_used);
1824 gc.mods = sRefSet_undefined;
1827 uentry context_getHeader (void)
1829 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1831 llfatalbug (message ("context_getHeader: bad call: %q",
1832 context_unparse ()));
1835 return (gc.cont.fcn);
1839 context_setFunctionDefined (fileloc loc)
1843 case CX_UNKNOWNMACRO:
1846 uentry_setFunctionDefined (gc.cont.fcn, loc);
1849 /* (not a bug because of parse errors) */
1855 context_enterFunction (/*@exposed@*/ uentry e)
1857 gc.kind = CX_FUNCTION;
1860 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1862 if (uentry_hasAccessType (e))
1864 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1872 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1873 typeIdSet_unparse (gc.acct)));
1875 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1877 gc.globs = uentry_getGlobs (e);
1878 globSet_clear (gc.globs_used);
1879 gc.mods = uentry_getMods (e);
1881 usymtab_enterFunctionScope (e);
1882 sRef_enterFunctionScope ();
1885 bool context_inOldSytleScope(void)
1887 if (gc.kind == CX_OLDSTYLESCOPE)
1894 context_enterOldStyleScope (void)
1896 gc.kind = CX_OLDSTYLESCOPE;
1897 DPRINTF (("Enter old style scope!"));
1898 usymtab_enterFunctionScope (uentry_undefined);
1902 context_completeOldStyleFunction (uentry e)
1904 llassert (gc.kind == CX_OLDSTYLESCOPE);
1906 gc.kind = CX_FUNCTION;
1909 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1911 if (uentry_hasAccessType (e))
1913 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1921 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1922 typeIdSet_unparse (gc.acct)));
1924 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1926 if (!globSet_isEmpty (uentry_getGlobs (e)))
1928 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1929 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1932 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1934 gc.globs = uentry_getGlobs (e);
1935 globSet_clear (gc.globs_used);
1937 gc.mods = uentry_getMods (e);
1939 if (!sRefSet_isEmpty (gc.mods))
1941 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1942 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1945 sRef_enterFunctionScope ();
1948 static bool context_checkStrictGlobals (void)
1950 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1953 static bool context_hasGlobs (void)
1955 if (context_inFunctionLike ())
1957 return (uentry_hasGlobs (gc.cont.fcn));
1965 static bool context_checkCheckedGlobals (void)
1967 return (context_getFlag (FLG_GLOBALS)
1968 && (context_getFlag (FLG_GLOBUNSPEC)
1969 || context_hasGlobs ()));
1972 static bool context_checkUnknownGlobals (void)
1974 /* should be uentry_hasGlobs ? */
1976 return (context_getFlag (FLG_ALLGLOBALS)
1977 && (context_getFlag (FLG_GLOBUNSPEC)
1978 || context_hasGlobs ()));
1981 static bool context_checkUncheckedGlobals (void)
1987 context_checkExport (uentry e)
1989 if (!gc.anyExports) return FALSE;
1991 if (uentry_isFunction (e)
1992 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1994 return context_maybeSet (FLG_EXPORTFCN);
1996 else if (uentry_isExpandedMacro (e))
1998 return context_maybeSet (FLG_EXPORTMACRO);
2000 else if (uentry_isVariable (e))
2002 return context_maybeSet (FLG_EXPORTVAR);
2004 else if (uentry_isEitherConstant (e))
2006 return context_maybeSet (FLG_EXPORTCONST);
2008 else if (uentry_isIter (e) || uentry_isEndIter (e))
2010 return context_maybeSet (FLG_EXPORTITER);
2012 else if (uentry_isDatatype (e))
2014 return context_maybeSet (FLG_EXPORTTYPE);
2023 context_checkGlobUse (uentry glob)
2026 if (uentry_isCheckedStrict (glob))
2028 return context_checkStrictGlobals ();
2030 else if (uentry_isChecked (glob))
2032 return context_checkCheckedGlobals ();
2034 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2036 return context_checkUnknownGlobals ();
2040 llassert (uentry_isUnchecked (glob));
2042 return context_checkUncheckedGlobals ();
2047 context_checkAliasGlob (uentry glob)
2049 if (uentry_isCheckedStrict (glob))
2051 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2053 else if (uentry_isChecked (glob))
2055 return gc.flags[FLG_CHECKEDGLOBALIAS];
2057 else if (uentry_isCheckMod (glob))
2059 return gc.flags[FLG_CHECKMODGLOBALIAS];
2063 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2065 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2069 bool context_checkInternalUse (void)
2071 if (context_hasGlobs ())
2073 return (gc.flags[FLG_INTERNALGLOBS]);
2077 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2082 context_checkGlobMod (sRef el)
2084 uentry ue = sRef_getUentry (el);
2086 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2088 if (uentry_isCheckedModify (ue)
2089 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2091 if (context_hasMods ())
2093 return (gc.flags[FLG_MODGLOBS]);
2097 if (uentry_isCheckedStrict (ue))
2099 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2103 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2109 if (context_hasMods ())
2111 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2121 context_usedGlobal (/*@exposed@*/ sRef el)
2123 if (!globSet_member (gc.globs_used, el))
2126 ** The first time a global is used in a function, we need
2127 ** to clear the derived sRefs, since they were set for the
2128 ** previous function.
2131 sRef_clearDerived (el);
2132 gc.globs_used = globSet_insert (gc.globs_used, el);
2136 /*@observer@*/ sRefSet
2137 context_modList (void)
2143 context_globAccess (sRef s)
2145 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2146 return (globSet_member (gc.globs, s));
2150 context_hasAccess (typeId t)
2152 if (context_inFunctionLike ())
2154 DPRINTF (("Access %d / %s",
2155 t, typeIdSet_unparse (gc.acct)));
2156 return (typeIdSet_member (gc.acct, t));
2160 return (context_hasFileAccess (t));
2165 context_hasFileAccess (typeId t)
2167 return (typeIdSet_member (gc.facct, t));
2171 context_unparseAccess (void)
2173 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2174 typeIdSet_unparse (gc.facct)));
2178 context_unparseClauses (void)
2180 return (clauseStack_unparse (gc.clauses));
2184 context_couldHaveAccess (typeId t)
2186 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2188 return (typeIdSet_member (gc.acct, t));
2192 return (typeIdSet_member (gc.facct, t));
2197 context_getRetType (void)
2199 ctype f = ctype_undefined;
2201 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2203 f = uentry_getType (gc.cont.fcn);
2205 else if (gc.kind == CX_UNKNOWNMACRO)
2207 return ctype_unknown;
2211 llcontbuglit ("context_getRetType: not in a function context");
2212 return ctype_unknown;
2215 if (!ctype_isFunction (f))
2217 if (ctype_isKnown (f))
2219 llbuglit ("context_getRetType: not a function");
2222 return ctype_unknown;
2224 return (ctype_getReturnType (f));
2228 context_hasMods (void)
2230 if (context_inFunctionLike ())
2232 return (uentry_hasMods (gc.cont.fcn));
2241 context_exitAllClauses (void)
2243 while (!clauseStack_isEmpty (gc.clauses))
2245 clause el = clauseStack_top (gc.clauses);
2248 if (clause_isNone (el))
2250 usymtab_quietExitScope (g_currentloc);
2251 clauseStack_pop (gc.clauses);
2255 context_exitClausePlain ();
2259 clauseStack_clear (gc.clauses);
2260 gc.inclause = NOCLAUSE;
2264 context_exitAllClausesQuiet (void)
2266 while (!clauseStack_isEmpty (gc.clauses))
2268 clause el = clauseStack_top (gc.clauses);
2271 usymtab_quietExitScope (g_currentloc);
2272 clauseStack_pop (gc.clauses);
2275 clauseStack_clear (gc.clauses);
2276 gc.inclause = NOCLAUSE;
2280 void context_exitClauseSimp (void)
2283 context_setJustPopped ();
2284 clauseStack_pop (gc.clauses);
2285 gc.inclause = topClause (gc.clauses);
2289 void context_exitCaseClause (void)
2291 context_setJustPopped ();
2292 usymtab_popCaseBranch ();
2293 clauseStack_pop (gc.clauses);
2294 gc.inclause = topClause (gc.clauses);
2298 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2300 context_setJustPopped ();
2301 /*@i32 was makeAlt */
2302 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2303 clauseStack_pop (gc.clauses);
2304 gc.inclause = topClause (gc.clauses);
2307 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2309 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2311 if (gc.inclause != TRUECLAUSE)
2313 llparseerror (cstring_makeLiteral
2314 ("Likely parse error. Conditional clauses are inconsistent."));
2318 context_setJustPopped ();
2319 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2320 clauseStack_pop (gc.clauses);
2321 gc.inclause = topClause (gc.clauses);
2324 void context_exitIterClause (exprNode body)
2326 llassert (gc.inclause == ITERCLAUSE);
2328 context_setJustPopped ();
2330 if (context_getFlag (FLG_ITERLOOPEXEC))
2332 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2336 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2339 clauseStack_pop (gc.clauses);
2340 gc.inclause = topClause (gc.clauses);
2343 static void context_popCase (void) {
2345 ** If we are exiting an outer clause, sometimes still in a switch case.
2359 DPRINTF (("Popping case clause: %s",
2360 clauseStack_unparse (gc.clauses)));
2362 if (gc.inclause == CASECLAUSE) {
2363 context_exitCaseClause ();
2367 void context_exitWhileClause (exprNode pred, exprNode body)
2369 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2373 if (gc.inclause != WHILECLAUSE) {
2374 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2375 clauseStack_unparse (gc.clauses)));
2378 llassert (gc.inclause == WHILECLAUSE);
2380 context_setJustPopped ();
2384 ** predicate must be false after while loop (unless there are breaks)
2387 if (context_getFlag (FLG_WHILELOOPEXEC))
2389 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2393 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2397 usymtab_addGuards (invGuards);
2398 guardSet_free (invGuards);
2400 clauseStack_pop (gc.clauses);
2401 gc.inclause = topClause (gc.clauses);
2404 void context_exitDoWhileClause (exprNode pred)
2406 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2408 if (gc.inclause == CASECLAUSE) {
2409 /* handle Duff's device */
2410 clauseStack_pop (gc.clauses);
2411 gc.inclause = topClause (gc.clauses);
2414 llassert (gc.inclause == DOWHILECLAUSE);
2416 context_setJustPopped ();
2419 usymtab_addGuards (invGuards);
2420 guardSet_free (invGuards);
2422 clauseStack_pop (gc.clauses);
2423 gc.inclause = topClause (gc.clauses);
2426 void context_exitForClause (exprNode forPred, exprNode body)
2428 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2430 llassert (gc.inclause == FORCLAUSE);
2431 context_setJustPopped ();
2433 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2436 ** Predicate must be false after for loop (unless there are breaks)
2439 if (context_getFlag (FLG_FORLOOPEXEC))
2441 DPRINTF (("Here: for loop exec"));
2442 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2446 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2447 && exprNode_loopMustExec (forPred))
2449 DPRINTF (("Here: loop must exec"));
2450 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2454 DPRINTF (("Pop true branch:"));
2455 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2459 usymtab_addGuards (invGuards);
2460 guardSet_free (invGuards);
2461 clauseStack_pop (gc.clauses);
2462 gc.inclause = topClause (gc.clauses);
2465 static void context_exitClausePlain (void)
2467 llassert (gc.inclause != NOCLAUSE);
2469 if (gc.inclause == FALSECLAUSE)
2471 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2475 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2479 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2481 context_setJustPopped ();
2483 if (gc.inclause == FALSECLAUSE)
2485 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2487 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2489 clauseStack_pop (gc.clauses);
2490 gc.inclause = topClause (gc.clauses);
2494 context_exitTrueClause (pred, tbranch);
2499 context_returnFunction (void)
2501 usymtab_checkFinalScope (TRUE);
2505 context_exitFunction (void)
2507 DPRINTF (("Exit function: %s", context_unparse ()));
2509 if (!context_inFunction () && !context_inMacroConstant ()
2510 && !context_inUnknownMacro ()
2511 && !context_inIterDef () && !context_inIterEnd ())
2514 ** not a bug because of parse errors
2521 if (context_inMacro () && usymtab_inFunctionScope ())
2523 usymtab_exitScope (exprNode_undefined);
2526 if (uentry_hasGlobs (gc.cont.fcn))
2528 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2532 if (uentry_hasMods (gc.cont.fcn))
2534 if (context_getFlag (FLG_MUSTMOD))
2536 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2540 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2543 ** clear file static modifies
2546 /* do this first to get unused error messages */
2548 usymtab_exitScope (exprNode_undefined);
2549 sRef_exitFunctionScope ();
2551 gc.showfunction = FALSE;
2552 gc.kind = CX_GLOBAL;
2553 gc.cont.glob = TRUE;
2555 gc.globs = globSet_new ();
2556 globSet_clear (gc.globs_used);
2557 gc.mods = sRefSet_new ();
2560 llassert (clauseStack_isEmpty (gc.clauses));
2561 llassert (gc.inclause == NOCLAUSE);
2562 DPRINTF (("After exit function: %s", context_unparse ()));
2566 context_quietExitFunction (void)
2568 while (gc.kind == CX_INNER)
2570 context_exitInnerPlain ();
2573 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2574 && !context_inIterDef () && !context_inIterEnd ())
2579 usymtab_quietExitScope (g_currentloc);
2581 gc.showfunction = FALSE;
2582 gc.kind = CX_GLOBAL;
2583 gc.cont.glob = TRUE;
2585 gc.globs = globSet_new ();
2586 globSet_clear (gc.globs_used);
2587 gc.mods = sRefSet_new ();
2589 sRef_exitFunctionScope ();
2593 /*@observer@*/ uentryList
2594 context_getParams (void)
2596 if (context_inFunctionLike ())
2598 return (uentry_getParams (gc.cont.fcn));
2602 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2603 return uentryList_undefined;
2607 /*@observer@*/ globSet
2608 context_getUsedGlobs (void)
2610 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2611 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2613 return (gc.globs_used);
2617 context_moduleName ()
2619 return (fileloc_getBase (g_currentloc));
2622 /*@observer@*/ globSet
2623 context_getGlobs (void)
2625 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2626 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2632 context_addBoolAccess (void)
2634 cstring bname = context_getString (FLG_BOOLTYPE);
2635 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2637 addModuleAccess (cstring_copy (bname), boolt);
2639 /* for sys/types (perhaps, this is bogus!) */
2640 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2645 context_canAccessBool (void)
2652 static typeId boolType = typeId_invalid;
2654 if (typeId_isInvalid (boolType))
2656 boolType = usymtab_getTypeId (context_getBoolName ());
2659 if (typeId_isInvalid (boolType)) {
2662 return (typeIdSet_member (gc.acct, boolType));
2667 /* evs 2000-07-25: old version - replaced */
2670 context_boolImplementationType () {
2671 /* For now, this is bogus! */
2676 context_canAccessBool (void)
2678 static typeId boolType = typeId_invalid;
2680 if (typeId_isInvalid (boolType))
2682 boolType = usymtab_getTypeId (context_getBoolName ());
2685 if (!typeId_isInvalid (boolType))
2687 return context_hasAccess (boolType);
2698 context_setMessageAnnote (/*@only@*/ cstring s)
2700 llassert (cstring_isUndefined (gc.msgAnnote));
2705 context_hasMessageAnnote (void)
2707 return (cstring_isDefined (gc.msgAnnote));
2711 context_clearMessageAnnote (void)
2713 if (cstring_isDefined (gc.msgAnnote))
2715 cstring_free (gc.msgAnnote);
2716 gc.msgAnnote = cstring_undefined;
2721 context_getMessageAnnote (void)
2723 cstring st = gc.msgAnnote;
2725 gc.msgAnnote = cstring_undefined;
2730 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2732 llassert (sRef_isInvalid (gc.aliasAnnote));
2733 llassert (!sRef_sameName (s, t));
2735 gc.aliasAnnoteAls = t;
2739 context_hasAliasAnnote (void)
2741 return (sRef_isValid (gc.aliasAnnote));
2745 context_clearAliasAnnote (void)
2747 gc.aliasAnnote = sRef_undefined;
2751 context_getAliasAnnote (void)
2753 sRef ret = gc.aliasAnnote;
2754 sRef als = gc.aliasAnnoteAls;
2756 llassert (sRef_isValid (ret) && sRef_isValid (als));
2758 gc.aliasAnnote = sRef_undefined;
2759 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2763 context_recordFileModifies (sRefSet mods)
2765 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2769 context_recordFileGlobals (globSet mods)
2771 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2772 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2776 context_setCommentMarkerChar (char c)
2778 llassert (c != '\0');
2780 context_setValue (FLG_COMMENTCHAR, (int) c);
2784 context_getCommentMarkerChar (void)
2786 return ((char) context_getValue (FLG_COMMENTCHAR));
2790 context_setValue (flagcode flag, int val)
2792 int index = flagcode_valueIndex (flag);
2794 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2802 llerror_flagWarning (message ("Value for %s must be a positive "
2803 "number (given %d)",
2804 flagcode_unparse (flag), val));
2807 if (flag == FLG_LINELEN && val < MINLINELEN)
2809 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2810 flagcode_unparse (flag),
2816 case FLG_INCLUDENEST:
2817 case FLG_CONTROLNESTDEPTH:
2818 case FLG_STRINGLITERALLEN:
2819 case FLG_NUMSTRUCTFIELDS:
2820 case FLG_NUMENUMMEMBERS:
2821 case FLG_INDENTSPACES:
2824 llerror_flagWarning (message ("Value for %s must be a non-negative "
2825 "number (given %d)",
2826 flagcode_unparse (flag), val));
2835 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2836 gc.values[index] = val;
2840 context_setValueAndFlag (flagcode flag, int val)
2842 gc.flags[flag] = TRUE;
2843 context_setValue (flag, val);
2847 context_getValue (flagcode flag)
2849 int index = flagcode_valueIndex (flag);
2851 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2852 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2853 return (gc.values[index]);
2857 context_getCounter (flagcode flag)
2859 int index = flagcode_valueIndex (flag);
2861 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2862 return (gc.counters[index]);
2866 context_incCounter (flagcode flag)
2868 int index = flagcode_valueIndex (flag);
2870 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2872 gc.counters[index]++;
2876 context_decCounter (flagcode flag)
2878 int index = flagcode_valueIndex (flag);
2880 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2881 gc.counters[index]--;
2884 bool context_showFunction (void)
2886 return (gc.showfunction);
2890 context_setString (flagcode flag, cstring val)
2892 int index = flagcode_stringIndex (flag);
2894 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2896 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2900 case FLG_MESSAGESTREAM:
2901 case FLG_WARNINGSTREAM:
2902 case FLG_ERRORSTREAM:
2904 if (cstring_isDefined (val))
2908 if (osd_fileExists (val))
2910 if (context_getFlag (FLG_STREAMOVERWRITE))
2912 llfatalerror (message
2913 ("Output stream file %s would overwrite existing file. "
2914 "Use -streamoverwrite if you want to allow this.",
2919 fstream = fopen (cstring_toCharsSafe (val), "w");
2921 if (fstream == NULL)
2923 llfatalerror (message ("Unable to open output stream file %s for writing",
2928 ** This ensures fstream will be closed on exit.
2931 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2935 case FLG_MESSAGESTREAM:
2936 g_messagestream = fstream;
2937 /*@innerbreak@*/ break;
2938 case FLG_WARNINGSTREAM:
2939 g_warningstream = fstream;
2940 /*@innerbreak@*/ break;
2941 case FLG_ERRORSTREAM:
2942 g_errorstream = fstream;
2943 /*@innerbreak@*/ break;
2946 /*@-statetransfer@*/
2947 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2950 case FLG_SYSTEMDIRS:
2952 llassert (cstring_isDefined (val));
2954 if (cstring_firstChar (val) == '\"')
2957 cstring tval = cstring_copy (cstring_suffix (val, 1));
2959 if (cstring_lastChar (tval) != '\"')
2961 int n = cstring_length (tval) - 1;
2963 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2968 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2971 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2975 cstring otval = tval;
2976 tval = cstring_prefix (tval, size_fromInt (n));
2977 cstring_free (otval);
2981 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2982 DPRINTF (("val = %s", val));
2983 cstring_free (tval);
2984 cstring_free (oval);
2991 llassert (cstring_isDefined (val));
2993 if (cstring_length (val) == 0)
2996 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2998 else if (cstring_lastChar (val) != CONNECTCHAR)
3000 val = cstring_appendChar (val, CONNECTCHAR);
3010 ; /* Okay not handle everything in this switch */
3014 if (cstring_length (val) >= 1
3015 && cstring_firstChar (val) == '\"')
3017 llerror_flagWarning (message
3018 ("setting %s to string beginning with \". You probably "
3019 "don't meant to have the \"'s.",
3020 flagcode_unparse (flag)));
3023 gc.strings[index] = val;
3026 static /*@exposed@*/ cstring
3027 context_exposeString (flagcode flag)
3029 int index = flagcode_stringIndex (flag);
3031 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3032 return (gc.strings[index]);
3036 context_getString (flagcode flag)
3038 return (context_exposeString (flag));
3042 context_resetErrors (void)
3047 void context_initMod (void)
3048 /*@globals undef gc; @*/
3050 gc.kind = CX_GLOBAL;
3052 gc.savekind = CX_ERROR;
3053 gc.savecont.glob = FALSE;
3055 gc.instandardlib = FALSE;
3058 gc.linesprocessed = 0;
3059 gc.speclinesprocessed = 0;
3060 gc.insuppressregion = FALSE;
3061 gc.macroMissingParams = FALSE;
3062 gc.preprocessing = FALSE;
3063 gc.incommandline = FALSE;
3064 gc.mc = macrocache_create ();
3066 gc.maxmods = DEFAULTMAXMODS;
3067 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3069 gc.library = FLG_ANSILIB;
3071 gc.locstack = filelocStack_new ();
3072 gc.modrecs = sRefSetList_undefined;
3073 gc.anyExports = FALSE;
3075 gc.ftab = fileTable_create ();
3076 gc.msgLog = messageLog_new ();
3077 gc.inimport = FALSE;
3078 gc.inDerivedFile = FALSE;
3079 gc.inheader = FALSE;
3080 gc.markers = flagMarkerList_new ();
3081 gc.cont.glob = TRUE;
3082 gc.showfunction = FALSE;
3083 gc.msgAnnote = cstring_undefined;
3084 gc.aliasAnnote = sRef_undefined;
3085 gc.aliasAnnoteAls = sRef_undefined;
3086 gc.boolType = ctype_bool;
3087 gc.mods = sRefSet_new ();
3089 gc.saveloc = fileloc_undefined;
3091 gc.inmacrocache = FALSE;
3092 gc.inclause = NOCLAUSE;
3093 gc.clauses = clauseStack_new ();
3094 gc.globs = globSet_new ();
3095 gc.nacct = typeIdSet_emptySet ();
3096 gc.acct = typeIdSet_emptySet ();
3097 gc.facct = typeIdSet_emptySet ();
3098 gc.savedFlags = FALSE;
3099 gc.pushloc = fileloc_undefined;
3100 gc.protectVars = FALSE;
3101 gc.justpopped = FALSE;
3102 gc.isNullGuarded = NO;
3103 gc.globs_used = globSet_undefined;
3107 gc.setGlobally[code] = FALSE;
3108 gc.setLocally[code] = FALSE;
3114 context_resetAllFlags ();
3116 assertSet (gc.flags); /* Can't use global in defines */
3117 assertSet (gc.saveflags);
3118 assertSet (gc.values);
3119 assertSet (gc.strings);
3121 conext_resetAllCounters ();
3122 assertSet (gc.counters);
3124 context_setMode (DEFAULT_MODE);
3126 gc.stateTable = metaStateTable_create ();
3127 gc.annotTable = annotationTable_create ();
3129 gc.inFunctionHeader = FALSE;
3131 DPRINTF (("Annotations: \n%s",
3132 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3133 DPRINTF (("State: \n%s",
3134 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3139 context_typeofZero (void)
3141 ctype ct = ctype_int;
3143 if (context_getFlag (FLG_ZEROPTR))
3145 ct = ctype_makeConj (ct, ctype_voidPointer);
3148 if (context_getFlag (FLG_ZEROBOOL)) {
3149 ct = ctype_makeConj (ct, ctype_bool);
3156 context_typeofOne (void)
3158 ctype ct = ctype_int;
3160 /* 1 is on longer a bool (was before 2.4)
3161 if (!context_getFlag (FLG_ABSTRACTBOOL))
3163 ct = ctype_makeConj (ct, ctype_bool);
3171 context_unparse (void)
3178 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3181 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3184 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3187 s = message ("Inner Context [%d] : %q",
3189 fileloc_unparse (g_currentloc));
3192 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3193 uentry_unparse (gc.cont.fcn),
3194 fileloc_unparse (g_currentloc),
3195 typeIdSet_unparse (gc.acct),
3196 sRefSet_unparse (gc.mods));
3199 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3201 case CX_UNKNOWNMACRO:
3202 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3205 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3208 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3211 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3213 case CX_FCNDECLARATION:
3214 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3217 s = message ("Un-unparseable context: %d", (int) gc.kind);
3221 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3226 context_currentFunctionType (void)
3228 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3230 return (uentry_getType (gc.cont.fcn));
3232 else if (gc.kind == CX_INNER)
3234 llcontbuglit ("context_currentFunctionType: inner context");
3235 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3236 return (context_currentFunctionType ());
3240 llcontbuglit ("context_currentFunctionType: not in function");
3241 return (ctype_undefined);
3246 context_enterInnerContext (void)
3248 if (context_getFlag (FLG_GRAMMAR))
3250 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3253 if (gc.kind == CX_GLOBAL)
3258 else if (gc.kind == CX_INNER)
3267 usymtab_enterScope ();
3268 pushClause (NOCLAUSE);
3272 context_exitInnerPlain (void) /*@modifies gc;@*/
3274 context_exitInner (exprNode_undefined);
3278 context_exitInner (exprNode exp)
3280 if (context_getFlag (FLG_GRAMMAR))
3282 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3285 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3286 ("inclause = %s", clause_nameTaken (gc.inclause)));
3288 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3289 gc.inclause = topClause (gc.clauses);
3291 if (gc.kind == CX_INNER)
3293 if (--gc.cont.cdepth == 0)
3295 gc.kind = CX_GLOBAL;
3296 gc.cont.glob = TRUE;
3301 if (gc.kind == CX_GLOBAL)
3303 llcontbuglit ("Attempt to exit global context");
3308 usymtab_exitScope (exp);
3313 context_enterStructInnerContext (void)
3315 if (context_getFlag (FLG_GRAMMAR))
3317 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3320 if (gc.kind == CX_GLOBAL)
3325 else if (gc.kind == CX_INNER)
3334 usymtab_enterScope ();
3336 if (context_getFlag (FLG_GRAMMAR))
3338 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3343 context_exitStructInnerContext (void)
3345 if (context_getFlag (FLG_GRAMMAR))
3347 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3350 if (gc.kind == CX_INNER)
3352 if (gc.cont.cdepth <= 0)
3354 llcontbuglit ("Attempt to exit inner context with no depth");
3355 gc.kind = CX_GLOBAL;
3356 gc.cont.glob = TRUE;
3362 if (gc.cont.cdepth == 0)
3364 gc.kind = CX_GLOBAL;
3365 gc.cont.glob = TRUE;
3371 if (gc.kind == CX_GLOBAL)
3373 llcontbuglit ("Attempt to exit global context");
3378 usymtab_exitScope (exprNode_undefined);
3380 if (context_getFlag (FLG_GRAMMAR))
3382 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3387 context_exitInnerSafe (void)
3389 if (context_getFlag (FLG_GRAMMAR))
3391 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3394 if (gc.kind == CX_INNER)
3396 if (--gc.cont.cdepth <= 0)
3401 else if (gc.kind == CX_GLOBAL)
3403 llcontbuglit ("Attempt to exit global context");
3408 if (usymtab_inDeepScope ())
3410 usymtab_exitScope (exprNode_undefined);
3416 void setModuleAccess (void)
3418 gc.facct = typeIdSet_emptySet ();
3420 if (fileId_isValid (currentFile ()))
3422 cstring baseName = fileloc_getBase (g_currentloc);
3424 if (context_getFlag (FLG_ACCESSFILE))
3426 if (usymtab_existsType (baseName))
3428 gc.facct = typeIdSet_insert (gc.facct,
3429 usymtab_getTypeId (baseName));
3437 if (context_getFlag (FLG_ACCESSMODULE))
3440 bool hasaccess = FALSE;
3442 for (i = 0; i < gc.nmods; i++)
3444 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3446 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3455 gc.inheader = fileId_isHeader (currentFile ());
3459 llcontbuglit ("Current file not defined\n");
3460 gc.facct = typeIdSet_emptySet ();
3462 gc.inheader = FALSE;
3465 /* 17 Jan 1995: forgot to clear nacct */
3467 gc.nacct = typeIdSet_emptySet ();
3471 context_enterFileAux (void)
3477 context_enterFile (void)
3479 context_enterFileAux ();
3480 usymtab_enterFile ();
3484 context_enterMacroFile (void)
3486 context_enterFileAux ();
3490 context_inFunction (void)
3492 kcontext ck = gc.kind;
3494 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3498 context_inFunctionLike (void)
3500 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3501 || gc.kind == CX_FCNDECLARATION
3502 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3506 context_inRealFunction (void)
3508 kcontext ck = gc.kind;
3510 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3514 context_processAllMacros (void)
3516 usymtab_enterFile ();
3518 gc.inmacrocache = TRUE;
3519 macrocache_processUndefinedElements (gc.mc);
3521 usymtab_exitFile ();
3523 gc.inmacrocache = FALSE;
3524 macrocache_finalize ();
3528 ** this happens once at the end of each C file
3530 ** check each Macro that was defined in current file.c or current file.h
3535 context_processMacros (void)
3537 if (fileId_isValid (currentFile ()))
3540 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3542 gc.inmacrocache = TRUE;
3544 DPRINTF (("Processing macros: %s", cbase));
3545 lastfl = macrocache_processFileElements (gc.mc, cbase);
3546 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3548 cstring_free (cbase);
3550 if (fileloc_isDefined (lastfl))
3552 g_currentloc = fileloc_update (g_currentloc, lastfl);
3556 gc.inmacrocache = FALSE;
3561 context_processingMacros (void)
3563 return (gc.inmacrocache);
3567 context_exitCFile (void)
3569 if (gc.kind != CX_GLOBAL)
3572 (cstring_makeLiteral ("File ended outside global scope"));
3575 if (gc.insuppressregion)
3577 /* gack...don't reverse the order of these lines! ;-> */
3578 gc.insuppressregion = FALSE;
3579 llerrorlit (FLG_SYNTAX,
3580 "File ended in ignore errors region, "
3581 "possible missing /*@end*/");
3584 /* fix up parse errors */
3586 while (!usymtab_inFileScope ())
3588 usymtab_quietExitScope (g_currentloc);
3592 ** Clear the file-specific modifies information.
3595 sRefSetList_elements (gc.modrecs, mods)
3597 sRefSet_clearStatics (mods);
3598 } end_sRefSetList_elements ;
3600 sRefSetList_clear (gc.modrecs);
3602 context_processMacros ();
3605 usymtab_exitFile ();
3607 gc.inDerivedFile = FALSE;
3608 filelocStack_clear (gc.locstack);
3610 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3612 gc.cont.glob = TRUE;
3616 context_restoreFlagSettings ();
3617 gc.savedFlags = FALSE;
3621 DPRINTF (("After exiting file: "));
3622 usymtab_printAll ();
3627 context_exitMacroCache (void)
3629 if (gc.kind != CX_GLOBAL)
3631 if (context_inMacro ())
3632 /* this is okay, file could end without newline in macro */
3634 DPRINTF (("Still in macro: %s",
3635 context_unparse ()));
3636 context_exitFunction ();
3640 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3641 context_unparse ()));
3642 gc.kind = CX_GLOBAL;
3647 ** no longer valid here
3648 ** if (gc.insuppressregion)
3650 ** gc.insuppressregion = FALSE;
3651 ** llerror ("File ended in ignore errors region, possible missing @");
3655 gc.cont.glob = TRUE;
3659 context_saveLocation (void)
3661 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3662 fileloc_free (gc.saveloc);
3663 gc.saveloc = fileloc_copy (g_currentloc);
3667 context_getSaveLocation (void)
3669 fileloc fl = gc.saveloc;
3670 gc.saveloc = fileloc_undefined;
3674 /*@observer@*/ cstring
3675 context_inFunctionName (void)
3677 if (gc.kind == CX_FUNCTION
3678 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3679 || gc.kind == CX_MACROCONST
3680 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3682 return (uentry_rawName (gc.cont.fcn));
3686 llcontbuglit ("context_inFunctionName: not in function");
3687 return (cstring_undefined);
3692 context_userSetFlag (flagcode f, bool b)
3694 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3696 if (f == FLG_NEVERINCLUDE && b)
3698 if (gc.flags[FLG_EXPORTHEADER])
3701 (cstring_makeLiteral
3702 ("setting +neverinclude after +exportheader. "
3703 "Turning off exportheader, since headers are not checked "
3704 "when +neverinclude is used."));
3706 gc.flags[FLG_EXPORTHEADER] = FALSE;
3711 if (f == FLG_EXPORTHEADER && b)
3713 if (gc.flags[FLG_NEVERINCLUDE])
3716 (cstring_makeLiteral
3717 ("setting +exportheader after +neverinclude. "
3718 "Not setting exportheader, since headers are not checked "
3719 "when +neverinclude is used."));
3720 gc.flags[FLG_EXPORTHEADER] = FALSE;
3726 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3728 bool lastsetting = context_getFlag (f);
3730 if (bool_equal (lastsetting, b)
3731 && !flagcode_isSpecialFlag (f)
3732 && !flagcode_isIdemFlag (f)
3733 && !flagcode_hasArgument (f))
3736 (message ("setting %s%s redundant with current value",
3737 cstring_makeLiteralTemp (b ? "+" : "-"),
3738 flagcode_unparse (f)));
3742 if (flagcode_isWarnUseFlag (f) && b)
3744 if (!context_getFlag (FLG_WARNUSE))
3747 (message ("flag +%s is canceled by -warnuse",
3748 flagcode_unparse (f)));
3753 if (flagcode_isLibraryFlag (f))
3755 if (gc.library != FLG_ANSILIB
3759 (message ("selecting library %s after library %s was "
3760 "selected (only one library may be used)",
3761 flagcode_unparse (f),
3762 flagcode_unparse (gc.library)));
3765 if (f == FLG_UNIXLIB)
3767 if (context_getFlag (FLG_WARNUNIXLIB))
3770 (cstring_makeLiteral
3771 ("selecting unix library. Unix library is "
3772 "ad hoc addition to POSIX library. Recommend "
3773 "use +posixlib to select POSIX library instead. "
3774 "Use -warnunixlib to suppress this message."));
3781 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3785 ("setting +%s will not produce warnings with -namechecks. "
3786 "Must set +namechecks also.",
3787 flagcode_unparse (f)));
3790 gc.setGlobally[f] = TRUE;
3791 context_setFlag (f, b, g_currentloc);
3795 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3799 context_saveFlagSettings ();
3802 if (ynm_isOff (set))
3804 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3806 else if (ynm_isOn (set))
3808 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3809 gc.setLocally[f] = TRUE;
3813 context_restoreFlag (f, loc);
3818 context_restoreFlag (flagcode f, fileloc loc)
3824 message ("Attempt to restore flag %s when no file scope flags "
3826 flagcode_unparse (f)),
3831 context_addFlagMarker (f, MAYBE, loc);
3832 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3838 context_setFlag (flagcode f, bool b, fileloc loc)
3840 context_setFlagAux (f, b, FALSE, FALSE, loc);
3844 context_setFlagTemp (flagcode f, bool b)
3846 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3851 # define DOSET(ff,b) \
3852 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3853 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3854 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3855 gc.flags[ff] = b; } while (FALSE)
3858 context_setFlagAux (flagcode f, bool b, bool inFile,
3859 /*@unused@*/ bool isRestore, fileloc loc)
3861 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3864 ** Removed test for special flags.
3867 if (flagcode_isIdemFlag (f))
3876 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3878 if (b) /* Turing higher level on, turns on all lower levels */
3882 case FLG_ITS4MOSTRISKY:
3883 DOSET (FLG_ITS4VERYRISKY, b);
3885 case FLG_ITS4VERYRISKY:
3886 DOSET (FLG_ITS4RISKY, b);
3889 DOSET (FLG_ITS4MODERATERISK, b);
3891 case FLG_ITS4MODERATERISK:
3892 DOSET (FLG_ITS4LOWRISK, b);
3894 case FLG_ITS4LOWRISK:
3899 else /* Turning level off, turns off all higher levels */
3903 case FLG_ITS4LOWRISK:
3904 DOSET (FLG_ITS4MODERATERISK, b);
3906 case FLG_ITS4MODERATERISK:
3907 DOSET (FLG_ITS4RISKY, b);
3910 DOSET (FLG_ITS4VERYRISKY, b);
3912 case FLG_ITS4VERYRISKY:
3913 DOSET (FLG_ITS4MOSTRISKY, b);
3915 case FLG_ITS4MOSTRISKY:
3924 case FLG_MESSAGESTREAMSTDOUT:
3925 g_messagestream = stdout;
3927 case FLG_MESSAGESTREAMSTDERR:
3928 g_messagestream = stderr;
3930 case FLG_WARNINGSTREAMSTDOUT:
3931 g_warningstream = stdout;
3933 case FLG_WARNINGSTREAMSTDERR:
3934 g_warningstream = stderr;
3936 case FLG_ERRORSTREAMSTDOUT:
3937 g_errorstream = stdout;
3939 case FLG_ERRORSTREAMSTDERR:
3940 g_errorstream = stderr;
3943 DOSET (FLG_ALLEMPTY, b);
3944 DOSET (FLG_IFEMPTY, b);
3945 DOSET (FLG_WHILEEMPTY, b);
3946 DOSET (FLG_FOREMPTY, b);
3949 DOSET (FLG_PREDBOOL, b);
3950 DOSET (FLG_PREDBOOLINT, b);
3951 DOSET (FLG_PREDBOOLPTR, b);
3952 DOSET (FLG_PREDBOOLOTHERS, b);
3955 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3956 DOSET (FLG_CHECKEDGLOBALIAS, b);
3957 DOSET (FLG_CHECKMODGLOBALIAS, b);
3958 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3961 DOSET (FLG_ALLBLOCK, b);
3962 DOSET (FLG_IFBLOCK, b);
3963 DOSET (FLG_WHILEBLOCK, b);
3964 DOSET (FLG_FORBLOCK, b);
3978 DOSET (FLG_GRAMMAR, b);
3980 case FLG_CODEIMPONLY:
3981 DOSET (FLG_CODEIMPONLY, b);
3982 DOSET (FLG_GLOBIMPONLY, b);
3983 DOSET (FLG_RETIMPONLY, b);
3984 DOSET (FLG_STRUCTIMPONLY, b);
3986 case FLG_SPECALLIMPONLY:
3987 DOSET (FLG_SPECALLIMPONLY, b);
3988 DOSET (FLG_SPECGLOBIMPONLY, b);
3989 DOSET (FLG_SPECRETIMPONLY, b);
3990 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3992 case FLG_ALLIMPONLY:
3993 DOSET (FLG_ALLIMPONLY, b);
3994 DOSET (FLG_GLOBIMPONLY, b);
3995 DOSET (FLG_RETIMPONLY, b);
3996 DOSET (FLG_STRUCTIMPONLY, b);
3997 DOSET (FLG_SPECGLOBIMPONLY, b);
3998 DOSET (FLG_SPECRETIMPONLY, b);
3999 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4001 case FLG_ANSI89LIMITS:
4002 DOSET (FLG_ANSI89LIMITS, b);
4003 DOSET (FLG_CONTROLNESTDEPTH, b);
4004 DOSET (FLG_STRINGLITERALLEN, b);
4005 DOSET (FLG_INCLUDENEST, b);
4006 DOSET (FLG_NUMSTRUCTFIELDS, b);
4007 DOSET (FLG_NUMENUMMEMBERS, b);
4011 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4012 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4013 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4014 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4015 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4016 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4017 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4020 case FLG_ISO99LIMITS:
4021 DOSET (FLG_ISO99LIMITS, b);
4022 DOSET (FLG_CONTROLNESTDEPTH, b);
4023 DOSET (FLG_STRINGLITERALLEN, b);
4024 DOSET (FLG_INCLUDENEST, b);
4025 DOSET (FLG_NUMSTRUCTFIELDS, b);
4026 DOSET (FLG_NUMENUMMEMBERS, b);
4030 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4031 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4032 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4033 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4034 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4035 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4036 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4039 case FLG_EXTERNALNAMELEN:
4040 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4041 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4043 case FLG_INTERNALNAMELEN:
4044 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4045 DOSET (FLG_INTERNALNAMELEN, TRUE);
4047 case FLG_EXTERNALNAMECASEINSENSITIVE:
4048 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4050 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4052 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4053 context_setValue (FLG_EXTERNALNAMELEN, 0);
4056 case FLG_INTERNALNAMECASEINSENSITIVE:
4057 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4059 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4061 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4062 context_setValue (FLG_INTERNALNAMELEN, 0);
4065 case FLG_INTERNALNAMELOOKALIKE:
4066 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4068 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4070 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4071 context_setValue (FLG_INTERNALNAMELEN, 0);
4075 DOSET (FLG_MODNOMODS, b);
4076 DOSET (FLG_MODGLOBSUNSPEC, b);
4077 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4080 DOSET (FLG_EXPORTVAR, b);
4081 DOSET (FLG_EXPORTFCN, b);
4082 DOSET (FLG_EXPORTTYPE, b);
4083 DOSET (FLG_EXPORTMACRO, b);
4084 DOSET (FLG_EXPORTCONST, b);
4085 gc.anyExports = TRUE;
4088 DOSET (FLG_RETEXPOSE, b);
4089 DOSET (FLG_ASSIGNEXPOSE, b);
4090 DOSET (FLG_CASTEXPOSE, b);
4093 DOSET (FLG_RETVALBOOL, b);
4094 DOSET (FLG_RETVALINT, b);
4095 DOSET (FLG_RETVALOTHER, b);
4100 DOSET (FLG_EXPORTLOCAL, FALSE);
4101 DOSET (FLG_DECLUNDEF, FALSE);
4102 DOSET (FLG_SPECUNDEF, FALSE);
4103 DOSET (FLG_TOPUNUSED, FALSE);
4107 DOSET (FLG_LOOPLOOPBREAK, b);
4108 DOSET (FLG_LOOPSWITCHBREAK, b);
4109 DOSET (FLG_SWITCHLOOPBREAK, b);
4110 DOSET (FLG_SWITCHSWITCHBREAK, b);
4111 DOSET (FLG_LOOPLOOPCONTINUE, b);
4112 DOSET (FLG_DEEPBREAK, b);
4115 DOSET (FLG_FORLOOPEXEC, b);
4116 DOSET (FLG_WHILELOOPEXEC, b);
4117 DOSET (FLG_ITERLOOPEXEC, b);
4120 DOSET (FLG_ACCESSMODULE, b);
4121 DOSET (FLG_ACCESSFILE, b);
4122 DOSET (FLG_ACCESSCZECH, b);
4125 DOSET (FLG_ALLMACROS, b);
4126 DOSET (FLG_FCNMACROS, b);
4127 DOSET (FLG_CONSTMACROS, b);
4130 DOSET (FLG_BOUNDSREAD, b);
4131 DOSET (FLG_BOUNDSWRITE, b);
4134 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4135 DOSET (FLG_CZECHFUNCTIONS, b);
4136 DOSET (FLG_CZECHVARS, b);
4137 DOSET (FLG_CZECHCONSTANTS, b);
4138 DOSET (FLG_CZECHTYPES, b);
4141 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4142 DOSET (FLG_SLOVAKFUNCTIONS, b);
4143 DOSET (FLG_SLOVAKVARS, b);
4144 DOSET (FLG_SLOVAKCONSTANTS, b);
4145 DOSET (FLG_SLOVAKTYPES, b);
4147 case FLG_CZECHOSLOVAK:
4148 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4149 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4150 DOSET (FLG_CZECHOSLOVAKVARS, b);
4151 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4152 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4155 DOSET (FLG_NULLSTATE, b);
4156 DOSET (FLG_NULLDEREF, b);
4157 DOSET (FLG_NULLASSIGN, b);
4158 DOSET (FLG_NULLPASS, b);
4159 DOSET (FLG_NULLRET, b);
4162 DOSET (FLG_MUSTFREEONLY, b);
4163 DOSET (FLG_MUSTFREEFRESH, b);
4166 DOSET (FLG_NULLSTATE, b);
4167 DOSET (FLG_NULLDEREF, b);
4168 DOSET (FLG_NULLASSIGN, b);
4169 DOSET (FLG_NULLPASS, b);
4170 DOSET (FLG_NULLRET, b);
4171 DOSET (FLG_COMPDEF, b);
4172 DOSET (FLG_COMPMEMPASS, b);
4173 DOSET (FLG_UNIONDEF, b);
4174 DOSET (FLG_MEMTRANS, b);
4175 DOSET (FLG_USERELEASED, b);
4176 DOSET (FLG_ALIASUNIQUE, b);
4177 DOSET (FLG_MAYALIASUNIQUE, b);
4178 DOSET (FLG_MUSTFREEONLY, b);
4179 DOSET (FLG_MUSTFREEFRESH, b);
4180 DOSET (FLG_MUSTDEFINE, b);
4181 DOSET (FLG_GLOBSTATE, b);
4182 DOSET (FLG_COMPDESTROY, b);
4183 DOSET (FLG_MUSTNOTALIAS, b);
4184 DOSET (FLG_MEMIMPLICIT, b);
4185 DOSET (FLG_BRANCHSTATE, b);
4186 /*@fallthrough@*/ /* also sets memtrans flags */
4188 DOSET (FLG_MEMTRANS, b);
4189 DOSET (FLG_EXPOSETRANS, b);
4190 DOSET (FLG_OBSERVERTRANS, b);
4191 DOSET (FLG_DEPENDENTTRANS, b);
4192 DOSET (FLG_NEWREFTRANS, b);
4193 DOSET (FLG_ONLYTRANS, b);
4194 DOSET (FLG_OWNEDTRANS, b);
4195 DOSET (FLG_FRESHTRANS, b);
4196 DOSET (FLG_SHAREDTRANS, b);
4197 DOSET (FLG_TEMPTRANS, b);
4198 DOSET (FLG_KEPTTRANS, b);
4199 DOSET (FLG_REFCOUNTTRANS, b);
4200 DOSET (FLG_STATICTRANS, b);
4201 DOSET (FLG_UNKNOWNTRANS, b);
4202 DOSET (FLG_KEEPTRANS, b);
4203 DOSET (FLG_IMMEDIATETRANS, b);
4210 if (b && !gc.anyExports
4211 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4212 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4213 || f == FLG_EXPORTCONST
4214 || f == FLG_EXPORTANY))
4216 gc.anyExports = TRUE;
4221 context_maybeSet (flagcode d)
4223 return (gc.flags[d] || gc.setLocally[d]);
4227 context_getFlag (flagcode d)
4229 return (gc.flags[d]);
4233 context_flagOn (flagcode f, fileloc loc)
4235 return (!context_suppressFlagMsg (f, loc));
4238 static void context_saveFlagSettings (void)
4240 gc.savedFlags = TRUE;
4241 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4242 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4245 static void context_restoreFlagSettings (void)
4247 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4248 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4249 gc.savedFlags = FALSE;
4252 void context_setFilename (fileId fid, int lineno)
4253 /*@globals fileloc g_currentloc;@*/
4254 /*@modifies g_currentloc@*/
4256 if (fileId_baseEqual (currentFile (), fid))
4263 fileloc_setColumn (g_currentloc, 0);
4265 if (fileloc_isSpecialFile (g_currentloc))
4267 gc.inDerivedFile = TRUE;
4270 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4272 int maxdepth = context_getValue (FLG_INCLUDENEST);
4274 if (filelocStack_size (gc.locstack) > maxdepth)
4276 int depth = filelocStack_includeDepth (gc.locstack);
4278 if (depth > maxdepth)
4282 message ("Maximum include nesting depth "
4283 "(%d, current depth %d) exceeded",
4286 filelocStack_nextTop (gc.locstack)))
4288 filelocStack_printIncludes (gc.locstack);
4294 g_currentloc = fileloc_create (fid, lineno, 1);
4295 gc.inheader = fileId_isHeader (currentFile ());
4297 context_enterFileAux ();
4301 void context_enterIterDef (/*@observer@*/ uentry le)
4303 context_enterMacro (le);
4304 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4305 gc.kind = CX_ITERDEF;
4308 void context_enterIterEnd (/*@observer@*/ uentry le)
4310 context_enterMacro (le);
4311 gc.kind = CX_ITEREND;
4315 context_destroyMod (void)
4316 /*@globals killed gc@*/
4319 ctype_destroyMod ();
4323 fileTable_free (gc.ftab);
4324 filelocStack_free (gc.locstack);
4326 gc.ftab = fileTable_undefined;
4328 macrocache_free (gc.mc);
4329 sfree (gc.moduleaccess);
4332 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4333 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4336 sRefSetList_free (gc.modrecs);
4338 flagMarkerList_free (gc.markers);
4340 messageLog_free (gc.msgLog);
4342 clauseStack_free (gc.clauses);
4345 cstring_free (gc.msgAnnote);
4346 globSet_free (gc.globs_used);
4347 metaStateTable_free (gc.stateTable);
4348 annotationTable_free (gc.annotTable);
4355 bool context_msgBoolInt (void)
4357 return gc.flags [FLG_BOOLINT];
4360 bool context_msgCharInt (void)
4362 return gc.flags [FLG_CHARINT];
4365 bool context_msgEnumInt (void)
4367 return gc.flags [FLG_ENUMINT];
4370 bool context_msgPointerArith (void)
4372 return gc.flags [FLG_POINTERARITH];
4375 bool context_msgStrictOps (void)
4377 return gc.flags [FLG_STRICTOPS];
4381 bool context_msgLh (void)
4383 return gc.flags [FLG_DOLH];
4387 void context_pushLoc (void)
4389 fileloc_free (gc.pushloc);
4390 gc.pushloc = gc.saveloc;
4391 gc.saveloc = fileloc_undefined;
4394 void context_popLoc (void)
4396 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4399 bool context_inGlobalScope (void)
4401 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4404 bool context_inInnerScope (void)
4406 return (gc.kind == CX_INNER);
4409 void context_setProtectVars (void)
4411 gc.protectVars = TRUE;
4414 bool context_anyErrors (void)
4416 return (gc.numerrors > 0);
4419 void context_hasError (void)
4422 DPRINTF (("num errors: %d", gc.numerrors));
4425 int context_numErrors (void)
4427 return gc.numerrors;
4430 bool context_neednl (void)
4435 void context_setNeednl (void)
4440 int context_getExpect (void)
4442 return (context_getValue (FLG_EXPECT));
4446 int context_getLCLExpect (void)
4448 return (context_getValue (FLG_LCLEXPECT));
4452 int context_getLimit (void)
4454 return (context_getValue (FLG_LIMIT));
4457 bool context_unlimitedMessages (void)
4459 return (context_getLimit () < 0);
4462 void context_releaseVars (void)
4464 llassert (gc.protectVars);
4465 gc.protectVars = FALSE;
4468 void context_sizeofReleaseVars (void)
4470 /* If there is a nested sizeof, this might not hold:
4471 llassert (gc.protectVars);
4474 gc.protectVars = FALSE;
4477 bool context_inProtectVars (void)
4479 return (gc.protectVars);
4482 void context_hideShowscan (void)
4484 gc.flags[FLG_SHOWSCAN] = FALSE;
4487 void context_unhideShowscan (void)
4489 gc.flags[FLG_SHOWSCAN] = TRUE;
4492 bool context_inHeader (void)
4494 return (gc.inheader);
4497 fileTable context_fileTable (void)
4502 cstring context_tmpdir (void)
4504 return (context_getString (FLG_TMPDIR));
4507 messageLog context_messageLog (void)
4512 bool context_inMacroFunction (void)
4514 return (gc.kind == CX_MACROFCN);
4517 bool context_inMacroConstant (void)
4519 return (gc.kind == CX_MACROCONST);
4522 bool context_inUnknownMacro (void)
4524 return (gc.kind == CX_UNKNOWNMACRO);
4527 void context_setShownFunction (void)
4529 gc.showfunction = FALSE;
4532 bool context_doDump (void)
4534 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4537 bool context_doMerge (void)
4539 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4542 cstring context_getDump (void)
4544 return context_getString (FLG_DUMP);
4547 cstring context_getMerge (void)
4549 return context_getString (FLG_MERGE);
4553 bool context_inLCLLib (void)
4555 return (gc.kind == CX_LCLLIB);
4558 bool context_inImport (void)
4560 return (gc.inimport);
4563 void context_enterImport (void)
4568 void context_leaveImport (void)
4570 gc.inimport = FALSE;
4574 bool context_inMacro (void)
4576 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4577 || gc.kind == CX_UNKNOWNMACRO
4578 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4581 bool context_inIterDef (void)
4583 return (gc.kind == CX_ITERDEF);
4586 bool context_inIterEnd (void)
4588 return (gc.kind == CX_ITEREND);
4591 int context_getLinesProcessed (void)
4593 return (gc.linesprocessed);
4596 int context_getSpecLinesProcessed (void)
4598 return (gc.speclinesprocessed);
4602 void context_processedSpecLine (void)
4604 gc.speclinesprocessed++;
4607 void context_resetSpecLines (void)
4609 gc.speclinesprocessed = 0;
4613 bool context_inGlobalContext (void)
4615 return (gc.kind == CX_GLOBAL);
4618 static void context_quietExitScopes (void)
4621 ** Try to restore the global scope (after an error).
4624 while (!usymtab_inFileScope ())
4626 usymtab_quietExitScope (g_currentloc);
4629 gc.cont.glob = TRUE;
4630 gc.kind = CX_GLOBAL;
4633 void context_checkGlobalScope (void)
4635 if (gc.kind != CX_GLOBAL)
4637 if (context_inMacro ())
4639 ; /* evans 2001-10-14: Okay to be in a macro here! */
4643 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4644 context_quietExitScopes ();
4649 void context_setFileId (fileId s)
4651 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4654 bool context_setBoolName (void)
4656 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4660 cstring context_printBoolName (void)
4662 if (context_setBoolName ())
4664 return context_getBoolName ();
4668 return cstring_makeLiteralTemp ("boolean");
4672 cstring context_getBoolName (void)
4674 return (context_getString (FLG_BOOLTYPE));
4677 cstring context_getFalseName (void)
4679 return (context_getString (FLG_BOOLFALSE));
4682 cstring context_getTrueName (void)
4684 return (context_getString (FLG_BOOLTRUE));
4687 cstring context_getLarchPath (void)
4689 return (context_getString (FLG_LARCHPATH));
4692 cstring context_getLCLImportDir (void)
4694 return (context_getString (FLG_LCLIMPORTDIR));
4697 static void context_setJustPopped (void)
4699 gc.justpopped = TRUE;
4702 void context_clearJustPopped (void)
4704 gc.justpopped = FALSE;
4707 bool context_justPopped (void)
4709 return (gc.justpopped);
4712 void context_setMacroMissingParams (void)
4714 gc.macroMissingParams = TRUE;
4717 void context_resetMacroMissingParams (void)
4719 gc.macroMissingParams = FALSE;
4722 bool context_isMacroMissingParams (void)
4724 return (gc.macroMissingParams);
4727 void context_showFilelocStack (void)
4729 filelocStack_printIncludes (gc.locstack);
4732 metaStateTable context_getMetaStateTable (void)
4734 return gc.stateTable;
4737 metaStateInfo context_lookupMetaStateInfo (cstring key)
4739 return metaStateTable_lookup (gc.stateTable, key);
4742 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4744 annotationInfo ainfo;
4746 ainfo = annotationTable_lookup (gc.annotTable, annot);
4751 void context_addAnnotation (annotationInfo ainfo)
4753 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4757 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4758 annotationInfo_getLoc (ainfo));
4760 annotationInfo_free (ainfo);
4764 annotationTable_insert (gc.annotTable, ainfo);
4768 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4770 if (metaStateTable_contains (gc.stateTable, mname))
4774 message ("Duplicate metastate declaration: %s", mname),
4775 metaStateInfo_getLoc (msinfo));
4776 cstring_free (mname);
4777 metaStateInfo_free (msinfo);
4781 DPRINTF (("Adding meta state: %s", mname));
4782 metaStateTable_insert (gc.stateTable, mname, msinfo);
4786 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4788 if (metaStateTable_size (gc.stateTable) > 0)
4790 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4791 /*@i32 should use smaller value... */
4792 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4794 metaStateTable_elements (gc.stateTable, msname, msi)
4796 mtContextNode context = metaStateInfo_getContext (msi);
4798 if (mtContextNode_matchesRefStrict (context, s))
4800 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4801 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4805 cstring_copy (metaStateInfo_getName (msi)),
4806 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4807 stateInfo_copy (sinfo)));
4811 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4814 end_metaStateTable_elements ;
4816 stateInfo_free (sinfo);
4817 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4822 stateInfo_free (sinfo);
4823 return valueTable_undefined;
4827 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4829 if (metaStateTable_size (gc.stateTable) > 0)
4831 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4832 /*@i32 should use smaller value... */
4834 metaStateTable_elements (gc.stateTable, msname, msi)
4836 /*@i23 only add global...*/
4837 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4838 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4840 valueTable_insert (res,
4841 cstring_copy (metaStateInfo_getName (msi)),
4842 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4843 stateInfo_copy (sinfo)));
4845 end_metaStateTable_elements ;
4847 stateInfo_free (sinfo);
4848 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4853 stateInfo_free (sinfo);
4854 return valueTable_undefined;
4859 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4863 static ctype lastStruct;
4865 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4871 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4877 /*@unused@*/ static int sInfoNum = 0;
4881 /*@unused@*/ uentry ue;
4882 /*@unused@*/ sRef s;
4886 /*@unused@*/ ctype ct;
4887 /*@unused@*/ constraintList inv;
4888 /*@unused@*/ int ngetUe;
4889 /*@unused@*/ struct getUe * t ;
4893 static struct sInfo globalStructInfo;
4896 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4897 stable release of splint. I coomented them out so that they won't break anything
4898 but didn't delete them because they will be fixed and included later
4902 void setGlobalStructInfo(ctype ct, constraintList list)
4907 f = ctype_getFields (ct);
4909 if (constraintList_isDefined(list) )
4911 globalStructInfo.ct = ct;
4912 globalStructInfo.inv = list;
4914 globalStructInfo.ngetUe = 0;
4916 / *abstraction violation fix it * /
4917 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4919 globalStructInfo.ngetUe = f->nelements;
4923 uentryList_elements(f, ue)
4925 globalStructInfo.t[i].ue = ue;
4926 globalStructInfo.t[i].s = uentry_getSref(ue);
4927 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4928 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4933 end_uentryList_elements;
4939 bool hasInvariants (ctype ct) /*@*/
4941 if ( ctype_sameName(globalStructInfo.ct, ct) )