]>
Commit | Line | Data |
---|---|---|
616915dd | 1 | /* |
2 | ** LCLint - annotation-assisted static program checker | |
3 | ** Copyright (C) 1994-2000 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 | ** idDecl.c | |
26 | */ | |
27 | ||
28 | # include "lclintMacros.nf" | |
29 | # include "basic.h" | |
30 | ||
31 | /*@only@*/ idDecl | |
32 | idDecl_create (/*@only@*/ cstring s, /*@only@*/ qtype t) | |
33 | { | |
34 | idDecl d = (idDecl) dmalloc (sizeof (*d)); | |
35 | ||
36 | d->id = s; | |
37 | d->typ = t; | |
38 | ||
39 | return (d); | |
40 | } | |
41 | ||
42 | void | |
43 | idDecl_free (idDecl t) | |
44 | { | |
45 | if (idDecl_isDefined (t)) | |
46 | { | |
47 | cstring_free (t->id); | |
48 | qtype_free (t->typ); | |
49 | sfree (t); | |
50 | } | |
51 | } | |
52 | ||
53 | cstring | |
54 | idDecl_unparse (idDecl d) | |
55 | { | |
56 | if (idDecl_isDefined (d)) | |
57 | { | |
58 | return (message ("%s : %q", d->id, qtype_unparse (d->typ))); | |
59 | } | |
60 | else | |
61 | { | |
62 | return (cstring_makeLiteral ("<undefined id>")); | |
63 | } | |
64 | } | |
65 | ||
66 | /*@observer@*/ cstring | |
67 | idDecl_observeId (idDecl d) | |
68 | { | |
69 | if (idDecl_isDefined (d)) | |
70 | { | |
71 | return (d->id); | |
72 | } | |
73 | else | |
74 | { | |
75 | return cstring_undefined; | |
76 | } | |
77 | } | |
78 | ||
79 | qtype | |
80 | idDecl_getTyp (idDecl d) | |
81 | { | |
82 | llassert (idDecl_isDefined (d)); | |
83 | ||
84 | return d->typ; | |
85 | } | |
86 | ||
87 | ctype | |
88 | idDecl_getCtype (idDecl d) | |
89 | { | |
90 | if (idDecl_isDefined (d)) | |
91 | { | |
92 | return (qtype_getType (d->typ)); | |
93 | } | |
94 | else | |
95 | { | |
96 | return ctype_unknown; | |
97 | } | |
98 | } | |
99 | ||
100 | qualList | |
101 | idDecl_getQuals (idDecl d) | |
102 | { | |
103 | if (idDecl_isDefined (d)) | |
104 | { | |
105 | return (qtype_getQuals (d->typ)); | |
106 | } | |
107 | else | |
108 | { | |
109 | return qualList_undefined; | |
110 | } | |
111 | } | |
112 | ||
113 | void | |
114 | idDecl_addQual (idDecl d, qual q) | |
115 | { | |
116 | llassert (idDecl_isDefined (d)); | |
117 | ||
118 | (void) qtype_addQual (d->typ, q); | |
119 | } | |
120 | ||
121 | void | |
122 | idDecl_setTyp (idDecl d, qtype c) | |
123 | { | |
124 | llassert (idDecl_isDefined (d)); | |
125 | ||
126 | qtype_free (d->typ); | |
127 | d->typ = c; | |
128 | } | |
129 | ||
130 | idDecl | |
131 | idDecl_replaceCtype (/*@returned@*/ idDecl d, ctype c) | |
132 | { | |
133 | llassert (idDecl_isDefined (d)); | |
134 | ||
135 | qtype_setType (d->typ, c); | |
136 | return d; | |
137 | } | |
138 | ||
139 | idDecl | |
140 | idDecl_fixBase (/*@returned@*/ idDecl t, qtype b) | |
141 | { | |
142 | llassert (idDecl_isDefined (t)); | |
143 | ||
144 | t->typ = qtype_newQbase (t->typ, b); | |
145 | return t; | |
146 | } | |
147 | ||
148 | idDecl | |
149 | idDecl_fixParamBase (/*@returned@*/ idDecl t, qtype b) | |
150 | { | |
151 | qtype q; | |
152 | ctype c; | |
153 | ||
154 | llassert (idDecl_isDefined (t)); | |
155 | ||
156 | q = qtype_newQbase (t->typ, b); | |
157 | c = qtype_getType (q); | |
158 | ||
159 | /* | |
160 | ** For some reason, C adds an implicit pointer to function | |
161 | ** parameters. It is "optional" syntax. | |
162 | */ | |
163 | ||
164 | if (ctype_isFunction (c) && !ctype_isPointer (c)) | |
165 | { | |
166 | qtype_setType (q, ctype_makePointer (c)); | |
167 | } | |
168 | ||
169 | t->typ = q; | |
170 | /* LCLint thinks t->typ is kept. */ | |
171 | /*@-compmempass@*/ return t; /*@=compmempass@*/ | |
172 | } | |
173 | ||
174 | idDecl | |
175 | idDecl_expectFunction (/*@returned@*/ idDecl d) | |
176 | { | |
177 | llassert (idDecl_isDefined (d)); | |
178 | ||
179 | qtype_setType (d->typ, ctype_expectFunction (qtype_getType (d->typ))); | |
180 | return d; | |
181 | } |