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 splint: splint@cs.virginia.edu
21 ** To report a bug: splint-bug@cs.virginia.edu
22 ** For more information: http://www.splint.org
28 # include "splintMacros.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", "warnings about (normal) comments" } ,
58 { FK_SYNCOMMENTS, "syncomments", "interpretation of annotation comments" } ,
59 { FK_COMPLETE, "complete", "completely defined, used, or specified system" } ,
60 { FK_CONTROL, "controlflow", "suspicious control structures" } ,
61 { FK_DEBUG, "debug", "flags for debugging splint" } ,
62 { FK_DECL, "declarations", "consistency of declarations" } ,
63 { FK_DEF, "definition", "undefined storage errors" } ,
64 { FK_DIRECT, "directories", "set directores" } ,
65 { FK_DISPLAY, "display", "control what is displayed" } ,
66 { FK_EFFECT, "effect", "statements with no effects" } ,
67 { FK_ERRORS, "errors", "control expected errors, summary reporting" } ,
68 { FK_EXPORT, "export", "control what may be exported" } ,
69 { FK_EXPOSURE, "exposure", "representation exposure" } ,
70 { FK_EXTENSIBLE, "extensible", "user-defined checks and annotations" },
71 { FK_FILES, "files", "control system files" } ,
72 { FK_FORMAT, "format", "control format of warning messages" } ,
73 { FK_GLOBALS, "globals", "use of global and file static variables" },
74 { FK_HEADERS, "headers", "control inclusion and generation of header files" },
75 { FK_HELP, "help", "on-line help" },
76 { FK_BOUNDS, "memorybounds", "out-of-bounds memory accesses" },
77 { FK_HINTS, "hints", "control display of warning hints" },
78 { FK_SYSTEMFUNCTIONS, "systemfunctions", "special properties of exit and main" },
79 { FK_IMPLICIT, "implicit", "control implicit annotations and interpretations" } ,
80 { FK_INIT, "initializations", "initialization files" } ,
81 { FK_ITER, "iterators", "checking iterator definitions and uses" } ,
82 { FK_LEAK, "leaks", "memory leaks" } ,
83 { FK_LIBS, "libraries", "loading and dumping of user and standard libraries" } ,
84 { FK_LIMITS, "limits", "violations of set limits" } ,
85 { FK_MACROS, "macros", "expansion, definition and use of macros" },
86 { FK_MEMORY, "memory", "memory management" } ,
87 { FK_MODIFIES, "modification", "modification errors" } ,
88 { FK_NAMES, "names", "naming conventions and limits" } ,
89 { FK_NULL, "null", "misuses of null pointers" } ,
90 { FK_NUMBERS, "numbers", "control type-checking of numeric types" } ,
91 { FK_OPS, "operations", "checking of primitive operations" } ,
92 { FK_PARAMS, "parameters", "function and macro parameters" } ,
93 { FK_SPEED, "performance", "speeding up checking" } ,
94 { FK_POINTER, "pointers", "pointers" } ,
95 { FK_PRED, "predicates", "condition test expressions" } ,
96 { FK_PREFIX, "prefixes", "set naming prefixes and control checking" } ,
97 { FK_PREPROC, "preproc", "defines and undefines for the preprocessor" } ,
98 { FK_PROTOS, "prototypes", "function prototypes" } ,
99 { FK_DEAD, "released", "using storage that has been deallocated" } ,
100 { FK_IGNORERET, "returnvals", "ignored return values" },
101 { FK_SECURITY, "security", "possible security vulnerability" },
102 { FK_SPEC, "specifications", "checks involving .lcl specifications" } ,
103 { FK_SUPPRESS, "suppress", "local and global suppression of messages" } ,
104 { FK_TYPEEQ, "typeequivalence", "control what types are equivalent" } ,
105 { FK_BEHAVIOR, "undefined", "code with undefined or implementation-defined behavior" } ,
106 { FK_UNRECOG, "unrecognized", "unrecognized identifiers" } ,
107 { FK_UNSPEC, "unconstrained", "checking in the presence of unconstrained functions" } ,
108 { FK_WARNUSE, "warnuse", "use of possibly problematic function" } ,
109 { FK_ITS4, "its4", "its4 compatibility flags (report warnings for uses of possibly insecure functions)" } ,
110 { FK_SYNTAX, NULL, NULL } ,
111 { FK_TYPE, NULL, NULL } ,
112 { FK_SECRET, NULL, NULL } ,
113 { FK_OBSOLETE, NULL, NULL } ,
114 { FK_NONE, NULL, NULL } /* must be last */
119 ARG_NUMBER, /* number */
121 ARG_STRING, /* string */
122 ARG_FILE, /* filename (also a string) */
123 ARG_DIRECTORY, /* directory (also a string) */
128 static /*@observer@*/ cstring argcode_unparse (argcode arg)
132 case ARG_STRING: return cstring_makeLiteralTemp ("string");
133 case ARG_FILE: return cstring_makeLiteralTemp ("filename");
134 case ARG_DIRECTORY: return cstring_makeLiteralTemp ("directory");
135 case ARG_PATH: return cstring_makeLiteralTemp ("path");
136 case ARG_NUMBER: return cstring_makeLiteralTemp ("number");
137 case ARG_CHAR: return cstring_makeLiteralTemp ("character");
148 bool isSpecial; /* setting this flag may set other flags (or values) */
149 bool isIdem; /* idempotent - always sets to TRUE */
150 bool isGlobal; /* cannot be set locally (using control comments) */
151 bool isModeFlag; /* set by modes */
153 /*@observer@*/ char *flag;
155 /*@observer@*/ /*@null@*/ char *desc;
161 typedef fflag flaglist[];
163 # include "flags.def"
165 /*@iter allFlags (yield observer fflag f); @*/
166 # define allFlags(m_f) \
167 { /*@+enumint@*/ flagcode m_i; for (m_i = 0; m_i < NUMFLAGS; m_i++) { fflag m_f = flags[m_i]; /*@=enumint@*/
168 # define end_allFlags }}
170 static bn_mstring mode_names[] =
172 "weak", "standard", "checks", "strict", NULL,
175 /*@iter allModes (yield bn_mstring modename)@*/
176 # define allModes(m_m) \
177 { int m_ii = 0; while (mstring_isDefined (mode_names[m_ii])) \
178 { bn_mstring m_m = mode_names[m_ii]; m_ii++;
180 # define end_allModes }}
184 static cstring getFlagModeSettings (flagcode p_flag) /*@modifies internalState@*/ ;
185 static cstring describeFlagCode (flagcode p_flag) /*@*/ ;
186 static cstringSList sortedFlags (void) /*@*/ ;
187 static /*@observer@*/ cstring categoryName (flagkind p_kind) /*@*/ ;
189 static flagcode flags_identifyFlagAux (cstring p_s, bool p_quiet) /*@modifies g_msgstream@*/ ;
192 static /*@unused@*/ cstring listModes (void) /*@*/ ;
195 bool flagcode_isSpecialFlag (flagcode f)
197 return (flags[f].isSpecial);
200 bool flagcode_isGlobalFlag (flagcode f)
202 return (flags[f].isGlobal);
205 bool flagcode_isIdemFlag (flagcode f)
207 return (flags[f].isIdem);
210 bool flagcode_isModeFlag (flagcode f)
212 return (flags[f].isModeFlag);
215 bool flagcode_isNameChecksFlag (flagcode f)
217 return (flags[f].main == FK_NAMES);
221 ** Internal consistency check on the flags.
224 void flags_initMod ()
229 if (flags[code].code != code)
232 "*** ERROR: inconsistent flag %s / %d / %d",
234 flags[code].code, code);
236 llbug (message ("*** ERROR: inconsistent flag %s / %d / %d",
237 cstring_fromChars (flags[code].flag),
238 flags[code].code, code));
251 char *buf = mstring_create (128);
255 if (f.nreported > 0 || f.nsuppressed > 0)
257 int nrep = f.nreported;
258 int nsup = f.nsuppressed;
259 cstring fs = cstring_fill (cstring_fromChars (f.flag), 23);
263 llmsgplain (cstring_makeLiteral
264 ("\nError Type Reported Suppressed\n"
265 "=================== ======== ========="));
269 sprintf (buf, "%s%7d %9d", cstring_toCharsSafe (fs), nrep, nsup);
275 llmsg (cstring_copy (cstring_fromChars (buf)));
281 cstring ts = cstring_fill (cstring_makeLiteralTemp ("Total"), 23);
283 llmsglit (" ======== =========");
285 sprintf (buf, "%s%7d %9d", cstring_toCharsSafe (ts), sumrep, sumsup);
287 llmsgplain (cstring_copy (cstring_fromChars (buf)));
296 flagcode_recordError (flagcode f)
298 if (f != INVALID_FLAG)
300 if (f == FLG_WARNFLAGS)
302 ; /* don't count these */
306 flags[f].nreported = flags[f].nreported + 1;
311 llcontbug (message ("flagcode_recordError: invalid flag: %d", (int) f));
316 flagcode_recordSuppressed (flagcode f)
318 llassertprint (f != INVALID_FLAG, ("flagcode: %s", flagcode_unparse (f)));
320 flags[f].nsuppressed = flags[f].nsuppressed + 1;
324 flagcode_numReported (flagcode f)
326 llassert (f != INVALID_FLAG);
328 return (flags[f].nreported);
331 /*@observer@*/ cstring
332 flagcodeHint (flagcode f)
334 llassert (f != INVALID_FLAG);
336 if (mstring_isDefined (flags[f].hint))
338 return (cstring_fromChars (flags[f].hint));
342 return (cstring_fromChars (flags[f].desc));
346 static int categorySize (flagkind kind) /*@*/
353 if (f.main == kind || f.sub == kind)
362 flagkind identifyCategory (cstring s)
366 for (i = 0; categories[i].kind != FK_NONE; i++)
368 if (mstring_isDefined (categories[i].name))
370 if (cstring_equalLit (s, categories[i].name))
372 return categories[i].kind;
380 static /*@observer@*/ cstring categoryName (flagkind kind)
384 for (i = 0; categories[i].kind != FK_NONE; i++)
386 if (categories[i].kind == kind)
388 return (cstring_fromChars (categories[i].name));
392 return (cstring_makeLiteralTemp ("<No Category>"));
395 static int categoryIndex (flagkind kind)
399 for (i = 0; categories[i].kind != FK_NONE; i++)
401 if (categories[i].kind == kind)
410 void printCategory (flagkind kind)
412 int index = categoryIndex (kind);
414 llassert (index >= 0);
416 llmsg (message ("%s (%d flags)\n\3%s\n\n",
417 cstring_fromChars (categories[index].name),
419 cstring_fromChars (categories[index].describe)));
423 if (f.main == kind || f.sub == kind)
425 llmsg (message (" %s\n\6%q", cstring_fromChars (f.flag),
426 describeFlagCode (f.code)));
432 listAllCategories (void)
436 for (i = 0; categories[i].kind != FK_NONE; i++)
438 flagkind kind = categories[i].kind ;
440 if (categories[i].describe != NULL)
442 llmsg (message ("%s (%d flags)\n\3%s",
445 cstring_fromChars (categories[i].describe)));
451 printAllFlags (bool desc, bool full)
455 cstringSList fl = sortedFlags ();
457 cstringSList_elements (fl, el)
459 llmsg (message ("%q\n\n", describeFlag (el)));
460 } end_cstringSList_elements ;
462 cstringSList_free (fl);
468 if (f.code != INVALID_FLAG && f.main != FK_OBSOLETE)
470 if (mstring_isDefined (f.desc))
474 llmsg (message ("%s --- %s", cstring_fromChars (f.flag),
475 cstring_fromChars (f.desc)));
484 printFlagManual (void)
487 ** Prints all flags by category, in order they appear in flags.def
490 flagkind lastCategory = FK_NONE;
494 cstring flagtype = cstring_undefined;
496 if (f.main != lastCategory)
498 llmsg (message ("\n%s\n%s\n",
499 categoryName (f.main),
500 cstring_makeLiteralTemp ("===================================")));
502 lastCategory = f.main;
505 if (f.argtype == ARG_NONE || f.argtype == ARG_SPECIAL)
507 flagname = cstring_fromCharsNew (f.flag);
511 if (flagcode_hasString (f.code))
513 flagname = message ("%s <%s>", cstring_fromChars (f.flag), argcode_unparse (f.argtype));
515 if (cstring_isDefined (context_getString (f.code)))
517 flagname = message ("%q [%s]", flagname,
518 context_getString (f.code));
521 else if (f.argtype == ARG_CHAR)
523 flagname = message ("%s <%s> [%c]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
524 (char) context_getValue (f.code));
528 llassert (f.argtype == ARG_NUMBER);
529 flagname = message ("%s <%s> [%d]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
530 context_getValue (f.code));
536 flagtype = message("%q<->", flagtype);
541 flagtype = message ("%q<G>", flagtype);
546 flagtype = message("%q<S>", flagtype);
551 flagtype = message ("%q<M:%q>", flagtype, getFlagModeSettings (f.code));
553 else /* its a plain flag */
555 flagtype = message ("%q<P:%s>", flagtype,
556 cstring_makeLiteralTemp (context_getFlag (f.code) ? "+" : "-"));
559 llmsg (message ("%s: %s", flagname, flagtype));
561 if (mstring_isDefined (f.hint))
563 llgenindentmsgnoloc (cstring_fromCharsNew (f.hint));
567 llgenindentmsgnoloc (message ("%q.", cstring_capitalize (cstring_fromChars (f.desc))));
573 describeFlagCode (flagcode flag)
575 cstring ret = cstring_undefined;
578 if (flagcode_isInvalid (flag))
580 return (cstring_makeLiteral ("<invalid>"));
583 context_resetAllFlags ();
586 ret = cstring_copy (cstring_fromChars (f.desc));
588 if (f.sub != FK_NONE)
590 ret = message ("%q\nCategories: %s, %s",
592 categoryName (f.main),
593 categoryName (f.sub));
597 if (f.main != FK_NONE)
599 cstring cname = categoryName (f.main);
601 if (cstring_isDefined (cname))
603 ret = message ("%q\nCategory: %s",
611 ret = message ("%q\nMode Settings: %q",
612 ret, getFlagModeSettings (flag));
616 ret = message ("%q\nDefault Setting: %s",
618 cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
623 ret = message("%q\nSet globally only", ret);
627 ret = message("%q\nSet locally", ret);
636 ret = message("%q\nNumeric Argument. Default: %d",
638 context_getValue (flag));
641 ret = message("%q\nCharacter Argument. Default: %h",
642 ret, (char) context_getValue (flag));
649 if (cstring_isDefined (context_getString (flag)))
651 ret = message("%q\n%q argument. Default: %s",
653 cstring_capitalize (argcode_unparse (f.argtype)),
654 context_getString (flag));
658 ret = message("%q\n%s argument. No default.",
660 cstring_capitalize (argcode_unparse (f.argtype)));
666 if (mstring_isDefined (f.hint))
668 ret = message("%q\n\3%s", ret, cstring_fromChars (f.hint));
674 static cstring getFlagModeSettings (flagcode flag)
676 cstring res = cstring_undefined;
680 context_setModeNoWarn (cstring_fromChars (mname));
682 res = message ("%q%s", res, cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
689 describeFlag (cstring flagname)
691 cstring oflagname = cstring_copy (flagname);
692 flagcode f = flags_identifyFlag (flagname);
694 if (flagcode_isSkip (f))
696 cstring_free (oflagname);
697 return cstring_undefined;
699 else if (flagcode_isValid (f))
701 if (cstring_equal (flagname, oflagname))
703 cstring_free (oflagname);
704 return (message ("%s\n\3%q", flagname, describeFlagCode (f)));
708 return (message ("%q (standardized name: %s)\n\3%q",
709 oflagname, flagname, describeFlagCode (f)));
714 if (isMode (flagname))
716 cstring_free (oflagname);
719 (message ("%s: predefined mode (see Manual for information)",
724 return (message ("%q: <invalid flag>", oflagname));
732 cstringSList s = cstringSList_new ();
738 s = cstringSList_add (s, cstring_fromChars (f.flag));
742 cstringSList_alphabetize (s);
747 void printAlphaFlags ()
749 cstringSList fl = sortedFlags ();
751 cstringSList_printSpaced (fl, 3, 1, context_getLineLen () - 25);
752 cstringSList_free (fl);
755 /*@observer@*/ cstring
756 flagcode_unparse (flagcode code)
758 if (code == INVALID_FLAG)
760 return cstring_makeLiteralTemp ("<invalid flag>");
763 return cstring_fromChars (flags[code].flag);
767 ** Transforms a flag into its cannonical form.
769 ** The following transformations are made:
775 ** parameter -> param
776 ** unrecognized -> unrecog
778 ** declaration -> decl
779 ** globalias -> (no change)
787 ** unconstrained -> unspec
794 canonicalizeFlag (cstring s)
797 static bn_mstring transform[] =
803 "parameter", "param",
804 "unrecognized", "unrecog",
806 "declaration", "decl",
814 "unconstrained", "uncon",
824 while ((current = transform[i]) != NULL)
826 if (cstring_containsLit (s, current))
828 cstring_replaceLit (s, current, transform[i+1]);
833 /* remove whitespace, -'s, and _'s */
834 cstring_stripChars (s, " -_");
838 flags_identifyFlag (cstring s)
840 return flags_identifyFlagAux (s, FALSE);
844 flags_identifyFlagQuiet (cstring s)
846 return flags_identifyFlagAux (s, TRUE);
850 flags_identifyFlagAux (cstring s, bool quiet)
852 if (cstring_length (s) == 0) {
853 /* evs 2000-06-25: A malformed flag. */
857 if (cstring_firstChar (s) == 'I')
859 return FLG_INCLUDEPATH; /* no space after -I */
862 if (cstring_firstChar (s) == 'S')
864 return FLG_SPECPATH; /* no space after -S */
867 if (cstring_firstChar (s) == 'D')
869 return FLG_DEFINE; /* no space after -D */
872 if (cstring_firstChar (s) == 'U')
874 return FLG_UNDEFINE; /* no space after -D */
877 canonicalizeFlag (s);
881 if (cstring_equal (cstring_fromChars (f.flag), s))
891 if (cstring_equalLit (s, "pred"))
896 if (cstring_equalLit (s, "modobserverstrict"))
898 return FLG_MODOBSERVERUNCON;
901 if (cstring_equalLit (s, "czechnames"))
906 if (cstring_equalLit (s, "slovaknames"))
911 if (cstring_equalLit (s, "czechoslovaknames"))
913 return FLG_CZECHOSLOVAK;
916 if (cstring_equalLit (s, "globunspec")
917 || cstring_equalLit (s, "globuncon"))
919 return FLG_GLOBUNSPEC;
922 if (cstring_equalLit (s, "modglobsunspec")
923 || cstring_equalLit (s, "modglobsuncon")
924 || cstring_equalLit (s, "modglobsnomods"))
926 return FLG_MODGLOBSUNSPEC;
929 if (cstring_equalLit (s, "export"))
931 return FLG_EXPORTANY;
934 if (cstring_equalLit (s, "macrospec"))
936 return FLG_MACRODECL;
939 if (cstring_equalLit (s, "ansireservedlocal"))
941 return FLG_ANSIRESERVEDLOCAL;
944 if (cstring_equalLit (s, "warnposix"))
946 return FLG_WARNPOSIX;
949 if (cstring_equalLit (s, "defuse"))
954 if (cstring_equalLit (s, "macroundef"))
956 return FLG_MACROUNDEF;
959 if (cstring_equalLit (s, "showcol"))
964 if (cstring_equalLit (s, "intbool"))
969 if (cstring_equalLit (s, "intchar"))
974 if (cstring_equalLit (s, "intenum"))
980 ** Backwards compatibility for our American friends...
983 if (cstring_equalLit (s, "ansilib"))
988 if (cstring_equalLit (s, "ansistrictlib"))
990 return FLG_STRICTLIB;
993 if (cstring_equalLit (s, "skipansiheaders"))
995 return FLG_SKIPANSIHEADERS;
998 if (cstring_equalLit (s, "ansireserved"))
1000 return FLG_ANSIRESERVED;
1003 if (cstring_equalLit (s, "ansireservedinternal"))
1005 return FLG_ANSIRESERVEDLOCAL;
1012 if (cstring_equalLit (s, "accessunspec"))
1017 (cstring_makeLiteral
1018 ("accessunspec flag is no longer supported. It has been replaced by accessmodule, accessfile and "
1019 "accessfunction to provide more precise control of accessibility "
1020 "of representations. For more information, "
1021 "see splint -help accessmodule"));
1026 else if (cstring_equalLit (s, "ansilimits"))
1029 (cstring_makeLiteral
1030 ("ansilimits flag is no longer supported. It has been replaced by ansi89limits and "
1031 "iso99limits to select either the lower translation limits imposed by the ANSI89 "
1032 "standard or the typically higher limits prescribed by ISO C99."));
1036 else if (cstring_equalLit (s, "staticmods"))
1041 (cstring_makeLiteral
1042 ("staticmods flag is obsolete. You probably "
1043 "want impcheckmodstatics. For more information, "
1044 "see splint -help impcheckmodstatics"));
1049 else if (cstring_equalLit (s, "bool"))
1054 (cstring_makeLiteral ("bool flag is obsolete. It never really "
1055 "made sense in the first place."));
1060 else if (cstring_equalLit (s, "shiftsigned"))
1065 (cstring_makeLiteral ("shiftsigned flag is obsolete. You probably "
1066 "want bitwisesigned, shiftnegative or shiftsize."));
1071 else if (cstring_equalLit (s, "ansi"))
1076 (cstring_makeLiteral ("ansi flag is obsolete. You probably "
1077 "want noparams and/or oldstyle."));
1082 else if (cstring_equalLit (s, "stdio"))
1087 (cstring_makeLiteral
1088 ("stdio flag is obsolete. You may "
1089 "want strictlib or one of the gloabls "
1090 "checking flags. For more information, "
1091 "see splint -help strictlib or splint -help flags globals"));
1098 return INVALID_FLAG;
1102 void setValueFlag (flagcode opt, cstring arg)
1110 case FLG_INDENTSPACES:
1112 case FLG_EXTERNALNAMELEN:
1113 case FLG_INTERNALNAMELEN:
1114 case FLG_CONTROLNESTDEPTH:
1115 case FLG_STRINGLITERALLEN:
1116 case FLG_NUMSTRUCTFIELDS:
1117 case FLG_NUMENUMMEMBERS:
1118 case FLG_INCLUDENEST:
1120 int val = cstring_toPosInt (arg);
1127 ("Flag %s must be followed by a positive number number. "
1129 flagcode_unparse (opt), arg));
1133 context_setValueAndFlag (opt, val);
1137 case FLG_COMMENTCHAR:
1139 if (cstring_length (arg) != 1)
1143 ("Flag %s should be followed by a single character. Followed by %s",
1144 flagcode_unparse (opt), arg));
1148 context_setCommentMarkerChar (cstring_firstChar (arg));
1156 void setStringFlag (flagcode opt, /*@only@*/ cstring arg)
1162 if (cstring_lastChar (arg) == CONNECTCHAR)
1164 context_setString (opt, arg);
1168 context_setString (opt, cstring_appendChar (arg, CONNECTCHAR));
1174 context_setString (opt, arg);
1183 cstring s = cstring_makeLiteral ("Flag ");
1184 cstringSList sflags = sortedFlags ();
1188 s = message ("%q%9s", s, cstring_fromChars (modename));
1191 s = message ("%q\n", s);
1193 cstringSList_elements (sflags, flagname)
1195 flagcode code = flags_identifyFlag (flagname);
1196 fflag currentflag = flags[code];
1198 if (mstring_isDefined (currentflag.desc) && flagcode_isModeFlag (code))
1200 s = message ("%q\n%27s", s,
1201 cstring_fromChars (currentflag.flag));
1205 context_setMode (cstring_fromChars (modename));
1207 if (context_getFlag (code))
1209 s = message ("%q%9s", s, cstring_makeLiteralTemp ("+"));
1213 s = message ("%q%9s", s, cstring_makeLiteralTemp (" "));
1216 context_resetModeFlags ();
1219 } end_cstringSList_elements;
1221 cstringSList_free (sflags);
1223 s = cstring_appendChar (s, '\n');
1229 static /*@unused@*/ cstring
1232 cstring s = cstring_makeLiteral ("\t");
1237 if (i != 0 && (i % 4 == 0))
1239 s = message ("%q\n\t%15s", s, cstring_fromChars (modename));
1243 s = message ("%q%15s", s, cstring_fromChars (modename));
1257 if (mstring_isDefined (modename))
1259 if (cstring_equalLit (s, modename))
1269 extern bool flagcode_hasArgument (flagcode f)
1271 return (flags[f].argtype != ARG_NONE);
1274 extern bool flagcode_hasNumber (flagcode f)
1276 return (flags[f].argtype == ARG_NUMBER);
1279 extern bool flagcode_hasChar (flagcode f)
1281 return (flags[f].argtype == ARG_CHAR);
1284 extern bool flagcode_hasString (flagcode f)
1286 return (flags[f].argtype == ARG_STRING
1287 || flags[f].argtype == ARG_FILE
1288 || flags[f].argtype == ARG_DIRECTORY
1289 || flags[f].argtype == ARG_PATH);
1292 extern int flagcode_valueIndex (flagcode f)
1294 /*@unchecked@*/ static bool initialized = FALSE;
1296 /*@unchecked@*/ static flagcode valueFlags[NUMVALUEFLAGS];
1304 if (flagcode_hasNumber (code) || flagcode_hasChar (code))
1306 llassert (nv < NUMVALUEFLAGS);
1307 DPRINTF (("Value flag: %s [%d]", flagcode_unparse (code), (int) code));
1308 valueFlags[nv] = code;
1313 llassertprint (nv == NUMVALUEFLAGS,
1314 ("Number of value flags: %d (expected %d)",
1315 nv, (int) NUMVALUEFLAGS));
1319 for (i = 0; i < NUMVALUEFLAGS; i++)
1321 /* static valueFlags must be defined */
1322 /*@-usedef@*/ if (f == valueFlags[i]) /*@=usedef@*/
1328 fprintf (stderr, "Cannot find value flag: %d", (int) f);
1329 exit (EXIT_FAILURE);
1330 /* Cannot do this...might call recursively...
1331 llfatalbug (message ("Cannot fine value flag: %d", (int) f));
1336 extern int flagcode_stringIndex (flagcode f)
1338 /*@unchecked@*/ static bool initialized = FALSE;
1339 /*@unchecked@*/ static flagcode stringFlags[NUMSTRINGFLAGS];
1349 if (flagcode_hasString (code))
1351 llassertprint (nv < NUMSTRINGFLAGS, ("Incorrect number of string flags: %d (need at least %d)", NUMSTRINGFLAGS, nv));
1352 stringFlags[nv] = code;
1357 llassertprint (nv == NUMSTRINGFLAGS,
1358 ("number of string flags: %d (expected %d)",
1359 nv, NUMSTRINGFLAGS));
1363 for (i = 0; i < NUMSTRINGFLAGS; i++)
1365 /*@-usedef@*/ if (f == stringFlags[i]) /*@=usedef@*/
1371 llbug (message ("Bad string flag: %s", flagcode_unparse (f)));
1375 bool flagcode_isNamePrefixFlag (flagcode f)
1379 case FLG_MACROVARPREFIX:
1381 case FLG_ENUMPREFIX:
1382 case FLG_FILESTATICPREFIX:
1383 case FLG_GLOBPREFIX:
1384 case FLG_TYPEPREFIX:
1385 case FLG_EXTERNALPREFIX:
1386 case FLG_LOCALPREFIX:
1387 case FLG_UNCHECKEDMACROPREFIX:
1388 case FLG_CONSTPREFIX:
1389 case FLG_ITERPREFIX:
1390 case FLG_DECLPARAMPREFIX: