]>
Commit | Line | Data |
---|---|---|
616915dd | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
77d37419 | 3 | ** Copyright (C) 1994-2002 University of Virginia, |
616915dd | 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 |
616915dd | 23 | */ |
24 | /* | |
25 | ** flagMarker.c | |
26 | */ | |
27 | ||
1b8ae690 | 28 | # include "splintMacros.nf" |
616915dd | 29 | # include "basic.h" |
30 | ||
31 | flagMarker flagMarker_createLocalSet (flagcode code, ynm set, fileloc loc) | |
32 | { | |
33 | flagMarker c = (flagMarker) dmalloc (sizeof (*c)); | |
34 | ||
35 | c->kind = FMK_LOCALSET; | |
36 | c->code = code; | |
37 | c->info.set = set; | |
38 | c->loc = fileloc_copy (loc); | |
39 | ||
40 | return c; | |
41 | } | |
42 | ||
43 | flagMarker flagMarker_createSuppress (flagcode code, fileloc loc) | |
44 | { | |
45 | flagMarker c = (flagMarker) dmalloc (sizeof (*c)); | |
46 | ||
47 | c->kind = FMK_SUPPRESS; | |
48 | c->code = code; | |
49 | c->loc = fileloc_copy (loc); | |
50 | ||
51 | return c; | |
52 | } | |
53 | ||
54 | flagMarker flagMarker_createIgnoreOn (fileloc loc) | |
55 | { | |
56 | flagMarker c = (flagMarker) dmalloc (sizeof (*c)); | |
57 | ||
58 | c->kind = FMK_IGNOREON; | |
59 | c->code = INVALID_FLAG; | |
60 | c->loc = fileloc_copy (loc); | |
61 | ||
62 | return c; | |
63 | } | |
64 | ||
65 | flagMarker flagMarker_createIgnoreCount (int count, fileloc loc) | |
66 | { | |
67 | flagMarker c = (flagMarker) dmalloc (sizeof (*c)); | |
68 | ||
69 | c->kind = FMK_IGNORECOUNT; | |
70 | c->code = INVALID_FLAG; | |
71 | c->info.nerrors = count; | |
72 | c->loc = fileloc_copy (loc); | |
73 | ||
28bf4b0b | 74 | DPRINTF (("Create ignore count: %s", flagMarker_unparse (c))); |
616915dd | 75 | return c; |
76 | } | |
77 | ||
78 | flagMarker flagMarker_createIgnoreOff (fileloc loc) | |
79 | { | |
80 | flagMarker c = (flagMarker) dmalloc (sizeof (*c)); | |
81 | ||
82 | c->kind = FMK_IGNOREOFF; | |
83 | c->code = INVALID_FLAG; | |
84 | c->loc = fileloc_copy (loc); | |
85 | ||
86 | return c; | |
87 | } | |
88 | ||
89 | ynm flagMarker_getSet (flagMarker f) | |
90 | { | |
91 | llassert (f->kind == FMK_LOCALSET); | |
92 | ||
93 | return f->info.set; | |
94 | } | |
95 | ||
96 | flagcode flagMarker_getCode (flagMarker f) | |
97 | { | |
98 | llassert (f->kind == FMK_LOCALSET|| f->kind == FMK_SUPPRESS); | |
99 | ||
100 | return f->code; | |
101 | } | |
102 | ||
103 | int flagMarker_getCount (flagMarker f) | |
104 | { | |
105 | llassert (f->kind == FMK_IGNORECOUNT); | |
106 | ||
107 | return f->info.nerrors; | |
108 | } | |
109 | ||
abd7f895 | 110 | bool flagMarker_equal (flagMarker f1, flagMarker f2) |
111 | { | |
112 | if (f1->kind != f2->kind) | |
113 | { | |
114 | return FALSE; | |
115 | } | |
116 | ||
117 | if (!fileloc_equal (f1->loc, f2->loc)) | |
118 | { | |
119 | return FALSE; | |
120 | } | |
121 | ||
122 | switch (f1->kind) | |
123 | { | |
124 | case FMK_LOCALSET: | |
125 | return (f1->info.set == f2->info.set | |
126 | && flagcode_equal (f1->code, f2->code)); | |
127 | case FMK_IGNORECOUNT: | |
128 | return (f1->info.nerrors == f2->info.nerrors); | |
129 | case FMK_IGNOREON: | |
130 | case FMK_IGNOREOFF: | |
131 | return TRUE; | |
132 | case FMK_SUPPRESS: | |
133 | return (flagcode_equal (f1->code, f2->code)); | |
134 | } | |
135 | ||
21f0106c | 136 | BADBRANCHRET (FALSE); |
abd7f895 | 137 | } |
138 | ||
616915dd | 139 | cstring flagMarker_unparse (flagMarker c) |
140 | { | |
141 | switch (c->kind) | |
142 | { | |
143 | case FMK_LOCALSET: | |
144 | return (message ("%q: %s%s", | |
145 | fileloc_unparse (c->loc), ynm_unparseCode (c->info.set), | |
28bf4b0b | 146 | flagcode_unparse (c->code))); |
616915dd | 147 | case FMK_IGNORECOUNT: |
148 | return (message ("%q: ignore count %d", | |
149 | fileloc_unparse (c->loc), c->info.nerrors)); | |
150 | case FMK_IGNOREON: | |
151 | return (message ("%q: ignore on", | |
152 | fileloc_unparse (c->loc))); | |
153 | case FMK_IGNOREOFF: | |
154 | return (message ("%q: ignore off", | |
155 | fileloc_unparse (c->loc))); | |
156 | case FMK_SUPPRESS: | |
157 | return (message ("%q: suppress %s", | |
158 | fileloc_unparse (c->loc), | |
28bf4b0b | 159 | flagcode_unparse (c->code))); |
616915dd | 160 | } |
161 | ||
8250fa4a | 162 | BADBRANCHRET (cstring_undefined); |
616915dd | 163 | } |
164 | ||
165 | void flagMarker_free (/*@only@*/ flagMarker c) | |
166 | { | |
11db3170 | 167 | fileloc_free (c->loc); /* evans 2001-03-24: Splint caught this... */ |
616915dd | 168 | sfree (c); |
169 | } | |
170 | ||
171 | bool flagMarker_sameFile (flagMarker c, fileloc loc) | |
172 | { | |
173 | return (fileloc_almostSameFile (c->loc, loc)); | |
174 | } | |
175 | ||
176 | /* | |
177 | ** return true if loc is before c->loc | |
178 | */ | |
179 | ||
180 | bool flagMarker_beforeMarker (flagMarker c, fileloc loc) | |
181 | { | |
182 | return (!fileloc_notAfter (c->loc, loc)); | |
183 | } | |
184 | ||
185 | ||
186 |