2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 * Modified by Herbert 04/19/97:
29 * - added include for new header portab.h containing OS dependent stuff.
30 * - changed occurrances of '/' as path delimiters to macro from portab.h
31 * - changed the handling of the tmp directory -- will no longer always be
32 * ".", if possible, environment variables "TMP" or, if not set, "TMP",
33 * or, if not set "." will be used.
36 # include "splintMacros.nf"
40 # include "usymtab_interface.h"
43 # include "exprChecks.h"
44 # include "filelocStack.h"
45 # include "fileIdList.h"
51 extern /*@external@*/ int yydebug;
52 extern /*@external@*/ int mtdebug;
64 CX_FUNCTION, CX_FCNDECLARATION,
65 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
66 CX_ITERDEF, CX_ITEREND,
67 CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
68 CX_LCL, CX_LCLLIB, CX_MT
74 int speclinesprocessed;
76 flagMarkerList markers;
79 ** used to record state where a macro must match a function name
80 ** (i.e., no params were listed in the macro definition
83 bool macroMissingParams BOOLBITS;
84 bool preprocessing BOOLBITS;
85 bool incommandline BOOLBITS;
86 bool insuppressregion BOOLBITS;
87 bool inDerivedFile BOOLBITS;
88 bool instandardlib BOOLBITS;
89 bool inimport BOOLBITS;
90 bool inheader BOOLBITS;
91 bool inmacrocache BOOLBITS;
92 bool protectVars BOOLBITS;
94 bool showfunction BOOLBITS;
95 bool savedFlags BOOLBITS;
96 bool justpopped BOOLBITS;
97 bool anyExports BOOLBITS;
98 bool inFunctionHeader BOOLBITS;
111 filelocStack locstack;
114 /*@observer@*/ sRef aliasAnnote;
115 /*@observer@*/ sRef aliasAnnoteAls;
119 /*@observer@*/ sRefSet mods;
121 /* file access types */
124 /* local access types (this function) */
127 /* no access types (@noaccess) */
130 /*@observer@*/ globSet globs;
131 /*@only@*/ globSet globs_used;
135 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
141 bool flags[NUMFLAGS];
142 bool saveflags[NUMFLAGS];
143 bool setGlobally[NUMFLAGS];
144 bool setLocally[NUMFLAGS];
146 int values[NUMVALUEFLAGS];
147 int counters[NUMVALUEFLAGS];
149 o_cstring strings[NUMSTRINGFLAGS];
150 sRefSetList modrecs; /*@i32 ???? what is this for? */
152 metaStateTable stateTable; /* User-defined state information. */
153 annotationTable annotTable; /* User-defined annotations table. */
158 /*@dependent@*/ /*@exposed@*/ uentry fcn;
162 union u_cont savecont;
165 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
166 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
167 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
168 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
170 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
171 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
172 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
173 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
174 static void context_setFlag (flagcode p_f, bool p_b, fileloc p_loc)
175 /*@modifies gc.flags@*/ ;
178 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile,
179 bool p_isRestore, fileloc p_loc)
180 /*@modifies gc.flags@*/ ;
182 static void context_restoreFlag (flagcode p_f, fileloc p_loc)
183 /*@modifies gc.flags@*/ ;
187 cstring context_unparseFlagMarkers ()
189 return (flagMarkerList_unparse (gc.markers));
192 void context_setPreprocessing (void)
194 llassert (!gc.preprocessing);
195 gc.preprocessing = TRUE;
198 void context_clearPreprocessing (void)
200 llassert (gc.preprocessing);
201 gc.preprocessing = FALSE;
204 bool context_isPreprocessing (void)
206 return gc.preprocessing;
209 bool context_loadingLibrary (void)
211 return (fileloc_isLib (g_currentloc));
214 bool context_inXHFile (void)
216 return (fileloc_isXHFile (g_currentloc));
219 void context_setInCommandLine (void)
221 llassert (!gc.incommandline);
222 gc.incommandline = TRUE;
225 void context_clearInCommandLine (void)
227 llassert (gc.incommandline);
228 gc.incommandline = FALSE;
231 bool context_isInCommandLine (void)
233 return gc.incommandline;
237 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
240 clauseStack_push (gc.clauses, c);
242 if (clause_isConditional (c)
243 && context_getFlag (FLG_CONTROLNESTDEPTH))
245 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
246 int depth = clauseStack_controlDepth (gc.clauses);
248 if (depth == maxdepth + 1)
251 (FLG_CONTROLNESTDEPTH,
252 message ("Maximum control nesting depth "
261 clause topClause (clauseStack s) /*@*/
263 if (clauseStack_isEmpty (s)) return NOCLAUSE;
264 return ((clause) clauseStack_top (s));
268 context_addMacroCache (/*@only@*/ cstring def)
270 DPRINTF (("macro cache: %s", def));
271 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
275 context_addComment (/*@only@*/ cstring def, fileloc loc)
277 macrocache_addComment (gc.mc, fileloc_copy (loc), def);
281 ** returns TRUE is fl is in ignore region, or region where -code
283 ** the logic is fuzzy...
287 context_inSuppressFlagZone (fileloc fl, flagcode code)
289 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
292 if (ynm_isMaybe (ret))
300 res = !gc.saveflags[code];
304 res = !context_getFlag (code);
309 res = ynm_toBoolStrict (ret);
316 context_suppressSystemMsg (fileloc fl)
318 if (context_getFlag (FLG_SYSTEMDIRERRORS))
324 return (fileloc_isSystemFile (fl));
329 context_suppressFlagMsg (flagcode flag, fileloc fl)
331 if (context_suppressSystemMsg (fl))
336 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
338 /* want same object compare here */
340 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
342 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
344 return (!context_getFlag (flag)
345 || context_inSuppressRegion ()
346 || context_inSuppressZone (fl)
347 || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
351 return (context_inSuppressFlagZone (fl, flag));
356 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
359 if (context_suppressSystemMsg (fl))
365 if (fl == g_currentloc)
366 /*@noaccess fileloc@*/
368 return (context_getFlag (flag) || context_inSuppressRegion ());
373 return (context_getFlag (flag) || context_inSuppressRegion ());
378 context_inSuppressZone (fileloc fl)
380 if (context_suppressSystemMsg (fl))
385 return (flagMarkerList_inIgnore (gc.markers, fl));
389 context_inSuppressRegion (void)
391 return (gc.insuppressregion);
395 context_enterSuppressRegion (fileloc loc)
397 if (gc.insuppressregion)
399 gc.insuppressregion = FALSE; /* get this msg! */
401 ("%q: New ignore errors region entered while in ignore errors region",
402 fileloc_unparse (loc)));
405 gc.insuppressregion = TRUE;
406 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (loc));
410 context_addFlagMarker (flagcode code, ynm set, fileloc loc)
412 (void) flagMarkerList_add (gc.markers,
413 flagMarker_createLocalSet (code, set, loc));
417 context_enterSuppressLine (int count, fileloc loc)
419 if (context_processingMacros ())
424 if (flagMarkerList_add
426 flagMarker_createIgnoreCount (count, loc)))
428 fileloc nextline = fileloc_copy (loc);
429 fileloc_nextLine (nextline);
430 fileloc_setColumn (nextline, 0);
432 check (flagMarkerList_add (gc.markers,
433 flagMarker_createIgnoreOff (nextline)));
434 fileloc_free (nextline);
438 void context_checkSuppressCounts (void)
440 if (context_getFlag (FLG_SUPCOUNTS))
442 flagMarkerList_checkSuppressCounts (gc.markers);
446 void context_incLineno (void)
453 context_exitSuppressRegion (fileloc loc)
455 if (!gc.insuppressregion)
459 message ("End ignore errors in region while not ignoring errors"),
463 gc.insuppressregion = FALSE;
464 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (loc));
468 context_enterMTfile (void)
474 context_exitMTfile (void)
476 llassert (gc.kind == CX_MT);
482 context_enterLCLfile (void)
485 gc.facct = typeIdSet_emptySet ();
490 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
494 for (i = 0; i < gc.nmods; i++)
496 if (cstring_equal (gc.moduleaccess[i].file, fname))
498 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
499 cstring_free (fname);
504 if (gc.nmods == gc.maxmods)
508 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
509 oldmods = gc.moduleaccess;
511 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
513 for (i = 0; i < gc.nmods; i++)
515 gc.moduleaccess[i] = oldmods[i];
521 gc.moduleaccess[gc.nmods].file = fname;
522 gc.moduleaccess[gc.nmods].daccess = mods;
528 insertModuleAccess (cstring fname, typeId t)
532 for (i = 0; i < gc.nmods; i++)
534 if (cstring_equal (gc.moduleaccess[i].file, fname))
536 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
541 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
546 context_exitLCLfile (void)
548 if (gc.kind != CX_LCLLIB)
551 fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION);
553 addModuleAccess (fileLib_removePath (lclname), gc.facct);
554 cstring_free (lclname);
559 gc.facct = typeIdSet_emptySet ();
564 context_dumpModuleAccess (FILE *fout)
568 for (i = 0; i < gc.nmods; i++)
570 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
572 fprintf (fout, "%s#%s@\n",
573 cstring_toCharsSafe (gc.moduleaccess[i].file),
574 cstring_toCharsSafe (td));
580 bool context_usingPosixLibrary ()
582 return (gc.library == FLG_POSIXLIB
583 || gc.library == FLG_POSIXSTRICTLIB
584 || gc.library == FLG_UNIXLIB
585 || gc.library == FLG_UNIXSTRICTLIB);
588 bool context_usingAnsiLibrary ()
590 return (gc.library != FLG_NOLIB);
593 flagcode context_getLibrary ()
598 void context_setLibrary (flagcode code)
603 /*@observer@*/ cstring context_selectedLibrary ()
608 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
610 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
611 case FLG_POSIXSTRICTLIB:
612 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
614 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
615 case FLG_UNIXSTRICTLIB:
616 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
618 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
625 context_loadModuleAccess (FILE *in)
627 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
629 char *name = mstring_create (MAX_NAME_LENGTH);
635 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
641 while (s != NULL && *s != ';' && *s != '\0')
645 while (*s != '#' && *s != '\0')
654 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
655 cstring_fromChars (s)));
661 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
662 typeIdSet_undump (&s));
664 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
665 llassert (s != lasts);
675 typeIdSet context_fileAccessTypes (void)
681 context_resetModeFlags (void)
685 if (flagcode_isModeFlag (code))
687 context_setFlag (code, FALSE, g_currentloc);
695 ** Set all flags to FALSE, except for a few which are
698 ** Set all values and strings to appropriate defaults.
699 ** Set all counters to 0.
703 conext_resetAllCounters (void)
707 for (i = 0; i < NUMVALUEFLAGS; i++)
714 context_resetAllFlags (void)
716 DPRINTF (("******** Reset all flags"));
720 gc.flags[code] = FALSE;
722 if (flagcode_hasNumber (code))
726 /*@-loopswitchbreak@*/
730 val = DEFAULT_LIMIT; break;
732 val = DEFAULT_BUGSLIMIT; break;
734 val = DEFAULT_LINELEN; break;
735 case FLG_INDENTSPACES:
736 val = DEFAULT_INDENTSPACES; break;
737 case FLG_EXTERNALNAMELEN:
738 val = ISO99_EXTERNALNAMELEN; break;
739 case FLG_INTERNALNAMELEN:
740 val = ISO99_INTERNALNAMELEN; break;
741 case FLG_COMMENTCHAR:
742 val = (int) DEFAULT_COMMENTCHAR; break;
743 case FLG_CONTROLNESTDEPTH:
744 val = (int) ISO99_CONTROLNESTDEPTH; break;
745 case FLG_STRINGLITERALLEN:
746 val = (int) ISO99_STRINGLITERALLEN; break;
747 case FLG_INCLUDENEST:
748 val = (int) ISO99_INCLUDENEST; break;
749 case FLG_NUMSTRUCTFIELDS:
750 val = (int) ISO99_NUMSTRUCTFIELDS; break;
751 case FLG_NUMENUMMEMBERS:
752 val = (int) ISO99_NUMENUMMEMBERS; break;
757 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
759 /*@=loopswitchbreak@*/
761 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
762 context_setValue (code, val);
763 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
764 llassert (context_getValue (code) == val);
766 else if (flagcode_hasChar (code))
768 llassert (code == FLG_COMMENTCHAR);
769 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
771 else if (flagcode_hasString (code))
773 cstring val = cstring_undefined;
776 { /*@-loopswitchbreak@*/
779 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
781 if (cstring_isDefined (larchpath))
783 val = cstring_copy (larchpath);
787 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
792 case FLG_LCLIMPORTDIR:
794 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
798 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
800 char *env = osd_getEnvironmentVariable ("TMP");
804 env = osd_getEnvironmentVariable ("TEMP");
807 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
810 val = cstring_makeLiteral (DEFAULT_TMPDIR);
811 # endif /* !defined(OS2) && !defined(MSDOS) */
815 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
817 val = cstring_makeLiteral ("FALSE"); break;
819 val = cstring_makeLiteral ("TRUE"); break;
820 case FLG_MACROVARPREFIX:
821 val = cstring_makeLiteral ("m_"); break;
823 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
826 } /*@=loopswitchbreak@*/
828 context_setString (code, val);
832 ; /* nothing to set */
837 ** These flags are true by default.
840 /*@i34 move this into flags.def */
842 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
843 gc.flags[FLG_MODIFIES] = TRUE;
844 gc.flags[FLG_NESTCOMMENT] = TRUE;
845 gc.flags[FLG_GLOBALS] = TRUE;
846 gc.flags[FLG_FULLINITBLOCK] = TRUE;
847 gc.flags[FLG_INITSIZE] = TRUE;
848 gc.flags[FLG_INITALLELEMENTS] = TRUE;
850 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
852 gc.flags[FLG_LIKELYBOOL] = TRUE;
853 gc.flags[FLG_ZEROPTR] = TRUE;
854 gc.flags[FLG_NUMLITERAL] = TRUE;
855 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
856 gc.flags[FLG_SKIPISOHEADERS] = TRUE;
857 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
858 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
859 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
860 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
861 gc.flags[FLG_CASTFCNPTR] = TRUE;
862 gc.flags[FLG_DOLCS] = TRUE;
863 gc.flags[FLG_USEVARARGS] = TRUE;
864 gc.flags[FLG_MAINTYPE] = TRUE;
865 gc.flags[FLG_SPECMACROS] = TRUE;
866 gc.flags[FLG_REDEF] = TRUE;
867 gc.flags[FLG_MACRONEXTLINE] = TRUE;
869 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
870 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
872 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
873 gc.flags[FLG_WARNUSE] = TRUE;
874 gc.flags[FLG_PREDASSIGN] = TRUE;
875 gc.flags[FLG_MODOBSERVER] = TRUE;
876 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
877 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
879 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
880 gc.flags[FLG_RETIMPONLY] = TRUE;
881 gc.flags[FLG_GLOBIMPONLY] = TRUE;
882 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
883 gc.flags[FLG_PREPROC] = TRUE;
884 gc.flags[FLG_NAMECHECKS] = TRUE;
885 gc.flags[FLG_FORMATCODE] = TRUE;
886 gc.flags[FLG_FORMATTYPE] = TRUE;
887 gc.flags[FLG_BADFLAG] = TRUE;
888 gc.flags[FLG_WARNFLAGS] = TRUE;
889 gc.flags[FLG_WARNRC] = TRUE;
890 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
891 gc.flags[FLG_WARNUNIXLIB] = TRUE;
892 gc.flags[FLG_WARNPOSIX] = TRUE;
893 gc.flags[FLG_SHOWCOL] = TRUE;
894 gc.flags[FLG_SHOWFUNC] = TRUE;
895 gc.flags[FLG_SUPCOUNTS] = TRUE;
896 gc.flags[FLG_HINTS] = TRUE;
897 gc.flags[FLG_SYNTAX] = TRUE;
898 gc.flags[FLG_TYPE] = TRUE;
899 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
900 gc.flags[FLG_ABSTRACT] = TRUE;
901 gc.flags[FLG_ITERBALANCE] = TRUE;
902 gc.flags[FLG_ITERYIELD] = TRUE;
903 gc.flags[FLG_DUPLICATECASES] = TRUE;
904 gc.flags[FLG_ALWAYSEXITS] = TRUE;
905 gc.flags[FLG_EMPTYRETURN] = TRUE;
906 gc.flags[FLG_MACRORETURN] = TRUE;
907 gc.flags[FLG_UNRECOG] = TRUE;
908 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
909 gc.flags[FLG_LINTCOMMENTS] = TRUE;
910 gc.flags[FLG_ACCESSCZECH] = TRUE;
911 gc.flags[FLG_ACCESSMODULE] = TRUE;
912 gc.flags[FLG_ACCESSFILE] = TRUE;
913 gc.flags[FLG_MACROVARPREFIX] = TRUE;
915 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
916 gc.flags[FLG_COMMENTERROR] = TRUE;
919 ** Changed for version 2.4.
922 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
928 /* commenting ou until some output issues are fixed */
929 /* gc.flags[FLG_ORCONSTRAINT] = TRUE;*/
931 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
934 gc.flags[FLG_WARNSYSFILES] = TRUE;
937 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
941 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
946 ** C is way-lame, and you can initialize an array to a constant except where
947 ** it is declared. Hence, a macro is used to set the modeflags.
951 # define SETFLAGS() \
952 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
953 if (!flagcode_isModeFlag (modeflags[i])) \
954 { llbug (message ("not a mode flag: %s", \
955 flagcode_unparse (modeflags[i]))); } \
956 else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }}
958 static void context_setModeAux (cstring p_s, bool p_warn) ;
961 context_setMode (cstring s)
963 context_setModeAux (s, TRUE);
967 context_setModeNoWarn (cstring s)
969 context_setModeAux (s, FALSE);
973 context_setModeAux (cstring s, bool warn)
975 intSet setflags = intSet_new ();
979 if (flagcode_isModeFlag (code))
981 if (gc.setGlobally[code])
983 (void) intSet_insert (setflags, (int) code);
988 if (!intSet_isEmpty (setflags))
990 cstring rflags = cstring_undefined;
993 intSet_elements (setflags, el)
995 if (cstring_isUndefined (rflags))
997 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
1001 rflags = message ("%q, %s", rflags,
1002 flagcode_unparse ((flagcode) el));
1006 if (num > 4 && intSet_size (setflags) > 6)
1008 rflags = message ("%q, (%d others) ...", rflags,
1009 intSet_size (setflags) - num);
1012 } end_intSet_elements ;
1016 voptgenerror (FLG_WARNFLAGS,
1017 message ("Setting mode %s after setting mode flags will "
1018 "override set values of flags: %s",
1023 cstring_free (rflags);
1026 intSet_free (setflags);
1028 context_resetModeFlags ();
1030 if (cstring_equalLit (s, "standard"))
1032 flagcode modeflags[] =
1034 FLG_ENUMINT, FLG_MACROMATCHNAME,
1035 FLG_STRINGLITNOROOM,
1036 FLG_MACROUNDEF, FLG_RELAXQUALS,
1037 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1038 FLG_CHECKSTRICTGLOBALIAS,
1039 FLG_CHECKEDGLOBALIAS,
1040 FLG_CHECKMODGLOBALIAS,
1041 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1042 FLG_UNSIGNEDCOMPARE,
1043 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1045 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1046 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1047 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1048 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1049 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1052 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1053 FLG_MACROSTMT, FLG_MACROPARENS,
1056 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1057 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1062 /* memchecks flags */
1064 FLG_NULLSTATE, FLG_NULLASSIGN,
1065 FLG_NULLPASS, FLG_NULLRET,
1067 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1070 /* memtrans flags */
1089 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1092 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1093 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1096 FLG_STATETRANSFER, FLG_STATEMERGE,
1097 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1099 FLG_IMPCHECKEDSPECGLOBALS,
1100 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1101 FLG_IFEMPTY, FLG_REALCOMPARE,
1102 FLG_BOOLOPS, FLG_PTRNEGATE,
1104 FLG_SHIFTIMPLEMENTATION,
1105 FLG_BUFFEROVERFLOWHIGH,
1112 else if (cstring_equalLit (s, "weak"))
1114 flagcode modeflags[] =
1116 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1117 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1118 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1119 FLG_CHARUNSIGNEDCHAR,
1121 FLG_VARUNUSED, FLG_FUNCUNUSED,
1123 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1126 FLG_BUFFEROVERFLOWHIGH,
1127 FLG_RETSTACK, FLG_PTRNEGATE,
1128 FLG_STATETRANSFER, FLG_STATEMERGE,
1129 FLG_LONGUNSIGNEDINTEGRAL,
1130 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1134 FLG_BUFFEROVERFLOWHIGH,
1140 else if (cstring_equalLit (s, "checks"))
1142 flagcode modeflags[] =
1144 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1145 FLG_STATETRANSFER, FLG_STATEMERGE,
1146 FLG_CHECKSTRICTGLOBALIAS,
1147 FLG_CHECKEDGLOBALIAS,
1148 FLG_CHECKMODGLOBALIAS,
1149 FLG_UNCHECKEDGLOBALIAS,
1151 FLG_STRINGLITNOROOM,
1152 FLG_STRINGLITNOROOMFINALNULL,
1153 FLG_STRINGLITSMALLER,
1154 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1155 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1156 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1157 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1158 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1159 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1160 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1161 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1162 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1163 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1164 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1165 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1166 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1167 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1174 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1178 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1180 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1181 FLG_EVALORDER, FLG_USEDEF,
1184 /* warn use flags */
1185 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1186 FLG_BUFFEROVERFLOWHIGH,
1188 /* memchecks flags */
1190 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1191 FLG_NULLPASS, FLG_NULLRET,
1193 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1195 /* memtrans flags */
1209 FLG_STATICINITTRANS,
1210 FLG_UNKNOWNINITTRANS,
1213 FLG_ONLYUNQGLOBALTRANS,
1214 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1217 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1218 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1221 FLG_NULLPOINTERARITH,
1222 FLG_SHADOW, FLG_DEPARRAYS,
1223 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1224 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1225 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1226 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1227 FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES,
1228 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1229 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1230 FLG_SHIFTIMPLEMENTATION,
1231 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1236 else if (cstring_equalLit (s, "strict"))
1238 flagcode modeflags[] =
1240 FLG_CHECKSTRICTGLOBALIAS,
1241 FLG_CHECKEDGLOBALIAS,
1242 FLG_CHECKMODGLOBALIAS,
1243 FLG_UNCHECKEDGLOBALIAS,
1247 FLG_STRINGLITNOROOM,
1248 FLG_STRINGLITNOROOMFINALNULL,
1249 FLG_STRINGLITSMALLER,
1250 FLG_STATETRANSFER, FLG_STATEMERGE,
1251 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1252 FLG_ALLGLOBALS, FLG_IMPTYPE,
1253 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1254 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1255 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1256 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1259 FLG_ONLYUNQGLOBALTRANS,
1260 FLG_GLOBALSIMPMODIFIESNOTHING,
1261 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1262 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1263 FLG_USEALLGLOBS, FLG_RETALIAS,
1264 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1265 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1266 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1268 FLG_EXPORTITER, FLG_EXPORTCONST,
1269 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1270 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1272 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1274 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1275 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1276 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1277 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1278 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1279 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1280 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1281 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1283 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1286 FLG_MACROREDEF, FLG_MACROEMPTY,
1287 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1289 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1291 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1292 FLG_MODOBSERVERUNCON,
1297 /* warn use flags */
1298 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1299 FLG_BUFFEROVERFLOWHIGH,
1300 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1302 /* memchecks flags */
1303 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1304 FLG_NULLPASS, FLG_NULLRET,
1306 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1308 /* memtrans flags */
1324 FLG_STATICINITTRANS,
1325 FLG_UNKNOWNINITTRANS,
1327 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1330 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1331 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1335 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1337 FLG_SHADOW, FLG_DEPARRAYS,
1338 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1339 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1340 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1341 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1342 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1343 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1344 FLG_IMPCHECKEDSTRICTSTATICS,
1345 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1346 FLG_IMPCHECKMODINTERNALS,
1347 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1348 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1349 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1350 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1351 FLG_CONTROLNESTDEPTH,
1352 FLG_FORBLOCK, FLG_WHILEBLOCK,
1353 FLG_FOREMPTY, FLG_WHILEEMPTY,
1354 FLG_IFEMPTY, FLG_IFBLOCK,
1356 FLG_REALCOMPARE, FLG_BOOLOPS,
1357 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1360 FLG_SHIFTIMPLEMENTATION,
1362 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1370 llcontbug (message ("context_setMode: bad mode: %s", s));
1375 context_isSpecialFile (cstring fname)
1377 cstring ext = fileLib_getExtension (fname);
1379 return (cstring_equalLit (ext, ".y")
1380 || cstring_equalLit (ext, ".l")
1381 || cstring_equalLit (fname, "lex.yy.c"));
1385 context_isSystemDir (cstring dir)
1387 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1388 cstring savedir = thisdir;
1389 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1391 if (cstring_isDefined (nextdir))
1393 /*@access cstring@*/
1394 *nextdir = '\0'; /* closes thisdir */
1396 /*@noaccess cstring@*/
1399 /* 2001-09-09: added thisdir[0] != '\0'
1400 ** herbert: don't compare with an empty name!
1401 ** should return false for empty directory path
1404 while (!cstring_isEmpty (thisdir))
1406 DPRINTF (("Test: %s / %s", dir, thisdir));
1408 if (osd_equalCanonicalPrefix (dir, thisdir))
1410 cstring_free (savedir);
1414 if (cstring_isDefined (nextdir))
1417 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1419 if (cstring_isDefined (nextdir))
1421 /*@access cstring@*/
1424 /*@noaccess cstring@*/
1433 DPRINTF (("Returns FALSE"));
1434 cstring_free (savedir);
1439 context_addFileAccessType (typeId t)
1443 if (context_inFunctionLike ())
1445 gc.acct = typeIdSet_insert (gc.acct, t);
1448 gc.facct = typeIdSet_insert (gc.facct, t);
1450 base = fileloc_getBase (g_currentloc);
1451 insertModuleAccess (base, t);
1452 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1453 typeIdSet_unparse (gc.acct)));
1457 context_removeFileAccessType (typeId t)
1459 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1460 || gc.kind == CX_UNKNOWNMACRO)
1462 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1465 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1466 gc.nacct = typeIdSet_insert (gc.nacct, t);
1469 void context_enterFunctionHeader (void)
1471 if (context_getFlag (FLG_GRAMMAR))
1473 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1476 if (gc.kind != CX_GLOBAL)
1478 llparseerror (cstring_makeLiteral
1479 ("Likely parse error. Function header outside global context."));
1483 llassert (gc.kind == CX_GLOBAL);
1484 DPRINTF (("Enter function header!"));
1485 gc.inFunctionHeader = TRUE;
1489 void context_exitFunctionHeader (void)
1491 if (context_getFlag (FLG_GRAMMAR))
1493 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1496 DPRINTF (("Exit function header!"));
1497 gc.inFunctionHeader = FALSE;
1500 bool context_inFunctionHeader (void)
1502 return (gc.inFunctionHeader);
1505 void context_enterFunctionDeclaration (uentry e)
1507 if (context_getFlag (FLG_GRAMMAR))
1509 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1512 DPRINTF (("Enter function decl"));
1513 llassert (gc.savekind == CX_ERROR);
1514 gc.savekind = gc.kind;
1515 gc.savecont = gc.cont;
1516 gc.kind = CX_FCNDECLARATION;
1520 void context_exitFunctionDeclaration (void)
1522 if (context_getFlag (FLG_GRAMMAR))
1524 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1527 DPRINTF (("Exit function decl"));
1528 llassert (gc.savekind != CX_ERROR);
1529 llassert (gc.kind == CX_FCNDECLARATION);
1530 gc.kind = gc.savekind;
1531 gc.cont = gc.savecont;
1533 gc.savekind = CX_ERROR;
1535 if (context_getFlag (FLG_GRAMMAR))
1537 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1541 bool context_inFunctionDeclaration (void)
1543 return (gc.kind == CX_FCNDECLARATION);
1548 context_enterMacro (/*@observer@*/ uentry e)
1550 context_enterFunction (e);
1551 gc.kind = CX_MACROFCN;
1555 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1557 llassert (uentry_isFunction (e));
1558 context_enterFunction (e);
1559 gc.kind = CX_UNKNOWNMACRO;
1562 void context_enterAndClause (exprNode e)
1565 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1566 pushClause (ANDCLAUSE);
1569 void context_enterOrClause (exprNode e)
1571 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1572 pushClause (ORCLAUSE);
1575 bool context_inDeepLoop (void)
1577 bool inLoop = FALSE;
1579 clauseStack_elements (gc.clauses, el)
1581 if (clause_isLoop (el))
1590 } end_clauseStack_elements;
1595 bool context_inDeepSwitch (void)
1597 bool inLoop = FALSE;
1599 clauseStack_elements (gc.clauses, el)
1601 if (clause_isSwitch (el))
1610 } end_clauseStack_elements;
1615 bool context_inDeepLoopSwitch (void)
1617 bool inLoop = FALSE;
1619 clauseStack_elements (gc.clauses, el)
1621 if (clause_isBreakable (el))
1630 } end_clauseStack_elements;
1635 clause context_breakClause (void)
1637 clauseStack_elements (gc.clauses, el)
1639 if (clause_isSwitch (el))
1643 else if (clause_isLoop (el))
1651 } end_clauseStack_elements;
1656 clause context_nextBreakClause (void)
1658 bool hasOne = FALSE;
1660 clauseStack_elements (gc.clauses, el)
1662 if (clause_isBreakable (el))
1673 } end_clauseStack_elements;
1678 bool context_inConditional (void)
1680 clauseStack_elements (gc.clauses, el)
1683 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1684 ** to distinguish if from ? for this
1687 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1691 } end_clauseStack_elements;
1696 void context_exitAndClause (exprNode pred, exprNode tbranch)
1698 context_setJustPopped ();
1700 llassert (gc.inclause == ANDCLAUSE);
1702 usymtab_popAndBranch (pred, tbranch);
1703 clauseStack_pop (gc.clauses);
1704 gc.inclause = topClause (gc.clauses);
1707 void context_exitOrClause (exprNode pred, exprNode tbranch)
1709 context_setJustPopped ();
1711 llassert (gc.inclause == ORCLAUSE);
1713 usymtab_popOrBranch (pred, tbranch);
1714 clauseStack_pop (gc.clauses);
1715 gc.inclause = topClause (gc.clauses);
1718 static void context_enterCondClauseAux (clause cl)
1724 static void context_enterTrueAux (exprNode e, clause cl)
1727 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1731 void context_enterIterClause (void)
1733 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1736 void context_enterDoWhileClause (void)
1738 pushClause (DOWHILECLAUSE);
1741 void context_enterWhileClause (exprNode e)
1743 context_enterTrueAux (e, WHILECLAUSE);
1746 void context_enterForClause (exprNode e)
1748 context_enterTrueAux (e, FORCLAUSE);
1751 void context_enterTrueClause (exprNode e)
1753 context_enterTrueAux (e, TRUECLAUSE);
1756 void context_enterSwitch (exprNode e)
1758 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1759 usymtab_switchBranch (e);
1760 context_enterCondClauseAux (SWITCHCLAUSE);
1763 void context_exitSwitch (exprNode e, bool allpaths)
1765 usymtab_exitSwitch (e, allpaths);
1767 while (clause_isCase (clauseStack_top (gc.clauses)))
1769 clauseStack_pop (gc.clauses);
1772 context_exitClauseSimp ();
1775 void context_enterCaseClause (exprNode e)
1777 bool branch = FALSE;
1779 DPRINTF (("Enter case clause!"));
1781 branch = usymtab_newCase (exprNode_undefined, e);
1785 context_enterCondClauseAux (CASECLAUSE);
1789 static void context_enterFalseClauseAux (exprNode e, clause cl)
1792 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1794 clauseStack_switchTop (gc.clauses, cl);
1797 void context_enterFalseClause (exprNode e)
1800 context_enterFalseClauseAux (e, FALSECLAUSE);
1804 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1806 gc.kind = CX_MACROCONST;
1808 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1810 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1814 usymtab_enterScope ();
1815 sRef_enterFunctionScope ();
1817 gc.globs = globSet_undefined;
1818 globSet_clear (gc.globs_used);
1819 gc.mods = sRefSet_undefined;
1822 uentry context_getHeader (void)
1824 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1826 llfatalbug (message ("context_getHeader: bad call: %q",
1827 context_unparse ()));
1830 return (gc.cont.fcn);
1834 context_setFunctionDefined (fileloc loc)
1838 case CX_UNKNOWNMACRO:
1841 uentry_setFunctionDefined (gc.cont.fcn, loc);
1844 /* (not a bug because of parse errors) */
1850 context_enterFunction (/*@exposed@*/ uentry e)
1852 gc.kind = CX_FUNCTION;
1855 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1857 if (uentry_hasAccessType (e))
1859 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1867 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1868 typeIdSet_unparse (gc.acct)));
1870 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1872 gc.globs = uentry_getGlobs (e);
1873 globSet_clear (gc.globs_used);
1874 gc.mods = uentry_getMods (e);
1876 usymtab_enterFunctionScope (e);
1877 sRef_enterFunctionScope ();
1880 bool context_inOldSytleScope(void)
1882 if (gc.kind == CX_OLDSTYLESCOPE)
1889 context_enterOldStyleScope (void)
1891 gc.kind = CX_OLDSTYLESCOPE;
1892 DPRINTF (("Enter old style scope!"));
1893 usymtab_enterFunctionScope (uentry_undefined);
1897 context_completeOldStyleFunction (uentry e)
1899 llassert (gc.kind == CX_OLDSTYLESCOPE);
1901 gc.kind = CX_FUNCTION;
1904 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1906 if (uentry_hasAccessType (e))
1908 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1916 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1917 typeIdSet_unparse (gc.acct)));
1919 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1921 if (!globSet_isEmpty (uentry_getGlobs (e)))
1923 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1924 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1927 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1929 gc.globs = uentry_getGlobs (e);
1930 globSet_clear (gc.globs_used);
1932 gc.mods = uentry_getMods (e);
1934 if (!sRefSet_isEmpty (gc.mods))
1936 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1937 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1940 sRef_enterFunctionScope ();
1943 static bool context_checkStrictGlobals (void)
1945 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1948 static bool context_hasGlobs (void)
1950 if (context_inFunctionLike ())
1952 return (uentry_hasGlobs (gc.cont.fcn));
1960 static bool context_checkCheckedGlobals (void)
1962 return (context_getFlag (FLG_GLOBALS)
1963 && (context_getFlag (FLG_GLOBUNSPEC)
1964 || context_hasGlobs ()));
1967 static bool context_checkUnknownGlobals (void)
1969 /* should be uentry_hasGlobs ? */
1971 return (context_getFlag (FLG_ALLGLOBALS)
1972 && (context_getFlag (FLG_GLOBUNSPEC)
1973 || context_hasGlobs ()));
1976 static bool context_checkUncheckedGlobals (void)
1982 context_checkExport (uentry e)
1984 if (!gc.anyExports) return FALSE;
1986 if (uentry_isFunction (e)
1987 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1989 return context_maybeSet (FLG_EXPORTFCN);
1991 else if (uentry_isExpandedMacro (e))
1993 return context_maybeSet (FLG_EXPORTMACRO);
1995 else if (uentry_isVariable (e))
1997 return context_maybeSet (FLG_EXPORTVAR);
1999 else if (uentry_isEitherConstant (e))
2001 return context_maybeSet (FLG_EXPORTCONST);
2003 else if (uentry_isIter (e) || uentry_isEndIter (e))
2005 return context_maybeSet (FLG_EXPORTITER);
2007 else if (uentry_isDatatype (e))
2009 return context_maybeSet (FLG_EXPORTTYPE);
2018 context_checkGlobUse (uentry glob)
2021 if (uentry_isCheckedStrict (glob))
2023 return context_checkStrictGlobals ();
2025 else if (uentry_isChecked (glob))
2027 return context_checkCheckedGlobals ();
2029 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2031 return context_checkUnknownGlobals ();
2035 llassert (uentry_isUnchecked (glob));
2037 return context_checkUncheckedGlobals ();
2042 context_checkAliasGlob (uentry glob)
2044 if (uentry_isCheckedStrict (glob))
2046 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2048 else if (uentry_isChecked (glob))
2050 return gc.flags[FLG_CHECKEDGLOBALIAS];
2052 else if (uentry_isCheckMod (glob))
2054 return gc.flags[FLG_CHECKMODGLOBALIAS];
2058 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2060 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2064 bool context_checkInternalUse (void)
2066 if (context_hasGlobs ())
2068 return (gc.flags[FLG_INTERNALGLOBS]);
2072 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2077 context_checkGlobMod (sRef el)
2079 uentry ue = sRef_getUentry (el);
2081 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2083 if (uentry_isCheckedModify (ue)
2084 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2086 if (context_hasMods ())
2088 return (gc.flags[FLG_MODGLOBS]);
2092 if (uentry_isCheckedStrict (ue))
2094 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2098 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2104 if (context_hasMods ())
2106 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2116 context_usedGlobal (/*@exposed@*/ sRef el)
2118 if (!globSet_member (gc.globs_used, el))
2121 ** The first time a global is used in a function, we need
2122 ** to clear the derived sRefs, since they were set for the
2123 ** previous function.
2126 sRef_clearDerived (el);
2127 gc.globs_used = globSet_insert (gc.globs_used, el);
2131 /*@observer@*/ sRefSet
2132 context_modList (void)
2138 context_globAccess (sRef s)
2140 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2141 return (globSet_member (gc.globs, s));
2145 context_hasAccess (typeId t)
2147 if (context_inFunctionLike ())
2149 DPRINTF (("Access %d / %s",
2150 t, typeIdSet_unparse (gc.acct)));
2151 return (typeIdSet_member (gc.acct, t));
2155 return (context_hasFileAccess (t));
2160 context_hasFileAccess (typeId t)
2162 return (typeIdSet_member (gc.facct, t));
2166 context_unparseAccess (void)
2168 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2169 typeIdSet_unparse (gc.facct)));
2173 context_unparseClauses (void)
2175 return (clauseStack_unparse (gc.clauses));
2179 context_couldHaveAccess (typeId t)
2181 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2183 return (typeIdSet_member (gc.acct, t));
2187 return (typeIdSet_member (gc.facct, t));
2192 context_getRetType (void)
2194 ctype f = ctype_undefined;
2196 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2198 f = uentry_getType (gc.cont.fcn);
2200 else if (gc.kind == CX_UNKNOWNMACRO)
2202 return ctype_unknown;
2206 llcontbuglit ("context_getRetType: not in a function context");
2207 return ctype_unknown;
2210 if (!ctype_isFunction (f))
2212 if (ctype_isKnown (f))
2214 llbuglit ("context_getRetType: not a function");
2217 return ctype_unknown;
2219 return (ctype_getReturnType (f));
2223 context_hasMods (void)
2225 if (context_inFunctionLike ())
2227 return (uentry_hasMods (gc.cont.fcn));
2236 context_exitAllClauses (void)
2238 while (!clauseStack_isEmpty (gc.clauses))
2240 clause el = clauseStack_top (gc.clauses);
2243 if (clause_isNone (el))
2245 usymtab_quietExitScope (g_currentloc);
2246 clauseStack_pop (gc.clauses);
2250 context_exitClausePlain ();
2254 clauseStack_clear (gc.clauses);
2255 gc.inclause = NOCLAUSE;
2259 context_exitAllClausesQuiet (void)
2261 while (!clauseStack_isEmpty (gc.clauses))
2263 clause el = clauseStack_top (gc.clauses);
2266 usymtab_quietExitScope (g_currentloc);
2267 clauseStack_pop (gc.clauses);
2270 clauseStack_clear (gc.clauses);
2271 gc.inclause = NOCLAUSE;
2275 void context_exitClauseSimp (void)
2278 context_setJustPopped ();
2279 clauseStack_pop (gc.clauses);
2280 gc.inclause = topClause (gc.clauses);
2284 void context_exitCaseClause (void)
2286 context_setJustPopped ();
2287 usymtab_popCaseBranch ();
2288 clauseStack_pop (gc.clauses);
2289 gc.inclause = topClause (gc.clauses);
2293 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2295 context_setJustPopped ();
2296 /*@i32 was makeAlt */
2297 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2298 clauseStack_pop (gc.clauses);
2299 gc.inclause = topClause (gc.clauses);
2302 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2304 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2306 if (gc.inclause != TRUECLAUSE)
2308 llparseerror (cstring_makeLiteral
2309 ("Likely parse error. Conditional clauses are inconsistent."));
2313 context_setJustPopped ();
2314 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2315 clauseStack_pop (gc.clauses);
2316 gc.inclause = topClause (gc.clauses);
2319 void context_exitIterClause (exprNode body)
2321 llassert (gc.inclause == ITERCLAUSE);
2323 context_setJustPopped ();
2325 if (context_getFlag (FLG_ITERLOOPEXEC))
2327 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2331 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2334 clauseStack_pop (gc.clauses);
2335 gc.inclause = topClause (gc.clauses);
2338 static void context_popCase (void) {
2340 ** If we are exiting an outer clause, sometimes still in a switch case.
2354 DPRINTF (("Popping case clause: %s",
2355 clauseStack_unparse (gc.clauses)));
2357 if (gc.inclause == CASECLAUSE) {
2358 context_exitCaseClause ();
2362 void context_exitWhileClause (exprNode pred, exprNode body)
2364 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2368 if (gc.inclause != WHILECLAUSE) {
2369 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2370 clauseStack_unparse (gc.clauses)));
2373 llassert (gc.inclause == WHILECLAUSE);
2375 context_setJustPopped ();
2379 ** predicate must be false after while loop (unless there are breaks)
2382 if (context_getFlag (FLG_WHILELOOPEXEC))
2384 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2388 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2392 usymtab_addGuards (invGuards);
2393 guardSet_free (invGuards);
2395 clauseStack_pop (gc.clauses);
2396 gc.inclause = topClause (gc.clauses);
2399 void context_exitDoWhileClause (exprNode pred)
2401 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2403 if (gc.inclause == CASECLAUSE) {
2404 /* handle Duff's device */
2405 clauseStack_pop (gc.clauses);
2406 gc.inclause = topClause (gc.clauses);
2409 llassert (gc.inclause == DOWHILECLAUSE);
2411 context_setJustPopped ();
2414 usymtab_addGuards (invGuards);
2415 guardSet_free (invGuards);
2417 clauseStack_pop (gc.clauses);
2418 gc.inclause = topClause (gc.clauses);
2421 void context_exitForClause (exprNode forPred, exprNode body)
2423 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2425 llassert (gc.inclause == FORCLAUSE);
2426 context_setJustPopped ();
2428 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2431 ** Predicate must be false after for loop (unless there are breaks)
2434 if (context_getFlag (FLG_FORLOOPEXEC))
2436 DPRINTF (("Here: for loop exec"));
2437 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2441 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2442 && exprNode_loopMustExec (forPred))
2444 DPRINTF (("Here: loop must exec"));
2445 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2449 DPRINTF (("Pop true branch:"));
2450 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2454 usymtab_addGuards (invGuards);
2455 guardSet_free (invGuards);
2456 clauseStack_pop (gc.clauses);
2457 gc.inclause = topClause (gc.clauses);
2460 static void context_exitClausePlain (void)
2462 llassert (gc.inclause != NOCLAUSE);
2464 if (gc.inclause == FALSECLAUSE)
2466 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2470 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2474 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2476 context_setJustPopped ();
2478 if (gc.inclause == FALSECLAUSE)
2480 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2482 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2484 clauseStack_pop (gc.clauses);
2485 gc.inclause = topClause (gc.clauses);
2489 context_exitTrueClause (pred, tbranch);
2494 context_returnFunction (void)
2496 usymtab_checkFinalScope (TRUE);
2500 context_exitFunction (void)
2502 DPRINTF (("Exit function: %s", context_unparse ()));
2504 if (!context_inFunction () && !context_inMacroConstant ()
2505 && !context_inUnknownMacro ()
2506 && !context_inIterDef () && !context_inIterEnd ())
2509 ** not a bug because of parse errors
2516 if (context_inMacro () && usymtab_inFunctionScope ())
2518 usymtab_exitScope (exprNode_undefined);
2521 if (uentry_hasGlobs (gc.cont.fcn))
2523 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2527 if (uentry_hasMods (gc.cont.fcn))
2529 if (context_getFlag (FLG_MUSTMOD))
2531 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2535 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2538 ** clear file static modifies
2541 /* do this first to get unused error messages */
2543 usymtab_exitScope (exprNode_undefined);
2544 sRef_exitFunctionScope ();
2546 gc.showfunction = FALSE;
2547 gc.kind = CX_GLOBAL;
2548 gc.cont.glob = TRUE;
2550 gc.globs = globSet_new ();
2551 globSet_clear (gc.globs_used);
2552 gc.mods = sRefSet_new ();
2555 llassert (clauseStack_isEmpty (gc.clauses));
2556 llassert (gc.inclause == NOCLAUSE);
2557 DPRINTF (("After exit function: %s", context_unparse ()));
2561 context_quietExitFunction (void)
2563 while (gc.kind == CX_INNER)
2565 context_exitInnerPlain ();
2568 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2569 && !context_inIterDef () && !context_inIterEnd ())
2574 usymtab_quietExitScope (g_currentloc);
2576 gc.showfunction = FALSE;
2577 gc.kind = CX_GLOBAL;
2578 gc.cont.glob = TRUE;
2580 gc.globs = globSet_new ();
2581 globSet_clear (gc.globs_used);
2582 gc.mods = sRefSet_new ();
2584 sRef_exitFunctionScope ();
2588 /*@observer@*/ uentryList
2589 context_getParams (void)
2591 if (context_inFunctionLike ())
2593 return (uentry_getParams (gc.cont.fcn));
2597 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2598 return uentryList_undefined;
2602 /*@observer@*/ globSet
2603 context_getUsedGlobs (void)
2605 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2606 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2608 return (gc.globs_used);
2612 context_moduleName ()
2614 return (fileloc_getBase (g_currentloc));
2617 /*@observer@*/ globSet
2618 context_getGlobs (void)
2620 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2621 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2627 context_addBoolAccess (void)
2629 cstring bname = context_getString (FLG_BOOLTYPE);
2630 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2632 addModuleAccess (cstring_copy (bname), boolt);
2634 /* for sys/types (perhaps, this is bogus!) */
2635 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2640 context_canAccessBool (void)
2647 static typeId boolType = typeId_invalid;
2649 if (typeId_isInvalid (boolType))
2651 boolType = usymtab_getTypeId (context_getBoolName ());
2654 if (typeId_isInvalid (boolType)) {
2657 return (typeIdSet_member (gc.acct, boolType));
2662 /* evs 2000-07-25: old version - replaced */
2665 context_boolImplementationType () {
2666 /* For now, this is bogus! */
2671 context_canAccessBool (void)
2673 static typeId boolType = typeId_invalid;
2675 if (typeId_isInvalid (boolType))
2677 boolType = usymtab_getTypeId (context_getBoolName ());
2680 if (!typeId_isInvalid (boolType))
2682 return context_hasAccess (boolType);
2693 context_setMessageAnnote (/*@only@*/ cstring s)
2695 llassert (cstring_isUndefined (gc.msgAnnote));
2700 context_hasMessageAnnote (void)
2702 return (cstring_isDefined (gc.msgAnnote));
2706 context_clearMessageAnnote (void)
2708 if (cstring_isDefined (gc.msgAnnote))
2710 cstring_free (gc.msgAnnote);
2711 gc.msgAnnote = cstring_undefined;
2716 context_getMessageAnnote (void)
2718 cstring st = gc.msgAnnote;
2720 gc.msgAnnote = cstring_undefined;
2725 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2727 llassert (sRef_isInvalid (gc.aliasAnnote));
2728 llassert (!sRef_sameName (s, t));
2730 gc.aliasAnnoteAls = t;
2734 context_hasAliasAnnote (void)
2736 return (sRef_isValid (gc.aliasAnnote));
2740 context_clearAliasAnnote (void)
2742 gc.aliasAnnote = sRef_undefined;
2746 context_getAliasAnnote (void)
2748 sRef ret = gc.aliasAnnote;
2749 sRef als = gc.aliasAnnoteAls;
2751 llassert (sRef_isValid (ret) && sRef_isValid (als));
2753 gc.aliasAnnote = sRef_undefined;
2754 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2758 context_recordFileModifies (sRefSet mods)
2760 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2764 context_recordFileGlobals (globSet mods)
2766 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2767 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2771 context_setCommentMarkerChar (char c)
2773 llassert (c != '\0');
2775 context_setValue (FLG_COMMENTCHAR, (int) c);
2779 context_getCommentMarkerChar (void)
2781 return ((char) context_getValue (FLG_COMMENTCHAR));
2785 context_setValue (flagcode flag, int val)
2787 int index = flagcode_valueIndex (flag);
2789 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2797 llerror_flagWarning (message ("Value for %s must be a positive "
2798 "number (given %d)",
2799 flagcode_unparse (flag), val));
2802 if (flag == FLG_LINELEN && val < MINLINELEN)
2804 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2805 flagcode_unparse (flag),
2811 case FLG_INCLUDENEST:
2812 case FLG_CONTROLNESTDEPTH:
2813 case FLG_STRINGLITERALLEN:
2814 case FLG_NUMSTRUCTFIELDS:
2815 case FLG_NUMENUMMEMBERS:
2816 case FLG_INDENTSPACES:
2819 llerror_flagWarning (message ("Value for %s must be a non-negative "
2820 "number (given %d)",
2821 flagcode_unparse (flag), val));
2830 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2831 gc.values[index] = val;
2835 context_setValueAndFlag (flagcode flag, int val)
2837 gc.flags[flag] = TRUE;
2838 context_setValue (flag, val);
2842 context_getValue (flagcode flag)
2844 int index = flagcode_valueIndex (flag);
2846 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2847 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2848 return (gc.values[index]);
2852 context_getCounter (flagcode flag)
2854 int index = flagcode_valueIndex (flag);
2856 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2857 return (gc.counters[index]);
2861 context_incCounter (flagcode flag)
2863 int index = flagcode_valueIndex (flag);
2865 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2867 gc.counters[index]++;
2871 context_decCounter (flagcode flag)
2873 int index = flagcode_valueIndex (flag);
2875 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2876 gc.counters[index]--;
2879 bool context_showFunction (void)
2881 return (gc.showfunction);
2885 context_setString (flagcode flag, cstring val)
2887 int index = flagcode_stringIndex (flag);
2889 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2891 if (flag == FLG_SYSTEMDIRS)
2893 llassert (cstring_isDefined (val));
2895 if (cstring_firstChar (val) == '\"')
2898 cstring tval = cstring_copy (cstring_suffix (val, 1));
2900 if (cstring_lastChar (tval) != '\"')
2902 int n = cstring_length (tval) - 1;
2904 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2909 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2911 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2915 cstring otval = tval;
2916 tval = cstring_prefix (tval, size_fromInt (n));
2917 cstring_free (otval);
2921 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2922 DPRINTF (("val = %s", val));
2923 cstring_free (tval);
2924 cstring_free (oval);
2928 if (flag == FLG_TMPDIR)
2930 llassert (cstring_isDefined (val));
2932 if (cstring_length (val) == 0)
2935 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2937 else if (cstring_lastChar (val) != CONNECTCHAR)
2939 val = cstring_appendChar (val, CONNECTCHAR);
2947 if (cstring_length (val) >= 1
2948 && cstring_firstChar (val) == '\"')
2950 llerror_flagWarning (message
2951 ("setting %s to string beginning with \". You probably "
2952 "don't meant to have the \"'s.",
2953 flagcode_unparse (flag)));
2956 if (flag == FLG_BOOLTYPE)
2961 gc.strings[index] = val;
2964 static /*@exposed@*/ cstring
2965 context_exposeString (flagcode flag)
2967 int index = flagcode_stringIndex (flag);
2969 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2970 return (gc.strings[index]);
2974 context_getString (flagcode flag)
2976 return (context_exposeString (flag));
2980 context_resetErrors (void)
2985 void context_initMod (void)
2986 /*@globals undef gc; @*/
2988 gc.kind = CX_GLOBAL;
2990 gc.savekind = CX_ERROR;
2991 gc.savecont.glob = FALSE;
2993 gc.instandardlib = FALSE;
2996 gc.linesprocessed = 0;
2997 gc.speclinesprocessed = 0;
2998 gc.insuppressregion = FALSE;
2999 gc.macroMissingParams = FALSE;
3000 gc.preprocessing = FALSE;
3001 gc.incommandline = FALSE;
3002 gc.mc = macrocache_create ();
3004 gc.maxmods = DEFAULTMAXMODS;
3005 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3007 gc.library = FLG_ANSILIB;
3009 gc.locstack = filelocStack_new ();
3010 gc.modrecs = sRefSetList_undefined;
3011 gc.anyExports = FALSE;
3013 gc.ftab = fileTable_create ();
3014 gc.msgLog = messageLog_new ();
3015 gc.inimport = FALSE;
3016 gc.inDerivedFile = FALSE;
3017 gc.inheader = FALSE;
3018 gc.markers = flagMarkerList_new ();
3019 gc.cont.glob = TRUE;
3020 gc.showfunction = FALSE;
3021 gc.msgAnnote = cstring_undefined;
3022 gc.aliasAnnote = sRef_undefined;
3023 gc.aliasAnnoteAls = sRef_undefined;
3024 gc.boolType = ctype_bool;
3025 gc.mods = sRefSet_new ();
3027 gc.saveloc = fileloc_undefined;
3029 gc.inmacrocache = FALSE;
3030 gc.inclause = NOCLAUSE;
3031 gc.clauses = clauseStack_new ();
3032 gc.globs = globSet_new ();
3033 gc.nacct = typeIdSet_emptySet ();
3034 gc.acct = typeIdSet_emptySet ();
3035 gc.facct = typeIdSet_emptySet ();
3036 gc.savedFlags = FALSE;
3037 gc.pushloc = fileloc_undefined;
3038 gc.protectVars = FALSE;
3039 gc.justpopped = FALSE;
3040 gc.isNullGuarded = NO;
3041 gc.globs_used = globSet_undefined;
3045 gc.setGlobally[code] = FALSE;
3046 gc.setLocally[code] = FALSE;
3052 context_resetAllFlags ();
3054 assertSet (gc.flags); /* Can't use global in defines */
3055 assertSet (gc.saveflags);
3056 assertSet (gc.values);
3057 assertSet (gc.strings);
3059 conext_resetAllCounters ();
3060 assertSet (gc.counters);
3062 context_setMode (DEFAULT_MODE);
3064 gc.stateTable = metaStateTable_create ();
3065 gc.annotTable = annotationTable_create ();
3067 gc.inFunctionHeader = FALSE;
3069 DPRINTF (("Annotations: \n%s",
3070 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3071 DPRINTF (("State: \n%s",
3072 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3077 context_typeofZero (void)
3079 ctype ct = ctype_int;
3081 if (context_getFlag (FLG_ZEROPTR))
3083 ct = ctype_makeConj (ct, ctype_voidPointer);
3086 if (context_getFlag (FLG_ZEROBOOL)) {
3087 ct = ctype_makeConj (ct, ctype_bool);
3094 context_typeofOne (void)
3096 ctype ct = ctype_int;
3098 /* 1 is on longer a bool (was before 2.4)
3099 if (!context_getFlag (FLG_ABSTRACTBOOL))
3101 ct = ctype_makeConj (ct, ctype_bool);
3109 context_unparse (void)
3116 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3119 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3122 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3125 s = message ("Inner Context [%d] : %q",
3127 fileloc_unparse (g_currentloc));
3130 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3131 uentry_unparse (gc.cont.fcn),
3132 fileloc_unparse (g_currentloc),
3133 typeIdSet_unparse (gc.acct),
3134 sRefSet_unparse (gc.mods));
3137 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3139 case CX_UNKNOWNMACRO:
3140 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3143 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3146 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3149 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3151 case CX_FCNDECLARATION:
3152 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3155 s = message ("Un-unparseable context: %d", (int) gc.kind);
3159 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3164 context_currentFunctionType (void)
3166 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3168 return (uentry_getType (gc.cont.fcn));
3170 else if (gc.kind == CX_INNER)
3172 llcontbuglit ("context_currentFunctionType: inner context");
3173 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3174 return (context_currentFunctionType ());
3178 llcontbuglit ("context_currentFunctionType: not in function");
3179 return (ctype_undefined);
3184 context_enterInnerContext (void)
3186 if (context_getFlag (FLG_GRAMMAR))
3188 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3191 if (gc.kind == CX_GLOBAL)
3196 else if (gc.kind == CX_INNER)
3205 usymtab_enterScope ();
3206 pushClause (NOCLAUSE);
3210 context_exitInnerPlain (void) /*@modifies gc;@*/
3212 context_exitInner (exprNode_undefined);
3216 context_exitInner (exprNode exp)
3218 if (context_getFlag (FLG_GRAMMAR))
3220 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3223 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3224 ("inclause = %s", clause_nameTaken (gc.inclause)));
3226 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3227 gc.inclause = topClause (gc.clauses);
3229 if (gc.kind == CX_INNER)
3231 if (--gc.cont.cdepth == 0)
3233 gc.kind = CX_GLOBAL;
3234 gc.cont.glob = TRUE;
3239 if (gc.kind == CX_GLOBAL)
3241 llcontbuglit ("Attempt to exit global context");
3246 usymtab_exitScope (exp);
3251 context_enterStructInnerContext (void)
3253 if (context_getFlag (FLG_GRAMMAR))
3255 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3258 if (gc.kind == CX_GLOBAL)
3263 else if (gc.kind == CX_INNER)
3272 usymtab_enterScope ();
3274 if (context_getFlag (FLG_GRAMMAR))
3276 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3281 context_exitStructInnerContext (void)
3283 if (context_getFlag (FLG_GRAMMAR))
3285 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3288 if (gc.kind == CX_INNER)
3290 if (gc.cont.cdepth <= 0)
3292 llcontbuglit ("Attempt to exit inner context with no depth");
3293 gc.kind = CX_GLOBAL;
3294 gc.cont.glob = TRUE;
3300 if (gc.cont.cdepth == 0)
3302 gc.kind = CX_GLOBAL;
3303 gc.cont.glob = TRUE;
3309 if (gc.kind == CX_GLOBAL)
3311 llcontbuglit ("Attempt to exit global context");
3316 usymtab_exitScope (exprNode_undefined);
3318 if (context_getFlag (FLG_GRAMMAR))
3320 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3325 context_exitInnerSafe (void)
3327 if (context_getFlag (FLG_GRAMMAR))
3329 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3332 if (gc.kind == CX_INNER)
3334 if (--gc.cont.cdepth <= 0)
3339 else if (gc.kind == CX_GLOBAL)
3341 llcontbuglit ("Attempt to exit global context");
3346 if (usymtab_inDeepScope ())
3348 usymtab_exitScope (exprNode_undefined);
3354 void setModuleAccess (void)
3356 gc.facct = typeIdSet_emptySet ();
3358 if (fileId_isValid (currentFile ()))
3360 cstring baseName = fileloc_getBase (g_currentloc);
3362 if (context_getFlag (FLG_ACCESSFILE))
3364 if (usymtab_existsType (baseName))
3366 gc.facct = typeIdSet_insert (gc.facct,
3367 usymtab_getTypeId (baseName));
3375 if (context_getFlag (FLG_ACCESSMODULE))
3378 bool hasaccess = FALSE;
3380 for (i = 0; i < gc.nmods; i++)
3382 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3384 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3393 gc.inheader = fileId_isHeader (currentFile ());
3397 llcontbuglit ("Current file not defined\n");
3398 gc.facct = typeIdSet_emptySet ();
3400 gc.inheader = FALSE;
3403 /* 17 Jan 1995: forgot to clear nacct */
3405 gc.nacct = typeIdSet_emptySet ();
3409 context_enterFileAux (void)
3415 context_enterFile (void)
3417 context_enterFileAux ();
3418 usymtab_enterFile ();
3422 context_enterMacroFile (void)
3424 context_enterFileAux ();
3428 context_inFunction (void)
3430 kcontext ck = gc.kind;
3432 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3436 context_inFunctionLike (void)
3438 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3439 || gc.kind == CX_FCNDECLARATION
3440 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3444 context_inRealFunction (void)
3446 kcontext ck = gc.kind;
3448 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3452 context_processAllMacros (void)
3454 usymtab_enterFile ();
3456 gc.inmacrocache = TRUE;
3457 macrocache_processUndefinedElements (gc.mc);
3459 usymtab_exitFile ();
3461 gc.inmacrocache = FALSE;
3462 macrocache_finalize ();
3466 ** this happens once at the end of each C file
3468 ** check each Macro that was defined in current file.c or current file.h
3473 context_processMacros (void)
3475 if (fileId_isValid (currentFile ()))
3478 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3480 gc.inmacrocache = TRUE;
3482 DPRINTF (("Processing macros: %s", cbase));
3483 lastfl = macrocache_processFileElements (gc.mc, cbase);
3484 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3486 cstring_free (cbase);
3488 if (fileloc_isDefined (lastfl))
3490 g_currentloc = fileloc_update (g_currentloc, lastfl);
3494 gc.inmacrocache = FALSE;
3499 context_processingMacros (void)
3501 return (gc.inmacrocache);
3505 context_exitCFile (void)
3507 if (gc.kind != CX_GLOBAL)
3510 (cstring_makeLiteral ("File ended outside global scope"));
3513 if (gc.insuppressregion)
3515 /* gack...don't reverse the order of these lines! ;-> */
3516 gc.insuppressregion = FALSE;
3517 llerrorlit (FLG_SYNTAX,
3518 "File ended in ignore errors region, "
3519 "possible missing /*@end*/");
3522 /* fix up parse errors */
3524 while (!usymtab_inFileScope ())
3526 usymtab_quietExitScope (g_currentloc);
3530 ** Clear the file-specific modifies information.
3533 sRefSetList_elements (gc.modrecs, mods)
3535 sRefSet_clearStatics (mods);
3536 } end_sRefSetList_elements ;
3538 sRefSetList_clear (gc.modrecs);
3540 context_processMacros ();
3543 usymtab_exitFile ();
3545 gc.inDerivedFile = FALSE;
3546 filelocStack_clear (gc.locstack);
3548 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3550 gc.cont.glob = TRUE;
3554 context_restoreFlagSettings ();
3555 gc.savedFlags = FALSE;
3559 DPRINTF (("After exiting file: "));
3560 usymtab_printAll ();
3565 context_exitMacroCache (void)
3567 if (gc.kind != CX_GLOBAL)
3569 if (context_inMacro ())
3570 /* this is okay, file could end without newline in macro */
3572 DPRINTF (("Still in macro: %s",
3573 context_unparse ()));
3574 context_exitFunction ();
3578 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3579 context_unparse ()));
3580 gc.kind = CX_GLOBAL;
3585 ** no longer valid here
3586 ** if (gc.insuppressregion)
3588 ** gc.insuppressregion = FALSE;
3589 ** llerror ("File ended in ignore errors region, possible missing @");
3593 gc.cont.glob = TRUE;
3597 context_saveLocation (void)
3599 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3600 fileloc_free (gc.saveloc);
3601 gc.saveloc = fileloc_copy (g_currentloc);
3605 context_getSaveLocation (void)
3607 fileloc fl = gc.saveloc;
3608 gc.saveloc = fileloc_undefined;
3612 /*@observer@*/ cstring
3613 context_inFunctionName (void)
3615 if (gc.kind == CX_FUNCTION
3616 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3617 || gc.kind == CX_MACROCONST
3618 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3620 return (uentry_rawName (gc.cont.fcn));
3624 llcontbuglit ("context_inFunctionName: not in function");
3625 return (cstring_undefined);
3630 context_userSetFlag (flagcode f, bool b)
3632 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3634 if (f == FLG_NEVERINCLUDE && b)
3636 if (gc.flags[FLG_EXPORTHEADER])
3639 (cstring_makeLiteral
3640 ("setting +neverinclude after +exportheader. "
3641 "Turning off exportheader, since headers are not checked "
3642 "when +neverinclude is used."));
3644 gc.flags[FLG_EXPORTHEADER] = FALSE;
3649 if (f == FLG_EXPORTHEADER && b)
3651 if (gc.flags[FLG_NEVERINCLUDE])
3654 (cstring_makeLiteral
3655 ("setting +exportheader after +neverinclude. "
3656 "Not setting exportheader, since headers are not checked "
3657 "when +neverinclude is used."));
3658 gc.flags[FLG_EXPORTHEADER] = FALSE;
3664 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3666 bool lastsetting = context_getFlag (f);
3668 if (bool_equal (lastsetting, b)
3669 && !flagcode_isSpecialFlag (f)
3670 && !flagcode_isIdemFlag (f)
3671 && !flagcode_hasArgument (f))
3674 (message ("setting %s%s redundant with current value",
3675 cstring_makeLiteralTemp (b ? "+" : "-"),
3676 flagcode_unparse (f)));
3680 if (flagcode_isWarnUseFlag (f) && b)
3682 if (!context_getFlag (FLG_WARNUSE))
3685 (message ("flag +%s is canceled by -warnuse",
3686 flagcode_unparse (f)));
3691 if (flagcode_isLibraryFlag (f))
3693 if (gc.library != FLG_ANSILIB
3697 (message ("selecting library %s after library %s was "
3698 "selected (only one library may be used)",
3699 flagcode_unparse (f),
3700 flagcode_unparse (gc.library)));
3703 if (f == FLG_UNIXLIB)
3705 if (context_getFlag (FLG_WARNUNIXLIB))
3708 (cstring_makeLiteral
3709 ("selecting unix library. Unix library is "
3710 "ad hoc addition to POSIX library. Recommend "
3711 "use +posixlib to select POSIX library instead. "
3712 "Use -warnunixlib to suppress this message."));
3719 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3723 ("setting +%s will not produce warnings with -namechecks. "
3724 "Must set +namechecks also.",
3725 flagcode_unparse (f)));
3728 gc.setGlobally[f] = TRUE;
3729 context_setFlag (f, b, g_currentloc);
3733 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3737 context_saveFlagSettings ();
3740 if (ynm_isOff (set))
3742 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3744 else if (ynm_isOn (set))
3746 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3747 gc.setLocally[f] = TRUE;
3751 context_restoreFlag (f, loc);
3756 context_restoreFlag (flagcode f, fileloc loc)
3762 message ("Attempt to restore flag %s when no file scope flags "
3764 flagcode_unparse (f)),
3769 context_addFlagMarker (f, MAYBE, loc);
3770 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3776 context_setFlag (flagcode f, bool b, fileloc loc)
3778 context_setFlagAux (f, b, FALSE, FALSE, loc);
3782 context_setFlagTemp (flagcode f, bool b)
3784 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3789 # define DOSET(ff,b) \
3790 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3791 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3792 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3793 gc.flags[ff] = b; } while (FALSE)
3796 context_setFlagAux (flagcode f, bool b, bool inFile,
3797 /*@unused@*/ bool isRestore, fileloc loc)
3799 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3801 if (f == FLG_USESTDERR)
3804 g_msgstream = stderr;
3806 g_msgstream = stdout;
3811 ** Removed test for special flags.
3814 if (flagcode_isIdemFlag (f))
3823 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3825 if (b) /* Turing higher level on, turns on all lower levels */
3829 case FLG_ITS4MOSTRISKY:
3830 DOSET (FLG_ITS4VERYRISKY, b);
3832 case FLG_ITS4VERYRISKY:
3833 DOSET (FLG_ITS4RISKY, b);
3836 DOSET (FLG_ITS4MODERATERISK, b);
3838 case FLG_ITS4MODERATERISK:
3839 DOSET (FLG_ITS4LOWRISK, b);
3841 case FLG_ITS4LOWRISK:
3846 else /* Turning level off, turns off all higher levels */
3850 case FLG_ITS4LOWRISK:
3851 DOSET (FLG_ITS4MODERATERISK, b);
3853 case FLG_ITS4MODERATERISK:
3854 DOSET (FLG_ITS4RISKY, b);
3857 DOSET (FLG_ITS4VERYRISKY, b);
3859 case FLG_ITS4VERYRISKY:
3860 DOSET (FLG_ITS4MOSTRISKY, b);
3862 case FLG_ITS4MOSTRISKY:
3872 DOSET (FLG_ALLEMPTY, b);
3873 DOSET (FLG_IFEMPTY, b);
3874 DOSET (FLG_WHILEEMPTY, b);
3875 DOSET (FLG_FOREMPTY, b);
3878 DOSET (FLG_PREDBOOL, b);
3879 DOSET (FLG_PREDBOOLINT, b);
3880 DOSET (FLG_PREDBOOLPTR, b);
3881 DOSET (FLG_PREDBOOLOTHERS, b);
3884 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3885 DOSET (FLG_CHECKEDGLOBALIAS, b);
3886 DOSET (FLG_CHECKMODGLOBALIAS, b);
3887 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3890 DOSET (FLG_ALLBLOCK, b);
3891 DOSET (FLG_IFBLOCK, b);
3892 DOSET (FLG_WHILEBLOCK, b);
3893 DOSET (FLG_FORBLOCK, b);
3907 DOSET (FLG_GRAMMAR, b);
3909 case FLG_CODEIMPONLY:
3910 DOSET (FLG_CODEIMPONLY, b);
3911 DOSET (FLG_GLOBIMPONLY, b);
3912 DOSET (FLG_RETIMPONLY, b);
3913 DOSET (FLG_STRUCTIMPONLY, b);
3915 case FLG_SPECALLIMPONLY:
3916 DOSET (FLG_SPECALLIMPONLY, b);
3917 DOSET (FLG_SPECGLOBIMPONLY, b);
3918 DOSET (FLG_SPECRETIMPONLY, b);
3919 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3921 case FLG_ALLIMPONLY:
3922 DOSET (FLG_ALLIMPONLY, b);
3923 DOSET (FLG_GLOBIMPONLY, b);
3924 DOSET (FLG_RETIMPONLY, b);
3925 DOSET (FLG_STRUCTIMPONLY, b);
3926 DOSET (FLG_SPECGLOBIMPONLY, b);
3927 DOSET (FLG_SPECRETIMPONLY, b);
3928 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3930 case FLG_ANSI89LIMITS:
3931 DOSET (FLG_ANSI89LIMITS, b);
3932 DOSET (FLG_CONTROLNESTDEPTH, b);
3933 DOSET (FLG_STRINGLITERALLEN, b);
3934 DOSET (FLG_INCLUDENEST, b);
3935 DOSET (FLG_NUMSTRUCTFIELDS, b);
3936 DOSET (FLG_NUMENUMMEMBERS, b);
3940 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
3941 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
3942 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
3943 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
3944 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
3945 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
3946 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
3949 case FLG_ISO99LIMITS:
3950 DOSET (FLG_ISO99LIMITS, b);
3951 DOSET (FLG_CONTROLNESTDEPTH, b);
3952 DOSET (FLG_STRINGLITERALLEN, b);
3953 DOSET (FLG_INCLUDENEST, b);
3954 DOSET (FLG_NUMSTRUCTFIELDS, b);
3955 DOSET (FLG_NUMENUMMEMBERS, b);
3959 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
3960 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
3961 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
3962 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
3963 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
3964 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
3965 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
3968 case FLG_EXTERNALNAMELEN:
3969 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3970 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3972 case FLG_INTERNALNAMELEN:
3973 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3974 DOSET (FLG_INTERNALNAMELEN, TRUE);
3976 case FLG_EXTERNALNAMECASEINSENSITIVE:
3977 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3979 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3981 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3982 context_setValue (FLG_EXTERNALNAMELEN, 0);
3985 case FLG_INTERNALNAMECASEINSENSITIVE:
3986 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3988 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3990 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3991 context_setValue (FLG_INTERNALNAMELEN, 0);
3994 case FLG_INTERNALNAMELOOKALIKE:
3995 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3997 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3999 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4000 context_setValue (FLG_INTERNALNAMELEN, 0);
4004 DOSET (FLG_MODNOMODS, b);
4005 DOSET (FLG_MODGLOBSUNSPEC, b);
4006 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4009 DOSET (FLG_EXPORTVAR, b);
4010 DOSET (FLG_EXPORTFCN, b);
4011 DOSET (FLG_EXPORTTYPE, b);
4012 DOSET (FLG_EXPORTMACRO, b);
4013 DOSET (FLG_EXPORTCONST, b);
4014 gc.anyExports = TRUE;
4017 DOSET (FLG_RETEXPOSE, b);
4018 DOSET (FLG_ASSIGNEXPOSE, b);
4019 DOSET (FLG_CASTEXPOSE, b);
4022 DOSET (FLG_RETVALBOOL, b);
4023 DOSET (FLG_RETVALINT, b);
4024 DOSET (FLG_RETVALOTHER, b);
4029 DOSET (FLG_EXPORTLOCAL, FALSE);
4030 DOSET (FLG_DECLUNDEF, FALSE);
4031 DOSET (FLG_SPECUNDEF, FALSE);
4032 DOSET (FLG_TOPUNUSED, FALSE);
4036 DOSET (FLG_LOOPLOOPBREAK, b);
4037 DOSET (FLG_LOOPSWITCHBREAK, b);
4038 DOSET (FLG_SWITCHLOOPBREAK, b);
4039 DOSET (FLG_SWITCHSWITCHBREAK, b);
4040 DOSET (FLG_LOOPLOOPCONTINUE, b);
4041 DOSET (FLG_DEEPBREAK, b);
4044 DOSET (FLG_FORLOOPEXEC, b);
4045 DOSET (FLG_WHILELOOPEXEC, b);
4046 DOSET (FLG_ITERLOOPEXEC, b);
4049 DOSET (FLG_ACCESSMODULE, b);
4050 DOSET (FLG_ACCESSFILE, b);
4051 DOSET (FLG_ACCESSCZECH, b);
4054 DOSET (FLG_ALLMACROS, b);
4055 DOSET (FLG_FCNMACROS, b);
4056 DOSET (FLG_CONSTMACROS, b);
4059 DOSET (FLG_BOUNDSREAD, b);
4060 DOSET (FLG_BOUNDSWRITE, b);
4063 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4064 DOSET (FLG_CZECHFUNCTIONS, b);
4065 DOSET (FLG_CZECHVARS, b);
4066 DOSET (FLG_CZECHCONSTANTS, b);
4067 DOSET (FLG_CZECHTYPES, b);
4070 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4071 DOSET (FLG_SLOVAKFUNCTIONS, b);
4072 DOSET (FLG_SLOVAKVARS, b);
4073 DOSET (FLG_SLOVAKCONSTANTS, b);
4074 DOSET (FLG_SLOVAKTYPES, b);
4076 case FLG_CZECHOSLOVAK:
4077 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4078 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4079 DOSET (FLG_CZECHOSLOVAKVARS, b);
4080 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4081 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4084 DOSET (FLG_NULLSTATE, b);
4085 DOSET (FLG_NULLDEREF, b);
4086 DOSET (FLG_NULLASSIGN, b);
4087 DOSET (FLG_NULLPASS, b);
4088 DOSET (FLG_NULLRET, b);
4091 DOSET (FLG_MUSTFREEONLY, b);
4092 DOSET (FLG_MUSTFREEFRESH, b);
4095 DOSET (FLG_NULLSTATE, b);
4096 DOSET (FLG_NULLDEREF, b);
4097 DOSET (FLG_NULLASSIGN, b);
4098 DOSET (FLG_NULLPASS, b);
4099 DOSET (FLG_NULLRET, b);
4100 DOSET (FLG_COMPDEF, b);
4101 DOSET (FLG_COMPMEMPASS, b);
4102 DOSET (FLG_UNIONDEF, b);
4103 DOSET (FLG_MEMTRANS, b);
4104 DOSET (FLG_USERELEASED, b);
4105 DOSET (FLG_ALIASUNIQUE, b);
4106 DOSET (FLG_MAYALIASUNIQUE, b);
4107 DOSET (FLG_MUSTFREEONLY, b);
4108 DOSET (FLG_MUSTFREEFRESH, b);
4109 DOSET (FLG_MUSTDEFINE, b);
4110 DOSET (FLG_GLOBSTATE, b);
4111 DOSET (FLG_COMPDESTROY, b);
4112 DOSET (FLG_MUSTNOTALIAS, b);
4113 DOSET (FLG_MEMIMPLICIT, b);
4114 DOSET (FLG_BRANCHSTATE, b);
4115 /*@fallthrough@*/ /* also sets memtrans flags */
4117 DOSET (FLG_MEMTRANS, b);
4118 DOSET (FLG_EXPOSETRANS, b);
4119 DOSET (FLG_OBSERVERTRANS, b);
4120 DOSET (FLG_DEPENDENTTRANS, b);
4121 DOSET (FLG_NEWREFTRANS, b);
4122 DOSET (FLG_ONLYTRANS, b);
4123 DOSET (FLG_OWNEDTRANS, b);
4124 DOSET (FLG_FRESHTRANS, b);
4125 DOSET (FLG_SHAREDTRANS, b);
4126 DOSET (FLG_TEMPTRANS, b);
4127 DOSET (FLG_KEPTTRANS, b);
4128 DOSET (FLG_REFCOUNTTRANS, b);
4129 DOSET (FLG_STATICTRANS, b);
4130 DOSET (FLG_UNKNOWNTRANS, b);
4131 DOSET (FLG_KEEPTRANS, b);
4132 DOSET (FLG_IMMEDIATETRANS, b);
4139 if (b && !gc.anyExports
4140 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4141 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4142 || f == FLG_EXPORTCONST
4143 || f == FLG_EXPORTANY))
4145 gc.anyExports = TRUE;
4150 context_maybeSet (flagcode d)
4152 return (gc.flags[d] || gc.setLocally[d]);
4156 context_getFlag (flagcode d)
4158 return (gc.flags[d]);
4162 context_flagOn (flagcode f, fileloc loc)
4164 return (!context_suppressFlagMsg (f, loc));
4167 static void context_saveFlagSettings (void)
4169 gc.savedFlags = TRUE;
4170 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4171 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4174 static void context_restoreFlagSettings (void)
4176 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4177 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4178 gc.savedFlags = FALSE;
4181 void context_setFilename (fileId fid, int lineno)
4182 /*@globals fileloc g_currentloc;@*/
4183 /*@modifies g_currentloc@*/
4185 if (fileId_baseEqual (currentFile (), fid))
4192 fileloc_setColumn (g_currentloc, 0);
4194 if (fileloc_isSpecialFile (g_currentloc))
4196 gc.inDerivedFile = TRUE;
4199 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4201 int maxdepth = context_getValue (FLG_INCLUDENEST);
4203 if (filelocStack_size (gc.locstack) > maxdepth)
4205 int depth = filelocStack_includeDepth (gc.locstack);
4207 if (depth > maxdepth)
4211 message ("Maximum include nesting depth "
4212 "(%d, current depth %d) exceeded",
4215 filelocStack_nextTop (gc.locstack)))
4217 filelocStack_printIncludes (gc.locstack);
4223 g_currentloc = fileloc_create (fid, lineno, 1);
4224 gc.inheader = fileId_isHeader (currentFile ());
4226 context_enterFileAux ();
4230 void context_enterIterDef (/*@observer@*/ uentry le)
4232 context_enterMacro (le);
4233 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4234 gc.kind = CX_ITERDEF;
4237 void context_enterIterEnd (/*@observer@*/ uentry le)
4239 context_enterMacro (le);
4240 gc.kind = CX_ITEREND;
4244 context_destroyMod (void)
4245 /*@globals killed gc@*/
4248 ctype_destroyMod ();
4252 fileTable_free (gc.ftab);
4253 filelocStack_free (gc.locstack);
4255 gc.ftab = fileTable_undefined;
4257 macrocache_free (gc.mc);
4258 sfree (gc.moduleaccess);
4261 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4262 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4265 sRefSetList_free (gc.modrecs);
4267 flagMarkerList_free (gc.markers);
4269 messageLog_free (gc.msgLog);
4271 clauseStack_free (gc.clauses);
4274 cstring_free (gc.msgAnnote);
4275 globSet_free (gc.globs_used);
4276 metaStateTable_free (gc.stateTable);
4277 annotationTable_free (gc.annotTable);
4284 bool context_msgBoolInt (void)
4286 return gc.flags [FLG_BOOLINT];
4289 bool context_msgCharInt (void)
4291 return gc.flags [FLG_CHARINT];
4294 bool context_msgEnumInt (void)
4296 return gc.flags [FLG_ENUMINT];
4299 bool context_msgPointerArith (void)
4301 return gc.flags [FLG_POINTERARITH];
4304 bool context_msgStrictOps (void)
4306 return gc.flags [FLG_STRICTOPS];
4310 bool context_msgLh (void)
4312 return gc.flags [FLG_DOLH];
4316 void context_pushLoc (void)
4318 fileloc_free (gc.pushloc);
4319 gc.pushloc = gc.saveloc;
4320 gc.saveloc = fileloc_undefined;
4323 void context_popLoc (void)
4325 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4328 bool context_inGlobalScope (void)
4330 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4333 bool context_inInnerScope (void)
4335 return (gc.kind == CX_INNER);
4338 void context_setProtectVars (void)
4340 gc.protectVars = TRUE;
4343 bool context_anyErrors (void)
4345 return (gc.numerrors > 0);
4348 void context_hasError (void)
4351 DPRINTF (("num errors: %d", gc.numerrors));
4354 int context_numErrors (void)
4356 return gc.numerrors;
4359 bool context_neednl (void)
4364 void context_setNeednl (void)
4369 int context_getExpect (void)
4371 return (context_getValue (FLG_EXPECT));
4375 int context_getLCLExpect (void)
4377 return (context_getValue (FLG_LCLEXPECT));
4381 int context_getLimit (void)
4383 return (context_getValue (FLG_LIMIT));
4386 bool context_unlimitedMessages (void)
4388 return (context_getLimit () < 0);
4391 void context_releaseVars (void)
4393 llassert (gc.protectVars);
4394 gc.protectVars = FALSE;
4397 void context_sizeofReleaseVars (void)
4399 /* If there is a nested sizeof, this might not hold:
4400 llassert (gc.protectVars);
4403 gc.protectVars = FALSE;
4406 bool context_inProtectVars (void)
4408 return (gc.protectVars);
4411 void context_hideShowscan (void)
4413 gc.flags[FLG_SHOWSCAN] = FALSE;
4416 void context_unhideShowscan (void)
4418 gc.flags[FLG_SHOWSCAN] = TRUE;
4421 bool context_inHeader (void)
4423 return (gc.inheader);
4426 fileTable context_fileTable (void)
4431 cstring context_tmpdir (void)
4433 return (context_getString (FLG_TMPDIR));
4436 messageLog context_messageLog (void)
4441 bool context_inMacroFunction (void)
4443 return (gc.kind == CX_MACROFCN);
4446 bool context_inMacroConstant (void)
4448 return (gc.kind == CX_MACROCONST);
4451 bool context_inUnknownMacro (void)
4453 return (gc.kind == CX_UNKNOWNMACRO);
4456 void context_setShownFunction (void)
4458 gc.showfunction = FALSE;
4461 bool context_doDump (void)
4463 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4466 bool context_doMerge (void)
4468 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4471 cstring context_getDump (void)
4473 return context_getString (FLG_DUMP);
4476 cstring context_getMerge (void)
4478 return context_getString (FLG_MERGE);
4482 bool context_inLCLLib (void)
4484 return (gc.kind == CX_LCLLIB);
4487 bool context_inImport (void)
4489 return (gc.inimport);
4492 void context_enterImport (void)
4497 void context_leaveImport (void)
4499 gc.inimport = FALSE;
4503 bool context_inMacro (void)
4505 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4506 || gc.kind == CX_UNKNOWNMACRO
4507 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4510 bool context_inIterDef (void)
4512 return (gc.kind == CX_ITERDEF);
4515 bool context_inIterEnd (void)
4517 return (gc.kind == CX_ITEREND);
4520 int context_getLinesProcessed (void)
4522 return (gc.linesprocessed);
4525 int context_getSpecLinesProcessed (void)
4527 return (gc.speclinesprocessed);
4531 void context_processedSpecLine (void)
4533 gc.speclinesprocessed++;
4536 void context_resetSpecLines (void)
4538 gc.speclinesprocessed = 0;
4542 bool context_inGlobalContext (void)
4544 return (gc.kind == CX_GLOBAL);
4547 static void context_quietExitScopes (void)
4550 ** Try to restore the global scope (after an error).
4553 while (!usymtab_inFileScope ())
4555 usymtab_quietExitScope (g_currentloc);
4558 gc.cont.glob = TRUE;
4559 gc.kind = CX_GLOBAL;
4562 void context_checkGlobalScope (void)
4564 if (gc.kind != CX_GLOBAL)
4566 if (context_inMacro ())
4568 ; /* evans 2001-10-14: Okay to be in a macro here! */
4572 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4573 context_quietExitScopes ();
4578 void context_setFileId (fileId s)
4580 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4583 bool context_setBoolName (void)
4585 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4589 cstring context_printBoolName (void)
4591 if (context_setBoolName ())
4593 return context_getBoolName ();
4597 return cstring_makeLiteralTemp ("boolean");
4601 cstring context_getBoolName (void)
4603 return (context_getString (FLG_BOOLTYPE));
4606 cstring context_getFalseName (void)
4608 return (context_getString (FLG_BOOLFALSE));
4611 cstring context_getTrueName (void)
4613 return (context_getString (FLG_BOOLTRUE));
4616 cstring context_getLarchPath (void)
4618 return (context_getString (FLG_LARCHPATH));
4621 cstring context_getLCLImportDir (void)
4623 return (context_getString (FLG_LCLIMPORTDIR));
4626 static void context_setJustPopped (void)
4628 gc.justpopped = TRUE;
4631 void context_clearJustPopped (void)
4633 gc.justpopped = FALSE;
4636 bool context_justPopped (void)
4638 return (gc.justpopped);
4641 void context_setMacroMissingParams (void)
4643 gc.macroMissingParams = TRUE;
4646 void context_resetMacroMissingParams (void)
4648 gc.macroMissingParams = FALSE;
4651 bool context_isMacroMissingParams (void)
4653 return (gc.macroMissingParams);
4656 void context_showFilelocStack (void)
4658 filelocStack_printIncludes (gc.locstack);
4661 metaStateTable context_getMetaStateTable (void)
4663 return gc.stateTable;
4666 metaStateInfo context_lookupMetaStateInfo (cstring key)
4668 return metaStateTable_lookup (gc.stateTable, key);
4671 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4673 annotationInfo ainfo;
4675 ainfo = annotationTable_lookup (gc.annotTable, annot);
4680 void context_addAnnotation (annotationInfo ainfo)
4682 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4686 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4687 annotationInfo_getLoc (ainfo));
4689 annotationInfo_free (ainfo);
4693 annotationTable_insert (gc.annotTable, ainfo);
4697 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4699 if (metaStateTable_contains (gc.stateTable, mname))
4703 message ("Duplicate metastate declaration: %s", mname),
4704 metaStateInfo_getLoc (msinfo));
4705 cstring_free (mname);
4706 metaStateInfo_free (msinfo);
4710 DPRINTF (("Adding meta state: %s", mname));
4711 metaStateTable_insert (gc.stateTable, mname, msinfo);
4715 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4717 if (metaStateTable_size (gc.stateTable) > 0)
4719 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4720 /*@i32 should use smaller value... */
4721 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4723 metaStateTable_elements (gc.stateTable, msname, msi)
4725 mtContextNode context = metaStateInfo_getContext (msi);
4727 if (mtContextNode_matchesRefStrict (context, s))
4729 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4730 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4734 cstring_copy (metaStateInfo_getName (msi)),
4735 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4736 stateInfo_copy (sinfo)));
4740 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4743 end_metaStateTable_elements ;
4745 stateInfo_free (sinfo);
4746 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4751 stateInfo_free (sinfo);
4752 return valueTable_undefined;
4756 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4758 if (metaStateTable_size (gc.stateTable) > 0)
4760 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4761 /*@i32 should use smaller value... */
4763 metaStateTable_elements (gc.stateTable, msname, msi)
4765 /*@i23 only add global...*/
4766 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4767 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4769 valueTable_insert (res,
4770 cstring_copy (metaStateInfo_getName (msi)),
4771 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4772 stateInfo_copy (sinfo)));
4774 end_metaStateTable_elements ;
4776 stateInfo_free (sinfo);
4777 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4782 stateInfo_free (sinfo);
4783 return valueTable_undefined;
4789 /*drl 12/30/01 these are some ugly functions that were added to facilitate struct annotations */
4793 static ctype lastStruct;
4795 ctype context_setLastStruct (/*@returned@*/ ctype s) /*@globals lastStruct@*/
4801 ctype context_getLastStruct (/*@returned@*/ /*ctype s*/) /*@globals lastStruct@*/
4807 /*@unused@*/ static int sInfoNum = 0;
4811 /*@unused@*/ uentry ue;
4812 /*@unused@*/ sRef s;
4816 /*@unused@*/ ctype ct;
4817 /*@unused@*/ constraintList inv;
4818 /*@unused@*/ int ngetUe;
4819 /*@unused@*/ struct getUe * t ;
4823 static struct sInfo globalStructInfo;
4826 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4827 stable release of splint. I coomented them out so that they won't break anything
4828 but didn't delete them because they will be fixed and included later
4832 void setGlobalStructInfo(ctype ct, constraintList list)
4837 f = ctype_getFields (ct);
4839 if (constraintList_isDefined(list) )
4841 globalStructInfo.ct = ct;
4842 globalStructInfo.inv = list;
4844 globalStructInfo.ngetUe = 0;
4846 / *abstraction violation fix it * /
4847 globalStructInfo.t = dmalloc(f->nelements * sizeof(struct getUe) );
4849 globalStructInfo.ngetUe = f->nelements;
4853 uentryList_elements(f, ue)
4855 globalStructInfo.t[i].ue = ue;
4856 globalStructInfo.t[i].s = uentry_getSref(ue);
4857 TPRINTF(( message(" setGlobalStructInfo:: adding ue=%s and sRef=%s",
4858 uentry_unparse(ue), sRef_unparse( uentry_getSref(ue) )
4863 end_uentryList_elements;
4869 bool hasInvariants (ctype ct) /*@*/
4871 if ( ctype_sameName(globalStructInfo.ct, ct) )
4881 /*drl 1/6/2001: I didn't think these functions were solid enough to include in the
4882 stable release of splint. I coomented them out so that they won't break anything
4883 but didn't delete them because they will be fixed and included later
4887 constraintList getInvariants (ctype ct)
4890 llassert(hasInvariants(ct) );
4892 return globalStructInfo.inv;
4897 static int getSref (ctype ct, sRef s)
4906 fprintf(stderr, "getSref: ct = %s (%x)\n", ctype_unparse(ct), ct );
4908 fprintf(stderr,"getSref: s = (%s) %X \n", sRef_unparse(s), s);
4911 while (i < globalStructInfo.ngetUe)
4913 DPRINTF(( message(" getSref:: comparing ue=%s and sRef=%s",
4914 uentry_unparse(globalStructInfo.t[i].ue),
4915 sRef_unparse(globalStructInfo.t[i].s)
4920 fprintf (stderr, " globalStructInfo.t[i].s = %x\n ",
4921 globalStructInfo.t[i].s );
4924 if (sRef_same(globalStructInfo.t[i].s,s) )
4933 sRef fixSref (ctype ct, sRef base, sRef fix)
4938 index = getSref(ct, fix);
4943 ue = globalStructInfo.t[index].ue;
4944 name = uentry_getName(ue);
4945 fix = sRef_buildField(base, name );