Nicer handling of hand-generated files by build system
[splint-patched.git] / src / lclsyntable.c
blobb9d39c967cc5b93d9a2c0b6a21ee2f1b666c96ac
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 ** syntable.c
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.
33 ** AUTHORS:
34 ** J.P. Wild
37 ** CREATION DATE: 90.08.10
40 # include "splintMacros.nf"
41 # include "basic.h"
42 # include "lcltokentable.h"
43 # include "lclsyntable.h"
45 static long unsigned MaxSyn; /* size of SynTable[] */
46 static /*@only@*/ /*@reldef@*/ /*@null@*/ lsymbol *SynTable;
47 static void
48 AllocSynTable (void)
49 /*@globals SynTable, MaxSyn@*/
50 /*@modifies *SynTable, MaxSyn@*/;
52 void
53 LCLAddSyn (lsymbol ntok, lsymbol otok)
55 while (otok >= MaxSyn)
57 /* No more space available. Allocate more. */
58 AllocSynTable ();
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);
71 else
73 llbuglit ("LCLAddSyn: invalid argument");
77 /*@exposed@*/ ltoken
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]);
88 bool
89 LCLIsSyn (lsymbol str)
91 if (MaxSyn == 0)
93 return FALSE;
95 else
97 llassert (SynTable != NULL);
99 if (str < MaxSyn)
101 /* Check for synonym entry in table. */
102 return (SynTable[str] != 0);
104 else
106 /* No token for synonym. Return FALSE. */
107 return FALSE;
112 static void
113 AllocSynTable (void) /*@globals SynTable; @*/
115 long unsigned newSize, oldSize;
116 long unsigned int i;
118 oldSize = MaxSyn;
120 if (oldSize == 0)
122 /* First time SynTable allocated. Set initial size. */
123 newSize = INITSYNTABLE;
124 SynTable = (lsymbol *) dmalloc
125 (size_fromLongUnsigned (newSize * sizeof (*SynTable)));
127 else
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];
143 sfree (oldSynTable);
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? */
150 /* #if VMS */
151 /* # include <string.h>; */
152 /* #else */
153 /* # include <memory.h>; */
154 /* */
155 /* memset (SynTable[oldSize], 0, */
156 /* (newSize - oldSize) * sizeof (*SynTable)); */
158 for (i = oldSize; i < newSize; i++)
160 SynTable[i] = 0;
163 MaxSyn = newSize;
167 void
168 LCLSynTableInit (void)
170 MaxSyn = 0;
173 void
174 LCLSynTableReset (void)
178 void
179 LCLSynTableCleanup (void)
181 sfree (SynTable);
182 SynTable = NULL;