]> andersk Git - splint.git/blame - src/qualList.c
- library fixes:
[splint.git] / src / qualList.c
CommitLineData
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** qualList.c (from slist_template.c)
26*/
27
1b8ae690 28# include "splintMacros.nf"
616915dd 29# include "basic.h"
30
31qualList
32qualList_new ()
33{
34 return qualList_undefined;
35}
36
37static /*@only@*/ /*@notnull@*/ qualList
38qualList_newEmpty (void)
39{
40 qualList s = (qualList) dmalloc (sizeof (*s));
41
42 s->nelements = 0;
43 s->free = qualListBASESIZE;
44 s->elements = (qual *) dmalloc (sizeof (*s->elements) * qualListBASESIZE);
45
46 return (s);
47}
48
49void
50qualList_clear (qualList q)
51{
52 if (qualList_isDefined (q))
53 {
54 q->free += q->nelements;
55 q->nelements = 0;
56 }
57}
58
59static void
60qualList_grow (/*@notnull@*/ qualList s)
61{
62 int i;
63 qual *oldelements = s->elements;
64
65 s->free += qualListBASESIZE;
66
67 s->elements = (qual *) dmalloc (sizeof (*s->elements) * (s->nelements + s->free));
68
69 for (i = 0; i < s->nelements; i++)
70 {
71 s->elements[i] = oldelements[i];
72 }
73
74 sfree (oldelements);
75}
76
f9264521 77qualList qualList_single (qual el)
78{
79 /*@-unqualifiedtrans@*/ /* must be only */
80 return (qualList_add (qualList_undefined, el));
81 /*@=unqualifiedtrans@*/
82}
83
616915dd 84qualList qualList_add (qualList s, qual el)
85{
86 if (qualList_isUndefined (s))
87 {
88 s = qualList_newEmpty ();
89 }
90
91 if (s->free <= 0)
92 qualList_grow (s);
93
94 s->free--;
95 s->elements[s->nelements] = el;
96 s->nelements++;
97
98 return (s);
99}
100
101qualList qualList_appendList (qualList s, qualList t)
102{
103 qualList_elements (t, current)
104 {
105 s = qualList_add (s, current);
106 } end_qualList_elements;
107
108 return s;
109}
110
111# ifndef NOLCL
112qualList qualList_copy (qualList s)
113{
114 qualList t = qualList_new ();
115
116 qualList_elements (s, current)
117 {
118 t = qualList_add (t, current);
119 } end_qualList_elements;
120
121 return t;
122}
123# endif
124
125/*@only@*/ cstring
126qualList_unparse (qualList s)
127{
128 int i;
129 cstring st = cstring_undefined;
130
131 if (qualList_isDefined (s))
132 {
133 for (i = 0; i < qualList_size (s); i++)
134 {
135 if (i == 0)
136 {
137 st = message ("%q%s ", st, qual_unparse (s->elements[i]));
138 }
139 else
140 st = message ("%q%s ", st, qual_unparse (s->elements[i]));
141 }
142 }
143
144 return st;
145}
146
147# ifndef NOLCL
148/*@only@*/ cstring
149qualList_toCComments (qualList s)
150{
151 int i;
152 cstring st = cstring_undefined;
153
154 if (qualList_isDefined (s))
155 {
156 for (i = 0; i < qualList_size (s); i++)
157 {
158 if (i == 0)
159 {
160 st = message ("%q/*@%s@*/ ", st, qual_unparse (s->elements[i]));
161 }
162 else
163 st = message ("%q/*@%s@*/ ", st, qual_unparse (s->elements[i]));
164 }
165 }
166
167 return st;
168}
169# endif
170
171bool
172qualList_hasAliasQualifier (qualList s)
173{
174 if (qualList_isDefined (s))
175 {
176 qualList_elements (s, q)
177 {
178 if (qual_isAliasQual (q)) return TRUE;
179 } end_qualList_elements;
180 }
181
182 return FALSE;
183}
184
185bool
186qualList_hasExposureQualifier (qualList s)
187{
188 if (qualList_isDefined (s))
189 {
190 qualList_elements (s, q)
191 {
192 if (qual_isExQual (q)) return TRUE;
193 } end_qualList_elements;
194 }
195
196 return FALSE;
197}
198
199void
200qualList_free (/*@only@*/ qualList s)
201{
202 if (qualList_isDefined (s))
203 {
204 sfree (s->elements);
205 sfree (s);
206 }
207}
208
209/* start modifications */
210/*
211requires: p is defined
212returns: true if qual is present in qualList
213modifies: none
214*/
28bf4b0b 215bool qualList_hasNullTerminatedQualifier(qualList s) {
216 qualList_elements(s, qu) {
217 if( qual_isNullTerminated(qu) ) return TRUE;
616915dd 218 } end_qualList_elements ;
219
220 return FALSE;
221}
222
223/* end modification/s */
224
225
This page took 0.10678 seconds and 5 git commands to generate.