]> andersk Git - splint.git/blame - src/lcltokentable.c
Fixed all /*@i...@*/ tags (except 1).
[splint.git] / src / lcltokentable.c
CommitLineData
616915dd 1/*
11db3170 2** Splint - annotation-assisted static program checker
c59f5181 3** Copyright (C) 1994-2003 University of Virginia,
616915dd 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**
155af98d 20** For information on splint: info@splint.org
21** To report a bug: splint-bug@splint.org
11db3170 22** For more information: http://www.splint.org
616915dd 23*/
24/*
25** tokentable.c
26**
27** Larch processors token table
28** This table stores predefined tokens for LCL.
29*/
30
1b8ae690 31# include "splintMacros.nf"
b73d1009 32# include "basic.h"
616915dd 33# include "lcltokentable.h"
34
35static long unsigned MaxToken;
36static /*@only@*/ /*@null@*/ o_ltoken *LCLTokenTable = NULL;
37
38static void AllocTokenTable (void)
39 /*@globals LCLTokenTable@*/
40 /*@modifies LCLTokenTable, MaxToken@*/;
41
42ltoken
43 LCLInsertToken (ltokenCode cod, lsymbol sym, lsymbol rTxt,
44 bool isPredefined)
45{
46 /*
47 ** If the token is already in the token table, it is returned. Otherwise,
48 ** the token is inserted into the table and then returned.
49 **
50 ** A new TokenTable is allocated when:
51 ** . The TokenTable[] is empty (initial case)
52 ** . The location where to insert the token is not in TokenTable[]
53 */
54
55 setCodePoint ();
56
57 while (sym >= MaxToken)
58 {
59 setCodePoint ();
60 /* No more space available. Allocate more. */
61 AllocTokenTable ();
62 }
63
64 llassert (LCLTokenTable != NULL);
65
66 if (ltoken_isUndefined (LCLTokenTable[sym]))
67 {
68 LCLTokenTable[sym] = ltoken_create (cod, sym);
69 ltoken_setRawText (LCLTokenTable[sym], rTxt);
70 ltoken_setDefined (LCLTokenTable[sym], isPredefined);
71 return LCLTokenTable[sym];
72 }
73
74 return LCLTokenTable[sym];
75}
76
77void LCLUpdateToken (ltokenCode cod, lsymbol sym, bool def)
78{
79 llassert (LCLTokenTable != NULL);
80
81 if (!ltoken_isUndefined (LCLTokenTable[sym]))
82 {
83 ltoken_setCode (LCLTokenTable[sym], cod);
84 ltoken_setDefined (LCLTokenTable[sym], def);
85 }
86 else
87 {
88 llfatalbug (message ("LCLUpdateToken: %s",
89 cstring_fromChars (lsymbol_toChars (sym))));
90 }
91}
92
93void LCLSetTokenHasSyn (lsymbol sym, bool syn)
94{
95 llassert (LCLTokenTable != NULL);
96
97 if (!ltoken_isUndefined (LCLTokenTable[sym]))
98 {
99 ltoken_setHasSyn (LCLTokenTable[sym], syn);
100 }
101 else
102 {
103 llfatalbug (message ("LCLSetTokenHasSyn: null token (%d)", (int)sym));
104 }
105}
106
107ltoken LCLGetToken (lsymbol sym)
108{
109 llassert (LCLTokenTable != NULL);
110 llassert (sym < MaxToken);
111
112 return LCLTokenTable[sym];
113}
114
115#if 0
116bool LCLTokenTableContainsToken (ltoken tok)
117{
118 unsigned long i;
119
120 if (LCLTokenTable != NULL) {
121 for (i = 0; i < MaxToken; i++) {
122 if (LCLTokenTable[i] == tok) {
123 return TRUE;
124 }
125 }
126 }
127
128 return FALSE;
129}
130# endif
131
132/*@exposed@*/ ltoken
133LCLReserveToken (ltokenCode cod, char *txt)
134{
135 /*
136 ** The same context that was active when the string-handle
137 ** was derived by a previous call to lsymbol_fromChars (),
138 ** must be established.
139 */
140 lsymbol sym;
141
142 setCodePoint ();
143 sym = lsymbol_fromChars (txt);
144
145 /*
146 ** Reserved tokens never have raw text like synonyms.
147 */
148
149 return (LCLInsertToken (cod, sym, lsymbol_undefined, TRUE));
150}
151
152static void
153 AllocTokenTable (void) /*@globals LCLTokenTable; @*/
154{
155 long unsigned oldSize, newSize;
156 long unsigned int i;
157
158 oldSize = MaxToken;
159
160 if (oldSize == 0)
161 {
162 newSize = INITTOKENTABLE;
163 llassert (LCLTokenTable == NULL);
e5081f8c 164 LCLTokenTable = (ltoken *) dmalloc
165 (size_fromLongUnsigned (newSize * sizeof (*LCLTokenTable)));
616915dd 166 }
167 else
168 {
169 o_ltoken *oldLCLTokenTable = LCLTokenTable;
170
171 llassert (oldLCLTokenTable != NULL);
172
173 newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
e5081f8c 174 LCLTokenTable = (ltoken *) dmalloc
175 (size_fromLongUnsigned (newSize * sizeof (*LCLTokenTable)));
616915dd 176
177 for (i = 0; i < oldSize; i++)
178 {
179 LCLTokenTable[i] = oldLCLTokenTable[i];
180 }
181
182 sfree (oldLCLTokenTable);
183 }
184
185 MaxToken = newSize;
186
187 /*@+loopexec@*/
188 for (i = oldSize; i < newSize; i++)
189 {
190 LCLTokenTable[i] = ltoken_undefined;
191 }
192 /*@=loopexec@*/
193/*@-compdef@*/ } /*=compdef@*/
194
195void
196LCLTokenTableInit (void)
197{
198 MaxToken = 0;
199}
200
201void
202LCLTokenTableCleanup (void)
203{
204
205 if (LCLTokenTable != NULL)
206 {
207 long unsigned i;
208
209 for (i = 0; i < MaxToken; i++)
210 {
211 ltoken tok = LCLTokenTable[i];
212
213 LCLTokenTable[i] = NULL;
214 /*@-dependenttrans@*/ ltoken_free (tok);
215 /*@=dependenttrans@*/
216 }
217
218 sfree (LCLTokenTable);
219 LCLTokenTable = NULL;
220 }
221
222 }
223
224
225
226
227
228
229
230
231
232
This page took 0.091143 seconds and 5 git commands to generate.