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: splint@cs.virginia.edu
21 ** To report a bug: splint-bug@cs.virginia.edu
22 ** For more information: http://www.splint.org
28 * Modified by Herbert 04/19/97:
29 * - added include for new header portab.h containing OS dependent stuff.
30 * - changed occurrances of '/' as path delimiters to macro from portab.h
31 * - changed the handling of the tmp directory -- will no longer always be
32 * ".", if possible, environment variables "TMP" or, if not set, "TMP",
33 * or, if not set "." will be used.
36 # include "splintMacros.nf"
40 # include "usymtab_interface.h"
43 # include "exprChecks.h"
44 # include "filelocStack.h"
45 # include "fileIdList.h"
51 extern /*@external@*/ int yydebug;
52 extern /*@external@*/ int mtdebug;
64 CX_FUNCTION, CX_FCNDECLARATION,
65 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
66 CX_ITERDEF, CX_ITEREND,
67 CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
68 CX_LCL, CX_LCLLIB, CX_MT
74 int speclinesprocessed;
76 flagMarkerList markers;
79 ** used to record state where a macro must match a function name
80 ** (i.e., no params were listed in the macro definition
83 bool macroMissingParams BOOLBITS;
84 bool preprocessing BOOLBITS;
85 bool incommandline BOOLBITS;
86 bool insuppressregion BOOLBITS;
87 bool inDerivedFile BOOLBITS;
88 bool instandardlib BOOLBITS;
89 bool inimport BOOLBITS;
90 bool inheader BOOLBITS;
91 bool inmacrocache BOOLBITS;
92 bool protectVars BOOLBITS;
94 bool showfunction BOOLBITS;
95 bool savedFlags BOOLBITS;
96 bool justpopped BOOLBITS;
97 bool anyExports BOOLBITS;
98 bool inFunctionHeader BOOLBITS;
111 filelocStack locstack;
114 /*@observer@*/ sRef aliasAnnote;
115 /*@observer@*/ sRef aliasAnnoteAls;
119 /*@observer@*/ sRefSet mods;
121 /* file access types */
124 /* local access types (this function) */
127 /* no access types (@noaccess) */
130 /*@observer@*/ globSet globs;
131 /*@only@*/ globSet globs_used;
135 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
141 bool flags[NUMFLAGS];
142 bool saveflags[NUMFLAGS];
143 bool setGlobally[NUMFLAGS];
144 bool setLocally[NUMFLAGS];
146 int values[NUMVALUEFLAGS];
147 int counters[NUMVALUEFLAGS];
149 o_cstring strings[NUMSTRINGFLAGS];
150 sRefSetList modrecs; /*@i32 ???? what is this for? */
152 metaStateTable stateTable; /* User-defined state information. */
153 annotationTable annotTable; /* User-defined annotations table. */
158 /*@dependent@*/ /*@exposed@*/ uentry fcn;
162 union u_cont savecont;
165 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
166 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
167 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
168 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
170 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
171 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
172 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
173 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
174 static void context_setFlag (flagcode p_f, bool p_b)
175 /*@modifies gc.flags@*/ ;
178 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, bool p_isRestore)
179 /*@modifies gc.flags@*/ ;
181 static void context_restoreFlag (flagcode p_f) /*@modifies gc.flags@*/ ;
185 cstring context_unparseFlagMarkers ()
187 return (flagMarkerList_unparse (gc.markers));
190 void context_setPreprocessing (void)
192 llassert (!gc.preprocessing);
193 gc.preprocessing = TRUE;
196 void context_clearPreprocessing (void)
198 llassert (gc.preprocessing);
199 gc.preprocessing = FALSE;
202 bool context_isPreprocessing (void)
204 return gc.preprocessing;
207 bool context_loadingLibrary (void)
209 return (fileloc_isLib (g_currentloc));
212 bool context_inXHFile (void)
214 return (fileloc_isXHFile (g_currentloc));
217 void context_setInCommandLine (void)
219 llassert (!gc.incommandline);
220 gc.incommandline = TRUE;
223 void context_clearInCommandLine (void)
225 llassert (gc.incommandline);
226 gc.incommandline = FALSE;
229 bool context_isInCommandLine (void)
231 return gc.incommandline;
235 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
238 clauseStack_push (gc.clauses, c);
240 if (clause_isConditional (c)
241 && context_getFlag (FLG_CONTROLNESTDEPTH))
243 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
244 int depth = clauseStack_controlDepth (gc.clauses);
246 if (depth == maxdepth + 1)
249 (FLG_CONTROLNESTDEPTH,
250 message ("Maximum control nesting depth "
259 clause topClause (clauseStack s) /*@*/
261 if (clauseStack_isEmpty (s)) return NOCLAUSE;
262 return ((clause) clauseStack_top (s));
266 context_addMacroCache (/*@only@*/ cstring def)
268 DPRINTF (("macro cache: %s", def));
269 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
273 context_addComment (/*@only@*/ cstring def)
275 DPRINTF (("macro comment: %s", def));
276 macrocache_addComment (gc.mc, fileloc_copy (g_currentloc), def);
280 ** returns TRUE is fl is in ignore region, or region where -code
282 ** the logic is fuzzy...
286 context_inSuppressFlagZone (fileloc fl, flagcode code)
288 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
291 if (ynm_isMaybe (ret))
299 res = !gc.saveflags[code];
303 res = !context_getFlag (code);
308 res = ynm_toBoolStrict (ret);
315 context_suppressSystemMsg (fileloc fl)
317 if (context_getFlag (FLG_SYSTEMDIRERRORS))
323 return (fileloc_isSystemFile (fl));
328 context_suppressFlagMsg (flagcode flag, fileloc fl)
330 if (context_suppressSystemMsg (fl))
335 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
337 /* want same object compare here */
339 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
341 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
343 return (!context_getFlag (flag)
344 || context_inSuppressRegion ()
345 || context_inSuppressZone (fl)
346 || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
350 return (context_inSuppressFlagZone (fl, flag));
355 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
358 if (context_suppressSystemMsg (fl))
364 if (fl == g_currentloc)
365 /*@noaccess fileloc@*/
367 return (context_getFlag (flag) || context_inSuppressRegion ());
372 return (context_getFlag (flag) || context_inSuppressRegion ());
377 context_inSuppressZone (fileloc fl)
379 if (context_suppressSystemMsg (fl))
384 return (flagMarkerList_inIgnore (gc.markers, fl));
388 context_inSuppressRegion (void)
390 return (gc.insuppressregion);
394 context_enterSuppressRegion (void)
396 if (gc.insuppressregion)
398 gc.insuppressregion = FALSE; /* get this msg! */
400 ("%q: New ignore errors region entered while in ignore errors region",
401 fileloc_unparse (g_currentloc)));
404 gc.insuppressregion = TRUE;
405 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (g_currentloc));
409 context_addFlagMarker (flagcode code, ynm set)
411 flagMarkerList_add (gc.markers,
412 flagMarker_createLocalSet (code, set, g_currentloc));
416 context_enterSuppressLine (int count)
418 fileloc nextline = fileloc_copy (g_currentloc);
420 flagMarkerList_add (gc.markers,
421 flagMarker_createIgnoreCount (count, g_currentloc));
423 fileloc_nextLine (nextline);
424 flagMarkerList_add (gc.markers,
425 flagMarker_createIgnoreOff (nextline));
426 fileloc_free (nextline);
429 void context_checkSuppressCounts (void)
431 if (context_getFlag (FLG_SUPCOUNTS))
433 flagMarkerList_checkSuppressCounts (gc.markers);
437 void context_incLineno (void)
444 context_exitSuppressRegion (void)
446 if (!gc.insuppressregion)
448 llerrorlit (FLG_SYNTAX,
449 "End ignore errors in region while not ignoring errors");
452 gc.insuppressregion = FALSE;
453 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (g_currentloc));
457 context_enterMTfile (void)
463 context_exitMTfile (void)
465 llassert (gc.kind == CX_MT);
471 context_enterLCLfile (void)
474 gc.facct = typeIdSet_emptySet ();
479 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
483 for (i = 0; i < gc.nmods; i++)
485 if (cstring_equal (gc.moduleaccess[i].file, fname))
487 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
488 cstring_free (fname);
493 if (gc.nmods == gc.maxmods)
497 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
498 oldmods = gc.moduleaccess;
500 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
502 for (i = 0; i < gc.nmods; i++)
504 gc.moduleaccess[i] = oldmods[i];
510 gc.moduleaccess[gc.nmods].file = fname;
511 gc.moduleaccess[gc.nmods].daccess = mods;
517 insertModuleAccess (cstring fname, typeId t)
521 for (i = 0; i < gc.nmods; i++)
523 if (cstring_equal (gc.moduleaccess[i].file, fname))
525 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
530 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
535 context_exitLCLfile (void)
537 if (gc.kind != CX_LCLLIB)
540 fileLib_withoutExtension (fileName (currentFile ()), LCL_EXTENSION);
542 addModuleAccess (fileLib_removePath (lclname), gc.facct);
543 cstring_free (lclname);
548 gc.facct = typeIdSet_emptySet ();
553 context_dumpModuleAccess (FILE *fout)
557 for (i = 0; i < gc.nmods; i++)
559 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
561 fprintf (fout, "%s#%s@\n",
562 cstring_toCharsSafe (gc.moduleaccess[i].file),
563 cstring_toCharsSafe (td));
569 bool context_usingPosixLibrary ()
571 return (gc.library == FLG_POSIXLIB
572 || gc.library == FLG_POSIXSTRICTLIB
573 || gc.library == FLG_UNIXLIB
574 || gc.library == FLG_UNIXSTRICTLIB);
577 bool context_usingAnsiLibrary ()
579 return (gc.library != FLG_NOLIB);
582 flagcode context_getLibrary ()
587 void context_setLibrary (flagcode code)
592 /*@observer@*/ cstring context_selectedLibrary ()
597 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
599 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
600 case FLG_POSIXSTRICTLIB:
601 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
603 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
604 case FLG_UNIXSTRICTLIB:
605 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
607 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
614 context_loadModuleAccess (FILE *in)
616 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
618 char *name = mstring_create (MAX_NAME_LENGTH);
624 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
630 while (s != NULL && *s != ';' && *s != '\0')
634 while (*s != '#' && *s != '\0')
643 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
644 cstring_fromChars (s)));
650 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
651 typeIdSet_undump (&s));
653 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
654 llassert (s != lasts);
664 typeIdSet context_fileAccessTypes (void)
670 context_resetModeFlags (void)
675 if (flagcode_isModeFlag (code))
677 context_setFlag (code, FALSE);
685 ** Set all flags to FALSE, except for a few which are
688 ** Set all values and strings to appropriate defaults.
689 ** Set all counters to 0.
693 conext_resetAllCounters (void)
697 for (i = 0; i < NUMVALUEFLAGS; i++)
704 context_resetAllFlags (void)
706 DPRINTF (("******** Reset all flags"));
710 gc.flags[code] = FALSE;
712 if (flagcode_hasNumber (code))
716 /*@-loopswitchbreak@*/
720 val = DEFAULT_LIMIT; break;
722 val = DEFAULT_BUGSLIMIT; break;
724 val = DEFAULT_LINELEN; break;
725 case FLG_INDENTSPACES:
726 val = DEFAULT_INDENTSPACES; break;
727 case FLG_EXTERNALNAMELEN:
728 val = ISO99_EXTERNALNAMELEN; break;
729 case FLG_INTERNALNAMELEN:
730 val = ISO99_INTERNALNAMELEN; break;
731 case FLG_COMMENTCHAR:
732 val = (int) DEFAULT_COMMENTCHAR; break;
733 case FLG_CONTROLNESTDEPTH:
734 val = (int) ISO99_CONTROLNESTDEPTH; break;
735 case FLG_STRINGLITERALLEN:
736 val = (int) ISO99_STRINGLITERALLEN; break;
737 case FLG_INCLUDENEST:
738 val = (int) ISO99_INCLUDENEST; break;
739 case FLG_NUMSTRUCTFIELDS:
740 val = (int) ISO99_NUMSTRUCTFIELDS; break;
741 case FLG_NUMENUMMEMBERS:
742 val = (int) ISO99_NUMENUMMEMBERS; break;
747 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
749 /*@=loopswitchbreak@*/
751 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
752 context_setValue (code, val);
753 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
754 llassert (context_getValue (code) == val);
756 else if (flagcode_hasChar (code))
758 llassert (code == FLG_COMMENTCHAR);
759 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
761 else if (flagcode_hasString (code))
763 cstring val = cstring_undefined;
766 { /*@-loopswitchbreak@*/
769 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
771 if (cstring_isDefined (larchpath))
773 val = cstring_copy (larchpath);
777 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
782 case FLG_LCLIMPORTDIR:
784 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
788 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
790 char *env = osd_getEnvironmentVariable ("TMP");
794 env = osd_getEnvironmentVariable ("TEMP");
797 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
800 val = cstring_makeLiteral (DEFAULT_TMPDIR);
801 # endif /* !defined(OS2) && !defined(MSDOS) */
805 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
807 val = cstring_makeLiteral ("FALSE"); break;
809 val = cstring_makeLiteral ("TRUE"); break;
810 case FLG_MACROVARPREFIX:
811 val = cstring_makeLiteral ("m_"); break;
813 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
816 } /*@=loopswitchbreak@*/
818 context_setString (code, val);
822 ; /* nothing to set */
827 ** These flags are true by default.
830 /*@i34 move this into flags.def */
832 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
833 gc.flags[FLG_MODIFIES] = TRUE;
834 gc.flags[FLG_NESTCOMMENT] = TRUE;
835 gc.flags[FLG_GLOBALS] = TRUE;
836 gc.flags[FLG_FULLINITBLOCK] = TRUE;
837 gc.flags[FLG_INITSIZE] = TRUE;
838 gc.flags[FLG_INITALLELEMENTS] = TRUE;
840 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
842 gc.flags[FLG_LIKELYBOOL] = TRUE;
843 gc.flags[FLG_ZEROPTR] = TRUE;
844 gc.flags[FLG_NUMLITERAL] = TRUE;
845 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
846 gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
847 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
848 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
849 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
850 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
851 gc.flags[FLG_CASTFCNPTR] = TRUE;
852 gc.flags[FLG_DOLCS] = TRUE;
853 gc.flags[FLG_USEVARARGS] = TRUE;
854 gc.flags[FLG_MAINTYPE] = TRUE;
855 gc.flags[FLG_SPECMACROS] = TRUE;
856 gc.flags[FLG_REDEF] = TRUE;
857 gc.flags[FLG_MACRONEXTLINE] = TRUE;
859 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
860 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
862 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
863 gc.flags[FLG_WARNUSE] = TRUE;
864 gc.flags[FLG_PREDASSIGN] = TRUE;
865 gc.flags[FLG_MODOBSERVER] = TRUE;
866 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
867 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
869 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
870 gc.flags[FLG_RETIMPONLY] = TRUE;
871 gc.flags[FLG_GLOBIMPONLY] = TRUE;
872 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
873 gc.flags[FLG_PREPROC] = TRUE;
874 gc.flags[FLG_NAMECHECKS] = TRUE;
875 gc.flags[FLG_FORMATCODE] = TRUE;
876 gc.flags[FLG_FORMATTYPE] = TRUE;
877 gc.flags[FLG_BADFLAG] = TRUE;
878 gc.flags[FLG_WARNFLAGS] = TRUE;
879 gc.flags[FLG_WARNRC] = TRUE;
880 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
881 gc.flags[FLG_WARNUNIXLIB] = TRUE;
882 gc.flags[FLG_WARNPOSIX] = TRUE;
883 gc.flags[FLG_SHOWCOL] = TRUE;
884 gc.flags[FLG_SHOWFUNC] = TRUE;
885 gc.flags[FLG_SUPCOUNTS] = TRUE;
886 gc.flags[FLG_HINTS] = TRUE;
887 gc.flags[FLG_SYNTAX] = TRUE;
888 gc.flags[FLG_TYPE] = TRUE;
889 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
890 gc.flags[FLG_ABSTRACT] = TRUE;
891 gc.flags[FLG_ITERBALANCE] = TRUE;
892 gc.flags[FLG_ITERYIELD] = TRUE;
893 gc.flags[FLG_DUPLICATECASES] = TRUE;
894 gc.flags[FLG_ALWAYSEXITS] = TRUE;
895 gc.flags[FLG_EMPTYRETURN] = TRUE;
896 gc.flags[FLG_MACRORETURN] = TRUE;
897 gc.flags[FLG_UNRECOG] = TRUE;
898 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
899 gc.flags[FLG_LINTCOMMENTS] = TRUE;
900 gc.flags[FLG_ACCESSCZECH] = TRUE;
901 gc.flags[FLG_ACCESSMODULE] = TRUE;
902 gc.flags[FLG_ACCESSFILE] = TRUE;
903 gc.flags[FLG_MACROVARPREFIX] = TRUE;
905 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
906 gc.flags[FLG_COMMENTERROR] = TRUE;
909 ** Changed for version 2.4.
912 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
917 gc.flags[FLG_ORCONSTRAINT] = TRUE;
918 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
920 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
924 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
929 ** C is way-lame, and you can initialize an array to a constant except where
930 ** it is declared. Hence, a macro is used to set the modeflags.
934 # define SETFLAGS() \
935 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
936 if (!flagcode_isModeFlag (modeflags[i])) \
937 { llbug (message ("not a mode flag: %s", \
938 flagcode_unparse (modeflags[i]))); } \
939 else { context_setFlag (modeflags[i], TRUE); } i++; }}
941 static void context_setModeAux (cstring p_s, bool p_warn) ;
944 context_setMode (cstring s)
946 context_setModeAux (s, TRUE);
950 context_setModeNoWarn (cstring s)
952 context_setModeAux (s, FALSE);
956 context_setModeAux (cstring s, bool warn)
958 intSet setflags = intSet_new ();
962 if (flagcode_isModeFlag (code))
964 if (gc.setGlobally[code])
966 (void) intSet_insert (setflags, (int) code);
971 if (!intSet_isEmpty (setflags))
973 cstring rflags = cstring_undefined;
976 intSet_elements (setflags, el)
978 if (cstring_isUndefined (rflags))
980 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
984 rflags = message ("%q, %s", rflags,
985 flagcode_unparse ((flagcode) el));
989 if (num > 4 && intSet_size (setflags) > 6)
991 rflags = message ("%q, (%d others) ...", rflags,
992 intSet_size (setflags) - num);
995 } end_intSet_elements ;
999 voptgenerror (FLG_WARNFLAGS,
1000 message ("Setting mode %s after setting mode flags will "
1001 "override set values of flags: %s",
1006 cstring_free (rflags);
1009 intSet_free (setflags);
1011 context_resetModeFlags ();
1013 if (cstring_equalLit (s, "standard"))
1015 flagcode modeflags[] =
1017 FLG_ENUMINT, FLG_MACROMATCHNAME,
1018 FLG_STRINGLITNOROOM,
1019 FLG_MACROUNDEF, FLG_RELAXQUALS,
1020 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1021 FLG_CHECKSTRICTGLOBALIAS,
1022 FLG_CHECKEDGLOBALIAS,
1023 FLG_CHECKMODGLOBALIAS,
1024 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1025 FLG_UNSIGNEDCOMPARE,
1026 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1028 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1029 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1030 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1031 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1032 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1035 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1036 FLG_MACROSTMT, FLG_MACROPARENS,
1039 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1040 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1045 /* memchecks flags */
1047 FLG_NULLSTATE, FLG_NULLASSIGN,
1048 FLG_NULLPASS, FLG_NULLRET,
1050 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1053 /* memtrans flags */
1072 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1075 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1076 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1079 FLG_STATETRANSFER, FLG_STATEMERGE,
1080 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1082 FLG_IMPCHECKEDSPECGLOBALS,
1083 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1084 FLG_IFEMPTY, FLG_REALCOMPARE,
1085 FLG_BOOLOPS, FLG_PTRNEGATE,
1087 FLG_SHIFTIMPLEMENTATION,
1088 FLG_BUFFEROVERFLOWHIGH,
1095 else if (cstring_equalLit (s, "weak"))
1097 flagcode modeflags[] =
1099 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1100 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1101 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1102 FLG_CHARUNSIGNEDCHAR,
1104 FLG_VARUNUSED, FLG_FUNCUNUSED,
1106 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1109 FLG_BUFFEROVERFLOWHIGH,
1110 FLG_RETSTACK, FLG_PTRNEGATE,
1111 FLG_STATETRANSFER, FLG_STATEMERGE,
1112 FLG_LONGUNSIGNEDINTEGRAL,
1113 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1117 FLG_BUFFEROVERFLOWHIGH,
1123 else if (cstring_equalLit (s, "checks"))
1125 flagcode modeflags[] =
1127 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1128 FLG_STATETRANSFER, FLG_STATEMERGE,
1129 FLG_CHECKSTRICTGLOBALIAS,
1130 FLG_CHECKEDGLOBALIAS,
1131 FLG_CHECKMODGLOBALIAS,
1132 FLG_UNCHECKEDGLOBALIAS,
1134 FLG_STRINGLITNOROOM,
1135 FLG_STRINGLITSMALLER,
1136 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1137 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1138 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1139 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1140 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1141 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1142 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1143 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1144 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1145 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1146 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1147 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1148 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1149 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1156 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1160 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1162 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1163 FLG_EVALORDER, FLG_USEDEF,
1166 /* warn use flags */
1167 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1168 FLG_BUFFEROVERFLOWHIGH,
1170 /* memchecks flags */
1172 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1173 FLG_NULLPASS, FLG_NULLRET,
1175 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1177 /* memtrans flags */
1191 FLG_STATICINITTRANS,
1192 FLG_UNKNOWNINITTRANS,
1195 FLG_ONLYUNQGLOBALTRANS,
1196 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1199 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1200 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1203 FLG_NULLPOINTERARITH,
1204 FLG_SHADOW, FLG_DEPARRAYS,
1205 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1206 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1207 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1208 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1209 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1210 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1211 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1212 FLG_SHIFTIMPLEMENTATION,
1213 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1218 else if (cstring_equalLit (s, "strict"))
1220 flagcode modeflags[] =
1222 FLG_CHECKSTRICTGLOBALIAS,
1223 FLG_CHECKEDGLOBALIAS,
1224 FLG_CHECKMODGLOBALIAS,
1225 FLG_UNCHECKEDGLOBALIAS,
1229 FLG_STRINGLITNOROOM,
1230 FLG_STRINGLITSMALLER,
1231 FLG_STATETRANSFER, FLG_STATEMERGE,
1232 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1233 FLG_ALLGLOBALS, FLG_IMPTYPE,
1234 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1235 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1236 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1237 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1240 FLG_ONLYUNQGLOBALTRANS,
1241 FLG_GLOBALSIMPMODIFIESNOTHING,
1242 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1243 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1244 FLG_USEALLGLOBS, FLG_RETALIAS,
1245 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1246 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1247 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1249 FLG_EXPORTITER, FLG_EXPORTCONST,
1250 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1251 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1253 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1255 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1256 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1257 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1258 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1259 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1260 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1261 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1262 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1264 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1267 FLG_MACROREDEF, FLG_MACROEMPTY,
1268 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1270 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1272 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1273 FLG_MODOBSERVERUNCON,
1278 /* warn use flags */
1279 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1280 FLG_BUFFEROVERFLOWHIGH,
1281 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1283 /* memchecks flags */
1284 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1285 FLG_NULLPASS, FLG_NULLRET,
1287 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1289 /* memtrans flags */
1305 FLG_STATICINITTRANS,
1306 FLG_UNKNOWNINITTRANS,
1308 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1311 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1312 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1316 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1318 FLG_SHADOW, FLG_DEPARRAYS,
1319 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1320 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1321 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1322 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1323 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1324 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1325 FLG_IMPCHECKEDSTRICTSTATICS,
1326 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1327 FLG_IMPCHECKMODINTERNALS,
1328 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1329 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1330 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1331 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1332 FLG_CONTROLNESTDEPTH,
1333 FLG_FORBLOCK, FLG_WHILEBLOCK,
1334 FLG_FOREMPTY, FLG_WHILEEMPTY,
1335 FLG_IFEMPTY, FLG_IFBLOCK,
1337 FLG_REALCOMPARE, FLG_BOOLOPS,
1338 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1341 FLG_SHIFTIMPLEMENTATION,
1343 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1351 llcontbug (message ("context_setMode: bad mode: %s", s));
1356 context_isSpecialFile (cstring fname)
1358 cstring ext = fileLib_getExtension (fname);
1360 return (cstring_equalLit (ext, ".y")
1361 || cstring_equalLit (ext, ".l")
1362 || cstring_equalLit (fname, "lex.yy.c"));
1366 context_isSystemDir (cstring dir)
1368 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1369 cstring savedir = thisdir;
1370 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1372 if (cstring_isDefined (nextdir))
1374 /*@access cstring@*/
1375 *nextdir = '\0'; /* closes thisdir */
1377 /*@noaccess cstring@*/
1380 /* 2001-09-09: added thisdir[0] != '\0'
1381 ** herbert: don't compare with an empty name!
1382 ** should return false for empty directory path
1385 while (!cstring_isEmpty (thisdir))
1387 DPRINTF (("Test: %s / %s", dir, thisdir));
1389 if (osd_equalCanonicalPrefix (dir, thisdir))
1391 cstring_free (savedir);
1395 if (cstring_isDefined (nextdir))
1398 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1400 if (cstring_isDefined (nextdir))
1402 /*@access cstring@*/
1405 /*@noaccess cstring@*/
1414 DPRINTF (("Returns FALSE"));
1415 cstring_free (savedir);
1420 context_addFileAccessType (typeId t)
1424 if (context_inFunctionLike ())
1426 gc.acct = typeIdSet_insert (gc.acct, t);
1429 gc.facct = typeIdSet_insert (gc.facct, t);
1431 base = fileloc_getBase (g_currentloc);
1432 insertModuleAccess (base, t);
1433 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1434 typeIdSet_unparse (gc.acct)));
1438 context_removeFileAccessType (typeId t)
1440 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1441 || gc.kind == CX_UNKNOWNMACRO)
1443 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1446 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1447 gc.nacct = typeIdSet_insert (gc.nacct, t);
1450 void context_enterFunctionHeader (void)
1452 if (context_getFlag (FLG_GRAMMAR))
1454 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1457 if (gc.kind != CX_GLOBAL)
1459 llparseerror (cstring_makeLiteral
1460 ("Likely parse error. Function header outside global context."));
1464 llassert (gc.kind == CX_GLOBAL);
1465 DPRINTF (("Enter function header!"));
1466 gc.inFunctionHeader = TRUE;
1470 void context_exitFunctionHeader (void)
1472 if (context_getFlag (FLG_GRAMMAR))
1474 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1477 DPRINTF (("Exit function header!"));
1478 gc.inFunctionHeader = FALSE;
1481 bool context_inFunctionHeader (void)
1483 return (gc.inFunctionHeader);
1486 void context_enterFunctionDeclaration (uentry e)
1488 if (context_getFlag (FLG_GRAMMAR))
1490 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1493 DPRINTF (("Enter function decl"));
1494 llassert (gc.savekind == CX_ERROR);
1495 gc.savekind = gc.kind;
1496 gc.savecont = gc.cont;
1497 gc.kind = CX_FCNDECLARATION;
1501 void context_exitFunctionDeclaration (void)
1503 if (context_getFlag (FLG_GRAMMAR))
1505 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1508 DPRINTF (("Exit function decl"));
1509 llassert (gc.savekind != CX_ERROR);
1510 llassert (gc.kind == CX_FCNDECLARATION);
1511 gc.kind = gc.savekind;
1512 gc.cont = gc.savecont;
1514 gc.savekind = CX_ERROR;
1516 if (context_getFlag (FLG_GRAMMAR))
1518 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1522 bool context_inFunctionDeclaration (void)
1524 return (gc.kind == CX_FCNDECLARATION);
1529 context_enterMacro (/*@observer@*/ uentry e)
1531 context_enterFunction (e);
1532 gc.kind = CX_MACROFCN;
1536 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1538 llassert (uentry_isFunction (e));
1539 context_enterFunction (e);
1540 gc.kind = CX_UNKNOWNMACRO;
1543 void context_enterAndClause (exprNode e)
1546 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1547 pushClause (ANDCLAUSE);
1550 void context_enterOrClause (exprNode e)
1552 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1553 pushClause (ORCLAUSE);
1556 bool context_inDeepLoop (void)
1558 bool inLoop = FALSE;
1560 clauseStack_elements (gc.clauses, el)
1562 if (clause_isLoop (el))
1571 } end_clauseStack_elements;
1576 bool context_inDeepSwitch (void)
1578 bool inLoop = FALSE;
1580 clauseStack_elements (gc.clauses, el)
1582 if (clause_isSwitch (el))
1591 } end_clauseStack_elements;
1596 bool context_inDeepLoopSwitch (void)
1598 bool inLoop = FALSE;
1600 clauseStack_elements (gc.clauses, el)
1602 if (clause_isBreakable (el))
1611 } end_clauseStack_elements;
1616 clause context_breakClause (void)
1618 clauseStack_elements (gc.clauses, el)
1620 if (clause_isSwitch (el))
1624 else if (clause_isLoop (el))
1632 } end_clauseStack_elements;
1637 clause context_nextBreakClause (void)
1639 bool hasOne = FALSE;
1641 clauseStack_elements (gc.clauses, el)
1643 if (clause_isBreakable (el))
1654 } end_clauseStack_elements;
1659 bool context_inConditional (void)
1661 clauseStack_elements (gc.clauses, el)
1664 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1665 ** to distinguish if from ? for this
1668 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1672 } end_clauseStack_elements;
1677 void context_exitAndClause (exprNode pred, exprNode tbranch)
1679 context_setJustPopped ();
1681 llassert (gc.inclause == ANDCLAUSE);
1683 usymtab_popAndBranch (pred, tbranch);
1684 clauseStack_pop (gc.clauses);
1685 gc.inclause = topClause (gc.clauses);
1688 void context_exitOrClause (exprNode pred, exprNode tbranch)
1690 context_setJustPopped ();
1692 llassert (gc.inclause == ORCLAUSE);
1694 usymtab_popOrBranch (pred, tbranch);
1695 clauseStack_pop (gc.clauses);
1696 gc.inclause = topClause (gc.clauses);
1699 static void context_enterCondClauseAux (clause cl)
1705 static void context_enterTrueAux (exprNode e, clause cl)
1708 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1712 void context_enterIterClause (void)
1714 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1717 void context_enterDoWhileClause (void)
1719 pushClause (DOWHILECLAUSE);
1722 void context_enterWhileClause (exprNode e)
1724 context_enterTrueAux (e, WHILECLAUSE);
1727 void context_enterForClause (exprNode e)
1729 context_enterTrueAux (e, FORCLAUSE);
1732 void context_enterTrueClause (exprNode e)
1734 context_enterTrueAux (e, TRUECLAUSE);
1737 void context_enterSwitch (exprNode e)
1740 usymtab_switchBranch (e);
1741 context_enterCondClauseAux (SWITCHCLAUSE);
1744 void context_exitSwitch (exprNode e, bool allpaths)
1746 usymtab_exitSwitch (e, allpaths);
1748 while (clause_isCase (clauseStack_top (gc.clauses)))
1750 clauseStack_pop (gc.clauses);
1753 context_exitClauseSimp ();
1756 void context_enterCaseClause (exprNode e)
1758 bool branch = FALSE;
1760 DPRINTF (("Enter case clause!"));
1762 branch = usymtab_newCase (exprNode_undefined, e);
1766 context_enterCondClauseAux (CASECLAUSE);
1770 static void context_enterFalseClauseAux (exprNode e, clause cl)
1773 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1775 clauseStack_switchTop (gc.clauses, cl);
1778 void context_enterFalseClause (exprNode e)
1781 context_enterFalseClauseAux (e, FALSECLAUSE);
1785 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1787 gc.kind = CX_MACROCONST;
1789 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1791 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1795 usymtab_enterScope ();
1796 sRef_enterFunctionScope ();
1798 gc.globs = globSet_undefined;
1799 globSet_clear (gc.globs_used);
1800 gc.mods = sRefSet_undefined;
1803 uentry context_getHeader (void)
1805 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1807 llfatalbug (message ("context_getHeader: bad call: %q",
1808 context_unparse ()));
1811 return (gc.cont.fcn);
1815 context_setFunctionDefined (fileloc loc)
1819 case CX_UNKNOWNMACRO:
1822 uentry_setFunctionDefined (gc.cont.fcn, loc);
1825 /* (not a bug because of parse errors) */
1831 context_enterFunction (/*@exposed@*/ uentry e)
1833 gc.kind = CX_FUNCTION;
1836 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1838 if (uentry_hasAccessType (e))
1840 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1848 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1849 typeIdSet_unparse (gc.acct)));
1851 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1853 gc.globs = uentry_getGlobs (e);
1854 globSet_clear (gc.globs_used);
1855 gc.mods = uentry_getMods (e);
1857 usymtab_enterFunctionScope (e);
1858 sRef_enterFunctionScope ();
1862 context_enterOldStyleScope (void)
1864 gc.kind = CX_OLDSTYLESCOPE;
1865 DPRINTF (("Enter old style scope!"));
1866 usymtab_enterFunctionScope (uentry_undefined);
1870 context_completeOldStyleFunction (uentry e)
1872 llassert (gc.kind == CX_OLDSTYLESCOPE);
1874 gc.kind = CX_FUNCTION;
1877 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1879 if (uentry_hasAccessType (e))
1881 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1889 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1890 typeIdSet_unparse (gc.acct)));
1892 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1894 if (!globSet_isEmpty (uentry_getGlobs (e)))
1896 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1897 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1900 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1902 gc.globs = uentry_getGlobs (e);
1903 globSet_clear (gc.globs_used);
1905 gc.mods = uentry_getMods (e);
1907 if (!sRefSet_isEmpty (gc.mods))
1909 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1910 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1913 sRef_enterFunctionScope ();
1916 static bool context_checkStrictGlobals (void)
1918 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1921 static bool context_hasGlobs (void)
1923 if (context_inFunctionLike ())
1925 return (uentry_hasGlobs (gc.cont.fcn));
1933 static bool context_checkCheckedGlobals (void)
1935 return (context_getFlag (FLG_GLOBALS)
1936 && (context_getFlag (FLG_GLOBUNSPEC)
1937 || context_hasGlobs ()));
1940 static bool context_checkUnknownGlobals (void)
1942 /* should be uentry_hasGlobs ? */
1944 return (context_getFlag (FLG_ALLGLOBALS)
1945 && (context_getFlag (FLG_GLOBUNSPEC)
1946 || context_hasGlobs ()));
1949 static bool context_checkUncheckedGlobals (void)
1955 context_checkExport (uentry e)
1957 if (!gc.anyExports) return FALSE;
1959 if (uentry_isFunction (e)
1960 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1962 return context_maybeSet (FLG_EXPORTFCN);
1964 else if (uentry_isExpandedMacro (e))
1966 return context_maybeSet (FLG_EXPORTMACRO);
1968 else if (uentry_isVariable (e))
1970 return context_maybeSet (FLG_EXPORTVAR);
1972 else if (uentry_isEitherConstant (e))
1974 return context_maybeSet (FLG_EXPORTCONST);
1976 else if (uentry_isIter (e) || uentry_isEndIter (e))
1978 return context_maybeSet (FLG_EXPORTITER);
1980 else if (uentry_isDatatype (e))
1982 return context_maybeSet (FLG_EXPORTTYPE);
1991 context_checkGlobUse (uentry glob)
1994 if (uentry_isCheckedStrict (glob))
1996 return context_checkStrictGlobals ();
1998 else if (uentry_isChecked (glob))
2000 return context_checkCheckedGlobals ();
2002 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2004 return context_checkUnknownGlobals ();
2008 llassert (uentry_isUnchecked (glob));
2010 return context_checkUncheckedGlobals ();
2015 context_checkAliasGlob (uentry glob)
2017 if (uentry_isCheckedStrict (glob))
2019 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2021 else if (uentry_isChecked (glob))
2023 return gc.flags[FLG_CHECKEDGLOBALIAS];
2025 else if (uentry_isCheckMod (glob))
2027 return gc.flags[FLG_CHECKMODGLOBALIAS];
2031 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2033 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2037 bool context_checkInternalUse (void)
2039 if (context_hasGlobs ())
2041 return (gc.flags[FLG_INTERNALGLOBS]);
2045 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2050 context_checkGlobMod (sRef el)
2052 uentry ue = sRef_getUentry (el);
2054 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2056 if (uentry_isCheckedModify (ue)
2057 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2059 if (context_hasMods ())
2061 return (gc.flags[FLG_MODGLOBS]);
2065 if (uentry_isCheckedStrict (ue))
2067 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2071 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2077 if (context_hasMods ())
2079 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2089 context_usedGlobal (/*@exposed@*/ sRef el)
2091 if (!globSet_member (gc.globs_used, el))
2094 ** The first time a global is used in a function, we need
2095 ** to clear the derived sRefs, since they were set for the
2096 ** previous function.
2099 sRef_clearDerived (el);
2100 gc.globs_used = globSet_insert (gc.globs_used, el);
2104 /*@observer@*/ sRefSet
2105 context_modList (void)
2111 context_globAccess (sRef s)
2113 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2114 return (globSet_member (gc.globs, s));
2118 context_hasAccess (typeId t)
2120 if (context_inFunctionLike ())
2122 DPRINTF (("Access %d / %s",
2123 t, typeIdSet_unparse (gc.acct)));
2124 return (typeIdSet_member (gc.acct, t));
2128 return (context_hasFileAccess (t));
2133 context_hasFileAccess (typeId t)
2135 return (typeIdSet_member (gc.facct, t));
2139 context_unparseAccess (void)
2141 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2142 typeIdSet_unparse (gc.facct)));
2146 context_unparseClauses (void)
2148 return (clauseStack_unparse (gc.clauses));
2152 context_couldHaveAccess (typeId t)
2154 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2156 return (typeIdSet_member (gc.acct, t));
2160 return (typeIdSet_member (gc.facct, t));
2165 context_getRetType (void)
2167 ctype f = ctype_undefined;
2169 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2171 f = uentry_getType (gc.cont.fcn);
2173 else if (gc.kind == CX_UNKNOWNMACRO)
2175 return ctype_unknown;
2179 llcontbuglit ("context_getRetType: not in a function context");
2180 return ctype_unknown;
2183 if (!ctype_isFunction (f))
2185 if (ctype_isKnown (f))
2187 llbuglit ("context_getRetType: not a function");
2190 return ctype_unknown;
2192 return (ctype_getReturnType (f));
2196 context_hasMods (void)
2198 if (context_inFunctionLike ())
2200 return (uentry_hasMods (gc.cont.fcn));
2209 context_exitAllClauses (void)
2211 while (!clauseStack_isEmpty (gc.clauses))
2213 clause el = clauseStack_top (gc.clauses);
2216 if (clause_isNone (el))
2218 usymtab_quietExitScope (g_currentloc);
2219 clauseStack_pop (gc.clauses);
2223 context_exitClausePlain ();
2227 clauseStack_clear (gc.clauses);
2228 gc.inclause = NOCLAUSE;
2232 context_exitAllClausesQuiet (void)
2234 while (!clauseStack_isEmpty (gc.clauses))
2236 clause el = clauseStack_top (gc.clauses);
2239 usymtab_quietExitScope (g_currentloc);
2240 clauseStack_pop (gc.clauses);
2243 clauseStack_clear (gc.clauses);
2244 gc.inclause = NOCLAUSE;
2248 void context_exitClauseSimp (void)
2251 context_setJustPopped ();
2252 clauseStack_pop (gc.clauses);
2253 gc.inclause = topClause (gc.clauses);
2257 void context_exitCaseClause (void)
2259 context_setJustPopped ();
2260 usymtab_popCaseBranch ();
2261 clauseStack_pop (gc.clauses);
2262 gc.inclause = topClause (gc.clauses);
2266 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2268 context_setJustPopped ();
2269 /*@i32 was makeAlt */
2270 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2271 clauseStack_pop (gc.clauses);
2272 gc.inclause = topClause (gc.clauses);
2275 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2277 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2279 if (gc.inclause != TRUECLAUSE)
2281 llparseerror (cstring_makeLiteral
2282 ("Likely parse error. Conditional clauses are inconsistent."));
2286 context_setJustPopped ();
2287 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2288 clauseStack_pop (gc.clauses);
2289 gc.inclause = topClause (gc.clauses);
2292 void context_exitIterClause (exprNode body)
2294 llassert (gc.inclause == ITERCLAUSE);
2296 context_setJustPopped ();
2298 if (context_getFlag (FLG_ITERLOOPEXEC))
2300 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2304 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2307 clauseStack_pop (gc.clauses);
2308 gc.inclause = topClause (gc.clauses);
2311 static void context_popCase (void) {
2313 ** If we are exiting an outer clause, sometimes still in a switch case.
2327 DPRINTF (("Popping case clause: %s",
2328 clauseStack_unparse (gc.clauses)));
2330 if (gc.inclause == CASECLAUSE) {
2331 context_exitCaseClause ();
2335 void context_exitWhileClause (exprNode pred, exprNode body)
2337 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2341 if (gc.inclause != WHILECLAUSE) {
2342 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2343 clauseStack_unparse (gc.clauses)));
2346 llassert (gc.inclause == WHILECLAUSE);
2348 context_setJustPopped ();
2352 ** predicate must be false after while loop (unless there are breaks)
2355 if (context_getFlag (FLG_WHILELOOPEXEC))
2357 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2361 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2365 usymtab_addGuards (invGuards);
2366 guardSet_free (invGuards);
2368 clauseStack_pop (gc.clauses);
2369 gc.inclause = topClause (gc.clauses);
2372 void context_exitDoWhileClause (exprNode pred)
2374 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2376 if (gc.inclause == CASECLAUSE) {
2377 /* handle Duff's device */
2378 clauseStack_pop (gc.clauses);
2379 gc.inclause = topClause (gc.clauses);
2382 llassert (gc.inclause == DOWHILECLAUSE);
2384 context_setJustPopped ();
2387 usymtab_addGuards (invGuards);
2388 guardSet_free (invGuards);
2390 clauseStack_pop (gc.clauses);
2391 gc.inclause = topClause (gc.clauses);
2394 void context_exitForClause (exprNode forPred, exprNode body)
2396 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2398 llassert (gc.inclause == FORCLAUSE);
2399 context_setJustPopped ();
2401 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2404 ** Predicate must be false after for loop (unless there are breaks)
2407 if (context_getFlag (FLG_FORLOOPEXEC))
2409 DPRINTF (("Here: for loop exec"));
2410 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2414 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2415 && exprNode_loopMustExec (forPred))
2417 DPRINTF (("Here: loop must exec"));
2418 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2422 DPRINTF (("Pop true branch:"));
2423 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2427 usymtab_addGuards (invGuards);
2428 guardSet_free (invGuards);
2429 clauseStack_pop (gc.clauses);
2430 gc.inclause = topClause (gc.clauses);
2433 static void context_exitClausePlain (void)
2435 llassert (gc.inclause != NOCLAUSE);
2437 if (gc.inclause == FALSECLAUSE)
2439 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2443 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2447 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2449 context_setJustPopped ();
2451 if (gc.inclause == FALSECLAUSE)
2453 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2455 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2457 clauseStack_pop (gc.clauses);
2458 gc.inclause = topClause (gc.clauses);
2462 context_exitTrueClause (pred, tbranch);
2467 context_returnFunction (void)
2469 usymtab_checkFinalScope (TRUE);
2473 context_exitFunction (void)
2475 DPRINTF (("Exit function: %s", context_unparse ()));
2477 if (!context_inFunction () && !context_inMacroConstant ()
2478 && !context_inUnknownMacro ()
2479 && !context_inIterDef () && !context_inIterEnd ())
2482 ** not a bug because of parse errors
2489 if (context_inMacro () && usymtab_inFunctionScope ())
2491 usymtab_exitScope (exprNode_undefined);
2494 if (uentry_hasGlobs (gc.cont.fcn))
2496 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2500 if (uentry_hasMods (gc.cont.fcn))
2502 if (context_getFlag (FLG_MUSTMOD))
2504 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2508 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2511 ** clear file static modifies
2514 /* do this first to get unused error messages */
2516 usymtab_exitScope (exprNode_undefined);
2517 sRef_exitFunctionScope ();
2519 gc.showfunction = FALSE;
2520 gc.kind = CX_GLOBAL;
2521 gc.cont.glob = TRUE;
2523 gc.globs = globSet_new ();
2524 globSet_clear (gc.globs_used);
2525 gc.mods = sRefSet_new ();
2528 llassert (clauseStack_isEmpty (gc.clauses));
2529 llassert (gc.inclause == NOCLAUSE);
2530 DPRINTF (("After exit function: %s", context_unparse ()));
2534 context_quietExitFunction (void)
2536 while (gc.kind == CX_INNER)
2538 context_exitInnerPlain ();
2541 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2542 && !context_inIterDef () && !context_inIterEnd ())
2547 usymtab_quietExitScope (g_currentloc);
2549 gc.showfunction = FALSE;
2550 gc.kind = CX_GLOBAL;
2551 gc.cont.glob = TRUE;
2553 gc.globs = globSet_new ();
2554 globSet_clear (gc.globs_used);
2555 gc.mods = sRefSet_new ();
2557 sRef_exitFunctionScope ();
2561 /*@observer@*/ uentryList
2562 context_getParams (void)
2564 if (context_inFunctionLike ())
2566 return (uentry_getParams (gc.cont.fcn));
2570 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2571 return uentryList_undefined;
2575 /*@observer@*/ globSet
2576 context_getUsedGlobs (void)
2578 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2579 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2581 return (gc.globs_used);
2585 context_moduleName ()
2587 return (fileloc_getBase (g_currentloc));
2590 /*@observer@*/ globSet
2591 context_getGlobs (void)
2593 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2594 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2600 context_addBoolAccess (void)
2602 cstring bname = context_getString (FLG_BOOLTYPE);
2603 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2605 addModuleAccess (cstring_copy (bname), boolt);
2607 /* for sys/types (perhaps, this is bogus!) */
2608 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2613 context_canAccessBool (void)
2620 static typeId boolType = typeId_invalid;
2622 if (typeId_isInvalid (boolType))
2624 boolType = usymtab_getTypeId (context_getBoolName ());
2627 if (typeId_isInvalid (boolType)) {
2630 return (typeIdSet_member (gc.acct, boolType));
2635 /* evs 2000-07-25: old version - replaced */
2638 context_boolImplementationType () {
2639 /* For now, this is bogus! */
2644 context_canAccessBool (void)
2646 static typeId boolType = typeId_invalid;
2648 if (typeId_isInvalid (boolType))
2650 boolType = usymtab_getTypeId (context_getBoolName ());
2653 if (!typeId_isInvalid (boolType))
2655 return context_hasAccess (boolType);
2666 context_setMessageAnnote (/*@only@*/ cstring s)
2668 llassert (cstring_isUndefined (gc.msgAnnote));
2673 context_hasMessageAnnote (void)
2675 return (cstring_isDefined (gc.msgAnnote));
2679 context_clearMessageAnnote (void)
2681 if (cstring_isDefined (gc.msgAnnote))
2683 cstring_free (gc.msgAnnote);
2684 gc.msgAnnote = cstring_undefined;
2689 context_getMessageAnnote (void)
2691 cstring st = gc.msgAnnote;
2693 gc.msgAnnote = cstring_undefined;
2698 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2700 llassert (sRef_isInvalid (gc.aliasAnnote));
2701 llassert (!sRef_sameName (s, t));
2703 gc.aliasAnnoteAls = t;
2707 context_hasAliasAnnote (void)
2709 return (sRef_isValid (gc.aliasAnnote));
2713 context_clearAliasAnnote (void)
2715 gc.aliasAnnote = sRef_undefined;
2719 context_getAliasAnnote (void)
2721 sRef ret = gc.aliasAnnote;
2722 sRef als = gc.aliasAnnoteAls;
2724 llassert (sRef_isValid (ret) && sRef_isValid (als));
2726 gc.aliasAnnote = sRef_undefined;
2727 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2731 context_recordFileModifies (sRefSet mods)
2733 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2737 context_recordFileGlobals (globSet mods)
2739 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2740 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2744 context_setCommentMarkerChar (char c)
2746 llassert (c != '\0');
2748 context_setValue (FLG_COMMENTCHAR, (int) c);
2752 context_getCommentMarkerChar (void)
2754 return ((char) context_getValue (FLG_COMMENTCHAR));
2758 context_setValue (flagcode flag, int val)
2760 int index = flagcode_valueIndex (flag);
2762 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2770 llerror_flagWarning (message ("Value for %s must be a positive "
2771 "number (given %d)",
2772 flagcode_unparse (flag), val));
2775 if (flag == FLG_LINELEN && val < MINLINELEN)
2777 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2778 flagcode_unparse (flag),
2784 case FLG_INCLUDENEST:
2785 case FLG_CONTROLNESTDEPTH:
2786 case FLG_STRINGLITERALLEN:
2787 case FLG_NUMSTRUCTFIELDS:
2788 case FLG_NUMENUMMEMBERS:
2789 case FLG_INDENTSPACES:
2792 llerror_flagWarning (message ("Value for %s must be a non-negative "
2793 "number (given %d)",
2794 flagcode_unparse (flag), val));
2803 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2804 gc.values[index] = val;
2808 context_setValueAndFlag (flagcode flag, int val)
2810 gc.flags[flag] = TRUE;
2811 context_setValue (flag, val);
2815 context_getValue (flagcode flag)
2817 int index = flagcode_valueIndex (flag);
2819 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2820 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2821 return (gc.values[index]);
2825 context_getCounter (flagcode flag)
2827 int index = flagcode_valueIndex (flag);
2829 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2830 return (gc.counters[index]);
2834 context_incCounter (flagcode flag)
2836 int index = flagcode_valueIndex (flag);
2838 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2840 gc.counters[index]++;
2844 context_decCounter (flagcode flag)
2846 int index = flagcode_valueIndex (flag);
2848 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2849 gc.counters[index]--;
2852 bool context_showFunction (void)
2854 return (gc.showfunction);
2858 context_setString (flagcode flag, cstring val)
2860 int index = flagcode_stringIndex (flag);
2862 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2864 if (flag == FLG_SYSTEMDIRS)
2866 llassert (cstring_isDefined (val));
2868 if (cstring_firstChar (val) == '\"')
2871 cstring tval = cstring_copy (cstring_suffix (val, 1));
2873 if (cstring_lastChar (tval) != '\"')
2875 int n = cstring_length (tval) - 1;
2877 while (isspace ((int) cstring_getChar (tval, n)))
2882 if (cstring_getChar (tval, n) != '\"')
2884 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2888 cstring otval = tval;
2889 tval = cstring_prefix (tval, n);
2890 cstring_free (otval);
2894 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2895 DPRINTF (("val = %s", val));
2896 cstring_free (tval);
2897 cstring_free (oval);
2901 if (flag == FLG_TMPDIR)
2903 llassert (cstring_isDefined (val));
2905 if (cstring_length (val) == 0)
2908 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2910 else if (cstring_lastChar (val) != CONNECTCHAR)
2912 val = cstring_appendChar (val, CONNECTCHAR);
2920 if (cstring_length (val) >= 1
2921 && cstring_firstChar (val) == '\"')
2923 llerror_flagWarning (message
2924 ("setting %s to string beginning with \". You probably "
2925 "don't meant to have the \"'s.",
2926 flagcode_unparse (flag)));
2929 if (flag == FLG_BOOLTYPE)
2934 gc.strings[index] = val;
2937 static /*@exposed@*/ cstring
2938 context_exposeString (flagcode flag)
2940 int index = flagcode_stringIndex (flag);
2942 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2943 return (gc.strings[index]);
2947 context_getString (flagcode flag)
2949 return (context_exposeString (flag));
2953 context_resetErrors (void)
2958 void context_initMod (void)
2959 /*@globals undef gc; @*/
2961 gc.kind = CX_GLOBAL;
2963 gc.savekind = CX_ERROR;
2964 gc.savecont.glob = FALSE;
2966 gc.instandardlib = FALSE;
2969 gc.linesprocessed = 0;
2970 gc.speclinesprocessed = 0;
2971 gc.insuppressregion = FALSE;
2972 gc.macroMissingParams = FALSE;
2973 gc.preprocessing = FALSE;
2974 gc.incommandline = FALSE;
2975 gc.mc = macrocache_create ();
2977 gc.maxmods = DEFAULTMAXMODS;
2978 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2980 gc.library = FLG_ANSILIB;
2982 gc.locstack = filelocStack_new ();
2983 gc.modrecs = sRefSetList_undefined;
2984 gc.anyExports = FALSE;
2986 gc.ftab = fileTable_create ();
2987 gc.msgLog = messageLog_new ();
2988 gc.inimport = FALSE;
2989 gc.inDerivedFile = FALSE;
2990 gc.inheader = FALSE;
2991 gc.markers = flagMarkerList_new ();
2992 gc.cont.glob = TRUE;
2993 gc.showfunction = FALSE;
2994 gc.msgAnnote = cstring_undefined;
2995 gc.aliasAnnote = sRef_undefined;
2996 gc.aliasAnnoteAls = sRef_undefined;
2997 gc.boolType = ctype_bool;
2998 gc.mods = sRefSet_new ();
3000 gc.saveloc = fileloc_undefined;
3002 gc.inmacrocache = FALSE;
3003 gc.inclause = NOCLAUSE;
3004 gc.clauses = clauseStack_new ();
3005 gc.globs = globSet_new ();
3006 gc.nacct = typeIdSet_emptySet ();
3007 gc.acct = typeIdSet_emptySet ();
3008 gc.facct = typeIdSet_emptySet ();
3009 gc.savedFlags = FALSE;
3010 gc.pushloc = fileloc_undefined;
3011 gc.protectVars = FALSE;
3012 gc.justpopped = FALSE;
3013 gc.isNullGuarded = NO;
3014 gc.globs_used = globSet_undefined;
3018 gc.setGlobally[code] = FALSE;
3019 gc.setLocally[code] = FALSE;
3025 context_resetAllFlags ();
3027 assertSet (gc.flags); /* Can't use global in defines */
3028 assertSet (gc.saveflags);
3029 assertSet (gc.values);
3030 assertSet (gc.strings);
3032 conext_resetAllCounters ();
3033 assertSet (gc.counters);
3035 context_setMode (DEFAULT_MODE);
3037 gc.stateTable = metaStateTable_create ();
3038 gc.annotTable = annotationTable_create ();
3040 gc.inFunctionHeader = FALSE;
3042 DPRINTF (("Annotations: \n%s",
3043 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3044 DPRINTF (("State: \n%s",
3045 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3050 context_typeofZero (void)
3052 ctype ct = ctype_int;
3054 if (context_getFlag (FLG_ZEROPTR))
3056 ct = ctype_makeConj (ct, ctype_voidPointer);
3059 if (context_getFlag (FLG_ZEROBOOL)) {
3060 ct = ctype_makeConj (ct, ctype_bool);
3067 context_typeofOne (void)
3069 ctype ct = ctype_int;
3071 /* 1 is on longer a bool (was before 2.4)
3072 if (!context_getFlag (FLG_ABSTRACTBOOL))
3074 ct = ctype_makeConj (ct, ctype_bool);
3082 context_unparse (void)
3089 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3092 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3095 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3098 s = message ("Inner Context [%d] : %q",
3100 fileloc_unparse (g_currentloc));
3103 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3104 uentry_unparse (gc.cont.fcn),
3105 fileloc_unparse (g_currentloc),
3106 typeIdSet_unparse (gc.acct),
3107 sRefSet_unparse (gc.mods));
3110 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3112 case CX_UNKNOWNMACRO:
3113 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3116 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3119 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3122 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3124 case CX_FCNDECLARATION:
3125 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3128 s = message ("Un-unparseable context: %d", (int) gc.kind);
3132 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3137 context_currentFunctionType (void)
3139 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3141 return (uentry_getType (gc.cont.fcn));
3143 else if (gc.kind == CX_INNER)
3145 llcontbuglit ("context_currentFunctionType: inner context");
3146 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3147 return (context_currentFunctionType ());
3151 llcontbuglit ("context_currentFunctionType: not in function");
3152 return (ctype_undefined);
3157 context_enterInnerContext (void)
3159 if (context_getFlag (FLG_GRAMMAR))
3161 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3164 if (gc.kind == CX_GLOBAL)
3169 else if (gc.kind == CX_INNER)
3178 usymtab_enterScope ();
3179 pushClause (NOCLAUSE);
3183 context_exitInnerPlain (void) /*@modifies gc;@*/
3185 context_exitInner (exprNode_undefined);
3189 context_exitInner (exprNode exp)
3191 if (context_getFlag (FLG_GRAMMAR))
3193 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3196 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3197 ("inclause = %s", clause_nameTaken (gc.inclause)));
3199 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3200 gc.inclause = topClause (gc.clauses);
3202 if (gc.kind == CX_INNER)
3204 if (--gc.cont.cdepth == 0)
3206 gc.kind = CX_GLOBAL;
3207 gc.cont.glob = TRUE;
3212 if (gc.kind == CX_GLOBAL)
3214 llcontbuglit ("Attempt to exit global context");
3219 usymtab_exitScope (exp);
3224 context_enterStructInnerContext (void)
3226 if (context_getFlag (FLG_GRAMMAR))
3228 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3231 if (gc.kind == CX_GLOBAL)
3236 else if (gc.kind == CX_INNER)
3245 usymtab_enterScope ();
3247 if (context_getFlag (FLG_GRAMMAR))
3249 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3254 context_exitStructInnerContext (void)
3256 if (context_getFlag (FLG_GRAMMAR))
3258 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3261 if (gc.kind == CX_INNER)
3263 if (gc.cont.cdepth <= 0)
3265 llcontbuglit ("Attempt to exit inner context with no depth");
3266 gc.kind = CX_GLOBAL;
3267 gc.cont.glob = TRUE;
3273 if (gc.cont.cdepth == 0)
3275 gc.kind = CX_GLOBAL;
3276 gc.cont.glob = TRUE;
3282 if (gc.kind == CX_GLOBAL)
3284 llcontbuglit ("Attempt to exit global context");
3289 usymtab_exitScope (exprNode_undefined);
3291 if (context_getFlag (FLG_GRAMMAR))
3293 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3298 context_exitInnerSafe (void)
3300 if (context_getFlag (FLG_GRAMMAR))
3302 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3305 if (gc.kind == CX_INNER)
3307 if (--gc.cont.cdepth <= 0)
3312 else if (gc.kind == CX_GLOBAL)
3314 llcontbuglit ("Attempt to exit global context");
3319 if (usymtab_inDeepScope ())
3321 usymtab_exitScope (exprNode_undefined);
3327 void setModuleAccess (void)
3329 gc.facct = typeIdSet_emptySet ();
3331 if (fileId_isValid (currentFile ()))
3333 cstring baseName = fileloc_getBase (g_currentloc);
3335 if (context_getFlag (FLG_ACCESSFILE))
3337 if (usymtab_existsType (baseName))
3339 gc.facct = typeIdSet_insert (gc.facct,
3340 usymtab_getTypeId (baseName));
3348 if (context_getFlag (FLG_ACCESSMODULE))
3351 bool hasaccess = FALSE;
3353 for (i = 0; i < gc.nmods; i++)
3355 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3357 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3366 gc.inheader = fileId_isHeader (currentFile ());
3370 llcontbuglit ("Current file not defined\n");
3371 gc.facct = typeIdSet_emptySet ();
3373 gc.inheader = FALSE;
3376 /* 17 Jan 1995: forgot to clear nacct */
3378 gc.nacct = typeIdSet_emptySet ();
3382 context_enterFileAux (void)
3388 context_enterFile (void)
3390 context_enterFileAux ();
3391 usymtab_enterFile ();
3395 context_enterMacroFile (void)
3397 context_enterFileAux ();
3401 context_inFunction (void)
3403 kcontext ck = gc.kind;
3405 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3409 context_inFunctionLike (void)
3411 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3412 || gc.kind == CX_FCNDECLARATION
3413 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3417 context_inRealFunction (void)
3419 kcontext ck = gc.kind;
3421 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3425 context_processAllMacros (void)
3427 usymtab_enterFile ();
3429 gc.inmacrocache = TRUE;
3430 macrocache_processUndefinedElements (gc.mc);
3432 usymtab_exitFile ();
3434 gc.inmacrocache = FALSE;
3435 macrocache_finalize ();
3439 ** this happens once at the end of each C file
3441 ** check each Macro that was defined in current file.c or current file.h
3446 context_processMacros (void)
3448 if (fileId_isValid (currentFile ()))
3451 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileName (currentFile ())));
3453 gc.inmacrocache = TRUE;
3455 DPRINTF (("Processing macros: %s", cbase));
3456 lastfl = macrocache_processFileElements (gc.mc, cbase);
3457 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3459 cstring_free (cbase);
3461 if (fileloc_isDefined (lastfl))
3463 g_currentloc = fileloc_update (g_currentloc, lastfl);
3467 gc.inmacrocache = FALSE;
3472 context_processingMacros (void)
3474 return (gc.inmacrocache);
3478 context_exitCFile (void)
3480 if (gc.kind != CX_GLOBAL)
3483 (cstring_makeLiteral ("File ended outside global scope"));
3486 if (gc.insuppressregion)
3488 /* gack...don't reverse the order of these lines! ;-> */
3489 gc.insuppressregion = FALSE;
3490 llerrorlit (FLG_SYNTAX,
3491 "File ended in ignore errors region, "
3492 "possible missing /*@end*/");
3495 /* fix up parse errors */
3497 while (!usymtab_inFileScope ())
3499 usymtab_quietExitScope (g_currentloc);
3503 ** Clear the file-specific modifies information.
3506 sRefSetList_elements (gc.modrecs, mods)
3508 sRefSet_clearStatics (mods);
3509 } end_sRefSetList_elements ;
3511 sRefSetList_clear (gc.modrecs);
3513 context_processMacros ();
3516 usymtab_exitFile ();
3518 gc.inDerivedFile = FALSE;
3519 filelocStack_clear (gc.locstack);
3521 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3523 gc.cont.glob = TRUE;
3527 context_restoreFlagSettings ();
3528 gc.savedFlags = FALSE;
3532 DPRINTF (("After exiting file: "));
3533 usymtab_printAll ();
3538 context_exitMacroCache (void)
3540 if (gc.kind != CX_GLOBAL)
3542 if (context_inMacro ())
3543 /* this is okay, file could end without newline in macro */
3545 DPRINTF (("Still in macro: %s",
3546 context_unparse ()));
3547 context_exitFunction ();
3551 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3552 context_unparse ()));
3553 gc.kind = CX_GLOBAL;
3558 ** no longer valid here
3559 ** if (gc.insuppressregion)
3561 ** gc.insuppressregion = FALSE;
3562 ** llerror ("File ended in ignore errors region, possible missing @");
3566 gc.cont.glob = TRUE;
3570 context_saveLocation (void)
3572 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3573 fileloc_free (gc.saveloc);
3574 gc.saveloc = fileloc_copy (g_currentloc);
3578 context_getSaveLocation (void)
3580 fileloc fl = gc.saveloc;
3581 gc.saveloc = fileloc_undefined;
3585 /*@observer@*/ cstring
3586 context_inFunctionName (void)
3588 if (gc.kind == CX_FUNCTION
3589 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3590 || gc.kind == CX_MACROCONST
3591 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3593 return (uentry_rawName (gc.cont.fcn));
3597 llcontbuglit ("context_inFunctionName: not in function");
3598 return (cstring_undefined);
3603 context_userSetFlag (flagcode f, bool b)
3605 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3607 if (f == FLG_NEVERINCLUDE && b)
3609 if (gc.flags[FLG_EXPORTHEADER])
3611 llerror_flagWarning (cstring_makeLiteral
3612 ("setting +neverinclude after +exportheader. "
3613 "Turning off exportheader, since headers are not checked "
3614 "when +neverinclude is used."));
3616 gc.flags[FLG_EXPORTHEADER] = FALSE;
3621 if (f == FLG_EXPORTHEADER && b)
3623 if (gc.flags[FLG_NEVERINCLUDE])
3625 llerror_flagWarning (cstring_makeLiteral
3626 ("setting +exportheader after +neverinclude. "
3627 "Not setting exportheader, since headers are not checked "
3628 "when +neverinclude is used."));
3629 gc.flags[FLG_EXPORTHEADER] = FALSE;
3635 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3637 bool lastsetting = context_getFlag (f);
3639 if (bool_equal (lastsetting, b)
3640 && !flagcode_isSpecialFlag (f)
3641 && !flagcode_isIdemFlag (f)
3642 && !flagcode_hasArgument (f))
3644 llerror_flagWarning (message ("setting %s%s redundant with current value",
3645 cstring_makeLiteralTemp (b ? "+" : "-"),
3646 flagcode_unparse (f)));
3650 if (flagcode_isWarnUseFlag (f) && b)
3652 if (!context_getFlag (FLG_WARNUSE))
3654 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3655 flagcode_unparse (f)));
3661 if (flagcode_isLibraryFlag (f))
3663 if (gc.library != FLG_ANSILIB
3666 llerror_flagWarning (message ("selecting library %s after library %s was "
3667 "selected (only one library may be used)",
3668 flagcode_unparse (f),
3669 flagcode_unparse (gc.library)));
3672 if (f == FLG_UNIXLIB)
3674 if (context_getFlag (FLG_WARNUNIXLIB))
3676 llerror_flagWarning (cstring_makeLiteral
3677 ("selecting unix library. Unix library is "
3678 "ad hoc addition to POSIX library. Recommend "
3679 "use +posixlib to select POSIX library instead. "
3680 "Use -warnunixlib to suppress this message."));
3687 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3689 llerror_flagWarning (message
3690 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3691 flagcode_unparse (f)));
3694 gc.setGlobally[f] = TRUE;
3695 context_setFlag (f, b);
3699 context_fileSetFlag (flagcode f, ynm set)
3703 context_saveFlagSettings ();
3706 if (ynm_isOff (set))
3708 context_setFlagAux (f, FALSE, TRUE, FALSE);
3710 else if (ynm_isOn (set))
3712 context_setFlagAux (f, TRUE, TRUE, FALSE);
3713 gc.setLocally[f] = TRUE;
3717 context_restoreFlag (f);
3722 context_restoreFlag (flagcode f)
3729 message ("Attempt to restore flag %s when no file scope flags "
3731 flagcode_unparse (f)),
3736 context_addFlagMarker (f, MAYBE);
3737 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3743 context_setFlag (flagcode f, bool b)
3745 context_setFlagAux (f, b, FALSE, FALSE);
3749 context_setFlagTemp (flagcode f, bool b)
3751 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3756 # define DOSET(ff,b) \
3757 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3758 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3759 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3760 gc.flags[ff] = b; } while (FALSE)
3763 context_setFlagAux (flagcode f, bool b, bool inFile,
3764 /*@unused@*/ bool isRestore)
3766 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3768 if (f == FLG_USESTDERR)
3771 g_msgstream = stderr;
3773 g_msgstream = stdout;
3778 ** Removed test for special flags.
3781 if (flagcode_isIdemFlag (f))
3790 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3792 if (b) /* Turing higher level on, turns on all lower levels */
3796 case FLG_ITS4MOSTRISKY:
3797 DOSET (FLG_ITS4VERYRISKY, b);
3799 case FLG_ITS4VERYRISKY:
3800 DOSET (FLG_ITS4RISKY, b);
3803 DOSET (FLG_ITS4MODERATERISK, b);
3805 case FLG_ITS4MODERATERISK:
3806 DOSET (FLG_ITS4LOWRISK, b);
3808 case FLG_ITS4LOWRISK:
3813 else /* Turning level off, turns off all higher levels */
3817 case FLG_ITS4LOWRISK:
3818 DOSET (FLG_ITS4MODERATERISK, b);
3820 case FLG_ITS4MODERATERISK:
3821 DOSET (FLG_ITS4RISKY, b);
3824 DOSET (FLG_ITS4VERYRISKY, b);
3826 case FLG_ITS4VERYRISKY:
3827 DOSET (FLG_ITS4MOSTRISKY, b);
3829 case FLG_ITS4MOSTRISKY:
3839 DOSET (FLG_ALLEMPTY, b);
3840 DOSET (FLG_IFEMPTY, b);
3841 DOSET (FLG_WHILEEMPTY, b);
3842 DOSET (FLG_FOREMPTY, b);
3845 DOSET (FLG_PREDBOOL, b);
3846 DOSET (FLG_PREDBOOLINT, b);
3847 DOSET (FLG_PREDBOOLPTR, b);
3848 DOSET (FLG_PREDBOOLOTHERS, b);
3851 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3852 DOSET (FLG_CHECKEDGLOBALIAS, b);
3853 DOSET (FLG_CHECKMODGLOBALIAS, b);
3854 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3857 DOSET (FLG_ALLBLOCK, b);
3858 DOSET (FLG_IFBLOCK, b);
3859 DOSET (FLG_WHILEBLOCK, b);
3860 DOSET (FLG_FORBLOCK, b);
3874 DOSET (FLG_GRAMMAR, b);
3876 case FLG_CODEIMPONLY:
3877 DOSET (FLG_CODEIMPONLY, b);
3878 DOSET (FLG_GLOBIMPONLY, b);
3879 DOSET (FLG_RETIMPONLY, b);
3880 DOSET (FLG_STRUCTIMPONLY, b);
3882 case FLG_SPECALLIMPONLY:
3883 DOSET (FLG_SPECALLIMPONLY, b);
3884 DOSET (FLG_SPECGLOBIMPONLY, b);
3885 DOSET (FLG_SPECRETIMPONLY, b);
3886 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3888 case FLG_ALLIMPONLY:
3889 DOSET (FLG_ALLIMPONLY, b);
3890 DOSET (FLG_GLOBIMPONLY, b);
3891 DOSET (FLG_RETIMPONLY, b);
3892 DOSET (FLG_STRUCTIMPONLY, b);
3893 DOSET (FLG_SPECGLOBIMPONLY, b);
3894 DOSET (FLG_SPECRETIMPONLY, b);
3895 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3897 case FLG_ANSI89LIMITS:
3898 DOSET (FLG_ANSI89LIMITS, b);
3899 DOSET (FLG_CONTROLNESTDEPTH, b);
3900 DOSET (FLG_STRINGLITERALLEN, b);
3901 DOSET (FLG_INCLUDENEST, b);
3902 DOSET (FLG_NUMSTRUCTFIELDS, b);
3903 DOSET (FLG_NUMENUMMEMBERS, b);
3907 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
3908 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
3909 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
3910 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
3911 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
3912 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
3913 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
3916 case FLG_ISO99LIMITS:
3917 DOSET (FLG_ISO99LIMITS, b);
3918 DOSET (FLG_CONTROLNESTDEPTH, b);
3919 DOSET (FLG_STRINGLITERALLEN, b);
3920 DOSET (FLG_INCLUDENEST, b);
3921 DOSET (FLG_NUMSTRUCTFIELDS, b);
3922 DOSET (FLG_NUMENUMMEMBERS, b);
3926 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
3927 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
3928 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
3929 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
3930 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
3931 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
3932 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
3935 case FLG_EXTERNALNAMELEN:
3936 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3937 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3939 case FLG_INTERNALNAMELEN:
3940 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3941 DOSET (FLG_INTERNALNAMELEN, TRUE);
3943 case FLG_EXTERNALNAMECASEINSENSITIVE:
3944 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3946 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3948 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3949 context_setValue (FLG_EXTERNALNAMELEN, 0);
3952 case FLG_INTERNALNAMECASEINSENSITIVE:
3953 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3955 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3957 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3958 context_setValue (FLG_INTERNALNAMELEN, 0);
3961 case FLG_INTERNALNAMELOOKALIKE:
3962 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3964 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3966 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3967 context_setValue (FLG_INTERNALNAMELEN, 0);
3971 DOSET (FLG_MODNOMODS, b);
3972 DOSET (FLG_MODGLOBSUNSPEC, b);
3973 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3976 DOSET (FLG_EXPORTVAR, b);
3977 DOSET (FLG_EXPORTFCN, b);
3978 DOSET (FLG_EXPORTTYPE, b);
3979 DOSET (FLG_EXPORTMACRO, b);
3980 DOSET (FLG_EXPORTCONST, b);
3981 gc.anyExports = TRUE;
3984 DOSET (FLG_RETEXPOSE, b);
3985 DOSET (FLG_ASSIGNEXPOSE, b);
3986 DOSET (FLG_CASTEXPOSE, b);
3989 DOSET (FLG_RETVALBOOL, b);
3990 DOSET (FLG_RETVALINT, b);
3991 DOSET (FLG_RETVALOTHER, b);
3996 DOSET (FLG_EXPORTLOCAL, FALSE);
3997 DOSET (FLG_DECLUNDEF, FALSE);
3998 DOSET (FLG_SPECUNDEF, FALSE);
3999 DOSET (FLG_TOPUNUSED, FALSE);
4003 DOSET (FLG_LOOPLOOPBREAK, b);
4004 DOSET (FLG_LOOPSWITCHBREAK, b);
4005 DOSET (FLG_SWITCHLOOPBREAK, b);
4006 DOSET (FLG_SWITCHSWITCHBREAK, b);
4007 DOSET (FLG_LOOPLOOPCONTINUE, b);
4008 DOSET (FLG_DEEPBREAK, b);
4011 DOSET (FLG_FORLOOPEXEC, b);
4012 DOSET (FLG_WHILELOOPEXEC, b);
4013 DOSET (FLG_ITERLOOPEXEC, b);
4016 DOSET (FLG_ACCESSMODULE, b);
4017 DOSET (FLG_ACCESSFILE, b);
4018 DOSET (FLG_ACCESSCZECH, b);
4021 DOSET (FLG_ALLMACROS, b);
4022 DOSET (FLG_FCNMACROS, b);
4023 DOSET (FLG_CONSTMACROS, b);
4026 DOSET (FLG_BOUNDSREAD, b);
4027 DOSET (FLG_BOUNDSWRITE, b);
4030 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4031 DOSET (FLG_CZECHFUNCTIONS, b);
4032 DOSET (FLG_CZECHVARS, b);
4033 DOSET (FLG_CZECHCONSTANTS, b);
4034 DOSET (FLG_CZECHTYPES, b);
4037 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4038 DOSET (FLG_SLOVAKFUNCTIONS, b);
4039 DOSET (FLG_SLOVAKVARS, b);
4040 DOSET (FLG_SLOVAKCONSTANTS, b);
4041 DOSET (FLG_SLOVAKTYPES, b);
4043 case FLG_CZECHOSLOVAK:
4044 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4045 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4046 DOSET (FLG_CZECHOSLOVAKVARS, b);
4047 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4048 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4051 DOSET (FLG_NULLSTATE, b);
4052 DOSET (FLG_NULLDEREF, b);
4053 DOSET (FLG_NULLASSIGN, b);
4054 DOSET (FLG_NULLPASS, b);
4055 DOSET (FLG_NULLRET, b);
4058 DOSET (FLG_MUSTFREEONLY, b);
4059 DOSET (FLG_MUSTFREEFRESH, b);
4062 DOSET (FLG_NULLSTATE, b);
4063 DOSET (FLG_NULLDEREF, b);
4064 DOSET (FLG_NULLASSIGN, b);
4065 DOSET (FLG_NULLPASS, b);
4066 DOSET (FLG_NULLRET, b);
4067 DOSET (FLG_COMPDEF, b);
4068 DOSET (FLG_COMPMEMPASS, b);
4069 DOSET (FLG_UNIONDEF, b);
4070 DOSET (FLG_MEMTRANS, b);
4071 DOSET (FLG_USERELEASED, b);
4072 DOSET (FLG_ALIASUNIQUE, b);
4073 DOSET (FLG_MAYALIASUNIQUE, b);
4074 DOSET (FLG_MUSTFREEONLY, b);
4075 DOSET (FLG_MUSTFREEFRESH, b);
4076 DOSET (FLG_MUSTDEFINE, b);
4077 DOSET (FLG_GLOBSTATE, b);
4078 DOSET (FLG_COMPDESTROY, b);
4079 DOSET (FLG_MUSTNOTALIAS, b);
4080 DOSET (FLG_MEMIMPLICIT, b);
4081 DOSET (FLG_BRANCHSTATE, b);
4082 /*@fallthrough@*/ /* also sets memtrans flags */
4084 DOSET (FLG_MEMTRANS, b);
4085 DOSET (FLG_EXPOSETRANS, b);
4086 DOSET (FLG_OBSERVERTRANS, b);
4087 DOSET (FLG_DEPENDENTTRANS, b);
4088 DOSET (FLG_NEWREFTRANS, b);
4089 DOSET (FLG_ONLYTRANS, b);
4090 DOSET (FLG_OWNEDTRANS, b);
4091 DOSET (FLG_FRESHTRANS, b);
4092 DOSET (FLG_SHAREDTRANS, b);
4093 DOSET (FLG_TEMPTRANS, b);
4094 DOSET (FLG_KEPTTRANS, b);
4095 DOSET (FLG_REFCOUNTTRANS, b);
4096 DOSET (FLG_STATICTRANS, b);
4097 DOSET (FLG_UNKNOWNTRANS, b);
4098 DOSET (FLG_KEEPTRANS, b);
4099 DOSET (FLG_IMMEDIATETRANS, b);
4106 if (b && !gc.anyExports
4107 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4108 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4109 || f == FLG_EXPORTCONST
4110 || f == FLG_EXPORTANY))
4112 gc.anyExports = TRUE;
4117 context_maybeSet (flagcode d)
4119 return (gc.flags[d] || gc.setLocally[d]);
4123 context_getFlag (flagcode d)
4125 return (gc.flags[d]);
4129 context_flagOn (flagcode f, fileloc loc)
4131 return (!context_suppressFlagMsg (f, loc));
4134 static void context_saveFlagSettings (void)
4136 gc.savedFlags = TRUE;
4137 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4138 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4141 static void context_restoreFlagSettings (void)
4143 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4144 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4145 gc.savedFlags = FALSE;
4148 void context_setFilename (fileId fid, int lineno)
4149 /*@globals fileloc g_currentloc;@*/
4150 /*@modifies g_currentloc@*/
4152 if (fileId_baseEqual (currentFile (), fid))
4159 fileloc_setColumn (g_currentloc, 0);
4161 if (fileloc_isSpecialFile (g_currentloc))
4163 gc.inDerivedFile = TRUE;
4166 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4168 int maxdepth = context_getValue (FLG_INCLUDENEST);
4170 if (filelocStack_size (gc.locstack) > maxdepth)
4172 int depth = filelocStack_includeDepth (gc.locstack);
4174 if (depth > maxdepth)
4178 message ("Maximum include nesting depth "
4179 "(%d, current depth %d) exceeded",
4182 filelocStack_nextTop (gc.locstack)))
4184 filelocStack_printIncludes (gc.locstack);
4190 g_currentloc = fileloc_create (fid, lineno, 1);
4191 gc.inheader = fileId_isHeader (currentFile ());
4193 context_enterFileAux ();
4197 void context_enterIterDef (/*@observer@*/ uentry le)
4199 context_enterMacro (le);
4200 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4201 gc.kind = CX_ITERDEF;
4204 void context_enterIterEnd (/*@observer@*/ uentry le)
4206 context_enterMacro (le);
4207 gc.kind = CX_ITEREND;
4211 context_destroyMod (void)
4212 /*@globals killed gc@*/
4215 ctype_destroyMod ();
4219 fileTable_free (gc.ftab);
4220 filelocStack_free (gc.locstack);
4222 gc.ftab = fileTable_undefined;
4224 macrocache_free (gc.mc);
4225 sfree (gc.moduleaccess);
4228 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4229 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4232 sRefSetList_free (gc.modrecs);
4234 flagMarkerList_free (gc.markers);
4236 messageLog_free (gc.msgLog);
4238 clauseStack_free (gc.clauses);
4241 cstring_free (gc.msgAnnote);
4242 globSet_free (gc.globs_used);
4243 metaStateTable_free (gc.stateTable);
4244 annotationTable_free (gc.annotTable);
4251 bool context_msgBoolInt (void)
4253 return gc.flags [FLG_BOOLINT];
4256 bool context_msgCharInt (void)
4258 return gc.flags [FLG_CHARINT];
4261 bool context_msgEnumInt (void)
4263 return gc.flags [FLG_ENUMINT];
4266 bool context_msgPointerArith (void)
4268 return gc.flags [FLG_POINTERARITH];
4271 bool context_msgStrictOps (void)
4273 return gc.flags [FLG_STRICTOPS];
4277 bool context_msgLh (void)
4279 return gc.flags [FLG_DOLH];
4283 void context_pushLoc (void)
4285 fileloc_free (gc.pushloc);
4286 gc.pushloc = gc.saveloc;
4287 gc.saveloc = fileloc_undefined;
4290 void context_popLoc (void)
4292 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4295 bool context_inGlobalScope (void)
4297 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4300 bool context_inInnerScope (void)
4302 return (gc.kind == CX_INNER);
4305 void context_setProtectVars (void)
4307 gc.protectVars = TRUE;
4310 bool context_anyErrors (void)
4312 return (gc.numerrors > 0);
4315 void context_hasError (void)
4318 DPRINTF (("num errors: %d", gc.numerrors));
4321 int context_numErrors (void)
4323 return gc.numerrors;
4326 bool context_neednl (void)
4331 void context_setNeednl (void)
4336 int context_getExpect (void)
4338 return (context_getValue (FLG_EXPECT));
4342 int context_getLCLExpect (void)
4344 return (context_getValue (FLG_LCLEXPECT));
4348 int context_getLimit (void)
4350 return (context_getValue (FLG_LIMIT));
4353 bool context_unlimitedMessages (void)
4355 return (context_getLimit () < 0);
4358 void context_releaseVars (void)
4360 llassert (gc.protectVars);
4361 gc.protectVars = FALSE;
4364 void context_sizeofReleaseVars (void)
4366 /* If there is a nested sizeof, this might not hold:
4367 llassert (gc.protectVars);
4370 gc.protectVars = FALSE;
4373 bool context_inProtectVars (void)
4375 return (gc.protectVars);
4378 void context_hideShowscan (void)
4380 gc.flags[FLG_SHOWSCAN] = FALSE;
4383 void context_unhideShowscan (void)
4385 gc.flags[FLG_SHOWSCAN] = TRUE;
4388 bool context_inHeader (void)
4390 return (gc.inheader);
4393 fileTable context_fileTable (void)
4398 cstring context_tmpdir (void)
4400 return (context_getString (FLG_TMPDIR));
4403 messageLog context_messageLog (void)
4408 bool context_inMacroFunction (void)
4410 return (gc.kind == CX_MACROFCN);
4413 bool context_inMacroConstant (void)
4415 return (gc.kind == CX_MACROCONST);
4418 bool context_inUnknownMacro (void)
4420 return (gc.kind == CX_UNKNOWNMACRO);
4423 void context_setShownFunction (void)
4425 gc.showfunction = FALSE;
4428 bool context_doDump (void)
4430 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4433 bool context_doMerge (void)
4435 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4438 cstring context_getDump (void)
4440 return context_getString (FLG_DUMP);
4443 cstring context_getMerge (void)
4445 return context_getString (FLG_MERGE);
4449 bool context_inLCLLib (void)
4451 return (gc.kind == CX_LCLLIB);
4454 bool context_inImport (void)
4456 return (gc.inimport);
4459 void context_enterImport (void)
4464 void context_leaveImport (void)
4466 gc.inimport = FALSE;
4470 bool context_inMacro (void)
4472 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4473 || gc.kind == CX_UNKNOWNMACRO
4474 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4477 bool context_inIterDef (void)
4479 return (gc.kind == CX_ITERDEF);
4482 bool context_inIterEnd (void)
4484 return (gc.kind == CX_ITEREND);
4487 int context_getLinesProcessed (void)
4489 return (gc.linesprocessed);
4492 int context_getSpecLinesProcessed (void)
4494 return (gc.speclinesprocessed);
4498 void context_processedSpecLine (void)
4500 gc.speclinesprocessed++;
4503 void context_resetSpecLines (void)
4505 gc.speclinesprocessed = 0;
4509 bool context_inGlobalContext (void)
4511 return (gc.kind == CX_GLOBAL);
4514 static void context_quietExitScopes (void)
4517 ** Try to restore the global scope (after an error).
4520 while (!usymtab_inFileScope ())
4522 usymtab_quietExitScope (g_currentloc);
4525 gc.cont.glob = TRUE;
4526 gc.kind = CX_GLOBAL;
4529 void context_checkGlobalScope (void)
4531 if (gc.kind != CX_GLOBAL)
4533 if (context_inMacro ())
4535 ; /* evans 2001-10-14: Okay to be in a macro here! */
4539 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4540 context_quietExitScopes ();
4545 void context_setFileId (fileId s)
4547 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4550 bool context_setBoolName (void)
4552 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4556 cstring context_printBoolName (void)
4558 if (context_setBoolName ())
4560 return context_getBoolName ();
4564 return cstring_makeLiteralTemp ("boolean");
4568 cstring context_getBoolName (void)
4570 return (context_getString (FLG_BOOLTYPE));
4573 cstring context_getFalseName (void)
4575 return (context_getString (FLG_BOOLFALSE));
4578 cstring context_getTrueName (void)
4580 return (context_getString (FLG_BOOLTRUE));
4583 cstring context_getLarchPath (void)
4585 return (context_getString (FLG_LARCHPATH));
4588 cstring context_getLCLImportDir (void)
4590 return (context_getString (FLG_LCLIMPORTDIR));
4593 static void context_setJustPopped (void)
4595 gc.justpopped = TRUE;
4598 void context_clearJustPopped (void)
4600 gc.justpopped = FALSE;
4603 bool context_justPopped (void)
4605 return (gc.justpopped);
4608 void context_setMacroMissingParams (void)
4610 gc.macroMissingParams = TRUE;
4613 void context_resetMacroMissingParams (void)
4615 gc.macroMissingParams = FALSE;
4618 bool context_isMacroMissingParams (void)
4620 return (gc.macroMissingParams);
4623 void context_showFilelocStack (void)
4625 filelocStack_printIncludes (gc.locstack);
4628 metaStateTable context_getMetaStateTable (void)
4630 return gc.stateTable;
4633 metaStateInfo context_lookupMetaStateInfo (cstring key)
4635 return metaStateTable_lookup (gc.stateTable, key);
4638 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4640 annotationInfo ainfo;
4642 ainfo = annotationTable_lookup (gc.annotTable, annot);
4647 void context_addAnnotation (annotationInfo ainfo)
4649 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4653 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4654 annotationInfo_getLoc (ainfo));
4656 annotationInfo_free (ainfo);
4660 annotationTable_insert (gc.annotTable, ainfo);
4664 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4666 if (metaStateTable_contains (gc.stateTable, mname))
4670 message ("Duplicate metastate declaration: %s", mname),
4671 metaStateInfo_getLoc (msinfo));
4672 cstring_free (mname);
4673 metaStateInfo_free (msinfo);
4677 DPRINTF (("Adding meta state: %s", mname));
4678 metaStateTable_insert (gc.stateTable, mname, msinfo);
4682 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4684 if (metaStateTable_size (gc.stateTable) > 0)
4686 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4687 /*@i32 should use smaller value... */
4688 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4690 metaStateTable_elements (gc.stateTable, msname, msi)
4692 mtContextNode context = metaStateInfo_getContext (msi);
4694 if (mtContextNode_matchesRefStrict (context, s))
4696 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4697 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4701 cstring_copy (metaStateInfo_getName (msi)),
4702 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4703 stateInfo_copy (sinfo)));
4707 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4710 end_metaStateTable_elements ;
4712 stateInfo_free (sinfo);
4713 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4718 stateInfo_free (sinfo);
4719 return valueTable_undefined;
4723 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4725 if (metaStateTable_size (gc.stateTable) > 0)
4727 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4728 /*@i32 should use smaller value... */
4730 metaStateTable_elements (gc.stateTable, msname, msi)
4732 /*@i23 only add global...*/
4733 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4734 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4736 valueTable_insert (res,
4737 cstring_copy (metaStateInfo_getName (msi)),
4738 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4739 stateInfo_copy (sinfo)));
4741 end_metaStateTable_elements ;
4743 stateInfo_free (sinfo);
4744 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4749 stateInfo_free (sinfo);
4750 return valueTable_undefined;