]> andersk Git - splint.git/blame - src/sRefTable.c
Updating to use the LEnsures and LRequires instead of the ensures requires so
[splint.git] / src / sRefTable.c
CommitLineData
616915dd 1/*
2** LCLint - annotation-assisted static program checker
3** Copyright (C) 1994-2000 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 lclint: lclint-request@cs.virginia.edu
21** To report a bug: lclint-bug@cs.virginia.edu
22** For more information: http://lclint.cs.virginia.edu
23*/
24/*
25** sRefTable.c
26**
27** based on table_template.c
28**
29** where T has T_equal (or change this) and T_unparse
30*/
31
32# include "lclintMacros.nf"
33# include "basic.h"
34# include "sRefTable.h"
35
36static /*@notnull@*/ /*@only@*/ sRefTable
37sRefTable_new (void)
38{
39 sRefTable s = (sRefTable) dmalloc (sizeof (*s));
40
41 s->entries = 0;
42 s->nspace = sRefTableBASESIZE;
43 s->elements = (sRef *) dmalloc (sizeof (*s->elements) * sRefTableBASESIZE);
44
45 return (s);
46}
47
48static void
49sRefTable_grow (/*@notnull@*/ sRefTable s)
50{
51 int i;
52 sRef *newelements;
53
54 s->nspace = sRefTableBASESIZE;
55 newelements = (sRef *) dmalloc (sizeof (*newelements) * (s->entries + s->nspace));
56
57 for (i = 0; i < s->entries; i++)
58 {
59 newelements[i] = s->elements[i];
60 }
61
62 sfree (s->elements);
63 s->elements = newelements;
64}
65
66sRefTable
67sRefTable_add (sRefTable s, /*@owned@*/ sRef el)
68{
69 if (sRefTable_isNull (s))
70 {
71 s = sRefTable_new ();
72 }
73
74 if (s->nspace <= 0)
75 {
76 sRefTable_grow (s);
77 }
78
79 s->nspace--;
80
81 llassert (s->elements != NULL);
82 s->elements[s->entries] = el;
83
84 s->entries++;
85
86 return s;
87}
88
89void
90sRefTable_clear (sRefTable s)
91{
92 if (sRefTable_isDefined (s))
93 {
94 int i;
95
96 for (i = 0; i < s->entries; i++)
97 {
98 sRef_free (s->elements[i]);
99 }
100
101 s->nspace += s->entries;
102 s->entries = 0;
103 }
104}
105
106static int sRefTable_size (sRefTable s)
107{
108 if (sRefTable_isNull (s)) return 0;
109 return s->entries;
110}
111
112/*@only@*/ cstring
113sRefTable_unparse (sRefTable s)
114{
115 int i;
116 cstring st = cstring_undefined;
117
118 if (sRefTable_isDefined (s))
119 {
120 for (i = 0; i < sRefTable_size (s); i++)
121 {
122 if (i == 0)
123 st = message ("%4d. %q\n", i, sRef_unparse (s->elements[i]));
124 else
125 st = message ("%q%4d. %q\n", st, i, sRef_unparse (s->elements[i]));
126 }
127 }
128 return st;
129}
130
131void
132sRefTable_free (/*@only@*/ sRefTable s)
133{
134 if (sRefTable_isDefined (s))
135 {
136 int i;
137
138 for (i = 0; i < s->entries; i++)
139 {
140 sRef_free (s->elements[i]);
141 }
142
143 sfree (s->elements);
144 sfree (s);
145 }
146}
147
This page took 0.202048 seconds and 5 git commands to generate.