2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
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 "lclintMacros.nf"
38 # include "mtincludes.h"
41 # include "usymtab_interface.h"
44 # include "exprChecks.h"
45 # include "filelocStack.h"
46 # include "fileIdList.h"
52 extern /*@external@*/ int yydebug;
53 extern /*@external@*/ int mtdebug;
65 CX_FUNCTION, CX_FCNDECLARATION,
66 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
67 CX_ITERDEF, CX_ITEREND,
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. */
142 bool flags[NUMFLAGS];
143 bool saveflags[NUMFLAGS];
144 bool setGlobally[NUMFLAGS];
145 bool setLocally[NUMFLAGS];
147 int values[NUMVALUEFLAGS];
148 int counters[NUMVALUEFLAGS];
150 o_cstring strings[NUMSTRINGFLAGS];
151 sRefSetList modrecs; /*@i32 ???? what is this for? */
153 metaStateTable stateTable; /* User-defined state information. */
154 annotationTable annotTable; /* User-defined annotations table. */
159 /*@dependent@*/ /*@exposed@*/ uentry fcn;
163 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
164 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
165 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
166 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
168 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
169 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
170 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
171 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
172 static void context_setFlag (flagcode p_f, bool p_b)
173 /*@modifies gc.flags@*/ ;
176 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, bool p_isRestore)
177 /*@modifies gc.flags@*/ ;
179 static void context_restoreFlag (flagcode p_f) /*@modifies gc.flags@*/ ;
183 cstring context_unparseFlagMarkers ()
185 return (flagMarkerList_unparse (gc.markers));
188 void context_setPreprocessing (void)
190 llassert (!gc.preprocessing);
191 gc.preprocessing = TRUE;
194 void context_clearPreprocessing (void)
196 llassert (gc.preprocessing);
197 gc.preprocessing = FALSE;
200 bool context_isPreprocessing (void)
202 return gc.preprocessing;
205 bool context_loadingLibrary (void)
207 return (fileloc_isLib (g_currentloc));
210 bool context_inXHFile (void)
212 return (fileloc_isXHFile (g_currentloc));
215 void context_setInCommandLine (void)
217 llassert (!gc.incommandline);
218 gc.incommandline = TRUE;
221 void context_clearInCommandLine (void)
223 llassert (gc.incommandline);
224 gc.incommandline = FALSE;
227 bool context_isInCommandLine (void)
229 return gc.incommandline;
233 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
236 clauseStack_push (gc.clauses, c);
238 if (clause_isConditional (c)
239 && context_getFlag (FLG_CONTROLNESTDEPTH))
241 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
242 int depth = clauseStack_controlDepth (gc.clauses);
244 if (depth == maxdepth + 1)
247 (FLG_CONTROLNESTDEPTH,
248 message ("Maximum control nesting depth "
257 clause topClause (clauseStack s) /*@*/
259 if (clauseStack_isEmpty (s)) return NOCLAUSE;
260 return ((clause) clauseStack_top (s));
264 context_addMacroCache (/*@only@*/ cstring def)
266 DPRINTF (("macro cache: %s", def));
267 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
271 context_addComment (/*@only@*/ cstring def)
273 DPRINTF (("macro comment: %s", def));
274 macrocache_addComment (gc.mc, fileloc_copy (g_currentloc), def);
278 ** returns TRUE is fl is in ignore region, or region where -code
280 ** the logic is fuzzy...
284 context_inSuppressFlagZone (fileloc fl, flagcode code)
286 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
289 if (ynm_isMaybe (ret))
297 res = !gc.saveflags[code];
301 res = !context_getFlag (code);
306 res = ynm_toBoolStrict (ret);
313 context_suppressSystemMsg (fileloc fl)
315 if (context_getFlag (FLG_SYSTEMDIRERRORS))
321 return (fileloc_isSystemFile (fl));
326 context_suppressFlagMsg (flagcode flag, fileloc fl)
328 if (context_suppressSystemMsg (fl))
333 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
335 /* want same object compare here */
337 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
339 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
341 return (!context_getFlag (flag)
342 || context_inSuppressRegion ()
343 || context_inSuppressZone (fl)
344 || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
348 return (context_inSuppressFlagZone (fl, flag));
353 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
356 if (context_suppressSystemMsg (fl))
362 if (fl == g_currentloc)
363 /*@noaccess fileloc@*/
365 return (context_getFlag (flag) || context_inSuppressRegion ());
370 return (context_getFlag (flag) || context_inSuppressRegion ());
375 context_inSuppressZone (fileloc fl)
377 if (context_suppressSystemMsg (fl))
382 return (flagMarkerList_inIgnore (gc.markers, fl));
386 context_inSuppressRegion (void)
388 return (gc.insuppressregion);
392 context_enterSuppressRegion (void)
394 if (gc.insuppressregion)
396 gc.insuppressregion = FALSE; /* get this msg! */
398 ("%q: New ignore errors region entered while in ignore errors region",
399 fileloc_unparse (g_currentloc)));
402 gc.insuppressregion = TRUE;
403 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (g_currentloc));
407 context_addFlagMarker (flagcode code, ynm set)
409 flagMarkerList_add (gc.markers,
410 flagMarker_createLocalSet (code, set, g_currentloc));
414 context_enterSuppressLine (int count)
416 fileloc nextline = fileloc_copy (g_currentloc);
418 flagMarkerList_add (gc.markers,
419 flagMarker_createIgnoreCount (count, g_currentloc));
421 fileloc_nextLine (nextline);
422 flagMarkerList_add (gc.markers,
423 flagMarker_createIgnoreOff (nextline));
424 fileloc_free (nextline);
427 void context_checkSuppressCounts (void)
429 if (context_getFlag (FLG_SUPCOUNTS))
431 flagMarkerList_checkSuppressCounts (gc.markers);
435 void context_incLineno (void)
442 context_exitSuppressRegion (void)
444 if (!gc.insuppressregion)
446 llerrorlit (FLG_SYNTAX,
447 "End ignore errors in region while not ignoring errors");
450 gc.insuppressregion = FALSE;
451 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (g_currentloc));
455 context_enterMTfile (void)
461 context_exitMTfile (void)
463 llassert (gc.kind == CX_MT);
469 context_enterLCLfile (void)
472 gc.facct = typeIdSet_emptySet ();
477 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
481 for (i = 0; i < gc.nmods; i++)
483 if (cstring_equal (gc.moduleaccess[i].file, fname))
485 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
486 cstring_free (fname);
491 if (gc.nmods == gc.maxmods)
495 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
496 oldmods = gc.moduleaccess;
498 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
500 for (i = 0; i < gc.nmods; i++)
502 gc.moduleaccess[i] = oldmods[i];
508 gc.moduleaccess[gc.nmods].file = fname;
509 gc.moduleaccess[gc.nmods].daccess = mods;
515 insertModuleAccess (cstring fname, typeId t)
519 for (i = 0; i < gc.nmods; i++)
521 if (cstring_equal (gc.moduleaccess[i].file, fname))
523 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
528 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
533 context_exitLCLfile (void)
535 if (gc.kind != CX_LCLLIB)
538 fileLib_withoutExtension (fileName (currentFile ()), LCL_EXTENSION);
540 addModuleAccess (fileLib_removePath (lclname), gc.facct);
541 cstring_free (lclname);
546 gc.facct = typeIdSet_emptySet ();
551 context_dumpModuleAccess (FILE *fout)
555 for (i = 0; i < gc.nmods; i++)
557 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
559 fprintf (fout, "%s#%s@\n",
560 cstring_toCharsSafe (gc.moduleaccess[i].file),
561 cstring_toCharsSafe (td));
567 bool context_usingPosixLibrary ()
569 return (gc.library == FLG_POSIXLIB
570 || gc.library == FLG_POSIXSTRICTLIB
571 || gc.library == FLG_UNIXLIB
572 || gc.library == FLG_UNIXSTRICTLIB);
575 bool context_usingAnsiLibrary ()
577 return (gc.library != FLG_NOLIB);
580 flagcode context_getLibrary ()
585 void context_setLibrary (flagcode code)
590 /*@observer@*/ cstring context_selectedLibrary ()
595 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
597 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
598 case FLG_POSIXSTRICTLIB:
599 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
601 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
602 case FLG_UNIXSTRICTLIB:
603 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
605 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
612 context_loadModuleAccess (FILE *in)
614 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
616 char *name = mstring_create (MAX_NAME_LENGTH);
622 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
628 while (s != NULL && *s != ';' && *s != '\0')
632 while (*s != '#' && *s != '\0')
641 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
642 cstring_fromChars (s)));
648 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
649 typeIdSet_undump (&s));
651 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
652 llassert (s != lasts);
662 typeIdSet context_fileAccessTypes (void)
668 context_resetModeFlags (void)
673 if (flagcode_isModeFlag (code))
675 context_setFlag (code, FALSE);
684 ** Set all flags to FALSE, except for a few which are
687 ** Set all values and strings to appropriate defaults.
688 ** Set all counters to 0.
692 conext_resetAllCounters (void)
696 for (i = 0; i < NUMVALUEFLAGS; i++)
703 context_resetAllFlags (void)
707 gc.flags[code] = FALSE;
709 if (flagcode_hasValue (code))
713 /*@-loopswitchbreak@*/
717 val = DEFAULT_LIMIT; break;
719 val = DEFAULT_BUGSLIMIT; break;
721 val = DEFAULT_LINELEN; break;
722 case FLG_INDENTSPACES:
723 val = DEFAULT_INDENTSPACES; break;
724 case FLG_EXTERNALNAMELEN:
725 val = DEFAULT_EXTERNALNAMELEN; break;
726 case FLG_INTERNALNAMELEN:
727 val = DEFAULT_INTERNALNAMELEN; break;
728 case FLG_COMMENTCHAR:
729 val = (int) DEFAULT_COMMENTCHAR; break;
730 case FLG_CONTROLNESTDEPTH:
731 val = (int) DEFAULT_CONTROLNESTDEPTH; break;
732 case FLG_STRINGLITERALLEN:
733 val = (int) DEFAULT_STRINGLITERALLEN; break;
734 case FLG_INCLUDENEST:
735 val = (int) DEFAULT_INCLUDENEST; break;
736 case FLG_NUMSTRUCTFIELDS:
737 val = (int) DEFAULT_NUMSTRUCTFIELDS; break;
738 case FLG_NUMENUMMEMBERS:
739 val = (int) DEFAULT_NUMENUMMEMBERS; break;
744 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
746 /*@=loopswitchbreak@*/
748 context_setValue (code, val);
750 else if (flagcode_hasString (code))
752 cstring val = cstring_undefined;
755 { /*@-loopswitchbreak@*/
758 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
760 if (cstring_isDefined (larchpath))
762 val = cstring_copy (larchpath);
766 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
771 case FLG_LCLIMPORTDIR:
773 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
777 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
779 char *env = osd_getEnvironmentVariable ("TMP");
783 env = osd_getEnvironmentVariable ("TEMP");
786 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
789 val = cstring_makeLiteral (DEFAULT_TMPDIR);
790 # endif /* !defined(OS2) && !defined(MSDOS) */
794 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
796 val = cstring_makeLiteral ("FALSE"); break;
798 val = cstring_makeLiteral ("TRUE"); break;
799 case FLG_MACROVARPREFIX:
800 val = cstring_makeLiteral ("m_"); break;
802 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
805 } /*@=loopswitchbreak@*/
807 context_setString (code, val);
811 ; /* nothing to set */
816 ** These flags are true by default.
819 /*@i34 move this into flags.def */
821 gc.flags[FLG_MODIFIES] = TRUE;
822 gc.flags[FLG_NESTCOMMENT] = TRUE;
823 gc.flags[FLG_GLOBALS] = TRUE;
824 gc.flags[FLG_FULLINITBLOCK] = TRUE;
825 gc.flags[FLG_LIKELYBOOL] = TRUE;
826 gc.flags[FLG_ZEROPTR] = TRUE;
827 gc.flags[FLG_NUMLITERAL] = TRUE;
828 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
829 gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
830 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
831 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
832 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
833 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
834 gc.flags[FLG_CASTFCNPTR] = TRUE;
835 gc.flags[FLG_DOLCS] = TRUE;
836 gc.flags[FLG_USEVARARGS] = TRUE;
837 gc.flags[FLG_MAINTYPE] = TRUE;
838 gc.flags[FLG_SPECMACROS] = TRUE;
839 gc.flags[FLG_REDEF] = TRUE;
840 gc.flags[FLG_MACRONEXTLINE] = TRUE;
842 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
843 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
845 gc.flags[FLG_WARNUSE] = TRUE;
846 gc.flags[FLG_PREDASSIGN] = TRUE;
847 gc.flags[FLG_MODOBSERVER] = TRUE;
848 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
849 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
851 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
852 gc.flags[FLG_RETIMPONLY] = TRUE;
853 gc.flags[FLG_GLOBIMPONLY] = TRUE;
854 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
855 gc.flags[FLG_PREPROC] = TRUE;
856 gc.flags[FLG_NAMECHECKS] = TRUE;
857 gc.flags[FLG_FORMATCODE] = TRUE;
858 gc.flags[FLG_FORMATTYPE] = TRUE;
859 gc.flags[FLG_BADFLAG] = TRUE;
860 gc.flags[FLG_WARNFLAGS] = TRUE;
861 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
862 gc.flags[FLG_WARNUNIXLIB] = TRUE;
863 gc.flags[FLG_WARNPOSIX] = TRUE;
864 gc.flags[FLG_SHOWCOL] = TRUE;
865 gc.flags[FLG_SHOWFUNC] = TRUE;
866 gc.flags[FLG_SUPCOUNTS] = TRUE;
867 gc.flags[FLG_HINTS] = TRUE;
868 gc.flags[FLG_SYNTAX] = TRUE;
869 gc.flags[FLG_TYPE] = TRUE;
870 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
871 gc.flags[FLG_ABSTRACT] = TRUE;
872 gc.flags[FLG_ITER] = TRUE;
873 gc.flags[FLG_CONTROL] = TRUE;
874 gc.flags[FLG_UNRECOG] = TRUE;
875 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
876 gc.flags[FLG_LINTCOMMENTS] = TRUE;
877 gc.flags[FLG_ACCESSCZECH] = TRUE;
878 gc.flags[FLG_ACCESSMODULE] = TRUE;
879 gc.flags[FLG_ACCESSFILE] = TRUE;
880 gc.flags[FLG_MACROVARPREFIX] = TRUE;
882 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
883 gc.flags[FLG_COMMENTERROR] = TRUE;
886 ** Changed for version 2.4.
889 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
892 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
896 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
901 ** C is way-lame, and you can initialize an array to a constant except where
902 ** it is declared. Hence, a macro is used to set the modeflags.
906 # define SETFLAGS() \
907 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
908 if (!flagcode_isModeFlag (modeflags[i])) \
909 { llbug (message ("not a mode flag: %s", \
910 flagcode_unparse (modeflags[i]))); } \
911 else { context_setFlag (modeflags[i], TRUE); } i++; }}
914 context_setMode (cstring s)
916 intSet setflags = intSet_new ();
920 if (flagcode_isModeFlag (code))
922 if (gc.setGlobally[code])
924 (void) intSet_insert (setflags, (int) code);
929 if (!intSet_isEmpty (setflags))
931 cstring rflags = cstring_undefined;
934 intSet_elements (setflags, el)
936 if (cstring_isUndefined (rflags))
938 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
942 rflags = message ("%q, %s", rflags,
943 flagcode_unparse ((flagcode) el));
947 if (num > 4 && intSet_size (setflags) > 6)
949 rflags = message ("%q, (%d others) ...", rflags,
950 intSet_size (setflags) - num);
953 } end_intSet_elements ;
955 voptgenerror (FLG_WARNFLAGS,
956 message ("Setting mode %s after setting mode flags will "
957 "override set values of flags: %s",
961 cstring_free (rflags);
964 intSet_free (setflags);
966 context_resetModeFlags ();
968 if (cstring_equalLit (s, "standard"))
970 flagcode modeflags[] =
972 FLG_ENUMINT, FLG_MACROMATCHNAME,
973 FLG_MACROUNDEF, FLG_RELAXQUALS,
974 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
975 FLG_CHECKSTRICTGLOBALIAS,
976 FLG_CHECKEDGLOBALIAS,
977 FLG_CHECKMODGLOBALIAS,
978 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
979 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
981 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
982 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_MUTREP,
983 FLG_NOEFFECT, FLG_IMPTYPE,
984 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
985 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
988 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
989 FLG_MACROSTMT, FLG_MACROPARENS,
992 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
993 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
998 /* memchecks flags */
1000 FLG_NULLSTATE, FLG_NULLASSIGN,
1001 FLG_NULLPASS, FLG_NULLRET,
1003 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1006 /* memtrans flags */
1025 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1026 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1027 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1030 FLG_STATETRANSFER, FLG_STATEMERGE,
1031 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1033 FLG_IMPCHECKEDSPECGLOBALS,
1034 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1035 FLG_IFEMPTY, FLG_REALCOMPARE,
1036 FLG_BOOLOPS, FLG_PTRNEGATE,
1038 FLG_BUFFEROVERFLOWHIGH,
1045 else if (cstring_equalLit (s, "weak"))
1047 flagcode modeflags[] =
1049 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1050 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1051 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1052 FLG_CHARUNSIGNEDCHAR,
1054 FLG_VARUNUSED, FLG_FUNCUNUSED,
1056 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1059 FLG_RETSTACK, FLG_PTRNEGATE,
1060 FLG_STATETRANSFER, FLG_STATEMERGE,
1061 FLG_LONGUNSIGNEDINTEGRAL,
1062 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1066 FLG_BUFFEROVERFLOWHIGH,
1072 else if (cstring_equalLit (s, "checks"))
1074 flagcode modeflags[] =
1076 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1077 FLG_STATETRANSFER, FLG_STATEMERGE,
1078 FLG_CHECKSTRICTGLOBALIAS,
1079 FLG_CHECKEDGLOBALIAS,
1080 FLG_CHECKMODGLOBALIAS,
1081 FLG_UNCHECKEDGLOBALIAS,
1083 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1084 FLG_BOOLCOMPARE, FLG_MACROUNDEF,
1085 FLG_MUSTMOD, FLG_ALLGLOBALS,
1086 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1087 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1088 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1089 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1090 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1091 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1092 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1093 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1094 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1095 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1096 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1103 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1107 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1109 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1110 FLG_EVALORDER, FLG_USEDEF,
1114 /* memchecks flags */
1116 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1117 FLG_NULLPASS, FLG_NULLRET,
1119 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1121 /* memtrans flags */
1135 FLG_STATICINITTRANS,
1136 FLG_UNKNOWNINITTRANS,
1139 FLG_ONLYUNQGLOBALTRANS,
1140 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1141 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1142 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1145 FLG_NULLPOINTERARITH,
1146 FLG_SHADOW, FLG_DEPARRAYS,
1147 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1148 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1149 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1150 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1151 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1152 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1153 FLG_BOOLOPS, FLG_SHIFTSIGNED,
1154 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1159 else if (cstring_equalLit (s, "strict"))
1161 flagcode modeflags[] =
1163 FLG_CHECKSTRICTGLOBALIAS,
1164 FLG_CHECKEDGLOBALIAS,
1165 FLG_CHECKMODGLOBALIAS,
1166 FLG_UNCHECKEDGLOBALIAS,
1170 FLG_STATETRANSFER, FLG_STATEMERGE,
1171 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1172 FLG_ALLGLOBALS, FLG_IMPTYPE,
1173 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1174 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1175 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1176 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1179 FLG_ONLYUNQGLOBALTRANS,
1180 FLG_GLOBALSIMPMODIFIESNOTHING,
1181 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1182 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1183 FLG_USEALLGLOBS, FLG_RETALIAS,
1184 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1185 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1186 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1188 FLG_EXPORTITER, FLG_EXPORTCONST,
1189 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1190 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1192 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1194 FLG_BOOLCOMPARE, FLG_NOEFFECT,
1195 FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1196 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1197 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1198 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1199 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1200 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1201 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1203 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1206 FLG_MACROREDEF, FLG_MACROEMPTY,
1207 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1209 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1211 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1212 FLG_MODOBSERVERUNCON,
1217 /* memchecks flags */
1218 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1219 FLG_NULLPASS, FLG_NULLRET,
1221 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1223 /* memtrans flags */
1239 FLG_STATICINITTRANS,
1240 FLG_UNKNOWNINITTRANS,
1242 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1243 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1244 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1248 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1250 FLG_SHADOW, FLG_DEPARRAYS,
1251 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1252 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1253 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1254 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1255 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1256 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1257 FLG_IMPCHECKEDSTRICTSTATICS,
1258 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1259 FLG_IMPCHECKMODINTERNALS,
1260 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1261 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1262 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1263 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1264 FLG_CONTROLNESTDEPTH,
1265 FLG_FORBLOCK, FLG_WHILEBLOCK,
1266 FLG_FOREMPTY, FLG_WHILEEMPTY,
1267 FLG_IFEMPTY, FLG_IFBLOCK,
1269 FLG_REALCOMPARE, FLG_BOOLOPS,
1270 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1272 FLG_SHIFTSIGNED, FLG_BITWISEOPS,
1273 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1281 llcontbug (message ("context_setMode: bad mode: %s", s));
1286 context_isSpecialFile (cstring fname)
1288 cstring ext = fileLib_getExtension (fname);
1290 return (cstring_equalLit (ext, ".y")
1291 || cstring_equalLit (ext, ".l")
1292 || cstring_equalLit (fname, "lex.yy.c"));
1296 context_isSystemDir (cstring dir)
1298 cstring sysDirs = context_exposeString (FLG_SYSTEMDIRS);
1299 char *thisdir = cstring_toCharsSafe (sysDirs);
1300 char *nextdir = strchr (thisdir, SEPCHAR);
1302 if (nextdir != NULL)
1308 while (thisdir != NULL)
1310 DPRINTF (("Test: %s / %s", dir, thisdir));
1312 if (cstring_equalCanonicalPrefix (dir, thisdir))
1314 if (nextdir != NULL)
1316 *(nextdir - 1) = SEPCHAR;
1322 if (nextdir != NULL)
1324 *(nextdir - 1) = SEPCHAR;
1327 if (nextdir != NULL)
1330 nextdir = strchr (thisdir, SEPCHAR);
1332 if (nextdir != NULL)
1344 DPRINTF (("Returns FALSE"));
1349 context_addFileAccessType (typeId t)
1353 if (context_inFunctionLike ())
1355 gc.acct = typeIdSet_insert (gc.acct, t);
1358 gc.facct = typeIdSet_insert (gc.facct, t);
1360 base = fileloc_getBase (g_currentloc);
1361 insertModuleAccess (base, t);
1362 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1363 typeIdSet_unparse (gc.acct)));
1367 context_removeFileAccessType (typeId t)
1369 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1370 || gc.kind == CX_UNKNOWNMACRO)
1372 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1375 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1376 gc.nacct = typeIdSet_insert (gc.nacct, t);
1379 void context_enterFunctionHeader (void)
1381 if (gc.kind != CX_GLOBAL)
1383 llparseerror (cstring_makeLiteral
1384 ("Likely parse error. Function header outside global context."));
1388 llassert (gc.kind == CX_GLOBAL);
1389 DPRINTF (("Enter function header!"));
1390 gc.inFunctionHeader = TRUE;
1394 void context_exitFunctionHeader (void)
1396 DPRINTF (("Exit function header!"));
1397 gc.inFunctionHeader = FALSE;
1400 bool context_inFunctionHeader (void)
1402 return (gc.inFunctionHeader);
1405 void context_enterFunctionDeclaration (uentry e)
1407 DPRINTF (("Enter function decl"));
1408 llassert (gc.savekind == CX_ERROR);
1409 gc.savekind = gc.kind;
1410 gc.kind = CX_FCNDECLARATION;
1414 void context_exitFunctionDeclaration (void)
1416 DPRINTF (("Exit function decl"));
1417 llassert (gc.savekind != CX_ERROR);
1418 llassert (gc.kind == CX_FCNDECLARATION);
1419 gc.kind = gc.savekind;
1420 gc.cont.fcn = uentry_undefined;
1421 gc.savekind = CX_ERROR;
1424 bool context_inFunctionDeclaration (void)
1426 return (gc.kind == CX_FCNDECLARATION);
1431 context_enterMacro (/*@observer@*/ uentry e)
1433 context_enterFunction (e);
1434 gc.kind = CX_MACROFCN;
1438 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1440 llassert (uentry_isFunction (e));
1441 context_enterFunction (e);
1442 gc.kind = CX_UNKNOWNMACRO;
1445 void context_enterAndClause (exprNode e)
1448 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1449 pushClause (ANDCLAUSE);
1452 void context_enterOrClause (exprNode e)
1454 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1455 pushClause (ORCLAUSE);
1458 bool context_inDeepLoop (void)
1460 bool inLoop = FALSE;
1462 clauseStack_elements (gc.clauses, el)
1464 if (clause_isLoop (el))
1473 } end_clauseStack_elements;
1478 bool context_inDeepSwitch (void)
1480 bool inLoop = FALSE;
1482 clauseStack_elements (gc.clauses, el)
1484 if (clause_isSwitch (el))
1493 } end_clauseStack_elements;
1498 bool context_inDeepLoopSwitch (void)
1500 bool inLoop = FALSE;
1502 clauseStack_elements (gc.clauses, el)
1504 if (clause_isBreakable (el))
1513 } end_clauseStack_elements;
1518 clause context_breakClause (void)
1520 clauseStack_elements (gc.clauses, el)
1522 if (clause_isSwitch (el))
1526 else if (clause_isLoop (el))
1534 } end_clauseStack_elements;
1539 clause context_nextBreakClause (void)
1541 bool hasOne = FALSE;
1543 clauseStack_elements (gc.clauses, el)
1545 if (clause_isBreakable (el))
1556 } end_clauseStack_elements;
1561 bool context_inConditional (void)
1563 clauseStack_elements (gc.clauses, el)
1566 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1567 ** to distinguish if from ? for this
1570 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1574 } end_clauseStack_elements;
1579 void context_exitAndClause (exprNode pred, exprNode tbranch)
1581 context_setJustPopped ();
1583 llassert (gc.inclause == ANDCLAUSE);
1585 usymtab_popAndBranch (pred, tbranch);
1586 clauseStack_pop (gc.clauses);
1587 gc.inclause = topClause (gc.clauses);
1590 void context_exitOrClause (exprNode pred, exprNode tbranch)
1592 context_setJustPopped ();
1594 llassert (gc.inclause == ORCLAUSE);
1596 usymtab_popOrBranch (pred, tbranch);
1597 clauseStack_pop (gc.clauses);
1598 gc.inclause = topClause (gc.clauses);
1601 static void context_enterCondClauseAux (clause cl)
1607 static void context_enterTrueAux (exprNode e, clause cl)
1610 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1614 void context_enterIterClause (void)
1616 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1619 void context_enterDoWhileClause (void)
1621 pushClause (DOWHILECLAUSE);
1624 void context_enterWhileClause (exprNode e)
1626 context_enterTrueAux (e, WHILECLAUSE);
1629 void context_enterForClause (exprNode e)
1631 context_enterTrueAux (e, FORCLAUSE);
1634 void context_enterTrueClause (exprNode e)
1636 context_enterTrueAux (e, TRUECLAUSE);
1639 void context_enterSwitch (exprNode e)
1642 usymtab_switchBranch (e);
1643 context_enterCondClauseAux (SWITCHCLAUSE);
1646 void context_exitSwitch (exprNode e, bool allpaths)
1648 usymtab_exitSwitch (e, allpaths);
1650 while (clause_isCase (clauseStack_top (gc.clauses)))
1652 clauseStack_pop (gc.clauses);
1655 context_exitClauseSimp ();
1658 void context_enterCaseClause (exprNode e)
1660 bool branch = FALSE;
1662 DPRINTF (("Enter case clause!"));
1664 branch = usymtab_newCase (exprNode_undefined, e);
1668 context_enterCondClauseAux (CASECLAUSE);
1672 static void context_enterFalseClauseAux (exprNode e, clause cl)
1675 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1677 clauseStack_switchTop (gc.clauses, cl);
1680 void context_enterFalseClause (exprNode e)
1683 context_enterFalseClauseAux (e, FALSECLAUSE);
1687 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1689 gc.kind = CX_MACROCONST;
1691 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1693 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1697 usymtab_enterScope ();
1698 sRef_enterFunctionScope ();
1700 gc.globs = globSet_undefined;
1701 globSet_clear (gc.globs_used);
1702 gc.mods = sRefSet_undefined;
1705 uentry context_getHeader (void)
1707 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1709 llfatalbug (message ("context_getHeader: bad call: %q",
1710 context_unparse ()));
1713 return (gc.cont.fcn);
1717 context_setFunctionDefined (fileloc loc)
1721 case CX_UNKNOWNMACRO:
1724 uentry_setFunctionDefined (gc.cont.fcn, loc);
1727 /* (not a bug because of parse errors) */
1733 context_enterFunction (/*@exposed@*/ uentry e)
1735 gc.kind = CX_FUNCTION;
1738 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1740 if (uentry_hasAccessType (e))
1742 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1750 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1751 typeIdSet_unparse (gc.acct)));
1753 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1755 gc.globs = uentry_getGlobs (e);
1756 globSet_clear (gc.globs_used);
1757 gc.mods = uentry_getMods (e);
1759 usymtab_enterFunctionScope (e);
1760 sRef_enterFunctionScope ();
1763 static bool context_checkStrictGlobals (void)
1765 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1768 static bool context_hasGlobs (void)
1770 if (context_inFunctionLike ())
1772 return (uentry_hasGlobs (gc.cont.fcn));
1780 static bool context_checkCheckedGlobals (void)
1782 return (context_getFlag (FLG_GLOBALS)
1783 && (context_getFlag (FLG_GLOBUNSPEC)
1784 || context_hasGlobs ()));
1787 static bool context_checkUnknownGlobals (void)
1789 /* should be uentry_hasGlobs ? */
1791 return (context_getFlag (FLG_ALLGLOBALS)
1792 && (context_getFlag (FLG_GLOBUNSPEC)
1793 || context_hasGlobs ()));
1796 static bool context_checkUncheckedGlobals (void)
1802 context_checkExport (uentry e)
1804 if (!gc.anyExports) return FALSE;
1806 if (uentry_isFunction (e)
1807 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1809 return context_maybeSet (FLG_EXPORTFCN);
1811 else if (uentry_isExpandedMacro (e))
1813 return context_maybeSet (FLG_EXPORTMACRO);
1815 else if (uentry_isVariable (e))
1817 return context_maybeSet (FLG_EXPORTVAR);
1819 else if (uentry_isEitherConstant (e))
1821 return context_maybeSet (FLG_EXPORTCONST);
1823 else if (uentry_isIter (e) || uentry_isEndIter (e))
1825 return context_maybeSet (FLG_EXPORTITER);
1827 else if (uentry_isDatatype (e))
1829 return context_maybeSet (FLG_EXPORTTYPE);
1838 context_checkGlobUse (uentry glob)
1841 if (uentry_isCheckedStrict (glob))
1843 return context_checkStrictGlobals ();
1845 else if (uentry_isChecked (glob))
1847 return context_checkCheckedGlobals ();
1849 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
1851 return context_checkUnknownGlobals ();
1855 llassert (uentry_isUnchecked (glob));
1857 return context_checkUncheckedGlobals ();
1862 context_checkAliasGlob (uentry glob)
1864 if (uentry_isCheckedStrict (glob))
1866 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
1868 else if (uentry_isChecked (glob))
1870 return gc.flags[FLG_CHECKEDGLOBALIAS];
1872 else if (uentry_isCheckMod (glob))
1874 return gc.flags[FLG_CHECKMODGLOBALIAS];
1878 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
1880 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
1884 bool context_checkInternalUse (void)
1886 if (context_hasGlobs ())
1888 return (gc.flags[FLG_INTERNALGLOBS]);
1892 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
1897 context_checkGlobMod (sRef el)
1899 uentry ue = sRef_getUentry (el);
1901 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
1903 if (uentry_isCheckedModify (ue)
1904 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
1906 if (context_hasMods ())
1908 return (gc.flags[FLG_MODGLOBS]);
1912 if (uentry_isCheckedStrict (ue))
1914 return (gc.flags[FLG_MODGLOBSUNSPEC]);
1918 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
1924 if (context_hasMods ())
1926 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
1936 context_usedGlobal (/*@exposed@*/ sRef el)
1938 if (!globSet_member (gc.globs_used, el))
1941 ** The first time a global is used in a function, we need
1942 ** to clear the derived sRefs, since they were set for the
1943 ** previous function.
1946 sRef_clearDerived (el);
1947 gc.globs_used = globSet_insert (gc.globs_used, el);
1951 /*@observer@*/ sRefSet
1952 context_modList (void)
1958 context_globAccess (sRef s)
1960 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
1961 return (globSet_member (gc.globs, s));
1965 context_hasAccess (typeId t)
1967 if (context_inFunctionLike ())
1969 DPRINTF (("Access %d / %s",
1970 t, typeIdSet_unparse (gc.acct)));
1971 return (typeIdSet_member (gc.acct, t));
1975 return (context_hasFileAccess (t));
1980 context_hasFileAccess (typeId t)
1982 return (typeIdSet_member (gc.facct, t));
1986 context_unparseAccess (void)
1988 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
1989 typeIdSet_unparse (gc.facct)));
1993 context_unparseClauses (void)
1995 return (clauseStack_unparse (gc.clauses));
1999 context_couldHaveAccess (typeId t)
2001 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2003 return (typeIdSet_member (gc.acct, t));
2007 return (typeIdSet_member (gc.facct, t));
2012 context_getRetType (void)
2014 ctype f = ctype_undefined;
2016 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2018 f = uentry_getType (gc.cont.fcn);
2020 else if (gc.kind == CX_UNKNOWNMACRO)
2022 return ctype_unknown;
2026 llcontbuglit ("context_getRetType: not in a function context");
2027 return ctype_unknown;
2030 if (!ctype_isFunction (f))
2032 if (ctype_isKnown (f))
2034 llbuglit ("context_getRetType: not a function");
2037 return ctype_unknown;
2039 return (ctype_getReturnType (f));
2043 context_hasMods (void)
2045 if (context_inFunctionLike ())
2047 return (uentry_hasMods (gc.cont.fcn));
2056 context_exitAllClauses (void)
2058 while (!clauseStack_isEmpty (gc.clauses))
2060 clause el = clauseStack_top (gc.clauses);
2063 if (clause_isNone (el))
2065 usymtab_quietExitScope (g_currentloc);
2066 clauseStack_pop (gc.clauses);
2070 context_exitClausePlain ();
2074 clauseStack_clear (gc.clauses);
2075 gc.inclause = NOCLAUSE;
2079 context_exitAllClausesQuiet (void)
2081 while (!clauseStack_isEmpty (gc.clauses))
2083 clause el = clauseStack_top (gc.clauses);
2086 usymtab_quietExitScope (g_currentloc);
2087 clauseStack_pop (gc.clauses);
2090 clauseStack_clear (gc.clauses);
2091 gc.inclause = NOCLAUSE;
2095 void context_exitClauseSimp (void)
2098 context_setJustPopped ();
2099 clauseStack_pop (gc.clauses);
2100 gc.inclause = topClause (gc.clauses);
2104 void context_exitCaseClause (void)
2106 context_setJustPopped ();
2107 usymtab_popCaseBranch ();
2108 clauseStack_pop (gc.clauses);
2109 gc.inclause = topClause (gc.clauses);
2113 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2115 context_setJustPopped ();
2116 /*@i32 was makeAlt */
2117 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2118 clauseStack_pop (gc.clauses);
2119 gc.inclause = topClause (gc.clauses);
2122 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2124 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2126 if (gc.inclause != TRUECLAUSE)
2128 llparseerror (cstring_makeLiteral
2129 ("Likely parse error. Conditional clauses are inconsistent."));
2133 context_setJustPopped ();
2134 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2135 clauseStack_pop (gc.clauses);
2136 gc.inclause = topClause (gc.clauses);
2139 void context_exitIterClause (exprNode body)
2141 llassert (gc.inclause == ITERCLAUSE);
2143 context_setJustPopped ();
2145 if (context_getFlag (FLG_LOOPEXEC))
2147 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2151 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2154 clauseStack_pop (gc.clauses);
2155 gc.inclause = topClause (gc.clauses);
2158 static void context_popCase (void) {
2160 ** If we are exiting an outer clause, sometimes still in a switch case.
2174 DPRINTF (("Popping case clause: %s",
2175 clauseStack_unparse (gc.clauses)));
2177 if (gc.inclause == CASECLAUSE) {
2178 context_exitCaseClause ();
2182 void context_exitWhileClause (exprNode pred, exprNode body)
2184 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2188 if (gc.inclause != WHILECLAUSE) {
2189 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2190 clauseStack_unparse (gc.clauses)));
2193 llassert (gc.inclause == WHILECLAUSE);
2195 context_setJustPopped ();
2199 ** predicate must be false after while loop (unless there are breaks)
2202 if (context_getFlag (FLG_LOOPEXEC))
2204 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2208 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2212 usymtab_addGuards (invGuards);
2213 guardSet_free (invGuards);
2215 clauseStack_pop (gc.clauses);
2216 gc.inclause = topClause (gc.clauses);
2219 void context_exitDoWhileClause (exprNode pred)
2221 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2223 if (gc.inclause == CASECLAUSE) {
2224 /* handle Duff's device */
2225 clauseStack_pop (gc.clauses);
2226 gc.inclause = topClause (gc.clauses);
2229 llassert (gc.inclause == DOWHILECLAUSE);
2231 context_setJustPopped ();
2234 usymtab_addGuards (invGuards);
2235 guardSet_free (invGuards);
2237 clauseStack_pop (gc.clauses);
2238 gc.inclause = topClause (gc.clauses);
2241 void context_exitForClause (exprNode forPred, exprNode body)
2243 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2245 llassert (gc.inclause == FORCLAUSE);
2246 context_setJustPopped ();
2249 ** predicate must be false after while loop (unless there are breaks)
2252 if (context_getFlag (FLG_LOOPEXEC))
2254 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2258 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2261 usymtab_addGuards (invGuards);
2262 guardSet_free (invGuards);
2263 clauseStack_pop (gc.clauses);
2264 gc.inclause = topClause (gc.clauses);
2267 static void context_exitClausePlain (void)
2269 llassert (gc.inclause != NOCLAUSE);
2271 if (gc.inclause == FALSECLAUSE)
2273 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2277 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2281 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2283 context_setJustPopped ();
2285 if (gc.inclause == FALSECLAUSE)
2287 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2289 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2291 clauseStack_pop (gc.clauses);
2292 gc.inclause = topClause (gc.clauses);
2296 context_exitTrueClause (pred, tbranch);
2301 context_returnFunction (void)
2303 usymtab_checkFinalScope (TRUE);
2307 context_exitFunction (void)
2309 if (!context_inFunction () && !context_inMacroConstant ()
2310 && !context_inMacroUnknown ()
2311 && !context_inIterDef () && !context_inIterEnd ())
2314 ** not a bug because of parse errors
2319 if (context_inMacro () && usymtab_inFunctionScope ())
2321 usymtab_exitScope (exprNode_undefined);
2324 if (uentry_hasGlobs (gc.cont.fcn))
2326 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2330 if (uentry_hasMods (gc.cont.fcn))
2332 if (context_getFlag (FLG_MUSTMOD))
2334 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2338 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2341 ** clear file static modifies
2344 /* do this first to get unused error messages */
2346 usymtab_exitScope (exprNode_undefined);
2347 sRef_exitFunctionScope ();
2349 gc.showfunction = FALSE;
2350 gc.kind = CX_GLOBAL;
2351 gc.cont.glob = TRUE;
2353 gc.globs = globSet_new ();
2354 globSet_clear (gc.globs_used);
2355 gc.mods = sRefSet_new ();
2358 llassert (clauseStack_isEmpty (gc.clauses));
2359 llassert (gc.inclause == NOCLAUSE);
2363 context_quietExitFunction (void)
2365 while (gc.kind == CX_INNER)
2367 context_exitInnerPlain ();
2370 if (!context_inFunction () && !context_inMacroConstant () && !context_inMacroUnknown ()
2371 && !context_inIterDef () && !context_inIterEnd ())
2376 usymtab_quietExitScope (g_currentloc);
2378 gc.showfunction = FALSE;
2379 gc.kind = CX_GLOBAL;
2380 gc.cont.glob = TRUE;
2382 gc.globs = globSet_new ();
2383 globSet_clear (gc.globs_used);
2384 gc.mods = sRefSet_new ();
2386 sRef_exitFunctionScope ();
2390 /*@observer@*/ uentryList
2391 context_getParams (void)
2393 if (context_inFunctionLike ())
2395 return (uentry_getParams (gc.cont.fcn));
2399 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2400 return uentryList_undefined;
2404 /*@observer@*/ globSet
2405 context_getUsedGlobs (void)
2407 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2408 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2410 return (gc.globs_used);
2414 context_moduleName ()
2416 return (fileloc_getBase (g_currentloc));
2419 /*@observer@*/ globSet
2420 context_getGlobs (void)
2422 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2423 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2429 context_addBoolAccess (void)
2431 cstring bname = context_getString (FLG_BOOLTYPE);
2432 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2434 addModuleAccess (cstring_copy (bname), boolt);
2436 /* for sys/types (perhaps, this is bogus!) */
2437 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2442 context_canAccessBool (void)
2449 static typeId boolType = typeId_invalid;
2451 if (typeId_isInvalid (boolType))
2453 boolType = usymtab_getTypeId (context_getBoolName ());
2456 if (typeId_isInvalid (boolType)) {
2459 return (typeIdSet_member (gc.acct, boolType));
2464 /* evs 2000-07-25: old version - replaced */
2467 context_boolImplementationType () {
2468 /* For now, this is bogus! */
2473 context_canAccessBool (void)
2475 static typeId boolType = typeId_invalid;
2477 if (typeId_isInvalid (boolType))
2479 boolType = usymtab_getTypeId (context_getBoolName ());
2482 if (!typeId_isInvalid (boolType))
2484 return context_hasAccess (boolType);
2495 context_setMessageAnnote (/*@only@*/ cstring s)
2497 llassert (cstring_isUndefined (gc.msgAnnote));
2502 context_hasMessageAnnote (void)
2504 return (cstring_isDefined (gc.msgAnnote));
2508 context_clearMessageAnnote (void)
2510 if (cstring_isDefined (gc.msgAnnote))
2512 cstring_free (gc.msgAnnote);
2513 gc.msgAnnote = cstring_undefined;
2518 context_getMessageAnnote (void)
2520 cstring st = gc.msgAnnote;
2522 gc.msgAnnote = cstring_undefined;
2527 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2529 llassert (sRef_isInvalid (gc.aliasAnnote));
2530 llassert (!sRef_sameName (s, t));
2532 gc.aliasAnnoteAls = t;
2536 context_hasAliasAnnote (void)
2538 return (sRef_isValid (gc.aliasAnnote));
2542 context_clearAliasAnnote (void)
2544 gc.aliasAnnote = sRef_undefined;
2548 context_getAliasAnnote (void)
2550 sRef ret = gc.aliasAnnote;
2551 sRef als = gc.aliasAnnoteAls;
2553 llassert (sRef_isValid (ret) && sRef_isValid (als));
2555 gc.aliasAnnote = sRef_undefined;
2556 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2560 context_recordFileModifies (sRefSet mods)
2562 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2566 context_recordFileGlobals (globSet mods)
2568 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2569 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2573 context_setCommentMarkerChar (char c)
2575 llassert (c != '\0');
2577 context_setValue (FLG_COMMENTCHAR, (int) c);
2581 context_getCommentMarkerChar (void)
2583 return ((char) context_getValue (FLG_COMMENTCHAR));
2587 context_setValue (flagcode flag, int val)
2589 int index = flagcode_valueIndex (flag);
2591 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2599 llerror_flagWarning (message ("Value for %s must be a positive "
2600 "number (given %d)",
2601 flagcode_unparse (flag), val));
2604 if (flag == FLG_LINELEN && val < MINLINELEN)
2606 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2607 flagcode_unparse (flag),
2613 case FLG_INCLUDENEST:
2614 case FLG_CONTROLNESTDEPTH:
2615 case FLG_STRINGLITERALLEN:
2616 case FLG_NUMSTRUCTFIELDS:
2617 case FLG_NUMENUMMEMBERS:
2618 case FLG_INDENTSPACES:
2622 llerror_flagWarning (message ("Value for %s must be a non-negative "
2623 "number (given %d)",
2624 flagcode_unparse (flag), val));
2633 gc.values[index] = val;
2637 context_setValueAndFlag (flagcode flag, int val)
2639 gc.flags[flag] = TRUE;
2640 context_setValue (flag, val);
2644 context_getValue (flagcode flag)
2646 int index = flagcode_valueIndex (flag);
2648 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2649 return (gc.values[index]);
2653 context_getCounter (flagcode flag)
2655 int index = flagcode_valueIndex (flag);
2657 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2658 return (gc.counters[index]);
2662 context_incCounter (flagcode flag)
2664 int index = flagcode_valueIndex (flag);
2666 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2668 gc.counters[index]++;
2672 context_decCounter (flagcode flag)
2674 int index = flagcode_valueIndex (flag);
2676 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2677 gc.counters[index]--;
2680 bool context_showFunction (void)
2682 return (gc.showfunction);
2686 context_setString (flagcode flag, cstring val)
2688 int index = flagcode_stringIndex (flag);
2690 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2692 if (flag == FLG_SYSTEMDIRS)
2694 llassert (cstring_isDefined (val));
2696 if (cstring_firstChar (val) == '\"')
2699 cstring tval = cstring_copy (cstring_suffix (val, 1));
2701 if (cstring_lastChar (tval) != '\"')
2703 int n = cstring_length (tval) - 1;
2705 while (isspace ((int) cstring_getChar (tval, n)))
2710 if (cstring_getChar (tval, n) != '\"')
2712 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2716 cstring otval = tval;
2717 tval = cstring_prefix (tval, n);
2718 cstring_free (otval);
2722 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2723 DPRINTF (("val = %s", val));
2724 cstring_free (tval);
2725 cstring_free (oval);
2729 if (flag == FLG_TMPDIR)
2731 llassert (cstring_isDefined (val));
2733 if (cstring_length (val) == 0)
2736 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2738 else if (cstring_lastChar (val) != CONNECTCHAR)
2740 val = cstring_appendChar (val, CONNECTCHAR);
2748 if (cstring_length (val) >= 1
2749 && cstring_firstChar (val) == '"')
2751 llerror_flagWarning (message
2752 ("setting %s to string beginning with \". You probably "
2753 "don't meant to have the \"'s.",
2754 flagcode_unparse (flag)));
2757 if (flag == FLG_BOOLTYPE)
2762 gc.strings[index] = val;
2765 static /*@exposed@*/ cstring
2766 context_exposeString (flagcode flag)
2768 int index = flagcode_stringIndex (flag);
2770 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2771 return (gc.strings[index]);
2775 context_getString (flagcode flag)
2777 return (context_exposeString (flag));
2781 context_resetErrors (void)
2786 void context_initMod (void)
2787 /*@globals undef gc; @*/
2789 gc.kind = CX_GLOBAL;
2790 gc.savekind = CX_ERROR;
2791 gc.instandardlib = FALSE;
2794 gc.linesprocessed = 0;
2795 gc.speclinesprocessed = 0;
2796 gc.insuppressregion = FALSE;
2797 gc.macroMissingParams = FALSE;
2798 gc.preprocessing = FALSE;
2799 gc.incommandline = FALSE;
2800 gc.mc = macrocache_create ();
2802 gc.maxmods = DEFAULTMAXMODS;
2803 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2805 gc.library = FLG_ANSILIB;
2807 gc.locstack = filelocStack_new ();
2808 gc.modrecs = sRefSetList_undefined;
2809 gc.anyExports = FALSE;
2811 gc.ftab = fileTable_create ();
2812 gc.msgLog = messageLog_new ();
2813 gc.inimport = FALSE;
2814 gc.inDerivedFile = FALSE;
2815 gc.inheader = FALSE;
2816 gc.markers = flagMarkerList_new ();
2817 gc.cont.glob = TRUE;
2818 gc.showfunction = FALSE;
2819 gc.msgAnnote = cstring_undefined;
2820 gc.aliasAnnote = sRef_undefined;
2821 gc.aliasAnnoteAls = sRef_undefined;
2822 gc.boolType = ctype_bool;
2823 gc.mods = sRefSet_new ();
2825 gc.saveloc = fileloc_undefined;
2827 gc.inmacrocache = FALSE;
2828 gc.inclause = NOCLAUSE;
2829 gc.clauses = clauseStack_new ();
2830 gc.globs = globSet_new ();
2831 gc.nacct = typeIdSet_emptySet ();
2832 gc.acct = typeIdSet_emptySet ();
2833 gc.facct = typeIdSet_emptySet ();
2834 gc.savedFlags = FALSE;
2835 gc.pushloc = fileloc_undefined;
2836 gc.protectVars = FALSE;
2837 gc.justpopped = FALSE;
2838 gc.isNullGuarded = NO;
2839 gc.globs_used = globSet_undefined;
2843 gc.setGlobally[code] = FALSE;
2844 gc.setLocally[code] = FALSE;
2845 } end_allFlagCodes ;
2849 context_resetAllFlags ();
2850 assertSet (gc.flags); /* Can't use global in defines */
2851 assertSet (gc.saveflags);
2852 assertSet (gc.values);
2853 assertSet (gc.strings);
2855 conext_resetAllCounters ();
2856 assertSet (gc.counters);
2858 context_setMode (DEFAULT_MODE);
2860 gc.stateTable = metaStateTable_create ();
2861 gc.annotTable = annotationTable_create ();
2863 gc.inFunctionHeader = FALSE;
2865 DPRINTF (("Annotations: \n%s",
2866 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
2867 DPRINTF (("State: \n%s",
2868 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
2873 context_typeofZero (void)
2875 ctype ct = ctype_int;
2877 if (context_getFlag (FLG_ZEROPTR))
2879 ct = ctype_makeConj (ct, ctype_voidPointer);
2882 if (context_getFlag (FLG_ZEROBOOL)) {
2883 ct = ctype_makeConj (ct, ctype_bool);
2890 context_typeofOne (void)
2892 ctype ct = ctype_int;
2894 /* 1 is on longer a bool (was before 2.4)
2895 if (!context_getFlag (FLG_ABSTRACTBOOL))
2897 ct = ctype_makeConj (ct, ctype_bool);
2905 context_unparse (void)
2912 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
2915 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
2918 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
2921 s = message ("Inner Context:%q", fileloc_unparse (g_currentloc));
2924 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
2925 uentry_unparse (gc.cont.fcn),
2926 fileloc_unparse (g_currentloc),
2927 typeIdSet_unparse (gc.acct),
2928 sRefSet_unparse (gc.mods));
2931 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
2933 case CX_UNKNOWNMACRO:
2934 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
2937 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
2940 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
2943 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
2946 s = message ("Un-unparseable context: %d", (int) gc.kind);
2950 s = message ("%q\naccess: %q", s, context_unparseAccess ());
2955 context_currentFunctionType (void)
2957 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2959 return (uentry_getType (gc.cont.fcn));
2961 else if (gc.kind == CX_INNER)
2963 llcontbuglit ("context_currentFunctionType: inner context");
2964 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
2965 return (context_currentFunctionType ());
2969 llcontbuglit ("context_currentFunctionType: not in function");
2970 return (ctype_undefined);
2975 context_enterInnerContext (void)
2977 if (gc.kind == CX_GLOBAL)
2982 else if (gc.kind == CX_INNER)
2992 usymtab_enterScope ();
2993 pushClause (NOCLAUSE);
2997 context_exitInnerPlain (void) /*@modifies gc;@*/
2999 context_exitInner (exprNode_undefined);
3003 context_exitInner (exprNode exp)
3006 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3007 ("inclause = %s", clause_nameTaken (gc.inclause)));
3009 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3010 gc.inclause = topClause (gc.clauses);
3012 if (gc.kind == CX_INNER)
3014 if (--gc.cont.cdepth == 0)
3016 gc.kind = CX_GLOBAL;
3017 gc.cont.glob = TRUE;
3022 if (gc.kind == CX_GLOBAL)
3024 llcontbuglit ("Attempt to exit global context");
3029 usymtab_exitScope (exp);
3034 context_enterStructInnerContext (void)
3036 if (gc.kind == CX_GLOBAL)
3041 else if (gc.kind == CX_INNER)
3050 usymtab_enterScope ();
3054 context_exitStructInnerContext (void)
3056 if (gc.kind == CX_INNER)
3058 if (--gc.cont.cdepth == 0)
3060 gc.kind = CX_GLOBAL;
3061 gc.cont.glob = TRUE;
3066 if (gc.kind == CX_GLOBAL)
3068 llcontbuglit ("Attempt to exit global context");
3073 usymtab_exitScope (exprNode_undefined);
3077 context_exitInnerSafe (void)
3080 if (gc.kind == CX_INNER)
3082 if (--gc.cont.cdepth == 0)
3087 else if (gc.kind == CX_GLOBAL)
3089 llcontbuglit ("Attempt to exit global context");
3094 if (usymtab_inDeepScope ())
3096 usymtab_exitScope (exprNode_undefined);
3102 void setModuleAccess (void)
3104 gc.facct = typeIdSet_emptySet ();
3106 if (fileId_isValid (currentFile ()))
3108 cstring baseName = fileloc_getBase (g_currentloc);
3110 if (context_getFlag (FLG_ACCESSFILE))
3112 if (usymtab_existsType (baseName))
3114 gc.facct = typeIdSet_insert (gc.facct,
3115 usymtab_getTypeId (baseName));
3123 if (context_getFlag (FLG_ACCESSMODULE))
3126 bool hasaccess = FALSE;
3128 for (i = 0; i < gc.nmods; i++)
3130 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3132 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3141 gc.inheader = fileId_isHeader (currentFile ());
3145 llcontbuglit ("Current file not defined\n");
3146 gc.facct = typeIdSet_emptySet ();
3148 gc.inheader = FALSE;
3151 /* 17 Jan 1995: forgot to clear nacct */
3153 gc.nacct = typeIdSet_emptySet ();
3157 context_enterFileAux (void)
3163 context_enterFile (void)
3165 context_enterFileAux ();
3166 usymtab_enterFile ();
3170 context_enterMacroFile (void)
3172 context_enterFileAux ();
3176 context_inFunction (void)
3178 kcontext ck = gc.kind;
3180 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3184 context_inFunctionLike (void)
3186 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3187 || gc.kind == CX_FCNDECLARATION
3188 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3192 context_inRealFunction (void)
3194 kcontext ck = gc.kind;
3196 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3200 context_processAllMacros (void)
3202 usymtab_enterFile ();
3204 gc.inmacrocache = TRUE;
3205 macrocache_processUndefinedElements (gc.mc);
3207 usymtab_exitFile ();
3209 gc.inmacrocache = FALSE;
3210 macrocache_finalize ();
3214 ** this happens once at the end of each C file
3216 ** check each Macro that was defined in current file.c or current file.h
3221 context_processMacros (void)
3223 if (fileId_isValid (currentFile ()))
3226 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileName (currentFile ())));
3228 gc.inmacrocache = TRUE;
3230 DPRINTF (("Processing macros: %s", cbase));
3231 lastfl = macrocache_processFileElements (gc.mc, cbase);
3232 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3234 cstring_free (cbase);
3236 if (fileloc_isDefined (lastfl))
3238 g_currentloc = fileloc_update (g_currentloc, lastfl);
3242 gc.inmacrocache = FALSE;
3247 context_processingMacros (void)
3249 return (gc.inmacrocache);
3253 context_exitCFile (void)
3255 if (gc.kind != CX_GLOBAL)
3258 (cstring_makeLiteral ("File ended outside global scope"));
3261 if (gc.insuppressregion)
3263 /* gack...don't reverse the order of these lines! ;-> */
3264 gc.insuppressregion = FALSE;
3265 llerrorlit (FLG_SYNTAX,
3266 "File ended in ignore errors region, "
3267 "possible missing /*@end*/");
3270 /* fix up parse errors */
3272 while (!usymtab_inFileScope ())
3274 usymtab_quietExitScope (g_currentloc);
3278 ** Clear the file-specific modifies information.
3281 sRefSetList_elements (gc.modrecs, mods)
3283 sRefSet_clearStatics (mods);
3284 } end_sRefSetList_elements ;
3286 sRefSetList_clear (gc.modrecs);
3288 context_processMacros ();
3291 usymtab_exitFile ();
3293 gc.inDerivedFile = FALSE;
3294 filelocStack_clear (gc.locstack);
3296 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3298 gc.cont.glob = TRUE;
3302 context_restoreFlagSettings ();
3303 gc.savedFlags = FALSE;
3307 DPRINTF (("After exiting file: "));
3308 usymtab_printAll ();
3313 context_exitMacroCache (void)
3315 if (gc.kind != CX_GLOBAL)
3317 if (context_inMacro ())
3318 /* this is okay, file could end without newline in macro */
3320 DPRINTF (("Still in macro: %s",
3321 context_unparse ()));
3322 context_exitFunction ();
3326 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3327 context_unparse ()));
3328 gc.kind = CX_GLOBAL;
3333 ** no longer valid here
3334 ** if (gc.insuppressregion)
3336 ** gc.insuppressregion = FALSE;
3337 ** llerror ("File ended in ignore errors region, possible missing @");
3341 gc.cont.glob = TRUE;
3345 context_saveLocation (void)
3347 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3348 fileloc_free (gc.saveloc);
3351 gc.saveloc = fileloc_copy (g_currentloc);
3355 context_getSaveLocation (void)
3357 fileloc fl = gc.saveloc;
3359 gc.saveloc = fileloc_undefined;
3363 /*@observer@*/ cstring
3364 context_inFunctionName (void)
3366 if (gc.kind == CX_FUNCTION
3367 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3368 || gc.kind == CX_MACROCONST
3369 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3371 return (uentry_rawName (gc.cont.fcn));
3375 llcontbuglit ("context_inFunctionName: not in function");
3376 return (cstring_undefined);
3381 context_userSetFlag (flagcode f, bool b)
3383 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3385 if (f == FLG_NEVERINCLUDE && b)
3387 if (gc.flags[FLG_EXPORTHEADER])
3389 llerror_flagWarning (cstring_makeLiteral
3390 ("setting +neverinclude after +exportheader. "
3391 "Turning off exportheader, since headers are not checked "
3392 "when +neverinclude is used."));
3394 gc.flags[FLG_EXPORTHEADER] = FALSE;
3399 if (f == FLG_EXPORTHEADER && b)
3401 if (gc.flags[FLG_NEVERINCLUDE])
3403 llerror_flagWarning (cstring_makeLiteral
3404 ("setting +exportheader after +neverinclude. "
3405 "Not setting exportheader, since headers are not checked "
3406 "when +neverinclude is used."));
3407 gc.flags[FLG_EXPORTHEADER] = FALSE;
3413 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3415 bool lastsetting = context_getFlag (f);
3417 if (bool_equal (lastsetting, b)
3418 && !flagcode_isSpecialFlag (f)
3419 && !flagcode_isIdemFlag (f)
3420 && !flagcode_hasArgument (f))
3422 llerror_flagWarning (message ("setting %s%s redundant with current value",
3423 cstring_makeLiteralTemp (b ? "+" : "-"),
3424 flagcode_unparse (f)));
3428 if (flagcode_isWarnUseFlag (f) && b)
3430 if (!context_getFlag (FLG_WARNUSE))
3432 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3433 flagcode_unparse (f)));
3439 if (flagcode_isLibraryFlag (f))
3441 if (gc.library != FLG_ANSILIB
3444 llerror_flagWarning (message ("selecting library %s after library %s was "
3445 "selected (only one library may be used)",
3446 flagcode_unparse (f),
3447 flagcode_unparse (gc.library)));
3450 if (f == FLG_UNIXLIB)
3452 if (context_getFlag (FLG_WARNUNIXLIB))
3454 llerror_flagWarning (cstring_makeLiteral
3455 ("selecting unix library. Unix library is "
3456 "ad hoc addition to POSIX library. Recommend "
3457 "use +posixlib to select POSIX library instead. "
3458 "Use -warnunixlib to suppress this message."));
3465 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3467 llerror_flagWarning (message
3468 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3469 flagcode_unparse (f)));
3472 gc.setGlobally[f] = TRUE;
3473 context_setFlag (f, b);
3477 context_fileSetFlag (flagcode f, ynm set)
3481 context_saveFlagSettings ();
3484 if (ynm_isOff (set))
3486 context_setFlagAux (f, FALSE, TRUE, FALSE);
3488 else if (ynm_isOn (set))
3490 context_setFlagAux (f, TRUE, TRUE, FALSE);
3491 gc.setLocally[f] = TRUE;
3495 context_restoreFlag (f);
3500 context_restoreFlag (flagcode f)
3507 message ("Attempt to restore flag %s when no file scope flags "
3509 flagcode_unparse (f)),
3514 context_addFlagMarker (f, MAYBE);
3515 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3521 context_setFlag (flagcode f, bool b)
3523 context_setFlagAux (f, b, FALSE, FALSE);
3527 context_setFlagTemp (flagcode f, bool b)
3529 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3534 # define DOSET(ff,b) \
3535 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3536 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3537 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3538 gc.flags[ff] = b; } while (FALSE)
3541 context_setFlagAux (flagcode f, bool b, bool
3542 inFile, /*@unused@*/ bool isRestore)
3544 DPRINTF (("set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3546 if (f == FLG_USESTDERR)
3549 g_msgstream = stderr;
3551 g_msgstream = stdout;
3556 ** Removed test for special flags.
3559 if (flagcode_isIdemFlag (f))
3568 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3570 if (b) /* Turing higher level on, turns on all lower levels */
3574 case FLG_ITS4MOSTRISKY:
3575 DOSET (FLG_ITS4VERYRISKY, b);
3577 case FLG_ITS4VERYRISKY:
3578 DOSET (FLG_ITS4RISKY, b);
3581 DOSET (FLG_ITS4MODERATERISK, b);
3583 case FLG_ITS4MODERATERISK:
3584 DOSET (FLG_ITS4LOWRISK, b);
3586 case FLG_ITS4LOWRISK:
3591 else /* Turning level off, turns off all higher levels */
3595 case FLG_ITS4LOWRISK:
3596 DOSET (FLG_ITS4MODERATERISK, b);
3598 case FLG_ITS4MODERATERISK:
3599 DOSET (FLG_ITS4RISKY, b);
3602 DOSET (FLG_ITS4VERYRISKY, b);
3604 case FLG_ITS4VERYRISKY:
3605 DOSET (FLG_ITS4MOSTRISKY, b);
3607 case FLG_ITS4MOSTRISKY:
3617 DOSET (FLG_ALLEMPTY, b);
3618 DOSET (FLG_IFEMPTY, b);
3619 DOSET (FLG_WHILEEMPTY, b);
3620 DOSET (FLG_FOREMPTY, b);
3623 DOSET (FLG_PREDBOOL, b);
3624 DOSET (FLG_PREDBOOLINT, b);
3625 DOSET (FLG_PREDBOOLPTR, b);
3626 DOSET (FLG_PREDBOOLOTHERS, b);
3629 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3630 DOSET (FLG_CHECKEDGLOBALIAS, b);
3631 DOSET (FLG_CHECKMODGLOBALIAS, b);
3632 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3635 DOSET (FLG_ALLBLOCK, b);
3636 DOSET (FLG_IFBLOCK, b);
3637 DOSET (FLG_WHILEBLOCK, b);
3638 DOSET (FLG_FORBLOCK, b);
3652 DOSET (FLG_GRAMMAR, b);
3654 case FLG_CODEIMPONLY:
3655 DOSET (FLG_CODEIMPONLY, b);
3656 DOSET (FLG_GLOBIMPONLY, b);
3657 DOSET (FLG_RETIMPONLY, b);
3658 DOSET (FLG_STRUCTIMPONLY, b);
3660 case FLG_SPECALLIMPONLY:
3661 DOSET (FLG_SPECALLIMPONLY, b);
3662 DOSET (FLG_SPECGLOBIMPONLY, b);
3663 DOSET (FLG_SPECRETIMPONLY, b);
3664 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3666 case FLG_ALLIMPONLY:
3667 DOSET (FLG_ALLIMPONLY, b);
3668 DOSET (FLG_GLOBIMPONLY, b);
3669 DOSET (FLG_RETIMPONLY, b);
3670 DOSET (FLG_STRUCTIMPONLY, b);
3671 DOSET (FLG_SPECGLOBIMPONLY, b);
3672 DOSET (FLG_SPECRETIMPONLY, b);
3673 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3675 case FLG_ANSILIMITS:
3676 DOSET (FLG_ANSILIMITS, b);
3677 DOSET (FLG_CONTROLNESTDEPTH, b);
3678 DOSET (FLG_STRINGLITERALLEN, b);
3679 DOSET (FLG_INCLUDENEST, b);
3680 DOSET (FLG_NUMSTRUCTFIELDS, b);
3681 DOSET (FLG_NUMENUMMEMBERS, b);
3685 context_setValue (FLG_CONTROLNESTDEPTH, DEFAULT_CONTROLNESTDEPTH);
3686 context_setValue (FLG_STRINGLITERALLEN, DEFAULT_STRINGLITERALLEN);
3687 context_setValue (FLG_INCLUDENEST, DEFAULT_INCLUDENEST);
3688 context_setValue (FLG_NUMSTRUCTFIELDS, DEFAULT_NUMSTRUCTFIELDS);
3689 context_setValue (FLG_NUMENUMMEMBERS, DEFAULT_NUMENUMMEMBERS);
3692 case FLG_EXTERNALNAMELEN:
3693 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3694 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3696 case FLG_INTERNALNAMELEN:
3697 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3698 DOSET (FLG_INTERNALNAMELEN, TRUE);
3700 case FLG_EXTERNALNAMECASEINSENSITIVE:
3701 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3703 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3705 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3706 context_setValue (FLG_EXTERNALNAMELEN, 0);
3709 case FLG_INTERNALNAMECASEINSENSITIVE:
3710 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3712 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3714 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3715 context_setValue (FLG_INTERNALNAMELEN, 0);
3718 case FLG_INTERNALNAMELOOKALIKE:
3719 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3721 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3723 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3724 context_setValue (FLG_INTERNALNAMELEN, 0);
3728 DOSET (FLG_MODNOMODS, b);
3729 DOSET (FLG_MODGLOBSUNSPEC, b);
3730 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3733 DOSET (FLG_EXPORTVAR, b);
3734 DOSET (FLG_EXPORTFCN, b);
3735 DOSET (FLG_EXPORTTYPE, b);
3736 DOSET (FLG_EXPORTMACRO, b);
3737 DOSET (FLG_EXPORTCONST, b);
3738 gc.anyExports = TRUE;
3741 DOSET (FLG_RETEXPOSE, b);
3742 DOSET (FLG_ASSIGNEXPOSE, b);
3743 DOSET (FLG_CASTEXPOSE, b);
3746 DOSET (FLG_RETVALBOOL, b);
3747 DOSET (FLG_RETVALINT, b);
3748 DOSET (FLG_RETVALOTHER, b);
3753 DOSET (FLG_EXPORTLOCAL, FALSE);
3754 DOSET (FLG_DECLUNDEF, FALSE);
3755 DOSET (FLG_SPECUNDEF, FALSE);
3756 DOSET (FLG_TOPUNUSED, FALSE);
3760 DOSET (FLG_LOOPLOOPBREAK, b);
3761 DOSET (FLG_LOOPSWITCHBREAK, b);
3762 DOSET (FLG_SWITCHLOOPBREAK, b);
3763 DOSET (FLG_SWITCHSWITCHBREAK, b);
3764 DOSET (FLG_LOOPLOOPCONTINUE, b);
3765 DOSET (FLG_DEEPBREAK, b);
3768 DOSET (FLG_ACCESSMODULE, b);
3769 DOSET (FLG_ACCESSFILE, b);
3770 DOSET (FLG_ACCESSCZECH, b);
3773 DOSET (FLG_ALLMACROS, b);
3774 DOSET (FLG_FCNMACROS, b);
3775 DOSET (FLG_CONSTMACROS, b);
3778 if (b) { DOSET (FLG_ACCESSCZECH, b); }
3779 DOSET (FLG_CZECHFUNCTIONS, b);
3780 DOSET (FLG_CZECHVARS, b);
3781 DOSET (FLG_CZECHCONSTANTS, b);
3782 DOSET (FLG_CZECHTYPES, b);
3785 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
3786 DOSET (FLG_SLOVAKFUNCTIONS, b);
3787 DOSET (FLG_SLOVAKVARS, b);
3788 DOSET (FLG_SLOVAKCONSTANTS, b);
3789 DOSET (FLG_SLOVAKTYPES, b);
3791 case FLG_CZECHOSLOVAK:
3792 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
3793 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
3794 DOSET (FLG_CZECHOSLOVAKVARS, b);
3795 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
3796 DOSET (FLG_CZECHOSLOVAKTYPES, b);
3799 DOSET (FLG_NULLSTATE, b);
3800 DOSET (FLG_NULLDEREF, b);
3801 DOSET (FLG_NULLASSIGN, b);
3802 DOSET (FLG_NULLPASS, b);
3803 DOSET (FLG_NULLRET, b);
3806 DOSET (FLG_NULLSTATE, b);
3807 DOSET (FLG_NULLDEREF, b);
3808 DOSET (FLG_NULLASSIGN, b);
3809 DOSET (FLG_NULLPASS, b);
3810 DOSET (FLG_NULLRET, b);
3811 DOSET (FLG_COMPDEF, b);
3812 DOSET (FLG_COMPMEMPASS, b);
3813 DOSET (FLG_UNIONDEF, b);
3814 DOSET (FLG_MEMTRANS, b);
3815 DOSET (FLG_USERELEASED, b);
3816 DOSET (FLG_ALIASUNIQUE, b);
3817 DOSET (FLG_MAYALIASUNIQUE, b);
3818 DOSET (FLG_MUSTFREE, b);
3819 DOSET (FLG_MUSTDEFINE, b);
3820 DOSET (FLG_GLOBSTATE, b);
3821 DOSET (FLG_COMPDESTROY, b);
3822 DOSET (FLG_MUSTNOTALIAS, b);
3823 DOSET (FLG_MEMIMPLICIT, b);
3824 DOSET (FLG_BRANCHSTATE, b);
3825 /*@fallthrough@*/ /* also sets memtrans flags */
3827 DOSET (FLG_MEMTRANS, b);
3828 DOSET (FLG_EXPOSETRANS, b);
3829 DOSET (FLG_OBSERVERTRANS, b);
3830 DOSET (FLG_DEPENDENTTRANS, b);
3831 DOSET (FLG_NEWREFTRANS, b);
3832 DOSET (FLG_ONLYTRANS, b);
3833 DOSET (FLG_OWNEDTRANS, b);
3834 DOSET (FLG_FRESHTRANS, b);
3835 DOSET (FLG_SHAREDTRANS, b);
3836 DOSET (FLG_TEMPTRANS, b);
3837 DOSET (FLG_KEPTTRANS, b);
3838 DOSET (FLG_REFCOUNTTRANS, b);
3839 DOSET (FLG_STATICTRANS, b);
3840 DOSET (FLG_UNKNOWNTRANS, b);
3841 DOSET (FLG_KEEPTRANS, b);
3842 DOSET (FLG_IMMEDIATETRANS, b);
3849 if (b && !gc.anyExports
3850 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
3851 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
3852 || f == FLG_EXPORTCONST
3853 || f == FLG_EXPORTANY))
3855 gc.anyExports = TRUE;
3860 context_maybeSet (flagcode d)
3862 return (gc.flags[d] || gc.setLocally[d]);
3866 context_getFlag (flagcode d)
3868 return (gc.flags[d]);
3872 context_flagOn (flagcode f, fileloc loc)
3874 return (!context_suppressFlagMsg (f, loc));
3877 static void context_saveFlagSettings (void)
3879 gc.savedFlags = TRUE;
3880 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3881 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
3884 static void context_restoreFlagSettings (void)
3886 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3887 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
3888 gc.savedFlags = FALSE;
3891 void context_setFilename (fileId fid, int lineno)
3892 /*@globals fileloc g_currentloc;@*/
3893 /*@modifies g_currentloc@*/
3895 if (fileId_baseEqual (currentFile (), fid))
3902 fileloc_setColumn (g_currentloc, 0);
3904 if (fileloc_isSpecialFile (g_currentloc))
3906 gc.inDerivedFile = TRUE;
3909 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
3911 int maxdepth = context_getValue (FLG_INCLUDENEST);
3913 if (filelocStack_size (gc.locstack) > maxdepth)
3915 int depth = filelocStack_includeDepth (gc.locstack);
3917 if (depth > maxdepth)
3921 message ("Maximum include nesting depth "
3922 "(%d, current depth %d) exceeded",
3925 filelocStack_nextTop (gc.locstack)))
3927 filelocStack_printIncludes (gc.locstack);
3933 g_currentloc = fileloc_create (fid, lineno, 1);
3934 gc.inheader = fileId_isHeader (currentFile ());
3936 context_enterFileAux ();
3940 void context_enterIterDef (/*@observer@*/ uentry le)
3942 context_enterMacro (le);
3943 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
3944 gc.kind = CX_ITERDEF;
3947 void context_enterIterEnd (/*@observer@*/ uentry le)
3949 context_enterMacro (le);
3950 gc.kind = CX_ITEREND;
3954 context_destroyMod (void)
3955 /*@globals killed gc@*/
3958 ctype_destroyMod ();
3962 fileTable_free (gc.ftab);
3963 filelocStack_free (gc.locstack);
3965 gc.ftab = fileTable_undefined;
3967 macrocache_free (gc.mc);
3968 sfree (gc.moduleaccess);
3971 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
3972 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
3975 sRefSetList_free (gc.modrecs);
3977 flagMarkerList_free (gc.markers);
3979 messageLog_free (gc.msgLog);
3981 clauseStack_free (gc.clauses);
3984 cstring_free (gc.msgAnnote);
3985 globSet_free (gc.globs_used);
3986 metaStateTable_free (gc.stateTable);
3987 annotationTable_free (gc.annotTable);
3994 bool context_msgBoolInt (void)
3996 return gc.flags [FLG_BOOLINT];
3999 bool context_msgCharInt (void)
4001 return gc.flags [FLG_CHARINT];
4004 bool context_msgEnumInt (void)
4006 return gc.flags [FLG_ENUMINT];
4009 bool context_msgPointerArith (void)
4011 return gc.flags [FLG_POINTERARITH];
4014 bool context_msgStrictOps (void)
4016 return gc.flags [FLG_STRICTOPS];
4020 bool context_msgLh (void)
4022 return gc.flags [FLG_DOLH];
4026 void context_pushLoc (void)
4028 fileloc_free (gc.pushloc);
4029 gc.pushloc = gc.saveloc;
4030 gc.saveloc = fileloc_undefined;
4033 void context_popLoc (void)
4035 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4038 bool context_inGlobalScope (void)
4040 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4043 bool context_inInnerScope (void)
4045 return (gc.kind == CX_INNER);
4048 void context_setProtectVars (void)
4050 gc.protectVars = TRUE;
4053 bool context_anyErrors (void)
4055 return (gc.numerrors > 0);
4058 void context_hasError (void)
4063 int context_numErrors (void)
4065 return gc.numerrors;
4068 bool context_neednl (void)
4073 void context_setNeednl (void)
4078 int context_getExpect (void)
4080 return (context_getValue (FLG_EXPECT));
4084 int context_getLCLExpect (void)
4086 return (context_getValue (FLG_LCLEXPECT));
4090 int context_getLimit (void)
4092 return (context_getValue (FLG_LIMIT));
4095 bool context_unlimitedMessages (void)
4097 return (context_getLimit () < 0);
4100 void context_releaseVars (void)
4102 llassert (gc.protectVars);
4103 gc.protectVars = FALSE;
4106 void context_sizeofReleaseVars (void)
4108 /* If there is a nested sizeof, this might not hold:
4109 llassert (gc.protectVars);
4112 gc.protectVars = FALSE;
4115 bool context_inProtectVars (void)
4117 return (gc.protectVars);
4120 void context_hideShowscan (void)
4122 gc.flags[FLG_SHOWSCAN] = FALSE;
4125 void context_unhideShowscan (void)
4127 gc.flags[FLG_SHOWSCAN] = TRUE;
4130 bool context_inHeader (void)
4132 return (gc.inheader);
4135 fileTable context_fileTable (void)
4140 cstring context_tmpdir (void)
4142 return (context_getString (FLG_TMPDIR));
4145 messageLog context_messageLog (void)
4150 bool context_inMacroFunction (void)
4152 return (gc.kind == CX_MACROFCN);
4155 bool context_inMacroConstant (void)
4157 return (gc.kind == CX_MACROCONST);
4160 bool context_inMacroUnknown (void)
4162 return (gc.kind == CX_UNKNOWNMACRO);
4165 void context_setShownFunction (void)
4167 gc.showfunction = FALSE;
4170 bool context_doDump (void)
4172 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4175 bool context_doMerge (void)
4177 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4180 cstring context_getDump (void)
4182 return context_getString (FLG_DUMP);
4185 cstring context_getMerge (void)
4187 return context_getString (FLG_MERGE);
4191 bool context_inLCLLib (void)
4193 return (gc.kind == CX_LCLLIB);
4196 bool context_inImport (void)
4198 return (gc.inimport);
4201 void context_enterImport (void)
4206 void context_leaveImport (void)
4208 gc.inimport = FALSE;
4212 bool context_inMacro (void)
4214 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4215 || gc.kind == CX_UNKNOWNMACRO
4216 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4219 bool context_inIterDef (void)
4221 return (gc.kind == CX_ITERDEF);
4224 bool context_inIterEnd (void)
4226 return (gc.kind == CX_ITEREND);
4229 int context_getLinesProcessed (void)
4231 return (gc.linesprocessed);
4234 int context_getSpecLinesProcessed (void)
4236 return (gc.speclinesprocessed);
4240 void context_processedSpecLine (void)
4242 gc.speclinesprocessed++;
4245 void context_resetSpecLines (void)
4247 gc.speclinesprocessed = 0;
4251 bool context_inGlobalContext (void)
4253 return (gc.kind == CX_GLOBAL);
4256 void context_setFileId (fileId s)
4258 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4261 bool context_setBoolName (void)
4263 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4267 cstring context_printBoolName (void)
4269 if (context_setBoolName ())
4271 return context_getBoolName ();
4275 return cstring_makeLiteralTemp ("boolean");
4279 cstring context_getBoolName (void)
4281 return (context_getString (FLG_BOOLTYPE));
4284 cstring context_getFalseName (void)
4286 return (context_getString (FLG_BOOLFALSE));
4289 cstring context_getTrueName (void)
4291 return (context_getString (FLG_BOOLTRUE));
4294 cstring context_getLarchPath (void)
4296 return (context_getString (FLG_LARCHPATH));
4299 cstring context_getLCLImportDir (void)
4301 return (context_getString (FLG_LCLIMPORTDIR));
4304 static void context_setJustPopped (void)
4306 gc.justpopped = TRUE;
4309 void context_clearJustPopped (void)
4311 gc.justpopped = FALSE;
4314 bool context_justPopped (void)
4316 return (gc.justpopped);
4319 void context_setMacroMissingParams (void)
4321 gc.macroMissingParams = TRUE;
4324 void context_resetMacroMissingParams (void)
4326 gc.macroMissingParams = FALSE;
4329 bool context_isMacroMissingParams (void)
4331 return (gc.macroMissingParams);
4334 void context_showFilelocStack (void)
4336 filelocStack_printIncludes (gc.locstack);
4339 metaStateTable context_getMetaStateTable (void)
4341 return gc.stateTable;
4344 metaStateInfo context_lookupMetaStateInfo (cstring key)
4346 return metaStateTable_lookup (gc.stateTable, key);
4349 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4351 annotationInfo ainfo;
4353 ainfo = annotationTable_lookup (gc.annotTable, annot);
4358 void context_addAnnotation (annotationInfo ainfo)
4360 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4364 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4365 annotationInfo_getLoc (ainfo));
4367 annotationInfo_free (ainfo);
4371 annotationTable_insert (gc.annotTable, ainfo);
4375 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4377 if (metaStateTable_contains (gc.stateTable, mname))
4381 message ("Duplicate metastate declaration: %s", mname),
4382 metaStateInfo_getLoc (msinfo));
4383 cstring_free (mname);
4384 metaStateInfo_free (msinfo);
4388 DPRINTF (("Adding meta state: %s", mname));
4389 metaStateTable_insert (gc.stateTable, mname, msinfo);
4393 valueTable context_createValueTable (sRef s)
4395 if (metaStateTable_size (gc.stateTable) > 0)
4397 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4398 /*@i32 should use smaller value... */
4399 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4401 metaStateTable_elements (gc.stateTable, msname, msi)
4403 mtContextNode context = metaStateInfo_getContext (msi);
4405 if (mtContextNode_matchesRefStrict (context, s))
4407 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4408 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4412 cstring_copy (metaStateInfo_getName (msi)),
4413 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4414 stateInfo_undefined));
4418 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4421 end_metaStateTable_elements ;
4423 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4428 return valueTable_undefined;
4432 valueTable context_createGlobalMarkerValueTable ()
4434 if (metaStateTable_size (gc.stateTable) > 0)
4436 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4437 /*@i32 should use smaller value... */
4439 metaStateTable_elements (gc.stateTable, msname, msi)
4441 /*@i23 only add global...*/
4442 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4443 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4445 valueTable_insert (res,
4446 cstring_copy (metaStateInfo_getName (msi)),
4447 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4448 stateInfo_undefined));
4450 end_metaStateTable_elements ;
4452 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4457 return valueTable_undefined;