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

syntable.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 shared language synonym table
00028 **
00029 **      This table stores synonyms for the Larch Shared Language.  It is
00030 **      essentially a 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 # include "lclintMacros.nf"
00038 # include "basic.h"
00039 # include "tokentable.h"
00040 # include "syntable.h"
00041 
00042 /*@+ignorequals@*/
00043 
00044 typedef lsymbol *lsymbolTable;
00045 
00046 static /*@only@*/ /*@null@*/ lsymbolTable SynTable;     
00047 static unsigned long int SynTableEntries;
00048 
00049 static void SynTable_grow (int p_size);
00050 
00051 /*
00052 **++
00053 **  FUNCTION NAME:
00054 **
00055 **      LSLAddSyn ()
00056 **
00057 **  FORMAL PARAMETERS:
00058 **
00059 **      otok  - token-handle for token associated with oldToken
00060 **      ntok  - string-handle for the string to be a synonym with oldToken.
00061 **
00062 **  RETURN VALUE:
00063 **
00064 **  INVARIANTS:
00065 **
00066 **      A context must be established.
00067 **
00068 **  DESCRIPTION:
00069 **
00070 **    This routine inserts a synonym into the synonym table.  The synonym table
00071 **    is used to define synonyms in the form:
00072 **
00073 **          synonym oldToken newToken
00074 **
00075 **    The table associates the string for newToken with the token for oldToken.
00076 **    This table is used to find the the actual token (oldToken) from a synonym
00077 **    string (newToken).
00078 **
00079 **    A new SynTable is allocated when:
00080 **      . The SynTable[] is empty (initial case)
00081 **      . The location where to insert the synonym is not in SynTable[]
00082 **
00083 **  IMPLICIT INPUTS/OUTPUT:
00084 **
00085 **    SynTable      - (input/output) SynTable array
00086 **
00087 **  EXCEPTIONS:
00088 **    A synonym already exists at the location where the it is to be added.
00089 **
00090 **--
00091 */
00092 
00093 void
00094 LSLAddSyn (lsymbol ntok, lsymbol otok)
00095 {
00096   if (ntok >= SynTableEntries) /* was otok */
00097     {
00098       SynTable_grow (otok);
00099     }
00100 
00101   llassert (SynTable != NULL);
00102 
00103   if (SynTable[ntok] == (lsymbol) 0)
00104     {                           /* Entry is empty. Fill it in. */
00105       SynTable[ntok] = otok;
00106       LSLSetTokenHasSyn (otok, TRUE);   /* Mark oldToken as having a synonym. */
00107     }
00108   else
00109     {
00110       llbuglit ("LSLAddSyn: duplicate SynTable entry");
00111     }
00112 }
00113 
00114 /*@exposed@*/ ltoken
00115 LSLGetTokenForSyn (lsymbol ntok)
00116 {
00117   llassert (SynTable != NULL);
00118   llassert (!(!((ntok < SynTableEntries) || (SynTable[ntok] != 0))));
00119 
00120   return LSLGetToken (SynTable[ntok]);
00121 }
00122 
00123 bool
00124 LSLIsSyn (lsymbol str)
00125 {
00126   if (str < SynTableEntries)
00127     {
00128       llassert (SynTable != NULL);
00129       return (SynTable[str] != 0);
00130     }
00131   else
00132     {
00133       return FALSE;
00134     }
00135 }
00136 
00137 static void
00138 SynTable_grow (int size)
00139 {
00140   int oldSize;
00141   int i;
00142   lsymbolTable oldSynTable = SynTable;
00143   
00144   llassert (oldSynTable != NULL);
00145   oldSize = SynTableEntries;
00146   
00147   if (size <= oldSize)
00148     {
00149       llcontbuglit ("SynTable_grow: goal size is smaller than oldSize");
00150       return;
00151     }
00152   
00153   if (size < (oldSize + SYNTABLE_BASESIZE))
00154     {
00155       size = oldSize + SYNTABLE_BASESIZE;
00156     }
00157 
00158   SynTable = (lsymbolTable) dmalloc (size * sizeof (*SynTable));
00159   SynTableEntries = size;
00160 
00161   for (i = 0; i < oldSize; i++)
00162     {
00163       SynTable[i] = oldSynTable[i];
00164     }
00165 
00166   /* Zero out new allocated space.  Need to detect when cells are empty   */
00167   /* and do this by checking that SynTable[x] == 0.                       */
00168 
00169   /*@+loopexec@*/
00170   for (i = oldSize; i < size; i++)
00171     {
00172       SynTable[i] = (lsymbol) 0;
00173     }
00174   /*@=loopexec@*/
00175 
00176   sfree (oldSynTable);
00177 /*@-compdef@*/ } /*=compdef@*/
00178 
00179 void
00180 lsynTableInit (void) /*@globals undef SynTable; @*/
00181 {
00182   int i;
00183 
00184   SynTable = (lsymbolTable) dmalloc (sizeof (*SynTable) * SYNTABLE_BASESIZE);
00185 
00186   /*@+loopexec@*/
00187   for (i = 0; i < SYNTABLE_BASESIZE; i++)
00188     {
00189       SynTable[i] = (lsymbol) 0;
00190     }
00191   /*@=loopexec@*/
00192 
00193   SynTableEntries = SYNTABLE_BASESIZE;
00194 /*@-compdef@*/ } /*@=compdef@*/
00195 
00196 void
00197 lsynTableReset (void)
00198 {
00199 }
00200 
00201 void
00202 lsynTableCleanup (void)
00203 {
00204   sfree (SynTable);
00205   SynTable = NULL;
00206 }
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 

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