Some consistency changes to library & headers flags.
[splint-patched.git] / src / lcltokentable.c
blob9e3e11ec659c57635da57bcf25bad538e692dbe1
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
25 ** tokentable.c
27 ** Larch processors token table
28 ** This table stores predefined tokens for LCL.
31 # include "splintMacros.nf"
32 # include "basic.h"
33 # include "lcltokentable.h"
35 static long unsigned MaxToken;
36 static /*@only@*/ /*@null@*/ o_ltoken *LCLTokenTable = NULL;
38 static void AllocTokenTable (void)
39 /*@globals LCLTokenTable@*/
40 /*@modifies LCLTokenTable, MaxToken@*/;
42 ltoken
43 LCLInsertToken (ltokenCode cod, lsymbol sym, lsymbol rTxt,
44 bool isPredefined)
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.
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[]
55 setCodePoint ();
57 while (sym >= MaxToken)
59 setCodePoint ();
60 /* No more space available. Allocate more. */
61 AllocTokenTable ();
64 llassert (LCLTokenTable != NULL);
66 if (ltoken_isUndefined (LCLTokenTable[sym]))
68 LCLTokenTable[sym] = ltoken_create (cod, sym);
69 ltoken_setRawText (LCLTokenTable[sym], rTxt);
70 ltoken_setDefined (LCLTokenTable[sym], isPredefined);
71 return LCLTokenTable[sym];
74 return LCLTokenTable[sym];
77 void LCLUpdateToken (ltokenCode cod, lsymbol sym, bool def)
79 llassert (LCLTokenTable != NULL);
81 if (!ltoken_isUndefined (LCLTokenTable[sym]))
83 ltoken_setCode (LCLTokenTable[sym], cod);
84 ltoken_setDefined (LCLTokenTable[sym], def);
86 else
88 llfatalbug (message ("LCLUpdateToken: %s",
89 cstring_fromChars (lsymbol_toChars (sym))));
93 void LCLSetTokenHasSyn (lsymbol sym, bool syn)
95 llassert (LCLTokenTable != NULL);
97 if (!ltoken_isUndefined (LCLTokenTable[sym]))
99 ltoken_setHasSyn (LCLTokenTable[sym], syn);
101 else
103 llfatalbug (message ("LCLSetTokenHasSyn: null token (%d)", (int)sym));
107 ltoken LCLGetToken (lsymbol sym)
109 llassert (LCLTokenTable != NULL);
110 llassert (sym < MaxToken);
112 return LCLTokenTable[sym];
115 #if 0
116 bool LCLTokenTableContainsToken (ltoken tok)
118 unsigned long i;
120 if (LCLTokenTable != NULL) {
121 for (i = 0; i < MaxToken; i++) {
122 if (LCLTokenTable[i] == tok) {
123 return TRUE;
128 return FALSE;
130 # endif
132 /*@exposed@*/ ltoken
133 LCLReserveToken (ltokenCode cod, const char *txt)
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.
140 lsymbol sym;
142 setCodePoint ();
143 sym = lsymbol_fromChars (txt);
146 ** Reserved tokens never have raw text like synonyms.
149 return (LCLInsertToken (cod, sym, lsymbol_undefined, TRUE));
152 static void
153 AllocTokenTable (void) /*@globals LCLTokenTable; @*/
155 long unsigned oldSize, newSize;
156 long unsigned int i;
158 oldSize = MaxToken;
160 if (oldSize == 0)
162 newSize = INITTOKENTABLE;
163 llassert (LCLTokenTable == NULL);
164 LCLTokenTable = (ltoken *) dmalloc
165 (size_fromLongUnsigned (newSize * sizeof (*LCLTokenTable)));
167 else
169 o_ltoken *oldLCLTokenTable = LCLTokenTable;
171 llassert (oldLCLTokenTable != NULL);
173 newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
174 LCLTokenTable = (ltoken *) dmalloc
175 (size_fromLongUnsigned (newSize * sizeof (*LCLTokenTable)));
177 for (i = 0; i < oldSize; i++)
179 LCLTokenTable[i] = oldLCLTokenTable[i];
182 sfree (oldLCLTokenTable);
185 MaxToken = newSize;
187 /*@+loopexec@*/
188 for (i = oldSize; i < newSize; i++)
190 LCLTokenTable[i] = ltoken_undefined;
192 /*@=loopexec@*/
193 /*@-compdef@*/ } /*=compdef@*/
195 void
196 LCLTokenTableInit (void)
198 MaxToken = 0;
201 void
202 LCLTokenTableCleanup (void)
205 if (LCLTokenTable != NULL)
207 long unsigned i;
209 for (i = 0; i < MaxToken; i++)
211 ltoken tok = LCLTokenTable[i];
213 LCLTokenTable[i] = NULL;
214 /*@-dependenttrans@*/ ltoken_free (tok);
215 /*@=dependenttrans@*/
218 sfree (LCLTokenTable);
219 LCLTokenTable = NULL;