]> andersk Git - splint.git/blame - src/lclscan.c
*** empty log message ***
[splint.git] / src / lclscan.c
CommitLineData
616915dd 1/*
11db3170 2** Splint - annotation-assisted static program checker
c59f5181 3** Copyright (C) 1994-2003 University of Virginia,
616915dd 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**
155af98d 20** For information on splint: info@splint.org
21** To report a bug: splint-bug@splint.org
11db3170 22** For more information: http://www.splint.org
616915dd 23*/
24/*
25** lclscan.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
1b8ae690 45# include "splintMacros.nf"
b73d1009 46# include "basic.h"
616915dd 47
48/*@-redecl@*/ /* from llgrammar.y */
49extern bool g_inTypeDef;
50/*@=redecl@*/
51
52/*@ignore@*/
53# include "llgrammar2.h" /* hack to force real include */
54/*@end@*/
55
56# include "lclscan.h"
57# include "scanline.h"
58# include "lclscanline.h"
59# include "lcltokentable.h"
60
28bf4b0b 61static inputStream scanFile; /* file to scan */
616915dd 62static o_ltoken TokenList[MAXLINE]; /* available tokens */
63static bool restore = FALSE; /* wasn't static! */
64static YYSTYPE restoretok;
65static int nextToken; /* next available token */
66static int lastToken; /* next available slot */
67
68static /*@dependent@*/ /*@null@*/ char *line; /* input text */
69static unsigned int lineNumber; /* current line number */
70
71ltokenCode yllex (void)
a9ec3280 72 /*@globals killed restoretok@*/ /* only if restore is TRUE */
616915dd 73{
74 lsymbol tokenSym;
75
76 if (restore)
77 {
78 yllval = restoretok;
79 restore = FALSE;
80 }
81 else
82 {
a9ec3280 83 /*@-onlyunqglobaltrans@*/
616915dd 84 yllval.ltok = ltoken_copy (LCLScanNextToken ());
a9ec3280 85 /*@=onlyunqglobaltrans@*/
616915dd 86 }
87
88 tokenSym = ltoken_getText (yllval.ltok);
89
90 if (ltoken_getCode (yllval.ltok) == simpleId)
91 {
92 if (g_inTypeDef)
93 {
94 ltoken_setCode (yllval.ltok, LLT_TYPEDEF_NAME);
95 LCLUpdateToken (LLT_TYPEDEF_NAME, tokenSym,
96 ltoken_isStateDefined (yllval.ltok));
97 }
98 else
99 {
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))
103 {
104 if (typeInfo_exists (symtable_typeInfo (g_symtab, tokenSym)))
105 {
106 ltoken_setCode (yllval.ltok, LLT_TYPEDEF_NAME);
107 LCLUpdateToken (LLT_TYPEDEF_NAME, tokenSym,
108 ltoken_isStateDefined (yllval.ltok));
109 }
110 }
111 }
112 }
113
a9ec3280 114 /*@-onlyunqglobaltrans@*/ /* restoretok not released on non-restore path */
115 /*@-globstate@*/
616915dd 116 return (ltoken_getCode (yllval.ltok));
a9ec3280 117 /*@=onlyunqglobaltrans@*/
118 /*@=globstate@*/
616915dd 119}
120
121/* useful for scanning LCL init files and LSL init files ? */
122
123/*@dependent@*/ ltoken
124LCLScanNextToken (void)
125{
126 ltoken ret;
127
128 if (nextToken < lastToken)
129 {
130 ret = TokenList[nextToken++];
131 }
132 else
133 {
134 lastToken = 0;
135 lineNumber++;
28bf4b0b 136 line = inputStream_nextLine (scanFile);
616915dd 137
138 if (line != (char *) 0)
139 {
140
141 LCLScanLine (line);
142 nextToken = 0;
143 ret = LCLScanNextToken ();
144 return ret;
145 }
146 else
147 {
148 ret = LCLScanEofToken ();
149 }
150 }
151
152
153 return ret;
154}
155
156static /*@exposed@*/ /*@dependent@*/ ltoken
157LCLScanLookAhead (void)
158{
159 if (nextToken < lastToken)
160 {
161 return TokenList[nextToken];
162 }
163 else
164 {
165 lastToken = 0;
28bf4b0b 166 line = inputStream_nextLine (scanFile);
616915dd 167 if (line != (char *) 0)
168 {
169 LCLScanLine (line);
170 nextToken = 0;
171 return LCLScanLookAhead ();
172 }
173 else
174 {
175 return LCLScanEofToken ();
176 }
177 }
178}
179
180void
181LCLScanFreshToken (/*@only@*/ ltoken tok)
182{
183 if (lastToken < MAXLINE)
184 {
185 TokenList[lastToken++] = tok;
186 }
187 else
188 {
189 llbugexitlit ("LCLScanFreshToken: out of range");
190 }
191}
192
28bf4b0b 193inputStream LCLScanSource (void)
616915dd 194{
195 return scanFile;
196}
197
198
199void
200LCLScanInit (void)
201{
202}
203
204void
28bf4b0b 205LCLScanReset (inputStream s)
616915dd 206{
207 scanFile = s;
208 lastToken = 0;
209 nextToken = lastToken + 1;
210 lineNumber = 0;
211}
212
213void
214LCLScanCleanup (void)
215{
216}
217
218
This page took 0.117659 seconds and 5 git commands to generate.