2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://www.splint.org
28 * Modified by Herbert 04/19/97:
29 * - added include for new header portab.h containing OS dependent stuff.
30 * - changed occurrances of '/' as path delimiters to macro from portab.h
31 * - changed the handling of the tmp directory -- will no longer always be
32 * ".", if possible, environment variables "TMP" or, if not set, "TMP",
33 * or, if not set "." will be used.
36 # include "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_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
68 CX_LCL, CX_LCLLIB, CX_MT
74 int speclinesprocessed;
76 flagMarkerList markers;
79 ** used to record state where a macro must match a function name
80 ** (i.e., no params were listed in the macro definition
83 bool macroMissingParams BOOLBITS;
84 bool preprocessing BOOLBITS;
85 bool incommandline BOOLBITS;
86 bool insuppressregion BOOLBITS;
87 bool inDerivedFile BOOLBITS;
88 bool instandardlib BOOLBITS;
89 bool inimport BOOLBITS;
90 bool inheader BOOLBITS;
91 bool inmacrocache BOOLBITS;
92 bool protectVars BOOLBITS;
94 bool showfunction BOOLBITS;
95 bool savedFlags BOOLBITS;
96 bool justpopped BOOLBITS;
97 bool anyExports BOOLBITS;
98 bool inFunctionHeader BOOLBITS;
111 filelocStack locstack;
114 /*@observer@*/ sRef aliasAnnote;
115 /*@observer@*/ sRef aliasAnnoteAls;
119 /*@observer@*/ sRefSet mods;
121 /* file access types */
124 /* local access types (this function) */
127 /* no access types (@noaccess) */
130 /*@observer@*/ globSet globs;
131 /*@only@*/ globSet globs_used;
135 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
141 bool flags[NUMFLAGS];
142 bool saveflags[NUMFLAGS];
143 bool setGlobally[NUMFLAGS];
144 bool setLocally[NUMFLAGS];
146 int values[NUMVALUEFLAGS];
147 int counters[NUMVALUEFLAGS];
149 o_cstring strings[NUMSTRINGFLAGS];
150 sRefSetList modrecs; /*@i32 ???? what is this for? */
152 metaStateTable stateTable; /* User-defined state information. */
153 annotationTable annotTable; /* User-defined annotations table. */
158 /*@dependent@*/ /*@exposed@*/ uentry fcn;
162 union u_cont savecont;
165 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
166 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
167 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
168 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
170 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
171 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
172 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
173 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
174 static void context_setFlag (flagcode p_f, bool p_b)
175 /*@modifies gc.flags@*/ ;
178 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, bool p_isRestore)
179 /*@modifies gc.flags@*/ ;
181 static void context_restoreFlag (flagcode p_f) /*@modifies gc.flags@*/ ;
185 cstring context_unparseFlagMarkers ()
187 return (flagMarkerList_unparse (gc.markers));
190 void context_setPreprocessing (void)
192 llassert (!gc.preprocessing);
193 gc.preprocessing = TRUE;
196 void context_clearPreprocessing (void)
198 llassert (gc.preprocessing);
199 gc.preprocessing = FALSE;
202 bool context_isPreprocessing (void)
204 return gc.preprocessing;
207 bool context_loadingLibrary (void)
209 return (fileloc_isLib (g_currentloc));
212 bool context_inXHFile (void)
214 return (fileloc_isXHFile (g_currentloc));
217 void context_setInCommandLine (void)
219 llassert (!gc.incommandline);
220 gc.incommandline = TRUE;
223 void context_clearInCommandLine (void)
225 llassert (gc.incommandline);
226 gc.incommandline = FALSE;
229 bool context_isInCommandLine (void)
231 return gc.incommandline;
235 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
238 clauseStack_push (gc.clauses, c);
240 if (clause_isConditional (c)
241 && context_getFlag (FLG_CONTROLNESTDEPTH))
243 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
244 int depth = clauseStack_controlDepth (gc.clauses);
246 if (depth == maxdepth + 1)
249 (FLG_CONTROLNESTDEPTH,
250 message ("Maximum control nesting depth "
259 clause topClause (clauseStack s) /*@*/
261 if (clauseStack_isEmpty (s)) return NOCLAUSE;
262 return ((clause) clauseStack_top (s));
266 context_addMacroCache (/*@only@*/ cstring def)
268 DPRINTF (("macro cache: %s", def));
269 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
273 context_addComment (/*@only@*/ cstring def)
275 DPRINTF (("macro comment: %s", def));
276 macrocache_addComment (gc.mc, fileloc_copy (g_currentloc), def);
280 ** returns TRUE is fl is in ignore region, or region where -code
282 ** the logic is fuzzy...
286 context_inSuppressFlagZone (fileloc fl, flagcode code)
288 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
291 if (ynm_isMaybe (ret))
299 res = !gc.saveflags[code];
303 res = !context_getFlag (code);
308 res = ynm_toBoolStrict (ret);
315 context_suppressSystemMsg (fileloc fl)
317 if (context_getFlag (FLG_SYSTEMDIRERRORS))
323 return (fileloc_isSystemFile (fl));
328 context_suppressFlagMsg (flagcode flag, fileloc fl)
330 if (context_suppressSystemMsg (fl))
335 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
337 /* want same object compare here */
339 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
341 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
343 return (!context_getFlag (flag)
344 || context_inSuppressRegion ()
345 || context_inSuppressZone (fl)
346 || (/*@!@@#@ gc.inDerivedFile && */ context_inSuppressFlagZone (fl, flag)));
350 return (context_inSuppressFlagZone (fl, flag));
355 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
358 if (context_suppressSystemMsg (fl))
364 if (fl == g_currentloc)
365 /*@noaccess fileloc@*/
367 return (context_getFlag (flag) || context_inSuppressRegion ());
372 return (context_getFlag (flag) || context_inSuppressRegion ());
377 context_inSuppressZone (fileloc fl)
379 if (context_suppressSystemMsg (fl))
384 return (flagMarkerList_inIgnore (gc.markers, fl));
388 context_inSuppressRegion (void)
390 return (gc.insuppressregion);
394 context_enterSuppressRegion (void)
396 if (gc.insuppressregion)
398 gc.insuppressregion = FALSE; /* get this msg! */
400 ("%q: New ignore errors region entered while in ignore errors region",
401 fileloc_unparse (g_currentloc)));
404 gc.insuppressregion = TRUE;
405 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (g_currentloc));
409 context_addFlagMarker (flagcode code, ynm set)
411 flagMarkerList_add (gc.markers,
412 flagMarker_createLocalSet (code, set, g_currentloc));
416 context_enterSuppressLine (int count)
418 fileloc nextline = fileloc_copy (g_currentloc);
420 flagMarkerList_add (gc.markers,
421 flagMarker_createIgnoreCount (count, g_currentloc));
423 fileloc_nextLine (nextline);
424 flagMarkerList_add (gc.markers,
425 flagMarker_createIgnoreOff (nextline));
426 fileloc_free (nextline);
429 void context_checkSuppressCounts (void)
431 if (context_getFlag (FLG_SUPCOUNTS))
433 flagMarkerList_checkSuppressCounts (gc.markers);
437 void context_incLineno (void)
444 context_exitSuppressRegion (void)
446 if (!gc.insuppressregion)
448 llerrorlit (FLG_SYNTAX,
449 "End ignore errors in region while not ignoring errors");
452 gc.insuppressregion = FALSE;
453 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (g_currentloc));
457 context_enterMTfile (void)
463 context_exitMTfile (void)
465 llassert (gc.kind == CX_MT);
471 context_enterLCLfile (void)
474 gc.facct = typeIdSet_emptySet ();
479 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
483 for (i = 0; i < gc.nmods; i++)
485 if (cstring_equal (gc.moduleaccess[i].file, fname))
487 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
488 cstring_free (fname);
493 if (gc.nmods == gc.maxmods)
497 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
498 oldmods = gc.moduleaccess;
500 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
502 for (i = 0; i < gc.nmods; i++)
504 gc.moduleaccess[i] = oldmods[i];
510 gc.moduleaccess[gc.nmods].file = fname;
511 gc.moduleaccess[gc.nmods].daccess = mods;
517 insertModuleAccess (cstring fname, typeId t)
521 for (i = 0; i < gc.nmods; i++)
523 if (cstring_equal (gc.moduleaccess[i].file, fname))
525 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
530 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
535 context_exitLCLfile (void)
537 if (gc.kind != CX_LCLLIB)
540 fileLib_withoutExtension (fileName (currentFile ()), LCL_EXTENSION);
542 addModuleAccess (fileLib_removePath (lclname), gc.facct);
543 cstring_free (lclname);
548 gc.facct = typeIdSet_emptySet ();
553 context_dumpModuleAccess (FILE *fout)
557 for (i = 0; i < gc.nmods; i++)
559 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
561 fprintf (fout, "%s#%s@\n",
562 cstring_toCharsSafe (gc.moduleaccess[i].file),
563 cstring_toCharsSafe (td));
569 bool context_usingPosixLibrary ()
571 return (gc.library == FLG_POSIXLIB
572 || gc.library == FLG_POSIXSTRICTLIB
573 || gc.library == FLG_UNIXLIB
574 || gc.library == FLG_UNIXSTRICTLIB);
577 bool context_usingAnsiLibrary ()
579 return (gc.library != FLG_NOLIB);
582 flagcode context_getLibrary ()
587 void context_setLibrary (flagcode code)
592 /*@observer@*/ cstring context_selectedLibrary ()
597 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
599 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
600 case FLG_POSIXSTRICTLIB:
601 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
603 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
604 case FLG_UNIXSTRICTLIB:
605 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
607 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
614 context_loadModuleAccess (FILE *in)
616 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
618 char *name = mstring_create (MAX_NAME_LENGTH);
624 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
630 while (s != NULL && *s != ';' && *s != '\0')
634 while (*s != '#' && *s != '\0')
643 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
644 cstring_fromChars (s)));
650 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
651 typeIdSet_undump (&s));
653 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
654 llassert (s != lasts);
664 typeIdSet context_fileAccessTypes (void)
670 context_resetModeFlags (void)
675 if (flagcode_isModeFlag (code))
677 context_setFlag (code, FALSE);
686 ** Set all flags to FALSE, except for a few which are
689 ** Set all values and strings to appropriate defaults.
690 ** Set all counters to 0.
694 conext_resetAllCounters (void)
698 for (i = 0; i < NUMVALUEFLAGS; i++)
705 context_resetAllFlags (void)
709 gc.flags[code] = FALSE;
711 if (flagcode_hasValue (code))
715 /*@-loopswitchbreak@*/
719 val = DEFAULT_LIMIT; break;
721 val = DEFAULT_BUGSLIMIT; break;
723 val = DEFAULT_LINELEN; break;
724 case FLG_INDENTSPACES:
725 val = DEFAULT_INDENTSPACES; break;
726 case FLG_EXTERNALNAMELEN:
727 val = DEFAULT_EXTERNALNAMELEN; break;
728 case FLG_INTERNALNAMELEN:
729 val = DEFAULT_INTERNALNAMELEN; break;
730 case FLG_COMMENTCHAR:
731 val = (int) DEFAULT_COMMENTCHAR; break;
732 case FLG_CONTROLNESTDEPTH:
733 val = (int) DEFAULT_CONTROLNESTDEPTH; break;
734 case FLG_STRINGLITERALLEN:
735 val = (int) DEFAULT_STRINGLITERALLEN; break;
736 case FLG_INCLUDENEST:
737 val = (int) DEFAULT_INCLUDENEST; break;
738 case FLG_NUMSTRUCTFIELDS:
739 val = (int) DEFAULT_NUMSTRUCTFIELDS; break;
740 case FLG_NUMENUMMEMBERS:
741 val = (int) DEFAULT_NUMENUMMEMBERS; break;
746 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
748 /*@=loopswitchbreak@*/
750 context_setValue (code, val);
752 else if (flagcode_hasString (code))
754 cstring val = cstring_undefined;
757 { /*@-loopswitchbreak@*/
760 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
762 if (cstring_isDefined (larchpath))
764 val = cstring_copy (larchpath);
768 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
773 case FLG_LCLIMPORTDIR:
775 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
779 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
781 char *env = osd_getEnvironmentVariable ("TMP");
785 env = osd_getEnvironmentVariable ("TEMP");
788 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
791 val = cstring_makeLiteral (DEFAULT_TMPDIR);
792 # endif /* !defined(OS2) && !defined(MSDOS) */
796 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
798 val = cstring_makeLiteral ("FALSE"); break;
800 val = cstring_makeLiteral ("TRUE"); break;
801 case FLG_MACROVARPREFIX:
802 val = cstring_makeLiteral ("m_"); break;
804 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
807 } /*@=loopswitchbreak@*/
809 context_setString (code, val);
813 ; /* nothing to set */
818 ** These flags are true by default.
821 /*@i34 move this into flags.def */
823 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
824 gc.flags[FLG_MODIFIES] = TRUE;
825 gc.flags[FLG_NESTCOMMENT] = TRUE;
826 gc.flags[FLG_GLOBALS] = TRUE;
827 gc.flags[FLG_FULLINITBLOCK] = TRUE;
828 gc.flags[FLG_INITSIZE] = TRUE;
829 gc.flags[FLG_INITALLELEMENTS] = TRUE;
831 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
833 gc.flags[FLG_LIKELYBOOL] = TRUE;
834 gc.flags[FLG_ZEROPTR] = TRUE;
835 gc.flags[FLG_NUMLITERAL] = TRUE;
836 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
837 gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
838 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
839 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
840 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
841 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
842 gc.flags[FLG_CASTFCNPTR] = TRUE;
843 gc.flags[FLG_DOLCS] = TRUE;
844 gc.flags[FLG_USEVARARGS] = TRUE;
845 gc.flags[FLG_MAINTYPE] = TRUE;
846 gc.flags[FLG_SPECMACROS] = TRUE;
847 gc.flags[FLG_REDEF] = TRUE;
848 gc.flags[FLG_MACRONEXTLINE] = TRUE;
850 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
851 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
853 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
854 gc.flags[FLG_WARNUSE] = TRUE;
855 gc.flags[FLG_PREDASSIGN] = TRUE;
856 gc.flags[FLG_MODOBSERVER] = TRUE;
857 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
858 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
860 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
861 gc.flags[FLG_RETIMPONLY] = TRUE;
862 gc.flags[FLG_GLOBIMPONLY] = TRUE;
863 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
864 gc.flags[FLG_PREPROC] = TRUE;
865 gc.flags[FLG_NAMECHECKS] = TRUE;
866 gc.flags[FLG_FORMATCODE] = TRUE;
867 gc.flags[FLG_FORMATTYPE] = TRUE;
868 gc.flags[FLG_BADFLAG] = TRUE;
869 gc.flags[FLG_WARNFLAGS] = TRUE;
870 gc.flags[FLG_WARNRC] = TRUE;
871 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
872 gc.flags[FLG_WARNUNIXLIB] = TRUE;
873 gc.flags[FLG_WARNPOSIX] = TRUE;
874 gc.flags[FLG_SHOWCOL] = TRUE;
875 gc.flags[FLG_SHOWFUNC] = TRUE;
876 gc.flags[FLG_SUPCOUNTS] = TRUE;
877 gc.flags[FLG_HINTS] = TRUE;
878 gc.flags[FLG_SYNTAX] = TRUE;
879 gc.flags[FLG_TYPE] = TRUE;
880 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
881 gc.flags[FLG_ABSTRACT] = TRUE;
882 gc.flags[FLG_ITER] = TRUE;
883 gc.flags[FLG_CONTROL] = TRUE;
884 gc.flags[FLG_UNRECOG] = TRUE;
885 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
886 gc.flags[FLG_LINTCOMMENTS] = TRUE;
887 gc.flags[FLG_ACCESSCZECH] = TRUE;
888 gc.flags[FLG_ACCESSMODULE] = TRUE;
889 gc.flags[FLG_ACCESSFILE] = TRUE;
890 gc.flags[FLG_MACROVARPREFIX] = TRUE;
892 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
893 gc.flags[FLG_COMMENTERROR] = TRUE;
896 ** Changed for version 2.4.
899 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
902 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
906 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
911 ** C is way-lame, and you can initialize an array to a constant except where
912 ** it is declared. Hence, a macro is used to set the modeflags.
916 # define SETFLAGS() \
917 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
918 if (!flagcode_isModeFlag (modeflags[i])) \
919 { llbug (message ("not a mode flag: %s", \
920 flagcode_unparse (modeflags[i]))); } \
921 else { context_setFlag (modeflags[i], TRUE); } i++; }}
924 context_setMode (cstring s)
926 intSet setflags = intSet_new ();
930 if (flagcode_isModeFlag (code))
932 if (gc.setGlobally[code])
934 (void) intSet_insert (setflags, (int) code);
939 if (!intSet_isEmpty (setflags))
941 cstring rflags = cstring_undefined;
944 intSet_elements (setflags, el)
946 if (cstring_isUndefined (rflags))
948 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
952 rflags = message ("%q, %s", rflags,
953 flagcode_unparse ((flagcode) el));
957 if (num > 4 && intSet_size (setflags) > 6)
959 rflags = message ("%q, (%d others) ...", rflags,
960 intSet_size (setflags) - num);
963 } end_intSet_elements ;
965 voptgenerror (FLG_WARNFLAGS,
966 message ("Setting mode %s after setting mode flags will "
967 "override set values of flags: %s",
971 cstring_free (rflags);
974 intSet_free (setflags);
976 context_resetModeFlags ();
978 if (cstring_equalLit (s, "standard"))
980 flagcode modeflags[] =
982 FLG_ENUMINT, FLG_MACROMATCHNAME,
984 FLG_MACROUNDEF, FLG_RELAXQUALS,
985 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
986 FLG_CHECKSTRICTGLOBALIAS,
987 FLG_CHECKEDGLOBALIAS,
988 FLG_CHECKMODGLOBALIAS,
989 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
991 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
993 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
994 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
995 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
996 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
997 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1000 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1001 FLG_MACROSTMT, FLG_MACROPARENS,
1004 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1005 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1010 /* memchecks flags */
1012 FLG_NULLSTATE, FLG_NULLASSIGN,
1013 FLG_NULLPASS, FLG_NULLRET,
1015 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1018 /* memtrans flags */
1037 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1038 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1039 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1042 FLG_STATETRANSFER, FLG_STATEMERGE,
1043 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1045 FLG_IMPCHECKEDSPECGLOBALS,
1046 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1047 FLG_IFEMPTY, FLG_REALCOMPARE,
1048 FLG_BOOLOPS, FLG_PTRNEGATE,
1050 FLG_SHIFTIMPLEMENTATION,
1051 FLG_BUFFEROVERFLOWHIGH,
1058 else if (cstring_equalLit (s, "weak"))
1060 flagcode modeflags[] =
1062 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1063 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1064 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1065 FLG_CHARUNSIGNEDCHAR,
1067 FLG_VARUNUSED, FLG_FUNCUNUSED,
1069 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1072 FLG_BUFFEROVERFLOWHIGH,
1073 FLG_RETSTACK, FLG_PTRNEGATE,
1074 FLG_STATETRANSFER, FLG_STATEMERGE,
1075 FLG_LONGUNSIGNEDINTEGRAL,
1076 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1080 FLG_BUFFEROVERFLOWHIGH,
1086 else if (cstring_equalLit (s, "checks"))
1088 flagcode modeflags[] =
1090 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1091 FLG_STATETRANSFER, FLG_STATEMERGE,
1092 FLG_CHECKSTRICTGLOBALIAS,
1093 FLG_CHECKEDGLOBALIAS,
1094 FLG_CHECKMODGLOBALIAS,
1095 FLG_UNCHECKEDGLOBALIAS,
1097 FLG_STRINGLITNOROOM,
1098 FLG_STRINGLITSMALLER,
1099 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1100 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1101 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1102 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1103 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1104 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1105 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1106 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1107 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1108 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1109 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1110 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1111 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1112 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1119 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1123 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1125 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1126 FLG_EVALORDER, FLG_USEDEF,
1129 /* warn use flags */
1130 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1131 FLG_BUFFEROVERFLOWHIGH,
1133 /* memchecks flags */
1135 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1136 FLG_NULLPASS, FLG_NULLRET,
1138 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1140 /* memtrans flags */
1154 FLG_STATICINITTRANS,
1155 FLG_UNKNOWNINITTRANS,
1158 FLG_ONLYUNQGLOBALTRANS,
1159 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1160 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1161 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1164 FLG_NULLPOINTERARITH,
1165 FLG_SHADOW, FLG_DEPARRAYS,
1166 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1167 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1168 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1169 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1170 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1171 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1172 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1173 FLG_SHIFTIMPLEMENTATION,
1174 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1179 else if (cstring_equalLit (s, "strict"))
1181 flagcode modeflags[] =
1183 FLG_CHECKSTRICTGLOBALIAS,
1184 FLG_CHECKEDGLOBALIAS,
1185 FLG_CHECKMODGLOBALIAS,
1186 FLG_UNCHECKEDGLOBALIAS,
1190 FLG_STRINGLITNOROOM,
1191 FLG_STRINGLITSMALLER,
1192 FLG_STATETRANSFER, FLG_STATEMERGE,
1193 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1194 FLG_ALLGLOBALS, FLG_IMPTYPE,
1195 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1196 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1197 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1198 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1201 FLG_ONLYUNQGLOBALTRANS,
1202 FLG_GLOBALSIMPMODIFIESNOTHING,
1203 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1204 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1205 FLG_USEALLGLOBS, FLG_RETALIAS,
1206 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1207 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1208 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1210 FLG_EXPORTITER, FLG_EXPORTCONST,
1211 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1212 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1214 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1216 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1217 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1218 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1219 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1220 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1221 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1222 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1223 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1225 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1228 FLG_MACROREDEF, FLG_MACROEMPTY,
1229 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1231 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1233 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1234 FLG_MODOBSERVERUNCON,
1239 /* warn use flags */
1240 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1241 FLG_BUFFEROVERFLOWHIGH,
1242 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1244 /* memchecks flags */
1245 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1246 FLG_NULLPASS, FLG_NULLRET,
1248 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1250 /* memtrans flags */
1266 FLG_STATICINITTRANS,
1267 FLG_UNKNOWNINITTRANS,
1269 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1270 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1271 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1275 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1277 FLG_SHADOW, FLG_DEPARRAYS,
1278 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1279 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1280 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1281 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1282 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1283 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1284 FLG_IMPCHECKEDSTRICTSTATICS,
1285 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1286 FLG_IMPCHECKMODINTERNALS,
1287 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1288 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1289 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1290 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1291 FLG_CONTROLNESTDEPTH,
1292 FLG_FORBLOCK, FLG_WHILEBLOCK,
1293 FLG_FOREMPTY, FLG_WHILEEMPTY,
1294 FLG_IFEMPTY, FLG_IFBLOCK,
1296 FLG_REALCOMPARE, FLG_BOOLOPS,
1297 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1300 FLG_SHIFTIMPLEMENTATION,
1302 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1310 llcontbug (message ("context_setMode: bad mode: %s", s));
1315 context_isSpecialFile (cstring fname)
1317 cstring ext = fileLib_getExtension (fname);
1319 return (cstring_equalLit (ext, ".y")
1320 || cstring_equalLit (ext, ".l")
1321 || cstring_equalLit (fname, "lex.yy.c"));
1325 context_isSystemDir (cstring dir)
1327 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1328 cstring savedir = thisdir;
1329 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1331 if (cstring_isDefined (nextdir))
1333 /*@access cstring@*/
1334 *nextdir = '\0'; /* closes thisdir */
1336 /*@noaccess cstring@*/
1339 /* 2001-09-09: added thisdir[0] != '\0'
1340 ** herbert: don't compare with an empty name!
1341 ** should return false for empty directory path
1344 while (!cstring_isEmpty (thisdir))
1346 DPRINTF (("Test: %s / %s", dir, thisdir));
1348 if (osd_equalCanonicalPrefix (dir, thisdir))
1350 cstring_free (savedir);
1354 if (cstring_isDefined (nextdir))
1357 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1359 if (cstring_isDefined (nextdir))
1361 /*@access cstring@*/
1364 /*@noaccess cstring@*/
1373 DPRINTF (("Returns FALSE"));
1374 cstring_free (savedir);
1379 context_addFileAccessType (typeId t)
1383 if (context_inFunctionLike ())
1385 gc.acct = typeIdSet_insert (gc.acct, t);
1388 gc.facct = typeIdSet_insert (gc.facct, t);
1390 base = fileloc_getBase (g_currentloc);
1391 insertModuleAccess (base, t);
1392 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1393 typeIdSet_unparse (gc.acct)));
1397 context_removeFileAccessType (typeId t)
1399 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1400 || gc.kind == CX_UNKNOWNMACRO)
1402 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1405 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1406 gc.nacct = typeIdSet_insert (gc.nacct, t);
1409 void context_enterFunctionHeader (void)
1411 if (context_getFlag (FLG_GRAMMAR))
1413 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1416 if (gc.kind != CX_GLOBAL)
1418 llparseerror (cstring_makeLiteral
1419 ("Likely parse error. Function header outside global context."));
1423 llassert (gc.kind == CX_GLOBAL);
1424 DPRINTF (("Enter function header!"));
1425 gc.inFunctionHeader = TRUE;
1429 void context_exitFunctionHeader (void)
1431 if (context_getFlag (FLG_GRAMMAR))
1433 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1436 DPRINTF (("Exit function header!"));
1437 gc.inFunctionHeader = FALSE;
1440 bool context_inFunctionHeader (void)
1442 return (gc.inFunctionHeader);
1445 void context_enterFunctionDeclaration (uentry e)
1447 if (context_getFlag (FLG_GRAMMAR))
1449 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1452 DPRINTF (("Enter function decl"));
1453 llassert (gc.savekind == CX_ERROR);
1454 gc.savekind = gc.kind;
1455 gc.savecont = gc.cont;
1456 gc.kind = CX_FCNDECLARATION;
1460 void context_exitFunctionDeclaration (void)
1462 if (context_getFlag (FLG_GRAMMAR))
1464 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1467 DPRINTF (("Exit function decl"));
1468 llassert (gc.savekind != CX_ERROR);
1469 llassert (gc.kind == CX_FCNDECLARATION);
1470 gc.kind = gc.savekind;
1471 gc.cont = gc.savecont;
1473 gc.savekind = CX_ERROR;
1475 if (context_getFlag (FLG_GRAMMAR))
1477 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1481 bool context_inFunctionDeclaration (void)
1483 return (gc.kind == CX_FCNDECLARATION);
1488 context_enterMacro (/*@observer@*/ uentry e)
1490 context_enterFunction (e);
1491 gc.kind = CX_MACROFCN;
1495 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1497 llassert (uentry_isFunction (e));
1498 context_enterFunction (e);
1499 gc.kind = CX_UNKNOWNMACRO;
1502 void context_enterAndClause (exprNode e)
1505 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1506 pushClause (ANDCLAUSE);
1509 void context_enterOrClause (exprNode e)
1511 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1512 pushClause (ORCLAUSE);
1515 bool context_inDeepLoop (void)
1517 bool inLoop = FALSE;
1519 clauseStack_elements (gc.clauses, el)
1521 if (clause_isLoop (el))
1530 } end_clauseStack_elements;
1535 bool context_inDeepSwitch (void)
1537 bool inLoop = FALSE;
1539 clauseStack_elements (gc.clauses, el)
1541 if (clause_isSwitch (el))
1550 } end_clauseStack_elements;
1555 bool context_inDeepLoopSwitch (void)
1557 bool inLoop = FALSE;
1559 clauseStack_elements (gc.clauses, el)
1561 if (clause_isBreakable (el))
1570 } end_clauseStack_elements;
1575 clause context_breakClause (void)
1577 clauseStack_elements (gc.clauses, el)
1579 if (clause_isSwitch (el))
1583 else if (clause_isLoop (el))
1591 } end_clauseStack_elements;
1596 clause context_nextBreakClause (void)
1598 bool hasOne = FALSE;
1600 clauseStack_elements (gc.clauses, el)
1602 if (clause_isBreakable (el))
1613 } end_clauseStack_elements;
1618 bool context_inConditional (void)
1620 clauseStack_elements (gc.clauses, el)
1623 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1624 ** to distinguish if from ? for this
1627 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1631 } end_clauseStack_elements;
1636 void context_exitAndClause (exprNode pred, exprNode tbranch)
1638 context_setJustPopped ();
1640 llassert (gc.inclause == ANDCLAUSE);
1642 usymtab_popAndBranch (pred, tbranch);
1643 clauseStack_pop (gc.clauses);
1644 gc.inclause = topClause (gc.clauses);
1647 void context_exitOrClause (exprNode pred, exprNode tbranch)
1649 context_setJustPopped ();
1651 llassert (gc.inclause == ORCLAUSE);
1653 usymtab_popOrBranch (pred, tbranch);
1654 clauseStack_pop (gc.clauses);
1655 gc.inclause = topClause (gc.clauses);
1658 static void context_enterCondClauseAux (clause cl)
1664 static void context_enterTrueAux (exprNode e, clause cl)
1667 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1671 void context_enterIterClause (void)
1673 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1676 void context_enterDoWhileClause (void)
1678 pushClause (DOWHILECLAUSE);
1681 void context_enterWhileClause (exprNode e)
1683 context_enterTrueAux (e, WHILECLAUSE);
1686 void context_enterForClause (exprNode e)
1688 context_enterTrueAux (e, FORCLAUSE);
1691 void context_enterTrueClause (exprNode e)
1693 context_enterTrueAux (e, TRUECLAUSE);
1696 void context_enterSwitch (exprNode e)
1699 usymtab_switchBranch (e);
1700 context_enterCondClauseAux (SWITCHCLAUSE);
1703 void context_exitSwitch (exprNode e, bool allpaths)
1705 usymtab_exitSwitch (e, allpaths);
1707 while (clause_isCase (clauseStack_top (gc.clauses)))
1709 clauseStack_pop (gc.clauses);
1712 context_exitClauseSimp ();
1715 void context_enterCaseClause (exprNode e)
1717 bool branch = FALSE;
1719 DPRINTF (("Enter case clause!"));
1721 branch = usymtab_newCase (exprNode_undefined, e);
1725 context_enterCondClauseAux (CASECLAUSE);
1729 static void context_enterFalseClauseAux (exprNode e, clause cl)
1732 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1734 clauseStack_switchTop (gc.clauses, cl);
1737 void context_enterFalseClause (exprNode e)
1740 context_enterFalseClauseAux (e, FALSECLAUSE);
1744 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1746 gc.kind = CX_MACROCONST;
1748 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1750 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1754 usymtab_enterScope ();
1755 sRef_enterFunctionScope ();
1757 gc.globs = globSet_undefined;
1758 globSet_clear (gc.globs_used);
1759 gc.mods = sRefSet_undefined;
1762 uentry context_getHeader (void)
1764 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1766 llfatalbug (message ("context_getHeader: bad call: %q",
1767 context_unparse ()));
1770 return (gc.cont.fcn);
1774 context_setFunctionDefined (fileloc loc)
1778 case CX_UNKNOWNMACRO:
1781 uentry_setFunctionDefined (gc.cont.fcn, loc);
1784 /* (not a bug because of parse errors) */
1790 context_enterFunction (/*@exposed@*/ uentry e)
1792 gc.kind = CX_FUNCTION;
1795 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1797 if (uentry_hasAccessType (e))
1799 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1807 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1808 typeIdSet_unparse (gc.acct)));
1810 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1812 gc.globs = uentry_getGlobs (e);
1813 globSet_clear (gc.globs_used);
1814 gc.mods = uentry_getMods (e);
1816 usymtab_enterFunctionScope (e);
1817 sRef_enterFunctionScope ();
1821 context_enterOldStyleScope (void)
1823 gc.kind = CX_OLDSTYLESCOPE;
1824 DPRINTF (("Enter old style scope!"));
1825 usymtab_enterFunctionScope (uentry_undefined);
1829 context_completeOldStyleFunction (uentry e)
1831 llassert (gc.kind == CX_OLDSTYLESCOPE);
1833 gc.kind = CX_FUNCTION;
1836 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1838 if (uentry_hasAccessType (e))
1840 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1848 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1849 typeIdSet_unparse (gc.acct)));
1851 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1853 if (!globSet_isEmpty (uentry_getGlobs (e)))
1855 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1856 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1859 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1861 gc.globs = uentry_getGlobs (e);
1862 globSet_clear (gc.globs_used);
1864 gc.mods = uentry_getMods (e);
1866 if (!sRefSet_isEmpty (gc.mods))
1868 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1869 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1872 sRef_enterFunctionScope ();
1875 static bool context_checkStrictGlobals (void)
1877 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1880 static bool context_hasGlobs (void)
1882 if (context_inFunctionLike ())
1884 return (uentry_hasGlobs (gc.cont.fcn));
1892 static bool context_checkCheckedGlobals (void)
1894 return (context_getFlag (FLG_GLOBALS)
1895 && (context_getFlag (FLG_GLOBUNSPEC)
1896 || context_hasGlobs ()));
1899 static bool context_checkUnknownGlobals (void)
1901 /* should be uentry_hasGlobs ? */
1903 return (context_getFlag (FLG_ALLGLOBALS)
1904 && (context_getFlag (FLG_GLOBUNSPEC)
1905 || context_hasGlobs ()));
1908 static bool context_checkUncheckedGlobals (void)
1914 context_checkExport (uentry e)
1916 if (!gc.anyExports) return FALSE;
1918 if (uentry_isFunction (e)
1919 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1921 return context_maybeSet (FLG_EXPORTFCN);
1923 else if (uentry_isExpandedMacro (e))
1925 return context_maybeSet (FLG_EXPORTMACRO);
1927 else if (uentry_isVariable (e))
1929 return context_maybeSet (FLG_EXPORTVAR);
1931 else if (uentry_isEitherConstant (e))
1933 return context_maybeSet (FLG_EXPORTCONST);
1935 else if (uentry_isIter (e) || uentry_isEndIter (e))
1937 return context_maybeSet (FLG_EXPORTITER);
1939 else if (uentry_isDatatype (e))
1941 return context_maybeSet (FLG_EXPORTTYPE);
1950 context_checkGlobUse (uentry glob)
1953 if (uentry_isCheckedStrict (glob))
1955 return context_checkStrictGlobals ();
1957 else if (uentry_isChecked (glob))
1959 return context_checkCheckedGlobals ();
1961 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
1963 return context_checkUnknownGlobals ();
1967 llassert (uentry_isUnchecked (glob));
1969 return context_checkUncheckedGlobals ();
1974 context_checkAliasGlob (uentry glob)
1976 if (uentry_isCheckedStrict (glob))
1978 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
1980 else if (uentry_isChecked (glob))
1982 return gc.flags[FLG_CHECKEDGLOBALIAS];
1984 else if (uentry_isCheckMod (glob))
1986 return gc.flags[FLG_CHECKMODGLOBALIAS];
1990 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
1992 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
1996 bool context_checkInternalUse (void)
1998 if (context_hasGlobs ())
2000 return (gc.flags[FLG_INTERNALGLOBS]);
2004 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2009 context_checkGlobMod (sRef el)
2011 uentry ue = sRef_getUentry (el);
2013 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2015 if (uentry_isCheckedModify (ue)
2016 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2018 if (context_hasMods ())
2020 return (gc.flags[FLG_MODGLOBS]);
2024 if (uentry_isCheckedStrict (ue))
2026 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2030 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2036 if (context_hasMods ())
2038 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2048 context_usedGlobal (/*@exposed@*/ sRef el)
2050 if (!globSet_member (gc.globs_used, el))
2053 ** The first time a global is used in a function, we need
2054 ** to clear the derived sRefs, since they were set for the
2055 ** previous function.
2058 sRef_clearDerived (el);
2059 gc.globs_used = globSet_insert (gc.globs_used, el);
2063 /*@observer@*/ sRefSet
2064 context_modList (void)
2070 context_globAccess (sRef s)
2072 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2073 return (globSet_member (gc.globs, s));
2077 context_hasAccess (typeId t)
2079 if (context_inFunctionLike ())
2081 DPRINTF (("Access %d / %s",
2082 t, typeIdSet_unparse (gc.acct)));
2083 return (typeIdSet_member (gc.acct, t));
2087 return (context_hasFileAccess (t));
2092 context_hasFileAccess (typeId t)
2094 return (typeIdSet_member (gc.facct, t));
2098 context_unparseAccess (void)
2100 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2101 typeIdSet_unparse (gc.facct)));
2105 context_unparseClauses (void)
2107 return (clauseStack_unparse (gc.clauses));
2111 context_couldHaveAccess (typeId t)
2113 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2115 return (typeIdSet_member (gc.acct, t));
2119 return (typeIdSet_member (gc.facct, t));
2124 context_getRetType (void)
2126 ctype f = ctype_undefined;
2128 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2130 f = uentry_getType (gc.cont.fcn);
2132 else if (gc.kind == CX_UNKNOWNMACRO)
2134 return ctype_unknown;
2138 llcontbuglit ("context_getRetType: not in a function context");
2139 return ctype_unknown;
2142 if (!ctype_isFunction (f))
2144 if (ctype_isKnown (f))
2146 llbuglit ("context_getRetType: not a function");
2149 return ctype_unknown;
2151 return (ctype_getReturnType (f));
2155 context_hasMods (void)
2157 if (context_inFunctionLike ())
2159 return (uentry_hasMods (gc.cont.fcn));
2168 context_exitAllClauses (void)
2170 while (!clauseStack_isEmpty (gc.clauses))
2172 clause el = clauseStack_top (gc.clauses);
2175 if (clause_isNone (el))
2177 usymtab_quietExitScope (g_currentloc);
2178 clauseStack_pop (gc.clauses);
2182 context_exitClausePlain ();
2186 clauseStack_clear (gc.clauses);
2187 gc.inclause = NOCLAUSE;
2191 context_exitAllClausesQuiet (void)
2193 while (!clauseStack_isEmpty (gc.clauses))
2195 clause el = clauseStack_top (gc.clauses);
2198 usymtab_quietExitScope (g_currentloc);
2199 clauseStack_pop (gc.clauses);
2202 clauseStack_clear (gc.clauses);
2203 gc.inclause = NOCLAUSE;
2207 void context_exitClauseSimp (void)
2210 context_setJustPopped ();
2211 clauseStack_pop (gc.clauses);
2212 gc.inclause = topClause (gc.clauses);
2216 void context_exitCaseClause (void)
2218 context_setJustPopped ();
2219 usymtab_popCaseBranch ();
2220 clauseStack_pop (gc.clauses);
2221 gc.inclause = topClause (gc.clauses);
2225 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2227 context_setJustPopped ();
2228 /*@i32 was makeAlt */
2229 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2230 clauseStack_pop (gc.clauses);
2231 gc.inclause = topClause (gc.clauses);
2234 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2236 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2238 if (gc.inclause != TRUECLAUSE)
2240 llparseerror (cstring_makeLiteral
2241 ("Likely parse error. Conditional clauses are inconsistent."));
2245 context_setJustPopped ();
2246 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2247 clauseStack_pop (gc.clauses);
2248 gc.inclause = topClause (gc.clauses);
2251 void context_exitIterClause (exprNode body)
2253 llassert (gc.inclause == ITERCLAUSE);
2255 context_setJustPopped ();
2257 if (context_getFlag (FLG_ITERLOOPEXEC))
2259 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2263 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2266 clauseStack_pop (gc.clauses);
2267 gc.inclause = topClause (gc.clauses);
2270 static void context_popCase (void) {
2272 ** If we are exiting an outer clause, sometimes still in a switch case.
2286 DPRINTF (("Popping case clause: %s",
2287 clauseStack_unparse (gc.clauses)));
2289 if (gc.inclause == CASECLAUSE) {
2290 context_exitCaseClause ();
2294 void context_exitWhileClause (exprNode pred, exprNode body)
2296 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2300 if (gc.inclause != WHILECLAUSE) {
2301 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2302 clauseStack_unparse (gc.clauses)));
2305 llassert (gc.inclause == WHILECLAUSE);
2307 context_setJustPopped ();
2311 ** predicate must be false after while loop (unless there are breaks)
2314 if (context_getFlag (FLG_WHILELOOPEXEC))
2316 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2320 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2324 usymtab_addGuards (invGuards);
2325 guardSet_free (invGuards);
2327 clauseStack_pop (gc.clauses);
2328 gc.inclause = topClause (gc.clauses);
2331 void context_exitDoWhileClause (exprNode pred)
2333 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2335 if (gc.inclause == CASECLAUSE) {
2336 /* handle Duff's device */
2337 clauseStack_pop (gc.clauses);
2338 gc.inclause = topClause (gc.clauses);
2341 llassert (gc.inclause == DOWHILECLAUSE);
2343 context_setJustPopped ();
2346 usymtab_addGuards (invGuards);
2347 guardSet_free (invGuards);
2349 clauseStack_pop (gc.clauses);
2350 gc.inclause = topClause (gc.clauses);
2353 void context_exitForClause (exprNode forPred, exprNode body)
2355 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2357 llassert (gc.inclause == FORCLAUSE);
2358 context_setJustPopped ();
2360 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2363 ** Predicate must be false after for loop (unless there are breaks)
2366 if (context_getFlag (FLG_FORLOOPEXEC))
2368 DPRINTF (("Here: for loop exec"));
2369 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2373 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2374 && exprNode_loopMustExec (forPred))
2376 DPRINTF (("Here: loop must exec"));
2377 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2381 DPRINTF (("Pop true branch:"));
2382 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2386 usymtab_addGuards (invGuards);
2387 guardSet_free (invGuards);
2388 clauseStack_pop (gc.clauses);
2389 gc.inclause = topClause (gc.clauses);
2392 static void context_exitClausePlain (void)
2394 llassert (gc.inclause != NOCLAUSE);
2396 if (gc.inclause == FALSECLAUSE)
2398 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2402 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2406 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2408 context_setJustPopped ();
2410 if (gc.inclause == FALSECLAUSE)
2412 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2414 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2416 clauseStack_pop (gc.clauses);
2417 gc.inclause = topClause (gc.clauses);
2421 context_exitTrueClause (pred, tbranch);
2426 context_returnFunction (void)
2428 usymtab_checkFinalScope (TRUE);
2432 context_exitFunction (void)
2434 DPRINTF (("Exit function: %s", context_unparse ()));
2436 if (!context_inFunction () && !context_inMacroConstant ()
2437 && !context_inUnknownMacro ()
2438 && !context_inIterDef () && !context_inIterEnd ())
2441 ** not a bug because of parse errors
2448 if (context_inMacro () && usymtab_inFunctionScope ())
2450 usymtab_exitScope (exprNode_undefined);
2453 if (uentry_hasGlobs (gc.cont.fcn))
2455 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2459 if (uentry_hasMods (gc.cont.fcn))
2461 if (context_getFlag (FLG_MUSTMOD))
2463 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2467 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2470 ** clear file static modifies
2473 /* do this first to get unused error messages */
2475 usymtab_exitScope (exprNode_undefined);
2476 sRef_exitFunctionScope ();
2478 gc.showfunction = FALSE;
2479 gc.kind = CX_GLOBAL;
2480 gc.cont.glob = TRUE;
2482 gc.globs = globSet_new ();
2483 globSet_clear (gc.globs_used);
2484 gc.mods = sRefSet_new ();
2487 llassert (clauseStack_isEmpty (gc.clauses));
2488 llassert (gc.inclause == NOCLAUSE);
2489 DPRINTF (("After exit function: %s", context_unparse ()));
2493 context_quietExitFunction (void)
2495 while (gc.kind == CX_INNER)
2497 context_exitInnerPlain ();
2500 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2501 && !context_inIterDef () && !context_inIterEnd ())
2506 usymtab_quietExitScope (g_currentloc);
2508 gc.showfunction = FALSE;
2509 gc.kind = CX_GLOBAL;
2510 gc.cont.glob = TRUE;
2512 gc.globs = globSet_new ();
2513 globSet_clear (gc.globs_used);
2514 gc.mods = sRefSet_new ();
2516 sRef_exitFunctionScope ();
2520 /*@observer@*/ uentryList
2521 context_getParams (void)
2523 if (context_inFunctionLike ())
2525 return (uentry_getParams (gc.cont.fcn));
2529 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2530 return uentryList_undefined;
2534 /*@observer@*/ globSet
2535 context_getUsedGlobs (void)
2537 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2538 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2540 return (gc.globs_used);
2544 context_moduleName ()
2546 return (fileloc_getBase (g_currentloc));
2549 /*@observer@*/ globSet
2550 context_getGlobs (void)
2552 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2553 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2559 context_addBoolAccess (void)
2561 cstring bname = context_getString (FLG_BOOLTYPE);
2562 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2564 addModuleAccess (cstring_copy (bname), boolt);
2566 /* for sys/types (perhaps, this is bogus!) */
2567 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2572 context_canAccessBool (void)
2579 static typeId boolType = typeId_invalid;
2581 if (typeId_isInvalid (boolType))
2583 boolType = usymtab_getTypeId (context_getBoolName ());
2586 if (typeId_isInvalid (boolType)) {
2589 return (typeIdSet_member (gc.acct, boolType));
2594 /* evs 2000-07-25: old version - replaced */
2597 context_boolImplementationType () {
2598 /* For now, this is bogus! */
2603 context_canAccessBool (void)
2605 static typeId boolType = typeId_invalid;
2607 if (typeId_isInvalid (boolType))
2609 boolType = usymtab_getTypeId (context_getBoolName ());
2612 if (!typeId_isInvalid (boolType))
2614 return context_hasAccess (boolType);
2625 context_setMessageAnnote (/*@only@*/ cstring s)
2627 llassert (cstring_isUndefined (gc.msgAnnote));
2632 context_hasMessageAnnote (void)
2634 return (cstring_isDefined (gc.msgAnnote));
2638 context_clearMessageAnnote (void)
2640 if (cstring_isDefined (gc.msgAnnote))
2642 cstring_free (gc.msgAnnote);
2643 gc.msgAnnote = cstring_undefined;
2648 context_getMessageAnnote (void)
2650 cstring st = gc.msgAnnote;
2652 gc.msgAnnote = cstring_undefined;
2657 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2659 llassert (sRef_isInvalid (gc.aliasAnnote));
2660 llassert (!sRef_sameName (s, t));
2662 gc.aliasAnnoteAls = t;
2666 context_hasAliasAnnote (void)
2668 return (sRef_isValid (gc.aliasAnnote));
2672 context_clearAliasAnnote (void)
2674 gc.aliasAnnote = sRef_undefined;
2678 context_getAliasAnnote (void)
2680 sRef ret = gc.aliasAnnote;
2681 sRef als = gc.aliasAnnoteAls;
2683 llassert (sRef_isValid (ret) && sRef_isValid (als));
2685 gc.aliasAnnote = sRef_undefined;
2686 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2690 context_recordFileModifies (sRefSet mods)
2692 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2696 context_recordFileGlobals (globSet mods)
2698 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2699 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2703 context_setCommentMarkerChar (char c)
2705 llassert (c != '\0');
2707 context_setValue (FLG_COMMENTCHAR, (int) c);
2711 context_getCommentMarkerChar (void)
2713 return ((char) context_getValue (FLG_COMMENTCHAR));
2717 context_setValue (flagcode flag, int val)
2719 int index = flagcode_valueIndex (flag);
2721 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2729 llerror_flagWarning (message ("Value for %s must be a positive "
2730 "number (given %d)",
2731 flagcode_unparse (flag), val));
2734 if (flag == FLG_LINELEN && val < MINLINELEN)
2736 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2737 flagcode_unparse (flag),
2743 case FLG_INCLUDENEST:
2744 case FLG_CONTROLNESTDEPTH:
2745 case FLG_STRINGLITERALLEN:
2746 case FLG_NUMSTRUCTFIELDS:
2747 case FLG_NUMENUMMEMBERS:
2748 case FLG_INDENTSPACES:
2751 llerror_flagWarning (message ("Value for %s must be a non-negative "
2752 "number (given %d)",
2753 flagcode_unparse (flag), val));
2762 gc.values[index] = val;
2766 context_setValueAndFlag (flagcode flag, int val)
2768 gc.flags[flag] = TRUE;
2769 context_setValue (flag, val);
2773 context_getValue (flagcode flag)
2775 int index = flagcode_valueIndex (flag);
2777 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2778 return (gc.values[index]);
2782 context_getCounter (flagcode flag)
2784 int index = flagcode_valueIndex (flag);
2786 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2787 return (gc.counters[index]);
2791 context_incCounter (flagcode flag)
2793 int index = flagcode_valueIndex (flag);
2795 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2797 gc.counters[index]++;
2801 context_decCounter (flagcode flag)
2803 int index = flagcode_valueIndex (flag);
2805 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2806 gc.counters[index]--;
2809 bool context_showFunction (void)
2811 return (gc.showfunction);
2815 context_setString (flagcode flag, cstring val)
2817 int index = flagcode_stringIndex (flag);
2819 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2821 if (flag == FLG_SYSTEMDIRS)
2823 llassert (cstring_isDefined (val));
2825 if (cstring_firstChar (val) == '\"')
2828 cstring tval = cstring_copy (cstring_suffix (val, 1));
2830 if (cstring_lastChar (tval) != '\"')
2832 int n = cstring_length (tval) - 1;
2834 while (isspace ((int) cstring_getChar (tval, n)))
2839 if (cstring_getChar (tval, n) != '\"')
2841 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2845 cstring otval = tval;
2846 tval = cstring_prefix (tval, n);
2847 cstring_free (otval);
2851 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2852 DPRINTF (("val = %s", val));
2853 cstring_free (tval);
2854 cstring_free (oval);
2858 if (flag == FLG_TMPDIR)
2860 llassert (cstring_isDefined (val));
2862 if (cstring_length (val) == 0)
2865 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2867 else if (cstring_lastChar (val) != CONNECTCHAR)
2869 val = cstring_appendChar (val, CONNECTCHAR);
2877 if (cstring_length (val) >= 1
2878 && cstring_firstChar (val) == '\"')
2880 llerror_flagWarning (message
2881 ("setting %s to string beginning with \". You probably "
2882 "don't meant to have the \"'s.",
2883 flagcode_unparse (flag)));
2886 if (flag == FLG_BOOLTYPE)
2891 gc.strings[index] = val;
2894 static /*@exposed@*/ cstring
2895 context_exposeString (flagcode flag)
2897 int index = flagcode_stringIndex (flag);
2899 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2900 return (gc.strings[index]);
2904 context_getString (flagcode flag)
2906 return (context_exposeString (flag));
2910 context_resetErrors (void)
2915 void context_initMod (void)
2916 /*@globals undef gc; @*/
2918 gc.kind = CX_GLOBAL;
2920 gc.savekind = CX_ERROR;
2921 gc.savecont.glob = FALSE;
2923 gc.instandardlib = FALSE;
2926 gc.linesprocessed = 0;
2927 gc.speclinesprocessed = 0;
2928 gc.insuppressregion = FALSE;
2929 gc.macroMissingParams = FALSE;
2930 gc.preprocessing = FALSE;
2931 gc.incommandline = FALSE;
2932 gc.mc = macrocache_create ();
2934 gc.maxmods = DEFAULTMAXMODS;
2935 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2937 gc.library = FLG_ANSILIB;
2939 gc.locstack = filelocStack_new ();
2940 gc.modrecs = sRefSetList_undefined;
2941 gc.anyExports = FALSE;
2943 gc.ftab = fileTable_create ();
2944 gc.msgLog = messageLog_new ();
2945 gc.inimport = FALSE;
2946 gc.inDerivedFile = FALSE;
2947 gc.inheader = FALSE;
2948 gc.markers = flagMarkerList_new ();
2949 gc.cont.glob = TRUE;
2950 gc.showfunction = FALSE;
2951 gc.msgAnnote = cstring_undefined;
2952 gc.aliasAnnote = sRef_undefined;
2953 gc.aliasAnnoteAls = sRef_undefined;
2954 gc.boolType = ctype_bool;
2955 gc.mods = sRefSet_new ();
2957 gc.saveloc = fileloc_undefined;
2959 gc.inmacrocache = FALSE;
2960 gc.inclause = NOCLAUSE;
2961 gc.clauses = clauseStack_new ();
2962 gc.globs = globSet_new ();
2963 gc.nacct = typeIdSet_emptySet ();
2964 gc.acct = typeIdSet_emptySet ();
2965 gc.facct = typeIdSet_emptySet ();
2966 gc.savedFlags = FALSE;
2967 gc.pushloc = fileloc_undefined;
2968 gc.protectVars = FALSE;
2969 gc.justpopped = FALSE;
2970 gc.isNullGuarded = NO;
2971 gc.globs_used = globSet_undefined;
2975 gc.setGlobally[code] = FALSE;
2976 gc.setLocally[code] = FALSE;
2977 } end_allFlagCodes ;
2981 context_resetAllFlags ();
2982 assertSet (gc.flags); /* Can't use global in defines */
2983 assertSet (gc.saveflags);
2984 assertSet (gc.values);
2985 assertSet (gc.strings);
2987 conext_resetAllCounters ();
2988 assertSet (gc.counters);
2990 context_setMode (DEFAULT_MODE);
2992 gc.stateTable = metaStateTable_create ();
2993 gc.annotTable = annotationTable_create ();
2995 gc.inFunctionHeader = FALSE;
2997 DPRINTF (("Annotations: \n%s",
2998 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
2999 DPRINTF (("State: \n%s",
3000 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3005 context_typeofZero (void)
3007 ctype ct = ctype_int;
3009 if (context_getFlag (FLG_ZEROPTR))
3011 ct = ctype_makeConj (ct, ctype_voidPointer);
3014 if (context_getFlag (FLG_ZEROBOOL)) {
3015 ct = ctype_makeConj (ct, ctype_bool);
3022 context_typeofOne (void)
3024 ctype ct = ctype_int;
3026 /* 1 is on longer a bool (was before 2.4)
3027 if (!context_getFlag (FLG_ABSTRACTBOOL))
3029 ct = ctype_makeConj (ct, ctype_bool);
3037 context_unparse (void)
3044 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3047 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3050 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3053 s = message ("Inner Context [%d] : %q",
3055 fileloc_unparse (g_currentloc));
3058 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3059 uentry_unparse (gc.cont.fcn),
3060 fileloc_unparse (g_currentloc),
3061 typeIdSet_unparse (gc.acct),
3062 sRefSet_unparse (gc.mods));
3065 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3067 case CX_UNKNOWNMACRO:
3068 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3071 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3074 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3077 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3079 case CX_FCNDECLARATION:
3080 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3083 s = message ("Un-unparseable context: %d", (int) gc.kind);
3087 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3092 context_currentFunctionType (void)
3094 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3096 return (uentry_getType (gc.cont.fcn));
3098 else if (gc.kind == CX_INNER)
3100 llcontbuglit ("context_currentFunctionType: inner context");
3101 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3102 return (context_currentFunctionType ());
3106 llcontbuglit ("context_currentFunctionType: not in function");
3107 return (ctype_undefined);
3112 context_enterInnerContext (void)
3114 if (context_getFlag (FLG_GRAMMAR))
3116 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3119 if (gc.kind == CX_GLOBAL)
3124 else if (gc.kind == CX_INNER)
3133 usymtab_enterScope ();
3134 pushClause (NOCLAUSE);
3138 context_exitInnerPlain (void) /*@modifies gc;@*/
3140 context_exitInner (exprNode_undefined);
3144 context_exitInner (exprNode exp)
3146 if (context_getFlag (FLG_GRAMMAR))
3148 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3151 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3152 ("inclause = %s", clause_nameTaken (gc.inclause)));
3154 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3155 gc.inclause = topClause (gc.clauses);
3157 if (gc.kind == CX_INNER)
3159 if (--gc.cont.cdepth == 0)
3161 gc.kind = CX_GLOBAL;
3162 gc.cont.glob = TRUE;
3167 if (gc.kind == CX_GLOBAL)
3169 llcontbuglit ("Attempt to exit global context");
3174 usymtab_exitScope (exp);
3179 context_enterStructInnerContext (void)
3181 if (context_getFlag (FLG_GRAMMAR))
3183 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3186 if (gc.kind == CX_GLOBAL)
3191 else if (gc.kind == CX_INNER)
3200 usymtab_enterScope ();
3202 if (context_getFlag (FLG_GRAMMAR))
3204 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3209 context_exitStructInnerContext (void)
3211 if (context_getFlag (FLG_GRAMMAR))
3213 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3216 if (gc.kind == CX_INNER)
3218 if (gc.cont.cdepth <= 0)
3220 llcontbuglit ("Attempt to exit inner context with no depth");
3221 gc.kind = CX_GLOBAL;
3222 gc.cont.glob = TRUE;
3228 if (gc.cont.cdepth == 0)
3230 gc.kind = CX_GLOBAL;
3231 gc.cont.glob = TRUE;
3237 if (gc.kind == CX_GLOBAL)
3239 llcontbuglit ("Attempt to exit global context");
3244 usymtab_exitScope (exprNode_undefined);
3246 if (context_getFlag (FLG_GRAMMAR))
3248 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3253 context_exitInnerSafe (void)
3255 if (context_getFlag (FLG_GRAMMAR))
3257 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3260 if (gc.kind == CX_INNER)
3262 if (--gc.cont.cdepth <= 0)
3267 else if (gc.kind == CX_GLOBAL)
3269 llcontbuglit ("Attempt to exit global context");
3274 if (usymtab_inDeepScope ())
3276 usymtab_exitScope (exprNode_undefined);
3282 void setModuleAccess (void)
3284 gc.facct = typeIdSet_emptySet ();
3286 if (fileId_isValid (currentFile ()))
3288 cstring baseName = fileloc_getBase (g_currentloc);
3290 if (context_getFlag (FLG_ACCESSFILE))
3292 if (usymtab_existsType (baseName))
3294 gc.facct = typeIdSet_insert (gc.facct,
3295 usymtab_getTypeId (baseName));
3303 if (context_getFlag (FLG_ACCESSMODULE))
3306 bool hasaccess = FALSE;
3308 for (i = 0; i < gc.nmods; i++)
3310 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3312 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3321 gc.inheader = fileId_isHeader (currentFile ());
3325 llcontbuglit ("Current file not defined\n");
3326 gc.facct = typeIdSet_emptySet ();
3328 gc.inheader = FALSE;
3331 /* 17 Jan 1995: forgot to clear nacct */
3333 gc.nacct = typeIdSet_emptySet ();
3337 context_enterFileAux (void)
3343 context_enterFile (void)
3345 context_enterFileAux ();
3346 usymtab_enterFile ();
3350 context_enterMacroFile (void)
3352 context_enterFileAux ();
3356 context_inFunction (void)
3358 kcontext ck = gc.kind;
3360 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3364 context_inFunctionLike (void)
3366 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3367 || gc.kind == CX_FCNDECLARATION
3368 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3372 context_inRealFunction (void)
3374 kcontext ck = gc.kind;
3376 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3380 context_processAllMacros (void)
3382 usymtab_enterFile ();
3384 gc.inmacrocache = TRUE;
3385 macrocache_processUndefinedElements (gc.mc);
3387 usymtab_exitFile ();
3389 gc.inmacrocache = FALSE;
3390 macrocache_finalize ();
3394 ** this happens once at the end of each C file
3396 ** check each Macro that was defined in current file.c or current file.h
3401 context_processMacros (void)
3403 if (fileId_isValid (currentFile ()))
3406 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileName (currentFile ())));
3408 gc.inmacrocache = TRUE;
3410 DPRINTF (("Processing macros: %s", cbase));
3411 lastfl = macrocache_processFileElements (gc.mc, cbase);
3412 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3414 cstring_free (cbase);
3416 if (fileloc_isDefined (lastfl))
3418 g_currentloc = fileloc_update (g_currentloc, lastfl);
3422 gc.inmacrocache = FALSE;
3427 context_processingMacros (void)
3429 return (gc.inmacrocache);
3433 context_exitCFile (void)
3435 if (gc.kind != CX_GLOBAL)
3438 (cstring_makeLiteral ("File ended outside global scope"));
3441 if (gc.insuppressregion)
3443 /* gack...don't reverse the order of these lines! ;-> */
3444 gc.insuppressregion = FALSE;
3445 llerrorlit (FLG_SYNTAX,
3446 "File ended in ignore errors region, "
3447 "possible missing /*@end*/");
3450 /* fix up parse errors */
3452 while (!usymtab_inFileScope ())
3454 usymtab_quietExitScope (g_currentloc);
3458 ** Clear the file-specific modifies information.
3461 sRefSetList_elements (gc.modrecs, mods)
3463 sRefSet_clearStatics (mods);
3464 } end_sRefSetList_elements ;
3466 sRefSetList_clear (gc.modrecs);
3468 context_processMacros ();
3471 usymtab_exitFile ();
3473 gc.inDerivedFile = FALSE;
3474 filelocStack_clear (gc.locstack);
3476 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3478 gc.cont.glob = TRUE;
3482 context_restoreFlagSettings ();
3483 gc.savedFlags = FALSE;
3487 DPRINTF (("After exiting file: "));
3488 usymtab_printAll ();
3493 context_exitMacroCache (void)
3495 if (gc.kind != CX_GLOBAL)
3497 if (context_inMacro ())
3498 /* this is okay, file could end without newline in macro */
3500 DPRINTF (("Still in macro: %s",
3501 context_unparse ()));
3502 context_exitFunction ();
3506 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3507 context_unparse ()));
3508 gc.kind = CX_GLOBAL;
3513 ** no longer valid here
3514 ** if (gc.insuppressregion)
3516 ** gc.insuppressregion = FALSE;
3517 ** llerror ("File ended in ignore errors region, possible missing @");
3521 gc.cont.glob = TRUE;
3525 context_saveLocation (void)
3527 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3528 fileloc_free (gc.saveloc);
3529 gc.saveloc = fileloc_copy (g_currentloc);
3533 context_getSaveLocation (void)
3535 fileloc fl = gc.saveloc;
3536 gc.saveloc = fileloc_undefined;
3540 /*@observer@*/ cstring
3541 context_inFunctionName (void)
3543 if (gc.kind == CX_FUNCTION
3544 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3545 || gc.kind == CX_MACROCONST
3546 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3548 return (uentry_rawName (gc.cont.fcn));
3552 llcontbuglit ("context_inFunctionName: not in function");
3553 return (cstring_undefined);
3558 context_userSetFlag (flagcode f, bool b)
3560 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3562 if (f == FLG_NEVERINCLUDE && b)
3564 if (gc.flags[FLG_EXPORTHEADER])
3566 llerror_flagWarning (cstring_makeLiteral
3567 ("setting +neverinclude after +exportheader. "
3568 "Turning off exportheader, since headers are not checked "
3569 "when +neverinclude is used."));
3571 gc.flags[FLG_EXPORTHEADER] = FALSE;
3576 if (f == FLG_EXPORTHEADER && b)
3578 if (gc.flags[FLG_NEVERINCLUDE])
3580 llerror_flagWarning (cstring_makeLiteral
3581 ("setting +exportheader after +neverinclude. "
3582 "Not setting exportheader, since headers are not checked "
3583 "when +neverinclude is used."));
3584 gc.flags[FLG_EXPORTHEADER] = FALSE;
3590 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3592 bool lastsetting = context_getFlag (f);
3594 if (bool_equal (lastsetting, b)
3595 && !flagcode_isSpecialFlag (f)
3596 && !flagcode_isIdemFlag (f)
3597 && !flagcode_hasArgument (f))
3599 llerror_flagWarning (message ("setting %s%s redundant with current value",
3600 cstring_makeLiteralTemp (b ? "+" : "-"),
3601 flagcode_unparse (f)));
3605 if (flagcode_isWarnUseFlag (f) && b)
3607 if (!context_getFlag (FLG_WARNUSE))
3609 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3610 flagcode_unparse (f)));
3616 if (flagcode_isLibraryFlag (f))
3618 if (gc.library != FLG_ANSILIB
3621 llerror_flagWarning (message ("selecting library %s after library %s was "
3622 "selected (only one library may be used)",
3623 flagcode_unparse (f),
3624 flagcode_unparse (gc.library)));
3627 if (f == FLG_UNIXLIB)
3629 if (context_getFlag (FLG_WARNUNIXLIB))
3631 llerror_flagWarning (cstring_makeLiteral
3632 ("selecting unix library. Unix library is "
3633 "ad hoc addition to POSIX library. Recommend "
3634 "use +posixlib to select POSIX library instead. "
3635 "Use -warnunixlib to suppress this message."));
3642 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3644 llerror_flagWarning (message
3645 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3646 flagcode_unparse (f)));
3649 gc.setGlobally[f] = TRUE;
3650 context_setFlag (f, b);
3654 context_fileSetFlag (flagcode f, ynm set)
3658 context_saveFlagSettings ();
3661 if (ynm_isOff (set))
3663 context_setFlagAux (f, FALSE, TRUE, FALSE);
3665 else if (ynm_isOn (set))
3667 context_setFlagAux (f, TRUE, TRUE, FALSE);
3668 gc.setLocally[f] = TRUE;
3672 context_restoreFlag (f);
3677 context_restoreFlag (flagcode f)
3684 message ("Attempt to restore flag %s when no file scope flags "
3686 flagcode_unparse (f)),
3691 context_addFlagMarker (f, MAYBE);
3692 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3698 context_setFlag (flagcode f, bool b)
3700 context_setFlagAux (f, b, FALSE, FALSE);
3704 context_setFlagTemp (flagcode f, bool b)
3706 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3711 # define DOSET(ff,b) \
3712 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3713 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3714 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3715 gc.flags[ff] = b; } while (FALSE)
3718 context_setFlagAux (flagcode f, bool b, bool inFile,
3719 /*@unused@*/ bool isRestore)
3721 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3723 if (f == FLG_USESTDERR)
3726 g_msgstream = stderr;
3728 g_msgstream = stdout;
3733 ** Removed test for special flags.
3736 if (flagcode_isIdemFlag (f))
3745 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3747 if (b) /* Turing higher level on, turns on all lower levels */
3751 case FLG_ITS4MOSTRISKY:
3752 DOSET (FLG_ITS4VERYRISKY, b);
3754 case FLG_ITS4VERYRISKY:
3755 DOSET (FLG_ITS4RISKY, b);
3758 DOSET (FLG_ITS4MODERATERISK, b);
3760 case FLG_ITS4MODERATERISK:
3761 DOSET (FLG_ITS4LOWRISK, b);
3763 case FLG_ITS4LOWRISK:
3768 else /* Turning level off, turns off all higher levels */
3772 case FLG_ITS4LOWRISK:
3773 DOSET (FLG_ITS4MODERATERISK, b);
3775 case FLG_ITS4MODERATERISK:
3776 DOSET (FLG_ITS4RISKY, b);
3779 DOSET (FLG_ITS4VERYRISKY, b);
3781 case FLG_ITS4VERYRISKY:
3782 DOSET (FLG_ITS4MOSTRISKY, b);
3784 case FLG_ITS4MOSTRISKY:
3794 DOSET (FLG_ALLEMPTY, b);
3795 DOSET (FLG_IFEMPTY, b);
3796 DOSET (FLG_WHILEEMPTY, b);
3797 DOSET (FLG_FOREMPTY, b);
3800 DOSET (FLG_PREDBOOL, b);
3801 DOSET (FLG_PREDBOOLINT, b);
3802 DOSET (FLG_PREDBOOLPTR, b);
3803 DOSET (FLG_PREDBOOLOTHERS, b);
3806 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3807 DOSET (FLG_CHECKEDGLOBALIAS, b);
3808 DOSET (FLG_CHECKMODGLOBALIAS, b);
3809 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3812 DOSET (FLG_ALLBLOCK, b);
3813 DOSET (FLG_IFBLOCK, b);
3814 DOSET (FLG_WHILEBLOCK, b);
3815 DOSET (FLG_FORBLOCK, b);
3829 DOSET (FLG_GRAMMAR, b);
3831 case FLG_CODEIMPONLY:
3832 DOSET (FLG_CODEIMPONLY, b);
3833 DOSET (FLG_GLOBIMPONLY, b);
3834 DOSET (FLG_RETIMPONLY, b);
3835 DOSET (FLG_STRUCTIMPONLY, b);
3837 case FLG_SPECALLIMPONLY:
3838 DOSET (FLG_SPECALLIMPONLY, b);
3839 DOSET (FLG_SPECGLOBIMPONLY, b);
3840 DOSET (FLG_SPECRETIMPONLY, b);
3841 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3843 case FLG_ALLIMPONLY:
3844 DOSET (FLG_ALLIMPONLY, b);
3845 DOSET (FLG_GLOBIMPONLY, b);
3846 DOSET (FLG_RETIMPONLY, b);
3847 DOSET (FLG_STRUCTIMPONLY, b);
3848 DOSET (FLG_SPECGLOBIMPONLY, b);
3849 DOSET (FLG_SPECRETIMPONLY, b);
3850 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3852 case FLG_ANSILIMITS:
3853 DOSET (FLG_ANSILIMITS, b);
3854 DOSET (FLG_CONTROLNESTDEPTH, b);
3855 DOSET (FLG_STRINGLITERALLEN, b);
3856 DOSET (FLG_INCLUDENEST, b);
3857 DOSET (FLG_NUMSTRUCTFIELDS, b);
3858 DOSET (FLG_NUMENUMMEMBERS, b);
3862 context_setValue (FLG_CONTROLNESTDEPTH, DEFAULT_CONTROLNESTDEPTH);
3863 context_setValue (FLG_STRINGLITERALLEN, DEFAULT_STRINGLITERALLEN);
3864 context_setValue (FLG_INCLUDENEST, DEFAULT_INCLUDENEST);
3865 context_setValue (FLG_NUMSTRUCTFIELDS, DEFAULT_NUMSTRUCTFIELDS);
3866 context_setValue (FLG_NUMENUMMEMBERS, DEFAULT_NUMENUMMEMBERS);
3869 case FLG_EXTERNALNAMELEN:
3870 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3871 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3873 case FLG_INTERNALNAMELEN:
3874 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3875 DOSET (FLG_INTERNALNAMELEN, TRUE);
3877 case FLG_EXTERNALNAMECASEINSENSITIVE:
3878 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3880 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3882 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3883 context_setValue (FLG_EXTERNALNAMELEN, 0);
3886 case FLG_INTERNALNAMECASEINSENSITIVE:
3887 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3889 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3891 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3892 context_setValue (FLG_INTERNALNAMELEN, 0);
3895 case FLG_INTERNALNAMELOOKALIKE:
3896 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3898 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3900 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3901 context_setValue (FLG_INTERNALNAMELEN, 0);
3905 DOSET (FLG_MODNOMODS, b);
3906 DOSET (FLG_MODGLOBSUNSPEC, b);
3907 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3910 DOSET (FLG_EXPORTVAR, b);
3911 DOSET (FLG_EXPORTFCN, b);
3912 DOSET (FLG_EXPORTTYPE, b);
3913 DOSET (FLG_EXPORTMACRO, b);
3914 DOSET (FLG_EXPORTCONST, b);
3915 gc.anyExports = TRUE;
3918 DOSET (FLG_RETEXPOSE, b);
3919 DOSET (FLG_ASSIGNEXPOSE, b);
3920 DOSET (FLG_CASTEXPOSE, b);
3923 DOSET (FLG_RETVALBOOL, b);
3924 DOSET (FLG_RETVALINT, b);
3925 DOSET (FLG_RETVALOTHER, b);
3930 DOSET (FLG_EXPORTLOCAL, FALSE);
3931 DOSET (FLG_DECLUNDEF, FALSE);
3932 DOSET (FLG_SPECUNDEF, FALSE);
3933 DOSET (FLG_TOPUNUSED, FALSE);
3937 DOSET (FLG_LOOPLOOPBREAK, b);
3938 DOSET (FLG_LOOPSWITCHBREAK, b);
3939 DOSET (FLG_SWITCHLOOPBREAK, b);
3940 DOSET (FLG_SWITCHSWITCHBREAK, b);
3941 DOSET (FLG_LOOPLOOPCONTINUE, b);
3942 DOSET (FLG_DEEPBREAK, b);
3945 DOSET (FLG_FORLOOPEXEC, b);
3946 DOSET (FLG_WHILELOOPEXEC, b);
3947 DOSET (FLG_ITERLOOPEXEC, b);
3950 DOSET (FLG_ACCESSMODULE, b);
3951 DOSET (FLG_ACCESSFILE, b);
3952 DOSET (FLG_ACCESSCZECH, b);
3955 DOSET (FLG_ALLMACROS, b);
3956 DOSET (FLG_FCNMACROS, b);
3957 DOSET (FLG_CONSTMACROS, b);
3960 if (b) { DOSET (FLG_ACCESSCZECH, b); }
3961 DOSET (FLG_CZECHFUNCTIONS, b);
3962 DOSET (FLG_CZECHVARS, b);
3963 DOSET (FLG_CZECHCONSTANTS, b);
3964 DOSET (FLG_CZECHTYPES, b);
3967 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
3968 DOSET (FLG_SLOVAKFUNCTIONS, b);
3969 DOSET (FLG_SLOVAKVARS, b);
3970 DOSET (FLG_SLOVAKCONSTANTS, b);
3971 DOSET (FLG_SLOVAKTYPES, b);
3973 case FLG_CZECHOSLOVAK:
3974 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
3975 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
3976 DOSET (FLG_CZECHOSLOVAKVARS, b);
3977 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
3978 DOSET (FLG_CZECHOSLOVAKTYPES, b);
3981 DOSET (FLG_NULLSTATE, b);
3982 DOSET (FLG_NULLDEREF, b);
3983 DOSET (FLG_NULLASSIGN, b);
3984 DOSET (FLG_NULLPASS, b);
3985 DOSET (FLG_NULLRET, b);
3988 DOSET (FLG_NULLSTATE, b);
3989 DOSET (FLG_NULLDEREF, b);
3990 DOSET (FLG_NULLASSIGN, b);
3991 DOSET (FLG_NULLPASS, b);
3992 DOSET (FLG_NULLRET, b);
3993 DOSET (FLG_COMPDEF, b);
3994 DOSET (FLG_COMPMEMPASS, b);
3995 DOSET (FLG_UNIONDEF, b);
3996 DOSET (FLG_MEMTRANS, b);
3997 DOSET (FLG_USERELEASED, b);
3998 DOSET (FLG_ALIASUNIQUE, b);
3999 DOSET (FLG_MAYALIASUNIQUE, b);
4000 DOSET (FLG_MUSTFREE, b);
4001 DOSET (FLG_MUSTDEFINE, b);
4002 DOSET (FLG_GLOBSTATE, b);
4003 DOSET (FLG_COMPDESTROY, b);
4004 DOSET (FLG_MUSTNOTALIAS, b);
4005 DOSET (FLG_MEMIMPLICIT, b);
4006 DOSET (FLG_BRANCHSTATE, b);
4007 /*@fallthrough@*/ /* also sets memtrans flags */
4009 DOSET (FLG_MEMTRANS, b);
4010 DOSET (FLG_EXPOSETRANS, b);
4011 DOSET (FLG_OBSERVERTRANS, b);
4012 DOSET (FLG_DEPENDENTTRANS, b);
4013 DOSET (FLG_NEWREFTRANS, b);
4014 DOSET (FLG_ONLYTRANS, b);
4015 DOSET (FLG_OWNEDTRANS, b);
4016 DOSET (FLG_FRESHTRANS, b);
4017 DOSET (FLG_SHAREDTRANS, b);
4018 DOSET (FLG_TEMPTRANS, b);
4019 DOSET (FLG_KEPTTRANS, b);
4020 DOSET (FLG_REFCOUNTTRANS, b);
4021 DOSET (FLG_STATICTRANS, b);
4022 DOSET (FLG_UNKNOWNTRANS, b);
4023 DOSET (FLG_KEEPTRANS, b);
4024 DOSET (FLG_IMMEDIATETRANS, b);
4031 if (b && !gc.anyExports
4032 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4033 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4034 || f == FLG_EXPORTCONST
4035 || f == FLG_EXPORTANY))
4037 gc.anyExports = TRUE;
4042 context_maybeSet (flagcode d)
4044 return (gc.flags[d] || gc.setLocally[d]);
4048 context_getFlag (flagcode d)
4050 return (gc.flags[d]);
4054 context_flagOn (flagcode f, fileloc loc)
4056 return (!context_suppressFlagMsg (f, loc));
4059 static void context_saveFlagSettings (void)
4061 gc.savedFlags = TRUE;
4062 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4063 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4066 static void context_restoreFlagSettings (void)
4068 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4069 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4070 gc.savedFlags = FALSE;
4073 void context_setFilename (fileId fid, int lineno)
4074 /*@globals fileloc g_currentloc;@*/
4075 /*@modifies g_currentloc@*/
4077 if (fileId_baseEqual (currentFile (), fid))
4084 fileloc_setColumn (g_currentloc, 0);
4086 if (fileloc_isSpecialFile (g_currentloc))
4088 gc.inDerivedFile = TRUE;
4091 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4093 int maxdepth = context_getValue (FLG_INCLUDENEST);
4095 if (filelocStack_size (gc.locstack) > maxdepth)
4097 int depth = filelocStack_includeDepth (gc.locstack);
4099 if (depth > maxdepth)
4103 message ("Maximum include nesting depth "
4104 "(%d, current depth %d) exceeded",
4107 filelocStack_nextTop (gc.locstack)))
4109 filelocStack_printIncludes (gc.locstack);
4115 g_currentloc = fileloc_create (fid, lineno, 1);
4116 gc.inheader = fileId_isHeader (currentFile ());
4118 context_enterFileAux ();
4122 void context_enterIterDef (/*@observer@*/ uentry le)
4124 context_enterMacro (le);
4125 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4126 gc.kind = CX_ITERDEF;
4129 void context_enterIterEnd (/*@observer@*/ uentry le)
4131 context_enterMacro (le);
4132 gc.kind = CX_ITEREND;
4136 context_destroyMod (void)
4137 /*@globals killed gc@*/
4140 ctype_destroyMod ();
4144 fileTable_free (gc.ftab);
4145 filelocStack_free (gc.locstack);
4147 gc.ftab = fileTable_undefined;
4149 macrocache_free (gc.mc);
4150 sfree (gc.moduleaccess);
4153 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4154 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4157 sRefSetList_free (gc.modrecs);
4159 flagMarkerList_free (gc.markers);
4161 messageLog_free (gc.msgLog);
4163 clauseStack_free (gc.clauses);
4166 cstring_free (gc.msgAnnote);
4167 globSet_free (gc.globs_used);
4168 metaStateTable_free (gc.stateTable);
4169 annotationTable_free (gc.annotTable);
4176 bool context_msgBoolInt (void)
4178 return gc.flags [FLG_BOOLINT];
4181 bool context_msgCharInt (void)
4183 return gc.flags [FLG_CHARINT];
4186 bool context_msgEnumInt (void)
4188 return gc.flags [FLG_ENUMINT];
4191 bool context_msgPointerArith (void)
4193 return gc.flags [FLG_POINTERARITH];
4196 bool context_msgStrictOps (void)
4198 return gc.flags [FLG_STRICTOPS];
4202 bool context_msgLh (void)
4204 return gc.flags [FLG_DOLH];
4208 void context_pushLoc (void)
4210 fileloc_free (gc.pushloc);
4211 gc.pushloc = gc.saveloc;
4212 gc.saveloc = fileloc_undefined;
4215 void context_popLoc (void)
4217 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4220 bool context_inGlobalScope (void)
4222 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4225 bool context_inInnerScope (void)
4227 return (gc.kind == CX_INNER);
4230 void context_setProtectVars (void)
4232 gc.protectVars = TRUE;
4235 bool context_anyErrors (void)
4237 return (gc.numerrors > 0);
4240 void context_hasError (void)
4243 DPRINTF (("num errors: %d", gc.numerrors));
4246 int context_numErrors (void)
4248 return gc.numerrors;
4251 bool context_neednl (void)
4256 void context_setNeednl (void)
4261 int context_getExpect (void)
4263 return (context_getValue (FLG_EXPECT));
4267 int context_getLCLExpect (void)
4269 return (context_getValue (FLG_LCLEXPECT));
4273 int context_getLimit (void)
4275 return (context_getValue (FLG_LIMIT));
4278 bool context_unlimitedMessages (void)
4280 return (context_getLimit () < 0);
4283 void context_releaseVars (void)
4285 llassert (gc.protectVars);
4286 gc.protectVars = FALSE;
4289 void context_sizeofReleaseVars (void)
4291 /* If there is a nested sizeof, this might not hold:
4292 llassert (gc.protectVars);
4295 gc.protectVars = FALSE;
4298 bool context_inProtectVars (void)
4300 return (gc.protectVars);
4303 void context_hideShowscan (void)
4305 gc.flags[FLG_SHOWSCAN] = FALSE;
4308 void context_unhideShowscan (void)
4310 gc.flags[FLG_SHOWSCAN] = TRUE;
4313 bool context_inHeader (void)
4315 return (gc.inheader);
4318 fileTable context_fileTable (void)
4323 cstring context_tmpdir (void)
4325 return (context_getString (FLG_TMPDIR));
4328 messageLog context_messageLog (void)
4333 bool context_inMacroFunction (void)
4335 return (gc.kind == CX_MACROFCN);
4338 bool context_inMacroConstant (void)
4340 return (gc.kind == CX_MACROCONST);
4343 bool context_inUnknownMacro (void)
4345 return (gc.kind == CX_UNKNOWNMACRO);
4348 void context_setShownFunction (void)
4350 gc.showfunction = FALSE;
4353 bool context_doDump (void)
4355 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4358 bool context_doMerge (void)
4360 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4363 cstring context_getDump (void)
4365 return context_getString (FLG_DUMP);
4368 cstring context_getMerge (void)
4370 return context_getString (FLG_MERGE);
4374 bool context_inLCLLib (void)
4376 return (gc.kind == CX_LCLLIB);
4379 bool context_inImport (void)
4381 return (gc.inimport);
4384 void context_enterImport (void)
4389 void context_leaveImport (void)
4391 gc.inimport = FALSE;
4395 bool context_inMacro (void)
4397 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4398 || gc.kind == CX_UNKNOWNMACRO
4399 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4402 bool context_inIterDef (void)
4404 return (gc.kind == CX_ITERDEF);
4407 bool context_inIterEnd (void)
4409 return (gc.kind == CX_ITEREND);
4412 int context_getLinesProcessed (void)
4414 return (gc.linesprocessed);
4417 int context_getSpecLinesProcessed (void)
4419 return (gc.speclinesprocessed);
4423 void context_processedSpecLine (void)
4425 gc.speclinesprocessed++;
4428 void context_resetSpecLines (void)
4430 gc.speclinesprocessed = 0;
4434 bool context_inGlobalContext (void)
4436 return (gc.kind == CX_GLOBAL);
4439 static void context_quietExitScopes (void)
4442 ** Try to restore the global scope (after an error).
4445 while (!usymtab_inFileScope ())
4447 usymtab_quietExitScope (g_currentloc);
4450 gc.cont.glob = TRUE;
4451 gc.kind = CX_GLOBAL;
4454 void context_checkGlobalScope (void)
4456 if (gc.kind != CX_GLOBAL)
4458 if (context_inMacro ())
4460 ; /* evans 2001-10-14: Okay to be in a macro here! */
4464 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4465 context_quietExitScopes ();
4470 void context_setFileId (fileId s)
4472 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4475 bool context_setBoolName (void)
4477 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4481 cstring context_printBoolName (void)
4483 if (context_setBoolName ())
4485 return context_getBoolName ();
4489 return cstring_makeLiteralTemp ("boolean");
4493 cstring context_getBoolName (void)
4495 return (context_getString (FLG_BOOLTYPE));
4498 cstring context_getFalseName (void)
4500 return (context_getString (FLG_BOOLFALSE));
4503 cstring context_getTrueName (void)
4505 return (context_getString (FLG_BOOLTRUE));
4508 cstring context_getLarchPath (void)
4510 return (context_getString (FLG_LARCHPATH));
4513 cstring context_getLCLImportDir (void)
4515 return (context_getString (FLG_LCLIMPORTDIR));
4518 static void context_setJustPopped (void)
4520 gc.justpopped = TRUE;
4523 void context_clearJustPopped (void)
4525 gc.justpopped = FALSE;
4528 bool context_justPopped (void)
4530 return (gc.justpopped);
4533 void context_setMacroMissingParams (void)
4535 gc.macroMissingParams = TRUE;
4538 void context_resetMacroMissingParams (void)
4540 gc.macroMissingParams = FALSE;
4543 bool context_isMacroMissingParams (void)
4545 return (gc.macroMissingParams);
4548 void context_showFilelocStack (void)
4550 filelocStack_printIncludes (gc.locstack);
4553 metaStateTable context_getMetaStateTable (void)
4555 return gc.stateTable;
4558 metaStateInfo context_lookupMetaStateInfo (cstring key)
4560 return metaStateTable_lookup (gc.stateTable, key);
4563 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4565 annotationInfo ainfo;
4567 ainfo = annotationTable_lookup (gc.annotTable, annot);
4572 void context_addAnnotation (annotationInfo ainfo)
4574 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4578 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4579 annotationInfo_getLoc (ainfo));
4581 annotationInfo_free (ainfo);
4585 annotationTable_insert (gc.annotTable, ainfo);
4589 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4591 if (metaStateTable_contains (gc.stateTable, mname))
4595 message ("Duplicate metastate declaration: %s", mname),
4596 metaStateInfo_getLoc (msinfo));
4597 cstring_free (mname);
4598 metaStateInfo_free (msinfo);
4602 DPRINTF (("Adding meta state: %s", mname));
4603 metaStateTable_insert (gc.stateTable, mname, msinfo);
4607 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4609 if (metaStateTable_size (gc.stateTable) > 0)
4611 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4612 /*@i32 should use smaller value... */
4613 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4615 metaStateTable_elements (gc.stateTable, msname, msi)
4617 mtContextNode context = metaStateInfo_getContext (msi);
4619 if (mtContextNode_matchesRefStrict (context, s))
4621 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4622 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4626 cstring_copy (metaStateInfo_getName (msi)),
4627 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4628 stateInfo_copy (sinfo)));
4632 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4635 end_metaStateTable_elements ;
4637 stateInfo_free (sinfo);
4638 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4643 stateInfo_free (sinfo);
4644 return valueTable_undefined;
4648 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4650 if (metaStateTable_size (gc.stateTable) > 0)
4652 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4653 /*@i32 should use smaller value... */
4655 metaStateTable_elements (gc.stateTable, msname, msi)
4657 /*@i23 only add global...*/
4658 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4659 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4661 valueTable_insert (res,
4662 cstring_copy (metaStateInfo_getName (msi)),
4663 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4664 stateInfo_copy (sinfo)));
4666 end_metaStateTable_elements ;
4668 stateInfo_free (sinfo);
4669 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4674 stateInfo_free (sinfo);
4675 return valueTable_undefined;