2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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 splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
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 "splintMacros.nf"
39 # include "usymtab_interface.h"
40 # include "exprChecks.h"
41 # include "filelocStack.h"
46 extern /*@external@*/ int yydebug;
47 extern /*@external@*/ int mtdebug;
59 CX_FUNCTION, CX_FCNDECLARATION,
60 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
61 CX_ITERDEF, CX_ITEREND,
62 CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */
63 CX_LCL, CX_LCLLIB, CX_MT
69 int speclinesprocessed;
71 flagMarkerList markers;
74 ** used to record state where a macro must match a function name
75 ** (i.e., no params were listed in the macro definition
78 bool macroMissingParams BOOLBITS;
79 bool preprocessing BOOLBITS;
80 bool incommandline BOOLBITS;
81 bool insuppressregion BOOLBITS;
82 bool inDerivedFile BOOLBITS;
83 bool instandardlib BOOLBITS;
84 bool inimport BOOLBITS;
85 bool inheader BOOLBITS;
86 bool inmacrocache BOOLBITS;
87 bool protectVars BOOLBITS;
89 bool showfunction BOOLBITS;
90 bool savedFlags BOOLBITS;
91 bool justpopped BOOLBITS;
92 bool anyExports BOOLBITS;
93 bool inFunctionHeader BOOLBITS;
106 filelocStack locstack;
109 /*@observer@*/ sRef aliasAnnote;
110 /*@observer@*/ sRef aliasAnnoteAls;
114 /*@observer@*/ sRefSet mods;
116 /* file access types */
119 /* local access types (this function) */
122 /* no access types (@noaccess) */
125 /*@observer@*/ globSet globs;
126 /*@only@*/ globSet globs_used;
130 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
136 bool flags[NUMFLAGS];
137 bool saveflags[NUMFLAGS];
138 bool setGlobally[NUMFLAGS];
139 bool setLocally[NUMFLAGS];
141 int values[NUMVALUEFLAGS];
142 int counters[NUMVALUEFLAGS];
144 o_cstring strings[NUMSTRINGFLAGS];
145 sRefSetList modrecs; /* Keep track of file static symbols modified. */
147 metaStateTable stateTable; /* User-defined state information. */
148 annotationTable annotTable; /* User-defined annotations table. */
153 /*@dependent@*/ /*@exposed@*/ uentry fcn;
157 union u_cont savecont;
160 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
161 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
162 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
163 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
165 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
166 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
167 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
168 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
169 static void context_setFlag (flagcode p_f, bool p_b, fileloc p_loc)
170 /*@modifies gc.flags@*/ ;
173 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile,
174 bool p_isRestore, fileloc p_loc)
175 /*@modifies gc.flags@*/ ;
177 static void context_restoreFlag (flagcode p_f, fileloc p_loc)
178 /*@modifies gc.flags@*/ ;
182 cstring context_unparseFlagMarkers ()
184 return (flagMarkerList_unparse (gc.markers));
187 void context_setPreprocessing (void)
189 llassert (!gc.preprocessing);
190 gc.preprocessing = TRUE;
193 void context_clearPreprocessing (void)
195 llassert (gc.preprocessing);
196 gc.preprocessing = FALSE;
199 bool context_isPreprocessing (void)
201 return gc.preprocessing;
204 bool context_loadingLibrary (void)
206 return (fileloc_isLib (g_currentloc));
209 bool context_inXHFile (void)
211 return (fileloc_isXHFile (g_currentloc));
214 void context_setInCommandLine (void)
216 llassert (!gc.incommandline);
217 gc.incommandline = TRUE;
220 void context_clearInCommandLine (void)
222 llassert (gc.incommandline);
223 gc.incommandline = FALSE;
226 bool context_isInCommandLine (void)
228 return gc.incommandline;
232 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
235 clauseStack_push (gc.clauses, c);
237 if (clause_isConditional (c)
238 && context_getFlag (FLG_CONTROLNESTDEPTH))
240 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
241 int depth = clauseStack_controlDepth (gc.clauses);
243 if (depth == maxdepth + 1)
246 (FLG_CONTROLNESTDEPTH,
247 message ("Maximum control nesting depth "
256 clause topClause (clauseStack s) /*@*/
258 if (clauseStack_isEmpty (s)) return NOCLAUSE;
259 return ((clause) clauseStack_top (s));
263 context_addMacroCache (/*@only@*/ cstring def)
265 DPRINTF (("macro cache: %s", def));
266 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
270 context_addComment (/*@only@*/ cstring def, fileloc loc)
272 macrocache_addComment (gc.mc, fileloc_copy (loc), def);
276 ** returns TRUE is fl is in ignore region, or region where -code
278 ** the logic is fuzzy...
282 context_inSuppressFlagZone (fileloc fl, flagcode code)
284 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
287 if (ynm_isMaybe (ret))
295 res = !gc.saveflags[code];
299 res = !context_getFlag (code);
304 res = ynm_toBoolStrict (ret);
311 context_suppressSystemMsg (fileloc fl)
313 if (context_getFlag (FLG_SYSTEMDIRERRORS))
319 return (fileloc_isSystemFile (fl));
324 context_suppressFlagMsg (flagcode flag, fileloc fl)
326 if (context_suppressSystemMsg (fl))
331 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
333 /* want same object compare here */
335 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
337 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
339 return (!context_getFlag (flag)
340 || context_inSuppressRegion ()
341 || context_inSuppressZone (fl)
342 || (context_inSuppressFlagZone (fl, flag))); /* removed gc.inDerivedFile from this */
346 return (context_inSuppressFlagZone (fl, flag));
351 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
354 if (context_suppressSystemMsg (fl))
360 if (fl == g_currentloc)
361 /*@noaccess fileloc@*/
363 return (context_getFlag (flag) || context_inSuppressRegion ());
368 return (context_getFlag (flag) || context_inSuppressRegion ());
373 context_inSuppressZone (fileloc fl)
375 if (context_suppressSystemMsg (fl))
380 return (flagMarkerList_inIgnore (gc.markers, fl));
384 context_inSuppressRegion (void)
386 return (gc.insuppressregion);
390 context_enterSuppressRegion (fileloc loc)
392 if (gc.insuppressregion)
394 gc.insuppressregion = FALSE; /* get this msg! */
396 ("%q: New ignore errors region entered while in ignore errors region",
397 fileloc_unparse (loc)));
400 gc.insuppressregion = TRUE;
401 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (loc));
405 context_addFlagMarker (flagcode code, ynm set, fileloc loc)
407 (void) flagMarkerList_add (gc.markers,
408 flagMarker_createLocalSet (code, set, loc));
412 context_enterSuppressLine (int count, fileloc loc)
414 if (context_processingMacros ())
419 if (flagMarkerList_add
421 flagMarker_createIgnoreCount (count, loc)))
423 fileloc nextline = fileloc_copy (loc);
424 fileloc_nextLine (nextline);
425 fileloc_setColumn (nextline, 0);
427 check (flagMarkerList_add (gc.markers,
428 flagMarker_createIgnoreOff (nextline)));
429 fileloc_free (nextline);
433 void context_checkSuppressCounts (void)
435 if (context_getFlag (FLG_SUPCOUNTS))
437 flagMarkerList_checkSuppressCounts (gc.markers);
441 void context_incLineno (void)
448 context_exitSuppressRegion (fileloc loc)
450 if (!gc.insuppressregion)
454 message ("End ignore errors in region while not ignoring errors"),
458 gc.insuppressregion = FALSE;
459 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (loc));
463 context_enterMTfile (void)
469 context_exitMTfile (void)
471 llassert (gc.kind == CX_MT);
476 context_enterLCLfile (void)
479 gc.facct = typeIdSet_emptySet ();
483 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
487 for (i = 0; i < gc.nmods; i++)
489 if (cstring_equal (gc.moduleaccess[i].file, fname))
491 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
492 cstring_free (fname);
497 if (gc.nmods == gc.maxmods)
501 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
502 oldmods = gc.moduleaccess;
504 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
506 for (i = 0; i < gc.nmods; i++)
508 gc.moduleaccess[i] = oldmods[i];
514 gc.moduleaccess[gc.nmods].file = fname;
515 gc.moduleaccess[gc.nmods].daccess = mods;
521 insertModuleAccess (cstring fname, typeId t)
525 for (i = 0; i < gc.nmods; i++)
527 if (cstring_equal (gc.moduleaccess[i].file, fname))
529 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
534 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
538 context_exitLCLfile (void)
540 if (gc.kind != CX_LCLLIB)
543 fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION);
545 addModuleAccess (fileLib_removePath (lclname), gc.facct);
546 cstring_free (lclname);
551 gc.facct = typeIdSet_emptySet ();
555 context_dumpModuleAccess (FILE *fout)
559 for (i = 0; i < gc.nmods; i++)
561 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
563 fprintf (fout, "%s#%s@\n",
564 cstring_toCharsSafe (gc.moduleaccess[i].file),
565 cstring_toCharsSafe (td));
571 bool context_usingPosixLibrary ()
573 return (gc.library == FLG_POSIXLIB
574 || gc.library == FLG_POSIXSTRICTLIB
575 || gc.library == FLG_UNIXLIB
576 || gc.library == FLG_UNIXSTRICTLIB);
579 bool context_usingAnsiLibrary ()
581 return (gc.library != FLG_NOLIB);
584 flagcode context_getLibrary ()
589 void context_setLibrary (flagcode code)
594 /*@observer@*/ cstring context_selectedLibrary ()
599 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
601 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
602 case FLG_POSIXSTRICTLIB:
603 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
605 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
606 case FLG_UNIXSTRICTLIB:
607 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
609 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
616 context_loadModuleAccess (FILE *in)
618 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
620 char *name = mstring_create (MAX_NAME_LENGTH);
626 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
632 while (s != NULL && *s != ';' && *s != '\0')
636 while (*s != '#' && *s != '\0')
645 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
646 cstring_fromChars (s)));
652 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
653 typeIdSet_undump (&s));
655 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
656 llassert (s != lasts);
666 typeIdSet context_fileAccessTypes (void)
672 context_resetModeFlags (void)
676 if (flagcode_isModeFlag (code))
678 context_setFlag (code, FALSE, g_currentloc);
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)
707 DPRINTF (("******** Reset all flags"));
711 gc.flags[code] = FALSE;
713 if (flagcode_hasNumber (code))
717 /*@-loopswitchbreak@*/
721 val = DEFAULT_LIMIT; break;
723 val = DEFAULT_BUGSLIMIT; break;
725 val = DEFAULT_LINELEN; break;
726 case FLG_INDENTSPACES:
727 val = DEFAULT_INDENTSPACES; break;
728 case FLG_LOCINDENTSPACES:
729 val = DEFAULT_LOCINDENTSPACES; break;
730 case FLG_EXTERNALNAMELEN:
731 val = ISO99_EXTERNALNAMELEN; break;
732 case FLG_INTERNALNAMELEN:
733 val = ISO99_INTERNALNAMELEN; break;
734 case FLG_COMMENTCHAR:
735 val = (int) DEFAULT_COMMENTCHAR; break;
736 case FLG_CONTROLNESTDEPTH:
737 val = (int) ISO99_CONTROLNESTDEPTH; break;
738 case FLG_STRINGLITERALLEN:
739 val = (int) ISO99_STRINGLITERALLEN; break;
740 case FLG_INCLUDENEST:
741 val = (int) ISO99_INCLUDENEST; break;
742 case FLG_NUMSTRUCTFIELDS:
743 val = (int) ISO99_NUMSTRUCTFIELDS; break;
744 case FLG_NUMENUMMEMBERS:
745 val = (int) ISO99_NUMENUMMEMBERS; break;
750 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
752 /*@=loopswitchbreak@*/
754 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
755 context_setValue (code, val);
756 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
757 llassert (context_getValue (code) == val);
759 else if (flagcode_hasChar (code))
761 llassert (code == FLG_COMMENTCHAR);
762 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
764 else if (flagcode_hasString (code))
766 cstring val = cstring_undefined;
769 { /*@-loopswitchbreak@*/
772 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
774 if (cstring_isDefined (larchpath))
776 val = cstring_copy (larchpath);
780 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
785 case FLG_LCLIMPORTDIR:
787 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
791 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
793 char *env = osd_getEnvironmentVariable ("TMP");
797 env = osd_getEnvironmentVariable ("TEMP");
800 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
803 val = cstring_makeLiteral (DEFAULT_TMPDIR);
804 # endif /* !defined(OS2) && !defined(MSDOS) */
808 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
810 val = cstring_makeLiteral ("false"); break;
812 val = cstring_makeLiteral ("true"); break;
813 case FLG_MACROVARPREFIX:
814 val = cstring_makeLiteral ("m_"); break;
816 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
819 } /*@=loopswitchbreak@*/
821 context_setString (code, val);
825 ; /* nothing to set */
830 ** These flags are true by default.
833 /* eventually, move this into flags.def */
835 gc.flags[FLG_STREAMOVERWRITE] = TRUE;
836 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
837 gc.flags[FLG_MODIFIES] = TRUE;
838 gc.flags[FLG_NESTCOMMENT] = TRUE;
839 gc.flags[FLG_GLOBALS] = TRUE;
840 gc.flags[FLG_FULLINITBLOCK] = TRUE;
841 gc.flags[FLG_INITSIZE] = TRUE;
842 gc.flags[FLG_INITALLELEMENTS] = TRUE;
843 gc.flags[FLG_NULLINIT] = TRUE;
845 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
847 gc.flags[FLG_LIKELYBOOL] = TRUE;
848 gc.flags[FLG_ZEROPTR] = TRUE;
849 gc.flags[FLG_NUMLITERAL] = TRUE;
850 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
851 gc.flags[FLG_SKIPISOHEADERS] = TRUE;
852 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
853 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
854 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
855 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
856 gc.flags[FLG_CASTFCNPTR] = TRUE;
857 gc.flags[FLG_DOLCS] = TRUE;
858 gc.flags[FLG_USEVARARGS] = TRUE;
859 gc.flags[FLG_MAINTYPE] = TRUE;
860 gc.flags[FLG_SPECMACROS] = TRUE;
861 gc.flags[FLG_REDEF] = TRUE;
862 gc.flags[FLG_MACRONEXTLINE] = TRUE;
864 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
865 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
867 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
868 gc.flags[FLG_WARNUSE] = TRUE;
869 gc.flags[FLG_PREDASSIGN] = TRUE;
870 gc.flags[FLG_MODOBSERVER] = TRUE;
871 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
872 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
874 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
875 gc.flags[FLG_RETIMPONLY] = TRUE;
876 gc.flags[FLG_GLOBIMPONLY] = TRUE;
877 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
878 gc.flags[FLG_PREPROC] = TRUE;
879 gc.flags[FLG_NAMECHECKS] = TRUE;
880 gc.flags[FLG_FORMATCODE] = TRUE;
881 gc.flags[FLG_FORMATTYPE] = TRUE;
882 gc.flags[FLG_BADFLAG] = TRUE;
883 gc.flags[FLG_WARNFLAGS] = TRUE;
884 gc.flags[FLG_WARNRC] = TRUE;
885 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
886 gc.flags[FLG_WARNUNIXLIB] = FALSE;
887 gc.flags[FLG_WARNPOSIX] = TRUE;
888 gc.flags[FLG_SHOWCOL] = TRUE;
889 gc.flags[FLG_SHOWDEEPHISTORY] = FALSE; /* TRUE; */
890 gc.flags[FLG_SHOWFUNC] = TRUE;
891 gc.flags[FLG_SUPCOUNTS] = TRUE;
892 gc.flags[FLG_HINTS] = TRUE;
893 gc.flags[FLG_SYNTAX] = TRUE;
894 gc.flags[FLG_TYPE] = TRUE;
895 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
896 gc.flags[FLG_ABSTRACT] = TRUE;
897 gc.flags[FLG_NUMABSTRACT] = TRUE;
898 gc.flags[FLG_ITERBALANCE] = TRUE;
899 gc.flags[FLG_ITERYIELD] = TRUE;
900 gc.flags[FLG_DUPLICATECASES] = TRUE;
901 gc.flags[FLG_ALWAYSEXITS] = TRUE;
902 gc.flags[FLG_EMPTYRETURN] = TRUE;
903 gc.flags[FLG_MACRORETURN] = TRUE;
904 gc.flags[FLG_UNRECOG] = TRUE;
905 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
906 gc.flags[FLG_LINTCOMMENTS] = TRUE;
907 gc.flags[FLG_ACCESSCZECH] = TRUE;
908 gc.flags[FLG_ACCESSMODULE] = TRUE;
909 gc.flags[FLG_ACCESSFILE] = TRUE;
910 gc.flags[FLG_MACROVARPREFIX] = TRUE;
912 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
913 gc.flags[FLG_COMMENTERROR] = TRUE;
916 ** Changed for version 2.4.
919 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
925 /* commenting ou until some output issues are fixed */
926 gc.flags[FLG_ORCONSTRAINT] = TRUE;
928 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
931 gc.flags[FLG_WARNSYSFILES] = TRUE;
934 ** On by default for Win32, but not Unix
938 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
939 gc.flags[FLG_CASEINSENSITIVEFILENAMES] = TRUE;
944 ** C is way-lame, and you can initialize an array to a constant except where
945 ** it is declared. Hence, a macro is used to set the modeflags.
949 # define SETFLAGS() \
950 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
951 if (!flagcode_isModeFlag (modeflags[i])) \
952 { llbug (message ("not a mode flag: %s", \
953 flagcode_unparse (modeflags[i]))); } \
954 else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }}
956 static void context_setModeAux (cstring p_s, bool p_warn) ;
959 context_setMode (cstring s)
961 context_setModeAux (s, TRUE);
965 context_setModeNoWarn (cstring s)
967 context_setModeAux (s, FALSE);
971 context_setModeAux (cstring s, bool warn)
973 intSet setflags = intSet_new ();
977 if (flagcode_isModeFlag (code))
979 if (gc.setGlobally[code])
981 (void) intSet_insert (setflags, (int) code);
986 if (!intSet_isEmpty (setflags))
988 cstring rflags = cstring_undefined;
991 intSet_elements (setflags, el)
993 if (cstring_isUndefined (rflags))
995 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
999 rflags = message ("%q, %s", rflags,
1000 flagcode_unparse ((flagcode) el));
1004 if (num > 4 && intSet_size (setflags) > 6)
1006 rflags = message ("%q, (%d others) ...", rflags,
1007 intSet_size (setflags) - num);
1010 } end_intSet_elements ;
1014 voptgenerror (FLG_WARNFLAGS,
1015 message ("Setting mode %s after setting mode flags will "
1016 "override set values of flags: %s",
1021 cstring_free (rflags);
1024 intSet_free (setflags);
1026 context_resetModeFlags ();
1028 if (cstring_equalLit (s, "standard"))
1030 flagcode modeflags[] =
1032 FLG_ENUMINT, FLG_MACROMATCHNAME,
1033 FLG_STRINGLITNOROOM,
1034 FLG_STRINGLITNOROOMFINALNULL,
1035 FLG_MACROUNDEF, FLG_RELAXQUALS,
1036 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1037 FLG_CHECKSTRICTGLOBALIAS,
1038 FLG_CHECKEDGLOBALIAS,
1039 FLG_CHECKMODGLOBALIAS,
1040 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1041 FLG_UNSIGNEDCOMPARE,
1042 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1044 FLG_ABSTRACTCOMPARE,
1045 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1046 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1047 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1048 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1049 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1052 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1053 FLG_MACROSTMT, FLG_MACROPARENS,
1056 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1057 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1063 /* memchecks flags */
1065 FLG_NULLSTATE, FLG_NULLASSIGN,
1066 FLG_NULLPASS, FLG_NULLRET,
1069 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1072 /* memtrans flags */
1088 FLG_NUMABSTRACTCAST,
1091 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1094 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1095 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1098 FLG_STATETRANSFER, FLG_STATEMERGE,
1099 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1101 FLG_IMPCHECKEDSPECGLOBALS,
1102 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1103 FLG_IFEMPTY, FLG_REALCOMPARE,
1104 FLG_BOOLOPS, FLG_PTRNEGATE,
1106 FLG_SHIFTIMPLEMENTATION,
1107 FLG_BUFFEROVERFLOWHIGH,
1114 else if (cstring_equalLit (s, "weak"))
1116 flagcode modeflags[] =
1118 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE, FLG_LONGINT, FLG_SHORTINT,
1119 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1120 FLG_CHARINDEX, FLG_NUMABSTRACTINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1121 FLG_CHARUNSIGNEDCHAR,
1124 FLG_VARUNUSED, FLG_FUNCUNUSED,
1126 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1129 FLG_BUFFEROVERFLOWHIGH,
1130 FLG_RETSTACK, FLG_PTRNEGATE,
1131 FLG_STATETRANSFER, FLG_STATEMERGE,
1132 FLG_LONGUNSIGNEDINTEGRAL,
1133 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1137 FLG_BUFFEROVERFLOWHIGH,
1138 FLG_STRINGLITNOROOM,
1139 FLG_STRINGLITNOROOMFINALNULL,
1145 else if (cstring_equalLit (s, "checks"))
1147 flagcode modeflags[] =
1149 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1150 FLG_NUMABSTRACTCAST,
1151 FLG_ABSTRACTCOMPARE,
1152 FLG_STATETRANSFER, FLG_STATEMERGE,
1153 FLG_CHECKSTRICTGLOBALIAS,
1154 FLG_CHECKEDGLOBALIAS,
1155 FLG_CHECKMODGLOBALIAS,
1156 FLG_UNCHECKEDGLOBALIAS,
1158 FLG_STRINGLITNOROOM,
1159 FLG_STRINGLITNOROOMFINALNULL,
1160 FLG_STRINGLITSMALLER,
1161 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1162 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1163 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1164 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1165 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1166 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1167 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1168 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1169 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1170 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1171 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1172 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1173 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1174 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1175 FLG_NUMABSTRACTPRINT,
1182 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1186 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1188 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1189 FLG_EVALORDER, FLG_USEDEF,
1192 /* warn use flags */
1193 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1194 FLG_BUFFEROVERFLOWHIGH,
1196 /* memchecks flags */
1198 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1199 FLG_NULLPASS, FLG_NULLRET,
1202 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1204 /* memtrans flags */
1218 FLG_STATICINITTRANS,
1219 FLG_UNKNOWNINITTRANS,
1222 FLG_ONLYUNQGLOBALTRANS,
1223 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1226 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1227 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1230 FLG_NULLPOINTERARITH,
1231 FLG_SHADOW, FLG_DEPARRAYS,
1232 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1233 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1234 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1235 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1236 FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES,
1237 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1238 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1239 FLG_SHIFTIMPLEMENTATION,
1240 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1245 else if (cstring_equalLit (s, "strict"))
1247 flagcode modeflags[] =
1249 FLG_ABSTRACTCOMPARE,
1250 FLG_CHECKSTRICTGLOBALIAS,
1251 FLG_NUMABSTRACTCAST,
1252 FLG_CHECKEDGLOBALIAS,
1253 FLG_CHECKMODGLOBALIAS,
1254 FLG_UNCHECKEDGLOBALIAS,
1258 FLG_NUMABSTRACTPRINT,
1259 FLG_STRINGLITNOROOM,
1260 FLG_STRINGLITNOROOMFINALNULL,
1261 FLG_STRINGLITSMALLER,
1262 FLG_STATETRANSFER, FLG_STATEMERGE,
1263 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1264 FLG_ALLGLOBALS, FLG_IMPTYPE,
1265 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1266 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1267 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1268 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1271 FLG_ONLYUNQGLOBALTRANS,
1272 FLG_GLOBALSIMPMODIFIESNOTHING,
1273 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1274 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1275 FLG_USEALLGLOBS, FLG_RETALIAS,
1276 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1277 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1278 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1280 FLG_EXPORTITER, FLG_EXPORTCONST,
1281 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1282 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1284 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1286 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1287 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1288 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1289 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1290 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1291 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1292 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1293 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1295 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1298 FLG_MACROREDEF, FLG_MACROEMPTY,
1299 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1301 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1303 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1304 FLG_MODOBSERVERUNCON,
1309 /* warn use flags */
1310 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1311 FLG_BUFFEROVERFLOWHIGH,
1312 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1314 /* memchecks flags */
1315 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1316 FLG_NULLPASS, FLG_NULLRET,
1318 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1320 /* memory checking flags */
1321 FLG_BOUNDSREAD, FLG_BOUNDSWRITE,
1322 FLG_LIKELYBOUNDSREAD, FLG_LIKELYBOUNDSWRITE,
1325 /* memtrans flags */
1341 FLG_STATICINITTRANS,
1342 FLG_UNKNOWNINITTRANS,
1344 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1347 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1348 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1352 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1354 FLG_SHADOW, FLG_DEPARRAYS,
1355 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1356 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1357 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1358 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1359 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1360 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1361 FLG_IMPCHECKEDSTRICTSTATICS,
1362 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1363 FLG_IMPCHECKMODINTERNALS,
1364 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1365 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1366 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1367 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1368 FLG_CONTROLNESTDEPTH,
1369 FLG_FORBLOCK, FLG_WHILEBLOCK,
1370 FLG_FOREMPTY, FLG_WHILEEMPTY,
1371 FLG_IFEMPTY, FLG_IFBLOCK,
1373 FLG_REALCOMPARE, FLG_BOOLOPS,
1374 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1377 FLG_SHIFTIMPLEMENTATION,
1379 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1387 llcontbug (message ("context_setMode: bad mode: %s", s));
1392 context_isSpecialFile (cstring fname)
1394 cstring ext = fileLib_getExtension (fname);
1396 return (cstring_equalLit (ext, ".y")
1397 || cstring_equalLit (ext, ".l")
1398 || cstring_equalLit (fname, "lex.yy.c"));
1402 context_isSystemDir (cstring dir)
1404 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1405 cstring savedir = thisdir;
1406 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1408 if (cstring_isDefined (nextdir))
1410 /*@access cstring@*/
1411 *nextdir = '\0'; /* closes thisdir */
1413 /*@noaccess cstring@*/
1416 /* 2001-09-09: added thisdir[0] != '\0'
1417 ** herbert: don't compare with an empty name!
1418 ** should return false for empty directory path
1421 while (!cstring_isEmpty (thisdir))
1423 DPRINTF (("Test: %s / %s", dir, thisdir));
1425 if (osd_equalCanonicalPrefix (dir, thisdir))
1427 cstring_free (savedir);
1431 if (cstring_isDefined (nextdir))
1434 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1436 if (cstring_isDefined (nextdir))
1438 /*@access cstring@*/
1441 /*@noaccess cstring@*/
1450 DPRINTF (("Returns FALSE"));
1451 cstring_free (savedir);
1456 context_addFileAccessType (typeId t)
1460 if (context_inFunctionLike ())
1462 gc.acct = typeIdSet_insert (gc.acct, t);
1465 gc.facct = typeIdSet_insert (gc.facct, t);
1467 base = fileloc_getBase (g_currentloc);
1468 insertModuleAccess (base, t);
1469 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1470 typeIdSet_unparse (gc.acct)));
1474 context_removeFileAccessType (typeId t)
1476 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1477 || gc.kind == CX_UNKNOWNMACRO)
1479 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1482 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1483 gc.nacct = typeIdSet_insert (gc.nacct, t);
1486 void context_enterFunctionHeader (void)
1488 if (context_getFlag (FLG_GRAMMAR))
1490 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1493 if (gc.kind != CX_GLOBAL)
1495 llparseerror (cstring_makeLiteral
1496 ("Likely parse error. Function header outside global context."));
1500 llassert (gc.kind == CX_GLOBAL);
1501 DPRINTF (("Enter function header!"));
1502 gc.inFunctionHeader = TRUE;
1506 void context_exitFunctionHeader (void)
1508 if (context_getFlag (FLG_GRAMMAR))
1510 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1513 DPRINTF (("Exit function header!"));
1514 gc.inFunctionHeader = FALSE;
1517 bool context_inFunctionHeader (void)
1519 return (gc.inFunctionHeader);
1522 void context_enterFunctionDeclaration (uentry e)
1524 if (context_getFlag (FLG_GRAMMAR))
1526 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1529 DPRINTF (("Enter function decl"));
1530 llassert (gc.savekind == CX_ERROR);
1531 gc.savekind = gc.kind;
1532 gc.savecont = gc.cont;
1533 gc.kind = CX_FCNDECLARATION;
1537 void context_exitFunctionDeclaration (void)
1539 if (context_getFlag (FLG_GRAMMAR))
1541 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1544 DPRINTF (("Exit function decl"));
1545 llassert (gc.savekind != CX_ERROR);
1546 llassert (gc.kind == CX_FCNDECLARATION);
1547 gc.kind = gc.savekind;
1548 gc.cont = gc.savecont;
1550 gc.savekind = CX_ERROR;
1552 if (context_getFlag (FLG_GRAMMAR))
1554 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1558 bool context_inFunctionDeclaration (void)
1560 return (gc.kind == CX_FCNDECLARATION);
1565 context_enterMacro (/*@observer@*/ uentry e)
1567 context_enterFunction (e);
1568 gc.kind = CX_MACROFCN;
1572 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1574 llassert (uentry_isFunction (e));
1575 context_enterFunction (e);
1576 gc.kind = CX_UNKNOWNMACRO;
1579 void context_enterAndClause (exprNode e)
1582 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1583 pushClause (ANDCLAUSE);
1586 void context_enterOrClause (exprNode e)
1588 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1589 pushClause (ORCLAUSE);
1592 bool context_inDeepLoop (void)
1594 bool inLoop = FALSE;
1596 clauseStack_elements (gc.clauses, el)
1598 if (clause_isLoop (el))
1607 } end_clauseStack_elements;
1612 bool context_inDeepSwitch (void)
1614 bool inLoop = FALSE;
1616 clauseStack_elements (gc.clauses, el)
1618 if (clause_isSwitch (el))
1627 } end_clauseStack_elements;
1632 bool context_inDeepLoopSwitch (void)
1634 bool inLoop = FALSE;
1636 clauseStack_elements (gc.clauses, el)
1638 if (clause_isBreakable (el))
1647 } end_clauseStack_elements;
1652 clause context_breakClause (void)
1654 clauseStack_elements (gc.clauses, el)
1656 if (clause_isSwitch (el))
1660 else if (clause_isLoop (el))
1668 } end_clauseStack_elements;
1673 clause context_nextBreakClause (void)
1675 bool hasOne = FALSE;
1677 clauseStack_elements (gc.clauses, el)
1679 if (clause_isBreakable (el))
1690 } end_clauseStack_elements;
1695 bool context_inConditional (void)
1697 clauseStack_elements (gc.clauses, el)
1700 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1701 ** to distinguish if from ? for this
1704 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1708 } end_clauseStack_elements;
1713 void context_exitAndClause (exprNode pred, exprNode tbranch)
1715 context_setJustPopped ();
1717 llassert (gc.inclause == ANDCLAUSE);
1719 usymtab_popAndBranch (pred, tbranch);
1720 clauseStack_pop (gc.clauses);
1721 gc.inclause = topClause (gc.clauses);
1724 void context_exitOrClause (exprNode pred, exprNode tbranch)
1726 context_setJustPopped ();
1728 llassert (gc.inclause == ORCLAUSE);
1730 usymtab_popOrBranch (pred, tbranch);
1731 clauseStack_pop (gc.clauses);
1732 gc.inclause = topClause (gc.clauses);
1735 static void context_enterCondClauseAux (clause cl)
1741 static void context_enterTrueAux (exprNode e, clause cl)
1744 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1748 void context_enterIterClause (void)
1750 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1753 void context_enterDoWhileClause (void)
1755 pushClause (DOWHILECLAUSE);
1758 void context_enterWhileClause (exprNode e)
1760 context_enterTrueAux (e, WHILECLAUSE);
1763 void context_enterForClause (exprNode e)
1765 context_enterTrueAux (e, FORCLAUSE);
1768 void context_enterTrueClause (exprNode e)
1770 context_enterTrueAux (e, TRUECLAUSE);
1773 void context_enterSwitch (exprNode e)
1775 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1776 usymtab_switchBranch (e);
1777 context_enterCondClauseAux (SWITCHCLAUSE);
1780 void context_exitSwitch (exprNode e, bool allpaths)
1782 usymtab_exitSwitch (e, allpaths);
1784 while (clause_isCase (clauseStack_top (gc.clauses)))
1786 clauseStack_pop (gc.clauses);
1789 context_exitClauseSimp ();
1792 void context_enterCaseClause (exprNode e)
1794 bool branch = FALSE;
1796 DPRINTF (("Enter case clause!"));
1798 branch = usymtab_newCase (exprNode_undefined, e);
1802 context_enterCondClauseAux (CASECLAUSE);
1806 static void context_enterFalseClauseAux (exprNode e, clause cl)
1809 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1811 clauseStack_switchTop (gc.clauses, cl);
1814 void context_enterFalseClause (exprNode e)
1817 context_enterFalseClauseAux (e, FALSECLAUSE);
1821 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1823 gc.kind = CX_MACROCONST;
1825 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1827 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1831 usymtab_enterScope ();
1832 sRef_enterFunctionScope ();
1834 gc.globs = globSet_undefined;
1835 globSet_clear (gc.globs_used);
1836 gc.mods = sRefSet_undefined;
1839 uentry context_getHeader (void)
1841 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1843 llfatalbug (message ("context_getHeader: bad call: %q",
1844 context_unparse ()));
1847 return (gc.cont.fcn);
1851 context_setFunctionDefined (fileloc loc)
1855 case CX_UNKNOWNMACRO:
1858 uentry_setFunctionDefined (gc.cont.fcn, loc);
1861 /* (not a bug because of parse errors) */
1867 context_enterFunction (/*@exposed@*/ uentry e)
1869 gc.kind = CX_FUNCTION;
1872 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1874 if (uentry_hasAccessType (e))
1876 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1884 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1885 typeIdSet_unparse (gc.acct)));
1887 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1889 gc.globs = uentry_getGlobs (e);
1890 globSet_clear (gc.globs_used);
1891 gc.mods = uentry_getMods (e);
1893 usymtab_enterFunctionScope (e);
1894 sRef_enterFunctionScope ();
1897 bool context_inOldStyleScope(void)
1899 return (gc.kind == CX_OLDSTYLESCOPE);
1903 context_enterOldStyleScope (void)
1905 gc.kind = CX_OLDSTYLESCOPE;
1906 DPRINTF (("Enter old style scope!"));
1907 usymtab_enterFunctionScope (uentry_undefined);
1911 context_completeOldStyleFunction (uentry e)
1913 llassert (gc.kind == CX_OLDSTYLESCOPE);
1915 gc.kind = CX_FUNCTION;
1918 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1920 if (uentry_hasAccessType (e))
1922 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1930 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1931 typeIdSet_unparse (gc.acct)));
1933 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1935 if (!globSet_isEmpty (uentry_getGlobs (e)))
1937 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1938 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1941 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1943 gc.globs = uentry_getGlobs (e);
1944 globSet_clear (gc.globs_used);
1946 gc.mods = uentry_getMods (e);
1948 if (!sRefSet_isEmpty (gc.mods))
1950 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1951 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1954 sRef_enterFunctionScope ();
1957 static bool context_checkStrictGlobals (void)
1959 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1962 static bool context_hasGlobs (void)
1964 if (context_inFunctionLike ())
1966 return (uentry_hasGlobs (gc.cont.fcn));
1974 static bool context_checkCheckedGlobals (void)
1976 return (context_getFlag (FLG_GLOBALS)
1977 && (context_getFlag (FLG_GLOBUNSPEC)
1978 || context_hasGlobs ()));
1981 static bool context_checkUnknownGlobals (void)
1983 /* should be uentry_hasGlobs ? */
1985 return (context_getFlag (FLG_ALLGLOBALS)
1986 && (context_getFlag (FLG_GLOBUNSPEC)
1987 || context_hasGlobs ()));
1990 static bool context_checkUncheckedGlobals (void)
1996 context_checkExport (uentry e)
1998 if (!gc.anyExports) return FALSE;
2000 if (uentry_isFunction (e)
2001 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
2003 return context_maybeSet (FLG_EXPORTFCN);
2005 else if (uentry_isExpandedMacro (e))
2007 return context_maybeSet (FLG_EXPORTMACRO);
2009 else if (uentry_isVariable (e))
2011 return context_maybeSet (FLG_EXPORTVAR);
2013 else if (uentry_isEitherConstant (e))
2015 return context_maybeSet (FLG_EXPORTCONST);
2017 else if (uentry_isIter (e) || uentry_isEndIter (e))
2019 return context_maybeSet (FLG_EXPORTITER);
2021 else if (uentry_isDatatype (e))
2023 return context_maybeSet (FLG_EXPORTTYPE);
2032 context_checkGlobUse (uentry glob)
2035 if (uentry_isCheckedStrict (glob))
2037 return context_checkStrictGlobals ();
2039 else if (uentry_isChecked (glob))
2041 return context_checkCheckedGlobals ();
2043 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2045 return context_checkUnknownGlobals ();
2049 llassert (uentry_isUnchecked (glob));
2051 return context_checkUncheckedGlobals ();
2056 context_checkAliasGlob (uentry glob)
2058 if (uentry_isCheckedStrict (glob))
2060 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2062 else if (uentry_isChecked (glob))
2064 return gc.flags[FLG_CHECKEDGLOBALIAS];
2066 else if (uentry_isCheckMod (glob))
2068 return gc.flags[FLG_CHECKMODGLOBALIAS];
2072 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2074 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2078 bool context_checkInternalUse (void)
2080 if (context_hasGlobs ())
2082 return (gc.flags[FLG_INTERNALGLOBS]);
2086 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2091 context_checkGlobMod (sRef el)
2093 uentry ue = sRef_getUentry (el);
2095 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2097 if (uentry_isCheckedModify (ue)
2098 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2100 if (context_hasMods ())
2102 return (gc.flags[FLG_MODGLOBS]);
2106 if (uentry_isCheckedStrict (ue))
2108 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2112 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2118 if (context_hasMods ())
2120 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2130 context_usedGlobal (/*@exposed@*/ sRef el)
2132 if (!globSet_member (gc.globs_used, el))
2135 ** The first time a global is used in a function, we need
2136 ** to clear the derived sRefs, since they were set for the
2137 ** previous function.
2140 sRef_clearDerived (el);
2141 gc.globs_used = globSet_insert (gc.globs_used, el);
2145 /*@observer@*/ sRefSet
2146 context_modList (void)
2152 context_globAccess (sRef s)
2154 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2155 return (globSet_member (gc.globs, s));
2159 context_hasAccess (typeId t)
2161 if (context_inFunctionLike ())
2163 DPRINTF (("Access %d / %s",
2164 t, typeIdSet_unparse (gc.acct)));
2165 return (typeIdSet_member (gc.acct, t));
2169 return (context_hasFileAccess (t));
2174 context_hasFileAccess (typeId t)
2176 return (typeIdSet_member (gc.facct, t));
2180 context_unparseAccess (void)
2182 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2183 typeIdSet_unparse (gc.facct)));
2187 context_unparseClauses (void)
2189 return (clauseStack_unparse (gc.clauses));
2193 context_couldHaveAccess (typeId t)
2195 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2197 return (typeIdSet_member (gc.acct, t));
2201 return (typeIdSet_member (gc.facct, t));
2206 context_getRetType (void)
2208 ctype f = ctype_undefined;
2210 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2212 f = uentry_getType (gc.cont.fcn);
2214 else if (gc.kind == CX_UNKNOWNMACRO)
2216 return ctype_unknown;
2220 llcontbuglit ("context_getRetType: not in a function context");
2221 return ctype_unknown;
2224 if (!ctype_isFunction (f))
2226 if (ctype_isKnown (f))
2228 llbuglit ("context_getRetType: not a function");
2231 return ctype_unknown;
2233 return (ctype_getReturnType (f));
2237 context_hasMods (void)
2239 if (context_inFunctionLike ())
2241 return (uentry_hasMods (gc.cont.fcn));
2250 context_exitAllClauses (void)
2252 while (!clauseStack_isEmpty (gc.clauses))
2254 clause el = clauseStack_top (gc.clauses);
2257 if (clause_isNone (el))
2259 usymtab_quietExitScope (g_currentloc);
2260 clauseStack_pop (gc.clauses);
2264 context_exitClausePlain ();
2268 clauseStack_clear (gc.clauses);
2269 gc.inclause = NOCLAUSE;
2273 context_exitAllClausesQuiet (void)
2275 while (!clauseStack_isEmpty (gc.clauses))
2277 clause el = clauseStack_top (gc.clauses);
2280 usymtab_quietExitScope (g_currentloc);
2281 clauseStack_pop (gc.clauses);
2284 clauseStack_clear (gc.clauses);
2285 gc.inclause = NOCLAUSE;
2289 void context_exitClauseSimp (void)
2292 context_setJustPopped ();
2293 clauseStack_pop (gc.clauses);
2294 gc.inclause = topClause (gc.clauses);
2298 void context_exitCaseClause (void)
2300 context_setJustPopped ();
2301 usymtab_popCaseBranch ();
2302 clauseStack_pop (gc.clauses);
2303 gc.inclause = topClause (gc.clauses);
2307 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2309 context_setJustPopped ();
2310 usymtab_popTrueBranch (pred, tbranch, gc.inclause); /* evans 2003-02-02?: was makeAlt */
2311 clauseStack_pop (gc.clauses);
2312 gc.inclause = topClause (gc.clauses);
2315 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2317 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2319 if (gc.inclause != TRUECLAUSE)
2321 llparseerror (cstring_makeLiteral
2322 ("Likely parse error. Conditional clauses are inconsistent."));
2326 context_setJustPopped ();
2327 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2328 clauseStack_pop (gc.clauses);
2329 gc.inclause = topClause (gc.clauses);
2332 void context_exitIterClause (exprNode body)
2334 llassert (gc.inclause == ITERCLAUSE);
2336 context_setJustPopped ();
2338 if (context_getFlag (FLG_ITERLOOPEXEC))
2340 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2344 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2347 clauseStack_pop (gc.clauses);
2348 gc.inclause = topClause (gc.clauses);
2351 static void context_popCase (void) {
2353 ** If we are exiting an outer clause, sometimes still in a switch case.
2367 DPRINTF (("Popping case clause: %s",
2368 clauseStack_unparse (gc.clauses)));
2370 if (gc.inclause == CASECLAUSE) {
2371 context_exitCaseClause ();
2375 void context_exitWhileClause (exprNode pred, exprNode body)
2377 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2381 if (gc.inclause != WHILECLAUSE) {
2382 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2383 clauseStack_unparse (gc.clauses)));
2386 llassert (gc.inclause == WHILECLAUSE);
2388 context_setJustPopped ();
2392 ** predicate must be false after while loop (unless there are breaks)
2395 if (context_getFlag (FLG_WHILELOOPEXEC))
2397 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2401 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2405 usymtab_addGuards (invGuards);
2406 guardSet_free (invGuards);
2408 clauseStack_pop (gc.clauses);
2409 gc.inclause = topClause (gc.clauses);
2412 void context_exitDoWhileClause (exprNode pred)
2414 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2416 if (gc.inclause == CASECLAUSE) {
2417 /* handle Duff's device */
2418 clauseStack_pop (gc.clauses);
2419 gc.inclause = topClause (gc.clauses);
2422 llassert (gc.inclause == DOWHILECLAUSE);
2424 context_setJustPopped ();
2427 usymtab_addGuards (invGuards);
2428 guardSet_free (invGuards);
2430 clauseStack_pop (gc.clauses);
2431 gc.inclause = topClause (gc.clauses);
2434 void context_exitForClause (exprNode forPred, exprNode body)
2436 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2438 llassert (gc.inclause == FORCLAUSE);
2439 context_setJustPopped ();
2441 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2444 ** Predicate must be false after for loop (unless there are breaks)
2447 if (context_getFlag (FLG_FORLOOPEXEC))
2449 DPRINTF (("Here: for loop exec"));
2450 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2454 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2455 && exprNode_loopMustExec (forPred))
2457 DPRINTF (("Here: loop must exec"));
2458 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2462 DPRINTF (("Pop true branch:"));
2463 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2467 usymtab_addGuards (invGuards);
2468 guardSet_free (invGuards);
2469 clauseStack_pop (gc.clauses);
2470 gc.inclause = topClause (gc.clauses);
2473 static void context_exitClausePlain (void)
2475 llassert (gc.inclause != NOCLAUSE);
2477 if (gc.inclause == FALSECLAUSE)
2479 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2483 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2487 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2489 context_setJustPopped ();
2491 if (gc.inclause == FALSECLAUSE)
2493 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2495 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2497 clauseStack_pop (gc.clauses);
2498 gc.inclause = topClause (gc.clauses);
2502 context_exitTrueClause (pred, tbranch);
2507 context_returnFunction (void)
2509 usymtab_checkFinalScope (TRUE);
2513 context_exitFunction (void)
2515 DPRINTF (("Exit function: %s", context_unparse ()));
2517 if (!context_inFunction () && !context_inMacroConstant ()
2518 && !context_inUnknownMacro ()
2519 && !context_inIterDef () && !context_inIterEnd ())
2522 ** not a bug because of parse errors
2529 if (context_inMacro () && usymtab_inFunctionScope ())
2531 usymtab_exitScope (exprNode_undefined);
2534 if (uentry_hasGlobs (gc.cont.fcn))
2536 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2540 if (uentry_hasMods (gc.cont.fcn))
2542 if (context_getFlag (FLG_MUSTMOD))
2544 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2548 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2551 ** clear file static modifies
2554 /* do this first to get unused error messages */
2556 usymtab_exitScope (exprNode_undefined);
2557 sRef_exitFunctionScope ();
2559 gc.showfunction = FALSE;
2560 gc.kind = CX_GLOBAL;
2561 gc.cont.glob = TRUE;
2563 gc.globs = globSet_new ();
2564 globSet_clear (gc.globs_used);
2565 gc.mods = sRefSet_new ();
2568 llassert (clauseStack_isEmpty (gc.clauses));
2569 llassert (gc.inclause == NOCLAUSE);
2570 DPRINTF (("After exit function: %s", context_unparse ()));
2574 context_quietExitFunction (void)
2576 while (gc.kind == CX_INNER)
2578 context_exitInnerPlain ();
2581 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2582 && !context_inIterDef () && !context_inIterEnd ())
2587 usymtab_quietExitScope (g_currentloc);
2589 gc.showfunction = FALSE;
2590 gc.kind = CX_GLOBAL;
2591 gc.cont.glob = TRUE;
2593 gc.globs = globSet_new ();
2594 globSet_clear (gc.globs_used);
2595 gc.mods = sRefSet_new ();
2597 sRef_exitFunctionScope ();
2601 /*@observer@*/ uentryList
2602 context_getParams (void)
2604 if (context_inFunctionLike ())
2606 return (uentry_getParams (gc.cont.fcn));
2610 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2611 return uentryList_undefined;
2615 /*@observer@*/ globSet
2616 context_getUsedGlobs (void)
2618 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2619 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2621 return (gc.globs_used);
2625 context_moduleName ()
2627 return (fileloc_getBase (g_currentloc));
2630 /*@observer@*/ globSet
2631 context_getGlobs (void)
2633 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2634 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2640 context_addBoolAccess (void)
2642 cstring bname = context_getString (FLG_BOOLTYPE);
2643 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2645 addModuleAccess (cstring_copy (bname), boolt);
2647 /* for sys/types (perhaps, this is bogus!) */
2648 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2653 context_canAccessBool (void)
2660 static typeId boolType = typeId_invalid;
2662 if (typeId_isInvalid (boolType))
2664 boolType = usymtab_getTypeId (context_getBoolName ());
2667 if (typeId_isInvalid (boolType)) {
2670 return (typeIdSet_member (gc.acct, boolType));
2675 /* evs 2000-07-25: old version - replaced */
2678 context_boolImplementationType () {
2679 /* For now, this is bogus! */
2684 context_canAccessBool (void)
2686 static typeId boolType = typeId_invalid;
2688 if (typeId_isInvalid (boolType))
2690 boolType = usymtab_getTypeId (context_getBoolName ());
2693 if (!typeId_isInvalid (boolType))
2695 return context_hasAccess (boolType);
2706 context_setMessageAnnote (/*@only@*/ cstring s)
2708 llassert (cstring_isUndefined (gc.msgAnnote));
2713 context_hasMessageAnnote (void)
2715 return (cstring_isDefined (gc.msgAnnote));
2719 context_clearMessageAnnote (void)
2721 if (cstring_isDefined (gc.msgAnnote))
2723 cstring_free (gc.msgAnnote);
2724 gc.msgAnnote = cstring_undefined;
2729 context_getMessageAnnote (void)
2731 cstring st = gc.msgAnnote;
2733 gc.msgAnnote = cstring_undefined;
2738 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2740 llassert (sRef_isInvalid (gc.aliasAnnote));
2741 llassert (!sRef_sameName (s, t));
2743 gc.aliasAnnoteAls = t;
2747 context_hasAliasAnnote (void)
2749 return (sRef_isValid (gc.aliasAnnote));
2753 context_clearAliasAnnote (void)
2755 gc.aliasAnnote = sRef_undefined;
2759 context_getAliasAnnote (void)
2761 sRef ret = gc.aliasAnnote;
2762 sRef als = gc.aliasAnnoteAls;
2764 llassert (sRef_isValid (ret) && sRef_isValid (als));
2766 gc.aliasAnnote = sRef_undefined;
2767 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2771 context_recordFileModifies (sRefSet mods)
2773 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2777 context_recordFileGlobals (globSet mods)
2779 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2780 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2784 context_setCommentMarkerChar (char c)
2786 llassert (c != '\0');
2788 context_setValue (FLG_COMMENTCHAR, (int) c);
2792 context_getCommentMarkerChar (void)
2794 return ((char) context_getValue (FLG_COMMENTCHAR));
2798 context_setValue (flagcode flag, int val)
2800 int index = flagcode_valueIndex (flag);
2802 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2810 llerror_flagWarning (message ("Value for %s must be a positive "
2811 "number (given %d)",
2812 flagcode_unparse (flag), val));
2815 if (flag == FLG_LINELEN && val < MINLINELEN)
2817 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2818 flagcode_unparse (flag),
2824 case FLG_INCLUDENEST:
2825 case FLG_CONTROLNESTDEPTH:
2826 case FLG_STRINGLITERALLEN:
2827 case FLG_NUMSTRUCTFIELDS:
2828 case FLG_NUMENUMMEMBERS:
2829 case FLG_INDENTSPACES:
2832 llerror_flagWarning (message ("Value for %s must be a non-negative "
2833 "number (given %d)",
2834 flagcode_unparse (flag), val));
2843 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2844 gc.values[index] = val;
2848 context_setValueAndFlag (flagcode flag, int val)
2850 gc.flags[flag] = TRUE;
2851 context_setValue (flag, val);
2855 context_getValue (flagcode flag)
2857 int index = flagcode_valueIndex (flag);
2859 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2860 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2861 return (gc.values[index]);
2865 context_getCounter (flagcode flag)
2867 int index = flagcode_valueIndex (flag);
2869 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2870 return (gc.counters[index]);
2874 context_incCounter (flagcode flag)
2876 int index = flagcode_valueIndex (flag);
2878 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2880 gc.counters[index]++;
2884 context_decCounter (flagcode flag)
2886 int index = flagcode_valueIndex (flag);
2888 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2889 gc.counters[index]--;
2892 bool context_showFunction (void)
2894 return (gc.showfunction);
2898 context_setString (flagcode flag, cstring val)
2900 int index = flagcode_stringIndex (flag);
2902 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2904 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2908 case FLG_MESSAGESTREAM:
2909 case FLG_WARNINGSTREAM:
2910 case FLG_ERRORSTREAM:
2912 if (cstring_isDefined (val))
2916 if (osd_fileExists (val))
2918 if (context_getFlag (FLG_STREAMOVERWRITE))
2920 llfatalerror (message
2921 ("Output stream file %s would overwrite existing file. "
2922 "Use -streamoverwrite if you want to allow this.",
2927 fstream = fopen (cstring_toCharsSafe (val), "w");
2929 if (fstream == NULL)
2931 llfatalerror (message ("Unable to open output stream file %s for writing",
2936 ** This ensures fstream will be closed on exit.
2939 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2943 case FLG_MESSAGESTREAM:
2944 g_messagestream = fstream;
2945 /*@innerbreak@*/ break;
2946 case FLG_WARNINGSTREAM:
2947 g_warningstream = fstream;
2948 /*@innerbreak@*/ break;
2949 case FLG_ERRORSTREAM:
2950 g_errorstream = fstream;
2951 /*@innerbreak@*/ break;
2954 /*@-statetransfer@*/
2955 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2958 case FLG_SYSTEMDIRS:
2960 llassert (cstring_isDefined (val));
2962 if (cstring_firstChar (val) == '\"')
2965 cstring tval = cstring_copy (cstring_suffix (val, 1));
2967 if (cstring_lastChar (tval) != '\"')
2969 int n = size_toInt (cstring_length (tval) - 1);
2971 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2976 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2979 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2983 cstring otval = tval;
2984 tval = cstring_prefix (tval, size_fromInt (n));
2985 cstring_free (otval);
2989 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2990 DPRINTF (("val = %s", val));
2991 cstring_free (tval);
2992 cstring_free (oval);
2999 llassert (cstring_isDefined (val));
3001 if (cstring_length (val) == 0)
3004 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
3006 else if (cstring_lastChar (val) != CONNECTCHAR)
3008 val = cstring_appendChar (val, CONNECTCHAR);
3018 ; /* Okay not handle everything in this switch */
3021 } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */
3024 if (cstring_length (val) >= 1
3025 && cstring_firstChar (val) == '\"')
3027 llerror_flagWarning (message
3028 ("Setting %s to string beginning with \". You probably "
3029 "don't meant to have the \"'s.",
3030 flagcode_unparse (flag)));
3033 gc.strings[index] = val;
3036 static /*@exposed@*/ cstring
3037 context_exposeString (flagcode flag)
3039 int index = flagcode_stringIndex (flag);
3041 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3042 return (gc.strings[index]);
3046 context_getString (flagcode flag)
3048 return (context_exposeString (flag));
3052 context_resetErrors (void)
3057 void context_initMod (void)
3058 /*@globals undef gc; @*/
3060 gc.kind = CX_GLOBAL;
3062 gc.savekind = CX_ERROR;
3063 gc.savecont.glob = FALSE;
3065 gc.instandardlib = FALSE;
3068 gc.linesprocessed = 0;
3069 gc.speclinesprocessed = 0;
3070 gc.insuppressregion = FALSE;
3071 gc.macroMissingParams = FALSE;
3072 gc.preprocessing = FALSE;
3073 gc.incommandline = FALSE;
3074 gc.mc = macrocache_create ();
3076 gc.maxmods = DEFAULTMAXMODS;
3077 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3079 gc.library = FLG_ANSILIB;
3081 gc.locstack = filelocStack_new ();
3082 gc.modrecs = sRefSetList_undefined;
3083 gc.anyExports = FALSE;
3085 gc.ftab = fileTable_create ();
3086 gc.msgLog = messageLog_new ();
3087 gc.inimport = FALSE;
3088 gc.inDerivedFile = FALSE;
3089 gc.inheader = FALSE;
3090 gc.markers = flagMarkerList_new ();
3091 gc.cont.glob = TRUE;
3092 gc.showfunction = FALSE;
3093 gc.msgAnnote = cstring_undefined;
3094 gc.aliasAnnote = sRef_undefined;
3095 gc.aliasAnnoteAls = sRef_undefined;
3096 gc.boolType = ctype_bool;
3097 gc.mods = sRefSet_new ();
3099 gc.saveloc = fileloc_undefined;
3101 gc.inmacrocache = FALSE;
3102 gc.inclause = NOCLAUSE;
3103 gc.clauses = clauseStack_new ();
3104 gc.globs = globSet_new ();
3105 gc.nacct = typeIdSet_emptySet ();
3106 gc.acct = typeIdSet_emptySet ();
3107 gc.facct = typeIdSet_emptySet ();
3108 gc.savedFlags = FALSE;
3109 gc.pushloc = fileloc_undefined;
3110 gc.protectVars = FALSE;
3111 gc.justpopped = FALSE;
3112 gc.isNullGuarded = NO;
3113 gc.globs_used = globSet_undefined;
3117 gc.setGlobally[code] = FALSE;
3118 gc.setLocally[code] = FALSE;
3123 context_resetAllFlags ();
3125 assertSet (gc.flags); /* Can't use global in defines */
3126 assertSet (gc.saveflags);
3127 assertSet (gc.values);
3128 assertSet (gc.strings);
3130 conext_resetAllCounters ();
3131 assertSet (gc.counters);
3133 context_setMode (DEFAULT_MODE);
3135 gc.stateTable = metaStateTable_create ();
3136 gc.annotTable = annotationTable_create ();
3138 gc.inFunctionHeader = FALSE;
3140 DPRINTF (("Annotations: \n%s",
3141 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3142 DPRINTF (("State: \n%s",
3143 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3148 context_typeofZero (void)
3150 ctype ct = ctype_int;
3152 if (context_getFlag (FLG_ZEROPTR))
3154 ct = ctype_makeConj (ct, ctype_voidPointer);
3157 if (context_getFlag (FLG_ZEROBOOL)) {
3158 ct = ctype_makeConj (ct, ctype_bool);
3165 context_typeofOne (void)
3167 ctype ct = ctype_int;
3169 /* 1 is on longer a bool (was before 2.4)
3170 if (!context_getFlag (FLG_ABSTRACTBOOL))
3172 ct = ctype_makeConj (ct, ctype_bool);
3180 context_unparse (void)
3187 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3190 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3193 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3196 s = message ("Inner Context [%d] : %q",
3198 fileloc_unparse (g_currentloc));
3201 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3202 uentry_unparse (gc.cont.fcn),
3203 fileloc_unparse (g_currentloc),
3204 typeIdSet_unparse (gc.acct),
3205 sRefSet_unparse (gc.mods));
3208 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3210 case CX_UNKNOWNMACRO:
3211 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3214 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3217 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3220 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3222 case CX_FCNDECLARATION:
3223 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3226 s = message ("Un-unparseable context: %d", (int) gc.kind);
3230 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3235 context_currentFunctionType (void)
3237 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3239 return (uentry_getType (gc.cont.fcn));
3241 else if (gc.kind == CX_INNER)
3243 llcontbuglit ("context_currentFunctionType: inner context");
3244 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3245 return (context_currentFunctionType ());
3249 llcontbuglit ("context_currentFunctionType: not in function");
3250 return (ctype_undefined);
3255 context_enterInnerContext (void)
3257 if (context_getFlag (FLG_GRAMMAR))
3259 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3262 if (gc.kind == CX_GLOBAL)
3267 else if (gc.kind == CX_INNER)
3276 usymtab_enterScope ();
3277 pushClause (NOCLAUSE);
3281 context_exitInnerPlain (void) /*@modifies gc;@*/
3283 context_exitInner (exprNode_undefined);
3287 context_exitInner (exprNode exp)
3289 if (context_getFlag (FLG_GRAMMAR))
3291 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3294 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3295 ("inclause = %s", clause_nameTaken (gc.inclause)));
3297 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3298 gc.inclause = topClause (gc.clauses);
3300 if (gc.kind == CX_INNER)
3302 if (--gc.cont.cdepth == 0)
3304 gc.kind = CX_GLOBAL;
3305 gc.cont.glob = TRUE;
3310 if (gc.kind == CX_GLOBAL)
3312 llcontbuglit ("Attempt to exit global context");
3317 usymtab_exitScope (exp);
3322 context_enterStructInnerContext (void)
3324 if (context_getFlag (FLG_GRAMMAR))
3326 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3329 if (gc.kind == CX_GLOBAL)
3334 else if (gc.kind == CX_INNER)
3343 usymtab_enterScope ();
3345 if (context_getFlag (FLG_GRAMMAR))
3347 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3352 context_exitStructInnerContext (void)
3354 if (context_getFlag (FLG_GRAMMAR))
3356 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3359 if (gc.kind == CX_INNER)
3361 if (gc.cont.cdepth <= 0)
3363 llcontbuglit ("Attempt to exit inner context with no depth");
3364 gc.kind = CX_GLOBAL;
3365 gc.cont.glob = TRUE;
3371 if (gc.cont.cdepth == 0)
3373 gc.kind = CX_GLOBAL;
3374 gc.cont.glob = TRUE;
3380 if (gc.kind == CX_GLOBAL)
3382 llcontbuglit ("Attempt to exit global context");
3387 usymtab_exitScope (exprNode_undefined);
3389 if (context_getFlag (FLG_GRAMMAR))
3391 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3396 context_exitInnerSafe (void)
3398 if (context_getFlag (FLG_GRAMMAR))
3400 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3403 if (gc.kind == CX_INNER)
3405 if (--gc.cont.cdepth <= 0)
3410 else if (gc.kind == CX_GLOBAL)
3412 llcontbuglit ("Attempt to exit global context");
3417 if (usymtab_inDeepScope ())
3419 usymtab_exitScope (exprNode_undefined);
3425 void setModuleAccess (void)
3427 gc.facct = typeIdSet_emptySet ();
3429 if (fileId_isValid (currentFile ()))
3431 cstring baseName = fileloc_getBase (g_currentloc);
3433 if (context_getFlag (FLG_ACCESSFILE))
3435 if (usymtab_existsType (baseName))
3437 gc.facct = typeIdSet_insert (gc.facct,
3438 usymtab_getTypeId (baseName));
3446 if (context_getFlag (FLG_ACCESSMODULE))
3449 bool hasaccess = FALSE;
3451 for (i = 0; i < gc.nmods; i++)
3453 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3455 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3464 gc.inheader = fileId_isHeader (currentFile ());
3468 llcontbuglit ("Current file not defined\n");
3469 gc.facct = typeIdSet_emptySet ();
3471 gc.inheader = FALSE;
3474 /* 17 Jan 1995: forgot to clear nacct */
3476 gc.nacct = typeIdSet_emptySet ();
3480 context_enterFileAux (void)
3486 context_enterFile (void)
3488 context_enterFileAux ();
3489 usymtab_enterFile ();
3493 context_enterMacroFile (void)
3495 context_enterFileAux ();
3499 context_inFunction (void)
3501 kcontext ck = gc.kind;
3503 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3507 context_inFunctionLike (void)
3509 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3510 || gc.kind == CX_FCNDECLARATION
3511 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3515 context_inRealFunction (void)
3517 kcontext ck = gc.kind;
3519 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3523 context_processAllMacros (void)
3525 usymtab_enterFile ();
3527 gc.inmacrocache = TRUE;
3528 macrocache_processUndefinedElements (gc.mc);
3530 usymtab_exitFile ();
3532 gc.inmacrocache = FALSE;
3533 macrocache_finalize ();
3537 ** this happens once at the end of each C file
3539 ** check each Macro that was defined in current file.c or current file.h
3544 context_processMacros (void)
3546 if (fileId_isValid (currentFile ()))
3549 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3551 gc.inmacrocache = TRUE;
3553 DPRINTF (("Processing macros: %s", cbase));
3554 lastfl = macrocache_processFileElements (gc.mc, cbase);
3555 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3557 cstring_free (cbase);
3559 if (fileloc_isDefined (lastfl))
3561 g_currentloc = fileloc_update (g_currentloc, lastfl);
3565 gc.inmacrocache = FALSE;
3570 context_processingMacros (void)
3572 return (gc.inmacrocache);
3576 context_exitCFile (void)
3578 if (gc.kind != CX_GLOBAL)
3581 (cstring_makeLiteral ("File ended outside global scope"));
3584 if (gc.insuppressregion)
3586 /* gack...don't reverse the order of these lines! ;-> */
3587 gc.insuppressregion = FALSE;
3588 llerrorlit (FLG_SYNTAX,
3589 "File ended in ignore errors region, "
3590 "possible missing /*@end*/");
3593 /* fix up parse errors */
3595 while (!usymtab_inFileScope ())
3597 usymtab_quietExitScope (g_currentloc);
3601 ** Clear the file-specific modifies information.
3604 sRefSetList_elements (gc.modrecs, mods)
3606 sRefSet_clearStatics (mods);
3607 } end_sRefSetList_elements ;
3609 sRefSetList_clear (gc.modrecs);
3611 context_processMacros ();
3614 usymtab_exitFile ();
3616 gc.inDerivedFile = FALSE;
3617 filelocStack_clear (gc.locstack);
3619 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3621 gc.cont.glob = TRUE;
3625 context_restoreFlagSettings ();
3626 gc.savedFlags = FALSE;
3630 DPRINTF (("After exiting file: "));
3631 usymtab_printAll ();
3636 context_exitMacroCache (void)
3638 if (gc.kind != CX_GLOBAL)
3640 if (context_inMacro ())
3641 /* this is okay, file could end without newline in macro */
3643 DPRINTF (("Still in macro: %s",
3644 context_unparse ()));
3645 context_exitFunction ();
3649 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3650 context_unparse ()));
3651 gc.kind = CX_GLOBAL;
3656 ** no longer valid here
3657 ** if (gc.insuppressregion)
3659 ** gc.insuppressregion = FALSE;
3660 ** llerror ("File ended in ignore errors region, possible missing @");
3664 gc.cont.glob = TRUE;
3668 context_saveLocation (void)
3670 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3671 fileloc_free (gc.saveloc);
3672 gc.saveloc = fileloc_copy (g_currentloc);
3676 context_getSaveLocation (void)
3678 fileloc fl = gc.saveloc;
3679 gc.saveloc = fileloc_undefined;
3683 /*@observer@*/ cstring
3684 context_inFunctionName (void)
3686 if (gc.kind == CX_FUNCTION
3687 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3688 || gc.kind == CX_MACROCONST
3689 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3691 return (uentry_rawName (gc.cont.fcn));
3695 llcontbuglit ("context_inFunctionName: not in function");
3696 return (cstring_undefined);
3701 context_userSetFlag (flagcode f, bool b)
3703 DPRINTF (("set flag: %s / %s",
3704 flagcode_unparse (f),
3705 bool_unparse (context_getFlag (f))));
3707 if (f == FLG_NEVERINCLUDE && b)
3709 if (gc.flags[FLG_EXPORTHEADER])
3712 (cstring_makeLiteral
3713 ("Setting +neverinclude after +exportheader. "
3714 "Turning off exportheader, since headers are not checked "
3715 "when +neverinclude is used."));
3717 gc.flags[FLG_EXPORTHEADER] = FALSE;
3722 if (f == FLG_EXPORTHEADER && b)
3724 if (gc.flags[FLG_NEVERINCLUDE])
3727 (cstring_makeLiteral
3728 ("Setting +exportheader after +neverinclude. "
3729 "Not setting exportheader, since headers are not checked "
3730 "when +neverinclude is used."));
3731 gc.flags[FLG_EXPORTHEADER] = FALSE;
3737 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3739 bool lastsetting = context_getFlag (f);
3741 if (bool_equal (lastsetting, b)
3742 && !flagcode_isSpecialFlag (f)
3743 && !flagcode_isIdemFlag (f)
3744 && !flagcode_hasArgument (f))
3747 (message ("Setting %s%s redundant with current value",
3748 cstring_makeLiteralTemp (b ? "+" : "-"),
3749 flagcode_unparse (f)));
3753 if (flagcode_isWarnUseFlag (f) && b)
3755 if (!context_getFlag (FLG_WARNUSE))
3758 (message ("Flag +%s is canceled by -warnuse",
3759 flagcode_unparse (f)));
3764 if (flagcode_isLibraryFlag (f))
3766 if (gc.library != FLG_ANSILIB
3770 (message ("Selecting library %s after library %s was "
3771 "selected (only one library may be used)",
3772 flagcode_unparse (f),
3773 flagcode_unparse (gc.library)));
3776 if (f == FLG_UNIXLIB)
3778 if (context_getFlag (FLG_WARNUNIXLIB))
3781 (cstring_makeLiteral
3782 ("Selecting unix library. Unix library is "
3783 "based on the Single Unix Specification, Version 2. Not all "
3784 "Unix implementations are consistend with this specification. "
3785 "Use -warnunixlib to suppress this message."));
3792 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3796 ("Setting +%s will not produce warnings with -namechecks. "
3797 "Must set +namechecks also.",
3798 flagcode_unparse (f)));
3801 gc.setGlobally[f] = TRUE;
3802 context_setFlag (f, b, g_currentloc);
3806 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3810 context_saveFlagSettings ();
3813 if (ynm_isOff (set))
3815 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3817 else if (ynm_isOn (set))
3819 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3820 gc.setLocally[f] = TRUE;
3824 context_restoreFlag (f, loc);
3829 context_restoreFlag (flagcode f, fileloc loc)
3835 message ("Attempt to restore flag %s when no file scope flags "
3837 flagcode_unparse (f)),
3842 context_addFlagMarker (f, MAYBE, loc);
3843 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3849 context_setFlag (flagcode f, bool b, fileloc loc)
3851 context_setFlagAux (f, b, FALSE, FALSE, loc);
3855 context_setFlagTemp (flagcode f, bool b)
3857 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3862 # define DOSET(ff,b) \
3863 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3864 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3865 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3866 gc.flags[ff] = b; } while (FALSE)
3869 context_setFlagAux (flagcode f, bool b, bool inFile,
3870 /*@unused@*/ bool isRestore, fileloc loc)
3872 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3875 ** Removed test for special flags.
3878 if (flagcode_isIdemFlag (f))
3887 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3889 if (b) /* Turing higher level on, turns on all lower levels */
3893 case FLG_ITS4MOSTRISKY:
3894 DOSET (FLG_ITS4VERYRISKY, b);
3896 case FLG_ITS4VERYRISKY:
3897 DOSET (FLG_ITS4RISKY, b);
3900 DOSET (FLG_ITS4MODERATERISK, b);
3902 case FLG_ITS4MODERATERISK:
3903 DOSET (FLG_ITS4LOWRISK, b);
3905 case FLG_ITS4LOWRISK:
3910 else /* Turning level off, turns off all higher levels */
3914 case FLG_ITS4LOWRISK:
3915 DOSET (FLG_ITS4MODERATERISK, b);
3917 case FLG_ITS4MODERATERISK:
3918 DOSET (FLG_ITS4RISKY, b);
3921 DOSET (FLG_ITS4VERYRISKY, b);
3923 case FLG_ITS4VERYRISKY:
3924 DOSET (FLG_ITS4MOSTRISKY, b);
3926 case FLG_ITS4MOSTRISKY:
3935 case FLG_MESSAGESTREAMSTDOUT:
3936 g_messagestream = stdout;
3938 case FLG_MESSAGESTREAMSTDERR:
3939 g_messagestream = stderr;
3941 case FLG_WARNINGSTREAMSTDOUT:
3942 g_warningstream = stdout;
3944 case FLG_WARNINGSTREAMSTDERR:
3945 g_warningstream = stderr;
3947 case FLG_ERRORSTREAMSTDOUT:
3948 g_errorstream = stdout;
3950 case FLG_ERRORSTREAMSTDERR:
3951 g_errorstream = stderr;
3954 DOSET (FLG_ALLEMPTY, b);
3955 DOSET (FLG_IFEMPTY, b);
3956 DOSET (FLG_WHILEEMPTY, b);
3957 DOSET (FLG_FOREMPTY, b);
3960 DOSET (FLG_PREDBOOL, b);
3961 DOSET (FLG_PREDBOOLINT, b);
3962 DOSET (FLG_PREDBOOLPTR, b);
3963 DOSET (FLG_PREDBOOLOTHERS, b);
3966 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3967 DOSET (FLG_CHECKEDGLOBALIAS, b);
3968 DOSET (FLG_CHECKMODGLOBALIAS, b);
3969 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3972 DOSET (FLG_ALLBLOCK, b);
3973 DOSET (FLG_IFBLOCK, b);
3974 DOSET (FLG_WHILEBLOCK, b);
3975 DOSET (FLG_FORBLOCK, b);
3989 DOSET (FLG_GRAMMAR, b);
3991 case FLG_CODEIMPONLY:
3992 DOSET (FLG_CODEIMPONLY, b);
3993 DOSET (FLG_GLOBIMPONLY, b);
3994 DOSET (FLG_RETIMPONLY, b);
3995 DOSET (FLG_STRUCTIMPONLY, b);
3997 case FLG_SPECALLIMPONLY:
3998 DOSET (FLG_SPECALLIMPONLY, b);
3999 DOSET (FLG_SPECGLOBIMPONLY, b);
4000 DOSET (FLG_SPECRETIMPONLY, b);
4001 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4003 case FLG_ALLIMPONLY:
4004 DOSET (FLG_ALLIMPONLY, b);
4005 DOSET (FLG_GLOBIMPONLY, b);
4006 DOSET (FLG_RETIMPONLY, b);
4007 DOSET (FLG_STRUCTIMPONLY, b);
4008 DOSET (FLG_SPECGLOBIMPONLY, b);
4009 DOSET (FLG_SPECRETIMPONLY, b);
4010 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4012 case FLG_ANSI89LIMITS:
4013 DOSET (FLG_ANSI89LIMITS, b);
4014 DOSET (FLG_CONTROLNESTDEPTH, b);
4015 DOSET (FLG_STRINGLITERALLEN, b);
4016 DOSET (FLG_INCLUDENEST, b);
4017 DOSET (FLG_NUMSTRUCTFIELDS, b);
4018 DOSET (FLG_NUMENUMMEMBERS, b);
4022 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4023 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4024 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4025 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4026 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4027 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4028 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4031 case FLG_ISO99LIMITS:
4032 DOSET (FLG_ISO99LIMITS, b);
4033 DOSET (FLG_CONTROLNESTDEPTH, b);
4034 DOSET (FLG_STRINGLITERALLEN, b);
4035 DOSET (FLG_INCLUDENEST, b);
4036 DOSET (FLG_NUMSTRUCTFIELDS, b);
4037 DOSET (FLG_NUMENUMMEMBERS, b);
4041 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4042 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4043 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4044 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4045 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4046 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4047 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4050 case FLG_EXTERNALNAMELEN:
4051 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4052 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4054 case FLG_INTERNALNAMELEN:
4055 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4056 DOSET (FLG_INTERNALNAMELEN, TRUE);
4058 case FLG_EXTERNALNAMECASEINSENSITIVE:
4059 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4061 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4063 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4064 context_setValue (FLG_EXTERNALNAMELEN, 0);
4067 case FLG_INTERNALNAMECASEINSENSITIVE:
4068 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4070 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4072 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4073 context_setValue (FLG_INTERNALNAMELEN, 0);
4076 case FLG_INTERNALNAMELOOKALIKE:
4077 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4079 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4081 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4082 context_setValue (FLG_INTERNALNAMELEN, 0);
4086 DOSET (FLG_MODNOMODS, b);
4087 DOSET (FLG_MODGLOBSUNSPEC, b);
4088 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4091 DOSET (FLG_EXPORTVAR, b);
4092 DOSET (FLG_EXPORTFCN, b);
4093 DOSET (FLG_EXPORTTYPE, b);
4094 DOSET (FLG_EXPORTMACRO, b);
4095 DOSET (FLG_EXPORTCONST, b);
4096 gc.anyExports = TRUE;
4099 DOSET (FLG_RETEXPOSE, b);
4100 DOSET (FLG_ASSIGNEXPOSE, b);
4101 DOSET (FLG_CASTEXPOSE, b);
4104 DOSET (FLG_RETVALBOOL, b);
4105 DOSET (FLG_RETVALINT, b);
4106 DOSET (FLG_RETVALOTHER, b);
4111 DOSET (FLG_EXPORTLOCAL, FALSE);
4112 DOSET (FLG_DECLUNDEF, FALSE);
4113 DOSET (FLG_SPECUNDEF, FALSE);
4114 DOSET (FLG_TOPUNUSED, FALSE);
4118 DOSET (FLG_LOOPLOOPBREAK, b);
4119 DOSET (FLG_LOOPSWITCHBREAK, b);
4120 DOSET (FLG_SWITCHLOOPBREAK, b);
4121 DOSET (FLG_SWITCHSWITCHBREAK, b);
4122 DOSET (FLG_LOOPLOOPCONTINUE, b);
4123 DOSET (FLG_DEEPBREAK, b);
4126 DOSET (FLG_FORLOOPEXEC, b);
4127 DOSET (FLG_WHILELOOPEXEC, b);
4128 DOSET (FLG_ITERLOOPEXEC, b);
4131 DOSET (FLG_ACCESSMODULE, b);
4132 DOSET (FLG_ACCESSFILE, b);
4133 DOSET (FLG_ACCESSCZECH, b);
4136 DOSET (FLG_ALLMACROS, b);
4137 DOSET (FLG_FCNMACROS, b);
4138 DOSET (FLG_CONSTMACROS, b);
4141 DOSET (FLG_BOUNDSREAD, b);
4142 DOSET (FLG_BOUNDSWRITE, b);
4143 DOSET (FLG_LIKELYBOUNDSREAD, b);
4144 DOSET (FLG_LIKELYBOUNDSWRITE, b);
4146 case FLG_BOUNDSREAD:
4147 DOSET (FLG_LIKELYBOUNDSREAD, b);
4149 case FLG_BOUNDSWRITE:
4150 DOSET (FLG_LIKELYBOUNDSWRITE, b);
4152 case FLG_LIKELYBOUNDS:
4153 DOSET (FLG_LIKELYBOUNDSREAD, b);
4154 DOSET (FLG_LIKELYBOUNDSWRITE, b);
4158 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4159 DOSET (FLG_CZECHFUNCTIONS, b);
4160 DOSET (FLG_CZECHVARS, b);
4161 DOSET (FLG_CZECHCONSTANTS, b);
4162 DOSET (FLG_CZECHTYPES, b);
4165 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4166 DOSET (FLG_SLOVAKFUNCTIONS, b);
4167 DOSET (FLG_SLOVAKVARS, b);
4168 DOSET (FLG_SLOVAKCONSTANTS, b);
4169 DOSET (FLG_SLOVAKTYPES, b);
4171 case FLG_CZECHOSLOVAK:
4172 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4173 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4174 DOSET (FLG_CZECHOSLOVAKVARS, b);
4175 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4176 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4179 DOSET (FLG_NULLSTATE, b);
4180 DOSET (FLG_NULLDEREF, b);
4181 DOSET (FLG_NULLASSIGN, b);
4182 DOSET (FLG_NULLPASS, b);
4183 DOSET (FLG_NULLRET, b);
4186 DOSET (FLG_MUSTFREEONLY, b);
4187 DOSET (FLG_MUSTFREEFRESH, b);
4190 DOSET (FLG_NULLSTATE, b);
4191 DOSET (FLG_NULLDEREF, b);
4192 DOSET (FLG_NULLASSIGN, b);
4193 DOSET (FLG_NULLPASS, b);
4194 DOSET (FLG_NULLRET, b);
4195 DOSET (FLG_COMPDEF, b);
4196 DOSET (FLG_COMPMEMPASS, b);
4197 DOSET (FLG_UNIONDEF, b);
4198 DOSET (FLG_MEMTRANS, b);
4199 DOSET (FLG_USERELEASED, b);
4200 DOSET (FLG_ALIASUNIQUE, b);
4201 DOSET (FLG_MAYALIASUNIQUE, b);
4202 DOSET (FLG_MUSTFREEONLY, b);
4203 DOSET (FLG_MUSTFREEFRESH, b);
4204 DOSET (FLG_MUSTDEFINE, b);
4205 DOSET (FLG_GLOBSTATE, b);
4206 DOSET (FLG_COMPDESTROY, b);
4207 DOSET (FLG_MUSTNOTALIAS, b);
4208 DOSET (FLG_MEMIMPLICIT, b);
4209 DOSET (FLG_BRANCHSTATE, b);
4210 /*@fallthrough@*/ /* also sets memtrans flags */
4212 DOSET (FLG_MEMTRANS, b);
4213 DOSET (FLG_EXPOSETRANS, b);
4214 DOSET (FLG_OBSERVERTRANS, b);
4215 DOSET (FLG_DEPENDENTTRANS, b);
4216 DOSET (FLG_NEWREFTRANS, b);
4217 DOSET (FLG_ONLYTRANS, b);
4218 DOSET (FLG_OWNEDTRANS, b);
4219 DOSET (FLG_FRESHTRANS, b);
4220 DOSET (FLG_SHAREDTRANS, b);
4221 DOSET (FLG_TEMPTRANS, b);
4222 DOSET (FLG_KEPTTRANS, b);
4223 DOSET (FLG_REFCOUNTTRANS, b);
4224 DOSET (FLG_STATICTRANS, b);
4225 DOSET (FLG_UNKNOWNTRANS, b);
4226 DOSET (FLG_KEEPTRANS, b);
4227 DOSET (FLG_IMMEDIATETRANS, b);
4234 if (b && !gc.anyExports
4235 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4236 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4237 || f == FLG_EXPORTCONST
4238 || f == FLG_EXPORTANY))
4240 gc.anyExports = TRUE;
4245 context_maybeSet (flagcode d)
4247 return (gc.flags[d] || gc.setLocally[d]);
4251 context_getFlag (flagcode d)
4253 return (gc.flags[d]);
4257 context_flagOn (flagcode f, fileloc loc)
4259 return (!context_suppressFlagMsg (f, loc));
4262 static void context_saveFlagSettings (void)
4264 gc.savedFlags = TRUE;
4265 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4266 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4269 static void context_restoreFlagSettings (void)
4271 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4272 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4273 gc.savedFlags = FALSE;
4276 void context_setFilename (fileId fid, int lineno)
4277 /*@globals fileloc g_currentloc;@*/
4278 /*@modifies g_currentloc@*/
4280 if (fileId_baseEqual (currentFile (), fid))
4287 fileloc_setColumn (g_currentloc, 0);
4289 if (fileloc_isSpecialFile (g_currentloc))
4291 gc.inDerivedFile = TRUE;
4294 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4296 int maxdepth = context_getValue (FLG_INCLUDENEST);
4298 if (filelocStack_size (gc.locstack) > maxdepth)
4300 int depth = filelocStack_includeDepth (gc.locstack);
4302 if (depth > maxdepth)
4306 message ("Maximum include nesting depth "
4307 "(%d, current depth %d) exceeded",
4310 filelocStack_nextTop (gc.locstack)))
4312 filelocStack_printIncludes (gc.locstack);
4318 g_currentloc = fileloc_create (fid, lineno, 1);
4319 gc.inheader = fileId_isHeader (currentFile ());
4321 context_enterFileAux ();
4325 void context_enterIterDef (/*@observer@*/ uentry le)
4327 context_enterMacro (le);
4328 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4329 gc.kind = CX_ITERDEF;
4332 void context_enterIterEnd (/*@observer@*/ uentry le)
4334 context_enterMacro (le);
4335 gc.kind = CX_ITEREND;
4339 context_destroyMod (void)
4340 /*@globals killed gc@*/
4344 ctype_destroyMod ();
4351 fileTable_free (gc.ftab);
4352 gc.ftab = fileTable_undefined;
4354 filelocStack_free (gc.locstack);
4357 macrocache_free (gc.mc);
4359 /* evans 2002-07-12: not reported because of reldef */
4360 for (i = 0; i < gc.nmods; i++)
4362 cstring_free (gc.moduleaccess[i].file);
4365 sfree (gc.moduleaccess);
4368 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4369 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4372 sRefSetList_free (gc.modrecs);
4374 flagMarkerList_free (gc.markers);
4376 messageLog_free (gc.msgLog);
4378 clauseStack_free (gc.clauses);
4381 cstring_free (gc.msgAnnote);
4382 globSet_free (gc.globs_used);
4383 metaStateTable_free (gc.stateTable);
4384 annotationTable_free (gc.annotTable);
4391 bool context_msgBoolInt (void)
4393 return context_flagOn (FLG_BOOLINT, g_currentloc);
4396 bool context_msgCharInt (void)
4398 return context_flagOn (FLG_CHARINT, g_currentloc);
4401 bool context_msgEnumInt (void)
4403 return context_flagOn (FLG_ENUMINT, g_currentloc);
4406 bool context_msgLongInt (void)
4408 return context_flagOn (FLG_LONGINT, g_currentloc);
4411 bool context_msgShortInt (void)
4413 return context_flagOn (FLG_SHORTINT, g_currentloc);
4416 bool context_msgPointerArith (void)
4418 return context_flagOn (FLG_POINTERARITH, g_currentloc);
4421 bool context_msgStrictOps (void)
4423 return context_flagOn (FLG_STRICTOPS, g_currentloc);
4426 bool context_msgLh (void)
4428 return gc.flags [FLG_DOLH];
4431 void context_pushLoc (void)
4433 fileloc_free (gc.pushloc);
4434 gc.pushloc = gc.saveloc;
4435 gc.saveloc = fileloc_undefined;
4438 void context_popLoc (void)
4440 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4443 bool context_inGlobalScope (void)
4445 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4448 bool context_inInnerScope (void)
4450 return (gc.kind == CX_INNER);
4453 void context_setProtectVars (void)
4455 gc.protectVars = TRUE;
4458 bool context_anyErrors (void)
4460 return (gc.numerrors > 0);
4463 void context_hasError (void)
4466 DPRINTF (("num errors: %d", gc.numerrors));
4469 int context_numErrors (void)
4471 return gc.numerrors;
4474 bool context_neednl (void)
4479 void context_setNeednl (void)
4484 int context_getExpect (void)
4486 return (context_getValue (FLG_EXPECT));
4489 int context_getLCLExpect (void)
4491 return (context_getValue (FLG_LCLEXPECT));
4494 int context_getLimit (void)
4496 return (context_getValue (FLG_LIMIT));
4499 bool context_unlimitedMessages (void)
4501 return (context_getLimit () < 0);
4504 void context_releaseVars (void)
4506 llassert (gc.protectVars);
4507 gc.protectVars = FALSE;
4510 void context_sizeofReleaseVars (void)
4512 /* If there is a nested sizeof, this might not hold:
4513 llassert (gc.protectVars);
4516 gc.protectVars = FALSE;
4519 bool context_inProtectVars (void)
4521 return (gc.protectVars);
4524 void context_hideShowscan (void)
4526 gc.flags[FLG_SHOWSCAN] = FALSE;
4529 void context_unhideShowscan (void)
4531 gc.flags[FLG_SHOWSCAN] = TRUE;
4534 bool context_inHeader (void)
4536 return (gc.inheader);
4539 fileTable context_fileTable (void)
4544 cstring context_tmpdir (void)
4546 return (context_getString (FLG_TMPDIR));
4549 messageLog context_messageLog (void)
4554 bool context_inMacroFunction (void)
4556 return (gc.kind == CX_MACROFCN);
4559 bool context_inMacroConstant (void)
4561 return (gc.kind == CX_MACROCONST);
4564 bool context_inUnknownMacro (void)
4566 return (gc.kind == CX_UNKNOWNMACRO);
4569 void context_setShownFunction (void)
4571 gc.showfunction = FALSE;
4574 bool context_doDump (void)
4576 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4579 bool context_doMerge (void)
4581 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4584 cstring context_getDump (void)
4586 return context_getString (FLG_DUMP);
4589 cstring context_getMerge (void)
4591 return context_getString (FLG_MERGE);
4594 bool context_inLCLLib (void)
4596 return (gc.kind == CX_LCLLIB);
4600 /*drl add these 3/5/2003*/
4601 static bool inSizeof = FALSE;
4603 bool context_inSizeof (void)
4608 void context_enterSizeof (void)
4610 DPRINTF((message("context_enterSizeof ") ) );
4614 void context_leaveSizeof (void)
4616 DPRINTF((message("context_leaveSizeof ") ));
4619 /*end function added 3/5/2003*/
4622 bool context_inImport (void)
4624 return (gc.inimport);
4627 void context_enterImport (void)
4632 void context_leaveImport (void)
4634 gc.inimport = FALSE;
4637 bool context_inMacro (void)
4639 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4640 || gc.kind == CX_UNKNOWNMACRO
4641 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4644 bool context_inIterDef (void)
4646 return (gc.kind == CX_ITERDEF);
4649 bool context_inIterEnd (void)
4651 return (gc.kind == CX_ITEREND);
4654 int context_getLinesProcessed (void)
4656 return (gc.linesprocessed);
4659 int context_getSpecLinesProcessed (void)
4661 return (gc.speclinesprocessed);
4664 void context_processedSpecLine (void)
4666 gc.speclinesprocessed++;
4669 void context_resetSpecLines (void)
4671 gc.speclinesprocessed = 0;
4675 bool context_inGlobalContext (void)
4677 return (gc.kind == CX_GLOBAL);
4680 static void context_quietExitScopes (void)
4683 ** Try to restore the global scope (after an error).
4686 while (!usymtab_inFileScope ())
4688 usymtab_quietExitScope (g_currentloc);
4691 gc.cont.glob = TRUE;
4692 gc.kind = CX_GLOBAL;
4695 void context_checkGlobalScope (void)
4697 if (gc.kind != CX_GLOBAL)
4699 if (context_inMacro ())
4701 ; /* evans 2001-10-14: Okay to be in a macro here! */
4705 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4706 context_quietExitScopes ();
4711 void context_setFileId (fileId s)
4713 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4716 bool context_setBoolName (void)
4718 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4722 cstring context_printBoolName (void)
4724 if (context_setBoolName ())
4726 return context_getBoolName ();
4730 return cstring_makeLiteralTemp ("boolean");
4734 cstring context_getBoolName (void)
4736 return (context_getString (FLG_BOOLTYPE));
4739 cstring context_getFalseName (void)
4741 return (context_getString (FLG_BOOLFALSE));
4744 cstring context_getTrueName (void)
4746 return (context_getString (FLG_BOOLTRUE));
4749 cstring context_getLarchPath (void)
4751 return (context_getString (FLG_LARCHPATH));
4754 cstring context_getLCLImportDir (void)
4756 return (context_getString (FLG_LCLIMPORTDIR));
4759 static void context_setJustPopped (void)
4761 gc.justpopped = TRUE;
4764 void context_clearJustPopped (void)
4766 gc.justpopped = FALSE;
4769 bool context_justPopped (void)
4771 return (gc.justpopped);
4774 void context_setMacroMissingParams (void)
4776 gc.macroMissingParams = TRUE;
4779 void context_resetMacroMissingParams (void)
4781 gc.macroMissingParams = FALSE;
4784 bool context_isMacroMissingParams (void)
4786 return (gc.macroMissingParams);
4789 void context_showFilelocStack (void)
4791 filelocStack_printIncludes (gc.locstack);
4794 metaStateTable context_getMetaStateTable (void)
4796 return gc.stateTable;
4799 metaStateInfo context_lookupMetaStateInfo (cstring key)
4801 return metaStateTable_lookup (gc.stateTable, key);
4804 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4806 return annotationTable_lookup (gc.annotTable, annot);
4809 void context_addAnnotation (annotationInfo info)
4811 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (info)))
4815 message ("Duplicate annotation declaration: %s", annotationInfo_getName (info)),
4816 annotationInfo_getLoc (info));
4818 annotationInfo_free (info);
4822 annotationTable_insert (gc.annotTable, info);
4826 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4828 if (metaStateTable_contains (gc.stateTable, mname))
4832 message ("Duplicate metastate declaration: %s", mname),
4833 metaStateInfo_getLoc (msinfo));
4834 cstring_free (mname);
4835 metaStateInfo_free (msinfo);
4839 DPRINTF (("Adding meta state: %s", mname));
4840 metaStateTable_insert (gc.stateTable, mname, msinfo);
4844 valueTable context_createValueTable (sRef s, stateInfo info)
4846 if (metaStateTable_size (gc.stateTable) > 0)
4848 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4849 /* should use smaller value... */
4850 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4852 metaStateTable_elements (gc.stateTable, msname, msi)
4854 mtContextNode context = metaStateInfo_getContext (msi);
4856 if (mtContextNode_matchesRefStrict (context, s))
4858 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4859 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4863 cstring_copy (metaStateInfo_getName (msi)),
4864 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4865 stateInfo_copy (info)));
4869 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4872 end_metaStateTable_elements ;
4874 stateInfo_free (info);
4875 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4880 stateInfo_free (info);
4881 return valueTable_undefined;
4885 valueTable context_createGlobalMarkerValueTable (stateInfo info)
4887 if (metaStateTable_size (gc.stateTable) > 0)
4889 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4890 /* should use smaller value... */
4892 metaStateTable_elements (gc.stateTable, msname, msi)
4894 /* only add global...*/
4895 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4896 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4898 valueTable_insert (res,
4899 cstring_copy (metaStateInfo_getName (msi)),
4900 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4901 stateInfo_copy (info)));
4903 end_metaStateTable_elements ;
4905 stateInfo_free (info);
4906 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4911 stateInfo_free (info);
4912 return valueTable_undefined;
4916 constraintList context_getImplicitFcnConstraints (uentry ue)
4918 constraintList ret = constraintList_makeNew ();
4919 uentryList params = uentry_getParams (ue);
4921 uentryList_elements (params, el)
4923 DPRINTF (("setImplicitfcnConstraints doing: %s", uentry_unparse(el)));
4925 if (uentry_isElipsisMarker (el))
4931 sRef s = uentry_getSref (el);
4933 DPRINTF (("Trying: %s", sRef_unparse (s)));
4935 if (ctype_isPointer (sRef_getType (s)))
4937 constraint c = constraint_makeSRefWriteSafeInt (s, 0);
4938 ret = constraintList_add (ret, c);
4940 /*drl 10/23/2002 added support for out*/
4942 if (!uentry_isOut(el))
4944 c = constraint_makeSRefReadSafeInt (s, 0);
4945 ret = constraintList_add (ret , c);
4950 DPRINTF (("%s is NOT a pointer", sRef_unparseFull (s)));
4953 } end_uentryList_elements;
4955 DPRINTF (("Returns ==> %s", constraintList_unparse (ret)));