]> andersk Git - splint.git/blob - src/qualList.c
Moved doc/lclint.1 to doc/splint.1
[splint.git] / src / qualList.c
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 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_add (qualList s, qual el)
78 {
79   if (qualList_isUndefined (s))
80     {
81       s = qualList_newEmpty ();
82     }
83   
84   if (s->free <= 0)
85     qualList_grow (s);
86   
87   s->free--;
88   s->elements[s->nelements] = el;
89   s->nelements++;
90
91   return (s);
92 }
93
94 qualList qualList_appendList (qualList s, qualList t)
95 {
96   qualList_elements (t, current)
97     {
98       s = qualList_add (s, current);
99     } end_qualList_elements;
100
101   return s;
102 }
103
104 # ifndef NOLCL
105 qualList qualList_copy (qualList s)
106 {
107   qualList t = qualList_new ();
108
109   qualList_elements (s, current)
110     {
111       t = qualList_add (t, current);
112     } end_qualList_elements;
113
114   return t;
115 }
116 # endif
117
118 /*@only@*/ cstring
119 qualList_unparse (qualList s)
120 {
121    int i;
122    cstring st = cstring_undefined;
123
124    if (qualList_isDefined (s))
125      {
126        for (i = 0; i < qualList_size (s); i++)
127          {
128            if (i == 0)
129              {
130                st = message ("%q%s ", st, qual_unparse (s->elements[i]));
131              }
132            else
133              st = message ("%q%s ", st, qual_unparse (s->elements[i]));
134          }
135      }
136
137    return st;
138 }
139
140 # ifndef NOLCL
141 /*@only@*/ cstring
142 qualList_toCComments (qualList s)
143 {
144    int i;
145    cstring st = cstring_undefined;
146
147    if (qualList_isDefined (s))
148      {
149        for (i = 0; i < qualList_size (s); i++)
150          {
151            if (i == 0)
152              {
153                st = message ("%q/*@%s@*/ ", st, qual_unparse (s->elements[i]));
154              }
155            else
156              st = message ("%q/*@%s@*/ ", st, qual_unparse (s->elements[i]));
157          }
158      }
159
160    return st;
161 }
162 # endif
163
164 bool
165 qualList_hasAliasQualifier (qualList s)
166 {
167   if (qualList_isDefined (s))
168     {
169       qualList_elements (s, q)
170         {
171           if (qual_isAliasQual (q)) return TRUE;
172         } end_qualList_elements;
173     }
174
175   return FALSE;
176 }
177
178 bool
179 qualList_hasExposureQualifier (qualList s)
180 {
181   if (qualList_isDefined (s))
182     {
183       qualList_elements (s, q)
184         {
185           if (qual_isExQual (q)) return TRUE;
186         } end_qualList_elements;
187     }
188
189   return FALSE;
190 }
191
192 void
193 qualList_free (/*@only@*/ qualList s)
194 {
195   if (qualList_isDefined (s))
196     {
197       sfree (s->elements); 
198       sfree (s);
199     }
200 }
201
202 /* start modifications */
203 /*
204 requires: p is defined
205 returns: true if qual is present in qualList
206 modifies: none
207 */
208 bool qualList_hasNullTerminatedQualifier(qualList s) {
209     qualList_elements(s, qu) {
210       if( qual_isNullTerminated(qu) ) return TRUE;
211     } end_qualList_elements ;
212    
213   return FALSE;
214 }
215
216 /* end modification/s */        
217
218
This page took 0.364654 seconds and 5 git commands to generate.