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 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"
40 # include "lsltokentable.h"
41 # include "lslsyntable.h"
45 typedef lsymbol
*lsymbolTable
;
47 static /*@only@*/ /*@null@*/ lsymbolTable SynTable
;
48 static unsigned long int SynTableEntries
;
50 static void SynTable_grow (int p_size
);
60 ** otok - token-handle for token associated with oldToken
61 ** ntok - string-handle for the string to be a synonym with oldToken.
67 ** A context must be established.
71 ** This routine inserts a synonym into the synonym table. The synonym table
72 ** is used to define synonyms in the form:
74 ** synonym oldToken newToken
76 ** The table associates the string for newToken with the token for oldToken.
77 ** This table is used to find the the actual token (oldToken) from a synonym
80 ** A new SynTable is allocated when:
81 ** . The SynTable[] is empty (initial case)
82 ** . The location where to insert the synonym is not in SynTable[]
84 ** IMPLICIT INPUTS/OUTPUT:
86 ** SynTable - (input/output) SynTable array
89 ** A synonym already exists at the location where the it is to be added.
95 LSLAddSyn (lsymbol ntok
, lsymbol otok
)
97 if (ntok
>= SynTableEntries
) /* was otok */
102 llassert (SynTable
!= NULL
);
104 if (SynTable
[ntok
] == (lsymbol
) 0)
105 { /* Entry is empty. Fill it in. */
106 SynTable
[ntok
] = otok
;
107 LSLSetTokenHasSyn (otok
, TRUE
); /* Mark oldToken as having a synonym. */
111 llbuglit ("LSLAddSyn: duplicate SynTable entry");
116 LSLGetTokenForSyn (lsymbol ntok
)
118 llassert (SynTable
!= NULL
);
119 llassert (!(!((ntok
< SynTableEntries
) || (SynTable
[ntok
] != 0))));
121 return LSLGetToken (SynTable
[ntok
]);
125 LSLIsSyn (lsymbol str
)
127 if (str
< SynTableEntries
)
129 llassert (SynTable
!= NULL
);
130 return (SynTable
[str
] != 0);
139 SynTable_grow (int size
)
143 lsymbolTable oldSynTable
= SynTable
;
145 llassert (oldSynTable
!= NULL
);
146 oldSize
= SynTableEntries
;
150 llcontbuglit ("SynTable_grow: goal size is smaller than oldSize");
154 if (size
< (oldSize
+ SYNTABLE_BASESIZE
))
156 size
= oldSize
+ SYNTABLE_BASESIZE
;
159 SynTable
= (lsymbolTable
) dmalloc (size
* sizeof (*SynTable
));
160 SynTableEntries
= size
;
162 for (i
= 0; i
< oldSize
; i
++)
164 SynTable
[i
] = oldSynTable
[i
];
167 /* Zero out new allocated space. Need to detect when cells are empty */
168 /* and do this by checking that SynTable[x] == 0. */
171 for (i
= oldSize
; i
< size
; i
++)
173 SynTable
[i
] = (lsymbol
) 0;
178 /*@-compdef@*/ } /*=compdef@*/
181 lsynTableInit (void) /*@globals undef SynTable; @*/
185 SynTable
= (lsymbolTable
) dmalloc (sizeof (*SynTable
) * SYNTABLE_BASESIZE
);
188 for (i
= 0; i
< SYNTABLE_BASESIZE
; i
++)
190 SynTable
[i
] = (lsymbol
) 0;
194 SynTableEntries
= SYNTABLE_BASESIZE
;
195 /*@-compdef@*/ } /*@=compdef@*/
198 lsynTableReset (void)
203 lsynTableCleanup (void)