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