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 processors token table
28 ** This table stores predefined tokens for LCL.
31 # include "splintMacros.nf"
33 # include "lcltokentable.h"
35 static long unsigned MaxToken
;
36 static /*@only@*/ /*@null@*/ o_ltoken
*LCLTokenTable
= NULL
;
38 static void AllocTokenTable (void)
39 /*@globals LCLTokenTable@*/
40 /*@modifies LCLTokenTable, MaxToken@*/;
43 LCLInsertToken (ltokenCode cod
, lsymbol sym
, lsymbol rTxt
,
47 ** If the token is already in the token table, it is returned. Otherwise,
48 ** the token is inserted into the table and then returned.
50 ** A new TokenTable is allocated when:
51 ** . The TokenTable[] is empty (initial case)
52 ** . The location where to insert the token is not in TokenTable[]
57 while (sym
>= MaxToken
)
60 /* No more space available. Allocate more. */
64 llassert (LCLTokenTable
!= NULL
);
66 if (ltoken_isUndefined (LCLTokenTable
[sym
]))
68 LCLTokenTable
[sym
] = ltoken_create (cod
, sym
);
69 ltoken_setRawText (LCLTokenTable
[sym
], rTxt
);
70 ltoken_setDefined (LCLTokenTable
[sym
], isPredefined
);
71 return LCLTokenTable
[sym
];
74 return LCLTokenTable
[sym
];
77 void LCLUpdateToken (ltokenCode cod
, lsymbol sym
, bool def
)
79 llassert (LCLTokenTable
!= NULL
);
81 if (!ltoken_isUndefined (LCLTokenTable
[sym
]))
83 ltoken_setCode (LCLTokenTable
[sym
], cod
);
84 ltoken_setDefined (LCLTokenTable
[sym
], def
);
88 llfatalbug (message ("LCLUpdateToken: %s",
89 cstring_fromChars (lsymbol_toChars (sym
))));
93 void LCLSetTokenHasSyn (lsymbol sym
, bool syn
)
95 llassert (LCLTokenTable
!= NULL
);
97 if (!ltoken_isUndefined (LCLTokenTable
[sym
]))
99 ltoken_setHasSyn (LCLTokenTable
[sym
], syn
);
103 llfatalbug (message ("LCLSetTokenHasSyn: null token (%d)", (int)sym
));
107 ltoken
LCLGetToken (lsymbol sym
)
109 llassert (LCLTokenTable
!= NULL
);
110 llassert (sym
< MaxToken
);
112 return LCLTokenTable
[sym
];
116 bool LCLTokenTableContainsToken (ltoken tok
)
120 if (LCLTokenTable
!= NULL
) {
121 for (i
= 0; i
< MaxToken
; i
++) {
122 if (LCLTokenTable
[i
] == tok
) {
133 LCLReserveToken (ltokenCode cod
, const char *txt
)
136 ** The same context that was active when the string-handle
137 ** was derived by a previous call to lsymbol_fromChars (),
138 ** must be established.
143 sym
= lsymbol_fromChars (txt
);
146 ** Reserved tokens never have raw text like synonyms.
149 return (LCLInsertToken (cod
, sym
, lsymbol_undefined
, TRUE
));
153 AllocTokenTable (void) /*@globals LCLTokenTable; @*/
155 long unsigned oldSize
, newSize
;
162 newSize
= INITTOKENTABLE
;
163 llassert (LCLTokenTable
== NULL
);
164 LCLTokenTable
= (ltoken
*) dmalloc
165 (size_fromLongUnsigned (newSize
* sizeof (*LCLTokenTable
)));
169 o_ltoken
*oldLCLTokenTable
= LCLTokenTable
;
171 llassert (oldLCLTokenTable
!= NULL
);
173 newSize
= (long unsigned) (DELTATOKENTABLE
* oldSize
);
174 LCLTokenTable
= (ltoken
*) dmalloc
175 (size_fromLongUnsigned (newSize
* sizeof (*LCLTokenTable
)));
177 for (i
= 0; i
< oldSize
; i
++)
179 LCLTokenTable
[i
] = oldLCLTokenTable
[i
];
182 sfree (oldLCLTokenTable
);
188 for (i
= oldSize
; i
< newSize
; i
++)
190 LCLTokenTable
[i
] = ltoken_undefined
;
193 /*@-compdef@*/ } /*=compdef@*/
196 LCLTokenTableInit (void)
202 LCLTokenTableCleanup (void)
205 if (LCLTokenTable
!= NULL
)
209 for (i
= 0; i
< MaxToken
; i
++)
211 ltoken tok
= LCLTokenTable
[i
];
213 LCLTokenTable
[i
] = NULL
;
214 /*@-dependenttrans@*/ ltoken_free (tok
);
215 /*@=dependenttrans@*/
218 sfree (LCLTokenTable
);
219 LCLTokenTable
= NULL
;