2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
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.
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.
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
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.
37 # include "splintMacros.nf"
39 # include "tokentable.h"
40 # include "syntable.h"
44 typedef lsymbol *lsymbolTable;
46 static /*@only@*/ /*@null@*/ lsymbolTable SynTable;
47 static unsigned long int SynTableEntries;
49 static void SynTable_grow (int p_size);
59 ** otok - token-handle for token associated with oldToken
60 ** ntok - string-handle for the string to be a synonym with oldToken.
66 ** A context must be established.
70 ** This routine inserts a synonym into the synonym table. The synonym table
71 ** is used to define synonyms in the form:
73 ** synonym oldToken newToken
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
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[]
83 ** IMPLICIT INPUTS/OUTPUT:
85 ** SynTable - (input/output) SynTable array
88 ** A synonym already exists at the location where the it is to be added.
94 LSLAddSyn (lsymbol ntok, lsymbol otok)
96 if (ntok >= SynTableEntries) /* was otok */
101 llassert (SynTable != NULL);
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. */
110 llbuglit ("LSLAddSyn: duplicate SynTable entry");
115 LSLGetTokenForSyn (lsymbol ntok)
117 llassert (SynTable != NULL);
118 llassert (!(!((ntok < SynTableEntries) || (SynTable[ntok] != 0))));
120 return LSLGetToken (SynTable[ntok]);
124 LSLIsSyn (lsymbol str)
126 if (str < SynTableEntries)
128 llassert (SynTable != NULL);
129 return (SynTable[str] != 0);
138 SynTable_grow (int size)
142 lsymbolTable oldSynTable = SynTable;
144 llassert (oldSynTable != NULL);
145 oldSize = SynTableEntries;
149 llcontbuglit ("SynTable_grow: goal size is smaller than oldSize");
153 if (size < (oldSize + SYNTABLE_BASESIZE))
155 size = oldSize + SYNTABLE_BASESIZE;
158 SynTable = (lsymbolTable) dmalloc (size * sizeof (*SynTable));
159 SynTableEntries = size;
161 for (i = 0; i < oldSize; i++)
163 SynTable[i] = oldSynTable[i];
166 /* Zero out new allocated space. Need to detect when cells are empty */
167 /* and do this by checking that SynTable[x] == 0. */
170 for (i = oldSize; i < size; i++)
172 SynTable[i] = (lsymbol) 0;
177 /*@-compdef@*/ } /*=compdef@*/
180 lsynTableInit (void) /*@globals undef SynTable; @*/
184 SynTable = (lsymbolTable) dmalloc (sizeof (*SynTable) * SYNTABLE_BASESIZE);
187 for (i = 0; i < SYNTABLE_BASESIZE; i++)
189 SynTable[i] = (lsymbol) 0;
193 SynTableEntries = SYNTABLE_BASESIZE;
194 /*@-compdef@*/ } /*@=compdef@*/
197 lsynTableReset (void)
202 lsynTableCleanup (void)