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)
175 /*@modifies gc.flags@*/ ;
178 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, bool p_isRestore)
179 /*@modifies gc.flags@*/ ;
181 static void context_restoreFlag (flagcode p_f) /*@modifies gc.flags@*/ ;
185 cstring context_unparseFlagMarkers ()
187 return (flagMarkerList_unparse (gc.markers));
190 void context_setPreprocessing (void)
192 llassert (!gc.preprocessing);
193 gc.preprocessing = TRUE;
196 void context_clearPreprocessing (void)
198 llassert (gc.preprocessing);
199 gc.preprocessing = FALSE;
202 bool context_isPreprocessing (void)
204 return gc.preprocessing;
207 bool context_loadingLibrary (void)
209 return (fileloc_isLib (g_currentloc));
212 bool context_inXHFile (void)
214 return (fileloc_isXHFile (g_currentloc));
217 void context_setInCommandLine (void)
219 llassert (!gc.incommandline);
220 gc.incommandline = TRUE;
223 void context_clearInCommandLine (void)
225 llassert (gc.incommandline);
226 gc.incommandline = FALSE;
229 bool context_isInCommandLine (void)
231 return gc.incommandline;
235 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
238 clauseStack_push (gc.clauses, c);
240 if (clause_isConditional (c)
241 && context_getFlag (FLG_CONTROLNESTDEPTH))
243 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
244 int depth = clauseStack_controlDepth (gc.clauses);
246 if (depth == maxdepth + 1)
249 (FLG_CONTROLNESTDEPTH,
250 message ("Maximum control nesting depth "
259 clause topClause (clauseStack s) /*@*/
261 if (clauseStack_isEmpty (s)) return NOCLAUSE;
262 return ((clause) clauseStack_top (s));
266 context_addMacroCache (/*@only@*/ cstring def)
268 DPRINTF (("macro cache: %s", def));
269 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
273 context_addComment (/*@only@*/ cstring def)
275 DPRINTF (("macro comment: %s", def));
276 macrocache_addComment (gc.mc, fileloc_copy (g_currentloc), def);
280 ** returns TRUE is fl is in ignore region, or region where -code
282 ** the logic is fuzzy...
286 context_inSuppressFlagZone (fileloc fl, flagcode code)
288 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
291 if (ynm_isMaybe (ret))
299 res = !gc.saveflags[code];
303 res = !context_getFlag (code);
308 res = ynm_toBoolStrict (ret);
315 context_suppressSystemMsg (fileloc fl)
317 if (context_getFlag (FLG_SYSTEMDIRERRORS))
323 return (fileloc_isSystemFile (fl));
328 context_suppressFlagMsg (flagcode flag, fileloc fl)
330 if (context_suppressSystemMsg (fl))
335 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
337 /* want same object compare here */
339 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
341 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
343 return (!context_getFlag (flag)
344 || context_inSuppressRegion ()
345 || context_inSuppressZone (fl)
346 || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
350 return (context_inSuppressFlagZone (fl, flag));
355 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
358 if (context_suppressSystemMsg (fl))
364 if (fl == g_currentloc)
365 /*@noaccess fileloc@*/
367 return (context_getFlag (flag) || context_inSuppressRegion ());
372 return (context_getFlag (flag) || context_inSuppressRegion ());
377 context_inSuppressZone (fileloc fl)
379 if (context_suppressSystemMsg (fl))
384 return (flagMarkerList_inIgnore (gc.markers, fl));
388 context_inSuppressRegion (void)
390 return (gc.insuppressregion);
394 context_enterSuppressRegion (void)
396 if (gc.insuppressregion)
398 gc.insuppressregion = FALSE; /* get this msg! */
400 ("%q: New ignore errors region entered while in ignore errors region",
401 fileloc_unparse (g_currentloc)));
404 gc.insuppressregion = TRUE;
405 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (g_currentloc));
409 context_addFlagMarker (flagcode code, ynm set)
411 flagMarkerList_add (gc.markers,
412 flagMarker_createLocalSet (code, set, g_currentloc));
416 context_enterSuppressLine (int count)
418 fileloc nextline = fileloc_copy (g_currentloc);
420 flagMarkerList_add (gc.markers,
421 flagMarker_createIgnoreCount (count, g_currentloc));
423 fileloc_nextLine (nextline);
424 flagMarkerList_add (gc.markers,
425 flagMarker_createIgnoreOff (nextline));
426 fileloc_free (nextline);
429 void context_checkSuppressCounts (void)
431 if (context_getFlag (FLG_SUPCOUNTS))
433 flagMarkerList_checkSuppressCounts (gc.markers);
437 void context_incLineno (void)
444 context_exitSuppressRegion (void)
446 if (!gc.insuppressregion)
448 llerrorlit (FLG_SYNTAX,
449 "End ignore errors in region while not ignoring errors");
452 gc.insuppressregion = FALSE;
453 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (g_currentloc));
457 context_enterMTfile (void)
463 context_exitMTfile (void)
465 llassert (gc.kind == CX_MT);
471 context_enterLCLfile (void)
474 gc.facct = typeIdSet_emptySet ();
479 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
483 for (i = 0; i < gc.nmods; i++)
485 if (cstring_equal (gc.moduleaccess[i].file, fname))
487 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
488 cstring_free (fname);
493 if (gc.nmods == gc.maxmods)
497 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
498 oldmods = gc.moduleaccess;
500 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
502 for (i = 0; i < gc.nmods; i++)
504 gc.moduleaccess[i] = oldmods[i];
510 gc.moduleaccess[gc.nmods].file = fname;
511 gc.moduleaccess[gc.nmods].daccess = mods;
517 insertModuleAccess (cstring fname, typeId t)
521 for (i = 0; i < gc.nmods; i++)
523 if (cstring_equal (gc.moduleaccess[i].file, fname))
525 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
530 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
535 context_exitLCLfile (void)
537 if (gc.kind != CX_LCLLIB)
540 fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION);
542 addModuleAccess (fileLib_removePath (lclname), gc.facct);
543 cstring_free (lclname);
548 gc.facct = typeIdSet_emptySet ();
553 context_dumpModuleAccess (FILE *fout)
557 for (i = 0; i < gc.nmods; i++)
559 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
561 fprintf (fout, "%s#%s@\n",
562 cstring_toCharsSafe (gc.moduleaccess[i].file),
563 cstring_toCharsSafe (td));
569 bool context_usingPosixLibrary ()
571 return (gc.library == FLG_POSIXLIB
572 || gc.library == FLG_POSIXSTRICTLIB
573 || gc.library == FLG_UNIXLIB
574 || gc.library == FLG_UNIXSTRICTLIB);
577 bool context_usingAnsiLibrary ()
579 return (gc.library != FLG_NOLIB);
582 flagcode context_getLibrary ()
587 void context_setLibrary (flagcode code)
592 /*@observer@*/ cstring context_selectedLibrary ()
597 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
599 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
600 case FLG_POSIXSTRICTLIB:
601 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
603 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
604 case FLG_UNIXSTRICTLIB:
605 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
607 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
614 context_loadModuleAccess (FILE *in)
616 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
618 char *name = mstring_create (MAX_NAME_LENGTH);
624 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
630 while (s != NULL && *s != ';' && *s != '\0')
634 while (*s != '#' && *s != '\0')
643 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
644 cstring_fromChars (s)));
650 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
651 typeIdSet_undump (&s));
653 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
654 llassert (s != lasts);
664 typeIdSet context_fileAccessTypes (void)
670 context_resetModeFlags (void)
675 if (flagcode_isModeFlag (code))
677 context_setFlag (code, FALSE);
685 ** Set all flags to FALSE, except for a few which are
688 ** Set all values and strings to appropriate defaults.
689 ** Set all counters to 0.
693 conext_resetAllCounters (void)
697 for (i = 0; i < NUMVALUEFLAGS; i++)
704 context_resetAllFlags (void)
706 DPRINTF (("******** Reset all flags"));
710 gc.flags[code] = FALSE;
712 if (flagcode_hasNumber (code))
716 /*@-loopswitchbreak@*/
720 val = DEFAULT_LIMIT; break;
722 val = DEFAULT_BUGSLIMIT; break;
724 val = DEFAULT_LINELEN; break;
725 case FLG_INDENTSPACES:
726 val = DEFAULT_INDENTSPACES; break;
727 case FLG_EXTERNALNAMELEN:
728 val = ISO99_EXTERNALNAMELEN; break;
729 case FLG_INTERNALNAMELEN:
730 val = ISO99_INTERNALNAMELEN; break;
731 case FLG_COMMENTCHAR:
732 val = (int) DEFAULT_COMMENTCHAR; break;
733 case FLG_CONTROLNESTDEPTH:
734 val = (int) ISO99_CONTROLNESTDEPTH; break;
735 case FLG_STRINGLITERALLEN:
736 val = (int) ISO99_STRINGLITERALLEN; break;
737 case FLG_INCLUDENEST:
738 val = (int) ISO99_INCLUDENEST; break;
739 case FLG_NUMSTRUCTFIELDS:
740 val = (int) ISO99_NUMSTRUCTFIELDS; break;
741 case FLG_NUMENUMMEMBERS:
742 val = (int) ISO99_NUMENUMMEMBERS; break;
747 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
749 /*@=loopswitchbreak@*/
751 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
752 context_setValue (code, val);
753 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
754 llassert (context_getValue (code) == val);
756 else if (flagcode_hasChar (code))
758 llassert (code == FLG_COMMENTCHAR);
759 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
761 else if (flagcode_hasString (code))
763 cstring val = cstring_undefined;
766 { /*@-loopswitchbreak@*/
769 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
771 if (cstring_isDefined (larchpath))
773 val = cstring_copy (larchpath);
777 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
782 case FLG_LCLIMPORTDIR:
784 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
788 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
790 char *env = osd_getEnvironmentVariable ("TMP");
794 env = osd_getEnvironmentVariable ("TEMP");
797 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
800 val = cstring_makeLiteral (DEFAULT_TMPDIR);
801 # endif /* !defined(OS2) && !defined(MSDOS) */
805 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
807 val = cstring_makeLiteral ("FALSE"); break;
809 val = cstring_makeLiteral ("TRUE"); break;
810 case FLG_MACROVARPREFIX:
811 val = cstring_makeLiteral ("m_"); break;
813 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
816 } /*@=loopswitchbreak@*/
818 context_setString (code, val);
822 ; /* nothing to set */
827 ** These flags are true by default.
830 /*@i34 move this into flags.def */
832 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
833 gc.flags[FLG_MODIFIES] = TRUE;
834 gc.flags[FLG_NESTCOMMENT] = TRUE;
835 gc.flags[FLG_GLOBALS] = TRUE;
836 gc.flags[FLG_FULLINITBLOCK] = TRUE;
837 gc.flags[FLG_INITSIZE] = TRUE;
838 gc.flags[FLG_INITALLELEMENTS] = TRUE;
840 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
842 gc.flags[FLG_LIKELYBOOL] = TRUE;
843 gc.flags[FLG_ZEROPTR] = TRUE;
844 gc.flags[FLG_NUMLITERAL] = TRUE;
845 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
846 gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
847 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
848 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
849 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
850 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
851 gc.flags[FLG_CASTFCNPTR] = TRUE;
852 gc.flags[FLG_DOLCS] = TRUE;
853 gc.flags[FLG_USEVARARGS] = TRUE;
854 gc.flags[FLG_MAINTYPE] = TRUE;
855 gc.flags[FLG_SPECMACROS] = TRUE;
856 gc.flags[FLG_REDEF] = TRUE;
857 gc.flags[FLG_MACRONEXTLINE] = TRUE;
859 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
860 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
862 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
863 gc.flags[FLG_WARNUSE] = TRUE;
864 gc.flags[FLG_PREDASSIGN] = TRUE;
865 gc.flags[FLG_MODOBSERVER] = TRUE;
866 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
867 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
869 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
870 gc.flags[FLG_RETIMPONLY] = TRUE;
871 gc.flags[FLG_GLOBIMPONLY] = TRUE;
872 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
873 gc.flags[FLG_PREPROC] = TRUE;
874 gc.flags[FLG_NAMECHECKS] = TRUE;
875 gc.flags[FLG_FORMATCODE] = TRUE;
876 gc.flags[FLG_FORMATTYPE] = TRUE;
877 gc.flags[FLG_BADFLAG] = TRUE;
878 gc.flags[FLG_WARNFLAGS] = TRUE;
879 gc.flags[FLG_WARNRC] = TRUE;
880 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
881 gc.flags[FLG_WARNUNIXLIB] = TRUE;
882 gc.flags[FLG_WARNPOSIX] = TRUE;
883 gc.flags[FLG_SHOWCOL] = TRUE;
884 gc.flags[FLG_SHOWFUNC] = TRUE;
885 gc.flags[FLG_SUPCOUNTS] = TRUE;
886 gc.flags[FLG_HINTS] = TRUE;
887 gc.flags[FLG_SYNTAX] = TRUE;
888 gc.flags[FLG_TYPE] = TRUE;
889 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
890 gc.flags[FLG_ABSTRACT] = TRUE;
891 gc.flags[FLG_ITERBALANCE] = TRUE;
892 gc.flags[FLG_ITERYIELD] = TRUE;
893 gc.flags[FLG_DUPLICATECASES] = TRUE;
894 gc.flags[FLG_ALWAYSEXITS] = TRUE;
895 gc.flags[FLG_EMPTYRETURN] = TRUE;
896 gc.flags[FLG_MACRORETURN] = TRUE;
897 gc.flags[FLG_UNRECOG] = TRUE;
898 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
899 gc.flags[FLG_LINTCOMMENTS] = TRUE;
900 gc.flags[FLG_ACCESSCZECH] = TRUE;
901 gc.flags[FLG_ACCESSMODULE] = TRUE;
902 gc.flags[FLG_ACCESSFILE] = TRUE;
903 gc.flags[FLG_MACROVARPREFIX] = TRUE;
905 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
906 gc.flags[FLG_COMMENTERROR] = TRUE;
909 ** Changed for version 2.4.
912 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
917 gc.flags[FLG_ORCONSTRAINT] = TRUE;
918 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
921 gc.flags[FLG_WARNSYSFILES] = TRUE;
924 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
928 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
933 ** C is way-lame, and you can initialize an array to a constant except where
934 ** it is declared. Hence, a macro is used to set the modeflags.
938 # define SETFLAGS() \
939 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
940 if (!flagcode_isModeFlag (modeflags[i])) \
941 { llbug (message ("not a mode flag: %s", \
942 flagcode_unparse (modeflags[i]))); } \
943 else { context_setFlag (modeflags[i], TRUE); } i++; }}
945 static void context_setModeAux (cstring p_s, bool p_warn) ;
948 context_setMode (cstring s)
950 context_setModeAux (s, TRUE);
954 context_setModeNoWarn (cstring s)
956 context_setModeAux (s, FALSE);
960 context_setModeAux (cstring s, bool warn)
962 intSet setflags = intSet_new ();
966 if (flagcode_isModeFlag (code))
968 if (gc.setGlobally[code])
970 (void) intSet_insert (setflags, (int) code);
975 if (!intSet_isEmpty (setflags))
977 cstring rflags = cstring_undefined;
980 intSet_elements (setflags, el)
982 if (cstring_isUndefined (rflags))
984 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
988 rflags = message ("%q, %s", rflags,
989 flagcode_unparse ((flagcode) el));
993 if (num > 4 && intSet_size (setflags) > 6)
995 rflags = message ("%q, (%d others) ...", rflags,
996 intSet_size (setflags) - num);
999 } end_intSet_elements ;
1003 voptgenerror (FLG_WARNFLAGS,
1004 message ("Setting mode %s after setting mode flags will "
1005 "override set values of flags: %s",
1010 cstring_free (rflags);
1013 intSet_free (setflags);
1015 context_resetModeFlags ();
1017 if (cstring_equalLit (s, "standard"))
1019 flagcode modeflags[] =
1021 FLG_ENUMINT, FLG_MACROMATCHNAME,
1022 FLG_STRINGLITNOROOM,
1023 FLG_MACROUNDEF, FLG_RELAXQUALS,
1024 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1025 FLG_CHECKSTRICTGLOBALIAS,
1026 FLG_CHECKEDGLOBALIAS,
1027 FLG_CHECKMODGLOBALIAS,
1028 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1029 FLG_UNSIGNEDCOMPARE,
1030 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1032 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1033 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1034 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1035 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1036 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1039 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1040 FLG_MACROSTMT, FLG_MACROPARENS,
1043 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1044 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1049 /* memchecks flags */
1051 FLG_NULLSTATE, FLG_NULLASSIGN,
1052 FLG_NULLPASS, FLG_NULLRET,
1054 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1057 /* memtrans flags */
1076 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1079 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1080 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1083 FLG_STATETRANSFER, FLG_STATEMERGE,
1084 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1086 FLG_IMPCHECKEDSPECGLOBALS,
1087 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1088 FLG_IFEMPTY, FLG_REALCOMPARE,
1089 FLG_BOOLOPS, FLG_PTRNEGATE,
1091 FLG_SHIFTIMPLEMENTATION,
1092 FLG_BUFFEROVERFLOWHIGH,
1099 else if (cstring_equalLit (s, "weak"))
1101 flagcode modeflags[] =
1103 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1104 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1105 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1106 FLG_CHARUNSIGNEDCHAR,
1108 FLG_VARUNUSED, FLG_FUNCUNUSED,
1110 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1113 FLG_BUFFEROVERFLOWHIGH,
1114 FLG_RETSTACK, FLG_PTRNEGATE,
1115 FLG_STATETRANSFER, FLG_STATEMERGE,
1116 FLG_LONGUNSIGNEDINTEGRAL,
1117 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1121 FLG_BUFFEROVERFLOWHIGH,
1127 else if (cstring_equalLit (s, "checks"))
1129 flagcode modeflags[] =
1131 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1132 FLG_STATETRANSFER, FLG_STATEMERGE,
1133 FLG_CHECKSTRICTGLOBALIAS,
1134 FLG_CHECKEDGLOBALIAS,
1135 FLG_CHECKMODGLOBALIAS,
1136 FLG_UNCHECKEDGLOBALIAS,
1138 FLG_STRINGLITNOROOM,
1139 FLG_STRINGLITSMALLER,
1140 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1141 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1142 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1143 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1144 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1145 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1146 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1147 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1148 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1149 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1150 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1151 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1152 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1153 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1160 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1164 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1166 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1167 FLG_EVALORDER, FLG_USEDEF,
1170 /* warn use flags */
1171 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1172 FLG_BUFFEROVERFLOWHIGH,
1174 /* memchecks flags */
1176 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1177 FLG_NULLPASS, FLG_NULLRET,
1179 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1181 /* memtrans flags */
1195 FLG_STATICINITTRANS,
1196 FLG_UNKNOWNINITTRANS,
1199 FLG_ONLYUNQGLOBALTRANS,
1200 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1203 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1204 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1207 FLG_NULLPOINTERARITH,
1208 FLG_SHADOW, FLG_DEPARRAYS,
1209 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1210 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1211 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1212 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1213 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1214 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1215 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1216 FLG_SHIFTIMPLEMENTATION,
1217 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1222 else if (cstring_equalLit (s, "strict"))
1224 flagcode modeflags[] =
1226 FLG_CHECKSTRICTGLOBALIAS,
1227 FLG_CHECKEDGLOBALIAS,
1228 FLG_CHECKMODGLOBALIAS,
1229 FLG_UNCHECKEDGLOBALIAS,
1233 FLG_STRINGLITNOROOM,
1234 FLG_STRINGLITSMALLER,
1235 FLG_STATETRANSFER, FLG_STATEMERGE,
1236 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1237 FLG_ALLGLOBALS, FLG_IMPTYPE,
1238 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1239 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1240 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1241 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1244 FLG_ONLYUNQGLOBALTRANS,
1245 FLG_GLOBALSIMPMODIFIESNOTHING,
1246 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1247 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1248 FLG_USEALLGLOBS, FLG_RETALIAS,
1249 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1250 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1251 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1253 FLG_EXPORTITER, FLG_EXPORTCONST,
1254 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1255 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1257 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1259 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1260 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1261 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1262 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1263 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1264 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1265 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1266 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1268 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1271 FLG_MACROREDEF, FLG_MACROEMPTY,
1272 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1274 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1276 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1277 FLG_MODOBSERVERUNCON,
1282 /* warn use flags */
1283 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1284 FLG_BUFFEROVERFLOWHIGH,
1285 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1287 /* memchecks flags */
1288 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1289 FLG_NULLPASS, FLG_NULLRET,
1291 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1293 /* memtrans flags */
1309 FLG_STATICINITTRANS,
1310 FLG_UNKNOWNINITTRANS,
1312 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1315 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1316 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1320 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1322 FLG_SHADOW, FLG_DEPARRAYS,
1323 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1324 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1325 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1326 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1327 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1328 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1329 FLG_IMPCHECKEDSTRICTSTATICS,
1330 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1331 FLG_IMPCHECKMODINTERNALS,
1332 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1333 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1334 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1335 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1336 FLG_CONTROLNESTDEPTH,
1337 FLG_FORBLOCK, FLG_WHILEBLOCK,
1338 FLG_FOREMPTY, FLG_WHILEEMPTY,
1339 FLG_IFEMPTY, FLG_IFBLOCK,
1341 FLG_REALCOMPARE, FLG_BOOLOPS,
1342 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1345 FLG_SHIFTIMPLEMENTATION,
1347 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1355 llcontbug (message ("context_setMode: bad mode: %s", s));
1360 context_isSpecialFile (cstring fname)
1362 cstring ext = fileLib_getExtension (fname);
1364 return (cstring_equalLit (ext, ".y")
1365 || cstring_equalLit (ext, ".l")
1366 || cstring_equalLit (fname, "lex.yy.c"));
1370 context_isSystemDir (cstring dir)
1372 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1373 cstring savedir = thisdir;
1374 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1376 if (cstring_isDefined (nextdir))
1378 /*@access cstring@*/
1379 *nextdir = '\0'; /* closes thisdir */
1381 /*@noaccess cstring@*/
1384 /* 2001-09-09: added thisdir[0] != '\0'
1385 ** herbert: don't compare with an empty name!
1386 ** should return false for empty directory path
1389 while (!cstring_isEmpty (thisdir))
1391 DPRINTF (("Test: %s / %s", dir, thisdir));
1393 if (osd_equalCanonicalPrefix (dir, thisdir))
1395 cstring_free (savedir);
1399 if (cstring_isDefined (nextdir))
1402 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1404 if (cstring_isDefined (nextdir))
1406 /*@access cstring@*/
1409 /*@noaccess cstring@*/
1418 DPRINTF (("Returns FALSE"));
1419 cstring_free (savedir);
1424 context_addFileAccessType (typeId t)
1428 if (context_inFunctionLike ())
1430 gc.acct = typeIdSet_insert (gc.acct, t);
1433 gc.facct = typeIdSet_insert (gc.facct, t);
1435 base = fileloc_getBase (g_currentloc);
1436 insertModuleAccess (base, t);
1437 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1438 typeIdSet_unparse (gc.acct)));
1442 context_removeFileAccessType (typeId t)
1444 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1445 || gc.kind == CX_UNKNOWNMACRO)
1447 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1450 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1451 gc.nacct = typeIdSet_insert (gc.nacct, t);
1454 void context_enterFunctionHeader (void)
1456 if (context_getFlag (FLG_GRAMMAR))
1458 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1461 if (gc.kind != CX_GLOBAL)
1463 llparseerror (cstring_makeLiteral
1464 ("Likely parse error. Function header outside global context."));
1468 llassert (gc.kind == CX_GLOBAL);
1469 DPRINTF (("Enter function header!"));
1470 gc.inFunctionHeader = TRUE;
1474 void context_exitFunctionHeader (void)
1476 if (context_getFlag (FLG_GRAMMAR))
1478 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1481 DPRINTF (("Exit function header!"));
1482 gc.inFunctionHeader = FALSE;
1485 bool context_inFunctionHeader (void)
1487 return (gc.inFunctionHeader);
1490 void context_enterFunctionDeclaration (uentry e)
1492 if (context_getFlag (FLG_GRAMMAR))
1494 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1497 DPRINTF (("Enter function decl"));
1498 llassert (gc.savekind == CX_ERROR);
1499 gc.savekind = gc.kind;
1500 gc.savecont = gc.cont;
1501 gc.kind = CX_FCNDECLARATION;
1505 void context_exitFunctionDeclaration (void)
1507 if (context_getFlag (FLG_GRAMMAR))
1509 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1512 DPRINTF (("Exit function decl"));
1513 llassert (gc.savekind != CX_ERROR);
1514 llassert (gc.kind == CX_FCNDECLARATION);
1515 gc.kind = gc.savekind;
1516 gc.cont = gc.savecont;
1518 gc.savekind = CX_ERROR;
1520 if (context_getFlag (FLG_GRAMMAR))
1522 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1526 bool context_inFunctionDeclaration (void)
1528 return (gc.kind == CX_FCNDECLARATION);
1533 context_enterMacro (/*@observer@*/ uentry e)
1535 context_enterFunction (e);
1536 gc.kind = CX_MACROFCN;
1540 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1542 llassert (uentry_isFunction (e));
1543 context_enterFunction (e);
1544 gc.kind = CX_UNKNOWNMACRO;
1547 void context_enterAndClause (exprNode e)
1550 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1551 pushClause (ANDCLAUSE);
1554 void context_enterOrClause (exprNode e)
1556 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1557 pushClause (ORCLAUSE);
1560 bool context_inDeepLoop (void)
1562 bool inLoop = FALSE;
1564 clauseStack_elements (gc.clauses, el)
1566 if (clause_isLoop (el))
1575 } end_clauseStack_elements;
1580 bool context_inDeepSwitch (void)
1582 bool inLoop = FALSE;
1584 clauseStack_elements (gc.clauses, el)
1586 if (clause_isSwitch (el))
1595 } end_clauseStack_elements;
1600 bool context_inDeepLoopSwitch (void)
1602 bool inLoop = FALSE;
1604 clauseStack_elements (gc.clauses, el)
1606 if (clause_isBreakable (el))
1615 } end_clauseStack_elements;
1620 clause context_breakClause (void)
1622 clauseStack_elements (gc.clauses, el)
1624 if (clause_isSwitch (el))
1628 else if (clause_isLoop (el))
1636 } end_clauseStack_elements;
1641 clause context_nextBreakClause (void)
1643 bool hasOne = FALSE;
1645 clauseStack_elements (gc.clauses, el)
1647 if (clause_isBreakable (el))
1658 } end_clauseStack_elements;
1663 bool context_inConditional (void)
1665 clauseStack_elements (gc.clauses, el)
1668 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1669 ** to distinguish if from ? for this
1672 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1676 } end_clauseStack_elements;
1681 void context_exitAndClause (exprNode pred, exprNode tbranch)
1683 context_setJustPopped ();
1685 llassert (gc.inclause == ANDCLAUSE);
1687 usymtab_popAndBranch (pred, tbranch);
1688 clauseStack_pop (gc.clauses);
1689 gc.inclause = topClause (gc.clauses);
1692 void context_exitOrClause (exprNode pred, exprNode tbranch)
1694 context_setJustPopped ();
1696 llassert (gc.inclause == ORCLAUSE);
1698 usymtab_popOrBranch (pred, tbranch);
1699 clauseStack_pop (gc.clauses);
1700 gc.inclause = topClause (gc.clauses);
1703 static void context_enterCondClauseAux (clause cl)
1709 static void context_enterTrueAux (exprNode e, clause cl)
1712 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1716 void context_enterIterClause (void)
1718 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1721 void context_enterDoWhileClause (void)
1723 pushClause (DOWHILECLAUSE);
1726 void context_enterWhileClause (exprNode e)
1728 context_enterTrueAux (e, WHILECLAUSE);
1731 void context_enterForClause (exprNode e)
1733 context_enterTrueAux (e, FORCLAUSE);
1736 void context_enterTrueClause (exprNode e)
1738 context_enterTrueAux (e, TRUECLAUSE);
1741 void context_enterSwitch (exprNode e)
1744 usymtab_switchBranch (e);
1745 context_enterCondClauseAux (SWITCHCLAUSE);
1748 void context_exitSwitch (exprNode e, bool allpaths)
1750 usymtab_exitSwitch (e, allpaths);
1752 while (clause_isCase (clauseStack_top (gc.clauses)))
1754 clauseStack_pop (gc.clauses);
1757 context_exitClauseSimp ();
1760 void context_enterCaseClause (exprNode e)
1762 bool branch = FALSE;
1764 DPRINTF (("Enter case clause!"));
1766 branch = usymtab_newCase (exprNode_undefined, e);
1770 context_enterCondClauseAux (CASECLAUSE);
1774 static void context_enterFalseClauseAux (exprNode e, clause cl)
1777 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1779 clauseStack_switchTop (gc.clauses, cl);
1782 void context_enterFalseClause (exprNode e)
1785 context_enterFalseClauseAux (e, FALSECLAUSE);
1789 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1791 gc.kind = CX_MACROCONST;
1793 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1795 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1799 usymtab_enterScope ();
1800 sRef_enterFunctionScope ();
1802 gc.globs = globSet_undefined;
1803 globSet_clear (gc.globs_used);
1804 gc.mods = sRefSet_undefined;
1807 uentry context_getHeader (void)
1809 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1811 llfatalbug (message ("context_getHeader: bad call: %q",
1812 context_unparse ()));
1815 return (gc.cont.fcn);
1819 context_setFunctionDefined (fileloc loc)
1823 case CX_UNKNOWNMACRO:
1826 uentry_setFunctionDefined (gc.cont.fcn, loc);
1829 /* (not a bug because of parse errors) */
1835 context_enterFunction (/*@exposed@*/ uentry e)
1837 gc.kind = CX_FUNCTION;
1840 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1842 if (uentry_hasAccessType (e))
1844 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1852 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1853 typeIdSet_unparse (gc.acct)));
1855 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1857 gc.globs = uentry_getGlobs (e);
1858 globSet_clear (gc.globs_used);
1859 gc.mods = uentry_getMods (e);
1861 usymtab_enterFunctionScope (e);
1862 sRef_enterFunctionScope ();
1866 context_enterOldStyleScope (void)
1868 gc.kind = CX_OLDSTYLESCOPE;
1869 DPRINTF (("Enter old style scope!"));
1870 usymtab_enterFunctionScope (uentry_undefined);
1874 context_completeOldStyleFunction (uentry e)
1876 llassert (gc.kind == CX_OLDSTYLESCOPE);
1878 gc.kind = CX_FUNCTION;
1881 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1883 if (uentry_hasAccessType (e))
1885 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1893 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1894 typeIdSet_unparse (gc.acct)));
1896 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1898 if (!globSet_isEmpty (uentry_getGlobs (e)))
1900 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1901 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1904 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1906 gc.globs = uentry_getGlobs (e);
1907 globSet_clear (gc.globs_used);
1909 gc.mods = uentry_getMods (e);
1911 if (!sRefSet_isEmpty (gc.mods))
1913 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1914 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1917 sRef_enterFunctionScope ();
1920 static bool context_checkStrictGlobals (void)
1922 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1925 static bool context_hasGlobs (void)
1927 if (context_inFunctionLike ())
1929 return (uentry_hasGlobs (gc.cont.fcn));
1937 static bool context_checkCheckedGlobals (void)
1939 return (context_getFlag (FLG_GLOBALS)
1940 && (context_getFlag (FLG_GLOBUNSPEC)
1941 || context_hasGlobs ()));
1944 static bool context_checkUnknownGlobals (void)
1946 /* should be uentry_hasGlobs ? */
1948 return (context_getFlag (FLG_ALLGLOBALS)
1949 && (context_getFlag (FLG_GLOBUNSPEC)
1950 || context_hasGlobs ()));
1953 static bool context_checkUncheckedGlobals (void)
1959 context_checkExport (uentry e)
1961 if (!gc.anyExports) return FALSE;
1963 if (uentry_isFunction (e)
1964 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1966 return context_maybeSet (FLG_EXPORTFCN);
1968 else if (uentry_isExpandedMacro (e))
1970 return context_maybeSet (FLG_EXPORTMACRO);
1972 else if (uentry_isVariable (e))
1974 return context_maybeSet (FLG_EXPORTVAR);
1976 else if (uentry_isEitherConstant (e))
1978 return context_maybeSet (FLG_EXPORTCONST);
1980 else if (uentry_isIter (e) || uentry_isEndIter (e))
1982 return context_maybeSet (FLG_EXPORTITER);
1984 else if (uentry_isDatatype (e))
1986 return context_maybeSet (FLG_EXPORTTYPE);
1995 context_checkGlobUse (uentry glob)
1998 if (uentry_isCheckedStrict (glob))
2000 return context_checkStrictGlobals ();
2002 else if (uentry_isChecked (glob))
2004 return context_checkCheckedGlobals ();
2006 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2008 return context_checkUnknownGlobals ();
2012 llassert (uentry_isUnchecked (glob));
2014 return context_checkUncheckedGlobals ();
2019 context_checkAliasGlob (uentry glob)
2021 if (uentry_isCheckedStrict (glob))
2023 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2025 else if (uentry_isChecked (glob))
2027 return gc.flags[FLG_CHECKEDGLOBALIAS];
2029 else if (uentry_isCheckMod (glob))
2031 return gc.flags[FLG_CHECKMODGLOBALIAS];
2035 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2037 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2041 bool context_checkInternalUse (void)
2043 if (context_hasGlobs ())
2045 return (gc.flags[FLG_INTERNALGLOBS]);
2049 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2054 context_checkGlobMod (sRef el)
2056 uentry ue = sRef_getUentry (el);
2058 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2060 if (uentry_isCheckedModify (ue)
2061 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2063 if (context_hasMods ())
2065 return (gc.flags[FLG_MODGLOBS]);
2069 if (uentry_isCheckedStrict (ue))
2071 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2075 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2081 if (context_hasMods ())
2083 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2093 context_usedGlobal (/*@exposed@*/ sRef el)
2095 if (!globSet_member (gc.globs_used, el))
2098 ** The first time a global is used in a function, we need
2099 ** to clear the derived sRefs, since they were set for the
2100 ** previous function.
2103 sRef_clearDerived (el);
2104 gc.globs_used = globSet_insert (gc.globs_used, el);
2108 /*@observer@*/ sRefSet
2109 context_modList (void)
2115 context_globAccess (sRef s)
2117 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2118 return (globSet_member (gc.globs, s));
2122 context_hasAccess (typeId t)
2124 if (context_inFunctionLike ())
2126 DPRINTF (("Access %d / %s",
2127 t, typeIdSet_unparse (gc.acct)));
2128 return (typeIdSet_member (gc.acct, t));
2132 return (context_hasFileAccess (t));
2137 context_hasFileAccess (typeId t)
2139 return (typeIdSet_member (gc.facct, t));
2143 context_unparseAccess (void)
2145 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2146 typeIdSet_unparse (gc.facct)));
2150 context_unparseClauses (void)
2152 return (clauseStack_unparse (gc.clauses));
2156 context_couldHaveAccess (typeId t)
2158 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2160 return (typeIdSet_member (gc.acct, t));
2164 return (typeIdSet_member (gc.facct, t));
2169 context_getRetType (void)
2171 ctype f = ctype_undefined;
2173 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2175 f = uentry_getType (gc.cont.fcn);
2177 else if (gc.kind == CX_UNKNOWNMACRO)
2179 return ctype_unknown;
2183 llcontbuglit ("context_getRetType: not in a function context");
2184 return ctype_unknown;
2187 if (!ctype_isFunction (f))
2189 if (ctype_isKnown (f))
2191 llbuglit ("context_getRetType: not a function");
2194 return ctype_unknown;
2196 return (ctype_getReturnType (f));
2200 context_hasMods (void)
2202 if (context_inFunctionLike ())
2204 return (uentry_hasMods (gc.cont.fcn));
2213 context_exitAllClauses (void)
2215 while (!clauseStack_isEmpty (gc.clauses))
2217 clause el = clauseStack_top (gc.clauses);
2220 if (clause_isNone (el))
2222 usymtab_quietExitScope (g_currentloc);
2223 clauseStack_pop (gc.clauses);
2227 context_exitClausePlain ();
2231 clauseStack_clear (gc.clauses);
2232 gc.inclause = NOCLAUSE;
2236 context_exitAllClausesQuiet (void)
2238 while (!clauseStack_isEmpty (gc.clauses))
2240 clause el = clauseStack_top (gc.clauses);
2243 usymtab_quietExitScope (g_currentloc);
2244 clauseStack_pop (gc.clauses);
2247 clauseStack_clear (gc.clauses);
2248 gc.inclause = NOCLAUSE;
2252 void context_exitClauseSimp (void)
2255 context_setJustPopped ();
2256 clauseStack_pop (gc.clauses);
2257 gc.inclause = topClause (gc.clauses);
2261 void context_exitCaseClause (void)
2263 context_setJustPopped ();
2264 usymtab_popCaseBranch ();
2265 clauseStack_pop (gc.clauses);
2266 gc.inclause = topClause (gc.clauses);
2270 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2272 context_setJustPopped ();
2273 /*@i32 was makeAlt */
2274 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2275 clauseStack_pop (gc.clauses);
2276 gc.inclause = topClause (gc.clauses);
2279 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2281 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2283 if (gc.inclause != TRUECLAUSE)
2285 llparseerror (cstring_makeLiteral
2286 ("Likely parse error. Conditional clauses are inconsistent."));
2290 context_setJustPopped ();
2291 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2292 clauseStack_pop (gc.clauses);
2293 gc.inclause = topClause (gc.clauses);
2296 void context_exitIterClause (exprNode body)
2298 llassert (gc.inclause == ITERCLAUSE);
2300 context_setJustPopped ();
2302 if (context_getFlag (FLG_ITERLOOPEXEC))
2304 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2308 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2311 clauseStack_pop (gc.clauses);
2312 gc.inclause = topClause (gc.clauses);
2315 static void context_popCase (void) {
2317 ** If we are exiting an outer clause, sometimes still in a switch case.
2331 DPRINTF (("Popping case clause: %s",
2332 clauseStack_unparse (gc.clauses)));
2334 if (gc.inclause == CASECLAUSE) {
2335 context_exitCaseClause ();
2339 void context_exitWhileClause (exprNode pred, exprNode body)
2341 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2345 if (gc.inclause != WHILECLAUSE) {
2346 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2347 clauseStack_unparse (gc.clauses)));
2350 llassert (gc.inclause == WHILECLAUSE);
2352 context_setJustPopped ();
2356 ** predicate must be false after while loop (unless there are breaks)
2359 if (context_getFlag (FLG_WHILELOOPEXEC))
2361 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2365 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2369 usymtab_addGuards (invGuards);
2370 guardSet_free (invGuards);
2372 clauseStack_pop (gc.clauses);
2373 gc.inclause = topClause (gc.clauses);
2376 void context_exitDoWhileClause (exprNode pred)
2378 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2380 if (gc.inclause == CASECLAUSE) {
2381 /* handle Duff's device */
2382 clauseStack_pop (gc.clauses);
2383 gc.inclause = topClause (gc.clauses);
2386 llassert (gc.inclause == DOWHILECLAUSE);
2388 context_setJustPopped ();
2391 usymtab_addGuards (invGuards);
2392 guardSet_free (invGuards);
2394 clauseStack_pop (gc.clauses);
2395 gc.inclause = topClause (gc.clauses);
2398 void context_exitForClause (exprNode forPred, exprNode body)
2400 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2402 llassert (gc.inclause == FORCLAUSE);
2403 context_setJustPopped ();
2405 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2408 ** Predicate must be false after for loop (unless there are breaks)
2411 if (context_getFlag (FLG_FORLOOPEXEC))
2413 DPRINTF (("Here: for loop exec"));
2414 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2418 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2419 && exprNode_loopMustExec (forPred))
2421 DPRINTF (("Here: loop must exec"));
2422 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2426 DPRINTF (("Pop true branch:"));
2427 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2431 usymtab_addGuards (invGuards);
2432 guardSet_free (invGuards);
2433 clauseStack_pop (gc.clauses);
2434 gc.inclause = topClause (gc.clauses);
2437 static void context_exitClausePlain (void)
2439 llassert (gc.inclause != NOCLAUSE);
2441 if (gc.inclause == FALSECLAUSE)
2443 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2447 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2451 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2453 context_setJustPopped ();
2455 if (gc.inclause == FALSECLAUSE)
2457 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2459 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2461 clauseStack_pop (gc.clauses);
2462 gc.inclause = topClause (gc.clauses);
2466 context_exitTrueClause (pred, tbranch);
2471 context_returnFunction (void)
2473 usymtab_checkFinalScope (TRUE);
2477 context_exitFunction (void)
2479 DPRINTF (("Exit function: %s", context_unparse ()));
2481 if (!context_inFunction () && !context_inMacroConstant ()
2482 && !context_inUnknownMacro ()
2483 && !context_inIterDef () && !context_inIterEnd ())
2486 ** not a bug because of parse errors
2493 if (context_inMacro () && usymtab_inFunctionScope ())
2495 usymtab_exitScope (exprNode_undefined);
2498 if (uentry_hasGlobs (gc.cont.fcn))
2500 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2504 if (uentry_hasMods (gc.cont.fcn))
2506 if (context_getFlag (FLG_MUSTMOD))
2508 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2512 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2515 ** clear file static modifies
2518 /* do this first to get unused error messages */
2520 usymtab_exitScope (exprNode_undefined);
2521 sRef_exitFunctionScope ();
2523 gc.showfunction = FALSE;
2524 gc.kind = CX_GLOBAL;
2525 gc.cont.glob = TRUE;
2527 gc.globs = globSet_new ();
2528 globSet_clear (gc.globs_used);
2529 gc.mods = sRefSet_new ();
2532 llassert (clauseStack_isEmpty (gc.clauses));
2533 llassert (gc.inclause == NOCLAUSE);
2534 DPRINTF (("After exit function: %s", context_unparse ()));
2538 context_quietExitFunction (void)
2540 while (gc.kind == CX_INNER)
2542 context_exitInnerPlain ();
2545 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2546 && !context_inIterDef () && !context_inIterEnd ())
2551 usymtab_quietExitScope (g_currentloc);
2553 gc.showfunction = FALSE;
2554 gc.kind = CX_GLOBAL;
2555 gc.cont.glob = TRUE;
2557 gc.globs = globSet_new ();
2558 globSet_clear (gc.globs_used);
2559 gc.mods = sRefSet_new ();
2561 sRef_exitFunctionScope ();
2565 /*@observer@*/ uentryList
2566 context_getParams (void)
2568 if (context_inFunctionLike ())
2570 return (uentry_getParams (gc.cont.fcn));
2574 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2575 return uentryList_undefined;
2579 /*@observer@*/ globSet
2580 context_getUsedGlobs (void)
2582 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2583 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2585 return (gc.globs_used);
2589 context_moduleName ()
2591 return (fileloc_getBase (g_currentloc));
2594 /*@observer@*/ globSet
2595 context_getGlobs (void)
2597 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2598 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2604 context_addBoolAccess (void)
2606 cstring bname = context_getString (FLG_BOOLTYPE);
2607 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2609 addModuleAccess (cstring_copy (bname), boolt);
2611 /* for sys/types (perhaps, this is bogus!) */
2612 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2617 context_canAccessBool (void)
2624 static typeId boolType = typeId_invalid;
2626 if (typeId_isInvalid (boolType))
2628 boolType = usymtab_getTypeId (context_getBoolName ());
2631 if (typeId_isInvalid (boolType)) {
2634 return (typeIdSet_member (gc.acct, boolType));
2639 /* evs 2000-07-25: old version - replaced */
2642 context_boolImplementationType () {
2643 /* For now, this is bogus! */
2648 context_canAccessBool (void)
2650 static typeId boolType = typeId_invalid;
2652 if (typeId_isInvalid (boolType))
2654 boolType = usymtab_getTypeId (context_getBoolName ());
2657 if (!typeId_isInvalid (boolType))
2659 return context_hasAccess (boolType);
2670 context_setMessageAnnote (/*@only@*/ cstring s)
2672 llassert (cstring_isUndefined (gc.msgAnnote));
2677 context_hasMessageAnnote (void)
2679 return (cstring_isDefined (gc.msgAnnote));
2683 context_clearMessageAnnote (void)
2685 if (cstring_isDefined (gc.msgAnnote))
2687 cstring_free (gc.msgAnnote);
2688 gc.msgAnnote = cstring_undefined;
2693 context_getMessageAnnote (void)
2695 cstring st = gc.msgAnnote;
2697 gc.msgAnnote = cstring_undefined;
2702 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2704 llassert (sRef_isInvalid (gc.aliasAnnote));
2705 llassert (!sRef_sameName (s, t));
2707 gc.aliasAnnoteAls = t;
2711 context_hasAliasAnnote (void)
2713 return (sRef_isValid (gc.aliasAnnote));
2717 context_clearAliasAnnote (void)
2719 gc.aliasAnnote = sRef_undefined;
2723 context_getAliasAnnote (void)
2725 sRef ret = gc.aliasAnnote;
2726 sRef als = gc.aliasAnnoteAls;
2728 llassert (sRef_isValid (ret) && sRef_isValid (als));
2730 gc.aliasAnnote = sRef_undefined;
2731 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2735 context_recordFileModifies (sRefSet mods)
2737 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2741 context_recordFileGlobals (globSet mods)
2743 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2744 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2748 context_setCommentMarkerChar (char c)
2750 llassert (c != '\0');
2752 context_setValue (FLG_COMMENTCHAR, (int) c);
2756 context_getCommentMarkerChar (void)
2758 return ((char) context_getValue (FLG_COMMENTCHAR));
2762 context_setValue (flagcode flag, int val)
2764 int index = flagcode_valueIndex (flag);
2766 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2774 llerror_flagWarning (message ("Value for %s must be a positive "
2775 "number (given %d)",
2776 flagcode_unparse (flag), val));
2779 if (flag == FLG_LINELEN && val < MINLINELEN)
2781 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2782 flagcode_unparse (flag),
2788 case FLG_INCLUDENEST:
2789 case FLG_CONTROLNESTDEPTH:
2790 case FLG_STRINGLITERALLEN:
2791 case FLG_NUMSTRUCTFIELDS:
2792 case FLG_NUMENUMMEMBERS:
2793 case FLG_INDENTSPACES:
2796 llerror_flagWarning (message ("Value for %s must be a non-negative "
2797 "number (given %d)",
2798 flagcode_unparse (flag), val));
2807 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2808 gc.values[index] = val;
2812 context_setValueAndFlag (flagcode flag, int val)
2814 gc.flags[flag] = TRUE;
2815 context_setValue (flag, val);
2819 context_getValue (flagcode flag)
2821 int index = flagcode_valueIndex (flag);
2823 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2824 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2825 return (gc.values[index]);
2829 context_getCounter (flagcode flag)
2831 int index = flagcode_valueIndex (flag);
2833 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2834 return (gc.counters[index]);
2838 context_incCounter (flagcode flag)
2840 int index = flagcode_valueIndex (flag);
2842 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2844 gc.counters[index]++;
2848 context_decCounter (flagcode flag)
2850 int index = flagcode_valueIndex (flag);
2852 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2853 gc.counters[index]--;
2856 bool context_showFunction (void)
2858 return (gc.showfunction);
2862 context_setString (flagcode flag, cstring val)
2864 int index = flagcode_stringIndex (flag);
2866 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2868 if (flag == FLG_SYSTEMDIRS)
2870 llassert (cstring_isDefined (val));
2872 if (cstring_firstChar (val) == '\"')
2875 cstring tval = cstring_copy (cstring_suffix (val, 1));
2877 if (cstring_lastChar (tval) != '\"')
2879 int n = cstring_length (tval) - 1;
2881 while (isspace ((int) cstring_getChar (tval, n)))
2886 if (cstring_getChar (tval, n) != '\"')
2888 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2892 cstring otval = tval;
2893 tval = cstring_prefix (tval, n);
2894 cstring_free (otval);
2898 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2899 DPRINTF (("val = %s", val));
2900 cstring_free (tval);
2901 cstring_free (oval);
2905 if (flag == FLG_TMPDIR)
2907 llassert (cstring_isDefined (val));
2909 if (cstring_length (val) == 0)
2912 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2914 else if (cstring_lastChar (val) != CONNECTCHAR)
2916 val = cstring_appendChar (val, CONNECTCHAR);
2924 if (cstring_length (val) >= 1
2925 && cstring_firstChar (val) == '\"')
2927 llerror_flagWarning (message
2928 ("setting %s to string beginning with \". You probably "
2929 "don't meant to have the \"'s.",
2930 flagcode_unparse (flag)));
2933 if (flag == FLG_BOOLTYPE)
2938 gc.strings[index] = val;
2941 static /*@exposed@*/ cstring
2942 context_exposeString (flagcode flag)
2944 int index = flagcode_stringIndex (flag);
2946 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2947 return (gc.strings[index]);
2951 context_getString (flagcode flag)
2953 return (context_exposeString (flag));
2957 context_resetErrors (void)
2962 void context_initMod (void)
2963 /*@globals undef gc; @*/
2965 gc.kind = CX_GLOBAL;
2967 gc.savekind = CX_ERROR;
2968 gc.savecont.glob = FALSE;
2970 gc.instandardlib = FALSE;
2973 gc.linesprocessed = 0;
2974 gc.speclinesprocessed = 0;
2975 gc.insuppressregion = FALSE;
2976 gc.macroMissingParams = FALSE;
2977 gc.preprocessing = FALSE;
2978 gc.incommandline = FALSE;
2979 gc.mc = macrocache_create ();
2981 gc.maxmods = DEFAULTMAXMODS;
2982 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2984 gc.library = FLG_ANSILIB;
2986 gc.locstack = filelocStack_new ();
2987 gc.modrecs = sRefSetList_undefined;
2988 gc.anyExports = FALSE;
2990 gc.ftab = fileTable_create ();
2991 gc.msgLog = messageLog_new ();
2992 gc.inimport = FALSE;
2993 gc.inDerivedFile = FALSE;
2994 gc.inheader = FALSE;
2995 gc.markers = flagMarkerList_new ();
2996 gc.cont.glob = TRUE;
2997 gc.showfunction = FALSE;
2998 gc.msgAnnote = cstring_undefined;
2999 gc.aliasAnnote = sRef_undefined;
3000 gc.aliasAnnoteAls = sRef_undefined;
3001 gc.boolType = ctype_bool;
3002 gc.mods = sRefSet_new ();
3004 gc.saveloc = fileloc_undefined;
3006 gc.inmacrocache = FALSE;
3007 gc.inclause = NOCLAUSE;
3008 gc.clauses = clauseStack_new ();
3009 gc.globs = globSet_new ();
3010 gc.nacct = typeIdSet_emptySet ();
3011 gc.acct = typeIdSet_emptySet ();
3012 gc.facct = typeIdSet_emptySet ();
3013 gc.savedFlags = FALSE;
3014 gc.pushloc = fileloc_undefined;
3015 gc.protectVars = FALSE;
3016 gc.justpopped = FALSE;
3017 gc.isNullGuarded = NO;
3018 gc.globs_used = globSet_undefined;
3022 gc.setGlobally[code] = FALSE;
3023 gc.setLocally[code] = FALSE;
3029 context_resetAllFlags ();
3031 assertSet (gc.flags); /* Can't use global in defines */
3032 assertSet (gc.saveflags);
3033 assertSet (gc.values);
3034 assertSet (gc.strings);
3036 conext_resetAllCounters ();
3037 assertSet (gc.counters);
3039 context_setMode (DEFAULT_MODE);
3041 gc.stateTable = metaStateTable_create ();
3042 gc.annotTable = annotationTable_create ();
3044 gc.inFunctionHeader = FALSE;
3046 DPRINTF (("Annotations: \n%s",
3047 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3048 DPRINTF (("State: \n%s",
3049 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3054 context_typeofZero (void)
3056 ctype ct = ctype_int;
3058 if (context_getFlag (FLG_ZEROPTR))
3060 ct = ctype_makeConj (ct, ctype_voidPointer);
3063 if (context_getFlag (FLG_ZEROBOOL)) {
3064 ct = ctype_makeConj (ct, ctype_bool);
3071 context_typeofOne (void)
3073 ctype ct = ctype_int;
3075 /* 1 is on longer a bool (was before 2.4)
3076 if (!context_getFlag (FLG_ABSTRACTBOOL))
3078 ct = ctype_makeConj (ct, ctype_bool);
3086 context_unparse (void)
3093 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3096 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3099 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3102 s = message ("Inner Context [%d] : %q",
3104 fileloc_unparse (g_currentloc));
3107 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3108 uentry_unparse (gc.cont.fcn),
3109 fileloc_unparse (g_currentloc),
3110 typeIdSet_unparse (gc.acct),
3111 sRefSet_unparse (gc.mods));
3114 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3116 case CX_UNKNOWNMACRO:
3117 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3120 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3123 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3126 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3128 case CX_FCNDECLARATION:
3129 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3132 s = message ("Un-unparseable context: %d", (int) gc.kind);
3136 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3141 context_currentFunctionType (void)
3143 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3145 return (uentry_getType (gc.cont.fcn));
3147 else if (gc.kind == CX_INNER)
3149 llcontbuglit ("context_currentFunctionType: inner context");
3150 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3151 return (context_currentFunctionType ());
3155 llcontbuglit ("context_currentFunctionType: not in function");
3156 return (ctype_undefined);
3161 context_enterInnerContext (void)
3163 if (context_getFlag (FLG_GRAMMAR))
3165 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3168 if (gc.kind == CX_GLOBAL)
3173 else if (gc.kind == CX_INNER)
3182 usymtab_enterScope ();
3183 pushClause (NOCLAUSE);
3187 context_exitInnerPlain (void) /*@modifies gc;@*/
3189 context_exitInner (exprNode_undefined);
3193 context_exitInner (exprNode exp)
3195 if (context_getFlag (FLG_GRAMMAR))
3197 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3200 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3201 ("inclause = %s", clause_nameTaken (gc.inclause)));
3203 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3204 gc.inclause = topClause (gc.clauses);
3206 if (gc.kind == CX_INNER)
3208 if (--gc.cont.cdepth == 0)
3210 gc.kind = CX_GLOBAL;
3211 gc.cont.glob = TRUE;
3216 if (gc.kind == CX_GLOBAL)
3218 llcontbuglit ("Attempt to exit global context");
3223 usymtab_exitScope (exp);
3228 context_enterStructInnerContext (void)
3230 if (context_getFlag (FLG_GRAMMAR))
3232 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3235 if (gc.kind == CX_GLOBAL)
3240 else if (gc.kind == CX_INNER)
3249 usymtab_enterScope ();
3251 if (context_getFlag (FLG_GRAMMAR))
3253 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3258 context_exitStructInnerContext (void)
3260 if (context_getFlag (FLG_GRAMMAR))
3262 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3265 if (gc.kind == CX_INNER)
3267 if (gc.cont.cdepth <= 0)
3269 llcontbuglit ("Attempt to exit inner context with no depth");
3270 gc.kind = CX_GLOBAL;
3271 gc.cont.glob = TRUE;
3277 if (gc.cont.cdepth == 0)
3279 gc.kind = CX_GLOBAL;
3280 gc.cont.glob = TRUE;
3286 if (gc.kind == CX_GLOBAL)
3288 llcontbuglit ("Attempt to exit global context");
3293 usymtab_exitScope (exprNode_undefined);
3295 if (context_getFlag (FLG_GRAMMAR))
3297 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3302 context_exitInnerSafe (void)
3304 if (context_getFlag (FLG_GRAMMAR))
3306 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3309 if (gc.kind == CX_INNER)
3311 if (--gc.cont.cdepth <= 0)
3316 else if (gc.kind == CX_GLOBAL)
3318 llcontbuglit ("Attempt to exit global context");
3323 if (usymtab_inDeepScope ())
3325 usymtab_exitScope (exprNode_undefined);
3331 void setModuleAccess (void)
3333 gc.facct = typeIdSet_emptySet ();
3335 if (fileId_isValid (currentFile ()))
3337 cstring baseName = fileloc_getBase (g_currentloc);
3339 if (context_getFlag (FLG_ACCESSFILE))
3341 if (usymtab_existsType (baseName))
3343 gc.facct = typeIdSet_insert (gc.facct,
3344 usymtab_getTypeId (baseName));
3352 if (context_getFlag (FLG_ACCESSMODULE))
3355 bool hasaccess = FALSE;
3357 for (i = 0; i < gc.nmods; i++)
3359 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3361 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3370 gc.inheader = fileId_isHeader (currentFile ());
3374 llcontbuglit ("Current file not defined\n");
3375 gc.facct = typeIdSet_emptySet ();
3377 gc.inheader = FALSE;
3380 /* 17 Jan 1995: forgot to clear nacct */
3382 gc.nacct = typeIdSet_emptySet ();
3386 context_enterFileAux (void)
3392 context_enterFile (void)
3394 context_enterFileAux ();
3395 usymtab_enterFile ();
3399 context_enterMacroFile (void)
3401 context_enterFileAux ();
3405 context_inFunction (void)
3407 kcontext ck = gc.kind;
3409 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3413 context_inFunctionLike (void)
3415 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3416 || gc.kind == CX_FCNDECLARATION
3417 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3421 context_inRealFunction (void)
3423 kcontext ck = gc.kind;
3425 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3429 context_processAllMacros (void)
3431 usymtab_enterFile ();
3433 gc.inmacrocache = TRUE;
3434 macrocache_processUndefinedElements (gc.mc);
3436 usymtab_exitFile ();
3438 gc.inmacrocache = FALSE;
3439 macrocache_finalize ();
3443 ** this happens once at the end of each C file
3445 ** check each Macro that was defined in current file.c or current file.h
3450 context_processMacros (void)
3452 if (fileId_isValid (currentFile ()))
3455 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3457 gc.inmacrocache = TRUE;
3459 DPRINTF (("Processing macros: %s", cbase));
3460 lastfl = macrocache_processFileElements (gc.mc, cbase);
3461 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3463 cstring_free (cbase);
3465 if (fileloc_isDefined (lastfl))
3467 g_currentloc = fileloc_update (g_currentloc, lastfl);
3471 gc.inmacrocache = FALSE;
3476 context_processingMacros (void)
3478 return (gc.inmacrocache);
3482 context_exitCFile (void)
3484 if (gc.kind != CX_GLOBAL)
3487 (cstring_makeLiteral ("File ended outside global scope"));
3490 if (gc.insuppressregion)
3492 /* gack...don't reverse the order of these lines! ;-> */
3493 gc.insuppressregion = FALSE;
3494 llerrorlit (FLG_SYNTAX,
3495 "File ended in ignore errors region, "
3496 "possible missing /*@end*/");
3499 /* fix up parse errors */
3501 while (!usymtab_inFileScope ())
3503 usymtab_quietExitScope (g_currentloc);
3507 ** Clear the file-specific modifies information.
3510 sRefSetList_elements (gc.modrecs, mods)
3512 sRefSet_clearStatics (mods);
3513 } end_sRefSetList_elements ;
3515 sRefSetList_clear (gc.modrecs);
3517 context_processMacros ();
3520 usymtab_exitFile ();
3522 gc.inDerivedFile = FALSE;
3523 filelocStack_clear (gc.locstack);
3525 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3527 gc.cont.glob = TRUE;
3531 context_restoreFlagSettings ();
3532 gc.savedFlags = FALSE;
3536 DPRINTF (("After exiting file: "));
3537 usymtab_printAll ();
3542 context_exitMacroCache (void)
3544 if (gc.kind != CX_GLOBAL)
3546 if (context_inMacro ())
3547 /* this is okay, file could end without newline in macro */
3549 DPRINTF (("Still in macro: %s",
3550 context_unparse ()));
3551 context_exitFunction ();
3555 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3556 context_unparse ()));
3557 gc.kind = CX_GLOBAL;
3562 ** no longer valid here
3563 ** if (gc.insuppressregion)
3565 ** gc.insuppressregion = FALSE;
3566 ** llerror ("File ended in ignore errors region, possible missing @");
3570 gc.cont.glob = TRUE;
3574 context_saveLocation (void)
3576 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3577 fileloc_free (gc.saveloc);
3578 gc.saveloc = fileloc_copy (g_currentloc);
3582 context_getSaveLocation (void)
3584 fileloc fl = gc.saveloc;
3585 gc.saveloc = fileloc_undefined;
3589 /*@observer@*/ cstring
3590 context_inFunctionName (void)
3592 if (gc.kind == CX_FUNCTION
3593 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3594 || gc.kind == CX_MACROCONST
3595 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3597 return (uentry_rawName (gc.cont.fcn));
3601 llcontbuglit ("context_inFunctionName: not in function");
3602 return (cstring_undefined);
3607 context_userSetFlag (flagcode f, bool b)
3609 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3611 if (f == FLG_NEVERINCLUDE && b)
3613 if (gc.flags[FLG_EXPORTHEADER])
3615 llerror_flagWarning (cstring_makeLiteral
3616 ("setting +neverinclude after +exportheader. "
3617 "Turning off exportheader, since headers are not checked "
3618 "when +neverinclude is used."));
3620 gc.flags[FLG_EXPORTHEADER] = FALSE;
3625 if (f == FLG_EXPORTHEADER && b)
3627 if (gc.flags[FLG_NEVERINCLUDE])
3629 llerror_flagWarning (cstring_makeLiteral
3630 ("setting +exportheader after +neverinclude. "
3631 "Not setting exportheader, since headers are not checked "
3632 "when +neverinclude is used."));
3633 gc.flags[FLG_EXPORTHEADER] = FALSE;
3639 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3641 bool lastsetting = context_getFlag (f);
3643 if (bool_equal (lastsetting, b)
3644 && !flagcode_isSpecialFlag (f)
3645 && !flagcode_isIdemFlag (f)
3646 && !flagcode_hasArgument (f))
3648 llerror_flagWarning (message ("setting %s%s redundant with current value",
3649 cstring_makeLiteralTemp (b ? "+" : "-"),
3650 flagcode_unparse (f)));
3654 if (flagcode_isWarnUseFlag (f) && b)
3656 if (!context_getFlag (FLG_WARNUSE))
3658 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3659 flagcode_unparse (f)));
3665 if (flagcode_isLibraryFlag (f))
3667 if (gc.library != FLG_ANSILIB
3670 llerror_flagWarning (message ("selecting library %s after library %s was "
3671 "selected (only one library may be used)",
3672 flagcode_unparse (f),
3673 flagcode_unparse (gc.library)));
3676 if (f == FLG_UNIXLIB)
3678 if (context_getFlag (FLG_WARNUNIXLIB))
3680 llerror_flagWarning (cstring_makeLiteral
3681 ("selecting unix library. Unix library is "
3682 "ad hoc addition to POSIX library. Recommend "
3683 "use +posixlib to select POSIX library instead. "
3684 "Use -warnunixlib to suppress this message."));
3691 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3693 llerror_flagWarning (message
3694 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3695 flagcode_unparse (f)));
3698 gc.setGlobally[f] = TRUE;
3699 context_setFlag (f, b);
3703 context_fileSetFlag (flagcode f, ynm set)
3707 context_saveFlagSettings ();
3710 if (ynm_isOff (set))
3712 context_setFlagAux (f, FALSE, TRUE, FALSE);
3714 else if (ynm_isOn (set))
3716 context_setFlagAux (f, TRUE, TRUE, FALSE);
3717 gc.setLocally[f] = TRUE;
3721 context_restoreFlag (f);
3726 context_restoreFlag (flagcode f)
3733 message ("Attempt to restore flag %s when no file scope flags "
3735 flagcode_unparse (f)),
3740 context_addFlagMarker (f, MAYBE);
3741 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3747 context_setFlag (flagcode f, bool b)
3749 context_setFlagAux (f, b, FALSE, FALSE);
3753 context_setFlagTemp (flagcode f, bool b)
3755 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3760 # define DOSET(ff,b) \
3761 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3762 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3763 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3764 gc.flags[ff] = b; } while (FALSE)
3767 context_setFlagAux (flagcode f, bool b, bool inFile,
3768 /*@unused@*/ bool isRestore)
3770 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3772 if (f == FLG_USESTDERR)
3775 g_msgstream = stderr;
3777 g_msgstream = stdout;
3782 ** Removed test for special flags.
3785 if (flagcode_isIdemFlag (f))
3794 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3796 if (b) /* Turing higher level on, turns on all lower levels */
3800 case FLG_ITS4MOSTRISKY:
3801 DOSET (FLG_ITS4VERYRISKY, b);
3803 case FLG_ITS4VERYRISKY:
3804 DOSET (FLG_ITS4RISKY, b);
3807 DOSET (FLG_ITS4MODERATERISK, b);
3809 case FLG_ITS4MODERATERISK:
3810 DOSET (FLG_ITS4LOWRISK, b);
3812 case FLG_ITS4LOWRISK:
3817 else /* Turning level off, turns off all higher levels */
3821 case FLG_ITS4LOWRISK:
3822 DOSET (FLG_ITS4MODERATERISK, b);
3824 case FLG_ITS4MODERATERISK:
3825 DOSET (FLG_ITS4RISKY, b);
3828 DOSET (FLG_ITS4VERYRISKY, b);
3830 case FLG_ITS4VERYRISKY:
3831 DOSET (FLG_ITS4MOSTRISKY, b);
3833 case FLG_ITS4MOSTRISKY:
3843 DOSET (FLG_ALLEMPTY, b);
3844 DOSET (FLG_IFEMPTY, b);
3845 DOSET (FLG_WHILEEMPTY, b);
3846 DOSET (FLG_FOREMPTY, b);
3849 DOSET (FLG_PREDBOOL, b);
3850 DOSET (FLG_PREDBOOLINT, b);
3851 DOSET (FLG_PREDBOOLPTR, b);
3852 DOSET (FLG_PREDBOOLOTHERS, b);
3855 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3856 DOSET (FLG_CHECKEDGLOBALIAS, b);
3857 DOSET (FLG_CHECKMODGLOBALIAS, b);
3858 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3861 DOSET (FLG_ALLBLOCK, b);
3862 DOSET (FLG_IFBLOCK, b);
3863 DOSET (FLG_WHILEBLOCK, b);
3864 DOSET (FLG_FORBLOCK, b);
3878 DOSET (FLG_GRAMMAR, b);
3880 case FLG_CODEIMPONLY:
3881 DOSET (FLG_CODEIMPONLY, b);
3882 DOSET (FLG_GLOBIMPONLY, b);
3883 DOSET (FLG_RETIMPONLY, b);
3884 DOSET (FLG_STRUCTIMPONLY, b);
3886 case FLG_SPECALLIMPONLY:
3887 DOSET (FLG_SPECALLIMPONLY, b);
3888 DOSET (FLG_SPECGLOBIMPONLY, b);
3889 DOSET (FLG_SPECRETIMPONLY, b);
3890 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3892 case FLG_ALLIMPONLY:
3893 DOSET (FLG_ALLIMPONLY, b);
3894 DOSET (FLG_GLOBIMPONLY, b);
3895 DOSET (FLG_RETIMPONLY, b);
3896 DOSET (FLG_STRUCTIMPONLY, b);
3897 DOSET (FLG_SPECGLOBIMPONLY, b);
3898 DOSET (FLG_SPECRETIMPONLY, b);
3899 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3901 case FLG_ANSI89LIMITS:
3902 DOSET (FLG_ANSI89LIMITS, b);
3903 DOSET (FLG_CONTROLNESTDEPTH, b);
3904 DOSET (FLG_STRINGLITERALLEN, b);
3905 DOSET (FLG_INCLUDENEST, b);
3906 DOSET (FLG_NUMSTRUCTFIELDS, b);
3907 DOSET (FLG_NUMENUMMEMBERS, b);
3911 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
3912 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
3913 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
3914 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
3915 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
3916 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
3917 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
3920 case FLG_ISO99LIMITS:
3921 DOSET (FLG_ISO99LIMITS, b);
3922 DOSET (FLG_CONTROLNESTDEPTH, b);
3923 DOSET (FLG_STRINGLITERALLEN, b);
3924 DOSET (FLG_INCLUDENEST, b);
3925 DOSET (FLG_NUMSTRUCTFIELDS, b);
3926 DOSET (FLG_NUMENUMMEMBERS, b);
3930 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
3931 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
3932 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
3933 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
3934 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
3935 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
3936 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
3939 case FLG_EXTERNALNAMELEN:
3940 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3941 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3943 case FLG_INTERNALNAMELEN:
3944 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3945 DOSET (FLG_INTERNALNAMELEN, TRUE);
3947 case FLG_EXTERNALNAMECASEINSENSITIVE:
3948 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3950 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3952 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3953 context_setValue (FLG_EXTERNALNAMELEN, 0);
3956 case FLG_INTERNALNAMECASEINSENSITIVE:
3957 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3959 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3961 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3962 context_setValue (FLG_INTERNALNAMELEN, 0);
3965 case FLG_INTERNALNAMELOOKALIKE:
3966 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3968 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3970 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3971 context_setValue (FLG_INTERNALNAMELEN, 0);
3975 DOSET (FLG_MODNOMODS, b);
3976 DOSET (FLG_MODGLOBSUNSPEC, b);
3977 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3980 DOSET (FLG_EXPORTVAR, b);
3981 DOSET (FLG_EXPORTFCN, b);
3982 DOSET (FLG_EXPORTTYPE, b);
3983 DOSET (FLG_EXPORTMACRO, b);
3984 DOSET (FLG_EXPORTCONST, b);
3985 gc.anyExports = TRUE;
3988 DOSET (FLG_RETEXPOSE, b);
3989 DOSET (FLG_ASSIGNEXPOSE, b);
3990 DOSET (FLG_CASTEXPOSE, b);
3993 DOSET (FLG_RETVALBOOL, b);
3994 DOSET (FLG_RETVALINT, b);
3995 DOSET (FLG_RETVALOTHER, b);
4000 DOSET (FLG_EXPORTLOCAL, FALSE);
4001 DOSET (FLG_DECLUNDEF, FALSE);
4002 DOSET (FLG_SPECUNDEF, FALSE);
4003 DOSET (FLG_TOPUNUSED, FALSE);
4007 DOSET (FLG_LOOPLOOPBREAK, b);
4008 DOSET (FLG_LOOPSWITCHBREAK, b);
4009 DOSET (FLG_SWITCHLOOPBREAK, b);
4010 DOSET (FLG_SWITCHSWITCHBREAK, b);
4011 DOSET (FLG_LOOPLOOPCONTINUE, b);
4012 DOSET (FLG_DEEPBREAK, b);
4015 DOSET (FLG_FORLOOPEXEC, b);
4016 DOSET (FLG_WHILELOOPEXEC, b);
4017 DOSET (FLG_ITERLOOPEXEC, b);
4020 DOSET (FLG_ACCESSMODULE, b);
4021 DOSET (FLG_ACCESSFILE, b);
4022 DOSET (FLG_ACCESSCZECH, b);
4025 DOSET (FLG_ALLMACROS, b);
4026 DOSET (FLG_FCNMACROS, b);
4027 DOSET (FLG_CONSTMACROS, b);
4030 DOSET (FLG_BOUNDSREAD, b);
4031 DOSET (FLG_BOUNDSWRITE, b);
4034 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4035 DOSET (FLG_CZECHFUNCTIONS, b);
4036 DOSET (FLG_CZECHVARS, b);
4037 DOSET (FLG_CZECHCONSTANTS, b);
4038 DOSET (FLG_CZECHTYPES, b);
4041 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4042 DOSET (FLG_SLOVAKFUNCTIONS, b);
4043 DOSET (FLG_SLOVAKVARS, b);
4044 DOSET (FLG_SLOVAKCONSTANTS, b);
4045 DOSET (FLG_SLOVAKTYPES, b);
4047 case FLG_CZECHOSLOVAK:
4048 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4049 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4050 DOSET (FLG_CZECHOSLOVAKVARS, b);
4051 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4052 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4055 DOSET (FLG_NULLSTATE, b);
4056 DOSET (FLG_NULLDEREF, b);
4057 DOSET (FLG_NULLASSIGN, b);
4058 DOSET (FLG_NULLPASS, b);
4059 DOSET (FLG_NULLRET, b);
4062 DOSET (FLG_MUSTFREEONLY, b);
4063 DOSET (FLG_MUSTFREEFRESH, b);
4066 DOSET (FLG_NULLSTATE, b);
4067 DOSET (FLG_NULLDEREF, b);
4068 DOSET (FLG_NULLASSIGN, b);
4069 DOSET (FLG_NULLPASS, b);
4070 DOSET (FLG_NULLRET, b);
4071 DOSET (FLG_COMPDEF, b);
4072 DOSET (FLG_COMPMEMPASS, b);
4073 DOSET (FLG_UNIONDEF, b);
4074 DOSET (FLG_MEMTRANS, b);
4075 DOSET (FLG_USERELEASED, b);
4076 DOSET (FLG_ALIASUNIQUE, b);
4077 DOSET (FLG_MAYALIASUNIQUE, b);
4078 DOSET (FLG_MUSTFREEONLY, b);
4079 DOSET (FLG_MUSTFREEFRESH, b);
4080 DOSET (FLG_MUSTDEFINE, b);
4081 DOSET (FLG_GLOBSTATE, b);
4082 DOSET (FLG_COMPDESTROY, b);
4083 DOSET (FLG_MUSTNOTALIAS, b);
4084 DOSET (FLG_MEMIMPLICIT, b);
4085 DOSET (FLG_BRANCHSTATE, b);
4086 /*@fallthrough@*/ /* also sets memtrans flags */
4088 DOSET (FLG_MEMTRANS, b);
4089 DOSET (FLG_EXPOSETRANS, b);
4090 DOSET (FLG_OBSERVERTRANS, b);
4091 DOSET (FLG_DEPENDENTTRANS, b);
4092 DOSET (FLG_NEWREFTRANS, b);
4093 DOSET (FLG_ONLYTRANS, b);
4094 DOSET (FLG_OWNEDTRANS, b);
4095 DOSET (FLG_FRESHTRANS, b);
4096 DOSET (FLG_SHAREDTRANS, b);
4097 DOSET (FLG_TEMPTRANS, b);
4098 DOSET (FLG_KEPTTRANS, b);
4099 DOSET (FLG_REFCOUNTTRANS, b);
4100 DOSET (FLG_STATICTRANS, b);
4101 DOSET (FLG_UNKNOWNTRANS, b);
4102 DOSET (FLG_KEEPTRANS, b);
4103 DOSET (FLG_IMMEDIATETRANS, b);
4110 if (b && !gc.anyExports
4111 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4112 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4113 || f == FLG_EXPORTCONST
4114 || f == FLG_EXPORTANY))
4116 gc.anyExports = TRUE;
4121 context_maybeSet (flagcode d)
4123 return (gc.flags[d] || gc.setLocally[d]);
4127 context_getFlag (flagcode d)
4129 return (gc.flags[d]);
4133 context_flagOn (flagcode f, fileloc loc)
4135 return (!context_suppressFlagMsg (f, loc));
4138 static void context_saveFlagSettings (void)
4140 gc.savedFlags = TRUE;
4141 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4142 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4145 static void context_restoreFlagSettings (void)
4147 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4148 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4149 gc.savedFlags = FALSE;
4152 void context_setFilename (fileId fid, int lineno)
4153 /*@globals fileloc g_currentloc;@*/
4154 /*@modifies g_currentloc@*/
4156 if (fileId_baseEqual (currentFile (), fid))
4163 fileloc_setColumn (g_currentloc, 0);
4165 if (fileloc_isSpecialFile (g_currentloc))
4167 gc.inDerivedFile = TRUE;
4170 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4172 int maxdepth = context_getValue (FLG_INCLUDENEST);
4174 if (filelocStack_size (gc.locstack) > maxdepth)
4176 int depth = filelocStack_includeDepth (gc.locstack);
4178 if (depth > maxdepth)
4182 message ("Maximum include nesting depth "
4183 "(%d, current depth %d) exceeded",
4186 filelocStack_nextTop (gc.locstack)))
4188 filelocStack_printIncludes (gc.locstack);
4194 g_currentloc = fileloc_create (fid, lineno, 1);
4195 gc.inheader = fileId_isHeader (currentFile ());
4197 context_enterFileAux ();
4201 void context_enterIterDef (/*@observer@*/ uentry le)
4203 context_enterMacro (le);
4204 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4205 gc.kind = CX_ITERDEF;
4208 void context_enterIterEnd (/*@observer@*/ uentry le)
4210 context_enterMacro (le);
4211 gc.kind = CX_ITEREND;
4215 context_destroyMod (void)
4216 /*@globals killed gc@*/
4219 ctype_destroyMod ();
4223 fileTable_free (gc.ftab);
4224 filelocStack_free (gc.locstack);
4226 gc.ftab = fileTable_undefined;
4228 macrocache_free (gc.mc);
4229 sfree (gc.moduleaccess);
4232 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4233 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4236 sRefSetList_free (gc.modrecs);
4238 flagMarkerList_free (gc.markers);
4240 messageLog_free (gc.msgLog);
4242 clauseStack_free (gc.clauses);
4245 cstring_free (gc.msgAnnote);
4246 globSet_free (gc.globs_used);
4247 metaStateTable_free (gc.stateTable);
4248 annotationTable_free (gc.annotTable);
4255 bool context_msgBoolInt (void)
4257 return gc.flags [FLG_BOOLINT];
4260 bool context_msgCharInt (void)
4262 return gc.flags [FLG_CHARINT];
4265 bool context_msgEnumInt (void)
4267 return gc.flags [FLG_ENUMINT];
4270 bool context_msgPointerArith (void)
4272 return gc.flags [FLG_POINTERARITH];
4275 bool context_msgStrictOps (void)
4277 return gc.flags [FLG_STRICTOPS];
4281 bool context_msgLh (void)
4283 return gc.flags [FLG_DOLH];
4287 void context_pushLoc (void)
4289 fileloc_free (gc.pushloc);
4290 gc.pushloc = gc.saveloc;
4291 gc.saveloc = fileloc_undefined;
4294 void context_popLoc (void)
4296 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4299 bool context_inGlobalScope (void)
4301 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4304 bool context_inInnerScope (void)
4306 return (gc.kind == CX_INNER);
4309 void context_setProtectVars (void)
4311 gc.protectVars = TRUE;
4314 bool context_anyErrors (void)
4316 return (gc.numerrors > 0);
4319 void context_hasError (void)
4322 DPRINTF (("num errors: %d", gc.numerrors));
4325 int context_numErrors (void)
4327 return gc.numerrors;
4330 bool context_neednl (void)
4335 void context_setNeednl (void)
4340 int context_getExpect (void)
4342 return (context_getValue (FLG_EXPECT));
4346 int context_getLCLExpect (void)
4348 return (context_getValue (FLG_LCLEXPECT));
4352 int context_getLimit (void)
4354 return (context_getValue (FLG_LIMIT));
4357 bool context_unlimitedMessages (void)
4359 return (context_getLimit () < 0);
4362 void context_releaseVars (void)
4364 llassert (gc.protectVars);
4365 gc.protectVars = FALSE;
4368 void context_sizeofReleaseVars (void)
4370 /* If there is a nested sizeof, this might not hold:
4371 llassert (gc.protectVars);
4374 gc.protectVars = FALSE;
4377 bool context_inProtectVars (void)
4379 return (gc.protectVars);
4382 void context_hideShowscan (void)
4384 gc.flags[FLG_SHOWSCAN] = FALSE;
4387 void context_unhideShowscan (void)
4389 gc.flags[FLG_SHOWSCAN] = TRUE;
4392 bool context_inHeader (void)
4394 return (gc.inheader);
4397 fileTable context_fileTable (void)
4402 cstring context_tmpdir (void)
4404 return (context_getString (FLG_TMPDIR));
4407 messageLog context_messageLog (void)
4412 bool context_inMacroFunction (void)
4414 return (gc.kind == CX_MACROFCN);
4417 bool context_inMacroConstant (void)
4419 return (gc.kind == CX_MACROCONST);
4422 bool context_inUnknownMacro (void)
4424 return (gc.kind == CX_UNKNOWNMACRO);
4427 void context_setShownFunction (void)
4429 gc.showfunction = FALSE;
4432 bool context_doDump (void)
4434 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4437 bool context_doMerge (void)
4439 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4442 cstring context_getDump (void)
4444 return context_getString (FLG_DUMP);
4447 cstring context_getMerge (void)
4449 return context_getString (FLG_MERGE);
4453 bool context_inLCLLib (void)
4455 return (gc.kind == CX_LCLLIB);
4458 bool context_inImport (void)
4460 return (gc.inimport);
4463 void context_enterImport (void)
4468 void context_leaveImport (void)
4470 gc.inimport = FALSE;
4474 bool context_inMacro (void)
4476 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4477 || gc.kind == CX_UNKNOWNMACRO
4478 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4481 bool context_inIterDef (void)
4483 return (gc.kind == CX_ITERDEF);
4486 bool context_inIterEnd (void)
4488 return (gc.kind == CX_ITEREND);
4491 int context_getLinesProcessed (void)
4493 return (gc.linesprocessed);
4496 int context_getSpecLinesProcessed (void)
4498 return (gc.speclinesprocessed);
4502 void context_processedSpecLine (void)
4504 gc.speclinesprocessed++;
4507 void context_resetSpecLines (void)
4509 gc.speclinesprocessed = 0;
4513 bool context_inGlobalContext (void)
4515 return (gc.kind == CX_GLOBAL);
4518 static void context_quietExitScopes (void)
4521 ** Try to restore the global scope (after an error).
4524 while (!usymtab_inFileScope ())
4526 usymtab_quietExitScope (g_currentloc);
4529 gc.cont.glob = TRUE;
4530 gc.kind = CX_GLOBAL;
4533 void context_checkGlobalScope (void)
4535 if (gc.kind != CX_GLOBAL)
4537 if (context_inMacro ())
4539 ; /* evans 2001-10-14: Okay to be in a macro here! */
4543 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4544 context_quietExitScopes ();
4549 void context_setFileId (fileId s)
4551 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4554 bool context_setBoolName (void)
4556 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4560 cstring context_printBoolName (void)
4562 if (context_setBoolName ())
4564 return context_getBoolName ();
4568 return cstring_makeLiteralTemp ("boolean");
4572 cstring context_getBoolName (void)
4574 return (context_getString (FLG_BOOLTYPE));
4577 cstring context_getFalseName (void)
4579 return (context_getString (FLG_BOOLFALSE));
4582 cstring context_getTrueName (void)
4584 return (context_getString (FLG_BOOLTRUE));
4587 cstring context_getLarchPath (void)
4589 return (context_getString (FLG_LARCHPATH));
4592 cstring context_getLCLImportDir (void)
4594 return (context_getString (FLG_LCLIMPORTDIR));
4597 static void context_setJustPopped (void)
4599 gc.justpopped = TRUE;
4602 void context_clearJustPopped (void)
4604 gc.justpopped = FALSE;
4607 bool context_justPopped (void)
4609 return (gc.justpopped);
4612 void context_setMacroMissingParams (void)
4614 gc.macroMissingParams = TRUE;
4617 void context_resetMacroMissingParams (void)
4619 gc.macroMissingParams = FALSE;
4622 bool context_isMacroMissingParams (void)
4624 return (gc.macroMissingParams);
4627 void context_showFilelocStack (void)
4629 filelocStack_printIncludes (gc.locstack);
4632 metaStateTable context_getMetaStateTable (void)
4634 return gc.stateTable;
4637 metaStateInfo context_lookupMetaStateInfo (cstring key)
4639 return metaStateTable_lookup (gc.stateTable, key);
4642 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4644 annotationInfo ainfo;
4646 ainfo = annotationTable_lookup (gc.annotTable, annot);
4651 void context_addAnnotation (annotationInfo ainfo)
4653 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4657 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4658 annotationInfo_getLoc (ainfo));
4660 annotationInfo_free (ainfo);
4664 annotationTable_insert (gc.annotTable, ainfo);
4668 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4670 if (metaStateTable_contains (gc.stateTable, mname))
4674 message ("Duplicate metastate declaration: %s", mname),
4675 metaStateInfo_getLoc (msinfo));
4676 cstring_free (mname);
4677 metaStateInfo_free (msinfo);
4681 DPRINTF (("Adding meta state: %s", mname));
4682 metaStateTable_insert (gc.stateTable, mname, msinfo);
4686 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4688 if (metaStateTable_size (gc.stateTable) > 0)
4690 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4691 /*@i32 should use smaller value... */
4692 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4694 metaStateTable_elements (gc.stateTable, msname, msi)
4696 mtContextNode context = metaStateInfo_getContext (msi);
4698 if (mtContextNode_matchesRefStrict (context, s))
4700 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4701 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4705 cstring_copy (metaStateInfo_getName (msi)),
4706 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4707 stateInfo_copy (sinfo)));
4711 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4714 end_metaStateTable_elements ;
4716 stateInfo_free (sinfo);
4717 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4722 stateInfo_free (sinfo);
4723 return valueTable_undefined;
4727 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4729 if (metaStateTable_size (gc.stateTable) > 0)
4731 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4732 /*@i32 should use smaller value... */
4734 metaStateTable_elements (gc.stateTable, msname, msi)
4736 /*@i23 only add global...*/
4737 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4738 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4740 valueTable_insert (res,
4741 cstring_copy (metaStateInfo_getName (msi)),
4742 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4743 stateInfo_copy (sinfo)));
4745 end_metaStateTable_elements ;
4747 stateInfo_free (sinfo);
4748 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4753 stateInfo_free (sinfo);
4754 return valueTable_undefined;
4760 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4764 static ctype lastStruct;
4766 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4772 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4778 /*@unused@*/ static int sInfoNum = 0;
4782 /*@unused@*/ uentry ue;
4783 /*@unused@*/ sRef s;
4787 /*@unused@*/ ctype ct;
4788 /*@unused@*/ constraintList inv;
4789 /*@unused@*/ int ngetUe;
4790 /*@unused@*/ struct getUe * t ;
4794 static struct sInfo globalStructInfo;
4797 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4798 stable release of splint. I coomented them out so that they won't break anything
4799 but didn't delete them because they will be fixed and included later
4803 void setGlobalStructInfo(ctype ct, constraintList list)
4808 f = ctype_getFields (ct);
4810 if (constraintList_isDefined(list) )
4812 globalStructInfo.ct = ct;
4813 globalStructInfo.inv = list;
4815 globalStructInfo.ngetUe = 0;
4817 / *abstraction violation fix it * /
4818 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4820 globalStructInfo.ngetUe = f->nelements;
4824 uentryList_elements(f, ue)
4826 globalStructInfo.t[i].ue = ue;
4827 globalStructInfo.t[i].s = uentry_getSref(ue);
4828 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4829 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4834 end_uentryList_elements;
4840 bool hasInvariants (ctype ct) /*@*/
4842 if ( ctype_sameName(globalStructInfo.ct, ct) )
4852 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4853 stable release of splint. I coomented them out so that they won't break anything
4854 but didn't delete them because they will be fixed and included later
4858 constraintList getInvariants (ctype ct)
4861 llassert(hasInvariants(ct) );
4863 return globalStructInfo.inv;
4868 static int getSref (ctype ct, sRef s)
4877 fprintf(stderr, "getSref: ct = %s (%x)\n", ctype_unparse(ct), ct );
4879 fprintf(stderr,"getSref: s = (%s) %X \n", sRef_unparse(s), s);
4882 while (i < globalStructInfo.ngetUe)
4884 DPRINTF(( message(" getSref:: comparing ue=%s and sRef=%s",
4885 uentry_unparse(globalStructInfo.t[i].ue),
4886 sRef_unparse(globalStructInfo.t[i].s)
4891 fprintf (stderr, " globalStructInfo.t[i].s = %x\n ",
4892 globalStructInfo.t[i].s );
4895 if (sRef_same(globalStructInfo.t[i].s,s) )
4904 sRef fixSref (ctype ct, sRef base, sRef fix)
4909 index = getSref(ct, fix);
4914 ue = globalStructInfo.t[index].ue;
4915 name = uentry_getName(ue);
4916 fix = sRef_buildField(base, name );