]> andersk Git - splint.git/blob - src/qualList.c
noexpand always false.
[splint.git] / src / qualList.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 ** qualList.c (from slist_template.c)
26 */
27
28 # include "splintMacros.nf"
29 # include "basic.h"
30
31 qualList
32 qualList_new ()
33 {
34   return qualList_undefined;
35 }
36
37 static /*@only@*/ /*@notnull@*/ qualList
38 qualList_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
49 void
50 qualList_clear (qualList q)
51 {
52   if (qualList_isDefined (q))
53     {
54       q->free += q->nelements;
55       q->nelements = 0;
56     }
57 }
58
59 static void
60 qualList_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
77 qualList qualList_single (qual el)
78 {
79   /*@-unqualifiedtrans@*/ /* must be only */
80   return (qualList_add (qualList_undefined, el));
81   /*@=unqualifiedtrans@*/
82 }
83
84 qualList 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
101 qualList 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 qualList qualList_copy (qualList s)
112 {
113   qualList t = qualList_new ();
114
115   qualList_elements (s, current)
116     {
117       t = qualList_add (t, current);
118     } end_qualList_elements;
119
120   return t;
121 }
122
123 /*@only@*/ cstring
124 qualList_unparse (qualList s)
125 {
126    int i;
127    cstring st = cstring_undefined;
128
129    if (qualList_isDefined (s))
130      {
131        for (i = 0; i < qualList_size (s); i++)
132          {
133            if (i == 0)
134              {
135                st = message ("%q%s ", st, qual_unparse (s->elements[i]));
136              }
137            else
138              st = message ("%q%s ", st, qual_unparse (s->elements[i]));
139          }
140      }
141
142    return st;
143 }
144
145 /*@only@*/ cstring
146 qualList_toCComments (qualList s)
147 {
148    int i;
149    cstring st = cstring_undefined;
150
151    if (qualList_isDefined (s))
152      {
153        for (i = 0; i < qualList_size (s); i++)
154          {
155            if (i == 0)
156              {
157                st = message ("%q/*@%s@*/ ", st, qual_unparse (s->elements[i]));
158              }
159            else
160              st = message ("%q/*@%s@*/ ", st, qual_unparse (s->elements[i]));
161          }
162      }
163
164    return st;
165 }
166
167 bool
168 qualList_hasAliasQualifier (qualList s)
169 {
170   if (qualList_isDefined (s))
171     {
172       qualList_elements (s, q)
173         {
174           if (qual_isAliasQual (q)) return TRUE;
175         } end_qualList_elements;
176     }
177
178   return FALSE;
179 }
180
181 bool
182 qualList_hasExposureQualifier (qualList s)
183 {
184   if (qualList_isDefined (s))
185     {
186       qualList_elements (s, q)
187         {
188           if (qual_isExQual (q)) return TRUE;
189         } end_qualList_elements;
190     }
191
192   return FALSE;
193 }
194
195 void
196 qualList_free (/*@only@*/ qualList s)
197 {
198   if (qualList_isDefined (s))
199     {
200       sfree (s->elements); 
201       sfree (s);
202     }
203 }
204
205 /* start modifications */
206 /*
207 requires: p is defined
208 returns: true if qual is present in qualList
209 modifies: none
210 */
211 bool qualList_hasNullTerminatedQualifier(qualList s) {
212     qualList_elements(s, qu) {
213       if( qual_isNullTerminated(qu) ) return TRUE;
214     } end_qualList_elements ;
215    
216   return FALSE;
217 }
218
219 /* end modification/s */        
220
221
This page took 0.054797 seconds and 5 git commands to generate.