]> andersk Git - splint.git/blame - src/tokentable.c
Fixed all /*@i...@*/ tags (except 1).
[splint.git] / src / tokentable.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
1b8ae690 28# include "splintMacros.nf"
b73d1009 29# include "basic.h"
616915dd 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);
e5081f8c 129 TokenTable = (ltoken *)
130 dmalloc (size_fromLongUnsigned (newSize * sizeof (*TokenTable)));
616915dd 131 }
132 else
133 {
134 o_ltoken *oldTokenTable = TokenTable;
135
136 newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
e5081f8c 137 TokenTable = (ltoken *)
138 dmalloc (size_fromLongUnsigned (newSize * sizeof (*TokenTable)));
616915dd 139
140 llassert (oldSize > 0);
141 llassert (oldTokenTable != NULL);
142
143 for (i = 0; i < oldSize; i++)
144 {
145 TokenTable[i] = oldTokenTable[i];
146 }
147
148 sfree (oldTokenTable);
149 }
150
151 /*@+loopexec@*/
152 for (i = oldSize; i < newSize; i++)
153 {
154 TokenTable[i] = ltoken_undefined;
155 }
156 /*@=loopexec@*/
157
158 MaxToken = newSize;
159/*@-compdef@*/ } /*=compdef@*/
160
161void
162ltokenTableInit (void)
163{
164 MaxToken = 0;
165}
166
167void
168ltokenTableCleanup (void)
169{
170 if (TokenTable != NULL)
171 {
172 long unsigned i;
173
174 for (i = 0; i < MaxToken; i++)
175 {
176 ltoken_free (TokenTable[i]);
177 }
178
179 sfree (TokenTable);
180 TokenTable = NULL;
181 }
182}
This page took 0.091036 seconds and 5 git commands to generate.