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
28 # include "splintMacros.nf"
31 # include "lsltokentable.h"
33 static long unsigned MaxToken
;
34 static /*@null@*/ /*@only@*/ o_ltoken
*TokenTable
;
36 static void AllocTokenTable (void) /*@modifies TokenTable, MaxToken@*/ ;
39 LSLInsertToken (ltokenCode cod
, lsymbol sym
, lsymbol rTxt
, bool def
)
41 while (sym
>= MaxToken
)
46 llassert (TokenTable
!= NULL
);
48 if (ltoken_isUndefined (TokenTable
[sym
]))
50 TokenTable
[sym
] = ltoken_create (cod
, sym
);
51 ltoken_setRawText (TokenTable
[sym
], rTxt
);
52 ltoken_setDefined (TokenTable
[sym
], def
);
55 return TokenTable
[sym
];
59 LSLUpdateToken (ltokenCode cod
, lsymbol sym
, bool def
)
61 llassert (TokenTable
!= NULL
);
63 if (!ltoken_isUndefined (TokenTable
[sym
]))
65 ltoken_setCode (TokenTable
[sym
], cod
);
66 ltoken_setDefined (TokenTable
[sym
], def
);
70 llfatalbug (message ("LSLUpdateToken: token not in table: %d, text: %s",
71 (int) cod
, cstring_fromChars (lsymbol_toChars (sym
))));
76 LSLSetTokenHasSyn (lsymbol sym
, bool syn
)
78 llassert (TokenTable
!= NULL
);
80 if (!ltoken_isUndefined (TokenTable
[sym
]))
82 ltoken_setHasSyn (TokenTable
[sym
], syn
);
86 llbuglit ("LSLSetTokenHasSyn: null token");
90 ltoken
LSLGetToken (lsymbol sym
)
92 llassert (TokenTable
!= NULL
);
94 if (!((sym
< MaxToken
) || (!ltoken_isUndefined (TokenTable
[sym
]))))
96 llcontbuglit ("LSLGetToken: bad argument");
100 return TokenTable
[sym
];
104 LSLReserveToken (ltokenCode cod
, const char *txt
)
108 sym
= lsymbol_fromChars (txt
);
111 ** Reserved tokens never have raw text like synonyms.
114 return LSLInsertToken (cod
, sym
, lsymbol_undefined
, TRUE
);
118 AllocTokenTable (void)
120 long unsigned oldSize
, newSize
;
127 newSize
= INITTOKENTABLE
;
128 llassert (TokenTable
== NULL
);
129 TokenTable
= (ltoken
*)
130 dmalloc (size_fromLongUnsigned (newSize
* sizeof (*TokenTable
)));
134 o_ltoken
*oldTokenTable
= TokenTable
;
136 newSize
= (long unsigned) (DELTATOKENTABLE
* oldSize
);
137 TokenTable
= (ltoken
*)
138 dmalloc (size_fromLongUnsigned (newSize
* sizeof (*TokenTable
)));
140 llassert (oldSize
> 0);
141 llassert (oldTokenTable
!= NULL
);
143 for (i
= 0; i
< oldSize
; i
++)
145 TokenTable
[i
] = oldTokenTable
[i
];
148 sfree (oldTokenTable
);
152 for (i
= oldSize
; i
< newSize
; i
++)
154 TokenTable
[i
] = ltoken_undefined
;
159 /*@-compdef@*/ } /*=compdef@*/
162 ltokenTableInit (void)
168 ltokenTableCleanup (void)
170 if (TokenTable
!= NULL
)
174 for (i
= 0; i
< MaxToken
; i
++)
176 ltoken_free (TokenTable
[i
]);