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

tokentable.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 
00028 # include "lclintMacros.nf"
00029 # include "llbasic.h"
00030 # include "osd.h"
00031 # include "tokentable.h"
00032 
00033 static long unsigned MaxToken;  
00034 static /*@null@*/ /*@only@*/ o_ltoken *TokenTable;       
00035 
00036 static void AllocTokenTable (void) /*@modifies TokenTable, MaxToken@*/ ;
00037 
00038 ltoken
00039   LSLInsertToken (ltokenCode cod, lsymbol sym, lsymbol rTxt, bool def)
00040 {
00041   while (sym >= MaxToken)
00042     {
00043       AllocTokenTable ();
00044     }
00045 
00046   llassert (TokenTable != NULL);
00047 
00048   if (ltoken_isUndefined (TokenTable[sym]))
00049     {
00050       TokenTable[sym] = ltoken_create (cod, sym);        
00051       ltoken_setRawText (TokenTable[sym], rTxt);
00052       ltoken_setDefined (TokenTable[sym], def);
00053     }
00054   
00055   return TokenTable[sym];
00056 }
00057 
00058 void
00059 LSLUpdateToken (ltokenCode cod, lsymbol sym, bool def)
00060 {
00061   llassert (TokenTable != NULL);
00062 
00063   if (!ltoken_isUndefined (TokenTable[sym]))
00064     {
00065       ltoken_setCode (TokenTable[sym], cod);
00066       ltoken_setDefined (TokenTable[sym], def);
00067     }
00068   else
00069     {
00070       llfatalbug (message ("LSLUpdateToken: token not in table: %d, text: %s", 
00071                            (int) cod, cstring_fromChars (lsymbol_toChars (sym))));
00072     }
00073 }
00074 
00075 void
00076 LSLSetTokenHasSyn (lsymbol sym, bool syn)
00077 {
00078   llassert (TokenTable != NULL);
00079     
00080   if (!ltoken_isUndefined (TokenTable[sym]))
00081     {
00082       ltoken_setHasSyn (TokenTable[sym], syn);
00083     }
00084   else
00085     {
00086       llbuglit ("LSLSetTokenHasSyn: null token");
00087     }
00088 }
00089 
00090 ltoken LSLGetToken (lsymbol sym)
00091 {
00092   llassert (TokenTable != NULL);
00093 
00094   if (!((sym < MaxToken) || (!ltoken_isUndefined (TokenTable[sym]))))
00095     {
00096       llcontbuglit ("LSLGetToken: bad argument");
00097       return TokenTable[0];
00098     }
00099 
00100   return TokenTable[sym];
00101 }
00102 
00103 /*@exposed@*/ ltoken
00104 LSLReserveToken (ltokenCode cod, char *txt)
00105 {
00106   lsymbol sym;
00107   
00108   sym = lsymbol_fromChars (txt);
00109 
00110   /* 
00111   ** Reserved tokens never have raw text like synonyms.
00112   */
00113 
00114   return LSLInsertToken (cod, sym, lsymbol_undefined, TRUE);
00115 }
00116 
00117 static void
00118 AllocTokenTable (void)
00119 {
00120   long unsigned oldSize, newSize;
00121   long unsigned int i;
00122 
00123   oldSize = MaxToken;
00124 
00125   if (oldSize == 0)
00126     {
00127       newSize = INITTOKENTABLE;
00128       llassert (TokenTable == NULL);
00129       TokenTable = (ltoken *) dmalloc (newSize * sizeof (*TokenTable)); 
00130     }
00131   else
00132     {
00133       o_ltoken *oldTokenTable = TokenTable;
00134 
00135       newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
00136       TokenTable = (ltoken *) dmalloc (newSize * sizeof (*TokenTable));
00137 
00138       llassert (oldSize > 0);
00139       llassert (oldTokenTable != NULL);
00140       
00141       for (i = 0; i < oldSize; i++)
00142         {
00143           TokenTable[i] = oldTokenTable[i];
00144         }
00145 
00146       sfree (oldTokenTable);
00147     }
00148 
00149   /*@+loopexec@*/
00150   for (i = oldSize; i < newSize; i++)
00151     {
00152       TokenTable[i] = ltoken_undefined;
00153     }
00154   /*@=loopexec@*/
00155 
00156   MaxToken = newSize;
00157 /*@-compdef@*/ } /*=compdef@*/
00158 
00159 void
00160 ltokenTableInit (void)
00161 {
00162   MaxToken = 0;
00163 }
00164 
00165 void
00166 ltokenTableCleanup (void)
00167 {
00168   if (TokenTable != NULL)
00169     {
00170       long unsigned i;
00171       
00172       for (i = 0; i < MaxToken; i++)
00173         {
00174           ltoken_free (TokenTable[i]);
00175         }
00176 
00177       sfree (TokenTable); 
00178       TokenTable = NULL;
00179     }
00180 }

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