]>
Commit | Line | Data |
---|---|---|
616915dd | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
c59f5181 | 3 | ** Copyright (C) 1994-2003 University of Virginia, |
616915dd | 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 |
616915dd | 23 | */ |
24 | /* | |
25 | ** ctypeList.c | |
26 | ** | |
27 | ** based on list_template.c | |
28 | ** | |
29 | ** where T has T_equal (or change this) and T_unparse | |
30 | */ | |
31 | ||
1b8ae690 | 32 | # include "splintMacros.nf" |
616915dd | 33 | # include "basic.h" |
34 | ||
35 | /*@only@*/ ctypeList | |
36 | ctypeList_new () | |
37 | { | |
38 | ctypeList s = (ctypeList) dmalloc (sizeof (*s)); | |
39 | ||
40 | s->nelements = 0; | |
41 | s->nspace = ctypeListBASESIZE; | |
42 | s->elements = (ctype *) dmalloc (sizeof (*s->elements) * ctypeListBASESIZE); | |
43 | ||
44 | return (s); | |
45 | } | |
46 | ||
47 | static void | |
48 | ctypeList_grow (/*@notnull@*/ ctypeList s) | |
49 | { | |
50 | int i; | |
51 | ctype *newelements; | |
52 | ||
53 | s->nspace += ctypeListBASESIZE; | |
54 | newelements = (ctype *) dmalloc (sizeof (*newelements) * (s->nelements + s->nspace)); | |
55 | ||
56 | if (newelements == (ctype *) 0) | |
57 | { | |
58 | llfatalerror (cstring_makeLiteral ("ctypeList_grow: out of memory!")); | |
59 | } | |
60 | ||
61 | for (i = 0; i < s->nelements; i++) | |
62 | { | |
63 | newelements[i] = s->elements[i]; | |
64 | } | |
65 | ||
66 | sfree (s->elements); | |
67 | s->elements = newelements; | |
68 | } | |
69 | ||
70 | void ctypeList_addh (ctypeList s, ctype el) | |
71 | { | |
72 | llassert (ctypeList_isDefined (s)); | |
73 | llassert (ctypeListBASESIZE > 0); | |
74 | ||
75 | if (s->nspace <= 0) ctypeList_grow (s); | |
76 | ||
77 | s->nspace--; | |
78 | s->elements[s->nelements] = el; | |
79 | s->nelements++; | |
80 | } | |
81 | ||
28bf4b0b | 82 | ctypeList ctypeList_add (ctypeList s, ctype el) |
83 | { | |
84 | llassert (ctypeListBASESIZE > 0); | |
85 | ||
86 | if (ctypeList_isUndefined (s)) | |
87 | { | |
88 | s = ctypeList_new (); | |
89 | } | |
90 | ||
91 | ctypeList_addh (s, el); | |
92 | return s; | |
93 | } | |
94 | ||
95 | ctypeList ctypeList_append (ctypeList s1, ctypeList s2) | |
96 | { | |
97 | ctypeList res = s1; | |
98 | ||
99 | ctypeList_elements (s2, el) | |
100 | { | |
101 | res = ctypeList_add (res, el); | |
102 | } end_ctypeList_elements; | |
103 | ||
104 | return res; | |
105 | } | |
106 | ||
616915dd | 107 | /*@only@*/ cstring |
108 | ctypeList_unparse (ctypeList ct) | |
109 | { | |
110 | cstring s = cstring_undefined; | |
111 | int i; | |
112 | bool first = TRUE; | |
113 | ||
114 | if (ctypeList_isUndefined (ct) || ctypeList_size (ct) == 0) | |
115 | { | |
116 | return (cstring_makeLiteral ("void")); | |
117 | } | |
118 | ||
119 | for (i = 0; i < ct->nelements; i++) | |
120 | { | |
121 | if (first) | |
122 | { | |
123 | s = cstring_copy (ctype_unparse (ct->elements[i])); | |
124 | first = FALSE; | |
125 | } | |
126 | else | |
127 | { | |
128 | s = message ("%q, %s", s, ctype_unparse (ct->elements[i])); | |
129 | } | |
130 | } | |
131 | ||
132 | return s; | |
133 | } | |
134 | ||
135 | void | |
136 | ctypeList_free (/*@only@*/ ctypeList s) | |
137 | { | |
138 | if (ctypeList_isDefined (s)) | |
139 | { | |
140 | int i; | |
141 | for (i = 0; i < s->nelements; i++) | |
142 | { | |
143 | /* ctype_free (s->elements[i]); */ | |
144 | } | |
145 | ||
146 | sfree (s->elements); /* not quite!!! */ | |
147 | sfree (s); | |
148 | } | |
149 | } | |
150 | ||
151 | ||
152 | ||
153 | ||
154 | ||
155 | ||
156 |