]> andersk Git - splint.git/blob - src/functionConstraint.c
*** empty log message ***
[splint.git] / src / functionConstraint.c
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 ** functionConstraint.c
26 */
27
28 # include "lclintMacros.nf"
29 # include "basic.h"
30 # include "mtincludes.h"
31
32 static /*@only@*/ /*@notnull@*/ /*@special@*/ functionConstraint  /*@i32 need special? @*/
33 functionConstraint_alloc (functionConstraintKind kind) /*@defines result->kind@*/
34 {
35   functionConstraint res = (functionConstraint) dmalloc (sizeof (*res));
36
37   res->kind = kind;
38   return res;
39 }
40
41 extern functionConstraint functionConstraint_createBufferConstraint (constraintList buf)
42
43   functionConstraint res = functionConstraint_alloc (FCT_BUFFER);
44   res->constraint.buffer = buf;
45   return res;
46 }
47
48 extern functionConstraint functionConstraint_createMetaStateConstraint (metaStateConstraint msc)
49
50   functionConstraint res = functionConstraint_alloc (FCT_METASTATE);
51   res->constraint.metastate = msc;
52   return res;
53 }
54
55 /*@only@*/ cstring functionConstraint_unparse (functionConstraint p)
56 {
57   if (functionConstraint_isDefined (p)) 
58     {
59       switch (p->kind)
60         {
61         case FCT_BUFFER: 
62           return constraintList_unparse (p->constraint.buffer);
63         case FCT_METASTATE:
64           return metaStateConstraint_unparse (p->constraint.metastate);
65           BADDEFAULT;
66         }
67       BADBRANCH;
68     }
69   else
70     {
71       return cstring_makeLiteral ("< empty constraint >");
72     }
73 }
74
75 extern constraintList functionConstraint_getBufferConstraint (functionConstraint node)
76 {
77   llassert (functionConstraint_isDefined (node));
78   llassert (node->kind == FCT_BUFFER);
79   return node->constraint.buffer;
80 }
81
82 extern metaStateConstraint functionConstraint_getMetaStateConstraint (functionConstraint node)
83 {
84   llassert (functionConstraint_isDefined (node));
85   llassert (node->kind == FCT_METASTATE);
86   return node->constraint.metastate;
87 }
88
89 extern bool functionConstraint_hasBufferConstraint (functionConstraint node)
90 {
91   return functionConstraint_isDefined (node) && node->kind == FCT_BUFFER;
92 }
93
94 extern functionConstraint functionConstraint_copy (functionConstraint node) 
95 {
96   if (functionConstraint_isDefined (node))
97     {
98       switch (node->kind)
99         {
100         case FCT_BUFFER:
101           return functionConstraint_createBufferConstraint (constraintList_copy (node->constraint.buffer));
102         case FCT_METASTATE:
103           return functionConstraint_createMetaStateConstraint (metaStateConstraint_copy (node->constraint.metastate));
104         }
105       
106       BADBRANCH;
107     }
108   else
109     {
110       return functionConstraint_undefined;
111     }
112 }
113
114 extern void functionConstraint_free (/*@only@*/ functionConstraint node) 
115 {
116   if (functionConstraint_isDefined (node))
117     {
118       switch (node->kind)
119         {
120         case FCT_BUFFER:
121           constraintList_free (node->constraint.buffer);
122           break;
123         case FCT_METASTATE:
124           metaStateConstraint_free (node->constraint.metastate);
125           break;
126           BADDEFAULT;
127         }
128       
129       sfree (node);
130     }
131 }
This page took 0.046631 seconds and 5 git commands to generate.