]> andersk Git - splint.git/blame - src/constraintList.c
*** empty log message ***
[splint.git] / src / constraintList.c
CommitLineData
d0e5b01f 1/*
4cccc6ad 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/*
d0e5b01f 25** constraintList.c
4cccc6ad 26**
27** based on list_template.c
28**
29** where T has T_equal (or change this) and T_unparse
d0e5b01f 30*/
31
d0e5b01f 32# include "lclintMacros.nf"
4cccc6ad 33# include "llbasic.h"
d0e5b01f 34
4cccc6ad 35constraintList constraintList_new ()
36{
37 constraintList s = (constraintList) dmalloc (sizeof (*s));
d0e5b01f 38
4cccc6ad 39 s->nelements = 0;
40 s->nspace = constraintListBASESIZE;
41 s->elements = (constraint *)
42 dmalloc (sizeof (*s->elements) * constraintListBASESIZE);
d0e5b01f 43
4cccc6ad 44 return (s);
d0e5b01f 45}
46
4cccc6ad 47static void
48constraintList_grow (constraintList s)
d0e5b01f 49{
d0e5b01f 50 int i;
4cccc6ad 51 constraint *newelements;
52
53 s->nspace += constraintListBASESIZE;
54 newelements = (constraint *) dmalloc (sizeof (*newelements)
55 * (s->nelements + s->nspace));
56
57 for (i = 0; i < s->nelements; i++)
d0e5b01f 58 {
4cccc6ad 59 newelements[i] = s->elements[i];
d0e5b01f 60 }
d0e5b01f 61
4cccc6ad 62 sfree (s->elements);
63 s->elements = newelements;
d0e5b01f 64}
65
361091cc 66void constraintList_exprNodemerge()
d0e5b01f 67{
d0e5b01f 68}
4cccc6ad 69constraintList
70constraintList_add (constraintList s, constraint el)
d0e5b01f 71{
4cccc6ad 72 if (s->nspace <= 0)
73 constraintList_grow (s);
d0e5b01f 74
4cccc6ad 75 s->nspace--;
76 s->elements[s->nelements] = el;
77 s->nelements++;
78 return s;
79}
d0e5b01f 80
361091cc 81constraintList constraintList_addList (constraintList s, constraintList new)
82{
83 constraintList_elements(new, elem)
84 s = constraintList_add (s, elem);
85 end_constraintList_elements
86 return s;
87}
88
89cstring
90constraintList_print (constraintList s)
91{
92 int i;
93 cstring st = cstring_undefined;
94 bool first = TRUE;
95
96 if (s->nelements == 0)
97 st = cstring_makeLiteral("<List Empty>");
98
99 for (i = 0; i < s->nelements; i++)
100 {
101 cstring type = cstring_undefined;
102 constraint current = s->elements[i];
103
104 if (current != NULL)
105 {
106 cstring temp1 = constraint_print(current);
107 type = message ("%q %q\n", type, temp1 );
108 }
109
110 if (first)
111 {
112 st = type;
113 first = FALSE;
114 }
115 else
116 {
117 st = message ("%q, %q", st, type);
118 }
119 }
120 return st;
121}
4cccc6ad 122
bf92e32c 123
124cstring
125constraintList_printDetailed (constraintList s)
126{
127 int i;
128 cstring st = cstring_undefined;
129 bool first = TRUE;
130
131 if (s->nelements == 0)
132 st = cstring_makeLiteral("<List Empty>");
133
134 for (i = 0; i < s->nelements; i++)
135 {
136 cstring type = cstring_undefined;
137 constraint current = s->elements[i];
138
139 if (current != NULL)
140 {
141 cstring temp1 = constraint_printDetailed (current);
142 type = message ("%s %s\n", type, temp1 );
143 }
144
145 if (first)
146 {
147 st = type;
148 first = FALSE;
149 }
150 else
151 {
152 st = message ("%s %s", st, type);
153 }
154 }
155 return st;
156}
157
4cccc6ad 158void
159constraintList_free (constraintList s)
d0e5b01f 160{
d0e5b01f 161 int i;
4cccc6ad 162 for (i = 0; i < s->nelements; i++)
d0e5b01f 163 {
4cccc6ad 164 // constraint_free (s->elements[i]);
d0e5b01f 165 }
d0e5b01f 166
4cccc6ad 167 sfree (s->elements);
168 sfree (s);
d0e5b01f 169}
170
4cccc6ad 171constraintList
172constraintList_copy (constraintList s)
d0e5b01f 173{
4cccc6ad 174 constraintList ret = constraintList_new ();
d0e5b01f 175
4cccc6ad 176 constraintList_elements (s, el)
d0e5b01f 177 {
4cccc6ad 178 ret = constraintList_add (ret, constraint_copy (el));
179 } end_constraintList_elements;
d0e5b01f 180
4cccc6ad 181 return ret;
d0e5b01f 182}
361091cc 183
bf92e32c 184constraintList constraintList_preserveOrig (constraintList c)
185{
186 constraintList_elements (c, el);
187 {
188 el = constraint_preserveOrig (el);
189 }
190 end_constraintList_elements;
191 return c;
192}
This page took 0.807005 seconds and 5 git commands to generate.