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>", cstring_fromChars (f.flag), argcode_unparse (f.argtype));
509 if (cstring_isDefined (context_getString (f.code)))
511 flagname = message ("%q [%s]", flagname,
512 context_getString (f.code));
515 else if (f.argtype == ARG_CHAR)
517 flagname = message ("%s <%s> [%c]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
518 (char) context_getValue (f.code));
522 llassert (f.argtype == ARG_NUMBER);
523 flagname = message ("%s <%s> [%d]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
524 context_getValue (f.code));
530 flagtype = message("%q<->", flagtype);
535 flagtype = message ("%q<G>", flagtype);
540 flagtype = message("%q<S>", flagtype);
545 flagtype = message ("%q<M:%q>", flagtype, getFlagModeSettings (f.code));
547 else /* its a plain flag */
549 flagtype = message ("%q<P:%s>", flagtype,
550 cstring_makeLiteralTemp (context_getFlag (f.code) ? "+" : "-"));
553 llmsg (message ("%s: %s", flagname, flagtype));
558 describeFlagCode (flagcode flag)
560 cstring ret = cstring_undefined;
563 if (flagcode_isInvalid (flag))
565 return (cstring_makeLiteral ("<invalid>"));
568 context_resetAllFlags ();
571 ret = cstring_copy (cstring_fromChars (f.desc));
574 if (f.sub != FK_NONE)
576 ret = message ("%q\nCategories: %s, %s",
578 categoryName (f.main),
579 categoryName (f.sub));
583 if (f.main != FK_NONE)
585 cstring cname = categoryName (f.main);
587 if (cstring_isDefined (cname))
589 ret = message ("%q\nCategory: %s",
597 ret = message ("%q\nMode Settings: %q",
598 ret, getFlagModeSettings (flag));
602 ret = message ("%q\nDefault Setting: %s",
604 cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
609 ret = message("%q\nSet globally only", ret);
613 ret = message("%q\nSet locally", ret);
622 ret = message("%q\nNumeric Argument. Default: %d",
624 context_getValue (flag));
627 ret = message("%q\nCharacter Argument. Default: %h",
628 ret, (char) context_getValue (flag));
635 if (cstring_isDefined (context_getString (flag)))
637 ret = message("%q\n%q argument. Default: %s",
639 cstring_capitalize (argcode_unparse (f.argtype)),
640 context_getString (flag));
644 ret = message("%q\n%s argument. No default.",
646 cstring_capitalize (argcode_unparse (f.argtype)));
652 if (mstring_isDefined (f.hint))
654 ret = message("%q\n\3%s", ret, cstring_fromChars (f.hint));
660 static cstring getFlagModeSettings (flagcode flag)
662 cstring res = cstring_undefined;
666 context_setModeNoWarn (cstring_fromChars (mname));
668 res = message ("%q%s", res, cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
675 describeFlag (cstring flagname)
677 cstring oflagname = cstring_copy (flagname);
678 flagcode f = flags_identifyFlag (flagname);
680 if (flagcode_isSkip (f))
682 cstring_free (oflagname);
683 return cstring_undefined;
685 else if (flagcode_isValid (f))
687 if (cstring_equal (flagname, oflagname))
689 cstring_free (oflagname);
690 return (message ("%s\n\3%q", flagname, describeFlagCode (f)));
694 return (message ("%q (standardized name: %s)\n\3%q",
695 oflagname, flagname, describeFlagCode (f)));
700 if (isMode (flagname))
702 cstring_free (oflagname);
705 (message ("%s: predefined mode (see Manual for information)",
710 return (message ("%q: <invalid flag>", oflagname));
718 cstringSList s = cstringSList_new ();
724 s = cstringSList_add (s, cstring_fromChars (f.flag));
728 cstringSList_alphabetize (s);
733 void printAlphaFlags ()
735 cstringSList fl = sortedFlags ();
737 cstringSList_printSpaced (fl, 3, 1, context_getLineLen () - 25);
738 cstringSList_free (fl);
741 /*@observer@*/ cstring
742 flagcode_unparse (flagcode code)
744 if (code == INVALID_FLAG)
746 return cstring_makeLiteralTemp ("<invalid flag>");
749 return cstring_fromChars (flags[code].flag);
753 ** Transforms a flag into its cannonical form.
755 ** The following transformations are made:
761 ** parameter -> param
762 ** unrecognized -> unrecog
764 ** declaration -> decl
765 ** globalias -> (no change)
773 ** unconstrained -> unspec
780 canonicalizeFlag (cstring s)
783 static bn_mstring transform[] =
789 "parameter", "param",
790 "unrecognized", "unrecog",
792 "declaration", "decl",
800 "unconstrained", "uncon",
810 while ((current = transform[i]) != NULL)
812 if (cstring_containsLit (s, current))
814 cstring_replaceLit (s, current, transform[i+1]);
819 /* remove whitespace, -'s, and _'s */
820 cstring_stripChars (s, " -_");
824 flags_identifyFlag (cstring s)
826 return flags_identifyFlagAux (s, FALSE);
830 flags_identifyFlagQuiet (cstring s)
832 return flags_identifyFlagAux (s, TRUE);
836 flags_identifyFlagAux (cstring s, bool quiet)
838 if (cstring_length (s) == 0) {
839 /* evs 2000-06-25: A malformed flag. */
843 if (cstring_firstChar (s) == 'I')
845 return FLG_INCLUDEPATH; /* no space after -I */
848 if (cstring_firstChar (s) == 'S')
850 return FLG_SPECPATH; /* no space after -S */
853 if (cstring_firstChar (s) == 'D')
855 return FLG_DEFINE; /* no space after -D */
858 if (cstring_firstChar (s) == 'U')
860 return FLG_UNDEFINE; /* no space after -D */
863 canonicalizeFlag (s);
867 if (cstring_equal (cstring_fromChars (f.flag), s))
877 if (cstring_equalLit (s, "pred"))
882 if (cstring_equalLit (s, "modobserverstrict"))
884 return FLG_MODOBSERVERUNCON;
887 if (cstring_equalLit (s, "czechnames"))
892 if (cstring_equalLit (s, "slovaknames"))
897 if (cstring_equalLit (s, "czechoslovaknames"))
899 return FLG_CZECHOSLOVAK;
902 if (cstring_equalLit (s, "globunspec")
903 || cstring_equalLit (s, "globuncon"))
905 return FLG_GLOBUNSPEC;
908 if (cstring_equalLit (s, "modglobsunspec")
909 || cstring_equalLit (s, "modglobsuncon")
910 || cstring_equalLit (s, "modglobsnomods"))
912 return FLG_MODGLOBSUNSPEC;
915 if (cstring_equalLit (s, "export"))
917 return FLG_EXPORTANY;
920 if (cstring_equalLit (s, "macrospec"))
922 return FLG_MACRODECL;
925 if (cstring_equalLit (s, "ansireservedlocal"))
927 return FLG_ANSIRESERVEDLOCAL;
930 if (cstring_equalLit (s, "warnposix"))
932 return FLG_WARNPOSIX;
935 if (cstring_equalLit (s, "defuse"))
940 if (cstring_equalLit (s, "macroundef"))
942 return FLG_MACROUNDEF;
945 if (cstring_equalLit (s, "showcol"))
950 if (cstring_equalLit (s, "intbool"))
955 if (cstring_equalLit (s, "intchar"))
960 if (cstring_equalLit (s, "intenum"))
966 ** Backwards compatibility for our American friends...
969 if (cstring_equalLit (s, "ansilib"))
974 if (cstring_equalLit (s, "ansistrictlib"))
976 return FLG_STRICTLIB;
979 if (cstring_equalLit (s, "skipansiheaders"))
981 return FLG_SKIPANSIHEADERS;
984 if (cstring_equalLit (s, "ansireserved"))
986 return FLG_ANSIRESERVED;
989 if (cstring_equalLit (s, "ansireservedinternal"))
991 return FLG_ANSIRESERVEDLOCAL;
998 if (cstring_equalLit (s, "accessunspec"))
1003 (cstring_makeLiteral
1004 ("accessunspec flag is no longer supported. It has been replaced by accessmodule, accessfile and "
1005 "accessfunction to provide more precise control of accessibility "
1006 "of representations. For more information, "
1007 "see lclint -help accessmodule"));
1012 else if (cstring_equalLit (s, "ansilimits"))
1015 (cstring_makeLiteral
1016 ("ansilimits flag is no longer supported. It has been replaced by ansi89limits and "
1017 "iso99limits to select either the lower translation limits imposed by the ANSI89 "
1018 "standard or the typically higher limits prescribed by ISO C99."));
1022 else if (cstring_equalLit (s, "staticmods"))
1027 (cstring_makeLiteral
1028 ("staticmods flag is obsolete. You probably "
1029 "want impcheckmodstatics. For more information, "
1030 "see lclint -help impcheckmodstatics"));
1035 else if (cstring_equalLit (s, "bool"))
1040 (cstring_makeLiteral ("bool flag is obsolete. It never really "
1041 "made sense in the first place."));
1046 else if (cstring_equalLit (s, "shiftsigned"))
1051 (cstring_makeLiteral ("shiftsigned flag is obsolete. You probably "
1052 "want bitwisesigned, shiftnegative or shiftsize."));
1057 else if (cstring_equalLit (s, "ansi"))
1062 (cstring_makeLiteral ("ansi flag is obsolete. You probably "
1063 "want noparams and/or oldstyle."));
1068 else if (cstring_equalLit (s, "stdio"))
1073 (cstring_makeLiteral
1074 ("stdio flag is obsolete. You may "
1075 "want strictlib or one of the gloabls "
1076 "checking flags. For more information, "
1077 "see lclint -help strictlib or lclint -help flags globals"));
1084 return INVALID_FLAG;
1088 void setValueFlag (flagcode opt, cstring arg)
1096 case FLG_INDENTSPACES:
1098 case FLG_EXTERNALNAMELEN:
1099 case FLG_INTERNALNAMELEN:
1100 case FLG_CONTROLNESTDEPTH:
1101 case FLG_STRINGLITERALLEN:
1102 case FLG_NUMSTRUCTFIELDS:
1103 case FLG_NUMENUMMEMBERS:
1104 case FLG_INCLUDENEST:
1106 int val = cstring_toPosInt (arg);
1113 ("Flag %s must be followed by a positive number number. "
1115 flagcode_unparse (opt), arg));
1119 context_setValueAndFlag (opt, val);
1123 case FLG_COMMENTCHAR:
1125 if (cstring_length (arg) != 1)
1129 ("Flag %s should be followed by a single character. Followed by %s",
1130 flagcode_unparse (opt), arg));
1134 context_setCommentMarkerChar (cstring_firstChar (arg));
1142 void setStringFlag (flagcode opt, /*@only@*/ cstring arg)
1148 if (cstring_lastChar (arg) == CONNECTCHAR)
1150 context_setString (opt, arg);
1154 context_setString (opt, cstring_appendChar (arg, CONNECTCHAR));
1160 context_setString (opt, arg);
1169 cstring s = cstring_makeLiteral ("Flag ");
1170 cstringSList sflags = sortedFlags ();
1174 s = message ("%q%9s", s, cstring_fromChars (modename));
1177 s = message ("%q\n", s);
1179 cstringSList_elements (sflags, flagname)
1181 flagcode code = flags_identifyFlag (flagname);
1182 fflag currentflag = flags[code];
1184 if (mstring_isDefined (currentflag.desc) && flagcode_isModeFlag (code))
1186 s = message ("%q\n%27s", s,
1187 cstring_fromChars (currentflag.flag));
1191 context_setMode (cstring_fromChars (modename));
1193 if (context_getFlag (code))
1195 s = message ("%q%9s", s, cstring_makeLiteralTemp ("+"));
1199 s = message ("%q%9s", s, cstring_makeLiteralTemp (" "));
1202 context_resetModeFlags ();
1205 } end_cstringSList_elements;
1207 cstringSList_free (sflags);
1209 s = cstring_appendChar (s, '\n');
1215 static /*@unused@*/ cstring
1218 cstring s = cstring_makeLiteral ("\t");
1223 if (i != 0 && (i % 4 == 0))
1225 s = message ("%q\n\t%15s", s, cstring_fromChars (modename));
1229 s = message ("%q%15s", s, cstring_fromChars (modename));
1243 if (mstring_isDefined (modename))
1245 if (cstring_equalLit (s, modename))
1255 extern bool flagcode_hasArgument (flagcode f)
1257 return (flags[f].argtype != ARG_NONE);
1260 extern bool flagcode_hasNumber (flagcode f)
1262 return (flags[f].argtype == ARG_NUMBER);
1265 extern bool flagcode_hasChar (flagcode f)
1267 return (flags[f].argtype == ARG_CHAR);
1270 extern bool flagcode_hasString (flagcode f)
1272 return (flags[f].argtype == ARG_STRING
1273 || flags[f].argtype == ARG_FILE
1274 || flags[f].argtype == ARG_DIRECTORY
1275 || flags[f].argtype == ARG_PATH);
1278 extern int flagcode_valueIndex (flagcode f)
1280 /*@unchecked@*/ static bool initialized = FALSE;
1282 /*@unchecked@*/ static flagcode valueFlags[NUMVALUEFLAGS];
1290 if (flagcode_hasNumber (code) || flagcode_hasChar (code))
1292 llassert (nv < NUMVALUEFLAGS);
1293 DPRINTF (("Value flag: %s [%d]", flagcode_unparse (code), (int) code));
1294 valueFlags[nv] = code;
1299 llassertprint (nv == NUMVALUEFLAGS,
1300 ("Number of value flags: %d (expected %d)",
1301 nv, (int) NUMVALUEFLAGS));
1305 for (i = 0; i < NUMVALUEFLAGS; i++)
1307 /* static valueFlags must be defined */
1308 /*@-usedef@*/ if (f == valueFlags[i]) /*@=usedef@*/
1314 fprintf (stderr, "Cannot find value flag: %d", (int) f);
1315 exit (EXIT_FAILURE);
1316 /* Cannot do this...might call recursively...
1317 llfatalbug (message ("Cannot fine value flag: %d", (int) f));
1322 extern int flagcode_stringIndex (flagcode f)
1324 /*@unchecked@*/ static bool initialized = FALSE;
1325 /*@unchecked@*/ static flagcode stringFlags[NUMSTRINGFLAGS];
1335 if (flagcode_hasString (code))
1337 llassertprint (nv < NUMSTRINGFLAGS, ("Incorrect number of string flags: %d (need at least %d)", NUMSTRINGFLAGS, nv));
1338 stringFlags[nv] = code;
1343 llassertprint (nv == NUMSTRINGFLAGS,
1344 ("number of string flags: %d (expected %d)",
1345 nv, NUMSTRINGFLAGS));
1349 for (i = 0; i < NUMSTRINGFLAGS; i++)
1351 /*@-usedef@*/ if (f == stringFlags[i]) /*@=usedef@*/
1357 llbug (message ("Bad string flag: %s", flagcode_unparse (f)));
1361 bool flagcode_isNamePrefixFlag (flagcode f)
1365 case FLG_MACROVARPREFIX:
1367 case FLG_ENUMPREFIX:
1368 case FLG_FILESTATICPREFIX:
1369 case FLG_GLOBPREFIX:
1370 case FLG_TYPEPREFIX:
1371 case FLG_EXTERNALPREFIX:
1372 case FLG_LOCALPREFIX:
1373 case FLG_UNCHECKEDMACROPREFIX:
1374 case FLG_CONSTPREFIX:
1375 case FLG_ITERPREFIX:
1376 case FLG_DECLPARAMPREFIX: