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

lclsyntable.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 ** syntable.c
00026 **
00027 ** Larch/C Interface language synonym table
00028 **
00029 **      This table stores synonyms for the Larch/C Interface Language.  It is
00030 **      essentially an array of token-handles indexed by string-handles.
00031 **      Therefore, synonyms (strings) can be converted to the actual token.
00032 **
00033 **  AUTHORS:
00034 **      J.P. Wild
00035 **
00036 **
00037 **  CREATION DATE:  90.08.10
00038 */
00039 
00040 # include "lclintMacros.nf"
00041 # include "basic.h"
00042 # include "lcltokentable.h"
00043 # include "lclsyntable.h"
00044 
00045 static long unsigned MaxSyn;    /* size of SynTable[]              */
00046 static /*@only@*/ /*@reldef@*/ /*@null@*/ lsymbol *SynTable;
00047 static void
00048   AllocSynTable (void)
00049   /*@globals SynTable, MaxSyn@*/
00050   /*@modifies *SynTable, MaxSyn@*/;
00051 
00052 void
00053 LCLAddSyn (lsymbol ntok, lsymbol otok)
00054 {
00055   while (otok >= MaxSyn)
00056     {
00057       /* No more space available.  Allocate more. */
00058       AllocSynTable ();
00059     }
00060 
00061   llassert (SynTable != NULL);
00062 
00063   if (SynTable[ntok] == 0)
00064     {
00065      /* Entry is empty. Fill it in. */
00066       SynTable[ntok] = otok;
00067 
00068       /* Mark oldToken as having a synonym. */
00069       LCLSetTokenHasSyn (otok, TRUE);
00070     }
00071   else
00072     {
00073       llbuglit ("LCLAddSyn: invalid argument");
00074     }
00075 }
00076 
00077 /*@exposed@*/ ltoken
00078 LCLGetTokenForSyn (lsymbol ntok)
00079 {
00080   llassert (SynTable != NULL);
00081 
00082   if (!((ntok < MaxSyn) || (SynTable[ntok] != 0)))
00083     llbuglit ("LCLGetSyn: bad argument");
00084 
00085   return LCLGetToken (SynTable[ntok]);
00086 }
00087 
00088 bool
00089 LCLIsSyn (lsymbol str)
00090 {
00091   if (MaxSyn == 0)
00092     {
00093       return FALSE;
00094     }
00095   else
00096     {
00097       llassert (SynTable != NULL);
00098 
00099       if (str < MaxSyn)
00100         {
00101           /* Check for synonym entry in table. */
00102           return (SynTable[str] != 0);
00103         }
00104       else
00105         {
00106           /* No token for synonym.  Return FALSE. */
00107           return FALSE;
00108         }
00109     }
00110 }
00111   
00112 static void
00113 AllocSynTable (void) /*@globals SynTable; @*/
00114 {
00115   long unsigned newSize, oldSize;
00116   long unsigned int i;
00117 
00118   oldSize = MaxSyn;
00119 
00120   if (oldSize == 0)
00121     {
00122       /* First time SynTable allocated.  Set initial size. */
00123       newSize = INITSYNTABLE;
00124       SynTable = (lsymbol *) dmalloc (newSize * sizeof (*SynTable));
00125     }
00126   else
00127     {
00128       lsymbol *oldSynTable = SynTable; 
00129 
00130       llassert (oldSynTable != NULL);
00131 
00132       /* Synonym table already allocated.  Calulate extension size. */
00133       newSize = (unsigned long) (DELTASYNTABLE * oldSize);
00134       SynTable = (lsymbol *) dmalloc (newSize * sizeof (*SynTable));
00135 
00136       for (i = 0; i < oldSize; i++)
00137         {
00138           SynTable[i] = oldSynTable[i];
00139         }
00140       
00141       sfree (oldSynTable);
00142     }
00143 
00144   /* Zero out new allocated space.  Need to detect when cells are empty     */
00145   /* and do this by checking that SynTable[x] == 0.                         */
00146 
00147   /* ###  Should the "for" loop be replaced with the following?             */
00148   /* #if VMS                                                                */
00149   /* # include <string.h>;                                                  */
00150   /* #else                                                                  */
00151   /* # include <memory.h>;                                                  */
00152   /*                                                                        */
00153   /* memset (SynTable[oldSize], 0,                                          */
00154   /*          (newSize - oldSize) * sizeof (*SynTable));                            */
00155   
00156   for (i = oldSize; i < newSize; i++)
00157     {
00158       SynTable[i] = 0;
00159     }
00160 
00161   MaxSyn = newSize;
00162 }
00163 
00164 
00165 void
00166 LCLSynTableInit (void)
00167 {
00168   MaxSyn = 0;
00169 }
00170 
00171 void
00172 LCLSynTableReset (void)
00173 {
00174 }
00175 
00176 void
00177 LCLSynTableCleanup (void)
00178 {
00179   sfree (SynTable);
00180   SynTable = NULL;
00181 }

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