2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
28 * Modified by Herbert 04/19/97:
29 * - added include for new header portab.h containing OS dependent stuff.
30 * - changed occurrances of '/' as path delimiters to macro from portab.h
31 * - changed the handling of the tmp directory -- will no longer always be
32 * ".", if possible, environment variables "TMP" or, if not set, "TMP",
33 * or, if not set "." will be used.
36 # include "lclintMacros.nf"
40 # include "usymtab_interface.h"
43 # include "exprChecks.h"
44 # include "filelocStack.h"
45 # include "fileIdList.h"
51 extern /*@external@*/ int yydebug;
61 CX_FUNCTION, CX_FCNDECL,
62 CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO,
63 CX_ITERDEF, CX_ITEREND,
67 static struct _context
70 int speclinesprocessed;
72 flagMarkerList markers;
75 ** used to record state where a macro must match a function name
76 ** (i.e., no params were listed in the macro definition
79 bool macroMissingParams BOOLBITS;
80 bool preprocessing BOOLBITS;
81 bool incommandline BOOLBITS;
82 bool insuppressregion BOOLBITS;
83 bool inDerivedFile BOOLBITS;
84 bool instandardlib BOOLBITS;
85 bool inimport BOOLBITS;
86 bool inheader BOOLBITS;
87 bool inmacrocache BOOLBITS;
88 bool protectVars BOOLBITS;
90 bool showfunction BOOLBITS;
91 bool savedFlags BOOLBITS;
92 bool justpopped BOOLBITS;
93 bool anyExports BOOLBITS;
106 filelocStack locstack;
109 /*@observer@*/ sRef aliasAnnote;
110 /*@observer@*/ sRef aliasAnnoteAls;
114 /*@observer@*/ sRefSet mods;
116 /* file access types */
119 /* local access types (this function) */
122 /* no access types (@noaccess) */
125 /*@observer@*/ globSet globs;
126 /*@only@*/ globSet globs_used;
130 /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */
136 bool flags[NUMFLAGS];
137 bool saveflags[NUMFLAGS];
138 bool setGlobally[NUMFLAGS];
139 bool setLocally[NUMFLAGS];
141 int values[NUMVALUEFLAGS];
142 int counters[NUMVALUEFLAGS];
144 o_cstring strings[NUMSTRINGFLAGS];
151 /*@dependent@*/ /*@exposed@*/ uentry fcn;
155 static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ;
156 static void context_restoreFlagSettings (void) /*@modifies gc@*/ ;
157 static void context_saveFlagSettings (void) /*@modifies gc@*/ ;
158 static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch)
160 static void context_exitClauseSimp (void) /*@modifies gc@*/ ;
161 static void context_exitClausePlain (void) /*@modifies gc@*/ ;
162 static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ;
163 static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ;
164 /*drl fix static */ void context_setFlag (flagcode p_f, bool p_b)
165 /*@modifies gc.flags@*/ ;
168 context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, bool p_isRestore)
169 /*@modifies gc.flags@*/ ;
171 static void context_restoreFlag (flagcode p_f) /*@modifies gc.flags@*/ ;
175 cstring context_unparseFlagMarkers ()
177 return (flagMarkerList_unparse (gc.markers));
180 void context_setPreprocessing (void)
182 llassert (!gc.preprocessing);
183 gc.preprocessing = TRUE;
186 void context_clearPreprocessing (void)
188 llassert (gc.preprocessing);
189 gc.preprocessing = FALSE;
192 bool context_isPreprocessing (void)
194 return gc.preprocessing;
197 void context_setInCommandLine (void)
199 llassert (!gc.incommandline);
200 gc.incommandline = TRUE;
203 void context_clearInCommandLine (void)
205 llassert (gc.incommandline);
206 gc.incommandline = FALSE;
209 bool context_isInCommandLine (void)
211 return gc.incommandline;
215 void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/
218 clauseStack_push (gc.clauses, c);
220 if (clause_isConditional (c)
221 && context_getFlag (FLG_CONTROLNESTDEPTH))
223 int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH);
224 int depth = clauseStack_controlDepth (gc.clauses);
226 if (depth == maxdepth + 1)
229 (FLG_CONTROLNESTDEPTH,
230 message ("Maximum control nesting depth "
239 clause topClause (clauseStack s) /*@*/
241 if (clauseStack_isEmpty (s)) return NOCLAUSE;
242 return ((clause) clauseStack_top (s));
246 context_addMacroCache (/*@only@*/ cstring def)
248 macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def);
252 context_addComment (/*@only@*/ cstring def)
254 macrocache_addComment (gc.mc, fileloc_copy (g_currentloc), def);
258 ** returns TRUE is fl is in ignore region, or region where -code
260 ** the logic is fuzzy...
264 context_inSuppressFlagZone (fileloc fl, flagcode code)
266 ynm ret = flagMarkerList_suppressError (gc.markers, code, fl);
269 if (ynm_isMaybe (ret))
277 res = !gc.saveflags[code];
281 res = !context_getFlag (code);
286 res = ynm_toBoolStrict (ret);
293 context_suppressSystemMsg (fileloc fl)
295 if (context_getFlag (FLG_SYSTEMDIRERRORS))
301 return (fileloc_isSystemFile (fl));
306 context_suppressFlagMsg (flagcode flag, fileloc fl)
308 if (context_suppressSystemMsg (fl))
313 /* want same object compare here */
315 if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile)
317 return (!context_getFlag (flag)
318 || context_inSuppressRegion ()
319 || context_inSuppressZone (fl)
320 || (gc.inDerivedFile && context_inSuppressFlagZone (fl, flag)));
324 return (context_inSuppressFlagZone (fl, flag));
329 context_suppressNotFlagMsg (flagcode flag, fileloc fl)
332 if (context_suppressSystemMsg (fl))
338 if (fl == g_currentloc)
339 /*@noaccess fileloc@*/
341 return (context_getFlag (flag) || context_inSuppressRegion ());
346 return (context_getFlag (flag) || context_inSuppressRegion ());
351 context_inSuppressZone (fileloc fl)
353 if (context_suppressSystemMsg (fl))
358 return (flagMarkerList_inIgnore (gc.markers, fl));
362 context_inSuppressRegion (void)
364 return (gc.insuppressregion);
368 context_enterSuppressRegion (void)
370 if (gc.insuppressregion)
372 gc.insuppressregion = FALSE; /* get this msg! */
374 ("%q: New ignore errors region entered while in ignore errors region",
375 fileloc_unparse (g_currentloc)));
378 gc.insuppressregion = TRUE;
379 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (g_currentloc));
383 context_addFlagMarker (flagcode code, ynm set)
385 flagMarkerList_add (gc.markers,
386 flagMarker_createLocalSet (code, set, g_currentloc));
390 context_enterSuppressLine (int count)
392 fileloc nextline = fileloc_copy (g_currentloc);
394 flagMarkerList_add (gc.markers,
395 flagMarker_createIgnoreCount (count, g_currentloc));
397 fileloc_nextLine (nextline);
398 flagMarkerList_add (gc.markers,
399 flagMarker_createIgnoreOff (nextline));
400 fileloc_free (nextline);
403 void context_checkSuppressCounts (void)
405 if (context_getFlag (FLG_SUPCOUNTS))
407 flagMarkerList_checkSuppressCounts (gc.markers);
411 void context_incLineno (void)
418 context_exitSuppressRegion (void)
420 if (!gc.insuppressregion)
422 llerrorlit (FLG_SYNTAX,
423 "End ignore errors in region while not ignoring errors");
426 gc.insuppressregion = FALSE;
427 flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (g_currentloc));
432 context_enterLCLfile (void)
435 gc.facct = typeIdSet_emptySet ();
440 addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods)
444 for (i = 0; i < gc.nmods; i++)
446 if (cstring_equal (gc.moduleaccess[i].file, fname))
448 gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods);
449 cstring_free (fname);
454 if (gc.nmods == gc.maxmods)
458 gc.maxmods = gc.maxmods + DEFAULTMAXMODS;
459 oldmods = gc.moduleaccess;
461 gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
463 for (i = 0; i < gc.nmods; i++)
465 gc.moduleaccess[i] = oldmods[i];
471 gc.moduleaccess[gc.nmods].file = fname;
472 gc.moduleaccess[gc.nmods].daccess = mods;
478 insertModuleAccess (cstring fname, typeId t)
482 for (i = 0; i < gc.nmods; i++)
484 if (cstring_equal (gc.moduleaccess[i].file, fname))
486 gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t);
491 addModuleAccess (cstring_copy (fname), typeIdSet_single (t));
496 context_exitLCLfile (void)
498 if (gc.kind != CX_LCLLIB)
501 removeExtension (cstring_toCharsSafe
502 (fileName (currentFile ())), ".lcl");
504 addModuleAccess (cstring_fromCharsO (removePath (lclname)), gc.facct);
506 mstring_free (lclname);
511 gc.facct = typeIdSet_emptySet ();
516 context_dumpModuleAccess (FILE *fout)
520 for (i = 0; i < gc.nmods; i++)
522 cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess);
524 fprintf (fout, "%s#%s@\n",
525 cstring_toCharsSafe (gc.moduleaccess[i].file),
526 cstring_toCharsSafe (td));
532 bool context_usingPosixLibrary ()
534 return (gc.library == FLG_POSIXLIB
535 || gc.library == FLG_POSIXSTRICTLIB
536 || gc.library == FLG_UNIXLIB
537 || gc.library == FLG_UNIXSTRICTLIB);
540 bool context_usingAnsiLibrary ()
542 return (gc.library != FLG_NOLIB);
545 flagcode context_getLibrary ()
550 void context_setLibrary (flagcode code)
555 /*@observer@*/ char *context_selectedLibrary ()
560 return LLSTRICTLIBS_NAME;
562 return LLPOSIXLIBS_NAME;
563 case FLG_POSIXSTRICTLIB:
564 return LLPOSIXSTRICTLIBS_NAME;
566 return LLUNIXLIBS_NAME;
567 case FLG_UNIXSTRICTLIB:
568 return LLUNIXSTRICTLIBS_NAME;
570 return LLSTDLIBS_NAME;
577 context_loadModuleAccess (FILE *in)
579 char *s = mstring_create (MAX_DUMP_LINE_LENGTH);
581 char *name = mstring_create (MAX_NAME_LENGTH);
587 while (fgets (s, MAX_DUMP_LINE_LENGTH, in) != NULL
593 while (s != NULL && *s != ';' && *s != '\0')
597 while (*s != '#' && *s != '\0')
606 llcontbug (message ("context_loadModuleAccess: bad library line: %s\n",
607 cstring_fromChars (s)));
613 addModuleAccess (cstring_copy (cstring_fromChars (oname)),
614 typeIdSet_undump (&s));
616 (void) fgets (s, MAX_DUMP_LINE_LENGTH, in);
617 llassert (s != lasts);
627 typeIdSet context_fileAccessTypes (void)
633 context_resetModeFlags (void)
638 if (flagcode_isModeFlag (code))
640 context_setFlag (code, FALSE);
649 ** Set all flags to FALSE, except for a few which are
652 ** Set all values and strings to appropriate defaults.
653 ** Set all counters to 0.
657 conext_resetAllCounters (void)
661 for (i = 0; i < NUMVALUEFLAGS; i++)
668 context_resetAllFlags (void)
672 gc.flags[code] = FALSE;
674 if (flagcode_hasValue (code))
678 /*@-loopswitchbreak@*/
682 val = DEFAULT_LIMIT; break;
684 val = DEFAULT_LINELEN; break;
685 case FLG_EXTERNALNAMELEN:
686 val = DEFAULT_EXTERNALNAMELEN; break;
687 case FLG_INTERNALNAMELEN:
688 val = DEFAULT_INTERNALNAMELEN; break;
689 case FLG_COMMENTCHAR:
690 val = (int) DEFAULT_COMMENTCHAR; break;
691 case FLG_CONTROLNESTDEPTH:
692 val = (int) DEFAULT_CONTROLNESTDEPTH; break;
693 case FLG_STRINGLITERALLEN:
694 val = (int) DEFAULT_STRINGLITERALLEN; break;
695 case FLG_INCLUDENEST:
696 val = (int) DEFAULT_INCLUDENEST; break;
697 case FLG_NUMSTRUCTFIELDS:
698 val = (int) DEFAULT_NUMSTRUCTFIELDS; break;
699 case FLG_NUMENUMMEMBERS:
700 val = (int) DEFAULT_NUMENUMMEMBERS; break;
705 llbug (message ("Bad value flag: %s", flagcode_unparse (code)));
707 /*@=loopswitchbreak@*/
709 context_setValue (code, val);
711 else if (flagcode_hasString (code))
713 cstring val = cstring_undefined;
716 { /*@-loopswitchbreak@*/
719 char *larchpath = osd_getEnvironmentVariable (LARCH_PATH);
721 if (larchpath != NULL)
723 val = cstring_fromCharsNew (larchpath);
727 val = cstring_makeLiteral (DEFAULT_LARCHPATH);
732 case FLG_LCLIMPORTDIR:
734 val = cstring_fromCharsNew (osd_getEnvironment (LCLIMPORTDIR, DEFAULT_LCLIMPORTDIR));
738 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
740 char *env = osd_getEnvironmentVariable ("TMP");
744 env = osd_getEnvironmentVariable ("TEMP");
747 val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR);
750 val = cstring_makeLiteral (DEFAULT_TMPDIR);
751 # endif /* !defined(OS2) && !defined(MSDOS) */
755 val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break;
757 val = cstring_makeLiteral ("FALSE"); break;
759 val = cstring_makeLiteral ("TRUE"); break;
760 case FLG_MACROVARPREFIX:
761 val = cstring_makeLiteral ("m_"); break;
763 val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break;
766 } /*@=loopswitchbreak@*/
768 context_setString (code, val);
772 ; /* nothing to set */
777 ** These flags are true by default.
780 gc.flags[FLG_MODIFIES] = TRUE;
781 gc.flags[FLG_NESTCOMMENT] = TRUE;
782 gc.flags[FLG_GLOBALS] = TRUE;
783 gc.flags[FLG_FULLINITBLOCK] = TRUE;
784 gc.flags[FLG_LIKELYBOOL] = TRUE;
785 gc.flags[FLG_ZEROPTR] = TRUE;
786 gc.flags[FLG_NUMLITERAL] = TRUE;
787 gc.flags[FLG_DUPLICATEQUALS] = TRUE;
788 gc.flags[FLG_SKIPANSIHEADERS] = TRUE;
789 gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE;
790 gc.flags[FLG_SYSTEMDIREXPAND] = TRUE;
791 gc.flags[FLG_UNRECOGCOMMENTS] = TRUE;
792 gc.flags[FLG_CASTFCNPTR] = TRUE;
793 gc.flags[FLG_DOLCS] = TRUE;
794 gc.flags[FLG_USEVARARGS] = TRUE;
795 gc.flags[FLG_MAINTYPE] = TRUE;
796 gc.flags[FLG_SPECMACROS] = TRUE;
797 gc.flags[FLG_REDEF] = TRUE;
798 gc.flags[FLG_MACRONEXTLINE] = TRUE;
800 gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE;
801 gc.flags[FLG_FIXEDFORMALARRAY] = TRUE;
803 gc.flags[FLG_PREDASSIGN] = TRUE;
804 gc.flags[FLG_MODOBSERVER] = TRUE;
805 gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE;
806 gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE;
808 gc.flags[FLG_PARAMIMPTEMP] = TRUE;
809 gc.flags[FLG_RETIMPONLY] = TRUE;
810 gc.flags[FLG_GLOBIMPONLY] = TRUE;
811 gc.flags[FLG_STRUCTIMPONLY] = TRUE;
812 gc.flags[FLG_PREPROC] = TRUE;
813 gc.flags[FLG_NAMECHECKS] = TRUE;
814 gc.flags[FLG_FORMATCODE] = TRUE;
815 gc.flags[FLG_FORMATTYPE] = TRUE;
816 gc.flags[FLG_BADFLAG] = TRUE;
817 gc.flags[FLG_WARNFLAGS] = TRUE;
818 gc.flags[FLG_WARNUNIXLIB] = TRUE;
819 gc.flags[FLG_WARNPOSIX] = TRUE;
820 gc.flags[FLG_SHOWCOL] = TRUE;
821 gc.flags[FLG_SHOWFUNC] = TRUE;
822 gc.flags[FLG_SUPCOUNTS] = TRUE;
823 gc.flags[FLG_HINTS] = TRUE;
824 gc.flags[FLG_SYNTAX] = TRUE;
825 gc.flags[FLG_TYPE] = TRUE;
826 gc.flags[FLG_INCOMPLETETYPE] = TRUE;
827 gc.flags[FLG_ABSTRACT] = TRUE;
828 gc.flags[FLG_ITER] = TRUE;
829 gc.flags[FLG_CONTROL] = TRUE;
830 gc.flags[FLG_UNRECOG] = TRUE;
831 gc.flags[FLG_SYSTEMUNRECOG] = TRUE;
832 gc.flags[FLG_LINTCOMMENTS] = TRUE;
833 gc.flags[FLG_ACCESSCZECH] = TRUE;
834 gc.flags[FLG_ACCESSMODULE] = TRUE;
835 gc.flags[FLG_ACCESSFILE] = TRUE;
836 gc.flags[FLG_MACROVARPREFIX] = TRUE;
839 ** Changed for version 2.4.
842 gc.flags[FLG_GNUEXTENSIONS] = TRUE;
845 ** On by default for Win32, but not Unix (to support MS/VC++ error message format).
849 gc.flags[FLG_PARENFILEFORMAT] = TRUE;
854 ** C is way-lame, and you can initialize an array to a constant except where
855 ** it is declared. Hence, a macro is used to set the modeflags.
859 # define SETFLAGS() \
860 { int i = 0; while (modeflags[i] != INVALID_FLAG) { \
861 if (!flagcode_isModeFlag (modeflags[i])) \
862 { llbug (message ("not a mode flag: %s", \
863 flagcode_unparse (modeflags[i]))); } \
864 else { context_setFlag (modeflags[i], TRUE); } i++; }}
867 context_setMode (cstring s)
869 intSet setflags = intSet_new ();
873 if (flagcode_isModeFlag (code))
875 if (gc.setGlobally[code])
877 (void) intSet_insert (setflags, (int) code);
882 if (!intSet_isEmpty (setflags))
884 cstring rflags = cstring_undefined;
887 intSet_elements (setflags, el)
889 if (cstring_isUndefined (rflags))
891 rflags = cstring_copy (flagcode_unparse ((flagcode) (el)));
895 rflags = message ("%q, %s", rflags,
896 flagcode_unparse ((flagcode) el));
900 if (num > 4 && intSet_size (setflags) > 6)
902 rflags = message ("%q, (%d others) ...", rflags,
903 intSet_size (setflags) - num);
906 } end_intSet_elements ;
908 voptgenerror (FLG_WARNFLAGS,
909 message ("Setting mode %s after setting mode flags will "
910 "override set values of flags: %s",
914 cstring_free (rflags);
917 intSet_free (setflags);
919 context_resetModeFlags ();
921 if (cstring_equalLit (s, "standard"))
923 flagcode modeflags[] =
925 FLG_ENUMINT, FLG_MACROMATCHNAME,
926 FLG_MACROUNDEF, FLG_RELAXQUALS,
927 FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
928 FLG_CHECKSTRICTGLOBALIAS,
929 FLG_CHECKEDGLOBALIAS,
930 FLG_CHECKMODGLOBALIAS,
931 FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT,
932 FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED,
934 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED,
935 FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_MUTREP,
936 FLG_NOEFFECT, FLG_IMPTYPE,
937 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
938 FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
940 FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS,
941 FLG_MACROSTMT, FLG_MACROPARENS,
944 FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE,
945 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
950 /* memchecks flags */
952 FLG_NULLSTATE, FLG_NULLASSIGN,
953 FLG_NULLPASS, FLG_NULLRET,
955 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
977 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
978 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
979 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
983 FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS,
985 FLG_IMPCHECKEDSPECGLOBALS,
986 FLG_MODGLOBS, FLG_WARNLINTCOMMENTS,
987 FLG_IFEMPTY, FLG_REALCOMPARE,
988 FLG_BOOLOPS, FLG_PTRNEGATE,
994 else if (cstring_equalLit (s, "weak"))
996 flagcode modeflags[] =
998 FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE,
999 FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL,
1000 FLG_CHARINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS,
1001 FLG_CHARUNSIGNEDCHAR,
1003 FLG_VARUNUSED, FLG_FUNCUNUSED,
1005 FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME,
1008 FLG_RETSTACK, FLG_PTRNEGATE,
1009 FLG_LONGUNSIGNEDINTEGRAL,
1010 FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL,
1019 else if (cstring_equalLit (s, "checks"))
1021 flagcode modeflags[] =
1023 FLG_EXPORTLOCAL, FLG_IMPTYPE,
1024 FLG_CHECKSTRICTGLOBALIAS,
1025 FLG_CHECKEDGLOBALIAS,
1026 FLG_CHECKMODGLOBALIAS,
1027 FLG_UNCHECKEDGLOBALIAS,
1028 FLG_EXITARG, FLG_PTRNUMCOMPARE,
1029 FLG_BOOLCOMPARE, FLG_MACROUNDEF,
1030 FLG_MUSTMOD, FLG_ALLGLOBALS,
1031 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1032 FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS,
1033 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1034 FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING,
1035 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED,
1036 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1037 FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1038 FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT,
1039 FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS,
1040 FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB,
1047 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1051 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1053 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE,
1054 FLG_EVALORDER, FLG_USEDEF,
1058 /* memchecks flags */
1060 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1061 FLG_NULLPASS, FLG_NULLRET,
1063 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK,
1065 /* memtrans flags */
1079 FLG_STATICINITTRANS,
1080 FLG_UNKNOWNINITTRANS,
1083 FLG_ONLYUNQGLOBALTRANS,
1084 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1085 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1086 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1089 FLG_NULLPOINTERARITH,
1090 FLG_SHADOW, FLG_DEPARRAYS,
1091 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1092 FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS,
1093 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1094 FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS,
1095 FLG_INCLUDENEST, FLG_ANSIRESERVED, FLG_CPPNAMES,
1096 FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE,
1097 FLG_BOOLOPS, FLG_SHIFTSIGNED,
1102 else if (cstring_equalLit (s, "strict"))
1104 flagcode modeflags[] =
1106 FLG_CHECKSTRICTGLOBALIAS,
1107 FLG_CHECKEDGLOBALIAS,
1108 FLG_CHECKMODGLOBALIAS,
1109 FLG_UNCHECKEDGLOBALIAS,
1112 FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD,
1113 FLG_ALLGLOBALS, FLG_IMPTYPE,
1114 FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC,
1115 FLG_GLOBUNSPEC, FLG_SIZEOFTYPE,
1116 FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR,
1117 FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG,
1120 FLG_ONLYUNQGLOBALTRANS,
1121 FLG_GLOBALSIMPMODIFIESNOTHING,
1122 FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT,
1123 FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS,
1124 FLG_USEALLGLOBS, FLG_RETALIAS,
1125 FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED,
1126 FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE,
1127 FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON,
1129 FLG_EXPORTITER, FLG_EXPORTCONST,
1130 FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED,
1131 FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED,
1133 FLG_NULLPOINTERARITH, FLG_POINTERARITH,
1135 FLG_BOOLCOMPARE, FLG_NOEFFECT,
1136 FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER,
1137 FLG_ANSIRESERVED, FLG_ANSIRESERVEDLOCAL, FLG_CPPNAMES,
1138 FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF,
1139 FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS,
1140 FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR,
1141 FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS,
1143 FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS,
1146 FLG_MACROREDEF, FLG_MACROEMPTY,
1147 FLG_INFLOOPS, FLG_INFLOOPSUNCON,
1149 FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF,
1151 FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT,
1152 FLG_MODOBSERVERUNCON,
1157 /* memchecks flags */
1158 FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN,
1159 FLG_NULLPASS, FLG_NULLRET,
1161 FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
1163 /* memtrans flags */
1179 FLG_STATICINITTRANS,
1180 FLG_UNKNOWNINITTRANS,
1182 FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE,
1183 FLG_MUSTFREE, FLG_MUSTDEFINE, FLG_GLOBSTATE,
1184 FLG_COMPDESTROY, FLG_MUSTNOTALIAS,
1188 FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH,
1190 FLG_SHADOW, FLG_DEPARRAYS,
1191 FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE,
1192 FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS,
1193 FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK,
1194 FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE,
1195 FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS,
1196 FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS,
1197 FLG_IMPCHECKEDSTRICTSTATICS,
1198 FLG_IMPCHECKEDSTRICTSPECGLOBALS,
1199 FLG_IMPCHECKMODINTERNALS,
1200 FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS,
1201 FLG_WARNLINTCOMMENTS, FLG_ANSIRESERVEDLOCAL,
1202 FLG_INCLUDENEST, FLG_STRINGLITERALLEN,
1203 FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS,
1204 FLG_CONTROLNESTDEPTH,
1205 FLG_FORBLOCK, FLG_WHILEBLOCK,
1206 FLG_FOREMPTY, FLG_WHILEEMPTY,
1207 FLG_IFEMPTY, FLG_IFBLOCK,
1209 FLG_REALCOMPARE, FLG_BOOLOPS,
1210 FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL,
1212 FLG_SHIFTSIGNED, FLG_BITWISEOPS,
1219 llcontbug (message ("context_setMode: bad mode: %s", s));
1224 context_isSpecialFile (cstring fname)
1226 char *ext = filenameExtension (cstring_toCharsSafe (fname));
1228 return (mstring_equal (ext, ".y")
1229 || mstring_equal (ext, ".l")
1230 || cstring_equalLit (fname, "lex.yy.c"));
1234 context_isSystemDir (cstring dir)
1236 cstring sysDirs = context_exposeString (FLG_SYSTEMDIRS);
1237 char *thisdir = cstring_toCharsSafe (sysDirs);
1238 char *nextdir = strchr (thisdir, SEPCHAR);
1240 if (nextdir != NULL)
1246 while (thisdir != NULL)
1248 DPRINTF (("Test: %s / %s", dir, thisdir));
1250 if (cstring_equalCanonicalPrefix (dir, thisdir))
1252 if (nextdir != NULL)
1254 *(nextdir - 1) = SEPCHAR;
1260 if (nextdir != NULL)
1262 *(nextdir - 1) = SEPCHAR;
1265 if (nextdir != NULL)
1268 nextdir = strchr (thisdir, SEPCHAR);
1270 if (nextdir != NULL)
1282 DPRINTF (("Returns FALSE"));
1287 context_addFileAccessType (typeId t)
1291 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1292 || gc.kind == CX_UNKNOWNMACRO)
1294 gc.acct = typeIdSet_insert (gc.acct, t);
1297 gc.facct = typeIdSet_insert (gc.facct, t);
1299 base = fileloc_getBase (g_currentloc);
1300 insertModuleAccess (base, t);
1301 DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct),
1302 typeIdSet_unparse (gc.acct)));
1306 context_removeFileAccessType (typeId t)
1308 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
1309 || gc.kind == CX_UNKNOWNMACRO)
1311 gc.acct = typeIdSet_removeFresh (gc.acct, t);
1314 gc.facct = typeIdSet_removeFresh (gc.facct, t);
1315 gc.nacct = typeIdSet_insert (gc.nacct, t);
1318 void context_enterFunctionDecl (void)
1320 llassert (gc.kind == CX_GLOBAL);
1321 gc.kind = CX_FCNDECL;
1324 void context_exitFunctionDecl (void)
1326 gc.kind = CX_GLOBAL;
1329 bool context_inFunctionDecl (void)
1331 return (gc.kind == CX_FCNDECL);
1335 context_enterMacro (/*@observer@*/ uentry e)
1337 context_enterFunction (e);
1338 gc.kind = CX_MACROFCN;
1342 context_enterUnknownMacro (/*@dependent@*/ uentry e)
1344 llassert (uentry_isFunction (e));
1345 context_enterFunction (e);
1346 gc.kind = CX_UNKNOWNMACRO;
1349 void context_enterAndClause (exprNode e)
1352 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1353 pushClause (ANDCLAUSE);
1356 void context_enterOrClause (exprNode e)
1358 usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e)));
1359 pushClause (ORCLAUSE);
1362 bool context_inDeepLoop (void)
1364 bool inLoop = FALSE;
1366 clauseStack_elements (gc.clauses, el)
1368 if (clause_isLoop (el))
1377 } end_clauseStack_elements;
1382 bool context_inDeepSwitch (void)
1384 bool inLoop = FALSE;
1386 clauseStack_elements (gc.clauses, el)
1388 if (clause_isSwitch (el))
1397 } end_clauseStack_elements;
1402 bool context_inDeepLoopSwitch (void)
1404 bool inLoop = FALSE;
1406 clauseStack_elements (gc.clauses, el)
1408 if (clause_isBreakable (el))
1417 } end_clauseStack_elements;
1422 clause context_breakClause (void)
1424 clauseStack_elements (gc.clauses, el)
1426 if (clause_isSwitch (el))
1430 else if (clause_isLoop (el))
1438 } end_clauseStack_elements;
1443 clause context_nextBreakClause (void)
1445 bool hasOne = FALSE;
1447 clauseStack_elements (gc.clauses, el)
1449 if (clause_isBreakable (el))
1460 } end_clauseStack_elements;
1465 bool context_inConditional (void)
1467 clauseStack_elements (gc.clauses, el)
1470 ** Should also include TRUECLAUSE and FALSECLAUSE, but need
1471 ** to distinguish if from ? for this
1474 if (clause_isBreakable (el) && (el != DOWHILECLAUSE))
1478 } end_clauseStack_elements;
1483 void context_exitAndClause (exprNode pred, exprNode tbranch)
1485 context_setJustPopped ();
1487 llassert (gc.inclause == ANDCLAUSE);
1489 usymtab_popAndBranch (pred, tbranch);
1490 clauseStack_pop (gc.clauses);
1491 gc.inclause = topClause (gc.clauses);
1494 void context_exitOrClause (exprNode pred, exprNode tbranch)
1496 context_setJustPopped ();
1498 llassert (gc.inclause == ORCLAUSE);
1500 usymtab_popOrBranch (pred, tbranch);
1501 clauseStack_pop (gc.clauses);
1502 gc.inclause = topClause (gc.clauses);
1505 static void context_enterCondClauseAux (clause cl)
1511 static void context_enterTrueAux (exprNode e, clause cl)
1514 usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e)));
1518 void context_enterIterClause (void)
1520 context_enterTrueAux (exprNode_undefined, ITERCLAUSE);
1523 void context_enterDoWhileClause (void)
1525 pushClause (DOWHILECLAUSE);
1528 void context_enterWhileClause (exprNode e)
1530 context_enterTrueAux (e, WHILECLAUSE);
1533 void context_enterForClause (exprNode e)
1535 context_enterTrueAux (e, FORCLAUSE);
1538 void context_enterTrueClause (exprNode e)
1540 context_enterTrueAux (e, TRUECLAUSE);
1543 void context_enterSwitch (exprNode e)
1546 usymtab_switchBranch (e);
1547 context_enterCondClauseAux (SWITCHCLAUSE);
1550 void context_exitSwitch (exprNode e, bool allpaths)
1552 usymtab_exitSwitch (e, allpaths);
1554 while (clause_isCase (clauseStack_top (gc.clauses)))
1556 clauseStack_pop (gc.clauses);
1559 context_exitClauseSimp ();
1562 void context_enterCaseClause (exprNode e)
1564 bool branch = FALSE;
1566 DPRINTF (("Enter case clause!"));
1568 branch = usymtab_newCase (exprNode_undefined, e);
1572 context_enterCondClauseAux (CASECLAUSE);
1576 static void context_enterFalseClauseAux (exprNode e, clause cl)
1579 usymtab_altBranch (guardSet_invert (exprNode_getGuards (e)));
1581 clauseStack_switchTop (gc.clauses, cl);
1584 void context_enterFalseClause (exprNode e)
1587 context_enterFalseClauseAux (e, FALSECLAUSE);
1591 context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e)
1593 gc.kind = CX_MACROCONST;
1595 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1597 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1601 usymtab_enterScope ();
1602 sRef_enterFunctionScope ();
1604 gc.globs = globSet_undefined;
1605 globSet_clear (gc.globs_used);
1606 gc.mods = sRefSet_undefined;
1609 uentry context_getHeader (void)
1611 if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST)))
1613 llfatalbug (message ("context_getHeader: bad call: %q",
1614 context_unparse ()));
1617 return (gc.cont.fcn);
1621 context_setFunctionDefined (fileloc loc)
1625 case CX_UNKNOWNMACRO:
1628 uentry_setFunctionDefined (gc.cont.fcn, loc);
1631 /* (not a bug because of parse errors) */
1637 context_enterFunction (/*@exposed@*/ uentry e)
1639 gc.kind = CX_FUNCTION;
1642 if (uentry_hasAccessType (e))
1644 gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)),
1652 DPRINTF (("Enter function: %s / %s", uentry_unparse (e),
1653 typeIdSet_unparse (gc.acct)));
1655 gc.showfunction = context_getFlag (FLG_SHOWFUNC);
1657 gc.globs = uentry_getGlobs (e);
1658 globSet_clear (gc.globs_used);
1659 gc.mods = uentry_getMods (e);
1661 usymtab_enterFunctionScope (e);
1662 sRef_enterFunctionScope ();
1665 static bool context_checkStrictGlobals (void)
1667 return (context_getFlag (FLG_CHECKSTRICTGLOBALS));
1670 static bool context_hasGlobs (void)
1672 if (context_inFunctionLike ())
1674 return (uentry_hasGlobs (gc.cont.fcn));
1682 static bool context_checkCheckedGlobals (void)
1684 return (context_getFlag (FLG_GLOBALS)
1685 && (context_getFlag (FLG_GLOBUNSPEC)
1686 || context_hasGlobs ()));
1689 static bool context_checkUnknownGlobals (void)
1691 /* should be uentry_hasGlobs ? */
1693 return (context_getFlag (FLG_ALLGLOBALS)
1694 && (context_getFlag (FLG_GLOBUNSPEC)
1695 || context_hasGlobs ()));
1698 static bool context_checkUncheckedGlobals (void)
1704 context_checkExport (uentry e)
1706 if (!gc.anyExports) return FALSE;
1708 if (uentry_isFunction (e)
1709 || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))))
1711 return context_maybeSet (FLG_EXPORTFCN);
1713 else if (uentry_isExpandedMacro (e))
1715 return context_maybeSet (FLG_EXPORTMACRO);
1717 else if (uentry_isVariable (e))
1719 return context_maybeSet (FLG_EXPORTVAR);
1721 else if (uentry_isEitherConstant (e))
1723 return context_maybeSet (FLG_EXPORTCONST);
1725 else if (uentry_isIter (e) || uentry_isEndIter (e))
1727 return context_maybeSet (FLG_EXPORTITER);
1729 else if (uentry_isDatatype (e))
1731 return context_maybeSet (FLG_EXPORTTYPE);
1740 context_checkGlobUse (uentry glob)
1743 if (uentry_isCheckedStrict (glob))
1745 return context_checkStrictGlobals ();
1747 else if (uentry_isChecked (glob))
1749 return context_checkCheckedGlobals ();
1751 else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob))
1753 return context_checkUnknownGlobals ();
1757 llassert (uentry_isUnchecked (glob));
1759 return context_checkUncheckedGlobals ();
1764 context_checkAliasGlob (uentry glob)
1766 if (uentry_isCheckedStrict (glob))
1768 return gc.flags[FLG_CHECKSTRICTGLOBALIAS];
1770 else if (uentry_isChecked (glob))
1772 return gc.flags[FLG_CHECKEDGLOBALIAS];
1774 else if (uentry_isCheckMod (glob))
1776 return gc.flags[FLG_CHECKMODGLOBALIAS];
1780 llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob));
1782 return gc.flags[FLG_UNCHECKEDGLOBALIAS];
1786 bool context_checkInternalUse (void)
1788 if (context_hasGlobs ())
1790 return (gc.flags[FLG_INTERNALGLOBS]);
1794 return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]);
1799 context_checkGlobMod (sRef el)
1801 uentry ue = sRef_getUentry (el);
1803 /* no: llassert (sRef_isGlobal (el)); also check local statics */
1805 if (uentry_isCheckedModify (ue)
1806 || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS])))
1808 if (context_hasMods ())
1810 return (gc.flags[FLG_MODGLOBS]);
1814 if (uentry_isCheckedStrict (ue))
1816 return (gc.flags[FLG_MODGLOBSUNSPEC]);
1820 return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]);
1826 if (context_hasMods ())
1828 return (gc.flags[FLG_MODGLOBSUNCHECKED]);
1838 context_usedGlobal (sRef el)
1840 if (!globSet_member (gc.globs_used, el))
1843 ** The first time a global is used in a function, we need
1844 ** to clear the derived sRefs, since they were set for the
1845 ** previous function.
1848 sRef_clearDerived (el);
1849 gc.globs_used = globSet_insert (gc.globs_used, el);
1853 /*@observer@*/ sRefSet
1854 context_modList (void)
1860 context_globAccess (sRef s)
1862 llassert (sRef_isGlobal (s) || sRef_isKindSpecial (s));
1863 return (globSet_member (gc.globs, s));
1867 context_hasAccess (typeId t)
1869 if (context_inFunctionLike ())
1871 return (typeIdSet_member (gc.acct, t));
1875 return (context_hasFileAccess (t));
1880 context_hasFileAccess (typeId t)
1882 return (typeIdSet_member (gc.facct, t));
1886 context_unparseAccess (void)
1888 return (message ("%q / %q", typeIdSet_unparse (gc.acct),
1889 typeIdSet_unparse (gc.facct)));
1893 context_unparseClauses (void)
1895 return (clauseStack_unparse (gc.clauses));
1899 context_couldHaveAccess (typeId t)
1901 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO)
1903 return (typeIdSet_member (gc.acct, t));
1907 return (typeIdSet_member (gc.facct, t));
1912 context_getRetType (void)
1914 ctype f = ctype_undefined;
1916 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
1918 f = uentry_getType (gc.cont.fcn);
1920 else if (gc.kind == CX_UNKNOWNMACRO)
1922 return ctype_unknown;
1926 llcontbuglit ("context_getRetType: not in a function context");
1927 return ctype_unknown;
1930 if (!ctype_isFunction (f))
1932 if (ctype_isKnown (f))
1934 llbuglit ("context_getRetType: not a function");
1937 return ctype_unknown;
1939 return (ctype_returnValue (f));
1943 context_hasMods (void)
1945 if (context_inFunctionLike ())
1947 return (uentry_hasMods (gc.cont.fcn));
1956 context_exitAllClauses (void)
1959 while (!clauseStack_isEmpty (gc.clauses))
1961 clause el = clauseStack_top (gc.clauses);
1965 if (clause_isNone (el))
1967 usymtab_quietExitScope (g_currentloc);
1968 clauseStack_pop (gc.clauses);
1972 context_exitClausePlain ();
1976 clauseStack_clear (gc.clauses);
1979 gc.inclause = NOCLAUSE;
1983 void context_exitClauseSimp (void)
1986 context_setJustPopped ();
1987 clauseStack_pop (gc.clauses);
1988 gc.inclause = topClause (gc.clauses);
1992 void context_exitCaseClause (void)
1994 context_setJustPopped ();
1995 usymtab_popCaseBranch ();
1996 clauseStack_pop (gc.clauses);
1997 gc.inclause = topClause (gc.clauses);
2001 void context_exitClauseAux (exprNode pred, exprNode tbranch)
2003 context_setJustPopped ();
2004 usymtab_popTrueBranch (pred, tbranch, gc.inclause);
2005 clauseStack_pop (gc.clauses);
2006 gc.inclause = topClause (gc.clauses);
2009 void context_exitTrueClause (exprNode pred, exprNode tbranch)
2011 if (gc.inclause != TRUECLAUSE)
2013 llparseerror (cstring_makeLiteral
2014 ("Likely parse error. Conditional clauses are inconsistent."));
2019 context_setJustPopped ();
2021 usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE);
2022 clauseStack_pop (gc.clauses);
2023 gc.inclause = topClause (gc.clauses);
2027 void context_exitIterClause (exprNode body)
2029 llassert (gc.inclause == ITERCLAUSE);
2031 context_setJustPopped ();
2033 if (context_getFlag (FLG_LOOPEXEC))
2035 usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE);
2039 usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE);
2042 clauseStack_pop (gc.clauses);
2043 gc.inclause = topClause (gc.clauses);
2046 static void context_popCase (void) {
2048 ** If we are exiting an outer clause, sometimes still in a switch case.
2062 DPRINTF (("Popping case clause: %s",
2063 clauseStack_unparse (gc.clauses)));
2065 if (gc.inclause == CASECLAUSE) {
2066 context_exitCaseClause ();
2070 void context_exitWhileClause (exprNode pred, exprNode body)
2072 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2076 if (gc.inclause != WHILECLAUSE) {
2077 DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause),
2078 clauseStack_unparse (gc.clauses)));
2081 llassert (gc.inclause == WHILECLAUSE);
2083 context_setJustPopped ();
2087 ** predicate must be false after while loop (unless there are breaks)
2090 if (context_getFlag (FLG_LOOPEXEC))
2092 usymtab_popTrueExecBranch (pred, body, WHILECLAUSE);
2096 usymtab_popTrueBranch (pred, body, WHILECLAUSE);
2100 usymtab_addGuards (invGuards);
2101 guardSet_free (invGuards);
2103 clauseStack_pop (gc.clauses);
2104 gc.inclause = topClause (gc.clauses);
2107 void context_exitDoWhileClause (exprNode pred)
2109 guardSet invGuards = guardSet_invert (exprNode_getGuards (pred));
2111 if (gc.inclause == CASECLAUSE) {
2112 /* handle Duff's device */
2113 clauseStack_pop (gc.clauses);
2114 gc.inclause = topClause (gc.clauses);
2117 llassert (gc.inclause == DOWHILECLAUSE);
2119 context_setJustPopped ();
2122 usymtab_addGuards (invGuards);
2123 guardSet_free (invGuards);
2125 clauseStack_pop (gc.clauses);
2126 gc.inclause = topClause (gc.clauses);
2129 void context_exitForClause (exprNode forPred, exprNode body)
2131 guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred));
2133 llassert (gc.inclause == FORCLAUSE);
2134 context_setJustPopped ();
2137 ** predicate must be false after while loop (unless there are breaks)
2140 if (context_getFlag (FLG_LOOPEXEC))
2142 usymtab_popTrueExecBranch (forPred, body, FORCLAUSE);
2146 usymtab_popTrueBranch (forPred, body, FORCLAUSE);
2149 usymtab_addGuards (invGuards);
2150 guardSet_free (invGuards);
2151 clauseStack_pop (gc.clauses);
2152 gc.inclause = topClause (gc.clauses);
2155 static void context_exitClausePlain (void)
2157 llassert (gc.inclause != NOCLAUSE);
2159 if (gc.inclause == FALSECLAUSE)
2161 context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined);
2165 context_exitClauseAux (exprNode_undefined, exprNode_undefined);
2170 void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch)
2173 context_setJustPopped ();
2175 if (gc.inclause == FALSECLAUSE)
2177 usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE);
2179 llassert (clauseStack_top (gc.clauses) == FALSECLAUSE);
2181 clauseStack_pop (gc.clauses);
2182 gc.inclause = topClause (gc.clauses);
2186 context_exitTrueClause (pred, tbranch);
2191 context_returnFunction (void)
2193 usymtab_checkFinalScope (TRUE);
2197 context_exitFunction (void)
2199 if (!context_inFunction () && !context_inMacroConstant ()
2200 && !context_inMacroUnknown ()
2201 && !context_inIterDef () && !context_inIterEnd ())
2204 ** not a bug because of parse errors
2209 if (context_inMacro () && usymtab_inFunctionScope ())
2211 usymtab_exitScope (exprNode_undefined);
2214 if (uentry_hasGlobs (gc.cont.fcn))
2216 exprChecks_checkUsedGlobs (gc.globs, gc.globs_used);
2220 if (uentry_hasMods (gc.cont.fcn))
2222 if (context_getFlag (FLG_MUSTMOD))
2224 exprNode_checkAllMods (gc.mods, gc.cont.fcn);
2229 ** clear file static modifies
2232 /* do this first to get unused error messages */
2234 usymtab_exitScope (exprNode_undefined);
2235 sRef_exitFunctionScope ();
2237 gc.showfunction = FALSE;
2238 gc.kind = CX_GLOBAL;
2239 gc.cont.glob = TRUE;
2241 gc.globs = globSet_new ();
2242 globSet_clear (gc.globs_used);
2243 gc.mods = sRefSet_new ();
2246 llassert (clauseStack_isEmpty (gc.clauses));
2247 llassert (gc.inclause == NOCLAUSE);
2251 context_quietExitFunction (void)
2253 while (gc.kind == CX_INNER)
2255 context_exitInnerPlain ();
2258 if (!context_inFunction () && !context_inMacroConstant () && !context_inMacroUnknown ()
2259 && !context_inIterDef () && !context_inIterEnd ())
2264 usymtab_quietExitScope (g_currentloc);
2266 gc.showfunction = FALSE;
2267 gc.kind = CX_GLOBAL;
2268 gc.cont.glob = TRUE;
2270 gc.globs = globSet_new ();
2271 globSet_clear (gc.globs_used);
2272 gc.mods = sRefSet_new ();
2274 sRef_exitFunctionScope ();
2278 /*@observer@*/ uentryList
2279 context_getParams (void)
2281 if (context_inFunctionLike ())
2283 return (uentry_getParams (gc.cont.fcn));
2287 llcontbug (message ("context_getParams: not in function: %q", context_unparse ()));
2288 return uentryList_undefined;
2292 /*@observer@*/ globSet
2293 context_getUsedGlobs (void)
2295 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2296 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2298 return (gc.globs_used);
2302 context_moduleName ()
2304 return (fileloc_getBase (g_currentloc));
2307 /*@observer@*/ globSet
2308 context_getGlobs (void)
2310 llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
2311 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
2317 context_addBoolAccess (void)
2319 cstring bname = context_getString (FLG_BOOLTYPE);
2320 typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname));
2322 addModuleAccess (cstring_copy (bname), boolt);
2324 /* for sys/types (perhaps, this is bogus!) */
2325 addModuleAccess (cstring_makeLiteral ("types"), boolt);
2330 context_canAccessBool (void)
2337 static typeId boolType = typeId_invalid;
2339 if (typeId_isInvalid (boolType))
2341 boolType = usymtab_getTypeId (context_getBoolName ());
2344 if (typeId_isInvalid (boolType)) {
2347 return (typeIdSet_member (gc.acct, boolType));
2352 /* evs 2000-07-25: old version - replaced */
2355 context_boolImplementationType () {
2356 /* For now, this is bogus! */
2361 context_canAccessBool (void)
2363 static typeId boolType = typeId_invalid;
2365 if (typeId_isInvalid (boolType))
2367 boolType = usymtab_getTypeId (context_getBoolName ());
2370 if (!typeId_isInvalid (boolType))
2372 return context_hasAccess (boolType);
2383 context_setMessageAnnote (/*@only@*/ cstring s)
2385 llassert (cstring_isUndefined (gc.msgAnnote));
2390 context_hasMessageAnnote (void)
2392 return (cstring_isDefined (gc.msgAnnote));
2396 context_clearMessageAnnote (void)
2398 if (cstring_isDefined (gc.msgAnnote))
2400 cstring_free (gc.msgAnnote);
2401 gc.msgAnnote = cstring_undefined;
2406 context_getMessageAnnote (void)
2408 cstring st = gc.msgAnnote;
2410 gc.msgAnnote = cstring_undefined;
2415 context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t)
2417 llassert (sRef_isInvalid (gc.aliasAnnote));
2418 llassert (!sRef_sameName (s, t));
2420 gc.aliasAnnoteAls = t;
2424 context_hasAliasAnnote (void)
2426 return (sRef_isValid (gc.aliasAnnote));
2430 context_clearAliasAnnote (void)
2432 gc.aliasAnnote = sRef_undefined;
2436 context_getAliasAnnote (void)
2438 sRef ret = gc.aliasAnnote;
2439 sRef als = gc.aliasAnnoteAls;
2441 llassert (sRef_isValid (ret) && sRef_isValid (als));
2443 gc.aliasAnnote = sRef_undefined;
2444 return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret)));
2448 context_recordFileModifies (sRefSet mods)
2450 gc.modrecs = sRefSetList_add (gc.modrecs, mods);
2454 context_recordFileGlobals (globSet mods)
2456 /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/
2460 context_setCommentMarkerChar (char c)
2462 llassert (c != '\0');
2464 context_setValue (FLG_COMMENTCHAR, (int) c);
2468 context_getCommentMarkerChar (void)
2470 return ((char) context_getValue (FLG_COMMENTCHAR));
2474 context_setValue (flagcode flag, int val)
2476 int index = flagcode_valueIndex (flag);
2478 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2484 case FLG_INCLUDENEST:
2485 case FLG_CONTROLNESTDEPTH:
2486 case FLG_STRINGLITERALLEN:
2487 case FLG_NUMSTRUCTFIELDS:
2488 case FLG_NUMENUMMEMBERS:
2491 cstring warn = message ("Value for %s must be a positive "
2492 "number (given %d)",
2493 flagcode_unparse (flag), val);
2496 cstring_free (warn);
2505 if (flag == FLG_LINELEN && val < MINLINELEN)
2507 cstring warn = message ("Value for %s must be at least %d (given %d)",
2508 flagcode_unparse (flag),
2511 cstring_free (warn);
2515 gc.values[index] = val;
2519 context_setValueAndFlag (flagcode flag, int val)
2521 gc.flags[flag] = TRUE;
2522 context_setValue (flag, val);
2526 context_getValue (flagcode flag)
2528 int index = flagcode_valueIndex (flag);
2530 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2531 return (gc.values[index]);
2535 context_getCounter (flagcode flag)
2537 int index = flagcode_valueIndex (flag);
2539 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2540 return (gc.counters[index]);
2544 context_incCounter (flagcode flag)
2546 int index = flagcode_valueIndex (flag);
2548 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2550 gc.counters[index]++;
2554 context_decCounter (flagcode flag)
2556 int index = flagcode_valueIndex (flag);
2558 llassert (index >= 0 && index <= NUMVALUEFLAGS);
2559 gc.counters[index]--;
2562 bool context_showFunction (void)
2564 return (gc.showfunction);
2568 context_setString (flagcode flag, cstring val)
2570 int index = flagcode_stringIndex (flag);
2572 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2574 if (flag == FLG_SYSTEMDIRS)
2576 llassert (cstring_isDefined (val));
2578 if (cstring_firstChar (val) == '\"')
2581 cstring tval = cstring_copy (cstring_suffix (val, 1));
2583 if (cstring_lastChar (tval) != '\"')
2585 int n = cstring_length (tval) - 1;
2587 while (isspace ((int) cstring_getChar (tval, n)))
2592 if (cstring_getChar (tval, n) != '\"')
2594 cstring msg = message ("Setting -systemdirs to string with unmatching quotes: %s", val);
2600 cstring otval = tval;
2601 tval = cstring_prefix (tval, n);
2602 cstring_free (otval);
2606 val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1));
2607 DPRINTF (("val = %s", val));
2608 cstring_free (tval);
2609 cstring_free (oval);
2613 if (flag == FLG_TMPDIR)
2615 llassert (cstring_isDefined (val));
2617 if (cstring_length (val) == 0)
2620 val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR));
2622 else if (cstring_lastChar (val) != CONNECTCHAR)
2624 val = cstring_appendChar (val, CONNECTCHAR);
2632 if (cstring_length (val) >= 1
2633 && cstring_firstChar (val) == '"')
2636 ("setting %s to string beginning with \". You probably "
2637 "don't meant to have the \"'s.",
2638 flagcode_unparse (flag));
2644 if (flag == FLG_BOOLTYPE)
2649 gc.strings[index] = val;
2652 static /*@exposed@*/ cstring
2653 context_exposeString (flagcode flag)
2655 int index = flagcode_stringIndex (flag);
2657 llassert (index >= 0 && index <= NUMSTRINGFLAGS);
2658 return (gc.strings[index]);
2662 context_getString (flagcode flag)
2664 return (context_exposeString (flag));
2668 context_resetErrors (void)
2673 void context_initMod (void)
2674 /*@globals undef gc; @*/
2676 gc.kind = CX_GLOBAL;
2677 gc.instandardlib = FALSE;
2680 gc.linesprocessed = 0;
2681 gc.speclinesprocessed = 0;
2682 gc.insuppressregion = FALSE;
2683 gc.macroMissingParams = FALSE;
2684 gc.preprocessing = FALSE;
2685 gc.incommandline = FALSE;
2686 gc.mc = macrocache_create ();
2688 gc.maxmods = DEFAULTMAXMODS;
2689 gc.moduleaccess = (maccesst *)
2690 dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods));
2692 gc.library = FLG_ANSILIB;
2694 gc.locstack = filelocStack_new ();
2695 gc.modrecs = sRefSetList_undefined;
2696 gc.anyExports = FALSE;
2698 gc.ftab = fileTable_create ();
2699 gc.msgLog = messageLog_new ();
2700 gc.inimport = FALSE;
2701 gc.inDerivedFile = FALSE;
2702 gc.inheader = FALSE;
2703 gc.markers = flagMarkerList_new ();
2704 gc.cont.glob = TRUE;
2705 gc.showfunction = FALSE;
2706 gc.msgAnnote = cstring_undefined;
2707 gc.aliasAnnote = sRef_undefined;
2708 gc.aliasAnnoteAls = sRef_undefined;
2709 gc.boolType = ctype_bool;
2710 gc.mods = sRefSet_new ();
2712 gc.saveloc = fileloc_undefined;
2714 gc.inmacrocache = FALSE;
2715 gc.inclause = NOCLAUSE;
2716 gc.clauses = clauseStack_new ();
2717 gc.globs = globSet_new ();
2718 gc.nacct = typeIdSet_emptySet ();
2719 gc.acct = typeIdSet_emptySet ();
2720 gc.facct = typeIdSet_emptySet ();
2721 gc.savedFlags = FALSE;
2722 gc.pushloc = fileloc_undefined;
2723 gc.protectVars = FALSE;
2724 gc.justpopped = FALSE;
2725 gc.isNullGuarded = NO;
2726 gc.globs_used = globSet_undefined;
2730 gc.setGlobally[code] = FALSE;
2731 gc.setLocally[code] = FALSE;
2732 } end_allFlagCodes ;
2736 context_resetAllFlags ();
2737 conext_resetAllCounters ();
2738 context_setMode (DEFAULT_MODE);
2742 context_typeofZero (void)
2744 ctype ct = ctype_int;
2746 if (context_getFlag (FLG_ZEROPTR))
2748 ct = ctype_makeConj (ct, ctype_voidPointer);
2751 if (context_getFlag (FLG_ZEROBOOL)) {
2752 ct = ctype_makeConj (ct, ctype_bool);
2759 context_typeofOne (void)
2761 ctype ct = ctype_int;
2763 /* 1 is on longer a bool (was before 2.4)
2764 if (!context_getFlag (FLG_ABSTRACTBOOL))
2766 ct = ctype_makeConj (ct, ctype_bool);
2774 context_unparse (void)
2781 s = message ("LCL File: %q", fileloc_unparse (g_currentloc));
2784 s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc));
2787 s = message ("Global Context:%q", fileloc_unparse (g_currentloc));
2790 s = message ("Inner Context:%q", fileloc_unparse (g_currentloc));
2793 s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q",
2794 uentry_unparse (gc.cont.fcn),
2795 fileloc_unparse (g_currentloc),
2796 typeIdSet_unparse (gc.acct),
2797 sRefSet_unparse (gc.mods));
2800 s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn));
2802 case CX_UNKNOWNMACRO:
2803 s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn));
2806 s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn));
2809 s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn));
2812 s = message ("Iter end %q", uentry_unparse (gc.cont.fcn));
2815 s = message ("Un-unparseable context: %d", (int) gc.kind);
2819 s = message ("%q\naccess: %q", s, context_unparseAccess ());
2824 context_currentFunctionType (void)
2826 if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN)
2828 return (uentry_getType (gc.cont.fcn));
2830 else if (gc.kind == CX_INNER)
2832 llcontbuglit ("context_currentFunctionType: inner context");
2833 do { context_exitInnerPlain (); } while (gc.kind == CX_INNER);
2834 return (context_currentFunctionType ());
2838 llcontbuglit ("context_currentFunctionType: not in function");
2839 return (ctype_undefined);
2844 context_enterInnerContext (void)
2846 if (gc.kind == CX_GLOBAL)
2851 else if (gc.kind == CX_INNER)
2861 usymtab_enterScope ();
2862 pushClause (NOCLAUSE);
2866 context_exitInnerPlain (void) /*@modifies gc;@*/
2868 context_exitInner (exprNode_undefined);
2872 context_exitInner (exprNode exp)
2875 llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE,
2876 ("inclause = %s", clause_nameTaken (gc.inclause)));
2878 clauseStack_removeFirst (gc.clauses, NOCLAUSE);
2879 gc.inclause = topClause (gc.clauses);
2881 if (gc.kind == CX_INNER)
2883 if (--gc.cont.cdepth == 0)
2885 gc.kind = CX_GLOBAL;
2886 gc.cont.glob = TRUE;
2891 if (gc.kind == CX_GLOBAL)
2893 llcontbuglit ("Attempt to exit global context");
2898 usymtab_exitScope (exp);
2903 context_enterStructInnerContext (void)
2905 if (gc.kind == CX_GLOBAL)
2910 else if (gc.kind == CX_INNER)
2919 usymtab_enterScope ();
2923 context_exitStructInnerContext (void)
2925 if (gc.kind == CX_INNER)
2927 if (--gc.cont.cdepth == 0)
2929 gc.kind = CX_GLOBAL;
2930 gc.cont.glob = TRUE;
2935 if (gc.kind == CX_GLOBAL)
2937 llcontbuglit ("Attempt to exit global context");
2942 usymtab_exitScope (exprNode_undefined);
2946 context_exitInnerSafe (void)
2949 if (gc.kind == CX_INNER)
2951 if (--gc.cont.cdepth == 0)
2956 else if (gc.kind == CX_GLOBAL)
2958 llcontbuglit ("Attempt to exit global context");
2963 if (usymtab_inDeepScope ())
2965 usymtab_exitScope (exprNode_undefined);
2971 void setModuleAccess (void)
2973 gc.facct = typeIdSet_emptySet ();
2975 if (fileId_isValid (currentFile ()))
2977 cstring baseName = fileloc_getBase (g_currentloc);
2979 if (context_getFlag (FLG_ACCESSFILE))
2981 if (usymtab_existsType (baseName))
2983 gc.facct = typeIdSet_insert (gc.facct,
2984 usymtab_getTypeId (baseName));
2992 if (context_getFlag (FLG_ACCESSMODULE))
2995 bool hasaccess = FALSE;
2997 for (i = 0; i < gc.nmods; i++)
2999 if (cstring_equal (baseName, gc.moduleaccess[i].file))
3001 gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess);
3010 gc.inheader = fileId_isHeader (currentFile ());
3014 llcontbuglit ("Current file not defined\n");
3015 gc.facct = typeIdSet_emptySet ();
3017 gc.inheader = FALSE;
3020 /* 17 Jan 1995: forgot to clear nacct */
3022 gc.nacct = typeIdSet_emptySet ();
3026 context_enterFileAux (void)
3032 context_enterFile (void)
3034 context_enterFileAux ();
3035 usymtab_enterFile ();
3039 context_enterMacroFile (void)
3041 context_enterFileAux ();
3045 context_inFunction (void)
3047 kcontext ck = gc.kind;
3049 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER));
3053 context_inFunctionLike (void)
3055 return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN
3056 || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF);
3060 context_inRealFunction (void)
3062 kcontext ck = gc.kind;
3064 return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN));
3068 context_processAllMacros (void)
3070 usymtab_enterFile ();
3072 gc.inmacrocache = TRUE;
3073 macrocache_processUndefinedElements (gc.mc);
3075 usymtab_exitFile ();
3077 gc.inmacrocache = FALSE;
3078 macrocache_finalize ();
3082 ** this happens once at the end of each C file
3084 ** check each Macro that was defined in current file.c or current file.h
3089 context_processMacros (void)
3091 if (fileId_isValid (currentFile ()))
3094 cstring cbase = cstring_fromChars
3097 (cstring_toCharsSafe (fileName (currentFile ())))));
3099 gc.inmacrocache = TRUE;
3101 DPRINTF (("Processing macros: %s", cbase));
3102 lastfl = macrocache_processFileElements (gc.mc, cbase);
3103 DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl)));
3105 cstring_free (cbase);
3107 if (fileloc_isDefined (lastfl))
3109 g_currentloc = fileloc_update (g_currentloc, lastfl);
3113 gc.inmacrocache = FALSE;
3118 context_processingMacros (void)
3120 return (gc.inmacrocache);
3124 context_exitFile (void)
3126 if (gc.kind != CX_GLOBAL)
3129 (cstring_makeLiteral ("File ended outside global scope"));
3132 if (gc.insuppressregion)
3134 /* gack...don't reverse the order of these lines! ;-> */
3135 gc.insuppressregion = FALSE;
3136 llerrorlit (FLG_SYNTAX,
3137 "File ended in ignore errors region, "
3138 "possible missing /*@end*/");
3141 /* fix up parse errors */
3143 while (!usymtab_inFileScope ())
3145 usymtab_quietExitScope (g_currentloc);
3149 ** Clear the file-specific modifies information.
3152 sRefSetList_elements (gc.modrecs, mods)
3154 sRefSet_clearStatics (mods);
3155 } end_sRefSetList_elements ;
3157 sRefSetList_clear (gc.modrecs);
3159 context_processMacros ();
3162 usymtab_exitFile ();
3164 gc.inDerivedFile = FALSE;
3165 filelocStack_clear (gc.locstack);
3167 gc.nacct = typeIdSet_emptySet (); /* empty noaccess */
3169 gc.cont.glob = TRUE;
3173 context_restoreFlagSettings ();
3174 gc.savedFlags = FALSE;
3179 context_exitMacroCache (void)
3181 if (gc.kind != CX_GLOBAL)
3183 if (context_inMacro ()) /* this is okay, file could end without newline in macro */
3185 context_exitFunction ();
3189 llcontbug (message ("context_exitMacroCache: outside global scope: %q",
3190 context_unparse ()));
3191 gc.kind = CX_GLOBAL;
3196 ** no longer valid here
3197 ** if (gc.insuppressregion)
3199 ** gc.insuppressregion = FALSE;
3200 ** llerror ("File ended in ignore errors region, possible missing @");
3204 gc.cont.glob = TRUE;
3208 context_saveLocation (void)
3210 /* was llassert (fileloc_isUndefined (gc.saveloc)) */
3211 fileloc_free (gc.saveloc);
3214 gc.saveloc = fileloc_copy (g_currentloc);
3218 context_getSaveLocation (void)
3220 fileloc fl = gc.saveloc;
3222 gc.saveloc = fileloc_undefined;
3226 /*@observer@*/ cstring
3227 context_inFunctionName (void)
3229 if (gc.kind == CX_FUNCTION
3230 || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO
3231 || gc.kind == CX_MACROCONST
3232 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND)
3234 return (uentry_rawName (gc.cont.fcn));
3238 llcontbuglit ("context_inFunctionName: not in function");
3239 return (cstring_undefined);
3244 context_userSetFlag (flagcode f, bool b)
3246 DPRINTF (("set flag: %s", flagcode_name (f)));
3248 if (f == FLG_NEVERINCLUDE && b)
3250 if (gc.flags[FLG_EXPORTHEADER])
3252 flagWarning (cstring_makeLiteralTemp
3253 ("setting +neverinclude after +exportheader. "
3254 "Turning off exportheader, since headers are not checked "
3255 "when +neverinclude is used."));
3257 gc.flags[FLG_EXPORTHEADER] = FALSE;
3262 if (f == FLG_EXPORTHEADER && b)
3264 if (gc.flags[FLG_NEVERINCLUDE])
3266 flagWarning (cstring_makeLiteralTemp
3267 ("setting +exportheader after +neverinclude. "
3268 "Not setting exportheader, since headers are not checked "
3269 "when +neverinclude is used."));
3270 gc.flags[FLG_EXPORTHEADER] = FALSE;
3276 if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF)
3278 bool lastsetting = context_getFlag (f);
3280 if (bool_equal (lastsetting, b)
3281 && !flagcode_isSpecialFlag (f)
3282 && !flagcode_isIdemFlag (f)
3283 && !flagcode_hasArgument (f))
3285 cstring warn = message ("setting %s%s redundant with current value",
3286 cstring_makeLiteralTemp (b ? "+" : "-"),
3289 cstring_free (warn);
3293 if (flagcode_isLibraryFlag (f))
3295 if (gc.library != FLG_ANSILIB
3298 cstring warn = message ("selecting library %s after library %s was "
3299 "selected (only one library may be used)",
3301 flagcode_name (gc.library));
3303 cstring_free (warn);
3306 if (f == FLG_UNIXLIB)
3308 if (context_getFlag (FLG_WARNUNIXLIB))
3310 flagWarning (cstring_makeLiteralTemp
3311 ("selecting unix library. Unix library is "
3312 "ad hoc addition to POSIX library. Recommend "
3313 "use +posixlib to select POSIX library instead. "
3314 "Use -warnunixlib to suppress this message."));
3321 gc.setGlobally[f] = TRUE;
3322 context_setFlag (f, b);
3326 context_fileSetFlag (flagcode f, ynm set)
3330 context_saveFlagSettings ();
3333 if (ynm_isOff (set))
3335 context_setFlagAux (f, FALSE, TRUE, FALSE);
3337 else if (ynm_isOn (set))
3339 context_setFlagAux (f, TRUE, TRUE, FALSE);
3340 gc.setLocally[f] = TRUE;
3344 context_restoreFlag (f);
3349 context_restoreFlag (flagcode f)
3356 message ("Attempt to restore flag %s when no file scope flags "
3358 flagcode_unparse (f)),
3363 context_addFlagMarker (f, MAYBE);
3364 context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE);
3369 /*drl7x fix this static */ void
3370 context_setFlag (flagcode f, bool b)
3372 context_setFlagAux (f, b, FALSE, FALSE);
3376 context_setFlagTemp (flagcode f, bool b)
3378 DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3383 # define DOSET(ff,b) \
3384 do { if (inFile) { gc.setLocally[ff] = TRUE; \
3385 context_addFlagMarker (ff, ynm_fromBool (b)); } \
3386 DPRINTF (("set flag: %s / %s", flagcode_name (ff), bool_unparse (b))); \
3387 gc.flags[ff] = b; } while (FALSE)
3390 context_setFlagAux (flagcode f, bool b, bool
3391 inFile, /*@unused@*/ bool isRestore)
3393 DPRINTF (("set flag: %s / %s", flagcode_unparse (f), bool_unparse (b)));
3395 if (f == FLG_USESTDERR)
3398 g_msgstream = stderr;
3400 g_msgstream = stdout;
3404 if (flagcode_isSpecialFlag (f))
3412 DOSET (FLG_ALLEMPTY, b);
3413 DOSET (FLG_IFEMPTY, b);
3414 DOSET (FLG_WHILEEMPTY, b);
3415 DOSET (FLG_FOREMPTY, b);
3418 DOSET (FLG_PREDBOOL, b);
3419 DOSET (FLG_PREDBOOLINT, b);
3420 DOSET (FLG_PREDBOOLPTR, b);
3421 DOSET (FLG_PREDBOOLOTHERS, b);
3424 DOSET (FLG_CHECKSTRICTGLOBALIAS, b);
3425 DOSET (FLG_CHECKEDGLOBALIAS, b);
3426 DOSET (FLG_CHECKMODGLOBALIAS, b);
3427 DOSET (FLG_UNCHECKEDGLOBALIAS, b);
3430 DOSET (FLG_ALLBLOCK, b);
3431 DOSET (FLG_IFBLOCK, b);
3432 DOSET (FLG_WHILEBLOCK, b);
3433 DOSET (FLG_FORBLOCK, b);
3445 DOSET (FLG_GRAMMAR, b);
3447 case FLG_CODEIMPONLY:
3448 DOSET (FLG_CODEIMPONLY, b);
3449 DOSET (FLG_GLOBIMPONLY, b);
3450 DOSET (FLG_RETIMPONLY, b);
3451 DOSET (FLG_STRUCTIMPONLY, b);
3453 case FLG_SPECALLIMPONLY:
3454 DOSET (FLG_SPECALLIMPONLY, b);
3455 DOSET (FLG_SPECGLOBIMPONLY, b);
3456 DOSET (FLG_SPECRETIMPONLY, b);
3457 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3459 case FLG_ALLIMPONLY:
3460 DOSET (FLG_ALLIMPONLY, b);
3461 DOSET (FLG_GLOBIMPONLY, b);
3462 DOSET (FLG_RETIMPONLY, b);
3463 DOSET (FLG_STRUCTIMPONLY, b);
3464 DOSET (FLG_SPECGLOBIMPONLY, b);
3465 DOSET (FLG_SPECRETIMPONLY, b);
3466 DOSET (FLG_SPECSTRUCTIMPONLY, b);
3468 case FLG_ANSILIMITS:
3469 DOSET (FLG_ANSILIMITS, b);
3470 DOSET (FLG_CONTROLNESTDEPTH, b);
3471 DOSET (FLG_STRINGLITERALLEN, b);
3472 DOSET (FLG_INCLUDENEST, b);
3473 DOSET (FLG_NUMSTRUCTFIELDS, b);
3474 DOSET (FLG_NUMENUMMEMBERS, b);
3478 context_setValue (FLG_CONTROLNESTDEPTH, DEFAULT_CONTROLNESTDEPTH);
3479 context_setValue (FLG_STRINGLITERALLEN, DEFAULT_STRINGLITERALLEN);
3480 context_setValue (FLG_INCLUDENEST, DEFAULT_INCLUDENEST);
3481 context_setValue (FLG_NUMSTRUCTFIELDS, DEFAULT_NUMSTRUCTFIELDS);
3482 context_setValue (FLG_NUMENUMMEMBERS, DEFAULT_NUMENUMMEMBERS);
3485 case FLG_EXTERNALNAMELEN:
3486 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3487 DOSET (FLG_EXTERNALNAMELEN, TRUE);
3489 case FLG_INTERNALNAMELEN:
3490 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3491 DOSET (FLG_INTERNALNAMELEN, TRUE);
3493 case FLG_EXTERNALNAMECASEINSENSITIVE:
3494 DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b);
3496 if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES])
3498 DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE);
3499 context_setValue (FLG_EXTERNALNAMELEN, 0);
3502 case FLG_INTERNALNAMECASEINSENSITIVE:
3503 DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b);
3505 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3507 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3508 context_setValue (FLG_INTERNALNAMELEN, 0);
3511 case FLG_INTERNALNAMELOOKALIKE:
3512 DOSET (FLG_INTERNALNAMELOOKALIKE, b);
3514 if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES])
3516 DOSET (FLG_DISTINCTINTERNALNAMES, TRUE);
3517 context_setValue (FLG_INTERNALNAMELEN, 0);
3521 DOSET (FLG_MODNOMODS, b);
3522 DOSET (FLG_MODGLOBSUNSPEC, b);
3523 DOSET (FLG_MODSTRICTGLOBSUNSPEC, b);
3526 DOSET (FLG_EXPORTVAR, b);
3527 DOSET (FLG_EXPORTFCN, b);
3528 DOSET (FLG_EXPORTTYPE, b);
3529 DOSET (FLG_EXPORTMACRO, b);
3530 DOSET (FLG_EXPORTCONST, b);
3531 gc.anyExports = TRUE;
3534 DOSET (FLG_RETEXPOSE, b);
3535 DOSET (FLG_ASSIGNEXPOSE, b);
3536 DOSET (FLG_CASTEXPOSE, b);
3539 DOSET (FLG_RETVALBOOL, b);
3540 DOSET (FLG_RETVALINT, b);
3541 DOSET (FLG_RETVALOTHER, b);
3546 DOSET (FLG_EXPORTLOCAL, FALSE);
3547 DOSET (FLG_DECLUNDEF, FALSE);
3548 DOSET (FLG_SPECUNDEF, FALSE);
3549 DOSET (FLG_TOPUNUSED, FALSE);
3553 DOSET (FLG_LOOPLOOPBREAK, b);
3554 DOSET (FLG_LOOPSWITCHBREAK, b);
3555 DOSET (FLG_SWITCHLOOPBREAK, b);
3556 DOSET (FLG_SWITCHSWITCHBREAK, b);
3557 DOSET (FLG_LOOPLOOPCONTINUE, b);
3558 DOSET (FLG_DEEPBREAK, b);
3561 DOSET (FLG_ACCESSMODULE, b);
3562 DOSET (FLG_ACCESSFILE, b);
3563 DOSET (FLG_ACCESSCZECH, b);
3566 DOSET (FLG_ALLMACROS, b);
3567 DOSET (FLG_FCNMACROS, b);
3568 DOSET (FLG_CONSTMACROS, b);
3571 if (b) { DOSET (FLG_ACCESSCZECH, b); }
3572 DOSET (FLG_CZECHFUNCTIONS, b);
3573 DOSET (FLG_CZECHVARS, b);
3574 DOSET (FLG_CZECHCONSTANTS, b);
3575 DOSET (FLG_CZECHTYPES, b);
3578 if (b) { DOSET (FLG_ACCESSSLOVAK, b); }
3579 DOSET (FLG_SLOVAKFUNCTIONS, b);
3580 DOSET (FLG_SLOVAKVARS, b);
3581 DOSET (FLG_SLOVAKCONSTANTS, b);
3582 DOSET (FLG_SLOVAKTYPES, b);
3584 case FLG_CZECHOSLOVAK:
3585 if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); }
3586 DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b);
3587 DOSET (FLG_CZECHOSLOVAKVARS, b);
3588 DOSET (FLG_CZECHOSLOVAKCONSTANTS, b);
3589 DOSET (FLG_CZECHOSLOVAKTYPES, b);
3592 DOSET (FLG_NULLSTATE, b);
3593 DOSET (FLG_NULLDEREF, b);
3594 DOSET (FLG_NULLASSIGN, b);
3595 DOSET (FLG_NULLPASS, b);
3596 DOSET (FLG_NULLRET, b);
3599 DOSET (FLG_NULLSTATE, b);
3600 DOSET (FLG_NULLDEREF, b);
3601 DOSET (FLG_NULLASSIGN, b);
3602 DOSET (FLG_NULLPASS, b);
3603 DOSET (FLG_NULLRET, b);
3604 DOSET (FLG_COMPDEF, b);
3605 DOSET (FLG_COMPMEMPASS, b);
3606 DOSET (FLG_UNIONDEF, b);
3607 DOSET (FLG_MEMTRANS, b);
3608 DOSET (FLG_USERELEASED, b);
3609 DOSET (FLG_ALIASUNIQUE, b);
3610 DOSET (FLG_MAYALIASUNIQUE, b);
3611 DOSET (FLG_MUSTFREE, b);
3612 DOSET (FLG_MUSTDEFINE, b);
3613 DOSET (FLG_GLOBSTATE, b);
3614 DOSET (FLG_COMPDESTROY, b);
3615 DOSET (FLG_MUSTNOTALIAS, b);
3616 DOSET (FLG_MEMIMPLICIT, b);
3617 DOSET (FLG_BRANCHSTATE, b);
3618 /*@fallthrough@*/ /* also sets memtrans flags */
3620 DOSET (FLG_MEMTRANS, b);
3621 DOSET (FLG_EXPOSETRANS, b);
3622 DOSET (FLG_OBSERVERTRANS, b);
3623 DOSET (FLG_DEPENDENTTRANS, b);
3624 DOSET (FLG_NEWREFTRANS, b);
3625 DOSET (FLG_ONLYTRANS, b);
3626 DOSET (FLG_OWNEDTRANS, b);
3627 DOSET (FLG_FRESHTRANS, b);
3628 DOSET (FLG_SHAREDTRANS, b);
3629 DOSET (FLG_TEMPTRANS, b);
3630 DOSET (FLG_KEPTTRANS, b);
3631 DOSET (FLG_REFCOUNTTRANS, b);
3632 DOSET (FLG_STATICTRANS, b);
3633 DOSET (FLG_UNKNOWNTRANS, b);
3634 DOSET (FLG_KEEPTRANS, b);
3635 DOSET (FLG_IMMEDIATETRANS, b);
3639 llcontbug (message ("Unhandled special flag: %s",
3640 flagcode_unparse (f)));
3646 if (flagcode_isIdemFlag (f))
3652 if (b && !gc.anyExports
3653 && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN
3654 || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO
3655 || f == FLG_EXPORTCONST
3656 || f == FLG_EXPORTANY))
3658 gc.anyExports = TRUE;
3667 context_maybeSet (flagcode d)
3669 return (gc.flags[d] || gc.setLocally[d]);
3673 context_getFlag (flagcode d)
3675 return (gc.flags[d]);
3678 static void context_saveFlagSettings (void)
3680 gc.savedFlags = TRUE;
3681 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3682 memcpy (gc.saveflags, gc.flags, sizeof (gc.flags));
3685 static void context_restoreFlagSettings (void)
3687 llassert (sizeof (gc.saveflags) == sizeof (gc.flags));
3688 memcpy (gc.flags, gc.saveflags, sizeof (gc.flags));
3689 gc.savedFlags = FALSE;
3692 void context_setFilename (fileId fid, int lineno)
3693 /*@globals fileloc g_currentloc;@*/
3694 /*@modifies g_currentloc@*/
3696 if (fileId_baseEqual (currentFile (), fid))
3703 fileloc_setColumn (g_currentloc, 0);
3705 if (fileloc_isSpecialFile (g_currentloc))
3707 gc.inDerivedFile = TRUE;
3710 if (filelocStack_popPushFile (gc.locstack, g_currentloc))
3712 int maxdepth = context_getValue (FLG_INCLUDENEST);
3714 if (filelocStack_size (gc.locstack) > maxdepth)
3716 int depth = filelocStack_includeDepth (gc.locstack);
3718 if (depth > maxdepth)
3722 message ("Maximum include nesting depth "
3723 "(%d, current depth %d) exceeded",
3726 filelocStack_nextTop (gc.locstack)))
3728 filelocStack_printIncludes (gc.locstack);
3734 g_currentloc = fileloc_create (fid, lineno, 1);
3735 gc.inheader = fileId_isHeader (currentFile ());
3737 context_enterFileAux ();
3741 void context_enterIterDef (/*@observer@*/ uentry le)
3743 context_enterMacro (le);
3744 gc.acct = typeIdSet_subtract (gc.facct, gc.nacct);
3745 gc.kind = CX_ITERDEF;
3748 void context_enterIterEnd (/*@observer@*/ uentry le)
3750 context_enterMacro (le);
3751 gc.kind = CX_ITEREND;
3755 context_destroyMod (void)
3756 /*@globals killed gc@*/
3759 ctype_destroyMod ();
3763 fileTable_free (gc.ftab);
3764 filelocStack_free (gc.locstack);
3766 gc.ftab = fileTable_undefined;
3768 macrocache_free (gc.mc);
3769 sfree (gc.moduleaccess);
3772 fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined;
3773 fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined;
3776 sRefSetList_free (gc.modrecs);
3778 flagMarkerList_free (gc.markers);
3780 messageLog_free (gc.msgLog);
3782 clauseStack_free (gc.clauses);
3785 cstring_free (gc.msgAnnote);
3786 globSet_free (gc.globs_used);
3793 bool context_msgBoolInt (void)
3795 return gc.flags [FLG_BOOLINT];
3798 bool context_msgCharInt (void)
3800 return gc.flags [FLG_CHARINT];
3803 bool context_msgEnumInt (void)
3805 return gc.flags [FLG_ENUMINT];
3808 bool context_msgPointerArith (void)
3810 return gc.flags [FLG_POINTERARITH];
3813 bool context_msgStrictOps (void)
3815 return gc.flags [FLG_STRICTOPS];
3819 bool context_msgLh (void)
3821 return gc.flags [FLG_DOLH];
3825 void context_pushLoc (void)
3827 fileloc_free (gc.pushloc);
3828 gc.pushloc = gc.saveloc;
3829 gc.saveloc = fileloc_undefined;
3832 void context_popLoc (void)
3834 gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc);
3837 bool context_inGlobalScope (void)
3839 return (usymtab_inFileScope() || usymtab_inGlobalScope ());
3842 bool context_inInnerScope (void)
3844 return (gc.kind == CX_INNER);
3847 void context_setProtectVars (void)
3849 gc.protectVars = TRUE;
3852 bool context_anyErrors (void)
3854 return (gc.numerrors > 0);
3857 void context_hasError (void)
3862 int context_numErrors (void)
3864 return gc.numerrors;
3867 bool context_neednl (void)
3872 void context_setNeednl (void)
3877 int context_getExpect (void)
3879 return (context_getValue (FLG_EXPECT));
3883 int context_getLCLExpect (void)
3885 return (context_getValue (FLG_LCLEXPECT));
3889 int context_getLimit (void)
3891 return (context_getValue (FLG_LIMIT));
3894 bool context_unlimitedMessages (void)
3896 return (context_getLimit () < 0);
3899 void context_releaseVars (void)
3901 llassert (gc.protectVars);
3902 gc.protectVars = FALSE;
3905 void context_sizeofReleaseVars (void)
3907 /* If there is a nested sizeof, this might not hold:
3908 llassert (gc.protectVars);
3911 gc.protectVars = FALSE;
3914 bool context_inProtectVars (void)
3916 return (gc.protectVars);
3919 void context_hideShowscan (void)
3921 gc.flags[FLG_SHOWSCAN] = FALSE;
3924 void context_unhideShowscan (void)
3926 gc.flags[FLG_SHOWSCAN] = TRUE;
3929 bool context_inHeader (void)
3931 return (gc.inheader);
3934 fileTable context_fileTable (void)
3939 cstring context_tmpdir (void)
3941 return (context_getString (FLG_TMPDIR));
3944 messageLog context_messageLog (void)
3949 bool context_inMacroFunction (void)
3951 return (gc.kind == CX_MACROFCN);
3954 bool context_inMacroConstant (void)
3956 return (gc.kind == CX_MACROCONST);
3959 bool context_inMacroUnknown (void)
3961 return (gc.kind == CX_UNKNOWNMACRO);
3964 void context_setShownFunction (void)
3966 gc.showfunction = FALSE;
3969 bool context_doDump (void)
3971 return cstring_isNonEmpty (context_getString (FLG_DUMP));
3974 bool context_doMerge (void)
3976 return cstring_isNonEmpty (context_getString (FLG_MERGE));
3979 cstring context_getDump (void)
3981 return context_getString (FLG_DUMP);
3984 cstring context_getMerge (void)
3986 return context_getString (FLG_MERGE);
3990 bool context_inLCLLib (void)
3992 return (gc.kind == CX_LCLLIB);
3995 bool context_inImport (void)
3997 return (gc.inimport);
4000 void context_enterImport (void)
4005 void context_leaveImport (void)
4007 gc.inimport = FALSE;
4011 bool context_inMacro (void)
4013 return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST
4014 || gc.kind == CX_UNKNOWNMACRO
4015 || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND);
4018 bool context_inIterDef (void)
4020 return (gc.kind == CX_ITERDEF);
4023 bool context_inIterEnd (void)
4025 return (gc.kind == CX_ITEREND);
4028 int context_getLinesProcessed (void)
4030 return (gc.linesprocessed);
4033 int context_getSpecLinesProcessed (void)
4035 return (gc.speclinesprocessed);
4039 void context_processedSpecLine (void)
4041 gc.speclinesprocessed++;
4044 void context_resetSpecLines (void)
4046 gc.speclinesprocessed = 0;
4050 bool context_inGlobalContext (void)
4052 return (gc.kind == CX_GLOBAL);
4055 void context_setFileId (fileId s)
4057 g_currentloc = fileloc_updateFileId (g_currentloc, s);
4060 bool context_setBoolName (void)
4062 return (!cstring_equalLit (context_getString (FLG_BOOLTYPE),
4066 cstring context_printBoolName (void)
4068 if (context_setBoolName ())
4070 return context_getBoolName ();
4074 return cstring_makeLiteralTemp ("boolean");
4078 cstring context_getBoolName (void)
4080 return (context_getString (FLG_BOOLTYPE));
4083 cstring context_getFalseName (void)
4085 return (context_getString (FLG_BOOLFALSE));
4088 cstring context_getTrueName (void)
4090 return (context_getString (FLG_BOOLTRUE));
4093 cstring context_getLarchPath (void)
4095 return (context_getString (FLG_LARCHPATH));
4098 cstring context_getLCLImportDir (void)
4100 return (context_getString (FLG_LCLIMPORTDIR));
4103 static void context_setJustPopped (void)
4105 gc.justpopped = TRUE;
4108 void context_clearJustPopped (void)
4110 gc.justpopped = FALSE;
4113 bool context_justPopped (void)
4115 return (gc.justpopped);
4118 void context_setMacroMissingParams (void)
4120 gc.macroMissingParams = TRUE;
4123 void context_resetMacroMissingParams (void)
4125 gc.macroMissingParams = FALSE;
4128 bool context_isMacroMissingParams (void)
4130 return (gc.macroMissingParams);
4133 void context_showFilelocStack (void)
4135 filelocStack_printIncludes (gc.locstack);