]> andersk Git - splint.git/blame - src/functionClause.c
*** empty log message ***
[splint.git] / src / functionClause.c
CommitLineData
28bf4b0b 1/*
2** LCLint - annotation-assisted static program checker
3** Copyright (C) 1994-2001 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** functionClause.c
26*/
27
28# include "lclintMacros.nf"
29# include "basic.h"
30
31static /*@only@*/ /*@notnull@*/ /*@special@*/ functionClause /*@i32 need special? @*/
32functionClause_alloc (functionClauseKind kind) /*@defines result->kind@*/
33{
34 functionClause res = (functionClause) dmalloc (sizeof (*res));
35
36 res->kind = kind;
37 return res;
38}
39
40extern functionClause functionClause_createGlobals (globalsClause node) /*@*/
41{
42 functionClause res = functionClause_alloc (FCK_GLOBALS);
43 res->val.globals = node;
44 return res;
45}
46
47extern functionClause functionClause_createModifies (modifiesClause node) /*@*/
48{
49 functionClause res = functionClause_alloc (FCK_MODIFIES);
50 res->val.modifies = node;
51 return res;
52}
53
54extern functionClause functionClause_createState (stateClause node) /*@*/
55{
56 functionClause res = functionClause_alloc (FCK_STATE);
57 res->val.state = node;
58 return res;
59}
60
61extern functionClause functionClause_createWarn (warnClause node) /*@*/
62{
63 functionClause res = functionClause_alloc (FCK_WARN);
64 res->val.warn = node;
65 return res;
66}
67
68/*@only@*/ cstring functionClause_unparse (functionClause p)
69{
70 if (functionClause_isUndefined (p))
71 {
72 return cstring_undefined;
73 }
74
75 switch (p->kind)
76 {
77 case FCK_GLOBALS:
78 return globalsClause_unparse (p->val.globals);
79 case FCK_MODIFIES:
80 return modifiesClause_unparse (p->val.modifies);
81 case FCK_WARN:
82 return warnClause_unparse (p->val.warn);
83 case FCK_STATE:
84 return stateClause_unparse (p->val.state);
85 case FCK_DEAD:
86 BADBRANCH;
87 }
88
89 BADBRANCH;
90}
91
92extern bool functionClause_matchKind (functionClause p, functionClauseKind kind) /*@*/
93{
94 if (functionClause_isDefined (p))
95 {
96 return (p->kind == kind);
97 }
98 else
99 {
100 return FALSE;
101 }
102}
103
104extern stateClause functionClause_getState (functionClause node)
105{
106 llassert (functionClause_isDefined (node));
107 llassert (node->kind == FCK_STATE);
108
109 return node->val.state;
110}
111
112extern stateClause functionClause_takeState (functionClause fc)
113{
114 stateClause res;
115 llassert (functionClause_isDefined (fc));
116 llassert (fc->kind == FCK_STATE);
117
118 res = fc->val.state;
119 fc->val.state = NULL;
120 fc->kind = FCK_DEAD;
121 return res;
122}
123
124extern warnClause functionClause_getWarn (functionClause node)
125{
126 llassert (functionClause_isDefined (node));
127 llassert (node->kind == FCK_WARN);
128
129 return node->val.warn;
130}
131
132extern warnClause functionClause_takeWarn (functionClause fc)
133{
134 warnClause res;
135 llassert (functionClause_isDefined (fc));
136 llassert (fc->kind == FCK_WARN);
137
138 res = fc->val.warn;
139 fc->val.warn = warnClause_undefined;
140 fc->kind = FCK_DEAD;
141 return res;
142}
143
144extern modifiesClause functionClause_getModifies (functionClause node)
145{
146 llassert (functionClause_isDefined (node));
147 llassert (node->kind == FCK_MODIFIES);
148
149 return node->val.modifies;
150}
151
152extern globalsClause functionClause_getGlobals (functionClause node)
153{
154 llassert (functionClause_isDefined (node));
155 llassert (node->kind == FCK_GLOBALS);
156
157 return node->val.globals;
158}
159
160extern void functionClause_free (/*@only@*/ functionClause node)
161{
162 if (node != NULL)
163 {
164 switch (node->kind)
165 {
166 case FCK_GLOBALS:
167 globalsClause_free (node->val.globals);
168 break;
169 case FCK_MODIFIES:
170 modifiesClause_free (node->val.modifies);
171 break;
172 case FCK_WARN:
173 warnClause_free (node->val.warn);
174 break;
175 case FCK_STATE:
176 stateClause_free (node->val.state);
177 break;
178 case FCK_DEAD:
179 /* Nothing to release */
180 break;
181 }
182
183 sfree (node);
184 }
185}
This page took 0.0625520000000001 seconds and 5 git commands to generate.