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;
918 /* commenting ou until some output issues are fixed */
919 /* gc.flags[FLG_ORCONSTRAINT] = TRUE;*/
921 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
924 gc.flags[FLG_WARNSYSFILES] = TRUE;
927 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
931 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
936 ** C is way-lame, and you can initialize an array to a constant except where
937 ** it is declared. Hence, a macro is used to set the modeflags.
941 # define SETFLAGS() \
942 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
943 if (!flagcode_isModeFlag (modeflags[i])) \
944 { llbug (message ("not a mode flag: %s", \
945 flagcode_unparse (modeflags[i]))); } \
946 else { context_setFlag (modeflags[i], TRUE); } i++; }}
948 static void context_setModeAux (cstring p_s, bool p_warn) ;
951 context_setMode (cstring s)
953 context_setModeAux (s, TRUE);
957 context_setModeNoWarn (cstring s)
959 context_setModeAux (s, FALSE);
963 context_setModeAux (cstring s, bool warn)
965 intSet setflags = intSet_new ();
969 if (flagcode_isModeFlag (code))
971 if (gc.setGlobally[code])
973 (void) intSet_insert (setflags, (int) code);
978 if (!intSet_isEmpty (setflags))
980 cstring rflags = cstring_undefined;
983 intSet_elements (setflags, el)
985 if (cstring_isUndefined (rflags))
987 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
991 rflags = message ("%q, %s", rflags,
992 flagcode_unparse ((flagcode) el));
996 if (num > 4 && intSet_size (setflags) > 6)
998 rflags = message ("%q, (%d others) ...", rflags,
999 intSet_size (setflags) - num);
1002 } end_intSet_elements ;
1006 voptgenerror (FLG_WARNFLAGS,
1007 message ("Setting mode %s after setting mode flags will "
1008 "override set values of flags: %s",
1013 cstring_free (rflags);
1016 intSet_free (setflags);
1018 context_resetModeFlags ();
1020 if (cstring_equalLit (s, "standard"))
1022 flagcode modeflags[] =
1024 FLG_ENUMINT, FLG_MACROMATCHNAME,
1025 FLG_STRINGLITNOROOM,
1026 FLG_MACROUNDEF, FLG_RELAXQUALS,
1027 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1028 FLG_CHECKSTRICTGLOBALIAS,
1029 FLG_CHECKEDGLOBALIAS,
1030 FLG_CHECKMODGLOBALIAS,
1031 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1032 FLG_UNSIGNEDCOMPARE,
1033 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1035 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1036 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1037 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1038 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1039 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1042 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1043 FLG_MACROSTMT, FLG_MACROPARENS,
1046 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1047 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1052 /* memchecks flags */
1054 FLG_NULLSTATE, FLG_NULLASSIGN,
1055 FLG_NULLPASS, FLG_NULLRET,
1057 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1060 /* memtrans flags */
1079 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1082 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1083 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1086 FLG_STATETRANSFER, FLG_STATEMERGE,
1087 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1089 FLG_IMPCHECKEDSPECGLOBALS,
1090 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1091 FLG_IFEMPTY, FLG_REALCOMPARE,
1092 FLG_BOOLOPS, FLG_PTRNEGATE,
1094 FLG_SHIFTIMPLEMENTATION,
1095 FLG_BUFFEROVERFLOWHIGH,
1102 else if (cstring_equalLit (s, "weak"))
1104 flagcode modeflags[] =
1106 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1107 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1108 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1109 FLG_CHARUNSIGNEDCHAR,
1111 FLG_VARUNUSED, FLG_FUNCUNUSED,
1113 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1116 FLG_BUFFEROVERFLOWHIGH,
1117 FLG_RETSTACK, FLG_PTRNEGATE,
1118 FLG_STATETRANSFER, FLG_STATEMERGE,
1119 FLG_LONGUNSIGNEDINTEGRAL,
1120 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1124 FLG_BUFFEROVERFLOWHIGH,
1130 else if (cstring_equalLit (s, "checks"))
1132 flagcode modeflags[] =
1134 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1135 FLG_STATETRANSFER, FLG_STATEMERGE,
1136 FLG_CHECKSTRICTGLOBALIAS,
1137 FLG_CHECKEDGLOBALIAS,
1138 FLG_CHECKMODGLOBALIAS,
1139 FLG_UNCHECKEDGLOBALIAS,
1141 FLG_STRINGLITNOROOM,
1142 FLG_STRINGLITNOROOMFINALNULL,
1143 FLG_STRINGLITSMALLER,
1144 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1145 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1146 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1147 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1148 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1149 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1150 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1151 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1152 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1153 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1154 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1155 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1156 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1157 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1164 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1168 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1170 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1171 FLG_EVALORDER, FLG_USEDEF,
1174 /* warn use flags */
1175 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1176 FLG_BUFFEROVERFLOWHIGH,
1178 /* memchecks flags */
1180 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1181 FLG_NULLPASS, FLG_NULLRET,
1183 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1185 /* memtrans flags */
1199 FLG_STATICINITTRANS,
1200 FLG_UNKNOWNINITTRANS,
1203 FLG_ONLYUNQGLOBALTRANS,
1204 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1207 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1208 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1211 FLG_NULLPOINTERARITH,
1212 FLG_SHADOW, FLG_DEPARRAYS,
1213 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1214 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1215 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1216 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1217 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1218 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1219 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1220 FLG_SHIFTIMPLEMENTATION,
1221 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1226 else if (cstring_equalLit (s, "strict"))
1228 flagcode modeflags[] =
1230 FLG_CHECKSTRICTGLOBALIAS,
1231 FLG_CHECKEDGLOBALIAS,
1232 FLG_CHECKMODGLOBALIAS,
1233 FLG_UNCHECKEDGLOBALIAS,
1237 FLG_STRINGLITNOROOM,
1238 FLG_STRINGLITNOROOMFINALNULL,
1239 FLG_STRINGLITSMALLER,
1240 FLG_STATETRANSFER, FLG_STATEMERGE,
1241 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1242 FLG_ALLGLOBALS, FLG_IMPTYPE,
1243 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1244 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1245 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1246 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1249 FLG_ONLYUNQGLOBALTRANS,
1250 FLG_GLOBALSIMPMODIFIESNOTHING,
1251 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1252 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1253 FLG_USEALLGLOBS, FLG_RETALIAS,
1254 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1255 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1256 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1258 FLG_EXPORTITER, FLG_EXPORTCONST,
1259 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1260 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1262 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1264 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1265 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1266 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1267 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1268 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1269 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1270 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1271 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1273 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1276 FLG_MACROREDEF, FLG_MACROEMPTY,
1277 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1279 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1281 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1282 FLG_MODOBSERVERUNCON,
1287 /* warn use flags */
1288 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1289 FLG_BUFFEROVERFLOWHIGH,
1290 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1292 /* memchecks flags */
1293 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1294 FLG_NULLPASS, FLG_NULLRET,
1296 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1298 /* memtrans flags */
1314 FLG_STATICINITTRANS,
1315 FLG_UNKNOWNINITTRANS,
1317 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1320 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1321 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1325 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1327 FLG_SHADOW, FLG_DEPARRAYS,
1328 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1329 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1330 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1331 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1332 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1333 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1334 FLG_IMPCHECKEDSTRICTSTATICS,
1335 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1336 FLG_IMPCHECKMODINTERNALS,
1337 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1338 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1339 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1340 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1341 FLG_CONTROLNESTDEPTH,
1342 FLG_FORBLOCK, FLG_WHILEBLOCK,
1343 FLG_FOREMPTY, FLG_WHILEEMPTY,
1344 FLG_IFEMPTY, FLG_IFBLOCK,
1346 FLG_REALCOMPARE, FLG_BOOLOPS,
1347 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1350 FLG_SHIFTIMPLEMENTATION,
1352 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1360 llcontbug (message ("context_setMode: bad mode: %s", s));
1365 context_isSpecialFile (cstring fname)
1367 cstring ext = fileLib_getExtension (fname);
1369 return (cstring_equalLit (ext, ".y")
1370 || cstring_equalLit (ext, ".l")
1371 || cstring_equalLit (fname, "lex.yy.c"));
1375 context_isSystemDir (cstring dir)
1377 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1378 cstring savedir = thisdir;
1379 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1381 if (cstring_isDefined (nextdir))
1383 /*@access cstring@*/
1384 *nextdir = '\0'; /* closes thisdir */
1386 /*@noaccess cstring@*/
1389 /* 2001-09-09: added thisdir[0] != '\0'
1390 ** herbert: don't compare with an empty name!
1391 ** should return false for empty directory path
1394 while (!cstring_isEmpty (thisdir))
1396 DPRINTF (("Test: %s / %s", dir, thisdir));
1398 if (osd_equalCanonicalPrefix (dir, thisdir))
1400 cstring_free (savedir);
1404 if (cstring_isDefined (nextdir))
1407 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1409 if (cstring_isDefined (nextdir))
1411 /*@access cstring@*/
1414 /*@noaccess cstring@*/
1423 DPRINTF (("Returns FALSE"));
1424 cstring_free (savedir);
1429 context_addFileAccessType (typeId t)
1433 if (context_inFunctionLike ())
1435 gc.acct = typeIdSet_insert (gc.acct, t);
1438 gc.facct = typeIdSet_insert (gc.facct, t);
1440 base = fileloc_getBase (g_currentloc);
1441 insertModuleAccess (base, t);
1442 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1443 typeIdSet_unparse (gc.acct)));
1447 context_removeFileAccessType (typeId t)
1449 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1450 || gc.kind == CX_UNKNOWNMACRO)
1452 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1455 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1456 gc.nacct = typeIdSet_insert (gc.nacct, t);
1459 void context_enterFunctionHeader (void)
1461 if (context_getFlag (FLG_GRAMMAR))
1463 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1466 if (gc.kind != CX_GLOBAL)
1468 llparseerror (cstring_makeLiteral
1469 ("Likely parse error. Function header outside global context."));
1473 llassert (gc.kind == CX_GLOBAL);
1474 DPRINTF (("Enter function header!"));
1475 gc.inFunctionHeader = TRUE;
1479 void context_exitFunctionHeader (void)
1481 if (context_getFlag (FLG_GRAMMAR))
1483 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1486 DPRINTF (("Exit function header!"));
1487 gc.inFunctionHeader = FALSE;
1490 bool context_inFunctionHeader (void)
1492 return (gc.inFunctionHeader);
1495 void context_enterFunctionDeclaration (uentry e)
1497 if (context_getFlag (FLG_GRAMMAR))
1499 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1502 DPRINTF (("Enter function decl"));
1503 llassert (gc.savekind == CX_ERROR);
1504 gc.savekind = gc.kind;
1505 gc.savecont = gc.cont;
1506 gc.kind = CX_FCNDECLARATION;
1510 void context_exitFunctionDeclaration (void)
1512 if (context_getFlag (FLG_GRAMMAR))
1514 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1517 DPRINTF (("Exit function decl"));
1518 llassert (gc.savekind != CX_ERROR);
1519 llassert (gc.kind == CX_FCNDECLARATION);
1520 gc.kind = gc.savekind;
1521 gc.cont = gc.savecont;
1523 gc.savekind = CX_ERROR;
1525 if (context_getFlag (FLG_GRAMMAR))
1527 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1531 bool context_inFunctionDeclaration (void)
1533 return (gc.kind == CX_FCNDECLARATION);
1538 context_enterMacro (/*@observer@*/ uentry e)
1540 context_enterFunction (e);
1541 gc.kind = CX_MACROFCN;
1545 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1547 llassert (uentry_isFunction (e));
1548 context_enterFunction (e);
1549 gc.kind = CX_UNKNOWNMACRO;
1552 void context_enterAndClause (exprNode e)
1555 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1556 pushClause (ANDCLAUSE);
1559 void context_enterOrClause (exprNode e)
1561 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1562 pushClause (ORCLAUSE);
1565 bool context_inDeepLoop (void)
1567 bool inLoop = FALSE;
1569 clauseStack_elements (gc.clauses, el)
1571 if (clause_isLoop (el))
1580 } end_clauseStack_elements;
1585 bool context_inDeepSwitch (void)
1587 bool inLoop = FALSE;
1589 clauseStack_elements (gc.clauses, el)
1591 if (clause_isSwitch (el))
1600 } end_clauseStack_elements;
1605 bool context_inDeepLoopSwitch (void)
1607 bool inLoop = FALSE;
1609 clauseStack_elements (gc.clauses, el)
1611 if (clause_isBreakable (el))
1620 } end_clauseStack_elements;
1625 clause context_breakClause (void)
1627 clauseStack_elements (gc.clauses, el)
1629 if (clause_isSwitch (el))
1633 else if (clause_isLoop (el))
1641 } end_clauseStack_elements;
1646 clause context_nextBreakClause (void)
1648 bool hasOne = FALSE;
1650 clauseStack_elements (gc.clauses, el)
1652 if (clause_isBreakable (el))
1663 } end_clauseStack_elements;
1668 bool context_inConditional (void)
1670 clauseStack_elements (gc.clauses, el)
1673 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1674 ** to distinguish if from ? for this
1677 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1681 } end_clauseStack_elements;
1686 void context_exitAndClause (exprNode pred, exprNode tbranch)
1688 context_setJustPopped ();
1690 llassert (gc.inclause == ANDCLAUSE);
1692 usymtab_popAndBranch (pred, tbranch);
1693 clauseStack_pop (gc.clauses);
1694 gc.inclause = topClause (gc.clauses);
1697 void context_exitOrClause (exprNode pred, exprNode tbranch)
1699 context_setJustPopped ();
1701 llassert (gc.inclause == ORCLAUSE);
1703 usymtab_popOrBranch (pred, tbranch);
1704 clauseStack_pop (gc.clauses);
1705 gc.inclause = topClause (gc.clauses);
1708 static void context_enterCondClauseAux (clause cl)
1714 static void context_enterTrueAux (exprNode e, clause cl)
1717 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1721 void context_enterIterClause (void)
1723 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1726 void context_enterDoWhileClause (void)
1728 pushClause (DOWHILECLAUSE);
1731 void context_enterWhileClause (exprNode e)
1733 context_enterTrueAux (e, WHILECLAUSE);
1736 void context_enterForClause (exprNode e)
1738 context_enterTrueAux (e, FORCLAUSE);
1741 void context_enterTrueClause (exprNode e)
1743 context_enterTrueAux (e, TRUECLAUSE);
1746 void context_enterSwitch (exprNode e)
1748 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1749 usymtab_switchBranch (e);
1750 context_enterCondClauseAux (SWITCHCLAUSE);
1753 void context_exitSwitch (exprNode e, bool allpaths)
1755 usymtab_exitSwitch (e, allpaths);
1757 while (clause_isCase (clauseStack_top (gc.clauses)))
1759 clauseStack_pop (gc.clauses);
1762 context_exitClauseSimp ();
1765 void context_enterCaseClause (exprNode e)
1767 bool branch = FALSE;
1769 DPRINTF (("Enter case clause!"));
1771 branch = usymtab_newCase (exprNode_undefined, e);
1775 context_enterCondClauseAux (CASECLAUSE);
1779 static void context_enterFalseClauseAux (exprNode e, clause cl)
1782 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1784 clauseStack_switchTop (gc.clauses, cl);
1787 void context_enterFalseClause (exprNode e)
1790 context_enterFalseClauseAux (e, FALSECLAUSE);
1794 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1796 gc.kind = CX_MACROCONST;
1798 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1800 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1804 usymtab_enterScope ();
1805 sRef_enterFunctionScope ();
1807 gc.globs = globSet_undefined;
1808 globSet_clear (gc.globs_used);
1809 gc.mods = sRefSet_undefined;
1812 uentry context_getHeader (void)
1814 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1816 llfatalbug (message ("context_getHeader: bad call: %q",
1817 context_unparse ()));
1820 return (gc.cont.fcn);
1824 context_setFunctionDefined (fileloc loc)
1828 case CX_UNKNOWNMACRO:
1831 uentry_setFunctionDefined (gc.cont.fcn, loc);
1834 /* (not a bug because of parse errors) */
1840 context_enterFunction (/*@exposed@*/ uentry e)
1842 gc.kind = CX_FUNCTION;
1845 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1847 if (uentry_hasAccessType (e))
1849 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1857 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1858 typeIdSet_unparse (gc.acct)));
1860 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1862 gc.globs = uentry_getGlobs (e);
1863 globSet_clear (gc.globs_used);
1864 gc.mods = uentry_getMods (e);
1866 usymtab_enterFunctionScope (e);
1867 sRef_enterFunctionScope ();
1870 bool context_inOldSytleScope(void)
1872 if (gc.kind == CX_OLDSTYLESCOPE)
1879 context_enterOldStyleScope (void)
1881 gc.kind = CX_OLDSTYLESCOPE;
1882 DPRINTF (("Enter old style scope!"));
1883 usymtab_enterFunctionScope (uentry_undefined);
1887 context_completeOldStyleFunction (uentry e)
1889 llassert (gc.kind == CX_OLDSTYLESCOPE);
1891 gc.kind = CX_FUNCTION;
1894 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1896 if (uentry_hasAccessType (e))
1898 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1906 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1907 typeIdSet_unparse (gc.acct)));
1909 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1911 if (!globSet_isEmpty (uentry_getGlobs (e)))
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 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1919 gc.globs = uentry_getGlobs (e);
1920 globSet_clear (gc.globs_used);
1922 gc.mods = uentry_getMods (e);
1924 if (!sRefSet_isEmpty (gc.mods))
1926 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1927 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1930 sRef_enterFunctionScope ();
1933 static bool context_checkStrictGlobals (void)
1935 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1938 static bool context_hasGlobs (void)
1940 if (context_inFunctionLike ())
1942 return (uentry_hasGlobs (gc.cont.fcn));
1950 static bool context_checkCheckedGlobals (void)
1952 return (context_getFlag (FLG_GLOBALS)
1953 && (context_getFlag (FLG_GLOBUNSPEC)
1954 || context_hasGlobs ()));
1957 static bool context_checkUnknownGlobals (void)
1959 /* should be uentry_hasGlobs ? */
1961 return (context_getFlag (FLG_ALLGLOBALS)
1962 && (context_getFlag (FLG_GLOBUNSPEC)
1963 || context_hasGlobs ()));
1966 static bool context_checkUncheckedGlobals (void)
1972 context_checkExport (uentry e)
1974 if (!gc.anyExports) return FALSE;
1976 if (uentry_isFunction (e)
1977 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1979 return context_maybeSet (FLG_EXPORTFCN);
1981 else if (uentry_isExpandedMacro (e))
1983 return context_maybeSet (FLG_EXPORTMACRO);
1985 else if (uentry_isVariable (e))
1987 return context_maybeSet (FLG_EXPORTVAR);
1989 else if (uentry_isEitherConstant (e))
1991 return context_maybeSet (FLG_EXPORTCONST);
1993 else if (uentry_isIter (e) || uentry_isEndIter (e))
1995 return context_maybeSet (FLG_EXPORTITER);
1997 else if (uentry_isDatatype (e))
1999 return context_maybeSet (FLG_EXPORTTYPE);
2008 context_checkGlobUse (uentry glob)
2011 if (uentry_isCheckedStrict (glob))
2013 return context_checkStrictGlobals ();
2015 else if (uentry_isChecked (glob))
2017 return context_checkCheckedGlobals ();
2019 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2021 return context_checkUnknownGlobals ();
2025 llassert (uentry_isUnchecked (glob));
2027 return context_checkUncheckedGlobals ();
2032 context_checkAliasGlob (uentry glob)
2034 if (uentry_isCheckedStrict (glob))
2036 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2038 else if (uentry_isChecked (glob))
2040 return gc.flags[FLG_CHECKEDGLOBALIAS];
2042 else if (uentry_isCheckMod (glob))
2044 return gc.flags[FLG_CHECKMODGLOBALIAS];
2048 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2050 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2054 bool context_checkInternalUse (void)
2056 if (context_hasGlobs ())
2058 return (gc.flags[FLG_INTERNALGLOBS]);
2062 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2067 context_checkGlobMod (sRef el)
2069 uentry ue = sRef_getUentry (el);
2071 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2073 if (uentry_isCheckedModify (ue)
2074 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2076 if (context_hasMods ())
2078 return (gc.flags[FLG_MODGLOBS]);
2082 if (uentry_isCheckedStrict (ue))
2084 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2088 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2094 if (context_hasMods ())
2096 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2106 context_usedGlobal (/*@exposed@*/ sRef el)
2108 if (!globSet_member (gc.globs_used, el))
2111 ** The first time a global is used in a function, we need
2112 ** to clear the derived sRefs, since they were set for the
2113 ** previous function.
2116 sRef_clearDerived (el);
2117 gc.globs_used = globSet_insert (gc.globs_used, el);
2121 /*@observer@*/ sRefSet
2122 context_modList (void)
2128 context_globAccess (sRef s)
2130 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2131 return (globSet_member (gc.globs, s));
2135 context_hasAccess (typeId t)
2137 if (context_inFunctionLike ())
2139 DPRINTF (("Access %d / %s",
2140 t, typeIdSet_unparse (gc.acct)));
2141 return (typeIdSet_member (gc.acct, t));
2145 return (context_hasFileAccess (t));
2150 context_hasFileAccess (typeId t)
2152 return (typeIdSet_member (gc.facct, t));
2156 context_unparseAccess (void)
2158 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2159 typeIdSet_unparse (gc.facct)));
2163 context_unparseClauses (void)
2165 return (clauseStack_unparse (gc.clauses));
2169 context_couldHaveAccess (typeId t)
2171 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2173 return (typeIdSet_member (gc.acct, t));
2177 return (typeIdSet_member (gc.facct, t));
2182 context_getRetType (void)
2184 ctype f = ctype_undefined;
2186 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2188 f = uentry_getType (gc.cont.fcn);
2190 else if (gc.kind == CX_UNKNOWNMACRO)
2192 return ctype_unknown;
2196 llcontbuglit ("context_getRetType: not in a function context");
2197 return ctype_unknown;
2200 if (!ctype_isFunction (f))
2202 if (ctype_isKnown (f))
2204 llbuglit ("context_getRetType: not a function");
2207 return ctype_unknown;
2209 return (ctype_getReturnType (f));
2213 context_hasMods (void)
2215 if (context_inFunctionLike ())
2217 return (uentry_hasMods (gc.cont.fcn));
2226 context_exitAllClauses (void)
2228 while (!clauseStack_isEmpty (gc.clauses))
2230 clause el = clauseStack_top (gc.clauses);
2233 if (clause_isNone (el))
2235 usymtab_quietExitScope (g_currentloc);
2236 clauseStack_pop (gc.clauses);
2240 context_exitClausePlain ();
2244 clauseStack_clear (gc.clauses);
2245 gc.inclause = NOCLAUSE;
2249 context_exitAllClausesQuiet (void)
2251 while (!clauseStack_isEmpty (gc.clauses))
2253 clause el = clauseStack_top (gc.clauses);
2256 usymtab_quietExitScope (g_currentloc);
2257 clauseStack_pop (gc.clauses);
2260 clauseStack_clear (gc.clauses);
2261 gc.inclause = NOCLAUSE;
2265 void context_exitClauseSimp (void)
2268 context_setJustPopped ();
2269 clauseStack_pop (gc.clauses);
2270 gc.inclause = topClause (gc.clauses);
2274 void context_exitCaseClause (void)
2276 context_setJustPopped ();
2277 usymtab_popCaseBranch ();
2278 clauseStack_pop (gc.clauses);
2279 gc.inclause = topClause (gc.clauses);
2283 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2285 context_setJustPopped ();
2286 /*@i32 was makeAlt */
2287 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2288 clauseStack_pop (gc.clauses);
2289 gc.inclause = topClause (gc.clauses);
2292 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2294 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2296 if (gc.inclause != TRUECLAUSE)
2298 llparseerror (cstring_makeLiteral
2299 ("Likely parse error. Conditional clauses are inconsistent."));
2303 context_setJustPopped ();
2304 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2305 clauseStack_pop (gc.clauses);
2306 gc.inclause = topClause (gc.clauses);
2309 void context_exitIterClause (exprNode body)
2311 llassert (gc.inclause == ITERCLAUSE);
2313 context_setJustPopped ();
2315 if (context_getFlag (FLG_ITERLOOPEXEC))
2317 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2321 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2324 clauseStack_pop (gc.clauses);
2325 gc.inclause = topClause (gc.clauses);
2328 static void context_popCase (void) {
2330 ** If we are exiting an outer clause, sometimes still in a switch case.
2344 DPRINTF (("Popping case clause: %s",
2345 clauseStack_unparse (gc.clauses)));
2347 if (gc.inclause == CASECLAUSE) {
2348 context_exitCaseClause ();
2352 void context_exitWhileClause (exprNode pred, exprNode body)
2354 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2358 if (gc.inclause != WHILECLAUSE) {
2359 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2360 clauseStack_unparse (gc.clauses)));
2363 llassert (gc.inclause == WHILECLAUSE);
2365 context_setJustPopped ();
2369 ** predicate must be false after while loop (unless there are breaks)
2372 if (context_getFlag (FLG_WHILELOOPEXEC))
2374 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2378 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2382 usymtab_addGuards (invGuards);
2383 guardSet_free (invGuards);
2385 clauseStack_pop (gc.clauses);
2386 gc.inclause = topClause (gc.clauses);
2389 void context_exitDoWhileClause (exprNode pred)
2391 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2393 if (gc.inclause == CASECLAUSE) {
2394 /* handle Duff's device */
2395 clauseStack_pop (gc.clauses);
2396 gc.inclause = topClause (gc.clauses);
2399 llassert (gc.inclause == DOWHILECLAUSE);
2401 context_setJustPopped ();
2404 usymtab_addGuards (invGuards);
2405 guardSet_free (invGuards);
2407 clauseStack_pop (gc.clauses);
2408 gc.inclause = topClause (gc.clauses);
2411 void context_exitForClause (exprNode forPred, exprNode body)
2413 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2415 llassert (gc.inclause == FORCLAUSE);
2416 context_setJustPopped ();
2418 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2421 ** Predicate must be false after for loop (unless there are breaks)
2424 if (context_getFlag (FLG_FORLOOPEXEC))
2426 DPRINTF (("Here: for loop exec"));
2427 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2431 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2432 && exprNode_loopMustExec (forPred))
2434 DPRINTF (("Here: loop must exec"));
2435 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2439 DPRINTF (("Pop true branch:"));
2440 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2444 usymtab_addGuards (invGuards);
2445 guardSet_free (invGuards);
2446 clauseStack_pop (gc.clauses);
2447 gc.inclause = topClause (gc.clauses);
2450 static void context_exitClausePlain (void)
2452 llassert (gc.inclause != NOCLAUSE);
2454 if (gc.inclause == FALSECLAUSE)
2456 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2460 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2464 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2466 context_setJustPopped ();
2468 if (gc.inclause == FALSECLAUSE)
2470 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2472 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2474 clauseStack_pop (gc.clauses);
2475 gc.inclause = topClause (gc.clauses);
2479 context_exitTrueClause (pred, tbranch);
2484 context_returnFunction (void)
2486 usymtab_checkFinalScope (TRUE);
2490 context_exitFunction (void)
2492 DPRINTF (("Exit function: %s", context_unparse ()));
2494 if (!context_inFunction () && !context_inMacroConstant ()
2495 && !context_inUnknownMacro ()
2496 && !context_inIterDef () && !context_inIterEnd ())
2499 ** not a bug because of parse errors
2506 if (context_inMacro () && usymtab_inFunctionScope ())
2508 usymtab_exitScope (exprNode_undefined);
2511 if (uentry_hasGlobs (gc.cont.fcn))
2513 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2517 if (uentry_hasMods (gc.cont.fcn))
2519 if (context_getFlag (FLG_MUSTMOD))
2521 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2525 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2528 ** clear file static modifies
2531 /* do this first to get unused error messages */
2533 usymtab_exitScope (exprNode_undefined);
2534 sRef_exitFunctionScope ();
2536 gc.showfunction = FALSE;
2537 gc.kind = CX_GLOBAL;
2538 gc.cont.glob = TRUE;
2540 gc.globs = globSet_new ();
2541 globSet_clear (gc.globs_used);
2542 gc.mods = sRefSet_new ();
2545 llassert (clauseStack_isEmpty (gc.clauses));
2546 llassert (gc.inclause == NOCLAUSE);
2547 DPRINTF (("After exit function: %s", context_unparse ()));
2551 context_quietExitFunction (void)
2553 while (gc.kind == CX_INNER)
2555 context_exitInnerPlain ();
2558 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2559 && !context_inIterDef () && !context_inIterEnd ())
2564 usymtab_quietExitScope (g_currentloc);
2566 gc.showfunction = FALSE;
2567 gc.kind = CX_GLOBAL;
2568 gc.cont.glob = TRUE;
2570 gc.globs = globSet_new ();
2571 globSet_clear (gc.globs_used);
2572 gc.mods = sRefSet_new ();
2574 sRef_exitFunctionScope ();
2578 /*@observer@*/ uentryList
2579 context_getParams (void)
2581 if (context_inFunctionLike ())
2583 return (uentry_getParams (gc.cont.fcn));
2587 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2588 return uentryList_undefined;
2592 /*@observer@*/ globSet
2593 context_getUsedGlobs (void)
2595 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2596 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2598 return (gc.globs_used);
2602 context_moduleName ()
2604 return (fileloc_getBase (g_currentloc));
2607 /*@observer@*/ globSet
2608 context_getGlobs (void)
2610 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2611 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2617 context_addBoolAccess (void)
2619 cstring bname = context_getString (FLG_BOOLTYPE);
2620 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2622 addModuleAccess (cstring_copy (bname), boolt);
2624 /* for sys/types (perhaps, this is bogus!) */
2625 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2630 context_canAccessBool (void)
2637 static typeId boolType = typeId_invalid;
2639 if (typeId_isInvalid (boolType))
2641 boolType = usymtab_getTypeId (context_getBoolName ());
2644 if (typeId_isInvalid (boolType)) {
2647 return (typeIdSet_member (gc.acct, boolType));
2652 /* evs 2000-07-25: old version - replaced */
2655 context_boolImplementationType () {
2656 /* For now, this is bogus! */
2661 context_canAccessBool (void)
2663 static typeId boolType = typeId_invalid;
2665 if (typeId_isInvalid (boolType))
2667 boolType = usymtab_getTypeId (context_getBoolName ());
2670 if (!typeId_isInvalid (boolType))
2672 return context_hasAccess (boolType);
2683 context_setMessageAnnote (/*@only@*/ cstring s)
2685 llassert (cstring_isUndefined (gc.msgAnnote));
2690 context_hasMessageAnnote (void)
2692 return (cstring_isDefined (gc.msgAnnote));
2696 context_clearMessageAnnote (void)
2698 if (cstring_isDefined (gc.msgAnnote))
2700 cstring_free (gc.msgAnnote);
2701 gc.msgAnnote = cstring_undefined;
2706 context_getMessageAnnote (void)
2708 cstring st = gc.msgAnnote;
2710 gc.msgAnnote = cstring_undefined;
2715 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2717 llassert (sRef_isInvalid (gc.aliasAnnote));
2718 llassert (!sRef_sameName (s, t));
2720 gc.aliasAnnoteAls = t;
2724 context_hasAliasAnnote (void)
2726 return (sRef_isValid (gc.aliasAnnote));
2730 context_clearAliasAnnote (void)
2732 gc.aliasAnnote = sRef_undefined;
2736 context_getAliasAnnote (void)
2738 sRef ret = gc.aliasAnnote;
2739 sRef als = gc.aliasAnnoteAls;
2741 llassert (sRef_isValid (ret) && sRef_isValid (als));
2743 gc.aliasAnnote = sRef_undefined;
2744 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2748 context_recordFileModifies (sRefSet mods)
2750 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2754 context_recordFileGlobals (globSet mods)
2756 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2757 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2761 context_setCommentMarkerChar (char c)
2763 llassert (c != '\0');
2765 context_setValue (FLG_COMMENTCHAR, (int) c);
2769 context_getCommentMarkerChar (void)
2771 return ((char) context_getValue (FLG_COMMENTCHAR));
2775 context_setValue (flagcode flag, int val)
2777 int index = flagcode_valueIndex (flag);
2779 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2787 llerror_flagWarning (message ("Value for %s must be a positive "
2788 "number (given %d)",
2789 flagcode_unparse (flag), val));
2792 if (flag == FLG_LINELEN && val < MINLINELEN)
2794 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2795 flagcode_unparse (flag),
2801 case FLG_INCLUDENEST:
2802 case FLG_CONTROLNESTDEPTH:
2803 case FLG_STRINGLITERALLEN:
2804 case FLG_NUMSTRUCTFIELDS:
2805 case FLG_NUMENUMMEMBERS:
2806 case FLG_INDENTSPACES:
2809 llerror_flagWarning (message ("Value for %s must be a non-negative "
2810 "number (given %d)",
2811 flagcode_unparse (flag), val));
2820 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2821 gc.values[index] = val;
2825 context_setValueAndFlag (flagcode flag, int val)
2827 gc.flags[flag] = TRUE;
2828 context_setValue (flag, val);
2832 context_getValue (flagcode flag)
2834 int index = flagcode_valueIndex (flag);
2836 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2837 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2838 return (gc.values[index]);
2842 context_getCounter (flagcode flag)
2844 int index = flagcode_valueIndex (flag);
2846 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2847 return (gc.counters[index]);
2851 context_incCounter (flagcode flag)
2853 int index = flagcode_valueIndex (flag);
2855 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2857 gc.counters[index]++;
2861 context_decCounter (flagcode flag)
2863 int index = flagcode_valueIndex (flag);
2865 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2866 gc.counters[index]--;
2869 bool context_showFunction (void)
2871 return (gc.showfunction);
2875 context_setString (flagcode flag, cstring val)
2877 int index = flagcode_stringIndex (flag);
2879 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2881 if (flag == FLG_SYSTEMDIRS)
2883 llassert (cstring_isDefined (val));
2885 if (cstring_firstChar (val) == '\"')
2888 cstring tval = cstring_copy (cstring_suffix (val, 1));
2890 if (cstring_lastChar (tval) != '\"')
2892 int n = cstring_length (tval) - 1;
2894 while (isspace ((int) cstring_getChar (tval, n)))
2899 if (cstring_getChar (tval, n) != '\"')
2901 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2905 cstring otval = tval;
2906 tval = cstring_prefix (tval, n);
2907 cstring_free (otval);
2911 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2912 DPRINTF (("val = %s", val));
2913 cstring_free (tval);
2914 cstring_free (oval);
2918 if (flag == FLG_TMPDIR)
2920 llassert (cstring_isDefined (val));
2922 if (cstring_length (val) == 0)
2925 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2927 else if (cstring_lastChar (val) != CONNECTCHAR)
2929 val = cstring_appendChar (val, CONNECTCHAR);
2937 if (cstring_length (val) >= 1
2938 && cstring_firstChar (val) == '\"')
2940 llerror_flagWarning (message
2941 ("setting %s to string beginning with \". You probably "
2942 "don't meant to have the \"'s.",
2943 flagcode_unparse (flag)));
2946 if (flag == FLG_BOOLTYPE)
2951 gc.strings[index] = val;
2954 static /*@exposed@*/ cstring
2955 context_exposeString (flagcode flag)
2957 int index = flagcode_stringIndex (flag);
2959 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2960 return (gc.strings[index]);
2964 context_getString (flagcode flag)
2966 return (context_exposeString (flag));
2970 context_resetErrors (void)
2975 void context_initMod (void)
2976 /*@globals undef gc; @*/
2978 gc.kind = CX_GLOBAL;
2980 gc.savekind = CX_ERROR;
2981 gc.savecont.glob = FALSE;
2983 gc.instandardlib = FALSE;
2986 gc.linesprocessed = 0;
2987 gc.speclinesprocessed = 0;
2988 gc.insuppressregion = FALSE;
2989 gc.macroMissingParams = FALSE;
2990 gc.preprocessing = FALSE;
2991 gc.incommandline = FALSE;
2992 gc.mc = macrocache_create ();
2994 gc.maxmods = DEFAULTMAXMODS;
2995 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2997 gc.library = FLG_ANSILIB;
2999 gc.locstack = filelocStack_new ();
3000 gc.modrecs = sRefSetList_undefined;
3001 gc.anyExports = FALSE;
3003 gc.ftab = fileTable_create ();
3004 gc.msgLog = messageLog_new ();
3005 gc.inimport = FALSE;
3006 gc.inDerivedFile = FALSE;
3007 gc.inheader = FALSE;
3008 gc.markers = flagMarkerList_new ();
3009 gc.cont.glob = TRUE;
3010 gc.showfunction = FALSE;
3011 gc.msgAnnote = cstring_undefined;
3012 gc.aliasAnnote = sRef_undefined;
3013 gc.aliasAnnoteAls = sRef_undefined;
3014 gc.boolType = ctype_bool;
3015 gc.mods = sRefSet_new ();
3017 gc.saveloc = fileloc_undefined;
3019 gc.inmacrocache = FALSE;
3020 gc.inclause = NOCLAUSE;
3021 gc.clauses = clauseStack_new ();
3022 gc.globs = globSet_new ();
3023 gc.nacct = typeIdSet_emptySet ();
3024 gc.acct = typeIdSet_emptySet ();
3025 gc.facct = typeIdSet_emptySet ();
3026 gc.savedFlags = FALSE;
3027 gc.pushloc = fileloc_undefined;
3028 gc.protectVars = FALSE;
3029 gc.justpopped = FALSE;
3030 gc.isNullGuarded = NO;
3031 gc.globs_used = globSet_undefined;
3035 gc.setGlobally[code] = FALSE;
3036 gc.setLocally[code] = FALSE;
3042 context_resetAllFlags ();
3044 assertSet (gc.flags); /* Can't use global in defines */
3045 assertSet (gc.saveflags);
3046 assertSet (gc.values);
3047 assertSet (gc.strings);
3049 conext_resetAllCounters ();
3050 assertSet (gc.counters);
3052 context_setMode (DEFAULT_MODE);
3054 gc.stateTable = metaStateTable_create ();
3055 gc.annotTable = annotationTable_create ();
3057 gc.inFunctionHeader = FALSE;
3059 DPRINTF (("Annotations: \n%s",
3060 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3061 DPRINTF (("State: \n%s",
3062 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3067 context_typeofZero (void)
3069 ctype ct = ctype_int;
3071 if (context_getFlag (FLG_ZEROPTR))
3073 ct = ctype_makeConj (ct, ctype_voidPointer);
3076 if (context_getFlag (FLG_ZEROBOOL)) {
3077 ct = ctype_makeConj (ct, ctype_bool);
3084 context_typeofOne (void)
3086 ctype ct = ctype_int;
3088 /* 1 is on longer a bool (was before 2.4)
3089 if (!context_getFlag (FLG_ABSTRACTBOOL))
3091 ct = ctype_makeConj (ct, ctype_bool);
3099 context_unparse (void)
3106 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3109 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3112 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3115 s = message ("Inner Context [%d] : %q",
3117 fileloc_unparse (g_currentloc));
3120 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3121 uentry_unparse (gc.cont.fcn),
3122 fileloc_unparse (g_currentloc),
3123 typeIdSet_unparse (gc.acct),
3124 sRefSet_unparse (gc.mods));
3127 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3129 case CX_UNKNOWNMACRO:
3130 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3133 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3136 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3139 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3141 case CX_FCNDECLARATION:
3142 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3145 s = message ("Un-unparseable context: %d", (int) gc.kind);
3149 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3154 context_currentFunctionType (void)
3156 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3158 return (uentry_getType (gc.cont.fcn));
3160 else if (gc.kind == CX_INNER)
3162 llcontbuglit ("context_currentFunctionType: inner context");
3163 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3164 return (context_currentFunctionType ());
3168 llcontbuglit ("context_currentFunctionType: not in function");
3169 return (ctype_undefined);
3174 context_enterInnerContext (void)
3176 if (context_getFlag (FLG_GRAMMAR))
3178 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3181 if (gc.kind == CX_GLOBAL)
3186 else if (gc.kind == CX_INNER)
3195 usymtab_enterScope ();
3196 pushClause (NOCLAUSE);
3200 context_exitInnerPlain (void) /*@modifies gc;@*/
3202 context_exitInner (exprNode_undefined);
3206 context_exitInner (exprNode exp)
3208 if (context_getFlag (FLG_GRAMMAR))
3210 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3213 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3214 ("inclause = %s", clause_nameTaken (gc.inclause)));
3216 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3217 gc.inclause = topClause (gc.clauses);
3219 if (gc.kind == CX_INNER)
3221 if (--gc.cont.cdepth == 0)
3223 gc.kind = CX_GLOBAL;
3224 gc.cont.glob = TRUE;
3229 if (gc.kind == CX_GLOBAL)
3231 llcontbuglit ("Attempt to exit global context");
3236 usymtab_exitScope (exp);
3241 context_enterStructInnerContext (void)
3243 if (context_getFlag (FLG_GRAMMAR))
3245 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3248 if (gc.kind == CX_GLOBAL)
3253 else if (gc.kind == CX_INNER)
3262 usymtab_enterScope ();
3264 if (context_getFlag (FLG_GRAMMAR))
3266 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3271 context_exitStructInnerContext (void)
3273 if (context_getFlag (FLG_GRAMMAR))
3275 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3278 if (gc.kind == CX_INNER)
3280 if (gc.cont.cdepth <= 0)
3282 llcontbuglit ("Attempt to exit inner context with no depth");
3283 gc.kind = CX_GLOBAL;
3284 gc.cont.glob = TRUE;
3290 if (gc.cont.cdepth == 0)
3292 gc.kind = CX_GLOBAL;
3293 gc.cont.glob = TRUE;
3299 if (gc.kind == CX_GLOBAL)
3301 llcontbuglit ("Attempt to exit global context");
3306 usymtab_exitScope (exprNode_undefined);
3308 if (context_getFlag (FLG_GRAMMAR))
3310 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3315 context_exitInnerSafe (void)
3317 if (context_getFlag (FLG_GRAMMAR))
3319 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3322 if (gc.kind == CX_INNER)
3324 if (--gc.cont.cdepth <= 0)
3329 else if (gc.kind == CX_GLOBAL)
3331 llcontbuglit ("Attempt to exit global context");
3336 if (usymtab_inDeepScope ())
3338 usymtab_exitScope (exprNode_undefined);
3344 void setModuleAccess (void)
3346 gc.facct = typeIdSet_emptySet ();
3348 if (fileId_isValid (currentFile ()))
3350 cstring baseName = fileloc_getBase (g_currentloc);
3352 if (context_getFlag (FLG_ACCESSFILE))
3354 if (usymtab_existsType (baseName))
3356 gc.facct = typeIdSet_insert (gc.facct,
3357 usymtab_getTypeId (baseName));
3365 if (context_getFlag (FLG_ACCESSMODULE))
3368 bool hasaccess = FALSE;
3370 for (i = 0; i < gc.nmods; i++)
3372 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3374 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3383 gc.inheader = fileId_isHeader (currentFile ());
3387 llcontbuglit ("Current file not defined\n");
3388 gc.facct = typeIdSet_emptySet ();
3390 gc.inheader = FALSE;
3393 /* 17 Jan 1995: forgot to clear nacct */
3395 gc.nacct = typeIdSet_emptySet ();
3399 context_enterFileAux (void)
3405 context_enterFile (void)
3407 context_enterFileAux ();
3408 usymtab_enterFile ();
3412 context_enterMacroFile (void)
3414 context_enterFileAux ();
3418 context_inFunction (void)
3420 kcontext ck = gc.kind;
3422 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3426 context_inFunctionLike (void)
3428 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3429 || gc.kind == CX_FCNDECLARATION
3430 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3434 context_inRealFunction (void)
3436 kcontext ck = gc.kind;
3438 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3442 context_processAllMacros (void)
3444 usymtab_enterFile ();
3446 gc.inmacrocache = TRUE;
3447 macrocache_processUndefinedElements (gc.mc);
3449 usymtab_exitFile ();
3451 gc.inmacrocache = FALSE;
3452 macrocache_finalize ();
3456 ** this happens once at the end of each C file
3458 ** check each Macro that was defined in current file.c or current file.h
3463 context_processMacros (void)
3465 if (fileId_isValid (currentFile ()))
3468 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3470 gc.inmacrocache = TRUE;
3472 DPRINTF (("Processing macros: %s", cbase));
3473 lastfl = macrocache_processFileElements (gc.mc, cbase);
3474 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3476 cstring_free (cbase);
3478 if (fileloc_isDefined (lastfl))
3480 g_currentloc = fileloc_update (g_currentloc, lastfl);
3484 gc.inmacrocache = FALSE;
3489 context_processingMacros (void)
3491 return (gc.inmacrocache);
3495 context_exitCFile (void)
3497 if (gc.kind != CX_GLOBAL)
3500 (cstring_makeLiteral ("File ended outside global scope"));
3503 if (gc.insuppressregion)
3505 /* gack...don't reverse the order of these lines! ;-> */
3506 gc.insuppressregion = FALSE;
3507 llerrorlit (FLG_SYNTAX,
3508 "File ended in ignore errors region, "
3509 "possible missing /*@end*/");
3512 /* fix up parse errors */
3514 while (!usymtab_inFileScope ())
3516 usymtab_quietExitScope (g_currentloc);
3520 ** Clear the file-specific modifies information.
3523 sRefSetList_elements (gc.modrecs, mods)
3525 sRefSet_clearStatics (mods);
3526 } end_sRefSetList_elements ;
3528 sRefSetList_clear (gc.modrecs);
3530 context_processMacros ();
3533 usymtab_exitFile ();
3535 gc.inDerivedFile = FALSE;
3536 filelocStack_clear (gc.locstack);
3538 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3540 gc.cont.glob = TRUE;
3544 context_restoreFlagSettings ();
3545 gc.savedFlags = FALSE;
3549 DPRINTF (("After exiting file: "));
3550 usymtab_printAll ();
3555 context_exitMacroCache (void)
3557 if (gc.kind != CX_GLOBAL)
3559 if (context_inMacro ())
3560 /* this is okay, file could end without newline in macro */
3562 DPRINTF (("Still in macro: %s",
3563 context_unparse ()));
3564 context_exitFunction ();
3568 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3569 context_unparse ()));
3570 gc.kind = CX_GLOBAL;
3575 ** no longer valid here
3576 ** if (gc.insuppressregion)
3578 ** gc.insuppressregion = FALSE;
3579 ** llerror ("File ended in ignore errors region, possible missing @");
3583 gc.cont.glob = TRUE;
3587 context_saveLocation (void)
3589 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3590 fileloc_free (gc.saveloc);
3591 gc.saveloc = fileloc_copy (g_currentloc);
3595 context_getSaveLocation (void)
3597 fileloc fl = gc.saveloc;
3598 gc.saveloc = fileloc_undefined;
3602 /*@observer@*/ cstring
3603 context_inFunctionName (void)
3605 if (gc.kind == CX_FUNCTION
3606 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3607 || gc.kind == CX_MACROCONST
3608 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3610 return (uentry_rawName (gc.cont.fcn));
3614 llcontbuglit ("context_inFunctionName: not in function");
3615 return (cstring_undefined);
3620 context_userSetFlag (flagcode f, bool b)
3622 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3624 if (f == FLG_NEVERINCLUDE && b)
3626 if (gc.flags[FLG_EXPORTHEADER])
3628 llerror_flagWarning (cstring_makeLiteral
3629 ("setting +neverinclude after +exportheader. "
3630 "Turning off exportheader, since headers are not checked "
3631 "when +neverinclude is used."));
3633 gc.flags[FLG_EXPORTHEADER] = FALSE;
3638 if (f == FLG_EXPORTHEADER && b)
3640 if (gc.flags[FLG_NEVERINCLUDE])
3642 llerror_flagWarning (cstring_makeLiteral
3643 ("setting +exportheader after +neverinclude. "
3644 "Not setting exportheader, since headers are not checked "
3645 "when +neverinclude is used."));
3646 gc.flags[FLG_EXPORTHEADER] = FALSE;
3652 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3654 bool lastsetting = context_getFlag (f);
3656 if (bool_equal (lastsetting, b)
3657 && !flagcode_isSpecialFlag (f)
3658 && !flagcode_isIdemFlag (f)
3659 && !flagcode_hasArgument (f))
3661 llerror_flagWarning (message ("setting %s%s redundant with current value",
3662 cstring_makeLiteralTemp (b ? "+" : "-"),
3663 flagcode_unparse (f)));
3667 if (flagcode_isWarnUseFlag (f) && b)
3669 if (!context_getFlag (FLG_WARNUSE))
3671 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3672 flagcode_unparse (f)));
3678 if (flagcode_isLibraryFlag (f))
3680 if (gc.library != FLG_ANSILIB
3683 llerror_flagWarning (message ("selecting library %s after library %s was "
3684 "selected (only one library may be used)",
3685 flagcode_unparse (f),
3686 flagcode_unparse (gc.library)));
3689 if (f == FLG_UNIXLIB)
3691 if (context_getFlag (FLG_WARNUNIXLIB))
3693 llerror_flagWarning (cstring_makeLiteral
3694 ("selecting unix library. Unix library is "
3695 "ad hoc addition to POSIX library. Recommend "
3696 "use +posixlib to select POSIX library instead. "
3697 "Use -warnunixlib to suppress this message."));
3704 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3706 llerror_flagWarning (message
3707 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3708 flagcode_unparse (f)));
3711 gc.setGlobally[f] = TRUE;
3712 context_setFlag (f, b);
3716 context_fileSetFlag (flagcode f, ynm set)
3720 context_saveFlagSettings ();
3723 if (ynm_isOff (set))
3725 context_setFlagAux (f, FALSE, TRUE, FALSE);
3727 else if (ynm_isOn (set))
3729 context_setFlagAux (f, TRUE, TRUE, FALSE);
3730 gc.setLocally[f] = TRUE;
3734 context_restoreFlag (f);
3739 context_restoreFlag (flagcode f)
3746 message ("Attempt to restore flag %s when no file scope flags "
3748 flagcode_unparse (f)),
3753 context_addFlagMarker (f, MAYBE);
3754 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3760 context_setFlag (flagcode f, bool b)
3762 context_setFlagAux (f, b, FALSE, FALSE);
3766 context_setFlagTemp (flagcode f, bool b)
3768 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3773 # define DOSET(ff,b) \
3774 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3775 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3776 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3777 gc.flags[ff] = b; } while (FALSE)
3780 context_setFlagAux (flagcode f, bool b, bool inFile,
3781 /*@unused@*/ bool isRestore)
3783 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3785 if (f == FLG_USESTDERR)
3788 g_msgstream = stderr;
3790 g_msgstream = stdout;
3795 ** Removed test for special flags.
3798 if (flagcode_isIdemFlag (f))
3807 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3809 if (b) /* Turing higher level on, turns on all lower levels */
3813 case FLG_ITS4MOSTRISKY:
3814 DOSET (FLG_ITS4VERYRISKY, b);
3816 case FLG_ITS4VERYRISKY:
3817 DOSET (FLG_ITS4RISKY, b);
3820 DOSET (FLG_ITS4MODERATERISK, b);
3822 case FLG_ITS4MODERATERISK:
3823 DOSET (FLG_ITS4LOWRISK, b);
3825 case FLG_ITS4LOWRISK:
3830 else /* Turning level off, turns off all higher levels */
3834 case FLG_ITS4LOWRISK:
3835 DOSET (FLG_ITS4MODERATERISK, b);
3837 case FLG_ITS4MODERATERISK:
3838 DOSET (FLG_ITS4RISKY, b);
3841 DOSET (FLG_ITS4VERYRISKY, b);
3843 case FLG_ITS4VERYRISKY:
3844 DOSET (FLG_ITS4MOSTRISKY, b);
3846 case FLG_ITS4MOSTRISKY:
3856 DOSET (FLG_ALLEMPTY, b);
3857 DOSET (FLG_IFEMPTY, b);
3858 DOSET (FLG_WHILEEMPTY, b);
3859 DOSET (FLG_FOREMPTY, b);
3862 DOSET (FLG_PREDBOOL, b);
3863 DOSET (FLG_PREDBOOLINT, b);
3864 DOSET (FLG_PREDBOOLPTR, b);
3865 DOSET (FLG_PREDBOOLOTHERS, b);
3868 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3869 DOSET (FLG_CHECKEDGLOBALIAS, b);
3870 DOSET (FLG_CHECKMODGLOBALIAS, b);
3871 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3874 DOSET (FLG_ALLBLOCK, b);
3875 DOSET (FLG_IFBLOCK, b);
3876 DOSET (FLG_WHILEBLOCK, b);
3877 DOSET (FLG_FORBLOCK, b);
3891 DOSET (FLG_GRAMMAR, b);
3893 case FLG_CODEIMPONLY:
3894 DOSET (FLG_CODEIMPONLY, b);
3895 DOSET (FLG_GLOBIMPONLY, b);
3896 DOSET (FLG_RETIMPONLY, b);
3897 DOSET (FLG_STRUCTIMPONLY, b);
3899 case FLG_SPECALLIMPONLY:
3900 DOSET (FLG_SPECALLIMPONLY, b);
3901 DOSET (FLG_SPECGLOBIMPONLY, b);
3902 DOSET (FLG_SPECRETIMPONLY, b);
3903 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3905 case FLG_ALLIMPONLY:
3906 DOSET (FLG_ALLIMPONLY, b);
3907 DOSET (FLG_GLOBIMPONLY, b);
3908 DOSET (FLG_RETIMPONLY, b);
3909 DOSET (FLG_STRUCTIMPONLY, b);
3910 DOSET (FLG_SPECGLOBIMPONLY, b);
3911 DOSET (FLG_SPECRETIMPONLY, b);
3912 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3914 case FLG_ANSI89LIMITS:
3915 DOSET (FLG_ANSI89LIMITS, b);
3916 DOSET (FLG_CONTROLNESTDEPTH, b);
3917 DOSET (FLG_STRINGLITERALLEN, b);
3918 DOSET (FLG_INCLUDENEST, b);
3919 DOSET (FLG_NUMSTRUCTFIELDS, b);
3920 DOSET (FLG_NUMENUMMEMBERS, b);
3924 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
3925 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
3926 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
3927 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
3928 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
3929 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
3930 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
3933 case FLG_ISO99LIMITS:
3934 DOSET (FLG_ISO99LIMITS, b);
3935 DOSET (FLG_CONTROLNESTDEPTH, b);
3936 DOSET (FLG_STRINGLITERALLEN, b);
3937 DOSET (FLG_INCLUDENEST, b);
3938 DOSET (FLG_NUMSTRUCTFIELDS, b);
3939 DOSET (FLG_NUMENUMMEMBERS, b);
3943 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
3944 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
3945 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
3946 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
3947 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
3948 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
3949 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
3952 case FLG_EXTERNALNAMELEN:
3953 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3954 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3956 case FLG_INTERNALNAMELEN:
3957 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3958 DOSET (FLG_INTERNALNAMELEN, TRUE);
3960 case FLG_EXTERNALNAMECASEINSENSITIVE:
3961 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3963 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3965 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3966 context_setValue (FLG_EXTERNALNAMELEN, 0);
3969 case FLG_INTERNALNAMECASEINSENSITIVE:
3970 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3972 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3974 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3975 context_setValue (FLG_INTERNALNAMELEN, 0);
3978 case FLG_INTERNALNAMELOOKALIKE:
3979 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3981 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3983 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3984 context_setValue (FLG_INTERNALNAMELEN, 0);
3988 DOSET (FLG_MODNOMODS, b);
3989 DOSET (FLG_MODGLOBSUNSPEC, b);
3990 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3993 DOSET (FLG_EXPORTVAR, b);
3994 DOSET (FLG_EXPORTFCN, b);
3995 DOSET (FLG_EXPORTTYPE, b);
3996 DOSET (FLG_EXPORTMACRO, b);
3997 DOSET (FLG_EXPORTCONST, b);
3998 gc.anyExports = TRUE;
4001 DOSET (FLG_RETEXPOSE, b);
4002 DOSET (FLG_ASSIGNEXPOSE, b);
4003 DOSET (FLG_CASTEXPOSE, b);
4006 DOSET (FLG_RETVALBOOL, b);
4007 DOSET (FLG_RETVALINT, b);
4008 DOSET (FLG_RETVALOTHER, b);
4013 DOSET (FLG_EXPORTLOCAL, FALSE);
4014 DOSET (FLG_DECLUNDEF, FALSE);
4015 DOSET (FLG_SPECUNDEF, FALSE);
4016 DOSET (FLG_TOPUNUSED, FALSE);
4020 DOSET (FLG_LOOPLOOPBREAK, b);
4021 DOSET (FLG_LOOPSWITCHBREAK, b);
4022 DOSET (FLG_SWITCHLOOPBREAK, b);
4023 DOSET (FLG_SWITCHSWITCHBREAK, b);
4024 DOSET (FLG_LOOPLOOPCONTINUE, b);
4025 DOSET (FLG_DEEPBREAK, b);
4028 DOSET (FLG_FORLOOPEXEC, b);
4029 DOSET (FLG_WHILELOOPEXEC, b);
4030 DOSET (FLG_ITERLOOPEXEC, b);
4033 DOSET (FLG_ACCESSMODULE, b);
4034 DOSET (FLG_ACCESSFILE, b);
4035 DOSET (FLG_ACCESSCZECH, b);
4038 DOSET (FLG_ALLMACROS, b);
4039 DOSET (FLG_FCNMACROS, b);
4040 DOSET (FLG_CONSTMACROS, b);
4043 DOSET (FLG_BOUNDSREAD, b);
4044 DOSET (FLG_BOUNDSWRITE, b);
4047 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4048 DOSET (FLG_CZECHFUNCTIONS, b);
4049 DOSET (FLG_CZECHVARS, b);
4050 DOSET (FLG_CZECHCONSTANTS, b);
4051 DOSET (FLG_CZECHTYPES, b);
4054 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4055 DOSET (FLG_SLOVAKFUNCTIONS, b);
4056 DOSET (FLG_SLOVAKVARS, b);
4057 DOSET (FLG_SLOVAKCONSTANTS, b);
4058 DOSET (FLG_SLOVAKTYPES, b);
4060 case FLG_CZECHOSLOVAK:
4061 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4062 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4063 DOSET (FLG_CZECHOSLOVAKVARS, b);
4064 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4065 DOSET (FLG_CZECHOSLOVAKTYPES, 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);
4075 DOSET (FLG_MUSTFREEONLY, b);
4076 DOSET (FLG_MUSTFREEFRESH, b);
4079 DOSET (FLG_NULLSTATE, b);
4080 DOSET (FLG_NULLDEREF, b);
4081 DOSET (FLG_NULLASSIGN, b);
4082 DOSET (FLG_NULLPASS, b);
4083 DOSET (FLG_NULLRET, b);
4084 DOSET (FLG_COMPDEF, b);
4085 DOSET (FLG_COMPMEMPASS, b);
4086 DOSET (FLG_UNIONDEF, b);
4087 DOSET (FLG_MEMTRANS, b);
4088 DOSET (FLG_USERELEASED, b);
4089 DOSET (FLG_ALIASUNIQUE, b);
4090 DOSET (FLG_MAYALIASUNIQUE, b);
4091 DOSET (FLG_MUSTFREEONLY, b);
4092 DOSET (FLG_MUSTFREEFRESH, b);
4093 DOSET (FLG_MUSTDEFINE, b);
4094 DOSET (FLG_GLOBSTATE, b);
4095 DOSET (FLG_COMPDESTROY, b);
4096 DOSET (FLG_MUSTNOTALIAS, b);
4097 DOSET (FLG_MEMIMPLICIT, b);
4098 DOSET (FLG_BRANCHSTATE, b);
4099 /*@fallthrough@*/ /* also sets memtrans flags */
4101 DOSET (FLG_MEMTRANS, b);
4102 DOSET (FLG_EXPOSETRANS, b);
4103 DOSET (FLG_OBSERVERTRANS, b);
4104 DOSET (FLG_DEPENDENTTRANS, b);
4105 DOSET (FLG_NEWREFTRANS, b);
4106 DOSET (FLG_ONLYTRANS, b);
4107 DOSET (FLG_OWNEDTRANS, b);
4108 DOSET (FLG_FRESHTRANS, b);
4109 DOSET (FLG_SHAREDTRANS, b);
4110 DOSET (FLG_TEMPTRANS, b);
4111 DOSET (FLG_KEPTTRANS, b);
4112 DOSET (FLG_REFCOUNTTRANS, b);
4113 DOSET (FLG_STATICTRANS, b);
4114 DOSET (FLG_UNKNOWNTRANS, b);
4115 DOSET (FLG_KEEPTRANS, b);
4116 DOSET (FLG_IMMEDIATETRANS, b);
4123 if (b && !gc.anyExports
4124 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4125 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4126 || f == FLG_EXPORTCONST
4127 || f == FLG_EXPORTANY))
4129 gc.anyExports = TRUE;
4134 context_maybeSet (flagcode d)
4136 return (gc.flags[d] || gc.setLocally[d]);
4140 context_getFlag (flagcode d)
4142 return (gc.flags[d]);
4146 context_flagOn (flagcode f, fileloc loc)
4148 return (!context_suppressFlagMsg (f, loc));
4151 static void context_saveFlagSettings (void)
4153 gc.savedFlags = TRUE;
4154 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4155 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4158 static void context_restoreFlagSettings (void)
4160 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4161 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4162 gc.savedFlags = FALSE;
4165 void context_setFilename (fileId fid, int lineno)
4166 /*@globals fileloc g_currentloc;@*/
4167 /*@modifies g_currentloc@*/
4169 if (fileId_baseEqual (currentFile (), fid))
4176 fileloc_setColumn (g_currentloc, 0);
4178 if (fileloc_isSpecialFile (g_currentloc))
4180 gc.inDerivedFile = TRUE;
4183 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4185 int maxdepth = context_getValue (FLG_INCLUDENEST);
4187 if (filelocStack_size (gc.locstack) > maxdepth)
4189 int depth = filelocStack_includeDepth (gc.locstack);
4191 if (depth > maxdepth)
4195 message ("Maximum include nesting depth "
4196 "(%d, current depth %d) exceeded",
4199 filelocStack_nextTop (gc.locstack)))
4201 filelocStack_printIncludes (gc.locstack);
4207 g_currentloc = fileloc_create (fid, lineno, 1);
4208 gc.inheader = fileId_isHeader (currentFile ());
4210 context_enterFileAux ();
4214 void context_enterIterDef (/*@observer@*/ uentry le)
4216 context_enterMacro (le);
4217 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4218 gc.kind = CX_ITERDEF;
4221 void context_enterIterEnd (/*@observer@*/ uentry le)
4223 context_enterMacro (le);
4224 gc.kind = CX_ITEREND;
4228 context_destroyMod (void)
4229 /*@globals killed gc@*/
4232 ctype_destroyMod ();
4236 fileTable_free (gc.ftab);
4237 filelocStack_free (gc.locstack);
4239 gc.ftab = fileTable_undefined;
4241 macrocache_free (gc.mc);
4242 sfree (gc.moduleaccess);
4245 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4246 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4249 sRefSetList_free (gc.modrecs);
4251 flagMarkerList_free (gc.markers);
4253 messageLog_free (gc.msgLog);
4255 clauseStack_free (gc.clauses);
4258 cstring_free (gc.msgAnnote);
4259 globSet_free (gc.globs_used);
4260 metaStateTable_free (gc.stateTable);
4261 annotationTable_free (gc.annotTable);
4268 bool context_msgBoolInt (void)
4270 return gc.flags [FLG_BOOLINT];
4273 bool context_msgCharInt (void)
4275 return gc.flags [FLG_CHARINT];
4278 bool context_msgEnumInt (void)
4280 return gc.flags [FLG_ENUMINT];
4283 bool context_msgPointerArith (void)
4285 return gc.flags [FLG_POINTERARITH];
4288 bool context_msgStrictOps (void)
4290 return gc.flags [FLG_STRICTOPS];
4294 bool context_msgLh (void)
4296 return gc.flags [FLG_DOLH];
4300 void context_pushLoc (void)
4302 fileloc_free (gc.pushloc);
4303 gc.pushloc = gc.saveloc;
4304 gc.saveloc = fileloc_undefined;
4307 void context_popLoc (void)
4309 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4312 bool context_inGlobalScope (void)
4314 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4317 bool context_inInnerScope (void)
4319 return (gc.kind == CX_INNER);
4322 void context_setProtectVars (void)
4324 gc.protectVars = TRUE;
4327 bool context_anyErrors (void)
4329 return (gc.numerrors > 0);
4332 void context_hasError (void)
4335 DPRINTF (("num errors: %d", gc.numerrors));
4338 int context_numErrors (void)
4340 return gc.numerrors;
4343 bool context_neednl (void)
4348 void context_setNeednl (void)
4353 int context_getExpect (void)
4355 return (context_getValue (FLG_EXPECT));
4359 int context_getLCLExpect (void)
4361 return (context_getValue (FLG_LCLEXPECT));
4365 int context_getLimit (void)
4367 return (context_getValue (FLG_LIMIT));
4370 bool context_unlimitedMessages (void)
4372 return (context_getLimit () < 0);
4375 void context_releaseVars (void)
4377 llassert (gc.protectVars);
4378 gc.protectVars = FALSE;
4381 void context_sizeofReleaseVars (void)
4383 /* If there is a nested sizeof, this might not hold:
4384 llassert (gc.protectVars);
4387 gc.protectVars = FALSE;
4390 bool context_inProtectVars (void)
4392 return (gc.protectVars);
4395 void context_hideShowscan (void)
4397 gc.flags[FLG_SHOWSCAN] = FALSE;
4400 void context_unhideShowscan (void)
4402 gc.flags[FLG_SHOWSCAN] = TRUE;
4405 bool context_inHeader (void)
4407 return (gc.inheader);
4410 fileTable context_fileTable (void)
4415 cstring context_tmpdir (void)
4417 return (context_getString (FLG_TMPDIR));
4420 messageLog context_messageLog (void)
4425 bool context_inMacroFunction (void)
4427 return (gc.kind == CX_MACROFCN);
4430 bool context_inMacroConstant (void)
4432 return (gc.kind == CX_MACROCONST);
4435 bool context_inUnknownMacro (void)
4437 return (gc.kind == CX_UNKNOWNMACRO);
4440 void context_setShownFunction (void)
4442 gc.showfunction = FALSE;
4445 bool context_doDump (void)
4447 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4450 bool context_doMerge (void)
4452 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4455 cstring context_getDump (void)
4457 return context_getString (FLG_DUMP);
4460 cstring context_getMerge (void)
4462 return context_getString (FLG_MERGE);
4466 bool context_inLCLLib (void)
4468 return (gc.kind == CX_LCLLIB);
4471 bool context_inImport (void)
4473 return (gc.inimport);
4476 void context_enterImport (void)
4481 void context_leaveImport (void)
4483 gc.inimport = FALSE;
4487 bool context_inMacro (void)
4489 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4490 || gc.kind == CX_UNKNOWNMACRO
4491 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4494 bool context_inIterDef (void)
4496 return (gc.kind == CX_ITERDEF);
4499 bool context_inIterEnd (void)
4501 return (gc.kind == CX_ITEREND);
4504 int context_getLinesProcessed (void)
4506 return (gc.linesprocessed);
4509 int context_getSpecLinesProcessed (void)
4511 return (gc.speclinesprocessed);
4515 void context_processedSpecLine (void)
4517 gc.speclinesprocessed++;
4520 void context_resetSpecLines (void)
4522 gc.speclinesprocessed = 0;
4526 bool context_inGlobalContext (void)
4528 return (gc.kind == CX_GLOBAL);
4531 static void context_quietExitScopes (void)
4534 ** Try to restore the global scope (after an error).
4537 while (!usymtab_inFileScope ())
4539 usymtab_quietExitScope (g_currentloc);
4542 gc.cont.glob = TRUE;
4543 gc.kind = CX_GLOBAL;
4546 void context_checkGlobalScope (void)
4548 if (gc.kind != CX_GLOBAL)
4550 if (context_inMacro ())
4552 ; /* evans 2001-10-14: Okay to be in a macro here! */
4556 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4557 context_quietExitScopes ();
4562 void context_setFileId (fileId s)
4564 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4567 bool context_setBoolName (void)
4569 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4573 cstring context_printBoolName (void)
4575 if (context_setBoolName ())
4577 return context_getBoolName ();
4581 return cstring_makeLiteralTemp ("boolean");
4585 cstring context_getBoolName (void)
4587 return (context_getString (FLG_BOOLTYPE));
4590 cstring context_getFalseName (void)
4592 return (context_getString (FLG_BOOLFALSE));
4595 cstring context_getTrueName (void)
4597 return (context_getString (FLG_BOOLTRUE));
4600 cstring context_getLarchPath (void)
4602 return (context_getString (FLG_LARCHPATH));
4605 cstring context_getLCLImportDir (void)
4607 return (context_getString (FLG_LCLIMPORTDIR));
4610 static void context_setJustPopped (void)
4612 gc.justpopped = TRUE;
4615 void context_clearJustPopped (void)
4617 gc.justpopped = FALSE;
4620 bool context_justPopped (void)
4622 return (gc.justpopped);
4625 void context_setMacroMissingParams (void)
4627 gc.macroMissingParams = TRUE;
4630 void context_resetMacroMissingParams (void)
4632 gc.macroMissingParams = FALSE;
4635 bool context_isMacroMissingParams (void)
4637 return (gc.macroMissingParams);
4640 void context_showFilelocStack (void)
4642 filelocStack_printIncludes (gc.locstack);
4645 metaStateTable context_getMetaStateTable (void)
4647 return gc.stateTable;
4650 metaStateInfo context_lookupMetaStateInfo (cstring key)
4652 return metaStateTable_lookup (gc.stateTable, key);
4655 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4657 annotationInfo ainfo;
4659 ainfo = annotationTable_lookup (gc.annotTable, annot);
4664 void context_addAnnotation (annotationInfo ainfo)
4666 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4670 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4671 annotationInfo_getLoc (ainfo));
4673 annotationInfo_free (ainfo);
4677 annotationTable_insert (gc.annotTable, ainfo);
4681 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4683 if (metaStateTable_contains (gc.stateTable, mname))
4687 message ("Duplicate metastate declaration: %s", mname),
4688 metaStateInfo_getLoc (msinfo));
4689 cstring_free (mname);
4690 metaStateInfo_free (msinfo);
4694 DPRINTF (("Adding meta state: %s", mname));
4695 metaStateTable_insert (gc.stateTable, mname, msinfo);
4699 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4701 if (metaStateTable_size (gc.stateTable) > 0)
4703 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4704 /*@i32 should use smaller value... */
4705 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4707 metaStateTable_elements (gc.stateTable, msname, msi)
4709 mtContextNode context = metaStateInfo_getContext (msi);
4711 if (mtContextNode_matchesRefStrict (context, s))
4713 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4714 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4718 cstring_copy (metaStateInfo_getName (msi)),
4719 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4720 stateInfo_copy (sinfo)));
4724 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4727 end_metaStateTable_elements ;
4729 stateInfo_free (sinfo);
4730 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4735 stateInfo_free (sinfo);
4736 return valueTable_undefined;
4740 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4742 if (metaStateTable_size (gc.stateTable) > 0)
4744 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4745 /*@i32 should use smaller value... */
4747 metaStateTable_elements (gc.stateTable, msname, msi)
4749 /*@i23 only add global...*/
4750 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4751 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4753 valueTable_insert (res,
4754 cstring_copy (metaStateInfo_getName (msi)),
4755 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4756 stateInfo_copy (sinfo)));
4758 end_metaStateTable_elements ;
4760 stateInfo_free (sinfo);
4761 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4766 stateInfo_free (sinfo);
4767 return valueTable_undefined;
4773 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4777 static ctype lastStruct;
4779 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4785 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4791 /*@unused@*/ static int sInfoNum = 0;
4795 /*@unused@*/ uentry ue;
4796 /*@unused@*/ sRef s;
4800 /*@unused@*/ ctype ct;
4801 /*@unused@*/ constraintList inv;
4802 /*@unused@*/ int ngetUe;
4803 /*@unused@*/ struct getUe * t ;
4807 static struct sInfo globalStructInfo;
4810 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4811 stable release of splint. I coomented them out so that they won't break anything
4812 but didn't delete them because they will be fixed and included later
4816 void setGlobalStructInfo(ctype ct, constraintList list)
4821 f = ctype_getFields (ct);
4823 if (constraintList_isDefined(list) )
4825 globalStructInfo.ct = ct;
4826 globalStructInfo.inv = list;
4828 globalStructInfo.ngetUe = 0;
4830 / *abstraction violation fix it * /
4831 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4833 globalStructInfo.ngetUe = f->nelements;
4837 uentryList_elements(f, ue)
4839 globalStructInfo.t[i].ue = ue;
4840 globalStructInfo.t[i].s = uentry_getSref(ue);
4841 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4842 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4847 end_uentryList_elements;
4853 bool hasInvariants (ctype ct) /*@*/
4855 if ( ctype_sameName(globalStructInfo.ct, ct) )
4865 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4866 stable release of splint. I coomented them out so that they won't break anything
4867 but didn't delete them because they will be fixed and included later
4871 constraintList getInvariants (ctype ct)
4874 llassert(hasInvariants(ct) );
4876 return globalStructInfo.inv;
4881 static int getSref (ctype ct, sRef s)
4890 fprintf(stderr, "getSref: ct = %s (%x)\n", ctype_unparse(ct), ct );
4892 fprintf(stderr,"getSref: s = (%s) %X \n", sRef_unparse(s), s);
4895 while (i < globalStructInfo.ngetUe)
4897 DPRINTF(( message(" getSref:: comparing ue=%s and sRef=%s",
4898 uentry_unparse(globalStructInfo.t[i].ue),
4899 sRef_unparse(globalStructInfo.t[i].s)
4904 fprintf (stderr, " globalStructInfo.t[i].s = %x\n ",
4905 globalStructInfo.t[i].s );
4908 if (sRef_same(globalStructInfo.t[i].s,s) )
4917 sRef fixSref (ctype ct, sRef base, sRef fix)
4922 index = getSref(ct, fix);
4927 ue = globalStructInfo.t[index].ue;
4928 name = uentry_getName(ue);
4929 fix = sRef_buildField(base, name );