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;
107 filelocStack locstack;
110 /*@observer@*/ sRef aliasAnnote;
111 /*@observer@*/ sRef aliasAnnoteAls;
115 /*@observer@*/ sRefSet mods;
117 /* file access types */
120 /* local access types (this function) */
123 /* no access types (@noaccess) */
126 /*@observer@*/ globSet globs;
127 /*@only@*/ globSet globs_used;
131 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
137 bool flags[NUMFLAGS];
138 bool saveflags[NUMFLAGS];
139 bool setGlobally[NUMFLAGS];
140 bool setLocally[NUMFLAGS];
142 int values[NUMVALUEFLAGS];
143 int counters[NUMVALUEFLAGS];
145 o_cstring strings[NUMSTRINGFLAGS];
146 sRefSetList modrecs; /* Keep track of file static symbols modified. */
148 metaStateTable stateTable; /* User-defined state information. */
149 annotationTable annotTable; /* User-defined annotations table. */
154 /*@dependent@*/ /*@exposed@*/ uentry fcn;
158 union u_cont savecont;
161 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
162 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
163 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
164 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
166 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
167 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
168 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
169 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
170 static void context_setFlag (flagcode p_f, bool p_b, fileloc p_loc)
171 /*@modifies gc.flags@*/ ;
174 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile,
175 bool p_isRestore, fileloc p_loc)
176 /*@modifies gc.flags@*/ ;
178 static void context_restoreFlag (flagcode p_f, fileloc p_loc)
179 /*@modifies gc.flags@*/ ;
183 cstring context_unparseFlagMarkers ()
185 return (flagMarkerList_unparse (gc.markers));
188 void context_setPreprocessing (void)
190 llassert (!gc.preprocessing);
191 gc.preprocessing = TRUE;
194 void context_clearPreprocessing (void)
196 llassert (gc.preprocessing);
197 gc.preprocessing = FALSE;
200 bool context_isPreprocessing (void)
202 return gc.preprocessing;
205 bool context_loadingLibrary (void)
207 return (fileloc_isLib (g_currentloc));
210 bool context_inXHFile (void)
212 return (fileloc_isXHFile (g_currentloc));
215 void context_setInCommandLine (void)
217 llassert (!gc.incommandline);
218 gc.incommandline = TRUE;
221 void context_clearInCommandLine (void)
223 llassert (gc.incommandline);
224 gc.incommandline = FALSE;
227 bool context_isInCommandLine (void)
229 return gc.incommandline;
233 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
236 clauseStack_push (gc.clauses, c);
238 if (clause_isConditional (c)
239 && context_getFlag (FLG_CONTROLNESTDEPTH))
241 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
242 int depth = clauseStack_controlDepth (gc.clauses);
244 if (depth == maxdepth + 1)
247 (FLG_CONTROLNESTDEPTH,
248 message ("Maximum control nesting depth "
257 clause topClause (clauseStack s) /*@*/
259 if (clauseStack_isEmpty (s)) return NOCLAUSE;
260 return ((clause) clauseStack_top (s));
264 context_addMacroCache (/*@only@*/ cstring def)
266 DPRINTF (("macro cache: %s", def));
267 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
271 context_addComment (/*@only@*/ cstring def, fileloc loc)
273 macrocache_addComment (gc.mc, fileloc_copy (loc), def);
277 ** returns TRUE is fl is in ignore region, or region where -code
279 ** the logic is fuzzy...
283 context_inSuppressFlagZone (fileloc fl, flagcode code)
285 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
288 if (ynm_isMaybe (ret))
296 res = !gc.saveflags[code];
300 res = !context_getFlag (code);
305 res = ynm_toBoolStrict (ret);
312 context_suppressSystemMsg (fileloc fl)
314 if (context_getFlag (FLG_SYSTEMDIRERRORS))
320 return (fileloc_isSystemFile (fl));
325 context_suppressFlagMsg (flagcode flag, fileloc fl)
327 if (context_suppressSystemMsg (fl))
332 DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc)));
334 /* want same object compare here */
336 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
338 DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile)));
340 return (!context_getFlag (flag)
341 || context_inSuppressRegion ()
342 || context_inSuppressZone (fl)
343 || (context_inSuppressFlagZone (fl, flag))); /* removed gc.inDerivedFile from this */
347 return (context_inSuppressFlagZone (fl, flag));
352 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
355 if (context_suppressSystemMsg (fl))
361 if (fl == g_currentloc)
362 /*@noaccess fileloc@*/
364 return (context_getFlag (flag) || context_inSuppressRegion ());
369 return (context_getFlag (flag) || context_inSuppressRegion ());
374 context_inSuppressZone (fileloc fl)
376 if (context_suppressSystemMsg (fl))
381 return (flagMarkerList_inIgnore (gc.markers, fl));
385 context_inSuppressRegion (void)
387 return (gc.insuppressregion);
391 context_enterSuppressRegion (fileloc loc)
393 if (gc.insuppressregion)
395 gc.insuppressregion = FALSE; /* get this msg! */
397 ("%q: New ignore errors region entered while in ignore errors region",
398 fileloc_unparse (loc)));
401 gc.insuppressregion = TRUE;
402 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (loc));
406 context_addFlagMarker (flagcode code, ynm set, fileloc loc)
408 (void) flagMarkerList_add (gc.markers,
409 flagMarker_createLocalSet (code, set, loc));
413 context_enterSuppressLine (int count, fileloc loc)
415 if (context_processingMacros ())
420 if (flagMarkerList_add
422 flagMarker_createIgnoreCount (count, loc)))
424 fileloc nextline = fileloc_copy (loc);
425 fileloc_nextLine (nextline);
426 fileloc_setColumn (nextline, 0);
428 check (flagMarkerList_add (gc.markers,
429 flagMarker_createIgnoreOff (nextline)));
430 fileloc_free (nextline);
434 void context_checkSuppressCounts (void)
436 if (context_getFlag (FLG_SUPCOUNTS))
438 flagMarkerList_checkSuppressCounts (gc.markers);
442 void context_incLineno (void)
449 context_exitSuppressRegion (fileloc loc)
451 if (!gc.insuppressregion)
455 message ("End ignore errors in region while not ignoring errors"),
459 gc.insuppressregion = FALSE;
460 (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (loc));
464 context_enterMTfile (void)
470 context_exitMTfile (void)
472 llassert (gc.kind == CX_MT);
477 context_enterLCLfile (void)
480 gc.facct = typeIdSet_emptySet ();
484 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
488 for (i = 0; i < gc.nmods; i++)
490 if (cstring_equal (gc.moduleaccess[i].file, fname))
492 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
493 cstring_free (fname);
498 if (gc.nmods == gc.maxmods)
502 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
503 oldmods = gc.moduleaccess;
505 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
507 for (i = 0; i < gc.nmods; i++)
509 gc.moduleaccess[i] = oldmods[i];
515 gc.moduleaccess[gc.nmods].file = fname;
516 gc.moduleaccess[gc.nmods].daccess = mods;
522 insertModuleAccess (cstring fname, typeId t)
526 for (i = 0; i < gc.nmods; i++)
528 if (cstring_equal (gc.moduleaccess[i].file, fname))
530 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
535 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
539 context_exitLCLfile (void)
541 if (gc.kind != CX_LCLLIB)
544 fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION);
546 addModuleAccess (fileLib_removePath (lclname), gc.facct);
547 cstring_free (lclname);
552 gc.facct = typeIdSet_emptySet ();
556 context_dumpModuleAccess (FILE *fout)
560 for (i = 0; i < gc.nmods; i++)
562 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
564 fprintf (fout, "%s#%s@\n",
565 cstring_toCharsSafe (gc.moduleaccess[i].file),
566 cstring_toCharsSafe (td));
572 bool context_usingPosixLibrary ()
574 return (gc.library == FLG_POSIXLIB
575 || gc.library == FLG_POSIXSTRICTLIB
576 || gc.library == FLG_UNIXLIB
577 || gc.library == FLG_UNIXSTRICTLIB);
580 bool context_usingAnsiLibrary ()
582 return (gc.library != FLG_NOLIB);
585 flagcode context_getLibrary ()
590 void context_setLibrary (flagcode code)
595 /*@observer@*/ cstring context_selectedLibrary ()
600 return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME);
602 return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME);
603 case FLG_POSIXSTRICTLIB:
604 return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME);
606 return cstring_makeLiteralTemp (LLUNIXLIBS_NAME);
607 case FLG_UNIXSTRICTLIB:
608 return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME);
610 return cstring_makeLiteralTemp (LLSTDLIBS_NAME);
617 context_loadModuleAccess (FILE *in)
619 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
621 char *name = mstring_create (MAX_NAME_LENGTH);
627 while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL )
633 while (s != NULL && *s != ';' && *s != '\0')
637 while (*s != '#' && *s != '\0')
646 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
647 cstring_fromChars (s)));
653 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
654 typeIdSet_undump (&s));
656 (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH);
657 llassert (s != lasts);
667 typeIdSet context_fileAccessTypes (void)
673 context_resetModeFlags (void)
677 if (flagcode_isModeFlag (code))
679 context_setFlag (code, FALSE, g_currentloc);
687 ** Set all flags to FALSE, except for a few which are
690 ** Set all values and strings to appropriate defaults.
691 ** Set all counters to 0.
695 conext_resetAllCounters (void)
699 for (i = 0; i < NUMVALUEFLAGS; i++)
706 context_resetAllFlags (void)
708 DPRINTF (("******** Reset all flags"));
712 gc.flags[code] = FALSE;
714 if (flagcode_hasNumber (code))
718 /*@-loopswitchbreak@*/
722 val = DEFAULT_LIMIT; break;
724 val = DEFAULT_BUGSLIMIT; break;
726 val = DEFAULT_LINELEN; break;
727 case FLG_INDENTSPACES:
728 val = DEFAULT_INDENTSPACES; break;
729 case FLG_LOCINDENTSPACES:
730 val = DEFAULT_LOCINDENTSPACES; break;
731 case FLG_EXTERNALNAMELEN:
732 val = ISO99_EXTERNALNAMELEN; break;
733 case FLG_INTERNALNAMELEN:
734 val = ISO99_INTERNALNAMELEN; break;
735 case FLG_COMMENTCHAR:
736 val = (int) DEFAULT_COMMENTCHAR; break;
737 case FLG_CONTROLNESTDEPTH:
738 val = (int) ISO99_CONTROLNESTDEPTH; break;
739 case FLG_STRINGLITERALLEN:
740 val = (int) ISO99_STRINGLITERALLEN; break;
741 case FLG_INCLUDENEST:
742 val = (int) ISO99_INCLUDENEST; break;
743 case FLG_NUMSTRUCTFIELDS:
744 val = (int) ISO99_NUMSTRUCTFIELDS; break;
745 case FLG_NUMENUMMEMBERS:
746 val = (int) ISO99_NUMENUMMEMBERS; break;
751 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
753 /*@=loopswitchbreak@*/
755 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val));
756 context_setValue (code, val);
757 DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code)));
758 llassert (context_getValue (code) == val);
760 else if (flagcode_hasChar (code))
762 llassert (code == FLG_COMMENTCHAR);
763 context_setCommentMarkerChar (DEFAULT_COMMENTCHAR);
765 else if (flagcode_hasString (code))
767 cstring val = cstring_undefined;
770 { /*@-loopswitchbreak@*/
773 cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH);
775 if (cstring_isDefined (larchpath))
777 val = cstring_copy (larchpath);
781 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
786 case FLG_LCLIMPORTDIR:
788 val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR)));
792 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
794 char *env = osd_getEnvironmentVariable ("TMP");
798 env = osd_getEnvironmentVariable ("TEMP");
801 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
804 val = cstring_makeLiteral (DEFAULT_TMPDIR);
805 # endif /* !defined(OS2) && !defined(MSDOS) */
809 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
811 val = cstring_makeLiteral ("false"); break;
813 val = cstring_makeLiteral ("true"); break;
814 case FLG_MACROVARPREFIX:
815 val = cstring_makeLiteral ("m_"); break;
817 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
820 } /*@=loopswitchbreak@*/
822 context_setString (code, val);
826 ; /* nothing to set */
831 ** These flags are true by default.
834 /* eventually, move this into flags.def */
836 gc.flags[FLG_STREAMOVERWRITE] = TRUE;
837 gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE;
838 gc.flags[FLG_MODIFIES] = TRUE;
839 gc.flags[FLG_NESTCOMMENT] = TRUE;
840 gc.flags[FLG_GLOBALS] = TRUE;
841 gc.flags[FLG_FULLINITBLOCK] = TRUE;
842 gc.flags[FLG_INITSIZE] = TRUE;
843 gc.flags[FLG_INITALLELEMENTS] = TRUE;
844 gc.flags[FLG_NULLINIT] = TRUE;
846 gc.flags[FLG_STRINGLITTOOLONG] = TRUE;
847 gc.flags[FLG_MACROCONSTDIST] = TRUE;
848 gc.flags[FLG_LIKELYBOOL] = TRUE;
849 gc.flags[FLG_ZEROPTR] = TRUE;
850 gc.flags[FLG_NUMLITERAL] = TRUE;
851 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
852 gc.flags[FLG_SKIPISOHEADERS] = TRUE;
853 gc.flags[FLG_SKIPPOSIXHEADERS] = FALSE;
854 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
855 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
856 gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE;
857 gc.flags[FLG_CASTFCNPTR] = TRUE;
858 gc.flags[FLG_DOLCS] = TRUE;
859 gc.flags[FLG_USEVARARGS] = TRUE;
860 gc.flags[FLG_MAINTYPE] = TRUE;
861 gc.flags[FLG_SPECMACROS] = TRUE;
862 gc.flags[FLG_REDEF] = TRUE;
863 gc.flags[FLG_MACRONEXTLINE] = TRUE;
865 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
866 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
868 gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE;
869 gc.flags[FLG_WARNUSE] = TRUE;
870 gc.flags[FLG_PREDASSIGN] = TRUE;
871 gc.flags[FLG_MODOBSERVER] = TRUE;
872 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
873 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
875 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
876 gc.flags[FLG_RETIMPONLY] = TRUE;
877 gc.flags[FLG_GLOBIMPONLY] = TRUE;
878 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
879 gc.flags[FLG_PREPROC] = TRUE;
880 gc.flags[FLG_NAMECHECKS] = TRUE;
881 gc.flags[FLG_FORMATCODE] = TRUE;
882 gc.flags[FLG_FORMATTYPE] = TRUE;
883 gc.flags[FLG_BADFLAG] = TRUE;
884 gc.flags[FLG_WARNFLAGS] = TRUE;
885 gc.flags[FLG_WARNRC] = TRUE;
886 gc.flags[FLG_FILEEXTENSIONS] = TRUE;
887 gc.flags[FLG_WARNUNIXLIB] = FALSE;
888 gc.flags[FLG_WARNPOSIX] = TRUE;
889 gc.flags[FLG_SHOWCOL] = TRUE;
890 gc.flags[FLG_SHOWDEEPHISTORY] = FALSE; /* TRUE; */
891 gc.flags[FLG_SHOWFUNC] = TRUE;
892 gc.flags[FLG_SUPCOUNTS] = TRUE;
893 gc.flags[FLG_HINTS] = TRUE;
894 gc.flags[FLG_SYNTAX] = TRUE;
895 gc.flags[FLG_TYPE] = TRUE;
896 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
897 gc.flags[FLG_ABSTRACT] = TRUE;
898 gc.flags[FLG_NUMABSTRACT] = TRUE;
899 gc.flags[FLG_ITERBALANCE] = TRUE;
900 gc.flags[FLG_ITERYIELD] = TRUE;
901 gc.flags[FLG_DUPLICATECASES] = TRUE;
902 gc.flags[FLG_ALWAYSEXITS] = TRUE;
903 gc.flags[FLG_EMPTYRETURN] = TRUE;
904 gc.flags[FLG_MACRORETURN] = TRUE;
905 gc.flags[FLG_UNRECOG] = TRUE;
906 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
907 gc.flags[FLG_LINTCOMMENTS] = TRUE;
908 gc.flags[FLG_ACCESSCZECH] = TRUE;
909 gc.flags[FLG_ACCESSMODULE] = TRUE;
910 gc.flags[FLG_ACCESSFILE] = TRUE;
911 gc.flags[FLG_MACROVARPREFIX] = TRUE;
913 gc.flags[FLG_ANNOTATIONERROR] = TRUE;
914 gc.flags[FLG_COMMENTERROR] = TRUE;
917 ** Changed for version 2.4.
920 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
926 /* commenting ou until some output issues are fixed */
927 gc.flags[FLG_ORCONSTRAINT] = TRUE;
929 gc.flags[FLG_CONSTRAINTLOCATION] = TRUE;
932 gc.flags[FLG_WARNSYSFILES] = TRUE;
935 ** On by default for Win32, but not Unix
938 # if defined (WIN32) || defined (OS2)
939 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
940 gc.flags[FLG_CASEINSENSITIVEFILENAMES] = TRUE;
945 ** C is way-lame, and you can initialize an array to a constant except where
946 ** it is declared. Hence, a macro is used to set the modeflags.
950 # define SETFLAGS() \
951 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
952 if (!flagcode_isModeFlag (modeflags[i])) \
953 { llbug (message ("not a mode flag: %s", \
954 flagcode_unparse (modeflags[i]))); } \
955 else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }}
957 static void context_setModeAux (cstring p_s, bool p_warn) ;
960 context_setMode (cstring s)
962 context_setModeAux (s, TRUE);
966 context_setModeNoWarn (cstring s)
968 context_setModeAux (s, FALSE);
972 context_setModeAux (cstring s, bool warn)
974 intSet setflags = intSet_new ();
978 if (flagcode_isModeFlag (code))
980 if (gc.setGlobally[code])
982 (void) intSet_insert (setflags, (int) code);
987 if (!intSet_isEmpty (setflags))
989 cstring rflags = cstring_undefined;
992 intSet_elements (setflags, el)
994 if (cstring_isUndefined (rflags))
996 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
1000 rflags = message ("%q, %s", rflags,
1001 flagcode_unparse ((flagcode) el));
1005 if (num > 4 && intSet_size (setflags) > 6)
1007 rflags = message ("%q, (%d others) ...", rflags,
1008 intSet_size (setflags) - num);
1011 } end_intSet_elements ;
1015 voptgenerror (FLG_WARNFLAGS,
1016 message ("Setting mode %s after setting mode flags will "
1017 "override set values of flags: %s",
1022 cstring_free (rflags);
1025 intSet_free (setflags);
1027 context_resetModeFlags ();
1029 if (cstring_equalLit (s, "standard"))
1031 flagcode modeflags[] =
1033 FLG_ENUMINT, FLG_MACROMATCHNAME,
1034 FLG_STRINGLITNOROOM,
1035 FLG_STRINGLITNOROOMFINALNULL,
1036 FLG_MACROUNDEF, FLG_RELAXQUALS,
1037 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
1038 FLG_CHECKSTRICTGLOBALIAS,
1039 FLG_CHECKEDGLOBALIAS,
1040 FLG_CHECKMODGLOBALIAS,
1041 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
1042 FLG_UNSIGNEDCOMPARE,
1043 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
1045 FLG_ABSTRACTCOMPARE,
1046 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
1047 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1048 FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE,
1049 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1050 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL,
1053 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
1054 FLG_MACROSTMT, FLG_MACROPARENS,
1057 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
1058 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1064 /* memchecks flags */
1066 FLG_NULLSTATE, FLG_NULLASSIGN,
1067 FLG_NULLPASS, FLG_NULLRET,
1070 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1073 /* memtrans flags */
1089 FLG_NUMABSTRACTCAST,
1092 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1095 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1096 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1099 FLG_STATETRANSFER, FLG_STATEMERGE,
1100 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
1102 FLG_IMPCHECKEDSPECGLOBALS,
1103 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
1104 FLG_IFEMPTY, FLG_REALCOMPARE,
1105 FLG_BOOLOPS, FLG_PTRNEGATE,
1107 FLG_SHIFTIMPLEMENTATION,
1108 FLG_BUFFEROVERFLOWHIGH,
1115 else if (cstring_equalLit (s, "weak"))
1117 flagcode modeflags[] =
1119 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE, FLG_LONGINT, FLG_SHORTINT,
1120 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1121 FLG_CHARINDEX, FLG_NUMABSTRACTINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1122 FLG_CHARUNSIGNEDCHAR,
1125 FLG_VARUNUSED, FLG_FUNCUNUSED,
1127 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1130 FLG_BUFFEROVERFLOWHIGH,
1131 FLG_RETSTACK, FLG_PTRNEGATE,
1132 FLG_STATETRANSFER, FLG_STATEMERGE,
1133 FLG_LONGUNSIGNEDINTEGRAL,
1134 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1138 FLG_BUFFEROVERFLOWHIGH,
1139 FLG_STRINGLITNOROOM,
1140 FLG_STRINGLITNOROOMFINALNULL,
1146 else if (cstring_equalLit (s, "checks"))
1148 flagcode modeflags[] =
1150 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1151 FLG_NUMABSTRACTCAST,
1152 FLG_ABSTRACTCOMPARE,
1153 FLG_STATETRANSFER, FLG_STATEMERGE,
1154 FLG_CHECKSTRICTGLOBALIAS,
1155 FLG_CHECKEDGLOBALIAS,
1156 FLG_CHECKMODGLOBALIAS,
1157 FLG_UNCHECKEDGLOBALIAS,
1159 FLG_STRINGLITNOROOM,
1160 FLG_STRINGLITNOROOMFINALNULL,
1161 FLG_STRINGLITSMALLER,
1162 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1163 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1164 FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS,
1165 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1166 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1167 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1168 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1169 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1170 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1171 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1172 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1173 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1174 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1175 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1176 FLG_NUMABSTRACTPRINT,
1183 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1187 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1189 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1190 FLG_EVALORDER, FLG_USEDEF,
1193 /* warn use flags */
1194 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1195 FLG_BUFFEROVERFLOWHIGH,
1197 /* memchecks flags */
1199 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1200 FLG_NULLPASS, FLG_NULLRET,
1203 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1205 /* memtrans flags */
1219 FLG_STATICINITTRANS,
1220 FLG_UNKNOWNINITTRANS,
1223 FLG_ONLYUNQGLOBALTRANS,
1224 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1227 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1228 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1231 FLG_NULLPOINTERARITH,
1232 FLG_SHADOW, FLG_DEPARRAYS,
1233 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1234 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1235 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1236 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1237 FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES,
1238 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE, FLG_REALRELATECOMPARE,
1239 FLG_BOOLOPS, FLG_SHIFTNEGATIVE,
1240 FLG_SHIFTIMPLEMENTATION,
1241 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1246 else if (cstring_equalLit (s, "strict"))
1248 flagcode modeflags[] =
1250 FLG_ABSTRACTCOMPARE,
1251 FLG_CHECKSTRICTGLOBALIAS,
1252 FLG_NUMABSTRACTCAST,
1253 FLG_CHECKEDGLOBALIAS,
1254 FLG_CHECKMODGLOBALIAS,
1255 FLG_UNCHECKEDGLOBALIAS,
1259 FLG_NUMABSTRACTPRINT,
1260 FLG_STRINGLITNOROOM,
1261 FLG_STRINGLITNOROOMFINALNULL,
1262 FLG_STRINGLITSMALLER,
1263 FLG_STATETRANSFER, FLG_STATEMERGE,
1264 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1265 FLG_ALLGLOBALS, FLG_IMPTYPE,
1266 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1267 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1268 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1269 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1272 FLG_ONLYUNQGLOBALTRANS,
1273 FLG_GLOBALSIMPMODIFIESNOTHING,
1274 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1275 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1276 FLG_USEALLGLOBS, FLG_RETALIAS,
1277 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1278 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1279 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1281 FLG_EXPORTITER, FLG_EXPORTCONST,
1282 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1283 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1285 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1287 FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE,
1288 FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1289 FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES,
1290 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1291 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1292 FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL,
1293 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1294 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1296 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1299 FLG_MACROREDEF, FLG_MACROEMPTY,
1300 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1302 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1304 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1305 FLG_MODOBSERVERUNCON,
1310 /* warn use flags */
1311 FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
1312 FLG_BUFFEROVERFLOWHIGH,
1313 FLG_BUFFEROVERFLOW, FLG_TOCTOU,
1315 /* memchecks flags */
1316 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1317 FLG_NULLPASS, FLG_NULLRET,
1319 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1321 /* memory checking flags */
1322 FLG_BOUNDSREAD, FLG_BOUNDSWRITE,
1323 FLG_LIKELYBOUNDSREAD, FLG_LIKELYBOUNDSWRITE,
1326 /* memtrans flags */
1342 FLG_STATICINITTRANS,
1343 FLG_UNKNOWNINITTRANS,
1345 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1348 FLG_MUSTDEFINE, FLG_GLOBSTATE,
1349 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1353 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1355 FLG_SHADOW, FLG_DEPARRAYS,
1356 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1357 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1358 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1359 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1360 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1361 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1362 FLG_IMPCHECKEDSTRICTSTATICS,
1363 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1364 FLG_IMPCHECKMODINTERNALS,
1365 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1366 FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL,
1367 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1368 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1369 FLG_CONTROLNESTDEPTH,
1370 FLG_FORBLOCK, FLG_WHILEBLOCK,
1371 FLG_FOREMPTY, FLG_WHILEEMPTY,
1372 FLG_IFEMPTY, FLG_IFBLOCK,
1374 FLG_REALCOMPARE, FLG_BOOLOPS, FLG_REALRELATECOMPARE,
1375 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1378 FLG_SHIFTIMPLEMENTATION,
1380 FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW,
1388 llcontbug (message ("context_setMode: bad mode: %s", s));
1393 context_isSpecialFile (cstring fname)
1395 cstring ext = fileLib_getExtension (fname);
1397 return (cstring_equalLit (ext, ".y")
1398 || cstring_equalLit (ext, ".l")
1399 || cstring_equalLit (fname, "lex.yy.c"));
1403 context_isSystemDir (cstring dir)
1405 cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS));
1406 cstring savedir = thisdir;
1407 cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1409 if (cstring_isDefined (nextdir))
1411 /*@access cstring@*/
1412 *nextdir = '\0'; /* closes thisdir */
1414 /*@noaccess cstring@*/
1417 /* 2001-09-09: added thisdir[0] != '\0'
1418 ** herbert: don't compare with an empty name!
1419 ** should return false for empty directory path
1422 while (!cstring_isEmpty (thisdir))
1424 DPRINTF (("Test: %s / %s", dir, thisdir));
1426 if (osd_equalCanonicalPrefix (dir, thisdir))
1428 cstring_free (savedir);
1432 if (cstring_isDefined (nextdir))
1435 nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR);
1437 if (cstring_isDefined (nextdir))
1439 /*@access cstring@*/
1442 /*@noaccess cstring@*/
1451 DPRINTF (("Returns FALSE"));
1452 cstring_free (savedir);
1457 context_addFileAccessType (typeId t)
1461 if (context_inFunctionLike ())
1463 gc.acct = typeIdSet_insert (gc.acct, t);
1466 gc.facct = typeIdSet_insert (gc.facct, t);
1468 base = fileloc_getBase (g_currentloc);
1469 insertModuleAccess (base, t);
1470 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1471 typeIdSet_unparse (gc.acct)));
1475 context_removeFileAccessType (typeId t)
1477 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1478 || gc.kind == CX_UNKNOWNMACRO)
1480 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1483 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1484 gc.nacct = typeIdSet_insert (gc.nacct, t);
1487 void context_enterFunctionHeader (void)
1489 if (context_getFlag (FLG_GRAMMAR))
1491 lldiagmsg (message ("Enter function header: %q", context_unparse ()));
1494 if (gc.kind != CX_GLOBAL)
1496 llparseerror (cstring_makeLiteral
1497 ("Likely parse error. Function header outside global context."));
1501 llassert (gc.kind == CX_GLOBAL);
1502 DPRINTF (("Enter function header!"));
1503 gc.inFunctionHeader = TRUE;
1507 void context_exitFunctionHeader (void)
1509 if (context_getFlag (FLG_GRAMMAR))
1511 lldiagmsg (message ("Exit function header: %q", context_unparse ()));
1514 DPRINTF (("Exit function header!"));
1515 gc.inFunctionHeader = FALSE;
1518 bool context_inFunctionHeader (void)
1520 return (gc.inFunctionHeader);
1523 void context_enterFunctionDeclaration (uentry e)
1525 if (context_getFlag (FLG_GRAMMAR))
1527 lldiagmsg (message ("Enter function declaration: %q", context_unparse ()));
1530 DPRINTF (("Enter function decl"));
1531 llassert (gc.savekind == CX_ERROR);
1532 gc.savekind = gc.kind;
1533 gc.savecont = gc.cont;
1534 gc.kind = CX_FCNDECLARATION;
1538 void context_exitFunctionDeclaration (void)
1540 if (context_getFlag (FLG_GRAMMAR))
1542 lldiagmsg (message ("Exit function declaration: %q", context_unparse ()));
1545 DPRINTF (("Exit function decl"));
1546 llassert (gc.savekind != CX_ERROR);
1547 llassert (gc.kind == CX_FCNDECLARATION);
1548 gc.kind = gc.savekind;
1549 gc.cont = gc.savecont;
1551 gc.savekind = CX_ERROR;
1553 if (context_getFlag (FLG_GRAMMAR))
1555 lldiagmsg (message ("After exit function declaration: %q", context_unparse ()));
1559 bool context_inFunctionDeclaration (void)
1561 return (gc.kind == CX_FCNDECLARATION);
1566 context_enterMacro (/*@observer@*/ uentry e)
1568 context_enterFunction (e);
1569 gc.kind = CX_MACROFCN;
1573 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1575 llassert (uentry_isFunction (e));
1576 context_enterFunction (e);
1577 gc.kind = CX_UNKNOWNMACRO;
1580 void context_enterAndClause (exprNode e)
1582 DPRINTF (("enter and clause: %s", exprNode_unparse (e)));
1583 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1584 pushClause (ANDCLAUSE);
1587 void context_enterOrClause (exprNode e)
1589 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1590 pushClause (ORCLAUSE);
1593 bool context_inDeepLoop (void)
1595 bool inLoop = FALSE;
1597 clauseStack_elements (gc.clauses, el)
1599 if (clause_isLoop (el))
1608 } end_clauseStack_elements;
1613 bool context_inDeepSwitch (void)
1615 bool inLoop = FALSE;
1617 clauseStack_elements (gc.clauses, el)
1619 if (clause_isSwitch (el))
1628 } end_clauseStack_elements;
1633 bool context_inDeepLoopSwitch (void)
1635 bool inLoop = FALSE;
1637 clauseStack_elements (gc.clauses, el)
1639 if (clause_isBreakable (el))
1648 } end_clauseStack_elements;
1653 clause context_breakClause (void)
1655 clauseStack_elements (gc.clauses, el)
1657 if (clause_isSwitch (el))
1661 else if (clause_isLoop (el))
1669 } end_clauseStack_elements;
1674 clause context_nextBreakClause (void)
1676 bool hasOne = FALSE;
1678 clauseStack_elements (gc.clauses, el)
1680 if (clause_isBreakable (el))
1691 } end_clauseStack_elements;
1696 bool context_inConditional (void)
1698 clauseStack_elements (gc.clauses, el)
1701 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1702 ** to distinguish if from ? for this
1705 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1709 } end_clauseStack_elements;
1714 void context_exitAndClause (exprNode pred, exprNode tbranch)
1716 context_setJustPopped ();
1718 llassert (gc.inclause == ANDCLAUSE);
1720 usymtab_popAndBranch (pred, tbranch);
1721 clauseStack_pop (gc.clauses);
1722 gc.inclause = topClause (gc.clauses);
1725 void context_exitOrClause (exprNode pred, exprNode tbranch)
1727 context_setJustPopped ();
1729 llassert (gc.inclause == ORCLAUSE);
1731 usymtab_popOrBranch (pred, tbranch);
1732 clauseStack_pop (gc.clauses);
1733 gc.inclause = topClause (gc.clauses);
1736 static void context_enterCondClauseAux (clause cl)
1742 static void context_enterTrueAux (exprNode e, clause cl)
1745 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1749 void context_enterIterClause (void)
1751 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1754 void context_enterDoWhileClause (void)
1756 pushClause (DOWHILECLAUSE);
1759 void context_enterWhileClause (exprNode e)
1761 context_enterTrueAux (e, WHILECLAUSE);
1764 void context_enterForClause (exprNode e)
1766 context_enterTrueAux (e, FORCLAUSE);
1769 void context_enterTrueClause (exprNode e)
1771 context_enterTrueAux (e, TRUECLAUSE);
1774 void context_enterSwitch (exprNode e)
1776 DPRINTF (("Enter switch: %s", exprNode_unparse (e)));
1777 usymtab_switchBranch (e);
1778 context_enterCondClauseAux (SWITCHCLAUSE);
1781 void context_exitSwitch (exprNode e, bool allpaths)
1783 usymtab_exitSwitch (e, allpaths);
1785 while (clause_isCase (clauseStack_top (gc.clauses)))
1787 clauseStack_pop (gc.clauses);
1790 context_exitClauseSimp ();
1793 void context_enterCaseClause (exprNode e)
1795 bool branch = FALSE;
1797 DPRINTF (("Enter case clause!"));
1799 branch = usymtab_newCase (exprNode_undefined, e);
1803 context_enterCondClauseAux (CASECLAUSE);
1807 static void context_enterFalseClauseAux (exprNode e, clause cl)
1810 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1812 clauseStack_switchTop (gc.clauses, cl);
1815 void context_enterFalseClause (exprNode e)
1818 context_enterFalseClauseAux (e, FALSECLAUSE);
1822 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1824 gc.kind = CX_MACROCONST;
1826 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1828 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1832 usymtab_enterScope ();
1833 sRef_enterFunctionScope ();
1835 gc.globs = globSet_undefined;
1836 globSet_clear (gc.globs_used);
1837 gc.mods = sRefSet_undefined;
1840 uentry context_getHeader (void)
1842 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1844 llfatalbug (message ("context_getHeader: bad call: %q",
1845 context_unparse ()));
1848 return (gc.cont.fcn);
1852 context_setFunctionDefined (fileloc loc)
1856 case CX_UNKNOWNMACRO:
1859 uentry_setFunctionDefined (gc.cont.fcn, loc);
1862 /* (not a bug because of parse errors) */
1868 context_enterFunction (/*@exposed@*/ uentry e)
1870 gc.kind = CX_FUNCTION;
1873 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1875 if (uentry_hasAccessType (e))
1877 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1885 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1886 typeIdSet_unparse (gc.acct)));
1888 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1890 gc.globs = uentry_getGlobs (e);
1891 globSet_clear (gc.globs_used);
1892 gc.mods = uentry_getMods (e);
1894 usymtab_enterFunctionScope (e);
1895 sRef_enterFunctionScope ();
1898 bool context_inOldStyleScope(void)
1900 return (gc.kind == CX_OLDSTYLESCOPE);
1904 context_enterOldStyleScope (void)
1906 gc.kind = CX_OLDSTYLESCOPE;
1907 DPRINTF (("Enter old style scope!"));
1908 usymtab_enterFunctionScope (uentry_undefined);
1912 context_completeOldStyleFunction (uentry e)
1914 llassert (gc.kind == CX_OLDSTYLESCOPE);
1916 gc.kind = CX_FUNCTION;
1919 DPRINTF (("Enter function: %s", uentry_unparse (e)));
1921 if (uentry_hasAccessType (e))
1923 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1931 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1932 typeIdSet_unparse (gc.acct)));
1934 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1936 if (!globSet_isEmpty (uentry_getGlobs (e)))
1938 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1939 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1942 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1944 gc.globs = uentry_getGlobs (e);
1945 globSet_clear (gc.globs_used);
1947 gc.mods = uentry_getMods (e);
1949 if (!sRefSet_isEmpty (gc.mods))
1951 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
1952 fileloc_unparse (g_currentloc), uentry_unparse (e)));
1955 sRef_enterFunctionScope ();
1958 static bool context_checkStrictGlobals (void)
1960 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1963 static bool context_hasGlobs (void)
1965 if (context_inFunctionLike ())
1967 return (uentry_hasGlobs (gc.cont.fcn));
1975 static bool context_checkCheckedGlobals (void)
1977 return (context_getFlag (FLG_GLOBALS)
1978 && (context_getFlag (FLG_GLOBUNSPEC)
1979 || context_hasGlobs ()));
1982 static bool context_checkUnknownGlobals (void)
1984 /* should be uentry_hasGlobs ? */
1986 return (context_getFlag (FLG_ALLGLOBALS)
1987 && (context_getFlag (FLG_GLOBUNSPEC)
1988 || context_hasGlobs ()));
1991 static bool context_checkUncheckedGlobals (void)
1997 context_checkExport (uentry e)
1999 if (!gc.anyExports) return FALSE;
2001 if (uentry_isFunction (e)
2002 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
2004 return context_maybeSet (FLG_EXPORTFCN);
2006 else if (uentry_isExpandedMacro (e))
2008 return context_maybeSet (FLG_EXPORTMACRO);
2010 else if (uentry_isVariable (e))
2012 return context_maybeSet (FLG_EXPORTVAR);
2014 else if (uentry_isEitherConstant (e))
2016 return context_maybeSet (FLG_EXPORTCONST);
2018 else if (uentry_isIter (e) || uentry_isEndIter (e))
2020 return context_maybeSet (FLG_EXPORTITER);
2022 else if (uentry_isDatatype (e))
2024 return context_maybeSet (FLG_EXPORTTYPE);
2033 context_checkGlobUse (uentry glob)
2036 if (uentry_isCheckedStrict (glob))
2038 return context_checkStrictGlobals ();
2040 else if (uentry_isChecked (glob))
2042 return context_checkCheckedGlobals ();
2044 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
2046 return context_checkUnknownGlobals ();
2050 llassert (uentry_isUnchecked (glob));
2052 return context_checkUncheckedGlobals ();
2057 context_checkAliasGlob (uentry glob)
2059 if (uentry_isCheckedStrict (glob))
2061 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
2063 else if (uentry_isChecked (glob))
2065 return gc.flags[FLG_CHECKEDGLOBALIAS];
2067 else if (uentry_isCheckMod (glob))
2069 return gc.flags[FLG_CHECKMODGLOBALIAS];
2073 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
2075 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
2079 bool context_checkInternalUse (void)
2081 if (context_hasGlobs ())
2083 return (gc.flags[FLG_INTERNALGLOBS]);
2087 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
2092 context_checkGlobMod (sRef el)
2094 uentry ue = sRef_getUentry (el);
2096 /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */
2098 if (uentry_isCheckedModify (ue)
2099 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
2101 if (context_hasMods ())
2103 return (gc.flags[FLG_MODGLOBS]);
2107 if (uentry_isCheckedStrict (ue))
2109 return (gc.flags[FLG_MODGLOBSUNSPEC]);
2113 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
2119 if (context_hasMods ())
2121 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
2131 context_usedGlobal (/*@exposed@*/ sRef el)
2133 if (!globSet_member (gc.globs_used, el))
2136 ** The first time a global is used in a function, we need
2137 ** to clear the derived sRefs, since they were set for the
2138 ** previous function.
2141 sRef_clearDerived (el);
2142 gc.globs_used = globSet_insert (gc.globs_used, el);
2146 /*@observer@*/ sRefSet
2147 context_modList (void)
2153 context_globAccess (sRef s)
2155 llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s));
2156 return (globSet_member (gc.globs, s));
2160 context_hasAccess (typeId t)
2162 if (context_inFunctionLike ())
2164 DPRINTF (("Access %d / %s",
2165 t, typeIdSet_unparse (gc.acct)));
2166 return (typeIdSet_member (gc.acct, t));
2170 return (context_hasFileAccess (t));
2175 context_hasFileAccess (typeId t)
2177 return (typeIdSet_member (gc.facct, t));
2181 context_unparseAccess (void)
2183 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
2184 typeIdSet_unparse (gc.facct)));
2188 context_unparseClauses (void)
2190 return (clauseStack_unparse (gc.clauses));
2194 context_couldHaveAccess (typeId t)
2196 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
2198 return (typeIdSet_member (gc.acct, t));
2202 return (typeIdSet_member (gc.facct, t));
2207 context_getRetType (void)
2209 ctype f = ctype_undefined;
2211 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2213 f = uentry_getType (gc.cont.fcn);
2215 else if (gc.kind == CX_UNKNOWNMACRO)
2217 return ctype_unknown;
2221 llcontbuglit ("context_getRetType: not in a function context");
2222 return ctype_unknown;
2225 if (!ctype_isFunction (f))
2227 if (ctype_isKnown (f))
2229 llbuglit ("context_getRetType: not a function");
2232 return ctype_unknown;
2234 return (ctype_getReturnType (f));
2238 context_hasMods (void)
2240 if (context_inFunctionLike ())
2242 return (uentry_hasMods (gc.cont.fcn));
2251 context_exitAllClauses (void)
2253 while (!clauseStack_isEmpty (gc.clauses))
2255 clause el = clauseStack_top (gc.clauses);
2258 if (clause_isNone (el))
2260 usymtab_quietExitScope (g_currentloc);
2261 clauseStack_pop (gc.clauses);
2265 context_exitClausePlain ();
2269 clauseStack_clear (gc.clauses);
2270 gc.inclause = NOCLAUSE;
2274 context_exitAllClausesQuiet (void)
2276 while (!clauseStack_isEmpty (gc.clauses))
2278 clause el = clauseStack_top (gc.clauses);
2281 usymtab_quietExitScope (g_currentloc);
2282 clauseStack_pop (gc.clauses);
2285 clauseStack_clear (gc.clauses);
2286 gc.inclause = NOCLAUSE;
2290 void context_exitClauseSimp (void)
2293 context_setJustPopped ();
2294 clauseStack_pop (gc.clauses);
2295 gc.inclause = topClause (gc.clauses);
2299 void context_exitCaseClause (void)
2301 context_setJustPopped ();
2302 usymtab_popCaseBranch ();
2303 clauseStack_pop (gc.clauses);
2304 gc.inclause = topClause (gc.clauses);
2308 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2310 context_setJustPopped ();
2311 usymtab_popTrueBranch (pred, tbranch, gc.inclause); /* evans 2003-02-02?: was makeAlt */
2312 clauseStack_pop (gc.clauses);
2313 gc.inclause = topClause (gc.clauses);
2316 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2318 DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch)));
2320 if (gc.inclause != TRUECLAUSE)
2322 llparseerror (cstring_makeLiteral
2323 ("Likely parse error. Conditional clauses are inconsistent."));
2327 context_setJustPopped ();
2328 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2329 clauseStack_pop (gc.clauses);
2330 gc.inclause = topClause (gc.clauses);
2333 void context_exitIterClause (exprNode body)
2335 llassert (gc.inclause == ITERCLAUSE);
2337 context_setJustPopped ();
2339 if (context_getFlag (FLG_ITERLOOPEXEC))
2341 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2345 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2348 clauseStack_pop (gc.clauses);
2349 gc.inclause = topClause (gc.clauses);
2352 static void context_popCase (void) {
2354 ** If we are exiting an outer clause, sometimes still in a switch case.
2368 DPRINTF (("Popping case clause: %s",
2369 clauseStack_unparse (gc.clauses)));
2371 if (gc.inclause == CASECLAUSE) {
2372 context_exitCaseClause ();
2376 void context_exitWhileClause (exprNode pred, exprNode body)
2378 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2382 if (gc.inclause != WHILECLAUSE) {
2383 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2384 clauseStack_unparse (gc.clauses)));
2387 llassert (gc.inclause == WHILECLAUSE);
2389 context_setJustPopped ();
2393 ** predicate must be false after while loop (unless there are breaks)
2396 if (context_getFlag (FLG_WHILELOOPEXEC))
2398 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2402 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2406 usymtab_addGuards (invGuards);
2407 guardSet_free (invGuards);
2409 clauseStack_pop (gc.clauses);
2410 gc.inclause = topClause (gc.clauses);
2413 void context_exitDoWhileClause (exprNode pred)
2415 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2417 if (gc.inclause == CASECLAUSE) {
2418 /* handle Duff's device */
2419 clauseStack_pop (gc.clauses);
2420 gc.inclause = topClause (gc.clauses);
2423 llassert (gc.inclause == DOWHILECLAUSE);
2425 context_setJustPopped ();
2428 usymtab_addGuards (invGuards);
2429 guardSet_free (invGuards);
2431 clauseStack_pop (gc.clauses);
2432 gc.inclause = topClause (gc.clauses);
2435 void context_exitForClause (exprNode forPred, exprNode body)
2437 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2439 llassert (gc.inclause == FORCLAUSE);
2440 context_setJustPopped ();
2442 DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body)));
2445 ** Predicate must be false after for loop (unless there are breaks)
2448 if (context_getFlag (FLG_FORLOOPEXEC))
2450 DPRINTF (("Here: for loop exec"));
2451 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2455 if (context_getFlag (FLG_OBVIOUSLOOPEXEC)
2456 && exprNode_loopMustExec (forPred))
2458 DPRINTF (("Here: loop must exec"));
2459 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2463 DPRINTF (("Pop true branch:"));
2464 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2468 usymtab_addGuards (invGuards);
2469 guardSet_free (invGuards);
2470 clauseStack_pop (gc.clauses);
2471 gc.inclause = topClause (gc.clauses);
2474 static void context_exitClausePlain (void)
2476 llassert (gc.inclause != NOCLAUSE);
2478 if (gc.inclause == FALSECLAUSE)
2480 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2484 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2488 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2490 context_setJustPopped ();
2492 if (gc.inclause == FALSECLAUSE)
2494 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2496 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2498 clauseStack_pop (gc.clauses);
2499 gc.inclause = topClause (gc.clauses);
2503 context_exitTrueClause (pred, tbranch);
2508 context_returnFunction (void)
2510 usymtab_checkFinalScope (TRUE);
2514 context_exitFunction (void)
2516 DPRINTF (("Exit function: %s", context_unparse ()));
2518 if (!context_inFunction () && !context_inMacroConstant ()
2519 && !context_inUnknownMacro ()
2520 && !context_inIterDef () && !context_inIterEnd ())
2523 ** not a bug because of parse errors
2530 if (context_inMacro () && usymtab_inFunctionScope ())
2532 usymtab_exitScope (exprNode_undefined);
2535 if (uentry_hasGlobs (gc.cont.fcn))
2537 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2541 if (uentry_hasMods (gc.cont.fcn))
2543 if (context_getFlag (FLG_MUSTMOD))
2545 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2549 DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn)));
2552 ** clear file static modifies
2555 /* do this first to get unused error messages */
2557 usymtab_exitScope (exprNode_undefined);
2558 sRef_exitFunctionScope ();
2560 gc.showfunction = FALSE;
2561 gc.kind = CX_GLOBAL;
2562 gc.cont.glob = TRUE;
2564 gc.globs = globSet_new ();
2565 globSet_clear (gc.globs_used);
2566 gc.mods = sRefSet_new ();
2569 llassert (clauseStack_isEmpty (gc.clauses));
2570 llassert (gc.inclause == NOCLAUSE);
2571 DPRINTF (("After exit function: %s", context_unparse ()));
2575 context_quietExitFunction (void)
2577 while (gc.kind == CX_INNER)
2579 context_exitInnerPlain ();
2582 if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro ()
2583 && !context_inIterDef () && !context_inIterEnd ())
2588 usymtab_quietExitScope (g_currentloc);
2590 gc.showfunction = FALSE;
2591 gc.kind = CX_GLOBAL;
2592 gc.cont.glob = TRUE;
2594 gc.globs = globSet_new ();
2595 globSet_clear (gc.globs_used);
2596 gc.mods = sRefSet_new ();
2598 sRef_exitFunctionScope ();
2602 /*@observer@*/ uentryList
2603 context_getParams (void)
2605 if (context_inFunctionLike ())
2607 return (uentry_getParams (gc.cont.fcn));
2611 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2612 return uentryList_undefined;
2616 /*@observer@*/ globSet
2617 context_getUsedGlobs (void)
2619 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2620 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2622 return (gc.globs_used);
2626 context_moduleName ()
2628 return (fileloc_getBase (g_currentloc));
2631 /*@observer@*/ globSet
2632 context_getGlobs (void)
2634 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2635 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2641 context_addBoolAccess (void)
2643 cstring bname = context_getString (FLG_BOOLTYPE);
2644 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2646 addModuleAccess (cstring_copy (bname), boolt);
2648 /* for sys/types (perhaps, this is bogus!) */
2649 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2654 context_canAccessBool (void)
2661 static typeId boolType = typeId_invalid;
2663 if (typeId_isInvalid (boolType))
2665 boolType = usymtab_getTypeId (context_getBoolName ());
2668 if (typeId_isInvalid (boolType)) {
2671 return (typeIdSet_member (gc.acct, boolType));
2676 /* evs 2000-07-25: old version - replaced */
2679 context_boolImplementationType () {
2680 /* For now, this is bogus! */
2685 context_canAccessBool (void)
2687 static typeId boolType = typeId_invalid;
2689 if (typeId_isInvalid (boolType))
2691 boolType = usymtab_getTypeId (context_getBoolName ());
2694 if (!typeId_isInvalid (boolType))
2696 return context_hasAccess (boolType);
2707 context_setMessageAnnote (/*@only@*/ cstring s)
2709 llassert (cstring_isUndefined (gc.msgAnnote));
2714 context_hasMessageAnnote (void)
2716 return (cstring_isDefined (gc.msgAnnote));
2720 context_clearMessageAnnote (void)
2722 if (cstring_isDefined (gc.msgAnnote))
2724 cstring_free (gc.msgAnnote);
2725 gc.msgAnnote = cstring_undefined;
2730 context_getMessageAnnote (void)
2732 cstring st = gc.msgAnnote;
2734 gc.msgAnnote = cstring_undefined;
2739 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2741 llassert (sRef_isInvalid (gc.aliasAnnote));
2742 llassert (!sRef_sameName (s, t));
2744 gc.aliasAnnoteAls = t;
2748 context_hasAliasAnnote (void)
2750 return (sRef_isValid (gc.aliasAnnote));
2754 context_clearAliasAnnote (void)
2756 gc.aliasAnnote = sRef_undefined;
2760 context_getAliasAnnote (void)
2762 sRef ret = gc.aliasAnnote;
2763 sRef als = gc.aliasAnnoteAls;
2765 llassert (sRef_isValid (ret) && sRef_isValid (als));
2767 gc.aliasAnnote = sRef_undefined;
2768 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2772 context_recordFileModifies (sRefSet mods)
2774 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2778 context_recordFileGlobals (globSet mods)
2780 DPRINTF (("Recording file globals: %s", globSet_unparse (mods)));
2781 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2785 context_setCommentMarkerChar (char c)
2787 llassert (c != '\0');
2789 context_setValue (FLG_COMMENTCHAR, (int) c);
2793 context_getCommentMarkerChar (void)
2795 return ((char) context_getValue (FLG_COMMENTCHAR));
2799 context_setValue (flagcode flag, int val)
2801 int index = flagcode_valueIndex (flag);
2803 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2811 llerror_flagWarning (message ("Value for %s must be a positive "
2812 "number (given %d)",
2813 flagcode_unparse (flag), val));
2816 if (flag == FLG_LINELEN && val < MINLINELEN)
2818 llerror_flagWarning (message ("Value for %s must be at least %d (given %d)",
2819 flagcode_unparse (flag),
2825 case FLG_INCLUDENEST:
2826 case FLG_CONTROLNESTDEPTH:
2827 case FLG_STRINGLITERALLEN:
2828 case FLG_NUMSTRUCTFIELDS:
2829 case FLG_NUMENUMMEMBERS:
2830 case FLG_INDENTSPACES:
2833 llerror_flagWarning (message ("Value for %s must be a non-negative "
2834 "number (given %d)",
2835 flagcode_unparse (flag), val));
2844 DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val));
2845 gc.values[index] = val;
2849 context_setValueAndFlag (flagcode flag, int val)
2851 gc.flags[flag] = TRUE;
2852 context_setValue (flag, val);
2856 context_getValue (flagcode flag)
2858 int index = flagcode_valueIndex (flag);
2860 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2861 DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index]));
2862 return (gc.values[index]);
2866 context_getCounter (flagcode flag)
2868 int index = flagcode_valueIndex (flag);
2870 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2871 return (gc.counters[index]);
2875 context_incCounter (flagcode flag)
2877 int index = flagcode_valueIndex (flag);
2879 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2881 gc.counters[index]++;
2885 context_decCounter (flagcode flag)
2887 int index = flagcode_valueIndex (flag);
2889 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2890 gc.counters[index]--;
2893 bool context_showFunction (void)
2895 return (gc.showfunction);
2899 context_setString (flagcode flag, cstring val)
2901 int index = flagcode_stringIndex (flag);
2903 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2905 DPRINTF (("set string: %s", flagcode_unparse (flag)));
2909 case FLG_MESSAGESTREAM:
2910 case FLG_WARNINGSTREAM:
2911 case FLG_ERRORSTREAM:
2913 if (cstring_isDefined (val))
2917 if (osd_fileExists (val))
2919 if (context_getFlag (FLG_STREAMOVERWRITE))
2921 llfatalerror (message
2922 ("Output stream file %s would overwrite existing file. "
2923 "Use -streamoverwrite if you want to allow this.",
2928 fstream = fopen (cstring_toCharsSafe (val), "w");
2930 if (fstream == NULL)
2932 llfatalerror (message ("Unable to open output stream file %s for writing",
2937 ** This ensures fstream will be closed on exit.
2940 fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val));
2944 case FLG_MESSAGESTREAM:
2945 g_messagestream = fstream;
2946 /*@innerbreak@*/ break;
2947 case FLG_WARNINGSTREAM:
2948 g_warningstream = fstream;
2949 /*@innerbreak@*/ break;
2950 case FLG_ERRORSTREAM:
2951 g_errorstream = fstream;
2952 /*@innerbreak@*/ break;
2955 /*@-statetransfer@*/
2956 } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */
2959 case FLG_SYSTEMDIRS:
2961 llassert (cstring_isDefined (val));
2963 if (cstring_firstChar (val) == '\"')
2966 cstring tval = cstring_copy (cstring_suffix (val, 1));
2968 if (cstring_lastChar (tval) != '\"')
2970 int n = size_toInt (cstring_length (tval) - 1);
2972 while (isspace ((int) cstring_getChar (tval, size_fromInt (n))))
2977 if (cstring_getChar (tval, size_fromInt (n)) != '\"')
2980 (message ("Setting -systemdirs to string with unmatching quotes: %s", val));
2984 cstring otval = tval;
2985 tval = cstring_prefix (tval, size_fromInt (n));
2986 cstring_free (otval);
2990 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2991 DPRINTF (("val = %s", val));
2992 cstring_free (tval);
2993 cstring_free (oval);
3000 llassert (cstring_isDefined (val));
3002 if (cstring_length (val) == 0)
3005 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
3007 else if (cstring_lastChar (val) != CONNECTCHAR)
3009 val = cstring_appendChar (val, CONNECTCHAR);
3019 ; /* Okay not handle everything in this switch */
3022 } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */
3025 if (cstring_length (val) >= 1
3026 && cstring_firstChar (val) == '\"')
3028 llerror_flagWarning (message
3029 ("Setting %s to string beginning with \". You probably "
3030 "don't meant to have the \"'s.",
3031 flagcode_unparse (flag)));
3034 gc.strings[index] = val;
3037 static /*@exposed@*/ cstring
3038 context_exposeString (flagcode flag)
3040 int index = flagcode_stringIndex (flag);
3042 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
3043 return (gc.strings[index]);
3047 context_getString (flagcode flag)
3049 return (context_exposeString (flag));
3053 context_resetErrors (void)
3059 context_recordBug (void)
3065 context_numBugs (void)
3070 void context_initMod (void)
3071 /*@globals undef gc; @*/
3073 gc.kind = CX_GLOBAL;
3075 gc.savekind = CX_ERROR;
3076 gc.savecont.glob = FALSE;
3078 gc.instandardlib = FALSE;
3082 gc.linesprocessed = 0;
3083 gc.speclinesprocessed = 0;
3084 gc.insuppressregion = FALSE;
3085 gc.macroMissingParams = FALSE;
3086 gc.preprocessing = FALSE;
3087 gc.incommandline = FALSE;
3088 gc.mc = macrocache_create ();
3090 gc.maxmods = DEFAULTMAXMODS;
3091 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
3093 gc.library = FLG_ANSILIB;
3095 gc.locstack = filelocStack_new ();
3096 gc.modrecs = sRefSetList_undefined;
3097 gc.anyExports = FALSE;
3099 gc.ftab = fileTable_create ();
3100 gc.msgLog = messageLog_new ();
3101 gc.inimport = FALSE;
3102 gc.inDerivedFile = FALSE;
3103 gc.inheader = FALSE;
3104 gc.markers = flagMarkerList_new ();
3105 gc.cont.glob = TRUE;
3106 gc.showfunction = FALSE;
3107 gc.msgAnnote = cstring_undefined;
3108 gc.aliasAnnote = sRef_undefined;
3109 gc.aliasAnnoteAls = sRef_undefined;
3110 gc.boolType = ctype_bool;
3111 gc.mods = sRefSet_new ();
3113 gc.saveloc = fileloc_undefined;
3115 gc.inmacrocache = FALSE;
3116 gc.inclause = NOCLAUSE;
3117 gc.clauses = clauseStack_new ();
3118 gc.globs = globSet_new ();
3119 gc.nacct = typeIdSet_emptySet ();
3120 gc.acct = typeIdSet_emptySet ();
3121 gc.facct = typeIdSet_emptySet ();
3122 gc.savedFlags = FALSE;
3123 gc.pushloc = fileloc_undefined;
3124 gc.protectVars = FALSE;
3125 gc.justpopped = FALSE;
3126 gc.isNullGuarded = NO;
3127 gc.globs_used = globSet_undefined;
3131 gc.setGlobally[code] = FALSE;
3132 gc.setLocally[code] = FALSE;
3137 context_resetAllFlags ();
3139 assertSet (gc.flags); /* Can't use global in defines */
3140 assertSet (gc.saveflags);
3141 assertSet (gc.values);
3142 assertSet (gc.strings);
3144 conext_resetAllCounters ();
3145 assertSet (gc.counters);
3147 context_setMode (DEFAULT_MODE);
3149 gc.stateTable = metaStateTable_create ();
3150 gc.annotTable = annotationTable_create ();
3152 gc.inFunctionHeader = FALSE;
3154 DPRINTF (("Annotations: \n%s",
3155 cstring_toCharsSafe (annotationTable_unparse (gc.annotTable))));
3156 DPRINTF (("State: \n%s",
3157 cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable))));
3162 context_typeofZero (void)
3164 ctype ct = ctype_int;
3166 if (context_getFlag (FLG_ZEROPTR))
3168 ct = ctype_makeConj (ct, ctype_voidPointer);
3171 if (context_getFlag (FLG_ZEROBOOL)) {
3172 ct = ctype_makeConj (ct, ctype_bool);
3179 context_typeofOne (void)
3181 ctype ct = ctype_int;
3183 /* 1 is on longer a bool (was before 2.4)
3184 if (!context_getFlag (FLG_ABSTRACTBOOL))
3186 ct = ctype_makeConj (ct, ctype_bool);
3194 context_unparse (void)
3201 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
3204 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
3207 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
3210 s = message ("Inner Context [%d] : %q",
3212 fileloc_unparse (g_currentloc));
3215 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
3216 uentry_unparse (gc.cont.fcn),
3217 fileloc_unparse (g_currentloc),
3218 typeIdSet_unparse (gc.acct),
3219 sRefSet_unparse (gc.mods));
3222 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
3224 case CX_UNKNOWNMACRO:
3225 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
3228 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
3231 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
3234 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
3236 case CX_FCNDECLARATION:
3237 s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn));
3240 s = message ("Un-unparseable context: %d", (int) gc.kind);
3244 s = message ("%q\naccess: %q", s, context_unparseAccess ());
3249 context_currentFunctionType (void)
3251 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
3253 return (uentry_getType (gc.cont.fcn));
3255 else if (gc.kind == CX_INNER)
3257 llcontbuglit ("context_currentFunctionType: inner context");
3258 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
3259 return (context_currentFunctionType ());
3263 llcontbuglit ("context_currentFunctionType: not in function");
3264 return (ctype_undefined);
3269 context_enterInnerContext (void)
3271 if (context_getFlag (FLG_GRAMMAR))
3273 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3276 if (gc.kind == CX_GLOBAL)
3281 else if (gc.kind == CX_INNER)
3290 usymtab_enterScope ();
3291 pushClause (NOCLAUSE);
3295 context_exitInnerPlain (void) /*@modifies gc;@*/
3297 context_exitInner (exprNode_undefined);
3301 context_exitInner (exprNode exp)
3303 if (context_getFlag (FLG_GRAMMAR))
3305 lldiagmsg (message ("Enter inner context: %q", context_unparse ()));
3308 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
3309 ("inclause = %s", clause_nameTaken (gc.inclause)));
3311 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
3312 gc.inclause = topClause (gc.clauses);
3314 if (gc.kind == CX_INNER)
3316 if (--gc.cont.cdepth == 0)
3318 gc.kind = CX_GLOBAL;
3319 gc.cont.glob = TRUE;
3324 if (gc.kind == CX_GLOBAL)
3326 llcontbuglit ("Attempt to exit global context");
3331 usymtab_exitScope (exp);
3336 context_enterStructInnerContext (void)
3338 if (context_getFlag (FLG_GRAMMAR))
3340 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3343 if (gc.kind == CX_GLOBAL)
3348 else if (gc.kind == CX_INNER)
3357 usymtab_enterScope ();
3359 if (context_getFlag (FLG_GRAMMAR))
3361 lldiagmsg (message ("Enter struct inner context: %q", context_unparse ()));
3366 context_exitStructInnerContext (void)
3368 if (context_getFlag (FLG_GRAMMAR))
3370 lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3373 if (gc.kind == CX_INNER)
3375 if (gc.cont.cdepth <= 0)
3377 llcontbuglit ("Attempt to exit inner context with no depth");
3378 gc.kind = CX_GLOBAL;
3379 gc.cont.glob = TRUE;
3385 if (gc.cont.cdepth == 0)
3387 gc.kind = CX_GLOBAL;
3388 gc.cont.glob = TRUE;
3394 if (gc.kind == CX_GLOBAL)
3396 llcontbuglit ("Attempt to exit global context");
3401 usymtab_exitScope (exprNode_undefined);
3403 if (context_getFlag (FLG_GRAMMAR))
3405 lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth));
3410 context_exitInnerSafe (void)
3412 if (context_getFlag (FLG_GRAMMAR))
3414 lldiagmsg (message ("Exit inner safe: %q", context_unparse ()));
3417 if (gc.kind == CX_INNER)
3419 if (--gc.cont.cdepth <= 0)
3424 else if (gc.kind == CX_GLOBAL)
3426 llcontbuglit ("Attempt to exit global context");
3431 if (usymtab_inDeepScope ())
3433 usymtab_exitScope (exprNode_undefined);
3439 void setModuleAccess (void)
3441 gc.facct = typeIdSet_emptySet ();
3443 if (fileId_isValid (currentFile ()))
3445 cstring baseName = fileloc_getBase (g_currentloc);
3447 if (context_getFlag (FLG_ACCESSFILE))
3449 if (usymtab_existsType (baseName))
3451 gc.facct = typeIdSet_insert (gc.facct,
3452 usymtab_getTypeId (baseName));
3460 if (context_getFlag (FLG_ACCESSMODULE))
3463 bool hasaccess = FALSE;
3465 for (i = 0; i < gc.nmods; i++)
3467 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3469 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3478 gc.inheader = fileId_isHeader (currentFile ());
3482 llcontbuglit ("Current file not defined\n");
3483 gc.facct = typeIdSet_emptySet ();
3485 gc.inheader = FALSE;
3488 /* 17 Jan 1995: forgot to clear nacct */
3490 gc.nacct = typeIdSet_emptySet ();
3494 context_enterFileAux (void)
3500 context_enterFile (void)
3502 context_enterFileAux ();
3503 usymtab_enterFile ();
3507 context_enterMacroFile (void)
3509 context_enterFileAux ();
3513 context_inFunction (void)
3515 kcontext ck = gc.kind;
3517 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3521 context_inFunctionLike (void)
3523 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3524 || gc.kind == CX_FCNDECLARATION
3525 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3529 context_inRealFunction (void)
3531 kcontext ck = gc.kind;
3533 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3537 context_processAllMacros (void)
3539 usymtab_enterFile ();
3541 gc.inmacrocache = TRUE;
3542 macrocache_processUndefinedElements (gc.mc);
3544 usymtab_exitFile ();
3546 gc.inmacrocache = FALSE;
3547 macrocache_finalize ();
3551 ** this happens once at the end of each C file
3553 ** check each Macro that was defined in current file.c or current file.h
3558 context_processMacros (void)
3560 if (fileId_isValid (currentFile ()))
3563 cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ())));
3565 gc.inmacrocache = TRUE;
3567 DPRINTF (("Processing macros: %s", cbase));
3568 lastfl = macrocache_processFileElements (gc.mc, cbase);
3569 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3571 cstring_free (cbase);
3573 if (fileloc_isDefined (lastfl))
3575 g_currentloc = fileloc_update (g_currentloc, lastfl);
3579 gc.inmacrocache = FALSE;
3584 context_processingMacros (void)
3586 return (gc.inmacrocache);
3590 context_exitCFile (void)
3592 if (gc.kind != CX_GLOBAL)
3595 (cstring_makeLiteral ("File ended outside global scope"));
3598 if (gc.insuppressregion)
3600 /* gack...don't reverse the order of these lines! ;-> */
3601 gc.insuppressregion = FALSE;
3602 llerrorlit (FLG_SYNTAX,
3603 "File ended in ignore errors region, "
3604 "possible missing /*@end*/");
3607 /* fix up parse errors */
3609 while (!usymtab_inFileScope ())
3611 usymtab_quietExitScope (g_currentloc);
3615 ** Clear the file-specific modifies information.
3618 sRefSetList_elements (gc.modrecs, mods)
3620 sRefSet_clearStatics (mods);
3621 } end_sRefSetList_elements ;
3623 sRefSetList_clear (gc.modrecs);
3625 context_processMacros ();
3628 usymtab_exitFile ();
3630 gc.inDerivedFile = FALSE;
3631 filelocStack_clear (gc.locstack);
3633 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3635 gc.cont.glob = TRUE;
3639 context_restoreFlagSettings ();
3640 gc.savedFlags = FALSE;
3644 DPRINTF (("After exiting file: "));
3645 usymtab_printAll ();
3650 context_exitMacroCache (void)
3652 if (gc.kind != CX_GLOBAL)
3654 if (context_inMacro ())
3655 /* this is okay, file could end without newline in macro */
3657 DPRINTF (("Still in macro: %s",
3658 context_unparse ()));
3659 context_exitFunction ();
3663 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3664 context_unparse ()));
3665 gc.kind = CX_GLOBAL;
3670 ** no longer valid here
3671 ** if (gc.insuppressregion)
3673 ** gc.insuppressregion = FALSE;
3674 ** llerror ("File ended in ignore errors region, possible missing @");
3678 gc.cont.glob = TRUE;
3682 context_saveLocation (void)
3684 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3685 fileloc_free (gc.saveloc);
3686 gc.saveloc = fileloc_copy (g_currentloc);
3690 context_getSaveLocation (void)
3692 fileloc fl = gc.saveloc;
3693 gc.saveloc = fileloc_undefined;
3697 /*@observer@*/ cstring
3698 context_inFunctionName (void)
3700 if (gc.kind == CX_FUNCTION
3701 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3702 || gc.kind == CX_MACROCONST
3703 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3705 return (uentry_rawName (gc.cont.fcn));
3709 llcontbuglit ("context_inFunctionName: not in function");
3710 return (cstring_undefined);
3715 context_userSetFlag (flagcode f, bool b)
3717 DPRINTF (("set flag: %s / %s",
3718 flagcode_unparse (f),
3719 bool_unparse (context_getFlag (f))));
3721 if (f == FLG_NEVERINCLUDE && b)
3723 if (gc.flags[FLG_EXPORTHEADER])
3726 (cstring_makeLiteral
3727 ("Setting +neverinclude after +exportheader. "
3728 "Turning off exportheader, since headers are not checked "
3729 "when +neverinclude is used."));
3731 gc.flags[FLG_EXPORTHEADER] = FALSE;
3736 if (f == FLG_EXPORTHEADER && b)
3738 if (gc.flags[FLG_NEVERINCLUDE])
3741 (cstring_makeLiteral
3742 ("Setting +exportheader after +neverinclude. "
3743 "Not setting exportheader, since headers are not checked "
3744 "when +neverinclude is used."));
3745 gc.flags[FLG_EXPORTHEADER] = FALSE;
3751 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3753 bool lastsetting = context_getFlag (f);
3755 if (bool_equal (lastsetting, b)
3756 && !flagcode_isSpecialFlag (f)
3757 && !flagcode_isIdemFlag (f)
3758 && !flagcode_hasArgument (f))
3761 (message ("Setting %s%s redundant with current value",
3762 cstring_makeLiteralTemp (b ? "+" : "-"),
3763 flagcode_unparse (f)));
3767 if (flagcode_isWarnUseFlag (f) && b)
3769 if (!context_getFlag (FLG_WARNUSE))
3772 (message ("Flag +%s is canceled by -warnuse",
3773 flagcode_unparse (f)));
3778 if (flagcode_isLibraryFlag (f))
3780 if (gc.library != FLG_ANSILIB
3784 (message ("Selecting library %s after library %s was "
3785 "selected (only one library may be used)",
3786 flagcode_unparse (f),
3787 flagcode_unparse (gc.library)));
3790 if (f == FLG_UNIXLIB)
3792 if (context_getFlag (FLG_WARNUNIXLIB))
3795 (cstring_makeLiteral
3796 ("Selecting unix library. Unix library is "
3797 "based on the Single Unix Specification, Version 2. Not all "
3798 "Unix implementations are consistend with this specification. "
3799 "Use -warnunixlib to suppress this message."));
3806 if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS))
3810 ("Setting +%s will not produce warnings with -namechecks. "
3811 "Must set +namechecks also.",
3812 flagcode_unparse (f)));
3815 gc.setGlobally[f] = TRUE;
3816 context_setFlag (f, b, g_currentloc);
3820 context_fileSetFlag (flagcode f, ynm set, fileloc loc)
3824 context_saveFlagSettings ();
3827 if (ynm_isOff (set))
3829 context_setFlagAux (f, FALSE, TRUE, FALSE, loc);
3831 else if (ynm_isOn (set))
3833 context_setFlagAux (f, TRUE, TRUE, FALSE, loc);
3834 gc.setLocally[f] = TRUE;
3838 context_restoreFlag (f, loc);
3843 context_restoreFlag (flagcode f, fileloc loc)
3849 message ("Attempt to restore flag %s when no file scope flags "
3851 flagcode_unparse (f)),
3856 context_addFlagMarker (f, MAYBE, loc);
3857 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc);
3863 context_setFlag (flagcode f, bool b, fileloc loc)
3865 context_setFlagAux (f, b, FALSE, FALSE, loc);
3869 context_setFlagTemp (flagcode f, bool b)
3871 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3876 # define DOSET(ff,b) \
3877 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3878 context_addFlagMarker (ff, ynm_fromBool (b), loc); } \
3879 DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \
3880 gc.flags[ff] = b; } while (FALSE)
3883 context_setFlagAux (flagcode f, bool b, bool inFile,
3884 /*@unused@*/ bool isRestore, fileloc loc)
3886 DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3889 ** Removed test for special flags.
3892 if (flagcode_isIdemFlag (f))
3901 if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK)
3903 if (b) /* Turing higher level on, turns on all lower levels */
3907 case FLG_ITS4MOSTRISKY:
3908 DOSET (FLG_ITS4VERYRISKY, b);
3910 case FLG_ITS4VERYRISKY:
3911 DOSET (FLG_ITS4RISKY, b);
3914 DOSET (FLG_ITS4MODERATERISK, b);
3916 case FLG_ITS4MODERATERISK:
3917 DOSET (FLG_ITS4LOWRISK, b);
3919 case FLG_ITS4LOWRISK:
3924 else /* Turning level off, turns off all higher levels */
3928 case FLG_ITS4LOWRISK:
3929 DOSET (FLG_ITS4MODERATERISK, b);
3931 case FLG_ITS4MODERATERISK:
3932 DOSET (FLG_ITS4RISKY, b);
3935 DOSET (FLG_ITS4VERYRISKY, b);
3937 case FLG_ITS4VERYRISKY:
3938 DOSET (FLG_ITS4MOSTRISKY, b);
3940 case FLG_ITS4MOSTRISKY:
3949 case FLG_MESSAGESTREAMSTDOUT:
3950 g_messagestream = stdout;
3952 case FLG_MESSAGESTREAMSTDERR:
3953 g_messagestream = stderr;
3955 case FLG_WARNINGSTREAMSTDOUT:
3956 g_warningstream = stdout;
3958 case FLG_WARNINGSTREAMSTDERR:
3959 g_warningstream = stderr;
3961 case FLG_ERRORSTREAMSTDOUT:
3962 g_errorstream = stdout;
3964 case FLG_ERRORSTREAMSTDERR:
3965 g_errorstream = stderr;
3968 DOSET (FLG_ALLEMPTY, b);
3969 DOSET (FLG_IFEMPTY, b);
3970 DOSET (FLG_WHILEEMPTY, b);
3971 DOSET (FLG_FOREMPTY, b);
3974 DOSET (FLG_PREDBOOL, b);
3975 DOSET (FLG_PREDBOOLINT, b);
3976 DOSET (FLG_PREDBOOLPTR, b);
3977 DOSET (FLG_PREDBOOLOTHERS, b);
3980 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3981 DOSET (FLG_CHECKEDGLOBALIAS, b);
3982 DOSET (FLG_CHECKMODGLOBALIAS, b);
3983 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3986 DOSET (FLG_ALLBLOCK, b);
3987 DOSET (FLG_IFBLOCK, b);
3988 DOSET (FLG_WHILEBLOCK, b);
3989 DOSET (FLG_FORBLOCK, b);
4003 DOSET (FLG_GRAMMAR, b);
4005 case FLG_CODEIMPONLY:
4006 DOSET (FLG_CODEIMPONLY, b);
4007 DOSET (FLG_GLOBIMPONLY, b);
4008 DOSET (FLG_RETIMPONLY, b);
4009 DOSET (FLG_STRUCTIMPONLY, b);
4011 case FLG_SPECALLIMPONLY:
4012 DOSET (FLG_SPECALLIMPONLY, b);
4013 DOSET (FLG_SPECGLOBIMPONLY, b);
4014 DOSET (FLG_SPECRETIMPONLY, b);
4015 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4017 case FLG_ALLIMPONLY:
4018 DOSET (FLG_ALLIMPONLY, b);
4019 DOSET (FLG_GLOBIMPONLY, b);
4020 DOSET (FLG_RETIMPONLY, b);
4021 DOSET (FLG_STRUCTIMPONLY, b);
4022 DOSET (FLG_SPECGLOBIMPONLY, b);
4023 DOSET (FLG_SPECRETIMPONLY, b);
4024 DOSET (FLG_SPECSTRUCTIMPONLY, b);
4026 case FLG_ANSI89LIMITS:
4027 DOSET (FLG_ANSI89LIMITS, b);
4028 DOSET (FLG_CONTROLNESTDEPTH, b);
4029 DOSET (FLG_STRINGLITERALLEN, b);
4030 DOSET (FLG_INCLUDENEST, b);
4031 DOSET (FLG_NUMSTRUCTFIELDS, b);
4032 DOSET (FLG_NUMENUMMEMBERS, b);
4036 context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH);
4037 context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN);
4038 context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST);
4039 context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS);
4040 context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS);
4041 context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN);
4042 context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN);
4045 case FLG_ISO99LIMITS:
4046 DOSET (FLG_ISO99LIMITS, b);
4047 DOSET (FLG_CONTROLNESTDEPTH, b);
4048 DOSET (FLG_STRINGLITERALLEN, b);
4049 DOSET (FLG_INCLUDENEST, b);
4050 DOSET (FLG_NUMSTRUCTFIELDS, b);
4051 DOSET (FLG_NUMENUMMEMBERS, b);
4055 context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH);
4056 context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN);
4057 context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST);
4058 context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS);
4059 context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS);
4060 context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN);
4061 context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN);
4064 case FLG_EXTERNALNAMELEN:
4065 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4066 DOSET (FLG_EXTERNALNAMELEN, TRUE);
4068 case FLG_INTERNALNAMELEN:
4069 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4070 DOSET (FLG_INTERNALNAMELEN, TRUE);
4072 case FLG_EXTERNALNAMECASEINSENSITIVE:
4073 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
4075 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
4077 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
4078 context_setValue (FLG_EXTERNALNAMELEN, 0);
4081 case FLG_INTERNALNAMECASEINSENSITIVE:
4082 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
4084 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4086 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4087 context_setValue (FLG_INTERNALNAMELEN, 0);
4090 case FLG_INTERNALNAMELOOKALIKE:
4091 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
4093 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
4095 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
4096 context_setValue (FLG_INTERNALNAMELEN, 0);
4100 DOSET (FLG_MODNOMODS, b);
4101 DOSET (FLG_MODGLOBSUNSPEC, b);
4102 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
4105 DOSET (FLG_EXPORTVAR, b);
4106 DOSET (FLG_EXPORTFCN, b);
4107 DOSET (FLG_EXPORTTYPE, b);
4108 DOSET (FLG_EXPORTMACRO, b);
4109 DOSET (FLG_EXPORTCONST, b);
4110 gc.anyExports = TRUE;
4113 DOSET (FLG_RETEXPOSE, b);
4114 DOSET (FLG_ASSIGNEXPOSE, b);
4115 DOSET (FLG_CASTEXPOSE, b);
4118 DOSET (FLG_RETVALBOOL, b);
4119 DOSET (FLG_RETVALINT, b);
4120 DOSET (FLG_RETVALOTHER, b);
4125 DOSET (FLG_EXPORTLOCAL, FALSE);
4126 DOSET (FLG_DECLUNDEF, FALSE);
4127 DOSET (FLG_SPECUNDEF, FALSE);
4128 DOSET (FLG_TOPUNUSED, FALSE);
4132 DOSET (FLG_LOOPLOOPBREAK, b);
4133 DOSET (FLG_LOOPSWITCHBREAK, b);
4134 DOSET (FLG_SWITCHLOOPBREAK, b);
4135 DOSET (FLG_SWITCHSWITCHBREAK, b);
4136 DOSET (FLG_LOOPLOOPCONTINUE, b);
4137 DOSET (FLG_DEEPBREAK, b);
4140 DOSET (FLG_FORLOOPEXEC, b);
4141 DOSET (FLG_WHILELOOPEXEC, b);
4142 DOSET (FLG_ITERLOOPEXEC, b);
4145 DOSET (FLG_ACCESSMODULE, b);
4146 DOSET (FLG_ACCESSFILE, b);
4147 DOSET (FLG_ACCESSCZECH, b);
4150 DOSET (FLG_ALLMACROS, b);
4151 DOSET (FLG_FCNMACROS, b);
4152 DOSET (FLG_CONSTMACROS, b);
4155 DOSET (FLG_BOUNDSREAD, b);
4156 DOSET (FLG_BOUNDSWRITE, b);
4157 DOSET (FLG_LIKELYBOUNDSREAD, b);
4158 DOSET (FLG_LIKELYBOUNDSWRITE, b);
4160 case FLG_BOUNDSREAD:
4161 DOSET (FLG_LIKELYBOUNDSREAD, b);
4163 case FLG_BOUNDSWRITE:
4164 DOSET (FLG_LIKELYBOUNDSWRITE, b);
4166 case FLG_LIKELYBOUNDS:
4167 DOSET (FLG_LIKELYBOUNDSREAD, b);
4168 DOSET (FLG_LIKELYBOUNDSWRITE, b);
4172 if (b) { DOSET (FLG_ACCESSCZECH, b); }
4173 DOSET (FLG_CZECHFUNCTIONS, b);
4174 DOSET (FLG_CZECHVARS, b);
4175 DOSET (FLG_CZECHCONSTANTS, b);
4176 DOSET (FLG_CZECHTYPES, b);
4179 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
4180 DOSET (FLG_SLOVAKFUNCTIONS, b);
4181 DOSET (FLG_SLOVAKVARS, b);
4182 DOSET (FLG_SLOVAKCONSTANTS, b);
4183 DOSET (FLG_SLOVAKTYPES, b);
4185 case FLG_CZECHOSLOVAK:
4186 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
4187 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
4188 DOSET (FLG_CZECHOSLOVAKVARS, b);
4189 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
4190 DOSET (FLG_CZECHOSLOVAKTYPES, b);
4193 DOSET (FLG_NULLSTATE, b);
4194 DOSET (FLG_NULLDEREF, b);
4195 DOSET (FLG_NULLASSIGN, b);
4196 DOSET (FLG_NULLPASS, b);
4197 DOSET (FLG_NULLRET, b);
4200 DOSET (FLG_MUSTFREEONLY, b);
4201 DOSET (FLG_MUSTFREEFRESH, b);
4204 DOSET (FLG_NULLSTATE, b);
4205 DOSET (FLG_NULLDEREF, b);
4206 DOSET (FLG_NULLASSIGN, b);
4207 DOSET (FLG_NULLPASS, b);
4208 DOSET (FLG_NULLRET, b);
4209 DOSET (FLG_COMPDEF, b);
4210 DOSET (FLG_COMPMEMPASS, b);
4211 DOSET (FLG_UNIONDEF, b);
4212 DOSET (FLG_MEMTRANS, b);
4213 DOSET (FLG_USERELEASED, b);
4214 DOSET (FLG_ALIASUNIQUE, b);
4215 DOSET (FLG_MAYALIASUNIQUE, b);
4216 DOSET (FLG_MUSTFREEONLY, b);
4217 DOSET (FLG_MUSTFREEFRESH, b);
4218 DOSET (FLG_MUSTDEFINE, b);
4219 DOSET (FLG_GLOBSTATE, b);
4220 DOSET (FLG_COMPDESTROY, b);
4221 DOSET (FLG_MUSTNOTALIAS, b);
4222 DOSET (FLG_MEMIMPLICIT, b);
4223 DOSET (FLG_BRANCHSTATE, b);
4224 /*@fallthrough@*/ /* also sets memtrans flags */
4226 DOSET (FLG_MEMTRANS, b);
4227 DOSET (FLG_EXPOSETRANS, b);
4228 DOSET (FLG_OBSERVERTRANS, b);
4229 DOSET (FLG_DEPENDENTTRANS, b);
4230 DOSET (FLG_NEWREFTRANS, b);
4231 DOSET (FLG_ONLYTRANS, b);
4232 DOSET (FLG_OWNEDTRANS, b);
4233 DOSET (FLG_FRESHTRANS, b);
4234 DOSET (FLG_SHAREDTRANS, b);
4235 DOSET (FLG_TEMPTRANS, b);
4236 DOSET (FLG_KEPTTRANS, b);
4237 DOSET (FLG_REFCOUNTTRANS, b);
4238 DOSET (FLG_STATICTRANS, b);
4239 DOSET (FLG_UNKNOWNTRANS, b);
4240 DOSET (FLG_KEEPTRANS, b);
4241 DOSET (FLG_IMMEDIATETRANS, b);
4248 if (b && !gc.anyExports
4249 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
4250 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
4251 || f == FLG_EXPORTCONST
4252 || f == FLG_EXPORTANY))
4254 gc.anyExports = TRUE;
4259 context_maybeSet (flagcode d)
4261 return (gc.flags[d] || gc.setLocally[d]);
4265 context_getFlag (flagcode d)
4267 return (gc.flags[d]);
4271 context_flagOn (flagcode f, fileloc loc)
4273 return (!context_suppressFlagMsg (f, loc));
4276 static void context_saveFlagSettings (void)
4278 gc.savedFlags = TRUE;
4279 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4280 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
4283 static void context_restoreFlagSettings (void)
4285 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
4286 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
4287 gc.savedFlags = FALSE;
4290 void context_setFilename (fileId fid, int lineno)
4291 /*@globals fileloc g_currentloc;@*/
4292 /*@modifies g_currentloc@*/
4294 if (fileId_baseEqual (currentFile (), fid))
4301 fileloc_setColumn (g_currentloc, 0);
4303 if (fileloc_isSpecialFile (g_currentloc))
4305 gc.inDerivedFile = TRUE;
4308 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
4310 int maxdepth = context_getValue (FLG_INCLUDENEST);
4312 if (filelocStack_size (gc.locstack) > maxdepth)
4314 int depth = filelocStack_includeDepth (gc.locstack);
4316 if (depth > maxdepth)
4320 message ("Maximum include nesting depth "
4321 "(%d, current depth %d) exceeded",
4324 filelocStack_nextTop (gc.locstack)))
4326 filelocStack_printIncludes (gc.locstack);
4332 g_currentloc = fileloc_create (fid, lineno, 1);
4333 gc.inheader = fileId_isHeader (currentFile ());
4335 context_enterFileAux ();
4339 void context_enterIterDef (/*@observer@*/ uentry le)
4341 context_enterMacro (le);
4342 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
4343 gc.kind = CX_ITERDEF;
4346 void context_enterIterEnd (/*@observer@*/ uentry le)
4348 context_enterMacro (le);
4349 gc.kind = CX_ITEREND;
4353 context_destroyMod (void)
4354 /*@globals killed gc@*/
4358 ctype_destroyMod ();
4365 fileTable_free (gc.ftab);
4366 gc.ftab = fileTable_undefined;
4368 filelocStack_free (gc.locstack);
4371 macrocache_free (gc.mc);
4373 /* evans 2002-07-12: not reported because of reldef */
4374 for (i = 0; i < gc.nmods; i++)
4376 cstring_free (gc.moduleaccess[i].file);
4379 sfree (gc.moduleaccess);
4382 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
4383 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
4386 sRefSetList_free (gc.modrecs);
4388 flagMarkerList_free (gc.markers);
4390 messageLog_free (gc.msgLog);
4392 clauseStack_free (gc.clauses);
4395 cstring_free (gc.msgAnnote);
4396 globSet_free (gc.globs_used);
4397 metaStateTable_free (gc.stateTable);
4398 annotationTable_free (gc.annotTable);
4405 bool context_msgBoolInt (void)
4407 return context_flagOn (FLG_BOOLINT, g_currentloc);
4410 bool context_msgCharInt (void)
4412 return context_flagOn (FLG_CHARINT, g_currentloc);
4415 bool context_msgEnumInt (void)
4417 return context_flagOn (FLG_ENUMINT, g_currentloc);
4420 bool context_msgLongInt (void)
4422 return context_flagOn (FLG_LONGINT, g_currentloc);
4425 bool context_msgShortInt (void)
4427 return context_flagOn (FLG_SHORTINT, g_currentloc);
4430 bool context_msgPointerArith (void)
4432 return context_flagOn (FLG_POINTERARITH, g_currentloc);
4435 bool context_msgStrictOps (void)
4437 return context_flagOn (FLG_STRICTOPS, g_currentloc);
4440 bool context_msgLh (void)
4442 return gc.flags [FLG_DOLH];
4445 void context_pushLoc (void)
4447 fileloc_free (gc.pushloc);
4448 gc.pushloc = gc.saveloc;
4449 gc.saveloc = fileloc_undefined;
4452 void context_popLoc (void)
4454 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
4457 bool context_inGlobalScope (void)
4459 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
4462 bool context_inInnerScope (void)
4464 return (gc.kind == CX_INNER);
4467 void context_setProtectVars (void)
4469 gc.protectVars = TRUE;
4472 bool context_anyErrors (void)
4474 return (gc.numerrors > 0);
4477 void context_hasError (void)
4480 DPRINTF (("num errors: %d", gc.numerrors));
4483 int context_numErrors (void)
4485 return gc.numerrors;
4488 bool context_neednl (void)
4493 void context_setNeednl (void)
4498 int context_getExpect (void)
4500 return (context_getValue (FLG_EXPECT));
4503 int context_getLCLExpect (void)
4505 return (context_getValue (FLG_LCLEXPECT));
4508 int context_getLimit (void)
4510 return (context_getValue (FLG_LIMIT));
4513 bool context_unlimitedMessages (void)
4515 return (context_getLimit () < 0);
4518 void context_releaseVars (void)
4520 llassert (gc.protectVars);
4521 gc.protectVars = FALSE;
4524 void context_sizeofReleaseVars (void)
4526 /* If there is a nested sizeof, this might not hold:
4527 llassert (gc.protectVars);
4530 gc.protectVars = FALSE;
4533 bool context_inProtectVars (void)
4535 return (gc.protectVars);
4538 void context_hideShowscan (void)
4540 gc.flags[FLG_SHOWSCAN] = FALSE;
4543 void context_unhideShowscan (void)
4545 gc.flags[FLG_SHOWSCAN] = TRUE;
4548 bool context_inHeader (void)
4550 return (gc.inheader);
4553 fileTable context_fileTable (void)
4558 cstring context_tmpdir (void)
4560 return (context_getString (FLG_TMPDIR));
4563 messageLog context_messageLog (void)
4568 bool context_inMacroFunction (void)
4570 return (gc.kind == CX_MACROFCN);
4573 bool context_inMacroConstant (void)
4575 return (gc.kind == CX_MACROCONST);
4578 bool context_inUnknownMacro (void)
4580 return (gc.kind == CX_UNKNOWNMACRO);
4583 void context_setShownFunction (void)
4585 gc.showfunction = FALSE;
4588 bool context_doDump (void)
4590 return cstring_isNonEmpty (context_getString (FLG_DUMP));
4593 bool context_doMerge (void)
4595 return cstring_isNonEmpty (context_getString (FLG_MERGE));
4598 cstring context_getDump (void)
4600 return context_getString (FLG_DUMP);
4603 cstring context_getMerge (void)
4605 return context_getString (FLG_MERGE);
4608 bool context_inLCLLib (void)
4610 return (gc.kind == CX_LCLLIB);
4614 /*drl add these 3/5/2003*/
4615 static bool inSizeof = FALSE;
4617 bool context_inSizeof (void)
4622 void context_enterSizeof (void)
4624 DPRINTF((message("context_enterSizeof ") ) );
4628 void context_leaveSizeof (void)
4630 DPRINTF((message("context_leaveSizeof ") ));
4633 /*end function added 3/5/2003*/
4636 bool context_inImport (void)
4638 return (gc.inimport);
4641 void context_enterImport (void)
4646 void context_leaveImport (void)
4648 gc.inimport = FALSE;
4651 bool context_inMacro (void)
4653 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4654 || gc.kind == CX_UNKNOWNMACRO
4655 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4658 bool context_inIterDef (void)
4660 return (gc.kind == CX_ITERDEF);
4663 bool context_inIterEnd (void)
4665 return (gc.kind == CX_ITEREND);
4668 int context_getLinesProcessed (void)
4670 return (gc.linesprocessed);
4673 int context_getSpecLinesProcessed (void)
4675 return (gc.speclinesprocessed);
4678 void context_processedSpecLine (void)
4680 gc.speclinesprocessed++;
4683 void context_resetSpecLines (void)
4685 gc.speclinesprocessed = 0;
4689 bool context_inGlobalContext (void)
4691 return (gc.kind == CX_GLOBAL);
4694 static void context_quietExitScopes (void)
4697 ** Try to restore the global scope (after an error).
4700 while (!usymtab_inFileScope ())
4702 usymtab_quietExitScope (g_currentloc);
4705 gc.cont.glob = TRUE;
4706 gc.kind = CX_GLOBAL;
4709 void context_checkGlobalScope (void)
4711 if (gc.kind != CX_GLOBAL)
4713 if (context_inMacro ())
4715 ; /* evans 2001-10-14: Okay to be in a macro here! */
4719 llcontbug (message ("Not in global scope as expected: %q", context_unparse ()));
4720 context_quietExitScopes ();
4725 void context_setFileId (fileId s)
4727 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4730 bool context_setBoolName (void)
4732 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4736 cstring context_printBoolName (void)
4738 if (context_setBoolName ())
4740 return context_getBoolName ();
4744 return cstring_makeLiteralTemp ("boolean");
4748 cstring context_getBoolName (void)
4750 return (context_getString (FLG_BOOLTYPE));
4753 cstring context_getFalseName (void)
4755 return (context_getString (FLG_BOOLFALSE));
4758 cstring context_getTrueName (void)
4760 return (context_getString (FLG_BOOLTRUE));
4763 cstring context_getLarchPath (void)
4765 return (context_getString (FLG_LARCHPATH));
4768 cstring context_getLCLImportDir (void)
4770 return (context_getString (FLG_LCLIMPORTDIR));
4773 static void context_setJustPopped (void)
4775 gc.justpopped = TRUE;
4778 void context_clearJustPopped (void)
4780 gc.justpopped = FALSE;
4783 bool context_justPopped (void)
4785 return (gc.justpopped);
4788 void context_setMacroMissingParams (void)
4790 gc.macroMissingParams = TRUE;
4793 void context_resetMacroMissingParams (void)
4795 gc.macroMissingParams = FALSE;
4798 bool context_isMacroMissingParams (void)
4800 return (gc.macroMissingParams);
4803 void context_showFilelocStack (void)
4805 filelocStack_printIncludes (gc.locstack);
4808 metaStateTable context_getMetaStateTable (void)
4810 return gc.stateTable;
4813 metaStateInfo context_lookupMetaStateInfo (cstring key)
4815 return metaStateTable_lookup (gc.stateTable, key);
4818 /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot)
4820 return annotationTable_lookup (gc.annotTable, annot);
4823 void context_addAnnotation (annotationInfo info)
4825 if (annotationTable_contains (gc.annotTable, annotationInfo_getName (info)))
4829 message ("Duplicate annotation declaration: %s", annotationInfo_getName (info)),
4830 annotationInfo_getLoc (info));
4832 annotationInfo_free (info);
4836 annotationTable_insert (gc.annotTable, info);
4840 void context_addMetaState (cstring mname, metaStateInfo msinfo)
4842 if (metaStateTable_contains (gc.stateTable, mname))
4846 message ("Duplicate metastate declaration: %s", mname),
4847 metaStateInfo_getLoc (msinfo));
4848 cstring_free (mname);
4849 metaStateInfo_free (msinfo);
4853 DPRINTF (("Adding meta state: %s", mname));
4854 metaStateTable_insert (gc.stateTable, mname, msinfo);
4858 valueTable context_createValueTable (sRef s, stateInfo info)
4860 if (metaStateTable_size (gc.stateTable) > 0)
4862 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4863 /* should use smaller value... */
4864 DPRINTF (("Value table for: %s", sRef_unparse (s)));
4866 metaStateTable_elements (gc.stateTable, msname, msi)
4868 mtContextNode context = metaStateInfo_getContext (msi);
4870 if (mtContextNode_matchesRefStrict (context, s))
4872 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4873 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4877 cstring_copy (metaStateInfo_getName (msi)),
4878 stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s),
4879 stateInfo_copy (info)));
4883 DPRINTF (("No match: %s", metaStateInfo_unparse (msi)));
4886 end_metaStateTable_elements ;
4888 stateInfo_free (info);
4889 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4894 stateInfo_free (info);
4895 return valueTable_undefined;
4899 valueTable context_createGlobalMarkerValueTable (stateInfo info)
4901 if (metaStateTable_size (gc.stateTable) > 0)
4903 valueTable res = valueTable_create (metaStateTable_size (gc.stateTable));
4904 /* should use smaller value... */
4906 metaStateTable_elements (gc.stateTable, msname, msi)
4908 /* only add global...*/
4909 DPRINTF (("Create: %s", metaStateInfo_unparse (msi)));
4910 llassert (cstring_equal (msname, metaStateInfo_getName (msi)));
4912 valueTable_insert (res,
4913 cstring_copy (metaStateInfo_getName (msi)),
4914 stateValue_create (metaStateInfo_getDefaultGlobalValue (msi),
4915 stateInfo_copy (info)));
4917 end_metaStateTable_elements ;
4919 stateInfo_free (info);
4920 DPRINTF (("Value table: %s", valueTable_unparse (res)));
4925 stateInfo_free (info);
4926 return valueTable_undefined;
4930 constraintList context_getImplicitFcnConstraints (uentry ue)
4932 constraintList ret = constraintList_makeNew ();
4933 uentryList params = uentry_getParams (ue);
4935 uentryList_elements (params, el)
4937 DPRINTF (("setImplicitfcnConstraints doing: %s", uentry_unparse(el)));
4939 if (uentry_isElipsisMarker (el))
4945 sRef s = uentry_getSref (el);
4947 DPRINTF (("Trying: %s", sRef_unparse (s)));
4949 if (ctype_isPointer (sRef_getType (s)))
4951 constraint c = constraint_makeSRefWriteSafeInt (s, 0);
4952 ret = constraintList_add (ret, c);
4954 /*drl 10/23/2002 added support for out*/
4956 if (!uentry_isOut(el))
4958 c = constraint_makeSRefReadSafeInt (s, 0);
4959 ret = constraintList_add (ret , c);
4964 DPRINTF (("%s is NOT a pointer", sRef_unparseFull (s)));
4967 } end_uentryList_elements;
4969 DPRINTF (("Returns ==> %s", constraintList_unparse (ret)));