]> andersk Git - splint.git/blob - src/stateInfo.c
*** empty log message ***
[splint.git] / src / stateInfo.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 # include "lclintMacros.nf"
26 # include "basic.h"
27
28 void stateInfo_free (/*@only@*/ stateInfo a)
29 {
30   if (a != NULL)
31     {
32       fileloc_free (a->loc);
33       sfree (a);
34     }
35 }
36
37 /*@only@*/ stateInfo stateInfo_update (/*@only@*/ stateInfo old, stateInfo newinfo)
38      /*
39      ** returns an stateInfo with the same value as new.  May reuse the
40      ** storage of old.  (i.e., same effect as copy, but more
41      ** efficient.)
42      */
43 {
44   if (old == NULL) 
45     {
46       old = stateInfo_copy (newinfo);
47     }
48   else if (newinfo == NULL)
49     {
50       stateInfo_free (old);
51       return NULL;
52     }
53   else
54     {
55       old->loc = fileloc_update (old->loc, newinfo->loc);
56       old->ref = newinfo->ref;
57       old->ue = newinfo->ue;
58     }
59
60   return old;
61 }
62
63 /*@only@*/ stateInfo stateInfo_updateLoc (/*@only@*/ stateInfo old, fileloc loc)
64 {
65   if (old == NULL) 
66     {
67       old = stateInfo_makeLoc (loc);
68     }
69   else
70     {
71       old->loc = fileloc_update (old->loc, loc);
72       old->ue = uentry_undefined;
73       old->ref = sRef_undefined;
74     }
75
76   return old;
77 }
78
79 /*@only@*/ stateInfo 
80     stateInfo_updateRefLoc (/*@only@*/ stateInfo old, /*@exposed@*/ sRef ref, fileloc loc)
81 {
82   if (old == NULL) 
83     {
84       old = stateInfo_makeRefLoc (ref, loc);
85     }
86   else
87     {
88       old->loc = fileloc_update (old->loc, loc);
89       old->ue = uentry_undefined;
90       old->ref = ref;
91     }
92
93   return old;
94 }
95
96 /*@only@*/ stateInfo stateInfo_copy (stateInfo a)
97 {
98   if (a == NULL)
99     {
100       return NULL;
101     }
102   else
103     {
104       stateInfo ret = (stateInfo) dmalloc (sizeof (*ret));
105       
106       ret->loc = fileloc_copy (a->loc); /*< should report bug without copy! >*/
107       ret->ue = a->ue;
108       ret->ref = a->ref;
109
110       return ret;
111     }
112 }
113
114 /*@only@*/ /*@notnull@*/ stateInfo
115 stateInfo_currentLoc (void)
116 {
117   return stateInfo_makeLoc (g_currentloc);
118 }
119
120 /*@only@*/ /*@notnull@*/ stateInfo
121 stateInfo_makeLoc (fileloc loc)
122 {
123   stateInfo ret = (stateInfo) dmalloc (sizeof (*ret));
124
125   ret->loc = fileloc_copy (loc); /* don't need to copy! */
126   ret->ue = uentry_undefined;
127   ret->ref = sRef_undefined;
128   
129   return ret;
130 }
131
132 /*@only@*/ stateInfo
133 stateInfo_makeRefLoc (/*@exposed@*/ sRef ref, fileloc loc)
134 {
135   stateInfo ret = (stateInfo) dmalloc (sizeof (*ret));
136
137   ret->loc = fileloc_copy (loc);
138   ret->ref = ref;
139   ret->ue  = uentry_undefined;
140   
141   return ret;
142 }
143
144 /*@only@*/ cstring
145 stateInfo_unparse (stateInfo s)
146 {
147     if (stateInfo_isDefined (s) && 
148         fileloc_isDefined (s->loc)) {
149         return fileloc_unparse (s->loc);
150     } else {
151         return cstring_makeLiteral ("<no info>");
152     }
153 }
154
155 fileloc stateInfo_getLoc (stateInfo info)
156 {
157     if (stateInfo_isDefined (info)) {
158         return info->loc;
159     }
160
161     return fileloc_undefined;
162 }
163
This page took 0.178916 seconds and 5 git commands to generate.