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_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_MODIFIES] = TRUE;
824 gc.flags[FLG_NESTCOMMENT] = TRUE;
825 gc.flags[FLG_GLOBALS] = TRUE;
826 gc.flags[FLG_FULLINITBLOCK] = TRUE;
827 gc.flags[FLG_INITSIZE] = TRUE;
828 gc.flags[FLG_INITALLELEMENTS] = TRUE;
830 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
832 gc.flags[FLG_LIKELYBOOL] = TRUE;
833 gc.flags[FLG_ZEROPTR] = TRUE;
834 gc.flags[FLG_NUMLITERAL] = TRUE;
835 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
836 gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
837 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
838 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
839 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
840 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
841 gc.flags[FLG_CASTFCNPTR] = TRUE;
842 gc.flags[FLG_DOLCS] = TRUE;
843 gc.flags[FLG_USEVARARGS] = TRUE;
844 gc.flags[FLG_MAINTYPE] = TRUE;
845 gc.flags[FLG_SPECMACROS] = TRUE;
846 gc.flags[FLG_REDEF] = TRUE;
847 gc.flags[FLG_MACRONEXTLINE] = TRUE;
849 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
850 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
852 gc.flags[FLG_WARNUSE] = TRUE;
853 gc.flags[FLG_PREDASSIGN] = TRUE;
854 gc.flags[FLG_MODOBSERVER] = TRUE;
855 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
856 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
858 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
859 gc.flags[FLG_RETIMPONLY] = TRUE;
860 gc.flags[FLG_GLOBIMPONLY] = TRUE;
861 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
862 gc.flags[FLG_PREPROC] = TRUE;
863 gc.flags[FLG_NAMECHECKS] = TRUE;
864 gc.flags[FLG_FORMATCODE] = TRUE;
865 gc.flags[FLG_FORMATTYPE] = TRUE;
866 gc.flags[FLG_BADFLAG] = TRUE;
867 gc.flags[FLG_WARNFLAGS] = TRUE;
868 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
869 gc.flags[FLG_WARNUNIXLIB] = TRUE;
870 gc.flags[FLG_WARNPOSIX] = TRUE;
871 gc.flags[FLG_SHOWCOL] = TRUE;
872 gc.flags[FLG_SHOWFUNC] = TRUE;
873 gc.flags[FLG_SUPCOUNTS] = TRUE;
874 gc.flags[FLG_HINTS] = TRUE;
875 gc.flags[FLG_SYNTAX] = TRUE;
876 gc.flags[FLG_TYPE] = TRUE;
877 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
878 gc.flags[FLG_ABSTRACT] = TRUE;
879 gc.flags[FLG_ITER] = TRUE;
880 gc.flags[FLG_CONTROL] = TRUE;
881 gc.flags[FLG_UNRECOG] = TRUE;
882 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
883 gc.flags[FLG_LINTCOMMENTS] = TRUE;
884 gc.flags[FLG_ACCESSCZECH] = TRUE;
885 gc.flags[FLG_ACCESSMODULE] = TRUE;
886 gc.flags[FLG_ACCESSFILE] = TRUE;
887 gc.flags[FLG_MACROVARPREFIX] = TRUE;
889 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
890 gc.flags[FLG_COMMENTERROR] = TRUE;
893 ** Changed for version 2.4.
896 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
899 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
903 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
908 ** C is way-lame, and you can initialize an array to a constant except where
909 ** it is declared. Hence, a macro is used to set the modeflags.
913 # define SETFLAGS() \
914 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
915 if (!flagcode_isModeFlag (modeflags[i])) \
916 { llbug (message ("not a mode flag: %s", \
917 flagcode_unparse (modeflags[i]))); } \
918 else { context_setFlag (modeflags[i], TRUE); } i++; }}
921 context_setMode (cstring s)
923 intSet setflags = intSet_new ();
927 if (flagcode_isModeFlag (code))
929 if (gc.setGlobally[code])
931 (void) intSet_insert (setflags, (int) code);
936 if (!intSet_isEmpty (setflags))
938 cstring rflags = cstring_undefined;
941 intSet_elements (setflags, el)
943 if (cstring_isUndefined (rflags))
945 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
949 rflags = message ("%q, %s", rflags,
950 flagcode_unparse ((flagcode) el));
954 if (num > 4 && intSet_size (setflags) > 6)
956 rflags = message ("%q, (%d others) ...", rflags,
957 intSet_size (setflags) - num);
960 } end_intSet_elements ;
962 voptgenerror (FLG_WARNFLAGS,
963 message ("Setting mode %s after setting mode flags will "
964 "override set values of flags: %s",
968 cstring_free (rflags);
971 intSet_free (setflags);
973 context_resetModeFlags ();
975 if (cstring_equalLit (s, "standard"))
977 flagcode modeflags[] =
979 FLG_ENUMINT, FLG_MACROMATCHNAME,
981 FLG_MACROUNDEF, FLG_RELAXQUALS,
982 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
983 FLG_CHECKSTRICTGLOBALIAS,
984 FLG_CHECKEDGLOBALIAS,
985 FLG_CHECKMODGLOBALIAS,
986 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
988 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
990 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
991 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
992 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
993 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
994 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
997 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
998 FLG_MACROSTMT, FLG_MACROPARENS,
1001 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1002 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1007 /* memchecks flags */
1009 FLG_NULLSTATE, FLG_NULLASSIGN,
1010 FLG_NULLPASS, FLG_NULLRET,
1012 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1015 /* memtrans flags */
1034 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1035 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1036 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1039 FLG_STATETRANSFER, FLG_STATEMERGE,
1040 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1042 FLG_IMPCHECKEDSPECGLOBALS,
1043 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1044 FLG_IFEMPTY, FLG_REALCOMPARE,
1045 FLG_BOOLOPS, FLG_PTRNEGATE,
1047 FLG_BUFFEROVERFLOWHIGH,
1054 else if (cstring_equalLit (s, "weak"))
1056 flagcode modeflags[] =
1058 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1059 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1060 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1061 FLG_CHARUNSIGNEDCHAR,
1063 FLG_VARUNUSED, FLG_FUNCUNUSED,
1065 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1068 FLG_BUFFEROVERFLOWHIGH,
1069 FLG_RETSTACK, FLG_PTRNEGATE,
1070 FLG_STATETRANSFER, FLG_STATEMERGE,
1071 FLG_LONGUNSIGNEDINTEGRAL,
1072 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1076 FLG_BUFFEROVERFLOWHIGH,
1082 else if (cstring_equalLit (s, "checks"))
1084 flagcode modeflags[] =
1086 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1087 FLG_STATETRANSFER, FLG_STATEMERGE,
1088 FLG_CHECKSTRICTGLOBALIAS,
1089 FLG_CHECKEDGLOBALIAS,
1090 FLG_CHECKMODGLOBALIAS,
1091 FLG_UNCHECKEDGLOBALIAS,
1093 FLG_STRINGLITNOROOM,
1094 FLG_STRINGLITSMALLER,
1095 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1096 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1097 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1098 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1099 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1100 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1101 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1102 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1103 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1104 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1105 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1106 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1107 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1108 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1115 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1119 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1121 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1122 FLG_EVALORDER, FLG_USEDEF,
1126 /* warn use flags */
1127 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1128 FLG_BUFFEROVERFLOWHIGH,
1130 /* memchecks flags */
1132 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1133 FLG_NULLPASS, FLG_NULLRET,
1135 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1137 /* memtrans flags */
1151 FLG_STATICINITTRANS,
1152 FLG_UNKNOWNINITTRANS,
1155 FLG_ONLYUNQGLOBALTRANS,
1156 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1157 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1158 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1161 FLG_NULLPOINTERARITH,
1162 FLG_SHADOW, FLG_DEPARRAYS,
1163 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1164 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1165 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1166 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1167 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1168 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1169 FLG_BOOLOPS, FLG_SHIFTSIGNED,
1170 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1175 else if (cstring_equalLit (s, "strict"))
1177 flagcode modeflags[] =
1179 FLG_CHECKSTRICTGLOBALIAS,
1180 FLG_CHECKEDGLOBALIAS,
1181 FLG_CHECKMODGLOBALIAS,
1182 FLG_UNCHECKEDGLOBALIAS,
1186 FLG_STRINGLITNOROOM,
1187 FLG_STRINGLITSMALLER,
1188 FLG_STATETRANSFER, FLG_STATEMERGE,
1189 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1190 FLG_ALLGLOBALS, FLG_IMPTYPE,
1191 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1192 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1193 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1194 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1197 FLG_ONLYUNQGLOBALTRANS,
1198 FLG_GLOBALSIMPMODIFIESNOTHING,
1199 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1200 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1201 FLG_USEALLGLOBS, FLG_RETALIAS,
1202 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1203 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1204 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1206 FLG_EXPORTITER, FLG_EXPORTCONST,
1207 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1208 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1210 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1212 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1213 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1214 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1215 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1216 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1217 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1218 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1219 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1221 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1224 FLG_MACROREDEF, FLG_MACROEMPTY,
1225 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1227 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1229 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1230 FLG_MODOBSERVERUNCON,
1235 /* warn use flags */
1236 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1237 FLG_BUFFEROVERFLOWHIGH,
1238 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1240 /* memchecks flags */
1241 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1242 FLG_NULLPASS, FLG_NULLRET,
1244 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1246 /* memtrans flags */
1262 FLG_STATICINITTRANS,
1263 FLG_UNKNOWNINITTRANS,
1265 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1266 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1267 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1271 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1273 FLG_SHADOW, FLG_DEPARRAYS,
1274 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1275 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1276 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1277 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1278 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1279 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1280 FLG_IMPCHECKEDSTRICTSTATICS,
1281 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1282 FLG_IMPCHECKMODINTERNALS,
1283 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1284 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1285 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1286 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1287 FLG_CONTROLNESTDEPTH,
1288 FLG_FORBLOCK, FLG_WHILEBLOCK,
1289 FLG_FOREMPTY, FLG_WHILEEMPTY,
1290 FLG_IFEMPTY, FLG_IFBLOCK,
1292 FLG_REALCOMPARE, FLG_BOOLOPS,
1293 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1295 FLG_SHIFTSIGNED, FLG_BITWISEOPS,
1296 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1304 llcontbug (message ("context_setMode: bad mode: %s", s));
1309 context_isSpecialFile (cstring fname)
1311 cstring ext = fileLib_getExtension (fname);
1313 return (cstring_equalLit (ext, ".y")
1314 || cstring_equalLit (ext, ".l")
1315 || cstring_equalLit (fname, "lex.yy.c"));
1319 context_isSystemDir (cstring dir)
1321 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1322 cstring savedir = thisdir;
1323 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1325 if (cstring_isDefined (nextdir))
1327 /*@access cstring@*/
1328 *nextdir = '\0'; /* closes thisdir */
1330 /*@noaccess cstring@*/
1333 /* 2001-09-09: added thisdir[0] != '\0'
1334 ** herbert: don't compare with an empty name!
1335 ** should return false for empty directory path
1338 while (!cstring_isEmpty (thisdir))
1340 DPRINTF (("Test: %s / %s", dir, thisdir));
1342 if (osd_equalCanonicalPrefix (dir, thisdir))
1344 cstring_free (savedir);
1348 if (cstring_isDefined (nextdir))
1351 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1353 if (cstring_isDefined (nextdir))
1355 /*@access cstring@*/
1358 /*@noaccess cstring@*/
1367 DPRINTF (("Returns FALSE"));
1368 cstring_free (savedir);
1373 context_addFileAccessType (typeId t)
1377 if (context_inFunctionLike ())
1379 gc.acct = typeIdSet_insert (gc.acct, t);
1382 gc.facct = typeIdSet_insert (gc.facct, t);
1384 base = fileloc_getBase (g_currentloc);
1385 insertModuleAccess (base, t);
1386 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1387 typeIdSet_unparse (gc.acct)));
1391 context_removeFileAccessType (typeId t)
1393 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1394 || gc.kind == CX_UNKNOWNMACRO)
1396 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1399 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1400 gc.nacct = typeIdSet_insert (gc.nacct, t);
1403 void context_enterFunctionHeader (void)
1405 if (context_getFlag (FLG_GRAMMAR))
1407 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1410 if (gc.kind != CX_GLOBAL)
1412 llparseerror (cstring_makeLiteral
1413 ("Likely parse error. Function header outside global context."));
1417 llassert (gc.kind == CX_GLOBAL);
1418 DPRINTF (("Enter function header!"));
1419 gc.inFunctionHeader = TRUE;
1423 void context_exitFunctionHeader (void)
1425 if (context_getFlag (FLG_GRAMMAR))
1427 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1430 DPRINTF (("Exit function header!"));
1431 gc.inFunctionHeader = FALSE;
1434 bool context_inFunctionHeader (void)
1436 return (gc.inFunctionHeader);
1439 void context_enterFunctionDeclaration (uentry e)
1441 if (context_getFlag (FLG_GRAMMAR))
1443 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1446 DPRINTF (("Enter function decl"));
1447 llassert (gc.savekind == CX_ERROR);
1448 gc.savekind = gc.kind;
1449 gc.savecont = gc.cont;
1450 gc.kind = CX_FCNDECLARATION;
1454 void context_exitFunctionDeclaration (void)
1456 if (context_getFlag (FLG_GRAMMAR))
1458 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1461 DPRINTF (("Exit function decl"));
1462 llassert (gc.savekind != CX_ERROR);
1463 llassert (gc.kind == CX_FCNDECLARATION);
1464 gc.kind = gc.savekind;
1465 gc.cont = gc.savecont;
1467 gc.savekind = CX_ERROR;
1469 if (context_getFlag (FLG_GRAMMAR))
1471 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1475 bool context_inFunctionDeclaration (void)
1477 return (gc.kind == CX_FCNDECLARATION);
1482 context_enterMacro (/*@observer@*/ uentry e)
1484 context_enterFunction (e);
1485 gc.kind = CX_MACROFCN;
1489 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1491 llassert (uentry_isFunction (e));
1492 context_enterFunction (e);
1493 gc.kind = CX_UNKNOWNMACRO;
1496 void context_enterAndClause (exprNode e)
1499 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1500 pushClause (ANDCLAUSE);
1503 void context_enterOrClause (exprNode e)
1505 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1506 pushClause (ORCLAUSE);
1509 bool context_inDeepLoop (void)
1511 bool inLoop = FALSE;
1513 clauseStack_elements (gc.clauses, el)
1515 if (clause_isLoop (el))
1524 } end_clauseStack_elements;
1529 bool context_inDeepSwitch (void)
1531 bool inLoop = FALSE;
1533 clauseStack_elements (gc.clauses, el)
1535 if (clause_isSwitch (el))
1544 } end_clauseStack_elements;
1549 bool context_inDeepLoopSwitch (void)
1551 bool inLoop = FALSE;
1553 clauseStack_elements (gc.clauses, el)
1555 if (clause_isBreakable (el))
1564 } end_clauseStack_elements;
1569 clause context_breakClause (void)
1571 clauseStack_elements (gc.clauses, el)
1573 if (clause_isSwitch (el))
1577 else if (clause_isLoop (el))
1585 } end_clauseStack_elements;
1590 clause context_nextBreakClause (void)
1592 bool hasOne = FALSE;
1594 clauseStack_elements (gc.clauses, el)
1596 if (clause_isBreakable (el))
1607 } end_clauseStack_elements;
1612 bool context_inConditional (void)
1614 clauseStack_elements (gc.clauses, el)
1617 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1618 ** to distinguish if from ? for this
1621 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1625 } end_clauseStack_elements;
1630 void context_exitAndClause (exprNode pred, exprNode tbranch)
1632 context_setJustPopped ();
1634 llassert (gc.inclause == ANDCLAUSE);
1636 usymtab_popAndBranch (pred, tbranch);
1637 clauseStack_pop (gc.clauses);
1638 gc.inclause = topClause (gc.clauses);
1641 void context_exitOrClause (exprNode pred, exprNode tbranch)
1643 context_setJustPopped ();
1645 llassert (gc.inclause == ORCLAUSE);
1647 usymtab_popOrBranch (pred, tbranch);
1648 clauseStack_pop (gc.clauses);
1649 gc.inclause = topClause (gc.clauses);
1652 static void context_enterCondClauseAux (clause cl)
1658 static void context_enterTrueAux (exprNode e, clause cl)
1661 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1665 void context_enterIterClause (void)
1667 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1670 void context_enterDoWhileClause (void)
1672 pushClause (DOWHILECLAUSE);
1675 void context_enterWhileClause (exprNode e)
1677 context_enterTrueAux (e, WHILECLAUSE);
1680 void context_enterForClause (exprNode e)
1682 context_enterTrueAux (e, FORCLAUSE);
1685 void context_enterTrueClause (exprNode e)
1687 context_enterTrueAux (e, TRUECLAUSE);
1690 void context_enterSwitch (exprNode e)
1693 usymtab_switchBranch (e);
1694 context_enterCondClauseAux (SWITCHCLAUSE);
1697 void context_exitSwitch (exprNode e, bool allpaths)
1699 usymtab_exitSwitch (e, allpaths);
1701 while (clause_isCase (clauseStack_top (gc.clauses)))
1703 clauseStack_pop (gc.clauses);
1706 context_exitClauseSimp ();
1709 void context_enterCaseClause (exprNode e)
1711 bool branch = FALSE;
1713 DPRINTF (("Enter case clause!"));
1715 branch = usymtab_newCase (exprNode_undefined, e);
1719 context_enterCondClauseAux (CASECLAUSE);
1723 static void context_enterFalseClauseAux (exprNode e, clause cl)
1726 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1728 clauseStack_switchTop (gc.clauses, cl);
1731 void context_enterFalseClause (exprNode e)
1734 context_enterFalseClauseAux (e, FALSECLAUSE);
1738 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1740 gc.kind = CX_MACROCONST;
1742 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1744 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1748 usymtab_enterScope ();
1749 sRef_enterFunctionScope ();
1751 gc.globs = globSet_undefined;
1752 globSet_clear (gc.globs_used);
1753 gc.mods = sRefSet_undefined;
1756 uentry context_getHeader (void)
1758 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1760 llfatalbug (message ("context_getHeader: bad call: %q",
1761 context_unparse ()));
1764 return (gc.cont.fcn);
1768 context_setFunctionDefined (fileloc loc)
1772 case CX_UNKNOWNMACRO:
1775 uentry_setFunctionDefined (gc.cont.fcn, loc);
1778 /* (not a bug because of parse errors) */
1784 context_enterFunction (/*@exposed@*/ uentry e)
1786 gc.kind = CX_FUNCTION;
1789 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1791 if (uentry_hasAccessType (e))
1793 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1801 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1802 typeIdSet_unparse (gc.acct)));
1804 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1806 gc.globs = uentry_getGlobs (e);
1807 globSet_clear (gc.globs_used);
1808 gc.mods = uentry_getMods (e);
1810 usymtab_enterFunctionScope (e);
1811 sRef_enterFunctionScope ();
1815 context_enterOldStyleScope (void)
1817 gc.kind = CX_OLDSTYLESCOPE;
1818 DPRINTF (("Enter old style scope!"));
1819 usymtab_enterFunctionScope (uentry_undefined);
1823 context_completeOldStyleFunction (uentry e)
1825 llassert (gc.kind == CX_OLDSTYLESCOPE);
1827 gc.kind = CX_FUNCTION;
1830 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1832 if (uentry_hasAccessType (e))
1834 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1842 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1843 typeIdSet_unparse (gc.acct)));
1845 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1847 if (!globSet_isEmpty (uentry_getGlobs (e)))
1849 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1850 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1853 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1855 gc.globs = uentry_getGlobs (e);
1856 globSet_clear (gc.globs_used);
1858 gc.mods = uentry_getMods (e);
1860 if (!sRefSet_isEmpty (gc.mods))
1862 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1863 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1866 sRef_enterFunctionScope ();
1869 static bool context_checkStrictGlobals (void)
1871 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1874 static bool context_hasGlobs (void)
1876 if (context_inFunctionLike ())
1878 return (uentry_hasGlobs (gc.cont.fcn));
1886 static bool context_checkCheckedGlobals (void)
1888 return (context_getFlag (FLG_GLOBALS)
1889 && (context_getFlag (FLG_GLOBUNSPEC)
1890 || context_hasGlobs ()));
1893 static bool context_checkUnknownGlobals (void)
1895 /* should be uentry_hasGlobs ? */
1897 return (context_getFlag (FLG_ALLGLOBALS)
1898 && (context_getFlag (FLG_GLOBUNSPEC)
1899 || context_hasGlobs ()));
1902 static bool context_checkUncheckedGlobals (void)
1908 context_checkExport (uentry e)
1910 if (!gc.anyExports) return FALSE;
1912 if (uentry_isFunction (e)
1913 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1915 return context_maybeSet (FLG_EXPORTFCN);
1917 else if (uentry_isExpandedMacro (e))
1919 return context_maybeSet (FLG_EXPORTMACRO);
1921 else if (uentry_isVariable (e))
1923 return context_maybeSet (FLG_EXPORTVAR);
1925 else if (uentry_isEitherConstant (e))
1927 return context_maybeSet (FLG_EXPORTCONST);
1929 else if (uentry_isIter (e) || uentry_isEndIter (e))
1931 return context_maybeSet (FLG_EXPORTITER);
1933 else if (uentry_isDatatype (e))
1935 return context_maybeSet (FLG_EXPORTTYPE);
1944 context_checkGlobUse (uentry glob)
1947 if (uentry_isCheckedStrict (glob))
1949 return context_checkStrictGlobals ();
1951 else if (uentry_isChecked (glob))
1953 return context_checkCheckedGlobals ();
1955 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
1957 return context_checkUnknownGlobals ();
1961 llassert (uentry_isUnchecked (glob));
1963 return context_checkUncheckedGlobals ();
1968 context_checkAliasGlob (uentry glob)
1970 if (uentry_isCheckedStrict (glob))
1972 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
1974 else if (uentry_isChecked (glob))
1976 return gc.flags[FLG_CHECKEDGLOBALIAS];
1978 else if (uentry_isCheckMod (glob))
1980 return gc.flags[FLG_CHECKMODGLOBALIAS];
1984 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
1986 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
1990 bool context_checkInternalUse (void)
1992 if (context_hasGlobs ())
1994 return (gc.flags[FLG_INTERNALGLOBS]);
1998 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2003 context_checkGlobMod (sRef el)
2005 uentry ue = sRef_getUentry (el);
2007 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2009 if (uentry_isCheckedModify (ue)
2010 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2012 if (context_hasMods ())
2014 return (gc.flags[FLG_MODGLOBS]);
2018 if (uentry_isCheckedStrict (ue))
2020 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2024 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2030 if (context_hasMods ())
2032 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2042 context_usedGlobal (/*@exposed@*/ sRef el)
2044 if (!globSet_member (gc.globs_used, el))
2047 ** The first time a global is used in a function, we need
2048 ** to clear the derived sRefs, since they were set for the
2049 ** previous function.
2052 sRef_clearDerived (el);
2053 gc.globs_used = globSet_insert (gc.globs_used, el);
2057 /*@observer@*/ sRefSet
2058 context_modList (void)
2064 context_globAccess (sRef s)
2066 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2067 return (globSet_member (gc.globs, s));
2071 context_hasAccess (typeId t)
2073 if (context_inFunctionLike ())
2075 DPRINTF (("Access %d / %s",
2076 t, typeIdSet_unparse (gc.acct)));
2077 return (typeIdSet_member (gc.acct, t));
2081 return (context_hasFileAccess (t));
2086 context_hasFileAccess (typeId t)
2088 return (typeIdSet_member (gc.facct, t));
2092 context_unparseAccess (void)
2094 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2095 typeIdSet_unparse (gc.facct)));
2099 context_unparseClauses (void)
2101 return (clauseStack_unparse (gc.clauses));
2105 context_couldHaveAccess (typeId t)
2107 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2109 return (typeIdSet_member (gc.acct, t));
2113 return (typeIdSet_member (gc.facct, t));
2118 context_getRetType (void)
2120 ctype f = ctype_undefined;
2122 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2124 f = uentry_getType (gc.cont.fcn);
2126 else if (gc.kind == CX_UNKNOWNMACRO)
2128 return ctype_unknown;
2132 llcontbuglit ("context_getRetType: not in a function context");
2133 return ctype_unknown;
2136 if (!ctype_isFunction (f))
2138 if (ctype_isKnown (f))
2140 llbuglit ("context_getRetType: not a function");
2143 return ctype_unknown;
2145 return (ctype_getReturnType (f));
2149 context_hasMods (void)
2151 if (context_inFunctionLike ())
2153 return (uentry_hasMods (gc.cont.fcn));
2162 context_exitAllClauses (void)
2164 while (!clauseStack_isEmpty (gc.clauses))
2166 clause el = clauseStack_top (gc.clauses);
2169 if (clause_isNone (el))
2171 usymtab_quietExitScope (g_currentloc);
2172 clauseStack_pop (gc.clauses);
2176 context_exitClausePlain ();
2180 clauseStack_clear (gc.clauses);
2181 gc.inclause = NOCLAUSE;
2185 context_exitAllClausesQuiet (void)
2187 while (!clauseStack_isEmpty (gc.clauses))
2189 clause el = clauseStack_top (gc.clauses);
2192 usymtab_quietExitScope (g_currentloc);
2193 clauseStack_pop (gc.clauses);
2196 clauseStack_clear (gc.clauses);
2197 gc.inclause = NOCLAUSE;
2201 void context_exitClauseSimp (void)
2204 context_setJustPopped ();
2205 clauseStack_pop (gc.clauses);
2206 gc.inclause = topClause (gc.clauses);
2210 void context_exitCaseClause (void)
2212 context_setJustPopped ();
2213 usymtab_popCaseBranch ();
2214 clauseStack_pop (gc.clauses);
2215 gc.inclause = topClause (gc.clauses);
2219 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2221 context_setJustPopped ();
2222 /*@i32 was makeAlt */
2223 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2224 clauseStack_pop (gc.clauses);
2225 gc.inclause = topClause (gc.clauses);
2228 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2230 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2232 if (gc.inclause != TRUECLAUSE)
2234 llparseerror (cstring_makeLiteral
2235 ("Likely parse error. Conditional clauses are inconsistent."));
2239 context_setJustPopped ();
2240 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2241 clauseStack_pop (gc.clauses);
2242 gc.inclause = topClause (gc.clauses);
2245 void context_exitIterClause (exprNode body)
2247 llassert (gc.inclause == ITERCLAUSE);
2249 context_setJustPopped ();
2251 if (context_getFlag (FLG_LOOPEXEC))
2253 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2257 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2260 clauseStack_pop (gc.clauses);
2261 gc.inclause = topClause (gc.clauses);
2264 static void context_popCase (void) {
2266 ** If we are exiting an outer clause, sometimes still in a switch case.
2280 DPRINTF (("Popping case clause: %s",
2281 clauseStack_unparse (gc.clauses)));
2283 if (gc.inclause == CASECLAUSE) {
2284 context_exitCaseClause ();
2288 void context_exitWhileClause (exprNode pred, exprNode body)
2290 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2294 if (gc.inclause != WHILECLAUSE) {
2295 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2296 clauseStack_unparse (gc.clauses)));
2299 llassert (gc.inclause == WHILECLAUSE);
2301 context_setJustPopped ();
2305 ** predicate must be false after while loop (unless there are breaks)
2308 if (context_getFlag (FLG_LOOPEXEC))
2310 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2314 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2318 usymtab_addGuards (invGuards);
2319 guardSet_free (invGuards);
2321 clauseStack_pop (gc.clauses);
2322 gc.inclause = topClause (gc.clauses);
2325 void context_exitDoWhileClause (exprNode pred)
2327 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2329 if (gc.inclause == CASECLAUSE) {
2330 /* handle Duff's device */
2331 clauseStack_pop (gc.clauses);
2332 gc.inclause = topClause (gc.clauses);
2335 llassert (gc.inclause == DOWHILECLAUSE);
2337 context_setJustPopped ();
2340 usymtab_addGuards (invGuards);
2341 guardSet_free (invGuards);
2343 clauseStack_pop (gc.clauses);
2344 gc.inclause = topClause (gc.clauses);
2347 void context_exitForClause (exprNode forPred, exprNode body)
2349 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2351 llassert (gc.inclause == FORCLAUSE);
2352 context_setJustPopped ();
2355 ** predicate must be false after while loop (unless there are breaks)
2358 if (context_getFlag (FLG_LOOPEXEC))
2360 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2364 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2367 usymtab_addGuards (invGuards);
2368 guardSet_free (invGuards);
2369 clauseStack_pop (gc.clauses);
2370 gc.inclause = topClause (gc.clauses);
2373 static void context_exitClausePlain (void)
2375 llassert (gc.inclause != NOCLAUSE);
2377 if (gc.inclause == FALSECLAUSE)
2379 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2383 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2387 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2389 context_setJustPopped ();
2391 if (gc.inclause == FALSECLAUSE)
2393 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2395 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2397 clauseStack_pop (gc.clauses);
2398 gc.inclause = topClause (gc.clauses);
2402 context_exitTrueClause (pred, tbranch);
2407 context_returnFunction (void)
2409 usymtab_checkFinalScope (TRUE);
2413 context_exitFunction (void)
2415 DPRINTF (("Exit function: %s", context_unparse ()));
2417 if (!context_inFunction () && !context_inMacroConstant ()
2418 && !context_inUnknownMacro ()
2419 && !context_inIterDef () && !context_inIterEnd ())
2422 ** not a bug because of parse errors
2429 if (context_inMacro () && usymtab_inFunctionScope ())
2431 usymtab_exitScope (exprNode_undefined);
2434 if (uentry_hasGlobs (gc.cont.fcn))
2436 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2440 if (uentry_hasMods (gc.cont.fcn))
2442 if (context_getFlag (FLG_MUSTMOD))
2444 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2448 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2451 ** clear file static modifies
2454 /* do this first to get unused error messages */
2456 usymtab_exitScope (exprNode_undefined);
2457 sRef_exitFunctionScope ();
2459 gc.showfunction = FALSE;
2460 gc.kind = CX_GLOBAL;
2461 gc.cont.glob = TRUE;
2463 gc.globs = globSet_new ();
2464 globSet_clear (gc.globs_used);
2465 gc.mods = sRefSet_new ();
2468 llassert (clauseStack_isEmpty (gc.clauses));
2469 llassert (gc.inclause == NOCLAUSE);
2470 DPRINTF (("After exit function: %s", context_unparse ()));
2474 context_quietExitFunction (void)
2476 while (gc.kind == CX_INNER)
2478 context_exitInnerPlain ();
2481 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2482 && !context_inIterDef () && !context_inIterEnd ())
2487 usymtab_quietExitScope (g_currentloc);
2489 gc.showfunction = FALSE;
2490 gc.kind = CX_GLOBAL;
2491 gc.cont.glob = TRUE;
2493 gc.globs = globSet_new ();
2494 globSet_clear (gc.globs_used);
2495 gc.mods = sRefSet_new ();
2497 sRef_exitFunctionScope ();
2501 /*@observer@*/ uentryList
2502 context_getParams (void)
2504 if (context_inFunctionLike ())
2506 return (uentry_getParams (gc.cont.fcn));
2510 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2511 return uentryList_undefined;
2515 /*@observer@*/ globSet
2516 context_getUsedGlobs (void)
2518 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2519 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2521 return (gc.globs_used);
2525 context_moduleName ()
2527 return (fileloc_getBase (g_currentloc));
2530 /*@observer@*/ globSet
2531 context_getGlobs (void)
2533 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2534 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2540 context_addBoolAccess (void)
2542 cstring bname = context_getString (FLG_BOOLTYPE);
2543 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2545 addModuleAccess (cstring_copy (bname), boolt);
2547 /* for sys/types (perhaps, this is bogus!) */
2548 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2553 context_canAccessBool (void)
2560 static typeId boolType = typeId_invalid;
2562 if (typeId_isInvalid (boolType))
2564 boolType = usymtab_getTypeId (context_getBoolName ());
2567 if (typeId_isInvalid (boolType)) {
2570 return (typeIdSet_member (gc.acct, boolType));
2575 /* evs 2000-07-25: old version - replaced */
2578 context_boolImplementationType () {
2579 /* For now, this is bogus! */
2584 context_canAccessBool (void)
2586 static typeId boolType = typeId_invalid;
2588 if (typeId_isInvalid (boolType))
2590 boolType = usymtab_getTypeId (context_getBoolName ());
2593 if (!typeId_isInvalid (boolType))
2595 return context_hasAccess (boolType);
2606 context_setMessageAnnote (/*@only@*/ cstring s)
2608 llassert (cstring_isUndefined (gc.msgAnnote));
2613 context_hasMessageAnnote (void)
2615 return (cstring_isDefined (gc.msgAnnote));
2619 context_clearMessageAnnote (void)
2621 if (cstring_isDefined (gc.msgAnnote))
2623 cstring_free (gc.msgAnnote);
2624 gc.msgAnnote = cstring_undefined;
2629 context_getMessageAnnote (void)
2631 cstring st = gc.msgAnnote;
2633 gc.msgAnnote = cstring_undefined;
2638 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2640 llassert (sRef_isInvalid (gc.aliasAnnote));
2641 llassert (!sRef_sameName (s, t));
2643 gc.aliasAnnoteAls = t;
2647 context_hasAliasAnnote (void)
2649 return (sRef_isValid (gc.aliasAnnote));
2653 context_clearAliasAnnote (void)
2655 gc.aliasAnnote = sRef_undefined;
2659 context_getAliasAnnote (void)
2661 sRef ret = gc.aliasAnnote;
2662 sRef als = gc.aliasAnnoteAls;
2664 llassert (sRef_isValid (ret) && sRef_isValid (als));
2666 gc.aliasAnnote = sRef_undefined;
2667 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2671 context_recordFileModifies (sRefSet mods)
2673 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2677 context_recordFileGlobals (globSet mods)
2679 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2680 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2684 context_setCommentMarkerChar (char c)
2686 llassert (c != '\0');
2688 context_setValue (FLG_COMMENTCHAR, (int) c);
2692 context_getCommentMarkerChar (void)
2694 return ((char) context_getValue (FLG_COMMENTCHAR));
2698 context_setValue (flagcode flag, int val)
2700 int index = flagcode_valueIndex (flag);
2702 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2710 llerror_flagWarning (message ("Value for %s must be a positive "
2711 "number (given %d)",
2712 flagcode_unparse (flag), val));
2715 if (flag == FLG_LINELEN && val < MINLINELEN)
2717 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2718 flagcode_unparse (flag),
2724 case FLG_INCLUDENEST:
2725 case FLG_CONTROLNESTDEPTH:
2726 case FLG_STRINGLITERALLEN:
2727 case FLG_NUMSTRUCTFIELDS:
2728 case FLG_NUMENUMMEMBERS:
2729 case FLG_INDENTSPACES:
2733 llerror_flagWarning (message ("Value for %s must be a non-negative "
2734 "number (given %d)",
2735 flagcode_unparse (flag), val));
2744 gc.values[index] = val;
2748 context_setValueAndFlag (flagcode flag, int val)
2750 gc.flags[flag] = TRUE;
2751 context_setValue (flag, val);
2755 context_getValue (flagcode flag)
2757 int index = flagcode_valueIndex (flag);
2759 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2760 return (gc.values[index]);
2764 context_getCounter (flagcode flag)
2766 int index = flagcode_valueIndex (flag);
2768 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2769 return (gc.counters[index]);
2773 context_incCounter (flagcode flag)
2775 int index = flagcode_valueIndex (flag);
2777 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2779 gc.counters[index]++;
2783 context_decCounter (flagcode flag)
2785 int index = flagcode_valueIndex (flag);
2787 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2788 gc.counters[index]--;
2791 bool context_showFunction (void)
2793 return (gc.showfunction);
2797 context_setString (flagcode flag, cstring val)
2799 int index = flagcode_stringIndex (flag);
2801 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2803 if (flag == FLG_SYSTEMDIRS)
2805 llassert (cstring_isDefined (val));
2807 if (cstring_firstChar (val) == '\"')
2810 cstring tval = cstring_copy (cstring_suffix (val, 1));
2812 if (cstring_lastChar (tval) != '\"')
2814 int n = cstring_length (tval) - 1;
2816 while (isspace ((int) cstring_getChar (tval, n)))
2821 if (cstring_getChar (tval, n) != '\"')
2823 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2827 cstring otval = tval;
2828 tval = cstring_prefix (tval, n);
2829 cstring_free (otval);
2833 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2834 DPRINTF (("val = %s", val));
2835 cstring_free (tval);
2836 cstring_free (oval);
2840 if (flag == FLG_TMPDIR)
2842 llassert (cstring_isDefined (val));
2844 if (cstring_length (val) == 0)
2847 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2849 else if (cstring_lastChar (val) != CONNECTCHAR)
2851 val = cstring_appendChar (val, CONNECTCHAR);
2859 if (cstring_length (val) >= 1
2860 && cstring_firstChar (val) == '\"')
2862 llerror_flagWarning (message
2863 ("setting %s to string beginning with \". You probably "
2864 "don't meant to have the \"'s.",
2865 flagcode_unparse (flag)));
2868 if (flag == FLG_BOOLTYPE)
2873 gc.strings[index] = val;
2876 static /*@exposed@*/ cstring
2877 context_exposeString (flagcode flag)
2879 int index = flagcode_stringIndex (flag);
2881 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2882 return (gc.strings[index]);
2886 context_getString (flagcode flag)
2888 return (context_exposeString (flag));
2892 context_resetErrors (void)
2897 void context_initMod (void)
2898 /*@globals undef gc; @*/
2900 gc.kind = CX_GLOBAL;
2902 gc.savekind = CX_ERROR;
2903 gc.savecont.glob = FALSE;
2905 gc.instandardlib = FALSE;
2908 gc.linesprocessed = 0;
2909 gc.speclinesprocessed = 0;
2910 gc.insuppressregion = FALSE;
2911 gc.macroMissingParams = FALSE;
2912 gc.preprocessing = FALSE;
2913 gc.incommandline = FALSE;
2914 gc.mc = macrocache_create ();
2916 gc.maxmods = DEFAULTMAXMODS;
2917 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2919 gc.library = FLG_ANSILIB;
2921 gc.locstack = filelocStack_new ();
2922 gc.modrecs = sRefSetList_undefined;
2923 gc.anyExports = FALSE;
2925 gc.ftab = fileTable_create ();
2926 gc.msgLog = messageLog_new ();
2927 gc.inimport = FALSE;
2928 gc.inDerivedFile = FALSE;
2929 gc.inheader = FALSE;
2930 gc.markers = flagMarkerList_new ();
2931 gc.cont.glob = TRUE;
2932 gc.showfunction = FALSE;
2933 gc.msgAnnote = cstring_undefined;
2934 gc.aliasAnnote = sRef_undefined;
2935 gc.aliasAnnoteAls = sRef_undefined;
2936 gc.boolType = ctype_bool;
2937 gc.mods = sRefSet_new ();
2939 gc.saveloc = fileloc_undefined;
2941 gc.inmacrocache = FALSE;
2942 gc.inclause = NOCLAUSE;
2943 gc.clauses = clauseStack_new ();
2944 gc.globs = globSet_new ();
2945 gc.nacct = typeIdSet_emptySet ();
2946 gc.acct = typeIdSet_emptySet ();
2947 gc.facct = typeIdSet_emptySet ();
2948 gc.savedFlags = FALSE;
2949 gc.pushloc = fileloc_undefined;
2950 gc.protectVars = FALSE;
2951 gc.justpopped = FALSE;
2952 gc.isNullGuarded = NO;
2953 gc.globs_used = globSet_undefined;
2957 gc.setGlobally[code] = FALSE;
2958 gc.setLocally[code] = FALSE;
2959 } end_allFlagCodes ;
2963 context_resetAllFlags ();
2964 assertSet (gc.flags); /* Can't use global in defines */
2965 assertSet (gc.saveflags);
2966 assertSet (gc.values);
2967 assertSet (gc.strings);
2969 conext_resetAllCounters ();
2970 assertSet (gc.counters);
2972 context_setMode (DEFAULT_MODE);
2974 gc.stateTable = metaStateTable_create ();
2975 gc.annotTable = annotationTable_create ();
2977 gc.inFunctionHeader = FALSE;
2979 DPRINTF (("Annotations: \n%s",
2980 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
2981 DPRINTF (("State: \n%s",
2982 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
2987 context_typeofZero (void)
2989 ctype ct = ctype_int;
2991 if (context_getFlag (FLG_ZEROPTR))
2993 ct = ctype_makeConj (ct, ctype_voidPointer);
2996 if (context_getFlag (FLG_ZEROBOOL)) {
2997 ct = ctype_makeConj (ct, ctype_bool);
3004 context_typeofOne (void)
3006 ctype ct = ctype_int;
3008 /* 1 is on longer a bool (was before 2.4)
3009 if (!context_getFlag (FLG_ABSTRACTBOOL))
3011 ct = ctype_makeConj (ct, ctype_bool);
3019 context_unparse (void)
3026 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3029 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3032 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3035 s = message ("Inner Context [%d] : %q",
3037 fileloc_unparse (g_currentloc));
3040 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3041 uentry_unparse (gc.cont.fcn),
3042 fileloc_unparse (g_currentloc),
3043 typeIdSet_unparse (gc.acct),
3044 sRefSet_unparse (gc.mods));
3047 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3049 case CX_UNKNOWNMACRO:
3050 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3053 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3056 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3059 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3061 case CX_FCNDECLARATION:
3062 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3065 s = message ("Un-unparseable context: %d", (int) gc.kind);
3069 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3074 context_currentFunctionType (void)
3076 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3078 return (uentry_getType (gc.cont.fcn));
3080 else if (gc.kind == CX_INNER)
3082 llcontbuglit ("context_currentFunctionType: inner context");
3083 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3084 return (context_currentFunctionType ());
3088 llcontbuglit ("context_currentFunctionType: not in function");
3089 return (ctype_undefined);
3094 context_enterInnerContext (void)
3096 if (context_getFlag (FLG_GRAMMAR))
3098 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3101 if (gc.kind == CX_GLOBAL)
3106 else if (gc.kind == CX_INNER)
3115 usymtab_enterScope ();
3116 pushClause (NOCLAUSE);
3120 context_exitInnerPlain (void) /*@modifies gc;@*/
3122 context_exitInner (exprNode_undefined);
3126 context_exitInner (exprNode exp)
3128 if (context_getFlag (FLG_GRAMMAR))
3130 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3133 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3134 ("inclause = %s", clause_nameTaken (gc.inclause)));
3136 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3137 gc.inclause = topClause (gc.clauses);
3139 if (gc.kind == CX_INNER)
3141 if (--gc.cont.cdepth == 0)
3143 gc.kind = CX_GLOBAL;
3144 gc.cont.glob = TRUE;
3149 if (gc.kind == CX_GLOBAL)
3151 llcontbuglit ("Attempt to exit global context");
3156 usymtab_exitScope (exp);
3161 context_enterStructInnerContext (void)
3163 if (context_getFlag (FLG_GRAMMAR))
3165 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3168 if (gc.kind == CX_GLOBAL)
3173 else if (gc.kind == CX_INNER)
3182 usymtab_enterScope ();
3184 if (context_getFlag (FLG_GRAMMAR))
3186 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3191 context_exitStructInnerContext (void)
3193 if (context_getFlag (FLG_GRAMMAR))
3195 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3198 if (gc.kind == CX_INNER)
3200 if (gc.cont.cdepth <= 0)
3202 llcontbuglit ("Attempt to exit inner context with no depth");
3203 gc.kind = CX_GLOBAL;
3204 gc.cont.glob = TRUE;
3210 if (gc.cont.cdepth == 0)
3212 gc.kind = CX_GLOBAL;
3213 gc.cont.glob = TRUE;
3219 if (gc.kind == CX_GLOBAL)
3221 llcontbuglit ("Attempt to exit global context");
3226 usymtab_exitScope (exprNode_undefined);
3228 if (context_getFlag (FLG_GRAMMAR))
3230 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3235 context_exitInnerSafe (void)
3237 if (context_getFlag (FLG_GRAMMAR))
3239 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3242 if (gc.kind == CX_INNER)
3244 if (--gc.cont.cdepth <= 0)
3249 else if (gc.kind == CX_GLOBAL)
3251 llcontbuglit ("Attempt to exit global context");
3256 if (usymtab_inDeepScope ())
3258 usymtab_exitScope (exprNode_undefined);
3264 void setModuleAccess (void)
3266 gc.facct = typeIdSet_emptySet ();
3268 if (fileId_isValid (currentFile ()))
3270 cstring baseName = fileloc_getBase (g_currentloc);
3272 if (context_getFlag (FLG_ACCESSFILE))
3274 if (usymtab_existsType (baseName))
3276 gc.facct = typeIdSet_insert (gc.facct,
3277 usymtab_getTypeId (baseName));
3285 if (context_getFlag (FLG_ACCESSMODULE))
3288 bool hasaccess = FALSE;
3290 for (i = 0; i < gc.nmods; i++)
3292 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3294 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3303 gc.inheader = fileId_isHeader (currentFile ());
3307 llcontbuglit ("Current file not defined\n");
3308 gc.facct = typeIdSet_emptySet ();
3310 gc.inheader = FALSE;
3313 /* 17 Jan 1995: forgot to clear nacct */
3315 gc.nacct = typeIdSet_emptySet ();
3319 context_enterFileAux (void)
3325 context_enterFile (void)
3327 context_enterFileAux ();
3328 usymtab_enterFile ();
3332 context_enterMacroFile (void)
3334 context_enterFileAux ();
3338 context_inFunction (void)
3340 kcontext ck = gc.kind;
3342 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3346 context_inFunctionLike (void)
3348 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3349 || gc.kind == CX_FCNDECLARATION
3350 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3354 context_inRealFunction (void)
3356 kcontext ck = gc.kind;
3358 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3362 context_processAllMacros (void)
3364 usymtab_enterFile ();
3366 gc.inmacrocache = TRUE;
3367 macrocache_processUndefinedElements (gc.mc);
3369 usymtab_exitFile ();
3371 gc.inmacrocache = FALSE;
3372 macrocache_finalize ();
3376 ** this happens once at the end of each C file
3378 ** check each Macro that was defined in current file.c or current file.h
3383 context_processMacros (void)
3385 if (fileId_isValid (currentFile ()))
3388 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileName (currentFile ())));
3390 gc.inmacrocache = TRUE;
3392 DPRINTF (("Processing macros: %s", cbase));
3393 lastfl = macrocache_processFileElements (gc.mc, cbase);
3394 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3396 cstring_free (cbase);
3398 if (fileloc_isDefined (lastfl))
3400 g_currentloc = fileloc_update (g_currentloc, lastfl);
3404 gc.inmacrocache = FALSE;
3409 context_processingMacros (void)
3411 return (gc.inmacrocache);
3415 context_exitCFile (void)
3417 if (gc.kind != CX_GLOBAL)
3420 (cstring_makeLiteral ("File ended outside global scope"));
3423 if (gc.insuppressregion)
3425 /* gack...don't reverse the order of these lines! ;-> */
3426 gc.insuppressregion = FALSE;
3427 llerrorlit (FLG_SYNTAX,
3428 "File ended in ignore errors region, "
3429 "possible missing /*@end*/");
3432 /* fix up parse errors */
3434 while (!usymtab_inFileScope ())
3436 usymtab_quietExitScope (g_currentloc);
3440 ** Clear the file-specific modifies information.
3443 sRefSetList_elements (gc.modrecs, mods)
3445 sRefSet_clearStatics (mods);
3446 } end_sRefSetList_elements ;
3448 sRefSetList_clear (gc.modrecs);
3450 context_processMacros ();
3453 usymtab_exitFile ();
3455 gc.inDerivedFile = FALSE;
3456 filelocStack_clear (gc.locstack);
3458 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3460 gc.cont.glob = TRUE;
3464 context_restoreFlagSettings ();
3465 gc.savedFlags = FALSE;
3469 DPRINTF (("After exiting file: "));
3470 usymtab_printAll ();
3475 context_exitMacroCache (void)
3477 if (gc.kind != CX_GLOBAL)
3479 if (context_inMacro ())
3480 /* this is okay, file could end without newline in macro */
3482 DPRINTF (("Still in macro: %s",
3483 context_unparse ()));
3484 context_exitFunction ();
3488 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3489 context_unparse ()));
3490 gc.kind = CX_GLOBAL;
3495 ** no longer valid here
3496 ** if (gc.insuppressregion)
3498 ** gc.insuppressregion = FALSE;
3499 ** llerror ("File ended in ignore errors region, possible missing @");
3503 gc.cont.glob = TRUE;
3507 context_saveLocation (void)
3509 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3510 fileloc_free (gc.saveloc);
3511 gc.saveloc = fileloc_copy (g_currentloc);
3515 context_getSaveLocation (void)
3517 fileloc fl = gc.saveloc;
3518 gc.saveloc = fileloc_undefined;
3522 /*@observer@*/ cstring
3523 context_inFunctionName (void)
3525 if (gc.kind == CX_FUNCTION
3526 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3527 || gc.kind == CX_MACROCONST
3528 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3530 return (uentry_rawName (gc.cont.fcn));
3534 llcontbuglit ("context_inFunctionName: not in function");
3535 return (cstring_undefined);
3540 context_userSetFlag (flagcode f, bool b)
3542 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3544 if (f == FLG_NEVERINCLUDE && b)
3546 if (gc.flags[FLG_EXPORTHEADER])
3548 llerror_flagWarning (cstring_makeLiteral
3549 ("setting +neverinclude after +exportheader. "
3550 "Turning off exportheader, since headers are not checked "
3551 "when +neverinclude is used."));
3553 gc.flags[FLG_EXPORTHEADER] = FALSE;
3558 if (f == FLG_EXPORTHEADER && b)
3560 if (gc.flags[FLG_NEVERINCLUDE])
3562 llerror_flagWarning (cstring_makeLiteral
3563 ("setting +exportheader after +neverinclude. "
3564 "Not setting exportheader, since headers are not checked "
3565 "when +neverinclude is used."));
3566 gc.flags[FLG_EXPORTHEADER] = FALSE;
3572 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3574 bool lastsetting = context_getFlag (f);
3576 if (bool_equal (lastsetting, b)
3577 && !flagcode_isSpecialFlag (f)
3578 && !flagcode_isIdemFlag (f)
3579 && !flagcode_hasArgument (f))
3581 llerror_flagWarning (message ("setting %s%s redundant with current value",
3582 cstring_makeLiteralTemp (b ? "+" : "-"),
3583 flagcode_unparse (f)));
3587 if (flagcode_isWarnUseFlag (f) && b)
3589 if (!context_getFlag (FLG_WARNUSE))
3591 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3592 flagcode_unparse (f)));
3598 if (flagcode_isLibraryFlag (f))
3600 if (gc.library != FLG_ANSILIB
3603 llerror_flagWarning (message ("selecting library %s after library %s was "
3604 "selected (only one library may be used)",
3605 flagcode_unparse (f),
3606 flagcode_unparse (gc.library)));
3609 if (f == FLG_UNIXLIB)
3611 if (context_getFlag (FLG_WARNUNIXLIB))
3613 llerror_flagWarning (cstring_makeLiteral
3614 ("selecting unix library. Unix library is "
3615 "ad hoc addition to POSIX library. Recommend "
3616 "use +posixlib to select POSIX library instead. "
3617 "Use -warnunixlib to suppress this message."));
3624 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3626 llerror_flagWarning (message
3627 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3628 flagcode_unparse (f)));
3631 gc.setGlobally[f] = TRUE;
3632 context_setFlag (f, b);
3636 context_fileSetFlag (flagcode f, ynm set)
3640 context_saveFlagSettings ();
3643 if (ynm_isOff (set))
3645 context_setFlagAux (f, FALSE, TRUE, FALSE);
3647 else if (ynm_isOn (set))
3649 context_setFlagAux (f, TRUE, TRUE, FALSE);
3650 gc.setLocally[f] = TRUE;
3654 context_restoreFlag (f);
3659 context_restoreFlag (flagcode f)
3666 message ("Attempt to restore flag %s when no file scope flags "
3668 flagcode_unparse (f)),
3673 context_addFlagMarker (f, MAYBE);
3674 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3680 context_setFlag (flagcode f, bool b)
3682 context_setFlagAux (f, b, FALSE, FALSE);
3686 context_setFlagTemp (flagcode f, bool b)
3688 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3693 # define DOSET(ff,b) \
3694 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3695 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3696 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3697 gc.flags[ff] = b; } while (FALSE)
3700 context_setFlagAux (flagcode f, bool b, bool
3701 inFile, /*@unused@*/ bool isRestore)
3703 DPRINTF (("set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3705 if (f == FLG_USESTDERR)
3708 g_msgstream = stderr;
3710 g_msgstream = stdout;
3715 ** Removed test for special flags.
3718 if (flagcode_isIdemFlag (f))
3727 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3729 if (b) /* Turing higher level on, turns on all lower levels */
3733 case FLG_ITS4MOSTRISKY:
3734 DOSET (FLG_ITS4VERYRISKY, b);
3736 case FLG_ITS4VERYRISKY:
3737 DOSET (FLG_ITS4RISKY, b);
3740 DOSET (FLG_ITS4MODERATERISK, b);
3742 case FLG_ITS4MODERATERISK:
3743 DOSET (FLG_ITS4LOWRISK, b);
3745 case FLG_ITS4LOWRISK:
3750 else /* Turning level off, turns off all higher levels */
3754 case FLG_ITS4LOWRISK:
3755 DOSET (FLG_ITS4MODERATERISK, b);
3757 case FLG_ITS4MODERATERISK:
3758 DOSET (FLG_ITS4RISKY, b);
3761 DOSET (FLG_ITS4VERYRISKY, b);
3763 case FLG_ITS4VERYRISKY:
3764 DOSET (FLG_ITS4MOSTRISKY, b);
3766 case FLG_ITS4MOSTRISKY:
3776 DOSET (FLG_ALLEMPTY, b);
3777 DOSET (FLG_IFEMPTY, b);
3778 DOSET (FLG_WHILEEMPTY, b);
3779 DOSET (FLG_FOREMPTY, b);
3782 DOSET (FLG_PREDBOOL, b);
3783 DOSET (FLG_PREDBOOLINT, b);
3784 DOSET (FLG_PREDBOOLPTR, b);
3785 DOSET (FLG_PREDBOOLOTHERS, b);
3788 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3789 DOSET (FLG_CHECKEDGLOBALIAS, b);
3790 DOSET (FLG_CHECKMODGLOBALIAS, b);
3791 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3794 DOSET (FLG_ALLBLOCK, b);
3795 DOSET (FLG_IFBLOCK, b);
3796 DOSET (FLG_WHILEBLOCK, b);
3797 DOSET (FLG_FORBLOCK, b);
3811 DOSET (FLG_GRAMMAR, b);
3813 case FLG_CODEIMPONLY:
3814 DOSET (FLG_CODEIMPONLY, b);
3815 DOSET (FLG_GLOBIMPONLY, b);
3816 DOSET (FLG_RETIMPONLY, b);
3817 DOSET (FLG_STRUCTIMPONLY, b);
3819 case FLG_SPECALLIMPONLY:
3820 DOSET (FLG_SPECALLIMPONLY, b);
3821 DOSET (FLG_SPECGLOBIMPONLY, b);
3822 DOSET (FLG_SPECRETIMPONLY, b);
3823 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3825 case FLG_ALLIMPONLY:
3826 DOSET (FLG_ALLIMPONLY, b);
3827 DOSET (FLG_GLOBIMPONLY, b);
3828 DOSET (FLG_RETIMPONLY, b);
3829 DOSET (FLG_STRUCTIMPONLY, b);
3830 DOSET (FLG_SPECGLOBIMPONLY, b);
3831 DOSET (FLG_SPECRETIMPONLY, b);
3832 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3834 case FLG_ANSILIMITS:
3835 DOSET (FLG_ANSILIMITS, b);
3836 DOSET (FLG_CONTROLNESTDEPTH, b);
3837 DOSET (FLG_STRINGLITERALLEN, b);
3838 DOSET (FLG_INCLUDENEST, b);
3839 DOSET (FLG_NUMSTRUCTFIELDS, b);
3840 DOSET (FLG_NUMENUMMEMBERS, b);
3844 context_setValue (FLG_CONTROLNESTDEPTH, DEFAULT_CONTROLNESTDEPTH);
3845 context_setValue (FLG_STRINGLITERALLEN, DEFAULT_STRINGLITERALLEN);
3846 context_setValue (FLG_INCLUDENEST, DEFAULT_INCLUDENEST);
3847 context_setValue (FLG_NUMSTRUCTFIELDS, DEFAULT_NUMSTRUCTFIELDS);
3848 context_setValue (FLG_NUMENUMMEMBERS, DEFAULT_NUMENUMMEMBERS);
3851 case FLG_EXTERNALNAMELEN:
3852 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3853 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3855 case FLG_INTERNALNAMELEN:
3856 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3857 DOSET (FLG_INTERNALNAMELEN, TRUE);
3859 case FLG_EXTERNALNAMECASEINSENSITIVE:
3860 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3862 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3864 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3865 context_setValue (FLG_EXTERNALNAMELEN, 0);
3868 case FLG_INTERNALNAMECASEINSENSITIVE:
3869 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3871 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3873 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3874 context_setValue (FLG_INTERNALNAMELEN, 0);
3877 case FLG_INTERNALNAMELOOKALIKE:
3878 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3880 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3882 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3883 context_setValue (FLG_INTERNALNAMELEN, 0);
3887 DOSET (FLG_MODNOMODS, b);
3888 DOSET (FLG_MODGLOBSUNSPEC, b);
3889 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3892 DOSET (FLG_EXPORTVAR, b);
3893 DOSET (FLG_EXPORTFCN, b);
3894 DOSET (FLG_EXPORTTYPE, b);
3895 DOSET (FLG_EXPORTMACRO, b);
3896 DOSET (FLG_EXPORTCONST, b);
3897 gc.anyExports = TRUE;
3900 DOSET (FLG_RETEXPOSE, b);
3901 DOSET (FLG_ASSIGNEXPOSE, b);
3902 DOSET (FLG_CASTEXPOSE, b);
3905 DOSET (FLG_RETVALBOOL, b);
3906 DOSET (FLG_RETVALINT, b);
3907 DOSET (FLG_RETVALOTHER, b);
3912 DOSET (FLG_EXPORTLOCAL, FALSE);
3913 DOSET (FLG_DECLUNDEF, FALSE);
3914 DOSET (FLG_SPECUNDEF, FALSE);
3915 DOSET (FLG_TOPUNUSED, FALSE);
3919 DOSET (FLG_LOOPLOOPBREAK, b);
3920 DOSET (FLG_LOOPSWITCHBREAK, b);
3921 DOSET (FLG_SWITCHLOOPBREAK, b);
3922 DOSET (FLG_SWITCHSWITCHBREAK, b);
3923 DOSET (FLG_LOOPLOOPCONTINUE, b);
3924 DOSET (FLG_DEEPBREAK, b);
3927 DOSET (FLG_ACCESSMODULE, b);
3928 DOSET (FLG_ACCESSFILE, b);
3929 DOSET (FLG_ACCESSCZECH, b);
3932 DOSET (FLG_ALLMACROS, b);
3933 DOSET (FLG_FCNMACROS, b);
3934 DOSET (FLG_CONSTMACROS, b);
3937 if (b) { DOSET (FLG_ACCESSCZECH, b); }
3938 DOSET (FLG_CZECHFUNCTIONS, b);
3939 DOSET (FLG_CZECHVARS, b);
3940 DOSET (FLG_CZECHCONSTANTS, b);
3941 DOSET (FLG_CZECHTYPES, b);
3944 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
3945 DOSET (FLG_SLOVAKFUNCTIONS, b);
3946 DOSET (FLG_SLOVAKVARS, b);
3947 DOSET (FLG_SLOVAKCONSTANTS, b);
3948 DOSET (FLG_SLOVAKTYPES, b);
3950 case FLG_CZECHOSLOVAK:
3951 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
3952 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
3953 DOSET (FLG_CZECHOSLOVAKVARS, b);
3954 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
3955 DOSET (FLG_CZECHOSLOVAKTYPES, b);
3958 DOSET (FLG_NULLSTATE, b);
3959 DOSET (FLG_NULLDEREF, b);
3960 DOSET (FLG_NULLASSIGN, b);
3961 DOSET (FLG_NULLPASS, b);
3962 DOSET (FLG_NULLRET, b);
3965 DOSET (FLG_NULLSTATE, b);
3966 DOSET (FLG_NULLDEREF, b);
3967 DOSET (FLG_NULLASSIGN, b);
3968 DOSET (FLG_NULLPASS, b);
3969 DOSET (FLG_NULLRET, b);
3970 DOSET (FLG_COMPDEF, b);
3971 DOSET (FLG_COMPMEMPASS, b);
3972 DOSET (FLG_UNIONDEF, b);
3973 DOSET (FLG_MEMTRANS, b);
3974 DOSET (FLG_USERELEASED, b);
3975 DOSET (FLG_ALIASUNIQUE, b);
3976 DOSET (FLG_MAYALIASUNIQUE, b);
3977 DOSET (FLG_MUSTFREE, b);
3978 DOSET (FLG_MUSTDEFINE, b);
3979 DOSET (FLG_GLOBSTATE, b);
3980 DOSET (FLG_COMPDESTROY, b);
3981 DOSET (FLG_MUSTNOTALIAS, b);
3982 DOSET (FLG_MEMIMPLICIT, b);
3983 DOSET (FLG_BRANCHSTATE, b);
3984 /*@fallthrough@*/ /* also sets memtrans flags */
3986 DOSET (FLG_MEMTRANS, b);
3987 DOSET (FLG_EXPOSETRANS, b);
3988 DOSET (FLG_OBSERVERTRANS, b);
3989 DOSET (FLG_DEPENDENTTRANS, b);
3990 DOSET (FLG_NEWREFTRANS, b);
3991 DOSET (FLG_ONLYTRANS, b);
3992 DOSET (FLG_OWNEDTRANS, b);
3993 DOSET (FLG_FRESHTRANS, b);
3994 DOSET (FLG_SHAREDTRANS, b);
3995 DOSET (FLG_TEMPTRANS, b);
3996 DOSET (FLG_KEPTTRANS, b);
3997 DOSET (FLG_REFCOUNTTRANS, b);
3998 DOSET (FLG_STATICTRANS, b);
3999 DOSET (FLG_UNKNOWNTRANS, b);
4000 DOSET (FLG_KEEPTRANS, b);
4001 DOSET (FLG_IMMEDIATETRANS, b);
4008 if (b && !gc.anyExports
4009 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4010 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4011 || f == FLG_EXPORTCONST
4012 || f == FLG_EXPORTANY))
4014 gc.anyExports = TRUE;
4019 context_maybeSet (flagcode d)
4021 return (gc.flags[d] || gc.setLocally[d]);
4025 context_getFlag (flagcode d)
4027 return (gc.flags[d]);
4031 context_flagOn (flagcode f, fileloc loc)
4033 return (!context_suppressFlagMsg (f, loc));
4036 static void context_saveFlagSettings (void)
4038 gc.savedFlags = TRUE;
4039 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4040 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4043 static void context_restoreFlagSettings (void)
4045 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4046 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4047 gc.savedFlags = FALSE;
4050 void context_setFilename (fileId fid, int lineno)
4051 /*@globals fileloc g_currentloc;@*/
4052 /*@modifies g_currentloc@*/
4054 if (fileId_baseEqual (currentFile (), fid))
4061 fileloc_setColumn (g_currentloc, 0);
4063 if (fileloc_isSpecialFile (g_currentloc))
4065 gc.inDerivedFile = TRUE;
4068 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4070 int maxdepth = context_getValue (FLG_INCLUDENEST);
4072 if (filelocStack_size (gc.locstack) > maxdepth)
4074 int depth = filelocStack_includeDepth (gc.locstack);
4076 if (depth > maxdepth)
4080 message ("Maximum include nesting depth "
4081 "(%d, current depth %d) exceeded",
4084 filelocStack_nextTop (gc.locstack)))
4086 filelocStack_printIncludes (gc.locstack);
4092 g_currentloc = fileloc_create (fid, lineno, 1);
4093 gc.inheader = fileId_isHeader (currentFile ());
4095 context_enterFileAux ();
4099 void context_enterIterDef (/*@observer@*/ uentry le)
4101 context_enterMacro (le);
4102 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4103 gc.kind = CX_ITERDEF;
4106 void context_enterIterEnd (/*@observer@*/ uentry le)
4108 context_enterMacro (le);
4109 gc.kind = CX_ITEREND;
4113 context_destroyMod (void)
4114 /*@globals killed gc@*/
4117 ctype_destroyMod ();
4121 fileTable_free (gc.ftab);
4122 filelocStack_free (gc.locstack);
4124 gc.ftab = fileTable_undefined;
4126 macrocache_free (gc.mc);
4127 sfree (gc.moduleaccess);
4130 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4131 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4134 sRefSetList_free (gc.modrecs);
4136 flagMarkerList_free (gc.markers);
4138 messageLog_free (gc.msgLog);
4140 clauseStack_free (gc.clauses);
4143 cstring_free (gc.msgAnnote);
4144 globSet_free (gc.globs_used);
4145 metaStateTable_free (gc.stateTable);
4146 annotationTable_free (gc.annotTable);
4153 bool context_msgBoolInt (void)
4155 return gc.flags [FLG_BOOLINT];
4158 bool context_msgCharInt (void)
4160 return gc.flags [FLG_CHARINT];
4163 bool context_msgEnumInt (void)
4165 return gc.flags [FLG_ENUMINT];
4168 bool context_msgPointerArith (void)
4170 return gc.flags [FLG_POINTERARITH];
4173 bool context_msgStrictOps (void)
4175 return gc.flags [FLG_STRICTOPS];
4179 bool context_msgLh (void)
4181 return gc.flags [FLG_DOLH];
4185 void context_pushLoc (void)
4187 fileloc_free (gc.pushloc);
4188 gc.pushloc = gc.saveloc;
4189 gc.saveloc = fileloc_undefined;
4192 void context_popLoc (void)
4194 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4197 bool context_inGlobalScope (void)
4199 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4202 bool context_inInnerScope (void)
4204 return (gc.kind == CX_INNER);
4207 void context_setProtectVars (void)
4209 gc.protectVars = TRUE;
4212 bool context_anyErrors (void)
4214 return (gc.numerrors > 0);
4217 void context_hasError (void)
4220 DPRINTF (("num errors: %d", gc.numerrors));
4223 int context_numErrors (void)
4225 return gc.numerrors;
4228 bool context_neednl (void)
4233 void context_setNeednl (void)
4238 int context_getExpect (void)
4240 return (context_getValue (FLG_EXPECT));
4244 int context_getLCLExpect (void)
4246 return (context_getValue (FLG_LCLEXPECT));
4250 int context_getLimit (void)
4252 return (context_getValue (FLG_LIMIT));
4255 bool context_unlimitedMessages (void)
4257 return (context_getLimit () < 0);
4260 void context_releaseVars (void)
4262 llassert (gc.protectVars);
4263 gc.protectVars = FALSE;
4266 void context_sizeofReleaseVars (void)
4268 /* If there is a nested sizeof, this might not hold:
4269 llassert (gc.protectVars);
4272 gc.protectVars = FALSE;
4275 bool context_inProtectVars (void)
4277 return (gc.protectVars);
4280 void context_hideShowscan (void)
4282 gc.flags[FLG_SHOWSCAN] = FALSE;
4285 void context_unhideShowscan (void)
4287 gc.flags[FLG_SHOWSCAN] = TRUE;
4290 bool context_inHeader (void)
4292 return (gc.inheader);
4295 fileTable context_fileTable (void)
4300 cstring context_tmpdir (void)
4302 return (context_getString (FLG_TMPDIR));
4305 messageLog context_messageLog (void)
4310 bool context_inMacroFunction (void)
4312 return (gc.kind == CX_MACROFCN);
4315 bool context_inMacroConstant (void)
4317 return (gc.kind == CX_MACROCONST);
4320 bool context_inUnknownMacro (void)
4322 return (gc.kind == CX_UNKNOWNMACRO);
4325 void context_setShownFunction (void)
4327 gc.showfunction = FALSE;
4330 bool context_doDump (void)
4332 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4335 bool context_doMerge (void)
4337 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4340 cstring context_getDump (void)
4342 return context_getString (FLG_DUMP);
4345 cstring context_getMerge (void)
4347 return context_getString (FLG_MERGE);
4351 bool context_inLCLLib (void)
4353 return (gc.kind == CX_LCLLIB);
4356 bool context_inImport (void)
4358 return (gc.inimport);
4361 void context_enterImport (void)
4366 void context_leaveImport (void)
4368 gc.inimport = FALSE;
4372 bool context_inMacro (void)
4374 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4375 || gc.kind == CX_UNKNOWNMACRO
4376 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4379 bool context_inIterDef (void)
4381 return (gc.kind == CX_ITERDEF);
4384 bool context_inIterEnd (void)
4386 return (gc.kind == CX_ITEREND);
4389 int context_getLinesProcessed (void)
4391 return (gc.linesprocessed);
4394 int context_getSpecLinesProcessed (void)
4396 return (gc.speclinesprocessed);
4400 void context_processedSpecLine (void)
4402 gc.speclinesprocessed++;
4405 void context_resetSpecLines (void)
4407 gc.speclinesprocessed = 0;
4411 bool context_inGlobalContext (void)
4413 return (gc.kind == CX_GLOBAL);
4416 static void context_quietExitScopes (void)
4419 ** Try to restore the global scope (after an error).
4422 while (!usymtab_inFileScope ())
4424 usymtab_quietExitScope (g_currentloc);
4427 gc.cont.glob = TRUE;
4428 gc.kind = CX_GLOBAL;
4431 void context_checkGlobalScope (void)
4433 if (gc.kind != CX_GLOBAL)
4435 if (context_inMacro ())
4437 ; /* evans 2001-10-14: Okay to be in a macro here! */
4441 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4442 context_quietExitScopes ();
4447 void context_setFileId (fileId s)
4449 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4452 bool context_setBoolName (void)
4454 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4458 cstring context_printBoolName (void)
4460 if (context_setBoolName ())
4462 return context_getBoolName ();
4466 return cstring_makeLiteralTemp ("boolean");
4470 cstring context_getBoolName (void)
4472 return (context_getString (FLG_BOOLTYPE));
4475 cstring context_getFalseName (void)
4477 return (context_getString (FLG_BOOLFALSE));
4480 cstring context_getTrueName (void)
4482 return (context_getString (FLG_BOOLTRUE));
4485 cstring context_getLarchPath (void)
4487 return (context_getString (FLG_LARCHPATH));
4490 cstring context_getLCLImportDir (void)
4492 return (context_getString (FLG_LCLIMPORTDIR));
4495 static void context_setJustPopped (void)
4497 gc.justpopped = TRUE;
4500 void context_clearJustPopped (void)
4502 gc.justpopped = FALSE;
4505 bool context_justPopped (void)
4507 return (gc.justpopped);
4510 void context_setMacroMissingParams (void)
4512 gc.macroMissingParams = TRUE;
4515 void context_resetMacroMissingParams (void)
4517 gc.macroMissingParams = FALSE;
4520 bool context_isMacroMissingParams (void)
4522 return (gc.macroMissingParams);
4525 void context_showFilelocStack (void)
4527 filelocStack_printIncludes (gc.locstack);
4530 metaStateTable context_getMetaStateTable (void)
4532 return gc.stateTable;
4535 metaStateInfo context_lookupMetaStateInfo (cstring key)
4537 return metaStateTable_lookup (gc.stateTable, key);
4540 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4542 annotationInfo ainfo;
4544 ainfo = annotationTable_lookup (gc.annotTable, annot);
4549 void context_addAnnotation (annotationInfo ainfo)
4551 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4555 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4556 annotationInfo_getLoc (ainfo));
4558 annotationInfo_free (ainfo);
4562 annotationTable_insert (gc.annotTable, ainfo);
4566 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4568 if (metaStateTable_contains (gc.stateTable, mname))
4572 message ("Duplicate metastate declaration: %s", mname),
4573 metaStateInfo_getLoc (msinfo));
4574 cstring_free (mname);
4575 metaStateInfo_free (msinfo);
4579 DPRINTF (("Adding meta state: %s", mname));
4580 metaStateTable_insert (gc.stateTable, mname, msinfo);
4584 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4586 if (metaStateTable_size (gc.stateTable) > 0)
4588 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4589 /*@i32 should use smaller value... */
4590 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4592 metaStateTable_elements (gc.stateTable, msname, msi)
4594 mtContextNode context = metaStateInfo_getContext (msi);
4596 if (mtContextNode_matchesRefStrict (context, s))
4598 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4599 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4603 cstring_copy (metaStateInfo_getName (msi)),
4604 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4605 stateInfo_copy (sinfo)));
4609 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4612 end_metaStateTable_elements ;
4614 stateInfo_free (sinfo);
4615 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4620 stateInfo_free (sinfo);
4621 return valueTable_undefined;
4625 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4627 if (metaStateTable_size (gc.stateTable) > 0)
4629 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4630 /*@i32 should use smaller value... */
4632 metaStateTable_elements (gc.stateTable, msname, msi)
4634 /*@i23 only add global...*/
4635 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4636 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4638 valueTable_insert (res,
4639 cstring_copy (metaStateInfo_getName (msi)),
4640 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4641 stateInfo_copy (sinfo)));
4643 end_metaStateTable_elements ;
4645 stateInfo_free (sinfo);
4646 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4651 stateInfo_free (sinfo);
4652 return valueTable_undefined;