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

lcltokentable.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 ** tokentable.c
00026 **
00027 ** Larch processors token table
00028 ** This table stores predefined tokens for LCL.
00029 */
00030 
00031 # include "lclintMacros.nf"
00032 # include "llbasic.h"
00033 # include "lcltokentable.h"
00034 
00035 static long unsigned MaxToken; 
00036 static /*@only@*/ /*@null@*/ o_ltoken *LCLTokenTable = NULL;    
00037 
00038 static void AllocTokenTable (void) 
00039    /*@globals LCLTokenTable@*/
00040    /*@modifies LCLTokenTable, MaxToken@*/;
00041 
00042 ltoken 
00043   LCLInsertToken (ltokenCode cod, lsymbol sym, lsymbol rTxt,
00044                   bool isPredefined)
00045 {
00046   /*
00047   ** If the token is already in the token table, it is returned.  Otherwise,
00048   ** the token is inserted into the table and then returned.
00049   **
00050   ** A new TokenTable is allocated when:
00051   **   . The TokenTable[] is empty (initial case)
00052   **   . The location where to insert the token is not in TokenTable[]
00053   */
00054 
00055   setCodePoint ();
00056 
00057   while (sym >= MaxToken)
00058     {
00059       setCodePoint ();
00060       /* No more space available.  Allocate more. */
00061       AllocTokenTable ();
00062     }
00063   
00064   llassert (LCLTokenTable != NULL);
00065 
00066   if (ltoken_isUndefined (LCLTokenTable[sym]))
00067     {
00068       LCLTokenTable[sym] = ltoken_create (cod, sym);      
00069       ltoken_setRawText (LCLTokenTable[sym], rTxt);
00070       ltoken_setDefined (LCLTokenTable[sym], isPredefined);
00071             return LCLTokenTable[sym];
00072     }
00073 
00074     return LCLTokenTable[sym];
00075 }
00076 
00077 void LCLUpdateToken (ltokenCode cod, lsymbol sym, bool def)
00078 {
00079   llassert (LCLTokenTable != NULL);
00080 
00081   if (!ltoken_isUndefined (LCLTokenTable[sym]))
00082     {
00083       ltoken_setCode (LCLTokenTable[sym], cod);
00084       ltoken_setDefined (LCLTokenTable[sym], def);
00085     }
00086   else
00087     {
00088       llfatalbug (message ("LCLUpdateToken: %s", 
00089                            cstring_fromChars (lsymbol_toChars (sym))));
00090     }
00091 }
00092 
00093 void LCLSetTokenHasSyn (lsymbol sym, bool syn)
00094 {
00095   llassert (LCLTokenTable != NULL);
00096 
00097   if (!ltoken_isUndefined (LCLTokenTable[sym]))
00098     {
00099       ltoken_setHasSyn (LCLTokenTable[sym], syn);
00100     }
00101   else
00102     {
00103       llfatalbug (message ("LCLSetTokenHasSyn: null token (%d)", (int)sym));
00104     }
00105 }
00106 
00107 ltoken LCLGetToken (lsymbol sym)
00108 {
00109   llassert (LCLTokenTable != NULL);
00110   llassert (sym < MaxToken);
00111 
00112   return LCLTokenTable[sym];
00113 }
00114 
00115 #if 0
00116 bool LCLTokenTableContainsToken (ltoken tok)
00117 {
00118   unsigned long i;
00119 
00120   if (LCLTokenTable != NULL) {
00121     for (i = 0; i < MaxToken; i++) {
00122       if (LCLTokenTable[i] == tok) {
00123         return TRUE;
00124       }
00125     }
00126   }
00127 
00128   return FALSE;
00129 }
00130 # endif
00131 
00132 /*@exposed@*/ ltoken
00133 LCLReserveToken (ltokenCode cod, char *txt)
00134 {
00135   /*
00136   ** The same context that was active when the string-handle
00137   ** was derived by a previous call to lsymbol_fromChars (),
00138   ** must be established.
00139   */
00140   lsymbol sym;
00141 
00142   setCodePoint ();
00143   sym = lsymbol_fromChars (txt);
00144   
00145   /* 
00146   ** Reserved tokens never have raw text like synonyms.
00147   */
00148 
00149     return (LCLInsertToken (cod, sym, lsymbol_undefined, TRUE));
00150 }
00151 
00152 static void
00153   AllocTokenTable (void) /*@globals LCLTokenTable; @*/ 
00154 {
00155   long unsigned oldSize, newSize;
00156   long unsigned int i;
00157   
00158   oldSize = MaxToken;
00159 
00160   if (oldSize == 0)
00161     {
00162       newSize = INITTOKENTABLE;
00163       llassert (LCLTokenTable == NULL);
00164       LCLTokenTable = (ltoken *) dmalloc (newSize * sizeof (*LCLTokenTable));
00165     }
00166   else
00167     {
00168       o_ltoken *oldLCLTokenTable = LCLTokenTable;
00169 
00170       llassert (oldLCLTokenTable != NULL);
00171 
00172       newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
00173       LCLTokenTable = (ltoken *) dmalloc (newSize * sizeof (*LCLTokenTable));
00174 
00175       for (i = 0; i < oldSize; i++)
00176         {
00177           LCLTokenTable[i] = oldLCLTokenTable[i];
00178         }
00179       
00180       sfree (oldLCLTokenTable);
00181     }
00182 
00183   MaxToken = newSize;
00184   
00185   /*@+loopexec@*/
00186   for (i = oldSize; i < newSize; i++)
00187     {
00188       LCLTokenTable[i] = ltoken_undefined;
00189     }
00190   /*@=loopexec@*/
00191 /*@-compdef@*/ } /*=compdef@*/
00192 
00193 void
00194 LCLTokenTableInit (void)
00195 {
00196     MaxToken = 0;
00197 }
00198 
00199 void
00200 LCLTokenTableCleanup (void)
00201 {
00202     
00203   if (LCLTokenTable != NULL)
00204     {
00205       long unsigned i;
00206       
00207       for (i = 0; i < MaxToken; i++)
00208         {
00209           ltoken tok = LCLTokenTable[i];
00210           
00211           LCLTokenTable[i] = NULL;
00212           /*@-dependenttrans@*/ ltoken_free (tok);
00213           /*@=dependenttrans@*/
00214         }
00215       
00216       sfree (LCLTokenTable); 
00217       LCLTokenTable = NULL;
00218     }
00219 
00220   }
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 

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