]> andersk Git - splint.git/blame - src/tokentable.c
Committing to make sure that the ./configure works.
[splint.git] / src / tokentable.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
1b8ae690 28# include "splintMacros.nf"
616915dd 29# include "llbasic.h"
30# include "osd.h"
31# include "tokentable.h"
32
33static long unsigned MaxToken;
34static /*@null@*/ /*@only@*/ o_ltoken *TokenTable;
35
36static void AllocTokenTable (void) /*@modifies TokenTable, MaxToken@*/ ;
37
38ltoken
39 LSLInsertToken (ltokenCode cod, lsymbol sym, lsymbol rTxt, bool def)
40{
41 while (sym >= MaxToken)
42 {
43 AllocTokenTable ();
44 }
45
46 llassert (TokenTable != NULL);
47
48 if (ltoken_isUndefined (TokenTable[sym]))
49 {
50 TokenTable[sym] = ltoken_create (cod, sym);
51 ltoken_setRawText (TokenTable[sym], rTxt);
52 ltoken_setDefined (TokenTable[sym], def);
53 }
54
55 return TokenTable[sym];
56}
57
58void
59LSLUpdateToken (ltokenCode cod, lsymbol sym, bool def)
60{
61 llassert (TokenTable != NULL);
62
63 if (!ltoken_isUndefined (TokenTable[sym]))
64 {
65 ltoken_setCode (TokenTable[sym], cod);
66 ltoken_setDefined (TokenTable[sym], def);
67 }
68 else
69 {
70 llfatalbug (message ("LSLUpdateToken: token not in table: %d, text: %s",
71 (int) cod, cstring_fromChars (lsymbol_toChars (sym))));
72 }
73}
74
75void
76LSLSetTokenHasSyn (lsymbol sym, bool syn)
77{
78 llassert (TokenTable != NULL);
79
80 if (!ltoken_isUndefined (TokenTable[sym]))
81 {
82 ltoken_setHasSyn (TokenTable[sym], syn);
83 }
84 else
85 {
86 llbuglit ("LSLSetTokenHasSyn: null token");
87 }
88}
89
90ltoken LSLGetToken (lsymbol sym)
91{
92 llassert (TokenTable != NULL);
93
94 if (!((sym < MaxToken) || (!ltoken_isUndefined (TokenTable[sym]))))
95 {
96 llcontbuglit ("LSLGetToken: bad argument");
97 return TokenTable[0];
98 }
99
100 return TokenTable[sym];
101}
102
103/*@exposed@*/ ltoken
104LSLReserveToken (ltokenCode cod, char *txt)
105{
106 lsymbol sym;
107
108 sym = lsymbol_fromChars (txt);
109
110 /*
111 ** Reserved tokens never have raw text like synonyms.
112 */
113
114 return LSLInsertToken (cod, sym, lsymbol_undefined, TRUE);
115}
116
117static void
118AllocTokenTable (void)
119{
120 long unsigned oldSize, newSize;
121 long unsigned int i;
122
123 oldSize = MaxToken;
124
125 if (oldSize == 0)
126 {
127 newSize = INITTOKENTABLE;
128 llassert (TokenTable == NULL);
129 TokenTable = (ltoken *) dmalloc (newSize * sizeof (*TokenTable));
130 }
131 else
132 {
133 o_ltoken *oldTokenTable = TokenTable;
134
135 newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
136 TokenTable = (ltoken *) dmalloc (newSize * sizeof (*TokenTable));
137
138 llassert (oldSize > 0);
139 llassert (oldTokenTable != NULL);
140
141 for (i = 0; i < oldSize; i++)
142 {
143 TokenTable[i] = oldTokenTable[i];
144 }
145
146 sfree (oldTokenTable);
147 }
148
149 /*@+loopexec@*/
150 for (i = oldSize; i < newSize; i++)
151 {
152 TokenTable[i] = ltoken_undefined;
153 }
154 /*@=loopexec@*/
155
156 MaxToken = newSize;
157/*@-compdef@*/ } /*=compdef@*/
158
159void
160ltokenTableInit (void)
161{
162 MaxToken = 0;
163}
164
165void
166ltokenTableCleanup (void)
167{
168 if (TokenTable != NULL)
169 {
170 long unsigned i;
171
172 for (i = 0; i < MaxToken; i++)
173 {
174 ltoken_free (TokenTable[i]);
175 }
176
177 sfree (TokenTable);
178 TokenTable = NULL;
179 }
180}
This page took 0.092651 seconds and 5 git commands to generate.