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 ** Deliver tokens one at a time
30 ** The input arrives via LSLScanFreshToken ().
31 ** The output is reported via LSLScanNextToken ().
33 ** The tokens are built in module ScanLine.
34 ** The tokens are delivered from this module.
35 ** Meantimes, they are saved in a static array.
37 ** The tokenizing is split off from the delivery of tokens
38 ** to facilitate incremental scanning at a later date.
39 ** The essential is that scanline () can be called or not
40 ** if the input text is dirty or not. Clean lines cause
41 ** tokens to be played out from the saved token list (not
42 ** yet implemented in this version).
45 # include "splintMacros.nf"
48 /*@-redecl@*/ /* from llgrammar.y */
49 extern bool g_inTypeDef;
53 # include "llgrammar2.h" /* hack to force real include */
57 # include "scanline.h"
58 # include "lclscanline.h"
59 # include "lcltokentable.h"
61 static inputStream scanFile; /* file to scan */
62 static o_ltoken TokenList[MAXLINE]; /* available tokens */
63 static bool restore = FALSE; /* wasn't static! */
64 static YYSTYPE restoretok;
65 static int nextToken; /* next available token */
66 static int lastToken; /* next available slot */
68 static /*@dependent@*/ /*@null@*/ char *line; /* input text */
69 static unsigned int lineNumber; /* current line number */
71 ltokenCode yllex (void)
72 /*@globals killed restoretok@*/ /* only if restore is TRUE */
83 /*@-onlyunqglobaltrans@*/
84 yllval.ltok = ltoken_copy (LCLScanNextToken ());
85 /*@=onlyunqglobaltrans@*/
88 tokenSym = ltoken_getText (yllval.ltok);
90 if (ltoken_getCode (yllval.ltok) == simpleId)
94 ltoken_setCode (yllval.ltok, LLT_TYPEDEF_NAME);
95 LCLUpdateToken (LLT_TYPEDEF_NAME, tokenSym,
96 ltoken_isStateDefined (yllval.ltok));
100 /* or if it is already declared as a type, so
101 typedef int foo; typedef foo bar; works*/
102 if (symtable_exists (g_symtab, tokenSym))
104 if (typeInfo_exists (symtable_typeInfo (g_symtab, tokenSym)))
106 ltoken_setCode (yllval.ltok, LLT_TYPEDEF_NAME);
107 LCLUpdateToken (LLT_TYPEDEF_NAME, tokenSym,
108 ltoken_isStateDefined (yllval.ltok));
114 /*@-onlyunqglobaltrans@*/ /* restoretok not released on non-restore path */
116 return (ltoken_getCode (yllval.ltok));
117 /*@=onlyunqglobaltrans@*/
121 /* useful for scanning LCL init files and LSL init files ? */
123 /*@dependent@*/ ltoken
124 LCLScanNextToken (void)
128 if (nextToken < lastToken)
130 ret = TokenList[nextToken++];
136 line = inputStream_nextLine (scanFile);
138 if (line != (char *) 0)
143 ret = LCLScanNextToken ();
148 ret = LCLScanEofToken ();
156 static /*@exposed@*/ /*@dependent@*/ ltoken
157 LCLScanLookAhead (void)
159 if (nextToken < lastToken)
161 return TokenList[nextToken];
166 line = inputStream_nextLine (scanFile);
167 if (line != (char *) 0)
171 return LCLScanLookAhead ();
175 return LCLScanEofToken ();
181 LCLScanFreshToken (/*@only@*/ ltoken tok)
183 if (lastToken < MAXLINE)
185 TokenList[lastToken++] = tok;
189 llbugexitlit ("LCLScanFreshToken: out of range");
193 inputStream LCLScanSource (void)
205 LCLScanReset (inputStream s)
209 nextToken = lastToken + 1;
214 LCLScanCleanup (void)