Some consistency changes to library & headers flags.
[splint-patched.git] / src / lsltokentable.c
blob64f0132ba972bec6fb5e2d4a7bfd71069aa3f0d5
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 ** lsltokentable.c
28 # include "splintMacros.nf"
29 # include "basic.h"
31 # include "lsltokentable.h"
33 static long unsigned MaxToken;
34 static /*@null@*/ /*@only@*/ o_ltoken *TokenTable;
36 static void AllocTokenTable (void) /*@modifies TokenTable, MaxToken@*/ ;
38 ltoken
39 LSLInsertToken (ltokenCode cod, lsymbol sym, lsymbol rTxt, bool def)
41 while (sym >= MaxToken)
43 AllocTokenTable ();
46 llassert (TokenTable != NULL);
48 if (ltoken_isUndefined (TokenTable[sym]))
50 TokenTable[sym] = ltoken_create (cod, sym);
51 ltoken_setRawText (TokenTable[sym], rTxt);
52 ltoken_setDefined (TokenTable[sym], def);
55 return TokenTable[sym];
58 void
59 LSLUpdateToken (ltokenCode cod, lsymbol sym, bool def)
61 llassert (TokenTable != NULL);
63 if (!ltoken_isUndefined (TokenTable[sym]))
65 ltoken_setCode (TokenTable[sym], cod);
66 ltoken_setDefined (TokenTable[sym], def);
68 else
70 llfatalbug (message ("LSLUpdateToken: token not in table: %d, text: %s",
71 (int) cod, cstring_fromChars (lsymbol_toChars (sym))));
75 void
76 LSLSetTokenHasSyn (lsymbol sym, bool syn)
78 llassert (TokenTable != NULL);
80 if (!ltoken_isUndefined (TokenTable[sym]))
82 ltoken_setHasSyn (TokenTable[sym], syn);
84 else
86 llbuglit ("LSLSetTokenHasSyn: null token");
90 ltoken LSLGetToken (lsymbol sym)
92 llassert (TokenTable != NULL);
94 if (!((sym < MaxToken) || (!ltoken_isUndefined (TokenTable[sym]))))
96 llcontbuglit ("LSLGetToken: bad argument");
97 return TokenTable[0];
100 return TokenTable[sym];
103 /*@exposed@*/ ltoken
104 LSLReserveToken (ltokenCode cod, const char *txt)
106 lsymbol sym;
108 sym = lsymbol_fromChars (txt);
111 ** Reserved tokens never have raw text like synonyms.
114 return LSLInsertToken (cod, sym, lsymbol_undefined, TRUE);
117 static void
118 AllocTokenTable (void)
120 long unsigned oldSize, newSize;
121 long unsigned int i;
123 oldSize = MaxToken;
125 if (oldSize == 0)
127 newSize = INITTOKENTABLE;
128 llassert (TokenTable == NULL);
129 TokenTable = (ltoken *)
130 dmalloc (size_fromLongUnsigned (newSize * sizeof (*TokenTable)));
132 else
134 o_ltoken *oldTokenTable = TokenTable;
136 newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
137 TokenTable = (ltoken *)
138 dmalloc (size_fromLongUnsigned (newSize * sizeof (*TokenTable)));
140 llassert (oldSize > 0);
141 llassert (oldTokenTable != NULL);
143 for (i = 0; i < oldSize; i++)
145 TokenTable[i] = oldTokenTable[i];
148 sfree (oldTokenTable);
151 /*@+loopexec@*/
152 for (i = oldSize; i < newSize; i++)
154 TokenTable[i] = ltoken_undefined;
156 /*@=loopexec@*/
158 MaxToken = newSize;
159 /*@-compdef@*/ } /*=compdef@*/
161 void
162 ltokenTableInit (void)
164 MaxToken = 0;
167 void
168 ltokenTableCleanup (void)
170 if (TokenTable != NULL)
172 long unsigned i;
174 for (i = 0; i < MaxToken; i++)
176 ltoken_free (TokenTable[i]);
179 sfree (TokenTable);
180 TokenTable = NULL;