]> andersk Git - splint.git/blob - src/sortList.c
noexpand always false.
[splint.git] / src / sortList.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 ** sortList.c
26 **
27 ** based on list_template.c
28 **
29 ** where T has T_equal (or change this) and T_unparse
30 */
31
32 # include "splintMacros.nf"
33 # include "basic.h"
34
35 /*@only@*/ sortList
36 sortList_new ()
37 {
38   sortList s = (sortList) dmalloc (sizeof (*s));
39   
40   s->nelements = 0;
41   s->nspace = sortListBASESIZE;
42   s->elements = (sort *) dmalloc (sizeof (*s->elements) * sortListBASESIZE);
43   s->current = 0;
44
45   return (s);
46 }
47
48 static void
49 sortList_grow (sortList s)
50 {
51   int i;
52   sort *newelements;
53
54   s->nspace += sortListBASESIZE;
55
56   newelements = (sort *) dmalloc (sizeof (*newelements) * (s->nelements + s->nspace));
57
58   if (newelements == (sort *) 0)
59     {
60       llfatalerror (cstring_makeLiteral ("sortList_grow: out of memory!"));
61     }
62
63   for (i = 0; i < s->nelements; i++)
64     {
65       newelements[i] = s->elements[i];
66     }
67
68   sfree (s->elements);
69   s->elements = newelements;
70 }
71
72 void 
73 sortList_addh (sortList s, sort el)
74 {
75   if (s->nspace <= 0)
76     sortList_grow (s);
77
78   s->nspace--;
79   s->elements[s->nelements] = el;
80   s->nelements++;
81 }
82
83 void 
84 sortList_reset (sortList s)
85 {
86   s->current = 0;
87 }
88
89 void 
90 sortList_advance (sortList s)
91 {
92   s->current++;
93   llassert (s->current < s->nelements);
94 }
95
96 sort 
97 sortList_current (sortList s)
98 {
99   if (s->current < 0 || s->current >= s->nelements)
100     {
101       llbug (message ("sortList_current: current out of range: %d (size: %d)",
102                       s->current, s->nelements));
103     }
104   return (s->elements[s->current]);
105 }
106
107 /*@only@*/ cstring
108 sortList_unparse (sortList s)
109 {
110   int i;
111   cstring st = cstring_undefined;
112
113   for (i = 0; i < s->nelements; i++)
114     {
115       if (i == 0)
116         {
117           st = cstring_copy (sort_unparseName (s->elements[i])); /* !!! NEED COPY HERE !!! */
118         }
119       else
120         {
121           st = message ("%q, %s", st, sort_unparseName (s->elements[i]));
122         }
123     }
124
125   return st;
126 }
127
128 void
129 sortList_free (sortList s)
130 {
131   int i;
132   for (i = 0; i < s->nelements; i++)
133     {
134       /*      sort_free (s->elements[i]); */
135     }
136   
137   sfree (s->elements);          /* not quite!!! */
138   sfree (s);
139 }
This page took 0.098639 seconds and 5 git commands to generate.