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_STRINGLITNOROOMFINALNULL,
1140 FLG_STRINGLITSMALLER,
1141 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1142 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1143 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1144 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1145 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1146 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1147 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1148 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1149 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1150 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1151 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1152 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1153 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1154 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1161 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1165 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1167 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1168 FLG_EVALORDER, FLG_USEDEF,
1171 /* warn use flags */
1172 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1173 FLG_BUFFEROVERFLOWHIGH,
1175 /* memchecks flags */
1177 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1178 FLG_NULLPASS, FLG_NULLRET,
1180 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1182 /* memtrans flags */
1196 FLG_STATICINITTRANS,
1197 FLG_UNKNOWNINITTRANS,
1200 FLG_ONLYUNQGLOBALTRANS,
1201 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1204 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1205 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1208 FLG_NULLPOINTERARITH,
1209 FLG_SHADOW, FLG_DEPARRAYS,
1210 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1211 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1212 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1213 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1214 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1215 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1216 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1217 FLG_SHIFTIMPLEMENTATION,
1218 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1223 else if (cstring_equalLit (s, "strict"))
1225 flagcode modeflags[] =
1227 FLG_CHECKSTRICTGLOBALIAS,
1228 FLG_CHECKEDGLOBALIAS,
1229 FLG_CHECKMODGLOBALIAS,
1230 FLG_UNCHECKEDGLOBALIAS,
1234 FLG_STRINGLITNOROOM,
1235 FLG_STRINGLITNOROOMFINALNULL,
1236 FLG_STRINGLITSMALLER,
1237 FLG_STATETRANSFER, FLG_STATEMERGE,
1238 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1239 FLG_ALLGLOBALS, FLG_IMPTYPE,
1240 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1241 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1242 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1243 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1246 FLG_ONLYUNQGLOBALTRANS,
1247 FLG_GLOBALSIMPMODIFIESNOTHING,
1248 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1249 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1250 FLG_USEALLGLOBS, FLG_RETALIAS,
1251 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1252 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1253 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1255 FLG_EXPORTITER, FLG_EXPORTCONST,
1256 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1257 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1259 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1261 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1262 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1263 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1264 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1265 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1266 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1267 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1268 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1270 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1273 FLG_MACROREDEF, FLG_MACROEMPTY,
1274 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1276 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1278 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1279 FLG_MODOBSERVERUNCON,
1284 /* warn use flags */
1285 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1286 FLG_BUFFEROVERFLOWHIGH,
1287 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1289 /* memchecks flags */
1290 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1291 FLG_NULLPASS, FLG_NULLRET,
1293 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1295 /* memtrans flags */
1311 FLG_STATICINITTRANS,
1312 FLG_UNKNOWNINITTRANS,
1314 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1317 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1318 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1322 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1324 FLG_SHADOW, FLG_DEPARRAYS,
1325 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1326 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1327 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1328 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1329 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1330 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1331 FLG_IMPCHECKEDSTRICTSTATICS,
1332 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1333 FLG_IMPCHECKMODINTERNALS,
1334 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1335 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1336 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1337 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1338 FLG_CONTROLNESTDEPTH,
1339 FLG_FORBLOCK, FLG_WHILEBLOCK,
1340 FLG_FOREMPTY, FLG_WHILEEMPTY,
1341 FLG_IFEMPTY, FLG_IFBLOCK,
1343 FLG_REALCOMPARE, FLG_BOOLOPS,
1344 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1347 FLG_SHIFTIMPLEMENTATION,
1349 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1357 llcontbug (message ("context_setMode: bad mode: %s", s));
1362 context_isSpecialFile (cstring fname)
1364 cstring ext = fileLib_getExtension (fname);
1366 return (cstring_equalLit (ext, ".y")
1367 || cstring_equalLit (ext, ".l")
1368 || cstring_equalLit (fname, "lex.yy.c"));
1372 context_isSystemDir (cstring dir)
1374 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1375 cstring savedir = thisdir;
1376 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1378 if (cstring_isDefined (nextdir))
1380 /*@access cstring@*/
1381 *nextdir = '\0'; /* closes thisdir */
1383 /*@noaccess cstring@*/
1386 /* 2001-09-09: added thisdir[0] != '\0'
1387 ** herbert: don't compare with an empty name!
1388 ** should return false for empty directory path
1391 while (!cstring_isEmpty (thisdir))
1393 DPRINTF (("Test: %s / %s", dir, thisdir));
1395 if (osd_equalCanonicalPrefix (dir, thisdir))
1397 cstring_free (savedir);
1401 if (cstring_isDefined (nextdir))
1404 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1406 if (cstring_isDefined (nextdir))
1408 /*@access cstring@*/
1411 /*@noaccess cstring@*/
1420 DPRINTF (("Returns FALSE"));
1421 cstring_free (savedir);
1426 context_addFileAccessType (typeId t)
1430 if (context_inFunctionLike ())
1432 gc.acct = typeIdSet_insert (gc.acct, t);
1435 gc.facct = typeIdSet_insert (gc.facct, t);
1437 base = fileloc_getBase (g_currentloc);
1438 insertModuleAccess (base, t);
1439 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1440 typeIdSet_unparse (gc.acct)));
1444 context_removeFileAccessType (typeId t)
1446 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1447 || gc.kind == CX_UNKNOWNMACRO)
1449 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1452 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1453 gc.nacct = typeIdSet_insert (gc.nacct, t);
1456 void context_enterFunctionHeader (void)
1458 if (context_getFlag (FLG_GRAMMAR))
1460 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1463 if (gc.kind != CX_GLOBAL)
1465 llparseerror (cstring_makeLiteral
1466 ("Likely parse error. Function header outside global context."));
1470 llassert (gc.kind == CX_GLOBAL);
1471 DPRINTF (("Enter function header!"));
1472 gc.inFunctionHeader = TRUE;
1476 void context_exitFunctionHeader (void)
1478 if (context_getFlag (FLG_GRAMMAR))
1480 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1483 DPRINTF (("Exit function header!"));
1484 gc.inFunctionHeader = FALSE;
1487 bool context_inFunctionHeader (void)
1489 return (gc.inFunctionHeader);
1492 void context_enterFunctionDeclaration (uentry e)
1494 if (context_getFlag (FLG_GRAMMAR))
1496 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1499 DPRINTF (("Enter function decl"));
1500 llassert (gc.savekind == CX_ERROR);
1501 gc.savekind = gc.kind;
1502 gc.savecont = gc.cont;
1503 gc.kind = CX_FCNDECLARATION;
1507 void context_exitFunctionDeclaration (void)
1509 if (context_getFlag (FLG_GRAMMAR))
1511 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1514 DPRINTF (("Exit function decl"));
1515 llassert (gc.savekind != CX_ERROR);
1516 llassert (gc.kind == CX_FCNDECLARATION);
1517 gc.kind = gc.savekind;
1518 gc.cont = gc.savecont;
1520 gc.savekind = CX_ERROR;
1522 if (context_getFlag (FLG_GRAMMAR))
1524 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1528 bool context_inFunctionDeclaration (void)
1530 return (gc.kind == CX_FCNDECLARATION);
1535 context_enterMacro (/*@observer@*/ uentry e)
1537 context_enterFunction (e);
1538 gc.kind = CX_MACROFCN;
1542 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1544 llassert (uentry_isFunction (e));
1545 context_enterFunction (e);
1546 gc.kind = CX_UNKNOWNMACRO;
1549 void context_enterAndClause (exprNode e)
1552 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1553 pushClause (ANDCLAUSE);
1556 void context_enterOrClause (exprNode e)
1558 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1559 pushClause (ORCLAUSE);
1562 bool context_inDeepLoop (void)
1564 bool inLoop = FALSE;
1566 clauseStack_elements (gc.clauses, el)
1568 if (clause_isLoop (el))
1577 } end_clauseStack_elements;
1582 bool context_inDeepSwitch (void)
1584 bool inLoop = FALSE;
1586 clauseStack_elements (gc.clauses, el)
1588 if (clause_isSwitch (el))
1597 } end_clauseStack_elements;
1602 bool context_inDeepLoopSwitch (void)
1604 bool inLoop = FALSE;
1606 clauseStack_elements (gc.clauses, el)
1608 if (clause_isBreakable (el))
1617 } end_clauseStack_elements;
1622 clause context_breakClause (void)
1624 clauseStack_elements (gc.clauses, el)
1626 if (clause_isSwitch (el))
1630 else if (clause_isLoop (el))
1638 } end_clauseStack_elements;
1643 clause context_nextBreakClause (void)
1645 bool hasOne = FALSE;
1647 clauseStack_elements (gc.clauses, el)
1649 if (clause_isBreakable (el))
1660 } end_clauseStack_elements;
1665 bool context_inConditional (void)
1667 clauseStack_elements (gc.clauses, el)
1670 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1671 ** to distinguish if from ? for this
1674 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1678 } end_clauseStack_elements;
1683 void context_exitAndClause (exprNode pred, exprNode tbranch)
1685 context_setJustPopped ();
1687 llassert (gc.inclause == ANDCLAUSE);
1689 usymtab_popAndBranch (pred, tbranch);
1690 clauseStack_pop (gc.clauses);
1691 gc.inclause = topClause (gc.clauses);
1694 void context_exitOrClause (exprNode pred, exprNode tbranch)
1696 context_setJustPopped ();
1698 llassert (gc.inclause == ORCLAUSE);
1700 usymtab_popOrBranch (pred, tbranch);
1701 clauseStack_pop (gc.clauses);
1702 gc.inclause = topClause (gc.clauses);
1705 static void context_enterCondClauseAux (clause cl)
1711 static void context_enterTrueAux (exprNode e, clause cl)
1714 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1718 void context_enterIterClause (void)
1720 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1723 void context_enterDoWhileClause (void)
1725 pushClause (DOWHILECLAUSE);
1728 void context_enterWhileClause (exprNode e)
1730 context_enterTrueAux (e, WHILECLAUSE);
1733 void context_enterForClause (exprNode e)
1735 context_enterTrueAux (e, FORCLAUSE);
1738 void context_enterTrueClause (exprNode e)
1740 context_enterTrueAux (e, TRUECLAUSE);
1743 void context_enterSwitch (exprNode e)
1746 usymtab_switchBranch (e);
1747 context_enterCondClauseAux (SWITCHCLAUSE);
1750 void context_exitSwitch (exprNode e, bool allpaths)
1752 usymtab_exitSwitch (e, allpaths);
1754 while (clause_isCase (clauseStack_top (gc.clauses)))
1756 clauseStack_pop (gc.clauses);
1759 context_exitClauseSimp ();
1762 void context_enterCaseClause (exprNode e)
1764 bool branch = FALSE;
1766 DPRINTF (("Enter case clause!"));
1768 branch = usymtab_newCase (exprNode_undefined, e);
1772 context_enterCondClauseAux (CASECLAUSE);
1776 static void context_enterFalseClauseAux (exprNode e, clause cl)
1779 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1781 clauseStack_switchTop (gc.clauses, cl);
1784 void context_enterFalseClause (exprNode e)
1787 context_enterFalseClauseAux (e, FALSECLAUSE);
1791 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1793 gc.kind = CX_MACROCONST;
1795 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1797 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1801 usymtab_enterScope ();
1802 sRef_enterFunctionScope ();
1804 gc.globs = globSet_undefined;
1805 globSet_clear (gc.globs_used);
1806 gc.mods = sRefSet_undefined;
1809 uentry context_getHeader (void)
1811 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1813 llfatalbug (message ("context_getHeader: bad call: %q",
1814 context_unparse ()));
1817 return (gc.cont.fcn);
1821 context_setFunctionDefined (fileloc loc)
1825 case CX_UNKNOWNMACRO:
1828 uentry_setFunctionDefined (gc.cont.fcn, loc);
1831 /* (not a bug because of parse errors) */
1837 context_enterFunction (/*@exposed@*/ uentry e)
1839 gc.kind = CX_FUNCTION;
1842 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1844 if (uentry_hasAccessType (e))
1846 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1854 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1855 typeIdSet_unparse (gc.acct)));
1857 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1859 gc.globs = uentry_getGlobs (e);
1860 globSet_clear (gc.globs_used);
1861 gc.mods = uentry_getMods (e);
1863 usymtab_enterFunctionScope (e);
1864 sRef_enterFunctionScope ();
1868 context_enterOldStyleScope (void)
1870 gc.kind = CX_OLDSTYLESCOPE;
1871 DPRINTF (("Enter old style scope!"));
1872 usymtab_enterFunctionScope (uentry_undefined);
1876 context_completeOldStyleFunction (uentry e)
1878 llassert (gc.kind == CX_OLDSTYLESCOPE);
1880 gc.kind = CX_FUNCTION;
1883 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1885 if (uentry_hasAccessType (e))
1887 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1895 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1896 typeIdSet_unparse (gc.acct)));
1898 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1900 if (!globSet_isEmpty (uentry_getGlobs (e)))
1902 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1903 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1906 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1908 gc.globs = uentry_getGlobs (e);
1909 globSet_clear (gc.globs_used);
1911 gc.mods = uentry_getMods (e);
1913 if (!sRefSet_isEmpty (gc.mods))
1915 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1916 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1919 sRef_enterFunctionScope ();
1922 static bool context_checkStrictGlobals (void)
1924 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1927 static bool context_hasGlobs (void)
1929 if (context_inFunctionLike ())
1931 return (uentry_hasGlobs (gc.cont.fcn));
1939 static bool context_checkCheckedGlobals (void)
1941 return (context_getFlag (FLG_GLOBALS)
1942 && (context_getFlag (FLG_GLOBUNSPEC)
1943 || context_hasGlobs ()));
1946 static bool context_checkUnknownGlobals (void)
1948 /* should be uentry_hasGlobs ? */
1950 return (context_getFlag (FLG_ALLGLOBALS)
1951 && (context_getFlag (FLG_GLOBUNSPEC)
1952 || context_hasGlobs ()));
1955 static bool context_checkUncheckedGlobals (void)
1961 context_checkExport (uentry e)
1963 if (!gc.anyExports) return FALSE;
1965 if (uentry_isFunction (e)
1966 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1968 return context_maybeSet (FLG_EXPORTFCN);
1970 else if (uentry_isExpandedMacro (e))
1972 return context_maybeSet (FLG_EXPORTMACRO);
1974 else if (uentry_isVariable (e))
1976 return context_maybeSet (FLG_EXPORTVAR);
1978 else if (uentry_isEitherConstant (e))
1980 return context_maybeSet (FLG_EXPORTCONST);
1982 else if (uentry_isIter (e) || uentry_isEndIter (e))
1984 return context_maybeSet (FLG_EXPORTITER);
1986 else if (uentry_isDatatype (e))
1988 return context_maybeSet (FLG_EXPORTTYPE);
1997 context_checkGlobUse (uentry glob)
2000 if (uentry_isCheckedStrict (glob))
2002 return context_checkStrictGlobals ();
2004 else if (uentry_isChecked (glob))
2006 return context_checkCheckedGlobals ();
2008 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2010 return context_checkUnknownGlobals ();
2014 llassert (uentry_isUnchecked (glob));
2016 return context_checkUncheckedGlobals ();
2021 context_checkAliasGlob (uentry glob)
2023 if (uentry_isCheckedStrict (glob))
2025 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2027 else if (uentry_isChecked (glob))
2029 return gc.flags[FLG_CHECKEDGLOBALIAS];
2031 else if (uentry_isCheckMod (glob))
2033 return gc.flags[FLG_CHECKMODGLOBALIAS];
2037 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2039 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2043 bool context_checkInternalUse (void)
2045 if (context_hasGlobs ())
2047 return (gc.flags[FLG_INTERNALGLOBS]);
2051 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2056 context_checkGlobMod (sRef el)
2058 uentry ue = sRef_getUentry (el);
2060 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2062 if (uentry_isCheckedModify (ue)
2063 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2065 if (context_hasMods ())
2067 return (gc.flags[FLG_MODGLOBS]);
2071 if (uentry_isCheckedStrict (ue))
2073 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2077 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2083 if (context_hasMods ())
2085 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2095 context_usedGlobal (/*@exposed@*/ sRef el)
2097 if (!globSet_member (gc.globs_used, el))
2100 ** The first time a global is used in a function, we need
2101 ** to clear the derived sRefs, since they were set for the
2102 ** previous function.
2105 sRef_clearDerived (el);
2106 gc.globs_used = globSet_insert (gc.globs_used, el);
2110 /*@observer@*/ sRefSet
2111 context_modList (void)
2117 context_globAccess (sRef s)
2119 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2120 return (globSet_member (gc.globs, s));
2124 context_hasAccess (typeId t)
2126 if (context_inFunctionLike ())
2128 DPRINTF (("Access %d / %s",
2129 t, typeIdSet_unparse (gc.acct)));
2130 return (typeIdSet_member (gc.acct, t));
2134 return (context_hasFileAccess (t));
2139 context_hasFileAccess (typeId t)
2141 return (typeIdSet_member (gc.facct, t));
2145 context_unparseAccess (void)
2147 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2148 typeIdSet_unparse (gc.facct)));
2152 context_unparseClauses (void)
2154 return (clauseStack_unparse (gc.clauses));
2158 context_couldHaveAccess (typeId t)
2160 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2162 return (typeIdSet_member (gc.acct, t));
2166 return (typeIdSet_member (gc.facct, t));
2171 context_getRetType (void)
2173 ctype f = ctype_undefined;
2175 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2177 f = uentry_getType (gc.cont.fcn);
2179 else if (gc.kind == CX_UNKNOWNMACRO)
2181 return ctype_unknown;
2185 llcontbuglit ("context_getRetType: not in a function context");
2186 return ctype_unknown;
2189 if (!ctype_isFunction (f))
2191 if (ctype_isKnown (f))
2193 llbuglit ("context_getRetType: not a function");
2196 return ctype_unknown;
2198 return (ctype_getReturnType (f));
2202 context_hasMods (void)
2204 if (context_inFunctionLike ())
2206 return (uentry_hasMods (gc.cont.fcn));
2215 context_exitAllClauses (void)
2217 while (!clauseStack_isEmpty (gc.clauses))
2219 clause el = clauseStack_top (gc.clauses);
2222 if (clause_isNone (el))
2224 usymtab_quietExitScope (g_currentloc);
2225 clauseStack_pop (gc.clauses);
2229 context_exitClausePlain ();
2233 clauseStack_clear (gc.clauses);
2234 gc.inclause = NOCLAUSE;
2238 context_exitAllClausesQuiet (void)
2240 while (!clauseStack_isEmpty (gc.clauses))
2242 clause el = clauseStack_top (gc.clauses);
2245 usymtab_quietExitScope (g_currentloc);
2246 clauseStack_pop (gc.clauses);
2249 clauseStack_clear (gc.clauses);
2250 gc.inclause = NOCLAUSE;
2254 void context_exitClauseSimp (void)
2257 context_setJustPopped ();
2258 clauseStack_pop (gc.clauses);
2259 gc.inclause = topClause (gc.clauses);
2263 void context_exitCaseClause (void)
2265 context_setJustPopped ();
2266 usymtab_popCaseBranch ();
2267 clauseStack_pop (gc.clauses);
2268 gc.inclause = topClause (gc.clauses);
2272 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2274 context_setJustPopped ();
2275 /*@i32 was makeAlt */
2276 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2277 clauseStack_pop (gc.clauses);
2278 gc.inclause = topClause (gc.clauses);
2281 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2283 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2285 if (gc.inclause != TRUECLAUSE)
2287 llparseerror (cstring_makeLiteral
2288 ("Likely parse error. Conditional clauses are inconsistent."));
2292 context_setJustPopped ();
2293 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2294 clauseStack_pop (gc.clauses);
2295 gc.inclause = topClause (gc.clauses);
2298 void context_exitIterClause (exprNode body)
2300 llassert (gc.inclause == ITERCLAUSE);
2302 context_setJustPopped ();
2304 if (context_getFlag (FLG_ITERLOOPEXEC))
2306 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2310 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2313 clauseStack_pop (gc.clauses);
2314 gc.inclause = topClause (gc.clauses);
2317 static void context_popCase (void) {
2319 ** If we are exiting an outer clause, sometimes still in a switch case.
2333 DPRINTF (("Popping case clause: %s",
2334 clauseStack_unparse (gc.clauses)));
2336 if (gc.inclause == CASECLAUSE) {
2337 context_exitCaseClause ();
2341 void context_exitWhileClause (exprNode pred, exprNode body)
2343 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2347 if (gc.inclause != WHILECLAUSE) {
2348 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2349 clauseStack_unparse (gc.clauses)));
2352 llassert (gc.inclause == WHILECLAUSE);
2354 context_setJustPopped ();
2358 ** predicate must be false after while loop (unless there are breaks)
2361 if (context_getFlag (FLG_WHILELOOPEXEC))
2363 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2367 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2371 usymtab_addGuards (invGuards);
2372 guardSet_free (invGuards);
2374 clauseStack_pop (gc.clauses);
2375 gc.inclause = topClause (gc.clauses);
2378 void context_exitDoWhileClause (exprNode pred)
2380 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2382 if (gc.inclause == CASECLAUSE) {
2383 /* handle Duff's device */
2384 clauseStack_pop (gc.clauses);
2385 gc.inclause = topClause (gc.clauses);
2388 llassert (gc.inclause == DOWHILECLAUSE);
2390 context_setJustPopped ();
2393 usymtab_addGuards (invGuards);
2394 guardSet_free (invGuards);
2396 clauseStack_pop (gc.clauses);
2397 gc.inclause = topClause (gc.clauses);
2400 void context_exitForClause (exprNode forPred, exprNode body)
2402 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2404 llassert (gc.inclause == FORCLAUSE);
2405 context_setJustPopped ();
2407 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2410 ** Predicate must be false after for loop (unless there are breaks)
2413 if (context_getFlag (FLG_FORLOOPEXEC))
2415 DPRINTF (("Here: for loop exec"));
2416 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2420 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2421 && exprNode_loopMustExec (forPred))
2423 DPRINTF (("Here: loop must exec"));
2424 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2428 DPRINTF (("Pop true branch:"));
2429 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2433 usymtab_addGuards (invGuards);
2434 guardSet_free (invGuards);
2435 clauseStack_pop (gc.clauses);
2436 gc.inclause = topClause (gc.clauses);
2439 static void context_exitClausePlain (void)
2441 llassert (gc.inclause != NOCLAUSE);
2443 if (gc.inclause == FALSECLAUSE)
2445 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2449 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2453 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2455 context_setJustPopped ();
2457 if (gc.inclause == FALSECLAUSE)
2459 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2461 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2463 clauseStack_pop (gc.clauses);
2464 gc.inclause = topClause (gc.clauses);
2468 context_exitTrueClause (pred, tbranch);
2473 context_returnFunction (void)
2475 usymtab_checkFinalScope (TRUE);
2479 context_exitFunction (void)
2481 DPRINTF (("Exit function: %s", context_unparse ()));
2483 if (!context_inFunction () && !context_inMacroConstant ()
2484 && !context_inUnknownMacro ()
2485 && !context_inIterDef () && !context_inIterEnd ())
2488 ** not a bug because of parse errors
2495 if (context_inMacro () && usymtab_inFunctionScope ())
2497 usymtab_exitScope (exprNode_undefined);
2500 if (uentry_hasGlobs (gc.cont.fcn))
2502 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2506 if (uentry_hasMods (gc.cont.fcn))
2508 if (context_getFlag (FLG_MUSTMOD))
2510 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2514 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2517 ** clear file static modifies
2520 /* do this first to get unused error messages */
2522 usymtab_exitScope (exprNode_undefined);
2523 sRef_exitFunctionScope ();
2525 gc.showfunction = FALSE;
2526 gc.kind = CX_GLOBAL;
2527 gc.cont.glob = TRUE;
2529 gc.globs = globSet_new ();
2530 globSet_clear (gc.globs_used);
2531 gc.mods = sRefSet_new ();
2534 llassert (clauseStack_isEmpty (gc.clauses));
2535 llassert (gc.inclause == NOCLAUSE);
2536 DPRINTF (("After exit function: %s", context_unparse ()));
2540 context_quietExitFunction (void)
2542 while (gc.kind == CX_INNER)
2544 context_exitInnerPlain ();
2547 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2548 && !context_inIterDef () && !context_inIterEnd ())
2553 usymtab_quietExitScope (g_currentloc);
2555 gc.showfunction = FALSE;
2556 gc.kind = CX_GLOBAL;
2557 gc.cont.glob = TRUE;
2559 gc.globs = globSet_new ();
2560 globSet_clear (gc.globs_used);
2561 gc.mods = sRefSet_new ();
2563 sRef_exitFunctionScope ();
2567 /*@observer@*/ uentryList
2568 context_getParams (void)
2570 if (context_inFunctionLike ())
2572 return (uentry_getParams (gc.cont.fcn));
2576 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2577 return uentryList_undefined;
2581 /*@observer@*/ globSet
2582 context_getUsedGlobs (void)
2584 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2585 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2587 return (gc.globs_used);
2591 context_moduleName ()
2593 return (fileloc_getBase (g_currentloc));
2596 /*@observer@*/ globSet
2597 context_getGlobs (void)
2599 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2600 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2606 context_addBoolAccess (void)
2608 cstring bname = context_getString (FLG_BOOLTYPE);
2609 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2611 addModuleAccess (cstring_copy (bname), boolt);
2613 /* for sys/types (perhaps, this is bogus!) */
2614 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2619 context_canAccessBool (void)
2626 static typeId boolType = typeId_invalid;
2628 if (typeId_isInvalid (boolType))
2630 boolType = usymtab_getTypeId (context_getBoolName ());
2633 if (typeId_isInvalid (boolType)) {
2636 return (typeIdSet_member (gc.acct, boolType));
2641 /* evs 2000-07-25: old version - replaced */
2644 context_boolImplementationType () {
2645 /* For now, this is bogus! */
2650 context_canAccessBool (void)
2652 static typeId boolType = typeId_invalid;
2654 if (typeId_isInvalid (boolType))
2656 boolType = usymtab_getTypeId (context_getBoolName ());
2659 if (!typeId_isInvalid (boolType))
2661 return context_hasAccess (boolType);
2672 context_setMessageAnnote (/*@only@*/ cstring s)
2674 llassert (cstring_isUndefined (gc.msgAnnote));
2679 context_hasMessageAnnote (void)
2681 return (cstring_isDefined (gc.msgAnnote));
2685 context_clearMessageAnnote (void)
2687 if (cstring_isDefined (gc.msgAnnote))
2689 cstring_free (gc.msgAnnote);
2690 gc.msgAnnote = cstring_undefined;
2695 context_getMessageAnnote (void)
2697 cstring st = gc.msgAnnote;
2699 gc.msgAnnote = cstring_undefined;
2704 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2706 llassert (sRef_isInvalid (gc.aliasAnnote));
2707 llassert (!sRef_sameName (s, t));
2709 gc.aliasAnnoteAls = t;
2713 context_hasAliasAnnote (void)
2715 return (sRef_isValid (gc.aliasAnnote));
2719 context_clearAliasAnnote (void)
2721 gc.aliasAnnote = sRef_undefined;
2725 context_getAliasAnnote (void)
2727 sRef ret = gc.aliasAnnote;
2728 sRef als = gc.aliasAnnoteAls;
2730 llassert (sRef_isValid (ret) && sRef_isValid (als));
2732 gc.aliasAnnote = sRef_undefined;
2733 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2737 context_recordFileModifies (sRefSet mods)
2739 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2743 context_recordFileGlobals (globSet mods)
2745 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2746 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2750 context_setCommentMarkerChar (char c)
2752 llassert (c != '\0');
2754 context_setValue (FLG_COMMENTCHAR, (int) c);
2758 context_getCommentMarkerChar (void)
2760 return ((char) context_getValue (FLG_COMMENTCHAR));
2764 context_setValue (flagcode flag, int val)
2766 int index = flagcode_valueIndex (flag);
2768 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2776 llerror_flagWarning (message ("Value for %s must be a positive "
2777 "number (given %d)",
2778 flagcode_unparse (flag), val));
2781 if (flag == FLG_LINELEN && val < MINLINELEN)
2783 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2784 flagcode_unparse (flag),
2790 case FLG_INCLUDENEST:
2791 case FLG_CONTROLNESTDEPTH:
2792 case FLG_STRINGLITERALLEN:
2793 case FLG_NUMSTRUCTFIELDS:
2794 case FLG_NUMENUMMEMBERS:
2795 case FLG_INDENTSPACES:
2798 llerror_flagWarning (message ("Value for %s must be a non-negative "
2799 "number (given %d)",
2800 flagcode_unparse (flag), val));
2809 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2810 gc.values[index] = val;
2814 context_setValueAndFlag (flagcode flag, int val)
2816 gc.flags[flag] = TRUE;
2817 context_setValue (flag, val);
2821 context_getValue (flagcode flag)
2823 int index = flagcode_valueIndex (flag);
2825 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2826 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2827 return (gc.values[index]);
2831 context_getCounter (flagcode flag)
2833 int index = flagcode_valueIndex (flag);
2835 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2836 return (gc.counters[index]);
2840 context_incCounter (flagcode flag)
2842 int index = flagcode_valueIndex (flag);
2844 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2846 gc.counters[index]++;
2850 context_decCounter (flagcode flag)
2852 int index = flagcode_valueIndex (flag);
2854 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2855 gc.counters[index]--;
2858 bool context_showFunction (void)
2860 return (gc.showfunction);
2864 context_setString (flagcode flag, cstring val)
2866 int index = flagcode_stringIndex (flag);
2868 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2870 if (flag == FLG_SYSTEMDIRS)
2872 llassert (cstring_isDefined (val));
2874 if (cstring_firstChar (val) == '\"')
2877 cstring tval = cstring_copy (cstring_suffix (val, 1));
2879 if (cstring_lastChar (tval) != '\"')
2881 int n = cstring_length (tval) - 1;
2883 while (isspace ((int) cstring_getChar (tval, n)))
2888 if (cstring_getChar (tval, n) != '\"')
2890 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2894 cstring otval = tval;
2895 tval = cstring_prefix (tval, n);
2896 cstring_free (otval);
2900 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2901 DPRINTF (("val = %s", val));
2902 cstring_free (tval);
2903 cstring_free (oval);
2907 if (flag == FLG_TMPDIR)
2909 llassert (cstring_isDefined (val));
2911 if (cstring_length (val) == 0)
2914 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2916 else if (cstring_lastChar (val) != CONNECTCHAR)
2918 val = cstring_appendChar (val, CONNECTCHAR);
2926 if (cstring_length (val) >= 1
2927 && cstring_firstChar (val) == '\"')
2929 llerror_flagWarning (message
2930 ("setting %s to string beginning with \". You probably "
2931 "don't meant to have the \"'s.",
2932 flagcode_unparse (flag)));
2935 if (flag == FLG_BOOLTYPE)
2940 gc.strings[index] = val;
2943 static /*@exposed@*/ cstring
2944 context_exposeString (flagcode flag)
2946 int index = flagcode_stringIndex (flag);
2948 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2949 return (gc.strings[index]);
2953 context_getString (flagcode flag)
2955 return (context_exposeString (flag));
2959 context_resetErrors (void)
2964 void context_initMod (void)
2965 /*@globals undef gc; @*/
2967 gc.kind = CX_GLOBAL;
2969 gc.savekind = CX_ERROR;
2970 gc.savecont.glob = FALSE;
2972 gc.instandardlib = FALSE;
2975 gc.linesprocessed = 0;
2976 gc.speclinesprocessed = 0;
2977 gc.insuppressregion = FALSE;
2978 gc.macroMissingParams = FALSE;
2979 gc.preprocessing = FALSE;
2980 gc.incommandline = FALSE;
2981 gc.mc = macrocache_create ();
2983 gc.maxmods = DEFAULTMAXMODS;
2984 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2986 gc.library = FLG_ANSILIB;
2988 gc.locstack = filelocStack_new ();
2989 gc.modrecs = sRefSetList_undefined;
2990 gc.anyExports = FALSE;
2992 gc.ftab = fileTable_create ();
2993 gc.msgLog = messageLog_new ();
2994 gc.inimport = FALSE;
2995 gc.inDerivedFile = FALSE;
2996 gc.inheader = FALSE;
2997 gc.markers = flagMarkerList_new ();
2998 gc.cont.glob = TRUE;
2999 gc.showfunction = FALSE;
3000 gc.msgAnnote = cstring_undefined;
3001 gc.aliasAnnote = sRef_undefined;
3002 gc.aliasAnnoteAls = sRef_undefined;
3003 gc.boolType = ctype_bool;
3004 gc.mods = sRefSet_new ();
3006 gc.saveloc = fileloc_undefined;
3008 gc.inmacrocache = FALSE;
3009 gc.inclause = NOCLAUSE;
3010 gc.clauses = clauseStack_new ();
3011 gc.globs = globSet_new ();
3012 gc.nacct = typeIdSet_emptySet ();
3013 gc.acct = typeIdSet_emptySet ();
3014 gc.facct = typeIdSet_emptySet ();
3015 gc.savedFlags = FALSE;
3016 gc.pushloc = fileloc_undefined;
3017 gc.protectVars = FALSE;
3018 gc.justpopped = FALSE;
3019 gc.isNullGuarded = NO;
3020 gc.globs_used = globSet_undefined;
3024 gc.setGlobally[code] = FALSE;
3025 gc.setLocally[code] = FALSE;
3031 context_resetAllFlags ();
3033 assertSet (gc.flags); /* Can't use global in defines */
3034 assertSet (gc.saveflags);
3035 assertSet (gc.values);
3036 assertSet (gc.strings);
3038 conext_resetAllCounters ();
3039 assertSet (gc.counters);
3041 context_setMode (DEFAULT_MODE);
3043 gc.stateTable = metaStateTable_create ();
3044 gc.annotTable = annotationTable_create ();
3046 gc.inFunctionHeader = FALSE;
3048 DPRINTF (("Annotations: \n%s",
3049 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3050 DPRINTF (("State: \n%s",
3051 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3056 context_typeofZero (void)
3058 ctype ct = ctype_int;
3060 if (context_getFlag (FLG_ZEROPTR))
3062 ct = ctype_makeConj (ct, ctype_voidPointer);
3065 if (context_getFlag (FLG_ZEROBOOL)) {
3066 ct = ctype_makeConj (ct, ctype_bool);
3073 context_typeofOne (void)
3075 ctype ct = ctype_int;
3077 /* 1 is on longer a bool (was before 2.4)
3078 if (!context_getFlag (FLG_ABSTRACTBOOL))
3080 ct = ctype_makeConj (ct, ctype_bool);
3088 context_unparse (void)
3095 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3098 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3101 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3104 s = message ("Inner Context [%d] : %q",
3106 fileloc_unparse (g_currentloc));
3109 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3110 uentry_unparse (gc.cont.fcn),
3111 fileloc_unparse (g_currentloc),
3112 typeIdSet_unparse (gc.acct),
3113 sRefSet_unparse (gc.mods));
3116 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3118 case CX_UNKNOWNMACRO:
3119 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3122 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3125 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3128 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3130 case CX_FCNDECLARATION:
3131 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3134 s = message ("Un-unparseable context: %d", (int) gc.kind);
3138 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3143 context_currentFunctionType (void)
3145 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3147 return (uentry_getType (gc.cont.fcn));
3149 else if (gc.kind == CX_INNER)
3151 llcontbuglit ("context_currentFunctionType: inner context");
3152 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3153 return (context_currentFunctionType ());
3157 llcontbuglit ("context_currentFunctionType: not in function");
3158 return (ctype_undefined);
3163 context_enterInnerContext (void)
3165 if (context_getFlag (FLG_GRAMMAR))
3167 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3170 if (gc.kind == CX_GLOBAL)
3175 else if (gc.kind == CX_INNER)
3184 usymtab_enterScope ();
3185 pushClause (NOCLAUSE);
3189 context_exitInnerPlain (void) /*@modifies gc;@*/
3191 context_exitInner (exprNode_undefined);
3195 context_exitInner (exprNode exp)
3197 if (context_getFlag (FLG_GRAMMAR))
3199 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3202 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3203 ("inclause = %s", clause_nameTaken (gc.inclause)));
3205 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3206 gc.inclause = topClause (gc.clauses);
3208 if (gc.kind == CX_INNER)
3210 if (--gc.cont.cdepth == 0)
3212 gc.kind = CX_GLOBAL;
3213 gc.cont.glob = TRUE;
3218 if (gc.kind == CX_GLOBAL)
3220 llcontbuglit ("Attempt to exit global context");
3225 usymtab_exitScope (exp);
3230 context_enterStructInnerContext (void)
3232 if (context_getFlag (FLG_GRAMMAR))
3234 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3237 if (gc.kind == CX_GLOBAL)
3242 else if (gc.kind == CX_INNER)
3251 usymtab_enterScope ();
3253 if (context_getFlag (FLG_GRAMMAR))
3255 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3260 context_exitStructInnerContext (void)
3262 if (context_getFlag (FLG_GRAMMAR))
3264 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3267 if (gc.kind == CX_INNER)
3269 if (gc.cont.cdepth <= 0)
3271 llcontbuglit ("Attempt to exit inner context with no depth");
3272 gc.kind = CX_GLOBAL;
3273 gc.cont.glob = TRUE;
3279 if (gc.cont.cdepth == 0)
3281 gc.kind = CX_GLOBAL;
3282 gc.cont.glob = TRUE;
3288 if (gc.kind == CX_GLOBAL)
3290 llcontbuglit ("Attempt to exit global context");
3295 usymtab_exitScope (exprNode_undefined);
3297 if (context_getFlag (FLG_GRAMMAR))
3299 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3304 context_exitInnerSafe (void)
3306 if (context_getFlag (FLG_GRAMMAR))
3308 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3311 if (gc.kind == CX_INNER)
3313 if (--gc.cont.cdepth <= 0)
3318 else if (gc.kind == CX_GLOBAL)
3320 llcontbuglit ("Attempt to exit global context");
3325 if (usymtab_inDeepScope ())
3327 usymtab_exitScope (exprNode_undefined);
3333 void setModuleAccess (void)
3335 gc.facct = typeIdSet_emptySet ();
3337 if (fileId_isValid (currentFile ()))
3339 cstring baseName = fileloc_getBase (g_currentloc);
3341 if (context_getFlag (FLG_ACCESSFILE))
3343 if (usymtab_existsType (baseName))
3345 gc.facct = typeIdSet_insert (gc.facct,
3346 usymtab_getTypeId (baseName));
3354 if (context_getFlag (FLG_ACCESSMODULE))
3357 bool hasaccess = FALSE;
3359 for (i = 0; i < gc.nmods; i++)
3361 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3363 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3372 gc.inheader = fileId_isHeader (currentFile ());
3376 llcontbuglit ("Current file not defined\n");
3377 gc.facct = typeIdSet_emptySet ();
3379 gc.inheader = FALSE;
3382 /* 17 Jan 1995: forgot to clear nacct */
3384 gc.nacct = typeIdSet_emptySet ();
3388 context_enterFileAux (void)
3394 context_enterFile (void)
3396 context_enterFileAux ();
3397 usymtab_enterFile ();
3401 context_enterMacroFile (void)
3403 context_enterFileAux ();
3407 context_inFunction (void)
3409 kcontext ck = gc.kind;
3411 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3415 context_inFunctionLike (void)
3417 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3418 || gc.kind == CX_FCNDECLARATION
3419 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3423 context_inRealFunction (void)
3425 kcontext ck = gc.kind;
3427 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3431 context_processAllMacros (void)
3433 usymtab_enterFile ();
3435 gc.inmacrocache = TRUE;
3436 macrocache_processUndefinedElements (gc.mc);
3438 usymtab_exitFile ();
3440 gc.inmacrocache = FALSE;
3441 macrocache_finalize ();
3445 ** this happens once at the end of each C file
3447 ** check each Macro that was defined in current file.c or current file.h
3452 context_processMacros (void)
3454 if (fileId_isValid (currentFile ()))
3457 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3459 gc.inmacrocache = TRUE;
3461 DPRINTF (("Processing macros: %s", cbase));
3462 lastfl = macrocache_processFileElements (gc.mc, cbase);
3463 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3465 cstring_free (cbase);
3467 if (fileloc_isDefined (lastfl))
3469 g_currentloc = fileloc_update (g_currentloc, lastfl);
3473 gc.inmacrocache = FALSE;
3478 context_processingMacros (void)
3480 return (gc.inmacrocache);
3484 context_exitCFile (void)
3486 if (gc.kind != CX_GLOBAL)
3489 (cstring_makeLiteral ("File ended outside global scope"));
3492 if (gc.insuppressregion)
3494 /* gack...don't reverse the order of these lines! ;-> */
3495 gc.insuppressregion = FALSE;
3496 llerrorlit (FLG_SYNTAX,
3497 "File ended in ignore errors region, "
3498 "possible missing /*@end*/");
3501 /* fix up parse errors */
3503 while (!usymtab_inFileScope ())
3505 usymtab_quietExitScope (g_currentloc);
3509 ** Clear the file-specific modifies information.
3512 sRefSetList_elements (gc.modrecs, mods)
3514 sRefSet_clearStatics (mods);
3515 } end_sRefSetList_elements ;
3517 sRefSetList_clear (gc.modrecs);
3519 context_processMacros ();
3522 usymtab_exitFile ();
3524 gc.inDerivedFile = FALSE;
3525 filelocStack_clear (gc.locstack);
3527 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3529 gc.cont.glob = TRUE;
3533 context_restoreFlagSettings ();
3534 gc.savedFlags = FALSE;
3538 DPRINTF (("After exiting file: "));
3539 usymtab_printAll ();
3544 context_exitMacroCache (void)
3546 if (gc.kind != CX_GLOBAL)
3548 if (context_inMacro ())
3549 /* this is okay, file could end without newline in macro */
3551 DPRINTF (("Still in macro: %s",
3552 context_unparse ()));
3553 context_exitFunction ();
3557 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3558 context_unparse ()));
3559 gc.kind = CX_GLOBAL;
3564 ** no longer valid here
3565 ** if (gc.insuppressregion)
3567 ** gc.insuppressregion = FALSE;
3568 ** llerror ("File ended in ignore errors region, possible missing @");
3572 gc.cont.glob = TRUE;
3576 context_saveLocation (void)
3578 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3579 fileloc_free (gc.saveloc);
3580 gc.saveloc = fileloc_copy (g_currentloc);
3584 context_getSaveLocation (void)
3586 fileloc fl = gc.saveloc;
3587 gc.saveloc = fileloc_undefined;
3591 /*@observer@*/ cstring
3592 context_inFunctionName (void)
3594 if (gc.kind == CX_FUNCTION
3595 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3596 || gc.kind == CX_MACROCONST
3597 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3599 return (uentry_rawName (gc.cont.fcn));
3603 llcontbuglit ("context_inFunctionName: not in function");
3604 return (cstring_undefined);
3609 context_userSetFlag (flagcode f, bool b)
3611 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3613 if (f == FLG_NEVERINCLUDE && b)
3615 if (gc.flags[FLG_EXPORTHEADER])
3617 llerror_flagWarning (cstring_makeLiteral
3618 ("setting +neverinclude after +exportheader. "
3619 "Turning off exportheader, since headers are not checked "
3620 "when +neverinclude is used."));
3622 gc.flags[FLG_EXPORTHEADER] = FALSE;
3627 if (f == FLG_EXPORTHEADER && b)
3629 if (gc.flags[FLG_NEVERINCLUDE])
3631 llerror_flagWarning (cstring_makeLiteral
3632 ("setting +exportheader after +neverinclude. "
3633 "Not setting exportheader, since headers are not checked "
3634 "when +neverinclude is used."));
3635 gc.flags[FLG_EXPORTHEADER] = FALSE;
3641 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3643 bool lastsetting = context_getFlag (f);
3645 if (bool_equal (lastsetting, b)
3646 && !flagcode_isSpecialFlag (f)
3647 && !flagcode_isIdemFlag (f)
3648 && !flagcode_hasArgument (f))
3650 llerror_flagWarning (message ("setting %s%s redundant with current value",
3651 cstring_makeLiteralTemp (b ? "+" : "-"),
3652 flagcode_unparse (f)));
3656 if (flagcode_isWarnUseFlag (f) && b)
3658 if (!context_getFlag (FLG_WARNUSE))
3660 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3661 flagcode_unparse (f)));
3667 if (flagcode_isLibraryFlag (f))
3669 if (gc.library != FLG_ANSILIB
3672 llerror_flagWarning (message ("selecting library %s after library %s was "
3673 "selected (only one library may be used)",
3674 flagcode_unparse (f),
3675 flagcode_unparse (gc.library)));
3678 if (f == FLG_UNIXLIB)
3680 if (context_getFlag (FLG_WARNUNIXLIB))
3682 llerror_flagWarning (cstring_makeLiteral
3683 ("selecting unix library. Unix library is "
3684 "ad hoc addition to POSIX library. Recommend "
3685 "use +posixlib to select POSIX library instead. "
3686 "Use -warnunixlib to suppress this message."));
3693 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3695 llerror_flagWarning (message
3696 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3697 flagcode_unparse (f)));
3700 gc.setGlobally[f] = TRUE;
3701 context_setFlag (f, b);
3705 context_fileSetFlag (flagcode f, ynm set)
3709 context_saveFlagSettings ();
3712 if (ynm_isOff (set))
3714 context_setFlagAux (f, FALSE, TRUE, FALSE);
3716 else if (ynm_isOn (set))
3718 context_setFlagAux (f, TRUE, TRUE, FALSE);
3719 gc.setLocally[f] = TRUE;
3723 context_restoreFlag (f);
3728 context_restoreFlag (flagcode f)
3735 message ("Attempt to restore flag %s when no file scope flags "
3737 flagcode_unparse (f)),
3742 context_addFlagMarker (f, MAYBE);
3743 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3749 context_setFlag (flagcode f, bool b)
3751 context_setFlagAux (f, b, FALSE, FALSE);
3755 context_setFlagTemp (flagcode f, bool b)
3757 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3762 # define DOSET(ff,b) \
3763 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3764 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3765 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3766 gc.flags[ff] = b; } while (FALSE)
3769 context_setFlagAux (flagcode f, bool b, bool inFile,
3770 /*@unused@*/ bool isRestore)
3772 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3774 if (f == FLG_USESTDERR)
3777 g_msgstream = stderr;
3779 g_msgstream = stdout;
3784 ** Removed test for special flags.
3787 if (flagcode_isIdemFlag (f))
3796 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3798 if (b) /* Turing higher level on, turns on all lower levels */
3802 case FLG_ITS4MOSTRISKY:
3803 DOSET (FLG_ITS4VERYRISKY, b);
3805 case FLG_ITS4VERYRISKY:
3806 DOSET (FLG_ITS4RISKY, b);
3809 DOSET (FLG_ITS4MODERATERISK, b);
3811 case FLG_ITS4MODERATERISK:
3812 DOSET (FLG_ITS4LOWRISK, b);
3814 case FLG_ITS4LOWRISK:
3819 else /* Turning level off, turns off all higher levels */
3823 case FLG_ITS4LOWRISK:
3824 DOSET (FLG_ITS4MODERATERISK, b);
3826 case FLG_ITS4MODERATERISK:
3827 DOSET (FLG_ITS4RISKY, b);
3830 DOSET (FLG_ITS4VERYRISKY, b);
3832 case FLG_ITS4VERYRISKY:
3833 DOSET (FLG_ITS4MOSTRISKY, b);
3835 case FLG_ITS4MOSTRISKY:
3845 DOSET (FLG_ALLEMPTY, b);
3846 DOSET (FLG_IFEMPTY, b);
3847 DOSET (FLG_WHILEEMPTY, b);
3848 DOSET (FLG_FOREMPTY, b);
3851 DOSET (FLG_PREDBOOL, b);
3852 DOSET (FLG_PREDBOOLINT, b);
3853 DOSET (FLG_PREDBOOLPTR, b);
3854 DOSET (FLG_PREDBOOLOTHERS, b);
3857 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3858 DOSET (FLG_CHECKEDGLOBALIAS, b);
3859 DOSET (FLG_CHECKMODGLOBALIAS, b);
3860 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3863 DOSET (FLG_ALLBLOCK, b);
3864 DOSET (FLG_IFBLOCK, b);
3865 DOSET (FLG_WHILEBLOCK, b);
3866 DOSET (FLG_FORBLOCK, b);
3880 DOSET (FLG_GRAMMAR, b);
3882 case FLG_CODEIMPONLY:
3883 DOSET (FLG_CODEIMPONLY, b);
3884 DOSET (FLG_GLOBIMPONLY, b);
3885 DOSET (FLG_RETIMPONLY, b);
3886 DOSET (FLG_STRUCTIMPONLY, b);
3888 case FLG_SPECALLIMPONLY:
3889 DOSET (FLG_SPECALLIMPONLY, b);
3890 DOSET (FLG_SPECGLOBIMPONLY, b);
3891 DOSET (FLG_SPECRETIMPONLY, b);
3892 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3894 case FLG_ALLIMPONLY:
3895 DOSET (FLG_ALLIMPONLY, b);
3896 DOSET (FLG_GLOBIMPONLY, b);
3897 DOSET (FLG_RETIMPONLY, b);
3898 DOSET (FLG_STRUCTIMPONLY, b);
3899 DOSET (FLG_SPECGLOBIMPONLY, b);
3900 DOSET (FLG_SPECRETIMPONLY, b);
3901 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3903 case FLG_ANSI89LIMITS:
3904 DOSET (FLG_ANSI89LIMITS, b);
3905 DOSET (FLG_CONTROLNESTDEPTH, b);
3906 DOSET (FLG_STRINGLITERALLEN, b);
3907 DOSET (FLG_INCLUDENEST, b);
3908 DOSET (FLG_NUMSTRUCTFIELDS, b);
3909 DOSET (FLG_NUMENUMMEMBERS, b);
3913 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
3914 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
3915 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
3916 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
3917 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
3918 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
3919 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
3922 case FLG_ISO99LIMITS:
3923 DOSET (FLG_ISO99LIMITS, b);
3924 DOSET (FLG_CONTROLNESTDEPTH, b);
3925 DOSET (FLG_STRINGLITERALLEN, b);
3926 DOSET (FLG_INCLUDENEST, b);
3927 DOSET (FLG_NUMSTRUCTFIELDS, b);
3928 DOSET (FLG_NUMENUMMEMBERS, b);
3932 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
3933 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
3934 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
3935 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
3936 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
3937 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
3938 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
3941 case FLG_EXTERNALNAMELEN:
3942 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3943 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3945 case FLG_INTERNALNAMELEN:
3946 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3947 DOSET (FLG_INTERNALNAMELEN, TRUE);
3949 case FLG_EXTERNALNAMECASEINSENSITIVE:
3950 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3952 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3954 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3955 context_setValue (FLG_EXTERNALNAMELEN, 0);
3958 case FLG_INTERNALNAMECASEINSENSITIVE:
3959 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3961 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3963 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3964 context_setValue (FLG_INTERNALNAMELEN, 0);
3967 case FLG_INTERNALNAMELOOKALIKE:
3968 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3970 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3972 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3973 context_setValue (FLG_INTERNALNAMELEN, 0);
3977 DOSET (FLG_MODNOMODS, b);
3978 DOSET (FLG_MODGLOBSUNSPEC, b);
3979 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3982 DOSET (FLG_EXPORTVAR, b);
3983 DOSET (FLG_EXPORTFCN, b);
3984 DOSET (FLG_EXPORTTYPE, b);
3985 DOSET (FLG_EXPORTMACRO, b);
3986 DOSET (FLG_EXPORTCONST, b);
3987 gc.anyExports = TRUE;
3990 DOSET (FLG_RETEXPOSE, b);
3991 DOSET (FLG_ASSIGNEXPOSE, b);
3992 DOSET (FLG_CASTEXPOSE, b);
3995 DOSET (FLG_RETVALBOOL, b);
3996 DOSET (FLG_RETVALINT, b);
3997 DOSET (FLG_RETVALOTHER, b);
4002 DOSET (FLG_EXPORTLOCAL, FALSE);
4003 DOSET (FLG_DECLUNDEF, FALSE);
4004 DOSET (FLG_SPECUNDEF, FALSE);
4005 DOSET (FLG_TOPUNUSED, FALSE);
4009 DOSET (FLG_LOOPLOOPBREAK, b);
4010 DOSET (FLG_LOOPSWITCHBREAK, b);
4011 DOSET (FLG_SWITCHLOOPBREAK, b);
4012 DOSET (FLG_SWITCHSWITCHBREAK, b);
4013 DOSET (FLG_LOOPLOOPCONTINUE, b);
4014 DOSET (FLG_DEEPBREAK, b);
4017 DOSET (FLG_FORLOOPEXEC, b);
4018 DOSET (FLG_WHILELOOPEXEC, b);
4019 DOSET (FLG_ITERLOOPEXEC, b);
4022 DOSET (FLG_ACCESSMODULE, b);
4023 DOSET (FLG_ACCESSFILE, b);
4024 DOSET (FLG_ACCESSCZECH, b);
4027 DOSET (FLG_ALLMACROS, b);
4028 DOSET (FLG_FCNMACROS, b);
4029 DOSET (FLG_CONSTMACROS, b);
4032 DOSET (FLG_BOUNDSREAD, b);
4033 DOSET (FLG_BOUNDSWRITE, b);
4036 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4037 DOSET (FLG_CZECHFUNCTIONS, b);
4038 DOSET (FLG_CZECHVARS, b);
4039 DOSET (FLG_CZECHCONSTANTS, b);
4040 DOSET (FLG_CZECHTYPES, b);
4043 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4044 DOSET (FLG_SLOVAKFUNCTIONS, b);
4045 DOSET (FLG_SLOVAKVARS, b);
4046 DOSET (FLG_SLOVAKCONSTANTS, b);
4047 DOSET (FLG_SLOVAKTYPES, b);
4049 case FLG_CZECHOSLOVAK:
4050 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4051 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4052 DOSET (FLG_CZECHOSLOVAKVARS, b);
4053 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4054 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4057 DOSET (FLG_NULLSTATE, b);
4058 DOSET (FLG_NULLDEREF, b);
4059 DOSET (FLG_NULLASSIGN, b);
4060 DOSET (FLG_NULLPASS, b);
4061 DOSET (FLG_NULLRET, b);
4064 DOSET (FLG_MUSTFREEONLY, b);
4065 DOSET (FLG_MUSTFREEFRESH, b);
4068 DOSET (FLG_NULLSTATE, b);
4069 DOSET (FLG_NULLDEREF, b);
4070 DOSET (FLG_NULLASSIGN, b);
4071 DOSET (FLG_NULLPASS, b);
4072 DOSET (FLG_NULLRET, b);
4073 DOSET (FLG_COMPDEF, b);
4074 DOSET (FLG_COMPMEMPASS, b);
4075 DOSET (FLG_UNIONDEF, b);
4076 DOSET (FLG_MEMTRANS, b);
4077 DOSET (FLG_USERELEASED, b);
4078 DOSET (FLG_ALIASUNIQUE, b);
4079 DOSET (FLG_MAYALIASUNIQUE, b);
4080 DOSET (FLG_MUSTFREEONLY, b);
4081 DOSET (FLG_MUSTFREEFRESH, b);
4082 DOSET (FLG_MUSTDEFINE, b);
4083 DOSET (FLG_GLOBSTATE, b);
4084 DOSET (FLG_COMPDESTROY, b);
4085 DOSET (FLG_MUSTNOTALIAS, b);
4086 DOSET (FLG_MEMIMPLICIT, b);
4087 DOSET (FLG_BRANCHSTATE, b);
4088 /*@fallthrough@*/ /* also sets memtrans flags */
4090 DOSET (FLG_MEMTRANS, b);
4091 DOSET (FLG_EXPOSETRANS, b);
4092 DOSET (FLG_OBSERVERTRANS, b);
4093 DOSET (FLG_DEPENDENTTRANS, b);
4094 DOSET (FLG_NEWREFTRANS, b);
4095 DOSET (FLG_ONLYTRANS, b);
4096 DOSET (FLG_OWNEDTRANS, b);
4097 DOSET (FLG_FRESHTRANS, b);
4098 DOSET (FLG_SHAREDTRANS, b);
4099 DOSET (FLG_TEMPTRANS, b);
4100 DOSET (FLG_KEPTTRANS, b);
4101 DOSET (FLG_REFCOUNTTRANS, b);
4102 DOSET (FLG_STATICTRANS, b);
4103 DOSET (FLG_UNKNOWNTRANS, b);
4104 DOSET (FLG_KEEPTRANS, b);
4105 DOSET (FLG_IMMEDIATETRANS, b);
4112 if (b && !gc.anyExports
4113 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4114 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4115 || f == FLG_EXPORTCONST
4116 || f == FLG_EXPORTANY))
4118 gc.anyExports = TRUE;
4123 context_maybeSet (flagcode d)
4125 return (gc.flags[d] || gc.setLocally[d]);
4129 context_getFlag (flagcode d)
4131 return (gc.flags[d]);
4135 context_flagOn (flagcode f, fileloc loc)
4137 return (!context_suppressFlagMsg (f, loc));
4140 static void context_saveFlagSettings (void)
4142 gc.savedFlags = TRUE;
4143 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4144 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4147 static void context_restoreFlagSettings (void)
4149 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4150 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4151 gc.savedFlags = FALSE;
4154 void context_setFilename (fileId fid, int lineno)
4155 /*@globals fileloc g_currentloc;@*/
4156 /*@modifies g_currentloc@*/
4158 if (fileId_baseEqual (currentFile (), fid))
4165 fileloc_setColumn (g_currentloc, 0);
4167 if (fileloc_isSpecialFile (g_currentloc))
4169 gc.inDerivedFile = TRUE;
4172 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4174 int maxdepth = context_getValue (FLG_INCLUDENEST);
4176 if (filelocStack_size (gc.locstack) > maxdepth)
4178 int depth = filelocStack_includeDepth (gc.locstack);
4180 if (depth > maxdepth)
4184 message ("Maximum include nesting depth "
4185 "(%d, current depth %d) exceeded",
4188 filelocStack_nextTop (gc.locstack)))
4190 filelocStack_printIncludes (gc.locstack);
4196 g_currentloc = fileloc_create (fid, lineno, 1);
4197 gc.inheader = fileId_isHeader (currentFile ());
4199 context_enterFileAux ();
4203 void context_enterIterDef (/*@observer@*/ uentry le)
4205 context_enterMacro (le);
4206 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4207 gc.kind = CX_ITERDEF;
4210 void context_enterIterEnd (/*@observer@*/ uentry le)
4212 context_enterMacro (le);
4213 gc.kind = CX_ITEREND;
4217 context_destroyMod (void)
4218 /*@globals killed gc@*/
4221 ctype_destroyMod ();
4225 fileTable_free (gc.ftab);
4226 filelocStack_free (gc.locstack);
4228 gc.ftab = fileTable_undefined;
4230 macrocache_free (gc.mc);
4231 sfree (gc.moduleaccess);
4234 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4235 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4238 sRefSetList_free (gc.modrecs);
4240 flagMarkerList_free (gc.markers);
4242 messageLog_free (gc.msgLog);
4244 clauseStack_free (gc.clauses);
4247 cstring_free (gc.msgAnnote);
4248 globSet_free (gc.globs_used);
4249 metaStateTable_free (gc.stateTable);
4250 annotationTable_free (gc.annotTable);
4257 bool context_msgBoolInt (void)
4259 return gc.flags [FLG_BOOLINT];
4262 bool context_msgCharInt (void)
4264 return gc.flags [FLG_CHARINT];
4267 bool context_msgEnumInt (void)
4269 return gc.flags [FLG_ENUMINT];
4272 bool context_msgPointerArith (void)
4274 return gc.flags [FLG_POINTERARITH];
4277 bool context_msgStrictOps (void)
4279 return gc.flags [FLG_STRICTOPS];
4283 bool context_msgLh (void)
4285 return gc.flags [FLG_DOLH];
4289 void context_pushLoc (void)
4291 fileloc_free (gc.pushloc);
4292 gc.pushloc = gc.saveloc;
4293 gc.saveloc = fileloc_undefined;
4296 void context_popLoc (void)
4298 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4301 bool context_inGlobalScope (void)
4303 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4306 bool context_inInnerScope (void)
4308 return (gc.kind == CX_INNER);
4311 void context_setProtectVars (void)
4313 gc.protectVars = TRUE;
4316 bool context_anyErrors (void)
4318 return (gc.numerrors > 0);
4321 void context_hasError (void)
4324 DPRINTF (("num errors: %d", gc.numerrors));
4327 int context_numErrors (void)
4329 return gc.numerrors;
4332 bool context_neednl (void)
4337 void context_setNeednl (void)
4342 int context_getExpect (void)
4344 return (context_getValue (FLG_EXPECT));
4348 int context_getLCLExpect (void)
4350 return (context_getValue (FLG_LCLEXPECT));
4354 int context_getLimit (void)
4356 return (context_getValue (FLG_LIMIT));
4359 bool context_unlimitedMessages (void)
4361 return (context_getLimit () < 0);
4364 void context_releaseVars (void)
4366 llassert (gc.protectVars);
4367 gc.protectVars = FALSE;
4370 void context_sizeofReleaseVars (void)
4372 /* If there is a nested sizeof, this might not hold:
4373 llassert (gc.protectVars);
4376 gc.protectVars = FALSE;
4379 bool context_inProtectVars (void)
4381 return (gc.protectVars);
4384 void context_hideShowscan (void)
4386 gc.flags[FLG_SHOWSCAN] = FALSE;
4389 void context_unhideShowscan (void)
4391 gc.flags[FLG_SHOWSCAN] = TRUE;
4394 bool context_inHeader (void)
4396 return (gc.inheader);
4399 fileTable context_fileTable (void)
4404 cstring context_tmpdir (void)
4406 return (context_getString (FLG_TMPDIR));
4409 messageLog context_messageLog (void)
4414 bool context_inMacroFunction (void)
4416 return (gc.kind == CX_MACROFCN);
4419 bool context_inMacroConstant (void)
4421 return (gc.kind == CX_MACROCONST);
4424 bool context_inUnknownMacro (void)
4426 return (gc.kind == CX_UNKNOWNMACRO);
4429 void context_setShownFunction (void)
4431 gc.showfunction = FALSE;
4434 bool context_doDump (void)
4436 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4439 bool context_doMerge (void)
4441 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4444 cstring context_getDump (void)
4446 return context_getString (FLG_DUMP);
4449 cstring context_getMerge (void)
4451 return context_getString (FLG_MERGE);
4455 bool context_inLCLLib (void)
4457 return (gc.kind == CX_LCLLIB);
4460 bool context_inImport (void)
4462 return (gc.inimport);
4465 void context_enterImport (void)
4470 void context_leaveImport (void)
4472 gc.inimport = FALSE;
4476 bool context_inMacro (void)
4478 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4479 || gc.kind == CX_UNKNOWNMACRO
4480 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4483 bool context_inIterDef (void)
4485 return (gc.kind == CX_ITERDEF);
4488 bool context_inIterEnd (void)
4490 return (gc.kind == CX_ITEREND);
4493 int context_getLinesProcessed (void)
4495 return (gc.linesprocessed);
4498 int context_getSpecLinesProcessed (void)
4500 return (gc.speclinesprocessed);
4504 void context_processedSpecLine (void)
4506 gc.speclinesprocessed++;
4509 void context_resetSpecLines (void)
4511 gc.speclinesprocessed = 0;
4515 bool context_inGlobalContext (void)
4517 return (gc.kind == CX_GLOBAL);
4520 static void context_quietExitScopes (void)
4523 ** Try to restore the global scope (after an error).
4526 while (!usymtab_inFileScope ())
4528 usymtab_quietExitScope (g_currentloc);
4531 gc.cont.glob = TRUE;
4532 gc.kind = CX_GLOBAL;
4535 void context_checkGlobalScope (void)
4537 if (gc.kind != CX_GLOBAL)
4539 if (context_inMacro ())
4541 ; /* evans 2001-10-14: Okay to be in a macro here! */
4545 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4546 context_quietExitScopes ();
4551 void context_setFileId (fileId s)
4553 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4556 bool context_setBoolName (void)
4558 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4562 cstring context_printBoolName (void)
4564 if (context_setBoolName ())
4566 return context_getBoolName ();
4570 return cstring_makeLiteralTemp ("boolean");
4574 cstring context_getBoolName (void)
4576 return (context_getString (FLG_BOOLTYPE));
4579 cstring context_getFalseName (void)
4581 return (context_getString (FLG_BOOLFALSE));
4584 cstring context_getTrueName (void)
4586 return (context_getString (FLG_BOOLTRUE));
4589 cstring context_getLarchPath (void)
4591 return (context_getString (FLG_LARCHPATH));
4594 cstring context_getLCLImportDir (void)
4596 return (context_getString (FLG_LCLIMPORTDIR));
4599 static void context_setJustPopped (void)
4601 gc.justpopped = TRUE;
4604 void context_clearJustPopped (void)
4606 gc.justpopped = FALSE;
4609 bool context_justPopped (void)
4611 return (gc.justpopped);
4614 void context_setMacroMissingParams (void)
4616 gc.macroMissingParams = TRUE;
4619 void context_resetMacroMissingParams (void)
4621 gc.macroMissingParams = FALSE;
4624 bool context_isMacroMissingParams (void)
4626 return (gc.macroMissingParams);
4629 void context_showFilelocStack (void)
4631 filelocStack_printIncludes (gc.locstack);
4634 metaStateTable context_getMetaStateTable (void)
4636 return gc.stateTable;
4639 metaStateInfo context_lookupMetaStateInfo (cstring key)
4641 return metaStateTable_lookup (gc.stateTable, key);
4644 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4646 annotationInfo ainfo;
4648 ainfo = annotationTable_lookup (gc.annotTable, annot);
4653 void context_addAnnotation (annotationInfo ainfo)
4655 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4659 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4660 annotationInfo_getLoc (ainfo));
4662 annotationInfo_free (ainfo);
4666 annotationTable_insert (gc.annotTable, ainfo);
4670 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4672 if (metaStateTable_contains (gc.stateTable, mname))
4676 message ("Duplicate metastate declaration: %s", mname),
4677 metaStateInfo_getLoc (msinfo));
4678 cstring_free (mname);
4679 metaStateInfo_free (msinfo);
4683 DPRINTF (("Adding meta state: %s", mname));
4684 metaStateTable_insert (gc.stateTable, mname, msinfo);
4688 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4690 if (metaStateTable_size (gc.stateTable) > 0)
4692 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4693 /*@i32 should use smaller value... */
4694 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4696 metaStateTable_elements (gc.stateTable, msname, msi)
4698 mtContextNode context = metaStateInfo_getContext (msi);
4700 if (mtContextNode_matchesRefStrict (context, s))
4702 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4703 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4707 cstring_copy (metaStateInfo_getName (msi)),
4708 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4709 stateInfo_copy (sinfo)));
4713 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4716 end_metaStateTable_elements ;
4718 stateInfo_free (sinfo);
4719 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4724 stateInfo_free (sinfo);
4725 return valueTable_undefined;
4729 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4731 if (metaStateTable_size (gc.stateTable) > 0)
4733 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4734 /*@i32 should use smaller value... */
4736 metaStateTable_elements (gc.stateTable, msname, msi)
4738 /*@i23 only add global...*/
4739 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4740 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4742 valueTable_insert (res,
4743 cstring_copy (metaStateInfo_getName (msi)),
4744 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4745 stateInfo_copy (sinfo)));
4747 end_metaStateTable_elements ;
4749 stateInfo_free (sinfo);
4750 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4755 stateInfo_free (sinfo);
4756 return valueTable_undefined;
4762 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4766 static ctype lastStruct;
4768 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4774 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4780 /*@unused@*/ static int sInfoNum = 0;
4784 /*@unused@*/ uentry ue;
4785 /*@unused@*/ sRef s;
4789 /*@unused@*/ ctype ct;
4790 /*@unused@*/ constraintList inv;
4791 /*@unused@*/ int ngetUe;
4792 /*@unused@*/ struct getUe * t ;
4796 static struct sInfo globalStructInfo;
4799 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4800 stable release of splint. I coomented them out so that they won't break anything
4801 but didn't delete them because they will be fixed and included later
4805 void setGlobalStructInfo(ctype ct, constraintList list)
4810 f = ctype_getFields (ct);
4812 if (constraintList_isDefined(list) )
4814 globalStructInfo.ct = ct;
4815 globalStructInfo.inv = list;
4817 globalStructInfo.ngetUe = 0;
4819 / *abstraction violation fix it * /
4820 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4822 globalStructInfo.ngetUe = f->nelements;
4826 uentryList_elements(f, ue)
4828 globalStructInfo.t[i].ue = ue;
4829 globalStructInfo.t[i].s = uentry_getSref(ue);
4830 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4831 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4836 end_uentryList_elements;
4842 bool hasInvariants (ctype ct) /*@*/
4844 if ( ctype_sameName(globalStructInfo.ct, ct) )
4854 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4855 stable release of splint. I coomented them out so that they won't break anything
4856 but didn't delete them because they will be fixed and included later
4860 constraintList getInvariants (ctype ct)
4863 llassert(hasInvariants(ct) );
4865 return globalStructInfo.inv;
4870 static int getSref (ctype ct, sRef s)
4879 fprintf(stderr, "getSref: ct = %s (%x)\n", ctype_unparse(ct), ct );
4881 fprintf(stderr,"getSref: s = (%s) %X \n", sRef_unparse(s), s);
4884 while (i < globalStructInfo.ngetUe)
4886 DPRINTF(( message(" getSref:: comparing ue=%s and sRef=%s",
4887 uentry_unparse(globalStructInfo.t[i].ue),
4888 sRef_unparse(globalStructInfo.t[i].s)
4893 fprintf (stderr, " globalStructInfo.t[i].s = %x\n ",
4894 globalStructInfo.t[i].s );
4897 if (sRef_same(globalStructInfo.t[i].s,s) )
4906 sRef fixSref (ctype ct, sRef base, sRef fix)
4911 index = getSref(ct, fix);
4916 ue = globalStructInfo.t[index].ue;
4917 name = uentry_getName(ue);
4918 fix = sRef_buildField(base, name );