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_MACROUNDEF, FLG_RELAXQUALS,
1039 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1040 FLG_CHECKSTRICTGLOBALIAS,
1041 FLG_CHECKEDGLOBALIAS,
1042 FLG_CHECKMODGLOBALIAS,
1043 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1044 FLG_UNSIGNEDCOMPARE,
1045 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1047 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1048 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1049 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1050 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1051 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1054 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1055 FLG_MACROSTMT, FLG_MACROPARENS,
1058 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1059 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1064 /* memchecks flags */
1066 FLG_NULLSTATE, FLG_NULLASSIGN,
1067 FLG_NULLPASS, FLG_NULLRET,
1069 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1072 /* memtrans flags */
1091 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1094 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1095 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1098 FLG_STATETRANSFER, FLG_STATEMERGE,
1099 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1101 FLG_IMPCHECKEDSPECGLOBALS,
1102 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1103 FLG_IFEMPTY, FLG_REALCOMPARE,
1104 FLG_BOOLOPS, FLG_PTRNEGATE,
1106 FLG_SHIFTIMPLEMENTATION,
1107 FLG_BUFFEROVERFLOWHIGH,
1109 FLG_LITERALOVERSIZE,
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_LITERALOVERSIZE,
1144 else if (cstring_equalLit (s, "checks"))
1146 flagcode modeflags[] =
1148 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1149 FLG_STATETRANSFER, FLG_STATEMERGE,
1150 FLG_CHECKSTRICTGLOBALIAS,
1151 FLG_CHECKEDGLOBALIAS,
1152 FLG_CHECKMODGLOBALIAS,
1153 FLG_UNCHECKEDGLOBALIAS,
1155 FLG_STRINGLITNOROOM,
1156 FLG_STRINGLITNOROOMFINALNULL,
1157 FLG_STRINGLITSMALLER,
1158 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1159 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1160 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1161 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1162 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1163 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1164 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1165 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1166 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1167 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1168 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1169 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1170 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1171 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1178 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1182 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1184 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1185 FLG_EVALORDER, FLG_USEDEF,
1188 FLG_LITERALOVERSIZE, FLG_LITERALUNDERSIZE,
1190 /* warn use flags */
1191 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1192 FLG_BUFFEROVERFLOWHIGH,
1194 /* memchecks flags */
1196 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1197 FLG_NULLPASS, FLG_NULLRET,
1199 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1201 /* memtrans flags */
1215 FLG_STATICINITTRANS,
1216 FLG_UNKNOWNINITTRANS,
1219 FLG_ONLYUNQGLOBALTRANS,
1220 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1223 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1224 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1227 FLG_NULLPOINTERARITH,
1228 FLG_SHADOW, FLG_DEPARRAYS,
1229 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1230 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1231 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1232 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1233 FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES,
1234 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1235 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1236 FLG_SHIFTIMPLEMENTATION,
1237 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1242 else if (cstring_equalLit (s, "strict"))
1244 flagcode modeflags[] =
1246 FLG_CHECKSTRICTGLOBALIAS,
1247 FLG_CHECKEDGLOBALIAS,
1248 FLG_CHECKMODGLOBALIAS,
1249 FLG_UNCHECKEDGLOBALIAS,
1253 FLG_STRINGLITNOROOM,
1254 FLG_STRINGLITNOROOMFINALNULL,
1255 FLG_STRINGLITSMALLER,
1256 FLG_STATETRANSFER, FLG_STATEMERGE,
1257 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1258 FLG_ALLGLOBALS, FLG_IMPTYPE,
1259 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1260 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1261 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1262 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1265 FLG_ONLYUNQGLOBALTRANS,
1266 FLG_GLOBALSIMPMODIFIESNOTHING,
1267 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1268 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1269 FLG_USEALLGLOBS, FLG_RETALIAS,
1270 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1271 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1272 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1274 FLG_EXPORTITER, FLG_EXPORTCONST,
1275 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1276 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1278 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1280 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1281 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1282 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1283 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1284 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1285 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1286 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1287 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1289 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1292 FLG_MACROREDEF, FLG_MACROEMPTY,
1293 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1295 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1297 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1298 FLG_MODOBSERVERUNCON,
1303 /* warn use flags */
1304 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1305 FLG_BUFFEROVERFLOWHIGH,
1306 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1308 /* memchecks flags */
1309 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1310 FLG_NULLPASS, FLG_NULLRET,
1312 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1314 FLG_LITERALOVERSIZE, FLG_LITERALUNDERSIZE,
1316 /* memtrans flags */
1332 FLG_STATICINITTRANS,
1333 FLG_UNKNOWNINITTRANS,
1335 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1338 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1339 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1343 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1345 FLG_SHADOW, FLG_DEPARRAYS,
1346 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1347 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1348 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1349 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1350 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1351 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1352 FLG_IMPCHECKEDSTRICTSTATICS,
1353 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1354 FLG_IMPCHECKMODINTERNALS,
1355 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1356 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1357 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1358 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1359 FLG_CONTROLNESTDEPTH,
1360 FLG_FORBLOCK, FLG_WHILEBLOCK,
1361 FLG_FOREMPTY, FLG_WHILEEMPTY,
1362 FLG_IFEMPTY, FLG_IFBLOCK,
1364 FLG_REALCOMPARE, FLG_BOOLOPS,
1365 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1368 FLG_SHIFTIMPLEMENTATION,
1370 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1378 llcontbug (message ("context_setMode: bad mode: %s", s));
1383 context_isSpecialFile (cstring fname)
1385 cstring ext = fileLib_getExtension (fname);
1387 return (cstring_equalLit (ext, ".y")
1388 || cstring_equalLit (ext, ".l")
1389 || cstring_equalLit (fname, "lex.yy.c"));
1393 context_isSystemDir (cstring dir)
1395 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1396 cstring savedir = thisdir;
1397 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1399 if (cstring_isDefined (nextdir))
1401 /*@access cstring@*/
1402 *nextdir = '\0'; /* closes thisdir */
1404 /*@noaccess cstring@*/
1407 /* 2001-09-09: added thisdir[0] != '\0'
1408 ** herbert: don't compare with an empty name!
1409 ** should return false for empty directory path
1412 while (!cstring_isEmpty (thisdir))
1414 DPRINTF (("Test: %s / %s", dir, thisdir));
1416 if (osd_equalCanonicalPrefix (dir, thisdir))
1418 cstring_free (savedir);
1422 if (cstring_isDefined (nextdir))
1425 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1427 if (cstring_isDefined (nextdir))
1429 /*@access cstring@*/
1432 /*@noaccess cstring@*/
1441 DPRINTF (("Returns FALSE"));
1442 cstring_free (savedir);
1447 context_addFileAccessType (typeId t)
1451 if (context_inFunctionLike ())
1453 gc.acct = typeIdSet_insert (gc.acct, t);
1456 gc.facct = typeIdSet_insert (gc.facct, t);
1458 base = fileloc_getBase (g_currentloc);
1459 insertModuleAccess (base, t);
1460 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1461 typeIdSet_unparse (gc.acct)));
1465 context_removeFileAccessType (typeId t)
1467 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1468 || gc.kind == CX_UNKNOWNMACRO)
1470 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1473 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1474 gc.nacct = typeIdSet_insert (gc.nacct, t);
1477 void context_enterFunctionHeader (void)
1479 if (context_getFlag (FLG_GRAMMAR))
1481 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1484 if (gc.kind != CX_GLOBAL)
1486 llparseerror (cstring_makeLiteral
1487 ("Likely parse error. Function header outside global context."));
1491 llassert (gc.kind == CX_GLOBAL);
1492 DPRINTF (("Enter function header!"));
1493 gc.inFunctionHeader = TRUE;
1497 void context_exitFunctionHeader (void)
1499 if (context_getFlag (FLG_GRAMMAR))
1501 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1504 DPRINTF (("Exit function header!"));
1505 gc.inFunctionHeader = FALSE;
1508 bool context_inFunctionHeader (void)
1510 return (gc.inFunctionHeader);
1513 void context_enterFunctionDeclaration (uentry e)
1515 if (context_getFlag (FLG_GRAMMAR))
1517 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1520 DPRINTF (("Enter function decl"));
1521 llassert (gc.savekind == CX_ERROR);
1522 gc.savekind = gc.kind;
1523 gc.savecont = gc.cont;
1524 gc.kind = CX_FCNDECLARATION;
1528 void context_exitFunctionDeclaration (void)
1530 if (context_getFlag (FLG_GRAMMAR))
1532 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1535 DPRINTF (("Exit function decl"));
1536 llassert (gc.savekind != CX_ERROR);
1537 llassert (gc.kind == CX_FCNDECLARATION);
1538 gc.kind = gc.savekind;
1539 gc.cont = gc.savecont;
1541 gc.savekind = CX_ERROR;
1543 if (context_getFlag (FLG_GRAMMAR))
1545 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1549 bool context_inFunctionDeclaration (void)
1551 return (gc.kind == CX_FCNDECLARATION);
1556 context_enterMacro (/*@observer@*/ uentry e)
1558 context_enterFunction (e);
1559 gc.kind = CX_MACROFCN;
1563 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1565 llassert (uentry_isFunction (e));
1566 context_enterFunction (e);
1567 gc.kind = CX_UNKNOWNMACRO;
1570 void context_enterAndClause (exprNode e)
1573 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1574 pushClause (ANDCLAUSE);
1577 void context_enterOrClause (exprNode e)
1579 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1580 pushClause (ORCLAUSE);
1583 bool context_inDeepLoop (void)
1585 bool inLoop = FALSE;
1587 clauseStack_elements (gc.clauses, el)
1589 if (clause_isLoop (el))
1598 } end_clauseStack_elements;
1603 bool context_inDeepSwitch (void)
1605 bool inLoop = FALSE;
1607 clauseStack_elements (gc.clauses, el)
1609 if (clause_isSwitch (el))
1618 } end_clauseStack_elements;
1623 bool context_inDeepLoopSwitch (void)
1625 bool inLoop = FALSE;
1627 clauseStack_elements (gc.clauses, el)
1629 if (clause_isBreakable (el))
1638 } end_clauseStack_elements;
1643 clause context_breakClause (void)
1645 clauseStack_elements (gc.clauses, el)
1647 if (clause_isSwitch (el))
1651 else if (clause_isLoop (el))
1659 } end_clauseStack_elements;
1664 clause context_nextBreakClause (void)
1666 bool hasOne = FALSE;
1668 clauseStack_elements (gc.clauses, el)
1670 if (clause_isBreakable (el))
1681 } end_clauseStack_elements;
1686 bool context_inConditional (void)
1688 clauseStack_elements (gc.clauses, el)
1691 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1692 ** to distinguish if from ? for this
1695 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1699 } end_clauseStack_elements;
1704 void context_exitAndClause (exprNode pred, exprNode tbranch)
1706 context_setJustPopped ();
1708 llassert (gc.inclause == ANDCLAUSE);
1710 usymtab_popAndBranch (pred, tbranch);
1711 clauseStack_pop (gc.clauses);
1712 gc.inclause = topClause (gc.clauses);
1715 void context_exitOrClause (exprNode pred, exprNode tbranch)
1717 context_setJustPopped ();
1719 llassert (gc.inclause == ORCLAUSE);
1721 usymtab_popOrBranch (pred, tbranch);
1722 clauseStack_pop (gc.clauses);
1723 gc.inclause = topClause (gc.clauses);
1726 static void context_enterCondClauseAux (clause cl)
1732 static void context_enterTrueAux (exprNode e, clause cl)
1735 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1739 void context_enterIterClause (void)
1741 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1744 void context_enterDoWhileClause (void)
1746 pushClause (DOWHILECLAUSE);
1749 void context_enterWhileClause (exprNode e)
1751 context_enterTrueAux (e, WHILECLAUSE);
1754 void context_enterForClause (exprNode e)
1756 context_enterTrueAux (e, FORCLAUSE);
1759 void context_enterTrueClause (exprNode e)
1761 context_enterTrueAux (e, TRUECLAUSE);
1764 void context_enterSwitch (exprNode e)
1766 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1767 usymtab_switchBranch (e);
1768 context_enterCondClauseAux (SWITCHCLAUSE);
1771 void context_exitSwitch (exprNode e, bool allpaths)
1773 usymtab_exitSwitch (e, allpaths);
1775 while (clause_isCase (clauseStack_top (gc.clauses)))
1777 clauseStack_pop (gc.clauses);
1780 context_exitClauseSimp ();
1783 void context_enterCaseClause (exprNode e)
1785 bool branch = FALSE;
1787 DPRINTF (("Enter case clause!"));
1789 branch = usymtab_newCase (exprNode_undefined, e);
1793 context_enterCondClauseAux (CASECLAUSE);
1797 static void context_enterFalseClauseAux (exprNode e, clause cl)
1800 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1802 clauseStack_switchTop (gc.clauses, cl);
1805 void context_enterFalseClause (exprNode e)
1808 context_enterFalseClauseAux (e, FALSECLAUSE);
1812 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1814 gc.kind = CX_MACROCONST;
1816 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1818 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1822 usymtab_enterScope ();
1823 sRef_enterFunctionScope ();
1825 gc.globs = globSet_undefined;
1826 globSet_clear (gc.globs_used);
1827 gc.mods = sRefSet_undefined;
1830 uentry context_getHeader (void)
1832 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1834 llfatalbug (message ("context_getHeader: bad call: %q",
1835 context_unparse ()));
1838 return (gc.cont.fcn);
1842 context_setFunctionDefined (fileloc loc)
1846 case CX_UNKNOWNMACRO:
1849 uentry_setFunctionDefined (gc.cont.fcn, loc);
1852 /* (not a bug because of parse errors) */
1858 context_enterFunction (/*@exposed@*/ uentry e)
1860 gc.kind = CX_FUNCTION;
1863 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1865 if (uentry_hasAccessType (e))
1867 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1875 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1876 typeIdSet_unparse (gc.acct)));
1878 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1880 gc.globs = uentry_getGlobs (e);
1881 globSet_clear (gc.globs_used);
1882 gc.mods = uentry_getMods (e);
1884 usymtab_enterFunctionScope (e);
1885 sRef_enterFunctionScope ();
1888 bool context_inOldSytleScope(void)
1890 if (gc.kind == CX_OLDSTYLESCOPE)
1897 context_enterOldStyleScope (void)
1899 gc.kind = CX_OLDSTYLESCOPE;
1900 DPRINTF (("Enter old style scope!"));
1901 usymtab_enterFunctionScope (uentry_undefined);
1905 context_completeOldStyleFunction (uentry e)
1907 llassert (gc.kind == CX_OLDSTYLESCOPE);
1909 gc.kind = CX_FUNCTION;
1912 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1914 if (uentry_hasAccessType (e))
1916 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1924 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1925 typeIdSet_unparse (gc.acct)));
1927 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1929 if (!globSet_isEmpty (uentry_getGlobs (e)))
1931 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1932 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1935 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1937 gc.globs = uentry_getGlobs (e);
1938 globSet_clear (gc.globs_used);
1940 gc.mods = uentry_getMods (e);
1942 if (!sRefSet_isEmpty (gc.mods))
1944 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1945 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1948 sRef_enterFunctionScope ();
1951 static bool context_checkStrictGlobals (void)
1953 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1956 static bool context_hasGlobs (void)
1958 if (context_inFunctionLike ())
1960 return (uentry_hasGlobs (gc.cont.fcn));
1968 static bool context_checkCheckedGlobals (void)
1970 return (context_getFlag (FLG_GLOBALS)
1971 && (context_getFlag (FLG_GLOBUNSPEC)
1972 || context_hasGlobs ()));
1975 static bool context_checkUnknownGlobals (void)
1977 /* should be uentry_hasGlobs ? */
1979 return (context_getFlag (FLG_ALLGLOBALS)
1980 && (context_getFlag (FLG_GLOBUNSPEC)
1981 || context_hasGlobs ()));
1984 static bool context_checkUncheckedGlobals (void)
1990 context_checkExport (uentry e)
1992 if (!gc.anyExports) return FALSE;
1994 if (uentry_isFunction (e)
1995 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1997 return context_maybeSet (FLG_EXPORTFCN);
1999 else if (uentry_isExpandedMacro (e))
2001 return context_maybeSet (FLG_EXPORTMACRO);
2003 else if (uentry_isVariable (e))
2005 return context_maybeSet (FLG_EXPORTVAR);
2007 else if (uentry_isEitherConstant (e))
2009 return context_maybeSet (FLG_EXPORTCONST);
2011 else if (uentry_isIter (e) || uentry_isEndIter (e))
2013 return context_maybeSet (FLG_EXPORTITER);
2015 else if (uentry_isDatatype (e))
2017 return context_maybeSet (FLG_EXPORTTYPE);
2026 context_checkGlobUse (uentry glob)
2029 if (uentry_isCheckedStrict (glob))
2031 return context_checkStrictGlobals ();
2033 else if (uentry_isChecked (glob))
2035 return context_checkCheckedGlobals ();
2037 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2039 return context_checkUnknownGlobals ();
2043 llassert (uentry_isUnchecked (glob));
2045 return context_checkUncheckedGlobals ();
2050 context_checkAliasGlob (uentry glob)
2052 if (uentry_isCheckedStrict (glob))
2054 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2056 else if (uentry_isChecked (glob))
2058 return gc.flags[FLG_CHECKEDGLOBALIAS];
2060 else if (uentry_isCheckMod (glob))
2062 return gc.flags[FLG_CHECKMODGLOBALIAS];
2066 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2068 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2072 bool context_checkInternalUse (void)
2074 if (context_hasGlobs ())
2076 return (gc.flags[FLG_INTERNALGLOBS]);
2080 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2085 context_checkGlobMod (sRef el)
2087 uentry ue = sRef_getUentry (el);
2089 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2091 if (uentry_isCheckedModify (ue)
2092 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2094 if (context_hasMods ())
2096 return (gc.flags[FLG_MODGLOBS]);
2100 if (uentry_isCheckedStrict (ue))
2102 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2106 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2112 if (context_hasMods ())
2114 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2124 context_usedGlobal (/*@exposed@*/ sRef el)
2126 if (!globSet_member (gc.globs_used, el))
2129 ** The first time a global is used in a function, we need
2130 ** to clear the derived sRefs, since they were set for the
2131 ** previous function.
2134 sRef_clearDerived (el);
2135 gc.globs_used = globSet_insert (gc.globs_used, el);
2139 /*@observer@*/ sRefSet
2140 context_modList (void)
2146 context_globAccess (sRef s)
2148 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2149 return (globSet_member (gc.globs, s));
2153 context_hasAccess (typeId t)
2155 if (context_inFunctionLike ())
2157 DPRINTF (("Access %d / %s",
2158 t, typeIdSet_unparse (gc.acct)));
2159 return (typeIdSet_member (gc.acct, t));
2163 return (context_hasFileAccess (t));
2168 context_hasFileAccess (typeId t)
2170 return (typeIdSet_member (gc.facct, t));
2174 context_unparseAccess (void)
2176 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2177 typeIdSet_unparse (gc.facct)));
2181 context_unparseClauses (void)
2183 return (clauseStack_unparse (gc.clauses));
2187 context_couldHaveAccess (typeId t)
2189 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2191 return (typeIdSet_member (gc.acct, t));
2195 return (typeIdSet_member (gc.facct, t));
2200 context_getRetType (void)
2202 ctype f = ctype_undefined;
2204 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2206 f = uentry_getType (gc.cont.fcn);
2208 else if (gc.kind == CX_UNKNOWNMACRO)
2210 return ctype_unknown;
2214 llcontbuglit ("context_getRetType: not in a function context");
2215 return ctype_unknown;
2218 if (!ctype_isFunction (f))
2220 if (ctype_isKnown (f))
2222 llbuglit ("context_getRetType: not a function");
2225 return ctype_unknown;
2227 return (ctype_getReturnType (f));
2231 context_hasMods (void)
2233 if (context_inFunctionLike ())
2235 return (uentry_hasMods (gc.cont.fcn));
2244 context_exitAllClauses (void)
2246 while (!clauseStack_isEmpty (gc.clauses))
2248 clause el = clauseStack_top (gc.clauses);
2251 if (clause_isNone (el))
2253 usymtab_quietExitScope (g_currentloc);
2254 clauseStack_pop (gc.clauses);
2258 context_exitClausePlain ();
2262 clauseStack_clear (gc.clauses);
2263 gc.inclause = NOCLAUSE;
2267 context_exitAllClausesQuiet (void)
2269 while (!clauseStack_isEmpty (gc.clauses))
2271 clause el = clauseStack_top (gc.clauses);
2274 usymtab_quietExitScope (g_currentloc);
2275 clauseStack_pop (gc.clauses);
2278 clauseStack_clear (gc.clauses);
2279 gc.inclause = NOCLAUSE;
2283 void context_exitClauseSimp (void)
2286 context_setJustPopped ();
2287 clauseStack_pop (gc.clauses);
2288 gc.inclause = topClause (gc.clauses);
2292 void context_exitCaseClause (void)
2294 context_setJustPopped ();
2295 usymtab_popCaseBranch ();
2296 clauseStack_pop (gc.clauses);
2297 gc.inclause = topClause (gc.clauses);
2301 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2303 context_setJustPopped ();
2304 /*@i32 was makeAlt */
2305 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2306 clauseStack_pop (gc.clauses);
2307 gc.inclause = topClause (gc.clauses);
2310 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2312 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2314 if (gc.inclause != TRUECLAUSE)
2316 llparseerror (cstring_makeLiteral
2317 ("Likely parse error. Conditional clauses are inconsistent."));
2321 context_setJustPopped ();
2322 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2323 clauseStack_pop (gc.clauses);
2324 gc.inclause = topClause (gc.clauses);
2327 void context_exitIterClause (exprNode body)
2329 llassert (gc.inclause == ITERCLAUSE);
2331 context_setJustPopped ();
2333 if (context_getFlag (FLG_ITERLOOPEXEC))
2335 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2339 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2342 clauseStack_pop (gc.clauses);
2343 gc.inclause = topClause (gc.clauses);
2346 static void context_popCase (void) {
2348 ** If we are exiting an outer clause, sometimes still in a switch case.
2362 DPRINTF (("Popping case clause: %s",
2363 clauseStack_unparse (gc.clauses)));
2365 if (gc.inclause == CASECLAUSE) {
2366 context_exitCaseClause ();
2370 void context_exitWhileClause (exprNode pred, exprNode body)
2372 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2376 if (gc.inclause != WHILECLAUSE) {
2377 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2378 clauseStack_unparse (gc.clauses)));
2381 llassert (gc.inclause == WHILECLAUSE);
2383 context_setJustPopped ();
2387 ** predicate must be false after while loop (unless there are breaks)
2390 if (context_getFlag (FLG_WHILELOOPEXEC))
2392 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2396 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2400 usymtab_addGuards (invGuards);
2401 guardSet_free (invGuards);
2403 clauseStack_pop (gc.clauses);
2404 gc.inclause = topClause (gc.clauses);
2407 void context_exitDoWhileClause (exprNode pred)
2409 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2411 if (gc.inclause == CASECLAUSE) {
2412 /* handle Duff's device */
2413 clauseStack_pop (gc.clauses);
2414 gc.inclause = topClause (gc.clauses);
2417 llassert (gc.inclause == DOWHILECLAUSE);
2419 context_setJustPopped ();
2422 usymtab_addGuards (invGuards);
2423 guardSet_free (invGuards);
2425 clauseStack_pop (gc.clauses);
2426 gc.inclause = topClause (gc.clauses);
2429 void context_exitForClause (exprNode forPred, exprNode body)
2431 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2433 llassert (gc.inclause == FORCLAUSE);
2434 context_setJustPopped ();
2436 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2439 ** Predicate must be false after for loop (unless there are breaks)
2442 if (context_getFlag (FLG_FORLOOPEXEC))
2444 DPRINTF (("Here: for loop exec"));
2445 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2449 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2450 && exprNode_loopMustExec (forPred))
2452 DPRINTF (("Here: loop must exec"));
2453 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2457 DPRINTF (("Pop true branch:"));
2458 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2462 usymtab_addGuards (invGuards);
2463 guardSet_free (invGuards);
2464 clauseStack_pop (gc.clauses);
2465 gc.inclause = topClause (gc.clauses);
2468 static void context_exitClausePlain (void)
2470 llassert (gc.inclause != NOCLAUSE);
2472 if (gc.inclause == FALSECLAUSE)
2474 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2478 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2482 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2484 context_setJustPopped ();
2486 if (gc.inclause == FALSECLAUSE)
2488 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2490 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2492 clauseStack_pop (gc.clauses);
2493 gc.inclause = topClause (gc.clauses);
2497 context_exitTrueClause (pred, tbranch);
2502 context_returnFunction (void)
2504 usymtab_checkFinalScope (TRUE);
2508 context_exitFunction (void)
2510 DPRINTF (("Exit function: %s", context_unparse ()));
2512 if (!context_inFunction () && !context_inMacroConstant ()
2513 && !context_inUnknownMacro ()
2514 && !context_inIterDef () && !context_inIterEnd ())
2517 ** not a bug because of parse errors
2524 if (context_inMacro () && usymtab_inFunctionScope ())
2526 usymtab_exitScope (exprNode_undefined);
2529 if (uentry_hasGlobs (gc.cont.fcn))
2531 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2535 if (uentry_hasMods (gc.cont.fcn))
2537 if (context_getFlag (FLG_MUSTMOD))
2539 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2543 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2546 ** clear file static modifies
2549 /* do this first to get unused error messages */
2551 usymtab_exitScope (exprNode_undefined);
2552 sRef_exitFunctionScope ();
2554 gc.showfunction = FALSE;
2555 gc.kind = CX_GLOBAL;
2556 gc.cont.glob = TRUE;
2558 gc.globs = globSet_new ();
2559 globSet_clear (gc.globs_used);
2560 gc.mods = sRefSet_new ();
2563 llassert (clauseStack_isEmpty (gc.clauses));
2564 llassert (gc.inclause == NOCLAUSE);
2565 DPRINTF (("After exit function: %s", context_unparse ()));
2569 context_quietExitFunction (void)
2571 while (gc.kind == CX_INNER)
2573 context_exitInnerPlain ();
2576 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2577 && !context_inIterDef () && !context_inIterEnd ())
2582 usymtab_quietExitScope (g_currentloc);
2584 gc.showfunction = FALSE;
2585 gc.kind = CX_GLOBAL;
2586 gc.cont.glob = TRUE;
2588 gc.globs = globSet_new ();
2589 globSet_clear (gc.globs_used);
2590 gc.mods = sRefSet_new ();
2592 sRef_exitFunctionScope ();
2596 /*@observer@*/ uentryList
2597 context_getParams (void)
2599 if (context_inFunctionLike ())
2601 return (uentry_getParams (gc.cont.fcn));
2605 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2606 return uentryList_undefined;
2610 /*@observer@*/ globSet
2611 context_getUsedGlobs (void)
2613 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2614 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2616 return (gc.globs_used);
2620 context_moduleName ()
2622 return (fileloc_getBase (g_currentloc));
2625 /*@observer@*/ globSet
2626 context_getGlobs (void)
2628 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2629 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2635 context_addBoolAccess (void)
2637 cstring bname = context_getString (FLG_BOOLTYPE);
2638 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2640 addModuleAccess (cstring_copy (bname), boolt);
2642 /* for sys/types (perhaps, this is bogus!) */
2643 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2648 context_canAccessBool (void)
2655 static typeId boolType = typeId_invalid;
2657 if (typeId_isInvalid (boolType))
2659 boolType = usymtab_getTypeId (context_getBoolName ());
2662 if (typeId_isInvalid (boolType)) {
2665 return (typeIdSet_member (gc.acct, boolType));
2670 /* evs 2000-07-25: old version - replaced */
2673 context_boolImplementationType () {
2674 /* For now, this is bogus! */
2679 context_canAccessBool (void)
2681 static typeId boolType = typeId_invalid;
2683 if (typeId_isInvalid (boolType))
2685 boolType = usymtab_getTypeId (context_getBoolName ());
2688 if (!typeId_isInvalid (boolType))
2690 return context_hasAccess (boolType);
2701 context_setMessageAnnote (/*@only@*/ cstring s)
2703 llassert (cstring_isUndefined (gc.msgAnnote));
2708 context_hasMessageAnnote (void)
2710 return (cstring_isDefined (gc.msgAnnote));
2714 context_clearMessageAnnote (void)
2716 if (cstring_isDefined (gc.msgAnnote))
2718 cstring_free (gc.msgAnnote);
2719 gc.msgAnnote = cstring_undefined;
2724 context_getMessageAnnote (void)
2726 cstring st = gc.msgAnnote;
2728 gc.msgAnnote = cstring_undefined;
2733 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2735 llassert (sRef_isInvalid (gc.aliasAnnote));
2736 llassert (!sRef_sameName (s, t));
2738 gc.aliasAnnoteAls = t;
2742 context_hasAliasAnnote (void)
2744 return (sRef_isValid (gc.aliasAnnote));
2748 context_clearAliasAnnote (void)
2750 gc.aliasAnnote = sRef_undefined;
2754 context_getAliasAnnote (void)
2756 sRef ret = gc.aliasAnnote;
2757 sRef als = gc.aliasAnnoteAls;
2759 llassert (sRef_isValid (ret) && sRef_isValid (als));
2761 gc.aliasAnnote = sRef_undefined;
2762 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2766 context_recordFileModifies (sRefSet mods)
2768 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2772 context_recordFileGlobals (globSet mods)
2774 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2775 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2779 context_setCommentMarkerChar (char c)
2781 llassert (c != '\0');
2783 context_setValue (FLG_COMMENTCHAR, (int) c);
2787 context_getCommentMarkerChar (void)
2789 return ((char) context_getValue (FLG_COMMENTCHAR));
2793 context_setValue (flagcode flag, int val)
2795 int index = flagcode_valueIndex (flag);
2797 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2805 llerror_flagWarning (message ("Value for %s must be a positive "
2806 "number (given %d)",
2807 flagcode_unparse (flag), val));
2810 if (flag == FLG_LINELEN && val < MINLINELEN)
2812 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2813 flagcode_unparse (flag),
2819 case FLG_INCLUDENEST:
2820 case FLG_CONTROLNESTDEPTH:
2821 case FLG_STRINGLITERALLEN:
2822 case FLG_NUMSTRUCTFIELDS:
2823 case FLG_NUMENUMMEMBERS:
2824 case FLG_INDENTSPACES:
2827 llerror_flagWarning (message ("Value for %s must be a non-negative "
2828 "number (given %d)",
2829 flagcode_unparse (flag), val));
2838 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2839 gc.values[index] = val;
2843 context_setValueAndFlag (flagcode flag, int val)
2845 gc.flags[flag] = TRUE;
2846 context_setValue (flag, val);
2850 context_getValue (flagcode flag)
2852 int index = flagcode_valueIndex (flag);
2854 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2855 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2856 return (gc.values[index]);
2860 context_getCounter (flagcode flag)
2862 int index = flagcode_valueIndex (flag);
2864 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2865 return (gc.counters[index]);
2869 context_incCounter (flagcode flag)
2871 int index = flagcode_valueIndex (flag);
2873 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2875 gc.counters[index]++;
2879 context_decCounter (flagcode flag)
2881 int index = flagcode_valueIndex (flag);
2883 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2884 gc.counters[index]--;
2887 bool context_showFunction (void)
2889 return (gc.showfunction);
2893 context_setString (flagcode flag, cstring val)
2895 int index = flagcode_stringIndex (flag);
2897 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2899 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2903 case FLG_MESSAGESTREAM:
2904 case FLG_WARNINGSTREAM:
2905 case FLG_ERRORSTREAM:
2907 if (cstring_isDefined (val))
2911 if (osd_fileExists (val))
2913 if (context_getFlag (FLG_STREAMOVERWRITE))
2915 llfatalerror (message
2916 ("Output stream file %s would overwrite existing file. "
2917 "Use -streamoverwrite if you want to allow this.",
2922 fstream = fopen (cstring_toCharsSafe (val), "w");
2924 if (fstream == NULL)
2926 llfatalerror (message ("Unable to open output stream file %s for writing",
2931 ** This ensures fstream will be closed on exit.
2934 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2938 case FLG_MESSAGESTREAM:
2939 g_messagestream = fstream;
2940 /*@innerbreak@*/ break;
2941 case FLG_WARNINGSTREAM:
2942 g_warningstream = fstream;
2943 /*@innerbreak@*/ break;
2944 case FLG_ERRORSTREAM:
2945 g_errorstream = fstream;
2946 /*@innerbreak@*/ break;
2949 /*@-statetransfer@*/
2950 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2953 case FLG_SYSTEMDIRS:
2955 llassert (cstring_isDefined (val));
2957 if (cstring_firstChar (val) == '\"')
2960 cstring tval = cstring_copy (cstring_suffix (val, 1));
2962 if (cstring_lastChar (tval) != '\"')
2964 int n = cstring_length (tval) - 1;
2966 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2971 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2974 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2978 cstring otval = tval;
2979 tval = cstring_prefix (tval, size_fromInt (n));
2980 cstring_free (otval);
2984 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2985 DPRINTF (("val = %s", val));
2986 cstring_free (tval);
2987 cstring_free (oval);
2994 llassert (cstring_isDefined (val));
2996 if (cstring_length (val) == 0)
2999 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
3001 else if (cstring_lastChar (val) != CONNECTCHAR)
3003 val = cstring_appendChar (val, CONNECTCHAR);
3013 ; /* Okay not handle everything in this switch */
3017 if (cstring_length (val) >= 1
3018 && cstring_firstChar (val) == '\"')
3020 llerror_flagWarning (message
3021 ("setting %s to string beginning with \". You probably "
3022 "don't meant to have the \"'s.",
3023 flagcode_unparse (flag)));
3026 gc.strings[index] = val;
3029 static /*@exposed@*/ cstring
3030 context_exposeString (flagcode flag)
3032 int index = flagcode_stringIndex (flag);
3034 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3035 return (gc.strings[index]);
3039 context_getString (flagcode flag)
3041 return (context_exposeString (flag));
3045 context_resetErrors (void)
3050 void context_initMod (void)
3051 /*@globals undef gc; @*/
3053 gc.kind = CX_GLOBAL;
3055 gc.savekind = CX_ERROR;
3056 gc.savecont.glob = FALSE;
3058 gc.instandardlib = FALSE;
3061 gc.linesprocessed = 0;
3062 gc.speclinesprocessed = 0;
3063 gc.insuppressregion = FALSE;
3064 gc.macroMissingParams = FALSE;
3065 gc.preprocessing = FALSE;
3066 gc.incommandline = FALSE;
3067 gc.mc = macrocache_create ();
3069 gc.maxmods = DEFAULTMAXMODS;
3070 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3072 gc.library = FLG_ANSILIB;
3074 gc.locstack = filelocStack_new ();
3075 gc.modrecs = sRefSetList_undefined;
3076 gc.anyExports = FALSE;
3078 gc.ftab = fileTable_create ();
3079 gc.msgLog = messageLog_new ();
3080 gc.inimport = FALSE;
3081 gc.inDerivedFile = FALSE;
3082 gc.inheader = FALSE;
3083 gc.markers = flagMarkerList_new ();
3084 gc.cont.glob = TRUE;
3085 gc.showfunction = FALSE;
3086 gc.msgAnnote = cstring_undefined;
3087 gc.aliasAnnote = sRef_undefined;
3088 gc.aliasAnnoteAls = sRef_undefined;
3089 gc.boolType = ctype_bool;
3090 gc.mods = sRefSet_new ();
3092 gc.saveloc = fileloc_undefined;
3094 gc.inmacrocache = FALSE;
3095 gc.inclause = NOCLAUSE;
3096 gc.clauses = clauseStack_new ();
3097 gc.globs = globSet_new ();
3098 gc.nacct = typeIdSet_emptySet ();
3099 gc.acct = typeIdSet_emptySet ();
3100 gc.facct = typeIdSet_emptySet ();
3101 gc.savedFlags = FALSE;
3102 gc.pushloc = fileloc_undefined;
3103 gc.protectVars = FALSE;
3104 gc.justpopped = FALSE;
3105 gc.isNullGuarded = NO;
3106 gc.globs_used = globSet_undefined;
3110 gc.setGlobally[code] = FALSE;
3111 gc.setLocally[code] = FALSE;
3117 context_resetAllFlags ();
3119 assertSet (gc.flags); /* Can't use global in defines */
3120 assertSet (gc.saveflags);
3121 assertSet (gc.values);
3122 assertSet (gc.strings);
3124 conext_resetAllCounters ();
3125 assertSet (gc.counters);
3127 context_setMode (DEFAULT_MODE);
3129 gc.stateTable = metaStateTable_create ();
3130 gc.annotTable = annotationTable_create ();
3132 gc.inFunctionHeader = FALSE;
3134 DPRINTF (("Annotations: \n%s",
3135 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3136 DPRINTF (("State: \n%s",
3137 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3142 context_typeofZero (void)
3144 ctype ct = ctype_int;
3146 if (context_getFlag (FLG_ZEROPTR))
3148 ct = ctype_makeConj (ct, ctype_voidPointer);
3151 if (context_getFlag (FLG_ZEROBOOL)) {
3152 ct = ctype_makeConj (ct, ctype_bool);
3159 context_typeofOne (void)
3161 ctype ct = ctype_int;
3163 /* 1 is on longer a bool (was before 2.4)
3164 if (!context_getFlag (FLG_ABSTRACTBOOL))
3166 ct = ctype_makeConj (ct, ctype_bool);
3174 context_unparse (void)
3181 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3184 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3187 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3190 s = message ("Inner Context [%d] : %q",
3192 fileloc_unparse (g_currentloc));
3195 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3196 uentry_unparse (gc.cont.fcn),
3197 fileloc_unparse (g_currentloc),
3198 typeIdSet_unparse (gc.acct),
3199 sRefSet_unparse (gc.mods));
3202 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3204 case CX_UNKNOWNMACRO:
3205 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3208 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3211 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3214 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3216 case CX_FCNDECLARATION:
3217 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3220 s = message ("Un-unparseable context: %d", (int) gc.kind);
3224 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3229 context_currentFunctionType (void)
3231 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3233 return (uentry_getType (gc.cont.fcn));
3235 else if (gc.kind == CX_INNER)
3237 llcontbuglit ("context_currentFunctionType: inner context");
3238 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3239 return (context_currentFunctionType ());
3243 llcontbuglit ("context_currentFunctionType: not in function");
3244 return (ctype_undefined);
3249 context_enterInnerContext (void)
3251 if (context_getFlag (FLG_GRAMMAR))
3253 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3256 if (gc.kind == CX_GLOBAL)
3261 else if (gc.kind == CX_INNER)
3270 usymtab_enterScope ();
3271 pushClause (NOCLAUSE);
3275 context_exitInnerPlain (void) /*@modifies gc;@*/
3277 context_exitInner (exprNode_undefined);
3281 context_exitInner (exprNode exp)
3283 if (context_getFlag (FLG_GRAMMAR))
3285 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3288 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3289 ("inclause = %s", clause_nameTaken (gc.inclause)));
3291 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3292 gc.inclause = topClause (gc.clauses);
3294 if (gc.kind == CX_INNER)
3296 if (--gc.cont.cdepth == 0)
3298 gc.kind = CX_GLOBAL;
3299 gc.cont.glob = TRUE;
3304 if (gc.kind == CX_GLOBAL)
3306 llcontbuglit ("Attempt to exit global context");
3311 usymtab_exitScope (exp);
3316 context_enterStructInnerContext (void)
3318 if (context_getFlag (FLG_GRAMMAR))
3320 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3323 if (gc.kind == CX_GLOBAL)
3328 else if (gc.kind == CX_INNER)
3337 usymtab_enterScope ();
3339 if (context_getFlag (FLG_GRAMMAR))
3341 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3346 context_exitStructInnerContext (void)
3348 if (context_getFlag (FLG_GRAMMAR))
3350 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3353 if (gc.kind == CX_INNER)
3355 if (gc.cont.cdepth <= 0)
3357 llcontbuglit ("Attempt to exit inner context with no depth");
3358 gc.kind = CX_GLOBAL;
3359 gc.cont.glob = TRUE;
3365 if (gc.cont.cdepth == 0)
3367 gc.kind = CX_GLOBAL;
3368 gc.cont.glob = TRUE;
3374 if (gc.kind == CX_GLOBAL)
3376 llcontbuglit ("Attempt to exit global context");
3381 usymtab_exitScope (exprNode_undefined);
3383 if (context_getFlag (FLG_GRAMMAR))
3385 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3390 context_exitInnerSafe (void)
3392 if (context_getFlag (FLG_GRAMMAR))
3394 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3397 if (gc.kind == CX_INNER)
3399 if (--gc.cont.cdepth <= 0)
3404 else if (gc.kind == CX_GLOBAL)
3406 llcontbuglit ("Attempt to exit global context");
3411 if (usymtab_inDeepScope ())
3413 usymtab_exitScope (exprNode_undefined);
3419 void setModuleAccess (void)
3421 gc.facct = typeIdSet_emptySet ();
3423 if (fileId_isValid (currentFile ()))
3425 cstring baseName = fileloc_getBase (g_currentloc);
3427 if (context_getFlag (FLG_ACCESSFILE))
3429 if (usymtab_existsType (baseName))
3431 gc.facct = typeIdSet_insert (gc.facct,
3432 usymtab_getTypeId (baseName));
3440 if (context_getFlag (FLG_ACCESSMODULE))
3443 bool hasaccess = FALSE;
3445 for (i = 0; i < gc.nmods; i++)
3447 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3449 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3458 gc.inheader = fileId_isHeader (currentFile ());
3462 llcontbuglit ("Current file not defined\n");
3463 gc.facct = typeIdSet_emptySet ();
3465 gc.inheader = FALSE;
3468 /* 17 Jan 1995: forgot to clear nacct */
3470 gc.nacct = typeIdSet_emptySet ();
3474 context_enterFileAux (void)
3480 context_enterFile (void)
3482 context_enterFileAux ();
3483 usymtab_enterFile ();
3487 context_enterMacroFile (void)
3489 context_enterFileAux ();
3493 context_inFunction (void)
3495 kcontext ck = gc.kind;
3497 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3501 context_inFunctionLike (void)
3503 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3504 || gc.kind == CX_FCNDECLARATION
3505 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3509 context_inRealFunction (void)
3511 kcontext ck = gc.kind;
3513 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3517 context_processAllMacros (void)
3519 usymtab_enterFile ();
3521 gc.inmacrocache = TRUE;
3522 macrocache_processUndefinedElements (gc.mc);
3524 usymtab_exitFile ();
3526 gc.inmacrocache = FALSE;
3527 macrocache_finalize ();
3531 ** this happens once at the end of each C file
3533 ** check each Macro that was defined in current file.c or current file.h
3538 context_processMacros (void)
3540 if (fileId_isValid (currentFile ()))
3543 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3545 gc.inmacrocache = TRUE;
3547 DPRINTF (("Processing macros: %s", cbase));
3548 lastfl = macrocache_processFileElements (gc.mc, cbase);
3549 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3551 cstring_free (cbase);
3553 if (fileloc_isDefined (lastfl))
3555 g_currentloc = fileloc_update (g_currentloc, lastfl);
3559 gc.inmacrocache = FALSE;
3564 context_processingMacros (void)
3566 return (gc.inmacrocache);
3570 context_exitCFile (void)
3572 if (gc.kind != CX_GLOBAL)
3575 (cstring_makeLiteral ("File ended outside global scope"));
3578 if (gc.insuppressregion)
3580 /* gack...don't reverse the order of these lines! ;-> */
3581 gc.insuppressregion = FALSE;
3582 llerrorlit (FLG_SYNTAX,
3583 "File ended in ignore errors region, "
3584 "possible missing /*@end*/");
3587 /* fix up parse errors */
3589 while (!usymtab_inFileScope ())
3591 usymtab_quietExitScope (g_currentloc);
3595 ** Clear the file-specific modifies information.
3598 sRefSetList_elements (gc.modrecs, mods)
3600 sRefSet_clearStatics (mods);
3601 } end_sRefSetList_elements ;
3603 sRefSetList_clear (gc.modrecs);
3605 context_processMacros ();
3608 usymtab_exitFile ();
3610 gc.inDerivedFile = FALSE;
3611 filelocStack_clear (gc.locstack);
3613 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3615 gc.cont.glob = TRUE;
3619 context_restoreFlagSettings ();
3620 gc.savedFlags = FALSE;
3624 DPRINTF (("After exiting file: "));
3625 usymtab_printAll ();
3630 context_exitMacroCache (void)
3632 if (gc.kind != CX_GLOBAL)
3634 if (context_inMacro ())
3635 /* this is okay, file could end without newline in macro */
3637 DPRINTF (("Still in macro: %s",
3638 context_unparse ()));
3639 context_exitFunction ();
3643 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3644 context_unparse ()));
3645 gc.kind = CX_GLOBAL;
3650 ** no longer valid here
3651 ** if (gc.insuppressregion)
3653 ** gc.insuppressregion = FALSE;
3654 ** llerror ("File ended in ignore errors region, possible missing @");
3658 gc.cont.glob = TRUE;
3662 context_saveLocation (void)
3664 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3665 fileloc_free (gc.saveloc);
3666 gc.saveloc = fileloc_copy (g_currentloc);
3670 context_getSaveLocation (void)
3672 fileloc fl = gc.saveloc;
3673 gc.saveloc = fileloc_undefined;
3677 /*@observer@*/ cstring
3678 context_inFunctionName (void)
3680 if (gc.kind == CX_FUNCTION
3681 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3682 || gc.kind == CX_MACROCONST
3683 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3685 return (uentry_rawName (gc.cont.fcn));
3689 llcontbuglit ("context_inFunctionName: not in function");
3690 return (cstring_undefined);
3695 context_userSetFlag (flagcode f, bool b)
3697 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3699 if (f == FLG_NEVERINCLUDE && b)
3701 if (gc.flags[FLG_EXPORTHEADER])
3704 (cstring_makeLiteral
3705 ("setting +neverinclude after +exportheader. "
3706 "Turning off exportheader, since headers are not checked "
3707 "when +neverinclude is used."));
3709 gc.flags[FLG_EXPORTHEADER] = FALSE;
3714 if (f == FLG_EXPORTHEADER && b)
3716 if (gc.flags[FLG_NEVERINCLUDE])
3719 (cstring_makeLiteral
3720 ("setting +exportheader after +neverinclude. "
3721 "Not setting exportheader, since headers are not checked "
3722 "when +neverinclude is used."));
3723 gc.flags[FLG_EXPORTHEADER] = FALSE;
3729 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3731 bool lastsetting = context_getFlag (f);
3733 if (bool_equal (lastsetting, b)
3734 && !flagcode_isSpecialFlag (f)
3735 && !flagcode_isIdemFlag (f)
3736 && !flagcode_hasArgument (f))
3739 (message ("setting %s%s redundant with current value",
3740 cstring_makeLiteralTemp (b ? "+" : "-"),
3741 flagcode_unparse (f)));
3745 if (flagcode_isWarnUseFlag (f) && b)
3747 if (!context_getFlag (FLG_WARNUSE))
3750 (message ("flag +%s is canceled by -warnuse",
3751 flagcode_unparse (f)));
3756 if (flagcode_isLibraryFlag (f))
3758 if (gc.library != FLG_ANSILIB
3762 (message ("selecting library %s after library %s was "
3763 "selected (only one library may be used)",
3764 flagcode_unparse (f),
3765 flagcode_unparse (gc.library)));
3768 if (f == FLG_UNIXLIB)
3770 if (context_getFlag (FLG_WARNUNIXLIB))
3773 (cstring_makeLiteral
3774 ("selecting unix library. Unix library is "
3775 "ad hoc addition to POSIX library. Recommend "
3776 "use +posixlib to select POSIX library instead. "
3777 "Use -warnunixlib to suppress this message."));
3784 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3788 ("setting +%s will not produce warnings with -namechecks. "
3789 "Must set +namechecks also.",
3790 flagcode_unparse (f)));
3793 gc.setGlobally[f] = TRUE;
3794 context_setFlag (f, b, g_currentloc);
3798 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3802 context_saveFlagSettings ();
3805 if (ynm_isOff (set))
3807 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3809 else if (ynm_isOn (set))
3811 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3812 gc.setLocally[f] = TRUE;
3816 context_restoreFlag (f, loc);
3821 context_restoreFlag (flagcode f, fileloc loc)
3827 message ("Attempt to restore flag %s when no file scope flags "
3829 flagcode_unparse (f)),
3834 context_addFlagMarker (f, MAYBE, loc);
3835 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3841 context_setFlag (flagcode f, bool b, fileloc loc)
3843 context_setFlagAux (f, b, FALSE, FALSE, loc);
3847 context_setFlagTemp (flagcode f, bool b)
3849 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3854 # define DOSET(ff,b) \
3855 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3856 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3857 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3858 gc.flags[ff] = b; } while (FALSE)
3861 context_setFlagAux (flagcode f, bool b, bool inFile,
3862 /*@unused@*/ bool isRestore, fileloc loc)
3864 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3867 ** Removed test for special flags.
3870 if (flagcode_isIdemFlag (f))
3879 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3881 if (b) /* Turing higher level on, turns on all lower levels */
3885 case FLG_ITS4MOSTRISKY:
3886 DOSET (FLG_ITS4VERYRISKY, b);
3888 case FLG_ITS4VERYRISKY:
3889 DOSET (FLG_ITS4RISKY, b);
3892 DOSET (FLG_ITS4MODERATERISK, b);
3894 case FLG_ITS4MODERATERISK:
3895 DOSET (FLG_ITS4LOWRISK, b);
3897 case FLG_ITS4LOWRISK:
3902 else /* Turning level off, turns off all higher levels */
3906 case FLG_ITS4LOWRISK:
3907 DOSET (FLG_ITS4MODERATERISK, b);
3909 case FLG_ITS4MODERATERISK:
3910 DOSET (FLG_ITS4RISKY, b);
3913 DOSET (FLG_ITS4VERYRISKY, b);
3915 case FLG_ITS4VERYRISKY:
3916 DOSET (FLG_ITS4MOSTRISKY, b);
3918 case FLG_ITS4MOSTRISKY:
3927 case FLG_MESSAGESTREAMSTDOUT:
3928 g_messagestream = stdout;
3930 case FLG_MESSAGESTREAMSTDERR:
3931 g_messagestream = stderr;
3933 case FLG_WARNINGSTREAMSTDOUT:
3934 g_warningstream = stdout;
3936 case FLG_WARNINGSTREAMSTDERR:
3937 g_warningstream = stderr;
3939 case FLG_ERRORSTREAMSTDOUT:
3940 g_errorstream = stdout;
3942 case FLG_ERRORSTREAMSTDERR:
3943 g_errorstream = stderr;
3946 DOSET (FLG_ALLEMPTY, b);
3947 DOSET (FLG_IFEMPTY, b);
3948 DOSET (FLG_WHILEEMPTY, b);
3949 DOSET (FLG_FOREMPTY, b);
3952 DOSET (FLG_PREDBOOL, b);
3953 DOSET (FLG_PREDBOOLINT, b);
3954 DOSET (FLG_PREDBOOLPTR, b);
3955 DOSET (FLG_PREDBOOLOTHERS, b);
3958 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3959 DOSET (FLG_CHECKEDGLOBALIAS, b);
3960 DOSET (FLG_CHECKMODGLOBALIAS, b);
3961 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3964 DOSET (FLG_ALLBLOCK, b);
3965 DOSET (FLG_IFBLOCK, b);
3966 DOSET (FLG_WHILEBLOCK, b);
3967 DOSET (FLG_FORBLOCK, b);
3981 DOSET (FLG_GRAMMAR, b);
3983 case FLG_CODEIMPONLY:
3984 DOSET (FLG_CODEIMPONLY, b);
3985 DOSET (FLG_GLOBIMPONLY, b);
3986 DOSET (FLG_RETIMPONLY, b);
3987 DOSET (FLG_STRUCTIMPONLY, b);
3989 case FLG_SPECALLIMPONLY:
3990 DOSET (FLG_SPECALLIMPONLY, b);
3991 DOSET (FLG_SPECGLOBIMPONLY, b);
3992 DOSET (FLG_SPECRETIMPONLY, b);
3993 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3995 case FLG_ALLIMPONLY:
3996 DOSET (FLG_ALLIMPONLY, b);
3997 DOSET (FLG_GLOBIMPONLY, b);
3998 DOSET (FLG_RETIMPONLY, b);
3999 DOSET (FLG_STRUCTIMPONLY, b);
4000 DOSET (FLG_SPECGLOBIMPONLY, b);
4001 DOSET (FLG_SPECRETIMPONLY, b);
4002 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4004 case FLG_ANSI89LIMITS:
4005 DOSET (FLG_ANSI89LIMITS, b);
4006 DOSET (FLG_CONTROLNESTDEPTH, b);
4007 DOSET (FLG_STRINGLITERALLEN, b);
4008 DOSET (FLG_INCLUDENEST, b);
4009 DOSET (FLG_NUMSTRUCTFIELDS, b);
4010 DOSET (FLG_NUMENUMMEMBERS, b);
4014 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4015 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4016 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4017 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4018 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4019 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4020 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4023 case FLG_ISO99LIMITS:
4024 DOSET (FLG_ISO99LIMITS, b);
4025 DOSET (FLG_CONTROLNESTDEPTH, b);
4026 DOSET (FLG_STRINGLITERALLEN, b);
4027 DOSET (FLG_INCLUDENEST, b);
4028 DOSET (FLG_NUMSTRUCTFIELDS, b);
4029 DOSET (FLG_NUMENUMMEMBERS, b);
4033 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4034 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4035 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4036 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4037 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4038 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4039 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4042 case FLG_EXTERNALNAMELEN:
4043 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4044 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4046 case FLG_INTERNALNAMELEN:
4047 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4048 DOSET (FLG_INTERNALNAMELEN, TRUE);
4050 case FLG_EXTERNALNAMECASEINSENSITIVE:
4051 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4053 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4055 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4056 context_setValue (FLG_EXTERNALNAMELEN, 0);
4059 case FLG_INTERNALNAMECASEINSENSITIVE:
4060 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4062 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4064 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4065 context_setValue (FLG_INTERNALNAMELEN, 0);
4068 case FLG_INTERNALNAMELOOKALIKE:
4069 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4071 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4073 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4074 context_setValue (FLG_INTERNALNAMELEN, 0);
4078 DOSET (FLG_MODNOMODS, b);
4079 DOSET (FLG_MODGLOBSUNSPEC, b);
4080 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4083 DOSET (FLG_EXPORTVAR, b);
4084 DOSET (FLG_EXPORTFCN, b);
4085 DOSET (FLG_EXPORTTYPE, b);
4086 DOSET (FLG_EXPORTMACRO, b);
4087 DOSET (FLG_EXPORTCONST, b);
4088 gc.anyExports = TRUE;
4091 DOSET (FLG_RETEXPOSE, b);
4092 DOSET (FLG_ASSIGNEXPOSE, b);
4093 DOSET (FLG_CASTEXPOSE, b);
4096 DOSET (FLG_RETVALBOOL, b);
4097 DOSET (FLG_RETVALINT, b);
4098 DOSET (FLG_RETVALOTHER, b);
4103 DOSET (FLG_EXPORTLOCAL, FALSE);
4104 DOSET (FLG_DECLUNDEF, FALSE);
4105 DOSET (FLG_SPECUNDEF, FALSE);
4106 DOSET (FLG_TOPUNUSED, FALSE);
4110 DOSET (FLG_LOOPLOOPBREAK, b);
4111 DOSET (FLG_LOOPSWITCHBREAK, b);
4112 DOSET (FLG_SWITCHLOOPBREAK, b);
4113 DOSET (FLG_SWITCHSWITCHBREAK, b);
4114 DOSET (FLG_LOOPLOOPCONTINUE, b);
4115 DOSET (FLG_DEEPBREAK, b);
4118 DOSET (FLG_FORLOOPEXEC, b);
4119 DOSET (FLG_WHILELOOPEXEC, b);
4120 DOSET (FLG_ITERLOOPEXEC, b);
4123 DOSET (FLG_ACCESSMODULE, b);
4124 DOSET (FLG_ACCESSFILE, b);
4125 DOSET (FLG_ACCESSCZECH, b);
4128 DOSET (FLG_ALLMACROS, b);
4129 DOSET (FLG_FCNMACROS, b);
4130 DOSET (FLG_CONSTMACROS, b);
4133 DOSET (FLG_BOUNDSREAD, b);
4134 DOSET (FLG_BOUNDSWRITE, b);
4137 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4138 DOSET (FLG_CZECHFUNCTIONS, b);
4139 DOSET (FLG_CZECHVARS, b);
4140 DOSET (FLG_CZECHCONSTANTS, b);
4141 DOSET (FLG_CZECHTYPES, b);
4144 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4145 DOSET (FLG_SLOVAKFUNCTIONS, b);
4146 DOSET (FLG_SLOVAKVARS, b);
4147 DOSET (FLG_SLOVAKCONSTANTS, b);
4148 DOSET (FLG_SLOVAKTYPES, b);
4150 case FLG_CZECHOSLOVAK:
4151 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4152 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4153 DOSET (FLG_CZECHOSLOVAKVARS, b);
4154 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4155 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4158 DOSET (FLG_NULLSTATE, b);
4159 DOSET (FLG_NULLDEREF, b);
4160 DOSET (FLG_NULLASSIGN, b);
4161 DOSET (FLG_NULLPASS, b);
4162 DOSET (FLG_NULLRET, b);
4165 DOSET (FLG_MUSTFREEONLY, b);
4166 DOSET (FLG_MUSTFREEFRESH, b);
4169 DOSET (FLG_NULLSTATE, b);
4170 DOSET (FLG_NULLDEREF, b);
4171 DOSET (FLG_NULLASSIGN, b);
4172 DOSET (FLG_NULLPASS, b);
4173 DOSET (FLG_NULLRET, b);
4174 DOSET (FLG_COMPDEF, b);
4175 DOSET (FLG_COMPMEMPASS, b);
4176 DOSET (FLG_UNIONDEF, b);
4177 DOSET (FLG_MEMTRANS, b);
4178 DOSET (FLG_USERELEASED, b);
4179 DOSET (FLG_ALIASUNIQUE, b);
4180 DOSET (FLG_MAYALIASUNIQUE, b);
4181 DOSET (FLG_MUSTFREEONLY, b);
4182 DOSET (FLG_MUSTFREEFRESH, b);
4183 DOSET (FLG_MUSTDEFINE, b);
4184 DOSET (FLG_GLOBSTATE, b);
4185 DOSET (FLG_COMPDESTROY, b);
4186 DOSET (FLG_MUSTNOTALIAS, b);
4187 DOSET (FLG_MEMIMPLICIT, b);
4188 DOSET (FLG_BRANCHSTATE, b);
4189 /*@fallthrough@*/ /* also sets memtrans flags */
4191 DOSET (FLG_MEMTRANS, b);
4192 DOSET (FLG_EXPOSETRANS, b);
4193 DOSET (FLG_OBSERVERTRANS, b);
4194 DOSET (FLG_DEPENDENTTRANS, b);
4195 DOSET (FLG_NEWREFTRANS, b);
4196 DOSET (FLG_ONLYTRANS, b);
4197 DOSET (FLG_OWNEDTRANS, b);
4198 DOSET (FLG_FRESHTRANS, b);
4199 DOSET (FLG_SHAREDTRANS, b);
4200 DOSET (FLG_TEMPTRANS, b);
4201 DOSET (FLG_KEPTTRANS, b);
4202 DOSET (FLG_REFCOUNTTRANS, b);
4203 DOSET (FLG_STATICTRANS, b);
4204 DOSET (FLG_UNKNOWNTRANS, b);
4205 DOSET (FLG_KEEPTRANS, b);
4206 DOSET (FLG_IMMEDIATETRANS, b);
4213 if (b && !gc.anyExports
4214 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4215 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4216 || f == FLG_EXPORTCONST
4217 || f == FLG_EXPORTANY))
4219 gc.anyExports = TRUE;
4224 context_maybeSet (flagcode d)
4226 return (gc.flags[d] || gc.setLocally[d]);
4230 context_getFlag (flagcode d)
4232 return (gc.flags[d]);
4236 context_flagOn (flagcode f, fileloc loc)
4238 return (!context_suppressFlagMsg (f, loc));
4241 static void context_saveFlagSettings (void)
4243 gc.savedFlags = TRUE;
4244 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4245 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4248 static void context_restoreFlagSettings (void)
4250 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4251 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4252 gc.savedFlags = FALSE;
4255 void context_setFilename (fileId fid, int lineno)
4256 /*@globals fileloc g_currentloc;@*/
4257 /*@modifies g_currentloc@*/
4259 if (fileId_baseEqual (currentFile (), fid))
4266 fileloc_setColumn (g_currentloc, 0);
4268 if (fileloc_isSpecialFile (g_currentloc))
4270 gc.inDerivedFile = TRUE;
4273 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4275 int maxdepth = context_getValue (FLG_INCLUDENEST);
4277 if (filelocStack_size (gc.locstack) > maxdepth)
4279 int depth = filelocStack_includeDepth (gc.locstack);
4281 if (depth > maxdepth)
4285 message ("Maximum include nesting depth "
4286 "(%d, current depth %d) exceeded",
4289 filelocStack_nextTop (gc.locstack)))
4291 filelocStack_printIncludes (gc.locstack);
4297 g_currentloc = fileloc_create (fid, lineno, 1);
4298 gc.inheader = fileId_isHeader (currentFile ());
4300 context_enterFileAux ();
4304 void context_enterIterDef (/*@observer@*/ uentry le)
4306 context_enterMacro (le);
4307 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4308 gc.kind = CX_ITERDEF;
4311 void context_enterIterEnd (/*@observer@*/ uentry le)
4313 context_enterMacro (le);
4314 gc.kind = CX_ITEREND;
4318 context_destroyMod (void)
4319 /*@globals killed gc@*/
4322 ctype_destroyMod ();
4326 fileTable_free (gc.ftab);
4327 filelocStack_free (gc.locstack);
4329 gc.ftab = fileTable_undefined;
4331 macrocache_free (gc.mc);
4332 sfree (gc.moduleaccess);
4335 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4336 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4339 sRefSetList_free (gc.modrecs);
4341 flagMarkerList_free (gc.markers);
4343 messageLog_free (gc.msgLog);
4345 clauseStack_free (gc.clauses);
4348 cstring_free (gc.msgAnnote);
4349 globSet_free (gc.globs_used);
4350 metaStateTable_free (gc.stateTable);
4351 annotationTable_free (gc.annotTable);
4358 bool context_msgBoolInt (void)
4360 return gc.flags [FLG_BOOLINT];
4363 bool context_msgCharInt (void)
4365 return gc.flags [FLG_CHARINT];
4368 bool context_msgEnumInt (void)
4370 return gc.flags [FLG_ENUMINT];
4373 bool context_msgPointerArith (void)
4375 return gc.flags [FLG_POINTERARITH];
4378 bool context_msgStrictOps (void)
4380 return gc.flags [FLG_STRICTOPS];
4384 bool context_msgLh (void)
4386 return gc.flags [FLG_DOLH];
4390 void context_pushLoc (void)
4392 fileloc_free (gc.pushloc);
4393 gc.pushloc = gc.saveloc;
4394 gc.saveloc = fileloc_undefined;
4397 void context_popLoc (void)
4399 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4402 bool context_inGlobalScope (void)
4404 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4407 bool context_inInnerScope (void)
4409 return (gc.kind == CX_INNER);
4412 void context_setProtectVars (void)
4414 gc.protectVars = TRUE;
4417 bool context_anyErrors (void)
4419 return (gc.numerrors > 0);
4422 void context_hasError (void)
4425 DPRINTF (("num errors: %d", gc.numerrors));
4428 int context_numErrors (void)
4430 return gc.numerrors;
4433 bool context_neednl (void)
4438 void context_setNeednl (void)
4443 int context_getExpect (void)
4445 return (context_getValue (FLG_EXPECT));
4449 int context_getLCLExpect (void)
4451 return (context_getValue (FLG_LCLEXPECT));
4455 int context_getLimit (void)
4457 return (context_getValue (FLG_LIMIT));
4460 bool context_unlimitedMessages (void)
4462 return (context_getLimit () < 0);
4465 void context_releaseVars (void)
4467 llassert (gc.protectVars);
4468 gc.protectVars = FALSE;
4471 void context_sizeofReleaseVars (void)
4473 /* If there is a nested sizeof, this might not hold:
4474 llassert (gc.protectVars);
4477 gc.protectVars = FALSE;
4480 bool context_inProtectVars (void)
4482 return (gc.protectVars);
4485 void context_hideShowscan (void)
4487 gc.flags[FLG_SHOWSCAN] = FALSE;
4490 void context_unhideShowscan (void)
4492 gc.flags[FLG_SHOWSCAN] = TRUE;
4495 bool context_inHeader (void)
4497 return (gc.inheader);
4500 fileTable context_fileTable (void)
4505 cstring context_tmpdir (void)
4507 return (context_getString (FLG_TMPDIR));
4510 messageLog context_messageLog (void)
4515 bool context_inMacroFunction (void)
4517 return (gc.kind == CX_MACROFCN);
4520 bool context_inMacroConstant (void)
4522 return (gc.kind == CX_MACROCONST);
4525 bool context_inUnknownMacro (void)
4527 return (gc.kind == CX_UNKNOWNMACRO);
4530 void context_setShownFunction (void)
4532 gc.showfunction = FALSE;
4535 bool context_doDump (void)
4537 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4540 bool context_doMerge (void)
4542 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4545 cstring context_getDump (void)
4547 return context_getString (FLG_DUMP);
4550 cstring context_getMerge (void)
4552 return context_getString (FLG_MERGE);
4556 bool context_inLCLLib (void)
4558 return (gc.kind == CX_LCLLIB);
4561 bool context_inImport (void)
4563 return (gc.inimport);
4566 void context_enterImport (void)
4571 void context_leaveImport (void)
4573 gc.inimport = FALSE;
4577 bool context_inMacro (void)
4579 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4580 || gc.kind == CX_UNKNOWNMACRO
4581 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4584 bool context_inIterDef (void)
4586 return (gc.kind == CX_ITERDEF);
4589 bool context_inIterEnd (void)
4591 return (gc.kind == CX_ITEREND);
4594 int context_getLinesProcessed (void)
4596 return (gc.linesprocessed);
4599 int context_getSpecLinesProcessed (void)
4601 return (gc.speclinesprocessed);
4605 void context_processedSpecLine (void)
4607 gc.speclinesprocessed++;
4610 void context_resetSpecLines (void)
4612 gc.speclinesprocessed = 0;
4616 bool context_inGlobalContext (void)
4618 return (gc.kind == CX_GLOBAL);
4621 static void context_quietExitScopes (void)
4624 ** Try to restore the global scope (after an error).
4627 while (!usymtab_inFileScope ())
4629 usymtab_quietExitScope (g_currentloc);
4632 gc.cont.glob = TRUE;
4633 gc.kind = CX_GLOBAL;
4636 void context_checkGlobalScope (void)
4638 if (gc.kind != CX_GLOBAL)
4640 if (context_inMacro ())
4642 ; /* evans 2001-10-14: Okay to be in a macro here! */
4646 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4647 context_quietExitScopes ();
4652 void context_setFileId (fileId s)
4654 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4657 bool context_setBoolName (void)
4659 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4663 cstring context_printBoolName (void)
4665 if (context_setBoolName ())
4667 return context_getBoolName ();
4671 return cstring_makeLiteralTemp ("boolean");
4675 cstring context_getBoolName (void)
4677 return (context_getString (FLG_BOOLTYPE));
4680 cstring context_getFalseName (void)
4682 return (context_getString (FLG_BOOLFALSE));
4685 cstring context_getTrueName (void)
4687 return (context_getString (FLG_BOOLTRUE));
4690 cstring context_getLarchPath (void)
4692 return (context_getString (FLG_LARCHPATH));
4695 cstring context_getLCLImportDir (void)
4697 return (context_getString (FLG_LCLIMPORTDIR));
4700 static void context_setJustPopped (void)
4702 gc.justpopped = TRUE;
4705 void context_clearJustPopped (void)
4707 gc.justpopped = FALSE;
4710 bool context_justPopped (void)
4712 return (gc.justpopped);
4715 void context_setMacroMissingParams (void)
4717 gc.macroMissingParams = TRUE;
4720 void context_resetMacroMissingParams (void)
4722 gc.macroMissingParams = FALSE;
4725 bool context_isMacroMissingParams (void)
4727 return (gc.macroMissingParams);
4730 void context_showFilelocStack (void)
4732 filelocStack_printIncludes (gc.locstack);
4735 metaStateTable context_getMetaStateTable (void)
4737 return gc.stateTable;
4740 metaStateInfo context_lookupMetaStateInfo (cstring key)
4742 return metaStateTable_lookup (gc.stateTable, key);
4745 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4747 annotationInfo ainfo;
4749 ainfo = annotationTable_lookup (gc.annotTable, annot);
4754 void context_addAnnotation (annotationInfo ainfo)
4756 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4760 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4761 annotationInfo_getLoc (ainfo));
4763 annotationInfo_free (ainfo);
4767 annotationTable_insert (gc.annotTable, ainfo);
4771 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4773 if (metaStateTable_contains (gc.stateTable, mname))
4777 message ("Duplicate metastate declaration: %s", mname),
4778 metaStateInfo_getLoc (msinfo));
4779 cstring_free (mname);
4780 metaStateInfo_free (msinfo);
4784 DPRINTF (("Adding meta state: %s", mname));
4785 metaStateTable_insert (gc.stateTable, mname, msinfo);
4789 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4791 if (metaStateTable_size (gc.stateTable) > 0)
4793 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4794 /*@i32 should use smaller value... */
4795 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4797 metaStateTable_elements (gc.stateTable, msname, msi)
4799 mtContextNode context = metaStateInfo_getContext (msi);
4801 if (mtContextNode_matchesRefStrict (context, s))
4803 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4804 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4808 cstring_copy (metaStateInfo_getName (msi)),
4809 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4810 stateInfo_copy (sinfo)));
4814 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4817 end_metaStateTable_elements ;
4819 stateInfo_free (sinfo);
4820 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4825 stateInfo_free (sinfo);
4826 return valueTable_undefined;
4830 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4832 if (metaStateTable_size (gc.stateTable) > 0)
4834 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4835 /*@i32 should use smaller value... */
4837 metaStateTable_elements (gc.stateTable, msname, msi)
4839 /*@i23 only add global...*/
4840 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4841 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4843 valueTable_insert (res,
4844 cstring_copy (metaStateInfo_getName (msi)),
4845 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4846 stateInfo_copy (sinfo)));
4848 end_metaStateTable_elements ;
4850 stateInfo_free (sinfo);
4851 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4856 stateInfo_free (sinfo);
4857 return valueTable_undefined;
4862 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4866 static ctype lastStruct;
4868 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4874 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4880 /*@unused@*/ static int sInfoNum = 0;
4884 /*@unused@*/ uentry ue;
4885 /*@unused@*/ sRef s;
4889 /*@unused@*/ ctype ct;
4890 /*@unused@*/ constraintList inv;
4891 /*@unused@*/ int ngetUe;
4892 /*@unused@*/ struct getUe * t ;
4896 static struct sInfo globalStructInfo;
4899 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4900 stable release of splint. I coomented them out so that they won't break anything
4901 but didn't delete them because they will be fixed and included later
4905 void setGlobalStructInfo(ctype ct, constraintList list)
4910 f = ctype_getFields (ct);
4912 if (constraintList_isDefined(list) )
4914 globalStructInfo.ct = ct;
4915 globalStructInfo.inv = list;
4917 globalStructInfo.ngetUe = 0;
4919 / *abstraction violation fix it * /
4920 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4922 globalStructInfo.ngetUe = f->nelements;
4926 uentryList_elements(f, ue)
4928 globalStructInfo.t[i].ue = ue;
4929 globalStructInfo.t[i].s = uentry_getSref(ue);
4930 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4931 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4936 end_uentryList_elements;
4942 bool hasInvariants (ctype ct) /*@*/
4944 if ( ctype_sameName(globalStructInfo.ct, ct) )