]> andersk Git - splint.git/blame - src/syntable.c
noexpand always false.
[splint.git] / src / syntable.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** syntable.c
26**
27** Larch shared language synonym table
28**
29** This table stores synonyms for the Larch Shared Language. It is
30** essentially a array of token-handles indexed by string-handles.
31** Therefore, synonyms (strings) can be converted to the actual token.
32**
33** AUTHORS:
34** J.P. Wild
35*/
36
1b8ae690 37# include "splintMacros.nf"
616915dd 38# include "basic.h"
39# include "tokentable.h"
40# include "syntable.h"
41
42/*@+ignorequals@*/
43
44typedef lsymbol *lsymbolTable;
45
46static /*@only@*/ /*@null@*/ lsymbolTable SynTable;
47static unsigned long int SynTableEntries;
48
49static void SynTable_grow (int p_size);
50
51/*
52**++
53** FUNCTION NAME:
54**
55** LSLAddSyn ()
56**
57** FORMAL PARAMETERS:
58**
59** otok - token-handle for token associated with oldToken
60** ntok - string-handle for the string to be a synonym with oldToken.
61**
62** RETURN VALUE:
63**
64** INVARIANTS:
65**
66** A context must be established.
67**
68** DESCRIPTION:
69**
70** This routine inserts a synonym into the synonym table. The synonym table
71** is used to define synonyms in the form:
72**
73** synonym oldToken newToken
74**
75** The table associates the string for newToken with the token for oldToken.
76** This table is used to find the the actual token (oldToken) from a synonym
77** string (newToken).
78**
79** A new SynTable is allocated when:
80** . The SynTable[] is empty (initial case)
81** . The location where to insert the synonym is not in SynTable[]
82**
83** IMPLICIT INPUTS/OUTPUT:
84**
85** SynTable - (input/output) SynTable array
86**
87** EXCEPTIONS:
88** A synonym already exists at the location where the it is to be added.
89**
90**--
91*/
92
93void
94LSLAddSyn (lsymbol ntok, lsymbol otok)
95{
96 if (ntok >= SynTableEntries) /* was otok */
97 {
98 SynTable_grow (otok);
99 }
100
101 llassert (SynTable != NULL);
102
103 if (SynTable[ntok] == (lsymbol) 0)
104 { /* Entry is empty. Fill it in. */
105 SynTable[ntok] = otok;
106 LSLSetTokenHasSyn (otok, TRUE); /* Mark oldToken as having a synonym. */
107 }
108 else
109 {
110 llbuglit ("LSLAddSyn: duplicate SynTable entry");
111 }
112}
113
114/*@exposed@*/ ltoken
115LSLGetTokenForSyn (lsymbol ntok)
116{
117 llassert (SynTable != NULL);
118 llassert (!(!((ntok < SynTableEntries) || (SynTable[ntok] != 0))));
119
120 return LSLGetToken (SynTable[ntok]);
121}
122
123bool
124LSLIsSyn (lsymbol str)
125{
126 if (str < SynTableEntries)
127 {
128 llassert (SynTable != NULL);
129 return (SynTable[str] != 0);
130 }
131 else
132 {
133 return FALSE;
134 }
135}
136
137static void
138SynTable_grow (int size)
139{
140 int oldSize;
141 int i;
142 lsymbolTable oldSynTable = SynTable;
143
144 llassert (oldSynTable != NULL);
145 oldSize = SynTableEntries;
146
147 if (size <= oldSize)
148 {
149 llcontbuglit ("SynTable_grow: goal size is smaller than oldSize");
150 return;
151 }
152
153 if (size < (oldSize + SYNTABLE_BASESIZE))
154 {
155 size = oldSize + SYNTABLE_BASESIZE;
156 }
157
158 SynTable = (lsymbolTable) dmalloc (size * sizeof (*SynTable));
159 SynTableEntries = size;
160
161 for (i = 0; i < oldSize; i++)
162 {
163 SynTable[i] = oldSynTable[i];
164 }
165
166 /* Zero out new allocated space. Need to detect when cells are empty */
167 /* and do this by checking that SynTable[x] == 0. */
168
169 /*@+loopexec@*/
170 for (i = oldSize; i < size; i++)
171 {
172 SynTable[i] = (lsymbol) 0;
173 }
174 /*@=loopexec@*/
175
176 sfree (oldSynTable);
177/*@-compdef@*/ } /*=compdef@*/
178
179void
180lsynTableInit (void) /*@globals undef SynTable; @*/
181{
182 int i;
183
184 SynTable = (lsymbolTable) dmalloc (sizeof (*SynTable) * SYNTABLE_BASESIZE);
185
186 /*@+loopexec@*/
187 for (i = 0; i < SYNTABLE_BASESIZE; i++)
188 {
189 SynTable[i] = (lsymbol) 0;
190 }
191 /*@=loopexec@*/
192
193 SynTableEntries = SYNTABLE_BASESIZE;
194/*@-compdef@*/ } /*@=compdef@*/
195
196void
197lsynTableReset (void)
198{
199}
200
201void
202lsynTableCleanup (void)
203{
204 sfree (SynTable);
205 SynTable = NULL;
206}
207
208
209
210
211
212
213
214
215
216
217
218
This page took 0.104046 seconds and 5 git commands to generate.