Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

scan.c

Go to the documentation of this file.
00001 /*
00002 ** LCLint - annotation-assisted static program checker
00003 ** Copyright (C) 1994-2000 University of Virginia,
00004 **         Massachusetts Institute of Technology
00005 **
00006 ** This program is free software; you can redistribute it and/or modify it
00007 ** under the terms of the GNU General Public License as published by the
00008 ** Free Software Foundation; either version 2 of the License, or (at your
00009 ** option) any later version.
00010 ** 
00011 ** This program is distributed in the hope that it will be useful, but
00012 ** WITHOUT ANY WARRANTY; without even the implied warranty of
00013 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 ** General Public License for more details.
00015 ** 
00016 ** The GNU General Public License is available from http://www.gnu.org/ or
00017 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00018 ** MA 02111-1307, USA.
00019 **
00020 ** For information on lclint: lclint-request@cs.virginia.edu
00021 ** To report a bug: lclint-bug@cs.virginia.edu
00022 ** For more information: http://lclint.cs.virginia.edu
00023 */
00024 /*
00025 ** scan.c
00026 **
00027 ** Deliver tokens one at a time
00028 **
00029 **      METHOD:
00030 **      The input arrives via LSLScanFreshToken ().
00031 **      The output is reported via LSLScanNextToken ().
00032 **
00033 **      The tokens are built in module ScanLine.
00034 **      The tokens are delivered from this module.
00035 **      Meantimes, they are saved in a static array.
00036 **
00037 **      The tokenizing is split off from the delivery of tokens
00038 **      to facilitate incremental scanning at a later date.
00039 **      The essential is that scanline () can be called or not
00040 **      if the input text is dirty or not.  Clean lines cause
00041 **      tokens to be played out from the saved token list (not
00042 **      yet implemented in this version).
00043 */
00044 
00045 # include "lclintMacros.nf"
00046 # include "llbasic.h"
00047 # include "signature.h"
00048 # include "signature2.h"
00049 # include "scan.h"
00050 # include "scanline.h"
00051 
00052 extern /*@external@*/ /*@unused@*/ YYSTYPE lsllval;
00053 
00054 static /*@exposed@*/ ltoken LSLScanLookAhead (void);
00055 static tsource *scanFile;         /* file to scan */
00056 static o_ltoken TokenList[MAXLINE]; /* available tokens */
00057 static int nextToken;             /* next available token */
00058 static int lastToken;             /* next available slot */
00059 
00060 static /*@dependent@*/ /*@null@*/ char *line;   /* input text */
00061 static unsigned int lineNumber; /* current line number */
00062 
00063 unsigned int lsllex (YYSTYPE *lval)
00064 {
00065   /* This is important!  Bison expects this */
00066   lval->ltok = LSLScanNextToken ();
00067   return (ltoken_getCode (lval->ltok));
00068 }
00069 
00070 ltoken LSLScanNextToken (void)
00071 {
00072   
00073   if (nextToken < lastToken)
00074     {   
00075       /*@-retalias@*/
00076             return TokenList[nextToken++];
00077       /*@=retalias@*/
00078     }
00079   else
00080     {
00081       lastToken = 0;            
00082       lineNumber++;
00083 
00084       line = tsource_nextLine (scanFile);       
00085       
00086       if (line != (char *) 0)
00087         {
00088                   lscanLine (line);     /* tokenize */
00089           nextToken = 0;
00090           return LSLScanNextToken ();   
00091         }
00092       else
00093         {
00094                   return LSLScanEofToken ();
00095         }
00096     }
00097 }
00098 
00099 static /*@exposed@*/ ltoken
00100 LSLScanLookAhead (void)
00101 {
00102   if (nextToken < lastToken)
00103     {           
00104       return TokenList[nextToken];
00105     }
00106   else
00107     {
00108       lastToken = 0;            
00109       line = tsource_nextLine (scanFile);
00110 
00111       if (line != (char *) 0)
00112         {
00113           lscanLine (line);     
00114           nextToken = 0;        
00115           return LSLScanLookAhead ();   
00116         }
00117       else
00118         {
00119           /* 
00120           ** This is a real memory leak.  Its only a few bytes
00121           ** per file though, and lsl files are hardly ever used.
00122           */
00123 
00124           /*@-onlytrans@*/ 
00125           return LSLScanEofToken ();
00126           /*@=onlytrans@*/
00127         }
00128     }
00129 }
00130 
00131 void
00132 LSLScanFreshToken (ltoken tok)
00133 {
00134   if (lastToken < MAXLINE)
00135     {                           
00136       TokenList[lastToken++] = ltoken_copy (tok);       
00137     }
00138   else
00139     {
00140       llfatalbug (message ("LSLScanFreshToken: out of range: %s", 
00141                            cstring_fromChars (lsymbol_toChars (ltoken_getText (tok)))));
00142     }
00143 }
00144 
00145 /*@exposed@*/ tsource *LSLScanSource (void)
00146 {
00147   return scanFile;
00148 }
00149 
00150 
00151 void
00152 LSLScanInit (void)
00153 {
00154 }
00155 
00156 void
00157 LSLScanReset (tsource *s)
00158 {
00159   scanFile = s;
00160   lastToken = 0;
00161   nextToken = lastToken + 1;    /* force call to scanline   */
00162   lineNumber = 0;
00163 }
00164 
00165 void
00166 LSLScanCleanup (void)
00167 {
00168 }

Generated at Fri Nov 3 18:57:43 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000