]> andersk Git - splint.git/blame - src/flagSpec.c
Moved doc/lclint.1 to doc/splint.1
[splint.git] / src / flagSpec.c
CommitLineData
28bf4b0b 1/*
11db3170 2** Splint - annotation-assisted static program checker
77d37419 3** Copyright (C) 1994-2002 University of Virginia,
28bf4b0b 4** Massachusetts Institute of Technology
5**
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.
10**
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.
15**
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.
19**
155af98d 20** For information on splint: info@splint.org
21** To report a bug: splint-bug@splint.org
11db3170 22** For more information: http://www.splint.org
28bf4b0b 23*/
24/*
25** flagSpec.c
26*/
27
1b8ae690 28# include "splintMacros.nf"
28bf4b0b 29# include "basic.h"
30
31static /*@only@*/ flagSpecItem flagSpecItem_create (/*@only@*/ cstring fname)
32{
33 flagSpecItem res = (flagSpecItem) dmalloc (sizeof (*res));
34 res->name = fname;
a956d444 35 res->code = flags_identifyFlag (fname);
28bf4b0b 36 /* Invalid flag okay for now... */
37 return res;
38}
39
40static void flagSpecItem_free (/*@only@*/ flagSpecItem fitem)
41{
42 cstring_free (fitem->name);
43 sfree (fitem);
44}
45
46static /*@only@*/ flagSpec flagSpec_create (/*@only@*/ flagSpecItem fitem,
47 /*@only@*/ flagSpec frest)
48{
49 flagSpec res = (flagSpec) dmalloc (sizeof (*res));
50 res->tspec = fitem;
51 res->trest = frest;
52 return res;
53}
54
55flagSpec flagSpec_createPlain (cstring fname)
56{
57 flagSpecItem fitem = flagSpecItem_create (fname);
58 flagSpec res = flagSpec_create (fitem, flagSpec_undefined);
59 return res;
60}
61
62flagSpec flagSpec_createOr (cstring fname, flagSpec f)
63{
64 return flagSpec_create (flagSpecItem_create (fname), f);
65}
66
67void flagSpec_free (flagSpec f)
68{
69 if (flagSpec_isDefined (f))
70 {
71 flagSpecItem_free (f->tspec);
72 if (flagSpec_isDefined (f->trest))
73 {
74 flagSpec_free (f->trest);
75 }
76
77 sfree (f);
78 }
79}
80
efd360a3 81flagSpec flagSpec_copy (flagSpec f)
82{
83 if (flagSpec_isDefined (f))
84 {
85 if (flagSpec_isDefined (f->trest))
86 {
87 return flagSpec_createOr (cstring_copy (f->tspec->name),
88 flagSpec_copy (f->trest));
89 }
90 else
91 {
92 return flagSpec_createPlain (cstring_copy (f->tspec->name));
93 }
94 }
95 else
96 {
97 return flagSpec_undefined;
98 }
99}
100
28bf4b0b 101cstring flagSpec_unparse (flagSpec f)
102{
103 if (flagSpec_isDefined (f))
104 {
105 if (flagSpec_isDefined (f->trest))
106 {
107 return message ("%s | %q", f->tspec->name, flagSpec_unparse (f->trest));
108 }
109 else
110 {
111 return cstring_copy (f->tspec->name);
112 }
113 }
114 else
115 {
116 return cstring_makeLiteral ("<*** flagSpec undefined ***>");
117 }
118}
119
120cstring flagSpec_dump (flagSpec f)
121{
122 llassert (flagSpec_isDefined (f));
123 llassert (!cstring_containsChar (f->tspec->name, '|'));
124 llassert (!cstring_containsChar (f->tspec->name, '#'));
125
126 if (flagSpec_isDefined (f->trest))
127 {
128 return message ("%s|%q", f->tspec->name, flagSpec_dump (f->trest));
129 }
130 else
131 {
132 return cstring_copy (f->tspec->name);
133 }
134}
135
136flagSpec
137flagSpec_undump (char **s)
138{
139 cstring flagname;
140 flagname = reader_readUntilOne (s, "#|");
141
142 if (reader_optCheckChar (s, '|'))
143 {
144 return flagSpec_createOr (flagname, flagSpec_undump (s));
145 }
146 else
147 {
148 return flagSpec_createPlain (flagname);
149 }
150}
151
152flagcode
153flagSpec_getDominant (flagSpec fs)
154{
155 llassert (flagSpec_isDefined (fs));
156
157 /* Invalid flags? */
158 return fs->tspec->code;
159}
160
161bool
162flagSpec_isOn (flagSpec fs, fileloc loc)
163{
164 llassert (flagSpec_isDefined (fs));
165
166 if (context_flagOn (fs->tspec->code, loc))
167 {
168 return TRUE;
169 }
170 else if (flagSpec_isDefined (fs->trest))
171 {
172 return flagSpec_isOn (fs->trest, loc);
173 }
174 else
175 {
176 return FALSE;
177 }
178}
179
180flagcode
181flagSpec_getFirstOn (flagSpec fs, fileloc loc)
182{
183 llassert (flagSpec_isDefined (fs));
184
185 if (context_flagOn (fs->tspec->code, loc))
186 {
187 return fs->tspec->code;
188 }
189 else if (flagSpec_isDefined (fs->trest))
190 {
191 return flagSpec_getFirstOn (fs->trest, loc);
192 }
193 else
194 {
195 BADBRANCH;
196 }
8250fa4a 197
198 BADBRANCHRET (INVALID_FLAG);
28bf4b0b 199}
This page took 0.081653 seconds and 5 git commands to generate.