]> andersk Git - splint.git/blame - src/sRefList.c
noexpand always false.
[splint.git] / src / sRefList.c
CommitLineData
28bf4b0b 1/*
11db3170 2** Splint - annotation-assisted static program checker
c59f5181 3** Copyright (C) 1994-2003 University of Virginia,
28bf4b0b 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
28bf4b0b 23*/
24/*
25** sRefList.c (from slist_template.c)
26*/
27
1b8ae690 28# include "splintMacros.nf"
28bf4b0b 29# include "basic.h"
30
31sRefList
32sRefList_new ()
33{
34 return sRefList_undefined;
35}
36
37static /*@only@*/ /*@notnull@*/ sRefList
38sRefList_newEmpty (void)
39{
40 sRefList s = (sRefList) dmalloc (sizeof (*s));
41
42 s->nelements = 0;
43 s->nspace = sRefListBASESIZE;
44 s->elements = (sRef *) dmalloc (sizeof (*s->elements) * sRefListBASESIZE);
45
46 return (s);
47}
48
49/*@only@*/ sRefList sRefList_single (sRef el)
50{
51 sRefList res = sRefList_newEmpty ();
52 res = sRefList_add (res, el);
53 return res;
54}
55
56static void
57sRefList_grow (/*@notnull@*/ sRefList s)
58{
59 int i;
60 sRef *oldelements = s->elements;
61
62 s->nspace += sRefListBASESIZE;
63
64 s->elements = (sRef *) dmalloc (sizeof (*s->elements) * (s->nelements + s->nspace));
65
66 for (i = 0; i < s->nelements; i++)
67 {
68 s->elements[i] = oldelements[i];
69 }
70
71 sfree (oldelements);
72}
73
74/*@notnull@*/ sRefList sRefList_add (sRefList s, sRef el)
75{
76 if (sRefList_isUndefined (s))
77 {
78 s = sRefList_newEmpty ();
79 }
80
81 if (s->nspace <= 0)
82 sRefList_grow (s);
83
84 s->nspace--;
85 s->elements[s->nelements] = el;
86 s->nelements++;
87
88 return (s);
89}
90
91sRefList sRefList_copy (sRefList s)
92{
93 sRefList t = sRefList_new ();
94
95 sRefList_elements (s, current)
96 {
97 t = sRefList_add (t, sRef_copy (current));
98 } end_sRefList_elements;
99
100 return t;
101}
102
103/*@only@*/ cstring
104sRefList_unparse (sRefList s)
105{
106 int i;
107 cstring st = cstring_undefined;
108
109 if (sRefList_isDefined (s))
110 {
111 for (i = 0; i < sRefList_size (s); i++)
112 {
113 if (i == 0)
114 {
115 st = message ("%q%q ", st, sRef_unparse (s->elements[i]));
116 }
117 else
118 st = message ("%q%q ", st, sRef_unparse (s->elements[i]));
119 }
120 }
121
122 return st;
123}
124
125int sRefList_size (sRefList s)
126{
127 if (sRefList_isUndefined (s)) return 0;
128 return s->nelements;
129}
130
131void
132sRefList_free (/*@only@*/ sRefList s)
133{
134 if (sRefList_isDefined (s))
135 {
136 sfree (s->elements);
137 sfree (s);
138 }
139}
140
141
142
143
This page took 0.088046 seconds and 5 git commands to generate.