]>
Commit | Line | Data |
---|---|---|
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 | # 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_makeLoc (fileloc loc) | |
116 | { | |
117 | stateInfo ret = (stateInfo) dmalloc (sizeof (*ret)); | |
118 | ||
119 | ret->loc = fileloc_copy (loc); /* don't need to copy! */ | |
120 | ret->ue = uentry_undefined; | |
121 | ret->ref = sRef_undefined; | |
122 | ||
123 | return ret; | |
124 | } | |
125 | ||
126 | /*@only@*/ stateInfo | |
127 | stateInfo_makeRefLoc (/*@exposed@*/ sRef ref, fileloc loc) | |
128 | { | |
129 | stateInfo ret = (stateInfo) dmalloc (sizeof (*ret)); | |
130 | ||
131 | ret->loc = fileloc_copy (loc); | |
132 | ret->ref = ref; | |
133 | ret->ue = uentry_undefined; | |
134 | ||
135 | return ret; | |
136 | } | |
137 | ||
138 | /*@only@*/ cstring | |
139 | stateInfo_unparse (stateInfo s) | |
140 | { | |
141 | if (stateInfo_isDefined (s) && | |
142 | fileloc_isDefined (s->loc)) { | |
143 | return fileloc_unparse (s->loc); | |
144 | } else { | |
145 | return cstring_makeLiteral ("<no info>"); | |
146 | } | |
147 | } | |
148 | ||
149 | fileloc stateInfo_getLoc (stateInfo info) | |
150 | { | |
151 | if (stateInfo_isDefined (info)) { | |
152 | return info->loc; | |
153 | } | |
154 | ||
155 | return fileloc_undefined; | |
156 | } | |
157 |