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

mapping.c File Reference

#include "lclintMacros.nf"
#include "llbasic.h"

Go to the source code of this file.

Defines

#define MAPPING_SIZE   127
#define MMASH(key)    ((unsigned int) ((key) & MAPPING_SIZE))

Functions

void mapping_free ( mapping *m)
mapping* mapping_create (void)
lsymbol mapping_find (mapping * t, lsymbol domain)
void mapping_bind (mapping *t, lsymbol domain, lsymbol range)


Define Documentation

#define MAPPING_SIZE   127
 

Definition at line 38 of file mapping.c.

#define MMASH( key )   ((unsigned int) ((key) & MAPPING_SIZE))
 

Definition at line 43 of file mapping.c.

Referenced by mapping_bind(), and mapping_find().


Function Documentation

void mapping_bind ( mapping * t,
lsymbol domain,
lsymbol range )
 

Definition at line 107 of file mapping.c.

Referenced by symtable_enterType(), and symtable_new().

00108 {
00109   /* add the binding (domain -> range) to t */
00110   /* can assume that the binding is a new one in m, so no need
00111      to check. */
00112   mappair *entry;
00113   mappair *newentry = (mappair *) dmalloc (sizeof (*newentry));
00114   unsigned int key;
00115 
00116   key = MMASH (domain);
00117   /*@-deparrays@*/ entry = t->buckets[key]; /*@=deparrays@*/
00118   newentry->domain = domain;
00119   newentry->range = range;
00120   newentry->next = entry;
00121 
00122   t->buckets[key] = newentry; 
00123   t->count++;
00124 }

mapping * mapping_create ( void )
 

Definition at line 73 of file mapping.c.

Referenced by processImport(), and symtable_new().

00074 {
00075   int i;
00076   mapping *t = (mapping *) dmalloc (sizeof (*t));
00077 
00078   t->buckets = (mappair **) dmalloc ((MAPPING_SIZE + 1) * sizeof (*t->buckets));
00079   t->count = 0;
00080 
00081   for (i = 0; i <= MAPPING_SIZE; i++)
00082     {
00083       t->buckets[i] = (mappair *) 0;
00084     }
00085 
00086   return t;
00087 }

lsymbol mapping_find ( mapping * t,
lsymbol domain )
 

Definition at line 90 of file mapping.c.

Referenced by lsymbol_sortFromType(), and lsymbol_translateSort().

00091 {
00092   mappair *entry;
00093   unsigned int key;
00094 
00095   key = MMASH (domain);
00096   entry = t->buckets[key];
00097   for (; entry != NULL; entry = entry->next)
00098     {
00099       if (entry->domain == domain)
00100         return entry->range;
00101     }
00102 
00103   return lsymbol_undefined;
00104 }

void mapping_free ( mapping * m )
 

Definition at line 59 of file mapping.c.

Referenced by symtable_free().

00060 {
00061   int i;
00062 
00063   for (i = 0; i <= MAPPING_SIZE; i++)
00064     {
00065       mappair_free (m->buckets[i]);
00066     }
00067   
00068   sfree (m->buckets);
00069   sfree (m);
00070 }


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