]> andersk Git - splint.git/blame - src/idDeclList.c
Fixed -help <mode> bug.
[splint.git] / src / idDeclList.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** idDeclList.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
35idDeclList
36 idDeclList_singleton (/*@only@*/ idDecl e)
37{
38 idDeclList s = (idDeclList) dmalloc (sizeof (*s));
39
40 s->nelements = 1;
41 s->nspace = idDeclListBASESIZE - 1;
42 s->elements = (idDecl *) dmalloc (sizeof (*s->elements) * idDeclListBASESIZE);
43 s->elements[0] = e;
44 return (s);
45}
46
47static void
48idDeclList_grow (idDeclList s)
49{
50 int i;
51 idDecl *newelements;
52
53 s->nspace += idDeclListBASESIZE;
54 newelements = (idDecl *) dmalloc (sizeof (*newelements)
55 * (s->nelements + s->nspace));
56
57 for (i = 0; i < s->nelements; i++)
58 {
59 newelements[i] = s->elements[i];
60 }
61
62 sfree (s->elements);
63 s->elements = newelements;
64}
65
66idDeclList idDeclList_add (idDeclList s, /*@only@*/ idDecl el)
67{
68 if (s->nspace <= 0)
69 idDeclList_grow (s);
70
71 s->nspace--;
72 s->elements[s->nelements] = el;
73 s->nelements++;
74
75 return s;
76}
77
78/*@only@*/ cstring
79idDeclList_unparse (idDeclList s)
80{
81 int i;
82 cstring st = cstring_makeLiteral ("[");
83
84 for (i = 0; i < s->nelements; i++)
85 {
86 if (i == 0)
87 {
88 st = message ("%q %q", st, idDecl_unparse (s->elements[i]));
89 }
90 else
91 st = message ("%q, %q", st, idDecl_unparse (s->elements[i]));
92 }
93
94 st = message ("%q ]", st);
95 return st;
96}
97
98void
99idDeclList_free (idDeclList s)
100{
101 int i;
102 for (i = 0; i < s->nelements; i++)
103 {
104 idDecl_free (s->elements[i]);
105 }
106
107 sfree (s->elements);
108 sfree (s);
109}
This page took 0.211158 seconds and 5 git commands to generate.