]> andersk Git - splint.git/blame - src/scan.c
Updating to use the LEnsures and LRequires instead of the ensures requires so
[splint.git] / src / scan.c
CommitLineData
616915dd 1/*
2** LCLint - annotation-assisted static program checker
3** Copyright (C) 1994-2000 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.
19**
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
23*/
24/*
25** scan.c
26**
27** Deliver tokens one at a time
28**
29** METHOD:
30** The input arrives via LSLScanFreshToken ().
31** The output is reported via LSLScanNextToken ().
32**
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.
36**
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).
43*/
44
45# include "lclintMacros.nf"
46# include "llbasic.h"
47# include "signature.h"
48# include "signature2.h"
49# include "scan.h"
50# include "scanline.h"
51
52extern /*@external@*/ /*@unused@*/ YYSTYPE lsllval;
53
54static /*@exposed@*/ ltoken LSLScanLookAhead (void);
55static tsource *scanFile; /* file to scan */
56static o_ltoken TokenList[MAXLINE]; /* available tokens */
57static int nextToken; /* next available token */
58static int lastToken; /* next available slot */
59
60static /*@dependent@*/ /*@null@*/ char *line; /* input text */
61static unsigned int lineNumber; /* current line number */
62
63unsigned int lsllex (YYSTYPE *lval)
64{
65 /* This is important! Bison expects this */
66 lval->ltok = LSLScanNextToken ();
67 return (ltoken_getCode (lval->ltok));
68}
69
70ltoken LSLScanNextToken (void)
71{
72
73 if (nextToken < lastToken)
74 {
75 /*@-retalias@*/
76 return TokenList[nextToken++];
77 /*@=retalias@*/
78 }
79 else
80 {
81 lastToken = 0;
82 lineNumber++;
83
84 line = tsource_nextLine (scanFile);
85
86 if (line != (char *) 0)
87 {
88 lscanLine (line); /* tokenize */
89 nextToken = 0;
90 return LSLScanNextToken ();
91 }
92 else
93 {
94 return LSLScanEofToken ();
95 }
96 }
97}
98
99static /*@exposed@*/ ltoken
100LSLScanLookAhead (void)
101{
102 if (nextToken < lastToken)
103 {
104 return TokenList[nextToken];
105 }
106 else
107 {
108 lastToken = 0;
109 line = tsource_nextLine (scanFile);
110
111 if (line != (char *) 0)
112 {
113 lscanLine (line);
114 nextToken = 0;
115 return LSLScanLookAhead ();
116 }
117 else
118 {
119 /*
120 ** This is a real memory leak. Its only a few bytes
121 ** per file though, and lsl files are hardly ever used.
122 */
123
124 /*@-onlytrans@*/
125 return LSLScanEofToken ();
126 /*@=onlytrans@*/
127 }
128 }
129}
130
131void
132LSLScanFreshToken (ltoken tok)
133{
134 if (lastToken < MAXLINE)
135 {
136 TokenList[lastToken++] = ltoken_copy (tok);
137 }
138 else
139 {
140 llfatalbug (message ("LSLScanFreshToken: out of range: %s",
141 cstring_fromChars (lsymbol_toChars (ltoken_getText (tok)))));
142 }
143}
144
145/*@exposed@*/ tsource *LSLScanSource (void)
146{
147 return scanFile;
148}
149
150
151void
152LSLScanInit (void)
153{
154}
155
156void
157LSLScanReset (tsource *s)
158{
159 scanFile = s;
160 lastToken = 0;
161 nextToken = lastToken + 1; /* force call to scanline */
162 lineNumber = 0;
163}
164
165void
166LSLScanCleanup (void)
167{
168}
This page took 0.066513 seconds and 5 git commands to generate.