]>
Commit | Line | Data |
---|---|---|
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 | ** warnClause.c | |
26 | */ | |
27 | ||
1b8ae690 | 28 | # include "splintMacros.nf" |
28bf4b0b | 29 | # include "basic.h" |
28bf4b0b | 30 | |
31 | static warnClause warnClause_createAux (/*@only@*/ fileloc loc, | |
32 | /*@only@*/ flagSpec flag, | |
6970c11b | 33 | /*@only@*/ cstring msg) |
28bf4b0b | 34 | { |
35 | warnClause res = (warnClause) dmalloc (sizeof (*res)); | |
36 | ||
37 | res->loc = loc; | |
38 | res->flag = flag; | |
39 | res->msg = msg; | |
40 | ||
80489f0a | 41 | DPRINTF (("Creating warn clause with flag spec: [%p] %s", flag, |
42 | flagSpec_unparse (flag))); | |
28bf4b0b | 43 | return res; |
44 | } | |
45 | ||
6970c11b | 46 | extern warnClause warnClause_create (lltok tok, flagSpec flag, cstring msg) |
28bf4b0b | 47 | { |
48 | warnClause res; | |
80489f0a | 49 | /* |
50 | ** evans 2002-03-11 | |
51 | ** was | |
52 | ** res = warnClause_createAux (lltok_stealLoc (tok), flag, msg); | |
53 | ** but this leads to unexplained (yet) crashes. | |
54 | ** Reported by Walter Briscoe | |
55 | */ | |
56 | ||
57 | res = warnClause_createAux (fileloc_copy (lltok_getLoc (tok)), flag, msg); | |
58 | lltok_free (tok); | |
28bf4b0b | 59 | return res; |
60 | } | |
61 | ||
efd360a3 | 62 | warnClause warnClause_copy (warnClause w) |
63 | { | |
64 | if (warnClause_isDefined (w)) | |
65 | { | |
66 | return warnClause_createAux (fileloc_copy (w->loc), | |
67 | flagSpec_copy (w->flag), | |
6970c11b | 68 | cstring_copy (w->msg)); |
efd360a3 | 69 | } |
70 | else | |
71 | { | |
72 | return warnClause_undefined; | |
73 | } | |
74 | } | |
75 | ||
28bf4b0b | 76 | extern flagSpec warnClause_getFlag (warnClause w) |
77 | { | |
6970c11b | 78 | llassert (warnClause_isDefined (w)); |
28bf4b0b | 79 | return w->flag; |
80 | } | |
81 | ||
82 | extern cstring warnClause_unparse (warnClause w) | |
83 | { | |
84 | if (warnClause_isDefined (w)) | |
85 | { | |
6970c11b | 86 | return message ("<%q> %s", flagSpec_unparse (w->flag), w->msg); |
28bf4b0b | 87 | } |
88 | else | |
89 | { | |
90 | return cstring_undefined; | |
91 | } | |
92 | } | |
93 | ||
94 | extern bool warnClause_hasMessage (warnClause w) | |
95 | { | |
6970c11b | 96 | return warnClause_isDefined (w) && cstring_isDefined (w->msg); |
28bf4b0b | 97 | } |
98 | ||
99 | extern /*@observer@*/ cstring warnClause_getMessage (warnClause w) | |
100 | { | |
6970c11b | 101 | if (warnClause_isDefined (w)) { |
102 | return w->msg; | |
28bf4b0b | 103 | } else { |
104 | return cstring_undefined; | |
105 | } | |
106 | } | |
107 | ||
108 | ||
109 | extern void warnClause_free (warnClause w) | |
110 | { | |
111 | if (warnClause_isDefined (w)) | |
112 | { | |
113 | flagSpec_free (w->flag); | |
28bf4b0b | 114 | fileloc_free (w->loc); |
6970c11b | 115 | cstring_free (w->msg); |
28bf4b0b | 116 | sfree (w); |
117 | } | |
118 | } | |
119 | ||
120 | /*@only@*/ cstring | |
121 | warnClause_dump (warnClause wc) | |
122 | { | |
123 | cstring st = cstring_undefined; | |
6970c11b | 124 | llassert (warnClause_isDefined (wc)); |
28bf4b0b | 125 | llassert (!cstring_containsChar (warnClause_getMessage (wc), '#')); |
2c88d156 | 126 | |
127 | if (warnClause_hasMessage (wc)) | |
128 | { | |
129 | llassert (cstring_firstChar (warnClause_getMessage (wc)) != '.'); | |
130 | st = message ("%q#%s#", flagSpec_dump (wc->flag), warnClause_getMessage (wc)); | |
131 | } | |
132 | else | |
133 | { | |
134 | st = message ("%q#.#", flagSpec_dump (wc->flag)); | |
135 | } | |
136 | ||
28bf4b0b | 137 | return st; |
138 | } | |
139 | ||
140 | warnClause | |
141 | warnClause_undump (char **s) | |
142 | { | |
143 | flagSpec flag; | |
144 | cstring msg; | |
28bf4b0b | 145 | |
2c88d156 | 146 | DPRINTF (("Undump: %s", *s)); |
28bf4b0b | 147 | flag = flagSpec_undump (s); |
2c88d156 | 148 | DPRINTF (("Here: %s", *s)); |
28bf4b0b | 149 | reader_checkChar (s, '#'); |
2c88d156 | 150 | DPRINTF (("Here: %s", *s)); |
151 | ||
152 | if (reader_optCheckChar (s, '.')) | |
153 | { | |
154 | msg = cstring_undefined; | |
155 | } | |
156 | else | |
157 | { | |
158 | msg = reader_readUntil (s, '#'); | |
159 | } | |
160 | ||
161 | DPRINTF (("Here: %s", *s)); | |
28bf4b0b | 162 | reader_checkChar (s, '#'); |
2c88d156 | 163 | |
6970c11b | 164 | return warnClause_createAux (fileloc_copy (g_currentloc), flag, msg); |
28bf4b0b | 165 | } |