]> andersk Git - splint.git/blame - src/exprNodeSList.c
Fixed internal bug reporting for redefinition of __func__
[splint.git] / src / exprNodeSList.c
CommitLineData
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** exprNodeSList.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# include "exprNodeSList.h"
35
36exprNodeSList
37 exprNodeSList_new ()
38{
39 exprNodeSList s = (exprNodeSList) dmalloc (sizeof (*s));
40
41 s->nelements = 0;
42 s->nspace = exprNodeSListBASESIZE;
43 s->elements = (exprNode *)
44 dmalloc (sizeof (*s->elements) * exprNodeSListBASESIZE);
45
46 return (s);
47}
48
49static void
50exprNodeSList_grow (exprNodeSList s)
51{
52 int i;
53 exprNode *newelements;
54
55 s->nspace += exprNodeSListBASESIZE;
56
57 newelements = (exprNode *) dmalloc (sizeof (*newelements)
58 * (s->nelements + s->nspace));
59
60 if (newelements == (exprNode *) 0)
61 {
62 llfatalerror (cstring_makeLiteral ("exprNodeSList_grow: out of memory!"));
63 }
64
65 for (i = 0; i < s->nelements; i++)
66 {
67 newelements[i] = s->elements[i];
68 }
69
70 sfree (s->elements);
71 s->elements = newelements;
72}
73
74void exprNodeSList_addh (exprNodeSList s, /*@exposed@*/ /*@dependent@*/ exprNode el)
75{
76 llassert (exprNodeSListBASESIZE > 0);
77
78 if (s->nspace <= 0)
79 exprNodeSList_grow (s);
80
81 s->nspace--;
82 s->elements[s->nelements] = el;
83 s->nelements++;
84}
85
86/*
87** appends s2 to s1
88*/
89
90exprNodeSList exprNodeSList_append (/*@returned@*/ exprNodeSList s1, /*@only@*/ exprNodeSList s2)
91{
92 exprNodeSList_elements (s2, x)
93 {
94 exprNodeSList_addh (s1, x);
95 } end_exprNodeSList_elements;
96
97 exprNodeSList_free (s2);
98 return s1;
99}
100
101/*@only@*/ exprNodeSList exprNodeSList_singleton (/*@exposed@*/ /*@dependent@*/ exprNode e)
102{
103 exprNodeSList s = (exprNodeSList) dmalloc (sizeof (*s));
104
105 s->nelements = 1;
106 s->nspace = exprNodeSListBASESIZE - 1;
107 s->elements = (exprNode *) dmalloc (sizeof (*s->elements) * exprNodeSListBASESIZE);
108 s->elements[0] = e;
109
110 return (s);
111}
112
113/*@only@*/ cstring
114exprNodeSList_unparse (exprNodeSList s)
115{
116 int i;
117 cstring st = cstring_undefined;
118
119 for (i = 0; i < s->nelements; i++)
120 {
121 if (i == 0)
122 {
123 st = cstring_copy (exprNode_unparse (s->elements[i]));
124 }
125 else
126 st = message ("%q, %s", st, exprNode_unparse (s->elements[i]));
127 }
128
129 return st;
130}
131
132void
133exprNodeSList_free (exprNodeSList s)
134{
135 sfree (s->elements);
136 sfree (s);
137}
138
This page took 0.076186 seconds and 5 git commands to generate.