2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://www.splint.org
28 # include "lclintMacros.nf"
33 ** from the CC man page:
35 ** -Idir Search for #include files whose names do not begin with a
36 ** slash (/) in the following order: (1) in the directory of
37 ** the dir argument, (2) in the directories specified by -I
38 ** options, (3) in the standard directory (/usr/include).
41 /* needed for string literals literals */
45 /*@null@*/ /*@observer@*/ char *name;
46 /*@null@*/ /*@observer@*/ char *describe;
49 static flagcatinfo categories[] =
51 { FK_ABSTRACT, "abstract", "abstraction violations, representation access" } ,
52 { FK_ALIAS, "aliasing", "unexpected or dangerous aliasing" } ,
53 { FK_USE, "alluse", "all declarations are used" } ,
54 { FK_ANSI, "ansi", "violations of constraints imposed by ANSI/ISO standard" } ,
55 { FK_ARRAY, "arrays", "special checking involving arrays" } ,
56 { FK_BOOL, "booleans", "checking and naming of boolean types" } ,
57 { FK_COMMENTS, "comments", "interpretation of semantic comments" } ,
58 { FK_COMPLETE, "complete", "completely defined, used, or specified system" } ,
59 { FK_CONTROL, "controlflow", "suspicious control structures" } ,
60 { FK_DEBUG, "debug", "flags for debugging lclint" } ,
61 { FK_DECL, "declarations", "consistency of declarations" } ,
62 { FK_DEF, "definition", "undefined storage errors" } ,
63 { FK_DIRECT, "directories", "set directores" } ,
64 { FK_DISPLAY, "display", "control what is displayed" } ,
65 { FK_EFFECT, "effect", "statements with no effects" } ,
66 { FK_ERRORS, "errors", "control expected errors, summary reporting" } ,
67 { FK_EXPORT, "export", "control what may be exported" } ,
68 { FK_EXPOSURE, "exposure", "representation exposure" } ,
69 { FK_FILES, "files", "control system files" } ,
70 { FK_FORMAT, "format", "control format of warning messages" } ,
71 { FK_GLOBALS, "globals", "use of global and file static variables" },
72 { FK_HEADERS, "headers", "control inclusion and generation of header files" },
73 { FK_HELP, "help", "on-line help" },
74 { FK_IMPLICIT, "implicit", "control implicit annotations and interpretations" } ,
75 { FK_INIT, "initializations", "initialization files" } ,
76 { FK_ITER, "iterators", "checking iterator definitions and uses" } ,
77 { FK_LEAK, "leaks", "memory leaks" } ,
78 { FK_LIBS, "libraries", "loading and dumping of user and standard libraries" } ,
79 { FK_LIMITS, "limits", "violations of set limits" } ,
80 { FK_MACROS, "macros", "expansion, definition and use of macros" },
81 { FK_MEMORY, "memory", "memory management" } ,
82 { FK_MODIFIES, "modification", "modification errors" } ,
83 { FK_NAMES, "names", "naming conventions and limits" } ,
84 { FK_NULL, "null", "misuses of null pointers" } ,
85 { FK_NUMBERS, "numbers", "control type-checking of numeric types" } ,
86 { FK_OPS, "operations", "checking of primitive operations" } ,
87 { FK_PARAMS, "parameters", "function and macro parameters" } ,
88 { FK_SPEED, "performance", "speeding up checking" } ,
89 { FK_POINTER, "pointers", "pointers" } ,
90 { FK_PRED, "predicates", "condition test expressions" } ,
91 { FK_PREFIX, "prefixes", "set naming prefixes and control checking" } ,
92 { FK_PREPROC, "preproc", "defines and undefines for the preprocessor" } ,
93 { FK_PROTOS, "prototypes", "function prototypes" } ,
94 { FK_DEAD, "released", "using storage that has been deallocated" } ,
95 { FK_IGNORERET, "returnvals", "ignored return values" },
96 { FK_SECURITY, "security", "possible security vulnerability" },
97 { FK_SPEC, "specifications", "checks involving .lcl specifications" } ,
98 { FK_SUPPRESS, "suppress", "local and global suppression of messages" } ,
99 { FK_TYPEEQ, "typeequivalence", "control what types are equivalent" } ,
100 { FK_BEHAVIOR, "undefined", "code with undefined or implementation-defined behavior" } ,
101 { FK_UNRECOG, "unrecognized", "unrecognized identifiers" } ,
102 { FK_UNSPEC, "unconstrained", "checking in the presence of unconstrained functions" } ,
103 { FK_WARNUSE, "warnuse", "use of possibly problematic function" } ,
104 { FK_SYNTAX, NULL, NULL } ,
105 { FK_TYPE, NULL, NULL } ,
106 { FK_SECRET, NULL, NULL } ,
107 { FK_OBSOLETE, NULL, NULL } ,
108 { FK_NONE, NULL, NULL } /* must be last */
113 ARG_NUMBER, /* number */
115 ARG_STRING, /* string */
116 ARG_FILE, /* filename (also a string) */
117 ARG_DIRECTORY, /* directory (also a string) */
122 static /*@observer@*/ cstring argcode_unparse (argcode arg)
126 case ARG_STRING: return cstring_makeLiteralTemp ("string");
127 case ARG_FILE: return cstring_makeLiteralTemp ("filename");
128 case ARG_DIRECTORY: return cstring_makeLiteralTemp ("directory");
129 case ARG_PATH: return cstring_makeLiteralTemp ("path");
130 case ARG_NUMBER: return cstring_makeLiteralTemp ("number");
131 case ARG_CHAR: return cstring_makeLiteralTemp ("character");
142 bool isSpecial; /* setting this flag may set other flags (or values) */
143 bool isIdem; /* idempotent - always sets to TRUE */
144 bool isGlobal; /* cannot be set locally (using control comments) */
145 bool isModeFlag; /* set by modes */
147 /*@observer@*/ char *flag;
149 /*@observer@*/ /*@null@*/ char *desc;
155 typedef fflag flaglist[];
157 # include "flags.def"
159 /*@iter allFlags (yield observer fflag f); @*/
160 # define allFlags(m_f) \
161 { /*@+enumint@*/ flagcode m_i; for (m_i = 0; m_i < NUMFLAGS; m_i++) { fflag m_f = flags[m_i]; /*@=enumint@*/
162 # define end_allFlags }}
164 static bn_mstring mode_names[] =
166 "weak", "standard", "checks", "strict", NULL,
169 /*@iter allModes (yield bn_mstring modename)@*/
170 # define allModes(m_m) \
171 { int m_ii = 0; while (mstring_isDefined (mode_names[m_ii])) \
172 { bn_mstring m_m = mode_names[m_ii]; m_ii++;
174 # define end_allModes }}
178 static cstring getFlagModeSettings (flagcode p_flag) /*@modifies internalState@*/ ;
179 static cstring describeFlagCode (flagcode p_flag) /*@*/ ;
180 static cstringSList sortedFlags (void) /*@*/ ;
181 static /*@observer@*/ cstring categoryName (flagkind p_kind) /*@*/ ;
183 static flagcode flags_identifyFlagAux (cstring p_s, bool p_quiet) /*@modifies g_msgstream@*/ ;
186 static /*@unused@*/ cstring listModes (void) /*@*/ ;
189 bool flagcode_isSpecialFlag (flagcode f)
191 return (flags[f].isSpecial);
194 bool flagcode_isGlobalFlag (flagcode f)
196 return (flags[f].isGlobal);
199 bool flagcode_isIdemFlag (flagcode f)
201 return (flags[f].isIdem);
204 bool flagcode_isModeFlag (flagcode f)
206 return (flags[f].isModeFlag);
209 bool flagcode_isNameChecksFlag (flagcode f)
211 return (flags[f].main == FK_NAMES);
215 ** Internal consistency check on the flags.
218 void flags_initMod ()
223 if (flags[code].code != code)
226 "*** ERROR: inconsistent flag %s / %d / %d",
228 flags[code].code, code);
230 llbug (message ("*** ERROR: inconsistent flag %s / %d / %d",
231 cstring_fromChars (flags[code].flag),
232 flags[code].code, code));
245 char *buf = mstring_create (128);
249 if (f.nreported > 0 || f.nsuppressed > 0)
251 int nrep = f.nreported;
252 int nsup = f.nsuppressed;
253 cstring fs = cstring_fill (cstring_fromChars (f.flag), 23);
257 llmsgplain (cstring_makeLiteral
258 ("\nError Type Reported Suppressed\n"
259 "=================== ======== ========="));
263 sprintf (buf, "%s%7d %9d", cstring_toCharsSafe (fs), nrep, nsup);
269 llmsg (cstring_copy (cstring_fromChars (buf)));
275 cstring ts = cstring_fill (cstring_makeLiteralTemp ("Total"), 23);
277 llmsglit (" ======== =========");
279 sprintf (buf, "%s%7d %9d", cstring_toCharsSafe (ts), sumrep, sumsup);
281 llmsgplain (cstring_copy (cstring_fromChars (buf)));
290 flagcode_recordError (flagcode f)
292 if (f != INVALID_FLAG)
294 if (f == FLG_WARNFLAGS)
296 ; /* don't count these */
300 flags[f].nreported = flags[f].nreported + 1;
305 llcontbug (message ("flagcode_recordError: invalid flag: %d", (int) f));
310 flagcode_recordSuppressed (flagcode f)
312 llassertprint (f != INVALID_FLAG, ("flagcode: %s", flagcode_unparse (f)));
314 flags[f].nsuppressed = flags[f].nsuppressed + 1;
318 flagcode_numReported (flagcode f)
320 llassert (f != INVALID_FLAG);
322 return (flags[f].nreported);
325 /*@observer@*/ cstring
326 flagcodeHint (flagcode f)
328 llassert (f != INVALID_FLAG);
330 if (mstring_isDefined (flags[f].hint))
332 return (cstring_fromChars (flags[f].hint));
336 return (cstring_fromChars (flags[f].desc));
340 static int categorySize (flagkind kind) /*@*/
347 if (f.main == kind || f.sub == kind)
356 flagkind identifyCategory (cstring s)
360 for (i = 0; categories[i].kind != FK_NONE; i++)
362 if (mstring_isDefined (categories[i].name))
364 if (cstring_equalLit (s, categories[i].name))
366 return categories[i].kind;
374 static /*@observer@*/ cstring categoryName (flagkind kind)
378 for (i = 0; categories[i].kind != FK_NONE; i++)
380 if (categories[i].kind == kind)
382 return (cstring_fromChars (categories[i].name));
386 return (cstring_makeLiteralTemp ("<No Category>"));
389 static int categoryIndex (flagkind kind)
393 for (i = 0; categories[i].kind != FK_NONE; i++)
395 if (categories[i].kind == kind)
404 void printCategory (flagkind kind)
406 int index = categoryIndex (kind);
408 llassert (index >= 0);
410 llmsg (message ("%s (%d flags)\n\3%s\n\n",
411 cstring_fromChars (categories[index].name),
413 cstring_fromChars (categories[index].describe)));
417 if (f.main == kind || f.sub == kind)
419 llmsg (message (" %s\n\6%q", cstring_fromChars (f.flag),
420 describeFlagCode (f.code)));
426 listAllCategories (void)
430 for (i = 0; categories[i].kind != FK_NONE; i++)
432 flagkind kind = categories[i].kind ;
434 if (categories[i].describe != NULL)
436 llmsg (message ("%s (%d flags)\n\3%s",
439 cstring_fromChars (categories[i].describe)));
445 printAllFlags (bool desc, bool full)
449 cstringSList fl = sortedFlags ();
451 cstringSList_elements (fl, el)
453 llmsg (message ("%q\n\n", describeFlag (el)));
454 } end_cstringSList_elements ;
456 cstringSList_free (fl);
462 if (f.code != INVALID_FLAG && f.main != FK_OBSOLETE)
464 if (mstring_isDefined (f.desc))
468 llmsg (message ("%s --- %s", cstring_fromChars (f.flag),
469 cstring_fromChars (f.desc)));
478 printFlagManual (void)
481 ** Prints all flags by category, in order they appear in flags.def
484 flagkind lastCategory = FK_NONE;
488 cstring flagtype = cstring_undefined;
490 if (f.main != lastCategory)
492 llmsg (message ("\n%s\n%s\n",
493 categoryName (f.main),
494 cstring_makeLiteralTemp ("===================================")));
496 lastCategory = f.main;
499 if (f.argtype == ARG_NONE || f.argtype == ARG_SPECIAL)
501 flagname = cstring_fromCharsNew (f.flag);
505 if (flagcode_hasString (f.code))
507 flagname = message ("%s <%s [%s]>", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
508 context_getString (f.code));
510 else if (f.argtype == ARG_CHAR)
512 flagname = message ("%s <%s [%c]>", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
513 (char) context_getValue (f.code));
517 llassert (f.argtype == ARG_NUMBER);
518 flagname = message ("%s <%s [%d]>", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
519 context_getValue (f.code));
525 flagtype = message("%q<->", flagtype);
529 flagtype = message("%q<+->", flagtype);
534 flagtype = message ("%q<G>", flagtype);
539 flagtype = message("%q<S>", flagtype);
544 flagtype = message ("%q<M:%q>", flagtype, getFlagModeSettings (f.code));
546 else /* its a plain flag */
548 flagtype = message ("%q<P:%s>", flagtype,
549 cstring_makeLiteralTemp (context_getFlag (f.code) ? "+" : "-"));
552 llmsg (message ("%s: %s", flagname, flagtype));
557 describeFlagCode (flagcode flag)
559 cstring ret = cstring_undefined;
562 if (flagcode_isInvalid (flag))
564 return (cstring_makeLiteral ("<invalid>"));
567 context_resetAllFlags ();
570 ret = cstring_copy (cstring_fromChars (f.desc));
573 if (f.sub != FK_NONE)
575 ret = message ("%q\nCategories: %s, %s",
577 categoryName (f.main),
578 categoryName (f.sub));
582 if (f.main != FK_NONE)
584 cstring cname = categoryName (f.main);
586 if (cstring_isDefined (cname))
588 ret = message ("%q\nCategory: %s",
596 ret = message ("%q\nMode Settings: %q",
597 ret, getFlagModeSettings (flag));
601 ret = message ("%q\nDefault Setting: %s",
603 cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
608 ret = message("%q\nSet globally only", ret);
612 ret = message("%q\nSet locally", ret);
621 ret = message("%q\nNumeric Argument. Default: %d",
623 context_getValue (flag));
626 ret = message("%q\nCharacter Argument. Default: %h",
627 ret, (char) context_getValue (flag));
634 if (cstring_isDefined (context_getString (flag)))
636 ret = message("%q\n%q argument. Default: %s",
638 cstring_capitalize (argcode_unparse (f.argtype)),
639 context_getString (flag));
643 ret = message("%q\n%s argument. No default.",
645 cstring_capitalize (argcode_unparse (f.argtype)));
651 if (mstring_isDefined (f.hint))
653 ret = message("%q\n\3%s", ret, cstring_fromChars (f.hint));
659 static cstring getFlagModeSettings (flagcode flag)
661 cstring res = cstring_undefined;
665 context_setMode (cstring_fromChars (mname));
667 res = message ("%q%s", res, cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
674 describeFlag (cstring flagname)
676 cstring oflagname = cstring_copy (flagname);
677 flagcode f = flags_identifyFlag (flagname);
679 if (flagcode_isSkip (f))
681 cstring_free (oflagname);
682 return cstring_undefined;
684 else if (flagcode_isValid (f))
686 if (cstring_equal (flagname, oflagname))
688 cstring_free (oflagname);
689 return (message ("%s\n\3%q", flagname, describeFlagCode (f)));
693 return (message ("%q (standardized name: %s)\n\3%q",
694 oflagname, flagname, describeFlagCode (f)));
699 if (isMode (flagname))
701 cstring_free (oflagname);
704 (message ("%s: predefined mode (see Manual for information)",
709 return (message ("%q: <invalid flag>", oflagname));
717 cstringSList s = cstringSList_new ();
723 s = cstringSList_add (s, cstring_fromChars (f.flag));
727 cstringSList_alphabetize (s);
732 void printAlphaFlags ()
734 cstringSList fl = sortedFlags ();
736 cstringSList_printSpaced (fl, 3, 1, context_getLineLen () - 25);
737 cstringSList_free (fl);
740 /*@observer@*/ cstring
741 flagcode_unparse (flagcode code)
743 if (code == INVALID_FLAG)
745 return cstring_makeLiteralTemp ("<invalid flag>");
748 return cstring_fromChars (flags[code].flag);
752 ** Transforms a flag into its cannonical form.
754 ** The following transformations are made:
760 ** parameter -> param
761 ** unrecognized -> unrecog
763 ** declaration -> decl
764 ** globalias -> (no change)
772 ** unconstrained -> unspec
779 canonicalizeFlag (cstring s)
782 static bn_mstring transform[] =
788 "parameter", "param",
789 "unrecognized", "unrecog",
791 "declaration", "decl",
799 "unconstrained", "uncon",
809 while ((current = transform[i]) != NULL)
811 if (cstring_containsLit (s, current))
813 cstring_replaceLit (s, current, transform[i+1]);
818 /* remove whitespace, -'s, and _'s */
819 cstring_stripChars (s, " -_");
823 flags_identifyFlag (cstring s)
825 return flags_identifyFlagAux (s, FALSE);
829 flags_identifyFlagQuiet (cstring s)
831 return flags_identifyFlagAux (s, TRUE);
835 flags_identifyFlagAux (cstring s, bool quiet)
837 if (cstring_length (s) == 0) {
838 /* evs 2000-06-25: A malformed flag. */
842 if (cstring_firstChar (s) == 'I')
844 return FLG_INCLUDEPATH; /* no space after -I */
847 if (cstring_firstChar (s) == 'S')
849 return FLG_SPECPATH; /* no space after -S */
852 if (cstring_firstChar (s) == 'D')
854 return FLG_DEFINE; /* no space after -D */
857 if (cstring_firstChar (s) == 'U')
859 return FLG_UNDEFINE; /* no space after -D */
862 canonicalizeFlag (s);
866 if (cstring_equal (cstring_fromChars (f.flag), s))
876 if (cstring_equalLit (s, "pred"))
881 if (cstring_equalLit (s, "modobserverstrict"))
883 return FLG_MODOBSERVERUNCON;
886 if (cstring_equalLit (s, "czechnames"))
891 if (cstring_equalLit (s, "slovaknames"))
896 if (cstring_equalLit (s, "czechoslovaknames"))
898 return FLG_CZECHOSLOVAK;
901 if (cstring_equalLit (s, "globunspec")
902 || cstring_equalLit (s, "globuncon"))
904 return FLG_GLOBUNSPEC;
907 if (cstring_equalLit (s, "modglobsunspec")
908 || cstring_equalLit (s, "modglobsuncon")
909 || cstring_equalLit (s, "modglobsnomods"))
911 return FLG_MODGLOBSUNSPEC;
914 if (cstring_equalLit (s, "export"))
916 return FLG_EXPORTANY;
919 if (cstring_equalLit (s, "macrospec"))
921 return FLG_MACRODECL;
924 if (cstring_equalLit (s, "ansireservedlocal"))
926 return FLG_ANSIRESERVEDLOCAL;
929 if (cstring_equalLit (s, "warnposix"))
931 return FLG_WARNPOSIX;
934 if (cstring_equalLit (s, "defuse"))
939 if (cstring_equalLit (s, "macroundef"))
941 return FLG_MACROUNDEF;
944 if (cstring_equalLit (s, "showcol"))
949 if (cstring_equalLit (s, "intbool"))
954 if (cstring_equalLit (s, "intchar"))
959 if (cstring_equalLit (s, "intenum"))
965 ** Backwards compatibility for our American friends...
968 if (cstring_equalLit (s, "ansilib"))
973 if (cstring_equalLit (s, "ansistrictlib"))
975 return FLG_STRICTLIB;
978 if (cstring_equalLit (s, "skipansiheaders"))
980 return FLG_SKIPANSIHEADERS;
983 if (cstring_equalLit (s, "ansireserved"))
985 return FLG_ANSIRESERVED;
988 if (cstring_equalLit (s, "ansireservedinternal"))
990 return FLG_ANSIRESERVEDLOCAL;
997 if (cstring_equalLit (s, "accessunspec"))
1002 (cstring_makeLiteral
1003 ("accessunspec flag is no longer supported. It has been replaced by accessmodule, accessfile and "
1004 "accessfunction to provide more precise control of accessibility "
1005 "of representations. For more information, "
1006 "see lclint -help accessmodule"));
1011 else if (cstring_equalLit (s, "ansilimits"))
1014 (cstring_makeLiteral
1015 ("ansilimits flag is no longer supported. It has been replaced by ansi89limits and "
1016 "iso99limits to select either the lower translation limits imposed by the ANSI89 "
1017 "standard or the typically higher limits prescribed by ISO C99."));
1021 else if (cstring_equalLit (s, "staticmods"))
1026 (cstring_makeLiteral
1027 ("staticmods flag is obsolete. You probably "
1028 "want impcheckmodstatics. For more information, "
1029 "see lclint -help impcheckmodstatics"));
1034 else if (cstring_equalLit (s, "bool"))
1039 (cstring_makeLiteral ("bool flag is obsolete. It never really "
1040 "made sense in the first place."));
1045 else if (cstring_equalLit (s, "shiftsigned"))
1050 (cstring_makeLiteral ("shiftsigned flag is obsolete. You probably "
1051 "want bitwisesigned, shiftnegative or shiftsize."));
1056 else if (cstring_equalLit (s, "ansi"))
1061 (cstring_makeLiteral ("ansi flag is obsolete. You probably "
1062 "want noparams and/or oldstyle."));
1067 else if (cstring_equalLit (s, "stdio"))
1072 (cstring_makeLiteral
1073 ("stdio flag is obsolete. You may "
1074 "want strictlib or one of the gloabls "
1075 "checking flags. For more information, "
1076 "see lclint -help strictlib or lclint -help flags globals"));
1083 return INVALID_FLAG;
1087 void setValueFlag (flagcode opt, cstring arg)
1095 case FLG_INDENTSPACES:
1097 case FLG_EXTERNALNAMELEN:
1098 case FLG_INTERNALNAMELEN:
1099 case FLG_CONTROLNESTDEPTH:
1100 case FLG_STRINGLITERALLEN:
1101 case FLG_NUMSTRUCTFIELDS:
1102 case FLG_NUMENUMMEMBERS:
1103 case FLG_INCLUDENEST:
1105 int val = cstring_toPosInt (arg);
1112 ("Flag %s must be followed by a positive number number. "
1114 flagcode_unparse (opt), arg));
1118 context_setValueAndFlag (opt, val);
1122 case FLG_COMMENTCHAR:
1124 if (cstring_length (arg) != 1)
1128 ("Flag %s should be followed by a single character. Followed by %s",
1129 flagcode_unparse (opt), arg));
1133 context_setCommentMarkerChar (cstring_firstChar (arg));
1141 void setStringFlag (flagcode opt, /*@only@*/ cstring arg)
1147 if (cstring_lastChar (arg) == CONNECTCHAR)
1149 context_setString (opt, arg);
1153 context_setString (opt, cstring_appendChar (arg, CONNECTCHAR));
1159 context_setString (opt, arg);
1168 cstring s = cstring_makeLiteral ("Flag ");
1169 cstringSList sflags = sortedFlags ();
1173 s = message ("%q%9s", s, cstring_fromChars (modename));
1176 s = message ("%q\n", s);
1178 cstringSList_elements (sflags, flagname)
1180 flagcode code = flags_identifyFlag (flagname);
1181 fflag currentflag = flags[code];
1183 if (mstring_isDefined (currentflag.desc) && flagcode_isModeFlag (code))
1185 s = message ("%q\n%27s", s,
1186 cstring_fromChars (currentflag.flag));
1190 context_setMode (cstring_fromChars (modename));
1192 if (context_getFlag (code))
1194 s = message ("%q%9s", s, cstring_makeLiteralTemp ("+"));
1198 s = message ("%q%9s", s, cstring_makeLiteralTemp (" "));
1201 context_resetModeFlags ();
1204 } end_cstringSList_elements;
1206 cstringSList_free (sflags);
1208 s = cstring_appendChar (s, '\n');
1214 static /*@unused@*/ cstring
1217 cstring s = cstring_makeLiteral ("\t");
1222 if (i != 0 && (i % 4 == 0))
1224 s = message ("%q\n\t%15s", s, cstring_fromChars (modename));
1228 s = message ("%q%15s", s, cstring_fromChars (modename));
1242 if (mstring_isDefined (modename))
1244 if (cstring_equalLit (s, modename))
1254 extern bool flagcode_hasArgument (flagcode f)
1256 return (flags[f].argtype != ARG_NONE);
1259 extern bool flagcode_hasNumber (flagcode f)
1261 return (flags[f].argtype == ARG_NUMBER);
1264 extern bool flagcode_hasChar (flagcode f)
1266 return (flags[f].argtype == ARG_CHAR);
1269 extern bool flagcode_hasString (flagcode f)
1271 return (flags[f].argtype == ARG_STRING
1272 || flags[f].argtype == ARG_FILE
1273 || flags[f].argtype == ARG_DIRECTORY
1274 || flags[f].argtype == ARG_PATH);
1277 extern int flagcode_valueIndex (flagcode f)
1279 /*@unchecked@*/ static bool initialized = FALSE;
1281 /*@unchecked@*/ static flagcode valueFlags[NUMVALUEFLAGS];
1289 if (flagcode_hasNumber (code) || flagcode_hasChar (code))
1291 llassert (nv < NUMVALUEFLAGS);
1292 DPRINTF (("Value flag: %s [%d]", flagcode_unparse (code), (int) code));
1293 valueFlags[nv] = code;
1298 llassertprint (nv == NUMVALUEFLAGS,
1299 ("Number of value flags: %d (expected %d)",
1300 nv, (int) NUMVALUEFLAGS));
1304 for (i = 0; i < NUMVALUEFLAGS; i++)
1306 /* static valueFlags must be defined */
1307 /*@-usedef@*/ if (f == valueFlags[i]) /*@=usedef@*/
1313 fprintf (stderr, "Cannot find value flag: %d", (int) f);
1314 exit (EXIT_FAILURE);
1315 /* Cannot do this...might call recursively...
1316 llfatalbug (message ("Cannot fine value flag: %d", (int) f));
1321 extern int flagcode_stringIndex (flagcode f)
1323 /*@unchecked@*/ static bool initialized = FALSE;
1324 /*@unchecked@*/ static flagcode stringFlags[NUMSTRINGFLAGS];
1334 if (flagcode_hasString (code))
1336 llassertprint (nv < NUMSTRINGFLAGS, ("Incorrect number of string flags: %d (need at least %d)", NUMSTRINGFLAGS, nv));
1337 stringFlags[nv] = code;
1342 llassertprint (nv == NUMSTRINGFLAGS,
1343 ("number of string flags: %d (expected %d)",
1344 nv, NUMSTRINGFLAGS));
1348 for (i = 0; i < NUMSTRINGFLAGS; i++)
1350 /*@-usedef@*/ if (f == stringFlags[i]) /*@=usedef@*/
1356 llbug (message ("Bad string flag: %s", flagcode_unparse (f)));
1360 bool flagcode_isNamePrefixFlag (flagcode f)
1364 case FLG_MACROVARPREFIX:
1366 case FLG_ENUMPREFIX:
1367 case FLG_FILESTATICPREFIX:
1368 case FLG_GLOBPREFIX:
1369 case FLG_TYPEPREFIX:
1370 case FLG_EXTERNALPREFIX:
1371 case FLG_LOCALPREFIX:
1372 case FLG_UNCHECKEDMACROPREFIX:
1373 case FLG_CONSTPREFIX:
1374 case FLG_ITERPREFIX:
1375 case FLG_DECLPARAMPREFIX: