]> andersk Git - splint.git/blame - src/lcltokentable.c
Committing to make sure that the ./configure works.
[splint.git] / src / lcltokentable.c
CommitLineData
616915dd 1/*
11db3170 2** Splint - annotation-assisted static program checker
77d37419 3** Copyright (C) 1994-2002 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"
616915dd 32# include "llbasic.h"
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);
164 LCLTokenTable = (ltoken *) dmalloc (newSize * sizeof (*LCLTokenTable));
165 }
166 else
167 {
168 o_ltoken *oldLCLTokenTable = LCLTokenTable;
169
170 llassert (oldLCLTokenTable != NULL);
171
172 newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
173 LCLTokenTable = (ltoken *) dmalloc (newSize * sizeof (*LCLTokenTable));
174
175 for (i = 0; i < oldSize; i++)
176 {
177 LCLTokenTable[i] = oldLCLTokenTable[i];
178 }
179
180 sfree (oldLCLTokenTable);
181 }
182
183 MaxToken = newSize;
184
185 /*@+loopexec@*/
186 for (i = oldSize; i < newSize; i++)
187 {
188 LCLTokenTable[i] = ltoken_undefined;
189 }
190 /*@=loopexec@*/
191/*@-compdef@*/ } /*=compdef@*/
192
193void
194LCLTokenTableInit (void)
195{
196 MaxToken = 0;
197}
198
199void
200LCLTokenTableCleanup (void)
201{
202
203 if (LCLTokenTable != NULL)
204 {
205 long unsigned i;
206
207 for (i = 0; i < MaxToken; i++)
208 {
209 ltoken tok = LCLTokenTable[i];
210
211 LCLTokenTable[i] = NULL;
212 /*@-dependenttrans@*/ ltoken_free (tok);
213 /*@=dependenttrans@*/
214 }
215
216 sfree (LCLTokenTable);
217 LCLTokenTable = NULL;
218 }
219
220 }
221
222
223
224
225
226
227
228
229
230
This page took 0.100076 seconds and 5 git commands to generate.