]> andersk Git - splint.git/blame - src/lclsyntable.c
noexpand always false.
[splint.git] / src / lclsyntable.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/C Interface language synonym table
28**
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.
32**
33** AUTHORS:
34** J.P. Wild
35**
36**
37** CREATION DATE: 90.08.10
38*/
39
1b8ae690 40# include "splintMacros.nf"
616915dd 41# include "basic.h"
42# include "lcltokentable.h"
43# include "lclsyntable.h"
44
45static long unsigned MaxSyn; /* size of SynTable[] */
46static /*@only@*/ /*@reldef@*/ /*@null@*/ lsymbol *SynTable;
47static void
48 AllocSynTable (void)
49 /*@globals SynTable, MaxSyn@*/
50 /*@modifies *SynTable, MaxSyn@*/;
51
52void
53LCLAddSyn (lsymbol ntok, lsymbol otok)
54{
55 while (otok >= MaxSyn)
56 {
57 /* No more space available. Allocate more. */
58 AllocSynTable ();
59 }
60
61 llassert (SynTable != NULL);
62
63 if (SynTable[ntok] == 0)
64 {
65 /* Entry is empty. Fill it in. */
66 SynTable[ntok] = otok;
67
68 /* Mark oldToken as having a synonym. */
69 LCLSetTokenHasSyn (otok, TRUE);
70 }
71 else
72 {
73 llbuglit ("LCLAddSyn: invalid argument");
74 }
75}
76
77/*@exposed@*/ ltoken
78LCLGetTokenForSyn (lsymbol ntok)
79{
80 llassert (SynTable != NULL);
81
82 if (!((ntok < MaxSyn) || (SynTable[ntok] != 0)))
83 llbuglit ("LCLGetSyn: bad argument");
84
85 return LCLGetToken (SynTable[ntok]);
86}
87
88bool
89LCLIsSyn (lsymbol str)
90{
91 if (MaxSyn == 0)
92 {
93 return FALSE;
94 }
95 else
96 {
97 llassert (SynTable != NULL);
98
99 if (str < MaxSyn)
100 {
101 /* Check for synonym entry in table. */
102 return (SynTable[str] != 0);
103 }
104 else
105 {
106 /* No token for synonym. Return FALSE. */
107 return FALSE;
108 }
109 }
110}
111
112static void
113AllocSynTable (void) /*@globals SynTable; @*/
114{
115 long unsigned newSize, oldSize;
116 long unsigned int i;
117
118 oldSize = MaxSyn;
119
120 if (oldSize == 0)
121 {
122 /* First time SynTable allocated. Set initial size. */
123 newSize = INITSYNTABLE;
e5081f8c 124 SynTable = (lsymbol *) dmalloc
125 (size_fromLongUnsigned (newSize * sizeof (*SynTable)));
616915dd 126 }
127 else
128 {
129 lsymbol *oldSynTable = SynTable;
130
131 llassert (oldSynTable != NULL);
132
133 /* Synonym table already allocated. Calulate extension size. */
134 newSize = (unsigned long) (DELTASYNTABLE * oldSize);
e5081f8c 135 SynTable = (lsymbol *) dmalloc
136 (size_fromLongUnsigned (newSize * sizeof (*SynTable)));
616915dd 137
138 for (i = 0; i < oldSize; i++)
139 {
140 SynTable[i] = oldSynTable[i];
141 }
142
143 sfree (oldSynTable);
144 }
145
146 /* Zero out new allocated space. Need to detect when cells are empty */
147 /* and do this by checking that SynTable[x] == 0. */
148
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)); */
157
158 for (i = oldSize; i < newSize; i++)
159 {
160 SynTable[i] = 0;
161 }
162
163 MaxSyn = newSize;
164}
165
166
167void
168LCLSynTableInit (void)
169{
170 MaxSyn = 0;
171}
172
173void
174LCLSynTableReset (void)
175{
176}
177
178void
179LCLSynTableCleanup (void)
180{
181 sfree (SynTable);
182 SynTable = NULL;
183}
This page took 0.115808 seconds and 5 git commands to generate.