2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
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 "lclintMacros.nf"
47 # include "signature.h"
48 # include "signature2.h"
50 # include "scanline.h"
52 extern /*@external@*/ /*@unused@*/ YYSTYPE lsllval;
54 static /*@exposed@*/ ltoken LSLScanLookAhead (void);
55 static tsource *scanFile; /* file to scan */
56 static o_ltoken TokenList[MAXLINE]; /* available tokens */
57 static int nextToken; /* next available token */
58 static int lastToken; /* next available slot */
60 static /*@dependent@*/ /*@null@*/ char *line; /* input text */
61 static unsigned int lineNumber; /* current line number */
63 unsigned int lsllex (YYSTYPE *lval)
65 /* This is important! Bison expects this */
66 lval->ltok = LSLScanNextToken ();
67 return (ltoken_getCode (lval->ltok));
70 ltoken LSLScanNextToken (void)
73 if (nextToken < lastToken)
76 return TokenList[nextToken++];
84 line = tsource_nextLine (scanFile);
86 if (line != (char *) 0)
88 lscanLine (line); /* tokenize */
90 return LSLScanNextToken ();
94 return LSLScanEofToken ();
99 static /*@exposed@*/ ltoken
100 LSLScanLookAhead (void)
102 if (nextToken < lastToken)
104 return TokenList[nextToken];
109 line = tsource_nextLine (scanFile);
111 if (line != (char *) 0)
115 return LSLScanLookAhead ();
120 ** This is a real memory leak. Its only a few bytes
121 ** per file though, and lsl files are hardly ever used.
125 return LSLScanEofToken ();
132 LSLScanFreshToken (ltoken tok)
134 if (lastToken < MAXLINE)
136 TokenList[lastToken++] = ltoken_copy (tok);
140 llfatalbug (message ("LSLScanFreshToken: out of range: %s",
141 cstring_fromChars (lsymbol_toChars (ltoken_getText (tok)))));
145 /*@exposed@*/ tsource *LSLScanSource (void)
157 LSLScanReset (tsource *s)
161 nextToken = lastToken + 1; /* force call to scanline */
166 LSLScanCleanup (void)