Some consistency changes to library & headers flags.
[splint-patched.git] / src / lslsyntable.c
blob9c08deaa9a8300e4f8eb02521d7fd2f6e3424ad2
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 ** lslsyntable.c
27 ** Larch shared language synonym table
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.
33 ** AUTHORS:
34 ** J.P. Wild
37 # include "splintMacros.nf"
38 # include "basic.h"
40 # include "lsltokentable.h"
41 # include "lslsyntable.h"
43 /*@+ignorequals@*/
45 typedef lsymbol *lsymbolTable;
47 static /*@only@*/ /*@null@*/ lsymbolTable SynTable;
48 static unsigned long int SynTableEntries;
50 static void SynTable_grow (int p_size);
53 **++
54 ** FUNCTION NAME:
56 ** LSLAddSyn ()
58 ** FORMAL PARAMETERS:
60 ** otok - token-handle for token associated with oldToken
61 ** ntok - string-handle for the string to be a synonym with oldToken.
63 ** RETURN VALUE:
65 ** INVARIANTS:
67 ** A context must be established.
69 ** DESCRIPTION:
71 ** This routine inserts a synonym into the synonym table. The synonym table
72 ** is used to define synonyms in the form:
74 ** synonym oldToken newToken
76 ** The table associates the string for newToken with the token for oldToken.
77 ** This table is used to find the the actual token (oldToken) from a synonym
78 ** string (newToken).
80 ** A new SynTable is allocated when:
81 ** . The SynTable[] is empty (initial case)
82 ** . The location where to insert the synonym is not in SynTable[]
84 ** IMPLICIT INPUTS/OUTPUT:
86 ** SynTable - (input/output) SynTable array
88 ** EXCEPTIONS:
89 ** A synonym already exists at the location where the it is to be added.
91 **--
94 void
95 LSLAddSyn (lsymbol ntok, lsymbol otok)
97 if (ntok >= SynTableEntries) /* was otok */
99 SynTable_grow (otok);
102 llassert (SynTable != NULL);
104 if (SynTable[ntok] == (lsymbol) 0)
105 { /* Entry is empty. Fill it in. */
106 SynTable[ntok] = otok;
107 LSLSetTokenHasSyn (otok, TRUE); /* Mark oldToken as having a synonym. */
109 else
111 llbuglit ("LSLAddSyn: duplicate SynTable entry");
115 /*@exposed@*/ ltoken
116 LSLGetTokenForSyn (lsymbol ntok)
118 llassert (SynTable != NULL);
119 llassert (!(!((ntok < SynTableEntries) || (SynTable[ntok] != 0))));
121 return LSLGetToken (SynTable[ntok]);
124 bool
125 LSLIsSyn (lsymbol str)
127 if (str < SynTableEntries)
129 llassert (SynTable != NULL);
130 return (SynTable[str] != 0);
132 else
134 return FALSE;
138 static void
139 SynTable_grow (int size)
141 int oldSize;
142 int i;
143 lsymbolTable oldSynTable = SynTable;
145 llassert (oldSynTable != NULL);
146 oldSize = SynTableEntries;
148 if (size <= oldSize)
150 llcontbuglit ("SynTable_grow: goal size is smaller than oldSize");
151 return;
154 if (size < (oldSize + SYNTABLE_BASESIZE))
156 size = oldSize + SYNTABLE_BASESIZE;
159 SynTable = (lsymbolTable) dmalloc (size * sizeof (*SynTable));
160 SynTableEntries = size;
162 for (i = 0; i < oldSize; i++)
164 SynTable[i] = oldSynTable[i];
167 /* Zero out new allocated space. Need to detect when cells are empty */
168 /* and do this by checking that SynTable[x] == 0. */
170 /*@+loopexec@*/
171 for (i = oldSize; i < size; i++)
173 SynTable[i] = (lsymbol) 0;
175 /*@=loopexec@*/
177 sfree (oldSynTable);
178 /*@-compdef@*/ } /*=compdef@*/
180 void
181 lsynTableInit (void) /*@globals undef SynTable; @*/
183 int i;
185 SynTable = (lsymbolTable) dmalloc (sizeof (*SynTable) * SYNTABLE_BASESIZE);
187 /*@+loopexec@*/
188 for (i = 0; i < SYNTABLE_BASESIZE; i++)
190 SynTable[i] = (lsymbol) 0;
192 /*@=loopexec@*/
194 SynTableEntries = SYNTABLE_BASESIZE;
195 /*@-compdef@*/ } /*@=compdef@*/
197 void
198 lsynTableReset (void)
202 void
203 lsynTableCleanup (void)
205 sfree (SynTable);
206 SynTable = NULL;