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

lclscan.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 ** lclscan.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 
00048 /*@-redecl@*/ /* from llgrammar.y */
00049 extern bool g_inTypeDef;
00050 /*@=redecl@*/
00051 
00052 /*@ignore@*/
00053 # include "llgrammar2.h" /* hack to force real include */
00054 /*@end@*/
00055 
00056 # include "lclscan.h"
00057 # include "scanline.h"
00058 # include "lclscanline.h"
00059 # include "lcltokentable.h"
00060 
00061 static tsource *scanFile;       /* file to scan         */
00062 static o_ltoken TokenList[MAXLINE];     /* available tokens     */
00063 static bool restore = FALSE;      /* wasn't static! */
00064 static YYSTYPE restoretok;
00065 static int nextToken;           /* next available token */
00066 static int lastToken;           /* next available slot  */
00067 
00068 static /*@dependent@*/ /*@null@*/ char *line;  /* input text */
00069 static unsigned int lineNumber;                /* current line number */
00070 
00071 ltokenCode yllex (void)
00072   /*@globals killed restoretok@*/ 
00073 {
00074   lsymbol tokenSym;
00075 
00076   if (restore)
00077     {
00078       yllval = restoretok;
00079       restore = FALSE;
00080     }
00081   else
00082     {
00083       yllval.ltok = ltoken_copy (LCLScanNextToken ());
00084     }
00085 
00086   tokenSym = ltoken_getText (yllval.ltok);
00087 
00088   if (ltoken_getCode (yllval.ltok) == simpleId)
00089     {
00090       if (g_inTypeDef)
00091         {
00092           ltoken_setCode (yllval.ltok, LLT_TYPEDEF_NAME);
00093           LCLUpdateToken (LLT_TYPEDEF_NAME, tokenSym, 
00094                           ltoken_isStateDefined (yllval.ltok));
00095         }
00096       else
00097         {
00098          /* or if it is already declared as a type, so
00099             typedef int foo; typedef foo bar;      works*/
00100           if (symtable_exists (g_symtab, tokenSym))
00101             {
00102               if (typeInfo_exists (symtable_typeInfo (g_symtab, tokenSym)))
00103                 {
00104                   ltoken_setCode (yllval.ltok, LLT_TYPEDEF_NAME);
00105                   LCLUpdateToken (LLT_TYPEDEF_NAME, tokenSym, 
00106                                   ltoken_isStateDefined (yllval.ltok));
00107                 }
00108             }
00109         }
00110     }
00111 
00112   return (ltoken_getCode (yllval.ltok));
00113 }
00114 
00115 /* useful for scanning LCL init files and LSL init files ? */
00116 
00117 /*@dependent@*/ ltoken
00118 LCLScanNextToken (void)
00119 {
00120   ltoken ret;
00121 
00122   if (nextToken < lastToken)
00123     {                   
00124       ret = TokenList[nextToken++];
00125     }
00126   else
00127     {
00128       lastToken = 0;
00129       lineNumber++;
00130       line = tsource_nextLine (scanFile);       
00131 
00132       if (line != (char *) 0)
00133         {
00134           
00135           LCLScanLine (line);   
00136           nextToken = 0;
00137           ret = LCLScanNextToken ();    
00138           return ret;
00139         }
00140       else
00141         {
00142           ret = LCLScanEofToken ();
00143         }
00144     }
00145 
00146 
00147     return ret;
00148 }
00149 
00150 static /*@exposed@*/ /*@dependent@*/ ltoken
00151 LCLScanLookAhead (void)
00152 {
00153   if (nextToken < lastToken)
00154     {                   
00155       return TokenList[nextToken];
00156     }
00157   else
00158     {
00159       lastToken = 0;    
00160       line = tsource_nextLine (scanFile);
00161       if (line != (char *) 0)
00162         {
00163           LCLScanLine (line);   
00164           nextToken = 0;        
00165           return LCLScanLookAhead ();
00166         }
00167       else
00168         {
00169           return LCLScanEofToken ();    
00170         }
00171     }
00172 }
00173 
00174 void
00175 LCLScanFreshToken (/*@only@*/ ltoken tok)
00176 {
00177   if (lastToken < MAXLINE)
00178     {           
00179       TokenList[lastToken++] = tok;
00180     }
00181   else
00182     {
00183       llbugexitlit ("LCLScanFreshToken: out of range");
00184     }
00185 }
00186 
00187 tsource *LCLScanSource (void)
00188 {
00189   return scanFile;
00190 }
00191 
00192 
00193 void
00194 LCLScanInit (void)
00195 {
00196 }
00197 
00198 void
00199 LCLScanReset (tsource * s)
00200 {
00201   scanFile = s;
00202   lastToken = 0;
00203   nextToken = lastToken + 1;    
00204   lineNumber = 0;
00205 }
00206 
00207 void
00208 LCLScanCleanup (void)
00209 {
00210 }
00211 
00212 

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