2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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/C Interface language synonym table
29 ** This table stores synonyms for the Larch/C Interface Language. It is
30 ** essentially an array of token-handles indexed by string-handles.
31 ** Therefore, synonyms (strings) can be converted to the actual token.
37 ** CREATION DATE: 90.08.10
40 # include "splintMacros.nf"
42 # include "lcltokentable.h"
43 # include "lclsyntable.h"
45 static long unsigned MaxSyn; /* size of SynTable[] */
46 static /*@only@*/ /*@reldef@*/ /*@null@*/ lsymbol *SynTable;
49 /*@globals SynTable, MaxSyn@*/
50 /*@modifies *SynTable, MaxSyn@*/;
53 LCLAddSyn (lsymbol ntok, lsymbol otok)
55 while (otok >= MaxSyn)
57 /* No more space available. Allocate more. */
61 llassert (SynTable != NULL);
63 if (SynTable[ntok] == 0)
65 /* Entry is empty. Fill it in. */
66 SynTable[ntok] = otok;
68 /* Mark oldToken as having a synonym. */
69 LCLSetTokenHasSyn (otok, TRUE);
73 llbuglit ("LCLAddSyn: invalid argument");
78 LCLGetTokenForSyn (lsymbol ntok)
80 llassert (SynTable != NULL);
82 if (!((ntok < MaxSyn) || (SynTable[ntok] != 0)))
83 llbuglit ("LCLGetSyn: bad argument");
85 return LCLGetToken (SynTable[ntok]);
89 LCLIsSyn (lsymbol str)
97 llassert (SynTable != NULL);
101 /* Check for synonym entry in table. */
102 return (SynTable[str] != 0);
106 /* No token for synonym. Return FALSE. */
113 AllocSynTable (void) /*@globals SynTable; @*/
115 long unsigned newSize, oldSize;
122 /* First time SynTable allocated. Set initial size. */
123 newSize = INITSYNTABLE;
124 SynTable = (lsymbol *) dmalloc
125 (size_fromLongUnsigned (newSize * sizeof (*SynTable)));
129 lsymbol *oldSynTable = SynTable;
131 llassert (oldSynTable != NULL);
133 /* Synonym table already allocated. Calulate extension size. */
134 newSize = (unsigned long) (DELTASYNTABLE * oldSize);
135 SynTable = (lsymbol *) dmalloc
136 (size_fromLongUnsigned (newSize * sizeof (*SynTable)));
138 for (i = 0; i < oldSize; i++)
140 SynTable[i] = oldSynTable[i];
146 /* Zero out new allocated space. Need to detect when cells are empty */
147 /* and do this by checking that SynTable[x] == 0. */
149 /* ### Should the "for" loop be replaced with the following? */
151 /* # include <string.h>; */
153 /* # include <memory.h>; */
155 /* memset (SynTable[oldSize], 0, */
156 /* (newSize - oldSize) * sizeof (*SynTable)); */
158 for (i = oldSize; i < newSize; i++)
168 LCLSynTableInit (void)
174 LCLSynTableReset (void)
179 LCLSynTableCleanup (void)