]> andersk Git - splint.git/blob - src/lclsyntable.c
Fixed -help <mode> bug.
[splint.git] / src / lclsyntable.c
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.
19 **
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
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
40 # include "splintMacros.nf"
41 # include "basic.h"
42 # include "lcltokentable.h"
43 # include "lclsyntable.h"
44
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@*/;
51
52 void
53 LCLAddSyn (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
78 LCLGetTokenForSyn (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
88 bool
89 LCLIsSyn (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   
112 static void
113 AllocSynTable (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;
124       SynTable = (lsymbol *) dmalloc 
125         (size_fromLongUnsigned (newSize * sizeof (*SynTable)));
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);
135       SynTable = (lsymbol *) dmalloc 
136         (size_fromLongUnsigned (newSize * sizeof (*SynTable)));
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
167 void
168 LCLSynTableInit (void)
169 {
170   MaxSyn = 0;
171 }
172
173 void
174 LCLSynTableReset (void)
175 {
176 }
177
178 void
179 LCLSynTableCleanup (void)
180 {
181   sfree (SynTable);
182   SynTable = NULL;
183 }
This page took 0.736295 seconds and 5 git commands to generate.