Don't try calling lsl when file is missing.
[splint-patched.git] / src / lclscan.c
blob52412dc2de6d79513aa4ac7a52d30f3ae5406387
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.
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
25 ** lclscan.c
27 ** Deliver tokens one at a time
29 ** METHOD:
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"
46 # include "basic.h"
48 # include "lslscanline.h"
50 # include "lclscan.h"
51 # include "lclscanline.h"
52 # include "lcltokentable.h"
54 # include "llgrammar.h"
55 /*@-redecl@*/ /* from llgrammar.y */
56 extern bool g_inTypeDef;
57 /*@=redecl@*/
60 static inputStream scanFile; /* file to scan */
61 static o_ltoken TokenList[MAXLINE]; /* available tokens */
62 static bool restore = FALSE; /* wasn't static! */
63 static YLSTYPE restoretok;
64 static int nextToken; /* next available token */
65 static int lastToken; /* next available slot */
67 static /*@dependent@*/ /*@null@*/ char *line; /* input text */
68 static unsigned int lineNumber; /* current line number */
70 ltokenCode yllex (void)
71 /*@globals killed restoretok@*/ /* only if restore is TRUE */
73 lsymbol tokenSym;
75 if (restore)
77 yllval = restoretok;
78 restore = FALSE;
80 else
82 /*@-onlyunqglobaltrans@*/
83 yllval.ltok = ltoken_copy (LCLScanNextToken ());
84 /*@=onlyunqglobaltrans@*/
87 tokenSym = ltoken_getText (yllval.ltok);
89 if (ltoken_getCode (yllval.ltok) == simpleId)
91 if (g_inTypeDef)
93 ltoken_setCode (yllval.ltok, LLT_TYPEDEF_NAME);
94 LCLUpdateToken (LLT_TYPEDEF_NAME, tokenSym,
95 ltoken_isStateDefined (yllval.ltok));
97 else
99 /* or if it is already declared as a type, so
100 typedef int foo; typedef foo bar; works*/
101 if (symtable_exists (g_symtab, tokenSym))
103 if (typeInfo_exists (symtable_typeInfo (g_symtab, tokenSym)))
105 ltoken_setCode (yllval.ltok, LLT_TYPEDEF_NAME);
106 LCLUpdateToken (LLT_TYPEDEF_NAME, tokenSym,
107 ltoken_isStateDefined (yllval.ltok));
113 /*@-onlyunqglobaltrans@*/ /* restoretok not released on non-restore path */
114 /*@-globstate@*/
115 return (ltoken_getCode (yllval.ltok));
116 /*@=onlyunqglobaltrans@*/
117 /*@=globstate@*/
120 /* useful for scanning LCL init files and LSL init files ? */
122 /*@dependent@*/ ltoken
123 LCLScanNextToken (void)
125 ltoken ret;
127 if (nextToken < lastToken)
129 ret = TokenList[nextToken++];
131 else
133 lastToken = 0;
134 lineNumber++;
135 line = inputStream_nextLine (scanFile);
137 if (line != (char *) 0)
140 LCLScanLine (line);
141 nextToken = 0;
142 ret = LCLScanNextToken ();
143 return ret;
145 else
147 ret = LCLScanEofToken ();
152 return ret;
155 #ifdef DEADCODE
156 static /*@exposed@*/ /*@dependent@*/ ltoken
157 LCLScanLookAhead (void)
159 if (nextToken < lastToken)
161 return TokenList[nextToken];
163 else
165 lastToken = 0;
166 line = inputStream_nextLine (scanFile);
167 if (line != (char *) 0)
169 LCLScanLine (line);
170 nextToken = 0;
171 return LCLScanLookAhead ();
173 else
175 return LCLScanEofToken ();
179 #endif
181 void
182 LCLScanFreshToken (/*@only@*/ ltoken tok)
184 if (lastToken < MAXLINE)
186 TokenList[lastToken++] = tok;
188 else
190 llbugexitlit ("LCLScanFreshToken: out of range");
194 inputStream LCLScanSource (void)
196 return scanFile;
200 void
201 LCLScanInit (void)
205 void
206 LCLScanReset (inputStream s)
208 scanFile = s;
209 lastToken = 0;
210 nextToken = lastToken + 1;
211 lineNumber = 0;
214 void
215 LCLScanCleanup (void)