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"
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_LCL, CX_LCLLIB, CX_MT
73 int speclinesprocessed;
75 flagMarkerList markers;
78 ** used to record state where a macro must match a function name
79 ** (i.e., no params were listed in the macro definition
82 bool macroMissingParams BOOLBITS;
83 bool preprocessing BOOLBITS;
84 bool incommandline BOOLBITS;
85 bool insuppressregion BOOLBITS;
86 bool inDerivedFile BOOLBITS;
87 bool instandardlib BOOLBITS;
88 bool inimport BOOLBITS;
89 bool inheader BOOLBITS;
90 bool inmacrocache BOOLBITS;
91 bool protectVars BOOLBITS;
93 bool showfunction BOOLBITS;
94 bool savedFlags BOOLBITS;
95 bool justpopped BOOLBITS;
96 bool anyExports BOOLBITS;
97 bool inFunctionHeader BOOLBITS;
110 filelocStack locstack;
113 /*@observer@*/ sRef aliasAnnote;
114 /*@observer@*/ sRef aliasAnnoteAls;
118 /*@observer@*/ sRefSet mods;
120 /* file access types */
123 /* local access types (this function) */
126 /* no access types (@noaccess) */
129 /*@observer@*/ globSet globs;
130 /*@only@*/ globSet globs_used;
134 /*@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 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
163 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
164 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
165 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
167 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
168 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
169 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
170 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
171 static void context_setFlag (flagcode p_f, bool p_b)
172 /*@modifies gc.flags@*/ ;
175 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, bool p_isRestore)
176 /*@modifies gc.flags@*/ ;
178 static void context_restoreFlag (flagcode p_f) /*@modifies gc.flags@*/ ;
182 cstring context_unparseFlagMarkers ()
184 return (flagMarkerList_unparse (gc.markers));
187 void context_setPreprocessing (void)
189 llassert (!gc.preprocessing);
190 gc.preprocessing = TRUE;
193 void context_clearPreprocessing (void)
195 llassert (gc.preprocessing);
196 gc.preprocessing = FALSE;
199 bool context_isPreprocessing (void)
201 return gc.preprocessing;
204 bool context_loadingLibrary (void)
206 return (fileloc_isLib (g_currentloc));
209 bool context_inXHFile (void)
211 return (fileloc_isXHFile (g_currentloc));
214 void context_setInCommandLine (void)
216 llassert (!gc.incommandline);
217 gc.incommandline = TRUE;
220 void context_clearInCommandLine (void)
222 llassert (gc.incommandline);
223 gc.incommandline = FALSE;
226 bool context_isInCommandLine (void)
228 return gc.incommandline;
232 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
235 clauseStack_push (gc.clauses, c);
237 if (clause_isConditional (c)
238 && context_getFlag (FLG_CONTROLNESTDEPTH))
240 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
241 int depth = clauseStack_controlDepth (gc.clauses);
243 if (depth == maxdepth + 1)
246 (FLG_CONTROLNESTDEPTH,
247 message ("Maximum control nesting depth "
256 clause topClause (clauseStack s) /*@*/
258 if (clauseStack_isEmpty (s)) return NOCLAUSE;
259 return ((clause) clauseStack_top (s));
263 context_addMacroCache (/*@only@*/ cstring def)
265 DPRINTF (("macro cache: %s", def));
266 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
270 context_addComment (/*@only@*/ cstring def)
272 DPRINTF (("macro comment: %s", def));
273 macrocache_addComment (gc.mc, fileloc_copy (g_currentloc), def);
277 ** returns TRUE is fl is in ignore region, or region where -code
279 ** the logic is fuzzy...
283 context_inSuppressFlagZone (fileloc fl, flagcode code)
285 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
288 if (ynm_isMaybe (ret))
296 res = !gc.saveflags[code];
300 res = !context_getFlag (code);
305 res = ynm_toBoolStrict (ret);
312 context_suppressSystemMsg (fileloc fl)
314 if (context_getFlag (FLG_SYSTEMDIRERRORS))
320 return (fileloc_isSystemFile (fl));
325 context_suppressFlagMsg (flagcode flag, fileloc fl)
327 if (context_suppressSystemMsg (fl))
332 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
334 /* want same object compare here */
336 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
338 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
340 return (!context_getFlag (flag)
341 || context_inSuppressRegion ()
342 || context_inSuppressZone (fl)
343 || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
347 return (context_inSuppressFlagZone (fl, flag));
352 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
355 if (context_suppressSystemMsg (fl))
361 if (fl == g_currentloc)
362 /*@noaccess fileloc@*/
364 return (context_getFlag (flag) || context_inSuppressRegion ());
369 return (context_getFlag (flag) || context_inSuppressRegion ());
374 context_inSuppressZone (fileloc fl)
376 if (context_suppressSystemMsg (fl))
381 return (flagMarkerList_inIgnore (gc.markers, fl));
385 context_inSuppressRegion (void)
387 return (gc.insuppressregion);
391 context_enterSuppressRegion (void)
393 if (gc.insuppressregion)
395 gc.insuppressregion = FALSE; /* get this msg! */
397 ("%q: New ignore errors region entered while in ignore errors region",
398 fileloc_unparse (g_currentloc)));
401 gc.insuppressregion = TRUE;
402 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (g_currentloc));
406 context_addFlagMarker (flagcode code, ynm set)
408 flagMarkerList_add (gc.markers,
409 flagMarker_createLocalSet (code, set, g_currentloc));
413 context_enterSuppressLine (int count)
415 fileloc nextline = fileloc_copy (g_currentloc);
417 flagMarkerList_add (gc.markers,
418 flagMarker_createIgnoreCount (count, g_currentloc));
420 fileloc_nextLine (nextline);
421 flagMarkerList_add (gc.markers,
422 flagMarker_createIgnoreOff (nextline));
423 fileloc_free (nextline);
426 void context_checkSuppressCounts (void)
428 if (context_getFlag (FLG_SUPCOUNTS))
430 flagMarkerList_checkSuppressCounts (gc.markers);
434 void context_incLineno (void)
441 context_exitSuppressRegion (void)
443 if (!gc.insuppressregion)
445 llerrorlit (FLG_SYNTAX,
446 "End ignore errors in region while not ignoring errors");
449 gc.insuppressregion = FALSE;
450 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (g_currentloc));
454 context_enterMTfile (void)
460 context_exitMTfile (void)
462 llassert (gc.kind == CX_MT);
468 context_enterLCLfile (void)
471 gc.facct = typeIdSet_emptySet ();
476 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
480 for (i = 0; i < gc.nmods; i++)
482 if (cstring_equal (gc.moduleaccess[i].file, fname))
484 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
485 cstring_free (fname);
490 if (gc.nmods == gc.maxmods)
494 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
495 oldmods = gc.moduleaccess;
497 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
499 for (i = 0; i < gc.nmods; i++)
501 gc.moduleaccess[i] = oldmods[i];
507 gc.moduleaccess[gc.nmods].file = fname;
508 gc.moduleaccess[gc.nmods].daccess = mods;
514 insertModuleAccess (cstring fname, typeId t)
518 for (i = 0; i < gc.nmods; i++)
520 if (cstring_equal (gc.moduleaccess[i].file, fname))
522 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
527 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
532 context_exitLCLfile (void)
534 if (gc.kind != CX_LCLLIB)
537 fileLib_withoutExtension (fileName (currentFile ()), LCL_EXTENSION);
539 addModuleAccess (fileLib_removePath (lclname), gc.facct);
540 cstring_free (lclname);
545 gc.facct = typeIdSet_emptySet ();
550 context_dumpModuleAccess (FILE *fout)
554 for (i = 0; i < gc.nmods; i++)
556 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
558 fprintf (fout, "%s#%s@\n",
559 cstring_toCharsSafe (gc.moduleaccess[i].file),
560 cstring_toCharsSafe (td));
566 bool context_usingPosixLibrary ()
568 return (gc.library == FLG_POSIXLIB
569 || gc.library == FLG_POSIXSTRICTLIB
570 || gc.library == FLG_UNIXLIB
571 || gc.library == FLG_UNIXSTRICTLIB);
574 bool context_usingAnsiLibrary ()
576 return (gc.library != FLG_NOLIB);
579 flagcode context_getLibrary ()
584 void context_setLibrary (flagcode code)
589 /*@observer@*/ cstring context_selectedLibrary ()
594 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
596 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
597 case FLG_POSIXSTRICTLIB:
598 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
600 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
601 case FLG_UNIXSTRICTLIB:
602 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
604 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
611 context_loadModuleAccess (FILE *in)
613 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
615 char *name = mstring_create (MAX_NAME_LENGTH);
621 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
627 while (s != NULL && *s != ';' && *s != '\0')
631 while (*s != '#' && *s != '\0')
640 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
641 cstring_fromChars (s)));
647 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
648 typeIdSet_undump (&s));
650 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
651 llassert (s != lasts);
661 typeIdSet context_fileAccessTypes (void)
667 context_resetModeFlags (void)
672 if (flagcode_isModeFlag (code))
674 context_setFlag (code, FALSE);
683 ** Set all flags to FALSE, except for a few which are
686 ** Set all values and strings to appropriate defaults.
687 ** Set all counters to 0.
691 conext_resetAllCounters (void)
695 for (i = 0; i < NUMVALUEFLAGS; i++)
702 context_resetAllFlags (void)
706 gc.flags[code] = FALSE;
708 if (flagcode_hasValue (code))
712 /*@-loopswitchbreak@*/
716 val = DEFAULT_LIMIT; break;
718 val = DEFAULT_BUGSLIMIT; break;
720 val = DEFAULT_LINELEN; break;
721 case FLG_INDENTSPACES:
722 val = DEFAULT_INDENTSPACES; break;
723 case FLG_EXTERNALNAMELEN:
724 val = DEFAULT_EXTERNALNAMELEN; break;
725 case FLG_INTERNALNAMELEN:
726 val = DEFAULT_INTERNALNAMELEN; break;
727 case FLG_COMMENTCHAR:
728 val = (int) DEFAULT_COMMENTCHAR; break;
729 case FLG_CONTROLNESTDEPTH:
730 val = (int) DEFAULT_CONTROLNESTDEPTH; break;
731 case FLG_STRINGLITERALLEN:
732 val = (int) DEFAULT_STRINGLITERALLEN; break;
733 case FLG_INCLUDENEST:
734 val = (int) DEFAULT_INCLUDENEST; break;
735 case FLG_NUMSTRUCTFIELDS:
736 val = (int) DEFAULT_NUMSTRUCTFIELDS; break;
737 case FLG_NUMENUMMEMBERS:
738 val = (int) DEFAULT_NUMENUMMEMBERS; break;
743 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
745 /*@=loopswitchbreak@*/
747 context_setValue (code, val);
749 else if (flagcode_hasString (code))
751 cstring val = cstring_undefined;
754 { /*@-loopswitchbreak@*/
757 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
759 if (cstring_isDefined (larchpath))
761 val = cstring_copy (larchpath);
765 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
770 case FLG_LCLIMPORTDIR:
772 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
776 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
778 char *env = osd_getEnvironmentVariable ("TMP");
782 env = osd_getEnvironmentVariable ("TEMP");
785 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
788 val = cstring_makeLiteral (DEFAULT_TMPDIR);
789 # endif /* !defined(OS2) && !defined(MSDOS) */
793 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
795 val = cstring_makeLiteral ("FALSE"); break;
797 val = cstring_makeLiteral ("TRUE"); break;
798 case FLG_MACROVARPREFIX:
799 val = cstring_makeLiteral ("m_"); break;
801 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
804 } /*@=loopswitchbreak@*/
806 context_setString (code, val);
810 ; /* nothing to set */
815 ** These flags are true by default.
818 /*@i34 move this into flags.def */
820 gc.flags[FLG_MODIFIES] = TRUE;
821 gc.flags[FLG_NESTCOMMENT] = TRUE;
822 gc.flags[FLG_GLOBALS] = TRUE;
823 gc.flags[FLG_FULLINITBLOCK] = TRUE;
824 gc.flags[FLG_LIKELYBOOL] = TRUE;
825 gc.flags[FLG_ZEROPTR] = TRUE;
826 gc.flags[FLG_NUMLITERAL] = TRUE;
827 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
828 gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
829 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
830 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
831 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
832 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
833 gc.flags[FLG_CASTFCNPTR] = TRUE;
834 gc.flags[FLG_DOLCS] = TRUE;
835 gc.flags[FLG_USEVARARGS] = TRUE;
836 gc.flags[FLG_MAINTYPE] = TRUE;
837 gc.flags[FLG_SPECMACROS] = TRUE;
838 gc.flags[FLG_REDEF] = TRUE;
839 gc.flags[FLG_MACRONEXTLINE] = TRUE;
841 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
842 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
844 gc.flags[FLG_WARNUSE] = TRUE;
845 gc.flags[FLG_PREDASSIGN] = TRUE;
846 gc.flags[FLG_MODOBSERVER] = TRUE;
847 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
848 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
850 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
851 gc.flags[FLG_RETIMPONLY] = TRUE;
852 gc.flags[FLG_GLOBIMPONLY] = TRUE;
853 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
854 gc.flags[FLG_PREPROC] = TRUE;
855 gc.flags[FLG_NAMECHECKS] = TRUE;
856 gc.flags[FLG_FORMATCODE] = TRUE;
857 gc.flags[FLG_FORMATTYPE] = TRUE;
858 gc.flags[FLG_BADFLAG] = TRUE;
859 gc.flags[FLG_WARNFLAGS] = TRUE;
860 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
861 gc.flags[FLG_WARNUNIXLIB] = TRUE;
862 gc.flags[FLG_WARNPOSIX] = TRUE;
863 gc.flags[FLG_SHOWCOL] = TRUE;
864 gc.flags[FLG_SHOWFUNC] = TRUE;
865 gc.flags[FLG_SUPCOUNTS] = TRUE;
866 gc.flags[FLG_HINTS] = TRUE;
867 gc.flags[FLG_SYNTAX] = TRUE;
868 gc.flags[FLG_TYPE] = TRUE;
869 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
870 gc.flags[FLG_ABSTRACT] = TRUE;
871 gc.flags[FLG_ITER] = TRUE;
872 gc.flags[FLG_CONTROL] = TRUE;
873 gc.flags[FLG_UNRECOG] = TRUE;
874 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
875 gc.flags[FLG_LINTCOMMENTS] = TRUE;
876 gc.flags[FLG_ACCESSCZECH] = TRUE;
877 gc.flags[FLG_ACCESSMODULE] = TRUE;
878 gc.flags[FLG_ACCESSFILE] = TRUE;
879 gc.flags[FLG_MACROVARPREFIX] = TRUE;
881 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
882 gc.flags[FLG_COMMENTERROR] = TRUE;
885 ** Changed for version 2.4.
888 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
891 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
895 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
900 ** C is way-lame, and you can initialize an array to a constant except where
901 ** it is declared. Hence, a macro is used to set the modeflags.
905 # define SETFLAGS() \
906 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
907 if (!flagcode_isModeFlag (modeflags[i])) \
908 { llbug (message ("not a mode flag: %s", \
909 flagcode_unparse (modeflags[i]))); } \
910 else { context_setFlag (modeflags[i], TRUE); } i++; }}
913 context_setMode (cstring s)
915 intSet setflags = intSet_new ();
919 if (flagcode_isModeFlag (code))
921 if (gc.setGlobally[code])
923 (void) intSet_insert (setflags, (int) code);
928 if (!intSet_isEmpty (setflags))
930 cstring rflags = cstring_undefined;
933 intSet_elements (setflags, el)
935 if (cstring_isUndefined (rflags))
937 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
941 rflags = message ("%q, %s", rflags,
942 flagcode_unparse ((flagcode) el));
946 if (num > 4 && intSet_size (setflags) > 6)
948 rflags = message ("%q, (%d others) ...", rflags,
949 intSet_size (setflags) - num);
952 } end_intSet_elements ;
954 voptgenerror (FLG_WARNFLAGS,
955 message ("Setting mode %s after setting mode flags will "
956 "override set values of flags: %s",
960 cstring_free (rflags);
963 intSet_free (setflags);
965 context_resetModeFlags ();
967 if (cstring_equalLit (s, "standard"))
969 flagcode modeflags[] =
971 FLG_ENUMINT, FLG_MACROMATCHNAME,
972 FLG_MACROUNDEF, FLG_RELAXQUALS,
973 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
974 FLG_CHECKSTRICTGLOBALIAS,
975 FLG_CHECKEDGLOBALIAS,
976 FLG_CHECKMODGLOBALIAS,
977 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
978 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
980 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
981 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_MUTREP,
982 FLG_NOEFFECT, FLG_IMPTYPE,
983 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
984 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
987 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
988 FLG_MACROSTMT, FLG_MACROPARENS,
991 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
992 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
997 /* memchecks flags */
999 FLG_NULLSTATE, FLG_NULLASSIGN,
1000 FLG_NULLPASS, FLG_NULLRET,
1002 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1005 /* memtrans flags */
1024 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1025 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1026 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1029 FLG_STATETRANSFER, FLG_STATEMERGE,
1030 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1032 FLG_IMPCHECKEDSPECGLOBALS,
1033 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1034 FLG_IFEMPTY, FLG_REALCOMPARE,
1035 FLG_BOOLOPS, FLG_PTRNEGATE,
1037 FLG_BUFFEROVERFLOWHIGH,
1044 else if (cstring_equalLit (s, "weak"))
1046 flagcode modeflags[] =
1048 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1049 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1050 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1051 FLG_CHARUNSIGNEDCHAR,
1053 FLG_VARUNUSED, FLG_FUNCUNUSED,
1055 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1058 FLG_RETSTACK, FLG_PTRNEGATE,
1059 FLG_STATETRANSFER, FLG_STATEMERGE,
1060 FLG_LONGUNSIGNEDINTEGRAL,
1061 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1065 FLG_BUFFEROVERFLOWHIGH,
1071 else if (cstring_equalLit (s, "checks"))
1073 flagcode modeflags[] =
1075 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1076 FLG_STATETRANSFER, FLG_STATEMERGE,
1077 FLG_CHECKSTRICTGLOBALIAS,
1078 FLG_CHECKEDGLOBALIAS,
1079 FLG_CHECKMODGLOBALIAS,
1080 FLG_UNCHECKEDGLOBALIAS,
1082 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1083 FLG_BOOLCOMPARE, FLG_MACROUNDEF,
1084 FLG_MUSTMOD, FLG_ALLGLOBALS,
1085 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1086 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1087 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1088 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1089 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1090 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1091 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1092 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1093 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1094 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1095 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1102 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1106 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1108 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1109 FLG_EVALORDER, FLG_USEDEF,
1113 /* memchecks flags */
1115 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1116 FLG_NULLPASS, FLG_NULLRET,
1118 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1120 /* memtrans flags */
1134 FLG_STATICINITTRANS,
1135 FLG_UNKNOWNINITTRANS,
1138 FLG_ONLYUNQGLOBALTRANS,
1139 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1140 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1141 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1144 FLG_NULLPOINTERARITH,
1145 FLG_SHADOW, FLG_DEPARRAYS,
1146 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1147 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1148 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1149 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1150 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1151 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1152 FLG_BOOLOPS, FLG_SHIFTSIGNED,
1153 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1158 else if (cstring_equalLit (s, "strict"))
1160 flagcode modeflags[] =
1162 FLG_CHECKSTRICTGLOBALIAS,
1163 FLG_CHECKEDGLOBALIAS,
1164 FLG_CHECKMODGLOBALIAS,
1165 FLG_UNCHECKEDGLOBALIAS,
1169 FLG_STATETRANSFER, FLG_STATEMERGE,
1170 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1171 FLG_ALLGLOBALS, FLG_IMPTYPE,
1172 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1173 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1174 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1175 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1178 FLG_ONLYUNQGLOBALTRANS,
1179 FLG_GLOBALSIMPMODIFIESNOTHING,
1180 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1181 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1182 FLG_USEALLGLOBS, FLG_RETALIAS,
1183 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1184 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1185 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1187 FLG_EXPORTITER, FLG_EXPORTCONST,
1188 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1189 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1191 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1193 FLG_BOOLCOMPARE, FLG_NOEFFECT,
1194 FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1195 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1196 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1197 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1198 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1199 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1200 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1202 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1205 FLG_MACROREDEF, FLG_MACROEMPTY,
1206 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1208 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1210 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1211 FLG_MODOBSERVERUNCON,
1216 /* memchecks flags */
1217 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1218 FLG_NULLPASS, FLG_NULLRET,
1220 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1222 /* memtrans flags */
1238 FLG_STATICINITTRANS,
1239 FLG_UNKNOWNINITTRANS,
1241 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1242 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1243 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1247 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1249 FLG_SHADOW, FLG_DEPARRAYS,
1250 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1251 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1252 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1253 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1254 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1255 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1256 FLG_IMPCHECKEDSTRICTSTATICS,
1257 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1258 FLG_IMPCHECKMODINTERNALS,
1259 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1260 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1261 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1262 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1263 FLG_CONTROLNESTDEPTH,
1264 FLG_FORBLOCK, FLG_WHILEBLOCK,
1265 FLG_FOREMPTY, FLG_WHILEEMPTY,
1266 FLG_IFEMPTY, FLG_IFBLOCK,
1268 FLG_REALCOMPARE, FLG_BOOLOPS,
1269 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1271 FLG_SHIFTSIGNED, FLG_BITWISEOPS,
1272 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1280 llcontbug (message ("context_setMode: bad mode: %s", s));
1285 context_isSpecialFile (cstring fname)
1287 cstring ext = fileLib_getExtension (fname);
1289 return (cstring_equalLit (ext, ".y")
1290 || cstring_equalLit (ext, ".l")
1291 || cstring_equalLit (fname, "lex.yy.c"));
1295 context_isSystemDir (cstring dir)
1297 cstring sysDirs = context_exposeString (FLG_SYSTEMDIRS);
1298 char *thisdir = cstring_toCharsSafe (sysDirs);
1299 char *nextdir = strchr (thisdir, PATH_SEPARATOR);
1301 if (nextdir != NULL)
1307 while (thisdir != NULL)
1309 DPRINTF (("Test: %s / %s", dir, thisdir));
1311 if (cstring_equalCanonicalPrefix (dir, thisdir))
1313 if (nextdir != NULL)
1315 *(nextdir - 1) = PATH_SEPARATOR;
1321 if (nextdir != NULL)
1323 *(nextdir - 1) = PATH_SEPARATOR;
1326 if (nextdir != NULL)
1329 nextdir = strchr (thisdir, PATH_SEPARATOR);
1331 if (nextdir != NULL)
1343 DPRINTF (("Returns FALSE"));
1348 context_addFileAccessType (typeId t)
1352 if (context_inFunctionLike ())
1354 gc.acct = typeIdSet_insert (gc.acct, t);
1357 gc.facct = typeIdSet_insert (gc.facct, t);
1359 base = fileloc_getBase (g_currentloc);
1360 insertModuleAccess (base, t);
1361 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1362 typeIdSet_unparse (gc.acct)));
1366 context_removeFileAccessType (typeId t)
1368 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1369 || gc.kind == CX_UNKNOWNMACRO)
1371 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1374 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1375 gc.nacct = typeIdSet_insert (gc.nacct, t);
1378 void context_enterFunctionHeader (void)
1380 if (gc.kind != CX_GLOBAL)
1382 llparseerror (cstring_makeLiteral
1383 ("Likely parse error. Function header outside global context."));
1387 llassert (gc.kind == CX_GLOBAL);
1388 DPRINTF (("Enter function header!"));
1389 gc.inFunctionHeader = TRUE;
1393 void context_exitFunctionHeader (void)
1395 DPRINTF (("Exit function header!"));
1396 gc.inFunctionHeader = FALSE;
1399 bool context_inFunctionHeader (void)
1401 return (gc.inFunctionHeader);
1404 void context_enterFunctionDeclaration (uentry e)
1406 DPRINTF (("Enter function decl"));
1407 llassert (gc.savekind == CX_ERROR);
1408 gc.savekind = gc.kind;
1409 gc.kind = CX_FCNDECLARATION;
1413 void context_exitFunctionDeclaration (void)
1415 DPRINTF (("Exit function decl"));
1416 llassert (gc.savekind != CX_ERROR);
1417 llassert (gc.kind == CX_FCNDECLARATION);
1418 gc.kind = gc.savekind;
1419 gc.cont.fcn = uentry_undefined;
1420 gc.savekind = CX_ERROR;
1423 bool context_inFunctionDeclaration (void)
1425 return (gc.kind == CX_FCNDECLARATION);
1430 context_enterMacro (/*@observer@*/ uentry e)
1432 context_enterFunction (e);
1433 gc.kind = CX_MACROFCN;
1437 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1439 llassert (uentry_isFunction (e));
1440 context_enterFunction (e);
1441 gc.kind = CX_UNKNOWNMACRO;
1444 void context_enterAndClause (exprNode e)
1447 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1448 pushClause (ANDCLAUSE);
1451 void context_enterOrClause (exprNode e)
1453 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1454 pushClause (ORCLAUSE);
1457 bool context_inDeepLoop (void)
1459 bool inLoop = FALSE;
1461 clauseStack_elements (gc.clauses, el)
1463 if (clause_isLoop (el))
1472 } end_clauseStack_elements;
1477 bool context_inDeepSwitch (void)
1479 bool inLoop = FALSE;
1481 clauseStack_elements (gc.clauses, el)
1483 if (clause_isSwitch (el))
1492 } end_clauseStack_elements;
1497 bool context_inDeepLoopSwitch (void)
1499 bool inLoop = FALSE;
1501 clauseStack_elements (gc.clauses, el)
1503 if (clause_isBreakable (el))
1512 } end_clauseStack_elements;
1517 clause context_breakClause (void)
1519 clauseStack_elements (gc.clauses, el)
1521 if (clause_isSwitch (el))
1525 else if (clause_isLoop (el))
1533 } end_clauseStack_elements;
1538 clause context_nextBreakClause (void)
1540 bool hasOne = FALSE;
1542 clauseStack_elements (gc.clauses, el)
1544 if (clause_isBreakable (el))
1555 } end_clauseStack_elements;
1560 bool context_inConditional (void)
1562 clauseStack_elements (gc.clauses, el)
1565 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1566 ** to distinguish if from ? for this
1569 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1573 } end_clauseStack_elements;
1578 void context_exitAndClause (exprNode pred, exprNode tbranch)
1580 context_setJustPopped ();
1582 llassert (gc.inclause == ANDCLAUSE);
1584 usymtab_popAndBranch (pred, tbranch);
1585 clauseStack_pop (gc.clauses);
1586 gc.inclause = topClause (gc.clauses);
1589 void context_exitOrClause (exprNode pred, exprNode tbranch)
1591 context_setJustPopped ();
1593 llassert (gc.inclause == ORCLAUSE);
1595 usymtab_popOrBranch (pred, tbranch);
1596 clauseStack_pop (gc.clauses);
1597 gc.inclause = topClause (gc.clauses);
1600 static void context_enterCondClauseAux (clause cl)
1606 static void context_enterTrueAux (exprNode e, clause cl)
1609 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1613 void context_enterIterClause (void)
1615 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1618 void context_enterDoWhileClause (void)
1620 pushClause (DOWHILECLAUSE);
1623 void context_enterWhileClause (exprNode e)
1625 context_enterTrueAux (e, WHILECLAUSE);
1628 void context_enterForClause (exprNode e)
1630 context_enterTrueAux (e, FORCLAUSE);
1633 void context_enterTrueClause (exprNode e)
1635 context_enterTrueAux (e, TRUECLAUSE);
1638 void context_enterSwitch (exprNode e)
1641 usymtab_switchBranch (e);
1642 context_enterCondClauseAux (SWITCHCLAUSE);
1645 void context_exitSwitch (exprNode e, bool allpaths)
1647 usymtab_exitSwitch (e, allpaths);
1649 while (clause_isCase (clauseStack_top (gc.clauses)))
1651 clauseStack_pop (gc.clauses);
1654 context_exitClauseSimp ();
1657 void context_enterCaseClause (exprNode e)
1659 bool branch = FALSE;
1661 DPRINTF (("Enter case clause!"));
1663 branch = usymtab_newCase (exprNode_undefined, e);
1667 context_enterCondClauseAux (CASECLAUSE);
1671 static void context_enterFalseClauseAux (exprNode e, clause cl)
1674 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1676 clauseStack_switchTop (gc.clauses, cl);
1679 void context_enterFalseClause (exprNode e)
1682 context_enterFalseClauseAux (e, FALSECLAUSE);
1686 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1688 gc.kind = CX_MACROCONST;
1690 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1692 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1696 usymtab_enterScope ();
1697 sRef_enterFunctionScope ();
1699 gc.globs = globSet_undefined;
1700 globSet_clear (gc.globs_used);
1701 gc.mods = sRefSet_undefined;
1704 uentry context_getHeader (void)
1706 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1708 llfatalbug (message ("context_getHeader: bad call: %q",
1709 context_unparse ()));
1712 return (gc.cont.fcn);
1716 context_setFunctionDefined (fileloc loc)
1720 case CX_UNKNOWNMACRO:
1723 uentry_setFunctionDefined (gc.cont.fcn, loc);
1726 /* (not a bug because of parse errors) */
1732 context_enterFunction (/*@exposed@*/ uentry e)
1734 gc.kind = CX_FUNCTION;
1737 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1739 if (uentry_hasAccessType (e))
1741 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1749 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1750 typeIdSet_unparse (gc.acct)));
1752 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1754 gc.globs = uentry_getGlobs (e);
1755 globSet_clear (gc.globs_used);
1756 gc.mods = uentry_getMods (e);
1758 usymtab_enterFunctionScope (e);
1759 sRef_enterFunctionScope ();
1762 static bool context_checkStrictGlobals (void)
1764 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1767 static bool context_hasGlobs (void)
1769 if (context_inFunctionLike ())
1771 return (uentry_hasGlobs (gc.cont.fcn));
1779 static bool context_checkCheckedGlobals (void)
1781 return (context_getFlag (FLG_GLOBALS)
1782 && (context_getFlag (FLG_GLOBUNSPEC)
1783 || context_hasGlobs ()));
1786 static bool context_checkUnknownGlobals (void)
1788 /* should be uentry_hasGlobs ? */
1790 return (context_getFlag (FLG_ALLGLOBALS)
1791 && (context_getFlag (FLG_GLOBUNSPEC)
1792 || context_hasGlobs ()));
1795 static bool context_checkUncheckedGlobals (void)
1801 context_checkExport (uentry e)
1803 if (!gc.anyExports) return FALSE;
1805 if (uentry_isFunction (e)
1806 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1808 return context_maybeSet (FLG_EXPORTFCN);
1810 else if (uentry_isExpandedMacro (e))
1812 return context_maybeSet (FLG_EXPORTMACRO);
1814 else if (uentry_isVariable (e))
1816 return context_maybeSet (FLG_EXPORTVAR);
1818 else if (uentry_isEitherConstant (e))
1820 return context_maybeSet (FLG_EXPORTCONST);
1822 else if (uentry_isIter (e) || uentry_isEndIter (e))
1824 return context_maybeSet (FLG_EXPORTITER);
1826 else if (uentry_isDatatype (e))
1828 return context_maybeSet (FLG_EXPORTTYPE);
1837 context_checkGlobUse (uentry glob)
1840 if (uentry_isCheckedStrict (glob))
1842 return context_checkStrictGlobals ();
1844 else if (uentry_isChecked (glob))
1846 return context_checkCheckedGlobals ();
1848 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
1850 return context_checkUnknownGlobals ();
1854 llassert (uentry_isUnchecked (glob));
1856 return context_checkUncheckedGlobals ();
1861 context_checkAliasGlob (uentry glob)
1863 if (uentry_isCheckedStrict (glob))
1865 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
1867 else if (uentry_isChecked (glob))
1869 return gc.flags[FLG_CHECKEDGLOBALIAS];
1871 else if (uentry_isCheckMod (glob))
1873 return gc.flags[FLG_CHECKMODGLOBALIAS];
1877 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
1879 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
1883 bool context_checkInternalUse (void)
1885 if (context_hasGlobs ())
1887 return (gc.flags[FLG_INTERNALGLOBS]);
1891 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
1896 context_checkGlobMod (sRef el)
1898 uentry ue = sRef_getUentry (el);
1900 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
1902 if (uentry_isCheckedModify (ue)
1903 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
1905 if (context_hasMods ())
1907 return (gc.flags[FLG_MODGLOBS]);
1911 if (uentry_isCheckedStrict (ue))
1913 return (gc.flags[FLG_MODGLOBSUNSPEC]);
1917 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
1923 if (context_hasMods ())
1925 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
1935 context_usedGlobal (/*@exposed@*/ sRef el)
1937 if (!globSet_member (gc.globs_used, el))
1940 ** The first time a global is used in a function, we need
1941 ** to clear the derived sRefs, since they were set for the
1942 ** previous function.
1945 sRef_clearDerived (el);
1946 gc.globs_used = globSet_insert (gc.globs_used, el);
1950 /*@observer@*/ sRefSet
1951 context_modList (void)
1957 context_globAccess (sRef s)
1959 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
1960 return (globSet_member (gc.globs, s));
1964 context_hasAccess (typeId t)
1966 if (context_inFunctionLike ())
1968 DPRINTF (("Access %d / %s",
1969 t, typeIdSet_unparse (gc.acct)));
1970 return (typeIdSet_member (gc.acct, t));
1974 return (context_hasFileAccess (t));
1979 context_hasFileAccess (typeId t)
1981 return (typeIdSet_member (gc.facct, t));
1985 context_unparseAccess (void)
1987 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
1988 typeIdSet_unparse (gc.facct)));
1992 context_unparseClauses (void)
1994 return (clauseStack_unparse (gc.clauses));
1998 context_couldHaveAccess (typeId t)
2000 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2002 return (typeIdSet_member (gc.acct, t));
2006 return (typeIdSet_member (gc.facct, t));
2011 context_getRetType (void)
2013 ctype f = ctype_undefined;
2015 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2017 f = uentry_getType (gc.cont.fcn);
2019 else if (gc.kind == CX_UNKNOWNMACRO)
2021 return ctype_unknown;
2025 llcontbuglit ("context_getRetType: not in a function context");
2026 return ctype_unknown;
2029 if (!ctype_isFunction (f))
2031 if (ctype_isKnown (f))
2033 llbuglit ("context_getRetType: not a function");
2036 return ctype_unknown;
2038 return (ctype_getReturnType (f));
2042 context_hasMods (void)
2044 if (context_inFunctionLike ())
2046 return (uentry_hasMods (gc.cont.fcn));
2055 context_exitAllClauses (void)
2057 while (!clauseStack_isEmpty (gc.clauses))
2059 clause el = clauseStack_top (gc.clauses);
2062 if (clause_isNone (el))
2064 usymtab_quietExitScope (g_currentloc);
2065 clauseStack_pop (gc.clauses);
2069 context_exitClausePlain ();
2073 clauseStack_clear (gc.clauses);
2074 gc.inclause = NOCLAUSE;
2078 context_exitAllClausesQuiet (void)
2080 while (!clauseStack_isEmpty (gc.clauses))
2082 clause el = clauseStack_top (gc.clauses);
2085 usymtab_quietExitScope (g_currentloc);
2086 clauseStack_pop (gc.clauses);
2089 clauseStack_clear (gc.clauses);
2090 gc.inclause = NOCLAUSE;
2094 void context_exitClauseSimp (void)
2097 context_setJustPopped ();
2098 clauseStack_pop (gc.clauses);
2099 gc.inclause = topClause (gc.clauses);
2103 void context_exitCaseClause (void)
2105 context_setJustPopped ();
2106 usymtab_popCaseBranch ();
2107 clauseStack_pop (gc.clauses);
2108 gc.inclause = topClause (gc.clauses);
2112 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2114 context_setJustPopped ();
2115 /*@i32 was makeAlt */
2116 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2117 clauseStack_pop (gc.clauses);
2118 gc.inclause = topClause (gc.clauses);
2121 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2123 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2125 if (gc.inclause != TRUECLAUSE)
2127 llparseerror (cstring_makeLiteral
2128 ("Likely parse error. Conditional clauses are inconsistent."));
2132 context_setJustPopped ();
2133 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2134 clauseStack_pop (gc.clauses);
2135 gc.inclause = topClause (gc.clauses);
2138 void context_exitIterClause (exprNode body)
2140 llassert (gc.inclause == ITERCLAUSE);
2142 context_setJustPopped ();
2144 if (context_getFlag (FLG_LOOPEXEC))
2146 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2150 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2153 clauseStack_pop (gc.clauses);
2154 gc.inclause = topClause (gc.clauses);
2157 static void context_popCase (void) {
2159 ** If we are exiting an outer clause, sometimes still in a switch case.
2173 DPRINTF (("Popping case clause: %s",
2174 clauseStack_unparse (gc.clauses)));
2176 if (gc.inclause == CASECLAUSE) {
2177 context_exitCaseClause ();
2181 void context_exitWhileClause (exprNode pred, exprNode body)
2183 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2187 if (gc.inclause != WHILECLAUSE) {
2188 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2189 clauseStack_unparse (gc.clauses)));
2192 llassert (gc.inclause == WHILECLAUSE);
2194 context_setJustPopped ();
2198 ** predicate must be false after while loop (unless there are breaks)
2201 if (context_getFlag (FLG_LOOPEXEC))
2203 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2207 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2211 usymtab_addGuards (invGuards);
2212 guardSet_free (invGuards);
2214 clauseStack_pop (gc.clauses);
2215 gc.inclause = topClause (gc.clauses);
2218 void context_exitDoWhileClause (exprNode pred)
2220 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2222 if (gc.inclause == CASECLAUSE) {
2223 /* handle Duff's device */
2224 clauseStack_pop (gc.clauses);
2225 gc.inclause = topClause (gc.clauses);
2228 llassert (gc.inclause == DOWHILECLAUSE);
2230 context_setJustPopped ();
2233 usymtab_addGuards (invGuards);
2234 guardSet_free (invGuards);
2236 clauseStack_pop (gc.clauses);
2237 gc.inclause = topClause (gc.clauses);
2240 void context_exitForClause (exprNode forPred, exprNode body)
2242 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2244 llassert (gc.inclause == FORCLAUSE);
2245 context_setJustPopped ();
2248 ** predicate must be false after while loop (unless there are breaks)
2251 if (context_getFlag (FLG_LOOPEXEC))
2253 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2257 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2260 usymtab_addGuards (invGuards);
2261 guardSet_free (invGuards);
2262 clauseStack_pop (gc.clauses);
2263 gc.inclause = topClause (gc.clauses);
2266 static void context_exitClausePlain (void)
2268 llassert (gc.inclause != NOCLAUSE);
2270 if (gc.inclause == FALSECLAUSE)
2272 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2276 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2280 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2282 context_setJustPopped ();
2284 if (gc.inclause == FALSECLAUSE)
2286 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2288 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2290 clauseStack_pop (gc.clauses);
2291 gc.inclause = topClause (gc.clauses);
2295 context_exitTrueClause (pred, tbranch);
2300 context_returnFunction (void)
2302 usymtab_checkFinalScope (TRUE);
2306 context_exitFunction (void)
2308 if (!context_inFunction () && !context_inMacroConstant ()
2309 && !context_inMacroUnknown ()
2310 && !context_inIterDef () && !context_inIterEnd ())
2313 ** not a bug because of parse errors
2318 if (context_inMacro () && usymtab_inFunctionScope ())
2320 usymtab_exitScope (exprNode_undefined);
2323 if (uentry_hasGlobs (gc.cont.fcn))
2325 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2329 if (uentry_hasMods (gc.cont.fcn))
2331 if (context_getFlag (FLG_MUSTMOD))
2333 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2337 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2340 ** clear file static modifies
2343 /* do this first to get unused error messages */
2345 usymtab_exitScope (exprNode_undefined);
2346 sRef_exitFunctionScope ();
2348 gc.showfunction = FALSE;
2349 gc.kind = CX_GLOBAL;
2350 gc.cont.glob = TRUE;
2352 gc.globs = globSet_new ();
2353 globSet_clear (gc.globs_used);
2354 gc.mods = sRefSet_new ();
2357 llassert (clauseStack_isEmpty (gc.clauses));
2358 llassert (gc.inclause == NOCLAUSE);
2362 context_quietExitFunction (void)
2364 while (gc.kind == CX_INNER)
2366 context_exitInnerPlain ();
2369 if (!context_inFunction () && !context_inMacroConstant () && !context_inMacroUnknown ()
2370 && !context_inIterDef () && !context_inIterEnd ())
2375 usymtab_quietExitScope (g_currentloc);
2377 gc.showfunction = FALSE;
2378 gc.kind = CX_GLOBAL;
2379 gc.cont.glob = TRUE;
2381 gc.globs = globSet_new ();
2382 globSet_clear (gc.globs_used);
2383 gc.mods = sRefSet_new ();
2385 sRef_exitFunctionScope ();
2389 /*@observer@*/ uentryList
2390 context_getParams (void)
2392 if (context_inFunctionLike ())
2394 return (uentry_getParams (gc.cont.fcn));
2398 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2399 return uentryList_undefined;
2403 /*@observer@*/ globSet
2404 context_getUsedGlobs (void)
2406 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2407 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2409 return (gc.globs_used);
2413 context_moduleName ()
2415 return (fileloc_getBase (g_currentloc));
2418 /*@observer@*/ globSet
2419 context_getGlobs (void)
2421 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2422 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2428 context_addBoolAccess (void)
2430 cstring bname = context_getString (FLG_BOOLTYPE);
2431 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2433 addModuleAccess (cstring_copy (bname), boolt);
2435 /* for sys/types (perhaps, this is bogus!) */
2436 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2441 context_canAccessBool (void)
2448 static typeId boolType = typeId_invalid;
2450 if (typeId_isInvalid (boolType))
2452 boolType = usymtab_getTypeId (context_getBoolName ());
2455 if (typeId_isInvalid (boolType)) {
2458 return (typeIdSet_member (gc.acct, boolType));
2463 /* evs 2000-07-25: old version - replaced */
2466 context_boolImplementationType () {
2467 /* For now, this is bogus! */
2472 context_canAccessBool (void)
2474 static typeId boolType = typeId_invalid;
2476 if (typeId_isInvalid (boolType))
2478 boolType = usymtab_getTypeId (context_getBoolName ());
2481 if (!typeId_isInvalid (boolType))
2483 return context_hasAccess (boolType);
2494 context_setMessageAnnote (/*@only@*/ cstring s)
2496 llassert (cstring_isUndefined (gc.msgAnnote));
2501 context_hasMessageAnnote (void)
2503 return (cstring_isDefined (gc.msgAnnote));
2507 context_clearMessageAnnote (void)
2509 if (cstring_isDefined (gc.msgAnnote))
2511 cstring_free (gc.msgAnnote);
2512 gc.msgAnnote = cstring_undefined;
2517 context_getMessageAnnote (void)
2519 cstring st = gc.msgAnnote;
2521 gc.msgAnnote = cstring_undefined;
2526 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2528 llassert (sRef_isInvalid (gc.aliasAnnote));
2529 llassert (!sRef_sameName (s, t));
2531 gc.aliasAnnoteAls = t;
2535 context_hasAliasAnnote (void)
2537 return (sRef_isValid (gc.aliasAnnote));
2541 context_clearAliasAnnote (void)
2543 gc.aliasAnnote = sRef_undefined;
2547 context_getAliasAnnote (void)
2549 sRef ret = gc.aliasAnnote;
2550 sRef als = gc.aliasAnnoteAls;
2552 llassert (sRef_isValid (ret) && sRef_isValid (als));
2554 gc.aliasAnnote = sRef_undefined;
2555 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2559 context_recordFileModifies (sRefSet mods)
2561 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2565 context_recordFileGlobals (globSet mods)
2567 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2568 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2572 context_setCommentMarkerChar (char c)
2574 llassert (c != '\0');
2576 context_setValue (FLG_COMMENTCHAR, (int) c);
2580 context_getCommentMarkerChar (void)
2582 return ((char) context_getValue (FLG_COMMENTCHAR));
2586 context_setValue (flagcode flag, int val)
2588 int index = flagcode_valueIndex (flag);
2590 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2598 llerror_flagWarning (message ("Value for %s must be a positive "
2599 "number (given %d)",
2600 flagcode_unparse (flag), val));
2603 if (flag == FLG_LINELEN && val < MINLINELEN)
2605 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2606 flagcode_unparse (flag),
2612 case FLG_INCLUDENEST:
2613 case FLG_CONTROLNESTDEPTH:
2614 case FLG_STRINGLITERALLEN:
2615 case FLG_NUMSTRUCTFIELDS:
2616 case FLG_NUMENUMMEMBERS:
2617 case FLG_INDENTSPACES:
2621 llerror_flagWarning (message ("Value for %s must be a non-negative "
2622 "number (given %d)",
2623 flagcode_unparse (flag), val));
2632 gc.values[index] = val;
2636 context_setValueAndFlag (flagcode flag, int val)
2638 gc.flags[flag] = TRUE;
2639 context_setValue (flag, val);
2643 context_getValue (flagcode flag)
2645 int index = flagcode_valueIndex (flag);
2647 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2648 return (gc.values[index]);
2652 context_getCounter (flagcode flag)
2654 int index = flagcode_valueIndex (flag);
2656 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2657 return (gc.counters[index]);
2661 context_incCounter (flagcode flag)
2663 int index = flagcode_valueIndex (flag);
2665 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2667 gc.counters[index]++;
2671 context_decCounter (flagcode flag)
2673 int index = flagcode_valueIndex (flag);
2675 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2676 gc.counters[index]--;
2679 bool context_showFunction (void)
2681 return (gc.showfunction);
2685 context_setString (flagcode flag, cstring val)
2687 int index = flagcode_stringIndex (flag);
2689 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2691 if (flag == FLG_SYSTEMDIRS)
2693 llassert (cstring_isDefined (val));
2695 if (cstring_firstChar (val) == '\"')
2698 cstring tval = cstring_copy (cstring_suffix (val, 1));
2700 if (cstring_lastChar (tval) != '\"')
2702 int n = cstring_length (tval) - 1;
2704 while (isspace ((int) cstring_getChar (tval, n)))
2709 if (cstring_getChar (tval, n) != '\"')
2711 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2715 cstring otval = tval;
2716 tval = cstring_prefix (tval, n);
2717 cstring_free (otval);
2721 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2722 DPRINTF (("val = %s", val));
2723 cstring_free (tval);
2724 cstring_free (oval);
2728 if (flag == FLG_TMPDIR)
2730 llassert (cstring_isDefined (val));
2732 if (cstring_length (val) == 0)
2735 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2737 else if (cstring_lastChar (val) != CONNECTCHAR)
2739 val = cstring_appendChar (val, CONNECTCHAR);
2747 if (cstring_length (val) >= 1
2748 && cstring_firstChar (val) == '"')
2750 llerror_flagWarning (message
2751 ("setting %s to string beginning with \". You probably "
2752 "don't meant to have the \"'s.",
2753 flagcode_unparse (flag)));
2756 if (flag == FLG_BOOLTYPE)
2761 gc.strings[index] = val;
2764 static /*@exposed@*/ cstring
2765 context_exposeString (flagcode flag)
2767 int index = flagcode_stringIndex (flag);
2769 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2770 return (gc.strings[index]);
2774 context_getString (flagcode flag)
2776 return (context_exposeString (flag));
2780 context_resetErrors (void)
2785 void context_initMod (void)
2786 /*@globals undef gc; @*/
2788 gc.kind = CX_GLOBAL;
2789 gc.savekind = CX_ERROR;
2790 gc.instandardlib = FALSE;
2793 gc.linesprocessed = 0;
2794 gc.speclinesprocessed = 0;
2795 gc.insuppressregion = FALSE;
2796 gc.macroMissingParams = FALSE;
2797 gc.preprocessing = FALSE;
2798 gc.incommandline = FALSE;
2799 gc.mc = macrocache_create ();
2801 gc.maxmods = DEFAULTMAXMODS;
2802 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2804 gc.library = FLG_ANSILIB;
2806 gc.locstack = filelocStack_new ();
2807 gc.modrecs = sRefSetList_undefined;
2808 gc.anyExports = FALSE;
2810 gc.ftab = fileTable_create ();
2811 gc.msgLog = messageLog_new ();
2812 gc.inimport = FALSE;
2813 gc.inDerivedFile = FALSE;
2814 gc.inheader = FALSE;
2815 gc.markers = flagMarkerList_new ();
2816 gc.cont.glob = TRUE;
2817 gc.showfunction = FALSE;
2818 gc.msgAnnote = cstring_undefined;
2819 gc.aliasAnnote = sRef_undefined;
2820 gc.aliasAnnoteAls = sRef_undefined;
2821 gc.boolType = ctype_bool;
2822 gc.mods = sRefSet_new ();
2824 gc.saveloc = fileloc_undefined;
2826 gc.inmacrocache = FALSE;
2827 gc.inclause = NOCLAUSE;
2828 gc.clauses = clauseStack_new ();
2829 gc.globs = globSet_new ();
2830 gc.nacct = typeIdSet_emptySet ();
2831 gc.acct = typeIdSet_emptySet ();
2832 gc.facct = typeIdSet_emptySet ();
2833 gc.savedFlags = FALSE;
2834 gc.pushloc = fileloc_undefined;
2835 gc.protectVars = FALSE;
2836 gc.justpopped = FALSE;
2837 gc.isNullGuarded = NO;
2838 gc.globs_used = globSet_undefined;
2842 gc.setGlobally[code] = FALSE;
2843 gc.setLocally[code] = FALSE;
2844 } end_allFlagCodes ;
2848 context_resetAllFlags ();
2849 assertSet (gc.flags); /* Can't use global in defines */
2850 assertSet (gc.saveflags);
2851 assertSet (gc.values);
2852 assertSet (gc.strings);
2854 conext_resetAllCounters ();
2855 assertSet (gc.counters);
2857 context_setMode (DEFAULT_MODE);
2859 gc.stateTable = metaStateTable_create ();
2860 gc.annotTable = annotationTable_create ();
2862 gc.inFunctionHeader = FALSE;
2864 DPRINTF (("Annotations: \n%s",
2865 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
2866 DPRINTF (("State: \n%s",
2867 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
2872 context_typeofZero (void)
2874 ctype ct = ctype_int;
2876 if (context_getFlag (FLG_ZEROPTR))
2878 ct = ctype_makeConj (ct, ctype_voidPointer);
2881 if (context_getFlag (FLG_ZEROBOOL)) {
2882 ct = ctype_makeConj (ct, ctype_bool);
2889 context_typeofOne (void)
2891 ctype ct = ctype_int;
2893 /* 1 is on longer a bool (was before 2.4)
2894 if (!context_getFlag (FLG_ABSTRACTBOOL))
2896 ct = ctype_makeConj (ct, ctype_bool);
2904 context_unparse (void)
2911 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
2914 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
2917 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
2920 s = message ("Inner Context:%q", fileloc_unparse (g_currentloc));
2923 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
2924 uentry_unparse (gc.cont.fcn),
2925 fileloc_unparse (g_currentloc),
2926 typeIdSet_unparse (gc.acct),
2927 sRefSet_unparse (gc.mods));
2930 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
2932 case CX_UNKNOWNMACRO:
2933 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
2936 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
2939 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
2942 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
2945 s = message ("Un-unparseable context: %d", (int) gc.kind);
2949 s = message ("%q\naccess: %q", s, context_unparseAccess ());
2954 context_currentFunctionType (void)
2956 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2958 return (uentry_getType (gc.cont.fcn));
2960 else if (gc.kind == CX_INNER)
2962 llcontbuglit ("context_currentFunctionType: inner context");
2963 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
2964 return (context_currentFunctionType ());
2968 llcontbuglit ("context_currentFunctionType: not in function");
2969 return (ctype_undefined);
2974 context_enterInnerContext (void)
2976 if (gc.kind == CX_GLOBAL)
2981 else if (gc.kind == CX_INNER)
2991 usymtab_enterScope ();
2992 pushClause (NOCLAUSE);
2996 context_exitInnerPlain (void) /*@modifies gc;@*/
2998 context_exitInner (exprNode_undefined);
3002 context_exitInner (exprNode exp)
3005 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3006 ("inclause = %s", clause_nameTaken (gc.inclause)));
3008 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3009 gc.inclause = topClause (gc.clauses);
3011 if (gc.kind == CX_INNER)
3013 if (--gc.cont.cdepth == 0)
3015 gc.kind = CX_GLOBAL;
3016 gc.cont.glob = TRUE;
3021 if (gc.kind == CX_GLOBAL)
3023 llcontbuglit ("Attempt to exit global context");
3028 usymtab_exitScope (exp);
3033 context_enterStructInnerContext (void)
3035 if (gc.kind == CX_GLOBAL)
3040 else if (gc.kind == CX_INNER)
3049 usymtab_enterScope ();
3053 context_exitStructInnerContext (void)
3055 if (gc.kind == CX_INNER)
3057 if (--gc.cont.cdepth == 0)
3059 gc.kind = CX_GLOBAL;
3060 gc.cont.glob = TRUE;
3065 if (gc.kind == CX_GLOBAL)
3067 llcontbuglit ("Attempt to exit global context");
3072 usymtab_exitScope (exprNode_undefined);
3076 context_exitInnerSafe (void)
3079 if (gc.kind == CX_INNER)
3081 if (--gc.cont.cdepth == 0)
3086 else if (gc.kind == CX_GLOBAL)
3088 llcontbuglit ("Attempt to exit global context");
3093 if (usymtab_inDeepScope ())
3095 usymtab_exitScope (exprNode_undefined);
3101 void setModuleAccess (void)
3103 gc.facct = typeIdSet_emptySet ();
3105 if (fileId_isValid (currentFile ()))
3107 cstring baseName = fileloc_getBase (g_currentloc);
3109 if (context_getFlag (FLG_ACCESSFILE))
3111 if (usymtab_existsType (baseName))
3113 gc.facct = typeIdSet_insert (gc.facct,
3114 usymtab_getTypeId (baseName));
3122 if (context_getFlag (FLG_ACCESSMODULE))
3125 bool hasaccess = FALSE;
3127 for (i = 0; i < gc.nmods; i++)
3129 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3131 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3140 gc.inheader = fileId_isHeader (currentFile ());
3144 llcontbuglit ("Current file not defined\n");
3145 gc.facct = typeIdSet_emptySet ();
3147 gc.inheader = FALSE;
3150 /* 17 Jan 1995: forgot to clear nacct */
3152 gc.nacct = typeIdSet_emptySet ();
3156 context_enterFileAux (void)
3162 context_enterFile (void)
3164 context_enterFileAux ();
3165 usymtab_enterFile ();
3169 context_enterMacroFile (void)
3171 context_enterFileAux ();
3175 context_inFunction (void)
3177 kcontext ck = gc.kind;
3179 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3183 context_inFunctionLike (void)
3185 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3186 || gc.kind == CX_FCNDECLARATION
3187 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3191 context_inRealFunction (void)
3193 kcontext ck = gc.kind;
3195 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3199 context_processAllMacros (void)
3201 usymtab_enterFile ();
3203 gc.inmacrocache = TRUE;
3204 macrocache_processUndefinedElements (gc.mc);
3206 usymtab_exitFile ();
3208 gc.inmacrocache = FALSE;
3209 macrocache_finalize ();
3213 ** this happens once at the end of each C file
3215 ** check each Macro that was defined in current file.c or current file.h
3220 context_processMacros (void)
3222 if (fileId_isValid (currentFile ()))
3225 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileName (currentFile ())));
3227 gc.inmacrocache = TRUE;
3229 DPRINTF (("Processing macros: %s", cbase));
3230 lastfl = macrocache_processFileElements (gc.mc, cbase);
3231 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3233 cstring_free (cbase);
3235 if (fileloc_isDefined (lastfl))
3237 g_currentloc = fileloc_update (g_currentloc, lastfl);
3241 gc.inmacrocache = FALSE;
3246 context_processingMacros (void)
3248 return (gc.inmacrocache);
3252 context_exitCFile (void)
3254 if (gc.kind != CX_GLOBAL)
3257 (cstring_makeLiteral ("File ended outside global scope"));
3260 if (gc.insuppressregion)
3262 /* gack...don't reverse the order of these lines! ;-> */
3263 gc.insuppressregion = FALSE;
3264 llerrorlit (FLG_SYNTAX,
3265 "File ended in ignore errors region, "
3266 "possible missing /*@end*/");
3269 /* fix up parse errors */
3271 while (!usymtab_inFileScope ())
3273 usymtab_quietExitScope (g_currentloc);
3277 ** Clear the file-specific modifies information.
3280 sRefSetList_elements (gc.modrecs, mods)
3282 sRefSet_clearStatics (mods);
3283 } end_sRefSetList_elements ;
3285 sRefSetList_clear (gc.modrecs);
3287 context_processMacros ();
3290 usymtab_exitFile ();
3292 gc.inDerivedFile = FALSE;
3293 filelocStack_clear (gc.locstack);
3295 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3297 gc.cont.glob = TRUE;
3301 context_restoreFlagSettings ();
3302 gc.savedFlags = FALSE;
3306 DPRINTF (("After exiting file: "));
3307 usymtab_printAll ();
3312 context_exitMacroCache (void)
3314 if (gc.kind != CX_GLOBAL)
3316 if (context_inMacro ())
3317 /* this is okay, file could end without newline in macro */
3319 DPRINTF (("Still in macro: %s",
3320 context_unparse ()));
3321 context_exitFunction ();
3325 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3326 context_unparse ()));
3327 gc.kind = CX_GLOBAL;
3332 ** no longer valid here
3333 ** if (gc.insuppressregion)
3335 ** gc.insuppressregion = FALSE;
3336 ** llerror ("File ended in ignore errors region, possible missing @");
3340 gc.cont.glob = TRUE;
3344 context_saveLocation (void)
3346 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3347 fileloc_free (gc.saveloc);
3350 gc.saveloc = fileloc_copy (g_currentloc);
3354 context_getSaveLocation (void)
3356 fileloc fl = gc.saveloc;
3358 gc.saveloc = fileloc_undefined;
3362 /*@observer@*/ cstring
3363 context_inFunctionName (void)
3365 if (gc.kind == CX_FUNCTION
3366 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3367 || gc.kind == CX_MACROCONST
3368 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3370 return (uentry_rawName (gc.cont.fcn));
3374 llcontbuglit ("context_inFunctionName: not in function");
3375 return (cstring_undefined);
3380 context_userSetFlag (flagcode f, bool b)
3382 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3384 if (f == FLG_NEVERINCLUDE && b)
3386 if (gc.flags[FLG_EXPORTHEADER])
3388 llerror_flagWarning (cstring_makeLiteral
3389 ("setting +neverinclude after +exportheader. "
3390 "Turning off exportheader, since headers are not checked "
3391 "when +neverinclude is used."));
3393 gc.flags[FLG_EXPORTHEADER] = FALSE;
3398 if (f == FLG_EXPORTHEADER && b)
3400 if (gc.flags[FLG_NEVERINCLUDE])
3402 llerror_flagWarning (cstring_makeLiteral
3403 ("setting +exportheader after +neverinclude. "
3404 "Not setting exportheader, since headers are not checked "
3405 "when +neverinclude is used."));
3406 gc.flags[FLG_EXPORTHEADER] = FALSE;
3412 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3414 bool lastsetting = context_getFlag (f);
3416 if (bool_equal (lastsetting, b)
3417 && !flagcode_isSpecialFlag (f)
3418 && !flagcode_isIdemFlag (f)
3419 && !flagcode_hasArgument (f))
3421 llerror_flagWarning (message ("setting %s%s redundant with current value",
3422 cstring_makeLiteralTemp (b ? "+" : "-"),
3423 flagcode_unparse (f)));
3427 if (flagcode_isWarnUseFlag (f) && b)
3429 if (!context_getFlag (FLG_WARNUSE))
3431 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3432 flagcode_unparse (f)));
3438 if (flagcode_isLibraryFlag (f))
3440 if (gc.library != FLG_ANSILIB
3443 llerror_flagWarning (message ("selecting library %s after library %s was "
3444 "selected (only one library may be used)",
3445 flagcode_unparse (f),
3446 flagcode_unparse (gc.library)));
3449 if (f == FLG_UNIXLIB)
3451 if (context_getFlag (FLG_WARNUNIXLIB))
3453 llerror_flagWarning (cstring_makeLiteral
3454 ("selecting unix library. Unix library is "
3455 "ad hoc addition to POSIX library. Recommend "
3456 "use +posixlib to select POSIX library instead. "
3457 "Use -warnunixlib to suppress this message."));
3464 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3466 llerror_flagWarning (message
3467 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3468 flagcode_unparse (f)));
3471 gc.setGlobally[f] = TRUE;
3472 context_setFlag (f, b);
3476 context_fileSetFlag (flagcode f, ynm set)
3480 context_saveFlagSettings ();
3483 if (ynm_isOff (set))
3485 context_setFlagAux (f, FALSE, TRUE, FALSE);
3487 else if (ynm_isOn (set))
3489 context_setFlagAux (f, TRUE, TRUE, FALSE);
3490 gc.setLocally[f] = TRUE;
3494 context_restoreFlag (f);
3499 context_restoreFlag (flagcode f)
3506 message ("Attempt to restore flag %s when no file scope flags "
3508 flagcode_unparse (f)),
3513 context_addFlagMarker (f, MAYBE);
3514 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3520 context_setFlag (flagcode f, bool b)
3522 context_setFlagAux (f, b, FALSE, FALSE);
3526 context_setFlagTemp (flagcode f, bool b)
3528 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3533 # define DOSET(ff,b) \
3534 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3535 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3536 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3537 gc.flags[ff] = b; } while (FALSE)
3540 context_setFlagAux (flagcode f, bool b, bool
3541 inFile, /*@unused@*/ bool isRestore)
3543 DPRINTF (("set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3545 if (f == FLG_USESTDERR)
3548 g_msgstream = stderr;
3550 g_msgstream = stdout;
3555 ** Removed test for special flags.
3558 if (flagcode_isIdemFlag (f))
3567 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3569 if (b) /* Turing higher level on, turns on all lower levels */
3573 case FLG_ITS4MOSTRISKY:
3574 DOSET (FLG_ITS4VERYRISKY, b);
3576 case FLG_ITS4VERYRISKY:
3577 DOSET (FLG_ITS4RISKY, b);
3580 DOSET (FLG_ITS4MODERATERISK, b);
3582 case FLG_ITS4MODERATERISK:
3583 DOSET (FLG_ITS4LOWRISK, b);
3585 case FLG_ITS4LOWRISK:
3590 else /* Turning level off, turns off all higher levels */
3594 case FLG_ITS4LOWRISK:
3595 DOSET (FLG_ITS4MODERATERISK, b);
3597 case FLG_ITS4MODERATERISK:
3598 DOSET (FLG_ITS4RISKY, b);
3601 DOSET (FLG_ITS4VERYRISKY, b);
3603 case FLG_ITS4VERYRISKY:
3604 DOSET (FLG_ITS4MOSTRISKY, b);
3606 case FLG_ITS4MOSTRISKY:
3616 DOSET (FLG_ALLEMPTY, b);
3617 DOSET (FLG_IFEMPTY, b);
3618 DOSET (FLG_WHILEEMPTY, b);
3619 DOSET (FLG_FOREMPTY, b);
3622 DOSET (FLG_PREDBOOL, b);
3623 DOSET (FLG_PREDBOOLINT, b);
3624 DOSET (FLG_PREDBOOLPTR, b);
3625 DOSET (FLG_PREDBOOLOTHERS, b);
3628 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3629 DOSET (FLG_CHECKEDGLOBALIAS, b);
3630 DOSET (FLG_CHECKMODGLOBALIAS, b);
3631 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3634 DOSET (FLG_ALLBLOCK, b);
3635 DOSET (FLG_IFBLOCK, b);
3636 DOSET (FLG_WHILEBLOCK, b);
3637 DOSET (FLG_FORBLOCK, b);
3651 DOSET (FLG_GRAMMAR, b);
3653 case FLG_CODEIMPONLY:
3654 DOSET (FLG_CODEIMPONLY, b);
3655 DOSET (FLG_GLOBIMPONLY, b);
3656 DOSET (FLG_RETIMPONLY, b);
3657 DOSET (FLG_STRUCTIMPONLY, b);
3659 case FLG_SPECALLIMPONLY:
3660 DOSET (FLG_SPECALLIMPONLY, b);
3661 DOSET (FLG_SPECGLOBIMPONLY, b);
3662 DOSET (FLG_SPECRETIMPONLY, b);
3663 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3665 case FLG_ALLIMPONLY:
3666 DOSET (FLG_ALLIMPONLY, b);
3667 DOSET (FLG_GLOBIMPONLY, b);
3668 DOSET (FLG_RETIMPONLY, b);
3669 DOSET (FLG_STRUCTIMPONLY, b);
3670 DOSET (FLG_SPECGLOBIMPONLY, b);
3671 DOSET (FLG_SPECRETIMPONLY, b);
3672 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3674 case FLG_ANSILIMITS:
3675 DOSET (FLG_ANSILIMITS, b);
3676 DOSET (FLG_CONTROLNESTDEPTH, b);
3677 DOSET (FLG_STRINGLITERALLEN, b);
3678 DOSET (FLG_INCLUDENEST, b);
3679 DOSET (FLG_NUMSTRUCTFIELDS, b);
3680 DOSET (FLG_NUMENUMMEMBERS, b);
3684 context_setValue (FLG_CONTROLNESTDEPTH, DEFAULT_CONTROLNESTDEPTH);
3685 context_setValue (FLG_STRINGLITERALLEN, DEFAULT_STRINGLITERALLEN);
3686 context_setValue (FLG_INCLUDENEST, DEFAULT_INCLUDENEST);
3687 context_setValue (FLG_NUMSTRUCTFIELDS, DEFAULT_NUMSTRUCTFIELDS);
3688 context_setValue (FLG_NUMENUMMEMBERS, DEFAULT_NUMENUMMEMBERS);
3691 case FLG_EXTERNALNAMELEN:
3692 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3693 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3695 case FLG_INTERNALNAMELEN:
3696 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3697 DOSET (FLG_INTERNALNAMELEN, TRUE);
3699 case FLG_EXTERNALNAMECASEINSENSITIVE:
3700 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3702 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3704 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3705 context_setValue (FLG_EXTERNALNAMELEN, 0);
3708 case FLG_INTERNALNAMECASEINSENSITIVE:
3709 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3711 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3713 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3714 context_setValue (FLG_INTERNALNAMELEN, 0);
3717 case FLG_INTERNALNAMELOOKALIKE:
3718 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3720 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3722 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3723 context_setValue (FLG_INTERNALNAMELEN, 0);
3727 DOSET (FLG_MODNOMODS, b);
3728 DOSET (FLG_MODGLOBSUNSPEC, b);
3729 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3732 DOSET (FLG_EXPORTVAR, b);
3733 DOSET (FLG_EXPORTFCN, b);
3734 DOSET (FLG_EXPORTTYPE, b);
3735 DOSET (FLG_EXPORTMACRO, b);
3736 DOSET (FLG_EXPORTCONST, b);
3737 gc.anyExports = TRUE;
3740 DOSET (FLG_RETEXPOSE, b);
3741 DOSET (FLG_ASSIGNEXPOSE, b);
3742 DOSET (FLG_CASTEXPOSE, b);
3745 DOSET (FLG_RETVALBOOL, b);
3746 DOSET (FLG_RETVALINT, b);
3747 DOSET (FLG_RETVALOTHER, b);
3752 DOSET (FLG_EXPORTLOCAL, FALSE);
3753 DOSET (FLG_DECLUNDEF, FALSE);
3754 DOSET (FLG_SPECUNDEF, FALSE);
3755 DOSET (FLG_TOPUNUSED, FALSE);
3759 DOSET (FLG_LOOPLOOPBREAK, b);
3760 DOSET (FLG_LOOPSWITCHBREAK, b);
3761 DOSET (FLG_SWITCHLOOPBREAK, b);
3762 DOSET (FLG_SWITCHSWITCHBREAK, b);
3763 DOSET (FLG_LOOPLOOPCONTINUE, b);
3764 DOSET (FLG_DEEPBREAK, b);
3767 DOSET (FLG_ACCESSMODULE, b);
3768 DOSET (FLG_ACCESSFILE, b);
3769 DOSET (FLG_ACCESSCZECH, b);
3772 DOSET (FLG_ALLMACROS, b);
3773 DOSET (FLG_FCNMACROS, b);
3774 DOSET (FLG_CONSTMACROS, b);
3777 if (b) { DOSET (FLG_ACCESSCZECH, b); }
3778 DOSET (FLG_CZECHFUNCTIONS, b);
3779 DOSET (FLG_CZECHVARS, b);
3780 DOSET (FLG_CZECHCONSTANTS, b);
3781 DOSET (FLG_CZECHTYPES, b);
3784 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
3785 DOSET (FLG_SLOVAKFUNCTIONS, b);
3786 DOSET (FLG_SLOVAKVARS, b);
3787 DOSET (FLG_SLOVAKCONSTANTS, b);
3788 DOSET (FLG_SLOVAKTYPES, b);
3790 case FLG_CZECHOSLOVAK:
3791 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
3792 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
3793 DOSET (FLG_CZECHOSLOVAKVARS, b);
3794 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
3795 DOSET (FLG_CZECHOSLOVAKTYPES, b);
3798 DOSET (FLG_NULLSTATE, b);
3799 DOSET (FLG_NULLDEREF, b);
3800 DOSET (FLG_NULLASSIGN, b);
3801 DOSET (FLG_NULLPASS, b);
3802 DOSET (FLG_NULLRET, b);
3805 DOSET (FLG_NULLSTATE, b);
3806 DOSET (FLG_NULLDEREF, b);
3807 DOSET (FLG_NULLASSIGN, b);
3808 DOSET (FLG_NULLPASS, b);
3809 DOSET (FLG_NULLRET, b);
3810 DOSET (FLG_COMPDEF, b);
3811 DOSET (FLG_COMPMEMPASS, b);
3812 DOSET (FLG_UNIONDEF, b);
3813 DOSET (FLG_MEMTRANS, b);
3814 DOSET (FLG_USERELEASED, b);
3815 DOSET (FLG_ALIASUNIQUE, b);
3816 DOSET (FLG_MAYALIASUNIQUE, b);
3817 DOSET (FLG_MUSTFREE, b);
3818 DOSET (FLG_MUSTDEFINE, b);
3819 DOSET (FLG_GLOBSTATE, b);
3820 DOSET (FLG_COMPDESTROY, b);
3821 DOSET (FLG_MUSTNOTALIAS, b);
3822 DOSET (FLG_MEMIMPLICIT, b);
3823 DOSET (FLG_BRANCHSTATE, b);
3824 /*@fallthrough@*/ /* also sets memtrans flags */
3826 DOSET (FLG_MEMTRANS, b);
3827 DOSET (FLG_EXPOSETRANS, b);
3828 DOSET (FLG_OBSERVERTRANS, b);
3829 DOSET (FLG_DEPENDENTTRANS, b);
3830 DOSET (FLG_NEWREFTRANS, b);
3831 DOSET (FLG_ONLYTRANS, b);
3832 DOSET (FLG_OWNEDTRANS, b);
3833 DOSET (FLG_FRESHTRANS, b);
3834 DOSET (FLG_SHAREDTRANS, b);
3835 DOSET (FLG_TEMPTRANS, b);
3836 DOSET (FLG_KEPTTRANS, b);
3837 DOSET (FLG_REFCOUNTTRANS, b);
3838 DOSET (FLG_STATICTRANS, b);
3839 DOSET (FLG_UNKNOWNTRANS, b);
3840 DOSET (FLG_KEEPTRANS, b);
3841 DOSET (FLG_IMMEDIATETRANS, b);
3848 if (b && !gc.anyExports
3849 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
3850 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
3851 || f == FLG_EXPORTCONST
3852 || f == FLG_EXPORTANY))
3854 gc.anyExports = TRUE;
3859 context_maybeSet (flagcode d)
3861 return (gc.flags[d] || gc.setLocally[d]);
3865 context_getFlag (flagcode d)
3867 return (gc.flags[d]);
3871 context_flagOn (flagcode f, fileloc loc)
3873 return (!context_suppressFlagMsg (f, loc));
3876 static void context_saveFlagSettings (void)
3878 gc.savedFlags = TRUE;
3879 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3880 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
3883 static void context_restoreFlagSettings (void)
3885 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3886 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
3887 gc.savedFlags = FALSE;
3890 void context_setFilename (fileId fid, int lineno)
3891 /*@globals fileloc g_currentloc;@*/
3892 /*@modifies g_currentloc@*/
3894 if (fileId_baseEqual (currentFile (), fid))
3901 fileloc_setColumn (g_currentloc, 0);
3903 if (fileloc_isSpecialFile (g_currentloc))
3905 gc.inDerivedFile = TRUE;
3908 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
3910 int maxdepth = context_getValue (FLG_INCLUDENEST);
3912 if (filelocStack_size (gc.locstack) > maxdepth)
3914 int depth = filelocStack_includeDepth (gc.locstack);
3916 if (depth > maxdepth)
3920 message ("Maximum include nesting depth "
3921 "(%d, current depth %d) exceeded",
3924 filelocStack_nextTop (gc.locstack)))
3926 filelocStack_printIncludes (gc.locstack);
3932 g_currentloc = fileloc_create (fid, lineno, 1);
3933 gc.inheader = fileId_isHeader (currentFile ());
3935 context_enterFileAux ();
3939 void context_enterIterDef (/*@observer@*/ uentry le)
3941 context_enterMacro (le);
3942 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
3943 gc.kind = CX_ITERDEF;
3946 void context_enterIterEnd (/*@observer@*/ uentry le)
3948 context_enterMacro (le);
3949 gc.kind = CX_ITEREND;
3953 context_destroyMod (void)
3954 /*@globals killed gc@*/
3957 ctype_destroyMod ();
3961 fileTable_free (gc.ftab);
3962 filelocStack_free (gc.locstack);
3964 gc.ftab = fileTable_undefined;
3966 macrocache_free (gc.mc);
3967 sfree (gc.moduleaccess);
3970 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
3971 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
3974 sRefSetList_free (gc.modrecs);
3976 flagMarkerList_free (gc.markers);
3978 messageLog_free (gc.msgLog);
3980 clauseStack_free (gc.clauses);
3983 cstring_free (gc.msgAnnote);
3984 globSet_free (gc.globs_used);
3985 metaStateTable_free (gc.stateTable);
3986 annotationTable_free (gc.annotTable);
3993 bool context_msgBoolInt (void)
3995 return gc.flags [FLG_BOOLINT];
3998 bool context_msgCharInt (void)
4000 return gc.flags [FLG_CHARINT];
4003 bool context_msgEnumInt (void)
4005 return gc.flags [FLG_ENUMINT];
4008 bool context_msgPointerArith (void)
4010 return gc.flags [FLG_POINTERARITH];
4013 bool context_msgStrictOps (void)
4015 return gc.flags [FLG_STRICTOPS];
4019 bool context_msgLh (void)
4021 return gc.flags [FLG_DOLH];
4025 void context_pushLoc (void)
4027 fileloc_free (gc.pushloc);
4028 gc.pushloc = gc.saveloc;
4029 gc.saveloc = fileloc_undefined;
4032 void context_popLoc (void)
4034 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4037 bool context_inGlobalScope (void)
4039 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4042 bool context_inInnerScope (void)
4044 return (gc.kind == CX_INNER);
4047 void context_setProtectVars (void)
4049 gc.protectVars = TRUE;
4052 bool context_anyErrors (void)
4054 return (gc.numerrors > 0);
4057 void context_hasError (void)
4060 DPRINTF (("num errors: %d", gc.numerrors));
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;