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: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 # include "splintMacros.nf"
31 static /*@only@*/ flagSpecItem flagSpecItem_create (/*@only@*/ cstring fname)
33 flagSpecItem res = (flagSpecItem) dmalloc (sizeof (*res));
35 res->code = flags_identifyFlag (fname);
36 /* Invalid flag okay for now... */
40 static void flagSpecItem_free (/*@only@*/ flagSpecItem fitem)
42 cstring_free (fitem->name);
46 static /*@only@*/ flagSpec flagSpec_create (/*@only@*/ flagSpecItem fitem,
47 /*@only@*/ flagSpec frest)
49 flagSpec res = (flagSpec) dmalloc (sizeof (*res));
55 flagSpec flagSpec_createPlain (cstring fname)
57 flagSpecItem fitem = flagSpecItem_create (fname);
58 flagSpec res = flagSpec_create (fitem, flagSpec_undefined);
62 flagSpec flagSpec_createOr (cstring fname, flagSpec f)
64 return flagSpec_create (flagSpecItem_create (fname), f);
67 void flagSpec_free (flagSpec f)
69 if (flagSpec_isDefined (f))
71 flagSpecItem_free (f->tspec);
72 if (flagSpec_isDefined (f->trest))
74 flagSpec_free (f->trest);
81 flagSpec flagSpec_copy (flagSpec f)
83 if (flagSpec_isDefined (f))
85 if (flagSpec_isDefined (f->trest))
87 return flagSpec_createOr (cstring_copy (f->tspec->name),
88 flagSpec_copy (f->trest));
92 return flagSpec_createPlain (cstring_copy (f->tspec->name));
97 return flagSpec_undefined;
101 cstring flagSpec_unparse (flagSpec f)
103 if (flagSpec_isDefined (f))
105 if (flagSpec_isDefined (f->trest))
107 return message ("%s | %q", f->tspec->name, flagSpec_unparse (f->trest));
111 return cstring_copy (f->tspec->name);
116 return cstring_makeLiteral ("<*** flagSpec undefined ***>");
120 cstring flagSpec_dump (flagSpec f)
122 llassert (flagSpec_isDefined (f));
123 llassert (!cstring_containsChar (f->tspec->name, '|'));
124 llassert (!cstring_containsChar (f->tspec->name, '#'));
126 if (flagSpec_isDefined (f->trest))
128 return message ("%s|%q", f->tspec->name, flagSpec_dump (f->trest));
132 return cstring_copy (f->tspec->name);
137 flagSpec_undump (char **s)
140 flagname = reader_readUntilOne (s, "#|");
142 if (reader_optCheckChar (s, '|'))
144 return flagSpec_createOr (flagname, flagSpec_undump (s));
148 return flagSpec_createPlain (flagname);
153 flagSpec_getDominant (flagSpec fs)
155 llassert (flagSpec_isDefined (fs));
158 return fs->tspec->code;
162 flagSpec_isOn (flagSpec fs, fileloc loc)
164 llassert (flagSpec_isDefined (fs));
166 if (context_flagOn (fs->tspec->code, loc))
170 else if (flagSpec_isDefined (fs->trest))
172 return flagSpec_isOn (fs->trest, loc);
181 flagSpec_getFirstOn (flagSpec fs, fileloc loc)
183 llassert (flagSpec_isDefined (fs));
185 if (context_flagOn (fs->tspec->code, loc))
187 return fs->tspec->code;
189 else if (flagSpec_isDefined (fs->trest))
191 return flagSpec_getFirstOn (fs->trest, loc);
198 BADBRANCHRET (INVALID_FLAG);