]>
Commit | Line | Data |
---|---|---|
28bf4b0b | 1 | /* |
2 | ** LCLint - annotation-assisted static program checker | |
3 | ** Copyright (C) 1994-2001 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 lclint: lclint-request@cs.virginia.edu | |
21 | ** To report a bug: lclint-bug@cs.virginia.edu | |
22 | ** For more information: http://lclint.cs.virginia.edu | |
23 | */ | |
24 | /* | |
25 | ** flagSpec.c | |
26 | */ | |
27 | ||
28 | # include "lclintMacros.nf" | |
29 | # include "basic.h" | |
30 | ||
31 | static /*@only@*/ flagSpecItem flagSpecItem_create (/*@only@*/ cstring fname) | |
32 | { | |
33 | flagSpecItem res = (flagSpecItem) dmalloc (sizeof (*res)); | |
34 | res->name = fname; | |
35 | res->code = identifyFlag (fname); | |
36 | /* Invalid flag okay for now... */ | |
37 | return res; | |
38 | } | |
39 | ||
40 | static void flagSpecItem_free (/*@only@*/ flagSpecItem fitem) | |
41 | { | |
42 | cstring_free (fitem->name); | |
43 | sfree (fitem); | |
44 | } | |
45 | ||
46 | static /*@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 | ||
55 | flagSpec flagSpec_createPlain (cstring fname) | |
56 | { | |
57 | flagSpecItem fitem = flagSpecItem_create (fname); | |
58 | flagSpec res = flagSpec_create (fitem, flagSpec_undefined); | |
59 | return res; | |
60 | } | |
61 | ||
62 | flagSpec flagSpec_createOr (cstring fname, flagSpec f) | |
63 | { | |
64 | return flagSpec_create (flagSpecItem_create (fname), f); | |
65 | } | |
66 | ||
67 | void 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 | ||
81 | cstring flagSpec_unparse (flagSpec f) | |
82 | { | |
83 | if (flagSpec_isDefined (f)) | |
84 | { | |
85 | if (flagSpec_isDefined (f->trest)) | |
86 | { | |
87 | return message ("%s | %q", f->tspec->name, flagSpec_unparse (f->trest)); | |
88 | } | |
89 | else | |
90 | { | |
91 | return cstring_copy (f->tspec->name); | |
92 | } | |
93 | } | |
94 | else | |
95 | { | |
96 | return cstring_makeLiteral ("<*** flagSpec undefined ***>"); | |
97 | } | |
98 | } | |
99 | ||
100 | cstring flagSpec_dump (flagSpec f) | |
101 | { | |
102 | llassert (flagSpec_isDefined (f)); | |
103 | llassert (!cstring_containsChar (f->tspec->name, '|')); | |
104 | llassert (!cstring_containsChar (f->tspec->name, '#')); | |
105 | ||
106 | if (flagSpec_isDefined (f->trest)) | |
107 | { | |
108 | return message ("%s|%q", f->tspec->name, flagSpec_dump (f->trest)); | |
109 | } | |
110 | else | |
111 | { | |
112 | return cstring_copy (f->tspec->name); | |
113 | } | |
114 | } | |
115 | ||
116 | flagSpec | |
117 | flagSpec_undump (char **s) | |
118 | { | |
119 | cstring flagname; | |
120 | flagname = reader_readUntilOne (s, "#|"); | |
121 | ||
122 | if (reader_optCheckChar (s, '|')) | |
123 | { | |
124 | return flagSpec_createOr (flagname, flagSpec_undump (s)); | |
125 | } | |
126 | else | |
127 | { | |
128 | return flagSpec_createPlain (flagname); | |
129 | } | |
130 | } | |
131 | ||
132 | flagcode | |
133 | flagSpec_getDominant (flagSpec fs) | |
134 | { | |
135 | llassert (flagSpec_isDefined (fs)); | |
136 | ||
137 | /* Invalid flags? */ | |
138 | return fs->tspec->code; | |
139 | } | |
140 | ||
141 | bool | |
142 | flagSpec_isOn (flagSpec fs, fileloc loc) | |
143 | { | |
144 | llassert (flagSpec_isDefined (fs)); | |
145 | ||
146 | if (context_flagOn (fs->tspec->code, loc)) | |
147 | { | |
148 | return TRUE; | |
149 | } | |
150 | else if (flagSpec_isDefined (fs->trest)) | |
151 | { | |
152 | return flagSpec_isOn (fs->trest, loc); | |
153 | } | |
154 | else | |
155 | { | |
156 | return FALSE; | |
157 | } | |
158 | } | |
159 | ||
160 | flagcode | |
161 | flagSpec_getFirstOn (flagSpec fs, fileloc loc) | |
162 | { | |
163 | llassert (flagSpec_isDefined (fs)); | |
164 | ||
165 | if (context_flagOn (fs->tspec->code, loc)) | |
166 | { | |
167 | return fs->tspec->code; | |
168 | } | |
169 | else if (flagSpec_isDefined (fs->trest)) | |
170 | { | |
171 | return flagSpec_getFirstOn (fs->trest, loc); | |
172 | } | |
173 | else | |
174 | { | |
175 | BADBRANCH; | |
176 | } | |
177 | } |