]> andersk Git - splint.git/blob - src/ctypeList.c
Readded files.
[splint.git] / src / ctypeList.c
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 ** ctypeList.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 "lclintMacros.nf"
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
82 /*@only@*/ cstring
83 ctypeList_unparse (ctypeList ct)
84 {
85   cstring s = cstring_undefined;
86   int i;
87   bool first = TRUE;
88
89   if (ctypeList_isUndefined (ct) || ctypeList_size (ct) == 0)
90     {
91       return (cstring_makeLiteral ("void"));
92     }
93
94   for (i = 0; i < ct->nelements; i++)
95     {
96       if (first)
97         {
98           s = cstring_copy (ctype_unparse (ct->elements[i]));
99           first = FALSE;
100         }
101       else
102         {
103           s = message ("%q, %s", s, ctype_unparse (ct->elements[i]));
104         }
105     }
106
107   return s;
108 }
109
110 void
111 ctypeList_free (/*@only@*/ ctypeList s)
112 {
113   if (ctypeList_isDefined (s))
114     {
115       int i;
116       for (i = 0; i < s->nelements; i++)
117         {
118           /*      ctype_free (s->elements[i]); */
119         }
120       
121       sfree (s->elements); /* not quite!!! */
122       sfree (s);
123     }
124 }
125
126
127
128
129
130
131
This page took 0.044512 seconds and 5 git commands to generate.