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);
685 ** Set all flags to FALSE, except for a few which are
688 ** Set all values and strings to appropriate defaults.
689 ** Set all counters to 0.
693 conext_resetAllCounters (void)
697 for (i = 0; i < NUMVALUEFLAGS; i++)
704 context_resetAllFlags (void)
706 DPRINTF (("******** Reset all flags"));
710 gc.flags[code] = FALSE;
712 if (flagcode_hasNumber (code))
716 /*@-loopswitchbreak@*/
720 val = DEFAULT_LIMIT; break;
722 val = DEFAULT_BUGSLIMIT; break;
724 val = DEFAULT_LINELEN; break;
725 case FLG_INDENTSPACES:
726 val = DEFAULT_INDENTSPACES; break;
727 case FLG_EXTERNALNAMELEN:
728 val = ISO99_EXTERNALNAMELEN; break;
729 case FLG_INTERNALNAMELEN:
730 val = ISO99_INTERNALNAMELEN; break;
731 case FLG_COMMENTCHAR:
732 val = (int) DEFAULT_COMMENTCHAR; break;
733 case FLG_CONTROLNESTDEPTH:
734 val = (int) ISO99_CONTROLNESTDEPTH; break;
735 case FLG_STRINGLITERALLEN:
736 val = (int) ISO99_STRINGLITERALLEN; break;
737 case FLG_INCLUDENEST:
738 val = (int) ISO99_INCLUDENEST; break;
739 case FLG_NUMSTRUCTFIELDS:
740 val = (int) ISO99_NUMSTRUCTFIELDS; break;
741 case FLG_NUMENUMMEMBERS:
742 val = (int) ISO99_NUMENUMMEMBERS; break;
747 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
749 /*@=loopswitchbreak@*/
751 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
752 context_setValue (code, val);
753 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
754 llassert (context_getValue (code) == val);
756 else if (flagcode_hasChar (code))
758 llassert (code == FLG_COMMENTCHAR);
759 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
761 else if (flagcode_hasString (code))
763 cstring val = cstring_undefined;
766 { /*@-loopswitchbreak@*/
769 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
771 if (cstring_isDefined (larchpath))
773 val = cstring_copy (larchpath);
777 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
782 case FLG_LCLIMPORTDIR:
784 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
788 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
790 char *env = osd_getEnvironmentVariable ("TMP");
794 env = osd_getEnvironmentVariable ("TEMP");
797 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
800 val = cstring_makeLiteral (DEFAULT_TMPDIR);
801 # endif /* !defined(OS2) && !defined(MSDOS) */
805 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
807 val = cstring_makeLiteral ("FALSE"); break;
809 val = cstring_makeLiteral ("TRUE"); break;
810 case FLG_MACROVARPREFIX:
811 val = cstring_makeLiteral ("m_"); break;
813 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
816 } /*@=loopswitchbreak@*/
818 context_setString (code, val);
822 ; /* nothing to set */
827 ** These flags are true by default.
830 /*@i34 move this into flags.def */
832 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
833 gc.flags[FLG_MODIFIES] = TRUE;
834 gc.flags[FLG_NESTCOMMENT] = TRUE;
835 gc.flags[FLG_GLOBALS] = TRUE;
836 gc.flags[FLG_FULLINITBLOCK] = TRUE;
837 gc.flags[FLG_INITSIZE] = TRUE;
838 gc.flags[FLG_INITALLELEMENTS] = TRUE;
840 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
842 gc.flags[FLG_LIKELYBOOL] = TRUE;
843 gc.flags[FLG_ZEROPTR] = TRUE;
844 gc.flags[FLG_NUMLITERAL] = TRUE;
845 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
846 gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
847 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
848 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
849 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
850 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
851 gc.flags[FLG_CASTFCNPTR] = TRUE;
852 gc.flags[FLG_DOLCS] = TRUE;
853 gc.flags[FLG_USEVARARGS] = TRUE;
854 gc.flags[FLG_MAINTYPE] = TRUE;
855 gc.flags[FLG_SPECMACROS] = TRUE;
856 gc.flags[FLG_REDEF] = TRUE;
857 gc.flags[FLG_MACRONEXTLINE] = TRUE;
859 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
860 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
862 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
863 gc.flags[FLG_WARNUSE] = TRUE;
864 gc.flags[FLG_PREDASSIGN] = TRUE;
865 gc.flags[FLG_MODOBSERVER] = TRUE;
866 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
867 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
869 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
870 gc.flags[FLG_RETIMPONLY] = TRUE;
871 gc.flags[FLG_GLOBIMPONLY] = TRUE;
872 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
873 gc.flags[FLG_PREPROC] = TRUE;
874 gc.flags[FLG_NAMECHECKS] = TRUE;
875 gc.flags[FLG_FORMATCODE] = TRUE;
876 gc.flags[FLG_FORMATTYPE] = TRUE;
877 gc.flags[FLG_BADFLAG] = TRUE;
878 gc.flags[FLG_WARNFLAGS] = TRUE;
879 gc.flags[FLG_WARNRC] = TRUE;
880 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
881 gc.flags[FLG_WARNUNIXLIB] = TRUE;
882 gc.flags[FLG_WARNPOSIX] = TRUE;
883 gc.flags[FLG_SHOWCOL] = TRUE;
884 gc.flags[FLG_SHOWFUNC] = TRUE;
885 gc.flags[FLG_SUPCOUNTS] = TRUE;
886 gc.flags[FLG_HINTS] = TRUE;
887 gc.flags[FLG_SYNTAX] = TRUE;
888 gc.flags[FLG_TYPE] = TRUE;
889 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
890 gc.flags[FLG_ABSTRACT] = TRUE;
891 gc.flags[FLG_ITER] = TRUE;
892 gc.flags[FLG_CONTROL] = TRUE;
893 gc.flags[FLG_UNRECOG] = TRUE;
894 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
895 gc.flags[FLG_LINTCOMMENTS] = TRUE;
896 gc.flags[FLG_ACCESSCZECH] = TRUE;
897 gc.flags[FLG_ACCESSMODULE] = TRUE;
898 gc.flags[FLG_ACCESSFILE] = TRUE;
899 gc.flags[FLG_MACROVARPREFIX] = TRUE;
901 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
902 gc.flags[FLG_COMMENTERROR] = TRUE;
905 ** Changed for version 2.4.
908 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
911 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
915 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
920 ** C is way-lame, and you can initialize an array to a constant except where
921 ** it is declared. Hence, a macro is used to set the modeflags.
925 # define SETFLAGS() \
926 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
927 if (!flagcode_isModeFlag (modeflags[i])) \
928 { llbug (message ("not a mode flag: %s", \
929 flagcode_unparse (modeflags[i]))); } \
930 else { context_setFlag (modeflags[i], TRUE); } i++; }}
932 static void context_setModeAux (cstring p_s, bool p_warn) ;
935 context_setMode (cstring s)
937 context_setModeAux (s, TRUE);
941 context_setModeNoWarn (cstring s)
943 context_setModeAux (s, FALSE);
947 context_setModeAux (cstring s, bool warn)
949 intSet setflags = intSet_new ();
953 if (flagcode_isModeFlag (code))
955 if (gc.setGlobally[code])
957 (void) intSet_insert (setflags, (int) code);
962 if (!intSet_isEmpty (setflags))
964 cstring rflags = cstring_undefined;
967 intSet_elements (setflags, el)
969 if (cstring_isUndefined (rflags))
971 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
975 rflags = message ("%q, %s", rflags,
976 flagcode_unparse ((flagcode) el));
980 if (num > 4 && intSet_size (setflags) > 6)
982 rflags = message ("%q, (%d others) ...", rflags,
983 intSet_size (setflags) - num);
986 } end_intSet_elements ;
990 voptgenerror (FLG_WARNFLAGS,
991 message ("Setting mode %s after setting mode flags will "
992 "override set values of flags: %s",
997 cstring_free (rflags);
1000 intSet_free (setflags);
1002 context_resetModeFlags ();
1004 if (cstring_equalLit (s, "standard"))
1006 flagcode modeflags[] =
1008 FLG_ENUMINT, FLG_MACROMATCHNAME,
1009 FLG_STRINGLITNOROOM,
1010 FLG_MACROUNDEF, FLG_RELAXQUALS,
1011 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1012 FLG_CHECKSTRICTGLOBALIAS,
1013 FLG_CHECKEDGLOBALIAS,
1014 FLG_CHECKMODGLOBALIAS,
1015 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1016 FLG_UNSIGNEDCOMPARE,
1017 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1019 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1020 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1021 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1022 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1023 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1026 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1027 FLG_MACROSTMT, FLG_MACROPARENS,
1030 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1031 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1036 /* memchecks flags */
1038 FLG_NULLSTATE, FLG_NULLASSIGN,
1039 FLG_NULLPASS, FLG_NULLRET,
1041 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1044 /* memtrans flags */
1063 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1066 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1067 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1070 FLG_STATETRANSFER, FLG_STATEMERGE,
1071 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1073 FLG_IMPCHECKEDSPECGLOBALS,
1074 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1075 FLG_IFEMPTY, FLG_REALCOMPARE,
1076 FLG_BOOLOPS, FLG_PTRNEGATE,
1078 FLG_SHIFTIMPLEMENTATION,
1079 FLG_BUFFEROVERFLOWHIGH,
1086 else if (cstring_equalLit (s, "weak"))
1088 flagcode modeflags[] =
1090 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
1091 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1092 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1093 FLG_CHARUNSIGNEDCHAR,
1095 FLG_VARUNUSED, FLG_FUNCUNUSED,
1097 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1100 FLG_BUFFEROVERFLOWHIGH,
1101 FLG_RETSTACK, FLG_PTRNEGATE,
1102 FLG_STATETRANSFER, FLG_STATEMERGE,
1103 FLG_LONGUNSIGNEDINTEGRAL,
1104 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1108 FLG_BUFFEROVERFLOWHIGH,
1114 else if (cstring_equalLit (s, "checks"))
1116 flagcode modeflags[] =
1118 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1119 FLG_STATETRANSFER, FLG_STATEMERGE,
1120 FLG_CHECKSTRICTGLOBALIAS,
1121 FLG_CHECKEDGLOBALIAS,
1122 FLG_CHECKMODGLOBALIAS,
1123 FLG_UNCHECKEDGLOBALIAS,
1125 FLG_STRINGLITNOROOM,
1126 FLG_STRINGLITSMALLER,
1127 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1128 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1129 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1130 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1131 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1132 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1133 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1134 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1135 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1136 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1137 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1138 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1139 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1140 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1147 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1151 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1153 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1154 FLG_EVALORDER, FLG_USEDEF,
1157 /* warn use flags */
1158 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1159 FLG_BUFFEROVERFLOWHIGH,
1161 /* memchecks flags */
1163 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1164 FLG_NULLPASS, FLG_NULLRET,
1166 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1168 /* memtrans flags */
1182 FLG_STATICINITTRANS,
1183 FLG_UNKNOWNINITTRANS,
1186 FLG_ONLYUNQGLOBALTRANS,
1187 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1190 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1191 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1194 FLG_NULLPOINTERARITH,
1195 FLG_SHADOW, FLG_DEPARRAYS,
1196 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1197 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1198 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1199 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1200 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1201 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1202 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1203 FLG_SHIFTIMPLEMENTATION,
1204 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1209 else if (cstring_equalLit (s, "strict"))
1211 flagcode modeflags[] =
1213 FLG_CHECKSTRICTGLOBALIAS,
1214 FLG_CHECKEDGLOBALIAS,
1215 FLG_CHECKMODGLOBALIAS,
1216 FLG_UNCHECKEDGLOBALIAS,
1220 FLG_STRINGLITNOROOM,
1221 FLG_STRINGLITSMALLER,
1222 FLG_STATETRANSFER, FLG_STATEMERGE,
1223 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1224 FLG_ALLGLOBALS, FLG_IMPTYPE,
1225 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1226 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1227 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1228 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1231 FLG_ONLYUNQGLOBALTRANS,
1232 FLG_GLOBALSIMPMODIFIESNOTHING,
1233 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1234 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1235 FLG_USEALLGLOBS, FLG_RETALIAS,
1236 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1237 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1238 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1240 FLG_EXPORTITER, FLG_EXPORTCONST,
1241 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1242 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1244 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1246 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1247 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1248 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1249 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1250 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1251 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1252 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1253 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1255 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1258 FLG_MACROREDEF, FLG_MACROEMPTY,
1259 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1261 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1263 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1264 FLG_MODOBSERVERUNCON,
1269 /* warn use flags */
1270 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1271 FLG_BUFFEROVERFLOWHIGH,
1272 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1274 /* memchecks flags */
1275 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1276 FLG_NULLPASS, FLG_NULLRET,
1278 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1280 /* memtrans flags */
1296 FLG_STATICINITTRANS,
1297 FLG_UNKNOWNINITTRANS,
1299 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1302 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1303 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1307 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1309 FLG_SHADOW, FLG_DEPARRAYS,
1310 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1311 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1312 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1313 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1314 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1315 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1316 FLG_IMPCHECKEDSTRICTSTATICS,
1317 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1318 FLG_IMPCHECKMODINTERNALS,
1319 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1320 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1321 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1322 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1323 FLG_CONTROLNESTDEPTH,
1324 FLG_FORBLOCK, FLG_WHILEBLOCK,
1325 FLG_FOREMPTY, FLG_WHILEEMPTY,
1326 FLG_IFEMPTY, FLG_IFBLOCK,
1328 FLG_REALCOMPARE, FLG_BOOLOPS,
1329 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1332 FLG_SHIFTIMPLEMENTATION,
1334 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1342 llcontbug (message ("context_setMode: bad mode: %s", s));
1347 context_isSpecialFile (cstring fname)
1349 cstring ext = fileLib_getExtension (fname);
1351 return (cstring_equalLit (ext, ".y")
1352 || cstring_equalLit (ext, ".l")
1353 || cstring_equalLit (fname, "lex.yy.c"));
1357 context_isSystemDir (cstring dir)
1359 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1360 cstring savedir = thisdir;
1361 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1363 if (cstring_isDefined (nextdir))
1365 /*@access cstring@*/
1366 *nextdir = '\0'; /* closes thisdir */
1368 /*@noaccess cstring@*/
1371 /* 2001-09-09: added thisdir[0] != '\0'
1372 ** herbert: don't compare with an empty name!
1373 ** should return false for empty directory path
1376 while (!cstring_isEmpty (thisdir))
1378 DPRINTF (("Test: %s / %s", dir, thisdir));
1380 if (osd_equalCanonicalPrefix (dir, thisdir))
1382 cstring_free (savedir);
1386 if (cstring_isDefined (nextdir))
1389 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1391 if (cstring_isDefined (nextdir))
1393 /*@access cstring@*/
1396 /*@noaccess cstring@*/
1405 DPRINTF (("Returns FALSE"));
1406 cstring_free (savedir);
1411 context_addFileAccessType (typeId t)
1415 if (context_inFunctionLike ())
1417 gc.acct = typeIdSet_insert (gc.acct, t);
1420 gc.facct = typeIdSet_insert (gc.facct, t);
1422 base = fileloc_getBase (g_currentloc);
1423 insertModuleAccess (base, t);
1424 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1425 typeIdSet_unparse (gc.acct)));
1429 context_removeFileAccessType (typeId t)
1431 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1432 || gc.kind == CX_UNKNOWNMACRO)
1434 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1437 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1438 gc.nacct = typeIdSet_insert (gc.nacct, t);
1441 void context_enterFunctionHeader (void)
1443 if (context_getFlag (FLG_GRAMMAR))
1445 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1448 if (gc.kind != CX_GLOBAL)
1450 llparseerror (cstring_makeLiteral
1451 ("Likely parse error. Function header outside global context."));
1455 llassert (gc.kind == CX_GLOBAL);
1456 DPRINTF (("Enter function header!"));
1457 gc.inFunctionHeader = TRUE;
1461 void context_exitFunctionHeader (void)
1463 if (context_getFlag (FLG_GRAMMAR))
1465 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1468 DPRINTF (("Exit function header!"));
1469 gc.inFunctionHeader = FALSE;
1472 bool context_inFunctionHeader (void)
1474 return (gc.inFunctionHeader);
1477 void context_enterFunctionDeclaration (uentry e)
1479 if (context_getFlag (FLG_GRAMMAR))
1481 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1484 DPRINTF (("Enter function decl"));
1485 llassert (gc.savekind == CX_ERROR);
1486 gc.savekind = gc.kind;
1487 gc.savecont = gc.cont;
1488 gc.kind = CX_FCNDECLARATION;
1492 void context_exitFunctionDeclaration (void)
1494 if (context_getFlag (FLG_GRAMMAR))
1496 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1499 DPRINTF (("Exit function decl"));
1500 llassert (gc.savekind != CX_ERROR);
1501 llassert (gc.kind == CX_FCNDECLARATION);
1502 gc.kind = gc.savekind;
1503 gc.cont = gc.savecont;
1505 gc.savekind = CX_ERROR;
1507 if (context_getFlag (FLG_GRAMMAR))
1509 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1513 bool context_inFunctionDeclaration (void)
1515 return (gc.kind == CX_FCNDECLARATION);
1520 context_enterMacro (/*@observer@*/ uentry e)
1522 context_enterFunction (e);
1523 gc.kind = CX_MACROFCN;
1527 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1529 llassert (uentry_isFunction (e));
1530 context_enterFunction (e);
1531 gc.kind = CX_UNKNOWNMACRO;
1534 void context_enterAndClause (exprNode e)
1537 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1538 pushClause (ANDCLAUSE);
1541 void context_enterOrClause (exprNode e)
1543 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1544 pushClause (ORCLAUSE);
1547 bool context_inDeepLoop (void)
1549 bool inLoop = FALSE;
1551 clauseStack_elements (gc.clauses, el)
1553 if (clause_isLoop (el))
1562 } end_clauseStack_elements;
1567 bool context_inDeepSwitch (void)
1569 bool inLoop = FALSE;
1571 clauseStack_elements (gc.clauses, el)
1573 if (clause_isSwitch (el))
1582 } end_clauseStack_elements;
1587 bool context_inDeepLoopSwitch (void)
1589 bool inLoop = FALSE;
1591 clauseStack_elements (gc.clauses, el)
1593 if (clause_isBreakable (el))
1602 } end_clauseStack_elements;
1607 clause context_breakClause (void)
1609 clauseStack_elements (gc.clauses, el)
1611 if (clause_isSwitch (el))
1615 else if (clause_isLoop (el))
1623 } end_clauseStack_elements;
1628 clause context_nextBreakClause (void)
1630 bool hasOne = FALSE;
1632 clauseStack_elements (gc.clauses, el)
1634 if (clause_isBreakable (el))
1645 } end_clauseStack_elements;
1650 bool context_inConditional (void)
1652 clauseStack_elements (gc.clauses, el)
1655 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1656 ** to distinguish if from ? for this
1659 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1663 } end_clauseStack_elements;
1668 void context_exitAndClause (exprNode pred, exprNode tbranch)
1670 context_setJustPopped ();
1672 llassert (gc.inclause == ANDCLAUSE);
1674 usymtab_popAndBranch (pred, tbranch);
1675 clauseStack_pop (gc.clauses);
1676 gc.inclause = topClause (gc.clauses);
1679 void context_exitOrClause (exprNode pred, exprNode tbranch)
1681 context_setJustPopped ();
1683 llassert (gc.inclause == ORCLAUSE);
1685 usymtab_popOrBranch (pred, tbranch);
1686 clauseStack_pop (gc.clauses);
1687 gc.inclause = topClause (gc.clauses);
1690 static void context_enterCondClauseAux (clause cl)
1696 static void context_enterTrueAux (exprNode e, clause cl)
1699 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1703 void context_enterIterClause (void)
1705 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1708 void context_enterDoWhileClause (void)
1710 pushClause (DOWHILECLAUSE);
1713 void context_enterWhileClause (exprNode e)
1715 context_enterTrueAux (e, WHILECLAUSE);
1718 void context_enterForClause (exprNode e)
1720 context_enterTrueAux (e, FORCLAUSE);
1723 void context_enterTrueClause (exprNode e)
1725 context_enterTrueAux (e, TRUECLAUSE);
1728 void context_enterSwitch (exprNode e)
1731 usymtab_switchBranch (e);
1732 context_enterCondClauseAux (SWITCHCLAUSE);
1735 void context_exitSwitch (exprNode e, bool allpaths)
1737 usymtab_exitSwitch (e, allpaths);
1739 while (clause_isCase (clauseStack_top (gc.clauses)))
1741 clauseStack_pop (gc.clauses);
1744 context_exitClauseSimp ();
1747 void context_enterCaseClause (exprNode e)
1749 bool branch = FALSE;
1751 DPRINTF (("Enter case clause!"));
1753 branch = usymtab_newCase (exprNode_undefined, e);
1757 context_enterCondClauseAux (CASECLAUSE);
1761 static void context_enterFalseClauseAux (exprNode e, clause cl)
1764 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1766 clauseStack_switchTop (gc.clauses, cl);
1769 void context_enterFalseClause (exprNode e)
1772 context_enterFalseClauseAux (e, FALSECLAUSE);
1776 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1778 gc.kind = CX_MACROCONST;
1780 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1782 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1786 usymtab_enterScope ();
1787 sRef_enterFunctionScope ();
1789 gc.globs = globSet_undefined;
1790 globSet_clear (gc.globs_used);
1791 gc.mods = sRefSet_undefined;
1794 uentry context_getHeader (void)
1796 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1798 llfatalbug (message ("context_getHeader: bad call: %q",
1799 context_unparse ()));
1802 return (gc.cont.fcn);
1806 context_setFunctionDefined (fileloc loc)
1810 case CX_UNKNOWNMACRO:
1813 uentry_setFunctionDefined (gc.cont.fcn, loc);
1816 /* (not a bug because of parse errors) */
1822 context_enterFunction (/*@exposed@*/ uentry e)
1824 gc.kind = CX_FUNCTION;
1827 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1829 if (uentry_hasAccessType (e))
1831 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1839 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1840 typeIdSet_unparse (gc.acct)));
1842 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1844 gc.globs = uentry_getGlobs (e);
1845 globSet_clear (gc.globs_used);
1846 gc.mods = uentry_getMods (e);
1848 usymtab_enterFunctionScope (e);
1849 sRef_enterFunctionScope ();
1853 context_enterOldStyleScope (void)
1855 gc.kind = CX_OLDSTYLESCOPE;
1856 DPRINTF (("Enter old style scope!"));
1857 usymtab_enterFunctionScope (uentry_undefined);
1861 context_completeOldStyleFunction (uentry e)
1863 llassert (gc.kind == CX_OLDSTYLESCOPE);
1865 gc.kind = CX_FUNCTION;
1868 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1870 if (uentry_hasAccessType (e))
1872 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1880 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1881 typeIdSet_unparse (gc.acct)));
1883 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1885 if (!globSet_isEmpty (uentry_getGlobs (e)))
1887 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1888 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1891 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1893 gc.globs = uentry_getGlobs (e);
1894 globSet_clear (gc.globs_used);
1896 gc.mods = uentry_getMods (e);
1898 if (!sRefSet_isEmpty (gc.mods))
1900 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1901 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1904 sRef_enterFunctionScope ();
1907 static bool context_checkStrictGlobals (void)
1909 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1912 static bool context_hasGlobs (void)
1914 if (context_inFunctionLike ())
1916 return (uentry_hasGlobs (gc.cont.fcn));
1924 static bool context_checkCheckedGlobals (void)
1926 return (context_getFlag (FLG_GLOBALS)
1927 && (context_getFlag (FLG_GLOBUNSPEC)
1928 || context_hasGlobs ()));
1931 static bool context_checkUnknownGlobals (void)
1933 /* should be uentry_hasGlobs ? */
1935 return (context_getFlag (FLG_ALLGLOBALS)
1936 && (context_getFlag (FLG_GLOBUNSPEC)
1937 || context_hasGlobs ()));
1940 static bool context_checkUncheckedGlobals (void)
1946 context_checkExport (uentry e)
1948 if (!gc.anyExports) return FALSE;
1950 if (uentry_isFunction (e)
1951 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1953 return context_maybeSet (FLG_EXPORTFCN);
1955 else if (uentry_isExpandedMacro (e))
1957 return context_maybeSet (FLG_EXPORTMACRO);
1959 else if (uentry_isVariable (e))
1961 return context_maybeSet (FLG_EXPORTVAR);
1963 else if (uentry_isEitherConstant (e))
1965 return context_maybeSet (FLG_EXPORTCONST);
1967 else if (uentry_isIter (e) || uentry_isEndIter (e))
1969 return context_maybeSet (FLG_EXPORTITER);
1971 else if (uentry_isDatatype (e))
1973 return context_maybeSet (FLG_EXPORTTYPE);
1982 context_checkGlobUse (uentry glob)
1985 if (uentry_isCheckedStrict (glob))
1987 return context_checkStrictGlobals ();
1989 else if (uentry_isChecked (glob))
1991 return context_checkCheckedGlobals ();
1993 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
1995 return context_checkUnknownGlobals ();
1999 llassert (uentry_isUnchecked (glob));
2001 return context_checkUncheckedGlobals ();
2006 context_checkAliasGlob (uentry glob)
2008 if (uentry_isCheckedStrict (glob))
2010 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2012 else if (uentry_isChecked (glob))
2014 return gc.flags[FLG_CHECKEDGLOBALIAS];
2016 else if (uentry_isCheckMod (glob))
2018 return gc.flags[FLG_CHECKMODGLOBALIAS];
2022 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2024 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2028 bool context_checkInternalUse (void)
2030 if (context_hasGlobs ())
2032 return (gc.flags[FLG_INTERNALGLOBS]);
2036 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2041 context_checkGlobMod (sRef el)
2043 uentry ue = sRef_getUentry (el);
2045 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2047 if (uentry_isCheckedModify (ue)
2048 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2050 if (context_hasMods ())
2052 return (gc.flags[FLG_MODGLOBS]);
2056 if (uentry_isCheckedStrict (ue))
2058 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2062 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2068 if (context_hasMods ())
2070 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2080 context_usedGlobal (/*@exposed@*/ sRef el)
2082 if (!globSet_member (gc.globs_used, el))
2085 ** The first time a global is used in a function, we need
2086 ** to clear the derived sRefs, since they were set for the
2087 ** previous function.
2090 sRef_clearDerived (el);
2091 gc.globs_used = globSet_insert (gc.globs_used, el);
2095 /*@observer@*/ sRefSet
2096 context_modList (void)
2102 context_globAccess (sRef s)
2104 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2105 return (globSet_member (gc.globs, s));
2109 context_hasAccess (typeId t)
2111 if (context_inFunctionLike ())
2113 DPRINTF (("Access %d / %s",
2114 t, typeIdSet_unparse (gc.acct)));
2115 return (typeIdSet_member (gc.acct, t));
2119 return (context_hasFileAccess (t));
2124 context_hasFileAccess (typeId t)
2126 return (typeIdSet_member (gc.facct, t));
2130 context_unparseAccess (void)
2132 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2133 typeIdSet_unparse (gc.facct)));
2137 context_unparseClauses (void)
2139 return (clauseStack_unparse (gc.clauses));
2143 context_couldHaveAccess (typeId t)
2145 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2147 return (typeIdSet_member (gc.acct, t));
2151 return (typeIdSet_member (gc.facct, t));
2156 context_getRetType (void)
2158 ctype f = ctype_undefined;
2160 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2162 f = uentry_getType (gc.cont.fcn);
2164 else if (gc.kind == CX_UNKNOWNMACRO)
2166 return ctype_unknown;
2170 llcontbuglit ("context_getRetType: not in a function context");
2171 return ctype_unknown;
2174 if (!ctype_isFunction (f))
2176 if (ctype_isKnown (f))
2178 llbuglit ("context_getRetType: not a function");
2181 return ctype_unknown;
2183 return (ctype_getReturnType (f));
2187 context_hasMods (void)
2189 if (context_inFunctionLike ())
2191 return (uentry_hasMods (gc.cont.fcn));
2200 context_exitAllClauses (void)
2202 while (!clauseStack_isEmpty (gc.clauses))
2204 clause el = clauseStack_top (gc.clauses);
2207 if (clause_isNone (el))
2209 usymtab_quietExitScope (g_currentloc);
2210 clauseStack_pop (gc.clauses);
2214 context_exitClausePlain ();
2218 clauseStack_clear (gc.clauses);
2219 gc.inclause = NOCLAUSE;
2223 context_exitAllClausesQuiet (void)
2225 while (!clauseStack_isEmpty (gc.clauses))
2227 clause el = clauseStack_top (gc.clauses);
2230 usymtab_quietExitScope (g_currentloc);
2231 clauseStack_pop (gc.clauses);
2234 clauseStack_clear (gc.clauses);
2235 gc.inclause = NOCLAUSE;
2239 void context_exitClauseSimp (void)
2242 context_setJustPopped ();
2243 clauseStack_pop (gc.clauses);
2244 gc.inclause = topClause (gc.clauses);
2248 void context_exitCaseClause (void)
2250 context_setJustPopped ();
2251 usymtab_popCaseBranch ();
2252 clauseStack_pop (gc.clauses);
2253 gc.inclause = topClause (gc.clauses);
2257 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2259 context_setJustPopped ();
2260 /*@i32 was makeAlt */
2261 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2262 clauseStack_pop (gc.clauses);
2263 gc.inclause = topClause (gc.clauses);
2266 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2268 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2270 if (gc.inclause != TRUECLAUSE)
2272 llparseerror (cstring_makeLiteral
2273 ("Likely parse error. Conditional clauses are inconsistent."));
2277 context_setJustPopped ();
2278 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2279 clauseStack_pop (gc.clauses);
2280 gc.inclause = topClause (gc.clauses);
2283 void context_exitIterClause (exprNode body)
2285 llassert (gc.inclause == ITERCLAUSE);
2287 context_setJustPopped ();
2289 if (context_getFlag (FLG_ITERLOOPEXEC))
2291 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2295 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2298 clauseStack_pop (gc.clauses);
2299 gc.inclause = topClause (gc.clauses);
2302 static void context_popCase (void) {
2304 ** If we are exiting an outer clause, sometimes still in a switch case.
2318 DPRINTF (("Popping case clause: %s",
2319 clauseStack_unparse (gc.clauses)));
2321 if (gc.inclause == CASECLAUSE) {
2322 context_exitCaseClause ();
2326 void context_exitWhileClause (exprNode pred, exprNode body)
2328 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2332 if (gc.inclause != WHILECLAUSE) {
2333 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2334 clauseStack_unparse (gc.clauses)));
2337 llassert (gc.inclause == WHILECLAUSE);
2339 context_setJustPopped ();
2343 ** predicate must be false after while loop (unless there are breaks)
2346 if (context_getFlag (FLG_WHILELOOPEXEC))
2348 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2352 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2356 usymtab_addGuards (invGuards);
2357 guardSet_free (invGuards);
2359 clauseStack_pop (gc.clauses);
2360 gc.inclause = topClause (gc.clauses);
2363 void context_exitDoWhileClause (exprNode pred)
2365 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2367 if (gc.inclause == CASECLAUSE) {
2368 /* handle Duff's device */
2369 clauseStack_pop (gc.clauses);
2370 gc.inclause = topClause (gc.clauses);
2373 llassert (gc.inclause == DOWHILECLAUSE);
2375 context_setJustPopped ();
2378 usymtab_addGuards (invGuards);
2379 guardSet_free (invGuards);
2381 clauseStack_pop (gc.clauses);
2382 gc.inclause = topClause (gc.clauses);
2385 void context_exitForClause (exprNode forPred, exprNode body)
2387 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2389 llassert (gc.inclause == FORCLAUSE);
2390 context_setJustPopped ();
2392 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2395 ** Predicate must be false after for loop (unless there are breaks)
2398 if (context_getFlag (FLG_FORLOOPEXEC))
2400 DPRINTF (("Here: for loop exec"));
2401 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2405 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2406 && exprNode_loopMustExec (forPred))
2408 DPRINTF (("Here: loop must exec"));
2409 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2413 DPRINTF (("Pop true branch:"));
2414 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2418 usymtab_addGuards (invGuards);
2419 guardSet_free (invGuards);
2420 clauseStack_pop (gc.clauses);
2421 gc.inclause = topClause (gc.clauses);
2424 static void context_exitClausePlain (void)
2426 llassert (gc.inclause != NOCLAUSE);
2428 if (gc.inclause == FALSECLAUSE)
2430 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2434 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2438 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2440 context_setJustPopped ();
2442 if (gc.inclause == FALSECLAUSE)
2444 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2446 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2448 clauseStack_pop (gc.clauses);
2449 gc.inclause = topClause (gc.clauses);
2453 context_exitTrueClause (pred, tbranch);
2458 context_returnFunction (void)
2460 usymtab_checkFinalScope (TRUE);
2464 context_exitFunction (void)
2466 DPRINTF (("Exit function: %s", context_unparse ()));
2468 if (!context_inFunction () && !context_inMacroConstant ()
2469 && !context_inUnknownMacro ()
2470 && !context_inIterDef () && !context_inIterEnd ())
2473 ** not a bug because of parse errors
2480 if (context_inMacro () && usymtab_inFunctionScope ())
2482 usymtab_exitScope (exprNode_undefined);
2485 if (uentry_hasGlobs (gc.cont.fcn))
2487 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2491 if (uentry_hasMods (gc.cont.fcn))
2493 if (context_getFlag (FLG_MUSTMOD))
2495 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2499 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2502 ** clear file static modifies
2505 /* do this first to get unused error messages */
2507 usymtab_exitScope (exprNode_undefined);
2508 sRef_exitFunctionScope ();
2510 gc.showfunction = FALSE;
2511 gc.kind = CX_GLOBAL;
2512 gc.cont.glob = TRUE;
2514 gc.globs = globSet_new ();
2515 globSet_clear (gc.globs_used);
2516 gc.mods = sRefSet_new ();
2519 llassert (clauseStack_isEmpty (gc.clauses));
2520 llassert (gc.inclause == NOCLAUSE);
2521 DPRINTF (("After exit function: %s", context_unparse ()));
2525 context_quietExitFunction (void)
2527 while (gc.kind == CX_INNER)
2529 context_exitInnerPlain ();
2532 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2533 && !context_inIterDef () && !context_inIterEnd ())
2538 usymtab_quietExitScope (g_currentloc);
2540 gc.showfunction = FALSE;
2541 gc.kind = CX_GLOBAL;
2542 gc.cont.glob = TRUE;
2544 gc.globs = globSet_new ();
2545 globSet_clear (gc.globs_used);
2546 gc.mods = sRefSet_new ();
2548 sRef_exitFunctionScope ();
2552 /*@observer@*/ uentryList
2553 context_getParams (void)
2555 if (context_inFunctionLike ())
2557 return (uentry_getParams (gc.cont.fcn));
2561 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2562 return uentryList_undefined;
2566 /*@observer@*/ globSet
2567 context_getUsedGlobs (void)
2569 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2570 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2572 return (gc.globs_used);
2576 context_moduleName ()
2578 return (fileloc_getBase (g_currentloc));
2581 /*@observer@*/ globSet
2582 context_getGlobs (void)
2584 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2585 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2591 context_addBoolAccess (void)
2593 cstring bname = context_getString (FLG_BOOLTYPE);
2594 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2596 addModuleAccess (cstring_copy (bname), boolt);
2598 /* for sys/types (perhaps, this is bogus!) */
2599 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2604 context_canAccessBool (void)
2611 static typeId boolType = typeId_invalid;
2613 if (typeId_isInvalid (boolType))
2615 boolType = usymtab_getTypeId (context_getBoolName ());
2618 if (typeId_isInvalid (boolType)) {
2621 return (typeIdSet_member (gc.acct, boolType));
2626 /* evs 2000-07-25: old version - replaced */
2629 context_boolImplementationType () {
2630 /* For now, this is bogus! */
2635 context_canAccessBool (void)
2637 static typeId boolType = typeId_invalid;
2639 if (typeId_isInvalid (boolType))
2641 boolType = usymtab_getTypeId (context_getBoolName ());
2644 if (!typeId_isInvalid (boolType))
2646 return context_hasAccess (boolType);
2657 context_setMessageAnnote (/*@only@*/ cstring s)
2659 llassert (cstring_isUndefined (gc.msgAnnote));
2664 context_hasMessageAnnote (void)
2666 return (cstring_isDefined (gc.msgAnnote));
2670 context_clearMessageAnnote (void)
2672 if (cstring_isDefined (gc.msgAnnote))
2674 cstring_free (gc.msgAnnote);
2675 gc.msgAnnote = cstring_undefined;
2680 context_getMessageAnnote (void)
2682 cstring st = gc.msgAnnote;
2684 gc.msgAnnote = cstring_undefined;
2689 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2691 llassert (sRef_isInvalid (gc.aliasAnnote));
2692 llassert (!sRef_sameName (s, t));
2694 gc.aliasAnnoteAls = t;
2698 context_hasAliasAnnote (void)
2700 return (sRef_isValid (gc.aliasAnnote));
2704 context_clearAliasAnnote (void)
2706 gc.aliasAnnote = sRef_undefined;
2710 context_getAliasAnnote (void)
2712 sRef ret = gc.aliasAnnote;
2713 sRef als = gc.aliasAnnoteAls;
2715 llassert (sRef_isValid (ret) && sRef_isValid (als));
2717 gc.aliasAnnote = sRef_undefined;
2718 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2722 context_recordFileModifies (sRefSet mods)
2724 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2728 context_recordFileGlobals (globSet mods)
2730 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2731 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2735 context_setCommentMarkerChar (char c)
2737 llassert (c != '\0');
2739 context_setValue (FLG_COMMENTCHAR, (int) c);
2743 context_getCommentMarkerChar (void)
2745 return ((char) context_getValue (FLG_COMMENTCHAR));
2749 context_setValue (flagcode flag, int val)
2751 int index = flagcode_valueIndex (flag);
2753 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2761 llerror_flagWarning (message ("Value for %s must be a positive "
2762 "number (given %d)",
2763 flagcode_unparse (flag), val));
2766 if (flag == FLG_LINELEN && val < MINLINELEN)
2768 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2769 flagcode_unparse (flag),
2775 case FLG_INCLUDENEST:
2776 case FLG_CONTROLNESTDEPTH:
2777 case FLG_STRINGLITERALLEN:
2778 case FLG_NUMSTRUCTFIELDS:
2779 case FLG_NUMENUMMEMBERS:
2780 case FLG_INDENTSPACES:
2783 llerror_flagWarning (message ("Value for %s must be a non-negative "
2784 "number (given %d)",
2785 flagcode_unparse (flag), val));
2794 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2795 gc.values[index] = val;
2799 context_setValueAndFlag (flagcode flag, int val)
2801 gc.flags[flag] = TRUE;
2802 context_setValue (flag, val);
2806 context_getValue (flagcode flag)
2808 int index = flagcode_valueIndex (flag);
2810 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2811 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2812 return (gc.values[index]);
2816 context_getCounter (flagcode flag)
2818 int index = flagcode_valueIndex (flag);
2820 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2821 return (gc.counters[index]);
2825 context_incCounter (flagcode flag)
2827 int index = flagcode_valueIndex (flag);
2829 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2831 gc.counters[index]++;
2835 context_decCounter (flagcode flag)
2837 int index = flagcode_valueIndex (flag);
2839 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2840 gc.counters[index]--;
2843 bool context_showFunction (void)
2845 return (gc.showfunction);
2849 context_setString (flagcode flag, cstring val)
2851 int index = flagcode_stringIndex (flag);
2853 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2855 if (flag == FLG_SYSTEMDIRS)
2857 llassert (cstring_isDefined (val));
2859 if (cstring_firstChar (val) == '\"')
2862 cstring tval = cstring_copy (cstring_suffix (val, 1));
2864 if (cstring_lastChar (tval) != '\"')
2866 int n = cstring_length (tval) - 1;
2868 while (isspace ((int) cstring_getChar (tval, n)))
2873 if (cstring_getChar (tval, n) != '\"')
2875 llerror_flagWarning (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2879 cstring otval = tval;
2880 tval = cstring_prefix (tval, n);
2881 cstring_free (otval);
2885 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2886 DPRINTF (("val = %s", val));
2887 cstring_free (tval);
2888 cstring_free (oval);
2892 if (flag == FLG_TMPDIR)
2894 llassert (cstring_isDefined (val));
2896 if (cstring_length (val) == 0)
2899 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2901 else if (cstring_lastChar (val) != CONNECTCHAR)
2903 val = cstring_appendChar (val, CONNECTCHAR);
2911 if (cstring_length (val) >= 1
2912 && cstring_firstChar (val) == '\"')
2914 llerror_flagWarning (message
2915 ("setting %s to string beginning with \". You probably "
2916 "don't meant to have the \"'s.",
2917 flagcode_unparse (flag)));
2920 if (flag == FLG_BOOLTYPE)
2925 gc.strings[index] = val;
2928 static /*@exposed@*/ cstring
2929 context_exposeString (flagcode flag)
2931 int index = flagcode_stringIndex (flag);
2933 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2934 return (gc.strings[index]);
2938 context_getString (flagcode flag)
2940 return (context_exposeString (flag));
2944 context_resetErrors (void)
2949 void context_initMod (void)
2950 /*@globals undef gc; @*/
2952 gc.kind = CX_GLOBAL;
2954 gc.savekind = CX_ERROR;
2955 gc.savecont.glob = FALSE;
2957 gc.instandardlib = FALSE;
2960 gc.linesprocessed = 0;
2961 gc.speclinesprocessed = 0;
2962 gc.insuppressregion = FALSE;
2963 gc.macroMissingParams = FALSE;
2964 gc.preprocessing = FALSE;
2965 gc.incommandline = FALSE;
2966 gc.mc = macrocache_create ();
2968 gc.maxmods = DEFAULTMAXMODS;
2969 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2971 gc.library = FLG_ANSILIB;
2973 gc.locstack = filelocStack_new ();
2974 gc.modrecs = sRefSetList_undefined;
2975 gc.anyExports = FALSE;
2977 gc.ftab = fileTable_create ();
2978 gc.msgLog = messageLog_new ();
2979 gc.inimport = FALSE;
2980 gc.inDerivedFile = FALSE;
2981 gc.inheader = FALSE;
2982 gc.markers = flagMarkerList_new ();
2983 gc.cont.glob = TRUE;
2984 gc.showfunction = FALSE;
2985 gc.msgAnnote = cstring_undefined;
2986 gc.aliasAnnote = sRef_undefined;
2987 gc.aliasAnnoteAls = sRef_undefined;
2988 gc.boolType = ctype_bool;
2989 gc.mods = sRefSet_new ();
2991 gc.saveloc = fileloc_undefined;
2993 gc.inmacrocache = FALSE;
2994 gc.inclause = NOCLAUSE;
2995 gc.clauses = clauseStack_new ();
2996 gc.globs = globSet_new ();
2997 gc.nacct = typeIdSet_emptySet ();
2998 gc.acct = typeIdSet_emptySet ();
2999 gc.facct = typeIdSet_emptySet ();
3000 gc.savedFlags = FALSE;
3001 gc.pushloc = fileloc_undefined;
3002 gc.protectVars = FALSE;
3003 gc.justpopped = FALSE;
3004 gc.isNullGuarded = NO;
3005 gc.globs_used = globSet_undefined;
3009 gc.setGlobally[code] = FALSE;
3010 gc.setLocally[code] = FALSE;
3016 context_resetAllFlags ();
3018 assertSet (gc.flags); /* Can't use global in defines */
3019 assertSet (gc.saveflags);
3020 assertSet (gc.values);
3021 assertSet (gc.strings);
3023 conext_resetAllCounters ();
3024 assertSet (gc.counters);
3026 context_setMode (DEFAULT_MODE);
3028 gc.stateTable = metaStateTable_create ();
3029 gc.annotTable = annotationTable_create ();
3031 gc.inFunctionHeader = FALSE;
3033 DPRINTF (("Annotations: \n%s",
3034 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3035 DPRINTF (("State: \n%s",
3036 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3041 context_typeofZero (void)
3043 ctype ct = ctype_int;
3045 if (context_getFlag (FLG_ZEROPTR))
3047 ct = ctype_makeConj (ct, ctype_voidPointer);
3050 if (context_getFlag (FLG_ZEROBOOL)) {
3051 ct = ctype_makeConj (ct, ctype_bool);
3058 context_typeofOne (void)
3060 ctype ct = ctype_int;
3062 /* 1 is on longer a bool (was before 2.4)
3063 if (!context_getFlag (FLG_ABSTRACTBOOL))
3065 ct = ctype_makeConj (ct, ctype_bool);
3073 context_unparse (void)
3080 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3083 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3086 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3089 s = message ("Inner Context [%d] : %q",
3091 fileloc_unparse (g_currentloc));
3094 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3095 uentry_unparse (gc.cont.fcn),
3096 fileloc_unparse (g_currentloc),
3097 typeIdSet_unparse (gc.acct),
3098 sRefSet_unparse (gc.mods));
3101 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3103 case CX_UNKNOWNMACRO:
3104 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3107 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3110 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3113 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3115 case CX_FCNDECLARATION:
3116 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3119 s = message ("Un-unparseable context: %d", (int) gc.kind);
3123 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3128 context_currentFunctionType (void)
3130 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3132 return (uentry_getType (gc.cont.fcn));
3134 else if (gc.kind == CX_INNER)
3136 llcontbuglit ("context_currentFunctionType: inner context");
3137 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3138 return (context_currentFunctionType ());
3142 llcontbuglit ("context_currentFunctionType: not in function");
3143 return (ctype_undefined);
3148 context_enterInnerContext (void)
3150 if (context_getFlag (FLG_GRAMMAR))
3152 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3155 if (gc.kind == CX_GLOBAL)
3160 else if (gc.kind == CX_INNER)
3169 usymtab_enterScope ();
3170 pushClause (NOCLAUSE);
3174 context_exitInnerPlain (void) /*@modifies gc;@*/
3176 context_exitInner (exprNode_undefined);
3180 context_exitInner (exprNode exp)
3182 if (context_getFlag (FLG_GRAMMAR))
3184 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3187 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3188 ("inclause = %s", clause_nameTaken (gc.inclause)));
3190 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3191 gc.inclause = topClause (gc.clauses);
3193 if (gc.kind == CX_INNER)
3195 if (--gc.cont.cdepth == 0)
3197 gc.kind = CX_GLOBAL;
3198 gc.cont.glob = TRUE;
3203 if (gc.kind == CX_GLOBAL)
3205 llcontbuglit ("Attempt to exit global context");
3210 usymtab_exitScope (exp);
3215 context_enterStructInnerContext (void)
3217 if (context_getFlag (FLG_GRAMMAR))
3219 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3222 if (gc.kind == CX_GLOBAL)
3227 else if (gc.kind == CX_INNER)
3236 usymtab_enterScope ();
3238 if (context_getFlag (FLG_GRAMMAR))
3240 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3245 context_exitStructInnerContext (void)
3247 if (context_getFlag (FLG_GRAMMAR))
3249 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3252 if (gc.kind == CX_INNER)
3254 if (gc.cont.cdepth <= 0)
3256 llcontbuglit ("Attempt to exit inner context with no depth");
3257 gc.kind = CX_GLOBAL;
3258 gc.cont.glob = TRUE;
3264 if (gc.cont.cdepth == 0)
3266 gc.kind = CX_GLOBAL;
3267 gc.cont.glob = TRUE;
3273 if (gc.kind == CX_GLOBAL)
3275 llcontbuglit ("Attempt to exit global context");
3280 usymtab_exitScope (exprNode_undefined);
3282 if (context_getFlag (FLG_GRAMMAR))
3284 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3289 context_exitInnerSafe (void)
3291 if (context_getFlag (FLG_GRAMMAR))
3293 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3296 if (gc.kind == CX_INNER)
3298 if (--gc.cont.cdepth <= 0)
3303 else if (gc.kind == CX_GLOBAL)
3305 llcontbuglit ("Attempt to exit global context");
3310 if (usymtab_inDeepScope ())
3312 usymtab_exitScope (exprNode_undefined);
3318 void setModuleAccess (void)
3320 gc.facct = typeIdSet_emptySet ();
3322 if (fileId_isValid (currentFile ()))
3324 cstring baseName = fileloc_getBase (g_currentloc);
3326 if (context_getFlag (FLG_ACCESSFILE))
3328 if (usymtab_existsType (baseName))
3330 gc.facct = typeIdSet_insert (gc.facct,
3331 usymtab_getTypeId (baseName));
3339 if (context_getFlag (FLG_ACCESSMODULE))
3342 bool hasaccess = FALSE;
3344 for (i = 0; i < gc.nmods; i++)
3346 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3348 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3357 gc.inheader = fileId_isHeader (currentFile ());
3361 llcontbuglit ("Current file not defined\n");
3362 gc.facct = typeIdSet_emptySet ();
3364 gc.inheader = FALSE;
3367 /* 17 Jan 1995: forgot to clear nacct */
3369 gc.nacct = typeIdSet_emptySet ();
3373 context_enterFileAux (void)
3379 context_enterFile (void)
3381 context_enterFileAux ();
3382 usymtab_enterFile ();
3386 context_enterMacroFile (void)
3388 context_enterFileAux ();
3392 context_inFunction (void)
3394 kcontext ck = gc.kind;
3396 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3400 context_inFunctionLike (void)
3402 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3403 || gc.kind == CX_FCNDECLARATION
3404 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3408 context_inRealFunction (void)
3410 kcontext ck = gc.kind;
3412 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3416 context_processAllMacros (void)
3418 usymtab_enterFile ();
3420 gc.inmacrocache = TRUE;
3421 macrocache_processUndefinedElements (gc.mc);
3423 usymtab_exitFile ();
3425 gc.inmacrocache = FALSE;
3426 macrocache_finalize ();
3430 ** this happens once at the end of each C file
3432 ** check each Macro that was defined in current file.c or current file.h
3437 context_processMacros (void)
3439 if (fileId_isValid (currentFile ()))
3442 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileName (currentFile ())));
3444 gc.inmacrocache = TRUE;
3446 DPRINTF (("Processing macros: %s", cbase));
3447 lastfl = macrocache_processFileElements (gc.mc, cbase);
3448 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3450 cstring_free (cbase);
3452 if (fileloc_isDefined (lastfl))
3454 g_currentloc = fileloc_update (g_currentloc, lastfl);
3458 gc.inmacrocache = FALSE;
3463 context_processingMacros (void)
3465 return (gc.inmacrocache);
3469 context_exitCFile (void)
3471 if (gc.kind != CX_GLOBAL)
3474 (cstring_makeLiteral ("File ended outside global scope"));
3477 if (gc.insuppressregion)
3479 /* gack...don't reverse the order of these lines! ;-> */
3480 gc.insuppressregion = FALSE;
3481 llerrorlit (FLG_SYNTAX,
3482 "File ended in ignore errors region, "
3483 "possible missing /*@end*/");
3486 /* fix up parse errors */
3488 while (!usymtab_inFileScope ())
3490 usymtab_quietExitScope (g_currentloc);
3494 ** Clear the file-specific modifies information.
3497 sRefSetList_elements (gc.modrecs, mods)
3499 sRefSet_clearStatics (mods);
3500 } end_sRefSetList_elements ;
3502 sRefSetList_clear (gc.modrecs);
3504 context_processMacros ();
3507 usymtab_exitFile ();
3509 gc.inDerivedFile = FALSE;
3510 filelocStack_clear (gc.locstack);
3512 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3514 gc.cont.glob = TRUE;
3518 context_restoreFlagSettings ();
3519 gc.savedFlags = FALSE;
3523 DPRINTF (("After exiting file: "));
3524 usymtab_printAll ();
3529 context_exitMacroCache (void)
3531 if (gc.kind != CX_GLOBAL)
3533 if (context_inMacro ())
3534 /* this is okay, file could end without newline in macro */
3536 DPRINTF (("Still in macro: %s",
3537 context_unparse ()));
3538 context_exitFunction ();
3542 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3543 context_unparse ()));
3544 gc.kind = CX_GLOBAL;
3549 ** no longer valid here
3550 ** if (gc.insuppressregion)
3552 ** gc.insuppressregion = FALSE;
3553 ** llerror ("File ended in ignore errors region, possible missing @");
3557 gc.cont.glob = TRUE;
3561 context_saveLocation (void)
3563 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3564 fileloc_free (gc.saveloc);
3565 gc.saveloc = fileloc_copy (g_currentloc);
3569 context_getSaveLocation (void)
3571 fileloc fl = gc.saveloc;
3572 gc.saveloc = fileloc_undefined;
3576 /*@observer@*/ cstring
3577 context_inFunctionName (void)
3579 if (gc.kind == CX_FUNCTION
3580 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3581 || gc.kind == CX_MACROCONST
3582 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3584 return (uentry_rawName (gc.cont.fcn));
3588 llcontbuglit ("context_inFunctionName: not in function");
3589 return (cstring_undefined);
3594 context_userSetFlag (flagcode f, bool b)
3596 DPRINTF (("set flag: %s", flagcode_unparse (f)));
3598 if (f == FLG_NEVERINCLUDE && b)
3600 if (gc.flags[FLG_EXPORTHEADER])
3602 llerror_flagWarning (cstring_makeLiteral
3603 ("setting +neverinclude after +exportheader. "
3604 "Turning off exportheader, since headers are not checked "
3605 "when +neverinclude is used."));
3607 gc.flags[FLG_EXPORTHEADER] = FALSE;
3612 if (f == FLG_EXPORTHEADER && b)
3614 if (gc.flags[FLG_NEVERINCLUDE])
3616 llerror_flagWarning (cstring_makeLiteral
3617 ("setting +exportheader after +neverinclude. "
3618 "Not setting exportheader, since headers are not checked "
3619 "when +neverinclude is used."));
3620 gc.flags[FLG_EXPORTHEADER] = FALSE;
3626 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3628 bool lastsetting = context_getFlag (f);
3630 if (bool_equal (lastsetting, b)
3631 && !flagcode_isSpecialFlag (f)
3632 && !flagcode_isIdemFlag (f)
3633 && !flagcode_hasArgument (f))
3635 llerror_flagWarning (message ("setting %s%s redundant with current value",
3636 cstring_makeLiteralTemp (b ? "+" : "-"),
3637 flagcode_unparse (f)));
3641 if (flagcode_isWarnUseFlag (f) && b)
3643 if (!context_getFlag (FLG_WARNUSE))
3645 llerror_flagWarning (message ("flag +%s is canceled by -warnuse",
3646 flagcode_unparse (f)));
3652 if (flagcode_isLibraryFlag (f))
3654 if (gc.library != FLG_ANSILIB
3657 llerror_flagWarning (message ("selecting library %s after library %s was "
3658 "selected (only one library may be used)",
3659 flagcode_unparse (f),
3660 flagcode_unparse (gc.library)));
3663 if (f == FLG_UNIXLIB)
3665 if (context_getFlag (FLG_WARNUNIXLIB))
3667 llerror_flagWarning (cstring_makeLiteral
3668 ("selecting unix library. Unix library is "
3669 "ad hoc addition to POSIX library. Recommend "
3670 "use +posixlib to select POSIX library instead. "
3671 "Use -warnunixlib to suppress this message."));
3678 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3680 llerror_flagWarning (message
3681 ("setting +%s will not produce warnings with -namechecks. Must set +namechecks also.",
3682 flagcode_unparse (f)));
3685 gc.setGlobally[f] = TRUE;
3686 context_setFlag (f, b);
3690 context_fileSetFlag (flagcode f, ynm set)
3694 context_saveFlagSettings ();
3697 if (ynm_isOff (set))
3699 context_setFlagAux (f, FALSE, TRUE, FALSE);
3701 else if (ynm_isOn (set))
3703 context_setFlagAux (f, TRUE, TRUE, FALSE);
3704 gc.setLocally[f] = TRUE;
3708 context_restoreFlag (f);
3713 context_restoreFlag (flagcode f)
3720 message ("Attempt to restore flag %s when no file scope flags "
3722 flagcode_unparse (f)),
3727 context_addFlagMarker (f, MAYBE);
3728 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3734 context_setFlag (flagcode f, bool b)
3736 context_setFlagAux (f, b, FALSE, FALSE);
3740 context_setFlagTemp (flagcode f, bool b)
3742 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3747 # define DOSET(ff,b) \
3748 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3749 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3750 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3751 gc.flags[ff] = b; } while (FALSE)
3754 context_setFlagAux (flagcode f, bool b, bool inFile,
3755 /*@unused@*/ bool isRestore)
3757 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3759 if (f == FLG_USESTDERR)
3762 g_msgstream = stderr;
3764 g_msgstream = stdout;
3769 ** Removed test for special flags.
3772 if (flagcode_isIdemFlag (f))
3781 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3783 if (b) /* Turing higher level on, turns on all lower levels */
3787 case FLG_ITS4MOSTRISKY:
3788 DOSET (FLG_ITS4VERYRISKY, b);
3790 case FLG_ITS4VERYRISKY:
3791 DOSET (FLG_ITS4RISKY, b);
3794 DOSET (FLG_ITS4MODERATERISK, b);
3796 case FLG_ITS4MODERATERISK:
3797 DOSET (FLG_ITS4LOWRISK, b);
3799 case FLG_ITS4LOWRISK:
3804 else /* Turning level off, turns off all higher levels */
3808 case FLG_ITS4LOWRISK:
3809 DOSET (FLG_ITS4MODERATERISK, b);
3811 case FLG_ITS4MODERATERISK:
3812 DOSET (FLG_ITS4RISKY, b);
3815 DOSET (FLG_ITS4VERYRISKY, b);
3817 case FLG_ITS4VERYRISKY:
3818 DOSET (FLG_ITS4MOSTRISKY, b);
3820 case FLG_ITS4MOSTRISKY:
3830 DOSET (FLG_ALLEMPTY, b);
3831 DOSET (FLG_IFEMPTY, b);
3832 DOSET (FLG_WHILEEMPTY, b);
3833 DOSET (FLG_FOREMPTY, b);
3836 DOSET (FLG_PREDBOOL, b);
3837 DOSET (FLG_PREDBOOLINT, b);
3838 DOSET (FLG_PREDBOOLPTR, b);
3839 DOSET (FLG_PREDBOOLOTHERS, b);
3842 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3843 DOSET (FLG_CHECKEDGLOBALIAS, b);
3844 DOSET (FLG_CHECKMODGLOBALIAS, b);
3845 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3848 DOSET (FLG_ALLBLOCK, b);
3849 DOSET (FLG_IFBLOCK, b);
3850 DOSET (FLG_WHILEBLOCK, b);
3851 DOSET (FLG_FORBLOCK, b);
3865 DOSET (FLG_GRAMMAR, b);
3867 case FLG_CODEIMPONLY:
3868 DOSET (FLG_CODEIMPONLY, b);
3869 DOSET (FLG_GLOBIMPONLY, b);
3870 DOSET (FLG_RETIMPONLY, b);
3871 DOSET (FLG_STRUCTIMPONLY, b);
3873 case FLG_SPECALLIMPONLY:
3874 DOSET (FLG_SPECALLIMPONLY, b);
3875 DOSET (FLG_SPECGLOBIMPONLY, b);
3876 DOSET (FLG_SPECRETIMPONLY, b);
3877 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3879 case FLG_ALLIMPONLY:
3880 DOSET (FLG_ALLIMPONLY, b);
3881 DOSET (FLG_GLOBIMPONLY, b);
3882 DOSET (FLG_RETIMPONLY, b);
3883 DOSET (FLG_STRUCTIMPONLY, b);
3884 DOSET (FLG_SPECGLOBIMPONLY, b);
3885 DOSET (FLG_SPECRETIMPONLY, b);
3886 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3888 case FLG_ANSI89LIMITS:
3889 DOSET (FLG_ANSI89LIMITS, b);
3890 DOSET (FLG_CONTROLNESTDEPTH, b);
3891 DOSET (FLG_STRINGLITERALLEN, b);
3892 DOSET (FLG_INCLUDENEST, b);
3893 DOSET (FLG_NUMSTRUCTFIELDS, b);
3894 DOSET (FLG_NUMENUMMEMBERS, b);
3898 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
3899 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
3900 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
3901 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
3902 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
3903 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
3904 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
3907 case FLG_ISO99LIMITS:
3908 DOSET (FLG_ISO99LIMITS, b);
3909 DOSET (FLG_CONTROLNESTDEPTH, b);
3910 DOSET (FLG_STRINGLITERALLEN, b);
3911 DOSET (FLG_INCLUDENEST, b);
3912 DOSET (FLG_NUMSTRUCTFIELDS, b);
3913 DOSET (FLG_NUMENUMMEMBERS, b);
3917 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
3918 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
3919 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
3920 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
3921 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
3922 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
3923 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
3926 case FLG_EXTERNALNAMELEN:
3927 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3928 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3930 case FLG_INTERNALNAMELEN:
3931 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3932 DOSET (FLG_INTERNALNAMELEN, TRUE);
3934 case FLG_EXTERNALNAMECASEINSENSITIVE:
3935 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3937 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3939 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3940 context_setValue (FLG_EXTERNALNAMELEN, 0);
3943 case FLG_INTERNALNAMECASEINSENSITIVE:
3944 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3946 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3948 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3949 context_setValue (FLG_INTERNALNAMELEN, 0);
3952 case FLG_INTERNALNAMELOOKALIKE:
3953 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3955 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3957 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3958 context_setValue (FLG_INTERNALNAMELEN, 0);
3962 DOSET (FLG_MODNOMODS, b);
3963 DOSET (FLG_MODGLOBSUNSPEC, b);
3964 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3967 DOSET (FLG_EXPORTVAR, b);
3968 DOSET (FLG_EXPORTFCN, b);
3969 DOSET (FLG_EXPORTTYPE, b);
3970 DOSET (FLG_EXPORTMACRO, b);
3971 DOSET (FLG_EXPORTCONST, b);
3972 gc.anyExports = TRUE;
3975 DOSET (FLG_RETEXPOSE, b);
3976 DOSET (FLG_ASSIGNEXPOSE, b);
3977 DOSET (FLG_CASTEXPOSE, b);
3980 DOSET (FLG_RETVALBOOL, b);
3981 DOSET (FLG_RETVALINT, b);
3982 DOSET (FLG_RETVALOTHER, b);
3987 DOSET (FLG_EXPORTLOCAL, FALSE);
3988 DOSET (FLG_DECLUNDEF, FALSE);
3989 DOSET (FLG_SPECUNDEF, FALSE);
3990 DOSET (FLG_TOPUNUSED, FALSE);
3994 DOSET (FLG_LOOPLOOPBREAK, b);
3995 DOSET (FLG_LOOPSWITCHBREAK, b);
3996 DOSET (FLG_SWITCHLOOPBREAK, b);
3997 DOSET (FLG_SWITCHSWITCHBREAK, b);
3998 DOSET (FLG_LOOPLOOPCONTINUE, b);
3999 DOSET (FLG_DEEPBREAK, b);
4002 DOSET (FLG_FORLOOPEXEC, b);
4003 DOSET (FLG_WHILELOOPEXEC, b);
4004 DOSET (FLG_ITERLOOPEXEC, b);
4007 DOSET (FLG_ACCESSMODULE, b);
4008 DOSET (FLG_ACCESSFILE, b);
4009 DOSET (FLG_ACCESSCZECH, b);
4012 DOSET (FLG_ALLMACROS, b);
4013 DOSET (FLG_FCNMACROS, b);
4014 DOSET (FLG_CONSTMACROS, b);
4017 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4018 DOSET (FLG_CZECHFUNCTIONS, b);
4019 DOSET (FLG_CZECHVARS, b);
4020 DOSET (FLG_CZECHCONSTANTS, b);
4021 DOSET (FLG_CZECHTYPES, b);
4024 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4025 DOSET (FLG_SLOVAKFUNCTIONS, b);
4026 DOSET (FLG_SLOVAKVARS, b);
4027 DOSET (FLG_SLOVAKCONSTANTS, b);
4028 DOSET (FLG_SLOVAKTYPES, b);
4030 case FLG_CZECHOSLOVAK:
4031 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4032 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4033 DOSET (FLG_CZECHOSLOVAKVARS, b);
4034 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4035 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4038 DOSET (FLG_NULLSTATE, b);
4039 DOSET (FLG_NULLDEREF, b);
4040 DOSET (FLG_NULLASSIGN, b);
4041 DOSET (FLG_NULLPASS, b);
4042 DOSET (FLG_NULLRET, b);
4045 DOSET (FLG_MUSTFREEONLY, b);
4046 DOSET (FLG_MUSTFREEFRESH, b);
4049 DOSET (FLG_NULLSTATE, b);
4050 DOSET (FLG_NULLDEREF, b);
4051 DOSET (FLG_NULLASSIGN, b);
4052 DOSET (FLG_NULLPASS, b);
4053 DOSET (FLG_NULLRET, b);
4054 DOSET (FLG_COMPDEF, b);
4055 DOSET (FLG_COMPMEMPASS, b);
4056 DOSET (FLG_UNIONDEF, b);
4057 DOSET (FLG_MEMTRANS, b);
4058 DOSET (FLG_USERELEASED, b);
4059 DOSET (FLG_ALIASUNIQUE, b);
4060 DOSET (FLG_MAYALIASUNIQUE, b);
4061 DOSET (FLG_MUSTFREEONLY, b);
4062 DOSET (FLG_MUSTFREEFRESH, b);
4063 DOSET (FLG_MUSTDEFINE, b);
4064 DOSET (FLG_GLOBSTATE, b);
4065 DOSET (FLG_COMPDESTROY, b);
4066 DOSET (FLG_MUSTNOTALIAS, b);
4067 DOSET (FLG_MEMIMPLICIT, b);
4068 DOSET (FLG_BRANCHSTATE, b);
4069 /*@fallthrough@*/ /* also sets memtrans flags */
4071 DOSET (FLG_MEMTRANS, b);
4072 DOSET (FLG_EXPOSETRANS, b);
4073 DOSET (FLG_OBSERVERTRANS, b);
4074 DOSET (FLG_DEPENDENTTRANS, b);
4075 DOSET (FLG_NEWREFTRANS, b);
4076 DOSET (FLG_ONLYTRANS, b);
4077 DOSET (FLG_OWNEDTRANS, b);
4078 DOSET (FLG_FRESHTRANS, b);
4079 DOSET (FLG_SHAREDTRANS, b);
4080 DOSET (FLG_TEMPTRANS, b);
4081 DOSET (FLG_KEPTTRANS, b);
4082 DOSET (FLG_REFCOUNTTRANS, b);
4083 DOSET (FLG_STATICTRANS, b);
4084 DOSET (FLG_UNKNOWNTRANS, b);
4085 DOSET (FLG_KEEPTRANS, b);
4086 DOSET (FLG_IMMEDIATETRANS, b);
4093 if (b && !gc.anyExports
4094 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4095 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4096 || f == FLG_EXPORTCONST
4097 || f == FLG_EXPORTANY))
4099 gc.anyExports = TRUE;
4104 context_maybeSet (flagcode d)
4106 return (gc.flags[d] || gc.setLocally[d]);
4110 context_getFlag (flagcode d)
4112 return (gc.flags[d]);
4116 context_flagOn (flagcode f, fileloc loc)
4118 return (!context_suppressFlagMsg (f, loc));
4121 static void context_saveFlagSettings (void)
4123 gc.savedFlags = TRUE;
4124 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4125 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4128 static void context_restoreFlagSettings (void)
4130 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4131 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4132 gc.savedFlags = FALSE;
4135 void context_setFilename (fileId fid, int lineno)
4136 /*@globals fileloc g_currentloc;@*/
4137 /*@modifies g_currentloc@*/
4139 if (fileId_baseEqual (currentFile (), fid))
4146 fileloc_setColumn (g_currentloc, 0);
4148 if (fileloc_isSpecialFile (g_currentloc))
4150 gc.inDerivedFile = TRUE;
4153 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4155 int maxdepth = context_getValue (FLG_INCLUDENEST);
4157 if (filelocStack_size (gc.locstack) > maxdepth)
4159 int depth = filelocStack_includeDepth (gc.locstack);
4161 if (depth > maxdepth)
4165 message ("Maximum include nesting depth "
4166 "(%d, current depth %d) exceeded",
4169 filelocStack_nextTop (gc.locstack)))
4171 filelocStack_printIncludes (gc.locstack);
4177 g_currentloc = fileloc_create (fid, lineno, 1);
4178 gc.inheader = fileId_isHeader (currentFile ());
4180 context_enterFileAux ();
4184 void context_enterIterDef (/*@observer@*/ uentry le)
4186 context_enterMacro (le);
4187 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4188 gc.kind = CX_ITERDEF;
4191 void context_enterIterEnd (/*@observer@*/ uentry le)
4193 context_enterMacro (le);
4194 gc.kind = CX_ITEREND;
4198 context_destroyMod (void)
4199 /*@globals killed gc@*/
4202 ctype_destroyMod ();
4206 fileTable_free (gc.ftab);
4207 filelocStack_free (gc.locstack);
4209 gc.ftab = fileTable_undefined;
4211 macrocache_free (gc.mc);
4212 sfree (gc.moduleaccess);
4215 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4216 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4219 sRefSetList_free (gc.modrecs);
4221 flagMarkerList_free (gc.markers);
4223 messageLog_free (gc.msgLog);
4225 clauseStack_free (gc.clauses);
4228 cstring_free (gc.msgAnnote);
4229 globSet_free (gc.globs_used);
4230 metaStateTable_free (gc.stateTable);
4231 annotationTable_free (gc.annotTable);
4238 bool context_msgBoolInt (void)
4240 return gc.flags [FLG_BOOLINT];
4243 bool context_msgCharInt (void)
4245 return gc.flags [FLG_CHARINT];
4248 bool context_msgEnumInt (void)
4250 return gc.flags [FLG_ENUMINT];
4253 bool context_msgPointerArith (void)
4255 return gc.flags [FLG_POINTERARITH];
4258 bool context_msgStrictOps (void)
4260 return gc.flags [FLG_STRICTOPS];
4264 bool context_msgLh (void)
4266 return gc.flags [FLG_DOLH];
4270 void context_pushLoc (void)
4272 fileloc_free (gc.pushloc);
4273 gc.pushloc = gc.saveloc;
4274 gc.saveloc = fileloc_undefined;
4277 void context_popLoc (void)
4279 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4282 bool context_inGlobalScope (void)
4284 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4287 bool context_inInnerScope (void)
4289 return (gc.kind == CX_INNER);
4292 void context_setProtectVars (void)
4294 gc.protectVars = TRUE;
4297 bool context_anyErrors (void)
4299 return (gc.numerrors > 0);
4302 void context_hasError (void)
4305 DPRINTF (("num errors: %d", gc.numerrors));
4308 int context_numErrors (void)
4310 return gc.numerrors;
4313 bool context_neednl (void)
4318 void context_setNeednl (void)
4323 int context_getExpect (void)
4325 return (context_getValue (FLG_EXPECT));
4329 int context_getLCLExpect (void)
4331 return (context_getValue (FLG_LCLEXPECT));
4335 int context_getLimit (void)
4337 return (context_getValue (FLG_LIMIT));
4340 bool context_unlimitedMessages (void)
4342 return (context_getLimit () < 0);
4345 void context_releaseVars (void)
4347 llassert (gc.protectVars);
4348 gc.protectVars = FALSE;
4351 void context_sizeofReleaseVars (void)
4353 /* If there is a nested sizeof, this might not hold:
4354 llassert (gc.protectVars);
4357 gc.protectVars = FALSE;
4360 bool context_inProtectVars (void)
4362 return (gc.protectVars);
4365 void context_hideShowscan (void)
4367 gc.flags[FLG_SHOWSCAN] = FALSE;
4370 void context_unhideShowscan (void)
4372 gc.flags[FLG_SHOWSCAN] = TRUE;
4375 bool context_inHeader (void)
4377 return (gc.inheader);
4380 fileTable context_fileTable (void)
4385 cstring context_tmpdir (void)
4387 return (context_getString (FLG_TMPDIR));
4390 messageLog context_messageLog (void)
4395 bool context_inMacroFunction (void)
4397 return (gc.kind == CX_MACROFCN);
4400 bool context_inMacroConstant (void)
4402 return (gc.kind == CX_MACROCONST);
4405 bool context_inUnknownMacro (void)
4407 return (gc.kind == CX_UNKNOWNMACRO);
4410 void context_setShownFunction (void)
4412 gc.showfunction = FALSE;
4415 bool context_doDump (void)
4417 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4420 bool context_doMerge (void)
4422 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4425 cstring context_getDump (void)
4427 return context_getString (FLG_DUMP);
4430 cstring context_getMerge (void)
4432 return context_getString (FLG_MERGE);
4436 bool context_inLCLLib (void)
4438 return (gc.kind == CX_LCLLIB);
4441 bool context_inImport (void)
4443 return (gc.inimport);
4446 void context_enterImport (void)
4451 void context_leaveImport (void)
4453 gc.inimport = FALSE;
4457 bool context_inMacro (void)
4459 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4460 || gc.kind == CX_UNKNOWNMACRO
4461 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4464 bool context_inIterDef (void)
4466 return (gc.kind == CX_ITERDEF);
4469 bool context_inIterEnd (void)
4471 return (gc.kind == CX_ITEREND);
4474 int context_getLinesProcessed (void)
4476 return (gc.linesprocessed);
4479 int context_getSpecLinesProcessed (void)
4481 return (gc.speclinesprocessed);
4485 void context_processedSpecLine (void)
4487 gc.speclinesprocessed++;
4490 void context_resetSpecLines (void)
4492 gc.speclinesprocessed = 0;
4496 bool context_inGlobalContext (void)
4498 return (gc.kind == CX_GLOBAL);
4501 static void context_quietExitScopes (void)
4504 ** Try to restore the global scope (after an error).
4507 while (!usymtab_inFileScope ())
4509 usymtab_quietExitScope (g_currentloc);
4512 gc.cont.glob = TRUE;
4513 gc.kind = CX_GLOBAL;
4516 void context_checkGlobalScope (void)
4518 if (gc.kind != CX_GLOBAL)
4520 if (context_inMacro ())
4522 ; /* evans 2001-10-14: Okay to be in a macro here! */
4526 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4527 context_quietExitScopes ();
4532 void context_setFileId (fileId s)
4534 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4537 bool context_setBoolName (void)
4539 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4543 cstring context_printBoolName (void)
4545 if (context_setBoolName ())
4547 return context_getBoolName ();
4551 return cstring_makeLiteralTemp ("boolean");
4555 cstring context_getBoolName (void)
4557 return (context_getString (FLG_BOOLTYPE));
4560 cstring context_getFalseName (void)
4562 return (context_getString (FLG_BOOLFALSE));
4565 cstring context_getTrueName (void)
4567 return (context_getString (FLG_BOOLTRUE));
4570 cstring context_getLarchPath (void)
4572 return (context_getString (FLG_LARCHPATH));
4575 cstring context_getLCLImportDir (void)
4577 return (context_getString (FLG_LCLIMPORTDIR));
4580 static void context_setJustPopped (void)
4582 gc.justpopped = TRUE;
4585 void context_clearJustPopped (void)
4587 gc.justpopped = FALSE;
4590 bool context_justPopped (void)
4592 return (gc.justpopped);
4595 void context_setMacroMissingParams (void)
4597 gc.macroMissingParams = TRUE;
4600 void context_resetMacroMissingParams (void)
4602 gc.macroMissingParams = FALSE;
4605 bool context_isMacroMissingParams (void)
4607 return (gc.macroMissingParams);
4610 void context_showFilelocStack (void)
4612 filelocStack_printIncludes (gc.locstack);
4615 metaStateTable context_getMetaStateTable (void)
4617 return gc.stateTable;
4620 metaStateInfo context_lookupMetaStateInfo (cstring key)
4622 return metaStateTable_lookup (gc.stateTable, key);
4625 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4627 annotationInfo ainfo;
4629 ainfo = annotationTable_lookup (gc.annotTable, annot);
4634 void context_addAnnotation (annotationInfo ainfo)
4636 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (ainfo)))
4640 message ("Duplicate annotation declaration: %s", annotationInfo_getName (ainfo)),
4641 annotationInfo_getLoc (ainfo));
4643 annotationInfo_free (ainfo);
4647 annotationTable_insert (gc.annotTable, ainfo);
4651 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4653 if (metaStateTable_contains (gc.stateTable, mname))
4657 message ("Duplicate metastate declaration: %s", mname),
4658 metaStateInfo_getLoc (msinfo));
4659 cstring_free (mname);
4660 metaStateInfo_free (msinfo);
4664 DPRINTF (("Adding meta state: %s", mname));
4665 metaStateTable_insert (gc.stateTable, mname, msinfo);
4669 valueTable context_createValueTable (sRef s, stateInfo sinfo)
4671 if (metaStateTable_size (gc.stateTable) > 0)
4673 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4674 /*@i32 should use smaller value... */
4675 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4677 metaStateTable_elements (gc.stateTable, msname, msi)
4679 mtContextNode context = metaStateInfo_getContext (msi);
4681 if (mtContextNode_matchesRefStrict (context, s))
4683 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4684 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4688 cstring_copy (metaStateInfo_getName (msi)),
4689 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4690 stateInfo_copy (sinfo)));
4694 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4697 end_metaStateTable_elements ;
4699 stateInfo_free (sinfo);
4700 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4705 stateInfo_free (sinfo);
4706 return valueTable_undefined;
4710 valueTable context_createGlobalMarkerValueTable (stateInfo sinfo)
4712 if (metaStateTable_size (gc.stateTable) > 0)
4714 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4715 /*@i32 should use smaller value... */
4717 metaStateTable_elements (gc.stateTable, msname, msi)
4719 /*@i23 only add global...*/
4720 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4721 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4723 valueTable_insert (res,
4724 cstring_copy (metaStateInfo_getName (msi)),
4725 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4726 stateInfo_copy (sinfo)));
4728 end_metaStateTable_elements ;
4730 stateInfo_free (sinfo);
4731 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4736 stateInfo_free (sinfo);
4737 return valueTable_undefined;